@designtools/tokens 0.4.0 → 0.5.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 +85 -0
- package/README.md +84 -15
- package/dist/{chunk-MCLZSLHE.js → chunk-D6675UF5.js} +242 -129
- package/dist/cli.js +140 -46
- package/dist/index.d.ts +197 -20
- package/dist/index.js +13 -1
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -79,6 +79,20 @@ interface UtilityTokens {
|
|
|
79
79
|
input: string;
|
|
80
80
|
shadow: string;
|
|
81
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* The colour tiers of a token system, resolved against one gamut's ramps.
|
|
84
|
+
*
|
|
85
|
+
* Carried on `TokenSystem.p3` when generated with `gamut: "p3"`. Every token
|
|
86
|
+
* reads the same step as its sRGB counterpart, because the foreground search
|
|
87
|
+
* scores each candidate on both gamuts and keeps the worse; only the colours
|
|
88
|
+
* differ, where a wide-gamut display can show more chroma than sRGB holds.
|
|
89
|
+
*/
|
|
90
|
+
interface GamutTokens {
|
|
91
|
+
primitives: TokenSystem["primitives"];
|
|
92
|
+
semantic: TokenSystem["semantic"];
|
|
93
|
+
surface: TokenSystem["surface"];
|
|
94
|
+
utility: TokenSystem["utility"];
|
|
95
|
+
}
|
|
82
96
|
interface TokenSystem {
|
|
83
97
|
primitives: {
|
|
84
98
|
black: string;
|
|
@@ -110,6 +124,8 @@ interface TokenSystem {
|
|
|
110
124
|
light: Record<string, string>;
|
|
111
125
|
dark: Record<string, string>;
|
|
112
126
|
};
|
|
127
|
+
/** The same system on wide-gamut ramps. Present only with `gamut: "p3"`. */
|
|
128
|
+
p3?: GamutTokens;
|
|
113
129
|
}
|
|
114
130
|
/** Contrast algorithm choice */
|
|
115
131
|
type ContrastAlgorithm = "wcag" | "apca";
|
|
@@ -117,6 +133,14 @@ type ContrastAlgorithm = "wcag" | "apca";
|
|
|
117
133
|
type ContrastTarget = "aa-large" | "aa" | "aaa";
|
|
118
134
|
/** Lightness distribution strategy */
|
|
119
135
|
type LightnessStrategy = "fixed" | "perceptual";
|
|
136
|
+
/**
|
|
137
|
+
* A display gamut: the set of colours a screen can actually show.
|
|
138
|
+
*
|
|
139
|
+
* OKLCH can describe colours outside every screen's gamut, so a colour is only
|
|
140
|
+
* meaningful to measure or emit once it is known which gamut it is shown in.
|
|
141
|
+
* `srgb` is every screen; `p3` is the wide gamut of most phones and Macs.
|
|
142
|
+
*/
|
|
143
|
+
type Gamut = "srgb" | "p3";
|
|
120
144
|
/** Valid shade numbers in a ColorScale */
|
|
121
145
|
declare const VALID_SHADES: readonly [25, 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
|
|
122
146
|
type ShadeNumber = (typeof VALID_SHADES)[number];
|
|
@@ -170,11 +194,22 @@ interface GenerationOptions {
|
|
|
170
194
|
contrastTarget: ContrastTarget;
|
|
171
195
|
lightnessStrategy: LightnessStrategy;
|
|
172
196
|
/**
|
|
173
|
-
* Which step the seed
|
|
197
|
+
* Which step the primary seed lands on. Default: 500.
|
|
174
198
|
* Brand colours arrive as whatever they are — deep navies and pale tints are
|
|
175
199
|
* common — and forcing them all onto 500 wrecks the ramp either side.
|
|
200
|
+
*
|
|
201
|
+
* Primary only. Before 0.5.0 this moved every family, so a pale brand colour
|
|
202
|
+
* anchored at 200 dragged the neutral and the status colours to 200 with it.
|
|
203
|
+
* A pale brand does not imply a pale grey; anchor other families with
|
|
204
|
+
* `seedShades`.
|
|
176
205
|
*/
|
|
177
206
|
seedShade?: ShadeNumber;
|
|
207
|
+
/**
|
|
208
|
+
* Where other families' seeds land, by family name: `neutral`, an additional
|
|
209
|
+
* colour, or a status colour you supplied. A family not named sits on 500.
|
|
210
|
+
* An alias pair (`destructive`/`red`) is one ramp, so naming either anchors both.
|
|
211
|
+
*/
|
|
212
|
+
seedShades?: Record<string, ShadeNumber>;
|
|
178
213
|
/**
|
|
179
214
|
* Which steps to emit. Default: all twelve (25–950).
|
|
180
215
|
* Tokens naming a dropped step are snapped to the nearest emitted one.
|
|
@@ -189,6 +224,13 @@ interface GenerationOptions {
|
|
|
189
224
|
light?: Partial<UtilityShadeOverrides>;
|
|
190
225
|
dark?: Partial<UtilityShadeOverrides>;
|
|
191
226
|
};
|
|
227
|
+
/**
|
|
228
|
+
* Which displays to generate for. Default: `srgb`, every colour showable on
|
|
229
|
+
* every screen. `p3` additionally generates wide-gamut ramps for displays
|
|
230
|
+
* that can show them, carried on `TokenSystem.p3`, and chooses every
|
|
231
|
+
* foreground so it passes on both.
|
|
232
|
+
*/
|
|
233
|
+
gamut?: Gamut;
|
|
192
234
|
}
|
|
193
235
|
/** APCA contrast result for a single pairing */
|
|
194
236
|
interface APCAContrastResult {
|
|
@@ -208,10 +250,14 @@ interface SavedConfig {
|
|
|
208
250
|
primaryColor: string;
|
|
209
251
|
neutralColor: string;
|
|
210
252
|
seedShade?: ShadeNumber;
|
|
253
|
+
/** Where the neutral seed lands. Default: 500 */
|
|
254
|
+
neutralSeedShade?: ShadeNumber;
|
|
211
255
|
shades?: ShadeNumber[];
|
|
256
|
+
/** `seedShade` anchors that colour's own ramp. Default: 500 */
|
|
212
257
|
additionalColors: {
|
|
213
258
|
name: string;
|
|
214
259
|
color: string;
|
|
260
|
+
seedShade?: ShadeNumber;
|
|
215
261
|
}[];
|
|
216
262
|
colorFormat: ColorFormat;
|
|
217
263
|
contrastAlgorithm: ContrastAlgorithm;
|
|
@@ -220,6 +266,7 @@ interface SavedConfig {
|
|
|
220
266
|
shadeOverrides: SemanticShadeOverrides;
|
|
221
267
|
surfaceShadeOverrides?: GenerationOptions["surfaceShadeOverrides"];
|
|
222
268
|
utilityShadeOverrides?: GenerationOptions["utilityShadeOverrides"];
|
|
269
|
+
gamut?: Gamut;
|
|
223
270
|
}
|
|
224
271
|
|
|
225
272
|
/**
|
|
@@ -237,12 +284,19 @@ declare function generateTokens(brandColors: BrandColors, options?: Partial<Gene
|
|
|
237
284
|
* OKLCH provides perceptually uniform color manipulation
|
|
238
285
|
*/
|
|
239
286
|
|
|
287
|
+
/** Whether a colour can be shown exactly as written on a display of this gamut */
|
|
288
|
+
declare function isInGamut(color: string, gamut?: Gamut): boolean;
|
|
240
289
|
/**
|
|
241
290
|
* Convert any color format to OKLCH
|
|
242
291
|
*/
|
|
243
292
|
declare function parseToOklch(color: string): Oklch;
|
|
244
293
|
/**
|
|
245
|
-
* Convert OKLCH to hex
|
|
294
|
+
* Convert OKLCH to hex.
|
|
295
|
+
*
|
|
296
|
+
* Hex can only hold sRGB, so an out-of-gamut colour is gamut-mapped first rather
|
|
297
|
+
* than clipped channel by channel, which shifts hue and lightness. The derived
|
|
298
|
+
* status colours are built at a fixed hue and come through here, so clipping
|
|
299
|
+
* would move them off the hue they were built on.
|
|
246
300
|
*/
|
|
247
301
|
declare function oklchToHex(color: Oklch): string;
|
|
248
302
|
/** Per-shade options shared by both lightness strategies */
|
|
@@ -251,7 +305,27 @@ interface ScaleOptions {
|
|
|
251
305
|
seedShade?: ShadeNumber;
|
|
252
306
|
/** Which steps to emit. Default: all twelve */
|
|
253
307
|
shades?: readonly ShadeNumber[];
|
|
308
|
+
/** Which display gamut every step must fit. Default: srgb */
|
|
309
|
+
gamut?: Gamut;
|
|
254
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* Print an OKLCH colour that a display of `gamut` shows exactly as written.
|
|
313
|
+
*
|
|
314
|
+
* Ramps hold the seed's chroma, eased, from one end to the other, but a screen
|
|
315
|
+
* can show very little chroma near white and near black, so a saturated seed
|
|
316
|
+
* went out of gamut at both ends of its own ramp. The CSS then carried values
|
|
317
|
+
* no browser renders as written, and contrast was measured on colours nobody
|
|
318
|
+
* saw. Chroma is now capped at the most the gamut holds at that lightness and
|
|
319
|
+
* hue, so the value in the file is the colour on the page.
|
|
320
|
+
*
|
|
321
|
+
* Lightness and hue are never moved: the cap only lowers chroma, which keeps a
|
|
322
|
+
* step on its place in the ramp and on the seed's hue. The cap is taken at the
|
|
323
|
+
* printed lightness and hue, and rounded down, because rounding a colour on the
|
|
324
|
+
* gamut boundary to four places can land it just outside.
|
|
325
|
+
*
|
|
326
|
+
* A colour already in gamut after rounding prints exactly as it always did.
|
|
327
|
+
*/
|
|
328
|
+
declare function formatOklchInGamut(lightness: number, chroma: number, hue: number, gamut?: Gamut): string;
|
|
255
329
|
declare function generateColorScale(baseColor: string, options?: ScaleOptions): ColorScale;
|
|
256
330
|
declare function generateColorScaleAPCA(baseColor: string, options?: ScaleOptions): ColorScale;
|
|
257
331
|
/**
|
|
@@ -264,13 +338,13 @@ declare function adjustLightness(color: string, lightness: number): string;
|
|
|
264
338
|
declare function adjustChroma(color: string, chroma: number): string;
|
|
265
339
|
/**
|
|
266
340
|
* Get the relative luminance of a color (for contrast calculations)
|
|
267
|
-
* Using WCAG formula
|
|
341
|
+
* Using WCAG formula, on the colour as a display of `gamut` shows it.
|
|
268
342
|
*/
|
|
269
|
-
declare function getRelativeLuminance(color: string): number;
|
|
343
|
+
declare function getRelativeLuminance(color: string, gamut?: Gamut): number;
|
|
270
344
|
/**
|
|
271
345
|
* Calculate contrast ratio between two colors (WCAG formula)
|
|
272
346
|
*/
|
|
273
|
-
declare function getContrastRatio(color1: string, color2: string): number;
|
|
347
|
+
declare function getContrastRatio(color1: string, color2: string, gamut?: Gamut): number;
|
|
274
348
|
/**
|
|
275
349
|
* Check if contrast ratio meets WCAG AA standard
|
|
276
350
|
*/
|
|
@@ -281,9 +355,10 @@ declare function meetsWCAG_AA(ratio: number, isLargeText?: boolean): boolean;
|
|
|
281
355
|
declare function meetsWCAG_AAA(ratio: number, isLargeText?: boolean): boolean;
|
|
282
356
|
/**
|
|
283
357
|
* Calculate APCA contrast (Lc value) between foreground and background.
|
|
284
|
-
* Returns the absolute Lc value
|
|
358
|
+
* Returns the absolute Lc value, measured on the colours as a display of
|
|
359
|
+
* `gamut` shows them.
|
|
285
360
|
*/
|
|
286
|
-
declare function getAPCAContrast(foreground: string, background: string): number;
|
|
361
|
+
declare function getAPCAContrast(foreground: string, background: string, gamut?: Gamut): number;
|
|
287
362
|
/**
|
|
288
363
|
* Find contrasting color using APCA algorithm.
|
|
289
364
|
* Targets Lc >= 60 for body text readability.
|
|
@@ -308,7 +383,11 @@ declare function formatColorShort(color: string, format: ColorFormat): string;
|
|
|
308
383
|
*/
|
|
309
384
|
declare function getOklchString(color: string): string;
|
|
310
385
|
/**
|
|
311
|
-
* Convert a color to the specified format
|
|
386
|
+
* Convert a color to the specified format.
|
|
387
|
+
*
|
|
388
|
+
* hex, rgb and hsl can only hold sRGB, so they print the gamut-mapped colour —
|
|
389
|
+
* the one a browser would paint and the one the contrast checks measured.
|
|
390
|
+
* oklch prints the value as given.
|
|
312
391
|
*/
|
|
313
392
|
declare function formatColorAs(color: string, format: ColorFormat): string;
|
|
314
393
|
|
|
@@ -336,12 +415,30 @@ declare const DEFAULT_NEUTRAL_COLOR = "#747474";
|
|
|
336
415
|
declare const ALIAS_PAIRS: readonly (readonly [semantic: string, alias: string])[];
|
|
337
416
|
/** The other name for a scale, if it has one */
|
|
338
417
|
declare function aliasOf(name: string): string | undefined;
|
|
418
|
+
/**
|
|
419
|
+
* Where a family's seed is anchored.
|
|
420
|
+
*
|
|
421
|
+
* `seedShade` is the primary's; every other family is looked up in `seedShades`
|
|
422
|
+
* by its own name or its alias, and sits on 500 when not named. The derived
|
|
423
|
+
* status colours are built at mid lightness, so 500 is where they belong unless
|
|
424
|
+
* someone supplies their own.
|
|
425
|
+
*
|
|
426
|
+
* Returns undefined for "the default", which every consumer reads as 500.
|
|
427
|
+
*/
|
|
428
|
+
declare function familySeedShade(name: string, seedShade: ShadeNumber | undefined, seedShades: Record<string, ShadeNumber> | undefined): ShadeNumber | undefined;
|
|
339
429
|
/**
|
|
340
430
|
* Generate a complete primitive palette from brand colors
|
|
341
431
|
* Requires primary and neutral - other semantic colors are derived from primary
|
|
342
432
|
* Additional colors can be provided to generate custom scales
|
|
343
433
|
*/
|
|
344
|
-
|
|
434
|
+
/**
|
|
435
|
+
* Options for a whole palette. `seedShade` anchors the primary only; other
|
|
436
|
+
* families are anchored through `seedShades` (see familySeedShade).
|
|
437
|
+
*/
|
|
438
|
+
interface PaletteOptions extends ScaleOptions {
|
|
439
|
+
seedShades?: Record<string, ShadeNumber>;
|
|
440
|
+
}
|
|
441
|
+
declare function generatePrimitivePalette(brandColors: BrandColors, lightnessStrategy?: LightnessStrategy, options?: PaletteOptions): PrimitivePalette;
|
|
345
442
|
/**
|
|
346
443
|
* Get a specific shade from a color scale
|
|
347
444
|
*/
|
|
@@ -363,7 +460,15 @@ declare function getShade(palette: PrimitivePalette, colorName: string, shade: k
|
|
|
363
460
|
*/
|
|
364
461
|
/** One custom-property declaration, located by the block it sits in */
|
|
365
462
|
interface Declaration {
|
|
366
|
-
/**
|
|
463
|
+
/**
|
|
464
|
+
* Normalised selector of the enclosing block, prefixed by any enclosing
|
|
465
|
+
* at-rules: `@media (prefers-color-scheme: dark) > :root:not(...)`.
|
|
466
|
+
*
|
|
467
|
+
* The whole path, not just the innermost selector, because two blocks can
|
|
468
|
+
* share a selector: the wide-gamut layer is a `:root` inside
|
|
469
|
+
* `@media (color-gamut: p3)`, and keyed on `:root` alone its declarations
|
|
470
|
+
* would be merged into the sRGB primitives.
|
|
471
|
+
*/
|
|
367
472
|
block: string;
|
|
368
473
|
property: string;
|
|
369
474
|
value: string;
|
|
@@ -412,11 +517,27 @@ declare function diffSlice(target: string, slice: string): SliceDiff;
|
|
|
412
517
|
* Maps primitive colors to meaningful semantic roles
|
|
413
518
|
*/
|
|
414
519
|
|
|
520
|
+
/**
|
|
521
|
+
* Which gamut a palette was built for, and optionally a second gamut's palette
|
|
522
|
+
* whose displays every foreground must also pass on.
|
|
523
|
+
*/
|
|
524
|
+
interface SemanticGamuts {
|
|
525
|
+
own: Gamut;
|
|
526
|
+
other?: {
|
|
527
|
+
gamut: Gamut;
|
|
528
|
+
palette: PrimitivePalette;
|
|
529
|
+
};
|
|
530
|
+
}
|
|
415
531
|
/**
|
|
416
532
|
* Generate semantic tokens for a specific mode
|
|
417
533
|
* Supports additional custom colors beyond the core semantic colors
|
|
534
|
+
*
|
|
535
|
+
* With `gamut: "p3"` this runs once per gamut, each run handed the other's
|
|
536
|
+
* palette: the tokens resolve against `palette`, and every foreground is chosen
|
|
537
|
+
* to pass on both. The worse of two contrasts does not depend on which run is
|
|
538
|
+
* asking, so both pick the same steps.
|
|
418
539
|
*/
|
|
419
|
-
declare function generateSemanticTokens(palette: PrimitivePalette, mode: "light" | "dark", options?: Partial<GenerationOptions
|
|
540
|
+
declare function generateSemanticTokens(palette: PrimitivePalette, mode: "light" | "dark", options?: Partial<GenerationOptions>, gamuts?: SemanticGamuts): SemanticTokens;
|
|
420
541
|
/**
|
|
421
542
|
* Generate surface tokens (canvas / surface / overlay depth system) from neutral palette
|
|
422
543
|
*/
|
|
@@ -426,17 +547,56 @@ declare function generateSurfaceTokens(palette: PrimitivePalette, mode: "light"
|
|
|
426
547
|
*/
|
|
427
548
|
declare function generateUtilityTokens(palette: PrimitivePalette, mode: "light" | "dark", overrides?: Partial<UtilityShadeOverrides>, shades?: readonly ShadeNumber[], seedShade?: ShadeNumber): UtilityTokens;
|
|
428
549
|
/**
|
|
429
|
-
* Check contrast compliance for all semantic colors
|
|
550
|
+
* Check contrast compliance for all semantic colors, as a display of `gamut`
|
|
551
|
+
* shows them. Pass `TokenSystem.p3.semantic` with `"p3"` to check wide-gamut output.
|
|
430
552
|
*/
|
|
431
|
-
declare function checkSemanticContrast(tokens: SemanticTokens): Record<string, {
|
|
553
|
+
declare function checkSemanticContrast(tokens: SemanticTokens, gamut?: Gamut): Record<string, {
|
|
432
554
|
ratio: number;
|
|
433
555
|
passesAA: boolean;
|
|
434
556
|
passesAAA: boolean;
|
|
435
557
|
}>;
|
|
436
558
|
/**
|
|
437
|
-
* Check APCA contrast compliance for all semantic colors
|
|
559
|
+
* Check APCA contrast compliance for all semantic colors, as a display of
|
|
560
|
+
* `gamut` shows them.
|
|
438
561
|
*/
|
|
439
|
-
declare function checkSemanticContrastAPCA(tokens: SemanticTokens): Record<string, APCAContrastResult>;
|
|
562
|
+
declare function checkSemanticContrastAPCA(tokens: SemanticTokens, gamut?: Gamut): Record<string, APCAContrastResult>;
|
|
563
|
+
/**
|
|
564
|
+
* Contrast for the pairings the semantic check never looked at.
|
|
565
|
+
*
|
|
566
|
+
* `checkSemanticContrast` covers the extended families and `muted`. That leaves
|
|
567
|
+
* the ground a page is actually painted on — canvas, surface, overlay — and the
|
|
568
|
+
* focus ring, unmeasured. The ground is the thing projects most often override,
|
|
569
|
+
* and an unreadable focus ring is an accessibility defect that no other check
|
|
570
|
+
* here would have reported.
|
|
571
|
+
*
|
|
572
|
+
* Ring and border are measured against the canvas, since that is what they have
|
|
573
|
+
* to be visible against.
|
|
574
|
+
*/
|
|
575
|
+
interface SurfaceContrastResult extends WCAGContrastResult {
|
|
576
|
+
/**
|
|
577
|
+
* Whether this pairing is a non-text UI component, which WCAG 1.4.11 holds to
|
|
578
|
+
* 3:1 rather than the 4.5:1 body-text bar. Judging a focus ring against the
|
|
579
|
+
* text threshold reports a conforming ring as failing, which is its own way of
|
|
580
|
+
* making a report worth ignoring.
|
|
581
|
+
*/
|
|
582
|
+
nonText: boolean;
|
|
583
|
+
/** Passes the threshold that actually applies to this pairing */
|
|
584
|
+
passes: boolean;
|
|
585
|
+
/**
|
|
586
|
+
* Reported without a verdict, because whether it needs one depends on use.
|
|
587
|
+
* A border drawn round a card is decoration; the same token round a text
|
|
588
|
+
* input is the control's boundary and owes 3:1. The generator cannot tell
|
|
589
|
+
* which from here, and a fail mark on the decorative case is how a report
|
|
590
|
+
* teaches people to skip it.
|
|
591
|
+
*/
|
|
592
|
+
advisory: boolean;
|
|
593
|
+
}
|
|
594
|
+
declare function checkSurfaceContrast(surface: SurfaceTokens, utility: UtilityTokens, gamut?: Gamut): Record<string, SurfaceContrastResult>;
|
|
595
|
+
declare function checkRampChroma(palette: PrimitivePalette): Record<string, {
|
|
596
|
+
peak: number;
|
|
597
|
+
atShade: ShadeNumber;
|
|
598
|
+
low: boolean;
|
|
599
|
+
}>;
|
|
440
600
|
/**
|
|
441
601
|
* Compute an overall accessibility score for the token system.
|
|
442
602
|
*
|
|
@@ -447,8 +607,11 @@ declare function checkSemanticContrastAPCA(tokens: SemanticTokens): Record<strin
|
|
|
447
607
|
*
|
|
448
608
|
* Surface and utility pairings are reported separately and are not counted, so
|
|
449
609
|
* the number stays comparable with what earlier versions produced.
|
|
610
|
+
*
|
|
611
|
+
* `gamut` is the display the tokens are measured on; score `TokenSystem.p3`
|
|
612
|
+
* with `"p3"`.
|
|
450
613
|
*/
|
|
451
|
-
declare function computeAccessibilityScore(tokens: SemanticTokens, algorithm: ContrastAlgorithm, contrastTarget?: ContrastTarget): {
|
|
614
|
+
declare function computeAccessibilityScore(tokens: SemanticTokens, algorithm: ContrastAlgorithm, contrastTarget?: ContrastTarget, gamut?: Gamut): {
|
|
452
615
|
score: number;
|
|
453
616
|
passed: number;
|
|
454
617
|
total: number;
|
|
@@ -459,10 +622,17 @@ declare function computeAccessibilityScore(tokens: SemanticTokens, algorithm: Co
|
|
|
459
622
|
* Converts token system to CSS variables, Tailwind config, etc.
|
|
460
623
|
*/
|
|
461
624
|
|
|
625
|
+
/**
|
|
626
|
+
* The media query the wide-gamut layer sits under.
|
|
627
|
+
*
|
|
628
|
+
* Matches displays that can show P3. Every other display ignores the block and
|
|
629
|
+
* keeps the sRGB values, which are complete and contrast-checked on their own.
|
|
630
|
+
*/
|
|
631
|
+
declare const WIDE_GAMUT_QUERY = "@media (color-gamut: p3)";
|
|
462
632
|
/**
|
|
463
633
|
* Export tokens as CSS custom properties
|
|
464
634
|
*/
|
|
465
|
-
declare function exportToCss(tokens: TokenSystem, colorFormat?: ColorFormat, shadeOverrides?: SemanticShadeOverrides, sections?: TokenSection[], shades?: readonly ShadeNumber[], families?: readonly string[], seedShade?: ShadeNumber): string;
|
|
635
|
+
declare function exportToCss(tokens: TokenSystem, colorFormat?: ColorFormat, shadeOverrides?: SemanticShadeOverrides, sections?: TokenSection[], shades?: readonly ShadeNumber[], families?: readonly string[], seedShade?: ShadeNumber, seedShades?: Record<string, ShadeNumber>): string;
|
|
466
636
|
/**
|
|
467
637
|
* Emittable slices of the token system.
|
|
468
638
|
*
|
|
@@ -484,7 +654,7 @@ type TokenSection = (typeof TOKEN_SECTIONS)[number];
|
|
|
484
654
|
* emits once to :root and cannot vary by selector, so they are var()
|
|
485
655
|
* indirections registered in @theme and re-bound in each mode block.
|
|
486
656
|
*/
|
|
487
|
-
declare function exportToTailwindV4(tokens: TokenSystem, colorFormat?: ColorFormat, shadeOverrides?: SemanticShadeOverrides, replacePalette?: boolean, sections?: TokenSection[], shades?: readonly ShadeNumber[], families?: readonly string[], seedShade?: ShadeNumber): string;
|
|
657
|
+
declare function exportToTailwindV4(tokens: TokenSystem, colorFormat?: ColorFormat, shadeOverrides?: SemanticShadeOverrides, replacePalette?: boolean, sections?: TokenSection[], shades?: readonly ShadeNumber[], families?: readonly string[], seedShade?: ShadeNumber, seedShades?: Record<string, ShadeNumber>): string;
|
|
488
658
|
/**
|
|
489
659
|
* Export tokens as Tailwind v3 config
|
|
490
660
|
*/
|
|
@@ -526,8 +696,11 @@ interface ExportOptions {
|
|
|
526
696
|
* Which step the seed was anchored on. The semantic bridge is expressed as
|
|
527
697
|
* offsets from it, so an exporter that does not know the anchor emits
|
|
528
698
|
* semantics pointing at the wrong steps — see `bridge.ts`. Default: 500.
|
|
699
|
+
* The primary's anchor; other families take theirs from `seedShades`.
|
|
529
700
|
*/
|
|
530
701
|
seedShade?: ShadeNumber;
|
|
702
|
+
/** Other families' anchors, as passed to generateTokens. Default: 500 each */
|
|
703
|
+
seedShades?: Record<string, ShadeNumber>;
|
|
531
704
|
}
|
|
532
705
|
/** Formats whose structure lets a section filter be applied meaningfully */
|
|
533
706
|
declare const SECTIONED_FORMATS: ExportFormat[];
|
|
@@ -547,7 +720,11 @@ declare function externalReferences(css: string): string[];
|
|
|
547
720
|
* Colour only: the spacing, typography, radii and shadow tiers are carried
|
|
548
721
|
* through untouched when the full system is requested, and dropped otherwise.
|
|
549
722
|
*/
|
|
550
|
-
|
|
723
|
+
/** A TokenSystem narrowed by section or family, wide-gamut tiers included */
|
|
724
|
+
type SelectedTokens = Partial<Omit<TokenSystem, "p3">> & {
|
|
725
|
+
p3?: Partial<GamutTokens>;
|
|
726
|
+
};
|
|
727
|
+
declare function selectTokenSections(tokens: TokenSystem, sections?: TokenSection[], families?: readonly string[]): SelectedTokens;
|
|
551
728
|
/**
|
|
552
729
|
* Export tokens in the specified format
|
|
553
730
|
*/
|
|
@@ -649,4 +826,4 @@ declare function parseProvenance(text: string): Provenance | null;
|
|
|
649
826
|
/** Attach provenance to a JSON document as a `$designtools` key */
|
|
650
827
|
declare function withJsonProvenance(json: string, p: Provenance): string;
|
|
651
828
|
|
|
652
|
-
export { ALIAS_PAIRS, type APCAContrastResult, type BrandColors, type CVDType, type ColorFormat, type ColorScale, type ContrastAlgorithm, type ContrastTarget, DEFAULT_NEUTRAL_COLOR, DEFAULT_SEED_SHADE, type Declaration, type ExportFormat, type ExportOptions, type ExtendedSemanticColor, type ForegroundRef, GENERATOR_NAME, type GenerationOptions, type LightnessStrategy, type MergeResult, type PrimitivePalette, type Provenance, SECTIONED_FORMATS, SHADE_PRESETS, type SavedConfig, type ScaleOptions, type SeedFile, type SemanticColorPair, type SemanticShadeOverrides, type SemanticTokens, type ShadeNumber, type SliceDiff, type SurfaceRef, type SurfaceShadeOverrides, type SurfaceTokens, TAILWIND_SHADES, TOKEN_SECTIONS, type TokenSection, type TokenSystem, type UtilityShadeOverrides, type UtilityTokens, VALID_SHADES, type VariantShadeOverrides, type WCAGContrastResult, adjustChroma, adjustLightness, aliasOf, checkSemanticContrast, checkSemanticContrastAPCA, chromaShadeFor, classifyAPCALevel, computeAccessibilityScore, diffSlice, exportToCss, exportToDtcg, exportToTailwindV3, exportToTailwindV4, exportTokens, externalReferences, findContrastingColorAPCA, fingerprint, formatColorAs, formatColorShort, generateColorScale, generateColorScaleAPCA, generatePrimitivePalette, generateSemanticTokens, generateSurfaceTokens, generateTokens, generateUtilityTokens, getAPCAContrast, getContrastRatio, getOklchString, getRelativeLuminance, getShade, meetsWCAG_AA, meetsWCAG_AAA, mergeSlice, oklchToHex, parseProvenance, parseToOklch, provenanceComment, readDeclarations, reanchorFactors, resolveShades, seedFingerprint, selectTokenSections, simulateCVD, snapShade, stableStringify, tokenFamilies, withJsonProvenance };
|
|
829
|
+
export { ALIAS_PAIRS, type APCAContrastResult, type BrandColors, type CVDType, type ColorFormat, type ColorScale, type ContrastAlgorithm, type ContrastTarget, DEFAULT_NEUTRAL_COLOR, DEFAULT_SEED_SHADE, type Declaration, type ExportFormat, type ExportOptions, type ExtendedSemanticColor, type ForegroundRef, GENERATOR_NAME, type Gamut, type GamutTokens, type GenerationOptions, type LightnessStrategy, type MergeResult, type PaletteOptions, type PrimitivePalette, type Provenance, SECTIONED_FORMATS, SHADE_PRESETS, 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 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, familySeedShade, findContrastingColorAPCA, fingerprint, formatColorAs, formatColorShort, formatOklchInGamut, generateColorScale, generateColorScaleAPCA, generatePrimitivePalette, generateSemanticTokens, generateSurfaceTokens, generateTokens, generateUtilityTokens, getAPCAContrast, getContrastRatio, getOklchString, getRelativeLuminance, getShade, isInGamut, meetsWCAG_AA, meetsWCAG_AAA, mergeSlice, oklchToHex, parseProvenance, parseToOklch, provenanceComment, readDeclarations, reanchorFactors, resolveShades, seedFingerprint, selectTokenSections, simulateCVD, snapShade, stableStringify, tokenFamilies, withJsonProvenance };
|
package/dist/index.js
CHANGED
|
@@ -8,11 +8,14 @@ import {
|
|
|
8
8
|
TAILWIND_SHADES,
|
|
9
9
|
TOKEN_SECTIONS,
|
|
10
10
|
VALID_SHADES,
|
|
11
|
+
WIDE_GAMUT_QUERY,
|
|
11
12
|
adjustChroma,
|
|
12
13
|
adjustLightness,
|
|
13
14
|
aliasOf,
|
|
15
|
+
checkRampChroma,
|
|
14
16
|
checkSemanticContrast,
|
|
15
17
|
checkSemanticContrastAPCA,
|
|
18
|
+
checkSurfaceContrast,
|
|
16
19
|
chromaShadeFor,
|
|
17
20
|
classifyAPCALevel,
|
|
18
21
|
computeAccessibilityScore,
|
|
@@ -23,10 +26,12 @@ import {
|
|
|
23
26
|
exportToTailwindV4,
|
|
24
27
|
exportTokens,
|
|
25
28
|
externalReferences,
|
|
29
|
+
familySeedShade,
|
|
26
30
|
findContrastingColorAPCA,
|
|
27
31
|
fingerprint,
|
|
28
32
|
formatColorAs,
|
|
29
33
|
formatColorShort,
|
|
34
|
+
formatOklchInGamut,
|
|
30
35
|
generateColorScale,
|
|
31
36
|
generateColorScaleAPCA,
|
|
32
37
|
generatePrimitivePalette,
|
|
@@ -39,6 +44,7 @@ import {
|
|
|
39
44
|
getOklchString,
|
|
40
45
|
getRelativeLuminance,
|
|
41
46
|
getShade,
|
|
47
|
+
isInGamut,
|
|
42
48
|
meetsWCAG_AA,
|
|
43
49
|
meetsWCAG_AAA,
|
|
44
50
|
mergeSlice,
|
|
@@ -56,7 +62,7 @@ import {
|
|
|
56
62
|
stableStringify,
|
|
57
63
|
tokenFamilies,
|
|
58
64
|
withJsonProvenance
|
|
59
|
-
} from "./chunk-
|
|
65
|
+
} from "./chunk-D6675UF5.js";
|
|
60
66
|
export {
|
|
61
67
|
ALIAS_PAIRS,
|
|
62
68
|
DEFAULT_NEUTRAL_COLOR,
|
|
@@ -67,11 +73,14 @@ export {
|
|
|
67
73
|
TAILWIND_SHADES,
|
|
68
74
|
TOKEN_SECTIONS,
|
|
69
75
|
VALID_SHADES,
|
|
76
|
+
WIDE_GAMUT_QUERY,
|
|
70
77
|
adjustChroma,
|
|
71
78
|
adjustLightness,
|
|
72
79
|
aliasOf,
|
|
80
|
+
checkRampChroma,
|
|
73
81
|
checkSemanticContrast,
|
|
74
82
|
checkSemanticContrastAPCA,
|
|
83
|
+
checkSurfaceContrast,
|
|
75
84
|
chromaShadeFor,
|
|
76
85
|
classifyAPCALevel,
|
|
77
86
|
computeAccessibilityScore,
|
|
@@ -82,10 +91,12 @@ export {
|
|
|
82
91
|
exportToTailwindV4,
|
|
83
92
|
exportTokens,
|
|
84
93
|
externalReferences,
|
|
94
|
+
familySeedShade,
|
|
85
95
|
findContrastingColorAPCA,
|
|
86
96
|
fingerprint,
|
|
87
97
|
formatColorAs,
|
|
88
98
|
formatColorShort,
|
|
99
|
+
formatOklchInGamut,
|
|
89
100
|
generateColorScale,
|
|
90
101
|
generateColorScaleAPCA,
|
|
91
102
|
generatePrimitivePalette,
|
|
@@ -98,6 +109,7 @@ export {
|
|
|
98
109
|
getOklchString,
|
|
99
110
|
getRelativeLuminance,
|
|
100
111
|
getShade,
|
|
112
|
+
isInGamut,
|
|
101
113
|
meetsWCAG_AA,
|
|
102
114
|
meetsWCAG_AAA,
|
|
103
115
|
mergeSlice,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@designtools/tokens",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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": "CC-BY-NC-4.0",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
24
|
"dist",
|
|
25
|
-
"README.md"
|
|
25
|
+
"README.md",
|
|
26
|
+
"CHANGELOG.md"
|
|
26
27
|
],
|
|
27
28
|
"engines": {
|
|
28
29
|
"node": ">=18"
|