d2sketch

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: 17 Imported by: 1 module, 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 (
	BG_COLOR = color.N7
	FG_COLOR = color.N1
)

Variables

This section is empty.

Functions

func ArrowheadDrawables added in v0.9.0

func ArrowheadDrawables(arrowhead d2target.Arrowhead, stroke string, strokeWidth int) ([]rough.Drawable, bool)

ArrowheadDrawables returns the bounded, structured rough-go geometry for one D2 arrowhead. Every generator input has a fixed number of points, and each endpoint gets a fresh seeded generator so output is independent of object or frame traversal order.

func ArrowheadDrawablesWithWidth added in v0.10.0

func ArrowheadDrawablesWithWidth(arrowhead d2target.Arrowhead, stroke string, strokeWidth float64) ([]rough.Drawable, bool)

ArrowheadDrawablesWithWidth accepts fractional widths from animation frames.

func ArrowheadPlacement added in v0.10.0

func ArrowheadPlacement(connection d2target.Connection, isTarget bool, adjustment *geo.Point) (anchor geo.Point, degrees float64)

ArrowheadPlacement positions a sketch arrowhead's local geometry in diagram coordinates. Gradient paints use the same placement as the rendered paths.

func Arrowheads

func Arrowheads(connection d2target.Connection, srcAdj, dstAdj *geo.Point) (string, error)

func ArrowheadsWithPaint added in v0.10.0

func ArrowheadsWithPaint(connection d2target.Connection, srcAdj, dstAdj *geo.Point, srcStroke, dstStroke string) (string, error)

ArrowheadsWithPaint accepts a paint for each endpoint in its local coordinates.

func Class

func Class(shape d2target.Shape) (string, error)

func Connection

func Connection(connection d2target.Connection, path, attributes string) (string, error)

Connection is retained for source compatibility. Its legacy textual attribute list is parsed and re-serialized before use. Deprecated: use ConnectionWithAttributes.

func ConnectionDrawable added in v0.9.0

func ConnectionDrawable(ctx context.Context, path d2scene.Path, limits SceneLimits) (rough.Drawable, error)

ConnectionDrawable converts a typed connection path into deterministic rough-go operations without serializing or parsing SVG path data. Cubics are flattened at a fixed resolution before roughening; this keeps generation work predictable while retaining the route's rounded/curved silhouette. limits bound the rough intermediate before any expanded point slice is allocated. Long routes are generated in fixed-size sets so cancellation is observed between bounded rough-go calls.

func ConnectionWithAttributes added in v0.10.0

func ConnectionWithAttributes(connection d2target.Connection, path string, attributes []svg.Attribute) (string, error)

func DefineFillPatterns

func DefineFillPatterns(buf *bytes.Buffer, diagramHash string)

DefineFillPatterns adds reusable patterns that are overlayed on shapes with fill. This gives it a subtle streaky effect that subtly looks hand-drawn but not distractingly so.

func DefineSharedFillPatterns added in v0.10.0

func DefineSharedFillPatterns(buf *bytes.Buffer, diagramHash string)

DefineSharedFillPatterns reuses the path between inks. Use DefineFillPatterns when a custom stylesheet can target the path inside each pattern.

func DoubleOval

func DoubleOval(shape d2target.Shape, diagramHash string) (string, error)

func DoubleRect

func DoubleRect(shape d2target.Shape, diagramHash string) (string, error)

func MarkdownBackground added in v0.10.0

func MarkdownBackground(s d2target.Shape, sketch bool) string

MarkdownBackground keeps the viewport behind the glyphs clear while pencil strokes are visible. A label outside or across the border still needs its own backing. At either endpoint use the authored board's normal backing.

func Oval

func Oval(shape d2target.Shape, diagramHash string) (string, error)

func Paths

func Paths(shape d2target.Shape, diagramHash string, paths []string) (string, error)

TODO need to personalize this per shape like we do in Terrastruct app

func Rect

func Rect(shape d2target.Shape, diagramHash string) (string, error)

func Table

func Table(shape d2target.Shape) (string, error)

TODO cleanup

func TexturePaint added in v0.10.0

func TexturePaint(s d2target.Shape, renderedFill string) string

TexturePaint selects the material for the existing streak overlay. Static sketch textures use the material produced by the element renderer (which also resolves gradients). A pencil pattern takes its texture from the underlying sampled color, rather than from its temporary paint-server ID.

Types

type PencilFill added in v0.10.0

type PencilFill struct {
	Paper, Ink      string
	GraphiteOpacity float64
	Bands           [][4]d2scene.Point
}

PencilFill is one sampled pass of diagonal pencil strokes, in shape-local coordinates. Both exporters use these same strokes; the shape supplies the silhouette. Each quadrilateral is ordered around its perimeter.

func SamplePencilFill added in v0.10.0

func SamplePencilFill(s d2target.Shape) *PencilFill

type SceneLimits added in v0.9.0

type SceneLimits struct {
	MaxSets int
	MaxOps  int
}

SceneLimits bounds conversion work after rough-go has generated a drawable. D2 callers must additionally charge the generated commands against their document-wide scene/path budget.

type ScenePath added in v0.9.0

type ScenePath struct {
	Path        d2scene.Path
	Fill        string
	Stroke      string
	StrokeWidth float64
	Dash        []float64
	DashOffset  float64
}

ScenePath is the renderer-neutral form of one ordered rough-go operation set. Paint remains a string so callers can resolve D2 theme colors before constructing scene paint.

func CompileScenePaths added in v0.9.0

func CompileScenePaths(ctx context.Context, drawable rough.Drawable, limits SceneLimits) ([]ScenePath, error)

CompileScenePaths translates the rough-go operation types emitted by D2 into typed scene paths. It rejects path2D operation sets.

Jump to

Keyboard shortcuts

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