d2scenebuild

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2026 License: MPL-2.0 Imports: 47 Imported by: 0

Documentation

Overview

Package d2scenebuild converts D2's typed export model into the immutable scene consumed by d2raster.

Index

Constants

View Source
const DefaultPadding = 100

Variables

This section is empty.

Functions

func Build

func Build(ctx context.Context, diagram *d2target.Diagram, options Options) (*d2scene.Document, error)

Build preflights diagram features and returns a fully resolved, network-free scene. It never emits a partial scene on error.

Types

type AssetOptions

type AssetOptions struct {
	// Resolver owns bounded image loading for this scene build.
	// [imageasset.ErrUnavailable] substitutes the built-in missing-image
	// placeholder; every other error aborts the build.
	Resolver        *imageasset.Resolver
	SVGImportLimits d2svgimport.Limits
	SVGImportBudget SVGImportBudget
}

type FontFallbackOptions

type FontFallbackOptions struct {
	Resolver          d2fonts.FallbackResolver
	MaxAssets         int
	MaxBytes          int64
	MaxRunesPerText   int
	MaxTotalRunes     int
	MaxCoverageChecks int64
	// MaxFontFacesPerText, MaxShapingRuns, and MaxShapedGlyphs bound the
	// pure-Go shaping pass that materializes renderer-independent Glyphs after
	// fallback resolution. Zero selects bounded defaults.
	MaxFontFacesPerText int
	MaxShapingRuns      int
	MaxShapedGlyphs     int
}

FontFallbackOptions bounds all primary/custom and resolved fallback font assets retained by the scene. The resolver performs the explicit I/O phase for code points absent from D2's configured fonts; d2raster never receives it and performs no filesystem discovery while painting.

type LinkBudget

type LinkBudget struct {
	MaxRegions     int
	MaxStringBytes int
}

LinkBudget is a document-wide ceiling on link/tooltip metadata and, when Appendix is enabled, its corresponding static badges and row strings. Callers rendering a diagram that contains such metadata must provide positive limits; diagrams without metadata require no link budget.

type Options

type Options struct {
	Pad            *int64
	Scale          *float64
	Center         *bool
	ThemeID        *int64
	ThemeOverrides *d2target.ThemeOverrides
	// MaxNodes and MaxPathCommands enable an early, target-level admission
	// guard when positive. The guard rejects only when the target already
	// proves that the eventual scene must exceed a downstream renderer limit;
	// d2raster remains responsible for exact accounting of expanded geometry.
	MaxNodes        int
	MaxPathCommands int
	Sketch          bool
	SketchBudget    SketchBudget
	LinkBudget      LinkBudget
	// Appendix paints the numbered tooltip/link badges and static appendix
	// rows used by PNG, GIF, PDF, and PPTX exports. Interactive SVG callers
	// leave it false and retain typed metadata without static footnotes. Its
	// work is bounded by LinkBudget.
	Appendix bool

	// Assets configures the explicit, bounded I/O phase for image and
	// icon sources. Build stores only immutable bytes or imported vector scene
	// nodes in the returned document; d2raster never receives this resolver.
	Assets *AssetOptions
	Fonts  *FontFallbackOptions
}

Options configures scene construction. Scale changes the logical output dimensions, while the raster device scale is supplied to d2raster separately.

type SVGImportBudget

type SVGImportBudget struct {
	MaxSourceBytes          int
	MaxElements             int
	MaxAttributes           int
	MaxAttributeBytes       int
	MaxPathCommands         int
	MaxTransformFunctions   int
	MaxDeclaredResources    int
	MaxExpandedUseInstances int
}

SVGImportBudget is a document-wide ceiling on parse and emitted-scene work across all distinct imported SVG assets. SVGImportLimits independently bounds the transient parse/compile work of each asset.

type SketchBudget

type SketchBudget struct {
	MaxOperationSets int
	MaxOperations    int
	MaxPathCommands  int
}

SketchBudget is a document-wide ceiling on structured rough-go output. MaxOperationSets and MaxOperations bound the generated intermediate work; MaxPathCommands independently bounds the typed scene geometry retained by the document. Callers enabling Sketch for paintable sketch geometry must provide positive limits.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL