d2lib

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MPL-2.0 Imports: 32 Imported by: 12 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(ctx context.Context, input string, compileOpts *CompileOptions, renderOpts *d2svg.RenderOpts) (*d2target.Diagram, *d2graph.Graph, error)

func Parse

func Parse(ctx context.Context, input string, compileOpts *CompileOptions) (*d2ast.Map, error)

func PrepareSketchTransitions added in v0.10.0

func PrepareSketchTransitions(ctx context.Context, root *d2target.Diagram, duration int64) error

PrepareSketchTransitions adds pencil samples to a compiled diagram when a caller enables sketch at render time. It modifies the supplied board tree.

Types

type CompileOptions

type CompileOptions struct {
	UTF16Pos bool
	// AnimateDuration overrides the root animate-duration, in milliseconds.
	AnimateDuration *int64
	// AnimateTweens controls sampling of step transitions. Nil follows
	// the root animate-interval. False compiles only the authored endpoints.
	AnimateTweens *bool
	// MaxVariableExpansion bounds work added by variable substitutions and the
	// automatic copies they induce. Zero uses the secure compiler default.
	MaxVariableExpansion int64
	// MaxGlobExpansion bounds work performed by glob matching and
	// materialization. Zero uses the secure compiler default. Explicit source
	// fields are not counted as materialization work.
	MaxGlobExpansion int64
	// MaxEdgeExpansion bounds distinct edge-segment and endpoint combinations
	// considered by edge globs. Zero uses the secure compiler default. Explicit
	// edges do not consume this budget.
	MaxEdgeExpansion int64
	// MaxEdgeExpansionWork bounds all endpoint-pair examinations performed by
	// edge globs, including lazy replays. Zero uses the secure compiler default.
	MaxEdgeExpansionWork int64
	// FS is the file system used for resolving imports in the D2 text. Nil
	// disables imports. Callers that accept untrusted input should prefer a
	// filesystem constrained to the intended import root; lib/localfile provides
	// rooted and explicit unrestricted host-filesystem policies.
	FS             fs.FS
	MeasuredTexts  []*d2target.MText
	Ruler          *textmeasure.Ruler
	RouterResolver func(engine string) (d2graph.RouteEdges, error)
	LayoutResolver func(engine string) (d2graph.LayoutGraph, error)

	// LayoutReuse allows scenarios and steps whose layout inputs are unchanged
	// to reuse the geometry of their base board. Callers should enable this only
	// when LayoutResolver and RouterResolver return a stable built-in Dagre or
	// ELK configuration for the duration of Compile. It is disabled by default
	// so custom resolvers retain their existing per-board behavior.
	LayoutReuse bool

	// LayoutContinuations supplies optional refinements for related boards,
	// keyed by lowercase layout engine name. Independent layers start fresh.
	LayoutContinuations map[string]d2graph.LayoutContinuation

	Layout *string

	// FontFamily controls the font family used for all texts that are not the following:
	// - code
	// - latex
	// - pre-measured (web setting)
	// TODO maybe some will want to configure code font too, but that's much lower priority
	FontFamily *d2fonts.FontFamily

	// MonoFontFamily controls the font family used for code/mono texts
	MonoFontFamily *d2fonts.FontFamily

	InputPath string
}

Jump to

Keyboard shortcuts

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