d2animate

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MPL-2.0 Imports: 28 Imported by: 2 modules, 0 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

View Source
const ProgressGap = 8

ProgressGap is the clear space between the artwork canvas and the line, in output pixels.

View Source
const ProgressHeight = 6

ProgressHeight is the maximum playback progress line height in output pixels.

View Source
const ProgressTrackOpacity = 0.24

ProgressTrackOpacity is the fraction of the automatic progress color shown in the unplayed part of the bar.

Variables

This section is empty.

Functions

func IsLayerPullback added in v0.10.1

func IsLayerPullback(legs []LayerLeg) bool

IsLayerPullback reports whether the route travels through linked ancestors.

func LayerDuration added in v0.10.1

func LayerDuration(root *d2target.Diagram) (int, error)

LayerDuration reads the transition duration from the document root, even when only a subtree will be exported.

func ProgressBoardGap added in v0.10.1

func ProgressBoardGap(center, width, lineHeight, previousEnd int) (left, right int, ok bool)

ProgressBoardGap returns a cut at a board boundary. Leave at least one gap-width of track between cuts and at the ends so a densely repeated tour can still show how much time has elapsed. Coordinates are relative to the bar.

func ProgressColor added in v0.10.1

func ProgressColor(themeID *int64, overrides *d2target.ThemeOverrides) string

ProgressColor returns the contrast-checked inverse of the theme's canvas.

func ProgressLineHeight added in v0.10.1

func ProgressLineHeight(width, height int) int

ProgressLineHeight is 1% of the shorter canvas side, rounded to whole pixels.

func ProgressTickX added in v0.10.1

func ProgressTickX(elapsed, total int64, width int) int

ProgressTickX places a board boundary on the output clock. An internal boundary stays inside the canvas even if its time rounds to an edge.

func PullbackPosition added in v0.10.1

func PullbackPosition(legCount int, progress float64) (leg int, local float64)

PullbackPosition maps route progress to a leg and its local progress. The easing starts and stops the whole camera move, rather than each leg.

func ResolveProgressColor added in v0.10.1

func ResolveProgressColor(themeID *int64, overrides *d2target.ThemeOverrides, explicit string) (string, error)

ResolveProgressColor selects explicit paint or the theme canvas's automatic ink.

func TranslationTracks added in v0.10.1

func TranslationTracks(board *d2target.Diagram) map[string]d2scene.Track

TranslationTracks returns rigid translations of unchanged artwork in a validated board. A nil result keeps the original render-and-hold sequence. Matrices translate the first sample's integer geometry; compiler-provided motion offsets distinguish continuous trajectories from authored holds.

func ValidateSVGIconLoop added in v0.10.1

func ValidateSVGIconLoop(root *d2target.Diagram, boardPath []string, intervalMS, zoomMS int) error

ValidateSVGIconLoop checks an explicitly selected animation without creating per-frame pictures. A single drawable SVG runs its icon clocks continuously.

func Wrap

func Wrap(rootDiagram *d2target.Diagram, svgs [][]byte, renderOpts d2svg.RenderOpts, intervalMS int) ([]byte, error)

func WrapTimed added in v0.10.0

func WrapTimed(rootDiagram *d2target.Diagram, svgs [][]byte, renderOpts d2svg.RenderOpts, durationsMS []int) ([]byte, error)

WrapTimed composes independently rendered SVG frames on a shared playback clock.

func WrapTimeline added in v0.10.1

func WrapTimeline(rootDiagram *d2target.Diagram, boardPath []string, frames []Frame, svgs [][]byte, renderOpts d2svg.RenderOpts, durationMS int) ([]byte, error)

WrapTimeline plays every frame in order, zooming through linked layers. Activating a layer link pauses the tour to explore that layer and its steps. boardPath identifies the selected subtree relative to the document root.

Types

type Frame added in v0.10.0

type Frame struct {
	Diagram    *d2target.Diagram
	DurationMS int

	// TweenSample distinguishes an already sampled transition from a board
	// whose independent shape and connection animations still need sampling.
	TweenSample bool
	// ElapsedMS is the local time of a sampled frame within its board.
	ElapsedMS int
	// contains filtered or unexported fields
}

Frame is a diagram held for a duration on the playback timeline.

func AppendBoardFrames added in v0.10.0

func AppendBoardFrames(frames []Frame, board *d2target.Diagram, intervalMS int) []Frame

AppendBoardFrames expands one validated, drawable board. Raster exporters impose their own traversal limits before expanding its samples.

func RenderSVGFrames added in v0.10.1

func RenderSVGFrames(root *d2target.Diagram, boardPath []string, frames []Frame, opts d2svg.RenderOpts, zoomMS int, render func(*d2target.Diagram) ([]byte, error)) ([]Frame, [][]byte, error)

RenderSVGFrames renders the artwork for WrapTimeline. A straight or eased translation of otherwise identical artwork needs only a few reference poses. Check the emitted SVG too, since bundling, appendices and custom renderers can change it.

func SVGTimeline added in v0.10.1

func SVGTimeline(root *d2target.Diagram, boardPath []string, intervalMS, zoomMS int) ([]Frame, error)

SVGTimeline also accounts for the travel time of linked-layer zooms when rendering a selected subtree of the document.

func SceneTimeline added in v0.10.1

func SceneTimeline(root *d2target.Diagram, intervalMS, zoomMS int) ([]Frame, error)

SceneTimeline prepares board-local icon clocks for finite native playback. A camera can revisit an exact board at time zero or extend its final hold.

func Timeline added in v0.10.0

func Timeline(root *d2target.Diagram, intervalMS int) ([]Frame, error)

Timeline returns the same root, layer, scenario and step order as a normal multiboard export, inserting incoming transition samples immediately before each board.

func (Frame) Picture added in v0.10.1

func (f Frame) Picture() *d2target.Diagram

Picture returns the artwork for this frame, including any render-time icon schedule.

func (Frame) StartFraction added in v0.10.1

func (f Frame) StartFraction() time.Duration

StartFraction restores the fraction of a millisecond omitted by ElapsedMS for uniform tweens. Explicit millisecond boundaries have no remainder.

type IconTimeline added in v0.10.1

type IconTimeline struct {
	// contains filtered or unexported fields
}

IconTimeline can seek to any time within an authored board. Entry states retain only the copies still in flight, independently of the length of a hold.

func NewIconTimeline added in v0.10.1

func NewIconTimeline(root *d2target.Diagram, intervalMS int) (*IconTimeline, error)

func (*IconTimeline) Active added in v0.10.1

func (tl *IconTimeline) Active(board *d2target.Diagram) bool

func (*IconTimeline) MissingIconSample added in v0.10.1

func (tl *IconTimeline) MissingIconSample(board *d2target.Diagram, startMS, endMS int, samples []int) (int, bool)

MissingIconSample chooses a time inside the board's hold if the proposed storyboard samples all miss the moving artwork. Work depends on the number of streams, regardless of how long it takes for the next departure.

func (*IconTimeline) Sample added in v0.10.1

func (tl *IconTimeline) Sample(board, picture *d2target.Diagram, elapsedMS int) *d2target.Diagram

Sample keeps the route of picture (which may be a tween), and evaluates the icon clock at elapsedMS since the beginning of the authored board.

func (*IconTimeline) ScenePicture added in v0.10.1

func (tl *IconTimeline) ScenePicture(board *d2target.Diagram, frame Frame) *d2target.Diagram

ScenePicture gives a fixed native scene its carried icons and launch clock. Render that scene with timestamps measured from the beginning of its board.

type LayerLeg added in v0.10.1

type LayerLeg struct {
	From, To *d2target.Diagram
	Zoom     LayerZoom
}

LayerLeg visits two boards through a shape on their enclosing board.

type LayerNavigation added in v0.10.1

type LayerNavigation struct {
	// contains filtered or unexported fields
}

LayerNavigation resolves links between authored boards in a validated export tree. Tween samples are artwork, never navigation destinations.

func NewLayerNavigation added in v0.10.1

func NewLayerNavigation(root *d2target.Diagram, boardPath []string) *LayerNavigation

NewLayerNavigation indexes a selected subtree. boardPath is its absolute D2 target path relative to root, e.g. ["layers", "api"].

func (*LayerNavigation) HasLayerPortal added in v0.10.1

func (nav *LayerNavigation) HasLayerPortal() bool

HasLayerPortal reports whether an authored shape can take the camera between two drawable boards in this export tree.

func (*LayerNavigation) Route added in v0.10.1

func (nav *LayerNavigation) Route(from, to *d2target.Diagram) []LayerLeg

Route follows real portals up to the common layer and back down into the destination. A direct link takes precedence over the longer tree path. No route exists between two steps on the same layer or across a missing portal.

func (*LayerNavigation) Zoom added in v0.10.1

func (nav *LayerNavigation) Zoom(from, to *d2target.Diagram) (LayerZoom, bool)

Zoom uses the enclosing board's portal in both directions, even when the child has its own link pointing back to the parent.

type LayerPose added in v0.10.1

type LayerPose struct {
	Scale, DX, DY, Opacity float64
}

LayerPose maps artwork to viewport coordinates as scale*point + (DX,DY).

type LayerRouteTiming added in v0.10.1

type LayerRouteTiming struct {
	// contains filtered or unexported fields
}

LayerRouteTiming divides the configured movement time among the legs of a linked-layer route and holds each intermediate board at its resting pose.

func NewLayerRouteTiming added in v0.10.1

func NewLayerRouteTiming(legs, movementMS int) LayerRouteTiming

NewLayerRouteTiming plans a route with the configured aggregate movement time.

func (LayerRouteTiming) DurationMS added in v0.10.1

func (t LayerRouteTiming) DurationMS() int

DurationMS returns the full travel window, including intermediate holds.

func (LayerRouteTiming) Leg added in v0.10.1

func (t LayerRouteTiming) Leg(index int) (startMS, durationMS float64)

Leg returns the start and duration of one camera move in milliseconds.

func (LayerRouteTiming) Sample added in v0.10.1

func (t LayerRouteTiming) Sample(elapsedMS float64) (index int, progress float64)

Sample returns the active camera move and its progress. A waypoint hold samples the arriving move at its endpoint so all renderers paint the same pose.

type LayerZoom added in v0.10.1

type LayerZoom struct {
	Focus  *d2target.Shape
	Inward bool
	// contains filtered or unexported fields
}

LayerZoom moves through the linking shape on the enclosing board.

func (LayerZoom) Portal added in v0.10.1

func (z LayerZoom) Portal() image.Rectangle

Portal returns the camera's focus in its enclosing board's viewport.

func (LayerZoom) Poses added in v0.10.1

func (z LayerZoom) Poses(viewport image.Rectangle, progress float64) (parent, child LayerPose)

Poses returns the enclosing and inner boards' transforms, in that order for either direction. Studio uses 400ms for the pan, 600ms for the zoom, and 500ms for the outgoing child's fade. Scale each phase to the chosen transition duration.

type PullbackPose added in v0.10.1

type PullbackPose struct {
	LayerPose
	Blur float64
}

PullbackPose includes a blur radius in output pixels, independent of scale.

func PullbackPoses added in v0.10.1

func PullbackPoses(viewport, previous, portal, next image.Rectangle, local float64) (parent, child PullbackPose)

PullbackPoses returns the parent and child on the same camera. The previous portal is in child coordinates. The next portal is in the next ancestor's coordinates. Empty neighbors mark the first and last boards.

Jump to

Keyboard shortcuts

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