Code draft v0.1.1
The syntax highlighting colors of code, one per category, and the states of marked lines, readable on every surface in every mode.
Code samples, token paths and snippets are set in the mono family (Typography foundation); this foundation colors them. Each syntax category (keyword, variable, function, class and type, string, number, comment) has a semantic color from the Figma library's code colors, global.text.code; the design system adds colors for diffs, invalid code and links, and backgrounds for marked lines, all picked from colors it already has. Everything else in code (plain identifiers, operators, punctuation) keeps the primary on-base text color. A highlighter maps the categories of its grammars to these colors: on the web, a Shiki theme generated from the tokens does it once for every mode, and a style sheet draws the marked lines.
Specimens
The tokens this foundation is built from, drawn from packages/tokens/src/: raw primitives and the semantic decisions on top of them. A token added to one of these groups appears here with no site change; values that differ per mode or per platform are shown next to each other.
Syntax colors
One color per syntax category, and the additions for diffs, invalid code and links, with the palette step each aliases in every mode.
global.text.code.* · 12 tokens · Swatch, value and alias of each token in every mode, side by side.
| Token | light | dark |
|---|---|---|
global.text.code.keyword |
#7534A9{extended.lavender.700}
|
#B87BF5{extended.lavender.400}
|
global.text.code.variable |
#923D78{extended.orchid.700}
|
#F283CD{extended.orchid.400}
|
global.text.code.function |
#266280{extended.azure.700}
|
#5BB8E7{extended.azure.400}
|
global.text.code.class-and-typeDecision code-colors-contrast (Code foundation): the Figma library extended.amber.500 is 1.96:1 on global.bg.level.1.default, under the 4.5:1 of WCAG 1.4.3. |
#7F6426{extended.amber.700}
|
#EEB836{extended.amber.400}
|
global.text.code.stringDecision code-colors-contrast (Code foundation): the Figma library extended.forest.600 is 3.80:1 on global.bg.level.1.default. |
#18614E{extended.forest.700}
|
#68BBA1{extended.forest.400}
|
global.text.code.numberDecision code-colors-contrast (Code foundation): the Figma library extended.coral.500 is 3.21:1 on global.bg.level.1.default, coral 600 still 4.30:1. |
#9C4324{extended.coral.700}
|
#FD8C67{extended.coral.400}
|
global.text.code.comment |
#4C4A4A{light-switch.base.700}
|
#9D9B9C{dark-switch.base.300}
|
global.text.code.insertedLines a diff adds. The on-base success text step. |
#075D33{functional.success.700}
|
#11C772{functional.success.300}
|
global.text.code.deletedLines a diff removes. The step of error text on tinted fills: on-base error (error 500) is 4.26:1 on level 1. |
#C01619{functional.error.600}
|
#FAA79D{functional.error.200}
|
global.text.code.changedLines a context diff changes. The on-base severe text step. |
#764016{functional.severe.700}
|
#FE8400{functional.severe.300}
|
global.text.code.invalidCode a grammar marks invalid or deprecated. Same step as deleted. |
#C01619{functional.error.600}
|
#FAA79D{functional.error.200}
|
global.text.code.linkURLs and links in code and markup. The on-base brand text step. |
#175DD6{brand.light.600}
|
#9EE7FA{brand.dark.200}
|
Line backgrounds
Backgrounds of marked lines, aliasing the subtle fills.
global.bg.code.* · 5 tokens · Swatch, value and alias of each token in every mode, side by side.
| Token | light | dark |
|---|---|---|
global.bg.code.highlightedA line the author points out. |
#EEF1F7{global.bg.subtle.brand.default}
|
#09191D{global.bg.subtle.brand.default}
|
global.bg.code.insertedA line an example adds. |
#DBFAE6{global.bg.subtle.functional.success.default}
|
#011C16{global.bg.subtle.functional.success.default}
|
global.bg.code.deletedA line an example removes. |
#FEECEA{global.bg.subtle.functional.error.default}
|
#2B0B08{global.bg.subtle.functional.error.default}
|
global.bg.code.errorA line in error. |
#FEECEA{global.bg.subtle.functional.error.default}
|
#2B0B08{global.bg.subtle.functional.error.default}
|
global.bg.code.warningA line with a warning. |
#FFF1C7{global.bg.subtle.functional.warning.default}
|
#1F1504{global.bg.subtle.functional.warning.default}
|
Examples
Code samples from packages/components/specs/foundations/code/, highlighted with the design system's Shiki theme, generated from the tokens. A sample follows the page mode; set another mode context to compare, as in a component's playground.
/**
* Contrast between two colors, as WCAG defines it.
* Every category of the syntax shows here: keywords, variables,
* functions, classes, strings, numbers and comments.
*/
import { readFile } from 'node:fs/promises';
const HEX = /^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;
const MINIMUM = { text: 4.5, large: 3, ui: 3 };
export class Color {
#channels;
constructor(r, g, b, alpha = 1) {
this.#channels = [r, g, b].map((c) => Math.min(1, Math.max(0, c)));
this.alpha = alpha;
}
static fromHex(hex) {
const match = HEX.exec(hex.trim());
if (!match) throw new TypeError(`"${hex}" is not a six-digit hex color`);
const channels = match.slice(1).map((pair) => parseInt(pair, 16) / 255);
return new Color(...channels);
}
get luminance() {
const linear = (c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
const [r, g, b] = this.#channels.map(linear);
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
}
}
export function contrast(foreground, background) {
const [light, dark] = [foreground, background]
.map((color) => color.luminance)
.sort((a, b) => b - a);
return (light + 0.05) / (dark + 0.05);
}
export async function audit(file, { kind = 'text', signal } = {}) {
const text = await readFile(file, { encoding: 'utf8', signal });
const pairs = JSON.parse(text);
const failing = [];
for (const { fg, bg, name = 'unnamed' } of pairs) {
const ratio = contrast(Color.fromHex(fg), Color.fromHex(bg));
if (ratio < MINIMUM[kind]) {
failing.push({ name, ratio: Number(ratio.toFixed(2)) });
}
}
return failing.length === 0 ? null : failing;
}
/* A product page consuming the design system: its tokens, the component
styles the team implemented from the specs, semantic tokens for every
decision, literal lengths for its own layout only. */
@import url("@quantum-ds/tokens/css/index.css") layer(design-system);
@import url("./components.css") layer(design-system);
@layer product {
:root { --product-columns: 3; }
.product-grid {
display: grid;
grid-template-columns: repeat(var(--product-columns), minmax(0, 1fr));
gap: clamp(1rem, 2.5vw, 2rem);
}
.product-card {
position: relative;
padding: 1.25rem 1.5rem;
border: var(--stroke-width-sm) solid
var(--global-border-level-edge-level-1);
border-radius: var(--corner-radius-sm);
background: var(--global-bg-level-1-default);
color: var(--global-text-on-base-neutral-primary);
transition: border-color var(--duration-fast, 120ms)
var(--easing-standard);
}
.product-card:where(:hover, :focus-within) {
border-color: var(--global-border-level-edge-state-hover);
}
.product-card > h2::after {
content: " \2192";
color: color-mix(
in srgb, var(--global-text-on-base-neutral-tertiary) 80%, transparent
);
}
#featured.product-card:not(:has(img)) { grid-column: span 2; }
}
@media (max-width: 48em) {
:root { --product-columns: 1; }
#featured.product-card { grid-column: auto !important; }
}
<!doctype html>
<html lang="en" data-theme="auto">
<head>
<meta charset="utf-8">
<title>Dropdown · without script</title>
<link rel="stylesheet" href="node_modules/@quantum-ds/tokens/dist/css/index.css">
<!-- The component styles, implemented from the specs. -->
<link rel="stylesheet" href="css/components.css">
<style>
.stage { padding: 2rem; background: var(--global-bg-level-0-default); }
</style>
</head>
<body>
<main class="stage">
<!-- The trigger opens the menu natively: no script ships with it. -->
<div class="ds-dropdown">
<button
type="button"
class="ds-button ds-dropdown__trigger"
data-emphasis="subtle"
id="actions-trigger"
popovertarget="actions"
>
<span class="ds-button__label">Actions</span>
<span class="ds-button__icon" aria-hidden="true">expand_more</span>
</button>
<div class="ds-dropdown__menu" id="actions" popover
aria-labelledby="actions-trigger">
<ul class="ds-dropdown__group">
<li>
<button type="button" class="ds-dropdown__item"
popovertarget="actions" popovertargetaction="hide">
Duplicate
</button>
</li>
<li>
<button type="button" class="ds-dropdown__item"
data-intent="error" disabled>Delete project</button>
</li>
</ul>
</div>
</div>
</main>
<script type="module">
// The page, not the component, remembers the mode the reader picked.
const saved = localStorage.getItem('theme');
const modes = ['light', 'dark', 'auto'];
if (modes.includes(saved)) document.documentElement.dataset.theme = saved;
</script>
</body>
</html>
{
"$description": "Code colors, light mode (the Figma library's Colors / Mapped).",
"global": {
"text": {
"code": {
"$type": "color",
"keyword": { "$value": "{extended.lavender.700}" },
"string": {
"$value": {
"colorSpace": "srgb",
"components": [0.0943, 0.3804, 0.3059],
"alpha": 1,
"hex": "#18614e"
},
"$extensions": {
"io.quantum": { "deprecated": false, "since": "0.1.0", "aliases": null }
}
}
}
}
},
"size": {
"$type": "dimension",
"control": { "md": { "$value": { "value": 40, "unit": "px" } } }
}
}
#!/usr/bin/env bash
# Check the design system, then tag a release of the tokens.
set -euo pipefail
readonly VERSION="${1:?usage: release.sh <version>}"
readonly OUT_DIR="${OUT_DIR:-build}"
declare -i attempts=0
log() { printf '[%s] %s\n' "$(date +%H:%M:%S)" "$*" >&2; }
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
log "not a semantic version: $VERSION"
exit 64
fi
until pnpm check > "$OUT_DIR/check.log" 2>&1; do
attempts+=1
(( attempts >= 3 )) && { log "pnpm check failed $attempts times"; exit 1; }
sleep $(( attempts * 2 ))
done
for file in platforms/*/*.tokens.json; do
case "$file" in
*dark*) mode=dark ;;
*) mode=light ;;
esac
cp "$file" "$OUT_DIR/$(basename "$(dirname "$file")")-$mode.json"
done
git tag --annotate "tokens-v$VERSION" --message "Tokens $VERSION" \
&& log "tagged tokens-v$VERSION"
# Continuous integration: check the artifacts on every merge request.
stages: [check, build]
variables:
NODE_VERSION: "22"
PNPM_HOME: /cache/pnpm
CI_DEBUG: false
.pnpm: &pnpm
image: node:${NODE_VERSION}-slim
before_script:
- corepack enable
- pnpm install --frozen-lockfile
cache:
key: { files: [pnpm-lock.yaml] }
paths: [.pnpm-store/]
check:
<<: *pnpm
stage: check
script:
- pnpm check
- pnpm impact --base "origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
site:
<<: *pnpm
stage: build
needs: [check]
script: pnpm build
artifacts:
expire_in: 1 week
paths:
- apps/docs/dist/
retry: 2
timeout: 15m
// Marked lines: highlighted, added, removed, an error and a warning.
import { createHighlighter } from 'shiki';
import theme from './web/shiki-theme.json' with { type: 'json' };
const highlighter = await createHighlighter({
themes: ['github-light', 'github-dark'],
themes: [theme],
langs: ['css', 'html', 'javascript'],
});
export function render(source, lang) {
return highlighter.codeToHtml(source, { lang, theme: theme.name });
}
render('a { color: red }', 'scss');
render('<p>Hello</p>');
*** tokens/semantic/colors-mapped.tokens.json 2026-10-02 10:12:04
--- tokens/semantic/colors-mapped.tokens.json 2026-10-02 15:47:31
***************
*** 566,572 ****
"keyword": {"$type":"color","$value":"{extended.lavender.700}"},
"variable": {"$type":"color","$value":"{extended.orchid.700}"},
"function": {"$type":"color","$value":"{extended.azure.700}"},
! "class-and-type": {"$type":"color","$value":"{extended.amber.500}"},
! "string": {"$type":"color","$value":"{extended.forest.600}"},
"comment": {"$type":"color","$value":"{light-switch.base.700}"}
},
--- 566,573 ----
"keyword": {"$type":"color","$value":"{extended.lavender.700}"},
"variable": {"$type":"color","$value":"{extended.orchid.700}"},
"function": {"$type":"color","$value":"{extended.azure.700}"},
! "class-and-type": {"$type":"color","$value":"{extended.amber.700}"},
! "string": {"$type":"color","$value":"{extended.forest.700}"},
+ "number": {"$type":"color","$value":"{extended.coral.700}"},
"comment": {"$type":"color","$value":"{light-switch.base.700}"}
},
***************
*** 601,604 ****
- "skeleton": {"$type":"color","$value":"{light-switch.base.300}"},
"disabled": {"$type":"color","$value":"{light-switch.base.500}"}
--- 602,604 ----
# Code colors
> Syntax highlighting is an aid: the code reads the same **without** it.
Load the theme, then highlight with _any_ grammar:
- the theme lives in `web/shiki-theme.json`
- its colors are CSS variables, see [the Shiki docs](https://shiki.style/guide/load-theme)
- line states come from `web/foundations/code.css`
```js
import theme from './web/shiki-theme.json' with { type: 'json' };
const html = highlighter.codeToHtml(source, { lang: 'css', theme: theme.name });
```
{
"global": {
"text": {
"code": {
"keyword": { "$value": "{extended.lavender.700}" }
"variable": { "$value": "{extended.orchid.700}" },
comment: { "$value": "{light-switch.base.700}" }
}
}
}
}