Themes Implementation in Vanilla-Diagram

Stylesheets

The same API shape as the Gantt's: the theme and theme-css-path attributes, SUPPORTED_THEMES (the fourteen below, in the grid's order: default, default-dark, material, material-dark, fiori, fiori-dark, carbon, carbon-dark, glow, glow-dark, fluent, fluent-dark, apple, apple-dark), getSupportedThemes() and registerTheme(name, cssPath). An unknown name falls back to default; getThemeHref(name) returns the file a name resolves to (registered, built in, else the default's). A theme file styles the diagram, the palette and <vn-diagram-toolbar>. The palette's own theme attribute picks one independently of the diagram's, since it may draw before any diagram is linked; the toolbar follows the linked diagram's theme unless its own theme names one, and loads it through getThemeHref(). Themes are page-global, with the caveat the grid and the Gantt document: two elements with different themes on one page both take the last-loaded theme's tokens.

Built-in themes

The grid's seven theme families, each light and dark, with the grid's canvas, text and line colours, accent, corners and font. The grid's Ledger theme has no diagram twin built in; process-flowchart-js registers one of its own (A custom theme).

Theme Look
default, default-dark The grid's and the Gantt's Default: the purple accent (#667eea) on shapes and ports, rounded corners, the system font
material, material-dark The grid's Material, in Google's product palette: Grey 900 (#202124) text, #80868b outlines on #f8f9fa shapes, Blue 600 (#1a73e8, Blue 300 #8ab4f8 on the #292a2d dark canvas) for the selection and ports, 8px corners, Roboto
fiori, fiori-dark The grid's Fiori, after SAP's Quartz Light and Quartz Dark: #89919a field borders on #f7f7f7 shapes (#8696a9 on #29313a, over a #1c2228 canvas), Fiori Blue (#0a6ed1, #91c8f6 on dark) for the selection and ports, the Quartz focus colour (black, white on dark), square corners, the 72 font
carbon, carbon-dark The grid's Carbon and Carbon Dark, after IBM Carbon's White and Gray 100 themes: neutral shapes (#8d8d8d outlines), IBM Blue for the selection, ports and pressed tiles (#0f62fe, Blue 40 #78a9ff on dark), square corners, IBM Plex Sans
glow, glow-dark The grid's Glow, in the Tailwind palette: neutral grey shapes (#6b7280 outlines; #171717 shapes on a #0a0a0a canvas), the indigo accent (#6366f1, #818cf8 on dark) for the selection and ports, pink snap guides, 12px corners, Inter
fluent, fluent-dark The grid's Fluent, after the Fluent 2 web light and dark themes: the accessible neutral stroke (#616161, #adadad on dark) on #fafafa shapes (#292929 on a #1f1f1f canvas), communication blue (#0f6cbd, #479ef5 on dark) for the selection and ports, the Fluent focus stroke (black, white on dark), 4px corners, Segoe UI
apple, apple-dark The grid's Apple, in Apple's system colours: systemGray (#8e8e93) outlines on grouped-background (#f2f2f7) shapes (#2c2c2e on a #1c1c1e canvas), systemBlue (#007aff, #0a84ff on dark) for the selection and ports, systemOrange snap guides, 10px corners, SF Pro

Every theme keeps the focus ring apart from the selection it is drawn beside, in the text colour or the design system's own focus colour (Carbon: Gray 100 #161616 on the light canvas, white on the dark one). The themes name the design system's font first in --vn-diagram-node-font ('Roboto', '72', 'IBM Plex Sans', 'Inter', 'Segoe UI Variable', -apple-system and 'SF Pro Text') and, like the grid's, load no font file: a page that wants the font loads it (a @font-face or a font service), and without it the text falls back to the next family in the list (Helvetica Neue, Helvetica, Arial or the system font).

A custom theme

A theme of the host's own is a stylesheet that defines every token below (the 30 slot tokens and the toolbar's five included) on the same four selectors, .vn-diagram, .vn-diagram-palette, .vn-diagram-palette-ghost and .vn-diagram-toolbar, and frames the three elements as the built-in files do. VanillaDiagramElement.registerTheme(name, cssPath) names it; the diagram, the palette and the toolbar resolve a theme name through getThemeHref(), so one registration styles all three, and cssPath is used as given (a relative path resolves against the page). Register before an element first takes the name.

process-flowchart-js does this for ledger, the grid's Ledger look: themes/vn-diagram-ledger.css in the app's folder (manila shapes on warm paper, dark ink, the ruling blue as the grid's dots, the red margin line as the snap guides, oxblood for the selection and ports, serif type, index-card tints for the slots), registered by app.js, which also swaps in a page-chrome theme of its own, themes/app-ledger.css.

Tokens

Token Paints
--vn-diagram-bg The canvas
--vn-diagram-node-fill, --vn-diagram-node-stroke, --vn-diagram-node-stroke-width Node shapes, and the palette's tiles
--vn-diagram-node-text-color, --vn-diagram-node-font Node text (the font also the palette's and the message's)
--vn-diagram-connector-color, --vn-diagram-connector-width Connectors and their arrowheads, the palette's connector icons
--vn-diagram-port-fill, --vn-diagram-port-stroke, --vn-diagram-port-active-fill Ports; a target, armed or hovered port
--vn-diagram-selection-color Selection outlines, a selected connector and its arrowhead, handles' outline, the rotation handle's stem and arrow, the rubber band's and the drop outline's edge, the connect preview, the joining outline
--vn-diagram-handle-fill Resize, rotation and end handles
--vn-diagram-rubber-band-bg The rubber band and the drop outline
--vn-diagram-focus-ring The focus ring, the canvas's and the tiles' focus outline
--vn-diagram-message-color The load error, and the busy overlay's label and spinner
--vn-diagram-busy-scrim, --vn-diagram-busy-bg The busy overlay's scrim over the canvas, and its box (01-web-component ยง The busy state)
--vn-diagram-palette-bg, --vn-diagram-palette-heading-color The palette and its group headings
--vn-diagram-palette-tile-bg, --vn-diagram-palette-tile-hover-bg, --vn-diagram-palette-tile-pressed-bg Tiles at rest, hovered, pressed (and the current connector kind); the toolbar's buttons likewise
--vn-diagram-grid-color The grid's dots
--vn-diagram-guide-color The snap guides
--vn-diagram-group-fill, --vn-diagram-group-stroke A container's frame (the basic set's group, a host's container symbol), in place of the node fill and stroke; its swatch and style still win
--vn-diagram-error-color The toolbar's status text at severity error (Carbon: Red 60 on light, Red 40 on dark)
--vn-diagram-swatch-<slot>-fill, -stroke, -text Each colour slot, col1 to col10 (30 tokens)

The toolbar paints with the palette's tokens (its background, its buttons and its colour menu, the heading colour for its icons) and the node text colour for its status text. Connector labels sit on --vn-diagram-bg and use the node text colour.

tests/node/diagram-theme-set.test.js checks that every theme defines every token, the 30 slot tokens and the toolbar's five variant tokens, puts the toolbar in its token selector, that the base stylesheet maps each built-in slot, that the component README lists exactly these (the slots by their pattern) and the toolbar's README its five, and that every token the diagram's and the toolbar's base stylesheets read is defined by every theme.

The toolbar's variant tokens. --vn-diagram-toolbar-primary-bg and -primary-color (a primary button: the theme's accent, #667eea in Default, #0f62fe in Carbon, or the deeper fill the grid's filter Apply button takes where white text needs it: #4f46e5 in Glow, #0071e3 in both Apple themes, #1178ce in Fiori Dark, #115ea3 in Fluent Dark), --vn-diagram-toolbar-danger-bg and -danger-color (a danger button: the theme's error red) and --vn-diagram-toolbar-border (a secondary button's outline).

A node's own colours. A node's style (fill, stroke, strokeWidth, textColor) sets --vn-diagram-node-fill, --vn-diagram-node-stroke, --vn-diagram-node-stroke-width and --vn-diagram-node-text-color on its group, so it wins over the theme by inheritance, whatever order the stylesheets load in.

Colour slots

Ten built-in slots, col1 to col10 (VanillaDiagramElement.SUPPORTED_SWATCHES), are generic, as an office document's theme colours are: the data names a slot, the theme picks the colour. A node takes one by name (swatch: 'col3'), a palette gives each of its shapes one (its swatches map, 07-symbols-and-palette), and the toolbar's colour menu sets one on the selection (Diagram Toolbar).

Each slot's fill / stroke / text, per built-in theme:

Slot default default-dark
col1 #e0e7ff / #4f46e5 / #1e1b4b #312e81 / #a5b4fc / #e0e7ff
col2 #e0f2fe / #0284c7 / #0c4a6e #0c4a6e / #7dd3fc / #e0f2fe
col3 #ccfbf1 / #0d9488 / #134e4a #134e4a / #5eead4 / #ccfbf1
col4 #dcfce7 / #16a34a / #14532d #14532d / #86efac / #dcfce7
col5 #fef9c3 / #ca8a04 / #713f12 #713f12 / #fde047 / #fef9c3
col6 #ffedd5 / #ea580c / #7c2d12 #7c2d12 / #fdba74 / #ffedd5
col7 #fee2e2 / #dc2626 / #7f1d1d #7f1d1d / #fca5a5 / #fee2e2
col8 #fce7f3 / #db2777 / #831843 #831843 / #f9a8d4 / #fce7f3
col9 #f3e8ff / #9333ea / #581c87 #581c87 / #d8b4fe / #f3e8ff
col10 #e2e8f0 / #475569 / #0f172a #334155 / #cbd5e1 / #f1f5f9
Slot material material-dark
col1 #e8eaf6 / #303f9f / #1a237e #1a237e / #9fa8da / #e8eaf6
col2 #e3f2fd / #1976d2 / #0d47a1 #0d47a1 / #90caf9 / #e3f2fd
col3 #e0f2f1 / #00796b / #004d40 #004d40 / #80cbc4 / #e0f2f1
col4 #e8f5e9 / #388e3c / #1b5e20 #1b5e20 / #a5d6a7 / #e8f5e9
col5 #fff8e1 / #ffa000 / #3e2723 #4e342e / #ffe082 / #fff8e1
col6 #fbe9e7 / #e64a19 / #bf360c #bf360c / #ffab91 / #fbe9e7
col7 #ffebee / #d32f2f / #b71c1c #b71c1c / #ef9a9a / #ffebee
col8 #fce4ec / #c2185b / #880e4f #880e4f / #f48fb1 / #fce4ec
col9 #f3e5f5 / #7b1fa2 / #4a148c #4a148c / #ce93d8 / #f3e5f5
col10 #eceff1 / #455a64 / #263238 #263238 / #b0bec5 / #eceff1
Slot fiori fiori-dark
col1 #438cd5 / #438cd5 / #000000 #5899da / #5899da / #000000
col2 #e66729 / #e66729 / #000000 #e66729 / #e66729 / #000000
col3 #16976c / #16976c / #000000 #16976c / #16976c / #000000
col4 #ed4a7b / #ed4a7b / #000000 #ed4a7b / #ed4a7b / #000000
col5 #945ecf / #945ecf / #000000 #945ecf / #945ecf / #000000
col6 #1193a2 / #1193a2 / #000000 #1193a2 / #1193a2 / #000000
col7 #525df4 / #525df4 / #ffffff #525df4 / #525df4 / #ffffff
col8 #bf399e / #bf399e / #ffffff #bf399e / #bf399e / #ffffff
col9 #6c8893 / #6c8893 / #000000 #6c8893 / #6c8893 / #000000
col10 #ed5f5f / #ed5f5f / #000000 #ed5f5f / #ed5f5f / #000000
Slot carbon carbon-dark
col1 #6929c4 / #6929c4 / #ffffff #8a3ffc / #8a3ffc / #ffffff
col2 #1192e8 / #1192e8 / #161616 #33b1ff / #33b1ff / #161616
col3 #005d5d / #005d5d / #ffffff #007d79 / #007d79 / #ffffff
col4 #9f1853 / #9f1853 / #ffffff #ff7eb6 / #ff7eb6 / #161616
col5 #fa4d56 / #fa4d56 / #161616 #fa4d56 / #fa4d56 / #161616
col6 #520408 / #520408 / #ffffff #fff1f1 / #fff1f1 / #161616
col7 #198038 / #198038 / #ffffff #6fdc8c / #6fdc8c / #161616
col8 #002d9c / #002d9c / #ffffff #4589ff / #4589ff / #161616
col9 #ee5396 / #ee5396 / #161616 #d02670 / #d02670 / #ffffff
col10 #b28600 / #b28600 / #161616 #d2a106 / #d2a106 / #161616
Slot glow glow-dark
col1 #4f46e5 / #4f46e5 / #ffffff #1e1b4b / #818cf8 / #c7d2fe
col2 #0ea5e9 / #0ea5e9 / #111827 #082f49 / #38bdf8 / #bae6fd
col3 #14b8a6 / #14b8a6 / #111827 #042f2e / #2dd4bf / #99f6e4
col4 #10b981 / #10b981 / #111827 #022c22 / #34d399 / #a7f3d0
col5 #f59e0b / #f59e0b / #111827 #451a03 / #fbbf24 / #fde68a
col6 #f97316 / #f97316 / #111827 #431407 / #fb923c / #fed7aa
col7 #f43f5e / #f43f5e / #111827 #4c0519 / #fb7185 / #fecdd3
col8 #ec4899 / #ec4899 / #111827 #500724 / #f472b6 / #fbcfe8
col9 #7c3aed / #7c3aed / #ffffff #2e1065 / #a78bfa / #ddd6fe
col10 #64748b / #64748b / #ffffff #020617 / #94a3b8 / #e2e8f0
Slot fluent fluent-dark
col1 #c8d1fa / #4f6bed / #2c3c85 #2c3c85 / #93a4f4 / #c8d1fa
col2 #a9d3f2 / #0078d4 / #004377 #004377 / #5caae5 / #a9d3f2
col3 #9bd9db / #038387 / #02494c #02494c / #4cb4b7 / #9bd9db
col4 #9fd89f / #107c10 / #094509 #094509 / #54b054 / #9fd89f
col5 #f9e2ae / #eaa300 / #835b00 #835b00 / #f2c661 / #f9e2ae
col6 #f4bfab / #da3b01 / #7a2101 #7a2101 / #e9835e / #f4bfab
col7 #f1bbbc / #d13438 / #751d1f #751d1f / #e37d80 / #f1bbbc
col8 #f7c0e3 / #e43ba6 / #80215d #80215d / #ef85c8 / #f7c0e3
col9 #c6b1de / #5c2e91 / #341a51 #341a51 / #9470bd / #c6b1de
col10 #94c8d4 / #005b70 / #00333f #00333f / #4496a9 / #94c8d4
Slot apple apple-dark
col1 #e1e1f8 / #3634a3 / #1c1c1e #2e2e56 / #5e5ce6 / #ffffff
col2 #d1e7ff / #0040dd / #1c1c1e #17395d / #0a84ff / #ffffff
col3 #daf1f5 / #008299 / #1c1c1e #264c54 / #40c8e0 / #ffffff
col4 #daf5e1 / #248a3d / #1c1c1e #224f2e / #30d158 / #ffffff
col5 #fff6d1 / #b25000 / #1c1c1e #5c5018 / #ffd60a / #ffffff
col6 #ffecd1 / #c93400 / #1c1c1e #5c4118 / #ff9f0a / #ffffff
col7 #ffdcda / #d70015 / #1c1c1e #5c2726 / #ff453a / #ffffff
col8 #ffd9e0 / #d30f45 / #1c1c1e #5c2430 / #ff375f / #ffffff
col9 #f1e0f9 / #8944ab / #1c1c1e #4a2d59 / #bf5af2 / #ffffff
col10 #ebebec / #6c6c70 / #1c1c1e #3c3c3f / #8e8e93 / #ffffff

The toolbar's look

The toolbar's base stylesheet, vanilla-diagram-toolbar.css, is in its own component; its colours are the tokens above. Its ghost buttons (the default) are 30px high on --vn-diagram-palette-tile-bg, hovered and pressed as the palette's tiles, with 16px stroked icons in --vn-diagram-palette-heading-color; secondary, primary and danger take the variant tokens. The status text at its left is in the node font and text colour. The colour button and each row of the colour menu show a 16px colour box in the slot's fill and stroke ("No colour" the theme's struck through); the menu has the palette's background, a tile-pressed border and a shadow, its checked row the pressed background. Each theme frames the toolbar as it frames the palette, and the menu takes the frame's corners.

Forced colours

A @media (forced-colors: active) block paints shapes with Canvas and CanvasText, container frames with CanvasText and no fill, connectors and their arrowheads with CanvasText, and the selection, ports, handles (the rotation handle, its stem and its arrow included), the joining outline, the rubber band and focus with Highlight. The explicit rules drop a node's own colours and its swatch (they paint the shape through the tokens the rules no longer read) and make it not matter whether forced colours adjusts SVG fill and stroke by itself. The HTML text, the editor and the connector labels follow forced colours (labels on Canvas); the busy overlay drops its scrim and draws its box on Canvas with a CanvasText border, the spinner and label in CanvasText; the grid's dots are GrayText, the guides and route tangents Highlight. The toolbar's stylesheet has its own block: its buttons use ButtonFace and ButtonText (primary and danger with a 2px border), a pressed or focused one Highlight, its status text CanvasText, its colour menu Canvas with the checked row in Highlight, and its colour boxes lose their colours.