@designtools/tokens 0.3.0 → 0.4.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/cli.js CHANGED
@@ -5,20 +5,29 @@ import {
5
5
  SHADE_PRESETS,
6
6
  TOKEN_SECTIONS,
7
7
  VALID_SHADES,
8
+ checkRampChroma,
8
9
  checkSemanticContrast,
9
10
  checkSemanticContrastAPCA,
11
+ checkSurfaceContrast,
10
12
  computeAccessibilityScore,
13
+ diffSlice,
11
14
  exportTokens,
15
+ extendedBridgeShades,
16
+ externalReferences,
12
17
  generateTokens,
18
+ mergeSlice,
19
+ overrideContract,
13
20
  parseProvenance,
14
21
  parseToOklch,
15
22
  provenanceComment,
16
23
  resolveShades,
24
+ ringBridgeShade,
17
25
  seedFingerprint,
18
26
  selectTokenSections,
19
27
  snapShade,
28
+ tokenFamilies,
20
29
  withJsonProvenance
21
- } from "./chunk-3OG7U5V2.js";
30
+ } from "./chunk-MCLZSLHE.js";
22
31
 
23
32
  // src/cli.ts
24
33
  import { parseArgs } from "util";
@@ -56,6 +65,17 @@ Generation options:
56
65
  utilityShadeOverrides } (same shape as the web tool).
57
66
 
58
67
  Selection:
68
+ --ramps <names> Restrict output to these colour families, comma-separated
69
+ or repeated. A family is one colour plus everything
70
+ computed against it: its ramp, its alias ramp, and its
71
+ semantic tokens with their contrast-derived foregrounds.
72
+ That is the safe unit to regenerate on its own, because
73
+ the contrast search runs inside it.
74
+ Use with --merge to regenerate part of a token file
75
+ without rewriting regions a human has edited.
76
+ Surfaces and utilities belong to no single colour, so a
77
+ family-scoped slice leaves them alone.
78
+
59
79
  --only <sections> Emit only these slices, comma-separated or repeated:
60
80
  ramp the twelve-step colour ramps alone
61
81
  primitives the ramps plus black and white
@@ -76,10 +96,9 @@ Output:
76
96
  Default: oklch
77
97
  --out <path> File to write (or directory when --format all).
78
98
  Omit to print to stdout.
79
- --vanilla Accepted and ignored. The shadcn/ui aliases it used to
80
- switch off are gone in 0.2, so vanilla is now the only
81
- behaviour. Kept for one version so existing calls do not
82
- break; it will be removed in 0.3.
99
+ --vanilla Deprecated no-op, warns. The shadcn/ui aliases it used to
100
+ switch off no longer exist, so vanilla is the only
101
+ behaviour. Still accepted so existing calls keep working.
83
102
  --no-replace-palette tailwind-v4 only: keep Tailwind's stock colour palette.
84
103
  By default the generated theme clears it
85
104
  (--color-*: initial), so a colour class this tool does
@@ -87,7 +106,13 @@ Output:
87
106
  rendering off-brand. Pass this when adopting the
88
107
  generator into an existing Tailwind codebase that still
89
108
  uses stock hues like bg-slate-900.
90
- --replace-palette Accepted and ignored; this is the default in 0.3.
109
+ --replace-palette Deprecated no-op, warns; clearing the palette is the
110
+ default. Use --no-replace-palette to opt out instead.
111
+ --merge Rewrite only the declarations this run generates into the
112
+ existing file at --out, preserving every other line byte
113
+ for byte. A colour family spans four blocks (:root, light,
114
+ dark and the prefers-color-scheme fallback), so this is
115
+ what makes a partial regeneration safe to apply.
91
116
  --no-provenance Omit the "Generated by \u2026" header. The header is what
92
117
  makes --check able to distinguish a generator upgrade
93
118
  from a hand edit, so dropping it costs you that.
@@ -97,6 +122,9 @@ Verification:
97
122
  at --out. Writes nothing. Exit 0 if identical, 1 if it
98
123
  differs, and reports a version mismatch distinctly from
99
124
  an edit. Requires --out.
125
+ With --ramps or --merge, only the declarations this run
126
+ generates are compared, so hand-edited regions elsewhere
127
+ in the file are not reported as drift.
100
128
  --report Print the measured contrast of every semantic foreground
101
129
  pairing to stderr, with an overall score against the
102
130
  --contrast algorithm and --target level. Writes no files
@@ -142,6 +170,8 @@ try {
142
170
  shades: { type: "string" },
143
171
  overrides: { type: "string" },
144
172
  only: { type: "string", multiple: true },
173
+ ramps: { type: "string", multiple: true },
174
+ merge: { type: "boolean" },
145
175
  format: { type: "string" },
146
176
  "color-format": { type: "string" },
147
177
  out: { type: "string" },
@@ -251,6 +281,17 @@ var sections = (values.only ?? []).flatMap((entry) => entry.split(",")).map((s)
251
281
  }
252
282
  return s;
253
283
  });
284
+ var families = (values.ramps ?? []).flatMap((entry) => entry.split(",")).map((f) => f.trim()).filter((f) => f.length > 0);
285
+ if (families.length > 0 && !SECTIONED_FORMATS.includes(format) && format !== "json" && format !== "all") {
286
+ fail(`--ramps is not supported by --format ${format} (supported: ${[...SECTIONED_FORMATS, "json"].join(", ")})`);
287
+ }
288
+ if (values.merge) {
289
+ if (!values.out) fail("--merge needs --out to merge into");
290
+ if (format === "all") fail("--merge writes one file, so it cannot be used with --format all");
291
+ if (format === "dtcg" || format === "tailwind-v3" || format === "json") {
292
+ fail(`--merge only understands CSS-shaped output, not --format ${format}`);
293
+ }
294
+ }
254
295
  if (sections.length > 0) {
255
296
  const sectionable = [...SECTIONED_FORMATS, "json"];
256
297
  const targets = format === "all" ? SECTIONED_FORMATS : [format];
@@ -286,7 +327,23 @@ var options = {
286
327
  surfaceShadeOverrides: overrides.surfaceShadeOverrides,
287
328
  utilityShadeOverrides: overrides.utilityShadeOverrides
288
329
  };
330
+ for (const [flag, why] of [
331
+ ["vanilla", "the shadcn/ui aliases it switched off no longer exist, so this is already the only behaviour"],
332
+ ["replace-palette", "clearing Tailwind's stock palette is the default; use --no-replace-palette to opt out"]
333
+ ]) {
334
+ if (values[flag]) {
335
+ process.stderr.write(`generate-tokens: --${flag} does nothing \u2014 ${why}
336
+ `);
337
+ }
338
+ }
289
339
  var tokens = generateTokens(brandColors, options);
340
+ if (families.length > 0) {
341
+ const known = tokenFamilies(tokens);
342
+ const unknown = families.filter((f) => !known.includes(f));
343
+ if (unknown.length > 0) {
344
+ fail(`--ramps names no such colour: ${unknown.join(", ")} (available: ${known.join(", ")})`);
345
+ }
346
+ }
290
347
  if (shades) {
291
348
  const named = [
292
349
  ["muted (light)", 25],
@@ -338,17 +395,23 @@ var provenance = {
338
395
  };
339
396
  var stampProvenance = values["no-provenance"] !== true;
340
397
  var JSON_FORMATS = ["json", "dtcg"];
398
+ var CSS_SHAPED_FORMATS = ["css", "tailwind-v4"];
341
399
  function serialise(fmt) {
342
- const body = fmt === "json" ? JSON.stringify(selectTokenSections(tokens, sections), null, 2) : exportTokens(tokens, fmt, {
400
+ const body = fmt === "json" ? JSON.stringify(selectTokenSections(tokens, sections, families), null, 2) : exportTokens(tokens, fmt, {
343
401
  colorFormat,
344
402
  shadeOverrides: options.shadeOverrides,
345
403
  replacePalette,
346
404
  // `--format all` writes every format; only the sectionable ones get filtered.
347
405
  sections: SECTIONED_FORMATS.includes(fmt) ? sections : void 0,
348
- shades
406
+ shades,
407
+ families: SECTIONED_FORMATS.includes(fmt) ? families : void 0,
408
+ seedShade: options.seedShade
349
409
  });
350
410
  if (!stampProvenance) return body;
351
- return JSON_FORMATS.includes(fmt) ? withJsonProvenance(body, provenance) : `${provenanceComment(provenance)}
411
+ if (JSON_FORMATS.includes(fmt)) return withJsonProvenance(body, provenance);
412
+ const header = CSS_SHAPED_FORMATS.includes(fmt) ? `${provenanceComment(provenance)}
413
+ ${overrideContract()}` : provenanceComment(provenance);
414
+ return `${header}
352
415
  ${body}`;
353
416
  }
354
417
  function targetPath(fmt, out) {
@@ -392,8 +455,59 @@ function check(fmt, target) {
392
455
  }
393
456
  return false;
394
457
  }
458
+ function reportBridge() {
459
+ process.stderr.write(`
460
+ semantic bridge (seed anchored at ${options.seedShade ?? 500})
461
+ `);
462
+ const active = resolveShades(shades);
463
+ for (const mode of ["light", "dark"]) {
464
+ const e = extendedBridgeShades(mode, options.seedShade, active);
465
+ process.stderr.write(
466
+ ` ${mode.padEnd(6)} default ${String(e.DEFAULT).padStart(3)} subdued ${String(e.subdued).padStart(3)} highlight ${String(e.highlight).padStart(3)} ring ${String(ringBridgeShade(mode, options.seedShade, active)).padStart(3)}
467
+ `
468
+ );
469
+ }
470
+ }
471
+ function reportChroma() {
472
+ const chroma = checkRampChroma(tokens.primitives);
473
+ const unintended = ([name, r]) => r.low && name !== "neutral";
474
+ const low = Object.entries(chroma).filter(unintended);
475
+ process.stderr.write(`
476
+ ramp chroma (peak C per family)
477
+ `);
478
+ for (const [name, r] of Object.entries(chroma)) {
479
+ const mark = unintended([name, r]) ? "grey" : " ";
480
+ process.stderr.write(` ${mark} ${name.padEnd(14)} ${r.peak.toFixed(4)} at ${r.atShade}
481
+ `);
482
+ }
483
+ if (low.length > 0) {
484
+ process.stderr.write(
485
+ ` note: ${low.map(([n]) => n).join(", ")} carr${low.length === 1 ? "ies" : "y"} too little chroma to read as a marking
486
+ at small sizes. Picking harder will not fix it; a palette can be short of a colour.
487
+ `
488
+ );
489
+ }
490
+ }
491
+ function reportSurfaces() {
492
+ const width = 34;
493
+ for (const mode of ["light", "dark"]) {
494
+ process.stderr.write(`
495
+ ${mode} surfaces and utilities (wcag, not counted in the score)
496
+ `);
497
+ for (const [pair, r] of Object.entries(
498
+ checkSurfaceContrast(tokens.surface[mode], tokens.utility[mode])
499
+ )) {
500
+ const mark = r.advisory ? " " : r.nonText ? r.passes ? "3:1" : "- " : r.passesAAA ? "AAA" : r.passesAA ? "AA " : "- ";
501
+ const note = r.advisory ? " (advisory: 3:1 only where it bounds a control)" : r.nonText ? " (non-text, 1.4.11)" : "";
502
+ process.stderr.write(` ${mark} ${pair.padEnd(width)} ${r.ratio.toFixed(2)}:1${note}
503
+ `);
504
+ }
505
+ }
506
+ }
395
507
  function report() {
396
508
  const width = 34;
509
+ reportBridge();
510
+ reportChroma();
397
511
  for (const mode of ["light", "dark"]) {
398
512
  const semantic = tokens.semantic[mode];
399
513
  process.stderr.write(`
@@ -421,13 +535,81 @@ ${mode} mode (${contrastAlgorithm}, target ${contrastTarget})
421
535
  process.stderr.write(` score: ${score}% (${passed}/${total} pairings)
422
536
  `);
423
537
  }
538
+ reportSurfaces();
424
539
  }
425
540
  if (values.report) report();
426
541
  var formats = format === "all" ? Object.keys(FILE_NAMES) : [format];
542
+ var isSlice = families.length > 0 || sections.length > 0;
543
+ function reportExternalReferences(css) {
544
+ const external = externalReferences(css);
545
+ if (external.length === 0) return;
546
+ process.stderr.write(
547
+ `slice references ${external.length} token${external.length === 1 ? "" : "s"} defined elsewhere:
548
+ `
549
+ );
550
+ for (const name of external) process.stderr.write(` ${name}
551
+ `);
552
+ }
553
+ function checkSlice(target, slice) {
554
+ let existing;
555
+ try {
556
+ existing = readFileSync(target, "utf8");
557
+ } catch {
558
+ process.stderr.write(`check: ${target} does not exist
559
+ `);
560
+ return false;
561
+ }
562
+ const { matches, differing, missing } = diffSlice(existing, slice);
563
+ const scope = families.length > 0 ? families.join(", ") : sections.join(", ");
564
+ if (matches) {
565
+ process.stderr.write(`check: ${target} up to date for ${scope}
566
+ `);
567
+ return true;
568
+ }
569
+ process.stderr.write(
570
+ `check: ${target} differs for ${scope} \u2014 ${differing.length} changed, ${missing.length} missing
571
+ `
572
+ );
573
+ for (const d of differing.slice(0, 10)) {
574
+ process.stderr.write(` ${d.property} in ${d.block}
575
+ on disk: ${d.actual}
576
+ expected: ${d.expected}
577
+ `);
578
+ }
579
+ for (const m of missing.slice(0, 10)) {
580
+ process.stderr.write(` missing ${m.property} in ${m.block}
581
+ `);
582
+ }
583
+ return false;
584
+ }
427
585
  if (values.check) {
428
586
  const out = values.out;
587
+ if (isSlice) {
588
+ process.exit(checkSlice(targetPath(format, out), serialise(format)) ? 0 : 1);
589
+ }
429
590
  const ok = formats.map((fmt) => check(fmt, format === "all" ? join(out, FILE_NAMES[fmt]) : targetPath(fmt, out)));
430
591
  process.exit(ok.every(Boolean) ? 0 : 1);
592
+ } else if (values.merge) {
593
+ const target = targetPath(format, values.out);
594
+ let existing;
595
+ try {
596
+ existing = readFileSync(target, "utf8");
597
+ } catch (err) {
598
+ fail(`--merge needs an existing file at ${target}: ${err instanceof Error ? err.message : String(err)}`);
599
+ }
600
+ const slice = serialise(format).replace(/^\/\* Generated by [^\n]*\n/, "");
601
+ const result = mergeSlice(existing, slice);
602
+ if (result.missingBlocks.length > 0) {
603
+ fail(
604
+ `--merge cannot place ${result.missingBlocks.length} block(s) absent from ${target}: ` + result.missingBlocks.join(", ")
605
+ );
606
+ }
607
+ writeFileSync(target, result.css);
608
+ process.stderr.write(
609
+ `merged into ${target}: ${result.updated.length} updated, ${result.added.length} added, ${result.unchanged.length} already current
610
+ `
611
+ );
612
+ reportExternalReferences(slice);
431
613
  } else if (format === "all") {
432
614
  const dir = values.out ?? ".";
433
615
  mkdirSync(dir, { recursive: true });
@@ -447,4 +629,5 @@ if (values.check) {
447
629
  } else {
448
630
  process.stdout.write(output);
449
631
  }
632
+ if (isSlice && SECTIONED_FORMATS.includes(format)) reportExternalReferences(output);
450
633
  }
package/dist/index.d.ts CHANGED
@@ -325,6 +325,17 @@ type PrimitivePalette = {
325
325
  * Default neutral color - a balanced gray
326
326
  */
327
327
  declare const DEFAULT_NEUTRAL_COLOR = "#747474";
328
+ /**
329
+ * Scales that carry two names for the same colour: the semantic one the
330
+ * token layer reads, and a friendly alias so `bg-red-500` works.
331
+ *
332
+ * They are one object, not a derivation — overriding either name has to move
333
+ * both, or `bg-red-500` and `bg-destructive-500` silently become different
334
+ * colours.
335
+ */
336
+ declare const ALIAS_PAIRS: readonly (readonly [semantic: string, alias: string])[];
337
+ /** The other name for a scale, if it has one */
338
+ declare function aliasOf(name: string): string | undefined;
328
339
  /**
329
340
  * Generate a complete primitive palette from brand colors
330
341
  * Requires primary and neutral - other semantic colors are derived from primary
@@ -336,6 +347,66 @@ declare function generatePrimitivePalette(brandColors: BrandColors, lightnessStr
336
347
  */
337
348
  declare function getShade(palette: PrimitivePalette, colorName: string, shade: keyof ColorScale): string;
338
349
 
350
+ /**
351
+ * Merging a generated slice into an existing token file.
352
+ *
353
+ * A colour family is not one contiguous block: its ramp sits in `:root` and its
354
+ * semantic tokens repeat in the light block, the dark block and the
355
+ * prefers-color-scheme fallback. Regenerating "the reds" therefore means
356
+ * rewriting declarations in four places at once, which is exactly the kind of
357
+ * edit a caller splicing text by hand gets wrong — most often by missing the
358
+ * media-query copy, leaving system-dark on the old colour.
359
+ *
360
+ * So the tool does it. Every line the slice does not mention is preserved byte
361
+ * for byte, which is what makes it safe to run against a file with
362
+ * hand-authored regions in it.
363
+ */
364
+ /** One custom-property declaration, located by the block it sits in */
365
+ interface Declaration {
366
+ /** Normalised selector of the enclosing block */
367
+ block: string;
368
+ property: string;
369
+ value: string;
370
+ }
371
+ /** Every declaration in a stylesheet, in order */
372
+ declare function readDeclarations(css: string): Declaration[];
373
+ interface MergeResult {
374
+ css: string;
375
+ /** Declarations whose value the merge changed */
376
+ updated: Declaration[];
377
+ /** Declarations the slice defines that the target did not have */
378
+ added: Declaration[];
379
+ /** Declarations already matching, left alone */
380
+ unchanged: Declaration[];
381
+ /** Blocks the slice needs that the target does not contain */
382
+ missingBlocks: string[];
383
+ }
384
+ /**
385
+ * Rewrite the declarations a slice defines, leaving every other line intact.
386
+ *
387
+ * New declarations are appended to the end of their block, so adding a colour
388
+ * lands beside the existing ones rather than at the top of the file.
389
+ */
390
+ declare function mergeSlice(target: string, slice: string): MergeResult;
391
+ interface SliceDiff {
392
+ matches: boolean;
393
+ differing: {
394
+ block: string;
395
+ property: string;
396
+ expected: string;
397
+ actual: string;
398
+ }[];
399
+ missing: Declaration[];
400
+ }
401
+ /**
402
+ * Compare a slice against a target without writing.
403
+ *
404
+ * Only declarations the slice defines are considered, so hand-edited regions
405
+ * elsewhere in the file do not register as drift — which is the whole point of
406
+ * checking a part-generated file.
407
+ */
408
+ declare function diffSlice(target: string, slice: string): SliceDiff;
409
+
339
410
  /**
340
411
  * Semantic token generation
341
412
  * Maps primitive colors to meaningful semantic roles
@@ -353,7 +424,7 @@ declare function generateSurfaceTokens(palette: PrimitivePalette, mode: "light"
353
424
  /**
354
425
  * Generate utility tokens for borders, rings, inputs, shadow
355
426
  */
356
- declare function generateUtilityTokens(palette: PrimitivePalette, mode: "light" | "dark", overrides?: Partial<UtilityShadeOverrides>, shades?: readonly ShadeNumber[]): UtilityTokens;
427
+ declare function generateUtilityTokens(palette: PrimitivePalette, mode: "light" | "dark", overrides?: Partial<UtilityShadeOverrides>, shades?: readonly ShadeNumber[], seedShade?: ShadeNumber): UtilityTokens;
357
428
  /**
358
429
  * Check contrast compliance for all semantic colors
359
430
  */
@@ -368,8 +439,14 @@ declare function checkSemanticContrast(tokens: SemanticTokens): Record<string, {
368
439
  declare function checkSemanticContrastAPCA(tokens: SemanticTokens): Record<string, APCAContrastResult>;
369
440
  /**
370
441
  * 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.
442
+ *
443
+ * Counts every extended-family pairing and excludes `muted` alone. Neutral is
444
+ * deliberately included: it is the pairing most likely to fail on a default
445
+ * seed, and a score that quietly dropped it would flatter the palette exactly
446
+ * where a reader most needs the warning.
447
+ *
448
+ * Surface and utility pairings are reported separately and are not counted, so
449
+ * the number stays comparable with what earlier versions produced.
373
450
  */
374
451
  declare function computeAccessibilityScore(tokens: SemanticTokens, algorithm: ContrastAlgorithm, contrastTarget?: ContrastTarget): {
375
452
  score: number;
@@ -385,7 +462,7 @@ declare function computeAccessibilityScore(tokens: SemanticTokens, algorithm: Co
385
462
  /**
386
463
  * Export tokens as CSS custom properties
387
464
  */
388
- declare function exportToCss(tokens: TokenSystem, colorFormat?: ColorFormat, shadeOverrides?: SemanticShadeOverrides, sections?: TokenSection[], shades?: readonly ShadeNumber[]): string;
465
+ declare function exportToCss(tokens: TokenSystem, colorFormat?: ColorFormat, shadeOverrides?: SemanticShadeOverrides, sections?: TokenSection[], shades?: readonly ShadeNumber[], families?: readonly string[], seedShade?: ShadeNumber): string;
389
466
  /**
390
467
  * Emittable slices of the token system.
391
468
  *
@@ -407,7 +484,7 @@ type TokenSection = (typeof TOKEN_SECTIONS)[number];
407
484
  * emits once to :root and cannot vary by selector, so they are var()
408
485
  * indirections registered in @theme and re-bound in each mode block.
409
486
  */
410
- declare function exportToTailwindV4(tokens: TokenSystem, colorFormat?: ColorFormat, shadeOverrides?: SemanticShadeOverrides, replacePalette?: boolean, sections?: TokenSection[], shades?: readonly ShadeNumber[]): string;
487
+ declare function exportToTailwindV4(tokens: TokenSystem, colorFormat?: ColorFormat, shadeOverrides?: SemanticShadeOverrides, replacePalette?: boolean, sections?: TokenSection[], shades?: readonly ShadeNumber[], families?: readonly string[], seedShade?: ShadeNumber): string;
411
488
  /**
412
489
  * Export tokens as Tailwind v3 config
413
490
  */
@@ -439,16 +516,38 @@ interface ExportOptions {
439
516
  * snapped onto this set, so a dropped step never leaves a dangling var().
440
517
  */
441
518
  shades?: readonly ShadeNumber[];
519
+ /**
520
+ * Restrict output to these colour families — a family being one colour plus
521
+ * everything computed against it. Used to regenerate part of a token file
522
+ * without rewriting regions a human has edited.
523
+ */
524
+ families?: readonly string[];
525
+ /**
526
+ * Which step the seed was anchored on. The semantic bridge is expressed as
527
+ * offsets from it, so an exporter that does not know the anchor emits
528
+ * semantics pointing at the wrong steps — see `bridge.ts`. Default: 500.
529
+ */
530
+ seedShade?: ShadeNumber;
442
531
  }
443
532
  /** Formats whose structure lets a section filter be applied meaningfully */
444
533
  declare const SECTIONED_FORMATS: ExportFormat[];
534
+ /** Every colour family name a token system carries, ramps and aliases alike */
535
+ declare function tokenFamilies(tokens: TokenSystem): string[];
536
+ /**
537
+ * Custom properties a chunk of generated CSS reads but does not itself define.
538
+ *
539
+ * A family-scoped slice is not self-contained — a foreground search can land on
540
+ * a neutral shade or on black — so a caller splicing one needs to know which
541
+ * tokens have to already exist in the target.
542
+ */
543
+ declare function externalReferences(css: string): string[];
445
544
  /**
446
545
  * Narrow a TokenSystem to the requested sections, for the `json` output.
447
546
  *
448
547
  * Colour only: the spacing, typography, radii and shadow tiers are carried
449
548
  * through untouched when the full system is requested, and dropped otherwise.
450
549
  */
451
- declare function selectTokenSections(tokens: TokenSystem, sections?: TokenSection[]): Partial<TokenSystem>;
550
+ declare function selectTokenSections(tokens: TokenSystem, sections?: TokenSection[], families?: readonly string[]): Partial<TokenSystem>;
452
551
  /**
453
552
  * Export tokens in the specified format
454
553
  */
@@ -550,4 +649,4 @@ declare function parseProvenance(text: string): Provenance | null;
550
649
  /** Attach provenance to a JSON document as a `$designtools` key */
551
650
  declare function withJsonProvenance(json: string, p: Provenance): string;
552
651
 
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 };
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 };
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,
@@ -9,16 +10,19 @@ import {
9
10
  VALID_SHADES,
10
11
  adjustChroma,
11
12
  adjustLightness,
13
+ aliasOf,
12
14
  checkSemanticContrast,
13
15
  checkSemanticContrastAPCA,
14
16
  chromaShadeFor,
15
17
  classifyAPCALevel,
16
18
  computeAccessibilityScore,
19
+ diffSlice,
17
20
  exportToCss,
18
21
  exportToDtcg,
19
22
  exportToTailwindV3,
20
23
  exportToTailwindV4,
21
24
  exportTokens,
25
+ externalReferences,
22
26
  findContrastingColorAPCA,
23
27
  fingerprint,
24
28
  formatColorAs,
@@ -37,10 +41,12 @@ import {
37
41
  getShade,
38
42
  meetsWCAG_AA,
39
43
  meetsWCAG_AAA,
44
+ mergeSlice,
40
45
  oklchToHex,
41
46
  parseProvenance,
42
47
  parseToOklch,
43
48
  provenanceComment,
49
+ readDeclarations,
44
50
  reanchorFactors,
45
51
  resolveShades,
46
52
  seedFingerprint,
@@ -48,9 +54,11 @@ import {
48
54
  simulateCVD,
49
55
  snapShade,
50
56
  stableStringify,
57
+ tokenFamilies,
51
58
  withJsonProvenance
52
- } from "./chunk-3OG7U5V2.js";
59
+ } from "./chunk-MCLZSLHE.js";
53
60
  export {
61
+ ALIAS_PAIRS,
54
62
  DEFAULT_NEUTRAL_COLOR,
55
63
  DEFAULT_SEED_SHADE,
56
64
  GENERATOR_NAME,
@@ -61,16 +69,19 @@ export {
61
69
  VALID_SHADES,
62
70
  adjustChroma,
63
71
  adjustLightness,
72
+ aliasOf,
64
73
  checkSemanticContrast,
65
74
  checkSemanticContrastAPCA,
66
75
  chromaShadeFor,
67
76
  classifyAPCALevel,
68
77
  computeAccessibilityScore,
78
+ diffSlice,
69
79
  exportToCss,
70
80
  exportToDtcg,
71
81
  exportToTailwindV3,
72
82
  exportToTailwindV4,
73
83
  exportTokens,
84
+ externalReferences,
74
85
  findContrastingColorAPCA,
75
86
  fingerprint,
76
87
  formatColorAs,
@@ -89,10 +100,12 @@ export {
89
100
  getShade,
90
101
  meetsWCAG_AA,
91
102
  meetsWCAG_AAA,
103
+ mergeSlice,
92
104
  oklchToHex,
93
105
  parseProvenance,
94
106
  parseToOklch,
95
107
  provenanceComment,
108
+ readDeclarations,
96
109
  reanchorFactors,
97
110
  resolveShades,
98
111
  seedFingerprint,
@@ -100,5 +113,6 @@ export {
100
113
  simulateCVD,
101
114
  snapShade,
102
115
  stableStringify,
116
+ tokenFamilies,
103
117
  withJsonProvenance
104
118
  };
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.4.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",
@@ -42,5 +43,38 @@
42
43
  "tsup": "^8.0.0",
43
44
  "tsx": "^4.19.0",
44
45
  "typescript": "^5.9.3"
46
+ },
47
+ "keywords": [
48
+ "design-tokens",
49
+ "design-system",
50
+ "color",
51
+ "colour",
52
+ "palette",
53
+ "palette-generator",
54
+ "oklch",
55
+ "color-scale",
56
+ "color-ramp",
57
+ "theme",
58
+ "theming",
59
+ "dark-mode",
60
+ "accessibility",
61
+ "a11y",
62
+ "wcag",
63
+ "apca",
64
+ "contrast",
65
+ "contrast-checker",
66
+ "css-variables",
67
+ "custom-properties",
68
+ "tailwind",
69
+ "tailwindcss",
70
+ "tailwind-v4",
71
+ "dtcg",
72
+ "cli",
73
+ "generator",
74
+ "deterministic"
75
+ ],
76
+ "homepage": "https://github.com/andflett/designtools/tree/main/packages/tokens#readme",
77
+ "bugs": {
78
+ "url": "https://github.com/andflett/designtools/issues"
45
79
  }
46
80
  }