Documentation
¶
Overview ¶
Package d2scenebuild converts D2's typed export model into the immutable scene consumed by d2raster.
Index ¶
- Constants
- func Build(ctx context.Context, diagram *d2target.Diagram, options Options) (*d2scene.Document, error)
- func PaintAnimationPeriods(board *d2target.Diagram) iter.Seq[time.Duration]
- func ShortestAnimationPeriod(board *d2target.Diagram) time.Duration
- type AssetOptions
- type FontFallbackOptions
- type LinkBudget
- type Options
- type SVGImportBudget
- type SketchBudget
Constants ¶
const DefaultPadding = 100
UnavailableImageSVG is the built-in missing-image icon shared by native exports and their SVG previews.
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.
func PaintAnimationPeriods ¶ added in v0.10.1
PaintAnimationPeriods yields the visible periods of native shape pulses and moving dashes. A dash repeats its appearance ten times per track cycle.
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
// the built-in placeholder. Supply a fresh map for each board preview.
UnavailableImages map[string]struct{}
// source replaced by the built-in placeholder.
OnUnavailableImage func(error)
}
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 ¶
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 {
// MinimumBounds is the unpadded world-space viewport shared by animation frames.
MinimumBounds *image.Rectangle
// ShapeTranslations contains absolute translations of each shape's integer
// geometry during a continuous sampled step.
ShapeTranslations map[string]d2scene.Track
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 ¶
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.
Source Files
¶
- annotation.go
- appendix.go
- assets.go
- build.go
- code_shape.go
- color.go
- connection.go
- connection_icons.go
- font_fallback.go
- labels.go
- latex.go
- legend.go
- markdown.go
- metadata.go
- pattern_sources.go
- patterns.go
- pencil_fill.go
- shape_effects.go
- shared_strokes.go
- sketch.go
- sketch_connection.go
- sketch_shapes.go
- special_shapes.go
- tooltip.go