@astryxdesign/cli 0.7.15 → 0.7.16-canary.g22213fd

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 (222) hide show
  1. package/README.md +6 -4
  2. package/api/build/_adapter.d.mts +10 -0
  3. package/api/build/_adapter.mjs +24 -0
  4. package/api/build/blocks/blocks.d.mts +1 -0
  5. package/api/build/blocks/blocks.mjs +18 -1
  6. package/api/build/kit/shell.weights.json +1 -0
  7. package/api/build/kit/shellcall.d.mts +26 -0
  8. package/api/build/kit/shellcall.mjs +87 -0
  9. package/api/build/kit/start.mjs +67 -4
  10. package/api/build/kit/weights.d.mts +15 -0
  11. package/api/build/kit/weights.mjs +27 -0
  12. package/api/component/__fixtures__/resolutions/modules.txt +1 -1
  13. package/api/component/_adapter.d.mts +1 -1
  14. package/api/component/_adapter.mjs +28 -1
  15. package/api/doctor/_adapter.d.mts +38 -2
  16. package/api/doctor/_adapter.mjs +76 -1
  17. package/api/doctor/built-checks.mjs +1 -1
  18. package/api/doctor/doctor.d.mts +26 -0
  19. package/api/doctor/doctor.doc.mjs +1 -1
  20. package/api/doctor/doctor.mjs +156 -11
  21. package/api/doctor/theme-checks.mjs +163 -18
  22. package/api/icon/_adapter.d.mts +7 -3
  23. package/api/icon/_adapter.mjs +12 -3
  24. package/api/icon/icon.type.d.mts +15 -0
  25. package/api/icon/icon.type.mjs +10 -3
  26. package/api/icon/iconUse.doc.mjs +19 -5
  27. package/api/icon/list/list.mjs +7 -1
  28. package/api/icon/use/use.d.mts +8 -5
  29. package/api/icon/use/use.mjs +95 -13
  30. package/api/init/run/run.mjs +1 -0
  31. package/api/integration/add-contribution.mjs +3 -3
  32. package/api/integration/pack-check.mjs +14 -8
  33. package/api/integration/validate-integration.mjs +1 -1
  34. package/api/search/_adapter.mjs +15 -16
  35. package/api/search/_entries.d.mts +2 -1
  36. package/api/search/_entries.mjs +28 -1
  37. package/api/swizzle/_moduleGraph.mjs +1 -1
  38. package/api/template/template.type.d.mts +6 -2
  39. package/api/template/template.type.mjs +2 -1
  40. package/api/theme/_adapter.d.mts +5 -2
  41. package/api/theme/_adapter.mjs +59 -14
  42. package/api/theme/_fork.mjs +1 -1
  43. package/api/theme/build/build.d.mts +120 -32
  44. package/api/theme/build/build.mjs +471 -111
  45. package/api/theme/eject/eject.mjs +22 -1
  46. package/api/theme/generateTonalPalette.doc.mjs +2 -2
  47. package/api/theme/palette/generate/generator.mjs +141 -2
  48. package/api/theme/template/template.d.mts +19 -0
  49. package/api/theme/template/template.mjs +102 -25
  50. package/api/theme/theme.type.d.mts +44 -1
  51. package/api/theme/theme.type.mjs +23 -1
  52. package/api/theme/themeBuild.doc.mjs +4 -4
  53. package/api/theme/themeEject.doc.mjs +1 -1
  54. package/api/theme/themePaletteGenerate.doc.mjs +1 -1
  55. package/api/theme/themeTemplate.doc.mjs +9 -3
  56. package/api/theme-edit/_adapter.d.mts +33 -2
  57. package/api/theme-edit/_adapter.mjs +276 -41
  58. package/api/theme-edit/_check.d.mts +93 -4
  59. package/api/theme-edit/_check.mjs +1712 -223
  60. package/api/theme-edit/_color.d.mts +2 -8
  61. package/api/theme-edit/_color.mjs +292 -219
  62. package/api/theme-edit/_compiler.d.mts +1 -0
  63. package/api/theme-edit/_compiler.mjs +20 -1
  64. package/api/theme-edit/_context.d.mts +31 -1
  65. package/api/theme-edit/_context.mjs +445 -41
  66. package/api/theme-edit/_css.d.mts +60 -1
  67. package/api/theme-edit/_css.mjs +404 -28
  68. package/api/theme-edit/_edit.d.mts +25 -0
  69. package/api/theme-edit/_edit.mjs +1620 -154
  70. package/api/theme-edit/_how-commands.d.mts +11 -26
  71. package/api/theme-edit/_how-commands.mjs +30 -2
  72. package/api/theme-edit/_how-question.d.mts +15 -0
  73. package/api/theme-edit/_how-question.mjs +1469 -194
  74. package/api/theme-edit/_how.mjs +144 -30
  75. package/api/theme-edit/_marks.d.mts +13 -0
  76. package/api/theme-edit/_marks.mjs +15 -0
  77. package/api/theme-edit/_overview.mjs +2 -0
  78. package/api/theme-edit/_palette.d.mts +38 -0
  79. package/api/theme-edit/_palette.mjs +306 -73
  80. package/api/theme-edit/_parts.d.mts +33 -0
  81. package/api/theme-edit/_parts.mjs +138 -9
  82. package/api/theme-edit/_png.d.mts +18 -0
  83. package/api/theme-edit/_png.mjs +95 -14
  84. package/api/theme-edit/_preview-app.d.mts +55 -1
  85. package/api/theme-edit/_preview-app.mjs +1552 -101
  86. package/api/theme-edit/_preview.d.mts +71 -3
  87. package/api/theme-edit/_preview.mjs +565 -35
  88. package/api/theme-edit/_project.d.mts +15 -0
  89. package/api/theme-edit/_project.mjs +68 -13
  90. package/api/theme-edit/_settings.d.mts +299 -5
  91. package/api/theme-edit/_settings.mjs +2806 -158
  92. package/api/theme-edit/_tables.d.mts +24 -0
  93. package/api/theme-edit/_tables.mjs +212 -150
  94. package/api/theme-edit/_vet.d.mts +42 -0
  95. package/api/theme-edit/_vet.mjs +144 -0
  96. package/api/theme-edit/theme-edit.type.d.mts +31 -2
  97. package/api/theme-edit/theme-edit.type.mjs +10 -2
  98. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  99. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  100. package/api/theme-edit/themeEditShow.doc.mjs +11 -3
  101. package/api/upgrade/registry/registry.mjs +6 -1
  102. package/assets/codemods/parse.mjs +2 -2
  103. package/assets/docs/author-a-theme.doc.mjs +1 -1
  104. package/assets/docs/theme.doc.dense.mjs +1 -1
  105. package/assets/docs/theme.doc.mjs +1 -1
  106. package/assets/docs/theme.doc.zh.mjs +4 -3
  107. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  108. package/assets/docs/tree/icon-sets.doc.mjs +63 -8
  109. package/assets/docs/tree/single-component.doc.mjs +11 -2
  110. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  111. package/assets/docs.generated.json +2 -2
  112. package/assets/preview-app/next.config.mjs +7 -1
  113. package/assets/preview-app/package.json +1 -0
  114. package/assets/preview-app/src/app/globals.css +1 -0
  115. package/assets/self-audit.generated.json +1 -1
  116. package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.doc.mjs +21 -0
  117. package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.tsx +62 -0
  118. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
  119. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
  120. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
  121. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
  122. package/assets/templates/components.generated.json +1 -1
  123. package/assets/templates/pages/ai-chat/page.tsx +20 -2
  124. package/assets/templates/pages/dashboard/page.tsx +1 -1
  125. package/assets/templates/themes/neutral/neutralPalettes.generated.receipt.json +2 -0
  126. package/authoring/config/config.doc.mjs +8 -0
  127. package/authoring/config/parse.d.mts +1 -0
  128. package/authoring/config/parse.mjs +12 -0
  129. package/authoring/config/type.ts +8 -0
  130. package/authoring/doctypes/_schema.d.mts +52 -5
  131. package/authoring/doctypes/_schema.mjs +62 -7
  132. package/authoring/doctypes/base/type.ts +10 -0
  133. package/authoring/doctypes/component/component.doc.mjs +1 -1
  134. package/authoring/doctypes/function/function.doc.mjs +6 -0
  135. package/authoring/doctypes/function/type.ts +3 -0
  136. package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +3 -3
  137. package/authoring/doctypes/legacy.mjs +5 -1
  138. package/authoring/index.d.ts +1 -0
  139. package/authoring/shadcn/source-variants.d.mts +1 -1
  140. package/authoring/shadcn/source-variants.mjs +32 -10
  141. package/clients/cli/build-id.generated.json +1 -1
  142. package/clients/cli/commands/doctor.doc.mjs +2 -2
  143. package/clients/cli/commands/experimental/icon.mjs +61 -6
  144. package/clients/cli/commands/experimental/theme.mjs +244 -45
  145. package/clients/cli/commands/experimental-icon-use.doc.mjs +12 -5
  146. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  147. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
  148. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
  149. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +3 -3
  150. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  151. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  152. package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
  153. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  154. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  155. package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
  156. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  157. package/clients/cli/commands/theme-eject.doc.mjs +1 -1
  158. package/clients/cli/commands/theme-template.doc.mjs +3 -1
  159. package/clients/cli/commands/theme.doc.mjs +7 -2
  160. package/clients/cli/commands/theme.mjs +222 -55
  161. package/clients/cli/commands.generated.json +1 -1
  162. package/clients/cli/formatters/index.mjs +7 -4
  163. package/clients/cli/index.mjs +25 -5
  164. package/clients/cli/lib/cli-error.mjs +9 -3
  165. package/clients/cli/lib/component-format.mjs +27 -9
  166. package/clients/cli/lib/json-shim.mjs +72 -2
  167. package/clients/cli/manifest.generated.json +1 -1
  168. package/clients/cli/run.mjs +49 -0
  169. package/foundation/agent-docs/agent-docs-target.d.mts +2 -6
  170. package/foundation/agent-docs/agent-docs-target.mjs +9 -17
  171. package/foundation/agent-docs/agent-docs.mjs +4 -3
  172. package/foundation/config/config-writer.d.mts +23 -0
  173. package/foundation/config/config-writer.mjs +152 -58
  174. package/foundation/config/project.mjs +103 -16
  175. package/foundation/discovery/component-discovery.mjs +11 -22
  176. package/foundation/discovery/icon-set-checks.mjs +164 -48
  177. package/foundation/discovery/icon-set-discovery.d.mts +38 -5
  178. package/foundation/discovery/icon-set-discovery.mjs +50 -6
  179. package/foundation/discovery/icon-set-theme-maps.d.mts +59 -0
  180. package/foundation/discovery/icon-set-theme-maps.mjs +95 -0
  181. package/foundation/discovery/icon-set-writer.d.mts +2 -3
  182. package/foundation/discovery/icon-set-writer.mjs +58 -17
  183. package/foundation/discovery/module-exports.mjs +1 -15
  184. package/foundation/discovery/template-adapter.mjs +44 -19
  185. package/foundation/discovery/template-icons.d.mts +27 -10
  186. package/foundation/discovery/template-icons.mjs +142 -26
  187. package/foundation/discovery/template-source-tree.mjs +3 -16
  188. package/foundation/discovery/theme-discovery.d.mts +30 -1
  189. package/foundation/discovery/theme-discovery.mjs +109 -50
  190. package/foundation/fs/exact-codec.d.mts +35 -0
  191. package/foundation/fs/exact-codec.mjs +148 -0
  192. package/foundation/fs/gather-cache.d.mts +15 -5
  193. package/foundation/fs/gather-cache.mjs +129 -31
  194. package/foundation/fs/paths.d.mts +39 -0
  195. package/foundation/fs/paths.mjs +44 -11
  196. package/foundation/fs/read-record.mjs +11 -1
  197. package/foundation/integrations/autolink.d.mts +4 -2
  198. package/foundation/integrations/autolink.mjs +4 -2
  199. package/foundation/integrations/cli-requirement.d.mts +16 -5
  200. package/foundation/integrations/cli-requirement.mjs +27 -6
  201. package/foundation/integrations/contribution-fixes.mjs +1 -16
  202. package/foundation/integrations/may-have-integrations.mjs +7 -3
  203. package/foundation/integrations/missing-dependency.d.mts +9 -0
  204. package/foundation/integrations/missing-dependency.mjs +100 -0
  205. package/foundation/integrations/public-imports.mjs +1 -1
  206. package/foundation/render/embedded-imports.mjs +1 -1
  207. package/foundation/render/host-exit.d.mts +8 -0
  208. package/foundation/render/host-exit.mjs +11 -0
  209. package/foundation/render/page-host.mjs +56 -10
  210. package/foundation/render/page-worker.mjs +14 -0
  211. package/foundation/render/render-page.mjs +37 -2
  212. package/foundation/response/error-codes.d.mts +2 -1
  213. package/foundation/response/error-codes.d.ts +1 -0
  214. package/foundation/response/error-codes.doc.mjs +5 -0
  215. package/foundation/response/error-codes.mjs +3 -0
  216. package/foundation/response/json.d.mts +15 -0
  217. package/foundation/response/json.mjs +52 -1
  218. package/foundation/response/response-types.doc.mjs +1 -1
  219. package/foundation/runtime/lazy-dependencies.d.mts +14 -0
  220. package/foundation/runtime/lazy-dependencies.mjs +82 -0
  221. package/foundation/xle/browser.d.mts +2 -2
  222. 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) {
@@ -600,8 +650,7 @@ const strategyOf = modes =>
600
650
  modes.length > 1 ? 'light-and-dark' : `${modes[0]}-only`;
601
651
 
602
652
  /**
603
- * The fields of a config the generator never reads (such as
604
- * `darkChromaTaper`), by path.
653
+ * The fields of a config the generator never reads, by path.
605
654
  * @param {any} config
606
655
  * @returns {string[]}
607
656
  */
@@ -724,7 +773,12 @@ function usableStops(stops, slug) {
724
773
  * @param {{settings: Setting[]}} data
725
774
  * @param {{light: Record<string, string>, dark: Record<string, string>} | undefined} base
726
775
  */
727
- function tools(candidate, data, base) {
776
+ function tools(
777
+ candidate,
778
+ data,
779
+ base,
780
+ /** @type {Record<string, string>} */ own = {},
781
+ ) {
728
782
  const {stops} = candidate;
729
783
  /** @param {number} n */
730
784
  const at = n => nearestStop(stops, n);
@@ -735,11 +789,15 @@ function tools(candidate, data, base) {
735
789
  };
736
790
  const neutral = Boolean(/** @type {any} */ (candidate.palette).neutral);
737
791
  /**
738
- * The exact whole-theme color a token setting gives in a mode, or null.
792
+ * The whole-theme value a token setting gives in a mode, as written, or
793
+ * undefined.
739
794
  * @param {string} token @param {Mode} m
740
795
  */
741
- const exactOf = (token, m) => {
742
- const v = [...data.settings]
796
+ const settingOf = (token, m) =>
797
+ // A page-wide token the theme's own source sets wins over the settings
798
+ // (the build shows it), as an exact setting would.
799
+ (Object.hasOwn(own, token) ? own[token] : undefined) ??
800
+ [...data.settings]
743
801
  .reverse()
744
802
  .find(
745
803
  s =>
@@ -750,29 +808,60 @@ function tools(candidate, data, base) {
750
808
  !s.state &&
751
809
  (!s.mode || s.mode === m),
752
810
  )?.value;
811
+ /**
812
+ * The fixed color a value gives in a mode, as written when it is one
813
+ * already, or null: `light-dark()` takes its side for the mode, and a
814
+ * `var()` reads the theme's own setting, else the base theme's value.
815
+ * @param {unknown} value @param {Mode} m @param {Set<string>} [seen]
816
+ * @returns {string | null}
817
+ */
818
+ const colorIn = (value, m, seen = new Set()) => {
819
+ const v = String(value ?? '').trim();
820
+ if (!v) return null;
821
+ if (parseColor(v)) return v;
822
+ const fn = /^([a-z-]+)\((.*)\)$/is.exec(v);
823
+ if (!fn) return null;
824
+ const name = fn[1].toLowerCase();
825
+ if (name === 'light-dark') {
826
+ const halves = splitTop(fn[2], ',');
827
+ return halves.length === 2
828
+ ? colorIn(halves[m === 'dark' ? 1 : 0], m, seen)
829
+ : null;
830
+ }
831
+ if (name !== 'var') {
832
+ // A color function of tokens (a color-mix() of two) reads each one.
833
+ const put = v.replace(
834
+ /var\(\s*(--[a-z0-9-]+)\s*\)/gi,
835
+ (whole, t) => colorIn(`var(${t})`, m, new Set(seen)) ?? whole,
836
+ );
837
+ return put !== v && parseColor(put) ? put : null;
838
+ }
839
+ const [ref, ...rest] = splitTop(fn[2], ',');
840
+ const t = ref.trim();
841
+ if (!/^--[a-z0-9-]+$/i.test(t) || seen.has(t)) return null;
842
+ seen.add(t);
843
+ const own = settingOf(t, m);
844
+ const read =
845
+ own != null ? colorIn(own, m, seen) : colorIn(base?.[m]?.[t], m, seen);
846
+ return read ?? (rest.length ? colorIn(rest.join(','), m, seen) : null);
847
+ };
848
+ /**
849
+ * The exact whole-theme color a token setting gives in a mode, or null.
850
+ * @param {string} token @param {Mode} m
851
+ */
852
+ const exactOf = (token, m) => {
853
+ const v = colorIn(settingOf(token, m), m);
753
854
  const rgb = v == null ? null : parseColor(v);
754
- return rgb && alphaOf(v) >= 1 ? hex(rgb) : null;
855
+ return rgb && v != null && alphaOf(v) >= 1 ? hex(rgb) : null;
755
856
  };
756
857
  /**
757
858
  * 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.
859
+ * or not, as written (a hex keeps its alpha digits; a `light-dark()` or a
860
+ * `var()` gives the color it reads in the mode); null when there is none
861
+ * or it is not a fixed color.
760
862
  * @param {string} token @param {Mode} m
761
863
  */
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
- };
864
+ const rawOf = (token, m) => colorIn(settingOf(token, m), m);
776
865
  /**
777
866
  * Which column of a `[light, dark]` mapping a mode takes: the light one
778
867
  * on a light page and the dark one on a dark page, by the page the theme
@@ -873,6 +962,7 @@ function tools(candidate, data, base) {
873
962
  at,
874
963
  ref,
875
964
  exactOf,
965
+ settingOf,
876
966
  rawOf,
877
967
  side,
878
968
  solid,
@@ -952,7 +1042,10 @@ function planPalette(cwd, slug, data, base) {
952
1042
  ? {...existing}
953
1043
  : {};
954
1044
  const {settings: saved, mode: savedMode} = savedSettings(cwd, slug);
955
- const modes = modesOf(data);
1045
+ // Every theme's palette has both modes: a one-mode theme keeps both
1046
+ // halves of its colors (its mode is the one the app's <Theme> is given),
1047
+ // and a region Core draws in the other mode reads the other half.
1048
+ const modes = modesForStrategy('light-and-dark');
956
1049
 
957
1050
  const vibrancy = dialVibrancy(data.settings);
958
1051
  const savedVibrancy = dialVibrancy(saved);
@@ -1123,6 +1216,16 @@ function planPalette(cwd, slug, data, base) {
1123
1216
  families.push(family);
1124
1217
  }
1125
1218
  if (!families.length) return null;
1219
+ // The editor's colors stand in the order of their settings, wherever they
1220
+ // sit among a config's own families, so a step back writes the same file.
1221
+ const slots = families
1222
+ .map((f, i) => (PALETTE_DIALS.includes(f?.id) ? i : -1))
1223
+ .filter(i => i >= 0);
1224
+ const inOrder = fams
1225
+ .map(x => families.find(f => f?.id === x.id))
1226
+ .filter(Boolean);
1227
+ if (inOrder.length === slots.length)
1228
+ slots.forEach((i, k) => (families[i] = inOrder[k]));
1126
1229
  config.families = families;
1127
1230
  const dead = deadKeys(config);
1128
1231
  if (dead.length)
@@ -1145,7 +1248,12 @@ function planPalette(cwd, slug, data, base) {
1145
1248
  // The exact color anchors dark mode too when it reads there, as the
1146
1249
  // official themes anchor a brand color in both modes.
1147
1250
  if (modes.includes('dark') && Object.keys(fills).length) {
1148
- const t = tools(generate(config, file), data, base);
1251
+ const t = tools(
1252
+ generate(config, file),
1253
+ data,
1254
+ base,
1255
+ ownSourceTokenValues(cwd, slug),
1256
+ );
1149
1257
  /** @type {string[]} */
1150
1258
  const add = [];
1151
1259
  for (const [id, fill] of Object.entries(fills)) {
@@ -1266,7 +1374,12 @@ function syncPaletteFiles(cwd, slug, data, base) {
1266
1374
  const hash = fs.existsSync(abs(f.config))
1267
1375
  ? sha256(fs.readFileSync(abs(f.config)))
1268
1376
  : null;
1269
- const mine = hash != null && (data.palette === hash || saved === hash);
1377
+ // Or the config the editor recorded writing (a color change stopped
1378
+ // before its settings were saved).
1379
+ const recorded = readWrittenRecord(cwd, slug)['palette.config.json'];
1380
+ const mine =
1381
+ hash != null &&
1382
+ (data.palette === hash || saved === hash || recorded === hash);
1270
1383
  delete data.palette;
1271
1384
  if (!mine) return [];
1272
1385
  // A palette file edited by hand is never deleted: it stays, and the
@@ -1279,6 +1392,7 @@ function syncPaletteFiles(cwd, slug, data, base) {
1279
1392
  const notes = [];
1280
1393
  for (const p of [f.config, f.receipt, f.refs])
1281
1394
  fs.rmSync(abs(p), {force: true});
1395
+ noteWritten(cwd, slug, 'palette.config.json', null);
1282
1396
  if (editedPalette)
1283
1397
  notes.push(
1284
1398
  `${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 +1441,75 @@ function syncPaletteFiles(cwd, slug, data, base) {
1327
1441
  );
1328
1442
  }
1329
1443
  fs.mkdirSync(path.dirname(abs(f.config)), {recursive: true});
1444
+ // Recorded before it is written: a run stopped after this leaves a config
1445
+ // the next build knows is the editor's.
1446
+ noteWritten(cwd, slug, 'palette.config.json', sha256(Buffer.from(text)));
1330
1447
  writeWhole(abs(f.config), text);
1331
1448
  data.palette = sha256(Buffer.from(text));
1332
1449
  themePaletteGenerate(f.config, {out: f.palette, overwrite: true}, {cwd});
1333
1450
  return plan.notes;
1334
1451
  }
1335
1452
 
1453
+ /**
1454
+ * The record of the files the editor wrote into a theme folder,
1455
+ * `themes/<theme>/<theme>.pictures.json`: each by name, with the hash of
1456
+ * what was written (its pictures and its color config). The one reader and
1457
+ * writer of that record.
1458
+ * @param {string} cwd
1459
+ * @param {string} slug
1460
+ * @returns {Record<string, string>}
1461
+ */
1462
+ export function readWrittenRecord(cwd, slug) {
1463
+ try {
1464
+ const json = JSON.parse(
1465
+ fs.readFileSync(writtenRecordFile(cwd, slug), 'utf8'),
1466
+ );
1467
+ return json && typeof json === 'object' && !Array.isArray(json) ? json : {};
1468
+ } catch {
1469
+ return {};
1470
+ }
1471
+ }
1472
+
1473
+ /** @param {string} cwd @param {string} slug */
1474
+ const writtenRecordFile = (cwd, slug) =>
1475
+ path.join(cwd, 'themes', slug, `${slug}.pictures.json`);
1476
+
1477
+ /**
1478
+ * Write the record whole, or remove it when it names nothing. A record that
1479
+ * cannot be written leaves nothing removed later: the safe way round.
1480
+ * @param {string} cwd
1481
+ * @param {string} slug
1482
+ * @param {Record<string, string>} map
1483
+ */
1484
+ export function writeWrittenRecord(cwd, slug, map) {
1485
+ const file = writtenRecordFile(cwd, slug);
1486
+ try {
1487
+ if (!Object.keys(map).length) fs.rmSync(file, {force: true});
1488
+ else {
1489
+ fs.mkdirSync(path.dirname(file), {recursive: true});
1490
+ writeWhole(file, `${JSON.stringify(map, null, 2)}\n`);
1491
+ }
1492
+ } catch {
1493
+ // Without the record, nothing it names is removed later.
1494
+ }
1495
+ }
1496
+
1497
+ /**
1498
+ * Note a file the editor wrote into a theme folder, by name with the hash
1499
+ * of what it wrote, or forget it (null).
1500
+ * @param {string} cwd
1501
+ * @param {string} slug
1502
+ * @param {string} name
1503
+ * @param {string | null} hash
1504
+ */
1505
+ export function noteWritten(cwd, slug, name, hash) {
1506
+ const map = readWrittenRecord(cwd, slug);
1507
+ if (hash) map[name] = hash;
1508
+ else if (name in map) delete map[name];
1509
+ else return;
1510
+ writeWrittenRecord(cwd, slug, map);
1511
+ }
1512
+
1336
1513
  /**
1337
1514
  * The value of the object literal that starts at the first `{` from
1338
1515
  * `from`, read as data: string and numeric keys, string values, nested
@@ -1724,15 +1901,18 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
1724
1901
  const plan = /** @type {PalettePlan} */ (planPalette(cwd, slug, data, base));
1725
1902
  const {config} = plan;
1726
1903
  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);
1904
+ const t = tools(candidate, data, base, ownSourceTokenValues(cwd, slug));
1905
+ const {stops, at, ref, exactOf, rawOf, settingOf, side, solid, surfaces} = t;
1906
+ // Both halves, for a one-mode theme too (see planPalette).
1907
+ const modes = modesForStrategy('light-and-dark');
1730
1908
  /** @type {PaletteMapping['tokens']} */
1731
1909
  const tokens = {};
1732
1910
  /** @type {ContrastCheck[]} */
1733
1911
  const checks = [];
1734
1912
  /** @type {PaletteMapping['exact']} */
1735
1913
  const exact = {};
1914
+ /** @type {Record<string, string>} */
1915
+ const unread = {};
1736
1916
  const has = (/** @type {string} */ k) => k in tokenDefaults;
1737
1917
  /** A token the theme sets exactly in any mode: no check speaks for it. @param {string} k */
1738
1918
  const setExactly = k =>
@@ -1877,8 +2057,22 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
1877
2057
  for (const m of modes) {
1878
2058
  const v = rawOf(names.fill, m);
1879
2059
  if (v) exactFill[m] = v;
2060
+ else if (settingOf(names.fill, m) != null)
2061
+ unread[names.fill] = String(settingOf(names.fill, m)).trim();
1880
2062
  }
1881
- if (Object.keys(exactFill).length) exact[names.fill] = exactFill;
2063
+ if (Object.keys(exactFill).length)
2064
+ exact[names.fill] = Object.fromEntries(
2065
+ Object.entries(exactFill).map(([m, v]) => {
2066
+ // A var() is named with the color it reads, so the note says
2067
+ // which color the text was picked for.
2068
+ const written = String(
2069
+ settingOf(names.fill, /** @type {Mode} */ (m)) ?? '',
2070
+ ).trim();
2071
+ const rgb = parseColor(v);
2072
+ const color = rgb && alphaOf(v) >= 1 ? hex(rgb) : v;
2073
+ return [m, /var\(/i.test(written) ? `${written} = ${color}` : v];
2074
+ }),
2075
+ );
1882
2076
 
1883
2077
  /** @type {Partial<Record<Mode, StopRef>>} */
1884
2078
  const fill = {};
@@ -2139,6 +2333,37 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
2139
2333
  const found = {};
2140
2334
  for (const ground of new Set(LIFT_PARTS.map(([, , g]) => g))) {
2141
2335
  const {what, parts} = LIFT_GROUNDS[ground];
2336
+ /**
2337
+ * The shade the base theme itself lifts this ground's text to in a
2338
+ * mode, when it gives one: the search starts there, so a change of
2339
+ * color moves it only when that shade no longer reads.
2340
+ * @param {Mode} m
2341
+ * @returns {string | null}
2342
+ */
2343
+ const baseLift = m => {
2344
+ for (const [part, block, g] of LIFT_PARTS) {
2345
+ if (g !== ground) continue;
2346
+ const v = /** @type {any} */ (base)?.components?.[part]?.[block]?.[
2347
+ '--color-text-secondary'
2348
+ ];
2349
+ const pair = Array.isArray(v)
2350
+ ? v
2351
+ : typeof v === 'string'
2352
+ ? /^light-dark\((.*)\)$/s.exec(v.trim())?.[1]
2353
+ ? splitTop(
2354
+ /** @type {string} */ (
2355
+ /^light-dark\((.*)\)$/s.exec(v.trim())?.[1]
2356
+ ),
2357
+ ',',
2358
+ )
2359
+ : [v, v]
2360
+ : null;
2361
+ const c = pair?.[m === 'light' ? 0 : 1]?.trim();
2362
+ if (c && parseColor(c))
2363
+ return hex(/** @type {number[]} */ (parseColor(c)));
2364
+ }
2365
+ return null;
2366
+ };
2142
2367
  /** @type {Partial<Record<Mode, StopRef>>} */
2143
2368
  const byMode = {};
2144
2369
  for (const m of modes) {
@@ -2168,8 +2393,9 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
2168
2393
  const keys = Object.keys(g.ramp)
2169
2394
  .map(Number)
2170
2395
  .sort((a, b) => a - b);
2396
+ const from = baseLift(m) ?? text;
2171
2397
  const start = keys.reduce((x, y) =>
2172
- perceptualDelta(g.ramp[y], text) < perceptualDelta(g.ramp[x], text)
2398
+ perceptualDelta(g.ramp[y], from) < perceptualDelta(g.ramp[x], from)
2173
2399
  ? y
2174
2400
  : x,
2175
2401
  );
@@ -2190,7 +2416,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
2190
2416
  ? ref('neutral', m, b.stop)
2191
2417
  : {stop: b.stop, color: g.ramp[b.stop], family: 'literal'};
2192
2418
  const moved =
2193
- hex(/** @type {number[]} */ (parseColor(g.ramp[b.stop]))) !== text;
2419
+ hex(/** @type {number[]} */ (parseColor(g.ramp[b.stop]))) !== from;
2194
2420
  if (b.r < TEXT || moved)
2195
2421
  checks.push({
2196
2422
  token: '--color-text-secondary',
@@ -2204,7 +2430,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
2204
2430
  dials: ['accent', 'neutral'],
2205
2431
  note:
2206
2432
  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`
2433
+ ? `--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
2434
  : `--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
2435
  });
2210
2436
  }
@@ -2221,6 +2447,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
2221
2447
  lift,
2222
2448
  vibrancy: config.vibrancy ?? VIBRANCY_DEFAULT,
2223
2449
  exact,
2450
+ unread,
2224
2451
  notes: [
2225
2452
  ...plan.notes,
2226
2453
  ...(paletteEdited(cwd, slug)
@@ -2350,7 +2577,13 @@ export function paletteNotes(pal, dial, slug, modes = ['light', 'dark']) {
2350
2577
  notes.push(
2351
2578
  `${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
2579
  );
2353
- } else if (main) {
2580
+ }
2581
+ const unread = pal.unread?.[token];
2582
+ if (unread) {
2583
+ notes.push(
2584
+ `${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'}`,
2585
+ );
2586
+ } else if (!exact && main) {
2354
2587
  /** @param {Mode} m */
2355
2588
  const part = m =>
2356
2589
  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.