@designtools/tokens 0.12.0 → 0.13.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,12 @@
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.13.0
6
+
7
+ ### Minor Changes
8
+
9
+ - 8fed30f: `--ground-action` says where a ground's main button comes from, when the tint's answer is wrong: `page` keeps the page's button as it is (a pale brand colour its label carries, lime on a mist band as on the page), `own` takes the ground's own colour turned over, and a colour sets the fill, its label measured on it or given after a slash (`--ground-action yellow=neutral-950/primary-400`, ink with a yellow label on a yellow band). Unset, the button follows the tint as before. In a seed, `"action"` on a ground or `"groundAction"`; the report, `--check`, the seed round trip and the colour editor (a Button control on each ground) carry it.
10
+
5
11
  ## 0.12.0
6
12
 
7
13
  ### Minor Changes
package/README.md CHANGED
@@ -59,6 +59,8 @@ Two pairs of words look alike and aren't:
59
59
  | a success, warning or error banner | the page's `-subdued` tokens (`bg-success-subdued text-success-subdued-foreground`); no ground |
60
60
  | white lines, edges and focus ring on a dark band, text as usual | a ground with `--ground-tint white` (text on a dark ground is white anyway) |
61
61
  | lines and panels in a band's own hue, text in the page's | a ground, as it comes (`tint own`, `text page`) |
62
+ | the page's pale brand button kept as it is on a band | `--ground-action <name>=page` |
63
+ | a band's button in another colour (ink on a yellow band) | `--ground-action <name>=neutral-950`, its label after a slash if you name it |
62
64
  | a card inside a band that reads as the page again | `data-surface="canvas"` on the card |
63
65
 
64
66
  ## What it generates
@@ -194,6 +196,16 @@ Defaults: `text page`, `tint own`. So text is one standard set across a site, an
194
196
 
195
197
  **Buttons and other colours keep the page's value unless it fails.** The primary and secondary buttons, accent, success, error and warning are the page's wherever they stand out from the ground (3:1 for a fill, with a label that reads on it). One that doesn't is searched along its own ramp: a navy button on deep green moves to a step that shows. Under `tint own` (and one colour) the primary button is drawn from the ground's ramp (on its own colour it turns over: the deepest step with the ground's colour in its label), and the secondary button is tonal: a tint of the ground's hue whose label carries it.
196
198
 
199
+ **Where the main button comes from, when the tint's answer is wrong: `--ground-action`.** Unset, the primary button follows the tint, as above. Three values change it, for `--primary`, its label, hover and pressed:
200
+
201
+ | Value | The button |
202
+ | --- | --- |
203
+ | `page` | the page's, as it is, wherever it lands. For a pale brand colour that its label carries on the page (lime at 1.1:1 on cream), so a band doesn't turn it into another colour. The report notes the ratio. |
204
+ | `own` | the ground's own colour: kept where it stands out, turned over on its ramp where it doesn't, under any tint |
205
+ | one colour: `white`, `black`, a step (`neutral-950`) | that fill, its label measured on it, or given after a slash (`neutral-950/primary-400`). Hover and pressed step along the fill's ramp. The report notes a fill under 3:1 or a label under the text floor. |
206
+
207
+ Only the main button: the secondary and status buttons are searched as before. As the others, a bare value sets every ground and `<name>=<value>` one; in a seed, `"action"` on the ground or `"groundAction"`.
208
+
197
209
  **Resetting inside a ground.** `data-surface="canvas"` on a card or a nested section gives it the page's tokens as they are in the current mode, with nothing extra generated: the page's mode blocks match it.
198
210
 
199
211
  **Banners aren't grounds.** A success, warning or error banner is the page's `-subdued` pair. Its text always reads (it is measured on the page), and `--report` lists where a filled button blends into a tint, so the banner can use the outline button there.
@@ -589,6 +601,7 @@ A seed file:
589
601
  | `--ground` | `<name>=<ramp>@<step>` | — | A [ground](#grounds): a section painted that step, the same in both modes, with tokens that work on it inside `data-surface="<name>"`. Repeatable. |
590
602
  | `--ground-tint` | `own` · `page` · `white` · `black` · `<ramp>-<step>`, or `<name>=<value>` | `own` | Where a ground's lines, panels, card, input, ring and buttons come from. Repeatable; a named value wins. |
591
603
  | `--ground-text` | as `--ground-tint` | `page` | Where a ground's body and secondary text come from. Repeatable; a named value wins. |
604
+ | `--ground-action` | `page` · `own` · `white` · `black` · `<ramp>-<step>`, optionally `/<label>`, or `<name>=<value>` | unset: follows the tint | Where a ground's main button and its label come from. Repeatable; a named value wins. |
592
605
  | `--usage <file.json>` | — | — | Also write where each colour can go: every fill, status text tone and secondary 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. |
593
606
  | `--seed-shade` | `25`…`950` | `500` | Which step your primary lands on. |
594
607
  | `--neutral-seed-shade` | `25`…`950` | `500` | Which step your neutral lands on. |
@@ -827,7 +840,7 @@ Two consequences, both of which have cost real projects real time:
827
840
 
828
841
  Then check **both** colour schemes, not whichever your tool defaults to.
829
842
 
830
- **A token on one ground** is overridden on its scope, `[data-surface="pine"] { --border: var(--color-pine-600); }`, after the generated file and unlayered. A ground has no modes, so one selector is the whole of it. Better still, say it in the generator: `--ground-tint pine=pine-600`.
843
+ **A token on one ground** is overridden on its scope, `[data-surface="pine"] { --border: var(--color-pine-600); }`, after the generated file and unlayered. A ground has no modes, so one selector is the whole of it. Better still, say it in the generator: `--ground-tint pine=pine-600`, or for the button `--ground-action pine=neutral-950`.
831
844
 
832
845
  **Change a ramp step through its seed, not by overriding it.** Tailwind v4 utilities do read ramp steps through `var()` (checked against a Tailwind 4.3 compile), which is what lets the `--gamut p3` layer work. The one exception is an opacity modifier: `bg-primary-500/50` also emits the step's literal value as a fallback for browsers without `color-mix()`, and an override cannot reach that. But a hand-overridden step is a fork of the palette that the contrast search never saw and `--check` cannot detect. If you need a ramp step to change, change the seed and regenerate, or point the call sites at a token you do own.
833
846
 
@@ -1270,18 +1270,17 @@ function searchGround(spec, base, baseCanvas, colors, views, mode, options, acti
1270
1270
  refs.ring = inHue(base.ring) && cr(base.ring, ground) >= FILL_FLOOR ? base.ring : nearest(ringFamily, ringFrom, ground, FILL_FLOOR) ?? bestEnd(ground);
1271
1271
  for (const name of colors) {
1272
1272
  const src = tinted && (name === "primary" || name === "neutral") ? spec.family : name;
1273
- const fillRef2 = base[src];
1274
- const fillShade = fillRef2.shade;
1275
- const scaleIn = (v) => v.palette[src];
1273
+ const pageFill = base[src];
1274
+ const fillShade = pageFill.shade;
1276
1275
  const neutralIn = (v) => v.palette.neutral;
1277
- const labelOn = (bg, role2, pageGrounds = []) => {
1276
+ const labelOn = (bg, role2, pageGrounds = [], from = src) => {
1278
1277
  const found = findBestForeground(
1279
- views.map((v) => ({ background: valueOf(bg, v.palette), scale: scaleIn(v), neutral: neutralIn(v), gamut: v.gamut })),
1278
+ views.map((v) => ({ background: valueOf(bg, v.palette), scale: v.palette[from], neutral: neutralIn(v), gamut: v.gamut })),
1280
1279
  srgb.white,
1281
1280
  srgb.black,
1282
1281
  algorithm,
1283
1282
  target,
1284
- src,
1283
+ from,
1285
1284
  active,
1286
1285
  role2,
1287
1286
  options?.foreground ?? "balanced",
@@ -1296,15 +1295,40 @@ function searchGround(spec, base, baseCanvas, colors, views, mode, options, acti
1296
1295
  refs[`${name}-hover`] = { type: "value", value: stateOf(f, l, HOVER_SHIFT, views[0].gamut) };
1297
1296
  refs[`${name}-active`] = { type: "value", value: stateOf(f, l, ACTIVE_SHIFT, views[0].gamut) };
1298
1297
  };
1299
- if (tinted && name === "neutral") {
1298
+ const action = name === "primary" ? spec.action : void 0;
1299
+ if (action === "page") {
1300
+ refs[name] = base[name];
1301
+ refs[`${name}-foreground`] = base[`${name}-foreground`];
1302
+ refs[`${name}-hover`] = base[`${name}-hover`];
1303
+ refs[`${name}-active`] = base[`${name}-active`];
1304
+ if (cr(base[name], ground) < FILL_FLOOR) notes.push(`${name}: the page's, ${cr(base[name], ground).toFixed(2)}:1 against the ground (action page), carried by its label`);
1305
+ } else if (action === "own") {
1306
+ const own2 = base[spec.ramp];
1307
+ const ramp = steps(spec.ramp);
1308
+ const fill = cr(own2, ground) >= FILL_FLOOR ? own2 : light ? ramp[ramp.length - 1] : ramp[0];
1309
+ const label = sameRef(fill, own2) ? base[`${spec.ramp}-foreground`] : labelOn(fill, "tint", [], spec.ramp);
1310
+ refs[name] = fill;
1311
+ refs[`${name}-foreground`] = label;
1312
+ setStates(fill, label);
1313
+ if (cr(fill, ground) < FILL_FLOOR) notes.push(`${name}: no step of ${spec.ramp} stands out from the ground at ${FILL_FLOOR}:1 (action own)`);
1314
+ } else if (action) {
1315
+ const [fillName, labelName] = action.split("/");
1316
+ const fill = fillRef(fillName, srgb);
1317
+ const label = labelName ? fillRef(labelName, srgb) : labelOn(fill, "fill");
1318
+ refs[name] = fill;
1319
+ refs[`${name}-foreground`] = label;
1320
+ setStates(fill, label);
1321
+ if (cr(fill, ground) < FILL_FLOOR) notes.push(`${name}: ${fillName} is ${cr(fill, ground).toFixed(2)}:1 against the ground, under ${FILL_FLOOR}:1`);
1322
+ if (cr(label, fill) < textFloor) notes.push(`${name}-foreground: ${labelName ?? "the label"} is ${cr(label, fill).toFixed(2)}:1 on ${fillName}, under ${textFloor}:1`);
1323
+ } else if (tinted && name === "neutral") {
1300
1324
  const tonal = panelCandidates(steps(src), 1.6).map((fill2) => ({ fill: fill2, label: labelOn(fill2, "tint") })).find((t2) => cr(t2.label, t2.fill) >= textFloor);
1301
1325
  const fill = tonal?.fill ?? steps(src).filter(farSide)[0] ?? bestEnd(ground);
1302
1326
  const label = tonal?.label ?? labelOn(fill, "fill");
1303
1327
  refs[name] = fill;
1304
1328
  refs[`${name}-foreground`] = label;
1305
1329
  setStates(fill, label);
1306
- } else if (inHue(fillRef2) && cr(fillRef2, ground) >= FILL_FLOOR) {
1307
- refs[name] = fillRef2;
1330
+ } else if (inHue(pageFill) && cr(pageFill, ground) >= FILL_FLOOR) {
1331
+ refs[name] = pageFill;
1308
1332
  refs[`${name}-foreground`] = base[`${src}-foreground`];
1309
1333
  refs[`${name}-hover`] = base[`${src}-hover`];
1310
1334
  refs[`${name}-active`] = base[`${src}-active`];
@@ -1361,6 +1385,7 @@ function buildGround(name, given, tiers, views, options) {
1361
1385
  const polarity = light ? "light" : "dark";
1362
1386
  const tint = given.tint ?? options?.groundTint ?? "own";
1363
1387
  const text = given.text ?? options?.groundText ?? "page";
1388
+ const action = given.action ?? options?.groundAction;
1364
1389
  const notes = [];
1365
1390
  const bestEnd = (on) => cr({ type: "white" }, on) >= cr({ type: "black" }, on) ? { type: "white" } : { type: "black" };
1366
1391
  const tier = { semantic: tiers.semantic[polarity], surface: tiers.surface[polarity], utility: tiers.utility[polarity] };
@@ -1379,7 +1404,7 @@ function buildGround(name, given, tiers, views, options) {
1379
1404
  }
1380
1405
  if (cr(body, ground) < textFloor) notes.push(`canvas-foreground: ${cr(body, ground).toFixed(2)}:1, under ${textFloor}:1`);
1381
1406
  const searched = searchGround(
1382
- { name, canvas: ground, foreground: body, family: tint === "page" ? "neutral" : given.ramp, textFamily: text === "own" ? given.ramp : "neutral" },
1407
+ { name, canvas: ground, foreground: body, family: tint === "page" ? "neutral" : given.ramp, textFamily: text === "own" ? given.ramp : "neutral", ramp: given.ramp, ...action ? { action } : {} },
1383
1408
  base,
1384
1409
  page.canvas,
1385
1410
  colors,
@@ -1454,6 +1479,7 @@ function buildGround(name, given, tiers, views, options) {
1454
1479
  polarity,
1455
1480
  tint,
1456
1481
  text,
1482
+ ...action ? { action } : {},
1457
1483
  tokens: Object.fromEntries(order.map((k) => [k, valueOf(_refs[k], srgb)])),
1458
1484
  _refs,
1459
1485
  // the ground itself always; the rest where they differ from the page of the ground's polarity
package/dist/cli.js CHANGED
@@ -40,7 +40,7 @@ import {
40
40
  tokenFamilies,
41
41
  usageReport,
42
42
  withJsonProvenance
43
- } from "./chunk-TRGCDLOM.js";
43
+ } from "./chunk-HK7ME2YV.js";
44
44
 
45
45
  // src/cli.ts
46
46
  import { parseArgs as parseArgs2 } from "util";
@@ -208,6 +208,14 @@ Seeds:
208
208
  (default): the page's, where it reads; white or black
209
209
  where it doesn't. own: steps on its ramp. Or one
210
210
  colour for both. Repeatable, as --ground-tint.
211
+ --ground-action <action> or <name>=<action>
212
+ Where a ground's main button (--primary, its label and
213
+ states) comes from. Unset, it follows the tint. page:
214
+ the page's button as it is, wherever it lands (a pale
215
+ brand colour its label carries). own: the ground's own
216
+ colour, turned over on its ramp. Or a colour, with its
217
+ label measured on it or after a slash:
218
+ neutral-950/primary-400. Repeatable, as --ground-tint.
211
219
  --usage <file.json> Also write where each colour can go: every fill, status
212
220
  text tone and secondary text on every background, per mode,
213
221
  as text, shape or neither. @designtools/manifest reads it
@@ -398,6 +406,7 @@ try {
398
406
  "page-surface": { type: "string", multiple: true },
399
407
  "ground-tint": { type: "string", multiple: true },
400
408
  "ground-text": { type: "string", multiple: true },
409
+ "ground-action": { type: "string", multiple: true },
401
410
  gamut: { type: "string" },
402
411
  "seed-shade": { type: "string" },
403
412
  "neutral-seed-shade": { type: "string" },
@@ -554,6 +563,13 @@ function validateFill(flag, raw) {
554
563
  if (v === "page" || v === "own" || v === "white" || v === "black" || /^[a-z][a-z0-9-]*-\d+$/.test(v)) return v;
555
564
  fail(`--${flag} must be page, own, white, black or a step such as sage-100 (got "${raw}")`);
556
565
  }
566
+ function validateAction(flag, raw) {
567
+ const v = raw.trim();
568
+ const colour = (c) => c === "white" || c === "black" || /^[a-z][a-z0-9-]*-\d+$/.test(c);
569
+ const [fill, label, extra] = v.split("/");
570
+ if (v === "page" || v === "own" || colour(fill) && (label === void 0 || colour(label)) && extra === void 0) return v;
571
+ fail(`--${flag} must be page, own, or a colour such as neutral-950, with its label after a slash if you name it (neutral-950/primary-400) (got "${raw}")`);
572
+ }
557
573
  function rampStep(flag, raw) {
558
574
  const m = /^([a-z][a-z0-9-]*)@(\d+)$/.exec(raw.trim());
559
575
  if (!m || !VALID_SHADES.includes(Number(m[2]))) fail(`${flag} expects <ramp>@<step>, with a step of ${VALID_SHADES.join(", ")} (got "${raw}")`);
@@ -577,8 +593,8 @@ for (const entry of values.ground ?? []) {
577
593
  if (eq === -1) fail(`--ground expects name=<ramp>@<step> (got "${entry}")`);
578
594
  const name = entry.slice(0, eq).trim();
579
595
  if (!/^[a-z][a-z0-9-]*$/.test(name) || name === "canvas") fail(`--ground name must be lower-case kebab-case, and not "canvas" (got "${name}")`);
580
- const { tint, text } = grounds[name] ?? {};
581
- grounds[name] = { ...rampStep(`--ground ${name}`, entry.slice(eq + 1)), ...tint ? { tint } : {}, ...text ? { text } : {} };
596
+ const { tint, text, action } = grounds[name] ?? {};
597
+ grounds[name] = { ...rampStep(`--ground ${name}`, entry.slice(eq + 1)), ...tint ? { tint } : {}, ...text ? { text } : {}, ...action ? { action } : {} };
582
598
  }
583
599
  function fills(flag, key, seeded, fallback) {
584
600
  let all = seeded ?? fallback;
@@ -596,6 +612,17 @@ function fills(flag, key, seeded, fallback) {
596
612
  }
597
613
  var groundTint = fills("ground-tint", "tint", seed.groundTint, "own");
598
614
  var groundText = fills("ground-text", "text", seed.groundText, "page");
615
+ var groundAction = seed.groundAction;
616
+ for (const entry of values["ground-action"] ?? []) {
617
+ const eq = entry.indexOf("=");
618
+ if (eq === -1) {
619
+ groundAction = validateAction("ground-action", entry);
620
+ continue;
621
+ }
622
+ const name = entry.slice(0, eq).trim();
623
+ if (!grounds[name]) fail(`--ground-action names no ground: ${name} (grounds: ${Object.keys(grounds).join(", ") || "none"})`);
624
+ grounds[name] = { ...grounds[name], action: validateAction(`ground-action ${name}`, entry.slice(eq + 1)) };
625
+ }
599
626
  var hasSurfaceColors = Object.keys(surfaceColors.light).length + Object.keys(surfaceColors.dark).length > 0;
600
627
  var gamut = validateChoice("gamut", values.gamut ?? seed.gamut, ["srgb", "p3"], "srgb");
601
628
  var format = validateChoice(
@@ -738,6 +765,7 @@ var options = {
738
765
  ...Object.keys(grounds).length ? { grounds } : {},
739
766
  ...groundTint !== "own" ? { groundTint } : {},
740
767
  ...groundText !== "page" ? { groundText } : {},
768
+ ...groundAction ? { groundAction } : {},
741
769
  seedShade,
742
770
  ...Object.keys(seedShades).length > 0 ? { seedShades } : {},
743
771
  ...lightnessRange ? { lightnessRange: { ...lightnessRange.light !== void 0 ? { light: lightnessRange.light / 100 } : {}, ...lightnessRange.dark !== void 0 ? { dark: lightnessRange.dark / 100 } : {} } } : {},
@@ -852,6 +880,7 @@ var resolvedSeed = {
852
880
  ...Object.keys(grounds).length ? { grounds } : {},
853
881
  ...groundTint !== "own" ? { groundTint } : {},
854
882
  ...groundText !== "page" ? { groundText } : {},
883
+ ...groundAction ? { groundAction } : {},
855
884
  seedShade,
856
885
  neutralSeedShade,
857
886
  // left out when unset, so a seed without them keeps the fingerprint it always had
@@ -1105,7 +1134,7 @@ function reportGrounds() {
1105
1134
  grounds: what data-surface="<ground>" writes (ratio against the ground; a label's against its fill)
1106
1135
  `);
1107
1136
  for (const [name, g] of grounds2) {
1108
- process.stderr.write(` ${name.padEnd(14)}${g.ramp}@${g.step}, ${g.polarity}, text ${g.text}, tint ${g.tint}
1137
+ process.stderr.write(` ${name.padEnd(14)}${g.ramp}@${g.step}, ${g.polarity}, text ${g.text}, tint ${g.tint}${g.action ? `, action ${g.action}` : ""}
1109
1138
  `);
1110
1139
  const shown = g.own.filter((t) => t !== "canvas" && !t.endsWith("-hover") && !t.endsWith("-active"));
1111
1140
  const items = shown.map((t) => `${t} ${step(g._refs[t])} ${getContrastRatio(g.tokens[t], g.tokens[under(t)]).toFixed(1)}`);
package/dist/index.d.ts CHANGED
@@ -198,6 +198,17 @@ interface TokenSystem {
198
198
  * `black`, or a step written `<ramp>-<step>` (`sage-100`).
199
199
  */
200
200
  type GroundFill = "page" | "own" | "white" | "black" | `${string}-${number}`;
201
+ /** A colour a ground's button can be: `white`, `black`, or a step written `<ramp>-<step>` */
202
+ type GroundColour = "white" | "black" | `${string}-${number}`;
203
+ /**
204
+ * Where a ground's main button (`--primary`, its label and states) comes from. Unset, it follows
205
+ * the tint: from the ground's ramp under `own` or one colour, the page's under `page` where it
206
+ * stands out and searched along its ramp where it doesn't. `page`: the page's button as it is,
207
+ * wherever it lands (a pale brand colour its label carries on the page, kept on a band too).
208
+ * `own`: the ground's own colour, turned over on its own ramp. Or a colour: that fill, with its
209
+ * label measured on it, or given after a slash (`neutral-950/primary-400`).
210
+ */
211
+ type GroundAction = "page" | "own" | GroundColour | `${GroundColour}/${GroundColour}`;
201
212
  /** A ground as declared: the ramp and step it is painted, and where its tokens come from */
202
213
  interface GroundSpec {
203
214
  ramp: string;
@@ -206,6 +217,8 @@ interface GroundSpec {
206
217
  tint?: GroundFill;
207
218
  /** Body and secondary text. Default: `page` */
208
219
  text?: GroundFill;
220
+ /** The main button. Default: unset, following the tint */
221
+ action?: GroundAction;
209
222
  }
210
223
  /** Where a ground token comes from: a ramp step, black or white (a page surface given as a colour stays a value) */
211
224
  type GroundRef = ForegroundRef | {
@@ -228,6 +241,8 @@ interface GroundTokens {
228
241
  polarity: "light" | "dark";
229
242
  tint: GroundFill;
230
243
  text: GroundFill;
244
+ /** Where its main button comes from, when it doesn't follow the tint */
245
+ action?: GroundAction;
231
246
  tokens: Record<string, string>;
232
247
  _refs: Record<string, GroundRef>;
233
248
  /** The tokens this ground writes, in order: those that differ from the page's of its polarity */
@@ -435,6 +450,8 @@ interface GenerationOptions {
435
450
  groundTint?: GroundFill;
436
451
  /** Where every ground's text comes from, unless it says otherwise. Default `page` */
437
452
  groundText?: GroundFill;
453
+ /** Where every ground's main button comes from, unless it says otherwise. Default: the tint's */
454
+ groundAction?: GroundAction;
438
455
  /**
439
456
  * Which steps to emit. Default: all twelve (25–950).
440
457
  * Tokens naming a dropped step are snapped to the nearest emitted one.
@@ -511,6 +528,7 @@ interface SavedConfig {
511
528
  grounds?: GenerationOptions["grounds"];
512
529
  groundTint?: GroundFill;
513
530
  groundText?: GroundFill;
531
+ groundAction?: GroundAction;
514
532
  shadeOverrides: SemanticShadeOverrides;
515
533
  surfaceShadeOverrides?: GenerationOptions["surfaceShadeOverrides"];
516
534
  utilityShadeOverrides?: GenerationOptions["utilityShadeOverrides"];
@@ -1279,4 +1297,4 @@ declare function applyScaleOverrides(tiers: ScaleTier[], overrides: Record<strin
1279
1297
  type ScaleFormat = "css" | "tailwind-v4" | "tailwind-v3" | "dtcg" | "json";
1280
1298
  declare function exportScale(tiers: ScaleTier[], format: ScaleFormat, header?: string): string;
1281
1299
 
1282
- export { ALIAS_PAIRS, type APCAContrastResult, APCAUnavailableError, type BrandColors, type CVDType, type ChromaProfile, type ChromaShape, type ColorFormat, type ColorScale, type ContractBreak, type ContrastAlgorithm, type ContrastTarget, DEFAULT_NEUTRAL_COLOR, DEFAULT_SEED_SHADE, type Declaration, type ExportFormat, type ExportOptions, type ExtendedSemanticColor, type FamilyShape, type ForegroundRef, GENERATOR_NAME, GROUND_BASE_TOKENS, GROUND_COLOR_PARTS, GROUND_SELECTOR, type Gamut, type GamutTokens, type GenerationOptions, type GroundFill, type GroundRef, type GroundSpec, type GroundTokens, type HueDrift, type LightnessStrategy, type MergeResult, type PageContrast, type PageSurface, type PaletteOptions, type PrimitivePalette, type Provenance, SECTIONED_FORMATS, SHADE_PRESETS, type SavedConfig, type ScaleFormat, type ScaleOptions, type ScaleOverride, type ScaleTier, type ScaleTierId, type ScaleToken, type SeedFile, type SelectedTokens, type SemanticColorPair, type SemanticGamuts, type SemanticShadeOverrides, type SemanticTokens, type ShadeNumber, type SliceDiff, type SurfaceRef, type SurfaceShadeOverrides, type SurfaceTokens, TAILWIND_SHADES, TOKEN_SECTIONS, type TokenSection, type TokenSystem, type UsageReport, type UsageVerdict, type UtilityShadeOverrides, type UtilityTokens, VALID_SHADES, type VariantShadeOverrides, type WCAGContrastResult, WIDE_GAMUT_QUERY, adjustChroma, adjustLightness, aliasOf, applyScaleOverrides, checkRampChroma, checkSemanticContrast, checkSemanticContrastAPCA, checkSurfaceContrast, chromaShadeFor, classifyAPCALevel, computeAccessibilityScore, defaultScale, diffSlice, exportScale, exportToCss, exportToDtcg, exportToTailwindV3, exportToTailwindV4, exportTokens, externalReferences, familiesOf, familySeedShade, findContrastingColorAPCA, fingerprint, formatColorAs, formatColorShort, formatOklchInGamut, generateColorScale, generateColorScaleAPCA, generateGroundTokens, generatePrimitivePalette, generateSemanticTokens, generateSurfaceTokens, generateTokens, generateUtilityTokens, getAPCAContrast, getContrastRatio, getOklchString, getRelativeLuminance, getShade, groundTokenNames, isAPCAAvailable, isInGamut, meetsWCAG_AA, meetsWCAG_AAA, mergeSlice, modeSelectors, oklchToHex, parseProvenance, parseToOklch, provenanceComment, rangeOf, readDeclarations, reanchorFactors, reservedSurfaceNames, resolveShades, seedFingerprint, selectTokenSections, serialiseUsage, simulateCVD, snapShade, stableStringify, stepContract, suggestStep, tokenFamilies, usageReport, withJsonProvenance };
1300
+ export { ALIAS_PAIRS, type APCAContrastResult, APCAUnavailableError, type BrandColors, type CVDType, type ChromaProfile, type ChromaShape, type ColorFormat, type ColorScale, type ContractBreak, type ContrastAlgorithm, type ContrastTarget, DEFAULT_NEUTRAL_COLOR, DEFAULT_SEED_SHADE, type Declaration, type ExportFormat, type ExportOptions, type ExtendedSemanticColor, type FamilyShape, type ForegroundRef, GENERATOR_NAME, GROUND_BASE_TOKENS, GROUND_COLOR_PARTS, GROUND_SELECTOR, type Gamut, type GamutTokens, type GenerationOptions, type GroundAction, type GroundColour, type GroundFill, type GroundRef, type GroundSpec, type GroundTokens, type HueDrift, type LightnessStrategy, type MergeResult, type PageContrast, type PageSurface, type PaletteOptions, type PrimitivePalette, type Provenance, SECTIONED_FORMATS, SHADE_PRESETS, type SavedConfig, type ScaleFormat, type ScaleOptions, type ScaleOverride, type ScaleTier, type ScaleTierId, type ScaleToken, type SeedFile, type SelectedTokens, type SemanticColorPair, type SemanticGamuts, type SemanticShadeOverrides, type SemanticTokens, type ShadeNumber, type SliceDiff, type SurfaceRef, type SurfaceShadeOverrides, type SurfaceTokens, TAILWIND_SHADES, TOKEN_SECTIONS, type TokenSection, type TokenSystem, type UsageReport, type UsageVerdict, type UtilityShadeOverrides, type UtilityTokens, VALID_SHADES, type VariantShadeOverrides, type WCAGContrastResult, WIDE_GAMUT_QUERY, adjustChroma, adjustLightness, aliasOf, applyScaleOverrides, checkRampChroma, checkSemanticContrast, checkSemanticContrastAPCA, checkSurfaceContrast, chromaShadeFor, classifyAPCALevel, computeAccessibilityScore, defaultScale, diffSlice, exportScale, exportToCss, exportToDtcg, exportToTailwindV3, exportToTailwindV4, exportTokens, externalReferences, familiesOf, familySeedShade, findContrastingColorAPCA, fingerprint, formatColorAs, formatColorShort, formatOklchInGamut, generateColorScale, generateColorScaleAPCA, generateGroundTokens, generatePrimitivePalette, generateSemanticTokens, generateSurfaceTokens, generateTokens, generateUtilityTokens, getAPCAContrast, getContrastRatio, getOklchString, getRelativeLuminance, getShade, groundTokenNames, isAPCAAvailable, isInGamut, meetsWCAG_AA, meetsWCAG_AAA, mergeSlice, modeSelectors, oklchToHex, parseProvenance, parseToOklch, provenanceComment, rangeOf, readDeclarations, reanchorFactors, reservedSurfaceNames, resolveShades, seedFingerprint, selectTokenSections, serialiseUsage, simulateCVD, snapShade, stableStringify, stepContract, suggestStep, tokenFamilies, usageReport, withJsonProvenance };
package/dist/index.js CHANGED
@@ -80,7 +80,7 @@ import {
80
80
  tokenFamilies,
81
81
  usageReport,
82
82
  withJsonProvenance
83
- } from "./chunk-TRGCDLOM.js";
83
+ } from "./chunk-HK7ME2YV.js";
84
84
  export {
85
85
  ALIAS_PAIRS,
86
86
  APCAUnavailableError,
@@ -102,6 +102,8 @@ export function describeChanges(before, now) {
102
102
  out.push(`every ground's text ${now.groundText ?? "page"}`);
103
103
  if (!same(before.groundTint, now.groundTint))
104
104
  out.push(`every ground's lines and panels ${now.groundTint ?? "own"}`);
105
+ if (!same(before.groundAction, now.groundAction))
106
+ out.push(`every ground's button ${now.groundAction ?? "as its lines"}`);
105
107
  const grounds = new Set([...Object.keys(before.grounds ?? {}), ...Object.keys(now.grounds ?? {})]);
106
108
  for (const name of grounds) {
107
109
  const a = before.grounds?.[name];
@@ -119,6 +121,8 @@ export function describeChanges(before, now) {
119
121
  out.push(`${name} ground's text ${b.text ?? "as every ground's"}`);
120
122
  if (a.tint !== b.tint)
121
123
  out.push(`${name} ground's lines and panels ${b.tint ?? "as every ground's"}`);
124
+ if (a.action !== b.action)
125
+ out.push(`${name} ground's button ${b.action ?? "as every ground's"}`);
122
126
  }
123
127
  }
124
128
  if (!same(before.aliases, now.aliases))
@@ -35,8 +35,24 @@ function FillPicker({ label, hint, value, fallback, ramps, onChange, }) {
35
35
  const choose = (next) => onChange(next === fallback ? undefined : next);
36
36
  return (_jsx(Field, { label: label, actions: _jsx(Hint, { text: hint }), children: (id) => (_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Segmented, { labelledBy: id, value: kind, onChange: (v) => choose(v === "step" ? `${ramps[0] ?? "neutral"}-500` : v), options: ["own", "page", "white", "black", "step"].map((v) => ({ value: v, label: FILL_WORDS[v] })) }), step && (_jsxs(Row, { children: [_jsx(Select, { label: `${label}: ramp`, value: step[1], options: ramps.map((r) => ({ value: r, label: r })), onChange: (r) => choose(`${r}-${step[2]}`) }), _jsx(Select, { label: `${label}: step`, value: step[2], options: SHADES, onChange: (s) => choose(`${step[1]}-${s}`) })] }))] })) }));
37
37
  }
38
+ const ACTION_WORDS = { tint: "As the lines", page: "Page", own: "Own", colour: "A colour" };
39
+ const ACTION_HINT = "The main button. As the lines: it follows them. Page: the page's button as it is, a pale brand colour its label carries. Own: the ground's colour, turned over. Or one colour, with a label measured on it or chosen.";
40
+ /**
41
+ * Where a ground's main button comes from: unset (as the lines and panels), the page's, its own
42
+ * colour, or one colour with its label measured on it or chosen. Shown as what applies.
43
+ */
44
+ function ActionPicker({ value, fallback, ramps, onChange, }) {
45
+ const shown = value ?? fallback;
46
+ const [fill, label] = (shown ?? "").split("/");
47
+ const step = /^([a-z][\w-]*)-(\d+)$/.exec(fill);
48
+ const labelStep = label ? /^([a-z][\w-]*)-(\d+)$/.exec(label) : null;
49
+ const kind = !shown ? "tint" : shown === "page" || shown === "own" ? shown : "colour";
50
+ const choose = (next) => onChange(next === fallback ? undefined : next);
51
+ const colour = (f, l) => choose((l ? `${f}/${l}` : f));
52
+ return (_jsx(Field, { label: "Button", actions: _jsx(Hint, { text: ACTION_HINT }), children: (id) => (_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Segmented, { labelledBy: id, value: kind, onChange: (v) => (v === "tint" ? choose(undefined) : v === "colour" ? colour("neutral-950") : choose(v)), options: ["tint", "page", "own", "colour"].map((v) => ({ value: v, label: ACTION_WORDS[v] })) }), step && (_jsxs(_Fragment, { children: [_jsxs(Row, { children: [_jsx(Select, { label: "Button: ramp", value: step[1], options: ramps.map((r) => ({ value: r, label: r })), onChange: (r) => colour(`${r}-${step[2]}`, label) }), _jsx(Select, { label: "Button: step", value: step[2], options: SHADES, onChange: (n) => colour(`${step[1]}-${n}`, label) })] }), _jsxs(Row, { children: [_jsx(Select, { label: "Button label: ramp", value: labelStep?.[1] ?? "measured", options: [{ value: "measured", label: "Label measured" }, ...ramps.map((r) => ({ value: r, label: `Label ${r}` }))], onChange: (r) => colour(fill, r === "measured" ? undefined : `${r}-${labelStep?.[2] ?? "400"}`) }), labelStep && _jsx(Select, { label: "Button label: step", value: labelStep[2], options: SHADES, onChange: (n) => colour(fill, `${labelStep[1]}-${n}`) })] })] }))] })) }));
53
+ }
38
54
  const TEXT_HINT = "The text on it. Page: the page's own text, so every ground reads the same. Own: a step of the ground's ramp, its hue. Or one colour for all of it.";
39
- const TINT_HINT = "Lines, input edges, the focus ring, cards and the buttons. Own: steps of the ground's ramp, in its hue. Page: the page's own lines and panels. Or one colour for every line.";
55
+ const TINT_HINT = "Lines, input edges, the focus ring, cards and the buttons (unless the button says otherwise). Own: steps of the ground's ramp, in its hue. Page: the page's own lines and panels. Or one colour for every line.";
40
56
  /** The defaults every ground starts from: where its text, and its lines and panels, come from. */
41
57
  export function GroundDefaults({ edit }) {
42
58
  const { seed, set } = edit;
@@ -53,7 +69,7 @@ export function GroundControls({ name, edit }) {
53
69
  return null;
54
70
  const write = (patch) => {
55
71
  const next = { ...spec, ...patch };
56
- for (const k of ["tint", "text"])
72
+ for (const k of ["tint", "text", "action"])
57
73
  if (next[k] === undefined)
58
74
  delete next[k];
59
75
  set({ grounds: { ...grounds, [name]: next } });
@@ -63,7 +79,7 @@ export function GroundControls({ name, edit }) {
63
79
  set({ grounds: Object.keys(rest).length ? rest : undefined });
64
80
  };
65
81
  const made = system?.grounds?.[name];
66
- return (_jsxs("div", { className: "flex flex-col gap-3", children: [_jsxs("div", { className: "grid grid-cols-[repeat(auto-fit,minmax(13rem,1fr))] gap-4", children: [_jsxs("div", { className: "flex flex-col gap-3", children: [_jsx(Field, { label: "Painted", actions: _jsx(Hint, { text: "The ramp and the step it's painted. The same in light and dark mode." }), children: (id) => (_jsxs(Row, { children: [_jsx(Select, { labelledBy: id, value: spec.ramp, options: ramps.map((r) => ({ value: r, label: r })), onChange: (ramp) => write({ ramp }) }), _jsx(Select, { label: "Step", value: String(spec.step), options: SHADES, onChange: (s) => write({ step: Number(s) }) })] })) }), _jsxs("button", { type: "button", onClick: remove, className: ACTION, children: [_jsx(Trash2, { "aria-hidden": true, width: 13, height: 13 }), " Remove ", name] })] }), _jsx(FillPicker, { label: "Text", hint: TEXT_HINT, value: spec.text, fallback: seed.groundText ?? "page", ramps: ramps, onChange: (text) => write({ text }) }), _jsx(FillPicker, { label: "Lines and panels", hint: TINT_HINT, value: spec.tint, fallback: seed.groundTint ?? "own", ramps: ramps, onChange: (tint) => write({ tint }) })] }), made?.notes.length ? (_jsx("ul", { className: "flex flex-col gap-0.5 border-t border-edge pt-2 text-[11px] leading-snug text-ink2", children: made.notes.map((n) => (_jsx("li", { children: n }, n))) })) : null] }));
82
+ return (_jsxs("div", { className: "flex flex-col gap-3", children: [_jsxs("div", { className: "grid grid-cols-[repeat(auto-fit,minmax(13rem,1fr))] gap-4", children: [_jsxs("div", { className: "flex flex-col gap-3", children: [_jsx(Field, { label: "Painted", actions: _jsx(Hint, { text: "The ramp and the step it's painted. The same in light and dark mode." }), children: (id) => (_jsxs(Row, { children: [_jsx(Select, { labelledBy: id, value: spec.ramp, options: ramps.map((r) => ({ value: r, label: r })), onChange: (ramp) => write({ ramp }) }), _jsx(Select, { label: "Step", value: String(spec.step), options: SHADES, onChange: (s) => write({ step: Number(s) }) })] })) }), _jsxs("button", { type: "button", onClick: remove, className: ACTION, children: [_jsx(Trash2, { "aria-hidden": true, width: 13, height: 13 }), " Remove ", name] })] }), _jsx(FillPicker, { label: "Text", hint: TEXT_HINT, value: spec.text, fallback: seed.groundText ?? "page", ramps: ramps, onChange: (text) => write({ text }) }), _jsx(FillPicker, { label: "Lines and panels", hint: TINT_HINT, value: spec.tint, fallback: seed.groundTint ?? "own", ramps: ramps, onChange: (tint) => write({ tint }) }), _jsx(ActionPicker, { value: spec.action, fallback: seed.groundAction, ramps: ramps, onChange: (action) => write({ action }) })] }), made?.notes.length ? (_jsx("ul", { className: "flex flex-col gap-0.5 border-t border-edge pt-2 text-[11px] leading-snug text-ink2", children: made.notes.map((n) => (_jsx("li", { children: n }, n))) })) : null] }));
67
83
  }
68
84
  /** A new ground: a name, the ramp it's painted and the step. */
69
85
  export function AddGround({ edit }) {
@@ -2,7 +2,7 @@
2
2
  * The studio's plain logic, browser-safe: a project's generate-tokens command read into a seed, a
3
3
  * seed turned into the generator's inputs, and the command that regenerates from a seed.
4
4
  */
5
- import { type BrandColors, type GenerationOptions, type GroundFill, type SeedFile, type TokenSystem } from "@designtools/tokens";
5
+ import { type BrandColors, type GenerationOptions, type GroundAction, type GroundFill, type SeedFile, type TokenSystem } from "@designtools/tokens";
6
6
  /** Flags that say where and how the output is written, kept when the colour moves into a seed. */
7
7
  export interface OutputFlags {
8
8
  format?: string;
@@ -43,10 +43,14 @@ export declare function generateFromSeed(seed: SeedFile): TokenSystem;
43
43
  * tokens file uses, so added after it, it re-themes the page.
44
44
  */
45
45
  export declare function studioCss(seed: SeedFile, tokens?: TokenSystem): string;
46
- /** Where a ground's text and its lines and panels come from, as it stands: its own choice, else every ground's, else the generator's */
46
+ /**
47
+ * Where a ground's text, its lines and panels, and its main button come from, as it stands: its own
48
+ * choice, else every ground's, else the generator's (the button unset: it follows the tint)
49
+ */
47
50
  export declare function groundChoices(seed: SeedFile): Record<string, {
48
51
  text: GroundFill;
49
52
  tint: GroundFill;
53
+ action?: GroundAction;
50
54
  }>;
51
55
  /**
52
56
  * One ground as it would be with other choices for its text and its lines, as a rule for
@@ -56,6 +60,7 @@ export declare function groundChoices(seed: SeedFile): Record<string, {
56
60
  export declare function groundPreviewCss(seed: SeedFile, name: string, choice: {
57
61
  text?: GroundFill;
58
62
  tint?: GroundFill;
63
+ action?: GroundAction;
59
64
  }, selector: string): string | null;
60
65
  /** The command that regenerates from a seed file, keeping how and where the output is written. */
61
66
  export declare function seedCommand({ seedPath, output, version }: {
@@ -55,7 +55,7 @@ export function parseCommand(command) {
55
55
  const surfaces = { light: {}, dark: {} };
56
56
  const grounds = {};
57
57
  const pageSurfaces = {};
58
- /** `--ground-tint name=…` and `--ground-text name=…`, applied once every ground is known */
58
+ /** `--ground-tint name=…`, `--ground-text name=…` and `--ground-action name=…`, applied once every ground is known */
59
59
  const perGround = [];
60
60
  for (let i = 0; i < flags.length; i++) {
61
61
  const flag = flags[i];
@@ -129,6 +129,15 @@ export function parseCommand(command) {
129
129
  perGround.push({ name: entry.slice(0, at), key, fill: entry.slice(at + 1) });
130
130
  break;
131
131
  }
132
+ case "--ground-action": {
133
+ const entry = value();
134
+ const at = entry.indexOf("=");
135
+ if (at === -1)
136
+ seed.groundAction = entry;
137
+ else
138
+ perGround.push({ name: entry.slice(0, at), key: "action", fill: entry.slice(at + 1) });
139
+ break;
140
+ }
132
141
  case "--gamut":
133
142
  seed.gamut = value();
134
143
  break;
@@ -254,6 +263,7 @@ export function optionsFromSeed(seed) {
254
263
  ...(seed.grounds && Object.keys(seed.grounds).length ? { grounds: seed.grounds } : {}),
255
264
  ...(seed.groundTint && seed.groundTint !== "own" ? { groundTint: seed.groundTint } : {}),
256
265
  ...(seed.groundText && seed.groundText !== "page" ? { groundText: seed.groundText } : {}),
266
+ ...(seed.groundAction ? { groundAction: seed.groundAction } : {}),
257
267
  seedShade: seed.seedShade,
258
268
  ...(Object.keys(seedShades).length ? { seedShades } : {}),
259
269
  ...(rangeOf(seed) ? { lightnessRange: rangeOf(seed) } : {}),
@@ -288,9 +298,15 @@ export function studioCss(seed, tokens = generateFromSeed(seed)) {
288
298
  const grounds = tokens.grounds && Object.fromEntries(Object.entries(tokens.grounds).map(([name, g]) => [name, { ...g, own: Object.keys(g._refs) }]));
289
299
  return exportTokens(grounds ? { ...tokens, grounds } : tokens, "css", { colorFormat: seed.colorFormat ?? "oklch", shadeOverrides: options.shadeOverrides, seedShade: options.seedShade, seedShades: options.seedShades });
290
300
  }
291
- /** Where a ground's text and its lines and panels come from, as it stands: its own choice, else every ground's, else the generator's */
301
+ /**
302
+ * Where a ground's text, its lines and panels, and its main button come from, as it stands: its own
303
+ * choice, else every ground's, else the generator's (the button unset: it follows the tint)
304
+ */
292
305
  export function groundChoices(seed) {
293
- return Object.fromEntries(Object.entries(seed.grounds ?? {}).map(([name, g]) => [name, { text: g.text ?? seed.groundText ?? "page", tint: g.tint ?? seed.groundTint ?? "own" }]));
306
+ return Object.fromEntries(Object.entries(seed.grounds ?? {}).map(([name, g]) => {
307
+ const action = g.action ?? seed.groundAction;
308
+ return [name, { text: g.text ?? seed.groundText ?? "page", tint: g.tint ?? seed.groundTint ?? "own", ...(action ? { action } : {}) }];
309
+ }));
294
310
  }
295
311
  /**
296
312
  * One ground as it would be with other choices for its text and its lines, as a rule for
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@designtools/tokens",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Turn one brand colour into a complete design-token system: perceptual OKLCH ramps, contrast-checked semantic tokens (WCAG or APCA), light and dark, as CSS custom properties, Tailwind v4/v3 or DTCG. Deterministic CLI, safe for agents.",
5
5
  "type": "module",
6
6
  "license": "MIT",