@designtools/tokens 0.8.0 → 0.10.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/CHANGELOG.md CHANGED
@@ -2,6 +2,30 @@
2
2
 
3
3
  Notable changes to `@designtools/tokens`. Dates are release dates; versions follow semver, with breaking changes in the minor slot while the package is pre-1.0.
4
4
 
5
+ ## 0.10.0
6
+
7
+ ### Minor Changes
8
+
9
+ - 93dd9ed: Colours are edited in place on the docs' colour page: `ColourGenerator` floats a bar bottom right there (Edit colours, then Copy prompt, reset, light and dark, and settings) and adds nothing to the dock. With editing on, each ramp opens its colour and anchor step, its own shape and exact colours for single steps, over the project's ramp; each colour its fill and subdued step (only steps whose label passes); and the settings the whole system's options, a link carrying the settings and saved versions. Explanations are tooltips.
10
+
11
+ New generator controls, inputs to the maths rather than colours picked by hand, as flags and seed fields, all unchanged output when unset: `--light-end`/`--dark-end` (`lightnessRange`) and `--tint-floor` (`tintFloor`) for where the colour ramps end and how much colour their pale steps keep; `--chroma`, `--chroma-strength` and `--chroma-peak` (`chroma`) for colourfulness profiles; `--hue-drift` (`hueDrift`); `"families"` in a seed for one colour leaning away from the system; `--pin family@step=colour` (`pins`) for an exact colour on a step, refused with the reason when it would put the ramp out of order or off the screen; and `--contract`, which prints where a step number means something different in one colour than in the rest (`stepContract` in code). The neutral keeps its own shape unless named. `--no-aliases` (`"aliases": false`) emits each status ramp once, without green, red and yellow beside success, destructive and warning; the default is unchanged. The colour editor's copy buttons work on a dev server opened by its network address.
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [7005847]
16
+ - @designtools/widgets@0.1.4
17
+
18
+ ## 0.9.0
19
+
20
+ ### Minor Changes
21
+
22
+ - 3a8e79f: `ColourGenerator` in `@designtools/tokens/studio`: the generator's inputs as a tool in the widgets dock. Primary and neutral first, colours to add, then contrast, target, lightness, labels on fills and the primary's step, with the score in both modes. It re-themes the page and every artboard live, and Copy prompt hands back the seed and the command to regenerate. The studio's hand-back prompt reads more clearly, and asks for `--report`.
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies [3a8e79f]
27
+ - @designtools/widgets@0.1.3
28
+
5
29
  ## 0.8.0
6
30
 
7
31
  ### Minor Changes
package/README.md CHANGED
@@ -165,7 +165,7 @@ check: tokens.css differs — generated by v0.4.0, running v0.5.0. Expected afte
165
165
 
166
166
  ## Trying scales live: the studio
167
167
 
168
- Once the tokens exist, `@designtools/tokens/studio` lets you try the hand-authored scales on the running app before writing them: a type ramp from a base and a ratio, the spacing unit, radii and shadows. It draws in the [`@designtools/widgets`](../widgets) dock, on the page you put it on, and changes the page and every [artboard](../artboards) as you go. It never writes a file: Copy prompt hands the changes back for `scale.css`. Colour isn't offered yet; a re-theme is a new seed and the generator, as above.
168
+ Once the tokens exist, `@designtools/tokens/studio` lets you try the hand-authored scales on the running app before writing them: a type ramp from a base and a ratio, the spacing unit, radii and shadows. It draws in the [`@designtools/widgets`](../widgets) dock, on the page you put it on, and changes the page and every [artboard](../artboards) as you go. It never writes a file: Copy prompt hands the changes back for `scale.css`.
169
169
 
170
170
  ```bash
171
171
  pnpm add -D @designtools/widgets react react-dom @base-ui/react lucide-react
@@ -180,6 +180,43 @@ export function ScalesTool() {
180
180
  }
181
181
  ```
182
182
 
183
+ ## Editing colours in place: the colour generator
184
+
185
+ Designers change the inputs to the maths, never its outputs. `ColourGenerator` edits the colours on the docs' colour page itself, which is where you look at them, and the page keeps its layout. A bar floats bottom right on that page (local dev and previews only): **Edit colours**, and once editing, Copy prompt with the number of changes, then adding a colour, reset, light and dark for the page and the tools, and the settings, then Done. With editing on, each ramp and each colour gets a small button that opens its settings in place:
186
+
187
+ - **A ramp** (the swatch by its name): the ramp now over the project's own; the colour it's made from and the step that colour lands on (a status colour set by hand or left to follow the primary, an added colour renamed or removed); its own shape when it leans away from the system's; and exact colours for single steps.
188
+ - **A colour** (Steps, by its ring): which step its fill and its subdued sit on, in light and dark, chosen only from steps whose label passes; hover one for its contrast.
189
+ - **The whole system** (the bar's settings): the score; the contrast method and target, lightness and labels on fills; the shape all ramps share; a link carrying the settings; and saved versions.
190
+
191
+ Every change regenerates in the browser and re-themes the page, every open tab and every artboard. A setting the generator refuses (a pin out of order) is said plainly and not applied; the page keeps the last colours it could make. Copy prompt hands back what changed, the seed and the exact command, so the generator stays the source; reset puts the project's colours back. Colour adds nothing to the design tools dock: the dock appears only for a tool asked for on that page.
192
+
193
+ **A link carries the settings**: Copy a link with these colours puts them in the address's `#`, so "look at it with these" is a link someone opens on a preview; nothing reaches the server. **Versions** are kept in the browser, to compare before handing one back.
194
+
195
+ ```tsx
196
+ // once, in the layout, inside the app's <Widgets>; off in production
197
+ import { ColourGenerator } from "@designtools/tokens/studio";
198
+ import { readProjectSeed } from "@designtools/tokens/studio/next";
199
+
200
+ <ColourGenerator project={process.env.VERCEL_ENV === "production" ? null : readProjectSeed()} />
201
+ ```
202
+
203
+ It fills the empty anchors `@designtools/docs` leaves on its colour page (`data-designtools-slot="colour:page"`, `"colour:ramp"`, `"colour:family"`); a page without them gets nothing but the live preview.
204
+
205
+ ### The shape of the ramps
206
+
207
+ Four levels, broadest first, each an input to the maths rather than a colour picked by hand:
208
+
209
+ 1. **The whole system**: the range, the tint floor, colourfulness and hue drift, below.
210
+ 2. **One colour**: the same settings written as differences, in a seed's `"families"` (`{ "twilight": { "chroma": { "strength": 1.5 } } }`). The neutral takes the system's shape only from here.
211
+ 3. **One step**: a pin, `--pin camel@300=#B7B7A3` (repeatable) or `"pins"`, for a colour that has to be exact. The steps between it and the seed bend to pass through it. A pin that puts the ramp out of order, sits on the seed's own step, or can't be shown on screen is refused with the reason.
212
+ 4. **The roles**: which step a fill and a subdued sit on, from steps whose label passes (`--overrides`, or the colour page's Steps).
213
+
214
+ `--light-end` and `--dark-end` set where every colour ramp ends, as OKLCH lightness in percent (default 98 and 15). A brand that only uses soft deep tones raises the dark end instead of hand-picking its darks: the steps between spread over the new range, adjacent dark steps keep at least two points between them, and the semantic searches run again, so every label still passes. `--tint-floor` (0 to 1) is how much of the seed's colourfulness the pale steps keep, as far as a screen can show it; it matters most for muted colours, whose pale steps otherwise fade to grey. `--chroma` sets how colourful each step is: `follow` (the default, easing from pale tints to the seed's chroma), `constant` (the seed's chroma throughout, as the screen allows, like Material's tonal palettes), `relative` (the seed's share of what each step's lightness can hold) or `peak` (peaking at `--chroma-peak`, falling away either side, Tailwind's shape). `--chroma-strength` scales it (0.25 to 3), eased in beside the seed so the seed's own step never moves. `--hue-drift` turns the hue in the darks: `natural` deepens yellows towards amber and blues towards indigo, as Tailwind's do, and leaves other hues; a number is degrees at 950 (`--hue-drift=-20` for a negative one).
215
+
216
+ The neutral keeps its own range, tint, colourfulness and hue, because both modes' backgrounds are made from it; name it in `"families"` to change it. In a seed: `"lightnessRange": { "dark": 34 }, "tintFloor": 0.6, "chroma": { "profile": "constant" }, "hueDrift": "natural"`. Unset, the output is exactly as before.
217
+
218
+ **The step contract.** A step number should mean the same in every colour: if 700 carries text on white in one, it should in all, so a designer can reach for "the 700" without checking. `--contract` prints each step that carries text on white, or on black, in some colours and not others. It's measured, not enforced: a yellow brand seeded on 500 breaks it by nature, and that's worth knowing rather than forbidding.
219
+
183
220
  ## Regenerating part of a token file
184
221
 
185
222
  The problem this solves: an agent asked to "change the reds" regenerates the whole file and wipes out every hand-edit someone made to the primary.
@@ -344,6 +381,16 @@ A seed file:
344
381
  | `--usage <file.json>` | — | — | Also write where each colour can go: every fill, status text tone and muted text on every background, per mode, as text, shape or neither (`designtools.usage/1`). `@designtools/manifest` turns the failures into measured usage rules. `--check` compares it too. |
345
382
  | `--seed-shade` | `25`…`950` | `500` | Which step your primary lands on. |
346
383
  | `--neutral-seed-shade` | `25`…`950` | `500` | Which step your neutral lands on. |
384
+ | `--light-end` | `50`…`100` | `98` | OKLCH lightness (percent) of the colour ramps' palest step. Not the neutral. |
385
+ | `--dark-end` | `0`…`60` | `15` | OKLCH lightness (percent) the colour ramps' deepest step reaches. Not the neutral. At least 30 below `--light-end`. |
386
+ | `--tint-floor` | `0`…`1` | none | How much of the seed's colourfulness the pale steps keep. Not the neutral. |
387
+ | `--chroma` | `follow` · `constant` · `relative` · `peak` | `follow` | How colourful each step is. Not the neutral. |
388
+ | `--chroma-strength` | `0.25`…`3` | `1` | More or less colour, eased in beside the seed. |
389
+ | `--chroma-peak` | `25`…`950` | the seed's step | Where `--chroma peak` peaks. |
390
+ | `--hue-drift` | `none` · `natural` · degrees | `none` | How the hue turns in the darks. Not the neutral. |
391
+ | `--pin` | `family@step=colour` | — | An exact colour on a step; the ramp bends through it. Repeatable. |
392
+ | `--no-aliases` | — | — | Each status ramp once, as success, destructive and warning, without green, red and yellow as second names for the same ramps. |
393
+ | `--contract` | — | — | Print the step contract: steps that carry text on white or black in some colours and not others. |
347
394
  | `--gamut` | `srgb` · `p3` | `srgb` | Which displays to generate for. |
348
395
  | `--shades` | `tailwind` · `full` · a list | `full` | Which steps to emit. |
349
396
  | `--overrides <file.json>` | — | — | Per-token shade overrides. |
@@ -185,6 +185,42 @@ var LIGHTNESS_FACTORS = {
185
185
  achromatic: [0.98, 0.95, 0.9, 0.8, 0.66, 0.38, 0, -0.26, -0.44, -0.62, -0.8, -0.92]
186
186
  }
187
187
  };
188
+ function maxChroma(lightness, hue, gamut = "srgb") {
189
+ const capped = clampChroma({ mode: "oklch", l: lightness, c: 0.4, h: hue }, "oklch", GAMUT_SPACE[gamut]);
190
+ return capped.c ?? 0;
191
+ }
192
+ function hueDriftDegrees(drift, hue, achromatic) {
193
+ if (achromatic || drift === void 0 || drift === "none") return 0;
194
+ if (typeof drift === "number") return drift;
195
+ if (hue >= 60 && hue <= 125) return -Math.min(25, 0.3 * (hue - 40));
196
+ if (hue >= 180 && hue < 275) return Math.min(25, 0.3 * (275 - hue));
197
+ return 0;
198
+ }
199
+ function refitThroughPins(lightness, anchor, pins) {
200
+ const n = lightness.length;
201
+ const held = new Map([[0, lightness[0]], [n - 1, lightness[n - 1]], [anchor, lightness[anchor]], ...pins]);
202
+ const at = [...held.keys()].sort((a, b) => a - b);
203
+ const out = [...lightness];
204
+ for (let k = 0; k < at.length - 1; k++) {
205
+ const a = at[k];
206
+ const b = at[k + 1];
207
+ const da = held.get(a) - lightness[a];
208
+ const db = held.get(b) - lightness[b];
209
+ for (let i = a; i <= b; i++) {
210
+ const t = (i - a) / (b - a);
211
+ out[i] = lightness[i] + da * (1 - t) + db * t;
212
+ }
213
+ }
214
+ for (let i = 1; i < n; i++) {
215
+ if (out[i] > out[i - 1] + 1e-9) {
216
+ throw new Error(
217
+ `an exact colour puts steps ${VALID_SHADES[i - 1]} and ${VALID_SHADES[i]} out of order (${(out[i - 1] * 100).toFixed(1)}% then ${(out[i] * 100).toFixed(1)}% lightness): it has to be darker than the steps above it and lighter than those below`
218
+ );
219
+ }
220
+ }
221
+ return out;
222
+ }
223
+ var MIN_DARK_STEP = 0.02;
188
224
  function printOklch(l, c, h) {
189
225
  return `oklch(${l} ${c.toFixed(4)} ${h})`;
190
226
  }
@@ -211,8 +247,9 @@ function buildScale(baseColor, strategy, options) {
211
247
  const seedShade = options?.seedShade ?? DEFAULT_SEED_SHADE;
212
248
  const emitted = resolveShades(options?.shades);
213
249
  const gamut = options?.gamut ?? "srgb";
214
- const maxLightness = Math.max(0.98, baseLightness);
215
- const minLightness = Math.min(0.15, baseLightness);
250
+ const below = VALID_SHADES.length - 1 - VALID_SHADES.indexOf(seedShade);
251
+ const maxLightness = Math.max(options?.lightEnd ?? 0.98, baseLightness);
252
+ const minLightness = Math.min(options?.darkEnd !== void 0 ? Math.min(options.darkEnd, baseLightness - MIN_DARK_STEP * below) : 0.15, baseLightness);
216
253
  const headroomUp = maxLightness - baseLightness;
217
254
  const headroomDown = baseLightness - minLightness;
218
255
  const factors = reanchorFactors(
@@ -220,21 +257,56 @@ function buildScale(baseColor, strategy, options) {
220
257
  seedShade
221
258
  );
222
259
  const computeChroma = strategy === "perceptual" ? computeScaleChromaPerceptual : computeScaleChroma;
260
+ const n = VALID_SHADES.length;
261
+ const anchor = VALID_SHADES.indexOf(seedShade);
262
+ const pins = /* @__PURE__ */ new Map();
263
+ for (const [step, colour] of Object.entries(options?.pins ?? {})) {
264
+ if (!colour) continue;
265
+ const i = VALID_SHADES.indexOf(Number(step));
266
+ if (i === -1) throw new Error(`${step} is not a step (${VALID_SHADES.join(", ")})`);
267
+ if (i === anchor) throw new Error(`${step} is where the ramp's own colour lands: change that colour instead`);
268
+ if (!isInGamut(colour, gamut)) throw new Error(`the exact colour on ${step}, ${colour}, can't be shown on ${gamut === "p3" ? "a P3" : "an sRGB"} screen`);
269
+ pins.set(i, parseToOklch(colour));
270
+ }
271
+ let lightness = VALID_SHADES.map((_, i) => {
272
+ if (i === anchor) return baseLightness;
273
+ const factor = factors[i];
274
+ const target = factor >= 0 ? baseLightness + headroomUp * factor : baseLightness + headroomDown * factor;
275
+ return Math.max(minLightness, Math.min(maxLightness, target));
276
+ });
277
+ if (pins.size) lightness = refitThroughPins(lightness, anchor, new Map([...pins].map(([i, c]) => [i, c.l])));
278
+ const drift = hueDriftDegrees(options?.hueDrift, baseHue, isAchromatic);
279
+ const hueAt = (i) => drift && i > anchor ? ((baseHue + drift * (i - anchor) / (n - 1 - anchor)) % 360 + 360) % 360 : baseHue;
280
+ const profile = options?.chroma?.profile ?? "follow";
281
+ const strength = options?.chroma?.strength ?? 1;
282
+ const peak = VALID_SHADES.indexOf(options?.chroma?.peakAt ?? seedShade);
283
+ const bell = (i) => Math.exp(-(((i - peak) / 2.5) ** 2));
284
+ const share = profile === "relative" ? baseChroma / Math.max(1e-6, maxChroma(baseLightness, baseHue, gamut)) : 0;
285
+ const chromaAt = (i) => {
286
+ if (isAchromatic) return baseChroma;
287
+ let c;
288
+ if (profile === "constant") c = baseChroma;
289
+ else if (profile === "relative") c = maxChroma(lightness[i], hueAt(i), gamut) * share;
290
+ else if (profile === "peak") c = baseChroma * bell(i) / bell(anchor);
291
+ else c = computeChroma((chromaShadeFor(i, seedShade) - 25) / 925, baseChroma);
292
+ if (strength !== 1) c *= 1 + (strength - 1) * Math.min(1, Math.abs(i - anchor) / 2);
293
+ if (options?.tintFloor !== void 0 && i < anchor) c = Math.max(c, baseChroma * options.tintFloor);
294
+ return c;
295
+ };
223
296
  const scale = {};
224
- for (let i = 0; i < VALID_SHADES.length; i++) {
297
+ for (let i = 0; i < n; i++) {
225
298
  const shade = VALID_SHADES[i];
226
299
  if (!emitted.includes(shade)) continue;
227
- if (shade === seedShade) {
300
+ if (i === anchor) {
228
301
  scale[shade] = formatOklchInGamut(baseLightness, baseChroma, baseHue, gamut);
229
302
  continue;
230
303
  }
231
- const factor = factors[i];
232
- const target = factor >= 0 ? baseLightness + headroomUp * factor : baseLightness + headroomDown * factor;
233
- const lightness = Math.max(minLightness, Math.min(maxLightness, target));
234
- const chromaShade = chromaShadeFor(i, seedShade);
235
- const normalizedPosition = (chromaShade - 25) / 925;
236
- const chroma = isAchromatic ? baseChroma : computeChroma(normalizedPosition, baseChroma);
237
- scale[shade] = formatOklchInGamut(lightness, chroma, baseHue, gamut);
304
+ const pin = pins.get(i);
305
+ if (pin) {
306
+ scale[shade] = formatOklchInGamut(pin.l, pin.c ?? 0, pin.h ?? 0, gamut);
307
+ continue;
308
+ }
309
+ scale[shade] = formatOklchInGamut(lightness[i], chromaAt(i), hueAt(i), gamut);
238
310
  }
239
311
  return scale;
240
312
  }
@@ -422,13 +494,40 @@ function deriveWarningColor(primaryColor) {
422
494
  };
423
495
  return oklchToHex(warning);
424
496
  }
497
+ function byFamily(map, name) {
498
+ if (!map) return void 0;
499
+ const alias = aliasOf(name);
500
+ return map[name] ?? (alias ? map[alias] : void 0);
501
+ }
502
+ function shapeFor(name, options) {
503
+ const system = name === "neutral" ? {} : { lightEnd: options?.lightEnd, darkEnd: options?.darkEnd, tintFloor: options?.tintFloor, chroma: options?.chroma, hueDrift: options?.hueDrift };
504
+ const own = byFamily(options?.families, name);
505
+ if (!own) return system;
506
+ const chroma = own.chroma || system.chroma ? { ...system.chroma, ...own.chroma } : void 0;
507
+ return {
508
+ ...system,
509
+ ...own.lightnessRange?.light !== void 0 ? { lightEnd: own.lightnessRange.light } : {},
510
+ ...own.lightnessRange?.dark !== void 0 ? { darkEnd: own.lightnessRange.dark } : {},
511
+ ...own.tintFloor !== void 0 ? { tintFloor: own.tintFloor } : {},
512
+ ...chroma ? { chroma } : {},
513
+ ...own.hueDrift !== void 0 ? { hueDrift: own.hueDrift } : {}
514
+ };
515
+ }
425
516
  function generatePrimitivePalette(brandColors, lightnessStrategy = "fixed", options) {
426
517
  const gen = lightnessStrategy === "perceptual" ? generateColorScaleAPCA : generateColorScale;
427
- const genScale = (name, color) => gen(color, {
428
- shades: options?.shades,
429
- gamut: options?.gamut,
430
- seedShade: familySeedShade(name, options?.seedShade, options?.seedShades)
431
- });
518
+ const genScale = (name, color) => {
519
+ try {
520
+ return gen(color, {
521
+ shades: options?.shades,
522
+ gamut: options?.gamut,
523
+ seedShade: familySeedShade(name, options?.seedShade, options?.seedShades),
524
+ ...shapeFor(name, options),
525
+ pins: byFamily(options?.familyPins, name)
526
+ });
527
+ } catch (error) {
528
+ throw new Error(`${name}: ${error.message}`);
529
+ }
530
+ };
432
531
  const palette = {};
433
532
  palette.black = "oklch(0 0 0)";
434
533
  palette.white = "oklch(1 0 0)";
@@ -454,6 +553,7 @@ function generatePrimitivePalette(brandColors, lightnessStrategy = "fixed", opti
454
553
  else if (overrodeAlias && !overrodeSemantic) palette[semantic] = palette[alias];
455
554
  }
456
555
  }
556
+ if (options?.aliases === false) for (const [, alias] of ALIAS_PAIRS) delete palette[alias];
457
557
  return palette;
458
558
  }
459
559
  function getShade(palette, colorName, shade) {
@@ -1049,7 +1149,15 @@ function generateTokens(brandColors, options) {
1049
1149
  const scaleOptions = {
1050
1150
  seedShade: options?.seedShade,
1051
1151
  seedShades: options?.seedShades,
1052
- shades: options?.shades
1152
+ shades: options?.shades,
1153
+ lightEnd: options?.lightnessRange?.light,
1154
+ darkEnd: options?.lightnessRange?.dark,
1155
+ tintFloor: options?.tintFloor,
1156
+ chroma: options?.chroma,
1157
+ hueDrift: options?.hueDrift,
1158
+ families: options?.families,
1159
+ familyPins: options?.pins,
1160
+ aliases: options?.aliases
1053
1161
  };
1054
1162
  const primitives = generatePrimitivePalette(brandColors, strategy, { ...scaleOptions, gamut: "srgb" });
1055
1163
  const wide = options?.gamut === "p3" ? generatePrimitivePalette(brandColors, strategy, { ...scaleOptions, gamut: "p3" }) : void 0;
@@ -1895,6 +2003,31 @@ function diffSlice(target, slice) {
1895
2003
  return { matches: differing.length === 0 && missing.length === 0, differing, missing };
1896
2004
  }
1897
2005
 
2006
+ // src/contract.ts
2007
+ var ALIASES = new Set(ALIAS_PAIRS.map(([, alias]) => alias));
2008
+ var TEXT = 4.5;
2009
+ function stepContract(palette) {
2010
+ const families = Object.entries(palette).filter(([name, scale]) => typeof scale === "object" && name !== "neutral" && !ALIASES.has(name)).map(([name, scale]) => [name, scale]);
2011
+ const out = [];
2012
+ for (const step of VALID_SHADES) {
2013
+ for (const [role, ground] of [
2014
+ ["text on white", "#ffffff"],
2015
+ ["text on black", "#000000"]
2016
+ ]) {
2017
+ const holds = [];
2018
+ const fails = [];
2019
+ for (const [name, scale] of families) {
2020
+ const colour = scale[step];
2021
+ if (!colour) continue;
2022
+ (getContrastRatio(colour, ground) >= TEXT ? holds : fails).push(name);
2023
+ }
2024
+ if (!holds.length || !fails.length) continue;
2025
+ out.push({ step, role, holds, fails, odd: fails.length <= holds.length ? fails : holds });
2026
+ }
2027
+ }
2028
+ return out;
2029
+ }
2030
+
1898
2031
  // src/seed.ts
1899
2032
  var GENERATOR_NAME = "@designtools/tokens";
1900
2033
  function stableStringify(value) {
@@ -1935,6 +2068,22 @@ function withJsonProvenance(json, p) {
1935
2068
  };
1936
2069
  return JSON.stringify(stamped, null, 2);
1937
2070
  }
2071
+ function rangeOf(seed) {
2072
+ const r = seed.lightnessRange;
2073
+ if (!r || r.light === void 0 && r.dark === void 0) return void 0;
2074
+ return { ...r.light !== void 0 ? { light: r.light / 100 } : {}, ...r.dark !== void 0 ? { dark: r.dark / 100 } : {} };
2075
+ }
2076
+ function familiesOf(seed) {
2077
+ const entries = Object.entries(seed.families ?? {}).filter(([, f]) => f && Object.keys(f).length);
2078
+ if (!entries.length) return void 0;
2079
+ return Object.fromEntries(
2080
+ entries.map(([name, f]) => {
2081
+ const range = f.lightnessRange ? rangeOf({ lightnessRange: f.lightnessRange }) : void 0;
2082
+ const { lightnessRange: _, ...rest } = f;
2083
+ return [name, { ...rest, ...range ? { lightnessRange: range } : {} }];
2084
+ })
2085
+ );
2086
+ }
1938
2087
 
1939
2088
  export {
1940
2089
  APCAUnavailableError,
@@ -2001,11 +2150,14 @@ export {
2001
2150
  readDeclarations,
2002
2151
  mergeSlice,
2003
2152
  diffSlice,
2153
+ stepContract,
2004
2154
  GENERATOR_NAME,
2005
2155
  stableStringify,
2006
2156
  fingerprint,
2007
2157
  seedFingerprint,
2008
2158
  provenanceComment,
2009
2159
  parseProvenance,
2010
- withJsonProvenance
2160
+ withJsonProvenance,
2161
+ rangeOf,
2162
+ familiesOf
2011
2163
  };
package/dist/cli.js CHANGED
@@ -16,6 +16,7 @@ import {
16
16
  exportTokens,
17
17
  extendedBridgeShades,
18
18
  externalReferences,
19
+ familiesOf,
19
20
  generateTokens,
20
21
  isAPCAAvailable,
21
22
  isInGamut,
@@ -30,10 +31,11 @@ import {
30
31
  selectTokenSections,
31
32
  serialiseUsage,
32
33
  snapShade,
34
+ stepContract,
33
35
  tokenFamilies,
34
36
  usageReport,
35
37
  withJsonProvenance
36
- } from "./chunk-P562LKFL.js";
38
+ } from "./chunk-YOUMF42P.js";
37
39
 
38
40
  // src/cli.ts
39
41
  import { parseArgs } from "util";
@@ -94,6 +96,27 @@ Generation options:
94
96
  every family.) Anchor the others with
95
97
  --neutral-seed-shade and --color name=colour@shade.
96
98
  --neutral-seed-shade <25..950> Which step the neutral seed lands on. Default: 500.
99
+ --light-end <50..100> OKLCH lightness (percent) of the colour ramps' palest
100
+ step. Default: 98. The neutral keeps its own range.
101
+ --dark-end <0..60> OKLCH lightness (percent) the colour ramps' deepest step
102
+ reaches. Default: 15. Raise it for a brand that only uses
103
+ soft deep tones; adjacent dark steps keep a 2-point gap.
104
+ --tint-floor <0..1> How much of the seed's colourfulness the pale steps keep.
105
+ Default: none (they fade towards grey).
106
+ --chroma <profile> How colourful each step is: follow (default; eases from
107
+ pale tints to the seed's chroma), constant (the seed's
108
+ chroma throughout, as the screen allows), relative (the
109
+ seed's share of what each step can hold) or peak.
110
+ --chroma-strength <0.25..3> More or less colour than the seed's, eased in beside it;
111
+ the seed's own step never moves. Default: 1.
112
+ --chroma-peak <25..950> Where --chroma peak peaks. Default: the seed's step.
113
+ --hue-drift <none|natural|deg> How the hue turns in the darks: natural deepens yellows
114
+ to amber and blues to indigo; a number is degrees at 950
115
+ (a negative one as --hue-drift=-20).
116
+ --pin <family@step=colour> An exact colour on a step; the ramp is refitted through
117
+ it. Refused if it puts the ramp out of order or off the
118
+ screen. Repeatable. Per-family shape (a colour leaning
119
+ away from the system) is set in a --seed file: "families".
97
120
  --shades <list|preset> Which steps to emit. Default: all twelve (25-950).
98
121
  Presets: tailwind (50-950, matching Tailwind's
99
122
  stock ramps) and full. Or a list: 50,100,500,900.
@@ -171,6 +194,13 @@ Verification:
171
194
  With --ramps or --merge, only the declarations this run
172
195
  generates are compared, so hand-edited regions elsewhere
173
196
  in the file are not reported as drift.
197
+ --no-aliases Emit each status ramp once, as success, destructive and
198
+ warning, without green, red and yellow beside them as
199
+ the same ramps.
200
+ --contract Print the step contract: each step that carries text on
201
+ white (or black) in some colours and not others, so
202
+ "the 700" means the same everywhere. Measured, not
203
+ enforced.
174
204
  --report Print the measured contrast of every semantic foreground
175
205
  pairing to stderr, with an overall score against the
176
206
  --contrast algorithm and --target level. Writes no files
@@ -223,6 +253,15 @@ try {
223
253
  gamut: { type: "string" },
224
254
  "seed-shade": { type: "string" },
225
255
  "neutral-seed-shade": { type: "string" },
256
+ "light-end": { type: "string" },
257
+ "dark-end": { type: "string" },
258
+ "tint-floor": { type: "string" },
259
+ chroma: { type: "string" },
260
+ "chroma-strength": { type: "string" },
261
+ "chroma-peak": { type: "string" },
262
+ "hue-drift": { type: "string" },
263
+ pin: { type: "string", multiple: true },
264
+ "no-aliases": { type: "boolean" },
226
265
  shades: { type: "string" },
227
266
  overrides: { type: "string" },
228
267
  only: { type: "string", multiple: true },
@@ -237,6 +276,7 @@ try {
237
276
  seed: { type: "string" },
238
277
  check: { type: "boolean" },
239
278
  report: { type: "boolean" },
279
+ contract: { type: "boolean" },
240
280
  stdin: { type: "boolean" },
241
281
  "no-provenance": { type: "boolean" },
242
282
  help: { type: "boolean" }
@@ -372,6 +412,55 @@ if (shadesInput !== void 0) {
372
412
  }
373
413
  var seedShade = values["seed-shade"] !== void 0 ? parseShade("seed-shade", values["seed-shade"]) : seed.seedShade;
374
414
  var neutralSeedShade = values["neutral-seed-shade"] !== void 0 ? parseShade("neutral-seed-shade", values["neutral-seed-shade"]) : seed.neutralSeedShade;
415
+ function parseNumberIn(flag, raw, min, max) {
416
+ if (raw === void 0) return void 0;
417
+ const n = Number(String(raw).trim());
418
+ if (!Number.isFinite(n) || n < min || n > max) fail(`--${flag} must be a number from ${min} to ${max} (got "${raw}")`);
419
+ return n;
420
+ }
421
+ var lightEnd = parseNumberIn("light-end", values["light-end"] ?? seed.lightnessRange?.light, 50, 100);
422
+ var darkEnd = parseNumberIn("dark-end", values["dark-end"] ?? seed.lightnessRange?.dark, 0, 60);
423
+ if (lightEnd !== void 0 && darkEnd !== void 0 && lightEnd - darkEnd < 30) {
424
+ fail(`--light-end and --dark-end need at least 30 points between them, so the steps can be told apart (got ${lightEnd} and ${darkEnd})`);
425
+ }
426
+ var lightnessRange = lightEnd !== void 0 || darkEnd !== void 0 ? { ...lightEnd !== void 0 ? { light: lightEnd } : {}, ...darkEnd !== void 0 ? { dark: darkEnd } : {} } : void 0;
427
+ var tintFloor = parseNumberIn("tint-floor", values["tint-floor"] ?? seed.tintFloor, 0, 1);
428
+ var chromaProfile = values.chroma ?? seed.chroma?.profile;
429
+ if (chromaProfile !== void 0 && !["follow", "constant", "relative", "peak"].includes(chromaProfile)) {
430
+ fail(`--chroma must be one of: follow, constant, relative, peak (got "${chromaProfile}")`);
431
+ }
432
+ var chromaStrength = parseNumberIn("chroma-strength", values["chroma-strength"] ?? seed.chroma?.strength, 0.25, 3);
433
+ var chromaPeakRaw = values["chroma-peak"] ?? seed.chroma?.peakAt;
434
+ var chromaPeak = chromaPeakRaw !== void 0 ? parseShade("chroma-peak", chromaPeakRaw) : void 0;
435
+ var chroma = chromaProfile !== void 0 && chromaProfile !== "follow" || chromaStrength !== void 0 || chromaPeak !== void 0 ? {
436
+ ...chromaProfile !== void 0 && chromaProfile !== "follow" ? { profile: chromaProfile } : {},
437
+ ...chromaStrength !== void 0 ? { strength: chromaStrength } : {},
438
+ ...chromaPeak !== void 0 ? { peakAt: chromaPeak } : {}
439
+ } : void 0;
440
+ var hueDriftRaw = values["hue-drift"] ?? (seed.hueDrift !== void 0 ? String(seed.hueDrift) : void 0);
441
+ var hueDrift;
442
+ if (hueDriftRaw !== void 0 && hueDriftRaw !== "none") {
443
+ hueDrift = hueDriftRaw === "natural" ? "natural" : parseNumberIn("hue-drift", hueDriftRaw, -90, 90);
444
+ }
445
+ var familyShapes = seed.families && Object.keys(seed.families).length ? seed.families : void 0;
446
+ var pins = {};
447
+ for (const [name, steps] of Object.entries(seed.pins ?? {})) {
448
+ for (const [step, colour] of Object.entries(steps ?? {})) if (colour) pins[name] = { ...pins[name], [parseShade(`pin ${name}`, step)]: colour };
449
+ }
450
+ for (const raw of values.pin ?? []) {
451
+ const m = /^([a-z][\w-]*)@(\d+)=(.+)$/.exec(raw.trim());
452
+ if (!m) fail(`--pin takes family@step=colour, as in camel@300=#B7B7A3 (got "${raw}")`);
453
+ else {
454
+ try {
455
+ parseToOklch(m[3]);
456
+ } catch {
457
+ fail(`--pin ${raw}: "${m[3]}" is not a colour`);
458
+ }
459
+ pins[m[1]] = { ...pins[m[1]], [parseShade("pin", m[2])]: m[3] };
460
+ }
461
+ }
462
+ var hasPins = Object.keys(pins).length > 0;
463
+ var aliases = values["no-aliases"] === true ? false : seed.aliases ?? true;
375
464
  var seedShades = {};
376
465
  if (neutralSeedShade !== void 0) seedShades.neutral = neutralSeedShade;
377
466
  for (const [name, { flag, raw }] of Object.entries(additionalAnchors)) {
@@ -439,6 +528,13 @@ var options = {
439
528
  ...Object.keys(backgrounds).length ? { backgrounds } : {},
440
529
  seedShade,
441
530
  ...Object.keys(seedShades).length > 0 ? { seedShades } : {},
531
+ ...lightnessRange ? { lightnessRange: { ...lightnessRange.light !== void 0 ? { light: lightnessRange.light / 100 } : {}, ...lightnessRange.dark !== void 0 ? { dark: lightnessRange.dark / 100 } : {} } } : {},
532
+ ...tintFloor !== void 0 ? { tintFloor } : {},
533
+ ...chroma ? { chroma } : {},
534
+ ...hueDrift !== void 0 ? { hueDrift } : {},
535
+ ...familyShapes ? { families: familiesOf({ families: familyShapes }) } : {},
536
+ ...hasPins ? { pins } : {},
537
+ ...aliases ? {} : { aliases: false },
442
538
  ...decorative.size > 0 ? { decorative: [...decorative].sort() } : {},
443
539
  shades,
444
540
  shadeOverrides: overrides.shadeOverrides ?? {},
@@ -482,7 +578,13 @@ for (const [flag, why] of [
482
578
  `);
483
579
  }
484
580
  }
485
- var tokens = generateTokens(brandColors, options);
581
+ var tokens;
582
+ try {
583
+ tokens = generateTokens(brandColors, options);
584
+ } catch (error) {
585
+ if (error instanceof APCAUnavailableError) throw error;
586
+ fail(error.message);
587
+ }
486
588
  if (families.length > 0) {
487
589
  const known = tokenFamilies(tokens);
488
590
  const unknown = families.filter((f) => !known.includes(f));
@@ -536,6 +638,15 @@ var resolvedSeed = {
536
638
  ...Object.keys(backgrounds).length ? { backgrounds } : {},
537
639
  seedShade,
538
640
  neutralSeedShade,
641
+ // left out when unset, so a seed without them keeps the fingerprint it always had
642
+ ...lightnessRange ? { lightnessRange } : {},
643
+ ...tintFloor !== void 0 ? { tintFloor } : {},
644
+ ...chroma ? { chroma } : {},
645
+ ...hueDrift !== void 0 ? { hueDrift } : {},
646
+ ...familyShapes ? { families: familyShapes } : {},
647
+ ...hasPins ? { pins } : {},
648
+ // left out when on, the default, so existing seeds keep their fingerprint
649
+ ...aliases ? {} : { aliases: false },
539
650
  shades,
540
651
  shadeOverrides: options.shadeOverrides ?? {},
541
652
  surfaceShadeOverrides: options.surfaceShadeOverrides,
@@ -661,13 +772,13 @@ searched to their contrast floor (ring and input 3:1 on canvas and surface; mute
661
772
  }
662
773
  }
663
774
  function reportChroma() {
664
- const chroma = checkRampChroma(tokens.primitives);
775
+ const chroma2 = checkRampChroma(tokens.primitives);
665
776
  const unintended = ([name, r]) => r.low && name !== "neutral";
666
- const low = Object.entries(chroma).filter(unintended);
777
+ const low = Object.entries(chroma2).filter(unintended);
667
778
  process.stderr.write(`
668
779
  ramp chroma (peak C per family)
669
780
  `);
670
- for (const [name, r] of Object.entries(chroma)) {
781
+ for (const [name, r] of Object.entries(chroma2)) {
671
782
  const mark = unintended([name, r]) ? "grey" : " ";
672
783
  process.stderr.write(` ${mark} ${name.padEnd(14)} ${r.peak.toFixed(4)} at ${r.atShade}
673
784
  `);
@@ -765,6 +876,17 @@ ${mode} mode${label} (${contrastAlgorithm}, target ${contrastTarget})
765
876
  reportSurfaces();
766
877
  }
767
878
  if (values.report) report();
879
+ if (values.contract) {
880
+ const breaks = stepContract(tokens.primitives);
881
+ process.stderr.write(`
882
+ step contract (does a step mean the same in every colour?)
883
+ `);
884
+ if (!breaks.length) process.stderr.write(" every step carries text on white, and on black, in every colour or in none\n");
885
+ for (const b of breaks) {
886
+ process.stderr.write(` ${String(b.step).padStart(3)} ${b.role}: ${b.holds.join(", ")} yes; ${b.fails.join(", ")} no
887
+ `);
888
+ }
889
+ }
768
890
  var formats = format === "all" ? Object.keys(FILE_NAMES) : [format];
769
891
  var isSlice = families.length > 0 || sections.length > 0;
770
892
  function reportExternalReferences(css) {