@astryxdesign/cli 0.7.15-canary.gf890983 → 0.7.15

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.
Files changed (115) hide show
  1. package/CHANGELOG.md +353 -3
  2. package/api/doctor/_adapter.d.mts +2 -1
  3. package/api/doctor/_adapter.mjs +6 -1
  4. package/api/doctor/doctor.mjs +2 -2
  5. package/api/doctor/theme-checks.mjs +56 -21
  6. package/api/integration/add-helpers.mjs +5 -0
  7. package/api/integration/add-theme.mjs +15 -110
  8. package/api/theme/_adapter.d.mts +37 -5
  9. package/api/theme/_adapter.mjs +363 -50
  10. package/api/theme/_fork.d.mts +90 -0
  11. package/api/theme/_fork.mjs +246 -0
  12. package/api/theme/build/build.d.mts +25 -1
  13. package/api/theme/build/build.mjs +352 -41
  14. package/api/theme/eject/eject.mjs +36 -15
  15. package/api/theme/list/list.mjs +3 -6
  16. package/api/theme/palette/generate/generator.d.mts +13 -0
  17. package/api/theme/palette/generate/generator.mjs +32 -2
  18. package/api/theme/targets/targets.mjs +10 -3
  19. package/api/theme/template/template.mjs +48 -2
  20. package/api/theme/theme.type.d.mts +8 -0
  21. package/api/theme/theme.type.mjs +5 -1
  22. package/api/theme/themeBuild.doc.mjs +2 -2
  23. package/api/theme/themeRemove.doc.mjs +5 -2
  24. package/api/theme/themeTemplate.doc.mjs +2 -2
  25. package/api/theme/themeUse.doc.mjs +8 -2
  26. package/api/theme-edit/_adapter.mjs +157 -36
  27. package/api/theme-edit/_catalog.d.mts +1 -6
  28. package/api/theme-edit/_catalog.mjs +5 -268
  29. package/api/theme-edit/_check.d.mts +3 -1
  30. package/api/theme-edit/_check.mjs +733 -308
  31. package/api/theme-edit/_color.d.mts +19 -0
  32. package/api/theme-edit/_color.mjs +277 -33
  33. package/api/theme-edit/_compiler.d.mts +1 -0
  34. package/api/theme-edit/_compiler.mjs +25 -0
  35. package/api/theme-edit/_context.d.mts +2 -0
  36. package/api/theme-edit/_context.mjs +83 -9
  37. package/api/theme-edit/_css.d.mts +84 -0
  38. package/api/theme-edit/_css.mjs +700 -0
  39. package/api/theme-edit/_edit.mjs +370 -85
  40. package/api/theme-edit/_how-commands.d.mts +5 -0
  41. package/api/theme-edit/_how-commands.mjs +20 -13
  42. package/api/theme-edit/_how-question.d.mts +29 -0
  43. package/api/theme-edit/_how-question.mjs +1573 -182
  44. package/api/theme-edit/_how.mjs +306 -22
  45. package/api/theme-edit/_overview.mjs +2 -7
  46. package/api/theme-edit/_palette.d.mts +27 -5
  47. package/api/theme-edit/_palette.mjs +231 -97
  48. package/api/theme-edit/_parts.d.mts +42 -10
  49. package/api/theme-edit/_parts.mjs +224 -69
  50. package/api/theme-edit/_preview-app.d.mts +8 -0
  51. package/api/theme-edit/_preview-app.mjs +549 -96
  52. package/api/theme-edit/_preview.d.mts +7 -16
  53. package/api/theme-edit/_preview.mjs +77 -84
  54. package/api/theme-edit/_project.d.mts +20 -1
  55. package/api/theme-edit/_project.mjs +43 -13
  56. package/api/theme-edit/_settings.d.mts +96 -20
  57. package/api/theme-edit/_settings.mjs +646 -141
  58. package/api/theme-edit/_tables.d.mts +18 -12
  59. package/api/theme-edit/_tables.mjs +144 -147
  60. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  61. package/api/theme-edit/theme-edit.type.mjs +3 -1
  62. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  63. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
  64. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  65. package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
  66. package/api/theme-edit/themeEditSet.doc.mjs +1 -1
  67. package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
  68. package/assets/docs/tree/publishing.doc.mjs +1 -0
  69. package/assets/docs.generated.json +2 -2
  70. package/assets/self-audit.generated.json +1 -1
  71. package/clients/cli/build-id.generated.json +1 -1
  72. package/clients/cli/commands/experimental/index.mjs +10 -10
  73. package/clients/cli/commands/experimental/theme.mjs +22 -3
  74. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  75. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
  76. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  77. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  78. package/clients/cli/commands/integration.mjs +8 -0
  79. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  80. package/clients/cli/commands/theme-list.doc.mjs +1 -1
  81. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  82. package/clients/cli/commands/theme.mjs +325 -48
  83. package/clients/cli/index.mjs +18 -3
  84. package/clients/cli/lib/cli-error.mjs +118 -3
  85. package/clients/cli/manifest.generated.json +1 -1
  86. package/foundation/config/project.mjs +34 -8
  87. package/foundation/config/theme-state.d.mts +16 -0
  88. package/foundation/config/theme-state.mjs +84 -13
  89. package/foundation/discovery/template-needs.d.mts +13 -0
  90. package/foundation/discovery/template-needs.mjs +30 -15
  91. package/foundation/discovery/theme-discovery.mjs +14 -2
  92. package/foundation/discovery/theme-imports.d.mts +16 -0
  93. package/foundation/discovery/theme-imports.mjs +30 -2
  94. package/foundation/doc-compiler/import.mjs +10 -4
  95. package/foundation/fs/gather-cache.mjs +82 -23
  96. package/foundation/fs/jiti-cache.d.mts +21 -0
  97. package/foundation/fs/jiti-cache.mjs +66 -0
  98. package/foundation/fs/module-loader.mjs +7 -2
  99. package/foundation/integrations/autolink.d.mts +1 -24
  100. package/foundation/integrations/autolink.mjs +7 -60
  101. package/foundation/integrations/declared-dependencies.d.mts +27 -0
  102. package/foundation/integrations/declared-dependencies.mjs +73 -0
  103. package/foundation/integrations/may-have-integrations.d.mts +8 -0
  104. package/foundation/integrations/may-have-integrations.mjs +47 -0
  105. package/foundation/release/cache.d.mts +21 -2
  106. package/foundation/release/cache.mjs +48 -8
  107. package/foundation/release/folder-lock.d.mts +7 -0
  108. package/foundation/release/folder-lock.mjs +60 -26
  109. package/foundation/release/lock-lease.d.mts +2 -1
  110. package/foundation/release/lock-lease.mjs +7 -2
  111. package/foundation/response/error-codes.doc.mjs +1 -1
  112. package/foundation/response/response-types.doc.mjs +4 -4
  113. package/package.json +6 -6
  114. package/api/theme-edit/_css-properties.d.mts +0 -10
  115. package/api/theme-edit/_css-properties.mjs +0 -556
@@ -15,18 +15,24 @@
15
15
  * @position api/theme-edit — imported by _settings.mjs, _check.mjs, _how.mjs
16
16
  */
17
17
 
18
- import {createHash} from 'node:crypto';
19
18
  import * as fs from 'node:fs';
20
19
  import * as path from 'node:path';
21
20
  import {isAlive} from '../../foundation/release/cache.mjs';
21
+ import {stillHolds} from '../../foundation/release/folder-lock.mjs';
22
22
  import {AstryxError} from '../error.mjs';
23
23
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
24
+ import {parse} from '@babel/parser';
25
+ import {THEMES_DIR} from '../../foundation/discovery/theme-discovery.mjs';
24
26
  import {
27
+ ANCHOR_INPUT_KEYS,
25
28
  DEFAULT_21_STOPS,
29
+ FAMILY_INPUT_KEYS,
30
+ GENERATION_INPUT_KEYS,
26
31
  PALETTE_BLACK,
27
32
  PALETTE_GENERATOR_VERSION,
28
33
  PALETTE_WHITE,
29
34
  generateTonalPalette,
35
+ modesForStrategy,
30
36
  perceptualDelta,
31
37
  } from '../theme/palette/generate/generator.mjs';
32
38
  import {themePaletteGenerate} from '../theme/palette/generate/generate.mjs';
@@ -40,6 +46,8 @@ import {
40
46
  ratio,
41
47
  } from './_color.mjs';
42
48
  import {P} from './_tables.mjs';
49
+ import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
50
+ import {sha256} from '../../foundation/render/source-block.mjs';
43
51
 
44
52
  /**
45
53
  * Write a file whole: a temp file beside it, renamed into place, so a link
@@ -54,10 +62,17 @@ export function writeWhole(file, text) {
54
62
  if (fs.lstatSync(file, {throwIfNoEntry: false})?.isDirectory())
55
63
  throw new AstryxError(
56
64
  `${[path.dirname(path.dirname(file)), path.dirname(file), file].map(p => path.basename(p)).join('/')} is a folder, so the editor cannot write that file there. Rename or move the folder, then run the command again.`,
57
- [],
65
+ [
66
+ {
67
+ name: `ls -la ${quoteCommandArgument(file)}`,
68
+ reason:
69
+ 'see what is in the folder; move or rename it, then run the same command again',
70
+ },
71
+ ],
58
72
  ERROR_CODES.ERR_WRITE_FAILED,
59
73
  );
60
74
  sweepTemps(path.dirname(file));
75
+ refuseIfLockLost();
61
76
  const tmp = tempFor(file);
62
77
  try {
63
78
  fs.writeFileSync(tmp, text);
@@ -67,19 +82,43 @@ export function writeWhole(file, text) {
67
82
  }
68
83
  }
69
84
 
70
- /** Folders swept of left temp files in this run. */
71
- const swept = new Set();
85
+ /**
86
+ * A command stopped long enough for another to take its lock (Ctrl-Z, a
87
+ * sleeping computer, a debugger) writes nothing more: refuse. Called right
88
+ * before each write.
89
+ */
90
+ export function refuseIfLockLost() {
91
+ if (lockHeld()) return;
92
+ const error = new AstryxError(
93
+ `Another command took over the theme's lock while this one was stopped (Ctrl-Z, a sleeping computer, a debugger). This command's change was not applied, and it touched nothing more: the files stay as the other command left them. Run it again if you still want it.`,
94
+ [{name: `${P} how --list dials`, reason: 'what you can set'}],
95
+ ERROR_CODES.ERR_THEME_BUSY,
96
+ );
97
+ /** @type {any} */ (error).lockLost = true;
98
+ throw error;
99
+ }
100
+
101
+ /** Whether this command still holds its lock (true outside a lock). */
102
+ export function lockHeld() {
103
+ try {
104
+ stillHolds();
105
+ return true;
106
+ } catch {
107
+ return false;
108
+ }
109
+ }
110
+
111
+ /** When this process started, for telling its own temp files from an earlier one's with the same id. */
112
+ const STARTED_AT = Date.now() - process.uptime() * 1000;
72
113
 
73
114
  /**
74
115
  * Remove the editor's own temp files a stopped command left in a folder:
75
- * only names the editor makes (`.<name>.astryx-<pid>-<random>.tmp`), whose
76
- * process is gone and that are more than ten minutes old. Links are never
77
- * followed. Once per folder per run.
116
+ * only names the editor makes (`.<name>.astryx-<pid>-<random>.tmp`) whose
117
+ * process is gone, or that are older than ten minutes. Links are never
118
+ * followed. A theme folder holds a few files, so every write looks.
78
119
  * @param {string} dir
79
120
  */
80
121
  function sweepTemps(dir) {
81
- if (swept.has(dir)) return;
82
- swept.add(dir);
83
122
  let names;
84
123
  try {
85
124
  names = fs.readdirSync(dir);
@@ -88,12 +127,25 @@ function sweepTemps(dir) {
88
127
  }
89
128
  for (const n of names) {
90
129
  const m = /^\..+\.astryx-(\d+)-[a-z0-9]+\.tmp$/.exec(n);
91
- if (!m || Number(m[1]) === process.pid) continue;
130
+ if (!m) continue;
92
131
  const p = path.join(dir, n);
93
132
  try {
94
133
  const st = fs.lstatSync(p);
95
- if (!st.isFile() || Date.now() - st.mtimeMs < 10 * 60_000) continue;
96
- if (isAlive(Number(m[1]))) continue;
134
+ // Writes into a theme folder run under its lock, so a temp file
135
+ // whose process is gone is never one a live command still renames.
136
+ if (!st.isFile()) continue;
137
+ // A process id from another process space (pid 1 in a container)
138
+ // may look alive here: past ten minutes, an editor temp file is a
139
+ // leftover whatever its id says (a live writer renames it in
140
+ // moments, and holds the lock this write holds now).
141
+ // A temp named with this process's own id but older than this process
142
+ // is another one's (pid 1 in each container start).
143
+ const own = Number(m[1]) === process.pid;
144
+ const young = Date.now() - st.mtimeMs < 10 * 60_000;
145
+ if (
146
+ own ? st.mtimeMs >= STARTED_AT && young : isAlive(Number(m[1])) && young
147
+ )
148
+ continue;
97
149
  fs.rmSync(p, {force: true});
98
150
  } catch {
99
151
  // Gone already, or not ours to judge.
@@ -101,6 +153,24 @@ function sweepTemps(dir) {
101
153
  }
102
154
  }
103
155
 
156
+ /**
157
+ * Remove `dir` when it is empty; with `deep`, the empty folders under it
158
+ * first. A folder with a file in it stays.
159
+ * @param {string} dir
160
+ * @param {{deep?: boolean}} [opts]
161
+ */
162
+ export function removeEmptyFolder(dir, opts = {}) {
163
+ if (!fs.existsSync(dir)) return;
164
+ if (opts.deep)
165
+ for (const e of fs.readdirSync(dir, {withFileTypes: true}))
166
+ if (e.isDirectory()) removeEmptyFolder(path.join(dir, e.name), opts);
167
+ try {
168
+ fs.rmdirSync(dir);
169
+ } catch {
170
+ // Not empty, or gone already.
171
+ }
172
+ }
173
+
104
174
  /**
105
175
  * A temp file beside `file` for a whole write, named so only the editor
106
176
  * makes such names: `.<name>.astryx-<pid>-<random>.tmp`. The write that
@@ -209,64 +279,134 @@ const TEXT = 4.5;
209
279
  const NON_TEXT = 3;
210
280
 
211
281
  /**
212
- * The stop each token starts from, `[light, dark]`, as the official neutral
213
- * theme maps them. The page background, `--color-background-body`, stays
214
- * the base theme's, so a tinted gray never tints the page. A layout without
215
- * one of these stops uses the nearest one it has.
282
+ * The official neutral theme's color mapping, read from the theme the CLI
283
+ * ships rather than copied: each token's stops, `[light, dark]`, written
284
+ * there as `<family>.<mode>[N]` or `withAlpha(<family>.<mode>[N], 'aa')`,
285
+ * and the parts whose secondary text it lifts (`[part, block]`).
286
+ * @returns {{stops: Record<string, Array<{stop: number, alpha?: string}>>, lifted: Array<[string, string]>}}
216
287
  */
217
- const NEUTRAL_STOPS = /** @type {Record<string, [number, number]>} */ ({
218
- '--color-background-surface': [100, 15],
219
- '--color-background-card': [100, 10],
220
- '--color-background-popover': [100, 10],
221
- '--color-background-muted': [95, 10],
222
- '--color-text-primary': [0, 100],
223
- '--color-text-secondary': [30, 65],
224
- '--color-text-disabled': [60, 35],
225
- '--color-icon-primary': [0, 100],
226
- '--color-icon-secondary': [45, 65],
227
- '--color-icon-disabled': [60, 35],
228
- '--color-border-emphasized': [85, 35],
229
- '--color-skeleton': [95, 35],
230
- });
288
+ function readOfficialNeutral() {
289
+ const ast = parse(
290
+ fs.readFileSync(
291
+ path.join(THEMES_DIR, 'neutral', 'neutralTheme.ts'),
292
+ 'utf8',
293
+ ),
294
+ {sourceType: 'module', plugins: ['typescript']},
295
+ );
296
+ /** @param {any} n @returns {{stop: number, alpha?: string} | null} */
297
+ const stopOf = n => {
298
+ if (n?.type === 'CallExpression' && n.callee?.name === 'withAlpha') {
299
+ const inner = stopOf(n.arguments[0]);
300
+ const alpha = n.arguments[1]?.value;
301
+ return inner && typeof alpha === 'string'
302
+ ? {...inner, alpha: alpha.toLowerCase()}
303
+ : null;
304
+ }
305
+ return n?.type === 'MemberExpression' &&
306
+ n.computed &&
307
+ n.property.type === 'NumericLiteral' &&
308
+ ['light', 'dark'].includes(n.object?.property?.name)
309
+ ? {stop: n.property.value}
310
+ : null;
311
+ };
312
+ /** @type {Record<string, Array<{stop: number, alpha?: string}>>} */
313
+ const stops = {};
314
+ /** @type {Array<[string, string]>} */
315
+ const lifted = [];
316
+ /** @param {any} node @param {string[]} keys */
317
+ const visit = (node, keys) => {
318
+ if (!node || typeof node !== 'object') return;
319
+ if (node.type === 'ObjectProperty') {
320
+ const key = node.key.name ?? node.key.value;
321
+ const at = [...keys, String(key)];
322
+ if (keys.at(-1) === 'tokens' && node.value.type === 'ArrayExpression') {
323
+ const pair = node.value.elements.map(stopOf);
324
+ if (pair.length === 2 && pair.every(Boolean)) stops[key] = pair;
325
+ }
326
+ if (keys.at(-3) === 'components' && key === '--color-text-secondary')
327
+ lifted.push([keys.at(-2) ?? '', keys.at(-1) ?? '']);
328
+ visit(node.value, at);
329
+ return;
330
+ }
331
+ for (const [k, v] of Object.entries(node))
332
+ if (k !== 'loc' && k !== 'start' && k !== 'end')
333
+ for (const x of Array.isArray(v) ? v : [v]) visit(x, keys);
334
+ };
335
+ visit(ast.program, []);
336
+ return {stops, lifted};
337
+ }
338
+ const OFFICIAL = readOfficialNeutral();
339
+ /** A token's official `[light, dark]` stops. @param {string} token */
340
+ const officialStops = token =>
341
+ /** @type {[number, number]} */ (
342
+ (OFFICIAL.stops[token] ?? []).map(x => x.stop)
343
+ );
344
+
345
+ /**
346
+ * The tokens the neutral color sets at the official theme's stops. The page
347
+ * background, `--color-background-body`, stays the base theme's, so a
348
+ * tinted gray never tints the page. A layout without one of these stops
349
+ * uses the nearest one it has.
350
+ */
351
+ const NEUTRAL_STOPS = Object.fromEntries(
352
+ [
353
+ '--color-background-surface',
354
+ '--color-background-card',
355
+ '--color-background-popover',
356
+ '--color-background-muted',
357
+ '--color-text-primary',
358
+ '--color-text-secondary',
359
+ '--color-text-disabled',
360
+ '--color-icon-primary',
361
+ '--color-icon-secondary',
362
+ '--color-icon-disabled',
363
+ '--color-border-emphasized',
364
+ '--color-skeleton',
365
+ ].map(t => [t, officialStops(t)]),
366
+ );
231
367
  /** Neutral tints: a stop with an opacity, `[[stop, alpha], [stop, alpha]]`. */
232
- const NEUTRAL_TINTS =
233
- /** @type {Record<string, [[number, string], [number, string]]>} */ ({
234
- '--color-border': [
235
- [0, '14'],
236
- [100, '1a'],
237
- ],
238
- '--color-overlay-hover': [
239
- [0, '0d'],
240
- [100, '0d'],
241
- ],
242
- '--color-overlay-pressed': [
243
- [0, '1a'],
244
- [100, '1a'],
368
+ const NEUTRAL_TINTS = Object.fromEntries(
369
+ ['--color-border', '--color-overlay-hover', '--color-overlay-pressed'].map(
370
+ t => [
371
+ t,
372
+ /** @type {[[number, string], [number, string]]} */ (
373
+ OFFICIAL.stops[t].map(x => [x.stop, String(x.alpha)])
374
+ ),
245
375
  ],
246
- });
376
+ ),
377
+ );
247
378
  /**
248
379
  * Accent and status stops, `[light, dark]`, as the official neutral theme
249
- * maps its accent tint and its status families. The dark fill starts at 70,
250
- * where the theme authoring guide puts it, when the exact color does not
251
- * read in dark. A status tint is translucent in dark (`[stop, alpha]`).
380
+ * maps its accent tint and its status families (info stands for them). The
381
+ * dark fill starts at 70, where the theme authoring guide puts it, when the
382
+ * exact color does not read in dark. A status tint is translucent in dark
383
+ * (`[stop, alpha]`).
252
384
  */
253
385
  const DARK_FILL = 70;
254
- const TEXT_STOP = /** @type {[number, number]} */ ([45, 80]);
255
- const ACCENT_MUTED = /** @type {[number, number]} */ ([85, 30]);
386
+ const TEXT_STOP = officialStops('--color-text-info');
387
+ const ACCENT_MUTED = officialStops('--color-accent-muted');
388
+ const STATUS_MUTED = /** @type {[number, [number, string]]} */ (
389
+ OFFICIAL.stops['--color-info-muted'].map((x, i) =>
390
+ i === 0 ? x.stop : [x.stop, String(x.alpha)],
391
+ )
392
+ );
393
+ const ON_MUTED = officialStops('--color-on-info-muted');
256
394
  /**
257
395
  * The parts whose secondary text the official neutral theme lifts, with
258
- * the block it lifts it in and what the text sits on: the accent tint
259
- * under selected items and tree rows, a dropzone and numbered citations;
260
- * the translucent neutral track (`--color-neutral`) under segmented-control
261
- * labels.
396
+ * the block it lifts it in and what the text sits on: the accent tint,
397
+ * except under segmented-control labels, which sit on the translucent
398
+ * neutral track (`--color-neutral`).
262
399
  */
263
- export const LIFT_PARTS = /** @type {Array<[string, string, string]>} */ ([
264
- ['item', 'selected', '--color-accent-muted'],
265
- ['tree-list-item', 'selected', '--color-accent-muted'],
266
- ['file-input', 'mode:dropzone', '--color-accent-muted'],
267
- ['citation', 'variant:number', '--color-accent-muted'],
268
- ['segmented-control-item', 'base', '--color-neutral'],
269
- ]);
400
+ export const LIFT_PARTS = OFFICIAL.lifted.map(
401
+ ([part, block]) =>
402
+ /** @type {[string, string, string]} */ ([
403
+ part,
404
+ block,
405
+ part === 'segmented-control-item'
406
+ ? '--color-neutral'
407
+ : '--color-accent-muted',
408
+ ]),
409
+ );
270
410
  /** What each lifted background is, and the parts on it, for notes. */
271
411
  const LIFT_GROUNDS =
272
412
  /** @type {Record<string, {what: string, parts: string}>} */ ({
@@ -279,20 +419,16 @@ const LIFT_GROUNDS =
279
419
  parts: 'segmented-control labels',
280
420
  },
281
421
  });
282
- const STATUS_MUTED = /** @type {[number, [number, string]]} */ ([
283
- 85,
284
- [75, '3d'],
285
- ]);
286
- const ON_MUTED = /** @type {[number, number]} */ ([25, 80]);
287
422
  const BORDER = /** @type {[number, number]} */ ([80, 65]);
288
423
  /**
289
424
  * Text on a fill, from the neutral family as the official themes take it:
290
425
  * white (100) first in light, near-black (5) first in dark, and near-black
291
426
  * first in both modes on warning. Without a neutral color, black and white.
292
427
  */
428
+ const [ON_LIGHT, ON_DARK] = officialStops('--color-on-accent');
293
429
  const ON_FILL = /** @type {Record<Mode, [number, number]>} */ ({
294
- light: [100, 5],
295
- dark: [5, 100],
430
+ light: [ON_LIGHT, ON_DARK],
431
+ dark: [ON_DARK, ON_LIGHT],
296
432
  });
297
433
  /** A layout needs this many stops between black and white to map every token. */
298
434
  const MIN_INNER_STOPS = 5;
@@ -365,11 +501,11 @@ function sameColor(a, b) {
365
501
  * @returns {Mode[]}
366
502
  */
367
503
  export function modesOf(data) {
368
- return data.mode === 'light-only'
369
- ? ['light']
370
- : data.mode === 'dark-only'
371
- ? ['dark']
372
- : ['light', 'dark'];
504
+ return modesForStrategy(
505
+ data.mode === 'light-only' || data.mode === 'dark-only'
506
+ ? data.mode
507
+ : 'light-and-dark',
508
+ );
373
509
  }
374
510
 
375
511
  /**
@@ -463,17 +599,6 @@ function savedSettings(cwd, slug) {
463
599
  const strategyOf = modes =>
464
600
  modes.length > 1 ? 'light-and-dark' : `${modes[0]}-only`;
465
601
 
466
- /** The config fields the generator reads; anything else changes nothing. */
467
- const CONFIG_KEYS = [
468
- 'vibrancy',
469
- 'neutralProfile',
470
- 'modeStrategy',
471
- 'stops',
472
- 'families',
473
- ];
474
- const FAMILY_KEYS = ['id', 'name', 'seed', 'kind', 'anchors'];
475
- const ANCHOR_KEYS = ['mode', 'stop', 'color', 'policy', 'maxDeltaE'];
476
-
477
602
  /**
478
603
  * The fields of a config the generator never reads (such as
479
604
  * `darkChromaTaper`), by path.
@@ -482,17 +607,19 @@ const ANCHOR_KEYS = ['mode', 'stop', 'color', 'policy', 'maxDeltaE'];
482
607
  */
483
608
  function deadKeys(config) {
484
609
  /** @type {string[]} */
485
- const out = Object.keys(config).filter(k => !CONFIG_KEYS.includes(k));
610
+ const out = Object.keys(config).filter(
611
+ k => !GENERATION_INPUT_KEYS.includes(k),
612
+ );
486
613
  (Array.isArray(config.families) ? config.families : []).forEach(
487
614
  (/** @type {any} */ f, /** @type {number} */ i) => {
488
615
  if (!f || typeof f !== 'object') return;
489
616
  for (const k of Object.keys(f))
490
- if (!FAMILY_KEYS.includes(k)) out.push(`families[${i}].${k}`);
617
+ if (!FAMILY_INPUT_KEYS.includes(k)) out.push(`families[${i}].${k}`);
491
618
  (Array.isArray(f.anchors) ? f.anchors : []).forEach(
492
619
  (/** @type {any} */ a, /** @type {number} */ j) => {
493
620
  if (a && typeof a === 'object')
494
621
  for (const k of Object.keys(a))
495
- if (!ANCHOR_KEYS.includes(k))
622
+ if (!ANCHOR_INPUT_KEYS.includes(k))
496
623
  out.push(`families[${i}].anchors[${j}].${k}`);
497
624
  },
498
625
  );
@@ -562,7 +689,7 @@ function usableStops(stops, slug) {
562
689
  const refuse = why => {
563
690
  throw new AstryxError(
564
691
  `themes/${slug}/palette.config.json: its stops (${shown}) ${why}. ${fix}`,
565
- [],
692
+ [{name: `${P} how colors`, reason: 'how the shades are made'}],
566
693
  ERROR_CODES.ERR_THEME_INVALID,
567
694
  );
568
695
  };
@@ -970,7 +1097,7 @@ function planPalette(cwd, slug, data, base) {
970
1097
  // same bytes.
971
1098
  /** @type {Record<string, unknown>} */
972
1099
  const ordered = {};
973
- for (const k of FAMILY_KEYS) if (k in out) ordered[k] = out[k];
1100
+ for (const k of FAMILY_INPUT_KEYS) if (k in out) ordered[k] = out[k];
974
1101
  for (const k of Object.keys(out)) if (!(k in ordered)) ordered[k] = out[k];
975
1102
  return {family: /** @type {typeof out} */ (ordered), stop};
976
1103
  };
@@ -1084,9 +1211,6 @@ export function paletteConfig(cwd, slug, data, base) {
1084
1211
  return planPalette(cwd, slug, data, base)?.config ?? null;
1085
1212
  }
1086
1213
 
1087
- /** @param {string} text */
1088
- const sha256 = text => createHash('sha256').update(text).digest('hex');
1089
-
1090
1214
  /**
1091
1215
  * Write the palette config, palette and receipt the settings ask for, with
1092
1216
  * the same generator as `theme palette generate --out`; remove them all
@@ -1140,7 +1264,7 @@ function syncPaletteFiles(cwd, slug, data, base) {
1140
1264
  saved = undefined;
1141
1265
  }
1142
1266
  const hash = fs.existsSync(abs(f.config))
1143
- ? sha256(fs.readFileSync(abs(f.config), 'utf8'))
1267
+ ? sha256(fs.readFileSync(abs(f.config)))
1144
1268
  : null;
1145
1269
  const mine = hash != null && (data.palette === hash || saved === hash);
1146
1270
  delete data.palette;
@@ -1181,7 +1305,7 @@ function syncPaletteFiles(cwd, slug, data, base) {
1181
1305
  // Nothing to rewrite: no notes either, so a kept hand edit is named once,
1182
1306
  // when a color change touches the config.
1183
1307
  if (same) {
1184
- data.palette = sha256(text);
1308
+ data.palette = sha256(Buffer.from(text));
1185
1309
  // The theme reads only the selected shades, which come from the
1186
1310
  // generator, so a hand edit to the palette file never shows: say so.
1187
1311
  return paletteEdited(cwd, slug)
@@ -1204,7 +1328,7 @@ function syncPaletteFiles(cwd, slug, data, base) {
1204
1328
  }
1205
1329
  fs.mkdirSync(path.dirname(abs(f.config)), {recursive: true});
1206
1330
  writeWhole(abs(f.config), text);
1207
- data.palette = sha256(text);
1331
+ data.palette = sha256(Buffer.from(text));
1208
1332
  themePaletteGenerate(f.config, {out: f.palette, overwrite: true}, {cwd});
1209
1333
  return plan.notes;
1210
1334
  }
@@ -1319,6 +1443,14 @@ function samePalette(a, b) {
1319
1443
  return flat(a) === flat(b);
1320
1444
  }
1321
1445
 
1446
+ /**
1447
+ * The first line of the empty palette module the preview writes for a
1448
+ * Colors page it keeps (changed by hand) once the theme has no colors, so
1449
+ * the app still builds. The editor replaces it freely.
1450
+ */
1451
+ export const PALETTE_STAND_IN =
1452
+ '// A stand-in for a preview page that imports this file: the theme has no generated colors.';
1453
+
1322
1454
  /**
1323
1455
  * Whether a theme's palette file was edited by hand. Its bytes match its
1324
1456
  * receipt, or its colors (read as data, so formatting, a BOM or semicolons
@@ -1335,6 +1467,8 @@ export function paletteEdited(cwd, slug) {
1335
1467
  const file = path.join(cwd, f.palette);
1336
1468
  if (!fs.existsSync(file)) return false;
1337
1469
  const text = fs.readFileSync(file, 'utf8');
1470
+ // The empty stand-in a kept preview page imports is the editor's own.
1471
+ if (text.startsWith(PALETTE_STAND_IN)) return false;
1338
1472
  /** @type {any} */
1339
1473
  let receipt;
1340
1474
  try {
@@ -1342,7 +1476,7 @@ export function paletteEdited(cwd, slug) {
1342
1476
  } catch {
1343
1477
  receipt = null;
1344
1478
  }
1345
- if (receipt?.candidateSha256 === sha256(text)) return false;
1479
+ if (receipt?.candidateSha256 === sha256(Buffer.from(text))) return false;
1346
1480
  const data = paletteData(text);
1347
1481
  if (!data) return true;
1348
1482
  /** @type {any} */
@@ -1357,7 +1491,7 @@ export function paletteEdited(cwd, slug) {
1357
1491
  'utf8',
1358
1492
  ),
1359
1493
  )?.palette;
1360
- configMine = saved == null || saved === sha256(configText);
1494
+ configMine = saved == null || saved === sha256(Buffer.from(configText));
1361
1495
  request = JSON.parse(configText.replace(/^\uFEFF/, ''));
1362
1496
  } catch {
1363
1497
  request = null;
@@ -1525,7 +1659,7 @@ function generate(config, file = 'palette.config.json') {
1525
1659
  } catch (e) {
1526
1660
  throw new AstryxError(
1527
1661
  `${file}: the colors could not be generated: ${(e instanceof Error ? e.message : String(e)).replace(/\.$/, '')}. Fix that part of the file by hand, or remove it. Nothing was changed.`,
1528
- [],
1662
+ [{name: `${P} how colors`, reason: 'how the colors are made'}],
1529
1663
  ERROR_CODES.ERR_PALETTE_GENERATION,
1530
1664
  );
1531
1665
  }
@@ -2,20 +2,45 @@
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
4
  /**
5
- * @typedef {object} PartRecord
6
- * @property {Record<string, {tokens: Record<string, string[]>, values: string[]}>} own - property -> tokens (with conditions) and raw values
7
- * @property {Record<string, string[]>} inside - tokens read by unnamed elements inside the part -> properties
8
- * @property {Record<string, string[]>} attrs - data attributes seen on the part
9
- * @property {string[]} contains - parts rendered inside it
5
+ * The props a component renders with: its doc's playground defaults, or,
6
+ * for a doc with none (an older Core), a sample for each required prop.
7
+ * A group with no children gets three of the items its doc suggests. Null
8
+ * for a doc with no defaults that has no theming targets (a hook or a
9
+ * helper), or that is a part its parent lists as an item: it works only
10
+ * inside the parent, whose own entry shows it.
11
+ * @param {import('./_project.mjs').ThemeProject} project
12
+ * @param {string} name
13
+ * @returns {Record<string, unknown> | null}
14
+ */
15
+ export function demoProps(project: import("./_project.mjs").ThemeProject, name: string): Record<string, unknown> | null;
16
+ /**
17
+ * Whether a part's parent lists it as an item of its children.
18
+ * @param {import('./_project.mjs').ThemeProject} project
19
+ * @param {string} name
10
20
  */
21
+ export function isItemOf(project: import("./_project.mjs").ThemeProject, name: string): boolean;
11
22
  /**
12
- * @typedef {{target: string | null, tokens: string[], raw: string | null}} PaintSide
13
- * @typedef {{text: string, fg: PaintSide, bg: PaintSide, sample: string}} TextPair
14
- * @typedef {{version: number, coreKey: string, map: Record<string, PartRecord>, pairs: TextPair[], rendered: number, items: number}} PartData
23
+ * A component's catalog entries, all from its doc: its demo props
24
+ * ({@link demoProps}), then once per value of each visual prop with a
25
+ * closed set of values (`variant`, `status`, `color`, and a number union
26
+ * such as a heading's level), and its checked and disabled states. An
27
+ * overlay the playground shows in place renders open; on a page people
28
+ * see, once, as some of its variants size the window, not the card.
29
+ * @param {import('./_project.mjs').ThemeProject} project
30
+ * @param {string} name
31
+ * @param {number} cap at most this many
32
+ * @param {{shown?: boolean}} [opts] `shown`: for a page people see
33
+ * @returns {Array<{label: string, props: Record<string, unknown>}>}
15
34
  */
35
+ export function catalogVariants(project: import("./_project.mjs").ThemeProject, name: string, cap: number, opts?: {
36
+ shown?: boolean;
37
+ }): Array<{
38
+ label: string;
39
+ props: Record<string, unknown>;
40
+ }>;
16
41
  /**
17
- * The catalog: each component with playground defaults once per visual
18
- * variant value, the hand-made extras, and the sample page.
42
+ * The catalog: each component with playground defaults, once per visual
43
+ * variant value ({@link catalogVariants}), and the sample page.
19
44
  * @param {import('./_project.mjs').ThemeProject} project
20
45
  * @returns {{items: import('./_catalog.mjs').CatalogItem[], imports: Record<string, string>}}
21
46
  */
@@ -23,6 +48,13 @@ export function catalogItems(project: import("./_project.mjs").ThemeProject): {
23
48
  items: import("./_catalog.mjs").CatalogItem[];
24
49
  imports: Record<string, string>;
25
50
  };
51
+ /**
52
+ * What of React the project cannot resolve (react, react-dom/server), to
53
+ * render the editor's pages; empty when both resolve.
54
+ * @param {string} cwd
55
+ * @returns {string[]}
56
+ */
57
+ export function reactMissing(cwd: string): string[];
26
58
  /**
27
59
  * Render a generated page module and give its HTML and markup (the body,
28
60
  * without the embedded source block).