design
Palette
Color swatch grid with optional WCAG contrast and accessibility info
Install
- Add the package:
npm install @refrakt-md/design - Add it to the
pluginsarray inrefrakt.config.json:"plugins": ["@refrakt-md/design"]
Source
import Markdoc from '@markdoc/markdoc';
import type { Node } from '@markdoc/markdoc';
const { Tag } = Markdoc;
import {
createContentModelSchema,
bodyOnly,
createComponentRenderable,
asNodes,
extractText,
groupByHeading,
} from '@refrakt-md/runes';
function parseColorEntry(text: string): { name: string; values: string[] } | null {
const colonIndex = text.indexOf(':');
if (colonIndex === -1) return null;
const name = text.slice(0, colonIndex).trim();
const valueStr = text.slice(colonIndex + 1).trim();
const values = valueStr
.split(',')
.map((v) => v.trim())
.filter(Boolean);
return { name, values };
}
function hexToRgb(hex: string): [number, number, number] | null {
const clean = hex.replace('#', '');
if (clean.length !== 6 && clean.length !== 3) return null;
const full =
clean.length === 3
? clean
.split('')
.map((c) => c + c)
.join('')
: clean;
const num = parseInt(full, 16);
return [(num >> 16) & 255, (num >> 8) & 255, num & 255];
}
function relativeLuminance(r: number, g: number, b: number): number {
const [rs, gs, bs] = [r, g, b].map((c) => {
const s = c / 255;
return s <= 0.03928 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4);
});
return 0.2126 * rs + 0.7152 * gs + 0.0722 * bs;
}
function contrastRatio(hex: string, bgHex: string): number {
const rgb1 = hexToRgb(hex);
const rgb2 = hexToRgb(bgHex);
if (!rgb1 || !rgb2) return 0;
const l1 = relativeLuminance(...rgb1);
const l2 = relativeLuminance(...rgb2);
const lighter = Math.max(l1, l2);
const darker = Math.min(l1, l2);
return (lighter + 0.05) / (darker + 0.05);
}
function textColorFor(hex: string): string {
const rgb = hexToRgb(hex);
if (!rgb) return '#000';
const lum = relativeLuminance(...rgb);
return lum > 0.179 ? '#000' : '#fff';
}
function autoColumns(count: number, columns?: number): number {
if (columns != null && columns > 0) return columns;
if (count <= 3) return count;
if (count <= 6) return 3;
if (count <= 8) return 4;
return 5;
}
interface ColorEntry {
name: string;
values: string[];
group: string;
}
interface ColorGroup {
title: string;
entries: ColorEntry[];
}
export const paletteSections = { title: 'title' } as const;
export const palette = createContentModelSchema({
sections: paletteSections,
attributes: {
title: {
type: String,
required: false,
default: '',
description: 'Heading displayed above the palette section.',
},
showContrast: {
type: Boolean,
required: false,
default: false,
description: 'Enable/disable WCAG contrast ratio values against white and black.',
},
showA11y: {
type: Boolean,
required: false,
default: false,
description: 'Enable/disable AA/AAA accessibility compliance badges per swatch.',
},
columns: {
type: Number,
required: false,
description: 'Number of swatch columns in the grid; auto-calculated from count when omitted.',
},
},
contentModel: bodyOnly(),
transform(resolved, attrs) {
const children = asNodes(resolved.body) as Node[];
const groups: ColorGroup[] = [{ title: '', entries: [] }];
groupByHeading(children, {
initial: groups[0],
heading(heading) {
const group: ColorGroup = { title: extractText(heading), entries: [] };
groups.push(group);
return group;
},
item(item, group) {
const entry = parseColorEntry(extractText(item));
if (entry)
group.entries.push({ name: entry.name, values: entry.values, group: group.title });
},
});
const activeGroups = groups.filter((g) => g.entries.length > 0);
const titleMeta = new Tag('meta', { content: attrs.title });
const showContrastMeta = new Tag('meta', { content: String(attrs.showContrast) });
const showA11yMeta = new Tag('meta', { content: String(attrs.showA11y) });
const columnsMeta = new Tag('meta', {
content: attrs.columns != null ? String(attrs.columns) : '',
});
const groupTags: InstanceType<typeof Tag>[] = [];
for (const group of activeGroups) {
const groupChildren: (string | InstanceType<typeof Tag>)[] = [];
if (group.title) {
groupChildren.push(new Tag('h4', { 'data-name': 'group-title' }, [group.title]));
}
const singles = group.entries.filter((e) => e.values.length <= 1);
const scales = group.entries.filter((e) => e.values.length > 1);
if (singles.length > 0) {
const cols = autoColumns(singles.length, attrs.columns as number | undefined);
const swatchTags = singles.map((entry) => {
const color = entry.values[0] || '';
const swatchChildren: (string | InstanceType<typeof Tag>)[] = [
new Tag(
'div',
{ 'data-name': 'swatch-color', style: `background-color: ${color}` },
[],
),
new Tag('span', { 'data-name': 'swatch-name' }, [entry.name]),
new Tag('span', { 'data-name': 'swatch-value' }, [color]),
];
if (attrs.showContrast || attrs.showA11y) {
const onWhite = contrastRatio(color, '#FFFFFF');
const onBlack = contrastRatio(color, '#000000');
if (attrs.showContrast) {
swatchChildren.push(
new Tag('span', { 'data-name': 'swatch-contrast' }, [
`W: ${onWhite.toFixed(1)} \u00b7 B: ${onBlack.toFixed(1)}`,
]),
);
}
if (attrs.showA11y) {
const aaPass = onWhite >= 4.5;
const aaaPass = onWhite >= 7;
swatchChildren.push(
new Tag('span', { 'data-name': 'swatch-a11y' }, [
new Tag(
'span',
{ 'data-name': aaPass ? 'swatch-a11y--pass' : 'swatch-a11y--fail' },
[`AA ${aaPass ? '\u2713' : '\u2717'}`],
),
new Tag(
'span',
{ 'data-name': aaaPass ? 'swatch-a11y--pass' : 'swatch-a11y--fail' },
[`AAA ${aaaPass ? '\u2713' : '\u2717'}`],
),
]),
);
}
}
return new Tag('div', { 'data-name': 'swatch' }, swatchChildren);
});
groupChildren.push(
new Tag('div', { 'data-name': 'grid', style: `--rf-palette-cols: ${cols}` }, swatchTags),
);
}
for (const entry of scales) {
const stops = entry.values.map(
(value) =>
new Tag(
'div',
{
'data-name': 'scale-stop',
style: `background-color: ${value}; color: ${textColorFor(value)}`,
},
[value],
),
);
groupChildren.push(new Tag('div', { 'data-name': 'scale' }, stops));
groupChildren.push(new Tag('span', { 'data-name': 'swatch-name' }, [entry.name]));
}
groupTags.push(new Tag('div', { 'data-name': 'group' }, groupChildren));
}
const topChildren: (string | InstanceType<typeof Tag>)[] = [];
if (attrs.title) {
topChildren.push(new Tag('h3', { 'data-name': 'title' }, [attrs.title as string]));
}
topChildren.push(...groupTags);
return createComponentRenderable({
rune: 'palette',
tag: 'section',
properties: {
title: titleMeta,
showContrast: showContrastMeta,
showA11y: showA11yMeta,
columns: columnsMeta,
},
children: topChildren,
});
},
});
export function extractPaletteTokens(
node: Node,
): { name: string; value: string; group?: string }[] {
const tokens: { name: string; value: string; group?: string }[] = [];
groupByHeading(node.children, {
initial: '',
heading: (heading) => extractText(heading),
item(item, title) {
const entry = parseColorEntry(extractText(item));
if (!entry) return;
const group = title || undefined;
if (entry.values.length <= 1) {
tokens.push({ name: entry.name, value: entry.values[0] || '', group });
} else {
for (const v of entry.values) tokens.push({ name: entry.name, value: v, group });
}
},
});
return tokens;
}
Displays a grid of color swatches: a brand palette, a set of semantic colors, a neutral scale. To show a single color inside a sentence, use swatch.
Basic usage
A simple color palette grid.
{% palette title="Brand Colors" %}
- Blue: #2563EB
- Indigo: #4F46E5
- Purple: #7C3AED
- Pink: #EC4899
- Red: #EF4444
- Orange: #F97316
{% /palette %}<section data-rune="palette" data-rune-fields="{"title":"Brand Colors","showContrast":"false","showA11y":"false","columns":""}">
<h3 data-name="title">Brand Colors</h3>
<div data-name="group">
<div data-name="grid" style="--rf-palette-cols: 3">
<div data-name="swatch">
<div data-name="swatch-color" style="background-color: #2563EB"></div>
<span data-name="swatch-name">Blue</span>
<span data-name="swatch-value">#2563EB</span>
</div>
<div data-name="swatch">
<div data-name="swatch-color" style="background-color: #4F46E5"></div>
<span data-name="swatch-name">Indigo</span>
<span data-name="swatch-value">#4F46E5</span>
</div>
<div data-name="swatch">
<div data-name="swatch-color" style="background-color: #7C3AED"></div>
<span data-name="swatch-name">Purple</span>
<span data-name="swatch-value">#7C3AED</span>
</div>
<div data-name="swatch">
<div data-name="swatch-color" style="background-color: #EC4899"></div>
<span data-name="swatch-name">Pink</span>
<span data-name="swatch-value">#EC4899</span>
</div>
<div data-name="swatch">
<div data-name="swatch-color" style="background-color: #EF4444"></div>
<span data-name="swatch-name">Red</span>
<span data-name="swatch-value">#EF4444</span>
</div>
<div data-name="swatch">
<div data-name="swatch-color" style="background-color: #F97316"></div>
<span data-name="swatch-name">Orange</span>
<span data-name="swatch-value">#F97316</span>
</div>
</div>
</div>
</section>Brand Colors
<section class="rf-palette rf-palette--Brand Colors rf-palette--false rf-palette--false" data-title="Brand Colors" data-show-contrast="false" data-show-a11y="false" data-columns="" data-elevation="flat" data-rune="palette" data-density="full">
<h3 data-name="title" class="rf-palette__title" data-section="title">Brand Colors</h3>
<div data-name="group" class="rf-palette__group">
<div data-name="grid" style="--rf-palette-cols: 3" class="rf-palette__grid">
<div data-name="swatch" class="rf-palette__swatch">
<div data-name="swatch-color" style="background-color: #2563EB" class="rf-palette__swatch-color"></div>
<span data-name="swatch-name" class="rf-palette__swatch-name">Blue</span>
<span data-name="swatch-value" class="rf-palette__swatch-value">#2563EB</span>
</div>
<div data-name="swatch" class="rf-palette__swatch">
<div data-name="swatch-color" style="background-color: #4F46E5" class="rf-palette__swatch-color"></div>
<span data-name="swatch-name" class="rf-palette__swatch-name">Indigo</span>
<span data-name="swatch-value" class="rf-palette__swatch-value">#4F46E5</span>
</div>
<div data-name="swatch" class="rf-palette__swatch">
<div data-name="swatch-color" style="background-color: #7C3AED" class="rf-palette__swatch-color"></div>
<span data-name="swatch-name" class="rf-palette__swatch-name">Purple</span>
<span data-name="swatch-value" class="rf-palette__swatch-value">#7C3AED</span>
</div>
<div data-name="swatch" class="rf-palette__swatch">
<div data-name="swatch-color" style="background-color: #EC4899" class="rf-palette__swatch-color"></div>
<span data-name="swatch-name" class="rf-palette__swatch-name">Pink</span>
<span data-name="swatch-value" class="rf-palette__swatch-value">#EC4899</span>
</div>
<div data-name="swatch" class="rf-palette__swatch">
<div data-name="swatch-color" style="background-color: #EF4444" class="rf-palette__swatch-color"></div>
<span data-name="swatch-name" class="rf-palette__swatch-name">Red</span>
<span data-name="swatch-value" class="rf-palette__swatch-value">#EF4444</span>
</div>
<div data-name="swatch" class="rf-palette__swatch">
<div data-name="swatch-color" style="background-color: #F97316" class="rf-palette__swatch-color"></div>
<span data-name="swatch-name" class="rf-palette__swatch-name">Orange</span>
<span data-name="swatch-value" class="rf-palette__swatch-value">#F97316</span>
</div>
</div>
</div>
</section>How Markdown is read
| You write | It becomes |
|---|---|
A list item Name: #hex | A color swatch |
| A list item with several comma-separated values | A scale strip of those colors |
| A heading | Starts a group of colors; the heading is its title |
Grouped palette
Use ## headings to organize colors into groups.
{% palette title="Design System" %}
## Primary
- Blue: #2563EB
- Indigo: #4F46E5
## Semantic
- Success: #10B981
- Warning: #F59E0B
- Danger: #EF4444
{% /palette %}<section data-rune="palette" data-rune-fields="{"title":"Design System","showContrast":"false","showA11y":"false","columns":""}">
<h3 data-name="title">Design System</h3>
<div data-name="group">
<h4 data-name="group-title">Primary</h4>
<div data-name="grid" style="--rf-palette-cols: 2">
<div data-name="swatch">
<div data-name="swatch-color" style="background-color: #2563EB"></div>
<span data-name="swatch-name">Blue</span>
<span data-name="swatch-value">#2563EB</span>
</div>
<div data-name="swatch">
<div data-name="swatch-color" style="background-color: #4F46E5"></div>
<span data-name="swatch-name">Indigo</span>
<span data-name="swatch-value">#4F46E5</span>
</div>
</div>
</div>
<div data-name="group">
<h4 data-name="group-title">Semantic</h4>
<div data-name="grid" style="--rf-palette-cols: 3">
<div data-name="swatch">
<div data-name="swatch-color" style="background-color: #10B981"></div>
<span data-name="swatch-name">Success</span>
<span data-name="swatch-value">#10B981</span>
</div>
<div data-name="swatch">
<div data-name="swatch-color" style="background-color: #F59E0B"></div>
<span data-name="swatch-name">Warning</span>
<span data-name="swatch-value">#F59E0B</span>
</div>
<div data-name="swatch">
<div data-name="swatch-color" style="background-color: #EF4444"></div>
<span data-name="swatch-name">Danger</span>
<span data-name="swatch-value">#EF4444</span>
</div>
</div>
</div>
</section>Design System
Primary
Semantic
<section class="rf-palette rf-palette--Design System rf-palette--false rf-palette--false" data-title="Design System" data-show-contrast="false" data-show-a11y="false" data-columns="" data-elevation="flat" data-rune="palette" data-density="full">
<h3 data-name="title" class="rf-palette__title" data-section="title">Design System</h3>
<div data-name="group" class="rf-palette__group">
<h4 data-name="group-title" class="rf-palette__group-title">Primary</h4>
<div data-name="grid" style="--rf-palette-cols: 2" class="rf-palette__grid">
<div data-name="swatch" class="rf-palette__swatch">
<div data-name="swatch-color" style="background-color: #2563EB" class="rf-palette__swatch-color"></div>
<span data-name="swatch-name" class="rf-palette__swatch-name">Blue</span>
<span data-name="swatch-value" class="rf-palette__swatch-value">#2563EB</span>
</div>
<div data-name="swatch" class="rf-palette__swatch">
<div data-name="swatch-color" style="background-color: #4F46E5" class="rf-palette__swatch-color"></div>
<span data-name="swatch-name" class="rf-palette__swatch-name">Indigo</span>
<span data-name="swatch-value" class="rf-palette__swatch-value">#4F46E5</span>
</div>
</div>
</div>
<div data-name="group" class="rf-palette__group">
<h4 data-name="group-title" class="rf-palette__group-title">Semantic</h4>
<div data-name="grid" style="--rf-palette-cols: 3" class="rf-palette__grid">
<div data-name="swatch" class="rf-palette__swatch">
<div data-name="swatch-color" style="background-color: #10B981" class="rf-palette__swatch-color"></div>
<span data-name="swatch-name" class="rf-palette__swatch-name">Success</span>
<span data-name="swatch-value" class="rf-palette__swatch-value">#10B981</span>
</div>
<div data-name="swatch" class="rf-palette__swatch">
<div data-name="swatch-color" style="background-color: #F59E0B" class="rf-palette__swatch-color"></div>
<span data-name="swatch-name" class="rf-palette__swatch-name">Warning</span>
<span data-name="swatch-value" class="rf-palette__swatch-value">#F59E0B</span>
</div>
<div data-name="swatch" class="rf-palette__swatch">
<div data-name="swatch-color" style="background-color: #EF4444" class="rf-palette__swatch-color"></div>
<span data-name="swatch-name" class="rf-palette__swatch-name">Danger</span>
<span data-name="swatch-value" class="rf-palette__swatch-value">#EF4444</span>
</div>
</div>
</div>
</section>Neutral scale
Comma-separated values render as a horizontal gradient strip.
{% palette title="Gray Scale" %}
- Gray: #F9FAFB, #F3F4F6, #E5E7EB, #D1D5DB, #9CA3AF, #6B7280, #4B5563, #374151, #1F2937, #111827
{% /palette %}<section data-rune="palette" data-rune-fields="{"title":"Gray Scale","showContrast":"false","showA11y":"false","columns":""}">
<h3 data-name="title">Gray Scale</h3>
<div data-name="group">
<div data-name="scale">
<div data-name="scale-stop" style="background-color: #F9FAFB; color: #000">#F9FAFB</div>
<div data-name="scale-stop" style="background-color: #F3F4F6; color: #000">#F3F4F6</div>
<div data-name="scale-stop" style="background-color: #E5E7EB; color: #000">#E5E7EB</div>
<div data-name="scale-stop" style="background-color: #D1D5DB; color: #000">#D1D5DB</div>
<div data-name="scale-stop" style="background-color: #9CA3AF; color: #000">#9CA3AF</div>
<div data-name="scale-stop" style="background-color: #6B7280; color: #fff">#6B7280</div>
<div data-name="scale-stop" style="background-color: #4B5563; color: #fff">#4B5563</div>
<div data-name="scale-stop" style="background-color: #374151; color: #fff">#374151</div>
<div data-name="scale-stop" style="background-color: #1F2937; color: #fff">#1F2937</div>
<div data-name="scale-stop" style="background-color: #111827; color: #fff">#111827</div>
</div>
<span data-name="swatch-name">Gray</span>
</div>
</section>Gray Scale
<section class="rf-palette rf-palette--Gray Scale rf-palette--false rf-palette--false" data-title="Gray Scale" data-show-contrast="false" data-show-a11y="false" data-columns="" data-elevation="flat" data-rune="palette" data-density="full">
<h3 data-name="title" class="rf-palette__title" data-section="title">Gray Scale</h3>
<div data-name="group" class="rf-palette__group">
<div data-name="scale" class="rf-palette__scale">
<div data-name="scale-stop" style="background-color: #F9FAFB; color: #000" class="rf-palette__scale-stop">#F9FAFB</div>
<div data-name="scale-stop" style="background-color: #F3F4F6; color: #000" class="rf-palette__scale-stop">#F3F4F6</div>
<div data-name="scale-stop" style="background-color: #E5E7EB; color: #000" class="rf-palette__scale-stop">#E5E7EB</div>
<div data-name="scale-stop" style="background-color: #D1D5DB; color: #000" class="rf-palette__scale-stop">#D1D5DB</div>
<div data-name="scale-stop" style="background-color: #9CA3AF; color: #000" class="rf-palette__scale-stop">#9CA3AF</div>
<div data-name="scale-stop" style="background-color: #6B7280; color: #fff" class="rf-palette__scale-stop">#6B7280</div>
<div data-name="scale-stop" style="background-color: #4B5563; color: #fff" class="rf-palette__scale-stop">#4B5563</div>
<div data-name="scale-stop" style="background-color: #374151; color: #fff" class="rf-palette__scale-stop">#374151</div>
<div data-name="scale-stop" style="background-color: #1F2937; color: #fff" class="rf-palette__scale-stop">#1F2937</div>
<div data-name="scale-stop" style="background-color: #111827; color: #fff" class="rf-palette__scale-stop">#111827</div>
</div>
<span data-name="swatch-name" class="rf-palette__swatch-name">Gray</span>
</div>
</section>Contrast and accessibility
Enable showContrast and showA11y to display WCAG contrast ratios and AA/AAA compliance.
{% palette title="Accessible Colors" showContrast=true showA11y=true %}
- Navy: #1E3A5F
- Teal: #0D9488
- Coral: #FB7185
- Amber: #F59E0B
{% /palette %}<section data-rune="palette" data-rune-fields="{"title":"Accessible Colors","showContrast":"true","showA11y":"true","columns":""}">
<h3 data-name="title">Accessible Colors</h3>
<div data-name="group">
<div data-name="grid" style="--rf-palette-cols: 3">
<div data-name="swatch">
<div data-name="swatch-color" style="background-color: #1E3A5F"></div>
<span data-name="swatch-name">Navy</span>
<span data-name="swatch-value">#1E3A5F</span>
<span data-name="swatch-contrast">W: 11.5 · B: 1.8</span>
<span data-name="swatch-a11y">
<span data-name="swatch-a11y--pass">AA ✓</span>
<span data-name="swatch-a11y--pass">AAA ✓</span>
</span>
</div>
<div data-name="swatch">
<div data-name="swatch-color" style="background-color: #0D9488"></div>
<span data-name="swatch-name">Teal</span>
<span data-name="swatch-value">#0D9488</span>
<span data-name="swatch-contrast">W: 3.7 · B: 5.6</span>
<span data-name="swatch-a11y">
<span data-name="swatch-a11y--fail">AA ✗</span>
<span data-name="swatch-a11y--fail">AAA ✗</span>
</span>
</div>
<div data-name="swatch">
<div data-name="swatch-color" style="background-color: #FB7185"></div>
<span data-name="swatch-name">Coral</span>
<span data-name="swatch-value">#FB7185</span>
<span data-name="swatch-contrast">W: 2.7 · B: 7.8</span>
<span data-name="swatch-a11y">
<span data-name="swatch-a11y--fail">AA ✗</span>
<span data-name="swatch-a11y--fail">AAA ✗</span>
</span>
</div>
<div data-name="swatch">
<div data-name="swatch-color" style="background-color: #F59E0B"></div>
<span data-name="swatch-name">Amber</span>
<span data-name="swatch-value">#F59E0B</span>
<span data-name="swatch-contrast">W: 2.1 · B: 9.8</span>
<span data-name="swatch-a11y">
<span data-name="swatch-a11y--fail">AA ✗</span>
<span data-name="swatch-a11y--fail">AAA ✗</span>
</span>
</div>
</div>
</div>
</section>Accessible Colors
<section class="rf-palette rf-palette--Accessible Colors rf-palette--true rf-palette--true" data-title="Accessible Colors" data-show-contrast="true" data-show-a11y="true" data-columns="" data-elevation="flat" data-rune="palette" data-density="full">
<h3 data-name="title" class="rf-palette__title" data-section="title">Accessible Colors</h3>
<div data-name="group" class="rf-palette__group">
<div data-name="grid" style="--rf-palette-cols: 3" class="rf-palette__grid">
<div data-name="swatch" class="rf-palette__swatch">
<div data-name="swatch-color" style="background-color: #1E3A5F" class="rf-palette__swatch-color"></div>
<span data-name="swatch-name" class="rf-palette__swatch-name">Navy</span>
<span data-name="swatch-value" class="rf-palette__swatch-value">#1E3A5F</span>
<span data-name="swatch-contrast" class="rf-palette__swatch-contrast">W: 11.5 · B: 1.8</span>
<span data-name="swatch-a11y" class="rf-palette__swatch-a11y">
<span data-name="swatch-a11y--pass" class="rf-palette__swatch-a11y--pass">AA ✓</span>
<span data-name="swatch-a11y--pass" class="rf-palette__swatch-a11y--pass">AAA ✓</span>
</span>
</div>
<div data-name="swatch" class="rf-palette__swatch">
<div data-name="swatch-color" style="background-color: #0D9488" class="rf-palette__swatch-color"></div>
<span data-name="swatch-name" class="rf-palette__swatch-name">Teal</span>
<span data-name="swatch-value" class="rf-palette__swatch-value">#0D9488</span>
<span data-name="swatch-contrast" class="rf-palette__swatch-contrast">W: 3.7 · B: 5.6</span>
<span data-name="swatch-a11y" class="rf-palette__swatch-a11y">
<span data-name="swatch-a11y--fail" class="rf-palette__swatch-a11y--fail">AA ✗</span>
<span data-name="swatch-a11y--fail" class="rf-palette__swatch-a11y--fail">AAA ✗</span>
</span>
</div>
<div data-name="swatch" class="rf-palette__swatch">
<div data-name="swatch-color" style="background-color: #FB7185" class="rf-palette__swatch-color"></div>
<span data-name="swatch-name" class="rf-palette__swatch-name">Coral</span>
<span data-name="swatch-value" class="rf-palette__swatch-value">#FB7185</span>
<span data-name="swatch-contrast" class="rf-palette__swatch-contrast">W: 2.7 · B: 7.8</span>
<span data-name="swatch-a11y" class="rf-palette__swatch-a11y">
<span data-name="swatch-a11y--fail" class="rf-palette__swatch-a11y--fail">AA ✗</span>
<span data-name="swatch-a11y--fail" class="rf-palette__swatch-a11y--fail">AAA ✗</span>
</span>
</div>
<div data-name="swatch" class="rf-palette__swatch">
<div data-name="swatch-color" style="background-color: #F59E0B" class="rf-palette__swatch-color"></div>
<span data-name="swatch-name" class="rf-palette__swatch-name">Amber</span>
<span data-name="swatch-value" class="rf-palette__swatch-value">#F59E0B</span>
<span data-name="swatch-contrast" class="rf-palette__swatch-contrast">W: 2.1 · B: 9.8</span>
<span data-name="swatch-a11y" class="rf-palette__swatch-a11y">
<span data-name="swatch-a11y--fail" class="rf-palette__swatch-a11y--fail">AA ✗</span>
<span data-name="swatch-a11y--fail" class="rf-palette__swatch-a11y--fail">AAA ✗</span>
</span>
</div>
</div>
</div>
</section>Attributes
| Attribute | Type | Required | Description |
|---|---|---|---|
title | string | — | Heading displayed above the palette section. |
showContrast | boolean | — | Enable/disable WCAG contrast ratio values against white and black. |
showA11y | boolean | — | Enable/disable AA/AAA accessibility compliance badges per swatch. |
columns | number | — | Number of swatch columns in the grid; auto-calculated from count when omitted. |
Universal attributes
bg
The background layer: image, video, gradient, flat overlay wash and legibility scrim, in a single injected layer behind the rune's content.
| Attribute | Type | Required | Description |
|---|---|---|---|
bg | string | — | Background preset applied to this block |
bg-from | string | — | Gradient start colour — a semantic token name (→ var(--rf-color-*)) |
bg-gradient | "to-t" | "to-b" | "to-l" | "to-r" | "to-tr" | "to-br" | "to-bl" | "to-tl" | — | Gradient direction (bounded named set) |
bg-gradient-type | "linear" | "radial" | "conic" | — | Gradient type |
bg-to | string | — | Gradient end colour — a semantic token name |
bg-via | string | — | Optional middle gradient stop — a semantic token name |
scrim | "top" | "bottom" | "left" | "right" | "none" | — | Scrim direction (heaviest edge); presence turns the scrim on, "none" opts out of the default cover scrim |
scrim-blur | "none" | "sm" | "md" | "lg" | — | Frost scrim blur amount |
scrim-strength | "sm" | "md" | "lg" | — | Gradient scrim strength |
scrim-tone | "dark" | "light" | — | Whether the scrim darkens (for light text) or lightens (for dark text) |
scrim-type | "gradient" | "frost" | — | Scrim treatment: gradient (default) or frost (backdrop blur) |
elevation
How far the rune sits off the page, from sunken to overlay. The theme decides what each step looks like.
| Attribute | Type | Required | Description |
|---|---|---|---|
elevation | "sunken" | "flush" | "flat" | "raised" | "floating" | "overlay" | "none" | "sm" | "md" | "lg" | — | Surface depth, from sunken to overlay. Deprecated: none, sm, md and lg (read as flat, raised, raised and floating) |
inset
Internal padding override.
| Attribute | Type | Required | Description |
|---|---|---|---|
inset | "flush" | "tight" | "default" | "loose" | "breathe" | — | Inner padding of this block |
motion
Scroll-reveal entrance. You choose its character; the theme decides how it moves.
| Attribute | Type | Required | Description |
|---|---|---|---|
reveal | "none" | "fade" | "slide" | "scale" | "blur" | — | Scroll-reveal entrance character (none|fade|slide|scale|blur); the theme owns the choreography |
stagger | boolean | — | Cascade this block's items in as it reveals (no-op on single-child runes) |
prominence
Header emphasis. Scales a rune's header, or its featured quotation; the theme decides the type size for each step.
| Attribute | Type | Required | Description |
|---|---|---|---|
prominence | "quiet" | "normal" | "prominent" | "display" | "marquee" | — | Emphasis of a page-section header or a featured quotation (only on runes that have one) |
spacing
Block-level rhythm override.
| Attribute | Type | Required | Description |
|---|---|---|---|
spacing | "flush" | "tight" | "default" | "loose" | "breathe" | — | Vertical spacing above and below this block |
substrate
Generated pattern fills behind the content, drawn by the theme.
| Attribute | Type | Required | Description |
|---|---|---|---|
substrate | "dots" | "grid" | "lines" | "cross" | "checker" | "none" | — | Generated surface pattern |
substrate-fill | "inherit" | "inset" | — | Surface fill the pattern sits on (full colour stays with tint) |
substrate-opacity | "sm" | "md" | "lg" | — | Pattern ink strength |
substrate-size | "sm" | "md" | "lg" | — | Pattern cell size |
substrate-target | "self" | "media" | — | Which surface the pattern fills (overrides the rune/theme default) |
tint
Per-rune colour override: a named tint from the theme registry, with inline per-token overrides layered on top.
| Attribute | Type | Required | Description |
|---|---|---|---|
tint | string | — | Color tint preset applied to this block |
tint-mode | "auto" | "dark" | "light" | — | Whether the tint adapts to auto, dark, or light mode |
width
The track a block rune occupies.
| Attribute | Type | Required | Description |
|---|---|---|---|
width | "compact" | "narrow" | "content" | "wide" | "full" | — | Maximum width constraint for this block |
| Not available | Why |
|---|---|
| dropcap, reading | this rune declares no prose body |
| frame | this rune declares neither a `frameTarget` nor a media section |