Help us shape the future of Go! Take the 2026 Go Developer Survey

post

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package post applies a design system's SVG decorators to D2 output: the parts of a visual language D2's style model cannot express (Carbon side bars, colour blocks, pill labels, strike-through).

D2 writes each object and connection as a <g> whose class attribute holds an encoded ID followed by the element's D2 classes, so decorators select by class: a role, a modifier, or a marker class an author adds. Decorations take their colour from the element's stroke, so domain colours carry through.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(svg []byte, diagram, theme string, all []Decorator) []byte

Apply returns svg, a rendered diagram of the given type and theme, with decorators applied.

Types

type Colour

type Colour map[string]string

Colour is a colour for every theme, or one per theme. In JSON it is a string ("#fff") or an object ({"light": "#fff", "dark": "#000"}).

func (*Colour) UnmarshalJSON

func (c *Colour) UnmarshalJSON(b []byte) error

UnmarshalJSON accepts a plain string as a colour for every theme.

type Decorator

type Decorator struct {
	// Type is one of: bar, block, icon, avatar, fill, legend, chevron, pill,
	// strike.
	//   bar:    a solid band along one side of a node (Carbon side bar / top bar)
	//   block:  a solid square at the left of a node, holding its icon (Carbon colour block)
	//   icon:   an icon centred in a node (Carbon actor circles)
	//   avatar: a badge at the left of a node, holding the icon: round, or
	//           square with shape "square"; filled with fill ("stroke" = the
	//           node's domain colour) or the theme's text colour (Cloudscape
	//           avatars, Fluent service badges)
	//   fill:   fills a node with its stroke colour (legend swatches)
	//   legend: flattens the legend: no frame, shadow or rounded corners
	//           (takes no classes; applies to the whole diagram)
	//   chevron: draws filled arrowheads as open chevrons (takes no classes;
	//           hollow UML triangles, diamonds and crow's feet are kept)
	//   pill:   a rounded outline around a connection's label
	//   strike: a diagonal line through a node (Carbon "removed")
	Type string `json:"type"`
	// Classes selects the elements to decorate (any match).
	Classes []string `json:"classes"`
	// Diagrams limits the decorator to these diagram types; empty means all.
	// Roles are per diagram type, so the same class name can mean different
	// things in different diagrams.
	Diagrams []string `json:"diagrams,omitempty"`
	// Side places a bar: left (default), top or bottom.
	Side string `json:"side,omitempty"`
	// Size is the bar thickness, block width or avatar diameter, in px.
	Size float64 `json:"size,omitempty"`
	// Icon is an SVG file in the design system, drawn by block (when the node
	// has no icon of its own) and icon. It is filled with the canvas colour, so
	// it reads on the solid block or shape in both themes.
	Icon string `json:"icon,omitempty"`
	// IconStroke draws the icon as an outline, with strokes this wide in the
	// icon's own units (Cloudscape icons: 2 on a 16px grid). Zero fills it.
	IconStroke float64 `json:"icon_stroke,omitempty"`
	// Fill colours an avatar badge; IconColor colours the icon. Defaults: the
	// theme's text colour and the canvas colour.
	// Both take a colour, or one per theme: {"light": ..., "dark": ...}.
	// Fill "stroke" uses the node's stroke colour (its domain colour).
	Fill      Colour `json:"fill,omitempty"`
	IconColor Colour `json:"icon_color,omitempty"`
	// Shape of an avatar badge: circle (default) or square.
	Shape string `json:"shape,omitempty"`
	// Outline, by theme, restrokes a block's node after the block takes the
	// domain colour: the colour stays in the block, the border goes neutral.
	Outline Colour `json:"outline,omitempty"`
	// IconSVG is the icon file's content, loaded by the design system.
	IconSVG string `json:"-"`
	// contains filtered or unexported fields
}

Decorator is one entry of a manifest's "decorators" list.

func (Decorator) Validate

func (d Decorator) Validate() error

Validate reports a decorator its manifest got wrong.

Jump to

Keyboard shortcuts

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