@eluan/theme-generator 0.3.1 → 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.
@@ -1,101 +1,216 @@
1
+ import { SCALE_STEPS } from '../types.js';
2
+ import { parseRef } from './refs.js';
3
+ /**
4
+ * The dim ref for a light ref: one step deeper on the same ramp, 950 staying
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.
10
+ */
11
+ export function dimRef(light) {
12
+ const parsed = parseRef(light);
13
+ if (!parsed || parsed.steps.length > 1)
14
+ return light;
15
+ const index = SCALE_STEPS.indexOf(parsed.steps[0]);
16
+ const deeper = SCALE_STEPS[Math.min(index + 1, SCALE_STEPS.length - 1)];
17
+ return `${parsed.scaleName}.${deeper}`;
18
+ }
19
+ /** The ref an entry resolves to in `mode`; dim falls back to `dimRef(entry.light)`. */
20
+ export function modeRef(entry, mode) {
21
+ if (mode === 'dim')
22
+ return entry.dim ?? dimRef(entry.light);
23
+ return entry[mode];
24
+ }
25
+ /** The ground tokens an entry is checked against, as a list. */
26
+ export function contrastGrounds(entry) {
27
+ return entry.contrastAgainst === undefined ? [] : [].concat(entry.contrastAgainst);
28
+ }
29
+ /**
30
+ * Pins every entry's dim ref from its light ref, so later light-mode contrast
31
+ * corrections can't move dim along with them.
32
+ */
33
+ export function withDimRefs(map) {
34
+ const filled = {};
35
+ for (const [token, entry] of Object.entries(map)) {
36
+ filled[token] = { ...entry, dim: modeRef(entry, 'dim') };
37
+ }
38
+ return filled;
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 });
1
90
  export function buildSemanticMap() {
2
- return {
91
+ return withDimRefs({
92
+ // ── Base greys ─────────────────────────────────────────────
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'),
3
108
  // ── Container ──────────────────────────────────────────────
4
- 'container-bg': { light: 'neutral.50', dark: 'neutral.800', role: 'bg' },
5
- 'container-bg-alt': { light: 'neutral.100', dark: 'neutral.900', role: 'bg' },
6
- 'container-bg-inverse': { light: 'neutral.800', dark: 'neutral.100', role: 'bg' },
7
- 'container-border': { light: 'neutral.200', dark: 'neutral.700', role: 'border' },
8
- 'container-border-alt': { light: 'neutral.300', dark: 'neutral.600', role: 'border' },
9
- 'container-border-inverse': { light: 'neutral.600', dark: 'neutral.200', role: 'border' },
10
- 'container-fg': { light: 'neutral.950', dark: 'neutral.50', role: 'fg', contrastAgainst: 'container-bg', minContrast: 4.5 },
11
- 'container-fg-alt': { light: 'neutral.800', dark: 'neutral.100', role: 'fg', contrastAgainst: 'container-bg', minContrast: 4.5 },
12
- 'container-fg-inverse': { light: 'neutral.50', dark: 'neutral.950', role: 'fg', contrastAgainst: 'container-bg-inverse', minContrast: 4.5 },
13
- // Tooltip surface — matches container-bg in light and container-border in
14
- // dark, so the tooltip's border disappears against its own background.
15
- 'tooltip-bg': { light: 'neutral.50', dark: 'neutral.700', role: 'bg' },
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')),
16
119
  // ── Interactive ────────────────────────────────────────────
17
- 'interactive-bg': { light: 'neutral.50', dark: 'neutral.800', role: 'bg' },
18
- 'interactive-bg-alt': { light: 'neutral.100', dark: 'neutral.900', role: 'bg' },
19
- 'interactive-bg-alt2': { light: 'primary.50', dark: 'primary.950', role: 'bg' },
20
- 'interactive-bg-disabled': { light: 'neutral.200', dark: 'neutral.700', role: 'bg' },
21
- 'interactive-bg-hover': { light: 'neutral.200', dark: 'neutral.700', role: 'bg' },
22
- 'interactive-bg-active': { light: 'primary.800', dark: 'primary.300', role: 'bg' },
23
- 'interactive-bg-selected': { light: 'primary.800', dark: 'primary.300', role: 'bg' },
24
- 'interactive-bg-inverse': { light: 'neutral.950', dark: 'neutral.50', role: 'bg' },
25
- 'interactive-border': { light: 'neutral.200', dark: 'neutral.700', role: 'border' },
26
- 'interactive-border-alt': { light: 'neutral.300', dark: 'neutral.600', role: 'border' },
27
- 'interactive-border-disabled': { light: 'neutral.300', dark: 'neutral.600', role: 'border' },
28
- 'interactive-fg': { light: 'neutral.950', dark: 'neutral.50', role: 'fg', contrastAgainst: 'interactive-bg', minContrast: 4.5 },
29
- // Secondary text targets the WCAG 3:1 large-text/UI tier; allowBelowDefault
30
- // keeps it there even when the config asks for a stricter floor (e.g. AAA).
31
- 'interactive-fg-alt': { light: 'neutral.600', dark: 'neutral.300', role: 'fg', contrastAgainst: 'interactive-bg', minContrast: 3.0, allowBelowDefault: true },
32
- 'interactive-fg-readonly': { light: 'neutral.800', dark: 'neutral.100', role: 'fg', contrastAgainst: 'interactive-bg', minContrast: 4.5 },
33
- 'interactive-fg-disabled': { light: 'neutral.400', dark: 'neutral.500', role: 'fg' },
34
- 'interactive-fg-active': { light: 'primary.100', dark: 'primary.900', role: 'fg', contrastAgainst: 'interactive-bg-active', minContrast: 4.5 },
35
- 'interactive-fg-selected': { light: 'primary.100', dark: 'primary.900', role: 'fg', contrastAgainst: 'interactive-bg-selected', minContrast: 4.5 },
36
- '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')),
37
142
  // ── Action Primary ─────────────────────────────────────────
38
- 'action-primary-bg': { light: 'primary.500', dark: 'primary.500', role: 'bg' },
39
- 'action-primary-bg-hover': { light: 'primary.800', dark: 'primary.400', role: 'bg' },
40
- 'action-primary-bg-active': { light: 'primary.800', dark: 'primary.400', role: 'bg' },
41
- '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' },
42
148
  'action-primary-bg-disabled': { light: 'primary.100', dark: 'primary.900', role: 'bg' },
43
- 'action-primary-bg-inverse': { light: 'primary.50', dark: 'primary.950', role: 'bg' },
44
- 'action-primary-fg': { light: 'neutral.50', dark: 'neutral.50', role: 'fg', contrastAgainst: 'action-primary-bg', minContrast: 4.5 },
45
- 'action-primary-fg-disabled': { light: 'neutral.400', dark: 'neutral.600', role: 'fg' },
46
- 'action-primary-fg-active': { light: 'neutral.50', dark: 'neutral.50', role: 'fg', contrastAgainst: 'action-primary-bg-active', minContrast: 4.5 },
47
- '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 },
48
154
  'action-primary-fg-inverse': { light: 'primary.700', dark: 'primary.200', role: 'fg', contrastAgainst: 'action-primary-bg-inverse', minContrast: 4.5 },
49
155
  // ── Action Secondary ───────────────────────────────────────
50
- 'action-secondary-bg-hover': { light: 'primary.100', dark: 'primary.900', role: 'bg' },
51
- 'action-secondary-bg-active': { light: 'primary.500', dark: 'primary.500', role: 'bg' },
52
- 'action-secondary-bg-selected': { light: 'primary.500', dark: 'primary.500', role: 'bg' },
53
- 'action-secondary-bg-disabled': { light: 'neutral.200', dark: 'neutral.700', role: 'bg' },
54
- 'action-secondary-border': { light: 'primary.500', dark: 'primary.400', role: 'border' },
55
- 'action-secondary-border-alt': { light: 'primary.800', dark: 'primary.300', role: 'border' },
56
- 'action-secondary-border-disabled': { light: 'primary.100', dark: 'primary.900', role: 'border' },
57
- 'action-secondary-border-inverse': { light: 'primary.50', dark: 'primary.950', role: 'border' },
58
- 'action-secondary-fg': { light: 'primary.500', dark: 'primary.400', role: 'fg', contrastAgainst: 'container-bg', minContrast: 4.5 },
59
- 'action-secondary-fg-alt': { light: 'neutral.950', dark: 'neutral.50', role: 'fg' },
60
- 'action-secondary-fg-disabled': { light: 'neutral.400', dark: 'neutral.500', role: 'fg' },
61
- 'action-secondary-fg-active': { light: 'neutral.50', dark: 'neutral.50', role: 'fg', contrastAgainst: 'action-secondary-bg-active', minContrast: 4.5 },
62
- 'action-secondary-fg-selected': { light: 'neutral.50', dark: 'neutral.50', role: 'fg', contrastAgainst: 'action-secondary-bg-selected', minContrast: 4.5 },
63
- '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'),
64
171
  // ── Action Tertiary ────────────────────────────────────────
65
- 'action-tertiary-bg': { light: 'neutral.50', dark: 'neutral.800', role: 'bg' },
66
- 'action-tertiary-bg-alt': { light: 'neutral.100', dark: 'neutral.900', role: 'bg' },
67
- 'action-tertiary-bg-hover': { light: 'primary.50', dark: 'primary.950', role: 'bg' },
68
- 'action-tertiary-bg-active': { light: 'primary.100', dark: 'primary.900', role: 'bg' },
69
- 'action-tertiary-bg-selected': { light: 'primary.100', dark: 'primary.900', role: 'bg' },
70
- 'action-tertiary-bg-disabled': { light: 'neutral.50', dark: 'neutral.800', role: 'bg' },
71
- 'action-tertiary-bg-inverse': { light: 'neutral.50', dark: 'neutral.800', role: 'bg' },
72
- 'action-tertiary-border': { light: 'primary.500', dark: 'primary.400', role: 'border' },
73
- 'action-tertiary-border-alt': { light: 'primary.800', dark: 'primary.300', role: 'border' },
74
- 'action-tertiary-border-disabled': { light: 'neutral.300', dark: 'neutral.600', role: 'border' },
75
- 'action-tertiary-border-inverse': { light: 'primary.100', dark: 'primary.900', role: 'border' },
76
- 'action-tertiary-fg': { light: 'primary.500', dark: 'primary.400', role: 'fg', contrastAgainst: 'action-tertiary-bg', minContrast: 4.5 },
77
- 'action-tertiary-fg-alt': { light: 'neutral.950', dark: 'neutral.50', role: 'fg' },
78
- 'action-tertiary-fg-disabled': { light: 'neutral.400', dark: 'neutral.500', role: 'fg' },
79
- 'action-tertiary-fg-active': { light: 'primary.700', dark: 'primary.200', role: 'fg', contrastAgainst: 'action-tertiary-bg-active', minContrast: 4.5 },
80
- 'action-tertiary-fg-selected': { light: 'primary.700', dark: 'primary.200', role: 'fg', contrastAgainst: 'action-tertiary-bg-selected', minContrast: 4.5 },
81
- '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'),
190
+ // ── Action Neutral ─────────────────────────────────────────
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'])),
82
195
  // ── Destructive ────────────────────────────────────────────
83
196
  'destructive-bg': { light: 'error.50', dark: 'error.950', role: 'bg' },
84
197
  'destructive-bg-alt': { light: 'error.100', dark: 'error.900', role: 'bg' },
85
198
  'destructive-bg-hover': { light: 'error.100', dark: 'error.900', role: 'bg' },
86
199
  'destructive-bg-active': { light: 'error.800', dark: 'error.300', role: 'bg' },
87
200
  'destructive-bg-selected': { light: 'error.800', dark: 'error.300', role: 'bg' },
88
- 'destructive-bg-disabled': { light: 'neutral.200', dark: 'neutral.700', role: 'bg' },
201
+ 'destructive-bg-disabled': grey(BG.tertiary, 'bg'),
89
202
  'destructive-bg-inverse': { light: 'error.800', dark: 'error.200', role: 'bg' },
90
203
  'destructive-border': { light: 'error.500', dark: 'error.400', role: 'border' },
91
204
  'destructive-border-alt': { light: 'error.800', dark: 'error.300', role: 'border' },
92
205
  'destructive-border-disabled': { light: 'error.100', dark: 'error.900', role: 'border' },
93
206
  'destructive-border-inverse': { light: 'error.50', dark: 'error.950', role: 'border' },
94
- 'destructive-fg': { light: 'error.700', dark: 'error.200', role: 'fg', contrastAgainst: 'destructive-bg', minContrast: 4.5 },
95
- 'destructive-fg-alt': { light: 'neutral.950', dark: 'neutral.50', role: 'fg' },
96
- 'destructive-fg-disabled': { light: 'neutral.400', dark: 'neutral.500', role: 'fg' },
97
- 'destructive-fg-active': { light: 'neutral.50', dark: 'neutral.950', role: 'fg', contrastAgainst: 'destructive-bg-active', minContrast: 4.5 },
98
- 'destructive-fg-selected': { light: 'neutral.50', dark: 'neutral.950', role: 'fg', contrastAgainst: 'destructive-bg-selected', minContrast: 4.5 },
207
+ // Checked against -bg-alt, the harder of the two grounds it sits on (Banner
208
+ // uses the tint; Button and Badge the lighter -bg).
209
+ 'destructive-fg': { light: 'error.700', dark: 'error.200', role: 'fg', contrastAgainst: 'destructive-bg-alt', 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')),
99
214
  'destructive-fg-inverse': { light: 'error.50', dark: 'error.950', role: 'fg', contrastAgainst: 'destructive-bg-inverse', minContrast: 4.5 },
100
215
  // ── Positive ───────────────────────────────────────────────
101
216
  'positive-bg': { light: 'success.50', dark: 'success.950', role: 'bg' },
@@ -104,8 +219,9 @@ export function buildSemanticMap() {
104
219
  'positive-border': { light: 'success.500', dark: 'success.400', role: 'border' },
105
220
  'positive-border-alt': { light: 'success.800', dark: 'success.300', role: 'border' },
106
221
  'positive-border-inverse': { light: 'success.50', dark: 'success.950', role: 'border' },
107
- 'positive-fg': { light: 'success.700', dark: 'success.200', role: 'fg', contrastAgainst: 'positive-bg', minContrast: 4.5 },
108
- 'positive-fg-alt': { light: 'neutral.950', dark: 'neutral.50', role: 'fg' },
222
+ // Same as destructive-fg: checked against the tint Banner draws it on.
223
+ 'positive-fg': { light: 'success.700', dark: 'success.200', role: 'fg', contrastAgainst: 'positive-bg-alt', minContrast: 4.5 },
224
+ 'positive-fg-alt': grey(FG.primary, 'fg'),
109
225
  'positive-fg-inverse': { light: 'success.50', dark: 'success.950', role: 'fg', contrastAgainst: 'positive-bg-inverse', minContrast: 4.5 },
110
226
  // ── Cautionary ─────────────────────────────────────────────
111
227
  'cautionary-bg': { light: 'warning.50', dark: 'warning.950', role: 'bg' },
@@ -115,7 +231,7 @@ export function buildSemanticMap() {
115
231
  'cautionary-border-alt': { light: 'warning.800', dark: 'warning.300', role: 'border' },
116
232
  'cautionary-border-inverse': { light: 'warning.50', dark: 'warning.950', role: 'border' },
117
233
  'cautionary-fg': { light: 'warning.700', dark: 'warning.200', role: 'fg', contrastAgainst: 'cautionary-bg', minContrast: 4.5 },
118
- 'cautionary-fg-alt': { light: 'neutral.950', dark: 'neutral.50', role: 'fg' },
234
+ 'cautionary-fg-alt': grey(FG.primary, 'fg'),
119
235
  'cautionary-fg-inverse': { light: 'warning.50', dark: 'warning.950', role: 'fg', contrastAgainst: 'cautionary-bg-inverse', minContrast: 4.5 },
120
236
  // ── Informative ────────────────────────────────────────────
121
237
  'informative-bg': { light: 'info.50', dark: 'info.950', role: 'bg' },
@@ -125,7 +241,7 @@ export function buildSemanticMap() {
125
241
  'informative-border-alt': { light: 'info.800', dark: 'info.300', role: 'border' },
126
242
  'informative-border-inverse': { light: 'info.50', dark: 'info.950', role: 'border' },
127
243
  'informative-fg': { light: 'info.700', dark: 'info.200', role: 'fg', contrastAgainst: 'informative-bg', minContrast: 4.5 },
128
- 'informative-fg-alt': { light: 'neutral.950', dark: 'neutral.50', role: 'fg' },
244
+ 'informative-fg-alt': grey(FG.primary, 'fg'),
129
245
  'informative-fg-inverse': { light: 'info.50', dark: 'info.950', role: 'fg', contrastAgainst: 'informative-bg-inverse', minContrast: 4.5 },
130
246
  // ── Important ──────────────────────────────────────────────
131
247
  'important-bg': { light: 'primary.50', dark: 'primary.950', role: 'bg' },
@@ -135,7 +251,7 @@ export function buildSemanticMap() {
135
251
  'important-border-alt': { light: 'primary.800', dark: 'primary.300', role: 'border' },
136
252
  'important-border-inverse': { light: 'primary.50', dark: 'primary.950', role: 'border' },
137
253
  'important-fg': { light: 'primary.700', dark: 'primary.200', role: 'fg', contrastAgainst: 'important-bg', minContrast: 4.5 },
138
- 'important-fg-alt': { light: 'neutral.950', dark: 'neutral.50', role: 'fg' },
254
+ 'important-fg-alt': grey(FG.primary, 'fg'),
139
255
  'important-fg-inverse': { light: 'primary.50', dark: 'primary.950', role: 'fg', contrastAgainst: 'important-bg-inverse', minContrast: 4.5 },
140
256
  // ── Dataviz ────────────────────────────────────────────────
141
257
  'dataviz-1-main': { light: 'primary.500', dark: 'primary.400', role: 'decorative' },
@@ -162,5 +278,5 @@ export function buildSemanticMap() {
162
278
  'dataviz-8-main': { light: 'info.600', dark: 'info.300', role: 'decorative' },
163
279
  'dataviz-8-tint': { light: 'info.200', dark: 'info.800', role: 'decorative' },
164
280
  'dataviz-8-shade': { light: 'info.900', dark: 'info.100', role: 'decorative' },
165
- };
281
+ });
166
282
  }
package/dist/types.d.ts CHANGED
@@ -20,18 +20,45 @@ 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';
34
+ export type Mode = 'light' | 'dim' | 'dark';
25
35
  export type SemanticEntry = {
26
36
  light: TokenRef;
27
37
  dark: TokenRef;
28
- contrastAgainst?: string;
38
+ /**
39
+ * Dim-mode ref. When omitted, dim uses the light ref one step deeper on its
40
+ * ramp (950 stays put), so dim reads as light mode toned down.
41
+ */
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;
50
+ /**
51
+ * The ground token(s) this fg/border must clear `minContrast` on. With
52
+ * several, the hardest of them decides, for text that sits on more than one
53
+ * surface (page and panel, say).
54
+ */
55
+ contrastAgainst?: string | string[];
29
56
  minContrast?: number;
30
57
  /**
31
58
  * Honor `minContrast` as-is even when it is below the config-wide minimum.
32
59
  * For entries that deliberately target a lower WCAG tier (e.g. the 3:1
33
- * large-text/UI tier for secondary text) and must not be raised by a
34
- * stricter `GeneratorConfig.minContrast`.
60
+ * UI tier for the focus ring) and must not be raised by a stricter
61
+ * `GeneratorConfig.minContrast`.
35
62
  */
36
63
  allowBelowDefault?: boolean;
37
64
  role: SemanticRole;
@@ -43,12 +70,49 @@ export type GeneratorConfig = {
43
70
  /**
44
71
  * Contrast floor for every checked fg/border pairing (4.5 = WCAG AA,
45
72
  * 7 = AAA). Per-entry `minContrast` values can raise the floor for a token
46
- * 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.
47
76
  */
48
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
+ */
49
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
+ */
50
101
  curve?: ScaleStep[];
51
102
  systemHues?: Partial<Record<SystemHueName, number>>;
103
+ /**
104
+ * OKLCH lightness added to the colour ramps dark mode uses, so accents and
105
+ * status colours read as vivid on a dark ground as they do on a light one.
106
+ * Full on the mid steps, tapering to 0 at 50 and 950; neutral is never
107
+ * lifted. 0 turns it off. Default 0.08, maximum 0.2.
108
+ */
109
+ darkLift?: number;
110
+ /**
111
+ * Chroma multiplier for the colour ramps dim mode uses, so accents and
112
+ * status colours sit back on the softer ground. 1 turns it off. Default 0.8,
113
+ * minimum 0.5.
114
+ */
115
+ dimChroma?: number;
52
116
  };
53
117
  export type AccentClassification = 'normal' | 'low-chroma' | 'extreme-lightness';
54
118
  export type ValidatedAccent = {
@@ -58,7 +122,7 @@ export type ValidatedAccent = {
58
122
  };
59
123
  export type ContrastCorrection = {
60
124
  token: string;
61
- mode: 'light' | 'dark';
125
+ mode: Mode;
62
126
  originalRef: TokenRef;
63
127
  correctedRef: TokenRef;
64
128
  originalContrast: number;
@@ -67,14 +131,39 @@ export type ContrastCorrection = {
67
131
  };
68
132
  export type GeneratorResult = {
69
133
  primitives: PrimitiveTokens;
134
+ /** The primitives dark mode resolves against: `primitives` with the colour ramps lifted by `darkLift`. */
135
+ primitivesDark: PrimitiveTokens;
136
+ /** The primitives dim mode resolves against: `primitives` with the colour ramps toned down by `dimChroma`. */
137
+ primitivesDim: PrimitiveTokens;
70
138
  semanticMap: SemanticMap;
71
139
  corrections: ContrastCorrection[];
72
140
  css: {
73
141
  primitives: string;
74
142
  lightMode: string;
143
+ dimMode: string;
75
144
  darkMode: string;
76
145
  theme: string;
77
146
  };
147
+ /** Light-mode token map for `createTheme({ tokens })`. Kept for compatibility; prefer `createThemeOptions`. */
78
148
  createThemeTokens: Record<string, string>;
149
+ /** Light, dim and dark token maps for `createTheme({ name, ...createThemeOptions })` from @eluan/core. */
150
+ createThemeOptions: {
151
+ tokens: Record<string, string>;
152
+ modes: {
153
+ dim: Record<string, string>;
154
+ dark: Record<string, string>;
155
+ };
156
+ };
157
+ /**
158
+ * A ready custom theme, the same shape `createTheme()` returns: pass it to
159
+ * `<EluanProvider customThemes={[customTheme]} />`. Covers light, dim and dark mode.
160
+ */
161
+ customTheme: GeneratedCustomTheme;
79
162
  report: string;
80
163
  };
164
+ /** Structurally identical to @eluan/core's `CustomTheme`. */
165
+ export type GeneratedCustomTheme = {
166
+ name: string;
167
+ extends: 'eluan';
168
+ css: string;
169
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@eluan/theme-generator",
3
- "description": "CLI and browser-safe library that generates accessible, light + dark mode Eluan theme token sets from accent colors",
4
- "version": "0.3.1",
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.5.0",
5
5
  "license": "MIT",
6
6
  "author": "Frolda",
7
7
  "homepage": "https://github.com/vasfio/eluan#readme",
@@ -55,7 +55,7 @@
55
55
  "@types/prompts": "^2.4.9",
56
56
  "esbuild": "^0.28.1",
57
57
  "typescript": "^5.4.5",
58
- "vitest": "^3.2.6"
58
+ "vitest": "^4.1.12"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "rm -rf dist && tsc -p tsconfig.build.json",