@designtools/tokens 0.8.0 → 0.9.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,17 @@
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.9.0
6
+
7
+ ### Minor Changes
8
+
9
+ - 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`.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [3a8e79f]
14
+ - @designtools/widgets@0.1.3
15
+
5
16
  ## 0.8.0
6
17
 
7
18
  ### 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,20 @@ export function ScalesTool() {
180
180
  }
181
181
  ```
182
182
 
183
+ ## Trying new colours: the colour generator
184
+
185
+ `ColourGenerator` is the generator's own inputs as a tool in the dock: the primary and neutral first, any colours to add (named, removable), then how it generates (contrast method and target, lightness, labels on fills, the step the primary lands on), with the score in both modes. It starts from the project's seed, re-themes the page and every artboard as you change it, and the docs' colour page follows, added colours included. Copy prompt hands back the seed and the exact command, so the generator stays the source; reset puts the project's colours back.
186
+
187
+ ```tsx
188
+ // a server component on the page it was asked for (the docs' colour page, say), inside the app's <Widgets>
189
+ import { ColourGenerator } from "@designtools/tokens/studio";
190
+ import { readProjectSeed } from "@designtools/tokens/studio/next";
191
+
192
+ <ColourGenerator project={readProjectSeed()} />
193
+ ```
194
+
195
+ On the docs, put it on the colour page with `extras: { colour: <ColourGenerator project={readProjectSeed()} /> }`.
196
+
183
197
  ## Regenerating part of a token file
184
198
 
185
199
  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.
@@ -1,2 +1,2 @@
1
- export const css = "/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-border-style:solid;--tw-font-weight:initial;--tw-ordinal:initial;--tw-slashed-zero:initial;--tw-numeric-figure:initial;--tw-numeric-spacing:initial;--tw-numeric-fraction:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000}}}@layer theme{:root,:host{--font-sans:ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif;--spacing:4px;--font-weight-semibold:600}}@layer utilities{.fixed{position:fixed}.ml-auto{margin-left:auto}.flex{display:flex}.hidden{display:none}.inline{display:inline}.shrink-0{flex-shrink:0}.cursor-pointer{cursor:pointer}.flex-col{flex-direction:column}.items-baseline{align-items:baseline}.items-center{align-items:center}.justify-between{justify-content:space-between}.gap-0\\.5{gap:2px}.gap-1{gap:4px}.gap-1\\.5{gap:6px}.gap-2{gap:8px}.gap-3{gap:12px}.truncate{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.rounded-md{border-radius:6px}.rounded-sm{border-radius:4px}.border-t{border-top-style:var(--tw-border-style);border-top-width:1px}.border-edge{border-color:var(--dt-edge)}.bg-muted{background-color:var(--dt-muted)}.p-2\\.5{padding:10px}.px-1{padding-inline:4px}.pt-2{padding-top:8px}.font-mono{font-family:ui-monospace,SF Mono,SFMono-Regular,Menlo,Consolas,monospace}.text-\\[10px\\]{font-size:10px}.text-\\[11px\\]{font-size:11px}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.text-fail{color:var(--dt-fail)}.text-ink{color:var(--dt-ink)}.text-ink2{color:var(--dt-ink2)}.text-ink3{color:var(--dt-ink3)}.text-ok{color:var(--dt-ok)}.text-warn{color:var(--dt-warn)}.capitalize{text-transform:capitalize}.tabular-nums{--tw-numeric-spacing:tabular-nums;font-variant-numeric:var(--tw-ordinal,) var(--tw-slashed-zero,) var(--tw-numeric-figure,) var(--tw-numeric-spacing,) var(--tw-numeric-fraction,)}.shadow{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a), 0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}@media (hover:hover){.hover\\:text-ink:hover{color:var(--dt-ink)}}}:host{all:initial}.dt-base{all:initial;--dt-page:#fff;--dt-raised:#f8f8f9;--dt-muted:#f0f0f2;--dt-edge:#e4e4e7;--dt-ink:#09090b;--dt-ink2:#71717a;--dt-ink3:#a1a1aa;--dt-sel:#3b82f6;--dt-scrim:#0000000f;--dt-ok:#16a34a;--dt-warn:#d97706;--dt-fail:#dc2626;--dt-icon:oklch(55% 0 0);color-scheme:light;font-family:var(--font-sans);letter-spacing:normal;text-align:left;cursor:auto;color:var(--dt-ink);-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-size:11px;font-weight:400;line-height:1.4;display:contents}.dt-base[data-theme=dark]{--dt-page:#161618;--dt-raised:#18181b;--dt-muted:#27272a;--dt-edge:#2e2e33;--dt-ink:#fafafa;--dt-ink2:#b5b5be;--dt-ink3:#9494a0;--dt-scrim:#ffffff14;--dt-ok:#4ade80;--dt-warn:#fbbf24;--dt-fail:#f87171;color-scheme:dark}@media (prefers-color-scheme:dark){.dt-base:not([data-theme=light]){--dt-page:#161618;--dt-raised:#18181b;--dt-muted:#27272a;--dt-edge:#2e2e33;--dt-ink:#fafafa;--dt-ink2:#b5b5be;--dt-ink3:#9494a0;--dt-scrim:#ffffff14;--dt-ok:#4ade80;--dt-warn:#fbbf24;--dt-fail:#f87171;color-scheme:dark}}input[type=number]::-webkit-inner-spin-button{appearance:none;margin:0}input[type=number]::-webkit-outer-spin-button{appearance:none;margin:0}\n";
2
- export const properties = "@property --tw-border-style{syntax:\"*\";inherits:false;initial-value:solid}\n@property --tw-font-weight{syntax:\"*\";inherits:false}\n@property --tw-ordinal{syntax:\"*\";inherits:false}\n@property --tw-slashed-zero{syntax:\"*\";inherits:false}\n@property --tw-numeric-figure{syntax:\"*\";inherits:false}\n@property --tw-numeric-spacing{syntax:\"*\";inherits:false}\n@property --tw-numeric-fraction{syntax:\"*\";inherits:false}\n@property --tw-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}\n@property --tw-shadow-color{syntax:\"*\";inherits:false}\n@property --tw-shadow-alpha{syntax:\"<percentage>\";inherits:false;initial-value:100%}\n@property --tw-inset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}\n@property --tw-inset-shadow-color{syntax:\"*\";inherits:false}\n@property --tw-inset-shadow-alpha{syntax:\"<percentage>\";inherits:false;initial-value:100%}\n@property --tw-ring-color{syntax:\"*\";inherits:false}\n@property --tw-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}\n@property --tw-inset-ring-color{syntax:\"*\";inherits:false}\n@property --tw-inset-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}\n@property --tw-ring-inset{syntax:\"*\";inherits:false}\n@property --tw-ring-offset-width{syntax:\"<length>\";inherits:false;initial-value:0}\n@property --tw-ring-offset-color{syntax:\"*\";inherits:false;initial-value:#fff}\n@property --tw-ring-offset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}";
1
+ export const css = "/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-border-style:solid;--tw-font-weight:initial;--tw-tracking:initial;--tw-ordinal:initial;--tw-slashed-zero:initial;--tw-numeric-figure:initial;--tw-numeric-spacing:initial;--tw-numeric-fraction:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000}}}@layer theme{:root,:host{--font-sans:ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif;--spacing:4px;--font-weight-semibold:600;--tracking-wide:.025em}}@layer utilities{.fixed{position:fixed}.mb-1{margin-bottom:4px}.block{display:block}.flex{display:flex}.hidden{display:none}.inline{display:inline}.size-7{width:28px;height:28px}.h-7{height:28px}.w-\\[140px\\]{width:140px}.w-full{width:100%}.min-w-0{min-width:0}.flex-1{flex:1}.shrink-0{flex-shrink:0}.-rotate-90{rotate:-90deg}.cursor-pointer{cursor:pointer}.flex-col{flex-direction:column}.items-center{align-items:center}.items-end{align-items:flex-end}.justify-between{justify-content:space-between}.justify-center{justify-content:center}.gap-0\\.5{gap:2px}.gap-1{gap:4px}.gap-1\\.5{gap:6px}.gap-2{gap:8px}.gap-3{gap:12px}.truncate{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.rounded-md{border-radius:6px}.rounded-sm{border-radius:4px}.border{border-style:var(--tw-border-style);border-width:1px}.border-t{border-top-style:var(--tw-border-style);border-top-width:1px}.border-dashed{--tw-border-style:dashed;border-style:dashed}.border-edge{border-color:var(--dt-edge)}.bg-muted{background-color:var(--dt-muted)}.p-2\\.5{padding:10px}.px-1{padding-inline:4px}.px-2{padding-inline:8px}.pt-2{padding-top:8px}.font-mono{font-family:ui-monospace,SF Mono,SFMono-Regular,Menlo,Consolas,monospace}.text-\\[9px\\]{font-size:9px}.text-\\[10px\\]{font-size:10px}.text-\\[11px\\]{font-size:11px}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.tracking-wide{--tw-tracking:var(--tracking-wide);letter-spacing:var(--tracking-wide)}.text-fail{color:var(--dt-fail)}.text-ink{color:var(--dt-ink)}.text-ink2{color:var(--dt-ink2)}.text-ink3{color:var(--dt-ink3)}.text-ok{color:var(--dt-ok)}.text-warn{color:var(--dt-warn)}.capitalize{text-transform:capitalize}.uppercase{text-transform:uppercase}.tabular-nums{--tw-numeric-spacing:tabular-nums;font-variant-numeric:var(--tw-ordinal,) var(--tw-slashed-zero,) var(--tw-numeric-figure,) var(--tw-numeric-spacing,) var(--tw-numeric-fraction,)}.shadow{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a), 0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.ring,.ring-1{--tw-ring-shadow:var(--tw-ring-inset,) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.ring-fail{--tw-ring-color:var(--dt-fail)}.outline-none{--tw-outline-style:none;outline-style:none}@media (hover:hover){.hover\\:bg-scrim:hover{background-color:var(--dt-scrim)}.hover\\:text-ink:hover{color:var(--dt-ink)}}.focus-visible\\:ring-1:focus-visible{--tw-ring-shadow:var(--tw-ring-inset,) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.focus-visible\\:ring-sel:focus-visible{--tw-ring-color:var(--dt-sel)}}:host{all:initial}.dt-base{all:initial;--dt-page:#fff;--dt-raised:#f8f8f9;--dt-muted:#f0f0f2;--dt-edge:#e4e4e7;--dt-ink:#09090b;--dt-ink2:#71717a;--dt-ink3:#a1a1aa;--dt-sel:#3b82f6;--dt-scrim:#0000000f;--dt-ok:#16a34a;--dt-warn:#d97706;--dt-fail:#dc2626;--dt-icon:oklch(55% 0 0);color-scheme:light;font-family:var(--font-sans);letter-spacing:normal;text-align:left;cursor:auto;color:var(--dt-ink);-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-size:11px;font-weight:400;line-height:1.4;display:contents}.dt-base[data-theme=dark]{--dt-page:#161618;--dt-raised:#18181b;--dt-muted:#27272a;--dt-edge:#2e2e33;--dt-ink:#fafafa;--dt-ink2:#b5b5be;--dt-ink3:#9494a0;--dt-scrim:#ffffff14;--dt-ok:#4ade80;--dt-warn:#fbbf24;--dt-fail:#f87171;color-scheme:dark}@media (prefers-color-scheme:dark){.dt-base:not([data-theme=light]){--dt-page:#161618;--dt-raised:#18181b;--dt-muted:#27272a;--dt-edge:#2e2e33;--dt-ink:#fafafa;--dt-ink2:#b5b5be;--dt-ink3:#9494a0;--dt-scrim:#ffffff14;--dt-ok:#4ade80;--dt-warn:#fbbf24;--dt-fail:#f87171;color-scheme:dark}}input[type=number]::-webkit-inner-spin-button{appearance:none;margin:0}input[type=number]::-webkit-outer-spin-button{appearance:none;margin:0}\n";
2
+ export const properties = "@property --tw-border-style{syntax:\"*\";inherits:false;initial-value:solid}\n@property --tw-font-weight{syntax:\"*\";inherits:false}\n@property --tw-tracking{syntax:\"*\";inherits:false}\n@property --tw-ordinal{syntax:\"*\";inherits:false}\n@property --tw-slashed-zero{syntax:\"*\";inherits:false}\n@property --tw-numeric-figure{syntax:\"*\";inherits:false}\n@property --tw-numeric-spacing{syntax:\"*\";inherits:false}\n@property --tw-numeric-fraction{syntax:\"*\";inherits:false}\n@property --tw-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}\n@property --tw-shadow-color{syntax:\"*\";inherits:false}\n@property --tw-shadow-alpha{syntax:\"<percentage>\";inherits:false;initial-value:100%}\n@property --tw-inset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}\n@property --tw-inset-shadow-color{syntax:\"*\";inherits:false}\n@property --tw-inset-shadow-alpha{syntax:\"<percentage>\";inherits:false;initial-value:100%}\n@property --tw-ring-color{syntax:\"*\";inherits:false}\n@property --tw-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}\n@property --tw-inset-ring-color{syntax:\"*\";inherits:false}\n@property --tw-inset-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}\n@property --tw-ring-inset{syntax:\"*\";inherits:false}\n@property --tw-ring-offset-width{syntax:\"<length>\";inherits:false;initial-value:0}\n@property --tw-ring-offset-color{syntax:\"*\";inherits:false;initial-value:#fff}\n@property --tw-ring-offset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}";
@@ -1,3 +1,4 @@
1
1
  export type { ProjectSeed } from "./next.js";
2
2
  export { generateFromSeed, mergeSeed, type OutputFlags, optionsFromSeed, type ParsedCommand, parseCommand, seedCommand, seedJson, splitCommand, studioCss } from "./seed.js";
3
+ export { ColourGenerator } from "./studio.js";
3
4
  export { TokenStudio } from "./studio.js";
@@ -1,2 +1,3 @@
1
1
  export { generateFromSeed, mergeSeed, optionsFromSeed, parseCommand, seedCommand, seedJson, splitCommand, studioCss } from "./seed.js";
2
+ export { ColourGenerator } from "./studio.js";
2
3
  export { TokenStudio } from "./studio.js";
@@ -1,4 +1,20 @@
1
1
  import type { ProjectSeed } from "./next.js";
2
+ /** The seed the studio and the colour generator apply to the page, in every frame. */
3
+ export declare const STUDIO_KEY = "studio:seed";
4
+ /**
5
+ * The seed set in the studio, applied to this frame's page as the generator's own CSS, added after
6
+ * the app's so it wins. It runs in every frame, the dock's and each artboard's, so they all re-theme.
7
+ */
8
+ export declare function useApplySeed(): void;
9
+ /**
10
+ * The colour generator in the dock, where it's asked for: the project's seed to start from, changed by
11
+ * hand, live on the page, handed back as the seed and the command.
12
+ *
13
+ * <Widgets tokens={manifest}><ColourGenerator project={readProjectSeed()} /></Widgets>
14
+ */
15
+ export declare function ColourGenerator({ project }: {
16
+ project: ProjectSeed | null;
17
+ }): import("react").JSX.Element | null;
2
18
  export declare function TokenStudio({ project }: {
3
19
  project?: ProjectSeed | null;
4
20
  }): import("react").JSX.Element;
@@ -2,11 +2,13 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { computeAccessibilityScore, checkSemanticContrast, isAPCAAvailable, VALID_SHADES, } from "@designtools/tokens";
4
4
  import { ColorInput, Field, NumberScrub, readStored, Row, Segmented, Select, stepsFor, subscribeStored, TOKENS_KEY, Tool, TokenControl, useHandback, useSystemTokens, useToolsEnabled, writeStored, } from "@designtools/widgets";
5
- import { Palette, RotateCcw } from "lucide-react";
5
+ import { Plus, RotateCcw, X } from "lucide-react";
6
6
  import { useCallback, useEffect, useMemo, useSyncExternalStore } from "react";
7
7
  import { css, properties } from "./css.js";
8
8
  import { generateFromSeed, seedCommand, seedJson, studioCss } from "./seed.js";
9
- const KEY = "studio:seed";
9
+ /** The seed the studio and the colour generator apply to the page, in every frame. */
10
+ export const STUDIO_KEY = "studio:seed";
11
+ const KEY = STUDIO_KEY;
10
12
  const NONE = {};
11
13
  const STYLES = [{ id: "tokens-studio", css, properties }];
12
14
  function useStoredSeed() {
@@ -16,7 +18,7 @@ function useStoredSeed() {
16
18
  * The seed set in the studio, applied to this frame's page as the generator's own CSS, added after
17
19
  * the app's so it wins. It runs in every frame, the dock's and each artboard's, so they all re-theme.
18
20
  */
19
- function useApplySeed() {
21
+ export function useApplySeed() {
20
22
  const enabled = useToolsEnabled();
21
23
  useEffect(() => {
22
24
  if (!enabled)
@@ -25,7 +27,10 @@ function useApplySeed() {
25
27
  const seed = readStored(KEY, null);
26
28
  let tag = document.head.querySelector("style[data-designtools-studio]");
27
29
  if (!seed) {
28
- tag?.remove();
30
+ if (tag) {
31
+ tag.remove();
32
+ window.dispatchEvent(new Event("designtools:retheme"));
33
+ }
29
34
  return;
30
35
  }
31
36
  try {
@@ -40,6 +45,8 @@ function useApplySeed() {
40
45
  catch {
41
46
  // a half-typed colour: keep what was applied
42
47
  }
48
+ // anything measuring colours on the page (the docs' contrast) measures again
49
+ window.dispatchEvent(new Event("designtools:retheme"));
43
50
  };
44
51
  apply();
45
52
  return subscribeStored((k) => k === KEY && apply());
@@ -53,6 +60,14 @@ function failures(system, target) {
53
60
  .flatMap((mode) => Object.entries(checkSemanticContrast(system.semantic[mode])).filter(([, r]) => !need(r)).map(([pair, r]) => ({ mode, pair, ratio: r.ratio })))
54
61
  .sort((a, b) => a.ratio - b.ratio);
55
62
  }
63
+ /** The score as a ring: the share of pairings that pass, coloured by how close it is to all of them. */
64
+ function Ring({ passed, total }) {
65
+ const share = total ? passed / total : 0;
66
+ const tone = share === 1 ? "text-ok" : share >= 0.8 ? "text-warn" : "text-fail";
67
+ const r = 15;
68
+ const c = 2 * Math.PI * r;
69
+ return (_jsxs("svg", { viewBox: "0 0 36 36", width: 36, height: 36, className: `shrink-0 -rotate-90 ${tone}`, "aria-hidden": true, children: [_jsx("circle", { cx: "18", cy: "18", r: r, fill: "none", stroke: "currentColor", strokeOpacity: 0.18, strokeWidth: 3 }), _jsx("circle", { cx: "18", cy: "18", r: r, fill: "none", stroke: "currentColor", strokeWidth: 3, strokeLinecap: "round", strokeDasharray: `${c * share} ${c}` })] }));
70
+ }
56
71
  function Score({ system, seed }) {
57
72
  const algorithm = seed.contrastAlgorithm ?? "wcag";
58
73
  const target = seed.contrastTarget ?? "aa";
@@ -65,9 +80,18 @@ function Score({ system, seed }) {
65
80
  }
66
81
  });
67
82
  const failing = failures(system, target);
68
- return (_jsxs("div", { className: "flex flex-col gap-2 rounded-md bg-muted p-2.5", children: [_jsxs("div", { className: "flex items-center gap-3 text-[11px]", children: [scores.map((s) => (_jsxs("span", { className: "flex items-baseline gap-1.5", children: [_jsx("span", { className: "text-ink2 capitalize", children: s.mode }), _jsxs("span", { className: `font-semibold tabular-nums ${s.passed === s.total ? "text-ok" : "text-warn"}`, children: [s.passed, "/", s.total] })] }, s.mode))), _jsxs("span", { className: "ml-auto text-[10px] text-ink3", children: ["pairs pass ", target.toUpperCase()] })] }), failing.length > 0 && (_jsxs("ul", { className: "flex flex-col gap-0.5 border-t border-edge pt-2 text-[10px]", children: [failing.slice(0, 6).map((f) => (_jsxs("li", { className: "flex justify-between gap-2 text-ink2", children: [_jsxs("span", { className: "truncate font-mono", children: [f.pair, " ", _jsxs("span", { className: "text-ink3", children: ["(", f.mode, ")"] })] }), _jsxs("span", { className: "shrink-0 tabular-nums text-fail", children: [f.ratio.toFixed(2), ":1"] })] }, `${f.mode}-${f.pair}`))), failing.length > 6 && _jsxs("li", { className: "text-ink3", children: ["and ", failing.length - 6, " more"] })] }))] }));
83
+ const passed = scores.reduce((n, s) => n + s.passed, 0);
84
+ const total = scores.reduce((n, s) => n + s.total, 0);
85
+ const label = `${algorithm === "apca" ? "APCA" : "WCAG"} ${target === "aa-large" ? "AA large" : target.toUpperCase()}`;
86
+ return (_jsxs("div", { className: "flex flex-col gap-2 rounded-md bg-muted p-2.5", children: [_jsxs("div", { className: "flex items-center gap-3", children: [_jsx(Ring, { passed: passed, total: total }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-0.5", children: [_jsxs("span", { className: "text-[11px] font-semibold text-ink", children: [passed, "/", total, " pairings pass ", label] }), _jsx("span", { className: "flex gap-3 text-[10px] text-ink3", children: scores.map((s) => (_jsxs("span", { className: "capitalize tabular-nums", children: [s.mode, " ", s.passed, "/", s.total] }, s.mode))) })] })] }), failing.length > 0 && (_jsxs("ul", { className: "flex flex-col gap-0.5 border-t border-edge pt-2 text-[10px]", children: [failing.slice(0, 6).map((f) => (_jsxs("li", { className: "flex justify-between gap-2 text-ink2", children: [_jsxs("span", { className: "truncate font-mono", children: [f.pair, " ", _jsxs("span", { className: "text-ink3", children: ["(", f.mode, ")"] })] }), _jsxs("span", { className: "shrink-0 tabular-nums text-fail", children: [f.ratio.toFixed(2), ":1"] })] }, `${f.mode}-${f.pair}`))), failing.length > 6 && _jsxs("li", { className: "text-ink3", children: ["and ", failing.length - 6, " more"] })] }))] }));
69
87
  }
70
- /** The colour half: the generator's inputs, live on the page and in every artboard. */
88
+ const STATUS = ["success", "destructive", "warning"];
89
+ const NAME = /^[a-z][a-z0-9-]*$/;
90
+ /**
91
+ * The colour generator, as a tool in the dock: the brand colours first (primary, neutral, any added),
92
+ * then how it generates, with the score. Every change re-themes the page and every artboard at once;
93
+ * Copy prompt hands back the seed and the command, so the generator stays the source.
94
+ */
71
95
  function Colour({ project }) {
72
96
  useApplySeed();
73
97
  const stored = useStoredSeed();
@@ -82,37 +106,42 @@ function Colour({ project }) {
82
106
  }
83
107
  }, [seed]);
84
108
  const apca = isAPCAAvailable();
85
- useHandback("Theme colour", () => {
109
+ useHandback("Colour generator", () => {
86
110
  if (!stored)
87
111
  return null;
88
112
  return [
89
- "Colour: the tokens are generated, so regenerate them from this seed rather than editing the generated file.",
113
+ "Colour: I tried new brand colours with the colour generator. The tokens are generated, so regenerate them from this seed rather than editing the generated file.",
90
114
  `1. Save this as ${project.seedPath}:`,
91
115
  "",
92
116
  "```json",
93
117
  seedJson(stored),
94
118
  "```",
95
119
  "",
96
- `2. Make the${project.script ? ` "${project.script}"` : ""} script run, and run it: ${seedCommand({ seedPath: project.seedPath, output: project.output, version: project.version })}`,
97
- "3. Look at the colour page of the docs in both modes, and tell me about any pair the generator's --report flags.",
120
+ `2. ${project.script ? `Set the "${project.script}" script in package.json to this command, and run it` : "Run this"}: ${seedCommand({ seedPath: project.seedPath, output: project.output, version: project.version })}`,
121
+ "3. Run the same command with --report, tell me about any pair that misses its target, and check the colour page of the docs in both modes.",
98
122
  ].join("\n");
99
123
  });
100
124
  const colours = seed.additionalColors ?? [];
101
- const surfaces = ["canvas", "surface", "overlay"].filter((k) => seed.surfaceColors?.light?.[k] || seed.surfaceColors?.dark?.[k]);
102
- return (_jsxs(Tool, { name: "Theme colour", scope: "tokens", popover: { icon: Palette, label: "Theme colour: try new generator inputs" }, styles: STYLES, children: [_jsxs("div", { className: "flex items-center justify-between gap-2 text-[10px] text-ink3", children: [_jsx("span", { children: stored ? "Changed from the project's seed" : `From ${project.script ? `the "${project.script}" script` : "the project's seed"}` }), stored && (_jsxs("button", { type: "button", onClick: () => writeStored(KEY, undefined), className: "flex cursor-pointer items-center gap-1 rounded-sm px-1 hover:text-ink", children: [_jsx(RotateCcw, { "aria-hidden": true, width: 11, height: 11 }), " Back to the project's"] }))] }), _jsxs(Row, { children: [_jsx(Field, { label: "Primary", children: (id) => _jsx(ColorInput, { label: "Primary", labelledBy: id, value: seed.primaryColor ?? "", background: "#ffffff", onChange: (primaryColor) => set({ primaryColor }) }) }), _jsx(Field, { label: "Neutral", children: (id) => _jsx(ColorInput, { label: "Neutral", labelledBy: id, value: seed.neutralColor ?? "#737373", onChange: (neutralColor) => set({ neutralColor }) }) })] }), colours.length > 0 && (_jsx(Row, { children: colours.map((c, i) => (_jsx(Field, { label: c.decorative ? `${c.name}, decorative` : c.name, children: (id) => (_jsx(ColorInput, { label: c.name, labelledBy: id, value: c.color, onChange: (color) => set({ additionalColors: colours.map((x, j) => (j === i ? { ...x, color } : x)) }) })) }, c.name))) })), _jsx(Field, { label: "Seed lands on", children: (id) => _jsx(Select, { labelledBy: id, value: String(seed.seedShade ?? 500), options: SHADES, onChange: (v) => set({ seedShade: Number(v) }) }) }), _jsx(Field, { label: "Contrast", children: (id) => (_jsx(Segmented, { labelledBy: id, value: seed.contrastAlgorithm ?? "wcag", onChange: (v) => set({ contrastAlgorithm: v }), options: [
125
+ const setColours = (next) => set({ additionalColors: next.length ? next : undefined });
126
+ const addColour = () => {
127
+ const taken = new Set(["primary", "neutral", ...STATUS, ...colours.map((c) => c.name)]);
128
+ const name = ["accent", "info", "highlight", "brand", "extra"].find((n) => !taken.has(n)) ?? `colour-${colours.length + 1}`;
129
+ setColours([...colours, { name, color: "#8b5cf6" }]);
130
+ };
131
+ return (_jsxs(Tool, { name: "Colour generator", scope: "tokens", alone: true, onReset: () => writeStored(KEY, undefined), changes: () => (readStored(KEY, null) ? 1 : 0), styles: STYLES, children: [system ? _jsx(Score, { system: system, seed: seed }) : _jsx("p", { className: "text-[11px] text-fail", children: "That colour can't be read yet: finish typing it." }), _jsx("p", { className: "text-[10px] font-semibold tracking-wide text-ink3 uppercase", children: "Colours" }), _jsxs(Row, { children: [_jsx(Field, { label: "Primary", children: (id) => _jsx(ColorInput, { label: "Primary", labelledBy: id, value: seed.primaryColor ?? "", background: "#ffffff", onChange: (primaryColor) => set({ primaryColor }) }) }), _jsx(Field, { label: "Neutral", children: (id) => _jsx(ColorInput, { label: "Neutral", labelledBy: id, value: seed.neutralColor ?? "#737373", onChange: (neutralColor) => set({ neutralColor }) }) })] }), colours.map((c, i) => (_jsxs("div", { className: "flex items-end gap-1.5", children: [_jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("label", { className: "mb-1 block text-[9px] text-ink3", htmlFor: `colour-name-${i}`, children: "Name" }), _jsx("input", { id: `colour-name-${i}`, value: c.name, spellCheck: false, "aria-invalid": !NAME.test(c.name), onChange: (e) => setColours(colours.map((x, j) => (j === i ? { ...x, name: e.target.value.toLowerCase().replace(/\s+/g, "-") } : x))), className: `h-7 w-full rounded-md bg-muted px-2 font-mono text-[11px] text-ink outline-none focus-visible:ring-1 focus-visible:ring-sel ${NAME.test(c.name) ? "" : "ring-1 ring-fail"}` })] }), _jsx("div", { className: "w-[140px] shrink-0", children: _jsx(ColorInput, { label: `${c.name} colour`, value: c.color, onChange: (color) => setColours(colours.map((x, j) => (j === i ? { ...x, color } : x))) }) }), _jsx("button", { type: "button", "aria-label": `Remove ${c.name}`, onClick: () => setColours(colours.filter((_, j) => j !== i)), className: "flex size-7 shrink-0 cursor-pointer items-center justify-center rounded-md text-ink3 hover:bg-scrim hover:text-ink", children: _jsx(X, { "aria-hidden": true, width: 13, height: 13 }) })] }, i))), _jsxs("button", { type: "button", onClick: addColour, className: "flex h-7 cursor-pointer items-center justify-center gap-1.5 rounded-md border border-dashed border-edge text-[11px] text-ink2 hover:bg-scrim hover:text-ink", children: [_jsx(Plus, { "aria-hidden": true, width: 12, height: 12 }), " Add a colour"] }), _jsx("p", { className: "text-[10px] font-semibold tracking-wide text-ink3 uppercase", children: "How it generates" }), _jsx(Field, { label: "Contrast", children: (id) => (_jsx(Segmented, { labelledBy: id, value: seed.contrastAlgorithm ?? "wcag", onChange: (v) => set({ contrastAlgorithm: v }), options: [
103
132
  { value: "wcag", label: "WCAG 2" },
104
133
  ...(apca ? [{ value: "apca", label: "APCA" }] : []),
105
- ] })) }), _jsxs(Row, { children: [_jsx(Field, { label: "Target", children: (id) => (_jsx(Segmented, { labelledBy: id, value: seed.contrastTarget ?? "aa", onChange: (v) => set({ contrastTarget: v }), options: [
106
- { value: "aa-large", label: "AA large" },
107
- { value: "aa", label: "AA" },
108
- { value: "aaa", label: "AAA" },
109
- ] })) }), _jsx(Field, { label: "Lightness", children: (id) => (_jsx(Segmented, { labelledBy: id, value: seed.lightnessStrategy ?? "fixed", onChange: (v) => set({ lightnessStrategy: v }), options: [
134
+ ] })) }), _jsx(Field, { label: "Target", children: (id) => (_jsx(Segmented, { labelledBy: id, value: seed.contrastTarget ?? "aa", onChange: (v) => set({ contrastTarget: v }), options: [
135
+ { value: "aa-large", label: "AA large" },
136
+ { value: "aa", label: "AA" },
137
+ { value: "aaa", label: "AAA" },
138
+ ] })) }), _jsxs(Row, { children: [_jsx(Field, { label: "Lightness", children: (id) => (_jsx(Segmented, { labelledBy: id, value: seed.lightnessStrategy ?? "fixed", onChange: (v) => set({ lightnessStrategy: v }), options: [
110
139
  { value: "fixed", label: "Fixed" },
111
140
  { value: "perceptual", label: "Even" },
112
- ] })) })] }), _jsx(Field, { label: "Labels on fills", children: (id) => (_jsx(Segmented, { labelledBy: id, value: seed.foreground ?? "balanced", onChange: (v) => set({ foreground: v }), options: [
113
- { value: "balanced", label: "Balanced" },
114
- { value: "max", label: "Strongest" },
115
- ] })) }), surfaces.map((k) => (_jsx(Row, { children: ["light", "dark"].map((mode) => (_jsx(Field, { label: `${k}, ${mode}`, children: (id) => (_jsx(ColorInput, { label: `${k}, ${mode}`, labelledBy: id, value: seed.surfaceColors?.[mode]?.[k] ?? "", onChange: (v) => set({ surfaceColors: { ...seed.surfaceColors, [mode]: { ...seed.surfaceColors?.[mode], [k]: v } } }) })) }, mode))) }, k))), Object.entries(seed.backgrounds ?? {}).map(([name, bg]) => (_jsx(Row, { children: ["light", "dark"].map((mode) => (_jsx(Field, { label: `${name}, ${mode}`, children: (id) => (_jsx(ColorInput, { label: `${name}, ${mode}`, labelledBy: id, value: (mode === "light" ? bg.light : bg.dark) ?? "", onChange: (v) => set({ backgrounds: { ...seed.backgrounds, [name]: { ...bg, [mode]: v } } }) })) }, mode))) }, name))), system ? _jsx(Score, { system: system, seed: seed }) : _jsx("p", { className: "text-[11px] text-fail", children: "That colour can't be read yet." })] }));
141
+ ] })) }), _jsx(Field, { label: "Labels on fills", children: (id) => (_jsx(Segmented, { labelledBy: id, value: seed.foreground ?? "balanced", onChange: (v) => set({ foreground: v }), options: [
142
+ { value: "balanced", label: "Balanced" },
143
+ { value: "max", label: "Strongest" },
144
+ ] })) })] }), _jsx(Field, { label: "Primary lands on step", children: (id) => _jsx(Select, { labelledBy: id, value: String(seed.seedShade ?? 500), options: SHADES, onChange: (v) => set({ seedShade: Number(v) }) }) }), _jsxs("div", { className: "flex items-center justify-between gap-2 text-[10px] text-ink3", children: [_jsx("span", { children: stored ? "Changed from the project's seed" : `From ${project.script ? `the "${project.script}" script` : "the project's seed"}` }), stored && (_jsxs("button", { type: "button", onClick: () => writeStored(KEY, undefined), className: "flex cursor-pointer items-center gap-1 rounded-sm px-1 hover:text-ink", children: [_jsx(RotateCcw, { "aria-hidden": true, width: 11, height: 11 }), " Back to the project's"] }))] })] }));
116
145
  }
117
146
  const RATIOS = [
118
147
  { value: "1.067", label: "Minor second, 1.067" },
@@ -169,6 +198,15 @@ function Scales() {
169
198
  * both): the studio offers the scales only. The colour tool stays here, off, for when it is.
170
199
  */
171
200
  const COLOUR_EDITING = false;
201
+ /**
202
+ * The colour generator in the dock, where it's asked for: the project's seed to start from, changed by
203
+ * hand, live on the page, handed back as the seed and the command.
204
+ *
205
+ * <Widgets tokens={manifest}><ColourGenerator project={readProjectSeed()} /></Widgets>
206
+ */
207
+ export function ColourGenerator({ project }) {
208
+ return project ? _jsx(Colour, { project: project }) : null;
209
+ }
172
210
  export function TokenStudio({ project = null }) {
173
211
  return (_jsxs(_Fragment, { children: [COLOUR_EDITING && project ? _jsx(Colour, { project: project }) : null, _jsx(Scales, {})] }));
174
212
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@designtools/tokens",
3
- "version": "0.8.0",
3
+ "version": "0.9.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",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@base-ui/react": "^1.6.0",
46
- "@designtools/widgets": "^0.1.0",
46
+ "@designtools/widgets": "^0.1.3",
47
47
  "apca-w3": "^0.1.9",
48
48
  "lucide-react": "^1.23.0",
49
49
  "react": ">=19",
@@ -86,7 +86,7 @@
86
86
  "tsx": "^4.19.0",
87
87
  "typescript": "^5.9.3",
88
88
  "vitest": "^4.1.11",
89
- "@designtools/widgets": "0.1.0"
89
+ "@designtools/widgets": "0.1.3"
90
90
  },
91
91
  "keywords": [
92
92
  "design-tokens",