@designtools/tokens 0.13.0 → 0.15.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
@@ -2,12 +2,14 @@
2
2
  import {
3
3
  APCAUnavailableError,
4
4
  DEFAULT_NEUTRAL_COLOR,
5
+ LOCAL_TEMPLATE,
5
6
  SECTIONED_FORMATS,
6
7
  SHADE_PRESETS,
7
8
  TOKEN_SECTIONS,
8
9
  VALID_SHADES,
9
10
  applyScaleOverrides,
10
11
  bridgeShade,
12
+ checkLocalOverrides,
11
13
  checkRampChroma,
12
14
  checkSemanticContrast,
13
15
  checkSemanticContrastAPCA,
@@ -24,8 +26,10 @@ import {
24
26
  getContrastRatio,
25
27
  isAPCAAvailable,
26
28
  isInGamut,
29
+ isOwnedScale,
27
30
  mergeSlice,
28
31
  overrideContract,
32
+ ownedScaleHeader,
29
33
  parseProvenance,
30
34
  parseToOklch,
31
35
  provenanceComment,
@@ -39,17 +43,22 @@ import {
39
43
  suggestStep,
40
44
  tokenFamilies,
41
45
  usageReport,
46
+ verifyScale,
42
47
  withJsonProvenance
43
- } from "./chunk-HK7ME2YV.js";
48
+ } from "./chunk-FY6LQL2A.js";
44
49
 
45
50
  // src/cli.ts
46
51
  import { parseArgs as parseArgs2 } from "util";
47
- import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync2, readFileSync as readFileSync2, statSync } from "fs";
48
- import { join as join2, dirname } from "path";
52
+ import { mkdirSync as mkdirSync3, writeFileSync as writeFileSync3, readFileSync as readFileSync3, statSync } from "fs";
53
+ import { join as join3, dirname as dirname2 } from "path";
49
54
  import { fileURLToPath } from "url";
50
55
 
56
+ // src/init.ts
57
+ import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
58
+ import { dirname, join as join2, relative } from "path";
59
+
51
60
  // src/scale-cli.ts
52
- import { mkdirSync, readFileSync, writeFileSync } from "fs";
61
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
53
62
  import { join } from "path";
54
63
  import { parseArgs } from "util";
55
64
  var FORMATS = ["css", "tailwind-v4", "tailwind-v3", "dtcg", "json"];
@@ -60,26 +69,70 @@ var FILE_NAMES = {
60
69
  dtcg: "scale.dtcg.json",
61
70
  json: "scale.json"
62
71
  };
63
- var SCALE_HELP = `generate-tokens scale: the non-colour scale, from defaults and your overrides
72
+ var SCALE_HELP = `generate-tokens scale: the non-colour scale, scaffolded once and then the project's own
64
73
 
65
- generate-tokens scale --format tailwind-v4 --out app/styles/scale.css
66
- generate-tokens scale --format css --overrides scale.overrides.json --out src/scale.css
67
- generate-tokens scale --format all --out ./tokens
74
+ generate-tokens scale --init --format tailwind-v4 --out app/styles/scale.css
75
+ generate-tokens scale --verify app/styles/scale.css
68
76
 
69
77
  Space (--spacing), size (--size-*), type sizes with their line height and tracking (--text-*,
70
78
  --leading-*, --tracking-*, --font-weight-*), corners (--radius-*), elevation (--shadow-*),
71
79
  motion (--duration-*, --ease-*), screen sizes (--breakpoint-*) and widths (--container-*).
72
- The names are the contract; retune the values with --overrides, never by editing the file.
73
80
 
81
+ The scale is art direction, so it is written once and then edited by hand: nothing regenerates
82
+ it, and no overrides file tracks it. The names are the contract. Keep every one, and add new
83
+ ones only inside a tier's namespace; --verify (and designtools-manifest check) holds you to it.
84
+
85
+ --init Write the scale once. Refuses if the file exists: it is the project's.
86
+ --force With --init, write over an existing scale, after showing what changes.
87
+ --verify <file> Check a scale file's names against the contract. Exit 1 on a missing name,
88
+ or on one outside every tier. Values are never compared.
74
89
  --format <fmt> css | tailwind-v4 | tailwind-v3 | dtcg | json | all. Default: css.
75
90
  css writes screen sizes as @custom-media too, since a variable can't go in @media.
76
- --overrides <file> JSON, by token name: { "--radius-md": "0.5rem", "--text-5xl": { "value":
77
- "3rem", "description": "48px: page titles" }, "--leading-relaxed": null }.
78
- A new name joins the tier its prefix belongs to; null removes a token.
91
+ --overrides <file> JSON, by token name, to start --init from other values than the defaults:
92
+ { "--radius-md": "0.5rem", "--text-5xl": { "value": "3rem", "description":
93
+ "48px: page titles" } }. A new name joins the tier its prefix belongs to.
79
94
  --out <path> File to write, or a directory with --format all. Default: stdout.
80
- --check Compare against the file at --out instead of writing it. Exit 1 if it differs.
81
- --no-provenance Leave out the "Generated by" header.
95
+
96
+ Without --init, writing over a scale and --check still work, for projects that adopted the
97
+ scale before 0.14; both warn. Move to an owned scale: run --init --force once, delete the
98
+ overrides file, and drop the check.
82
99
  `;
100
+ function valuesOf(css) {
101
+ return new Map([...css.matchAll(/(?:^|[;{\s])(--[\w-]+)\s*:\s*([^;]+);/g)].map((m) => [m[1], m[2].trim()]));
102
+ }
103
+ function describeChange(before, after) {
104
+ const was = valuesOf(before);
105
+ const now = valuesOf(after);
106
+ const lines = [];
107
+ for (const [name, value] of now) {
108
+ const old = was.get(name);
109
+ if (old === void 0) lines.push(` + ${name}: ${value}`);
110
+ else if (old !== value) lines.push(` ~ ${name}: ${old} -> ${value}`);
111
+ }
112
+ for (const name of was.keys()) if (!now.has(name)) lines.push(` - ${name}`);
113
+ return lines;
114
+ }
115
+ function verify(file, fail2) {
116
+ let css;
117
+ try {
118
+ css = readFileSync(file, "utf8");
119
+ } catch {
120
+ return fail2(`can't read ${file}`);
121
+ }
122
+ const { missing, strays, own } = verifyScale(css);
123
+ if (!isOwnedScale(css)) {
124
+ process.stderr.write(`verify: ${file} is not an owned scale yet; run generate-tokens scale --init --force once to adopt it
125
+ `);
126
+ }
127
+ for (const name of missing) process.stderr.write(`verify: ${file} is missing ${name}, a name the scale promises
128
+ `);
129
+ for (const name of strays) process.stderr.write(`verify: ${file} declares ${name}, which belongs to no tier of the scale
130
+ `);
131
+ if (missing.length || strays.length) return 1;
132
+ process.stderr.write(`verify: ${file} keeps the scale's names${own.length ? `, with ${own.length} of its own inside the tiers` : ""}
133
+ `);
134
+ return 0;
135
+ }
83
136
  function runScale(argv, version) {
84
137
  const fail2 = (message) => {
85
138
  process.stderr.write(`generate-tokens scale: ${message}
@@ -95,6 +148,9 @@ function runScale(argv, version) {
95
148
  overrides: { type: "string" },
96
149
  out: { type: "string" },
97
150
  check: { type: "boolean" },
151
+ init: { type: "boolean" },
152
+ force: { type: "boolean" },
153
+ verify: { type: "string" },
98
154
  "no-provenance": { type: "boolean" },
99
155
  help: { type: "boolean", short: "h" }
100
156
  }
@@ -106,9 +162,12 @@ function runScale(argv, version) {
106
162
  process.stdout.write(SCALE_HELP);
107
163
  return 0;
108
164
  }
165
+ if (values2.verify) return verify(values2.verify, fail2);
109
166
  const format2 = values2.format ?? "css";
110
167
  if (format2 !== "all" && !FORMATS.includes(format2)) return fail2(`--format must be one of ${[...FORMATS, "all"].join(", ")}`);
111
168
  if (values2.check && !values2.out) return fail2("--check needs --out to compare against");
169
+ if (values2.force && !values2.init) return fail2("--force goes with --init");
170
+ if (values2.init && values2.check) return fail2("an owned scale has nothing to check against; use --verify");
112
171
  let overrides2 = {};
113
172
  if (values2.overrides) {
114
173
  try {
@@ -123,10 +182,14 @@ function runScale(argv, version) {
123
182
  } catch (err) {
124
183
  return fail2(err instanceof Error ? err.message : String(err));
125
184
  }
126
- const header = values2["no-provenance"] ? void 0 : `/* Generated by @designtools/tokens v${version} (scale${values2.overrides ? `, overrides ${values2.overrides}` : ""}) - retune with --overrides, do not edit by hand */`;
185
+ const header = values2["no-provenance"] ? void 0 : values2.init ? ownedScaleHeader(version) : `/* Generated by @designtools/tokens v${version} (scale${values2.overrides ? `, overrides ${values2.overrides}` : ""}) - retune with --overrides, do not edit by hand */`;
127
186
  const formats2 = format2 === "all" ? FORMATS.filter((f) => f !== "tailwind-v4") : [format2];
128
187
  const target = (f) => format2 === "all" ? join(values2.out ?? ".", FILE_NAMES[f]) : values2.out;
188
+ const legacy = () => process.stderr.write(
189
+ "generate-tokens scale: regenerating the scale is deprecated; scaffold it once with --init and own the file (see --help)\n"
190
+ );
129
191
  if (values2.check) {
192
+ legacy();
130
193
  let ok = true;
131
194
  for (const f of formats2) {
132
195
  const want = exportScale(tiers, f, header);
@@ -147,20 +210,107 @@ function runScale(argv, version) {
147
210
  process.stdout.write(exportScale(tiers, formats2[0], header));
148
211
  return 0;
149
212
  }
213
+ if (values2.init) {
214
+ for (const f of formats2) {
215
+ const path = target(f);
216
+ if (!existsSync(path)) continue;
217
+ const existing = readFileSync(path, "utf8");
218
+ if (!values2.force) {
219
+ return fail2(`${path} exists and is the project's own: edit it by hand, or pass --force to write over it`);
220
+ }
221
+ const changes = describeChange(existing, exportScale(tiers, f, header));
222
+ process.stderr.write(
223
+ changes.length ? `rewriting ${path}:
224
+ ${changes.join("\n")}
225
+ ` : `rewriting ${path}: the same names and values, now an owned scale
226
+ `
227
+ );
228
+ }
229
+ } else {
230
+ legacy();
231
+ }
150
232
  if (format2 === "all") mkdirSync(values2.out, { recursive: true });
151
233
  for (const f of formats2) {
152
234
  writeFileSync(target(f), exportScale(tiers, f, header));
153
- process.stderr.write(`wrote ${target(f)}
235
+ process.stderr.write(`wrote ${target(f)}${values2.init ? " (the project's now: edit it by hand)" : ""}
154
236
  `);
155
237
  }
156
238
  return 0;
157
239
  }
158
240
 
241
+ // src/init.ts
242
+ function take(args, flag) {
243
+ const i = args.findIndex((a) => a === flag || a.startsWith(`${flag}=`));
244
+ if (i === -1) return void 0;
245
+ const [arg] = args.splice(i, 1);
246
+ if (arg.includes("=")) return arg.slice(flag.length + 1);
247
+ return args.splice(i, 1)[0];
248
+ }
249
+ var ORDER = ["tokens.css", "tokens.local.css", "scale.css"];
250
+ function wire(entry, dir) {
251
+ const rel = (file) => {
252
+ const path = relative(dirname(entry), join2(dir, file)).replace(/\\/g, "/");
253
+ return path.startsWith(".") ? path : `./${path}`;
254
+ };
255
+ const imports = ORDER.map((file) => `@import "${rel(file)}";`);
256
+ let css = existsSync2(entry) ? readFileSync2(entry, "utf8") : '@import "tailwindcss";\n';
257
+ const missing = imports.filter((line) => !css.includes(line.slice(0, -1)));
258
+ if (!missing.length) {
259
+ process.stderr.write(`init: ${entry} already imports the tokens
260
+ `);
261
+ return;
262
+ }
263
+ const tailwind = /^@import\s+["']tailwindcss["'][^;\n]*;/m.exec(css);
264
+ const at = tailwind ? tailwind.index + tailwind[0].length : 0;
265
+ const rest = css.slice(at).replace(/^\n+/, "");
266
+ css = `${css.slice(0, at)}${at ? "\n\n" : ""}${missing.join("\n")}
267
+ ${rest ? `
268
+ ${rest}` : ""}`;
269
+ mkdirSync2(dirname(entry), { recursive: true });
270
+ writeFileSync2(entry, css);
271
+ process.stderr.write(`init: added ${missing.length} import${missing.length === 1 ? "" : "s"} to ${entry}
272
+ `);
273
+ }
274
+ function prepareInit(argv, version) {
275
+ const args = [...argv];
276
+ const dir = take(args, "--dir") ?? "app/styles";
277
+ const entry = take(args, "--entry");
278
+ mkdirSync2(dir, { recursive: true });
279
+ const scale = join2(dir, "scale.css");
280
+ if (existsSync2(scale)) {
281
+ process.stderr.write(`init: kept ${scale}: the scale is the project's own once written
282
+ `);
283
+ } else if (runScale(["--init", "--format", "tailwind-v4", "--out", scale], version) !== 0) {
284
+ return void 0;
285
+ }
286
+ const local = join2(dir, "tokens.local.css");
287
+ if (existsSync2(local)) process.stderr.write(`init: kept ${local}
288
+ `);
289
+ else {
290
+ writeFileSync2(local, LOCAL_TEMPLATE);
291
+ process.stderr.write(`wrote ${local} (empty: the overrides go here, checked on every run)
292
+ `);
293
+ }
294
+ if (entry) wire(entry, dir);
295
+ const has = (flag) => args.some((a) => a === flag || a.startsWith(`${flag}=`));
296
+ if (!has("--format")) args.push("--format", "tailwind-v4");
297
+ if (!has("--out")) args.push("--out", join2(dir, "tokens.css"));
298
+ if (!has("--local")) args.push("--local", local);
299
+ return args;
300
+ }
301
+
159
302
  // src/cli.ts
160
303
  var HELP = `generate-tokens \u2014 brand colour in, design tokens out
161
304
 
162
305
  Usage:
163
306
  generate-tokens --primary <colour> [options]
307
+ generate-tokens init --primary <colour> [options] [--dir <dir>] [--entry <stylesheet>]
308
+ Set a project up: the colour in tokens.css, the scale in
309
+ scale.css (written once, then the project's own) and an
310
+ empty tokens.local.css, in --dir (default app/styles).
311
+ --entry adds the three imports, in order, to a stylesheet.
312
+ generate-tokens scale --help
313
+ The non-colour scale.
164
314
 
165
315
  Seeds:
166
316
  --primary <colour> Brand colour (hex, rgb(), hsl(), oklch(), named). Required
@@ -194,15 +344,21 @@ Seeds:
194
344
  --decorative, or primary for a brand band), the same in
195
345
  light and dark mode. Inside data-surface="<name>",
196
346
  content reads tokens that work on it: the page's of the
197
- ground's polarity, and what --ground-tint and
198
- --ground-text change. Repeatable.
347
+ ground's polarity, and what --ground-tint,
348
+ --ground-panels and --ground-text change. Repeatable.
199
349
  --ground-tint <fill> or <name>=<fill>
200
- Where a ground's lines, panels, card, input edge, ring
201
- and buttons come from. own (default): steps on its
202
- ramp, each searched to its floor. page: the page's.
203
- Or one colour for every line, edge and ring: white,
204
- black, or a step (sage-100). A bare value sets every
205
- ground; name=value one, and wins. Repeatable.
350
+ Where a ground's lines (borders, input edge, ring) and
351
+ buttons come from. own (default): steps on its ramp,
352
+ each searched to its floor. page: the page's. Or one
353
+ colour for every line, edge and ring: white, black, or
354
+ a step (sage-100). A bare value sets every ground;
355
+ name=value one, and wins. Repeatable.
356
+ --ground-panels <fill> or <name>=<fill>
357
+ Where a ground's card (--surface) and quiet panel
358
+ (--neutral-subdued) come from. Unset: the page's with
359
+ page lines, else own. own: a step off the ground on
360
+ its ramp. page: the page's. Or one colour for both.
361
+ Repeatable, as --ground-tint.
206
362
  --ground-text <fill> or <name>=<fill>
207
363
  Where a ground's body and secondary text come from. page
208
364
  (default): the page's, where it reads; white or black
@@ -300,7 +456,7 @@ Selection:
300
456
  semantic intent tokens (primary, destructive, \u2026)
301
457
  surface canvas / surface / overlay, each with its text and secondary text
302
458
  utility border / input / ring / shadow
303
- grounds --on-<ground>-* and the data-surface scopes
459
+ grounds the [data-surface] scopes
304
460
  Keeps generated colour separable from hand-tuned files,
305
461
  so a re-theme does not clobber them. Supported by the
306
462
  css, tailwind-v4 and json formats.
@@ -336,6 +492,19 @@ Output:
336
492
  makes --check able to distinguish a generator upgrade
337
493
  from a hand edit, so dropping it costs you that.
338
494
 
495
+ Overrides:
496
+ --local <file> The project's overrides of the generated colour, loaded
497
+ after tokens.css: the one place for a value no flag or the
498
+ seed can say. Checked on every run, with or without
499
+ --check: only the generator's selectors (:root,
500
+ [data-theme], .dark, [data-surface="<ground>"]), only its
501
+ token names (never a --color- alias or a ramp step), and
502
+ values that point at the system (var(), or a ramp step
503
+ nudged with oklch(from \u2026)), never a literal colour. Each
504
+ override is listed as pinned by hand, and each pair it
505
+ touches is re-checked for contrast at --target. Exit 1 on
506
+ any problem.
507
+
339
508
  Verification:
340
509
  --check Regenerate in memory and compare against what is already
341
510
  at --out. Writes nothing. Exit 0 if identical, 1 if it
@@ -371,13 +540,18 @@ var FILE_NAMES2 = {
371
540
  };
372
541
  var VERSION = (() => {
373
542
  try {
374
- const here = dirname(fileURLToPath(import.meta.url));
375
- return JSON.parse(readFileSync2(join2(here, "../package.json"), "utf8")).version;
543
+ const here = dirname2(fileURLToPath(import.meta.url));
544
+ return JSON.parse(readFileSync3(join3(here, "../package.json"), "utf8")).version;
376
545
  } catch {
377
546
  return "0.0.0";
378
547
  }
379
548
  })();
380
549
  if (process.argv[2] === "scale") process.exit(runScale(process.argv.slice(3), VERSION));
550
+ if (process.argv[2] === "init") {
551
+ const colour = prepareInit(process.argv.slice(3), VERSION);
552
+ if (colour === void 0) process.exit(1);
553
+ process.argv.splice(2, process.argv.length - 2, ...colour);
554
+ }
381
555
  function fail(message) {
382
556
  process.stderr.write(`generate-tokens: ${message}
383
557
  `);
@@ -396,6 +570,7 @@ try {
396
570
  overlay: { type: "string" },
397
571
  background: { type: "string", multiple: true },
398
572
  usage: { type: "string" },
573
+ local: { type: "string" },
399
574
  contrast: { type: "string" },
400
575
  target: { type: "string" },
401
576
  lightness: { type: "string" },
@@ -405,6 +580,7 @@ try {
405
580
  ground: { type: "string", multiple: true },
406
581
  "page-surface": { type: "string", multiple: true },
407
582
  "ground-tint": { type: "string", multiple: true },
583
+ "ground-panels": { type: "string", multiple: true },
408
584
  "ground-text": { type: "string", multiple: true },
409
585
  "ground-action": { type: "string", multiple: true },
410
586
  gamut: { type: "string" },
@@ -450,14 +626,14 @@ if (values.help) {
450
626
  var seed = {};
451
627
  if (values.stdin) {
452
628
  try {
453
- seed = JSON.parse(readFileSync2(0, "utf8"));
629
+ seed = JSON.parse(readFileSync3(0, "utf8"));
454
630
  } catch (err) {
455
631
  fail(`could not read seed from stdin: ${err instanceof Error ? err.message : String(err)}`);
456
632
  }
457
633
  }
458
634
  if (values.seed) {
459
635
  try {
460
- seed = JSON.parse(readFileSync2(values.seed, "utf8"));
636
+ seed = JSON.parse(readFileSync3(values.seed, "utf8"));
461
637
  } catch (err) {
462
638
  fail(`could not read --seed file: ${err instanceof Error ? err.message : String(err)}`);
463
639
  }
@@ -593,8 +769,8 @@ for (const entry of values.ground ?? []) {
593
769
  if (eq === -1) fail(`--ground expects name=<ramp>@<step> (got "${entry}")`);
594
770
  const name = entry.slice(0, eq).trim();
595
771
  if (!/^[a-z][a-z0-9-]*$/.test(name) || name === "canvas") fail(`--ground name must be lower-case kebab-case, and not "canvas" (got "${name}")`);
596
- const { tint, text, action } = grounds[name] ?? {};
597
- grounds[name] = { ...rampStep(`--ground ${name}`, entry.slice(eq + 1)), ...tint ? { tint } : {}, ...text ? { text } : {}, ...action ? { action } : {} };
772
+ const { tint, panels, text, action } = grounds[name] ?? {};
773
+ grounds[name] = { ...rampStep(`--ground ${name}`, entry.slice(eq + 1)), ...tint ? { tint } : {}, ...panels ? { panels } : {}, ...text ? { text } : {}, ...action ? { action } : {} };
598
774
  }
599
775
  function fills(flag, key, seeded, fallback) {
600
776
  let all = seeded ?? fallback;
@@ -611,6 +787,7 @@ function fills(flag, key, seeded, fallback) {
611
787
  return all;
612
788
  }
613
789
  var groundTint = fills("ground-tint", "tint", seed.groundTint, "own");
790
+ var groundPanels = fills("ground-panels", "panels", seed.groundPanels);
614
791
  var groundText = fills("ground-text", "text", seed.groundText, "page");
615
792
  var groundAction = seed.groundAction;
616
793
  for (const entry of values["ground-action"] ?? []) {
@@ -744,7 +921,7 @@ var overrides = {
744
921
  };
745
922
  if (values.overrides) {
746
923
  try {
747
- overrides = JSON.parse(readFileSync2(values.overrides, "utf8"));
924
+ overrides = JSON.parse(readFileSync3(values.overrides, "utf8"));
748
925
  } catch (err) {
749
926
  fail(`could not read --overrides file: ${err instanceof Error ? err.message : String(err)}`);
750
927
  }
@@ -764,6 +941,7 @@ var options = {
764
941
  ...Object.keys(pageSurfaces).length ? { pageSurfaces } : {},
765
942
  ...Object.keys(grounds).length ? { grounds } : {},
766
943
  ...groundTint !== "own" ? { groundTint } : {},
944
+ ...groundPanels ? { groundPanels } : {},
767
945
  ...groundText !== "page" ? { groundText } : {},
768
946
  ...groundAction ? { groundAction } : {},
769
947
  seedShade,
@@ -879,6 +1057,7 @@ var resolvedSeed = {
879
1057
  ...Object.keys(pageSurfaces).length ? { pageSurfaces } : {},
880
1058
  ...Object.keys(grounds).length ? { grounds } : {},
881
1059
  ...groundTint !== "own" ? { groundTint } : {},
1060
+ ...groundPanels ? { groundPanels } : {},
882
1061
  ...groundText !== "page" ? { groundText } : {},
883
1062
  ...groundAction ? { groundAction } : {},
884
1063
  seedShade,
@@ -928,7 +1107,7 @@ ${body}`;
928
1107
  }
929
1108
  function targetPath(fmt, out) {
930
1109
  try {
931
- if (statSync(out).isDirectory()) return join2(out, FILE_NAMES2[fmt]);
1110
+ if (statSync(out).isDirectory()) return join3(out, FILE_NAMES2[fmt]);
932
1111
  } catch {
933
1112
  }
934
1113
  return out;
@@ -936,7 +1115,7 @@ function targetPath(fmt, out) {
936
1115
  function check(fmt, target) {
937
1116
  let existing;
938
1117
  try {
939
- existing = readFileSync2(target, "utf8");
1118
+ existing = readFileSync3(target, "utf8");
940
1119
  } catch {
941
1120
  process.stderr.write(`check: ${target} does not exist
942
1121
  `);
@@ -1134,7 +1313,7 @@ function reportGrounds() {
1134
1313
  grounds: what data-surface="<ground>" writes (ratio against the ground; a label's against its fill)
1135
1314
  `);
1136
1315
  for (const [name, g] of grounds2) {
1137
- process.stderr.write(` ${name.padEnd(14)}${g.ramp}@${g.step}, ${g.polarity}, text ${g.text}, tint ${g.tint}${g.action ? `, action ${g.action}` : ""}
1316
+ process.stderr.write(` ${name.padEnd(14)}${g.ramp}@${g.step}, ${g.polarity}, text ${g.text}, lines ${g.tint}, panels ${g.panels}${g.action ? `, action ${g.action}` : ""}
1138
1317
  `);
1139
1318
  const shown = g.own.filter((t) => t !== "canvas" && !t.endsWith("-hover") && !t.endsWith("-active"));
1140
1319
  const items = shown.map((t) => `${t} ${step(g._refs[t])} ${getContrastRatio(g.tokens[t], g.tokens[under(t)]).toFixed(1)}`);
@@ -1192,7 +1371,7 @@ function reportExternalReferences(css, merged) {
1192
1371
  function checkSlice(target, slice) {
1193
1372
  let existing;
1194
1373
  try {
1195
- existing = readFileSync2(target, "utf8");
1374
+ existing = readFileSync3(target, "utf8");
1196
1375
  } catch {
1197
1376
  process.stderr.write(`check: ${target} does not exist
1198
1377
  `);
@@ -1226,7 +1405,7 @@ function checkUsage() {
1226
1405
  if (!values.usage) return true;
1227
1406
  let existing = "";
1228
1407
  try {
1229
- existing = readFileSync2(values.usage, "utf8");
1408
+ existing = readFileSync3(values.usage, "utf8");
1230
1409
  } catch {
1231
1410
  process.stderr.write(`check: ${values.usage} is missing
1232
1411
  `);
@@ -1241,18 +1420,45 @@ function checkUsage() {
1241
1420
  `);
1242
1421
  return false;
1243
1422
  }
1423
+ function checkLocal() {
1424
+ if (!values.local) return true;
1425
+ if (isSlice) {
1426
+ process.stderr.write(`local: ${values.local} is checked on a full run, not a partial one
1427
+ `);
1428
+ return true;
1429
+ }
1430
+ let local = "";
1431
+ try {
1432
+ local = readFileSync3(values.local, "utf8");
1433
+ } catch {
1434
+ process.stderr.write(`local: ${values.local} is missing
1435
+ `);
1436
+ return false;
1437
+ }
1438
+ const generated = serialise(SECTIONED_FORMATS.includes(format) ? format : "css");
1439
+ const { overrides: overrides2, problems } = checkLocalOverrides(generated, local, contrastTarget);
1440
+ for (const o of overrides2) process.stderr.write(`local: pinned by hand: ${o.name} in ${o.selector}
1441
+ `);
1442
+ for (const p of problems) process.stderr.write(`local: ${values.local}: ${p.message}
1443
+ `);
1444
+ if (!problems.length) process.stderr.write(`local: ${values.local} keeps to the system (${overrides2.length} pinned)
1445
+ `);
1446
+ return problems.length === 0;
1447
+ }
1244
1448
  if (values.check) {
1245
1449
  const out = values.out;
1246
1450
  if (isSlice) {
1247
- process.exit(checkSlice(targetPath(format, out), serialise(format)) && checkUsage() ? 0 : 1);
1451
+ process.exit(
1452
+ checkSlice(targetPath(format, out), serialise(format)) && checkUsage() && checkLocal() ? 0 : 1
1453
+ );
1248
1454
  }
1249
- const ok = formats.map((fmt) => check(fmt, format === "all" ? join2(out, FILE_NAMES2[fmt]) : targetPath(fmt, out)));
1250
- process.exit(ok.every(Boolean) && checkUsage() ? 0 : 1);
1455
+ const ok = formats.map((fmt) => check(fmt, format === "all" ? join3(out, FILE_NAMES2[fmt]) : targetPath(fmt, out)));
1456
+ process.exit(ok.every(Boolean) && checkUsage() && checkLocal() ? 0 : 1);
1251
1457
  } else if (values.merge) {
1252
1458
  const target = targetPath(format, values.out);
1253
1459
  let existing;
1254
1460
  try {
1255
- existing = readFileSync2(target, "utf8");
1461
+ existing = readFileSync3(target, "utf8");
1256
1462
  } catch (err) {
1257
1463
  fail(`--merge needs an existing file at ${target}: ${err instanceof Error ? err.message : String(err)}`);
1258
1464
  }
@@ -1263,7 +1469,7 @@ if (values.check) {
1263
1469
  `--merge cannot place ${result.missingBlocks.length} block(s) absent from ${target}: ` + result.missingBlocks.join(", ")
1264
1470
  );
1265
1471
  }
1266
- writeFileSync2(target, result.css);
1472
+ writeFileSync3(target, result.css);
1267
1473
  process.stderr.write(
1268
1474
  `merged into ${target}: ${result.updated.length} updated, ${result.added.length} added, ${result.unchanged.length} already current
1269
1475
  `
@@ -1271,10 +1477,10 @@ if (values.check) {
1271
1477
  reportExternalReferences(slice, { target, css: result.css });
1272
1478
  } else if (format === "all") {
1273
1479
  const dir = values.out ?? ".";
1274
- mkdirSync2(dir, { recursive: true });
1480
+ mkdirSync3(dir, { recursive: true });
1275
1481
  for (const fmt of formats) {
1276
- const target = join2(dir, FILE_NAMES2[fmt]);
1277
- writeFileSync2(target, serialise(fmt) + "\n");
1482
+ const target = join3(dir, FILE_NAMES2[fmt]);
1483
+ writeFileSync3(target, serialise(fmt) + "\n");
1278
1484
  process.stderr.write(`wrote ${target}
1279
1485
  `);
1280
1486
  }
@@ -1282,7 +1488,7 @@ if (values.check) {
1282
1488
  const output = serialise(format) + "\n";
1283
1489
  if (values.out) {
1284
1490
  const target = targetPath(format, values.out);
1285
- writeFileSync2(target, output);
1491
+ writeFileSync3(target, output);
1286
1492
  process.stderr.write(`wrote ${target}
1287
1493
  `);
1288
1494
  } else {
@@ -1291,7 +1497,8 @@ if (values.check) {
1291
1497
  if (isSlice && SECTIONED_FORMATS.includes(format)) reportExternalReferences(output);
1292
1498
  }
1293
1499
  if (values.usage && !values.check) {
1294
- writeFileSync2(values.usage, usageText);
1500
+ writeFileSync3(values.usage, usageText);
1295
1501
  process.stderr.write(`wrote ${values.usage}
1296
1502
  `);
1297
1503
  }
1504
+ if (!values.check && !checkLocal()) process.exit(1);