@astryxdesign/cli 0.7.15 → 0.7.16-canary.g54dd64e

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 (123) hide show
  1. package/README.md +5 -3
  2. package/api/component/_adapter.d.mts +1 -1
  3. package/api/component/_adapter.mjs +28 -1
  4. package/api/doctor/_adapter.d.mts +17 -0
  5. package/api/doctor/_adapter.mjs +35 -0
  6. package/api/doctor/doctor.mjs +18 -4
  7. package/api/integration/pack-check.mjs +13 -7
  8. package/api/integration/validate-integration.mjs +1 -1
  9. package/api/theme/_adapter.d.mts +5 -2
  10. package/api/theme/_adapter.mjs +43 -12
  11. package/api/theme/build/build.d.mts +64 -27
  12. package/api/theme/build/build.mjs +341 -69
  13. package/api/theme/eject/eject.mjs +22 -1
  14. package/api/theme/template/template.d.mts +19 -0
  15. package/api/theme/template/template.mjs +102 -25
  16. package/api/theme/theme.type.d.mts +5 -1
  17. package/api/theme/theme.type.mjs +2 -1
  18. package/api/theme/themeBuild.doc.mjs +3 -3
  19. package/api/theme/themeEject.doc.mjs +1 -1
  20. package/api/theme/themeTemplate.doc.mjs +9 -3
  21. package/api/theme-edit/_adapter.d.mts +33 -0
  22. package/api/theme-edit/_adapter.mjs +208 -31
  23. package/api/theme-edit/_check.d.mts +38 -0
  24. package/api/theme-edit/_check.mjs +1326 -211
  25. package/api/theme-edit/_color.d.mts +2 -8
  26. package/api/theme-edit/_color.mjs +292 -219
  27. package/api/theme-edit/_compiler.d.mts +1 -0
  28. package/api/theme-edit/_compiler.mjs +20 -1
  29. package/api/theme-edit/_context.d.mts +29 -0
  30. package/api/theme-edit/_context.mjs +329 -30
  31. package/api/theme-edit/_css.d.mts +60 -1
  32. package/api/theme-edit/_css.mjs +404 -28
  33. package/api/theme-edit/_edit.d.mts +9 -0
  34. package/api/theme-edit/_edit.mjs +1025 -126
  35. package/api/theme-edit/_how-commands.d.mts +11 -26
  36. package/api/theme-edit/_how-commands.mjs +30 -2
  37. package/api/theme-edit/_how-question.d.mts +7 -0
  38. package/api/theme-edit/_how-question.mjs +1304 -176
  39. package/api/theme-edit/_how.mjs +144 -30
  40. package/api/theme-edit/_overview.mjs +2 -0
  41. package/api/theme-edit/_palette.d.mts +11 -0
  42. package/api/theme-edit/_palette.mjs +194 -65
  43. package/api/theme-edit/_parts.d.mts +16 -0
  44. package/api/theme-edit/_parts.mjs +59 -7
  45. package/api/theme-edit/_png.mjs +19 -14
  46. package/api/theme-edit/_preview-app.d.mts +3 -0
  47. package/api/theme-edit/_preview-app.mjs +843 -45
  48. package/api/theme-edit/_preview.d.mts +16 -3
  49. package/api/theme-edit/_preview.mjs +310 -29
  50. package/api/theme-edit/_project.d.mts +11 -0
  51. package/api/theme-edit/_project.mjs +46 -12
  52. package/api/theme-edit/_settings.d.mts +178 -5
  53. package/api/theme-edit/_settings.mjs +2035 -86
  54. package/api/theme-edit/_tables.d.mts +24 -0
  55. package/api/theme-edit/_tables.mjs +211 -149
  56. package/api/theme-edit/_vet.d.mts +42 -0
  57. package/api/theme-edit/_vet.mjs +144 -0
  58. package/api/theme-edit/theme-edit.type.d.mts +2 -1
  59. package/api/theme-edit/theme-edit.type.mjs +1 -1
  60. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  61. package/api/theme-edit/themeEditShow.doc.mjs +11 -3
  62. package/api/upgrade/registry/registry.mjs +6 -1
  63. package/assets/docs/tree/single-component.doc.mjs +11 -2
  64. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  65. package/assets/docs.generated.json +2 -2
  66. package/assets/preview-app/next.config.mjs +7 -1
  67. package/assets/preview-app/package.json +1 -0
  68. package/assets/preview-app/src/app/globals.css +1 -0
  69. package/assets/self-audit.generated.json +1 -1
  70. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
  71. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
  72. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
  73. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
  74. package/assets/templates/components.generated.json +1 -1
  75. package/assets/templates/pages/dashboard/page.tsx +1 -1
  76. package/authoring/doctypes/_schema.d.mts +52 -5
  77. package/authoring/doctypes/_schema.mjs +62 -7
  78. package/authoring/doctypes/base/type.ts +10 -0
  79. package/authoring/doctypes/component/component.doc.mjs +1 -1
  80. package/authoring/doctypes/function/function.doc.mjs +6 -0
  81. package/authoring/doctypes/function/type.ts +3 -0
  82. package/authoring/doctypes/legacy.mjs +5 -1
  83. package/authoring/index.d.ts +1 -0
  84. package/clients/cli/build-id.generated.json +1 -1
  85. package/clients/cli/commands/doctor.doc.mjs +2 -2
  86. package/clients/cli/commands/experimental/theme.mjs +190 -37
  87. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  88. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
  89. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
  90. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  91. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  92. package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
  93. package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
  94. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  95. package/clients/cli/commands/theme-eject.doc.mjs +1 -1
  96. package/clients/cli/commands/theme-template.doc.mjs +3 -1
  97. package/clients/cli/commands/theme.mjs +168 -45
  98. package/clients/cli/formatters/index.mjs +7 -4
  99. package/clients/cli/lib/cli-error.mjs +9 -3
  100. package/clients/cli/lib/component-format.mjs +27 -9
  101. package/clients/cli/lib/json-shim.mjs +40 -2
  102. package/clients/cli/manifest.generated.json +1 -1
  103. package/clients/cli/run.mjs +49 -0
  104. package/foundation/config/project.mjs +50 -14
  105. package/foundation/discovery/theme-discovery.d.mts +5 -1
  106. package/foundation/discovery/theme-discovery.mjs +24 -3
  107. package/foundation/fs/gather-cache.d.mts +9 -2
  108. package/foundation/fs/gather-cache.mjs +79 -15
  109. package/foundation/fs/paths.d.mts +31 -0
  110. package/foundation/fs/paths.mjs +43 -10
  111. package/foundation/render/host-exit.d.mts +8 -0
  112. package/foundation/render/host-exit.mjs +11 -0
  113. package/foundation/render/page-host.mjs +56 -10
  114. package/foundation/render/page-worker.mjs +14 -0
  115. package/foundation/render/render-page.mjs +37 -2
  116. package/foundation/response/error-codes.d.mts +2 -1
  117. package/foundation/response/error-codes.d.ts +1 -0
  118. package/foundation/response/error-codes.doc.mjs +5 -0
  119. package/foundation/response/error-codes.mjs +3 -0
  120. package/foundation/response/json.d.mts +15 -0
  121. package/foundation/response/json.mjs +52 -1
  122. package/foundation/response/response-types.doc.mjs +1 -1
  123. package/package.json +7 -6
@@ -36,6 +36,20 @@ import {
36
36
  perceptualDelta,
37
37
  } from '../theme/palette/generate/generator.mjs';
38
38
  import {themePaletteGenerate} from '../theme/palette/generate/generate.mjs';
39
+ /**
40
+ * How the page-wide tokens a theme's own source sets are read: given by
41
+ * _settings (which imports this module) when it loads.
42
+ * @type {(cwd: string, slug: string) => Record<string, string>}
43
+ */
44
+ let ownSourceTokenValues = () => ({});
45
+
46
+ /**
47
+ * Give the reader of the tokens a theme's own source sets.
48
+ * @param {(cwd: string, slug: string) => Record<string, string>} read
49
+ */
50
+ export function setOwnTokenReader(read) {
51
+ ownSourceTokenValues = read;
52
+ }
39
53
  import {hexToOklch, normalizeColor} from '../theme/palette/generate/color.mjs';
40
54
  import {
41
55
  alphaOf,
@@ -45,7 +59,8 @@ import {
45
59
  parseColor,
46
60
  ratio,
47
61
  } from './_color.mjs';
48
- import {P} from './_tables.mjs';
62
+ import {splitTop} from './_css.mjs';
63
+ import {P, wordTable} from './_tables.mjs';
49
64
  import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
50
65
  import {sha256} from '../../foundation/render/source-block.mjs';
51
66
 
@@ -114,7 +129,8 @@ const STARTED_AT = Date.now() - process.uptime() * 1000;
114
129
  /**
115
130
  * Remove the editor's own temp files a stopped command left in a folder:
116
131
  * 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
132
+ * process is gone, or that are older than ten minutes, and a build's
133
+ * `.<name>.tmp-<id>` older than ten minutes. Links are never
118
134
  * followed. A theme folder holds a few files, so every write looks.
119
135
  * @param {string} dir
120
136
  */
@@ -126,6 +142,20 @@ function sweepTemps(dir) {
126
142
  return;
127
143
  }
128
144
  for (const n of names) {
145
+ // A build's own temp (`.<name>.tmp-<id>`) names no process: one older
146
+ // than ten minutes is a leftover of a command stopped mid-build (a
147
+ // build renames it in moments).
148
+ if (/^\..+\.tmp-[\w-]+$/.test(n)) {
149
+ const p = path.join(dir, n);
150
+ try {
151
+ const st = fs.lstatSync(p);
152
+ if (st.isFile() && Date.now() - st.mtimeMs >= 10 * 60_000)
153
+ fs.rmSync(p, {force: true});
154
+ } catch {
155
+ // Gone already.
156
+ }
157
+ continue;
158
+ }
129
159
  const m = /^\..+\.astryx-(\d+)-[a-z0-9]+\.tmp$/.exec(n);
130
160
  if (!m) continue;
131
161
  const p = path.join(dir, n);
@@ -171,6 +201,15 @@ export function removeEmptyFolder(dir, opts = {}) {
171
201
  }
172
202
  }
173
203
 
204
+ /**
205
+ * Whether a file name is one of the editor's own temp files: a whole-file
206
+ * write's `.<name>.astryx-<pid>-<random>.tmp`, or a build's
207
+ * `.<name>.tmp-<id>`. A command stopped part way can leave one behind.
208
+ * @param {string} name
209
+ */
210
+ export const isEditorTemp = name =>
211
+ /^\..+\.(astryx-\d+-[a-z0-9]+\.tmp|tmp-[\w-]+)$/.test(name);
212
+
174
213
  /**
175
214
  * A temp file beside `file` for a whole write, named so only the editor
176
215
  * makes such names: `.<name>.astryx-<pid>-<random>.tmp`. The write that
@@ -222,6 +261,7 @@ export function tempFor(file) {
222
261
  * @property {ContrastCheck[]} contrast
223
262
  * @property {number} vibrancy - The generator's vibrancy, 0 to 100.
224
263
  * @property {Record<string, Partial<Record<Mode, string>>>} exact - Main tokens the theme sets exactly, the value per mode: the dial's fill gives way to them.
264
+ * @property {Record<string, string>} [unread] - Main tokens the theme sets exactly to a value the editor cannot read as one color in some mode, as written: the text on them is not picked for that value.
225
265
  * @property {string[]} notes - What the config writer kept or replaced of a hand edit.
226
266
  * @property {Record<string, Partial<Record<Mode, StopRef>>> | null} lift - Lifted secondary text per background token of LIFT_PARTS (the accent tint, the neutral track), per mode, from the neutral color; null without one.
227
267
  */
@@ -256,12 +296,14 @@ function dialVibrancy(settings) {
256
296
  }
257
297
 
258
298
  /** The Core token word of each status family. */
259
- const STATUS_TOKEN = /** @type {Record<string, string>} */ ({
260
- success: 'success',
261
- warning: 'warning',
262
- danger: 'error',
263
- info: 'info',
264
- });
299
+ const STATUS_TOKEN = wordTable(
300
+ /** @type {Record<string, string>} */ ({
301
+ success: 'success',
302
+ warning: 'warning',
303
+ danger: 'error',
304
+ info: 'info',
305
+ }),
306
+ );
265
307
 
266
308
  /**
267
309
  * The main token a color dial feeds: the exact-token escape hatch for it.
@@ -348,31 +390,35 @@ const officialStops = token =>
348
390
  * tinted gray never tints the page. A layout without one of these stops
349
391
  * uses the nearest one it has.
350
392
  */
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)]),
393
+ const NEUTRAL_STOPS = wordTable(
394
+ Object.fromEntries(
395
+ [
396
+ '--color-background-surface',
397
+ '--color-background-card',
398
+ '--color-background-popover',
399
+ '--color-background-muted',
400
+ '--color-text-primary',
401
+ '--color-text-secondary',
402
+ '--color-text-disabled',
403
+ '--color-icon-primary',
404
+ '--color-icon-secondary',
405
+ '--color-icon-disabled',
406
+ '--color-border-emphasized',
407
+ '--color-skeleton',
408
+ ].map(t => [t, officialStops(t)]),
409
+ ),
366
410
  );
367
411
  /** Neutral tints: a stop with an opacity, `[[stop, alpha], [stop, alpha]]`. */
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
- ),
375
- ],
412
+ const NEUTRAL_TINTS = wordTable(
413
+ Object.fromEntries(
414
+ ['--color-border', '--color-overlay-hover', '--color-overlay-pressed'].map(
415
+ t => [
416
+ t,
417
+ /** @type {[[number, string], [number, string]]} */ (
418
+ OFFICIAL.stops[t].map(x => [x.stop, String(x.alpha)])
419
+ ),
420
+ ],
421
+ ),
376
422
  ),
377
423
  );
378
424
  /**
@@ -426,20 +472,24 @@ const BORDER = /** @type {[number, number]} */ ([80, 65]);
426
472
  * first in both modes on warning. Without a neutral color, black and white.
427
473
  */
428
474
  const [ON_LIGHT, ON_DARK] = officialStops('--color-on-accent');
429
- const ON_FILL = /** @type {Record<Mode, [number, number]>} */ ({
430
- light: [ON_LIGHT, ON_DARK],
431
- dark: [ON_DARK, ON_LIGHT],
432
- });
475
+ const ON_FILL = wordTable(
476
+ /** @type {Record<Mode, [number, number]>} */ ({
477
+ light: [ON_LIGHT, ON_DARK],
478
+ dark: [ON_DARK, ON_LIGHT],
479
+ }),
480
+ );
433
481
  /** A layout needs this many stops between black and white to map every token. */
434
482
  const MIN_INNER_STOPS = 5;
435
483
  /** The widest gap between two stops that still maps every token near its stop. */
436
484
  const MAX_STOP_GAP = 25;
437
485
 
438
486
  /** Text on surfaces darkens in light mode and lightens in dark mode. */
439
- const TOWARD_CONTRAST = /** @type {Record<Mode, 1 | -1>} */ ({
440
- light: -1,
441
- dark: 1,
442
- });
487
+ const TOWARD_CONTRAST = wordTable(
488
+ /** @type {Record<Mode, 1 | -1>} */ ({
489
+ light: -1,
490
+ dark: 1,
491
+ }),
492
+ );
443
493
 
444
494
  /** @param {string} slug */
445
495
  export function paletteFiles(slug) {
@@ -724,7 +774,12 @@ function usableStops(stops, slug) {
724
774
  * @param {{settings: Setting[]}} data
725
775
  * @param {{light: Record<string, string>, dark: Record<string, string>} | undefined} base
726
776
  */
727
- function tools(candidate, data, base) {
777
+ function tools(
778
+ candidate,
779
+ data,
780
+ base,
781
+ /** @type {Record<string, string>} */ own = {},
782
+ ) {
728
783
  const {stops} = candidate;
729
784
  /** @param {number} n */
730
785
  const at = n => nearestStop(stops, n);
@@ -735,11 +790,15 @@ function tools(candidate, data, base) {
735
790
  };
736
791
  const neutral = Boolean(/** @type {any} */ (candidate.palette).neutral);
737
792
  /**
738
- * The exact whole-theme color a token setting gives in a mode, or null.
793
+ * The whole-theme value a token setting gives in a mode, as written, or
794
+ * undefined.
739
795
  * @param {string} token @param {Mode} m
740
796
  */
741
- const exactOf = (token, m) => {
742
- const v = [...data.settings]
797
+ const settingOf = (token, m) =>
798
+ // A page-wide token the theme's own source sets wins over the settings
799
+ // (the build shows it), as an exact setting would.
800
+ (Object.hasOwn(own, token) ? own[token] : undefined) ??
801
+ [...data.settings]
743
802
  .reverse()
744
803
  .find(
745
804
  s =>
@@ -750,29 +809,60 @@ function tools(candidate, data, base) {
750
809
  !s.state &&
751
810
  (!s.mode || s.mode === m),
752
811
  )?.value;
812
+ /**
813
+ * The fixed color a value gives in a mode, as written when it is one
814
+ * already, or null: `light-dark()` takes its side for the mode, and a
815
+ * `var()` reads the theme's own setting, else the base theme's value.
816
+ * @param {unknown} value @param {Mode} m @param {Set<string>} [seen]
817
+ * @returns {string | null}
818
+ */
819
+ const colorIn = (value, m, seen = new Set()) => {
820
+ const v = String(value ?? '').trim();
821
+ if (!v) return null;
822
+ if (parseColor(v)) return v;
823
+ const fn = /^([a-z-]+)\((.*)\)$/is.exec(v);
824
+ if (!fn) return null;
825
+ const name = fn[1].toLowerCase();
826
+ if (name === 'light-dark') {
827
+ const halves = splitTop(fn[2], ',');
828
+ return halves.length === 2
829
+ ? colorIn(halves[m === 'dark' ? 1 : 0], m, seen)
830
+ : null;
831
+ }
832
+ if (name !== 'var') {
833
+ // A color function of tokens (a color-mix() of two) reads each one.
834
+ const put = v.replace(
835
+ /var\(\s*(--[a-z0-9-]+)\s*\)/gi,
836
+ (whole, t) => colorIn(`var(${t})`, m, new Set(seen)) ?? whole,
837
+ );
838
+ return put !== v && parseColor(put) ? put : null;
839
+ }
840
+ const [ref, ...rest] = splitTop(fn[2], ',');
841
+ const t = ref.trim();
842
+ if (!/^--[a-z0-9-]+$/i.test(t) || seen.has(t)) return null;
843
+ seen.add(t);
844
+ const own = settingOf(t, m);
845
+ const read =
846
+ own != null ? colorIn(own, m, seen) : colorIn(base?.[m]?.[t], m, seen);
847
+ return read ?? (rest.length ? colorIn(rest.join(','), m, seen) : null);
848
+ };
849
+ /**
850
+ * The exact whole-theme color a token setting gives in a mode, or null.
851
+ * @param {string} token @param {Mode} m
852
+ */
853
+ const exactOf = (token, m) => {
854
+ const v = colorIn(settingOf(token, m), m);
753
855
  const rgb = v == null ? null : parseColor(v);
754
- return rgb && alphaOf(v) >= 1 ? hex(rgb) : null;
856
+ return rgb && v != null && alphaOf(v) >= 1 ? hex(rgb) : null;
755
857
  };
756
858
  /**
757
859
  * The exact whole-theme color a token setting gives in a mode, see-through
758
- * or not, as written (a hex keeps its alpha digits); null when there is
759
- * none or it is not a fixed color.
860
+ * or not, as written (a hex keeps its alpha digits; a `light-dark()` or a
861
+ * `var()` gives the color it reads in the mode); null when there is none
862
+ * or it is not a fixed color.
760
863
  * @param {string} token @param {Mode} m
761
864
  */
762
- const rawOf = (token, m) => {
763
- const v = [...data.settings]
764
- .reverse()
765
- .find(
766
- s =>
767
- s.source === 'token' &&
768
- s.thing === token &&
769
- !s.on &&
770
- !s.when &&
771
- !s.state &&
772
- (!s.mode || s.mode === m),
773
- )?.value;
774
- return v != null && parseColor(v) ? String(v).trim() : null;
775
- };
865
+ const rawOf = (token, m) => colorIn(settingOf(token, m), m);
776
866
  /**
777
867
  * Which column of a `[light, dark]` mapping a mode takes: the light one
778
868
  * on a light page and the dark one on a dark page, by the page the theme
@@ -873,6 +963,7 @@ function tools(candidate, data, base) {
873
963
  at,
874
964
  ref,
875
965
  exactOf,
966
+ settingOf,
876
967
  rawOf,
877
968
  side,
878
969
  solid,
@@ -1123,6 +1214,16 @@ function planPalette(cwd, slug, data, base) {
1123
1214
  families.push(family);
1124
1215
  }
1125
1216
  if (!families.length) return null;
1217
+ // The editor's colors stand in the order of their settings, wherever they
1218
+ // sit among a config's own families, so a step back writes the same file.
1219
+ const slots = families
1220
+ .map((f, i) => (PALETTE_DIALS.includes(f?.id) ? i : -1))
1221
+ .filter(i => i >= 0);
1222
+ const inOrder = fams
1223
+ .map(x => families.find(f => f?.id === x.id))
1224
+ .filter(Boolean);
1225
+ if (inOrder.length === slots.length)
1226
+ slots.forEach((i, k) => (families[i] = inOrder[k]));
1126
1227
  config.families = families;
1127
1228
  const dead = deadKeys(config);
1128
1229
  if (dead.length)
@@ -1145,7 +1246,12 @@ function planPalette(cwd, slug, data, base) {
1145
1246
  // The exact color anchors dark mode too when it reads there, as the
1146
1247
  // official themes anchor a brand color in both modes.
1147
1248
  if (modes.includes('dark') && Object.keys(fills).length) {
1148
- const t = tools(generate(config, file), data, base);
1249
+ const t = tools(
1250
+ generate(config, file),
1251
+ data,
1252
+ base,
1253
+ ownSourceTokenValues(cwd, slug),
1254
+ );
1149
1255
  /** @type {string[]} */
1150
1256
  const add = [];
1151
1257
  for (const [id, fill] of Object.entries(fills)) {
@@ -1724,8 +1830,8 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
1724
1830
  const plan = /** @type {PalettePlan} */ (planPalette(cwd, slug, data, base));
1725
1831
  const {config} = plan;
1726
1832
  const candidate = generate(config, paletteFiles(slug).config);
1727
- const t = tools(candidate, data, base);
1728
- const {stops, at, ref, exactOf, rawOf, side, solid, surfaces} = t;
1833
+ const t = tools(candidate, data, base, ownSourceTokenValues(cwd, slug));
1834
+ const {stops, at, ref, exactOf, rawOf, settingOf, side, solid, surfaces} = t;
1729
1835
  const modes = modesOf(data);
1730
1836
  /** @type {PaletteMapping['tokens']} */
1731
1837
  const tokens = {};
@@ -1733,6 +1839,8 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
1733
1839
  const checks = [];
1734
1840
  /** @type {PaletteMapping['exact']} */
1735
1841
  const exact = {};
1842
+ /** @type {Record<string, string>} */
1843
+ const unread = {};
1736
1844
  const has = (/** @type {string} */ k) => k in tokenDefaults;
1737
1845
  /** A token the theme sets exactly in any mode: no check speaks for it. @param {string} k */
1738
1846
  const setExactly = k =>
@@ -1877,8 +1985,22 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
1877
1985
  for (const m of modes) {
1878
1986
  const v = rawOf(names.fill, m);
1879
1987
  if (v) exactFill[m] = v;
1988
+ else if (settingOf(names.fill, m) != null)
1989
+ unread[names.fill] = String(settingOf(names.fill, m)).trim();
1880
1990
  }
1881
- if (Object.keys(exactFill).length) exact[names.fill] = exactFill;
1991
+ if (Object.keys(exactFill).length)
1992
+ exact[names.fill] = Object.fromEntries(
1993
+ Object.entries(exactFill).map(([m, v]) => {
1994
+ // A var() is named with the color it reads, so the note says
1995
+ // which color the text was picked for.
1996
+ const written = String(
1997
+ settingOf(names.fill, /** @type {Mode} */ (m)) ?? '',
1998
+ ).trim();
1999
+ const rgb = parseColor(v);
2000
+ const color = rgb && alphaOf(v) >= 1 ? hex(rgb) : v;
2001
+ return [m, /var\(/i.test(written) ? `${written} = ${color}` : v];
2002
+ }),
2003
+ );
1882
2004
 
1883
2005
  /** @type {Partial<Record<Mode, StopRef>>} */
1884
2006
  const fill = {};
@@ -2221,6 +2343,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
2221
2343
  lift,
2222
2344
  vibrancy: config.vibrancy ?? VIBRANCY_DEFAULT,
2223
2345
  exact,
2346
+ unread,
2224
2347
  notes: [
2225
2348
  ...plan.notes,
2226
2349
  ...(paletteEdited(cwd, slug)
@@ -2350,7 +2473,13 @@ export function paletteNotes(pal, dial, slug, modes = ['light', 'dark']) {
2350
2473
  notes.push(
2351
2474
  `${token} uses your exact setting (${shown}), not the generated ${dial} shade: an exact setting wins${dial === 'neutral' ? '' : '; the text on it is picked to read on your color'}${dial === 'accent' ? ', and the focus ring keeps following it' : ''}`,
2352
2475
  );
2353
- } else if (main) {
2476
+ }
2477
+ const unread = pal.unread?.[token];
2478
+ if (unread) {
2479
+ notes.push(
2480
+ `${token} keeps your exact setting (${unread}), which the editor cannot read as one color${exact ? ' in every mode' : ''}: an exact setting wins, so the generated ${dial} shade does not show${dial === 'neutral' ? '' : ' there, and the text on it is not checked against your color: set a fixed color, or set the text color on it exactly'}`,
2481
+ );
2482
+ } else if (!exact && main) {
2354
2483
  /** @param {Mode} m */
2355
2484
  const part = m =>
2356
2485
  main[m].exact
@@ -13,6 +13,14 @@
13
13
  * @returns {Record<string, unknown> | null}
14
14
  */
15
15
  export function demoProps(project: import("./_project.mjs").ThemeProject, name: string): Record<string, unknown> | null;
16
+ /**
17
+ * Whether a part works only inside its parent: its parent lists it as an
18
+ * item, or it is a piece of its parent by name (TableBody of Table) and
19
+ * its doc gives no playground of its own.
20
+ * @param {import('./_project.mjs').ThemeProject} project
21
+ * @param {string} name
22
+ */
23
+ export function needsParent(project: import("./_project.mjs").ThemeProject, name: string): boolean;
16
24
  /**
17
25
  * Whether a part's parent lists it as an item of its children.
18
26
  * @param {import('./_project.mjs').ThemeProject} project
@@ -77,6 +85,14 @@ export function renderGenerated(project: import("./_project.mjs").ThemeProject,
77
85
  * @returns {Promise<PartData>}
78
86
  */
79
87
  export function partData(project: import("./_project.mjs").ThemeProject): Promise<PartData>;
88
+ /**
89
+ * The tokens Core's stylesheet multiplies by another value inside calc()
90
+ * (`var(--text-body-size) * var(--text-body-leading)`): a unit there makes
91
+ * the declaration invalid. Empty with no stylesheet.
92
+ * @param {any} project
93
+ * @returns {Set<string>}
94
+ */
95
+ export function multipliedTokens(project: any): Set<string>;
80
96
  /**
81
97
  * Atomic class -> its declarations, with the condition (pseudo-class,
82
98
  * attribute) each one applies under.
@@ -118,7 +118,7 @@ export function demoProps(project, name) {
118
118
  // A doc that declares no props of its own name is a family page,
119
119
  // not a component the Core exports.
120
120
  !Object.keys(info.props ?? {}).length ||
121
- (info.subComponentOf && isItemOf(project, name)))
121
+ needsParent(project, name))
122
122
  )
123
123
  return null;
124
124
  const props = given ?? {};
@@ -144,6 +144,22 @@ export function demoProps(project, name) {
144
144
  return props;
145
145
  }
146
146
 
147
+ /**
148
+ * Whether a part works only inside its parent: its parent lists it as an
149
+ * item, or it is a piece of its parent by name (TableBody of Table) and
150
+ * its doc gives no playground of its own.
151
+ * @param {import('./_project.mjs').ThemeProject} project
152
+ * @param {string} name
153
+ */
154
+ export function needsParent(project, name) {
155
+ const info = project.components[name];
156
+ const parent = info?.subComponentOf;
157
+ if (!parent) return false;
158
+ if (isItemOf(project, name)) return true;
159
+ const own = info.defaults && typeof info.defaults === 'object';
160
+ return !own && name.startsWith(parent) && name !== parent;
161
+ }
162
+
147
163
  /**
148
164
  * Whether a part's parent lists it as an item of its children.
149
165
  * @param {import('./_project.mjs').ThemeProject} project
@@ -174,12 +190,16 @@ export function catalogVariants(project, name, cap, opts = {}) {
174
190
  const info = project.components[name];
175
191
  const demo = demoProps(project, name);
176
192
  if (!demo) return [];
177
- if (info.opens && opts.shown)
178
- return [
179
- {label: '', props: 'isOpen' in demo ? demo : {...demo, isOpen: true}},
180
- ];
181
- const base =
182
- info.opens && !('isOpen' in demo) ? {...demo, isOpen: true} : demo;
193
+ // An overlay shown open never takes focus: on a page of many, each would
194
+ // pull the page to itself as it opens.
195
+ /** @param {Record<string, unknown>} d @returns {Record<string, unknown>} */
196
+ const opened = d => ({
197
+ ...d,
198
+ ...('isOpen' in d ? {} : {isOpen: true}),
199
+ ...(info.props?.hasAutoFocus ? {hasAutoFocus: false} : {}),
200
+ });
201
+ if (info.opens && opts.shown) return [{label: '', props: opened(demo)}];
202
+ const base = info.opens ? opened(demo) : demo;
183
203
  const values = info.targets[0]?.values ?? {};
184
204
  const variants = [{label: '', props: base}];
185
205
  for (const p of ['variant', 'status', 'color'])
@@ -479,6 +499,38 @@ async function buildPartData(project) {
479
499
  };
480
500
  }
481
501
 
502
+ /** @type {Map<string, Set<string>>} */
503
+ const multipliedCache = new Map();
504
+
505
+ /**
506
+ * The tokens Core's stylesheet multiplies by another value inside calc()
507
+ * (`var(--text-body-size) * var(--text-body-leading)`): a unit there makes
508
+ * the declaration invalid. Empty with no stylesheet.
509
+ * @param {any} project
510
+ * @returns {Set<string>}
511
+ */
512
+ export function multipliedTokens(project) {
513
+ /** @type {string} */
514
+ let file;
515
+ try {
516
+ file = project.req.resolve('@astryxdesign/core/astryx.css');
517
+ } catch {
518
+ return new Set();
519
+ }
520
+ const cached = multipliedCache.get(file);
521
+ if (cached) return cached;
522
+ const css = fs.readFileSync(file, 'utf8');
523
+ /** @type {Set<string>} */
524
+ const out = new Set();
525
+ // Each side of a `*` on its own, so `a * b * c` names all three.
526
+ for (const m of css.matchAll(/var\((--[a-z0-9-]+)\)(?=\s*\*)/gi))
527
+ out.add(m[1].toLowerCase());
528
+ for (const m of css.matchAll(/\*\s*var\((--[a-z0-9-]+)\)/gi))
529
+ out.add(m[1].toLowerCase());
530
+ multipliedCache.set(file, out);
531
+ return out;
532
+ }
533
+
482
534
  /**
483
535
  * Atomic class -> its declarations, with the condition (pseudo-class,
484
536
  * attribute) each one applies under.
@@ -9,6 +9,7 @@
9
9
  */
10
10
 
11
11
  import * as zlib from 'node:zlib';
12
+ import {wordTable} from './_tables.mjs';
12
13
 
13
14
  const SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
14
15
 
@@ -25,20 +26,24 @@ export const MAX_PIXELS_16 = 20_000_000;
25
26
  const SAMPLE_BUDGET = 4_000_000;
26
27
 
27
28
  /** The bit depths each PNG color type allows. */
28
- const DEPTHS = /** @type {Record<number, number[]>} */ ({
29
- 0: [1, 2, 4, 8, 16],
30
- 2: [8, 16],
31
- 3: [1, 2, 4, 8],
32
- 4: [8, 16],
33
- 6: [8, 16],
34
- });
35
- const CHANNELS = /** @type {Record<number, number>} */ ({
36
- 0: 1,
37
- 2: 3,
38
- 3: 1,
39
- 4: 2,
40
- 6: 4,
41
- });
29
+ const DEPTHS = wordTable(
30
+ /** @type {Record<number, number[]>} */ ({
31
+ 0: [1, 2, 4, 8, 16],
32
+ 2: [8, 16],
33
+ 3: [1, 2, 4, 8],
34
+ 4: [8, 16],
35
+ 6: [8, 16],
36
+ }),
37
+ );
38
+ const CHANNELS = wordTable(
39
+ /** @type {Record<number, number>} */ ({
40
+ 0: 1,
41
+ 2: 3,
42
+ 3: 1,
43
+ 4: 2,
44
+ 6: 4,
45
+ }),
46
+ );
42
47
 
43
48
  /** @typedef {{width: number, height: number, rgba: Uint8Array}} Picture */
44
49
 
@@ -84,6 +84,8 @@ export type PreviewPage = {
84
84
  file: string;
85
85
  };
86
86
  /**
87
+ * `parents`: how many folders over the preview folder its first add made,
88
+ * which remove takes away again when they are empty.
87
89
  * `hashes`: a short hash of each file as the preview wrote it, so a file
88
90
  * changed by hand is never replaced or deleted
89
91
  */
@@ -93,6 +95,7 @@ export type PreviewData = {
93
95
  pages: PreviewPage[];
94
96
  files: string[];
95
97
  hashes?: Record<string, string>;
98
+ parents?: number;
96
99
  };
97
100
  /**
98
101
  * the command again, with