@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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @eluan/theme-generator
2
2
 
3
- CLI and library that generates accessible light, dim and 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,10 +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 |
36
38
  | `--dark-lift <num>` | `0.08` | OKLCH lightness added to dark-mode colours, 0–0.2 |
37
39
  | `--dim-chroma <num>` | `0.8` | Share of chroma dim-mode colours keep, 0.5–1 |
38
- | `--dim-warmth <num>` | `1` | How far dim-mode greys move toward warm teak, 0–1 |
39
40
  | `--config <path>` | — | Path to a JSON config file |
40
41
 
41
42
  You can also drop a `eluan-theme.config.json` in your project root; CLI flags override its values.
@@ -58,7 +59,6 @@ const result = generateTheme({
58
59
  neutralTintRatio: 0.04,
59
60
  darkLift: 0.08, // optional; brighter dark-mode colours (0 turns it off)
60
61
  dimChroma: 0.8, // optional; toned-down dim-mode colours (1 turns it off)
61
- dimWarmth: 1, // optional; warm teak greys in dim mode (0 keeps brand greys)
62
62
  })
63
63
 
64
64
  result.customTheme // { name, extends, css }: pass to <EluanProvider customThemes={[…]} />
@@ -68,26 +68,66 @@ result.css.theme // standalone CSS for every mode, scoped to [data-them
68
68
  result.createThemeTokens // light-mode token map only (kept for compatibility)
69
69
  ```
70
70
 
71
- `customTheme` and `createThemeOptions` cover light, dim and dark mode and layer on top of `minimal`, so its fonts stay in place. They also set the base grey aliases (`--backgrounds-*`, `--foregrounds-*`) for each mode, so any CSS of your own that reads them matches the generated greys; components only read theme tokens. `css.theme` replaces the theme instead, so it drops `minimal`'s fonts; prefer the first two in apps that use `EluanProvider`.
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.
72
111
 
73
112
  ### Contrast correction
74
113
 
75
- 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. Brand-coloured text like the Outline and Ghost button labels stays as close to its brand step as contrast allows. Only when no step on the ramp passes does it fall back to neutral, white or black. Text that sits on more than one surface is checked against each, and the hardest decides: Outline and Ghost button text (`action-secondary-fg`, `action-tertiary-fg`) must clear the minimum on both the page and the panel ground. Every correction is listed in `result.report`.
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.
76
117
 
77
118
  ### Brighter dark mode
78
119
 
79
- 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. Contrast is checked for every pair against the lifted ramp, and the report lists any corrections; on bright accents that usually means dark text on the primary button in dark mode. Light mode is unaffected.
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.
80
121
 
81
122
  ### Toned-down dim mode
82
123
 
83
- Dim is light mode with the volume down, built the way `minimal`'s own dim is. Every semantic token resolves one step deeper on its ramp than in light (page ground 50 → 100, status tint 100 → 200, status text 700 → 800; 950 stays put), against `result.primitivesDim`:
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.
84
125
 
85
- - **Colour ramps** (accents and status hues) keep `dimChroma` of the OKLCH chroma they have 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.
86
- - **Greys** move `dimWarmth` of the way toward the hue and chroma of `minimal`'s teak ramp, 1 by default. Lightness stays on the theme's curve, so step contrast holds. At 0 dim keeps the brand-tinted greys.
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.
87
127
 
88
- 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 either option.
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`.
89
129
 
90
- Lower-level helpers are exported too — `generateScale`, `buildPrimitives`, `buildDarkPrimitives`, `buildDimPrimitives`, `buildSemanticMap`, `dimRef`, `checkContrast`, `autoCorrect`, `compileThemeCSS`, `compileCreateThemeTokens`, `compileCustomThemeCSS`, and the `hexToOklch` / `oklchToHex` color utilities. See the exported TypeScript types for the full shape of `GeneratorResult`.
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`.
91
131
 
92
132
  ## Use in the browser
93
133
 
@@ -113,7 +153,7 @@ function applyTheme(accent: string) {
113
153
  const style = document.createElement("style")
114
154
  style.textContent = customTheme.css
115
155
  document.head.append(style)
116
- document.documentElement.dataset.theme = "minimal"
156
+ document.documentElement.dataset.theme = "eluan"
117
157
  document.documentElement.dataset.themeCustom = "live"
118
158
 
119
159
  // Option C — the token maps, for createTheme({ name: "live", ...createThemeOptions })
@@ -20,10 +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)
24
28
  --dark-lift <num> Lightness added to dark-mode colours, 0-0.2 (default: 0.08)
25
29
  --dim-chroma <num> Chroma kept in dim-mode colours, 0.5-1 (default: 0.8)
26
- --dim-warmth <num> How far dim-mode greys move toward warm teak, 0-1 (default: 1)
27
30
  --config <path> Path to config file (JSON)
28
31
  --help Show this help
29
32
 
@@ -131,9 +134,12 @@ function parseCliArgs() {
131
134
  name: { type: 'string' },
132
135
  out: { type: 'string' },
133
136
  'min-contrast': { type: 'string' },
137
+ neutral: { type: 'string' },
134
138
  'neutral-tint': { type: 'string' },
139
+ 'neutral-tint-ratio': { type: 'string' },
135
140
  'dark-lift': { type: 'string' },
136
141
  'dim-chroma': { type: 'string' },
142
+ // Removed: dim reads the same grey ramp now. Accepted so old scripts keep running.
137
143
  'dim-warmth': { type: 'string' },
138
144
  config: { type: 'string' },
139
145
  help: { type: 'boolean', default: false },
@@ -145,6 +151,9 @@ function parseCliArgs() {
145
151
  printUsage();
146
152
  process.exit(0);
147
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
+ }
148
157
  const config = loadConfigFile(values.config);
149
158
  const cliAccents = values.accent;
150
159
  const accents = (cliAccents && cliAccents.length > 0) ? cliAccents : (config?.accents ?? []);
@@ -152,23 +161,24 @@ function parseCliArgs() {
152
161
  const minContrast = values['min-contrast']
153
162
  ? parseFloat(values['min-contrast'])
154
163
  : (config?.minContrast ?? 4.5);
155
- const neutralTintRatio = values['neutral-tint']
156
- ? parseFloat(values['neutral-tint'])
164
+ const neutralTintRatio = values['neutral-tint-ratio']
165
+ ? parseFloat(values['neutral-tint-ratio'])
157
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;
158
171
  const darkLift = values['dark-lift']
159
172
  ? parseFloat(values['dark-lift'])
160
173
  : config?.darkLift;
161
174
  const dimChroma = values['dim-chroma']
162
175
  ? parseFloat(values['dim-chroma'])
163
176
  : config?.dimChroma;
164
- const dimWarmth = values['dim-warmth']
165
- ? parseFloat(values['dim-warmth'])
166
- : config?.dimWarmth;
167
177
  const outDir = values.out ?? config?.outDir ?? './tokens';
168
178
  if (accents.length === 0) {
169
179
  return null;
170
180
  }
171
- return { accents, themeName, minContrast, neutralTintRatio, darkLift, dimChroma, dimWarmth, outDir };
181
+ return { accents, themeName, minContrast, neutralTintRatio, neutral, neutralTint, darkLift, dimChroma, outDir };
172
182
  }
173
183
  function generate(opts) {
174
184
  const { outDir, ...config } = opts;
@@ -176,6 +186,10 @@ function generate(opts) {
176
186
  console.log(`Generating theme "${config.themeName}"...`);
177
187
  console.log(` Accents: ${config.accents.join(', ')}`);
178
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}`);
179
193
  console.log(` Output: ${resolvedOut}`);
180
194
  console.log('');
181
195
  const result = generateTheme(config);
@@ -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}.`);
@@ -16,8 +16,21 @@ export declare const MAX_DARK_LIFT = 0.2;
16
16
  */
17
17
  export declare const DARK_LIFT_WEIGHTS: Record<ScaleStepValue, number>;
18
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;
19
31
  /**
20
32
  * The primitives dark mode resolves against: every colour ramp lifted by
21
- * `lift`, neutral unchanged. A lift of 0 returns the light primitives as-is.
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.
22
35
  */
23
36
  export declare function buildDarkPrimitives(primitives: PrimitiveTokens, lift: number): PrimitiveTokens;
@@ -44,9 +44,36 @@ export function liftScale(scale, lift) {
44
44
  }
45
45
  return lifted;
46
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
+ }
47
73
  /**
48
74
  * The primitives dark mode resolves against: every colour ramp lifted by
49
- * `lift`, neutral unchanged. A lift of 0 returns the light primitives as-is.
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.
50
77
  */
51
78
  export function buildDarkPrimitives(primitives, lift) {
52
79
  if (lift === 0)
@@ -57,5 +84,8 @@ export function buildDarkPrimitives(primitives, lift) {
57
84
  if (scale)
58
85
  dark[name] = liftScale(scale, lift);
59
86
  }
87
+ if (primitives.primary && dark.primary) {
88
+ dark.primary = pinAccentSteps(dark.primary, primitives.primary);
89
+ }
60
90
  return dark;
61
91
  }
@@ -1,4 +1,4 @@
1
- import type { PrimitiveTokens, Scale, ScaleStepValue } from '../types.js';
1
+ import type { PrimitiveTokens, Scale } from '../types.js';
2
2
  /**
3
3
  * Default chroma multiplier for the dim-mode colour ramps. Dim is light mode
4
4
  * toned down: the same steps, one deeper, with accents and status colours
@@ -7,17 +7,6 @@ import type { PrimitiveTokens, Scale, ScaleStepValue } from '../types.js';
7
7
  export declare const DEFAULT_DIM_CHROMA = 0.8;
8
8
  /** Lowest chroma multiplier accepted; below this accents turn muddy. */
9
9
  export declare const MIN_DIM_CHROMA = 0.5;
10
- /** Default pull of the dim greys toward teak. 1 matches `minimal`'s dim; 0 keeps the brand-tinted greys. */
11
- export declare const DEFAULT_DIM_WARMTH = 1;
12
- /**
13
- * Hue and chroma of `minimal`'s teak ramp (packages/tokens/src/primitives.css),
14
- * the warm greys its dim mode draws on. Only hue and chroma are borrowed:
15
- * lightness stays on the theme's curve so step contrast is unchanged.
16
- */
17
- export declare const TEAK_HUE_CHROMA: Record<ScaleStepValue, {
18
- h: number;
19
- c: number;
20
- }>;
21
10
  /**
22
11
  * Dim refs sit one step deeper than light, and chroma climbs steeply toward
23
12
  * the mid steps, so scaling each step's own chroma would still leave dim tints
@@ -26,10 +15,11 @@ export declare const TEAK_HUE_CHROMA: Record<ScaleStepValue, {
26
15
  * dim colour keeps `factor` of the saturation it had in light mode.
27
16
  */
28
17
  export declare function toneDownScale(scale: Scale, factor: number): Scale;
29
- export declare function warmScale(scale: Scale, warmth: number): Scale;
30
18
  /**
31
19
  * The primitives dim mode resolves against: every colour ramp toned down to
32
- * `chroma` of its light-mode saturation, and neutral pulled `warmth` of the way toward teak's hue and
33
- * chroma. With chroma 1 and warmth 0 it returns the light primitives as-is.
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.
34
24
  */
35
- export declare function buildDimPrimitives(primitives: PrimitiveTokens, chroma: number, warmth: number): PrimitiveTokens;
25
+ export declare function buildDimPrimitives(primitives: PrimitiveTokens, chroma: number): PrimitiveTokens;
package/dist/color/dim.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { SCALE_STEPS } from '../types.js';
2
2
  import { gamutMap, oklchToHex } from './convert.js';
3
+ import { pinAccentSteps } from './darkLift.js';
3
4
  /**
4
5
  * Default chroma multiplier for the dim-mode colour ramps. Dim is light mode
5
6
  * toned down: the same steps, one deeper, with accents and status colours
@@ -8,36 +9,11 @@ import { gamutMap, oklchToHex } from './convert.js';
8
9
  export const DEFAULT_DIM_CHROMA = 0.8;
9
10
  /** Lowest chroma multiplier accepted; below this accents turn muddy. */
10
11
  export const MIN_DIM_CHROMA = 0.5;
11
- /** Default pull of the dim greys toward teak. 1 matches `minimal`'s dim; 0 keeps the brand-tinted greys. */
12
- export const DEFAULT_DIM_WARMTH = 1;
13
- /**
14
- * Hue and chroma of `minimal`'s teak ramp (packages/tokens/src/primitives.css),
15
- * the warm greys its dim mode draws on. Only hue and chroma are borrowed:
16
- * lightness stays on the theme's curve so step contrast is unchanged.
17
- */
18
- export const TEAK_HUE_CHROMA = {
19
- 50: { h: 100.82, c: 0.0106 },
20
- 100: { h: 102.89, c: 0.0302 },
21
- 200: { h: 96.16, c: 0.0556 },
22
- 300: { h: 93.94, c: 0.0781 },
23
- 400: { h: 89.04, c: 0.0868 },
24
- 500: { h: 81.36, c: 0.0805 },
25
- 600: { h: 74.01, c: 0.0721 },
26
- 700: { h: 65.88, c: 0.0617 },
27
- 800: { h: 58.2, c: 0.0515 },
28
- 900: { h: 56.46, c: 0.043 },
29
- 950: { h: 53.07, c: 0.0303 },
30
- };
31
- /** The colour ramps that get toned down. Neutral is warmed instead. */
12
+ /** The colour ramps that get toned down. Neutral is left alone: dim draws its surfaces from the same greys. */
32
13
  const TONED = ['primary', 'secondary', 'tertiary', 'error', 'warning', 'success', 'info'];
33
14
  function entry(raw) {
34
15
  return { oklch: gamutMap(raw), hex: oklchToHex(raw) };
35
16
  }
36
- /** Hue `t` of the way from `from` to `to`, along the shorter arc. */
37
- function mixHue(from, to, t) {
38
- const delta = ((to - from + 540) % 360) - 180;
39
- return (from + delta * t + 360) % 360;
40
- }
41
17
  /**
42
18
  * Dim refs sit one step deeper than light, and chroma climbs steeply toward
43
19
  * the mid steps, so scaling each step's own chroma would still leave dim tints
@@ -53,37 +29,24 @@ export function toneDownScale(scale, factor) {
53
29
  });
54
30
  return toned;
55
31
  }
56
- export function warmScale(scale, warmth) {
57
- const warmed = {};
58
- for (const step of SCALE_STEPS) {
59
- const { oklch } = scale[step];
60
- const teak = TEAK_HUE_CHROMA[step];
61
- warmed[step] = entry({
62
- ...oklch,
63
- h: mixHue(oklch.h, teak.h, warmth),
64
- c: oklch.c + (teak.c - oklch.c) * warmth,
65
- });
66
- }
67
- return warmed;
68
- }
69
32
  /**
70
33
  * The primitives dim mode resolves against: every colour ramp toned down to
71
- * `chroma` of its light-mode saturation, and neutral pulled `warmth` of the way toward teak's hue and
72
- * chroma. With chroma 1 and warmth 0 it returns the light primitives as-is.
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.
73
38
  */
74
- export function buildDimPrimitives(primitives, chroma, warmth) {
75
- if (chroma === 1 && warmth === 0)
39
+ export function buildDimPrimitives(primitives, chroma) {
40
+ if (chroma === 1)
76
41
  return primitives;
77
42
  const dim = { ...primitives };
78
- if (chroma !== 1) {
79
- for (const name of TONED) {
80
- const scale = primitives[name];
81
- if (scale)
82
- dim[name] = toneDownScale(scale, chroma);
83
- }
43
+ for (const name of TONED) {
44
+ const scale = primitives[name];
45
+ if (scale)
46
+ dim[name] = toneDownScale(scale, chroma);
84
47
  }
85
- if (warmth !== 0 && primitives.neutral) {
86
- dim.neutral = warmScale(primitives.neutral, warmth);
48
+ if (primitives.primary && dim.primary) {
49
+ dim.primary = pinAccentSteps(dim.primary, primitives.primary);
87
50
  }
88
51
  return dim;
89
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,15 +1,39 @@
1
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
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
17
  export declare function compileModeCSS(map: SemanticMap, primitives: PrimitiveTokens, mode: Mode, themeName: string): string;
6
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
+ */
7
30
  export declare function compileCreateThemeTokens(map: SemanticMap, primitives: PrimitiveTokens, mode: Mode): Record<string, string>;
8
31
  /**
9
- * CSS for a custom theme layered on `minimal`, in the same shape `createTheme()`
32
+ * CSS for a custom theme layered on `eluan`, in the same shape `createTheme()`
10
33
  * from @eluan/core emits: the light tokens on `[data-theme-custom="<name>"]`
11
34
  * and the dim and dark tokens on that plus `[data-mode]`. Because the theme
12
- * sits on top of `minimal` instead of replacing it, `minimal`'s fonts stay in
13
- * place. Without `dim`, dim mode uses the light tokens.
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.
14
38
  */
15
39
  export declare function compileCustomThemeCSS(themeName: string, light: Record<string, string>, dark: Record<string, string>, dim?: Record<string, string>): string;