@designtools/tokens 0.3.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/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 colour lands on. Default: 500.
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
 
@@ -325,27 +404,140 @@ type PrimitivePalette = {
325
404
  * Default neutral color - a balanced gray
326
405
  */
327
406
  declare const DEFAULT_NEUTRAL_COLOR = "#747474";
407
+ /**
408
+ * Scales that carry two names for the same colour: the semantic one the
409
+ * token layer reads, and a friendly alias so `bg-red-500` works.
410
+ *
411
+ * They are one object, not a derivation — overriding either name has to move
412
+ * both, or `bg-red-500` and `bg-destructive-500` silently become different
413
+ * colours.
414
+ */
415
+ declare const ALIAS_PAIRS: readonly (readonly [semantic: string, alias: string])[];
416
+ /** The other name for a scale, if it has one */
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;
328
429
  /**
329
430
  * Generate a complete primitive palette from brand colors
330
431
  * Requires primary and neutral - other semantic colors are derived from primary
331
432
  * Additional colors can be provided to generate custom scales
332
433
  */
333
- declare function generatePrimitivePalette(brandColors: BrandColors, lightnessStrategy?: LightnessStrategy, scaleOptions?: ScaleOptions): PrimitivePalette;
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;
334
442
  /**
335
443
  * Get a specific shade from a color scale
336
444
  */
337
445
  declare function getShade(palette: PrimitivePalette, colorName: string, shade: keyof ColorScale): string;
338
446
 
447
+ /**
448
+ * Merging a generated slice into an existing token file.
449
+ *
450
+ * A colour family is not one contiguous block: its ramp sits in `:root` and its
451
+ * semantic tokens repeat in the light block, the dark block and the
452
+ * prefers-color-scheme fallback. Regenerating "the reds" therefore means
453
+ * rewriting declarations in four places at once, which is exactly the kind of
454
+ * edit a caller splicing text by hand gets wrong — most often by missing the
455
+ * media-query copy, leaving system-dark on the old colour.
456
+ *
457
+ * So the tool does it. Every line the slice does not mention is preserved byte
458
+ * for byte, which is what makes it safe to run against a file with
459
+ * hand-authored regions in it.
460
+ */
461
+ /** One custom-property declaration, located by the block it sits in */
462
+ interface Declaration {
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
+ */
472
+ block: string;
473
+ property: string;
474
+ value: string;
475
+ }
476
+ /** Every declaration in a stylesheet, in order */
477
+ declare function readDeclarations(css: string): Declaration[];
478
+ interface MergeResult {
479
+ css: string;
480
+ /** Declarations whose value the merge changed */
481
+ updated: Declaration[];
482
+ /** Declarations the slice defines that the target did not have */
483
+ added: Declaration[];
484
+ /** Declarations already matching, left alone */
485
+ unchanged: Declaration[];
486
+ /** Blocks the slice needs that the target does not contain */
487
+ missingBlocks: string[];
488
+ }
489
+ /**
490
+ * Rewrite the declarations a slice defines, leaving every other line intact.
491
+ *
492
+ * New declarations are appended to the end of their block, so adding a colour
493
+ * lands beside the existing ones rather than at the top of the file.
494
+ */
495
+ declare function mergeSlice(target: string, slice: string): MergeResult;
496
+ interface SliceDiff {
497
+ matches: boolean;
498
+ differing: {
499
+ block: string;
500
+ property: string;
501
+ expected: string;
502
+ actual: string;
503
+ }[];
504
+ missing: Declaration[];
505
+ }
506
+ /**
507
+ * Compare a slice against a target without writing.
508
+ *
509
+ * Only declarations the slice defines are considered, so hand-edited regions
510
+ * elsewhere in the file do not register as drift — which is the whole point of
511
+ * checking a part-generated file.
512
+ */
513
+ declare function diffSlice(target: string, slice: string): SliceDiff;
514
+
339
515
  /**
340
516
  * Semantic token generation
341
517
  * Maps primitive colors to meaningful semantic roles
342
518
  */
343
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
+ }
344
531
  /**
345
532
  * Generate semantic tokens for a specific mode
346
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.
347
539
  */
348
- declare function generateSemanticTokens(palette: PrimitivePalette, mode: "light" | "dark", options?: Partial<GenerationOptions>): SemanticTokens;
540
+ declare function generateSemanticTokens(palette: PrimitivePalette, mode: "light" | "dark", options?: Partial<GenerationOptions>, gamuts?: SemanticGamuts): SemanticTokens;
349
541
  /**
350
542
  * Generate surface tokens (canvas / surface / overlay depth system) from neutral palette
351
543
  */
@@ -353,25 +545,73 @@ declare function generateSurfaceTokens(palette: PrimitivePalette, mode: "light"
353
545
  /**
354
546
  * Generate utility tokens for borders, rings, inputs, shadow
355
547
  */
356
- declare function generateUtilityTokens(palette: PrimitivePalette, mode: "light" | "dark", overrides?: Partial<UtilityShadeOverrides>, shades?: readonly ShadeNumber[]): UtilityTokens;
548
+ declare function generateUtilityTokens(palette: PrimitivePalette, mode: "light" | "dark", overrides?: Partial<UtilityShadeOverrides>, shades?: readonly ShadeNumber[], seedShade?: ShadeNumber): UtilityTokens;
357
549
  /**
358
- * 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.
359
552
  */
360
- declare function checkSemanticContrast(tokens: SemanticTokens): Record<string, {
553
+ declare function checkSemanticContrast(tokens: SemanticTokens, gamut?: Gamut): Record<string, {
361
554
  ratio: number;
362
555
  passesAA: boolean;
363
556
  passesAAA: boolean;
364
557
  }>;
365
558
  /**
366
- * 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.
367
561
  */
368
- 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
+ }>;
369
600
  /**
370
601
  * Compute an overall accessibility score for the token system.
371
- * Only counts pairings that are shown in the semantic preview
372
- * (excludes neutral, muted). Simple pass/fail counting.
602
+ *
603
+ * Counts every extended-family pairing and excludes `muted` alone. Neutral is
604
+ * deliberately included: it is the pairing most likely to fail on a default
605
+ * seed, and a score that quietly dropped it would flatter the palette exactly
606
+ * where a reader most needs the warning.
607
+ *
608
+ * Surface and utility pairings are reported separately and are not counted, so
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"`.
373
613
  */
374
- declare function computeAccessibilityScore(tokens: SemanticTokens, algorithm: ContrastAlgorithm, contrastTarget?: ContrastTarget): {
614
+ declare function computeAccessibilityScore(tokens: SemanticTokens, algorithm: ContrastAlgorithm, contrastTarget?: ContrastTarget, gamut?: Gamut): {
375
615
  score: number;
376
616
  passed: number;
377
617
  total: number;
@@ -382,10 +622,17 @@ declare function computeAccessibilityScore(tokens: SemanticTokens, algorithm: Co
382
622
  * Converts token system to CSS variables, Tailwind config, etc.
383
623
  */
384
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)";
385
632
  /**
386
633
  * Export tokens as CSS custom properties
387
634
  */
388
- declare function exportToCss(tokens: TokenSystem, colorFormat?: ColorFormat, shadeOverrides?: SemanticShadeOverrides, sections?: TokenSection[], shades?: readonly 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;
389
636
  /**
390
637
  * Emittable slices of the token system.
391
638
  *
@@ -407,7 +654,7 @@ type TokenSection = (typeof TOKEN_SECTIONS)[number];
407
654
  * emits once to :root and cannot vary by selector, so they are var()
408
655
  * indirections registered in @theme and re-bound in each mode block.
409
656
  */
410
- declare function exportToTailwindV4(tokens: TokenSystem, colorFormat?: ColorFormat, shadeOverrides?: SemanticShadeOverrides, replacePalette?: boolean, sections?: TokenSection[], shades?: readonly 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;
411
658
  /**
412
659
  * Export tokens as Tailwind v3 config
413
660
  */
@@ -439,16 +686,45 @@ interface ExportOptions {
439
686
  * snapped onto this set, so a dropped step never leaves a dangling var().
440
687
  */
441
688
  shades?: readonly ShadeNumber[];
689
+ /**
690
+ * Restrict output to these colour families — a family being one colour plus
691
+ * everything computed against it. Used to regenerate part of a token file
692
+ * without rewriting regions a human has edited.
693
+ */
694
+ families?: readonly string[];
695
+ /**
696
+ * Which step the seed was anchored on. The semantic bridge is expressed as
697
+ * offsets from it, so an exporter that does not know the anchor emits
698
+ * semantics pointing at the wrong steps — see `bridge.ts`. Default: 500.
699
+ * The primary's anchor; other families take theirs from `seedShades`.
700
+ */
701
+ seedShade?: ShadeNumber;
702
+ /** Other families' anchors, as passed to generateTokens. Default: 500 each */
703
+ seedShades?: Record<string, ShadeNumber>;
442
704
  }
443
705
  /** Formats whose structure lets a section filter be applied meaningfully */
444
706
  declare const SECTIONED_FORMATS: ExportFormat[];
707
+ /** Every colour family name a token system carries, ramps and aliases alike */
708
+ declare function tokenFamilies(tokens: TokenSystem): string[];
709
+ /**
710
+ * Custom properties a chunk of generated CSS reads but does not itself define.
711
+ *
712
+ * A family-scoped slice is not self-contained — a foreground search can land on
713
+ * a neutral shade or on black — so a caller splicing one needs to know which
714
+ * tokens have to already exist in the target.
715
+ */
716
+ declare function externalReferences(css: string): string[];
445
717
  /**
446
718
  * Narrow a TokenSystem to the requested sections, for the `json` output.
447
719
  *
448
720
  * Colour only: the spacing, typography, radii and shadow tiers are carried
449
721
  * through untouched when the full system is requested, and dropped otherwise.
450
722
  */
451
- declare function selectTokenSections(tokens: TokenSystem, sections?: TokenSection[]): Partial<TokenSystem>;
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;
452
728
  /**
453
729
  * Export tokens in the specified format
454
730
  */
@@ -550,4 +826,4 @@ declare function parseProvenance(text: string): Provenance | null;
550
826
  /** Attach provenance to a JSON document as a `$designtools` key */
551
827
  declare function withJsonProvenance(json: string, p: Provenance): string;
552
828
 
553
- export { type APCAContrastResult, type BrandColors, type CVDType, type ColorFormat, type ColorScale, type ContrastAlgorithm, type ContrastTarget, DEFAULT_NEUTRAL_COLOR, DEFAULT_SEED_SHADE, type ExportFormat, type ExportOptions, type ExtendedSemanticColor, type ForegroundRef, GENERATOR_NAME, type GenerationOptions, type LightnessStrategy, type PrimitivePalette, type Provenance, SECTIONED_FORMATS, SHADE_PRESETS, type SavedConfig, type ScaleOptions, type SeedFile, type SemanticColorPair, type SemanticShadeOverrides, type SemanticTokens, type ShadeNumber, 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, checkSemanticContrast, checkSemanticContrastAPCA, chromaShadeFor, classifyAPCALevel, computeAccessibilityScore, exportToCss, exportToDtcg, exportToTailwindV3, exportToTailwindV4, exportTokens, findContrastingColorAPCA, fingerprint, formatColorAs, formatColorShort, generateColorScale, generateColorScaleAPCA, generatePrimitivePalette, generateSemanticTokens, generateSurfaceTokens, generateTokens, generateUtilityTokens, getAPCAContrast, getContrastRatio, getOklchString, getRelativeLuminance, getShade, meetsWCAG_AA, meetsWCAG_AAA, oklchToHex, parseProvenance, parseToOklch, provenanceComment, reanchorFactors, resolveShades, seedFingerprint, selectTokenSections, simulateCVD, snapShade, stableStringify, 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
@@ -1,4 +1,5 @@
1
1
  import {
2
+ ALIAS_PAIRS,
2
3
  DEFAULT_NEUTRAL_COLOR,
3
4
  DEFAULT_SEED_SHADE,
4
5
  GENERATOR_NAME,
@@ -7,22 +8,30 @@ import {
7
8
  TAILWIND_SHADES,
8
9
  TOKEN_SECTIONS,
9
10
  VALID_SHADES,
11
+ WIDE_GAMUT_QUERY,
10
12
  adjustChroma,
11
13
  adjustLightness,
14
+ aliasOf,
15
+ checkRampChroma,
12
16
  checkSemanticContrast,
13
17
  checkSemanticContrastAPCA,
18
+ checkSurfaceContrast,
14
19
  chromaShadeFor,
15
20
  classifyAPCALevel,
16
21
  computeAccessibilityScore,
22
+ diffSlice,
17
23
  exportToCss,
18
24
  exportToDtcg,
19
25
  exportToTailwindV3,
20
26
  exportToTailwindV4,
21
27
  exportTokens,
28
+ externalReferences,
29
+ familySeedShade,
22
30
  findContrastingColorAPCA,
23
31
  fingerprint,
24
32
  formatColorAs,
25
33
  formatColorShort,
34
+ formatOklchInGamut,
26
35
  generateColorScale,
27
36
  generateColorScaleAPCA,
28
37
  generatePrimitivePalette,
@@ -35,12 +44,15 @@ import {
35
44
  getOklchString,
36
45
  getRelativeLuminance,
37
46
  getShade,
47
+ isInGamut,
38
48
  meetsWCAG_AA,
39
49
  meetsWCAG_AAA,
50
+ mergeSlice,
40
51
  oklchToHex,
41
52
  parseProvenance,
42
53
  parseToOklch,
43
54
  provenanceComment,
55
+ readDeclarations,
44
56
  reanchorFactors,
45
57
  resolveShades,
46
58
  seedFingerprint,
@@ -48,9 +60,11 @@ import {
48
60
  simulateCVD,
49
61
  snapShade,
50
62
  stableStringify,
63
+ tokenFamilies,
51
64
  withJsonProvenance
52
- } from "./chunk-3OG7U5V2.js";
65
+ } from "./chunk-D6675UF5.js";
53
66
  export {
67
+ ALIAS_PAIRS,
54
68
  DEFAULT_NEUTRAL_COLOR,
55
69
  DEFAULT_SEED_SHADE,
56
70
  GENERATOR_NAME,
@@ -59,22 +73,30 @@ export {
59
73
  TAILWIND_SHADES,
60
74
  TOKEN_SECTIONS,
61
75
  VALID_SHADES,
76
+ WIDE_GAMUT_QUERY,
62
77
  adjustChroma,
63
78
  adjustLightness,
79
+ aliasOf,
80
+ checkRampChroma,
64
81
  checkSemanticContrast,
65
82
  checkSemanticContrastAPCA,
83
+ checkSurfaceContrast,
66
84
  chromaShadeFor,
67
85
  classifyAPCALevel,
68
86
  computeAccessibilityScore,
87
+ diffSlice,
69
88
  exportToCss,
70
89
  exportToDtcg,
71
90
  exportToTailwindV3,
72
91
  exportToTailwindV4,
73
92
  exportTokens,
93
+ externalReferences,
94
+ familySeedShade,
74
95
  findContrastingColorAPCA,
75
96
  fingerprint,
76
97
  formatColorAs,
77
98
  formatColorShort,
99
+ formatOklchInGamut,
78
100
  generateColorScale,
79
101
  generateColorScaleAPCA,
80
102
  generatePrimitivePalette,
@@ -87,12 +109,15 @@ export {
87
109
  getOklchString,
88
110
  getRelativeLuminance,
89
111
  getShade,
112
+ isInGamut,
90
113
  meetsWCAG_AA,
91
114
  meetsWCAG_AAA,
115
+ mergeSlice,
92
116
  oklchToHex,
93
117
  parseProvenance,
94
118
  parseToOklch,
95
119
  provenanceComment,
120
+ readDeclarations,
96
121
  reanchorFactors,
97
122
  resolveShades,
98
123
  seedFingerprint,
@@ -100,5 +125,6 @@ export {
100
125
  simulateCVD,
101
126
  snapShade,
102
127
  stableStringify,
128
+ tokenFamilies,
103
129
  withJsonProvenance
104
130
  };
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@designtools/tokens",
3
- "version": "0.3.0",
4
- "description": "Headless colour token generation from brand colours: OKLCH primitive scales, contrast-checked semantic intents, light/dark modes, and serialisers for CSS custom properties (lead), Tailwind v4 (@theme static) and v3, and DTCG. Pure TypeScript, deterministic.",
3
+ "version": "0.5.0",
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",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/andflett/designtools"
9
+ "url": "git+https://github.com/andflett/designtools.git",
10
+ "directory": "packages/tokens"
10
11
  },
11
12
  "main": "dist/index.js",
12
13
  "types": "dist/index.d.ts",
@@ -21,7 +22,8 @@
21
22
  },
22
23
  "files": [
23
24
  "dist",
24
- "README.md"
25
+ "README.md",
26
+ "CHANGELOG.md"
25
27
  ],
26
28
  "engines": {
27
29
  "node": ">=18"
@@ -42,5 +44,38 @@
42
44
  "tsup": "^8.0.0",
43
45
  "tsx": "^4.19.0",
44
46
  "typescript": "^5.9.3"
47
+ },
48
+ "keywords": [
49
+ "design-tokens",
50
+ "design-system",
51
+ "color",
52
+ "colour",
53
+ "palette",
54
+ "palette-generator",
55
+ "oklch",
56
+ "color-scale",
57
+ "color-ramp",
58
+ "theme",
59
+ "theming",
60
+ "dark-mode",
61
+ "accessibility",
62
+ "a11y",
63
+ "wcag",
64
+ "apca",
65
+ "contrast",
66
+ "contrast-checker",
67
+ "css-variables",
68
+ "custom-properties",
69
+ "tailwind",
70
+ "tailwindcss",
71
+ "tailwind-v4",
72
+ "dtcg",
73
+ "cli",
74
+ "generator",
75
+ "deterministic"
76
+ ],
77
+ "homepage": "https://github.com/andflett/designtools/tree/main/packages/tokens#readme",
78
+ "bugs": {
79
+ "url": "https://github.com/andflett/designtools/issues"
45
80
  }
46
81
  }