@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 +24 -0
- package/README.md +48 -1
- package/dist/{chunk-P562LKFL.js → chunk-YOUMF42P.js} +170 -18
- package/dist/cli.js +127 -5
- package/dist/index.d.ts +132 -1
- package/dist/index.js +7 -1
- package/dist/studio/changes.d.ts +12 -0
- package/dist/studio/changes.js +98 -0
- package/dist/studio/clipboard.d.ts +7 -0
- package/dist/studio/clipboard.js +33 -0
- package/dist/studio/colour-controls.d.ts +54 -0
- package/dist/studio/colour-controls.js +199 -0
- package/dist/studio/colour-editor.d.ts +14 -0
- package/dist/studio/colour-editor.js +268 -0
- package/dist/studio/css.js +2 -2
- package/dist/studio/index.d.ts +1 -0
- package/dist/studio/index.js +1 -0
- package/dist/studio/seed.js +41 -1
- package/dist/studio/studio.d.ts +16 -0
- package/dist/studio/studio.js +78 -34
- package/package.json +3 -3
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type Edit } from "./colour-controls.js";
|
|
3
|
+
/** The page's anchors of one kind, kept up to date as the page renders (a colour the generator adds brings its own). */
|
|
4
|
+
export declare function useAnchors(kind: string): HTMLElement[];
|
|
5
|
+
/** Fills the colour page's anchors. Rendered by `ColourGenerator`, inside the app's `<Widgets>`. */
|
|
6
|
+
export declare function InPlaceEditor({ edit, score, clear, prompt, changes, }: {
|
|
7
|
+
edit: Edit;
|
|
8
|
+
score: ReactNode;
|
|
9
|
+
clear: () => void;
|
|
10
|
+
/** The hand-back for the agent, once something has changed. */
|
|
11
|
+
prompt: string | null;
|
|
12
|
+
/** What changed, in words. */
|
|
13
|
+
changes: string[];
|
|
14
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* The colour editor, in place on the docs' colour page. The page draws nothing for it: it leaves
|
|
5
|
+
* empty anchors (`data-designtools-slot="colour:page"`, `"colour:ramp"`, `"colour:family"`), and
|
|
6
|
+
* this fills them. The header gets an Edit colours switch; with it on, each ramp and each colour gets
|
|
7
|
+
* a small button beside its name that opens its settings in a popover, so the page keeps its layout
|
|
8
|
+
* and a ramp is changed while looking at it. Every change is a change to the generator's seed.
|
|
9
|
+
*/
|
|
10
|
+
import { Popover } from "@base-ui/react/popover";
|
|
11
|
+
import { getAPCAContrast, getContrastRatio, isAPCAAvailable, VALID_SHADES, } from "@designtools/tokens";
|
|
12
|
+
import { ColorInput, Field, POPUP, readStored, Row, Segmented, Select, subscribeStored, THEME_KEY, Tip, TipProvider, ToolRoot, usePortalContainer, writeStored } from "@designtools/widgets";
|
|
13
|
+
import { Bot, Check, Moon, Palette, Plus, RotateCcw, SlidersHorizontal, Sun, Trash2 } from "lucide-react";
|
|
14
|
+
import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
15
|
+
import { createPortal } from "react-dom";
|
|
16
|
+
import { ACTION, Compare, FamilyShapeControls, Hint, Pins, SystemShape, Versions } from "./colour-controls.js";
|
|
17
|
+
import { css, properties } from "./css.js";
|
|
18
|
+
import { generateFromSeed } from "./seed.js";
|
|
19
|
+
import { copyText } from "./clipboard.js";
|
|
20
|
+
const STYLES = [{ id: "tokens-studio", css, properties }];
|
|
21
|
+
/** Whether the colour page is in edit mode: kept, and the same in every tab. */
|
|
22
|
+
const EDIT_KEY = "colour:edit";
|
|
23
|
+
const STATUS = ["success", "destructive", "warning"];
|
|
24
|
+
const NAME = /^[a-z][a-z0-9-]*$/;
|
|
25
|
+
const FLOORS = {
|
|
26
|
+
wcag: { "aa-large": 3, aa: 4.5, aaa: 7 },
|
|
27
|
+
apca: { "aa-large": 45, aa: 60, aaa: 75 },
|
|
28
|
+
};
|
|
29
|
+
const SHADES = VALID_SHADES.map((s) => ({ value: String(s), label: String(s) }));
|
|
30
|
+
const BUTTON = "inline-flex h-8 cursor-pointer items-center gap-1.5 rounded-md border border-edge bg-page px-2.5 text-[12px] font-medium text-ink shadow-xs hover:bg-scrim data-popup-open:bg-scrim outline-none focus-visible:outline-2 focus-visible:outline-sel";
|
|
31
|
+
/** A button in the floating bar: no border of its own, the bar is the frame. */
|
|
32
|
+
const BAR = "inline-flex h-8 shrink-0 cursor-pointer items-center gap-1.5 rounded-lg px-2.5 text-[12px] font-medium text-ink hover:bg-scrim data-popup-open:bg-scrim outline-none focus-visible:outline-2 focus-visible:outline-sel";
|
|
33
|
+
/** An icon on its own in the bar. */
|
|
34
|
+
const ICON = `${BAR} w-8 justify-center px-0`;
|
|
35
|
+
function useEditing() {
|
|
36
|
+
return useSyncExternalStore(useCallback((cb) => subscribeStored((k) => k === EDIT_KEY && cb()), []), () => readStored(EDIT_KEY, false), () => false);
|
|
37
|
+
}
|
|
38
|
+
/** The page's anchors of one kind, kept up to date as the page renders (a colour the generator adds brings its own). */
|
|
39
|
+
export function useAnchors(kind) {
|
|
40
|
+
const [found, setFound] = useState([]);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
const find = () => {
|
|
43
|
+
const next = [...document.querySelectorAll(`[data-designtools-slot="${kind}"]`)];
|
|
44
|
+
setFound((was) => (was.length === next.length && was.every((el, i) => el === next[i]) ? was : next));
|
|
45
|
+
};
|
|
46
|
+
find();
|
|
47
|
+
const watch = new MutationObserver(find);
|
|
48
|
+
watch.observe(document.body, { childList: true, subtree: true });
|
|
49
|
+
return () => watch.disconnect();
|
|
50
|
+
}, [kind]);
|
|
51
|
+
return found;
|
|
52
|
+
}
|
|
53
|
+
/** A sealed spot in the page for one control: the widgets' styles inside, nothing leaking out. */
|
|
54
|
+
function Sealed({ children, style }) {
|
|
55
|
+
return (_jsx(ToolRoot, { styles: STYLES, style: style ?? { display: "inline-block", verticalAlign: "middle", lineHeight: 0 }, children: _jsx(TipProvider, { children: children }) }));
|
|
56
|
+
}
|
|
57
|
+
/** A button that opens its settings in place, in a popover beside it. */
|
|
58
|
+
function InPlace({ trigger, title, label, children, width = 288, bare = false, icon = false, side = "bottom", }) {
|
|
59
|
+
const container = usePortalContainer();
|
|
60
|
+
return (_jsxs(Popover.Root, { children: [_jsx(Popover.Trigger, { "aria-label": label, className: bare
|
|
61
|
+
? "flex size-6 cursor-pointer items-center justify-center rounded-md text-ink3 outline-none hover:bg-scrim hover:text-ink focus-visible:outline-2 focus-visible:outline-sel data-popup-open:bg-scrim data-popup-open:text-ink"
|
|
62
|
+
: icon
|
|
63
|
+
? ICON
|
|
64
|
+
: BUTTON, children: trigger }), _jsx(Popover.Portal, { container: container, children: _jsx(Popover.Positioner, { side: side, align: "end", sideOffset: side === "top" ? 10 : 6, collisionPadding: 12, positionMethod: "fixed", className: "z-50", children: _jsxs(Popover.Popup, { className: `${POPUP} flex max-h-[min(560px,calc(100vh-96px))] flex-col gap-3 overflow-y-auto p-3.5`, style: { width }, children: [_jsx(Popover.Title, { className: "text-[11px] font-semibold text-ink", children: title }), children] }) }) })] }));
|
|
65
|
+
}
|
|
66
|
+
/** A pairing's contrast in the chosen algorithm, and whether it reaches the target. */
|
|
67
|
+
function measure(fg, bg, algorithm, target) {
|
|
68
|
+
try {
|
|
69
|
+
const score = algorithm === "apca" ? Math.round(Math.abs(getAPCAContrast(fg, bg)) * 10) / 10 : Math.round(getContrastRatio(fg, bg) * 100) / 100;
|
|
70
|
+
return { score, pass: score >= FLOORS[algorithm][target] };
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return { score: 0, pass: false };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** Fills the colour page's anchors. Rendered by `ColourGenerator`, inside the app's `<Widgets>`. */
|
|
77
|
+
export function InPlaceEditor({ edit, score, clear, prompt, changes, }) {
|
|
78
|
+
const editing = useEditing();
|
|
79
|
+
const pages = useAnchors("colour:page");
|
|
80
|
+
const ramps = useAnchors("colour:ramp");
|
|
81
|
+
const families = useAnchors("colour:family");
|
|
82
|
+
return (_jsxs(_Fragment, { children: [pages.length > 0 && (_jsx(Sealed, { style: { position: "fixed", right: 16, bottom: 16, zIndex: 2147482000, lineHeight: 0 }, children: _jsxs("div", { role: "toolbar", "aria-label": "Colour", className: "flex max-w-[calc(100vw-32px)] items-center gap-0.5 rounded-xl border border-edge bg-page p-1 text-ink shadow-lg shadow-black/15", children: [editing && (_jsxs(_Fragment, { children: [prompt && (_jsxs(_Fragment, { children: [_jsx(CopyPrompt, { prompt: prompt, changes: changes }), _jsx(Divider, {})] })), _jsx(InPlace, { title: "Add a colour", label: "Add a colour", icon: true, side: "top", trigger: _jsx(Plus, { "aria-hidden": true, width: 15, height: 15 }), width: 300, children: _jsx(AddColour, { edit: edit }) }), prompt && (_jsx(Tip, { content: "Back to the project's colours", side: "top", children: _jsx("button", { type: "button", "aria-label": "Back to the project's colours", onClick: clear, className: ICON, children: _jsx(RotateCcw, { "aria-hidden": true, width: 14, height: 14 }) }) })), _jsx(ModeSwitch, {}), _jsxs(InPlace, { title: "Colour settings", label: "Colour settings", icon: true, side: "top", trigger: _jsx(SlidersHorizontal, { "aria-hidden": true, width: 14, height: 14 }), width: 320, children: [_jsx(Refused, { error: edit.error }), score, _jsx(SystemSettings, { edit: edit }), _jsx(Versions, { edit: edit })] }), _jsx(Divider, {})] })), _jsxs("button", { type: "button", "aria-pressed": editing, onClick: () => writeStored(EDIT_KEY, editing ? undefined : true), className: BAR, children: [editing ? _jsx(Check, { "aria-hidden": true, width: 14, height: 14 }) : _jsx(Palette, { "aria-hidden": true, width: 14, height: 14 }), editing ? "Done" : "Edit colours"] })] }) })), editing &&
|
|
83
|
+
ramps.map((el, i) => {
|
|
84
|
+
const family = el.dataset.family ?? "";
|
|
85
|
+
return editable(family, edit.seed)
|
|
86
|
+
? createPortal(_jsx(Sealed, { children: _jsx(RampSettings, { family: family, edit: edit }) }), el, `ramp-${family}-${i}`)
|
|
87
|
+
: null;
|
|
88
|
+
}), editing &&
|
|
89
|
+
families.map((el, i) => {
|
|
90
|
+
const family = el.dataset.family ?? "";
|
|
91
|
+
return edit.system?.semantic.light[family] ? createPortal(_jsx(Sealed, { children: _jsx(Roles, { family: family, edit: edit }) }), el, `family-${family}-${i}`) : null;
|
|
92
|
+
})] }));
|
|
93
|
+
}
|
|
94
|
+
/** A thin line between groups in the bar. */
|
|
95
|
+
function Divider() {
|
|
96
|
+
return _jsx("span", { "aria-hidden": true, className: "mx-1 h-5 w-px shrink-0 bg-edge" });
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Add a colour: a new family beside primary and neutral, made from one colour. It gets a full ramp
|
|
100
|
+
* (25 to 950) and its own fill, subdued, hover and press, each label measured like the rest, and it
|
|
101
|
+
* shows on the page as it's added.
|
|
102
|
+
*/
|
|
103
|
+
function AddColour({ edit }) {
|
|
104
|
+
const colours = edit.seed.additionalColors ?? [];
|
|
105
|
+
const taken = new Set(["primary", "neutral", "black", "white", "muted", "canvas", "surface", "overlay", "border", "input", "ring", ...STATUS, "green", "red", "yellow", ...colours.map((c) => c.name)]);
|
|
106
|
+
const suggest = () => ["accent", "info", "highlight", "brand", "extra"].find((n) => !taken.has(n)) ?? `colour-${colours.length + 1}`;
|
|
107
|
+
const [name, setName] = useState(suggest);
|
|
108
|
+
const [color, setColor] = useState("#8b5cf6");
|
|
109
|
+
const [added, setAdded] = useState(null);
|
|
110
|
+
const problem = !NAME.test(name) ? "Lower case letters, numbers and dashes, starting with a letter" : taken.has(name) ? "That name is taken" : null;
|
|
111
|
+
const add = () => {
|
|
112
|
+
if (problem)
|
|
113
|
+
return;
|
|
114
|
+
edit.set({ additionalColors: [...colours, { name, color }] });
|
|
115
|
+
setAdded(name);
|
|
116
|
+
setName(["accent", "info", "highlight", "brand", "extra"].find((n) => n !== name && !taken.has(n)) ?? `colour-${colours.length + 2}`);
|
|
117
|
+
};
|
|
118
|
+
return (_jsxs(_Fragment, { children: [_jsx("p", { className: "text-[11px] leading-snug text-ink2", children: "A new colour beside primary and neutral: its own ramp, and a fill, subdued, hover and press, each checked for contrast." }), _jsx(Field, { label: "Name", actions: _jsx(Hint, { text: `How it's written in the code: --${name || "accent"} and bg-${name || "accent"}.` }), children: (id) => (_jsx("input", { "aria-labelledby": id, value: name, spellCheck: false, "aria-invalid": Boolean(problem), onChange: (e) => setName(e.target.value.toLowerCase().replace(/\s+/g, "-")), onKeyDown: (e) => e.key === "Enter" && add(), className: `h-8 w-full rounded-md bg-muted px-2 font-mono text-[12px] text-ink outline-none focus-visible:ring-1 focus-visible:ring-sel ${problem ? "ring-1 ring-fail" : ""}` })) }), problem && _jsx("p", { className: "text-[11px] text-fail", children: problem }), _jsx(Field, { label: "Colour", actions: _jsx(Hint, { text: "The colour it's made from. It lands on step 500; change that on its ramp once it's added." }), children: (id) => _jsx(ColorInput, { label: "New colour", labelledBy: id, value: color, onChange: setColor }) }), _jsxs("button", { type: "button", onClick: add, disabled: Boolean(problem), className: ACTION, children: [_jsx(Plus, { "aria-hidden": true, width: 13, height: 13 }), " Add ", name || "colour"] }), added && _jsxs("p", { className: "text-[11px] text-ink2", children: ["Added ", added, ": it's on the page now, with its ramp and its settings."] })] }));
|
|
119
|
+
}
|
|
120
|
+
/** Light or dark, for the page and the tools together: the same switch as the dock's, in the widget's own button. */
|
|
121
|
+
function ModeSwitch() {
|
|
122
|
+
const chosen = useSyncExternalStore(useCallback((cb) => subscribeStored((k) => k === THEME_KEY && cb()), []), () => readStored(THEME_KEY, null), () => null);
|
|
123
|
+
const dark = chosen === "dark" ||
|
|
124
|
+
(chosen !== "light" && (document.documentElement.dataset.theme === "dark" || (!document.documentElement.dataset.theme && matchMedia("(prefers-color-scheme: dark)").matches)));
|
|
125
|
+
const label = dark ? "Light mode" : "Dark mode";
|
|
126
|
+
return (_jsx(Tip, { content: label, side: "top", children: _jsx("button", { type: "button", "aria-label": label, onClick: () => writeStored(THEME_KEY, dark ? "light" : "dark"), className: ICON, children: dark ? _jsx(Sun, { "aria-hidden": true, width: 14, height: 14 }) : _jsx(Moon, { "aria-hidden": true, width: 14, height: 14 }) }) }));
|
|
127
|
+
}
|
|
128
|
+
/** Copy prompt in the main widget: the changes on hover, the prompt shown to copy by hand when the clipboard refuses. */
|
|
129
|
+
function CopyPrompt({ prompt, changes }) {
|
|
130
|
+
const container = usePortalContainer();
|
|
131
|
+
const anchor = useRef(null);
|
|
132
|
+
const [state, setState] = useState("idle");
|
|
133
|
+
const copy = async () => {
|
|
134
|
+
try {
|
|
135
|
+
await copyText(prompt);
|
|
136
|
+
setState("copied");
|
|
137
|
+
setTimeout(() => setState("idle"), 1500);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
setState("manual");
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
return (_jsxs(Popover.Root, { open: state === "manual", onOpenChange: (open) => !open && setState("idle"), children: [_jsx(Tip, { content: `A prompt for your agent: ${changes.join("; ")}`, side: "top", children: _jsxs("button", { ref: anchor, type: "button", onClick: copy, className: BAR, children: [state === "copied" ? _jsx(Check, { "aria-hidden": true, width: 13, height: 13 }) : _jsx(Bot, { "aria-hidden": true, width: 13, height: 13 }), state === "copied" ? "Copied" : "Copy prompt", _jsx("span", { className: "rounded-full bg-sel px-1.5 text-[10px] leading-[16px] text-white tabular-nums", children: changes.length })] }) }), _jsx(Popover.Portal, { container: container, children: _jsx(Popover.Positioner, { anchor: anchor, side: "top", align: "end", sideOffset: 10, collisionPadding: 12, positionMethod: "fixed", className: "z-50", children: _jsxs(Popover.Popup, { className: `${POPUP} flex w-[340px] flex-col gap-2 p-3.5`, children: [_jsx(Popover.Title, { className: "text-[11px] font-semibold text-ink", children: "Copy this prompt" }), _jsx("textarea", { readOnly: true, value: prompt, onFocus: (e) => e.currentTarget.select(), className: "h-48 w-full resize-none rounded-md bg-muted p-2 font-mono text-[10px] leading-relaxed text-ink2" })] }) }) })] }));
|
|
144
|
+
}
|
|
145
|
+
/** A ramp the seed can change: the two seeds, the status colours, and colours added. Aliases (green for success) aren't. */
|
|
146
|
+
function editable(family, seed) {
|
|
147
|
+
return family === "primary" || family === "neutral" || STATUS.includes(family) || (seed.additionalColors ?? []).some((c) => c.name === family);
|
|
148
|
+
}
|
|
149
|
+
/** The whole system: how it measures and generates, and colours to add. */
|
|
150
|
+
function SystemSettings({ edit }) {
|
|
151
|
+
const { seed, set } = edit;
|
|
152
|
+
const apca = isAPCAAvailable();
|
|
153
|
+
return (_jsxs(_Fragment, { children: [_jsx(Field, { label: "Contrast", actions: _jsx(Hint, { text: "How contrast is measured. WCAG 2 is what audits check; APCA also weighs how text looks at its size, and is optional." }), children: (id) => (_jsx(Segmented, { labelledBy: id, value: seed.contrastAlgorithm ?? "wcag", onChange: (v) => set({ contrastAlgorithm: v }), options: [{ value: "wcag", label: "WCAG 2" }, ...(apca ? [{ value: "apca", label: "APCA" }] : [])] })) }), _jsx(Field, { label: "Target", actions: _jsx(Hint, { text: "The level every label has to reach on its fill: AA large 3:1, AA 4.5:1, AAA 7:1." }), children: (id) => (_jsx(Segmented, { labelledBy: id, value: seed.contrastTarget ?? "aa", onChange: (v) => set({ contrastTarget: v }), options: [
|
|
154
|
+
{ value: "aa-large", label: "AA large" },
|
|
155
|
+
{ value: "aa", label: "AA" },
|
|
156
|
+
{ value: "aaa", label: "AAA" },
|
|
157
|
+
] })) }), _jsxs(Row, { children: [_jsx(Field, { label: "Lightness", actions: _jsx(Hint, { text: "How the steps are spaced. Fixed: smooth at the light end, bigger jumps in the darks. Even: more evenly spaced as the eye sees them." }), children: (id) => (_jsx(Segmented, { labelledBy: id, value: seed.lightnessStrategy ?? "fixed", onChange: (v) => set({ lightnessStrategy: v }), options: [
|
|
158
|
+
{ value: "fixed", label: "Fixed" },
|
|
159
|
+
{ value: "perceptual", label: "Even" },
|
|
160
|
+
] })) }), _jsx(Field, { label: "Labels on fills", actions: _jsx(Hint, { text: "The text on a filled colour. Balanced: white, black, or a tint of the colour that keeps nearly all the contrast. Strongest: always white or black." }), children: (id) => (_jsx(Segmented, { labelledBy: id, value: seed.foreground ?? "balanced", onChange: (v) => set({ foreground: v }), options: [
|
|
161
|
+
{ value: "balanced", label: "Balanced" },
|
|
162
|
+
{ value: "max", label: "Strongest" },
|
|
163
|
+
] })) })] }), _jsx(SystemShape, { edit: edit })] }));
|
|
164
|
+
}
|
|
165
|
+
/** Why the settings can't be generated, when they can't: a refused pin, said plainly. */
|
|
166
|
+
function Refused({ error }) {
|
|
167
|
+
if (!error)
|
|
168
|
+
return null;
|
|
169
|
+
return _jsxs("p", { className: "rounded-md bg-fail/10 px-2.5 py-2 text-[11px] leading-snug text-fail", children: ["Not applied: ", error] });
|
|
170
|
+
}
|
|
171
|
+
/** One ramp: the colour it's made from, the step that colour lands on, and, for an added colour, its name. */
|
|
172
|
+
function RampSettings({ family, edit }) {
|
|
173
|
+
const { seed, set, system } = edit;
|
|
174
|
+
const colours = seed.additionalColors ?? [];
|
|
175
|
+
const entry = colours.find((c) => c.name === family);
|
|
176
|
+
const status = STATUS.includes(family);
|
|
177
|
+
const derived = status && !entry;
|
|
178
|
+
const scale = system?.primitives[family];
|
|
179
|
+
const swatch = family === "primary" ? seed.primaryColor : family === "neutral" ? seed.neutralColor : entry?.color;
|
|
180
|
+
const shown = swatch ?? (scale && typeof scale === "object" ? scale["500"] : "");
|
|
181
|
+
const step = family === "primary" ? seed.seedShade : family === "neutral" ? seed.neutralSeedShade : entry?.seedShade;
|
|
182
|
+
const setEntry = (patch) => set({ additionalColors: entry ? colours.map((c) => (c.name === family ? { ...c, ...patch } : c)) : [...colours, { name: family, color: shown ?? "#000000", ...patch }] });
|
|
183
|
+
const setColour = (color) => (family === "primary" ? set({ primaryColor: color }) : family === "neutral" ? set({ neutralColor: color }) : setEntry({ color }));
|
|
184
|
+
const setStep = (v) => {
|
|
185
|
+
const s = Number(v);
|
|
186
|
+
if (family === "primary")
|
|
187
|
+
set({ seedShade: s });
|
|
188
|
+
else if (family === "neutral")
|
|
189
|
+
set({ neutralSeedShade: s });
|
|
190
|
+
else
|
|
191
|
+
setEntry({ seedShade: s });
|
|
192
|
+
};
|
|
193
|
+
const without = colours.filter((c) => c.name !== family);
|
|
194
|
+
const anchor = ((family === "primary" ? seed.seedShade : family === "neutral" ? seed.neutralSeedShade : entry?.seedShade) ?? 500);
|
|
195
|
+
const refused = edit.error?.startsWith(`${family}:`) ? edit.error.slice(family.length + 1).trim() : null;
|
|
196
|
+
return (_jsxs(InPlace, { title: `${family.charAt(0).toUpperCase()}${family.slice(1)} ramp`, label: `${family} ramp settings`, width: 320, trigger: _jsx(SlidersHorizontal, { "aria-hidden": true, width: 14, height: 14 }), bare: true, children: [_jsx(Refused, { error: refused }), _jsx(Compare, { family: family, edit: edit }), _jsx(Field, { label: "Made from", actions: _jsx(Hint, { text: derived ? "Made from the primary until you change it here. The colour lands exactly on the step below." : "The colour this ramp is built from. It lands exactly on the step below; every other step is worked out from it." }), children: (id) => _jsx(ColorInput, { label: `${family} colour`, labelledBy: id, value: shown ?? "", onChange: setColour }) }), _jsx(Field, { label: "Lands on step", actions: _jsx(Hint, { text: "Which step the colour sits on. A dark colour belongs low (700), a pale one high (200), so the ramp has room either side." }), children: (id) => _jsx(Select, { labelledBy: id, value: String(step ?? 500), options: SHADES, onChange: setStep }) }), entry && !status && (_jsx(Field, { label: "Name", actions: _jsx(Hint, { text: `Its name in the code: --${family}, and bg-${family} in Tailwind.` }), children: (id) => (_jsx("input", { "aria-labelledby": id, value: family, spellCheck: false, "aria-invalid": !NAME.test(family), onChange: (e) => {
|
|
197
|
+
const name = e.target.value.toLowerCase().replace(/\s+/g, "-");
|
|
198
|
+
set({ additionalColors: colours.map((c) => (c.name === family ? { ...c, name } : c)) });
|
|
199
|
+
}, 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" })) })), entry && (_jsxs("button", { type: "button", onClick: () => set({ additionalColors: without.length ? without : undefined }), className: ACTION, children: [status ? _jsx(RotateCcw, { "aria-hidden": true, width: 13, height: 13 }) : _jsx(Trash2, { "aria-hidden": true, width: 13, height: 13 }), status ? "Made from the primary again" : "Remove this colour"] })), _jsx(FamilyShapeControls, { family: family, edit: edit }), _jsx(Pins, { family: family, anchor: anchor, edit: edit })] }));
|
|
200
|
+
}
|
|
201
|
+
const ROLES = [
|
|
202
|
+
{ key: "DEFAULT", label: "Fill", fg: "foreground" },
|
|
203
|
+
{ key: "subdued", label: "Subdued", fg: "subdued-foreground" },
|
|
204
|
+
];
|
|
205
|
+
/** One colour's roles: which step its fill and its subdued sit on, in each mode, from the steps whose labels pass. */
|
|
206
|
+
function Roles({ family, edit }) {
|
|
207
|
+
return (_jsx(InPlace, { title: `${family.charAt(0).toUpperCase()}${family.slice(1)}: which steps`, label: `${family} roles`, trigger: _jsxs(_Fragment, { children: [_jsx(SlidersHorizontal, { "aria-hidden": true, width: 13, height: 13 }), " Steps"] }), width: 320, children: _jsx(RolePicker, { family: family, edit: edit }) }));
|
|
208
|
+
}
|
|
209
|
+
function RolePicker({ family, edit }) {
|
|
210
|
+
const { seed, set, system } = edit;
|
|
211
|
+
const [mode, setMode] = useState(() => (document.documentElement.dataset.theme === "dark" ? "dark" : "light"));
|
|
212
|
+
const algorithm = seed.contrastAlgorithm ?? "wcag";
|
|
213
|
+
const target = seed.contrastTarget ?? "aa";
|
|
214
|
+
const scale = system?.primitives[family];
|
|
215
|
+
const steps = scale ? Object.keys(scale).map(Number).filter((n) => !Number.isNaN(n)) : [];
|
|
216
|
+
const overrides = seed.shadeOverrides?.[family]?.[mode] ?? {};
|
|
217
|
+
// each step tried in turn, generated for real, so the label the generator would choose is the one measured
|
|
218
|
+
const options = useMemo(() => {
|
|
219
|
+
const out = {};
|
|
220
|
+
for (const role of ROLES) {
|
|
221
|
+
out[role.key] = steps.map((step) => {
|
|
222
|
+
try {
|
|
223
|
+
const tried = generateFromSeed({
|
|
224
|
+
...seed,
|
|
225
|
+
shadeOverrides: { ...seed.shadeOverrides, [family]: { ...seed.shadeOverrides?.[family], [mode]: { ...overrides, [role.key]: step } } },
|
|
226
|
+
});
|
|
227
|
+
const c = tried.semantic[mode][family];
|
|
228
|
+
const bg = c[role.key];
|
|
229
|
+
const fg = c[role.fg];
|
|
230
|
+
return { step, bg, fg, ...measure(fg, bg, algorithm, target) };
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
return { step, bg: scale?.[String(step)] ?? "", fg: "", score: 0, pass: false };
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
return out;
|
|
238
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: the seed and mode decide every option
|
|
239
|
+
}, [seed, family, mode]);
|
|
240
|
+
const current = (key) => {
|
|
241
|
+
const c = system?.semantic[mode][family];
|
|
242
|
+
return options[key]?.find((o) => o.bg === c?.[key])?.step;
|
|
243
|
+
};
|
|
244
|
+
const choose = (key, step) => {
|
|
245
|
+
const nextMode = { ...overrides, [key]: step };
|
|
246
|
+
if (step === undefined)
|
|
247
|
+
delete nextMode[key];
|
|
248
|
+
const nextFamily = { ...seed.shadeOverrides?.[family], [mode]: nextMode };
|
|
249
|
+
if (!Object.keys(nextMode).length)
|
|
250
|
+
delete nextFamily[mode];
|
|
251
|
+
const next = { ...seed.shadeOverrides, [family]: nextFamily };
|
|
252
|
+
if (!Object.keys(nextFamily).length)
|
|
253
|
+
delete next[family];
|
|
254
|
+
set({ shadeOverrides: next });
|
|
255
|
+
};
|
|
256
|
+
const unit = algorithm === "apca" ? "Lc " : "";
|
|
257
|
+
const suffix = algorithm === "apca" ? "" : ":1";
|
|
258
|
+
return (_jsxs(_Fragment, { children: [_jsx(Segmented, { label: "Mode", value: mode, onChange: (v) => setMode(v), options: [
|
|
259
|
+
{ value: "light", label: "Light" },
|
|
260
|
+
{ value: "dark", label: "Dark" },
|
|
261
|
+
] }), ROLES.map((role) => {
|
|
262
|
+
const chosen = overrides[role.key];
|
|
263
|
+
const now = current(role.key);
|
|
264
|
+
return (_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsxs("div", { className: "flex items-center justify-between text-[10px]", children: [_jsxs("span", { className: "flex items-center gap-1.5 font-medium text-ink2", children: [role.label, _jsx(Hint, { text: role.key === "DEFAULT"
|
|
265
|
+
? "The step a button or badge in this colour is filled with. Only steps whose label passes can be chosen; hover one for its contrast."
|
|
266
|
+
: "The step for the quiet version: a pale chip or banner with darker text. Only steps whose label passes can be chosen." })] }), chosen !== undefined ? (_jsx("button", { type: "button", onClick: () => choose(role.key, undefined), className: "cursor-pointer rounded-sm px-1 text-ink3 hover:text-ink", children: "Reset" })) : (_jsx("span", { className: "text-ink3", children: "Generator's choice" }))] }), _jsx("div", { className: "grid grid-cols-6 gap-1", children: options[role.key]?.map((o) => (_jsxs("button", { type: "button", disabled: !o.pass, "aria-pressed": now === o.step, title: `${role.label} on ${o.step}: label ${unit}${o.score}${suffix}${o.pass ? "" : `, under ${target.toUpperCase()}`}`, onClick: () => choose(role.key, o.step), className: `flex h-10 cursor-pointer flex-col items-start justify-between rounded-[4px] p-1 text-[9px] leading-none tabular-nums outline-offset-1 disabled:cursor-not-allowed disabled:opacity-35 ${now === o.step ? "outline-2 outline-sel" : "outline-1 -outline-offset-1 outline-black/10"}`, style: { background: o.bg, color: o.fg || undefined }, children: [_jsx("span", { className: "font-semibold", children: "Aa" }), _jsx("span", { children: o.step })] }, o.step))) })] }, role.key));
|
|
267
|
+
})] }));
|
|
268
|
+
}
|
package/dist/studio/css.js
CHANGED
|
@@ -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}.
|
|
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-leading:initial;--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;--tw-outline-style:solid}}}@layer theme{:root,:host{--font-sans:ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif;--spacing:4px;--font-weight-medium:500;--font-weight-semibold:600;--tracking-wide:.025em;--leading-snug:1.375;--leading-relaxed:1.625;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4, 0, .2, 1)}}@layer utilities{.visible{visibility:visible}.fixed{position:fixed}.relative{position:relative}.z-50{z-index:50}.container{width:100%}.mx-1{margin-inline:4px}.flex{display:flex}.grid{display:grid}.hidden{display:none}.inline{display:inline}.inline-block{display:inline-block}.inline-flex{display:inline-flex}.size-6{width:24px;height:24px}.size-7{width:28px;height:28px}.size-8{width:32px;height:32px}.h-4{height:16px}.h-5{height:20px}.h-7{height:28px}.h-8{height:32px}.h-10{height:40px}.h-14{height:56px}.h-48{height:192px}.max-h-\\[min\\(560px\\,calc\\(100vh-96px\\)\\)\\]{max-height:min(560px,100vh - 96px)}.w-8{width:32px}.w-10{width:40px}.w-\\[84px\\]{width:84px}.w-\\[340px\\]{width:340px}.w-full{width:100%}.w-px{width:1px}.max-w-\\[calc\\(100vw-32px\\)\\]{max-width:calc(100vw - 32px)}.min-w-0{min-width:0}.flex-1{flex:1}.shrink-0{flex-shrink:0}.-rotate-90{rotate:-90deg}.cursor-help{cursor:help}.cursor-pointer{cursor:pointer}.resize-none{resize:none}.grid-cols-6{grid-template-columns:repeat(6,minmax(0,1fr))}.grid-cols-12{grid-template-columns:repeat(12,minmax(0,1fr))}.flex-col{flex-direction:column}.items-center{align-items:center}.items-end{align-items:flex-end}.items-start{align-items:flex-start}.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}.self-start{align-self:flex-start}.truncate{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.overflow-y-auto{overflow-y:auto}.rounded-\\[4px\\]{border-radius:4px}.rounded-full{border-radius:3.40282e38px}.rounded-lg{border-radius:8px}.rounded-md{border-radius:6px}.rounded-sm{border-radius:4px}.rounded-xl{border-radius:12px}.border{border-style:var(--tw-border-style);border-width:1px}.border-t{border-top-style:var(--tw-border-style);border-top-width:1px}.border-edge{border-color:var(--dt-edge)}.bg-edge{background-color:var(--dt-edge)}.bg-fail\\/10{background-color:var(--dt-fail)}@supports (color:color-mix(in lab, red, red)){.bg-fail\\/10{background-color:color-mix(in oklab, var(--dt-fail) 10%, transparent)}}.bg-muted{background-color:var(--dt-muted)}.bg-page{background-color:var(--dt-page)}.bg-sel{background-color:var(--dt-sel)}.p-1{padding:4px}.p-2{padding:8px}.p-2\\.5{padding:10px}.p-3\\.5{padding:14px}.px-0{padding-inline:0}.px-1{padding-inline:4px}.px-1\\.5{padding-inline:6px}.px-2{padding-inline:8px}.px-2\\.5{padding-inline:10px}.px-3{padding-inline:12px}.py-2{padding-block:8px}.pt-1{padding-top:4px}.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}.text-\\[12px\\]{font-size:12px}.leading-\\[16px\\]{--tw-leading:16px;line-height:16px}.leading-none{--tw-leading:1;line-height:1}.leading-relaxed{--tw-leading:var(--leading-relaxed);line-height:var(--leading-relaxed)}.leading-snug{--tw-leading:var(--leading-snug);line-height:var(--leading-snug)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.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)}.text-white{color:#fff}.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)}.shadow-lg{--tw-shadow:0 10px 15px -3px var(--tw-shadow-color,#0000001a), 0 4px 6px -4px 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)}.shadow-xs{--tw-shadow:0 1px 2px 0 var(--tw-shadow-color,#0000000d);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)}.shadow-black\\/15{--tw-shadow-color:#00000026}@supports (color:color-mix(in lab, red, red)){.shadow-black\\/15{--tw-shadow-color:color-mix(in oklab, oklab(0% none none/.15) var(--tw-shadow-alpha), transparent)}}.ring-fail{--tw-ring-color:var(--dt-fail)}.outline-1{outline-style:var(--tw-outline-style);outline-width:1px}.outline-2{outline-style:var(--tw-outline-style);outline-width:2px}.-outline-offset-1{outline-offset:calc(1px * -1)}.outline-offset-1{outline-offset:1px}.outline-black\\/10{outline-color:oklab(0% none none/.1)}.outline-sel{outline-color:var(--dt-sel)}.transition-colors{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.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)}.focus-visible\\:outline-2:focus-visible{outline-style:var(--tw-outline-style);outline-width:2px}.focus-visible\\:-outline-offset-2:focus-visible{outline-offset:calc(2px * -1)}.focus-visible\\:outline-sel:focus-visible{outline-color:var(--dt-sel)}.disabled\\:cursor-not-allowed:disabled{cursor:not-allowed}.disabled\\:opacity-35:disabled{opacity:.35}.disabled\\:opacity-40:disabled{opacity:.4}.data-popup-open\\:bg-scrim[data-popup-open]{background-color:var(--dt-scrim)}.data-popup-open\\:text-ink[data-popup-open]{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-leading{syntax:\"*\";inherits:false}\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}\n@property --tw-outline-style{syntax:\"*\";inherits:false;initial-value:solid}";
|
package/dist/studio/index.d.ts
CHANGED
|
@@ -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";
|
package/dist/studio/index.js
CHANGED
package/dist/studio/seed.js
CHANGED
|
@@ -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 { exportTokens, generateTokens, } from "@designtools/tokens";
|
|
5
|
+
import { exportTokens, generateTokens, familiesOf, rangeOf, } from "@designtools/tokens";
|
|
6
6
|
/** Split a command line on spaces outside quotes, unquoting as a shell would. */
|
|
7
7
|
export function splitCommand(command) {
|
|
8
8
|
const out = [];
|
|
@@ -117,6 +117,39 @@ export function parseCommand(command) {
|
|
|
117
117
|
case "--neutral-seed-shade":
|
|
118
118
|
seed.neutralSeedShade = Number(value());
|
|
119
119
|
break;
|
|
120
|
+
case "--light-end":
|
|
121
|
+
seed.lightnessRange = { ...seed.lightnessRange, light: Number(value()) };
|
|
122
|
+
break;
|
|
123
|
+
case "--dark-end":
|
|
124
|
+
seed.lightnessRange = { ...seed.lightnessRange, dark: Number(value()) };
|
|
125
|
+
break;
|
|
126
|
+
case "--no-aliases":
|
|
127
|
+
seed.aliases = false;
|
|
128
|
+
break;
|
|
129
|
+
case "--tint-floor":
|
|
130
|
+
seed.tintFloor = Number(value());
|
|
131
|
+
break;
|
|
132
|
+
case "--chroma":
|
|
133
|
+
seed.chroma = { ...seed.chroma, profile: value() };
|
|
134
|
+
break;
|
|
135
|
+
case "--chroma-strength":
|
|
136
|
+
seed.chroma = { ...seed.chroma, strength: Number(value()) };
|
|
137
|
+
break;
|
|
138
|
+
case "--chroma-peak":
|
|
139
|
+
seed.chroma = { ...seed.chroma, peakAt: Number(value()) };
|
|
140
|
+
break;
|
|
141
|
+
case "--hue-drift": {
|
|
142
|
+
const v = value();
|
|
143
|
+
seed.hueDrift = v === "none" || v === "natural" ? v : Number(v);
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
case "--pin": {
|
|
147
|
+
// family@step=colour
|
|
148
|
+
const m = /^([a-z][\w-]*)@(\d+)=(.+)$/.exec(value());
|
|
149
|
+
if (m)
|
|
150
|
+
seed.pins = { ...seed.pins, [m[1]]: { ...seed.pins?.[m[1]], [Number(m[2])]: m[3] } };
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
120
153
|
case "--shades":
|
|
121
154
|
seed.shades = value()
|
|
122
155
|
.split(",")
|
|
@@ -190,6 +223,13 @@ export function optionsFromSeed(seed) {
|
|
|
190
223
|
...(seed.backgrounds ? { backgrounds: seed.backgrounds } : {}),
|
|
191
224
|
seedShade: seed.seedShade,
|
|
192
225
|
...(Object.keys(seedShades).length ? { seedShades } : {}),
|
|
226
|
+
...(rangeOf(seed) ? { lightnessRange: rangeOf(seed) } : {}),
|
|
227
|
+
...(seed.tintFloor !== undefined ? { tintFloor: seed.tintFloor } : {}),
|
|
228
|
+
...(seed.chroma && Object.keys(seed.chroma).length ? { chroma: seed.chroma } : {}),
|
|
229
|
+
...(seed.hueDrift !== undefined && seed.hueDrift !== "none" ? { hueDrift: seed.hueDrift } : {}),
|
|
230
|
+
...(familiesOf(seed) ? { families: familiesOf(seed) } : {}),
|
|
231
|
+
...(seed.pins && Object.keys(seed.pins).length ? { pins: seed.pins } : {}),
|
|
232
|
+
...(seed.aliases === false ? { aliases: false } : {}),
|
|
193
233
|
...(decorative.length ? { decorative: decorative.sort() } : {}),
|
|
194
234
|
shades: seed.shades,
|
|
195
235
|
shadeOverrides: seed.shadeOverrides ?? {},
|
package/dist/studio/studio.d.ts
CHANGED
|
@@ -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;
|