@designtools/tokens 0.9.0 → 0.11.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 +25 -0
- package/README.md +144 -12
- package/dist/{chunk-P562LKFL.js → chunk-RQGC7LES.js} +632 -67
- package/dist/cli.js +189 -19
- package/dist/index.d.ts +230 -3
- package/dist/index.js +21 -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/seed.js +45 -1
- package/dist/studio/studio.js +41 -35
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -172,9 +172,45 @@ interface TokenSystem {
|
|
|
172
172
|
light: Record<string, string>;
|
|
173
173
|
dark: Record<string, string>;
|
|
174
174
|
};
|
|
175
|
+
/**
|
|
176
|
+
* Every token content needs, searched again against each ground it can sit on, per mode:
|
|
177
|
+
* the canvas and surface (today's values), the status tints and each named background.
|
|
178
|
+
* Emitted as `--on-<ground>-<token>`, and as a `[data-surface="<ground>"]` scope that points
|
|
179
|
+
* the everyday names (`--primary`, `--muted-foreground`) at them. See `grounds.ts`.
|
|
180
|
+
*/
|
|
181
|
+
grounds?: {
|
|
182
|
+
light: Record<string, GroundTokens>;
|
|
183
|
+
dark: Record<string, GroundTokens>;
|
|
184
|
+
};
|
|
175
185
|
/** The same system on wide-gamut ramps. Present only with `gamut: "p3"`. */
|
|
176
186
|
p3?: GamutTokens;
|
|
177
187
|
}
|
|
188
|
+
/** How much each ground carries: every token, the background and its text, or nothing */
|
|
189
|
+
type GroundsMode = "full" | "text" | "none";
|
|
190
|
+
/** Where a ground token comes from: a ramp step, black or white, or a colour given as it is */
|
|
191
|
+
type GroundRef = ForegroundRef | {
|
|
192
|
+
type: "value";
|
|
193
|
+
value: string;
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* One ground's tokens: a background content sits on, and everything content needs on it.
|
|
197
|
+
*
|
|
198
|
+
* Keys are the names the tokens take inside the ground, the page's own names: `canvas` and
|
|
199
|
+
* `canvas-foreground` are the ground and its text, then `muted`, `muted-foreground`, `border`,
|
|
200
|
+
* `input`, `ring`, and for every semantic colour its fill, `-foreground`, `-subdued`,
|
|
201
|
+
* `-subdued-foreground`, `-hover` and `-active`. A token keeps its page value wherever that
|
|
202
|
+
* still works on the ground; `changed` lists the ones that were searched again.
|
|
203
|
+
*/
|
|
204
|
+
interface GroundTokens {
|
|
205
|
+
/** `base` for the canvas and surface, `status` for a status tint, `background` for a named one */
|
|
206
|
+
kind: "base" | "status" | "background";
|
|
207
|
+
tokens: Record<string, string>;
|
|
208
|
+
_refs: Record<string, GroundRef>;
|
|
209
|
+
/** Tokens whose value differs from the page's in this mode */
|
|
210
|
+
changed: string[];
|
|
211
|
+
/** What the search could not reach, in words, for the report */
|
|
212
|
+
notes: string[];
|
|
213
|
+
}
|
|
178
214
|
/** Contrast algorithm choice */
|
|
179
215
|
type ContrastAlgorithm = "wcag" | "apca";
|
|
180
216
|
/** Contrast target level — controls minimum threshold for foreground selection */
|
|
@@ -218,6 +254,35 @@ type SemanticShadeOverrides = Record<string, {
|
|
|
218
254
|
light?: Partial<VariantShadeOverrides>;
|
|
219
255
|
dark?: Partial<VariantShadeOverrides>;
|
|
220
256
|
}>;
|
|
257
|
+
/**
|
|
258
|
+
* How colourful each step of a ramp is. `follow` (the default) eases from pale tints to the seed's
|
|
259
|
+
* chroma; `constant` holds the seed's chroma at every step, as far as the screen allows (Material's
|
|
260
|
+
* tonal palettes); `relative` keeps the seed's share of the most each step's lightness can hold;
|
|
261
|
+
* `peak` peaks at `peakAt` and falls away either side (Tailwind's shape).
|
|
262
|
+
*/
|
|
263
|
+
type ChromaProfile = "follow" | "constant" | "relative" | "peak";
|
|
264
|
+
/** Colourfulness: the profile, how strong (1 is the seed's own; it eases in beside the seed, which never moves), and where `peak` peaks. */
|
|
265
|
+
interface ChromaShape {
|
|
266
|
+
profile?: ChromaProfile;
|
|
267
|
+
strength?: number;
|
|
268
|
+
peakAt?: ShadeNumber;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* How the hue turns in the steps darker than the seed. `none` (the default) holds it; `natural` turns
|
|
272
|
+
* yellows towards amber and blues towards indigo, as Tailwind's darks do, and leaves other hues; a number
|
|
273
|
+
* is degrees at the deepest step, positive counter-clockwise.
|
|
274
|
+
*/
|
|
275
|
+
type HueDrift = "none" | "natural" | number;
|
|
276
|
+
/** One colour family leaning away from the system: each field replaces the system's for that family only. Lightness 0 to 1. */
|
|
277
|
+
interface FamilyShape {
|
|
278
|
+
lightnessRange?: {
|
|
279
|
+
light?: number;
|
|
280
|
+
dark?: number;
|
|
281
|
+
};
|
|
282
|
+
tintFloor?: number;
|
|
283
|
+
chroma?: ChromaShape;
|
|
284
|
+
hueDrift?: HueDrift;
|
|
285
|
+
}
|
|
221
286
|
/** Per-surface-token shade overrides */
|
|
222
287
|
interface SurfaceShadeOverrides {
|
|
223
288
|
canvas?: ShadeNumber | "white" | "black";
|
|
@@ -256,6 +321,44 @@ interface GenerationOptions {
|
|
|
256
321
|
* An alias pair (`destructive`/`red`) is one ramp, so naming either anchors both.
|
|
257
322
|
*/
|
|
258
323
|
seedShades?: Record<string, ShadeNumber>;
|
|
324
|
+
/**
|
|
325
|
+
* Where the colour ramps end, as OKLCH lightness from 0 to 1: `light` for the palest step (25),
|
|
326
|
+
* `dark` for the deepest (950). Default 0.98 and 0.15. A brand that only uses soft deep tones
|
|
327
|
+
* raises `dark`; the steps between are spread over the new range. The neutral keeps its own,
|
|
328
|
+
* because both modes' backgrounds are made from it. Adjacent dark steps keep a gap however high
|
|
329
|
+
* `dark` goes, so the ramp never collapses.
|
|
330
|
+
*/
|
|
331
|
+
lightnessRange?: {
|
|
332
|
+
light?: number;
|
|
333
|
+
dark?: number;
|
|
334
|
+
};
|
|
335
|
+
/**
|
|
336
|
+
* How much of the seed's colourfulness the pale steps keep, from 0 to 1. By default the steps
|
|
337
|
+
* above the seed fade towards grey; a tint floor of 0.6 keeps at least 60% of the seed's chroma
|
|
338
|
+
* in each, as far as a screen can show it. The neutral is left alone.
|
|
339
|
+
*/
|
|
340
|
+
tintFloor?: number;
|
|
341
|
+
/** How colourful the colour ramps are, step to step. The neutral is left alone. */
|
|
342
|
+
chroma?: ChromaShape;
|
|
343
|
+
/** How the colour ramps' hue turns in their darks. The neutral is left alone. */
|
|
344
|
+
hueDrift?: HueDrift;
|
|
345
|
+
/**
|
|
346
|
+
* A family leaning away from the system, by name (or its alias): `{ twilight: { chroma: { strength: 1.5 } } }`.
|
|
347
|
+
* The neutral takes the system's shape only from here.
|
|
348
|
+
*/
|
|
349
|
+
families?: Record<string, FamilyShape>;
|
|
350
|
+
/**
|
|
351
|
+
* Exact colours on given steps, by family: `{ camel: { 300: "#B7B7A3" } }`. The steps between the
|
|
352
|
+
* pin and the seed are refitted to pass through it. A pin that would put the ramp out of order, or that
|
|
353
|
+
* a screen can't show, is refused with the reason. A pin can't sit on the seed's own step.
|
|
354
|
+
*/
|
|
355
|
+
pins?: Record<string, Partial<Record<ShadeNumber, string>>>;
|
|
356
|
+
/**
|
|
357
|
+
* Whether the status ramps also get their everyday names: `green`, `red` and `yellow` as the same
|
|
358
|
+
* ramps as `success`, `destructive` and `warning`, so `bg-red-500` matches. Default true; false
|
|
359
|
+
* emits each ramp once, under its semantic name.
|
|
360
|
+
*/
|
|
361
|
+
aliases?: boolean;
|
|
259
362
|
/**
|
|
260
363
|
* Additional colours that get their ramp and nothing else: no `--<name>`,
|
|
261
364
|
* no `-foreground`, no `bg-<name>` semantic. An accent that may never be text
|
|
@@ -286,12 +389,20 @@ interface GenerationOptions {
|
|
|
286
389
|
/**
|
|
287
390
|
* More backgrounds a brand paints sections with, by name: `{ stone: { light: "#E8E8DB" } }`.
|
|
288
391
|
* Each becomes `--surface-<name>` with a measured `-foreground`; `dark` defaults to `light`.
|
|
289
|
-
* Every semantic colour is measured against each of them (see `pageContrast`)
|
|
392
|
+
* Every semantic colour is measured against each of them (see `pageContrast`), and each is a
|
|
393
|
+
* ground: content inside `data-surface="<name>"` gets its own searched tokens (see `grounds`).
|
|
394
|
+
* A name a ground or token already uses (`canvas`, `primary`, `warning-subdued`) is refused.
|
|
290
395
|
*/
|
|
291
396
|
backgrounds?: Record<string, {
|
|
292
397
|
light: string;
|
|
293
398
|
dark?: string;
|
|
294
399
|
}>;
|
|
400
|
+
/**
|
|
401
|
+
* How much a ground carries (see `grounds.ts`). `full` (default): every token, tinted to the
|
|
402
|
+
* ground and contrast-checked on it. `text`: the ground and its text only, so `data-surface`
|
|
403
|
+
* paints a section and everything else on it keeps the page's tokens. `none`: no grounds at all.
|
|
404
|
+
*/
|
|
405
|
+
grounds?: GroundsMode;
|
|
295
406
|
/**
|
|
296
407
|
* Which steps to emit. Default: all twelve (25–950).
|
|
297
408
|
* Tokens naming a dropped step are snapped to the nearest emitted one.
|
|
@@ -334,6 +445,21 @@ interface SavedConfig {
|
|
|
334
445
|
seedShade?: ShadeNumber;
|
|
335
446
|
/** Where the neutral seed lands. Default: 500 */
|
|
336
447
|
neutralSeedShade?: ShadeNumber;
|
|
448
|
+
/** Where the colour ramps end, as OKLCH lightness in percent: `{ "light": 97, "dark": 34 }`. */
|
|
449
|
+
lightnessRange?: {
|
|
450
|
+
light?: number;
|
|
451
|
+
dark?: number;
|
|
452
|
+
};
|
|
453
|
+
/** How much of the seed's colourfulness the pale steps keep, 0 to 1. */
|
|
454
|
+
tintFloor?: number;
|
|
455
|
+
chroma?: ChromaShape;
|
|
456
|
+
hueDrift?: HueDrift;
|
|
457
|
+
/** Families leaning away from the system; their lightness in percent, as above. */
|
|
458
|
+
families?: Record<string, FamilyShape>;
|
|
459
|
+
/** Exact colours on given steps, by family. */
|
|
460
|
+
pins?: Record<string, Partial<Record<ShadeNumber, string>>>;
|
|
461
|
+
/** false: no green, red and yellow beside success, destructive and warning. */
|
|
462
|
+
aliases?: boolean;
|
|
337
463
|
shades?: ShadeNumber[];
|
|
338
464
|
/** `seedShade` anchors that colour's own ramp. Default: 500 */
|
|
339
465
|
additionalColors: {
|
|
@@ -350,6 +476,7 @@ interface SavedConfig {
|
|
|
350
476
|
wcagFloor?: boolean;
|
|
351
477
|
surfaceColors?: GenerationOptions["surfaceColors"];
|
|
352
478
|
backgrounds?: GenerationOptions["backgrounds"];
|
|
479
|
+
grounds?: GroundsMode;
|
|
353
480
|
shadeOverrides: SemanticShadeOverrides;
|
|
354
481
|
surfaceShadeOverrides?: GenerationOptions["surfaceShadeOverrides"];
|
|
355
482
|
utilityShadeOverrides?: GenerationOptions["utilityShadeOverrides"];
|
|
@@ -394,6 +521,18 @@ interface ScaleOptions {
|
|
|
394
521
|
shades?: readonly ShadeNumber[];
|
|
395
522
|
/** Which display gamut every step must fit. Default: srgb */
|
|
396
523
|
gamut?: Gamut;
|
|
524
|
+
/** Lightness of the palest step's ceiling, 0 to 1. Default: 0.98 */
|
|
525
|
+
lightEnd?: number;
|
|
526
|
+
/** Lightness of the deepest step's floor, 0 to 1. Default: 0.15 */
|
|
527
|
+
darkEnd?: number;
|
|
528
|
+
/** Share of the seed's chroma every step above the seed keeps, 0 to 1. Default: none */
|
|
529
|
+
tintFloor?: number;
|
|
530
|
+
/** How colourful each step is. Default: follow */
|
|
531
|
+
chroma?: ChromaShape;
|
|
532
|
+
/** How the hue turns below the seed. Default: none */
|
|
533
|
+
hueDrift?: HueDrift;
|
|
534
|
+
/** Exact colours on given steps; the ramp is refitted through them. */
|
|
535
|
+
pins?: Partial<Record<ShadeNumber, string>>;
|
|
397
536
|
}
|
|
398
537
|
/**
|
|
399
538
|
* Print an OKLCH colour that a display of `gamut` shows exactly as written.
|
|
@@ -524,6 +663,12 @@ declare function familySeedShade(name: string, seedShade: ShadeNumber | undefine
|
|
|
524
663
|
*/
|
|
525
664
|
interface PaletteOptions extends ScaleOptions {
|
|
526
665
|
seedShades?: Record<string, ShadeNumber>;
|
|
666
|
+
/** Families leaning away from the system's shape, by name or alias. */
|
|
667
|
+
families?: Record<string, FamilyShape>;
|
|
668
|
+
/** Exact colours on given steps, by family name or alias. */
|
|
669
|
+
familyPins?: Record<string, Partial<Record<ShadeNumber, string>>>;
|
|
670
|
+
/** false: each status ramp once, under its semantic name only. */
|
|
671
|
+
aliases?: boolean;
|
|
527
672
|
}
|
|
528
673
|
declare function generatePrimitivePalette(brandColors: BrandColors, lightnessStrategy?: LightnessStrategy, options?: PaletteOptions): PrimitivePalette;
|
|
529
674
|
/**
|
|
@@ -720,6 +865,8 @@ declare function computeAccessibilityScore(tokens: SemanticTokens, algorithm: Co
|
|
|
720
865
|
* keeps the sRGB values, which are complete and contrast-checked on their own.
|
|
721
866
|
*/
|
|
722
867
|
declare const WIDE_GAMUT_QUERY = "@media (color-gamut: p3)";
|
|
868
|
+
/** The selector a ground's scope is emitted under */
|
|
869
|
+
declare const GROUND_SELECTOR: (ground: string) => string;
|
|
723
870
|
/**
|
|
724
871
|
* Export tokens as CSS custom properties
|
|
725
872
|
*/
|
|
@@ -734,7 +881,7 @@ declare function exportToCss(tokens: TokenSystem, colorFormat?: ColorFormat, sha
|
|
|
734
881
|
* Note there is no non-colour section: the TokenSystem carries spacing, type,
|
|
735
882
|
* radii and shadow defaults, but they are not yet serialised to CSS.
|
|
736
883
|
*/
|
|
737
|
-
declare const TOKEN_SECTIONS: readonly ["primitives", "ramp", "semantic", "surface", "utility"];
|
|
884
|
+
declare const TOKEN_SECTIONS: readonly ["primitives", "ramp", "semantic", "surface", "utility", "grounds"];
|
|
738
885
|
type TokenSection = (typeof TOKEN_SECTIONS)[number];
|
|
739
886
|
/**
|
|
740
887
|
* Export tokens as Tailwind v4 CSS.
|
|
@@ -916,6 +1063,13 @@ declare function provenanceComment(p: Provenance): string;
|
|
|
916
1063
|
declare function parseProvenance(text: string): Provenance | null;
|
|
917
1064
|
/** Attach provenance to a JSON document as a `$designtools` key */
|
|
918
1065
|
declare function withJsonProvenance(json: string, p: Provenance): string;
|
|
1066
|
+
/** A seed's lightness range (percent, as people write it) as the generator takes it (0 to 1), or nothing when unset. */
|
|
1067
|
+
declare function rangeOf(seed: SeedFile): {
|
|
1068
|
+
light?: number;
|
|
1069
|
+
dark?: number;
|
|
1070
|
+
} | undefined;
|
|
1071
|
+
/** A seed's families (lightness in percent) as the generator takes them (0 to 1), or nothing when none lean away. */
|
|
1072
|
+
declare function familiesOf(seed: SeedFile): GenerationOptions["families"] | undefined;
|
|
919
1073
|
|
|
920
1074
|
declare class APCAUnavailableError extends Error {
|
|
921
1075
|
constructor();
|
|
@@ -923,6 +1077,55 @@ declare class APCAUnavailableError extends Error {
|
|
|
923
1077
|
/** Whether apca-w3 is installed, so APCA contrast can be measured. */
|
|
924
1078
|
declare function isAPCAAvailable(): boolean;
|
|
925
1079
|
|
|
1080
|
+
/**
|
|
1081
|
+
* Grounds: every background content sits on, each with the tokens content needs on it.
|
|
1082
|
+
*
|
|
1083
|
+
* The page tokens are searched against the canvas, the surface and the overlay. Content also
|
|
1084
|
+
* sits on other backgrounds: a warning banner with a button in it, a brand-coloured band on a
|
|
1085
|
+
* marketing page with a caption and a call to action. There the page tokens were only measured,
|
|
1086
|
+
* never chosen: a primary button on a primary band is 1:1, a caption on a navy band 2.3:1.
|
|
1087
|
+
*
|
|
1088
|
+
* So each ground gets the page's tokens again, searched against it. A token keeps its page value
|
|
1089
|
+
* wherever that still works on the ground, so a pale banner changes little; anything that fails
|
|
1090
|
+
* is searched again by the same rules the page uses. Markup names the ground once
|
|
1091
|
+
* (`<section data-surface="brand">`) and every component inside reads the right values through
|
|
1092
|
+
* the everyday names, `bg-primary` and `text-muted-foreground`, with no change to the component.
|
|
1093
|
+
*
|
|
1094
|
+
* The grounds are the canvas and the surface (today's values, so a card inside a band can reset
|
|
1095
|
+
* to them), the status tints, and every named background. The surface and overlay tokens
|
|
1096
|
+
* themselves are not part of a ground: a card is still a card, on any band.
|
|
1097
|
+
*/
|
|
1098
|
+
|
|
1099
|
+
/** The status colours whose tints are grounds by default: a banner, an alert, an inline message */
|
|
1100
|
+
declare const STATUS_GROUNDS: readonly ["success", "warning", "destructive"];
|
|
1101
|
+
/** The non-colour tokens every ground carries, in the order they are emitted */
|
|
1102
|
+
declare const GROUND_BASE_TOKENS: readonly ["canvas", "canvas-foreground", "muted", "muted-foreground", "border", "input", "ring"];
|
|
1103
|
+
/** What each semantic colour carries inside a ground */
|
|
1104
|
+
declare const GROUND_COLOR_PARTS: readonly ["", "-foreground", "-subdued", "-subdued-foreground", "-hover", "-active"];
|
|
1105
|
+
interface View {
|
|
1106
|
+
palette: PrimitivePalette;
|
|
1107
|
+
gamut: Gamut;
|
|
1108
|
+
}
|
|
1109
|
+
/** Every token name a ground carries, for these semantic colours */
|
|
1110
|
+
declare function groundTokenNames(colors: readonly string[]): string[];
|
|
1111
|
+
/**
|
|
1112
|
+
* Names a `--background` cannot take: each ground is a `data-surface` value and the prefix of
|
|
1113
|
+
* `--on-<ground>-*`, and `--surface-<name>` sits beside the surface tokens. A band called
|
|
1114
|
+
* `primary` or `warning-subdued` would be two grounds under one name.
|
|
1115
|
+
*/
|
|
1116
|
+
declare function reservedGroundNames(colors: readonly string[]): string[];
|
|
1117
|
+
/**
|
|
1118
|
+
* Every ground's tokens for one mode.
|
|
1119
|
+
*
|
|
1120
|
+
* `views` is the palette the tokens resolve against, then any other gamut's: a pairing must
|
|
1121
|
+
* pass on every display the system is generated for.
|
|
1122
|
+
*/
|
|
1123
|
+
declare function generateGroundTokens(tiers: {
|
|
1124
|
+
semantic: Record<"light" | "dark", SemanticTokens>;
|
|
1125
|
+
surface: Record<"light" | "dark", SurfaceTokens>;
|
|
1126
|
+
utility: Record<"light" | "dark", UtilityTokens>;
|
|
1127
|
+
}, mode: "light" | "dark", views: readonly View[], options?: Partial<GenerationOptions>): Record<string, GroundTokens>;
|
|
1128
|
+
|
|
926
1129
|
/**
|
|
927
1130
|
* Where each colour can go: every semantic fill, status text tone and muted text measured
|
|
928
1131
|
* against every background a mode paints, with a verdict. Written beside the CSS with
|
|
@@ -954,4 +1157,28 @@ declare function usageReport(tokens: TokenSystem, target?: ContrastTarget): Usag
|
|
|
954
1157
|
/** Two-space JSON with a trailing newline, keys in the order built (already sorted) */
|
|
955
1158
|
declare function serialiseUsage(report: UsageReport): string;
|
|
956
1159
|
|
|
957
|
-
|
|
1160
|
+
/**
|
|
1161
|
+
* The step contract: a step number means the same in every colour. If 700 carries text on white in
|
|
1162
|
+
* one family, it should in all of them, so a designer can reach for "the 700" without checking. Lyft
|
|
1163
|
+
* built its colour system on this; hand-made ramps are where it breaks.
|
|
1164
|
+
*
|
|
1165
|
+
* This measures it rather than enforcing it: for each step, which colours carry text on white, and
|
|
1166
|
+
* on black (4.5:1), and which disagree with the rest. The neutral and the alias names (green for
|
|
1167
|
+
* success) are left out: one is grey by design, the others are the same ramp twice.
|
|
1168
|
+
*/
|
|
1169
|
+
|
|
1170
|
+
interface ContractBreak {
|
|
1171
|
+
step: ShadeNumber;
|
|
1172
|
+
/** What the step should promise: text on a white page, or on a black one. */
|
|
1173
|
+
role: "text on white" | "text on black";
|
|
1174
|
+
/** The colours where it holds. */
|
|
1175
|
+
holds: string[];
|
|
1176
|
+
/** The colours where it doesn't. */
|
|
1177
|
+
fails: string[];
|
|
1178
|
+
/** The odd ones out: whichever side has fewer colours (the failing side on a tie). */
|
|
1179
|
+
odd: string[];
|
|
1180
|
+
}
|
|
1181
|
+
/** Every step whose promise differs between colours, light to dark. Empty when every step means the same everywhere. */
|
|
1182
|
+
declare function stepContract(palette: PrimitivePalette): ContractBreak[];
|
|
1183
|
+
|
|
1184
|
+
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 GroundRef, type GroundTokens, type GroundsMode, type HueDrift, type LightnessStrategy, type MergeResult, type NamedBackground, type PageContrast, type PaletteOptions, type PrimitivePalette, type Provenance, SECTIONED_FORMATS, SHADE_PRESETS, STATUS_GROUNDS, type SavedConfig, type ScaleOptions, 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, checkRampChroma, checkSemanticContrast, checkSemanticContrastAPCA, checkSurfaceContrast, chromaShadeFor, classifyAPCALevel, computeAccessibilityScore, diffSlice, 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, oklchToHex, parseProvenance, parseToOklch, provenanceComment, rangeOf, readDeclarations, reanchorFactors, reservedGroundNames, resolveShades, seedFingerprint, selectTokenSections, serialiseUsage, simulateCVD, snapShade, stableStringify, stepContract, tokenFamilies, usageReport, withJsonProvenance };
|
package/dist/index.js
CHANGED
|
@@ -4,8 +4,12 @@ import {
|
|
|
4
4
|
DEFAULT_NEUTRAL_COLOR,
|
|
5
5
|
DEFAULT_SEED_SHADE,
|
|
6
6
|
GENERATOR_NAME,
|
|
7
|
+
GROUND_BASE_TOKENS,
|
|
8
|
+
GROUND_COLOR_PARTS,
|
|
9
|
+
GROUND_SELECTOR,
|
|
7
10
|
SECTIONED_FORMATS,
|
|
8
11
|
SHADE_PRESETS,
|
|
12
|
+
STATUS_GROUNDS,
|
|
9
13
|
TAILWIND_SHADES,
|
|
10
14
|
TOKEN_SECTIONS,
|
|
11
15
|
VALID_SHADES,
|
|
@@ -27,6 +31,7 @@ import {
|
|
|
27
31
|
exportToTailwindV4,
|
|
28
32
|
exportTokens,
|
|
29
33
|
externalReferences,
|
|
34
|
+
familiesOf,
|
|
30
35
|
familySeedShade,
|
|
31
36
|
findContrastingColorAPCA,
|
|
32
37
|
fingerprint,
|
|
@@ -35,6 +40,7 @@ import {
|
|
|
35
40
|
formatOklchInGamut,
|
|
36
41
|
generateColorScale,
|
|
37
42
|
generateColorScaleAPCA,
|
|
43
|
+
generateGroundTokens,
|
|
38
44
|
generatePrimitivePalette,
|
|
39
45
|
generateSemanticTokens,
|
|
40
46
|
generateSurfaceTokens,
|
|
@@ -45,6 +51,7 @@ import {
|
|
|
45
51
|
getOklchString,
|
|
46
52
|
getRelativeLuminance,
|
|
47
53
|
getShade,
|
|
54
|
+
groundTokenNames,
|
|
48
55
|
isAPCAAvailable,
|
|
49
56
|
isInGamut,
|
|
50
57
|
meetsWCAG_AA,
|
|
@@ -54,8 +61,10 @@ import {
|
|
|
54
61
|
parseProvenance,
|
|
55
62
|
parseToOklch,
|
|
56
63
|
provenanceComment,
|
|
64
|
+
rangeOf,
|
|
57
65
|
readDeclarations,
|
|
58
66
|
reanchorFactors,
|
|
67
|
+
reservedGroundNames,
|
|
59
68
|
resolveShades,
|
|
60
69
|
seedFingerprint,
|
|
61
70
|
selectTokenSections,
|
|
@@ -63,18 +72,23 @@ import {
|
|
|
63
72
|
simulateCVD,
|
|
64
73
|
snapShade,
|
|
65
74
|
stableStringify,
|
|
75
|
+
stepContract,
|
|
66
76
|
tokenFamilies,
|
|
67
77
|
usageReport,
|
|
68
78
|
withJsonProvenance
|
|
69
|
-
} from "./chunk-
|
|
79
|
+
} from "./chunk-RQGC7LES.js";
|
|
70
80
|
export {
|
|
71
81
|
ALIAS_PAIRS,
|
|
72
82
|
APCAUnavailableError,
|
|
73
83
|
DEFAULT_NEUTRAL_COLOR,
|
|
74
84
|
DEFAULT_SEED_SHADE,
|
|
75
85
|
GENERATOR_NAME,
|
|
86
|
+
GROUND_BASE_TOKENS,
|
|
87
|
+
GROUND_COLOR_PARTS,
|
|
88
|
+
GROUND_SELECTOR,
|
|
76
89
|
SECTIONED_FORMATS,
|
|
77
90
|
SHADE_PRESETS,
|
|
91
|
+
STATUS_GROUNDS,
|
|
78
92
|
TAILWIND_SHADES,
|
|
79
93
|
TOKEN_SECTIONS,
|
|
80
94
|
VALID_SHADES,
|
|
@@ -96,6 +110,7 @@ export {
|
|
|
96
110
|
exportToTailwindV4,
|
|
97
111
|
exportTokens,
|
|
98
112
|
externalReferences,
|
|
113
|
+
familiesOf,
|
|
99
114
|
familySeedShade,
|
|
100
115
|
findContrastingColorAPCA,
|
|
101
116
|
fingerprint,
|
|
@@ -104,6 +119,7 @@ export {
|
|
|
104
119
|
formatOklchInGamut,
|
|
105
120
|
generateColorScale,
|
|
106
121
|
generateColorScaleAPCA,
|
|
122
|
+
generateGroundTokens,
|
|
107
123
|
generatePrimitivePalette,
|
|
108
124
|
generateSemanticTokens,
|
|
109
125
|
generateSurfaceTokens,
|
|
@@ -114,6 +130,7 @@ export {
|
|
|
114
130
|
getOklchString,
|
|
115
131
|
getRelativeLuminance,
|
|
116
132
|
getShade,
|
|
133
|
+
groundTokenNames,
|
|
117
134
|
isAPCAAvailable,
|
|
118
135
|
isInGamut,
|
|
119
136
|
meetsWCAG_AA,
|
|
@@ -123,8 +140,10 @@ export {
|
|
|
123
140
|
parseProvenance,
|
|
124
141
|
parseToOklch,
|
|
125
142
|
provenanceComment,
|
|
143
|
+
rangeOf,
|
|
126
144
|
readDeclarations,
|
|
127
145
|
reanchorFactors,
|
|
146
|
+
reservedGroundNames,
|
|
128
147
|
resolveShades,
|
|
129
148
|
seedFingerprint,
|
|
130
149
|
selectTokenSections,
|
|
@@ -132,6 +151,7 @@ export {
|
|
|
132
151
|
simulateCVD,
|
|
133
152
|
snapShade,
|
|
134
153
|
stableStringify,
|
|
154
|
+
stepContract,
|
|
135
155
|
tokenFamilies,
|
|
136
156
|
usageReport,
|
|
137
157
|
withJsonProvenance
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a seed changes from the project's, in words, and a seed carried in a link. Plain functions,
|
|
3
|
+
* shared by the colour editor and the hand-back, and tested without a page.
|
|
4
|
+
*/
|
|
5
|
+
import type { SeedFile } from "@designtools/tokens";
|
|
6
|
+
/** What the seed changes from the project's, in words: "darkest 15% → 34%", "twilight colourfulness ×1.50". */
|
|
7
|
+
export declare function describeChanges(before: SeedFile, now: SeedFile): string[];
|
|
8
|
+
/** Where a link carries a seed: the page's hash, so nothing reaches the server. */
|
|
9
|
+
export declare const LINK_HASH = "designtools-colours";
|
|
10
|
+
export declare function seedFromHash(hash: string): SeedFile | null;
|
|
11
|
+
/** This page's address carrying a seed. */
|
|
12
|
+
export declare function linkFor(seed: SeedFile): string;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
const LIGHT_END = 98;
|
|
2
|
+
const DARK_END = 15;
|
|
3
|
+
/** What the seed changes from the project's, in words: "darkest 15% → 34%", "twilight colourfulness ×1.50". */
|
|
4
|
+
export function describeChanges(before, now) {
|
|
5
|
+
const out = [];
|
|
6
|
+
const pct = (v, d) => `${v ?? d}%`;
|
|
7
|
+
const same = (a, b) => JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
|
|
8
|
+
if (!same(before.primaryColor, now.primaryColor))
|
|
9
|
+
out.push(`primary ${before.primaryColor} → ${now.primaryColor}`);
|
|
10
|
+
if (!same(before.neutralColor, now.neutralColor))
|
|
11
|
+
out.push(`neutral ${before.neutralColor} → ${now.neutralColor}`);
|
|
12
|
+
if (!same(before.seedShade, now.seedShade))
|
|
13
|
+
out.push(`primary lands on ${now.seedShade ?? 500}`);
|
|
14
|
+
if (!same(before.neutralSeedShade, now.neutralSeedShade))
|
|
15
|
+
out.push(`neutral lands on ${now.neutralSeedShade ?? 500}`);
|
|
16
|
+
const was = new Map((before.additionalColors ?? []).map((c) => [c.name, c]));
|
|
17
|
+
const is = new Map((now.additionalColors ?? []).map((c) => [c.name, c]));
|
|
18
|
+
for (const [name, c] of is) {
|
|
19
|
+
const old = was.get(name);
|
|
20
|
+
if (!old)
|
|
21
|
+
out.push(`${name} ${c.color} added`);
|
|
22
|
+
else if (!same(old, c))
|
|
23
|
+
out.push(`${name} ${old.color === c.color ? `lands on ${c.seedShade ?? 500}` : `${old.color} → ${c.color}`}`);
|
|
24
|
+
}
|
|
25
|
+
for (const name of was.keys())
|
|
26
|
+
if (!is.has(name))
|
|
27
|
+
out.push(`${name} removed`);
|
|
28
|
+
for (const k of ["contrastAlgorithm", "contrastTarget", "lightnessStrategy", "foreground"]) {
|
|
29
|
+
if (!same(before[k], now[k]))
|
|
30
|
+
out.push(`${k.replace(/([A-Z])/g, " $1").toLowerCase()} ${now[k] ?? "default"}`);
|
|
31
|
+
}
|
|
32
|
+
if (!same(before.lightnessRange?.light, now.lightnessRange?.light))
|
|
33
|
+
out.push(`lightest ${pct(before.lightnessRange?.light, LIGHT_END)} → ${pct(now.lightnessRange?.light, LIGHT_END)}`);
|
|
34
|
+
if (!same(before.lightnessRange?.dark, now.lightnessRange?.dark))
|
|
35
|
+
out.push(`darkest ${pct(before.lightnessRange?.dark, DARK_END)} → ${pct(now.lightnessRange?.dark, DARK_END)}`);
|
|
36
|
+
if (!same(before.tintFloor, now.tintFloor))
|
|
37
|
+
out.push(`tint floor ${Math.round((now.tintFloor ?? 0) * 100)}%`);
|
|
38
|
+
if (!same(before.chroma, now.chroma))
|
|
39
|
+
out.push(`colourfulness ${now.chroma?.profile ?? "follow"}${now.chroma?.strength && now.chroma.strength !== 1 ? ` ×${now.chroma.strength.toFixed(2)}` : ""}`);
|
|
40
|
+
if (!same(before.hueDrift, now.hueDrift))
|
|
41
|
+
out.push(`hue in the darks ${typeof now.hueDrift === "number" ? `turns ${now.hueDrift}°` : (now.hueDrift ?? "holds")}`);
|
|
42
|
+
const names = new Set([...Object.keys(before.families ?? {}), ...Object.keys(now.families ?? {})]);
|
|
43
|
+
const WORDS = { lightnessRange: "range", tintFloor: "tint floor", chroma: "colourfulness", hueDrift: "hue in the darks" };
|
|
44
|
+
for (const name of names) {
|
|
45
|
+
if (same(before.families?.[name], now.families?.[name]))
|
|
46
|
+
continue;
|
|
47
|
+
const own = now.families?.[name];
|
|
48
|
+
out.push(own ? `${name} ramp's own ${Object.keys(own).map((k) => WORDS[k] ?? k).join(", ")}` : `${name} ramp matches all ramps again`);
|
|
49
|
+
}
|
|
50
|
+
const pinned = new Set([...Object.keys(before.pins ?? {}), ...Object.keys(now.pins ?? {})]);
|
|
51
|
+
for (const name of pinned) {
|
|
52
|
+
const a = before.pins?.[name] ?? {};
|
|
53
|
+
const b = now.pins?.[name] ?? {};
|
|
54
|
+
for (const step of new Set([...Object.keys(a), ...Object.keys(b)])) {
|
|
55
|
+
const x = a[step];
|
|
56
|
+
const y = b[step];
|
|
57
|
+
if (x !== y)
|
|
58
|
+
out.push(y ? `${name} ${step} set to ${y}` : `${name} ${step} back to the generated colour`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const roles = new Set([...Object.keys(before.shadeOverrides ?? {}), ...Object.keys(now.shadeOverrides ?? {})]);
|
|
62
|
+
for (const name of roles) {
|
|
63
|
+
for (const mode of ["light", "dark"]) {
|
|
64
|
+
const a = before.shadeOverrides?.[name]?.[mode] ?? {};
|
|
65
|
+
const b = now.shadeOverrides?.[name]?.[mode] ?? {};
|
|
66
|
+
for (const role of new Set([...Object.keys(a), ...Object.keys(b)])) {
|
|
67
|
+
const x = a[role];
|
|
68
|
+
const y = b[role];
|
|
69
|
+
const what = role === "DEFAULT" ? "fill" : role;
|
|
70
|
+
if (x !== y)
|
|
71
|
+
out.push(y !== undefined ? `${name} ${what} on ${y} in ${mode}` : `${name} ${what} back to the generator's choice in ${mode}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
/** Where a link carries a seed: the page's hash, so nothing reaches the server. */
|
|
78
|
+
export const LINK_HASH = "designtools-colours";
|
|
79
|
+
export function seedFromHash(hash) {
|
|
80
|
+
const m = new RegExp(`${LINK_HASH}=([^&]+)`).exec(hash);
|
|
81
|
+
if (!m)
|
|
82
|
+
return null;
|
|
83
|
+
try {
|
|
84
|
+
const bytes = Uint8Array.from(atob(m[1].replace(/-/g, "+").replace(/_/g, "/")), (c) => c.charCodeAt(0));
|
|
85
|
+
const json = new TextDecoder().decode(bytes);
|
|
86
|
+
const seed = JSON.parse(json);
|
|
87
|
+
return seed && typeof seed === "object" ? seed : null;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** This page's address carrying a seed. */
|
|
94
|
+
export function linkFor(seed) {
|
|
95
|
+
const bytes = new TextEncoder().encode(JSON.stringify(seed));
|
|
96
|
+
const packed = btoa(String.fromCharCode(...bytes)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
97
|
+
return `${location.origin}${location.pathname}#${LINK_HASH}=${packed}`;
|
|
98
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy text from a click. The clipboard API exists only on secure pages (https, localhost), so a
|
|
3
|
+
* dev server opened by its network address on a phone has none; there, and wherever the API
|
|
4
|
+
* refuses, copy the old way, from a hidden selection. Start it in the click itself: browsers only
|
|
5
|
+
* copy inside the gesture, and iOS only from an editable selection.
|
|
6
|
+
*/
|
|
7
|
+
export declare function copyText(text: string): Promise<void>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy text from a click. The clipboard API exists only on secure pages (https, localhost), so a
|
|
3
|
+
* dev server opened by its network address on a phone has none; there, and wherever the API
|
|
4
|
+
* refuses, copy the old way, from a hidden selection. Start it in the click itself: browsers only
|
|
5
|
+
* copy inside the gesture, and iOS only from an editable selection.
|
|
6
|
+
*/
|
|
7
|
+
export async function copyText(text) {
|
|
8
|
+
if (typeof navigator !== "undefined" && navigator.clipboard && window.isSecureContext) {
|
|
9
|
+
try {
|
|
10
|
+
await navigator.clipboard.writeText(text);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
// refused: try the old way below
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const area = document.createElement("textarea");
|
|
18
|
+
area.value = text;
|
|
19
|
+
area.contentEditable = "true";
|
|
20
|
+
area.style.cssText = "position:fixed;top:0;left:0;width:1px;height:1px;opacity:0;pointer-events:none;font-size:16px";
|
|
21
|
+
document.body.appendChild(area);
|
|
22
|
+
const range = document.createRange();
|
|
23
|
+
range.selectNodeContents(area);
|
|
24
|
+
const selection = window.getSelection();
|
|
25
|
+
selection?.removeAllRanges();
|
|
26
|
+
selection?.addRange(range);
|
|
27
|
+
area.setSelectionRange(0, text.length);
|
|
28
|
+
const copied = document.execCommand("copy");
|
|
29
|
+
area.remove();
|
|
30
|
+
selection?.removeAllRanges();
|
|
31
|
+
if (!copied)
|
|
32
|
+
throw new Error("The browser refused to copy");
|
|
33
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The colour editor's controls, each an input to the generator, never a colour written by hand
|
|
3
|
+
* (pins aside, the one control that takes a colour): the shape of the ramps for the whole system and
|
|
4
|
+
* for one family, pins, the step contract, a ramp before and after, what changed, a link carrying the
|
|
5
|
+
* settings, and saved versions.
|
|
6
|
+
*/
|
|
7
|
+
import { type SeedFile, type ShadeNumber, type TokenSystem } from "@designtools/tokens";
|
|
8
|
+
export type Edit = {
|
|
9
|
+
seed: SeedFile;
|
|
10
|
+
set: (patch: Partial<SeedFile>) => void;
|
|
11
|
+
system: TokenSystem | null;
|
|
12
|
+
/** The project's own system, from its seed: what "before" means. */
|
|
13
|
+
base: TokenSystem | null;
|
|
14
|
+
baseSeed: SeedFile;
|
|
15
|
+
/** Why the current settings can't be generated (a refused pin), if they can't. */
|
|
16
|
+
error: string | null;
|
|
17
|
+
};
|
|
18
|
+
/** A full-width action in a popover: big enough to hit on a phone. */
|
|
19
|
+
export declare const ACTION = "inline-flex h-8 shrink-0 cursor-pointer items-center justify-center gap-1.5 self-start rounded-md bg-muted px-3 text-[12px] font-medium text-ink transition-colors hover:bg-scrim disabled:cursor-not-allowed disabled:opacity-40 outline-none focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-sel";
|
|
20
|
+
/** What a control means, on hover or focus, instead of a paragraph under it. */
|
|
21
|
+
export declare function Hint({ text }: {
|
|
22
|
+
text: string;
|
|
23
|
+
}): import("react").JSX.Element;
|
|
24
|
+
declare const title: (s: string) => string;
|
|
25
|
+
/** Every colour ramp's shape, for the whole system. */
|
|
26
|
+
export declare function SystemShape({ edit }: {
|
|
27
|
+
edit: Edit;
|
|
28
|
+
}): import("react").JSX.Element;
|
|
29
|
+
/** One family's shape: the system's, until it leans away; every difference is listed in the settings. */
|
|
30
|
+
export declare function FamilyShapeControls({ family, edit }: {
|
|
31
|
+
family: string;
|
|
32
|
+
edit: Edit;
|
|
33
|
+
}): import("react").JSX.Element;
|
|
34
|
+
/** Exact colours on given steps of one family; the ramp bends through them. */
|
|
35
|
+
export declare function Pins({ family, anchor, edit }: {
|
|
36
|
+
family: string;
|
|
37
|
+
anchor: ShadeNumber;
|
|
38
|
+
edit: Edit;
|
|
39
|
+
}): import("react").JSX.Element;
|
|
40
|
+
/** One family's ramp now, over the project's own, to see what moved. */
|
|
41
|
+
export declare function Compare({ family, edit }: {
|
|
42
|
+
family: string;
|
|
43
|
+
edit: Edit;
|
|
44
|
+
}): import("react").JSX.Element | null;
|
|
45
|
+
/** The changes, listed, so drift is visible: every family that leans away shows here. */
|
|
46
|
+
export declare function Changes({ edit }: {
|
|
47
|
+
edit: Edit;
|
|
48
|
+
}): import("react").JSX.Element | null;
|
|
49
|
+
/** Named versions of the settings, kept in this browser, to compare before handing one back. */
|
|
50
|
+
export declare function Versions({ edit }: {
|
|
51
|
+
edit: Edit;
|
|
52
|
+
}): import("react").JSX.Element;
|
|
53
|
+
export { title };
|
|
54
|
+
export { describeChanges, seedFromHash } from "./changes.js";
|