d2themes

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: 6 Imported by: ? 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.

README

d2themes

d2themes defines themes for D2. You can add a new one in ./d2themescatalog, give a unique ID, and specify it in the CLI or library to see it.

Run d2 themes to list the available names and IDs. For example, you can select Shirley Temple (ID 102) in a diagram and use Dark Mauve for dark mode.

vars: {
  d2-config: {
    theme-id: Shirley Temple
    dark-theme-id: Dark Mauve
  }
}

Theme names are case-insensitive. You can use hyphens for spaces, as in shirley-temple, or pass the name as a single CLI argument.

d2 --theme "Shirley Temple" in.d2 out.svg

Run d2 --help or man d2 for more.

Themes overview

Color coding guide

To distinguish container nesting, objects get progressively lighter the more nested it is.

Color coding example

Documentation

Overview

d2themes defines themes to make d2 diagrams pretty Color codes: darkest (N1) -> lightest (N7)

Index

Constants

This section is empty.

Variables

View Source
var CoolNeutral = Neutral{
	N1: "#0A0F25",
	N2: "#676C7E",
	N3: "#9499AB",
	N4: "#CFD2DD",
	N5: "#DEE1EB",
	N6: "#EEF1F8",
	N7: "#FFFFFF",
}
View Source
var DarkMauveNeutral = Neutral{
	N1: "#CDD6F4",
	N2: "#BAC2DE",
	N3: "#A6ADC8",
	N4: "#585B70",
	N5: "#45475A",
	N6: "#313244",
	N7: "#1E1E2E",
}
View Source
var DarkNeutral = Neutral{
	N1: "#F4F6FA",
	N2: "#BBBEC9",
	N3: "#868A96",
	N4: "#676D7D",
	N5: "#3A3D49",
	N6: "#191C28",
	N7: "#000410",
}
View Source
var WarmNeutral = Neutral{
	N1: "#170206",
	N2: "#535152",
	N3: "#787777",
	N4: "#CCCACA",
	N5: "#DFDCDC",
	N6: "#ECEBEB",
	N7: "#FFFFFF",
}

Functions

func ClampBorderRadius added in v0.10.0

func ClampBorderRadius(borderRadius, width, height float64) float64

ClampBorderRadius limits both corner axes to half the shorter side of the body.

func PaintVisibleIn added in v0.10.0

func PaintVisibleIn(themes ...Theme) func(string) bool

PaintVisibleIn returns a per-render predicate for ink visible in every active palette. A responsive SVG shares its crossing masks between light and dark.

func ResolveThemeColor

func ResolveThemeColor(theme Theme, code string) string

func ShapeTheme

func ShapeTheme(shape d2target.Shape) (fill, stroke string)

Types

type ColorPalette

type ColorPalette struct {
	Neutrals Neutral `json:"neutrals"`

	// Base Colors: used for containers
	B1 string `json:"b1"`
	B2 string `json:"b2"`
	B3 string `json:"b3"`
	B4 string `json:"b4"`
	B5 string `json:"b5"`
	B6 string `json:"b6"`

	// Alternative colors A
	AA2 string `json:"aa2"`
	AA4 string `json:"aa4"`
	AA5 string `json:"aa5"`

	// Alternative colors B
	AB4 string `json:"ab4"`
	AB5 string `json:"ab5"`
}

type Neutral

type Neutral struct {
	N1 string `json:"n1"`
	N2 string `json:"n2"`
	N3 string `json:"n3"`
	N4 string `json:"n4"`
	N5 string `json:"n5"`
	N6 string `json:"n6"`
	N7 string `json:"n7"`
}

type PatternOverlay deprecated

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

PatternOverlay renders a legacy pattern overlay for a themable element.

Deprecated: PatternOverlay is no longer used by D2 and will be removed after one compatibility release. There is no replacement.

func NewPatternOverlay deprecated

func NewPatternOverlay(el *ThemableElement, pattern string) *PatternOverlay

NewPatternOverlay returns a legacy pattern overlay.

Deprecated: PatternOverlay is no longer used by D2 and will be removed after one compatibility release. There is no replacement.

func (*PatternOverlay) Render deprecated

func (o *PatternOverlay) Render() (string, error)

Render renders the legacy pattern overlay.

Deprecated: PatternOverlay is no longer used by D2 and will be removed after one compatibility release. There is no replacement.

type SpecialRules

type SpecialRules struct {
	Mono                       bool `json:"mono"`
	NoCornerRadius             bool `json:"noCornerRadius"`
	OuterContainerDoubleBorder bool `json:"outerContainerDoubleBorder"`
	ContainerDots              bool `json:"containerDots"`
	CapsLock                   bool `json:"capsLock"`
	C4                         bool `json:"c4"`

	AllPaper bool `json:"allPaper"`
}

type ThemableElement

type ThemableElement struct {
	X      float64
	X1     float64
	X2     float64
	Y      float64
	Y1     float64
	Y2     float64
	Width  float64
	Height float64
	R      float64
	Rx     float64
	Ry     float64
	Cx     float64
	Cy     float64

	D         string
	Points    string
	Transform string
	Href      string
	Xmlns     string

	Fill            string
	Stroke          string
	StrokeDashArray string
	BackgroundColor string
	Color           string

	ClassName string
	Style     string
	// Mask is retained for source compatibility and must be a local IRI in the
	// form url(#id). Deprecated: use SetMaskID.
	Mask string
	// ClipPath is retained for source compatibility and must contain a local
	// identifier. Deprecated: use SetClipPathID.
	ClipPath string
	// Attributes is retained for source compatibility. Values are parsed and
	// re-serialized through lib/svg; malformed or event attributes panic.
	// Deprecated: use AddAttributes.
	Attributes string

	// Content is retained as a trusted-markup compatibility escape hatch.
	// Deprecated: use SetText or SetInnerSVG.
	Content string

	FillPattern string
	// contains filtered or unexported fields
}

ThemableElement is a helper class for creating new XML elements. This should be preferred over formatting and must be used whenever Fill, Stroke, BackgroundColor or Color contains a color from a theme. i.e. N[1-7] | B[1-6] | AA[245] | AB[45]

func NewThemableElement

func NewThemableElement(tag string, inlineTheme *Theme) *ThemableElement

func (*ThemableElement) AddAttributes added in v0.10.0

func (el *ThemableElement) AddAttributes(attributes ...svg.Attribute)

func (*ThemableElement) Copy

func (el *ThemableElement) Copy() *ThemableElement

func (*ThemableElement) Render

func (el *ThemableElement) Render() string

func (*ThemableElement) RenderWithClasses added in v0.10.0

func (el *ThemableElement) RenderWithClasses(visit func(string)) string

RenderWithClasses also reports the classes generated for this element and its fill-pattern overlay. It does not inspect trusted inner SVG.

func (*ThemableElement) SetClipPathID added in v0.10.0

func (el *ThemableElement) SetClipPathID(id svg.ID)

func (*ThemableElement) SetInnerSVG added in v0.10.0

func (el *ThemableElement) SetInnerSVG(content svg.Fragment)

func (*ThemableElement) SetMaskID added in v0.10.0

func (el *ThemableElement) SetMaskID(id svg.ID)

func (*ThemableElement) SetMaskUrl

func (el *ThemableElement) SetMaskUrl(id string)

SetMaskUrl is retained for source compatibility. Deprecated: use SetMaskID.

func (*ThemableElement) SetText added in v0.10.0

func (el *ThemableElement) SetText(text string)

func (*ThemableElement) SetTranslate

func (el *ThemableElement) SetTranslate(x, y float64)

type ThemableSketchOverlay

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

func NewThemableSketchOverlay

func NewThemableSketchOverlay(el *ThemableElement, fill string) *ThemableSketchOverlay

func (*ThemableSketchOverlay) Render

func (o *ThemableSketchOverlay) Render() (string, error)

TODO we can just call el.Copy() to prevent that WARNING: Do not reuse the element afterwards as this function changes the Class property

type Theme

type Theme struct {
	ID     int64        `json:"id"`
	Name   string       `json:"name"`
	Colors ColorPalette `json:"colors"`

	SpecialRules SpecialRules `json:"specialRules,omitempty"`
}

func (*Theme) ApplyOverrides

func (t *Theme) ApplyOverrides(overrides *d2target.ThemeOverrides)

func (*Theme) IsDark

func (t *Theme) IsDark() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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