@astryxdesign/cli 0.7.15 → 0.7.16-canary.g3aa244b

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 (163) hide show
  1. package/README.md +5 -3
  2. package/api/build/_adapter.d.mts +1 -0
  3. package/api/build/blocks/blocks.d.mts +1 -0
  4. package/api/build/blocks/blocks.mjs +18 -1
  5. package/api/component/_adapter.d.mts +1 -1
  6. package/api/component/_adapter.mjs +28 -1
  7. package/api/doctor/_adapter.d.mts +35 -0
  8. package/api/doctor/_adapter.mjs +69 -0
  9. package/api/doctor/built-checks.mjs +1 -1
  10. package/api/doctor/doctor.d.mts +18 -0
  11. package/api/doctor/doctor.doc.mjs +1 -1
  12. package/api/doctor/doctor.mjs +104 -4
  13. package/api/doctor/theme-checks.mjs +6 -10
  14. package/api/integration/add-contribution.mjs +3 -3
  15. package/api/integration/pack-check.mjs +14 -8
  16. package/api/integration/validate-integration.mjs +1 -1
  17. package/api/search/_adapter.mjs +15 -16
  18. package/api/search/_entries.d.mts +2 -1
  19. package/api/search/_entries.mjs +28 -1
  20. package/api/swizzle/_moduleGraph.mjs +1 -1
  21. package/api/theme/_adapter.d.mts +5 -2
  22. package/api/theme/_adapter.mjs +43 -12
  23. package/api/theme/_fork.mjs +1 -1
  24. package/api/theme/build/build.d.mts +116 -32
  25. package/api/theme/build/build.mjs +449 -102
  26. package/api/theme/eject/eject.mjs +22 -1
  27. package/api/theme/template/template.d.mts +19 -0
  28. package/api/theme/template/template.mjs +102 -25
  29. package/api/theme/theme.type.d.mts +5 -1
  30. package/api/theme/theme.type.mjs +2 -1
  31. package/api/theme/themeBuild.doc.mjs +3 -3
  32. package/api/theme/themeEject.doc.mjs +1 -1
  33. package/api/theme/themeTemplate.doc.mjs +9 -3
  34. package/api/theme-edit/_adapter.d.mts +32 -2
  35. package/api/theme-edit/_adapter.mjs +264 -40
  36. package/api/theme-edit/_check.d.mts +93 -4
  37. package/api/theme-edit/_check.mjs +1727 -223
  38. package/api/theme-edit/_color.d.mts +2 -8
  39. package/api/theme-edit/_color.mjs +292 -219
  40. package/api/theme-edit/_compiler.d.mts +1 -0
  41. package/api/theme-edit/_compiler.mjs +20 -1
  42. package/api/theme-edit/_context.d.mts +31 -1
  43. package/api/theme-edit/_context.mjs +445 -41
  44. package/api/theme-edit/_css.d.mts +60 -1
  45. package/api/theme-edit/_css.mjs +404 -28
  46. package/api/theme-edit/_edit.d.mts +25 -0
  47. package/api/theme-edit/_edit.mjs +1532 -149
  48. package/api/theme-edit/_how-commands.d.mts +11 -26
  49. package/api/theme-edit/_how-commands.mjs +30 -2
  50. package/api/theme-edit/_how-question.d.mts +7 -0
  51. package/api/theme-edit/_how-question.mjs +1304 -176
  52. package/api/theme-edit/_how.mjs +144 -30
  53. package/api/theme-edit/_overview.mjs +2 -0
  54. package/api/theme-edit/_palette.d.mts +38 -0
  55. package/api/theme-edit/_palette.mjs +305 -71
  56. package/api/theme-edit/_parts.d.mts +33 -0
  57. package/api/theme-edit/_parts.mjs +138 -9
  58. package/api/theme-edit/_png.d.mts +18 -0
  59. package/api/theme-edit/_png.mjs +95 -14
  60. package/api/theme-edit/_preview-app.d.mts +36 -1
  61. package/api/theme-edit/_preview-app.mjs +1415 -96
  62. package/api/theme-edit/_preview.d.mts +64 -3
  63. package/api/theme-edit/_preview.mjs +514 -31
  64. package/api/theme-edit/_project.d.mts +11 -0
  65. package/api/theme-edit/_project.mjs +46 -12
  66. package/api/theme-edit/_settings.d.mts +278 -5
  67. package/api/theme-edit/_settings.mjs +2741 -195
  68. package/api/theme-edit/_tables.d.mts +24 -0
  69. package/api/theme-edit/_tables.mjs +211 -149
  70. package/api/theme-edit/_vet.d.mts +42 -0
  71. package/api/theme-edit/_vet.mjs +144 -0
  72. package/api/theme-edit/theme-edit.type.d.mts +20 -2
  73. package/api/theme-edit/theme-edit.type.mjs +6 -2
  74. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  75. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  76. package/api/theme-edit/themeEditShow.doc.mjs +11 -3
  77. package/api/upgrade/registry/registry.mjs +6 -1
  78. package/assets/codemods/parse.mjs +2 -2
  79. package/assets/docs/tree/single-component.doc.mjs +11 -2
  80. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  81. package/assets/docs.generated.json +2 -2
  82. package/assets/preview-app/next.config.mjs +7 -1
  83. package/assets/preview-app/package.json +1 -0
  84. package/assets/preview-app/src/app/globals.css +1 -0
  85. package/assets/self-audit.generated.json +1 -1
  86. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
  87. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
  88. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
  89. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
  90. package/assets/templates/components.generated.json +1 -1
  91. package/assets/templates/pages/dashboard/page.tsx +1 -1
  92. package/authoring/doctypes/_schema.d.mts +52 -5
  93. package/authoring/doctypes/_schema.mjs +62 -7
  94. package/authoring/doctypes/base/type.ts +10 -0
  95. package/authoring/doctypes/component/component.doc.mjs +1 -1
  96. package/authoring/doctypes/function/function.doc.mjs +6 -0
  97. package/authoring/doctypes/function/type.ts +3 -0
  98. package/authoring/doctypes/legacy.mjs +5 -1
  99. package/authoring/index.d.ts +1 -0
  100. package/authoring/shadcn/source-variants.d.mts +1 -1
  101. package/authoring/shadcn/source-variants.mjs +32 -10
  102. package/clients/cli/build-id.generated.json +1 -1
  103. package/clients/cli/commands/doctor.doc.mjs +2 -2
  104. package/clients/cli/commands/experimental/theme.mjs +239 -45
  105. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  106. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
  107. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
  108. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +3 -3
  109. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  110. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  111. package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
  112. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  113. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  114. package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
  115. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  116. package/clients/cli/commands/theme-eject.doc.mjs +1 -1
  117. package/clients/cli/commands/theme-template.doc.mjs +3 -1
  118. package/clients/cli/commands/theme.mjs +190 -46
  119. package/clients/cli/formatters/index.mjs +7 -4
  120. package/clients/cli/lib/cli-error.mjs +9 -3
  121. package/clients/cli/lib/component-format.mjs +27 -9
  122. package/clients/cli/lib/json-shim.mjs +72 -2
  123. package/clients/cli/manifest.generated.json +1 -1
  124. package/clients/cli/run.mjs +49 -0
  125. package/foundation/agent-docs/agent-docs-target.d.mts +2 -6
  126. package/foundation/agent-docs/agent-docs-target.mjs +9 -17
  127. package/foundation/agent-docs/agent-docs.mjs +3 -2
  128. package/foundation/config/config-writer.mjs +2 -2
  129. package/foundation/config/project.mjs +60 -14
  130. package/foundation/discovery/component-discovery.mjs +5 -17
  131. package/foundation/discovery/icon-set-writer.mjs +1 -1
  132. package/foundation/discovery/module-exports.mjs +1 -15
  133. package/foundation/discovery/template-adapter.mjs +44 -19
  134. package/foundation/discovery/template-source-tree.mjs +3 -16
  135. package/foundation/discovery/theme-discovery.d.mts +5 -1
  136. package/foundation/discovery/theme-discovery.mjs +61 -43
  137. package/foundation/fs/exact-codec.d.mts +35 -0
  138. package/foundation/fs/exact-codec.mjs +148 -0
  139. package/foundation/fs/gather-cache.d.mts +15 -5
  140. package/foundation/fs/gather-cache.mjs +129 -31
  141. package/foundation/fs/paths.d.mts +39 -0
  142. package/foundation/fs/paths.mjs +44 -11
  143. package/foundation/fs/read-record.mjs +11 -1
  144. package/foundation/integrations/contribution-fixes.mjs +1 -16
  145. package/foundation/integrations/may-have-integrations.mjs +3 -2
  146. package/foundation/integrations/public-imports.mjs +1 -1
  147. package/foundation/render/embedded-imports.mjs +1 -1
  148. package/foundation/render/host-exit.d.mts +8 -0
  149. package/foundation/render/host-exit.mjs +11 -0
  150. package/foundation/render/page-host.mjs +56 -10
  151. package/foundation/render/page-worker.mjs +14 -0
  152. package/foundation/render/render-page.mjs +37 -2
  153. package/foundation/response/error-codes.d.mts +2 -1
  154. package/foundation/response/error-codes.d.ts +1 -0
  155. package/foundation/response/error-codes.doc.mjs +5 -0
  156. package/foundation/response/error-codes.mjs +3 -0
  157. package/foundation/response/json.d.mts +15 -0
  158. package/foundation/response/json.mjs +52 -1
  159. package/foundation/response/response-types.doc.mjs +1 -1
  160. package/foundation/runtime/lazy-dependencies.d.mts +14 -0
  161. package/foundation/runtime/lazy-dependencies.mjs +82 -0
  162. package/foundation/xle/browser.d.mts +2 -2
  163. 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,
@@ -952,7 +1043,10 @@ function planPalette(cwd, slug, data, base) {
952
1043
  ? {...existing}
953
1044
  : {};
954
1045
  const {settings: saved, mode: savedMode} = savedSettings(cwd, slug);
955
- const modes = modesOf(data);
1046
+ // Every theme's palette has both modes: a one-mode theme keeps both
1047
+ // halves of its colors (its mode is the one the app's <Theme> is given),
1048
+ // and a region Core draws in the other mode reads the other half.
1049
+ const modes = modesForStrategy('light-and-dark');
956
1050
 
957
1051
  const vibrancy = dialVibrancy(data.settings);
958
1052
  const savedVibrancy = dialVibrancy(saved);
@@ -1123,6 +1217,16 @@ function planPalette(cwd, slug, data, base) {
1123
1217
  families.push(family);
1124
1218
  }
1125
1219
  if (!families.length) return null;
1220
+ // The editor's colors stand in the order of their settings, wherever they
1221
+ // sit among a config's own families, so a step back writes the same file.
1222
+ const slots = families
1223
+ .map((f, i) => (PALETTE_DIALS.includes(f?.id) ? i : -1))
1224
+ .filter(i => i >= 0);
1225
+ const inOrder = fams
1226
+ .map(x => families.find(f => f?.id === x.id))
1227
+ .filter(Boolean);
1228
+ if (inOrder.length === slots.length)
1229
+ slots.forEach((i, k) => (families[i] = inOrder[k]));
1126
1230
  config.families = families;
1127
1231
  const dead = deadKeys(config);
1128
1232
  if (dead.length)
@@ -1145,7 +1249,12 @@ function planPalette(cwd, slug, data, base) {
1145
1249
  // The exact color anchors dark mode too when it reads there, as the
1146
1250
  // official themes anchor a brand color in both modes.
1147
1251
  if (modes.includes('dark') && Object.keys(fills).length) {
1148
- const t = tools(generate(config, file), data, base);
1252
+ const t = tools(
1253
+ generate(config, file),
1254
+ data,
1255
+ base,
1256
+ ownSourceTokenValues(cwd, slug),
1257
+ );
1149
1258
  /** @type {string[]} */
1150
1259
  const add = [];
1151
1260
  for (const [id, fill] of Object.entries(fills)) {
@@ -1266,7 +1375,12 @@ function syncPaletteFiles(cwd, slug, data, base) {
1266
1375
  const hash = fs.existsSync(abs(f.config))
1267
1376
  ? sha256(fs.readFileSync(abs(f.config)))
1268
1377
  : null;
1269
- const mine = hash != null && (data.palette === hash || saved === hash);
1378
+ // Or the config the editor recorded writing (a color change stopped
1379
+ // before its settings were saved).
1380
+ const recorded = readWrittenRecord(cwd, slug)['palette.config.json'];
1381
+ const mine =
1382
+ hash != null &&
1383
+ (data.palette === hash || saved === hash || recorded === hash);
1270
1384
  delete data.palette;
1271
1385
  if (!mine) return [];
1272
1386
  // A palette file edited by hand is never deleted: it stays, and the
@@ -1279,6 +1393,7 @@ function syncPaletteFiles(cwd, slug, data, base) {
1279
1393
  const notes = [];
1280
1394
  for (const p of [f.config, f.receipt, f.refs])
1281
1395
  fs.rmSync(abs(p), {force: true});
1396
+ noteWritten(cwd, slug, 'palette.config.json', null);
1282
1397
  if (editedPalette)
1283
1398
  notes.push(
1284
1399
  `${f.palette} was edited by hand, so it stays: the theme no longer reads it. Move it out of tokens/ to keep it as your own, or delete it`,
@@ -1327,12 +1442,75 @@ function syncPaletteFiles(cwd, slug, data, base) {
1327
1442
  );
1328
1443
  }
1329
1444
  fs.mkdirSync(path.dirname(abs(f.config)), {recursive: true});
1445
+ // Recorded before it is written: a run stopped after this leaves a config
1446
+ // the next build knows is the editor's.
1447
+ noteWritten(cwd, slug, 'palette.config.json', sha256(Buffer.from(text)));
1330
1448
  writeWhole(abs(f.config), text);
1331
1449
  data.palette = sha256(Buffer.from(text));
1332
1450
  themePaletteGenerate(f.config, {out: f.palette, overwrite: true}, {cwd});
1333
1451
  return plan.notes;
1334
1452
  }
1335
1453
 
1454
+ /**
1455
+ * The record of the files the editor wrote into a theme folder,
1456
+ * `themes/<theme>/<theme>.pictures.json`: each by name, with the hash of
1457
+ * what was written (its pictures and its color config). The one reader and
1458
+ * writer of that record.
1459
+ * @param {string} cwd
1460
+ * @param {string} slug
1461
+ * @returns {Record<string, string>}
1462
+ */
1463
+ export function readWrittenRecord(cwd, slug) {
1464
+ try {
1465
+ const json = JSON.parse(
1466
+ fs.readFileSync(writtenRecordFile(cwd, slug), 'utf8'),
1467
+ );
1468
+ return json && typeof json === 'object' && !Array.isArray(json) ? json : {};
1469
+ } catch {
1470
+ return {};
1471
+ }
1472
+ }
1473
+
1474
+ /** @param {string} cwd @param {string} slug */
1475
+ const writtenRecordFile = (cwd, slug) =>
1476
+ path.join(cwd, 'themes', slug, `${slug}.pictures.json`);
1477
+
1478
+ /**
1479
+ * Write the record whole, or remove it when it names nothing. A record that
1480
+ * cannot be written leaves nothing removed later: the safe way round.
1481
+ * @param {string} cwd
1482
+ * @param {string} slug
1483
+ * @param {Record<string, string>} map
1484
+ */
1485
+ export function writeWrittenRecord(cwd, slug, map) {
1486
+ const file = writtenRecordFile(cwd, slug);
1487
+ try {
1488
+ if (!Object.keys(map).length) fs.rmSync(file, {force: true});
1489
+ else {
1490
+ fs.mkdirSync(path.dirname(file), {recursive: true});
1491
+ writeWhole(file, `${JSON.stringify(map, null, 2)}\n`);
1492
+ }
1493
+ } catch {
1494
+ // Without the record, nothing it names is removed later.
1495
+ }
1496
+ }
1497
+
1498
+ /**
1499
+ * Note a file the editor wrote into a theme folder, by name with the hash
1500
+ * of what it wrote, or forget it (null).
1501
+ * @param {string} cwd
1502
+ * @param {string} slug
1503
+ * @param {string} name
1504
+ * @param {string | null} hash
1505
+ */
1506
+ export function noteWritten(cwd, slug, name, hash) {
1507
+ const map = readWrittenRecord(cwd, slug);
1508
+ if (hash) map[name] = hash;
1509
+ else if (name in map) delete map[name];
1510
+ else return;
1511
+ writeWrittenRecord(cwd, slug, map);
1512
+ }
1513
+
1336
1514
  /**
1337
1515
  * The value of the object literal that starts at the first `{` from
1338
1516
  * `from`, read as data: string and numeric keys, string values, nested
@@ -1724,15 +1902,18 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
1724
1902
  const plan = /** @type {PalettePlan} */ (planPalette(cwd, slug, data, base));
1725
1903
  const {config} = plan;
1726
1904
  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;
1729
- const modes = modesOf(data);
1905
+ const t = tools(candidate, data, base, ownSourceTokenValues(cwd, slug));
1906
+ const {stops, at, ref, exactOf, rawOf, settingOf, side, solid, surfaces} = t;
1907
+ // Both halves, for a one-mode theme too (see planPalette).
1908
+ const modes = modesForStrategy('light-and-dark');
1730
1909
  /** @type {PaletteMapping['tokens']} */
1731
1910
  const tokens = {};
1732
1911
  /** @type {ContrastCheck[]} */
1733
1912
  const checks = [];
1734
1913
  /** @type {PaletteMapping['exact']} */
1735
1914
  const exact = {};
1915
+ /** @type {Record<string, string>} */
1916
+ const unread = {};
1736
1917
  const has = (/** @type {string} */ k) => k in tokenDefaults;
1737
1918
  /** A token the theme sets exactly in any mode: no check speaks for it. @param {string} k */
1738
1919
  const setExactly = k =>
@@ -1877,8 +2058,22 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
1877
2058
  for (const m of modes) {
1878
2059
  const v = rawOf(names.fill, m);
1879
2060
  if (v) exactFill[m] = v;
2061
+ else if (settingOf(names.fill, m) != null)
2062
+ unread[names.fill] = String(settingOf(names.fill, m)).trim();
1880
2063
  }
1881
- if (Object.keys(exactFill).length) exact[names.fill] = exactFill;
2064
+ if (Object.keys(exactFill).length)
2065
+ exact[names.fill] = Object.fromEntries(
2066
+ Object.entries(exactFill).map(([m, v]) => {
2067
+ // A var() is named with the color it reads, so the note says
2068
+ // which color the text was picked for.
2069
+ const written = String(
2070
+ settingOf(names.fill, /** @type {Mode} */ (m)) ?? '',
2071
+ ).trim();
2072
+ const rgb = parseColor(v);
2073
+ const color = rgb && alphaOf(v) >= 1 ? hex(rgb) : v;
2074
+ return [m, /var\(/i.test(written) ? `${written} = ${color}` : v];
2075
+ }),
2076
+ );
1882
2077
 
1883
2078
  /** @type {Partial<Record<Mode, StopRef>>} */
1884
2079
  const fill = {};
@@ -2139,6 +2334,37 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
2139
2334
  const found = {};
2140
2335
  for (const ground of new Set(LIFT_PARTS.map(([, , g]) => g))) {
2141
2336
  const {what, parts} = LIFT_GROUNDS[ground];
2337
+ /**
2338
+ * The shade the base theme itself lifts this ground's text to in a
2339
+ * mode, when it gives one: the search starts there, so a change of
2340
+ * color moves it only when that shade no longer reads.
2341
+ * @param {Mode} m
2342
+ * @returns {string | null}
2343
+ */
2344
+ const baseLift = m => {
2345
+ for (const [part, block, g] of LIFT_PARTS) {
2346
+ if (g !== ground) continue;
2347
+ const v = /** @type {any} */ (base)?.components?.[part]?.[block]?.[
2348
+ '--color-text-secondary'
2349
+ ];
2350
+ const pair = Array.isArray(v)
2351
+ ? v
2352
+ : typeof v === 'string'
2353
+ ? /^light-dark\((.*)\)$/s.exec(v.trim())?.[1]
2354
+ ? splitTop(
2355
+ /** @type {string} */ (
2356
+ /^light-dark\((.*)\)$/s.exec(v.trim())?.[1]
2357
+ ),
2358
+ ',',
2359
+ )
2360
+ : [v, v]
2361
+ : null;
2362
+ const c = pair?.[m === 'light' ? 0 : 1]?.trim();
2363
+ if (c && parseColor(c))
2364
+ return hex(/** @type {number[]} */ (parseColor(c)));
2365
+ }
2366
+ return null;
2367
+ };
2142
2368
  /** @type {Partial<Record<Mode, StopRef>>} */
2143
2369
  const byMode = {};
2144
2370
  for (const m of modes) {
@@ -2168,8 +2394,9 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
2168
2394
  const keys = Object.keys(g.ramp)
2169
2395
  .map(Number)
2170
2396
  .sort((a, b) => a - b);
2397
+ const from = baseLift(m) ?? text;
2171
2398
  const start = keys.reduce((x, y) =>
2172
- perceptualDelta(g.ramp[y], text) < perceptualDelta(g.ramp[x], text)
2399
+ perceptualDelta(g.ramp[y], from) < perceptualDelta(g.ramp[x], from)
2173
2400
  ? y
2174
2401
  : x,
2175
2402
  );
@@ -2190,7 +2417,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
2190
2417
  ? ref('neutral', m, b.stop)
2191
2418
  : {stop: b.stop, color: g.ramp[b.stop], family: 'literal'};
2192
2419
  const moved =
2193
- hex(/** @type {number[]} */ (parseColor(g.ramp[b.stop]))) !== text;
2420
+ hex(/** @type {number[]} */ (parseColor(g.ramp[b.stop]))) !== from;
2194
2421
  if (b.r < TEXT || moved)
2195
2422
  checks.push({
2196
2423
  token: '--color-text-secondary',
@@ -2204,7 +2431,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
2204
2431
  dials: ['accent', 'neutral'],
2205
2432
  note:
2206
2433
  b.r >= TEXT
2207
- ? `--color-text-secondary on ${parts} uses ${g.ramp[b.stop]} in ${m}, not ${text}, so it reads at ${round(b.r)}:1 on ${what} and under a hover, as the official theme lifts it`
2434
+ ? `--color-text-secondary on ${parts} uses ${g.ramp[b.stop]} in ${m}, not ${from}, so it stays readable (${round(b.r)}:1) on ${what} and under a hover`
2208
2435
  : `--color-text-secondary on ${parts} reads at only ${round(b.r)}:1 in ${m} on ${what} even at ${g.ramp[b.stop]}, the most contrasting gray (needs ${TEXT}:1): pick another accent or neutral, or set --color-text-secondary on those parts exactly`,
2209
2436
  });
2210
2437
  }
@@ -2221,6 +2448,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
2221
2448
  lift,
2222
2449
  vibrancy: config.vibrancy ?? VIBRANCY_DEFAULT,
2223
2450
  exact,
2451
+ unread,
2224
2452
  notes: [
2225
2453
  ...plan.notes,
2226
2454
  ...(paletteEdited(cwd, slug)
@@ -2350,7 +2578,13 @@ export function paletteNotes(pal, dial, slug, modes = ['light', 'dark']) {
2350
2578
  notes.push(
2351
2579
  `${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
2580
  );
2353
- } else if (main) {
2581
+ }
2582
+ const unread = pal.unread?.[token];
2583
+ if (unread) {
2584
+ notes.push(
2585
+ `${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'}`,
2586
+ );
2587
+ } else if (!exact && main) {
2354
2588
  /** @param {Mode} m */
2355
2589
  const part = m =>
2356
2590
  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,31 @@ 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 value Core falls back to where its stylesheet reads a variable
90
+ * (`var(--astryx-card-padding, var(--spacing-4))` gives `var(--spacing-4)`),
91
+ * or null when it gives none.
92
+ * @param {any} project
93
+ * @param {string} name
94
+ * @returns {string | null}
95
+ */
96
+ export function coreFallback(project: any, name: string): string | null;
97
+ /**
98
+ * The variables Core's stylesheet reads inside a calc() (a composer's
99
+ * padding in its send button's radius): only one length works there.
100
+ * Empty with no stylesheet.
101
+ * @param {any} project
102
+ * @returns {Set<string>}
103
+ */
104
+ export function calcVars(project: any): Set<string>;
105
+ /**
106
+ * The tokens Core's stylesheet multiplies by another value inside calc()
107
+ * (`var(--text-body-size) * var(--text-body-leading)`): a unit there makes
108
+ * the declaration invalid. Empty with no stylesheet.
109
+ * @param {any} project
110
+ * @returns {Set<string>}
111
+ */
112
+ export function multipliedTokens(project: any): Set<string>;
80
113
  /**
81
114
  * Atomic class -> its declarations, with the condition (pseudo-class,
82
115
  * attribute) each one applies under.