@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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @eluan/theme-generator
2
2
 
3
- CLI and library that generates accessible, light + dark mode [Eluan](https://github.com/vasfio/eluan) theme token sets from one to three accent colors. Contrast is checked (and auto-corrected) against a configurable minimum ratio, so generated themes are WCAG-aware out of the box.
3
+ CLI and library that generates an [Eluan](https://github.com/vasfio/eluan) theme from one to three accent colours and a grey: a tinted grey ramp, the accent as picked, and status and chart colours for light, dim and dark mode. Contrast is checked (and auto-corrected) against a configurable minimum ratio, so generated themes are WCAG-aware out of the box.
4
4
 
5
5
  The programmatic entry point (`@eluan/theme-generator`) is pure color math with no Node built-ins, so it runs in the browser as well as in Node. Only the `eluan-theme` binary touches the filesystem.
6
6
 
@@ -32,7 +32,11 @@ Options:
32
32
  | `--name <string>` | `custom` | Theme name |
33
33
  | `--out <dir>` | `./tokens` | Output directory |
34
34
  | `--min-contrast <num>` | `4.5` | Minimum contrast ratio to enforce |
35
- | `--neutral-tint <num>` | `0.04` | Neutral tint ratio |
35
+ | `--neutral <hex\|none>` | first accent | Colour the greys are tinted toward. `none` gives pure grey |
36
+ | `--neutral-tint <num>` | — | Tint strength, `0` (pure grey) to `1` (strongest). Without it, a `--neutral` colour keeps its own strength |
37
+ | `--neutral-tint-ratio <num>` | `0.04` | The older control: share of the accent's chroma, capped low. Used only when neither flag above is set |
38
+ | `--dark-lift <num>` | `0.08` | OKLCH lightness added to dark-mode colours, 0–0.2 |
39
+ | `--dim-chroma <num>` | `0.8` | Share of chroma dim-mode colours keep, 0.5–1 |
36
40
  | `--config <path>` | — | Path to a JSON config file |
37
41
 
38
42
  You can also drop a `eluan-theme.config.json` in your project root; CLI flags override its values.
@@ -41,7 +45,7 @@ You can also drop a `eluan-theme.config.json` in your project root; CLI flags ov
41
45
  { "name": "ocean", "accents": ["#FF4A2C"], "outDir": "./tokens" }
42
46
  ```
43
47
 
44
- The generator writes primitive + semantic token JSON, theme CSS, and a smoke-test preview HTML you can open to eyeball the result.
48
+ The generator writes primitive + semantic token JSON, theme CSS, a smoke-test preview HTML you can open to eyeball the result, and the two files for applying the theme in every mode: `custom-theme.css` (register it like a `createTheme()` result) and `create-theme.json` (`{ name, tokens, modes }` for `createTheme()`).
45
49
 
46
50
  ## Programmatic API
47
51
 
@@ -53,14 +57,77 @@ const result = generateTheme({
53
57
  themeName: "ocean",
54
58
  minContrast: 4.5,
55
59
  neutralTintRatio: 0.04,
60
+ darkLift: 0.08, // optional; brighter dark-mode colours (0 turns it off)
61
+ dimChroma: 0.8, // optional; toned-down dim-mode colours (1 turns it off)
56
62
  })
57
63
 
58
- result.css.theme // drop-in CSS for both modes, as a string
59
- result.createThemeTokens // light-mode token map for createTheme()
64
+ result.customTheme // { name, extends, css }: pass to <EluanProvider customThemes={[…]} />
65
+ result.createThemeOptions // { tokens, modes: { dim, dark } }: spread into createTheme() from @eluan/core
60
66
  result.report // markdown report: warnings, contrast corrections
67
+ result.css.theme // standalone CSS for every mode, scoped to [data-theme="ocean"]
68
+ result.createThemeTokens // light-mode token map only (kept for compatibility)
61
69
  ```
62
70
 
63
- Lower-level helpers are exported too — `generateScale`, `buildPrimitives`, `buildSemanticMap`, `checkContrast`, `autoCorrect`, `compileThemeCSS`, `compileCreateThemeTokens`, and the `hexToOklch` / `oklchToHex` color utilities. See the exported TypeScript types for the full shape of `GeneratorResult`.
71
+ ### What a theme states
72
+
73
+ A generated theme is small on purpose. It states:
74
+
75
+ - **The grey ramp**, `--color-neutral-0` to `--color-neutral-950`, once. Eluan's modes build every surface, text colour and border from that ramp, so paper, cards, hairlines, ink and the dark ground all follow it in light, dim and dark without the theme naming them.
76
+ - **The accent**: `--action-primary-*`. Step 500 of the primary ramp is the colour you picked, and the primary button uses it unchanged in every mode, with 600 for hover. Switches, checks, sliders and the focus ring take it from there.
77
+ - **Status and chart colours**: `--destructive-*`, `--positive-*`, `--cautionary-*`, `--informative-*`, `--important-*`, `--dataviz-*`, per mode.
78
+
79
+ Every grey token (`--container-*`, `--interactive-*`, Outline, Ghost and Secondary buttons) is left to the base theme. The generator still models them: `result.semanticMap` holds every token with `inherit: true` on the ones the theme leaves alone, and the contrast pass checks them against your ramp. If a correction has to move one, the theme states it in all three modes and the report lists it. `compileResolvedTokens(result.semanticMap, primitives, mode)` returns every token's value for a mode, stated or not, for swatches and audits. Pass that mode's primitives: `result.primitives`, `result.primitivesDim` or `result.primitivesDark`.
80
+
81
+ `customTheme` and `createThemeOptions` cover light, dim and dark mode and layer on top of the built-in `eluan` theme, so its fonts and everything else stay in place. `css.theme` is the same theme as a stylesheet scoped to `[data-theme="ocean"]`, for pages that don't use `EluanProvider`. Load it after `@eluan/tokens`, and put `data-mode` on the same element as `data-theme`: its selectors need both.
82
+
83
+ ### Neutral colour and tint strength
84
+
85
+ By default the greys carry a faint tint of the first accent. Two options change that:
86
+
87
+ ```ts
88
+ generateTheme({
89
+ accents: ['#FF5100'], // blaze orange for actions
90
+ neutral: '#909876', // greys tinted toward a concrete green instead
91
+ neutralTint: 0.8, // 0 = pure grey, 1 = strongest; optional
92
+ themeName: 'concrete',
93
+ minContrast: 4.5,
94
+ neutralTintRatio: 0.04,
95
+ });
96
+ ```
97
+
98
+ - `neutral` takes a hex, or `'none'` for pure grey. Only its hue and strength are used; lightness comes from the ramp.
99
+ - `neutralTint` is a 0–1 range. `1` is a peak chroma of `MAX_NEUTRAL_CHROMA` (0.06), which reads as a coloured grey; the default accent tint sits near `0.15`.
100
+ - With `neutral` set and no `neutralTint`, the ramp matches the colour's own strength (up to the maximum), so a muted colour gives its own ramp back.
101
+ - With `neutralTint` alone, the tint goes toward the first accent.
102
+ - With neither, `neutralTintRatio` applies: a faint tint of the first accent.
103
+
104
+ The ramp follows the lightness and chroma shape of Eluan's own concrete grey (`NEUTRAL_CURVE`): paper at 50, the hairline at 100, ink at 800, the dark ground at 950. The tint tapers toward both ends, so page grounds and the darkest text stay close to neutral. `neutral: '#909876'` with the accent `#FF5100` gives the built-in theme back.
105
+
106
+ ### The accent
107
+
108
+ The first accent is used as picked: its ramp is built around it so step 500 is exactly that colour, as long as its lightness is in the range a ramp can centre on (OKLCH 0.45–0.90, `ANCHOR_LIGHTNESS_RANGE`, which takes in yellows and limes; outside it the report warns and 500 is the nearest the curve gives, because a very dark fill would vanish on the dark ground). The primary button keeps 500 and 600 in dim and dark as well; dim's toning and dark's lift apply to the rest of the ramp.
109
+
110
+ Text on the accent is white wherever white reaches 3:1, which is the look: white on a saturated mid-tone such as `#FF5100` is about 3.3:1, under the 4.5:1 text floor. When that happens the report says so under "Primary action text". An accent too light for white (a yellow, say) gets the theme's ink instead, at the full floor. Text is checked on the fill and its hover together, so the label is the same colour in every state. To hold the primary button to 4.5:1 as well, pick a darker accent or set `--action-primary-fg` yourself.
111
+
112
+ ### Contrast correction
113
+
114
+ When a foreground falls short of the minimum against its background, the generator moves it the fewest steps along its own ramp that pass: darker in light mode, lighter in dark mode, and in dim whichever way suits the ground. Only when no step on the ramp passes does it fall back to the theme's ink or paper, then black or white. Text that sits on more than one surface is checked against each, and the hardest decides: body text must clear the minimum on the card, the paper ground and a raised fill; muted text on the card and the ground. Every correction is listed in `result.report`.
115
+
116
+ At the default 4.5:1 the grey tokens need no correction for any tint, so a generated theme and the built-in one share the same grey logic. A stricter floor (`minContrast: 7`) moves muted text and the theme then states it.
117
+
118
+ ### Brighter dark mode
119
+
120
+ Dark grounds swallow mid-tone colour, so dark mode resolves against `result.primitivesDark`: every colour ramp (accents and status hues, never neutral) lifted in OKLCH lightness by `darkLift`. The lift is full on steps 300–600 and tapers to nothing at 50 and 950, so surfaces and tints stay dark. The primary action's own steps, 500 and 600, are not lifted: the button is the same colour in every mode. Contrast is checked for every pair against the lifted ramp, and the report lists any corrections. Light mode is unaffected.
121
+
122
+ ### Toned-down dim mode
123
+
124
+ Dim is light mode with the volume down. Status and chart tokens resolve one step deeper on their ramp than in light (status tint 100 → 200, status text 700 → 800; 950 stays put), against `result.primitivesDim`, where every colour ramp keeps `dimChroma` of the OKLCH chroma it has in light mode, 0.8 by default, so nothing shouts on the softer ground. Each dim step takes the chroma of its light counterpart, the step above, so tints get quieter rather than louder.
125
+
126
+ The greys are not changed for dim: the same ramp, read deeper by the base theme (the card between 50 and 100, the ground between 100 and 200, ink at 900). The primary action stays as picked.
127
+
128
+ Each entry's dim ref is pinned in the semantic map (`semanticMap[token].dim`) and gets its own contrast pass, so the report can list dim corrections too. Light and dark output don't change with `dimChroma`.
129
+
130
+ Lower-level helpers are exported too — `generateScale`, `buildPrimitives`, `buildDarkPrimitives`, `buildDimPrimitives`, `buildSemanticMap`, `dimRef`, `checkContrast`, `autoCorrect`, `compileThemeCSS`, `compileCreateThemeTokens`, `compileResolvedTokens`, `compileNeutralRamp`, `compileCustomThemeCSS`, `resolveRef`, `anchorCurve`, and the `hexToOklch` / `oklchToHex` color utilities. See the exported TypeScript types for the full shape of `GeneratorResult`.
64
131
 
65
132
  ## Use in the browser
66
133
 
@@ -69,26 +136,28 @@ The package entry pulls in nothing from Node — no `fs`, no `crypto` — so you
69
136
  ```tsx
70
137
  "use client"
71
138
 
72
- import { generateTheme, compileCreateThemeTokens } from "@eluan/theme-generator"
139
+ import { generateTheme } from "@eluan/theme-generator"
73
140
 
74
141
  function applyTheme(accent: string) {
75
- const result = generateTheme({
142
+ const { customTheme, createThemeOptions } = generateTheme({
76
143
  accents: [accent],
77
144
  themeName: "live",
78
145
  minContrast: 4.5,
79
146
  neutralTintRatio: 0.04,
80
147
  })
81
148
 
82
- // Option A — inject the compiled CSS (both modes, scoped to data-theme="live")
149
+ // Option A — with EluanProvider: register it and switch to it
150
+ // <EluanProvider customThemes={[customTheme]} /> … setTheme("live")
151
+
152
+ // Option B — without the Provider: inject the CSS and set the attributes it targets
83
153
  const style = document.createElement("style")
84
- style.textContent = result.css.theme
154
+ style.textContent = customTheme.css
85
155
  document.head.append(style)
86
- document.documentElement.dataset.theme = "live"
156
+ document.documentElement.dataset.theme = "eluan"
157
+ document.documentElement.dataset.themeCustom = "live"
87
158
 
88
- // Option B — take the raw token maps and hand them to createTheme()
89
- const light = result.createThemeTokens
90
- const dark = compileCreateThemeTokens(result.semanticMap, result.primitives, "dark")
91
- return { light, dark }
159
+ // Option C — the token maps, for createTheme({ name: "live", ...createThemeOptions })
160
+ return createThemeOptions
92
161
  }
93
162
  ```
94
163
 
@@ -20,7 +20,13 @@ Options:
20
20
  --name <string> Theme name (default: "custom")
21
21
  --out <dir> Output directory (default: ./tokens)
22
22
  --min-contrast <num> Minimum contrast ratio (default: 4.5)
23
- --neutral-tint <num> Neutral tint ratio (default: 0.04)
23
+ --neutral <hex|none> Colour the greys are tinted toward (default: the first accent)
24
+ --neutral-tint <num> How strongly the greys are tinted, 0-1
25
+ --neutral-tint-ratio <num>
26
+ Share of the accent's chroma the greys keep when neither
27
+ flag above is set (default: 0.04)
28
+ --dark-lift <num> Lightness added to dark-mode colours, 0-0.2 (default: 0.08)
29
+ --dim-chroma <num> Chroma kept in dim-mode colours, 0.5-1 (default: 0.8)
24
30
  --config <path> Path to config file (JSON)
25
31
  --help Show this help
26
32
 
@@ -128,7 +134,13 @@ function parseCliArgs() {
128
134
  name: { type: 'string' },
129
135
  out: { type: 'string' },
130
136
  'min-contrast': { type: 'string' },
137
+ neutral: { type: 'string' },
131
138
  'neutral-tint': { type: 'string' },
139
+ 'neutral-tint-ratio': { type: 'string' },
140
+ 'dark-lift': { type: 'string' },
141
+ 'dim-chroma': { type: 'string' },
142
+ // Removed: dim reads the same grey ramp now. Accepted so old scripts keep running.
143
+ 'dim-warmth': { type: 'string' },
132
144
  config: { type: 'string' },
133
145
  help: { type: 'boolean', default: false },
134
146
  },
@@ -139,6 +151,9 @@ function parseCliArgs() {
139
151
  printUsage();
140
152
  process.exit(0);
141
153
  }
154
+ if (values['dim-warmth'] !== undefined) {
155
+ console.warn('--dim-warmth is ignored: dim mode now uses the same greys as light. Remove the flag.');
156
+ }
142
157
  const config = loadConfigFile(values.config);
143
158
  const cliAccents = values.accent;
144
159
  const accents = (cliAccents && cliAccents.length > 0) ? cliAccents : (config?.accents ?? []);
@@ -146,14 +161,24 @@ function parseCliArgs() {
146
161
  const minContrast = values['min-contrast']
147
162
  ? parseFloat(values['min-contrast'])
148
163
  : (config?.minContrast ?? 4.5);
149
- const neutralTintRatio = values['neutral-tint']
150
- ? parseFloat(values['neutral-tint'])
164
+ const neutralTintRatio = values['neutral-tint-ratio']
165
+ ? parseFloat(values['neutral-tint-ratio'])
151
166
  : (config?.neutralTintRatio ?? 0.04);
167
+ const neutral = values.neutral ?? config?.neutral;
168
+ const neutralTint = values['neutral-tint']
169
+ ? parseFloat(values['neutral-tint'])
170
+ : config?.neutralTint;
171
+ const darkLift = values['dark-lift']
172
+ ? parseFloat(values['dark-lift'])
173
+ : config?.darkLift;
174
+ const dimChroma = values['dim-chroma']
175
+ ? parseFloat(values['dim-chroma'])
176
+ : config?.dimChroma;
152
177
  const outDir = values.out ?? config?.outDir ?? './tokens';
153
178
  if (accents.length === 0) {
154
179
  return null;
155
180
  }
156
- return { accents, themeName, minContrast, neutralTintRatio, outDir };
181
+ return { accents, themeName, minContrast, neutralTintRatio, neutral, neutralTint, darkLift, dimChroma, outDir };
157
182
  }
158
183
  function generate(opts) {
159
184
  const { outDir, ...config } = opts;
@@ -161,19 +186,27 @@ function generate(opts) {
161
186
  console.log(`Generating theme "${config.themeName}"...`);
162
187
  console.log(` Accents: ${config.accents.join(', ')}`);
163
188
  console.log(` Min contrast: ${config.minContrast}:1`);
189
+ if (config.neutral !== undefined)
190
+ console.log(` Neutral: ${config.neutral}`);
191
+ if (config.neutralTint !== undefined)
192
+ console.log(` Neutral tint: ${config.neutralTint}`);
164
193
  console.log(` Output: ${resolvedOut}`);
165
194
  console.log('');
166
195
  const result = generateTheme(config);
167
196
  mkdirSync(resolvedOut, { recursive: true });
168
197
  writeFileSync(join(resolvedOut, 'primitives.json'), compilePrimitivesJSON(result.primitives));
169
- writeFileSync(join(resolvedOut, 'semantic.json'), compileSemanticJSON(result.semanticMap, result.primitives));
198
+ writeFileSync(join(resolvedOut, 'semantic.json'), compileSemanticJSON(result.semanticMap, result.primitives, result.primitivesDark, result.primitivesDim));
170
199
  const fullCSS = [
171
200
  result.css.primitives,
172
201
  '',
173
202
  result.css.theme,
174
203
  ].join('\n\n');
175
204
  writeFileSync(join(resolvedOut, 'theme.css'), fullCSS);
176
- const previewHTML = generateSmokeHTML(result.primitives, result.semanticMap, config.themeName);
205
+ // The dual-mode consumer path: register with EluanProvider's customThemes,
206
+ // or pass to createTheme({ name, ...options }) from @eluan/core
207
+ writeFileSync(join(resolvedOut, 'custom-theme.css'), result.customTheme.css);
208
+ writeFileSync(join(resolvedOut, 'create-theme.json'), JSON.stringify({ name: config.themeName, ...result.createThemeOptions }, null, 2));
209
+ const previewHTML = generateSmokeHTML(result.primitives, result.semanticMap, config.themeName, result.primitivesDark, result.primitivesDim);
177
210
  writeFileSync(join(resolvedOut, 'preview.html'), previewHTML);
178
211
  writeFileSync(join(resolvedOut, 'report.md'), result.report);
179
212
  if (result.corrections.length > 0) {
@@ -1,3 +1,25 @@
1
1
  import type { ScaleStep } from '../types.js';
2
2
  export declare const DEFAULT_CURVE: ScaleStep[];
3
+ /**
4
+ * The grey ramp's curve: the lightness and chroma shape of Eluan's concrete
5
+ * greys, which the look's surfaces are tuned to. Paper at 50, the hairline at
6
+ * 100, a field border at 200, muted text between 600 and 700, ink at 800 and
7
+ * the dark ground at 950. Chroma peaks at 500, so a tint shows in the mid
8
+ * greys and fades toward white and black.
9
+ */
10
+ export declare const NEUTRAL_CURVE: ScaleStep[];
11
+ /** The range an accent's lightness can anchor step 500 to and still leave a usable ramp either side. */
12
+ export declare const ANCHOR_LIGHTNESS_RANGE: {
13
+ readonly min: 0.45;
14
+ readonly max: 0.9;
15
+ };
16
+ /**
17
+ * `curve` with step 500 moved to `lightness`, the lighter steps spread between
18
+ * it and the top of the curve and the darker ones between it and the bottom,
19
+ * in the proportions they had. A ramp built on it has the accent itself at
20
+ * 500 instead of a colour near it. `lightness` is held inside
21
+ * `ANCHOR_LIGHTNESS_RANGE`, so a very light or very dark accent still gets
22
+ * tints above and shades below.
23
+ */
24
+ export declare function anchorCurve(curve: ScaleStep[], lightness: number): ScaleStep[];
3
25
  export declare function validateCurve(curve: ScaleStep[]): void;
@@ -11,6 +11,52 @@ export const DEFAULT_CURVE = [
11
11
  { step: 900, lightness: 0.27, chromaRatio: 0.40, hueShift: 0 },
12
12
  { step: 950, lightness: 0.18, chromaRatio: 0.25, hueShift: 0 },
13
13
  ];
14
+ /**
15
+ * The grey ramp's curve: the lightness and chroma shape of Eluan's concrete
16
+ * greys, which the look's surfaces are tuned to. Paper at 50, the hairline at
17
+ * 100, a field border at 200, muted text between 600 and 700, ink at 800 and
18
+ * the dark ground at 950. Chroma peaks at 500, so a tint shows in the mid
19
+ * greys and fades toward white and black.
20
+ */
21
+ export const NEUTRAL_CURVE = [
22
+ { step: 50, lightness: 0.987, chromaRatio: 0.06, hueShift: 0 },
23
+ { step: 100, lightness: 0.952, chromaRatio: 0.14, hueShift: 0 },
24
+ { step: 200, lightness: 0.883, chromaRatio: 0.34, hueShift: 0 },
25
+ { step: 300, lightness: 0.811, chromaRatio: 0.54, hueShift: 0 },
26
+ { step: 400, lightness: 0.738, chromaRatio: 0.78, hueShift: 0 },
27
+ { step: 500, lightness: 0.664, chromaRatio: 1.00, hueShift: 0 },
28
+ { step: 600, lightness: 0.574, chromaRatio: 0.95, hueShift: 0 },
29
+ { step: 700, lightness: 0.477, chromaRatio: 0.77, hueShift: 0 },
30
+ { step: 800, lightness: 0.374, chromaRatio: 0.58, hueShift: 0 },
31
+ { step: 900, lightness: 0.298, chromaRatio: 0.43, hueShift: 0 },
32
+ { step: 950, lightness: 0.226, chromaRatio: 0.31, hueShift: 0 },
33
+ ];
34
+ /** The range an accent's lightness can anchor step 500 to and still leave a usable ramp either side. */
35
+ export const ANCHOR_LIGHTNESS_RANGE = { min: 0.45, max: 0.9 };
36
+ /**
37
+ * `curve` with step 500 moved to `lightness`, the lighter steps spread between
38
+ * it and the top of the curve and the darker ones between it and the bottom,
39
+ * in the proportions they had. A ramp built on it has the accent itself at
40
+ * 500 instead of a colour near it. `lightness` is held inside
41
+ * `ANCHOR_LIGHTNESS_RANGE`, so a very light or very dark accent still gets
42
+ * tints above and shades below.
43
+ */
44
+ export function anchorCurve(curve, lightness) {
45
+ const middle = curve.find((s) => s.step === 500);
46
+ if (!middle)
47
+ return curve;
48
+ const top = curve[0].lightness;
49
+ const bottom = curve[curve.length - 1].lightness;
50
+ const target = Math.min(Math.max(lightness, ANCHOR_LIGHTNESS_RANGE.min), ANCHOR_LIGHTNESS_RANGE.max);
51
+ const upper = (top - target) / (top - middle.lightness);
52
+ const lower = (target - bottom) / (middle.lightness - bottom);
53
+ return curve.map((s) => ({
54
+ ...s,
55
+ lightness: s.lightness >= middle.lightness
56
+ ? top - (top - s.lightness) * upper
57
+ : bottom + (s.lightness - bottom) * lower,
58
+ }));
59
+ }
14
60
  export function validateCurve(curve) {
15
61
  if (curve.length !== 11) {
16
62
  throw new Error(`Curve must have exactly 11 steps, got ${curve.length}.`);
@@ -0,0 +1,36 @@
1
+ import type { PrimitiveTokens, Scale, ScaleStepValue } from '../types.js';
2
+ /**
3
+ * Default OKLCH lightness added to the dark-mode colour ramps. Dark grounds
4
+ * swallow mid-tone colour, so the same step reads dimmer than it does on a
5
+ * light page; lifting the ramp keeps accents and status colours as vivid in
6
+ * dark mode as they look in light mode.
7
+ */
8
+ export declare const DEFAULT_DARK_LIFT = 0.08;
9
+ /** Largest lift accepted; beyond this mid steps start to read as pastels. */
10
+ export declare const MAX_DARK_LIFT = 0.2;
11
+ /**
12
+ * Share of the lift each step gets: full on the mid steps people notice
13
+ * (buttons, borders, chart series), tapering to nothing at both ends so dark
14
+ * surfaces and tints (900–950) stay dark and the lightest steps don't clip
15
+ * to white.
16
+ */
17
+ export declare const DARK_LIFT_WEIGHTS: Record<ScaleStepValue, number>;
18
+ export declare function liftScale(scale: Scale, lift: number): Scale;
19
+ /**
20
+ * The steps the primary action is drawn in: its fill and its hover. They stay
21
+ * the picked accent in every mode, so a mode's version of the ramp leaves them
22
+ * alone.
23
+ */
24
+ export declare const ACCENT_PINNED_STEPS: ScaleStepValue[];
25
+ /**
26
+ * `scale` with the pinned accent steps put back from `original`. Steps darker
27
+ * than the pins are pulled under them where a lift had raised one past, so
28
+ * the ramp stays ordered.
29
+ */
30
+ export declare function pinAccentSteps(scale: Scale, original: Scale): Scale;
31
+ /**
32
+ * The primitives dark mode resolves against: every colour ramp lifted by
33
+ * `lift`, neutral unchanged, and the primary action's own steps left as
34
+ * picked. A lift of 0 returns the light primitives as-is.
35
+ */
36
+ export declare function buildDarkPrimitives(primitives: PrimitiveTokens, lift: number): PrimitiveTokens;
@@ -0,0 +1,91 @@
1
+ import { SCALE_STEPS } from '../types.js';
2
+ import { gamutMap, oklchToHex } from './convert.js';
3
+ /**
4
+ * Default OKLCH lightness added to the dark-mode colour ramps. Dark grounds
5
+ * swallow mid-tone colour, so the same step reads dimmer than it does on a
6
+ * light page; lifting the ramp keeps accents and status colours as vivid in
7
+ * dark mode as they look in light mode.
8
+ */
9
+ export const DEFAULT_DARK_LIFT = 0.08;
10
+ /** Largest lift accepted; beyond this mid steps start to read as pastels. */
11
+ export const MAX_DARK_LIFT = 0.2;
12
+ /**
13
+ * Share of the lift each step gets: full on the mid steps people notice
14
+ * (buttons, borders, chart series), tapering to nothing at both ends so dark
15
+ * surfaces and tints (900–950) stay dark and the lightest steps don't clip
16
+ * to white.
17
+ */
18
+ export const DARK_LIFT_WEIGHTS = {
19
+ 50: 0,
20
+ 100: 0.25,
21
+ 200: 0.5,
22
+ 300: 1,
23
+ 400: 1,
24
+ 500: 1,
25
+ 600: 1,
26
+ 700: 0.75,
27
+ 800: 0.5,
28
+ 900: 0.25,
29
+ 950: 0,
30
+ };
31
+ /** The colour ramps that get lifted. Neutral stays put: it draws the dark grounds. */
32
+ const LIFTED = ['primary', 'secondary', 'tertiary', 'error', 'warning', 'success', 'info'];
33
+ /** Smallest lightness gap kept between neighbouring steps, so the ramp stays ordered. */
34
+ const MIN_STEP_GAP = 0.005;
35
+ export function liftScale(scale, lift) {
36
+ const lifted = {};
37
+ let previous = Infinity;
38
+ for (const step of SCALE_STEPS) {
39
+ const { oklch } = scale[step];
40
+ const l = Math.min(oklch.l + lift * DARK_LIFT_WEIGHTS[step], 0.98, previous - MIN_STEP_GAP);
41
+ const raw = { ...oklch, l };
42
+ lifted[step] = { oklch: gamutMap(raw), hex: oklchToHex(raw) };
43
+ previous = l;
44
+ }
45
+ return lifted;
46
+ }
47
+ /**
48
+ * The steps the primary action is drawn in: its fill and its hover. They stay
49
+ * the picked accent in every mode, so a mode's version of the ramp leaves them
50
+ * alone.
51
+ */
52
+ export const ACCENT_PINNED_STEPS = [500, 600];
53
+ /**
54
+ * `scale` with the pinned accent steps put back from `original`. Steps darker
55
+ * than the pins are pulled under them where a lift had raised one past, so
56
+ * the ramp stays ordered.
57
+ */
58
+ export function pinAccentSteps(scale, original) {
59
+ const pinned = { ...scale };
60
+ for (const step of ACCENT_PINNED_STEPS)
61
+ pinned[step] = original[step];
62
+ let previous = Infinity;
63
+ for (const step of SCALE_STEPS) {
64
+ const entry = pinned[step];
65
+ if (entry.oklch.l >= previous) {
66
+ const raw = { ...entry.oklch, l: previous - MIN_STEP_GAP };
67
+ pinned[step] = { oklch: gamutMap(raw), hex: oklchToHex(raw) };
68
+ }
69
+ previous = pinned[step].oklch.l;
70
+ }
71
+ return pinned;
72
+ }
73
+ /**
74
+ * The primitives dark mode resolves against: every colour ramp lifted by
75
+ * `lift`, neutral unchanged, and the primary action's own steps left as
76
+ * picked. A lift of 0 returns the light primitives as-is.
77
+ */
78
+ export function buildDarkPrimitives(primitives, lift) {
79
+ if (lift === 0)
80
+ return primitives;
81
+ const dark = { ...primitives };
82
+ for (const name of LIFTED) {
83
+ const scale = primitives[name];
84
+ if (scale)
85
+ dark[name] = liftScale(scale, lift);
86
+ }
87
+ if (primitives.primary && dark.primary) {
88
+ dark.primary = pinAccentSteps(dark.primary, primitives.primary);
89
+ }
90
+ return dark;
91
+ }
@@ -0,0 +1,25 @@
1
+ import type { PrimitiveTokens, Scale } from '../types.js';
2
+ /**
3
+ * Default chroma multiplier for the dim-mode colour ramps. Dim is light mode
4
+ * toned down: the same steps, one deeper, with accents and status colours
5
+ * pulled back so nothing shouts on the softer ground.
6
+ */
7
+ export declare const DEFAULT_DIM_CHROMA = 0.8;
8
+ /** Lowest chroma multiplier accepted; below this accents turn muddy. */
9
+ export declare const MIN_DIM_CHROMA = 0.5;
10
+ /**
11
+ * Dim refs sit one step deeper than light, and chroma climbs steeply toward
12
+ * the mid steps, so scaling each step's own chroma would still leave dim tints
13
+ * louder than light's (100 → 200 nearly doubles it). Each step instead takes
14
+ * the chroma of the step above, its light counterpart, times `factor`: every
15
+ * dim colour keeps `factor` of the saturation it had in light mode.
16
+ */
17
+ export declare function toneDownScale(scale: Scale, factor: number): Scale;
18
+ /**
19
+ * The primitives dim mode resolves against: every colour ramp toned down to
20
+ * `chroma` of its light-mode saturation. The primary action's fill and its
21
+ * hover (primary 500 and 600) are left as they are, so the accent is the
22
+ * colour that was picked in every mode. With chroma 1 it returns the light
23
+ * primitives as-is.
24
+ */
25
+ export declare function buildDimPrimitives(primitives: PrimitiveTokens, chroma: number): PrimitiveTokens;
@@ -0,0 +1,52 @@
1
+ import { SCALE_STEPS } from '../types.js';
2
+ import { gamutMap, oklchToHex } from './convert.js';
3
+ import { pinAccentSteps } from './darkLift.js';
4
+ /**
5
+ * Default chroma multiplier for the dim-mode colour ramps. Dim is light mode
6
+ * toned down: the same steps, one deeper, with accents and status colours
7
+ * pulled back so nothing shouts on the softer ground.
8
+ */
9
+ export const DEFAULT_DIM_CHROMA = 0.8;
10
+ /** Lowest chroma multiplier accepted; below this accents turn muddy. */
11
+ export const MIN_DIM_CHROMA = 0.5;
12
+ /** The colour ramps that get toned down. Neutral is left alone: dim draws its surfaces from the same greys. */
13
+ const TONED = ['primary', 'secondary', 'tertiary', 'error', 'warning', 'success', 'info'];
14
+ function entry(raw) {
15
+ return { oklch: gamutMap(raw), hex: oklchToHex(raw) };
16
+ }
17
+ /**
18
+ * Dim refs sit one step deeper than light, and chroma climbs steeply toward
19
+ * the mid steps, so scaling each step's own chroma would still leave dim tints
20
+ * louder than light's (100 → 200 nearly doubles it). Each step instead takes
21
+ * the chroma of the step above, its light counterpart, times `factor`: every
22
+ * dim colour keeps `factor` of the saturation it had in light mode.
23
+ */
24
+ export function toneDownScale(scale, factor) {
25
+ const toned = {};
26
+ SCALE_STEPS.forEach((step, i) => {
27
+ const counterpart = scale[SCALE_STEPS[Math.max(i - 1, 0)]];
28
+ toned[step] = entry({ ...scale[step].oklch, c: counterpart.oklch.c * factor });
29
+ });
30
+ return toned;
31
+ }
32
+ /**
33
+ * The primitives dim mode resolves against: every colour ramp toned down to
34
+ * `chroma` of its light-mode saturation. The primary action's fill and its
35
+ * hover (primary 500 and 600) are left as they are, so the accent is the
36
+ * colour that was picked in every mode. With chroma 1 it returns the light
37
+ * primitives as-is.
38
+ */
39
+ export function buildDimPrimitives(primitives, chroma) {
40
+ if (chroma === 1)
41
+ return primitives;
42
+ const dim = { ...primitives };
43
+ for (const name of TONED) {
44
+ const scale = primitives[name];
45
+ if (scale)
46
+ dim[name] = toneDownScale(scale, chroma);
47
+ }
48
+ if (primitives.primary && dim.primary) {
49
+ dim.primary = pinAccentSteps(dim.primary, primitives.primary);
50
+ }
51
+ return dim;
52
+ }
@@ -1,2 +1,22 @@
1
1
  import type { Scale, ScaleStep } from '../types.js';
2
+ /**
3
+ * Peak chroma of the grey ramp at `neutralTint` 1: the strongest tint that
4
+ * still reads as a neutral. A warm "concrete" grey sits near 0.8 of it.
5
+ */
6
+ export declare const MAX_NEUTRAL_CHROMA = 0.06;
7
+ /** The grey ramp tinted by a share of the accent's chroma, capped low. */
2
8
  export declare function generateNeutralScale(accentHue: number, accentPeakChroma: number, tintRatio: number, curve: ScaleStep[]): Scale;
9
+ export type NeutralSource = {
10
+ /** Hue the greys lean toward. */
11
+ hue: number;
12
+ /** Chroma of the colour the hue came from. */
13
+ chroma: number;
14
+ };
15
+ /**
16
+ * The grey ramp for an explicit choice of tint.
17
+ *
18
+ * `strength` runs 0 (pure grey) to 1 (`MAX_NEUTRAL_CHROMA`). Left out, the
19
+ * ramp takes the source colour's own chroma, held under the maximum, so a
20
+ * grey passed in as the neutral comes back as tinted as it went in.
21
+ */
22
+ export declare function generateTintedNeutralScale(source: NeutralSource, strength: number | undefined, curve: ScaleStep[]): Scale;
@@ -1,7 +1,27 @@
1
1
  import { generateScale } from './scale.js';
2
+ /** Cap on the grey ramp's chroma when it is derived from an accent and a ratio. */
2
3
  const ABSOLUTE_CHROMA_CEILING = 0.02;
4
+ /**
5
+ * Peak chroma of the grey ramp at `neutralTint` 1: the strongest tint that
6
+ * still reads as a neutral. A warm "concrete" grey sits near 0.8 of it.
7
+ */
8
+ export const MAX_NEUTRAL_CHROMA = 0.06;
9
+ /** The grey ramp tinted by a share of the accent's chroma, capped low. */
3
10
  export function generateNeutralScale(accentHue, accentPeakChroma, tintRatio, curve) {
4
11
  const rawChroma = accentPeakChroma * tintRatio;
5
12
  const clampedChroma = Math.min(rawChroma, ABSOLUTE_CHROMA_CEILING);
6
13
  return generateScale(accentHue, clampedChroma, curve);
7
14
  }
15
+ /**
16
+ * The grey ramp for an explicit choice of tint.
17
+ *
18
+ * `strength` runs 0 (pure grey) to 1 (`MAX_NEUTRAL_CHROMA`). Left out, the
19
+ * ramp takes the source colour's own chroma, held under the maximum, so a
20
+ * grey passed in as the neutral comes back as tinted as it went in.
21
+ */
22
+ export function generateTintedNeutralScale(source, strength, curve) {
23
+ const peakChroma = strength === undefined
24
+ ? Math.min(source.chroma, MAX_NEUTRAL_CHROMA)
25
+ : strength * MAX_NEUTRAL_CHROMA;
26
+ return generateScale(source.hue, peakChroma, curve);
27
+ }
@@ -1,7 +1,39 @@
1
- import type { PrimitiveTokens, SemanticMap } from '../types.js';
1
+ import type { Mode, PrimitiveTokens, SemanticMap } from '../types.js';
2
+ /**
3
+ * The tokens a generated theme states. The base theme derives every grey
4
+ * token from the ramp, so those are left to it, except one a contrast
5
+ * correction has moved: that one is stated, and in every mode, because the
6
+ * theme's light block applies in all three.
7
+ */
8
+ export declare function emittedTokens(map: SemanticMap): string[];
9
+ /**
10
+ * The grey ramp as `--color-neutral-*`, the one thing every mode's surfaces,
11
+ * text and borders are built from. Step 0 is white.
12
+ */
13
+ export declare function compileNeutralRamp(primitives: PrimitiveTokens): Record<string, string>;
2
14
  export declare function compilePrimitivesJSON(primitives: PrimitiveTokens): string;
3
- export declare function compileSemanticJSON(map: SemanticMap, primitives: PrimitiveTokens): string;
15
+ export declare function compileSemanticJSON(map: SemanticMap, primitives: PrimitiveTokens, darkPrimitives?: PrimitiveTokens, dimPrimitives?: PrimitiveTokens): string;
4
16
  export declare function compilePrimitivesCSS(primitives: PrimitiveTokens, themeName: string): string;
5
- export declare function compileModeCSS(map: SemanticMap, primitives: PrimitiveTokens, mode: 'light' | 'dark', themeName: string): string;
6
- export declare function compileThemeCSS(map: SemanticMap, primitives: PrimitiveTokens, themeName: string, inputHash: string): string;
7
- export declare function compileCreateThemeTokens(map: SemanticMap, primitives: PrimitiveTokens, mode: 'light' | 'dark'): Record<string, string>;
17
+ export declare function compileModeCSS(map: SemanticMap, primitives: PrimitiveTokens, mode: Mode, themeName: string): string;
18
+ export declare function compileThemeCSS(map: SemanticMap, primitives: PrimitiveTokens, themeName: string, inputHash: string, darkPrimitives?: PrimitiveTokens, dimPrimitives?: PrimitiveTokens): string;
19
+ /**
20
+ * Every token in the map resolved for `mode`, whether or not the theme states
21
+ * it. For contrast checks, previews and swatches; a theme itself needs only
22
+ * `compileCreateThemeTokens`.
23
+ */
24
+ export declare function compileResolvedTokens(map: SemanticMap, primitives: PrimitiveTokens, mode: Mode): Record<string, string>;
25
+ /**
26
+ * The tokens a theme states for `mode`, as `createTheme()` from @eluan/core
27
+ * takes them: the grey ramp (light only), the accent and status colours, and
28
+ * any grey token a contrast correction moved.
29
+ */
30
+ export declare function compileCreateThemeTokens(map: SemanticMap, primitives: PrimitiveTokens, mode: Mode): Record<string, string>;
31
+ /**
32
+ * CSS for a custom theme layered on `eluan`, in the same shape `createTheme()`
33
+ * from @eluan/core emits: the light tokens on `[data-theme-custom="<name>"]`
34
+ * and the dim and dark tokens on that plus `[data-mode]`. Because the theme
35
+ * sits on top of `eluan` instead of replacing it, the base theme's fonts and
36
+ * its surface logic stay in place. Without `dim`, dim mode uses the light
37
+ * tokens.
38
+ */
39
+ export declare function compileCustomThemeCSS(themeName: string, light: Record<string, string>, dark: Record<string, string>, dim?: Record<string, string>): string;