@eluan/theme-generator 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ import type { PrimitiveTokens, ScaleName, ScaleStepValue, TokenRef } from '../types.js';
2
+ export type ParsedRef = {
3
+ scaleName: ScaleName;
4
+ /** One step for a plain ref, two for a mix. */
5
+ steps: ScaleStepValue[];
6
+ /** Share of the first step in a mix, 0 to 1. 1 for a plain ref. */
7
+ share: number;
8
+ };
9
+ /** Splits a ref into its ramp and step(s). `white` and `black` have neither. */
10
+ export declare function parseRef(ref: TokenRef): ParsedRef | null;
11
+ /**
12
+ * The hex a ref stands for in `primitives`, or null when the ramp or step is
13
+ * not there. A mix is interpolated in OKLCH, as `color-mix(in oklch, …)` does.
14
+ */
15
+ export declare function resolveRef(ref: TokenRef, primitives: PrimitiveTokens): string | null;
16
+ /** `resolveRef`, throwing on a ref that names a ramp or step that is not there. */
17
+ export declare function resolveHex(ref: TokenRef, primitives: PrimitiveTokens): string;
@@ -0,0 +1,59 @@
1
+ import { oklchToHex } from '../color/convert.js';
2
+ /** `share` of `a` and the rest of `b`, in OKLCH, hue along the shorter arc. A grey takes the other's hue. */
3
+ function mixOklch(a, b, share) {
4
+ const t = 1 - share;
5
+ const ha = a.c < 1e-4 ? b.h : a.h;
6
+ const hb = b.c < 1e-4 ? a.h : b.h;
7
+ const delta = ((hb - ha + 540) % 360) - 180;
8
+ return {
9
+ mode: 'oklch',
10
+ l: a.l + (b.l - a.l) * t,
11
+ c: a.c + (b.c - a.c) * t,
12
+ h: (ha + delta * t + 360) % 360,
13
+ };
14
+ }
15
+ /** Splits a ref into its ramp and step(s). `white` and `black` have neither. */
16
+ export function parseRef(ref) {
17
+ if (ref === 'white' || ref === 'black')
18
+ return null;
19
+ const [scaleName, rest] = ref.split('.');
20
+ const [stepPart, sharePart] = rest.split('@');
21
+ const steps = stepPart.split('/').map((s) => Number(s));
22
+ return { scaleName, steps, share: sharePart === undefined ? 1 : Number(sharePart) / 100 };
23
+ }
24
+ /**
25
+ * The hex a ref stands for in `primitives`, or null when the ramp or step is
26
+ * not there. A mix is interpolated in OKLCH, as `color-mix(in oklch, …)` does.
27
+ */
28
+ export function resolveRef(ref, primitives) {
29
+ if (ref === 'white')
30
+ return '#ffffff';
31
+ if (ref === 'black')
32
+ return '#000000';
33
+ const parsed = parseRef(ref);
34
+ if (!parsed)
35
+ return null;
36
+ const scale = primitives[parsed.scaleName];
37
+ if (!scale)
38
+ return null;
39
+ const [first, second] = parsed.steps.map((step) => scale[step]);
40
+ if (!first)
41
+ return null;
42
+ if (parsed.steps.length === 1)
43
+ return first.hex;
44
+ if (!second)
45
+ return null;
46
+ return oklchToHex(mixOklch(first.oklch, second.oklch, parsed.share));
47
+ }
48
+ /** `resolveRef`, throwing on a ref that names a ramp or step that is not there. */
49
+ export function resolveHex(ref, primitives) {
50
+ const hex = resolveRef(ref, primitives);
51
+ if (hex === null) {
52
+ const parsed = parseRef(ref);
53
+ const scale = parsed && primitives[parsed.scaleName];
54
+ throw new Error(scale || !parsed
55
+ ? `Invalid token reference "${ref}": scale "${parsed?.scaleName}" has no step ${parsed?.steps.join('/')}.`
56
+ : `Invalid token reference "${ref}": unknown scale "${parsed.scaleName}".`);
57
+ }
58
+ return hex;
59
+ }
@@ -1,9 +1,11 @@
1
1
  import type { Mode, SemanticEntry, SemanticMap, TokenRef } from '../types.js';
2
2
  /**
3
3
  * The dim ref for a light ref: one step deeper on the same ramp, 950 staying
4
- * put. `minimal`'s own dim follows the same rule (page 0 → 100, tint 100 →
5
- * 200, status text 700 → 800), which is what keeps dim a softer light mode
6
- * rather than a lighter dark one.
4
+ * put. It is how the base theme's own dim treats colour (a tint at 100 becomes
5
+ * 200, status text at 700 becomes 800), which keeps dim a softer light mode
6
+ * rather than a lighter dark one. Greys do not follow it: dim's surfaces are
7
+ * in-between steps, so every grey entry names its dim ref. A mix is returned
8
+ * as it is.
7
9
  */
8
10
  export declare function dimRef(light: TokenRef): TokenRef;
9
11
  /** The ref an entry resolves to in `mode`; dim falls back to `dimRef(entry.light)`. */
@@ -1,17 +1,20 @@
1
1
  import { SCALE_STEPS } from '../types.js';
2
+ import { parseRef } from './refs.js';
2
3
  /**
3
4
  * The dim ref for a light ref: one step deeper on the same ramp, 950 staying
4
- * put. `minimal`'s own dim follows the same rule (page 0 → 100, tint 100 →
5
- * 200, status text 700 → 800), which is what keeps dim a softer light mode
6
- * rather than a lighter dark one.
5
+ * put. It is how the base theme's own dim treats colour (a tint at 100 becomes
6
+ * 200, status text at 700 becomes 800), which keeps dim a softer light mode
7
+ * rather than a lighter dark one. Greys do not follow it: dim's surfaces are
8
+ * in-between steps, so every grey entry names its dim ref. A mix is returned
9
+ * as it is.
7
10
  */
8
11
  export function dimRef(light) {
9
- if (light === 'white' || light === 'black')
12
+ const parsed = parseRef(light);
13
+ if (!parsed || parsed.steps.length > 1)
10
14
  return light;
11
- const [scale, step] = light.split('.');
12
- const index = SCALE_STEPS.indexOf(Number(step));
15
+ const index = SCALE_STEPS.indexOf(parsed.steps[0]);
13
16
  const deeper = SCALE_STEPS[Math.min(index + 1, SCALE_STEPS.length - 1)];
14
- return `${scale}.${deeper}`;
17
+ return `${parsed.scaleName}.${deeper}`;
15
18
  }
16
19
  /** The ref an entry resolves to in `mode`; dim falls back to `dimRef(entry.light)`. */
17
20
  export function modeRef(entry, mode) {
@@ -34,130 +37,168 @@ export function withDimRefs(map) {
34
37
  }
35
38
  return filled;
36
39
  }
40
+ /*
41
+ * The grey steps each mode gives its surfaces, text and borders. This is
42
+ * modes.css in @eluan/tokens, restated so contrast can be checked here; the
43
+ * two must agree. A generated theme does not emit these: it emits the ramp
44
+ * and the base theme derives them.
45
+ *
46
+ * light cards white, the ground paper (50), ink at 800
47
+ * dim the same order a little deeper, on in-between steps
48
+ * dark the ground at 950, cards at 900, raised controls at 800
49
+ */
50
+ const BG = {
51
+ primary: { light: 'white', dim: 'neutral.50/100@50', dark: 'neutral.900' },
52
+ secondary: { light: 'neutral.50', dim: 'neutral.100/200@60', dark: 'neutral.950' },
53
+ tertiary: { light: 'neutral.100', dim: 'neutral.100/200@25', dark: 'neutral.800' },
54
+ quaternary: { light: 'neutral.200', dim: 'neutral.200/300@50', dark: 'neutral.700' },
55
+ quinary: { light: 'neutral.300', dim: 'neutral.400', dark: 'neutral.600' },
56
+ };
57
+ const FG = {
58
+ primary: { light: 'neutral.800', dim: 'neutral.900', dark: 'neutral.100' },
59
+ secondary: { light: 'neutral.700', dim: 'neutral.800', dark: 'neutral.300' },
60
+ tertiary: { light: 'neutral.600/700@65', dim: 'neutral.700', dark: 'neutral.400' },
61
+ quaternary: { light: 'neutral.500/600@65', dim: 'neutral.600', dark: 'neutral.500' },
62
+ quinary: { light: 'neutral.400', dim: 'neutral.500', dark: 'neutral.600' },
63
+ };
64
+ const BORDER = {
65
+ primary: { light: 'neutral.100', dim: 'neutral.100/200@25', dark: 'neutral.900/800@50' },
66
+ secondary: { light: 'neutral.200', dim: 'neutral.200/300@50', dark: 'neutral.800/700@50' },
67
+ };
68
+ /** The accent as picked, and its hover: the same step in every mode. */
69
+ const ACCENT = { light: 'primary.500', dim: 'primary.500', dark: 'primary.500' };
70
+ const ACCENT_HOVER = { light: 'primary.600', dim: 'primary.600', dark: 'primary.600' };
71
+ const WHITE = { light: 'white', dim: 'white', dark: 'white' };
72
+ /**
73
+ * White on the accent is the look, and it holds down to the 3:1 UI tier. An
74
+ * accent too light for that gets ink instead (the corrector's fallback).
75
+ */
76
+ const ON_ACCENT = { minContrast: 3.0, allowBelowDefault: true };
77
+ /**
78
+ * Text on the accent is checked on the fill and its hover together, so every
79
+ * state gets the same colour: a label never turns from ink to white on press.
80
+ */
81
+ const ON_ACCENT_GROUNDS = ['action-primary-bg', 'action-primary-bg-hover'];
82
+ /** A token the base theme derives from the greys: checked here, not emitted. */
83
+ const grey = (refs, role, checks = {}) => ({
84
+ ...refs,
85
+ role,
86
+ inherit: true,
87
+ ...checks,
88
+ });
89
+ const text = (against) => ({ contrastAgainst: against, minContrast: 4.5 });
37
90
  export function buildSemanticMap() {
38
91
  return withDimRefs({
39
92
  // ── Base greys ─────────────────────────────────────────────
40
- // The mode-level ramp aliases `minimal` defines in modes.css. Most tokens
41
- // here supersede them, but some components read them directly (Secondary
42
- // and Ghost-family buttons, Card, Progress, SegmentedControl), so a theme
43
- // that leaves them alone shows `minimal`'s greys there.
44
- 'backgrounds-primary': { light: 'neutral.50', dark: 'neutral.800', role: 'bg' },
45
- 'backgrounds-secondary': { light: 'neutral.100', dark: 'neutral.900', role: 'bg' },
46
- 'backgrounds-tertiary': { light: 'neutral.200', dark: 'neutral.950', role: 'bg' },
47
- 'backgrounds-quaternary': { light: 'neutral.300', dark: 'neutral.700', role: 'bg' },
48
- 'backgrounds-quinary': { light: 'neutral.400', dark: 'neutral.600', role: 'bg' },
49
- // Secondary button text sits on the tertiary fill; the rest on page and panel.
50
- 'foregrounds-primary': { light: 'neutral.950', dark: 'neutral.50', role: 'fg', contrastAgainst: ['backgrounds-primary', 'backgrounds-secondary', 'backgrounds-tertiary'], minContrast: 4.5 },
51
- 'foregrounds-secondary': { light: 'neutral.800', dark: 'neutral.100', role: 'fg', contrastAgainst: ['backgrounds-primary', 'backgrounds-secondary'], minContrast: 4.5 },
52
- 'foregrounds-tertiary': { light: 'neutral.600', dark: 'neutral.200', role: 'fg', contrastAgainst: ['backgrounds-primary', 'backgrounds-secondary'], minContrast: 4.5 },
53
- 'foregrounds-quaternary': { light: 'neutral.500', dark: 'neutral.300', role: 'fg', contrastAgainst: ['backgrounds-primary', 'backgrounds-secondary'], minContrast: 3.0, allowBelowDefault: true },
54
- 'foregrounds-quinary': { light: 'neutral.400', dark: 'neutral.400', role: 'fg' },
93
+ 'backgrounds-primary': grey(BG.primary, 'bg'),
94
+ 'backgrounds-secondary': grey(BG.secondary, 'bg'),
95
+ 'backgrounds-tertiary': grey(BG.tertiary, 'bg'),
96
+ 'backgrounds-quaternary': grey(BG.quaternary, 'bg'),
97
+ 'backgrounds-quinary': grey(BG.quinary, 'bg'),
98
+ // Ink sits on the card, the ground and a neutral fill (the Secondary button).
99
+ 'foregrounds-primary': grey(FG.primary, 'fg', text(['backgrounds-primary', 'backgrounds-secondary', 'backgrounds-tertiary'])),
100
+ 'foregrounds-secondary': grey(FG.secondary, 'fg', text(['backgrounds-primary', 'backgrounds-secondary'])),
101
+ // Muted text: body copy, so it meets the text floor on card and ground.
102
+ 'foregrounds-tertiary': grey(FG.tertiary, 'fg', text(['backgrounds-primary', 'backgrounds-secondary'])),
103
+ // Captions and placeholders: the 3:1 tier, on card and ground.
104
+ 'foregrounds-quaternary': grey(FG.quaternary, 'fg', { contrastAgainst: ['backgrounds-primary', 'backgrounds-secondary'], minContrast: 3.0, allowBelowDefault: true }),
105
+ 'foregrounds-quinary': grey(FG.quinary, 'fg'),
106
+ 'borders-primary': grey(BORDER.primary, 'border'),
107
+ 'borders-secondary': grey(BORDER.secondary, 'border'),
55
108
  // ── Container ──────────────────────────────────────────────
56
- 'container-bg': { light: 'neutral.50', dark: 'neutral.800', role: 'bg' },
57
- 'container-bg-alt': { light: 'neutral.100', dark: 'neutral.900', role: 'bg' },
58
- 'container-bg-inverse': { light: 'neutral.800', dark: 'neutral.100', role: 'bg' },
59
- 'container-border': { light: 'neutral.200', dark: 'neutral.700', role: 'border' },
60
- 'container-border-alt': { light: 'neutral.300', dark: 'neutral.600', role: 'border' },
61
- 'container-border-inverse': { light: 'neutral.600', dark: 'neutral.200', role: 'border' },
62
- 'container-fg': { light: 'neutral.950', dark: 'neutral.50', role: 'fg', contrastAgainst: 'container-bg', minContrast: 4.5 },
63
- 'container-fg-alt': { light: 'neutral.800', dark: 'neutral.100', role: 'fg', contrastAgainst: 'container-bg', minContrast: 4.5 },
64
- 'container-fg-inverse': { light: 'neutral.50', dark: 'neutral.950', role: 'fg', contrastAgainst: 'container-bg-inverse', minContrast: 4.5 },
65
- // Tooltip surface — matches container-bg in light and container-border in
66
- // dark, so the tooltip's border disappears against its own background.
67
- 'tooltip-bg': { light: 'neutral.50', dark: 'neutral.700', role: 'bg' },
68
- // Dialog/Sheet scrim, drawn at 0.8 opacity — the darkest step in both
69
- // modes so it dims the page behind an overlay instead of washing it out.
70
- 'overlay-bg': { light: 'neutral.950', dark: 'neutral.950', role: 'bg' },
71
- // Keyboard focus outline — a non-text indicator, so it targets the WCAG
72
- // 3:1 UI tier (1.4.11) against the page ground, like interactive-fg-alt.
73
- // Mid-ramp rather than neutral.950/50 so focus never matches the pressed fill.
74
- 'focus-ring': { light: 'neutral.500', dark: 'neutral.400', role: 'fg', contrastAgainst: 'container-bg', minContrast: 3.0, allowBelowDefault: true },
109
+ 'container-bg': grey(BG.primary, 'bg'),
110
+ // A quiet fill: the hairline's shade.
111
+ 'container-bg-alt': grey(BORDER.primary, 'bg'),
112
+ 'container-bg-inverse': grey(FG.secondary, 'bg'),
113
+ 'container-border': grey(BORDER.primary, 'border'),
114
+ 'container-border-alt': grey(BORDER.secondary, 'border'),
115
+ 'container-border-inverse': grey(FG.tertiary, 'border'),
116
+ 'container-fg': grey(FG.primary, 'fg', text('container-bg')),
117
+ 'container-fg-alt': grey(FG.secondary, 'fg', text('container-bg')),
118
+ 'container-fg-inverse': grey(BG.primary, 'fg', text('container-bg-inverse')),
75
119
  // ── Interactive ────────────────────────────────────────────
76
- 'interactive-bg': { light: 'neutral.50', dark: 'neutral.800', role: 'bg' },
77
- 'interactive-bg-alt': { light: 'neutral.100', dark: 'neutral.900', role: 'bg' },
78
- 'interactive-bg-alt2': { light: 'primary.50', dark: 'primary.950', role: 'bg' },
79
- 'interactive-bg-disabled': { light: 'neutral.200', dark: 'neutral.700', role: 'bg' },
80
- 'interactive-bg-hover': { light: 'neutral.200', dark: 'neutral.700', role: 'bg' },
81
- 'interactive-bg-active': { light: 'primary.800', dark: 'primary.300', role: 'bg' },
82
- 'interactive-bg-selected': { light: 'primary.800', dark: 'primary.300', role: 'bg' },
83
- 'interactive-bg-inverse': { light: 'neutral.950', dark: 'neutral.50', role: 'bg' },
84
- 'interactive-border': { light: 'neutral.200', dark: 'neutral.700', role: 'border' },
85
- 'interactive-border-alt': { light: 'neutral.300', dark: 'neutral.600', role: 'border' },
86
- 'interactive-border-disabled': { light: 'neutral.300', dark: 'neutral.600', role: 'border' },
87
- 'interactive-fg': { light: 'neutral.950', dark: 'neutral.50', role: 'fg', contrastAgainst: 'interactive-bg', minContrast: 4.5 },
88
- // Muted text: placeholders, unselected tabs and segments, and the
89
- // descriptions in Card, Dialog and Sheet. Body text, so it meets the text
90
- // floor on the page and panel grounds it sits on.
91
- 'interactive-fg-alt': { light: 'neutral.600', dark: 'neutral.300', role: 'fg', contrastAgainst: ['interactive-bg', 'interactive-bg-alt', 'container-bg', 'container-bg-alt'], minContrast: 4.5 },
92
- 'interactive-fg-readonly': { light: 'neutral.800', dark: 'neutral.100', role: 'fg', contrastAgainst: 'interactive-bg', minContrast: 4.5 },
93
- 'interactive-fg-disabled': { light: 'neutral.400', dark: 'neutral.500', role: 'fg' },
94
- 'interactive-fg-active': { light: 'primary.100', dark: 'primary.900', role: 'fg', contrastAgainst: 'interactive-bg-active', minContrast: 4.5 },
95
- 'interactive-fg-selected': { light: 'primary.100', dark: 'primary.900', role: 'fg', contrastAgainst: 'interactive-bg-selected', minContrast: 4.5 },
96
- 'interactive-fg-inverse': { light: 'neutral.50', dark: 'neutral.950', role: 'fg', contrastAgainst: 'interactive-bg-inverse', minContrast: 4.5 },
120
+ 'interactive-bg': grey(BG.primary, 'bg'),
121
+ 'interactive-bg-alt': grey(BG.secondary, 'bg'),
122
+ 'interactive-bg-alt2': grey(BORDER.primary, 'bg'),
123
+ 'interactive-bg-disabled': grey(BG.tertiary, 'bg'),
124
+ 'interactive-bg-hover': grey(BG.tertiary, 'bg'),
125
+ // Switches, checks, sliders and progress take the accent from the primary
126
+ // action; the base theme points these at it, so they follow what is
127
+ // emitted there.
128
+ 'interactive-bg-active': grey(ACCENT, 'bg'),
129
+ 'interactive-bg-selected': grey(ACCENT, 'bg'),
130
+ 'interactive-bg-inverse': grey(FG.primary, 'bg'),
131
+ 'interactive-border': grey(BORDER.primary, 'border'),
132
+ 'interactive-border-alt': grey(BORDER.secondary, 'border'),
133
+ 'interactive-border-disabled': grey(BORDER.primary, 'border'),
134
+ 'interactive-fg': grey(FG.primary, 'fg', text('interactive-bg')),
135
+ // Placeholders, unselected tabs and segments, descriptions.
136
+ 'interactive-fg-alt': grey(FG.tertiary, 'fg', text(['interactive-bg', 'interactive-bg-alt'])),
137
+ 'interactive-fg-readonly': grey(FG.secondary, 'fg', text('interactive-bg')),
138
+ 'interactive-fg-disabled': grey(FG.quinary, 'fg'),
139
+ 'interactive-fg-active': grey(WHITE, 'fg', { contrastAgainst: ON_ACCENT_GROUNDS, ...ON_ACCENT }),
140
+ 'interactive-fg-selected': grey(WHITE, 'fg', { contrastAgainst: ON_ACCENT_GROUNDS, ...ON_ACCENT }),
141
+ 'interactive-fg-inverse': grey(BG.primary, 'fg', text('interactive-bg-inverse')),
97
142
  // ── Action Primary ─────────────────────────────────────────
98
- 'action-primary-bg': { light: 'primary.500', dark: 'primary.500', role: 'bg' },
99
- 'action-primary-bg-hover': { light: 'primary.800', dark: 'primary.400', role: 'bg' },
100
- 'action-primary-bg-active': { light: 'primary.800', dark: 'primary.400', role: 'bg' },
101
- 'action-primary-bg-selected': { light: 'primary.800', dark: 'primary.400', role: 'bg' },
143
+ // The accent as picked, in every mode, with white on it.
144
+ 'action-primary-bg': { ...ACCENT, role: 'bg' },
145
+ 'action-primary-bg-hover': { ...ACCENT_HOVER, role: 'bg' },
146
+ 'action-primary-bg-active': { ...ACCENT_HOVER, role: 'bg' },
147
+ 'action-primary-bg-selected': { ...ACCENT_HOVER, role: 'bg' },
102
148
  'action-primary-bg-disabled': { light: 'primary.100', dark: 'primary.900', role: 'bg' },
103
- 'action-primary-bg-inverse': { light: 'primary.50', dark: 'primary.950', role: 'bg' },
104
- 'action-primary-fg': { light: 'neutral.50', dark: 'neutral.50', role: 'fg', contrastAgainst: 'action-primary-bg', minContrast: 4.5 },
105
- 'action-primary-fg-disabled': { light: 'neutral.400', dark: 'neutral.600', role: 'fg' },
106
- 'action-primary-fg-active': { light: 'neutral.50', dark: 'neutral.50', role: 'fg', contrastAgainst: 'action-primary-bg-active', minContrast: 4.5 },
107
- 'action-primary-fg-selected': { light: 'neutral.50', dark: 'neutral.50', role: 'fg', contrastAgainst: 'action-primary-bg-selected', minContrast: 4.5 },
149
+ 'action-primary-bg-inverse': grey(BG.primary, 'bg'),
150
+ 'action-primary-fg': { ...WHITE, role: 'fg', contrastAgainst: ON_ACCENT_GROUNDS, ...ON_ACCENT },
151
+ 'action-primary-fg-disabled': grey(FG.quinary, 'fg'),
152
+ 'action-primary-fg-active': { ...WHITE, role: 'fg', contrastAgainst: ON_ACCENT_GROUNDS, ...ON_ACCENT },
153
+ 'action-primary-fg-selected': { ...WHITE, role: 'fg', contrastAgainst: ON_ACCENT_GROUNDS, ...ON_ACCENT },
108
154
  'action-primary-fg-inverse': { light: 'primary.700', dark: 'primary.200', role: 'fg', contrastAgainst: 'action-primary-bg-inverse', minContrast: 4.5 },
109
155
  // ── Action Secondary ───────────────────────────────────────
110
- 'action-secondary-bg-hover': { light: 'primary.100', dark: 'primary.900', role: 'bg' },
111
- 'action-secondary-bg-active': { light: 'primary.500', dark: 'primary.500', role: 'bg' },
112
- 'action-secondary-bg-selected': { light: 'primary.500', dark: 'primary.500', role: 'bg' },
113
- 'action-secondary-bg-disabled': { light: 'neutral.200', dark: 'neutral.700', role: 'bg' },
114
- 'action-secondary-border': { light: 'primary.500', dark: 'primary.400', role: 'border' },
115
- 'action-secondary-border-alt': { light: 'primary.800', dark: 'primary.300', role: 'border' },
116
- 'action-secondary-border-disabled': { light: 'primary.100', dark: 'primary.900', role: 'border' },
117
- 'action-secondary-border-inverse': { light: 'primary.50', dark: 'primary.950', role: 'border' },
118
- // Outline button text, on page and panel surfaces alike: checked against
119
- // both, like action-tertiary-fg. Whichever is harder in a mode decides.
120
- 'action-secondary-fg': { light: 'primary.500', dark: 'primary.400', role: 'fg', contrastAgainst: ['container-bg', 'container-bg-alt'], minContrast: 4.5 },
121
- 'action-secondary-fg-alt': { light: 'neutral.950', dark: 'neutral.50', role: 'fg' },
122
- 'action-secondary-fg-disabled': { light: 'neutral.400', dark: 'neutral.500', role: 'fg' },
123
- 'action-secondary-fg-active': { light: 'neutral.50', dark: 'neutral.50', role: 'fg', contrastAgainst: 'action-secondary-bg-active', minContrast: 4.5 },
124
- 'action-secondary-fg-selected': { light: 'neutral.50', dark: 'neutral.50', role: 'fg', contrastAgainst: 'action-secondary-bg-selected', minContrast: 4.5 },
125
- 'action-secondary-fg-inverse': { light: 'neutral.950', dark: 'neutral.50', role: 'fg' },
156
+ // The Outline button. Neutral in the look: a raised surface with ink on it.
157
+ 'action-secondary-bg-hover': grey(BG.tertiary, 'bg'),
158
+ 'action-secondary-bg-active': grey(BG.quaternary, 'bg'),
159
+ 'action-secondary-bg-selected': grey(BG.quaternary, 'bg'),
160
+ 'action-secondary-bg-disabled': grey(BG.tertiary, 'bg'),
161
+ 'action-secondary-border': grey(BORDER.secondary, 'border'),
162
+ 'action-secondary-border-alt': grey(FG.quaternary, 'border'),
163
+ 'action-secondary-border-disabled': grey(BORDER.primary, 'border'),
164
+ 'action-secondary-border-inverse': grey(BG.secondary, 'border'),
165
+ 'action-secondary-fg': grey(FG.primary, 'fg', text(['backgrounds-primary', 'backgrounds-secondary'])),
166
+ 'action-secondary-fg-alt': grey(FG.primary, 'fg'),
167
+ 'action-secondary-fg-disabled': grey(FG.quinary, 'fg'),
168
+ 'action-secondary-fg-active': grey(FG.primary, 'fg', text('action-secondary-bg-active')),
169
+ 'action-secondary-fg-selected': grey(FG.primary, 'fg', text('action-secondary-bg-selected')),
170
+ 'action-secondary-fg-inverse': grey(FG.primary, 'fg'),
126
171
  // ── Action Tertiary ────────────────────────────────────────
127
- 'action-tertiary-bg': { light: 'neutral.50', dark: 'neutral.800', role: 'bg' },
128
- 'action-tertiary-bg-alt': { light: 'neutral.100', dark: 'neutral.900', role: 'bg' },
129
- 'action-tertiary-bg-hover': { light: 'primary.50', dark: 'primary.950', role: 'bg' },
130
- 'action-tertiary-bg-active': { light: 'primary.100', dark: 'primary.900', role: 'bg' },
131
- 'action-tertiary-bg-selected': { light: 'primary.100', dark: 'primary.900', role: 'bg' },
132
- 'action-tertiary-bg-disabled': { light: 'neutral.50', dark: 'neutral.800', role: 'bg' },
133
- 'action-tertiary-bg-inverse': { light: 'neutral.50', dark: 'neutral.800', role: 'bg' },
134
- 'action-tertiary-border': { light: 'primary.500', dark: 'primary.400', role: 'border' },
135
- 'action-tertiary-border-alt': { light: 'primary.800', dark: 'primary.300', role: 'border' },
136
- 'action-tertiary-border-disabled': { light: 'neutral.300', dark: 'neutral.600', role: 'border' },
137
- 'action-tertiary-border-inverse': { light: 'primary.100', dark: 'primary.900', role: 'border' },
138
- // Ghost button text sits on page and panel surfaces alike, so it is checked
139
- // against both: -bg (the page) and -bg-alt (the panel, container-bg-alt's
140
- // refs). Whichever is harder in a mode decides.
141
- 'action-tertiary-fg': { light: 'primary.500', dark: 'primary.400', role: 'fg', contrastAgainst: ['action-tertiary-bg', 'action-tertiary-bg-alt'], minContrast: 4.5 },
142
- 'action-tertiary-fg-alt': { light: 'neutral.950', dark: 'neutral.50', role: 'fg' },
143
- 'action-tertiary-fg-disabled': { light: 'neutral.400', dark: 'neutral.500', role: 'fg' },
144
- 'action-tertiary-fg-active': { light: 'primary.700', dark: 'primary.200', role: 'fg', contrastAgainst: 'action-tertiary-bg-active', minContrast: 4.5 },
145
- 'action-tertiary-fg-selected': { light: 'primary.700', dark: 'primary.200', role: 'fg', contrastAgainst: 'action-tertiary-bg-selected', minContrast: 4.5 },
146
- 'action-tertiary-fg-inverse': { light: 'neutral.50', dark: 'neutral.950', role: 'fg' },
172
+ // The Ghost button: ink on the card or the ground, a quiet fill on hover.
173
+ 'action-tertiary-bg': grey(BG.primary, 'bg'),
174
+ 'action-tertiary-bg-alt': grey(BG.secondary, 'bg'),
175
+ 'action-tertiary-bg-hover': grey(BG.secondary, 'bg'),
176
+ 'action-tertiary-bg-active': grey(BG.tertiary, 'bg'),
177
+ 'action-tertiary-bg-selected': grey(BG.tertiary, 'bg'),
178
+ 'action-tertiary-bg-disabled': grey(BG.primary, 'bg'),
179
+ 'action-tertiary-bg-inverse': grey(BG.primary, 'bg'),
180
+ 'action-tertiary-border': grey(BORDER.secondary, 'border'),
181
+ 'action-tertiary-border-alt': grey(BORDER.primary, 'border'),
182
+ 'action-tertiary-border-disabled': grey(BORDER.primary, 'border'),
183
+ 'action-tertiary-border-inverse': grey(BG.secondary, 'border'),
184
+ 'action-tertiary-fg': grey(FG.primary, 'fg', text(['action-tertiary-bg', 'action-tertiary-bg-alt'])),
185
+ 'action-tertiary-fg-alt': grey(FG.primary, 'fg'),
186
+ 'action-tertiary-fg-disabled': grey(FG.quinary, 'fg'),
187
+ 'action-tertiary-fg-active': grey(FG.primary, 'fg', text('action-tertiary-bg-active')),
188
+ 'action-tertiary-fg-selected': grey(FG.primary, 'fg', text('action-tertiary-bg-selected')),
189
+ 'action-tertiary-fg-inverse': grey(BG.primary, 'fg'),
147
190
  // ── Action Neutral ─────────────────────────────────────────
148
- // The Secondary button: a grey fill that deepens on hover, on the same
149
- // steps as backgrounds-tertiary and -quaternary. Its text is checked
150
- // against both fills.
151
- 'action-neutral-bg': { light: 'neutral.200', dark: 'neutral.950', role: 'bg' },
152
- 'action-neutral-bg-hover': { light: 'neutral.300', dark: 'neutral.700', role: 'bg' },
153
- 'action-neutral-fg': { light: 'neutral.950', dark: 'neutral.50', role: 'fg', contrastAgainst: ['action-neutral-bg', 'action-neutral-bg-hover'], minContrast: 4.5 },
191
+ // The Secondary button: a grey fill that deepens on hover.
192
+ 'action-neutral-bg': grey(BG.tertiary, 'bg'),
193
+ 'action-neutral-bg-hover': grey(BG.quaternary, 'bg'),
194
+ 'action-neutral-fg': grey(FG.primary, 'fg', text(['action-neutral-bg', 'action-neutral-bg-hover'])),
154
195
  // ── Destructive ────────────────────────────────────────────
155
196
  'destructive-bg': { light: 'error.50', dark: 'error.950', role: 'bg' },
156
197
  'destructive-bg-alt': { light: 'error.100', dark: 'error.900', role: 'bg' },
157
198
  'destructive-bg-hover': { light: 'error.100', dark: 'error.900', role: 'bg' },
158
199
  'destructive-bg-active': { light: 'error.800', dark: 'error.300', role: 'bg' },
159
200
  'destructive-bg-selected': { light: 'error.800', dark: 'error.300', role: 'bg' },
160
- 'destructive-bg-disabled': { light: 'neutral.200', dark: 'neutral.700', role: 'bg' },
201
+ 'destructive-bg-disabled': grey(BG.tertiary, 'bg'),
161
202
  'destructive-bg-inverse': { light: 'error.800', dark: 'error.200', role: 'bg' },
162
203
  'destructive-border': { light: 'error.500', dark: 'error.400', role: 'border' },
163
204
  'destructive-border-alt': { light: 'error.800', dark: 'error.300', role: 'border' },
@@ -166,10 +207,10 @@ export function buildSemanticMap() {
166
207
  // Checked against -bg-alt, the harder of the two grounds it sits on (Banner
167
208
  // uses the tint; Button and Badge the lighter -bg).
168
209
  'destructive-fg': { light: 'error.700', dark: 'error.200', role: 'fg', contrastAgainst: 'destructive-bg-alt', minContrast: 4.5 },
169
- 'destructive-fg-alt': { light: 'neutral.950', dark: 'neutral.50', role: 'fg' },
170
- 'destructive-fg-disabled': { light: 'neutral.400', dark: 'neutral.500', role: 'fg' },
171
- 'destructive-fg-active': { light: 'neutral.50', dark: 'neutral.950', role: 'fg', contrastAgainst: 'destructive-bg-active', minContrast: 4.5 },
172
- 'destructive-fg-selected': { light: 'neutral.50', dark: 'neutral.950', role: 'fg', contrastAgainst: 'destructive-bg-selected', minContrast: 4.5 },
210
+ 'destructive-fg-alt': grey(FG.primary, 'fg'),
211
+ 'destructive-fg-disabled': grey(FG.quinary, 'fg'),
212
+ 'destructive-fg-active': grey(BG.primary, 'fg', text('destructive-bg-active')),
213
+ 'destructive-fg-selected': grey(BG.primary, 'fg', text('destructive-bg-selected')),
173
214
  'destructive-fg-inverse': { light: 'error.50', dark: 'error.950', role: 'fg', contrastAgainst: 'destructive-bg-inverse', minContrast: 4.5 },
174
215
  // ── Positive ───────────────────────────────────────────────
175
216
  'positive-bg': { light: 'success.50', dark: 'success.950', role: 'bg' },
@@ -180,7 +221,7 @@ export function buildSemanticMap() {
180
221
  'positive-border-inverse': { light: 'success.50', dark: 'success.950', role: 'border' },
181
222
  // Same as destructive-fg: checked against the tint Banner draws it on.
182
223
  'positive-fg': { light: 'success.700', dark: 'success.200', role: 'fg', contrastAgainst: 'positive-bg-alt', minContrast: 4.5 },
183
- 'positive-fg-alt': { light: 'neutral.950', dark: 'neutral.50', role: 'fg' },
224
+ 'positive-fg-alt': grey(FG.primary, 'fg'),
184
225
  'positive-fg-inverse': { light: 'success.50', dark: 'success.950', role: 'fg', contrastAgainst: 'positive-bg-inverse', minContrast: 4.5 },
185
226
  // ── Cautionary ─────────────────────────────────────────────
186
227
  'cautionary-bg': { light: 'warning.50', dark: 'warning.950', role: 'bg' },
@@ -190,7 +231,7 @@ export function buildSemanticMap() {
190
231
  'cautionary-border-alt': { light: 'warning.800', dark: 'warning.300', role: 'border' },
191
232
  'cautionary-border-inverse': { light: 'warning.50', dark: 'warning.950', role: 'border' },
192
233
  'cautionary-fg': { light: 'warning.700', dark: 'warning.200', role: 'fg', contrastAgainst: 'cautionary-bg', minContrast: 4.5 },
193
- 'cautionary-fg-alt': { light: 'neutral.950', dark: 'neutral.50', role: 'fg' },
234
+ 'cautionary-fg-alt': grey(FG.primary, 'fg'),
194
235
  'cautionary-fg-inverse': { light: 'warning.50', dark: 'warning.950', role: 'fg', contrastAgainst: 'cautionary-bg-inverse', minContrast: 4.5 },
195
236
  // ── Informative ────────────────────────────────────────────
196
237
  'informative-bg': { light: 'info.50', dark: 'info.950', role: 'bg' },
@@ -200,7 +241,7 @@ export function buildSemanticMap() {
200
241
  'informative-border-alt': { light: 'info.800', dark: 'info.300', role: 'border' },
201
242
  'informative-border-inverse': { light: 'info.50', dark: 'info.950', role: 'border' },
202
243
  'informative-fg': { light: 'info.700', dark: 'info.200', role: 'fg', contrastAgainst: 'informative-bg', minContrast: 4.5 },
203
- 'informative-fg-alt': { light: 'neutral.950', dark: 'neutral.50', role: 'fg' },
244
+ 'informative-fg-alt': grey(FG.primary, 'fg'),
204
245
  'informative-fg-inverse': { light: 'info.50', dark: 'info.950', role: 'fg', contrastAgainst: 'informative-bg-inverse', minContrast: 4.5 },
205
246
  // ── Important ──────────────────────────────────────────────
206
247
  'important-bg': { light: 'primary.50', dark: 'primary.950', role: 'bg' },
@@ -210,7 +251,7 @@ export function buildSemanticMap() {
210
251
  'important-border-alt': { light: 'primary.800', dark: 'primary.300', role: 'border' },
211
252
  'important-border-inverse': { light: 'primary.50', dark: 'primary.950', role: 'border' },
212
253
  'important-fg': { light: 'primary.700', dark: 'primary.200', role: 'fg', contrastAgainst: 'important-bg', minContrast: 4.5 },
213
- 'important-fg-alt': { light: 'neutral.950', dark: 'neutral.50', role: 'fg' },
254
+ 'important-fg-alt': grey(FG.primary, 'fg'),
214
255
  'important-fg-inverse': { light: 'primary.50', dark: 'primary.950', role: 'fg', contrastAgainst: 'important-bg-inverse', minContrast: 4.5 },
215
256
  // ── Dataviz ────────────────────────────────────────────────
216
257
  'dataviz-1-main': { light: 'primary.500', dark: 'primary.400', role: 'decorative' },
package/dist/types.d.ts CHANGED
@@ -20,7 +20,16 @@ export type Scale = Record<ScaleStepValue, ScaleEntry>;
20
20
  export type ScaleName = 'primary' | 'secondary' | 'tertiary' | 'neutral' | 'success' | 'warning' | 'error' | 'info';
21
21
  export type SystemHueName = 'error' | 'warning' | 'success' | 'info';
22
22
  export type PrimitiveTokens = Partial<Record<ScaleName, Scale>>;
23
- export type TokenRef = `${ScaleName}.${ScaleStepValue}` | 'white' | 'black';
23
+ /** One step of a ramp, e.g. `neutral.200`. */
24
+ export type StepRef = `${ScaleName}.${ScaleStepValue}`;
25
+ /**
26
+ * Two steps of one ramp mixed in OKLCH: `neutral.600/700@80` is 80% of step
27
+ * 600 and 20% of step 700, what `color-mix(in oklch, A 80%, B)` gives in CSS.
28
+ * The base theme uses a few such in-between greys (dim's surfaces, dark's
29
+ * hairlines), and a generated theme has to resolve them to check contrast.
30
+ */
31
+ export type MixRef = `${ScaleName}.${number}/${number}@${number}`;
32
+ export type TokenRef = StepRef | MixRef | 'white' | 'black';
24
33
  export type SemanticRole = 'bg' | 'fg' | 'border' | 'overlay' | 'decorative';
25
34
  export type Mode = 'light' | 'dim' | 'dark';
26
35
  export type SemanticEntry = {
@@ -31,6 +40,13 @@ export type SemanticEntry = {
31
40
  * ramp (950 stays put), so dim reads as light mode toned down.
32
41
  */
33
42
  dim?: TokenRef;
43
+ /**
44
+ * The base `eluan` theme already derives this token from the grey ramp (or
45
+ * from another token), so a generated theme does not restate it: it emits
46
+ * the ramp and the token follows. It is emitted only when a contrast
47
+ * correction moved it, and then in every mode.
48
+ */
49
+ inherit?: boolean;
34
50
  /**
35
51
  * The ground token(s) this fg/border must clear `minContrast` on. With
36
52
  * several, the hardest of them decides, for text that sits on more than one
@@ -54,10 +70,34 @@ export type GeneratorConfig = {
54
70
  /**
55
71
  * Contrast floor for every checked fg/border pairing (4.5 = WCAG AA,
56
72
  * 7 = AAA). Per-entry `minContrast` values can raise the floor for a token
57
- * but never lower it, unless the entry sets `allowBelowDefault`.
73
+ * but never lower it, unless the entry sets `allowBelowDefault`. The text
74
+ * on the primary action is one such entry: it stays white down to 3:1,
75
+ * which is the look, and turns to ink below that.
58
76
  */
59
77
  minContrast: number;
78
+ /**
79
+ * Share of the first accent's chroma the greys keep, capped low. Used only
80
+ * when neither `neutral` nor `neutralTint` is set.
81
+ */
60
82
  neutralTintRatio: number;
83
+ /**
84
+ * The colour the greys are tinted toward, as a hex, when it should not be
85
+ * the first accent: a warm concrete grey under an orange accent, say.
86
+ * `'none'` gives pure grey. On its own it also sets the strength: the greys
87
+ * keep this colour's chroma, up to the maximum `neutralTint` allows.
88
+ */
89
+ neutral?: string;
90
+ /**
91
+ * How strongly the greys are tinted, 0 (pure grey) to 1 (the strongest tint
92
+ * that still reads as a neutral). The hue comes from `neutral`, or from the
93
+ * first accent without it. Overrides `neutralTintRatio`.
94
+ */
95
+ neutralTint?: number;
96
+ /**
97
+ * One lightness and chroma curve for every ramp, replacing the defaults.
98
+ * Without it each accent ramp is anchored so its step 500 is the colour as
99
+ * picked, and the greys follow the look's own curve (`NEUTRAL_CURVE`).
100
+ */
61
101
  curve?: ScaleStep[];
62
102
  systemHues?: Partial<Record<SystemHueName, number>>;
63
103
  /**
@@ -73,12 +113,6 @@ export type GeneratorConfig = {
73
113
  * minimum 0.5.
74
114
  */
75
115
  dimChroma?: number;
76
- /**
77
- * How far dim mode's greys move toward the warm teak ramp `minimal`'s dim
78
- * uses: 1 takes teak's hue and chroma, 0 keeps the brand-tinted greys.
79
- * Default 1.
80
- */
81
- dimWarmth?: number;
82
116
  };
83
117
  export type AccentClassification = 'normal' | 'low-chroma' | 'extreme-lightness';
84
118
  export type ValidatedAccent = {
@@ -99,7 +133,7 @@ export type GeneratorResult = {
99
133
  primitives: PrimitiveTokens;
100
134
  /** The primitives dark mode resolves against: `primitives` with the colour ramps lifted by `darkLift`. */
101
135
  primitivesDark: PrimitiveTokens;
102
- /** The primitives dim mode resolves against: colour ramps toned down by `dimChroma`, neutral warmed by `dimWarmth`. */
136
+ /** The primitives dim mode resolves against: `primitives` with the colour ramps toned down by `dimChroma`. */
103
137
  primitivesDim: PrimitiveTokens;
104
138
  semanticMap: SemanticMap;
105
139
  corrections: ContrastCorrection[];
@@ -130,6 +164,6 @@ export type GeneratorResult = {
130
164
  /** Structurally identical to @eluan/core's `CustomTheme`. */
131
165
  export type GeneratedCustomTheme = {
132
166
  name: string;
133
- extends: 'minimal';
167
+ extends: 'eluan';
134
168
  css: string;
135
169
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@eluan/theme-generator",
3
3
  "description": "CLI and browser-safe library that generates accessible light, dim and dark mode Eluan theme token sets from accent colors",
4
- "version": "0.4.0",
4
+ "version": "0.5.0",
5
5
  "license": "MIT",
6
6
  "author": "Frolda",
7
7
  "homepage": "https://github.com/vasfio/eluan#readme",