designsystem

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: 11 Imported by: 0

Documentation

Overview

Package designsystem loads a design system: D2 style files (layer 2) plus the render settings and SVG decorators it needs (layer 3). Design systems form a chain through "extends"; every chain ends at "plain".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Names

func Names() []string

Names lists the bundled design systems.

Types

type DesignSystem

type DesignSystem struct {
	Name string
	// contains filtered or unexported fields
}

DesignSystem is a resolved chain of manifests, base first.

func Load

func Load(name string) (*DesignSystem, error)

Load resolves a bundled design system and its parents.

func (*DesignSystem) Decorators

func (ds *DesignSystem) Decorators() ([]post.Decorator, error)

Decorators returns the SVG decorators of the whole chain, base first, with their icon files loaded.

func (*DesignSystem) Font

func (ds *DesignSystem) Font() (*d2fonts.FontFamily, error)

Font returns the chain's font family, or nil when no design system bundles fonts. The most specific design system wins per style.

D2 draws node labels in its bold style, so a design system whose labels are semibold (IBM Plex Sans) maps "bold" to the semibold file.

func (*DesignSystem) Prelude

func (ds *DesignSystem) Prelude(diagram, theme, layout string) (string, error)

Prelude returns the D2 that precedes a diagram's source: tokens, styles and d2-config, from the base design system to the most specific.

Every file's top-level vars are hoisted above all classes. D2 fails to resolve a spread variable that references other variables (...${carbon.node}, whose style uses ${color.x}) when it is merged into a class first defined before those variables were declared, which is exactly what extending a parent's classes does.

type Manifest

type Manifest struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	// Extends names the parent design system. Defaults to "plain".
	Extends string `json:"extends"`
	// Tokens maps a theme (light, dark) to a D2 file defining colour vars and
	// d2-config theme overrides.
	Tokens map[string]string `json:"tokens"`
	// Styles are D2 files loaded for every diagram type. diagrams/<type>.d2 is
	// loaded after them when present.
	Styles []string `json:"styles"`
	// Layout overrides the core's layout engine per diagram type.
	Layout map[string]string `json:"layout"`
	Pad    *int              `json:"pad"`
	// Fonts maps a d2 font flag (regular, italic, bold, semibold) to a .ttf file.
	Fonts      map[string]string `json:"fonts"`
	Decorators []post.Decorator  `json:"decorators"`
	// contains filtered or unexported fields
}

Manifest is a design system's manifest.json.

Jump to

Keyboard shortcuts

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