@astryxdesign/cli 0.7.17 → 0.7.18-canary.g32556bb

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 (261) hide show
  1. package/README.md +1 -1
  2. package/api/discover/_adapter.d.mts +7 -5
  3. package/api/discover/_adapter.mjs +12 -11
  4. package/api/docs/_adapter.d.mts +19 -2
  5. package/api/docs/_adapter.mjs +66 -5
  6. package/api/doctor/_adapter.d.mts +11 -62
  7. package/api/doctor/_adapter.mjs +242 -472
  8. package/api/doctor/doctor.d.mts +1 -1
  9. package/api/doctor/doctor.mjs +3 -3
  10. package/api/doctor/theme-checks.mjs +37 -45
  11. package/api/error.d.mts +21 -0
  12. package/api/error.mjs +89 -0
  13. package/api/hook/list/list.d.mts +1 -1
  14. package/api/icon/_adapter.d.mts +8 -0
  15. package/api/icon/_adapter.mjs +17 -0
  16. package/api/icon/_authoring.mjs +6 -6
  17. package/api/icon/_default-look.mjs +16 -16
  18. package/api/icon/add/add.mjs +3 -3
  19. package/api/icon/exportIconIndex.doc.mjs +2 -2
  20. package/api/icon/icon.doc.mjs +2 -2
  21. package/api/icon/icon.type.d.mts +4 -0
  22. package/api/icon/icon.type.mjs +2 -1
  23. package/api/icon/search/icon-index.mjs +16 -3
  24. package/api/icon/search/search.d.mts +15 -5
  25. package/api/icon/search/search.mjs +74 -16
  26. package/api/icon/use/use.mjs +4 -4
  27. package/api/render/_adapter.mjs +233 -40
  28. package/api/render/render.type.d.mts +1 -1
  29. package/api/render/render.type.mjs +1 -1
  30. package/api/search/ORDERING.md +2 -2
  31. package/api/search/_adapter.mjs +4 -0
  32. package/api/search/_candidate-score.mjs +32 -8
  33. package/api/search/_cards.json +1 -1
  34. package/api/search/_compound.d.mts +0 -1
  35. package/api/search/_compound.mjs +93 -2
  36. package/api/search/_icons.d.mts +4 -2
  37. package/api/search/_icons.mjs +4 -2
  38. package/api/search/_lexical.mjs +177 -17
  39. package/api/search/_order.d.mts +3 -1
  40. package/api/search/_order.mjs +16 -5
  41. package/api/search/_result.d.mts +9 -0
  42. package/api/search/_result.mjs +10 -0
  43. package/api/search/_score.mjs +21 -3
  44. package/api/swizzle/_moduleGraph.d.mts +8 -0
  45. package/api/swizzle/_moduleGraph.mjs +61 -3
  46. package/api/template/copy/copy.mjs +5 -3
  47. package/api/template/template.type.d.mts +3 -3
  48. package/api/template/template.type.mjs +3 -3
  49. package/api/theme/_adapter.mjs +48 -12
  50. package/api/theme/build/build.d.mts +4 -0
  51. package/api/theme/build/build.mjs +69 -18
  52. package/api/theme/build/style-keys.mjs +4 -5
  53. package/api/theme/build/theme-object.mjs +5 -0
  54. package/api/theme/palette/generate/color.d.mts +47 -0
  55. package/api/theme/palette/generate/color.mjs +58 -1
  56. package/api/theme/palette/generate/derive-look.d.mts +293 -0
  57. package/api/theme/palette/generate/derive-look.mjs +1362 -0
  58. package/api/theme/palette/generate/editor-look.d.mts +62 -0
  59. package/api/theme/palette/generate/editor-look.mjs +550 -0
  60. package/api/theme/palette/generate/mapping.d.mts +94 -9
  61. package/api/theme/palette/generate/mapping.mjs +94 -22
  62. package/api/theme-edit/_adapter.mjs +13 -2
  63. package/api/theme-edit/_catalog.d.mts +13 -13
  64. package/api/theme-edit/_catalog.mjs +66 -28
  65. package/api/theme-edit/_check.d.mts +82 -6
  66. package/api/theme-edit/_check.mjs +1270 -238
  67. package/api/theme-edit/_color.d.mts +74 -0
  68. package/api/theme-edit/_color.mjs +168 -3
  69. package/api/theme-edit/_compiler.d.mts +3 -5
  70. package/api/theme-edit/_compiler.mjs +122 -23
  71. package/api/theme-edit/_context.d.mts +55 -12
  72. package/api/theme-edit/_context.mjs +114 -60
  73. package/api/theme-edit/_css.d.mts +11 -0
  74. package/api/theme-edit/_css.mjs +40 -0
  75. package/api/theme-edit/_edit.d.mts +15 -2
  76. package/api/theme-edit/_edit.mjs +1469 -133
  77. package/api/theme-edit/_how-commands.d.mts +116 -0
  78. package/api/theme-edit/_how-commands.mjs +227 -115
  79. package/api/theme-edit/_how-question.d.mts +74 -29
  80. package/api/theme-edit/_how-question.mjs +8514 -1256
  81. package/api/theme-edit/_how-sides.d.mts +22 -0
  82. package/api/theme-edit/_how-sides.mjs +173 -0
  83. package/api/theme-edit/_how-steps.d.mts +42 -0
  84. package/api/theme-edit/_how-steps.mjs +208 -0
  85. package/api/theme-edit/_how-values.d.mts +29 -0
  86. package/api/theme-edit/_how-values.mjs +111 -0
  87. package/api/theme-edit/_how-words.d.mts +15 -0
  88. package/api/theme-edit/_how-words.mjs +239 -0
  89. package/api/theme-edit/_how.d.mts +1 -1
  90. package/api/theme-edit/_how.mjs +422 -37
  91. package/api/theme-edit/_missed.d.mts +2 -1
  92. package/api/theme-edit/_missed.mjs +125 -13
  93. package/api/theme-edit/_normal.d.mts +5 -3
  94. package/api/theme-edit/_normal.mjs +54 -14
  95. package/api/theme-edit/_palette.d.mts +204 -4
  96. package/api/theme-edit/_palette.mjs +901 -25
  97. package/api/theme-edit/_part-pieces.d.mts +54 -0
  98. package/api/theme-edit/_part-pieces.mjs +179 -0
  99. package/api/theme-edit/_part-words.mjs +33 -5
  100. package/api/theme-edit/_parts.d.mts +133 -0
  101. package/api/theme-edit/_parts.mjs +599 -10
  102. package/api/theme-edit/_picture-traits.d.mts +259 -0
  103. package/api/theme-edit/_picture-traits.mjs +1030 -0
  104. package/api/theme-edit/_preview.d.mts +95 -4
  105. package/api/theme-edit/_preview.mjs +284 -31
  106. package/api/theme-edit/_project.d.mts +14 -4
  107. package/api/theme-edit/_project.mjs +95 -26
  108. package/api/theme-edit/_resolved.d.mts +46 -0
  109. package/api/theme-edit/_resolved.mjs +800 -0
  110. package/api/theme-edit/_set-line.d.mts +29 -0
  111. package/api/theme-edit/_set-line.mjs +100 -0
  112. package/api/theme-edit/_settings.d.mts +625 -28
  113. package/api/theme-edit/_settings.mjs +4867 -888
  114. package/api/theme-edit/_tables.d.mts +25 -1
  115. package/api/theme-edit/_tables.mjs +115 -11
  116. package/api/theme-edit/_text-looks.d.mts +78 -0
  117. package/api/theme-edit/_text-looks.mjs +376 -0
  118. package/api/theme-edit/_vet.d.mts +3 -26
  119. package/api/theme-edit/_vet.mjs +5 -89
  120. package/api/theme-edit/how/how.d.mts +1 -1
  121. package/api/theme-edit/how/how.mjs +1 -1
  122. package/api/theme-edit/show/show.d.mts +4 -3
  123. package/api/theme-edit/show/show.mjs +3 -2
  124. package/api/theme-edit/theme-edit.type.d.mts +117 -1
  125. package/api/theme-edit/theme-edit.type.mjs +46 -3
  126. package/api/theme-edit/themeEditHow.doc.mjs +3 -3
  127. package/api/theme-edit/themeEditNew.doc.mjs +4 -0
  128. package/api/theme-edit/themeEditSet.doc.mjs +6 -2
  129. package/api/theme-edit/themeEditShow.doc.mjs +22 -3
  130. package/api/theme-edit/themeEditUndo.doc.mjs +4 -0
  131. package/assets/component-list.generated.json +1 -1
  132. package/assets/docs/author-a-theme.doc.mjs +7 -4
  133. package/assets/docs/icons.doc.mjs +7 -6
  134. package/assets/docs/theme.doc.dense.mjs +10 -0
  135. package/assets/docs/theme.doc.mjs +10 -0
  136. package/assets/docs/theme.doc.zh.mjs +10 -0
  137. package/assets/docs/tree/export-pages.doc.mjs +1 -1
  138. package/assets/docs/tree/icon-sets.doc.mjs +1 -1
  139. package/assets/docs/use-a-theme.doc.mjs +89 -17
  140. package/assets/docs-routes.generated.json +1 -1
  141. package/assets/docs.generated.json +2 -2
  142. package/assets/icons/definitions/article.doc.mjs +9 -0
  143. package/assets/icons/template-icons.json +5 -0
  144. package/assets/search-catalog.generated.json +2 -2
  145. package/assets/self-audit.generated.json +1 -1
  146. package/assets/templates/blocks/components/Citation/CitationInlineText.doc.mjs +1 -1
  147. package/assets/templates/blocks/components/Citation/CitationInlineText.tsx +3 -1
  148. package/assets/templates/blocks/components/Citation/CitationShowcase.doc.mjs +1 -1
  149. package/assets/templates/blocks/components/Citation/CitationShowcase.tsx +3 -1
  150. package/assets/templates/blocks/components/Citation/CitationSourceList.doc.mjs +1 -1
  151. package/assets/templates/blocks/components/Citation/CitationSourceList.tsx +7 -3
  152. package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.doc.mjs +1 -1
  153. package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.tsx +5 -2
  154. package/assets/templates/blocks/components/SideNav/SideNavShowcase.tsx +9 -1
  155. package/assets/templates/blocks/components/SideNavCollapseButton/SideNavCollapseButtonShowcase.doc.mjs +9 -2
  156. package/assets/templates/blocks/components/SideNavHeading/SideNavHeadingShowcase.doc.mjs +3 -2
  157. package/assets/templates/blocks/components/SideNavHeading/SideNavHeadingShowcase.tsx +2 -1
  158. package/assets/templates/blocks/components/SideNavItem/SideNavItemShowcase.doc.mjs +3 -2
  159. package/assets/templates/blocks/components/SideNavSection/SideNavSectionShowcase.doc.mjs +2 -1
  160. package/assets/templates/components.generated.json +1 -1
  161. package/assets/templates/pages/ide/page.tsx +5 -10
  162. package/assets/templates/pages/payment-form/page.tsx +16 -60
  163. package/assets/templates/themes/neutral/neutralTheme.ts +4 -3
  164. package/authoring/config/parse.mjs +1 -1
  165. package/authoring/debug/parse.d.mts +1 -1
  166. package/authoring/doctypes/_schema.d.mts +13 -13
  167. package/authoring/doctypes/icon-definition/parse.mjs +2 -2
  168. package/authoring/doctypes/icon-set/parse.mjs +1 -1
  169. package/authoring/doctypes/template/parse.mjs +1 -4
  170. package/authoring/gap-report/parse.d.mts +1 -1
  171. package/clients/cli/build-id.generated.json +1 -1
  172. package/clients/cli/commands/ensure-core-built.mjs +17 -10
  173. package/clients/cli/commands/experimental/icon.mjs +7 -7
  174. package/clients/cli/commands/experimental/theme.mjs +175 -13
  175. package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
  176. package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
  177. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +11 -3
  178. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +3 -3
  179. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +15 -5
  180. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  181. package/clients/cli/commands/hook.mjs +7 -0
  182. package/clients/cli/commands/template.mjs +1 -1
  183. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  184. package/clients/cli/index.mjs +6 -2
  185. package/clients/cli/lib/hook-format.mjs +41 -1
  186. package/clients/cli/lib/json-shim.mjs +34 -14
  187. package/clients/cli/lib/other-cli-words.mjs +7 -0
  188. package/clients/cli/lib/unknown-command.mjs +345 -46
  189. package/clients/cli/manifest.generated.json +1 -1
  190. package/foundation/agent-docs/agent-docs.d.mts +11 -2
  191. package/foundation/agent-docs/agent-docs.mjs +51 -8
  192. package/foundation/config/project.d.mts +11 -1
  193. package/foundation/config/project.mjs +11 -2
  194. package/foundation/discovery/component-replacement.d.mts +5 -8
  195. package/foundation/discovery/component-replacement.mjs +12 -14
  196. package/foundation/discovery/core-augmentation-points.d.mts +35 -0
  197. package/foundation/discovery/core-augmentation-points.mjs +410 -9
  198. package/foundation/discovery/core-elements.d.mts +6 -0
  199. package/foundation/discovery/core-elements.mjs +10 -2
  200. package/foundation/discovery/core-prop-types.d.mts +5 -0
  201. package/foundation/discovery/core-prop-types.mjs +10 -3
  202. package/foundation/discovery/core-props.d.mts +8 -0
  203. package/foundation/discovery/core-props.mjs +29 -13
  204. package/foundation/discovery/icon-ranking.d.mts +5 -2
  205. package/foundation/discovery/icon-ranking.mjs +101 -18
  206. package/foundation/discovery/icon-set-checks.mjs +1 -1
  207. package/foundation/discovery/icon-set-writer.mjs +1 -1
  208. package/foundation/discovery/official-list.d.mts +17 -0
  209. package/foundation/discovery/official-list.mjs +77 -0
  210. package/foundation/discovery/template-icon-notes.mjs +3 -3
  211. package/foundation/discovery/template-icons.mjs +2 -2
  212. package/foundation/discovery/template-placeholders.mjs +1 -1
  213. package/foundation/discovery/unknown-core-props.d.mts +130 -0
  214. package/foundation/discovery/unknown-core-props.mjs +601 -0
  215. package/foundation/discovery/written-prop-values.d.mts +35 -0
  216. package/foundation/discovery/written-prop-values.mjs +258 -0
  217. package/foundation/fonts/fontsource-families.generated.d.mts +5 -0
  218. package/foundation/fonts/fontsource-families.generated.mjs +2110 -0
  219. package/foundation/fs/package-name.d.mts +10 -0
  220. package/foundation/fs/package-name.mjs +37 -0
  221. package/foundation/fs/project-source-files.d.mts +27 -0
  222. package/foundation/fs/project-source-files.mjs +115 -0
  223. package/foundation/fs/project-sources.d.mts +25 -0
  224. package/foundation/fs/project-sources.mjs +83 -0
  225. package/foundation/fs/read-record.d.mts +18 -0
  226. package/foundation/fs/read-record.mjs +36 -2
  227. package/foundation/integrations/integration-warnings.d.mts +39 -7
  228. package/foundation/integrations/integration-warnings.mjs +141 -19
  229. package/foundation/integrations/missing-dependency.d.mts +11 -0
  230. package/foundation/integrations/missing-dependency.mjs +20 -5
  231. package/foundation/release/folder-lock.d.mts +5 -2
  232. package/foundation/release/folder-lock.mjs +9 -3
  233. package/foundation/release/notices.mjs +2 -8
  234. package/foundation/render/cut-short.d.mts +8 -2
  235. package/foundation/render/cut-short.mjs +50 -5
  236. package/foundation/render/drawn-contrast.d.mts +40 -0
  237. package/foundation/render/drawn-contrast.mjs +355 -0
  238. package/foundation/render/file-header.mjs +4 -0
  239. package/foundation/render/layers.d.mts +2 -1
  240. package/foundation/render/layers.mjs +22 -1
  241. package/foundation/render/package-resolve-hooks.d.mts +38 -9
  242. package/foundation/render/package-resolve-hooks.mjs +124 -32
  243. package/foundation/render/page-worker.mjs +95 -23
  244. package/foundation/render/part-boxes.d.mts +27 -0
  245. package/foundation/render/part-boxes.mjs +45 -0
  246. package/foundation/render/picture-chrome.mjs +36 -4
  247. package/foundation/render/picture-playwright.mjs +26 -2
  248. package/foundation/render/picture-window.d.mts +29 -2
  249. package/foundation/render/picture-window.mjs +99 -1
  250. package/foundation/render/render-page.d.mts +39 -6
  251. package/foundation/render/render-page.mjs +26 -10
  252. package/foundation/render/ts-paths.mjs +2 -1
  253. package/foundation/response/error-codes.doc.mjs +1 -1
  254. package/foundation/response/error-codes.mjs +1 -1
  255. package/foundation/response/response-types.doc.mjs +9 -5
  256. package/foundation/suggest/other-command.mjs +25 -1
  257. package/foundation/text/icon-set-next.d.mts +1 -1
  258. package/foundation/text/icon-set-next.mjs +2 -2
  259. package/foundation/text/written-string.d.mts +4 -1
  260. package/foundation/text/written-string.mjs +4 -1
  261. package/package.json +8 -7
@@ -62,12 +62,18 @@ import {
62
62
  fillAt,
63
63
  grownGrays,
64
64
  isGray,
65
+ isLookToken,
65
66
  mapPalette,
66
67
  nearestShade,
67
68
  paletteToken,
68
69
  sameColor,
69
70
  shade,
70
71
  } from '../theme/palette/generate/mapping.mjs';
72
+ import * as editorLook from '../theme/palette/generate/editor-look.mjs';
73
+ import {
74
+ cvdClashes,
75
+ isLookFamily,
76
+ } from '../theme/palette/generate/derive-look.mjs';
71
77
  /**
72
78
  * How the page-wide tokens a theme's own source sets are read: given by
73
79
  * _settings (which imports this module) when it loads.
@@ -83,7 +89,13 @@ export function setOwnTokenReader(read) {
83
89
  ownSourceTokenValues = read;
84
90
  }
85
91
  import {alphaOf, hex, isClipped, parseColor} from './_color.mjs';
92
+ import {
93
+ contrastRatio,
94
+ hexToOklch,
95
+ oklchClampedHex,
96
+ } from '../theme/palette/generate/color.mjs';
86
97
  import {splitTop} from './_css.mjs';
98
+ import {isColorToken} from './_compiler.mjs';
87
99
  import {P} from './_tables.mjs';
88
100
  import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
89
101
  import {sha256} from '../../foundation/render/source-block.mjs';
@@ -283,6 +295,7 @@ export function tempFor(file) {
283
295
  * @property {string} [alpha] - Two hex digits of opacity.
284
296
  * @property {string} [family] - The family the stop is from when it is not the token's own: `neutral` for text on a fill, or `black` / `white`, the palette's own ends.
285
297
  * @property {boolean} [exact] - The stop holds the seed's exact color (an exact anchor).
298
+ * @property {boolean} [base] - The half is the base theme's own value in that mode (family `literal`): the generated module reads it from the base, so the mode follows the base theme.
286
299
  */
287
300
 
288
301
  /**
@@ -304,7 +317,8 @@ export function tempFor(file) {
304
317
  /**
305
318
  * A color dial's family: its seed, and the source token that gives it when
306
319
  * the theme's own source sets the family's fill (null when the setting does).
307
- * @typedef {{id: string, dial: string, seed: string, value: string, source: string | null}} DialFamily
320
+ * An accent set as a token carries the one mode it is for.
321
+ * @typedef {{id: string, dial: string, seed: string, value: string, source: string | null, only?: 'light' | 'dark'}} DialFamily
308
322
  */
309
323
 
310
324
  /**
@@ -314,10 +328,16 @@ export function tempFor(file) {
314
328
  * @property {DialFamily[]} families
315
329
  * @property {Record<string, {family: string, light: StopRef, dark: StopRef}>} tokens
316
330
  * @property {ContrastCheck[]} contrast
331
+ * @property {boolean} [stored] - Whether the palette is kept as saved (made with a recipe this CLI does not know): its colors cannot change here.
317
332
  * @property {number} vibrancy - The generator's vibrancy, 0 to 100.
318
333
  * @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.
319
334
  * @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.
320
335
  * @property {string[]} notes - What the config writer kept or replaced of a hand edit.
336
+ * @property {{badges: 'derived' | 'none', chart: 'derived' | 'none', limits: string[], moved: string[], alike: boolean, unread: boolean}} [categories] - Whether the category colors (Badge, Token, Card tints) and the chart colors follow the look, and what they gave up to stay written.
337
+ * @property {Array<{a: string, b: string, vision: 'red-weak' | 'green-weak', mode: Mode, colors: [string, string], page?: string, pages?: string[]}>} [cvd] - Status fills someone red-weak or green-weak may not tell apart.
338
+ * @property {string[]} [code] - The code colors that keep the base theme's because none of their family's stops reads on the code background and the page.
339
+ * @property {Array<{token: string, mode: Mode, pair: import('../theme/palette/generate/mapping.mjs').BasePair, ratio: number}>} [kept] - The look's colors kept at the base theme's in a mode, because a text/fill pair the base theme draws with them would not read.
340
+ * @property {{roles: Record<string, 'derived'>, why: string[], short: string[]}} [statuses] - The status roles the theme leaves unset, each derived from the look, and what they gave up to stay written.
321
341
  * @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.
322
342
  */
323
343
 
@@ -470,6 +490,38 @@ function dialFamilies(data, own = {}) {
470
490
  source: inEffect ? paletteToken(dial) : null,
471
491
  });
472
492
  }
493
+ // A whole-theme --color-accent set as a token is the accent too: the
494
+ // accent's shades (links, selected rows, tints) grow from it as from the
495
+ // dial, and the token itself keeps the exact value it was given.
496
+ if (!out.some(f => f.id === 'accent')) {
497
+ const raws = data.settings.filter(
498
+ x =>
499
+ x?.source === 'token' &&
500
+ x.thing === '--color-accent' &&
501
+ !x.on &&
502
+ !x.when &&
503
+ !x.state,
504
+ );
505
+ const last = (/** @type {(m: unknown) => boolean} */ ok) =>
506
+ [...raws].reverse().find(x => ok(x.mode));
507
+ const light = last(m => !m || m === 'light') ?? last(m => m === 'dark');
508
+ const seed = light && seedOf(light.value);
509
+ // Set for one mode only, it moves that mode only.
510
+ const modes = new Set(raws.map(x => x.mode ?? 'both'));
511
+ const only =
512
+ modes.size === 1 && (modes.has('light') || modes.has('dark'))
513
+ ? /** @type {'light' | 'dark'} */ ([...modes][0])
514
+ : null;
515
+ if (light && seed)
516
+ out.unshift({
517
+ id: 'accent',
518
+ dial: 'accent',
519
+ seed,
520
+ value: light.value,
521
+ source: null,
522
+ ...(only ? {only} : {}),
523
+ });
524
+ }
473
525
  return out;
474
526
  }
475
527
 
@@ -481,7 +533,121 @@ function dialFamilies(data, own = {}) {
481
533
  * @param {{settings: Setting[]}} data
482
534
  */
483
535
  export function seedsInEffect(cwd, slug, data) {
484
- return dialFamilies(data, ownSourceTokenValues(cwd, slug));
536
+ return seedsOfSettings(data, ownSourceTokenValues(cwd, slug));
537
+ }
538
+
539
+ /**
540
+ * The seeds of a theme's color settings, its own source's values read:
541
+ * what seedsInEffect returns, for a caller that holds those values.
542
+ * @param {{settings: Setting[]}} data
543
+ * @param {Record<string, string>} own the theme source's own token values
544
+ */
545
+ export function seedsOfSettings(data, own) {
546
+ // (A color setting's families only: an accent set as a token keeps its
547
+ // exact value, so it is not a seed a dial such as vibrancy moves.)
548
+ return dialFamilies(data, own).filter(f =>
549
+ data.settings.some(x => x?.source === 'dial' && x.thing === f.dial),
550
+ );
551
+ }
552
+
553
+ /**
554
+ * Whether `set <theme> vibrancy` changes anything: a color setting's seed
555
+ * that vibrancy moves, the check set runs.
556
+ * @param {{settings: Setting[]}} data
557
+ * @param {Record<string, string>} own the theme source's own token values
558
+ */
559
+ export function vibrancyTakes(data, own) {
560
+ return vibrancyMovesAny(seedsOfSettings(data, own));
561
+ }
562
+
563
+ /**
564
+ * Whether vibrancy changes any of these seeds: the one test `set <theme>
565
+ * vibrancy`, `how` and the color notes share.
566
+ * @param {DialFamily[]} seeds
567
+ */
568
+ export function vibrancyMovesAny(seeds) {
569
+ return seeds.some(f => vibrancyMoves(f.dial, f.seed, 0, 100));
570
+ }
571
+
572
+ /**
573
+ * The token words of the status roles a theme's look derives: every role
574
+ * it leaves unset, once it sets a color.
575
+ * @param {{settings: Setting[]}} data
576
+ * @returns {string[]}
577
+ */
578
+ export function derivedStatusWords(data) {
579
+ const fams = dialFamilies(data);
580
+ if (!fams.length) return [];
581
+ return Object.keys(STATUS_TOKEN)
582
+ .filter(d => !fams.some(f => f.id === d))
583
+ .map(d => STATUS_TOKEN[d]);
584
+ }
585
+
586
+ /**
587
+ * The tokens a theme sets to a value of its own for the whole theme: the
588
+ * change names each, apart from the colors that move with the look.
589
+ * @param {{settings: Setting[]}} data
590
+ * @returns {string[]}
591
+ */
592
+ export function exactTokens(data) {
593
+ return data.settings
594
+ .filter(x => x?.source === 'token' && !x.on && !x.when && !x.state)
595
+ .map(x => x.thing);
596
+ }
597
+
598
+ export {isLookToken, STATUS_TOKEN};
599
+
600
+ /** A code color or the overlay scrim. @param {string} token */
601
+ const isCodeToken = token => /^--color-(?:syntax-[a-z]+|overlay)$/.test(token);
602
+
603
+ /**
604
+ * A change's token lines with the look's own (category and chart colors)
605
+ * said in one line each, as counts: they move together with every look
606
+ * change, and one line per value would bury the rest.
607
+ * @param {unknown[]} lines - `token (mode): before -> after` lines.
608
+ * @param {string[]} [statusWords] - The status words whose colors the look derives (derivedStatusWords): theirs are counted too.
609
+ * @param {string[]} [exact] - Tokens the theme sets to a value of its own (exactTokens): each is named, never counted, as it did not move with the look.
610
+ */
611
+ export function lookCollapsed(lines, statusWords = [], exact = []) {
612
+ const tokenOf = (/** @type {unknown} */ c) => String(c).split(/[\s:]/)[0];
613
+ const status = new RegExp(
614
+ `^--color-(?:(?:on|text|icon|border)-)?(?:${statusWords.join('|') || '(?!)'})(?:-muted)?$`,
615
+ );
616
+ const folded = (/** @type {unknown} */ c) =>
617
+ status.test(tokenOf(c)) && !exact.includes(tokenOf(c));
618
+ const statusLines = lines.filter(folded);
619
+ const rest = lines.filter(c => !folded(c));
620
+ lines = rest;
621
+ // (A look token the theme sets to a value of its own is named, never
622
+ // counted: it did not move with the look.)
623
+ const counted = (/** @type {unknown} */ c) =>
624
+ isLookToken(tokenOf(c)) && !exact.includes(tokenOf(c));
625
+ const look = lines.filter(counted).map(String);
626
+ const code = look.filter(c => isCodeToken(tokenOf(c))).length;
627
+ const badges = look.filter(
628
+ c => !tokenOf(c).startsWith('--color-data-') && !isCodeToken(tokenOf(c)),
629
+ );
630
+ const chart = look.length - badges.length - code;
631
+ return {
632
+ lines: [
633
+ ...lines.filter(c => !counted(c)).map(String),
634
+ ...(badges.length
635
+ ? [
636
+ `category colors (badges, tokens and card tints): ${badges.length} values moved with the look`,
637
+ ]
638
+ : []),
639
+ ...(chart ? [`chart colors: ${chart} values moved with the look`] : []),
640
+ ...(code
641
+ ? [`code colors and the overlay: ${code} values moved with the look`]
642
+ : []),
643
+ ...(statusLines.length
644
+ ? [
645
+ `status colors (${statusWords.join(', ')}): ${statusLines.length} values moved with the look`,
646
+ ]
647
+ : []),
648
+ ],
649
+ look: [...look, ...statusLines.map(String)],
650
+ };
485
651
  }
486
652
 
487
653
  /** Notes for damaged color configs kept aside during one sync. @type {string[]} */
@@ -530,30 +696,40 @@ function keepDamaged(file) {
530
696
  }
531
697
 
532
698
  /**
533
- * The settings saved on disk, before the change being built: what the
534
- * editor wrote into the config last time, so a value it did not write is
535
- * known to be a hand edit.
699
+ * A theme's settings file as it is on disk, or null when it does not read.
536
700
  * @param {string} cwd
537
701
  * @param {string} slug
538
- * @returns {{settings: Setting[], mode: string | null}}
702
+ * @returns {any}
539
703
  */
540
- function savedSettings(cwd, slug) {
704
+ function savedTheme(cwd, slug) {
541
705
  try {
542
- const data = JSON.parse(
706
+ return JSON.parse(
543
707
  fs.readFileSync(
544
708
  path.join(cwd, 'themes', slug, `${slug}.settings.json`),
545
709
  'utf8',
546
710
  ),
547
711
  );
548
- return {
549
- settings: Array.isArray(data?.settings) ? data.settings : [],
550
- mode: typeof data?.mode === 'string' ? data.mode : null,
551
- };
552
712
  } catch {
553
- return {settings: [], mode: null};
713
+ return null;
554
714
  }
555
715
  }
556
716
 
717
+ /**
718
+ * The settings saved on disk, before the change being built: what the
719
+ * editor wrote into the config last time, so a value it did not write is
720
+ * known to be a hand edit.
721
+ * @param {string} cwd
722
+ * @param {string} slug
723
+ * @returns {{settings: Setting[], mode: string | null}}
724
+ */
725
+ function savedSettings(cwd, slug) {
726
+ const data = savedTheme(cwd, slug);
727
+ return {
728
+ settings: Array.isArray(data?.settings) ? data.settings : [],
729
+ mode: typeof data?.mode === 'string' ? data.mode : null,
730
+ };
731
+ }
732
+
557
733
  /** The generator's mode strategy for a list of modes. @param {Mode[]} modes */
558
734
  const strategyOf = modes =>
559
735
  modes.length > 1 ? 'light-and-dark' : `${modes[0]}-only`;
@@ -636,10 +812,10 @@ function usableStops(stops, slug) {
636
812
  * What the palette mapping reads of a theme: its base colors, the tokens it
637
813
  * has, its exact token settings (a page-wide token its own source sets wins,
638
814
  * as the build shows it), the fixed color a value gives in a mode, and the
639
- * command that sets a value.
815
+ * command that sets a value, and the modes the theme shows.
640
816
  * @param {string} cwd
641
817
  * @param {string} slug
642
- * @param {{settings: Setting[]}} data
818
+ * @param {{mode?: string, settings: Setting[]}} data
643
819
  * @param {{light: Record<string, string>, dark: Record<string, string>} | undefined} base
644
820
  * @param {Record<string, unknown>} [tokenDefaults]
645
821
  * @returns {import('../theme/palette/generate/mapping.mjs').PaletteMappingContext}
@@ -700,6 +876,11 @@ function paletteContext(cwd, slug, data, base, tokenDefaults = {}) {
700
876
  return {
701
877
  base,
702
878
  has: token => token in tokenDefaults,
879
+ // The editor's own rules (Core's context.editor), which only the
880
+ // editor loads.
881
+ editor: editorLook,
882
+ shown: modesOf(data),
883
+ defaults: tokenDefaults,
703
884
  reader: {
704
885
  rgb: value =>
705
886
  /** @type {[number, number, number] | null} */ (parseColor(value)),
@@ -729,7 +910,214 @@ function paletteContext(cwd, slug, data, base, tokenDefaults = {}) {
729
910
  * @property {any} config
730
911
  * @property {string[]} notes
731
912
  * @property {Record<string, {stop: number, dark: boolean, why: string, ratio: number}>} fills
913
+ * @property {boolean} [stored] the saved palette, kept as it is (a recipe this CLI does not know)
914
+ */
915
+
916
+ /**
917
+ * Whether a theme's palette names a recipe this CLI does not know (its
918
+ * colors are kept as saved, made by a newer CLI).
919
+ * @param {string} cwd
920
+ * @param {string} slug
921
+ */
922
+ export function paletteRecipeUnknown(cwd, slug) {
923
+ const config = readConfig(path.join(cwd, paletteFiles(slug).config));
924
+ return newerRecipe(config?.recipe) != null;
925
+ }
926
+
927
+ /**
928
+ * What a palette kept as saved is, in words: whose colors use which recipe,
929
+ * that this CLI does not make it, and what still works. No update step: a
930
+ * CLI that makes the recipe may not be released yet.
931
+ * @param {string} slug
932
+ * @param {unknown} recipe
933
+ */
934
+ const keptPaletteWords = (slug, recipe) =>
935
+ `${slug}'s colors use the ${String(recipe)} recipe, which this Astryx CLI (${cliVersion()}) does not make; its palette is kept as saved. Changes to what the palette is made from (the accent, neutral and status colors, the vibrancy) need a CLI that makes that recipe; other changes, including exact color tokens, a part's colors, the mode and the base, save as usual.`;
936
+
937
+ /**
938
+ * The refusal of a color change to a palette kept as saved (a recipe a
939
+ * newer CLI names): what it is, and nothing to run.
940
+ * @param {string} slug
941
+ * @param {unknown} recipe
942
+ */
943
+ function unknownRecipe(slug, recipe) {
944
+ return new AstryxError(
945
+ `${keptPaletteWords(slug, recipe)} Nothing was changed.`,
946
+ [],
947
+ ERROR_CODES.ERR_PALETTE_GENERATION,
948
+ );
949
+ }
950
+
951
+ /**
952
+ * Each theme's colors as saved (its {@link paletteMadeFromKey}), as the
953
+ * settings reader read the file: a change is compared with this.
954
+ * @type {Map<string, string | null>}
955
+ */
956
+ const SAVED_COLORS = new Map();
957
+
958
+ /**
959
+ * Each theme's settings as the settings reader read the file, before any
960
+ * change: what a hand edit is checked against.
961
+ * @type {Map<string, any>}
962
+ */
963
+ const LOADED_SETTINGS = new Map();
964
+
965
+ /**
966
+ * Note what a theme's colors come from as saved, read as the settings
967
+ * reader reads the file (its base word, its field and entry names).
968
+ * @param {string} cwd
969
+ * @param {string} slug
970
+ * @param {any} data the settings as read, before any change
971
+ */
972
+ export function noteSavedColors(cwd, slug, data) {
973
+ SAVED_COLORS.set(path.join(cwd, 'themes', slug), paletteMadeFromKey(data));
974
+ LOADED_SETTINGS.set(path.join(cwd, 'themes', slug), data);
975
+ }
976
+
977
+ /**
978
+ * A theme's settings as read before any change (the ones its settings
979
+ * module was built from), else as the file holds them now.
980
+ * @param {string} cwd
981
+ * @param {string} slug
982
+ * @returns {any}
983
+ */
984
+ export function settingsBeforeChange(cwd, slug) {
985
+ const dir = path.join(cwd, 'themes', slug);
986
+ return LOADED_SETTINGS.has(dir)
987
+ ? LOADED_SETTINGS.get(dir)
988
+ : savedTheme(cwd, slug);
989
+ }
990
+
991
+ /**
992
+ * What a palette is made from, as one key to compare: the color dials and
993
+ * vibrancy, and a whole-theme accent token, as {@link dialFamilies} reads
994
+ * them. A change to these makes the palette again; the mode, the base and
995
+ * any other color token only map it.
996
+ * @param {{settings?: Setting[]} | null} d
997
+ */
998
+ export function paletteMadeFromKey(d) {
999
+ // (Beside an accent dial, a whole-theme accent token is an exact value
1000
+ // the palette never reads, as dialFamilies reads it.)
1001
+ const accentDial = (d?.settings ?? []).some(
1002
+ x => x?.source === 'dial' && x.thing === 'accent' && !x.on && !x.mode,
1003
+ );
1004
+ return d
1005
+ ? JSON.stringify(
1006
+ (d.settings ?? [])
1007
+ .filter(
1008
+ x =>
1009
+ (x?.source === 'dial' &&
1010
+ !x.on &&
1011
+ (PALETTE_DIALS.includes(x.thing) || x.thing === 'vibrancy')) ||
1012
+ (!accentDial &&
1013
+ x?.source === 'token' &&
1014
+ x.thing === '--color-accent' &&
1015
+ !x.on &&
1016
+ !x.when &&
1017
+ !x.state),
1018
+ )
1019
+ .map(x =>
1020
+ [x.source, x.thing, x.value, x.mode]
1021
+ .map(v => String(v ?? '').toLowerCase())
1022
+ .join('|'),
1023
+ ),
1024
+ )
1025
+ : null;
1026
+ }
1027
+
1028
+ /**
1029
+ * What a theme's colors come from, as one key to compare: its mode, its
1030
+ * base, its color dials (and vibrancy) and its color tokens. A change that
1031
+ * leaves this as it was leaves the palette's colors alone.
1032
+ * @param {{mode?: string | null, like?: string | null, settings?: Setting[]} | null} d
1033
+ */
1034
+ export function paletteColorKey(d) {
1035
+ return d
1036
+ ? JSON.stringify({
1037
+ mode: d.mode ?? 'both',
1038
+ like: d.like ?? null,
1039
+ // (Each by what it says.)
1040
+ colors: (d.settings ?? [])
1041
+ .filter(
1042
+ x =>
1043
+ (x?.source === 'dial' &&
1044
+ (PALETTE_DIALS.includes(x.thing) || x.thing === 'vibrancy')) ||
1045
+ (x?.source === 'token' && isColorToken(x.thing)),
1046
+ )
1047
+ .map(x =>
1048
+ [x.source, x.thing, x.value, x.on, x.when, x.state, x.mode]
1049
+ .map(v => String(v ?? '').toLowerCase())
1050
+ .join('|'),
1051
+ ),
1052
+ })
1053
+ : null;
1054
+ }
1055
+
1056
+ /**
1057
+ * The palette as its files hold it, read as the generator's candidate
1058
+ * (its stops, families and ends), for a palette this CLI cannot make
1059
+ * again; null when the palette file is missing or does not read.
1060
+ * @param {string} cwd
1061
+ * @param {string} slug
1062
+ * @param {any} config
1063
+ */
1064
+ function storedCandidate(cwd, slug, config) {
1065
+ const f = paletteFiles(slug);
1066
+ let data;
1067
+ try {
1068
+ data = paletteData(fs.readFileSync(path.join(cwd, f.palette), 'utf8'));
1069
+ } catch {
1070
+ return null;
1071
+ }
1072
+ if (!data) return null;
1073
+ const first = /** @type {any} */ (Object.values(data.palette)[0]);
1074
+ const stops = (
1075
+ Array.isArray(config?.stops)
1076
+ ? config.stops
1077
+ : Object.keys(first?.light ?? first?.dark ?? {})
1078
+ )
1079
+ .map(Number)
1080
+ .sort((/** @type {number} */ a, /** @type {number} */ b) => a - b);
1081
+ return {
1082
+ schemaVersion: 1,
1083
+ status: 'candidate',
1084
+ recipe: config?.recipe,
1085
+ black: data.black ?? PALETTE_BLACK,
1086
+ white: data.white ?? PALETTE_WHITE,
1087
+ stops,
1088
+ palette: data.palette,
1089
+ };
1090
+ }
1091
+
1092
+ /**
1093
+ * Whether a theme's palette is kept exactly as saved, as one made with a
1094
+ * recipe this CLI does not know is ({@link planPalette}): its build keeps
1095
+ * what that palette made.
1096
+ * @param {string} cwd
1097
+ * @param {string} slug
1098
+ * @param {{mode?: string, settings: Setting[]}} data
1099
+ * @param {{light: Record<string, string>, dark: Record<string, string>}} [base]
1100
+ */
1101
+ export function paletteKeptAsSaved(cwd, slug, data, base) {
1102
+ try {
1103
+ return Boolean(planPalette(cwd, slug, data, base)?.stored);
1104
+ } catch {
1105
+ return false;
1106
+ }
1107
+ }
1108
+
1109
+ /**
1110
+ * The candidate a plan's palette is: the saved one for a palette this CLI
1111
+ * cannot make again, else the generator's.
1112
+ * @param {string} cwd
1113
+ * @param {string} slug
1114
+ * @param {PalettePlan} plan
732
1115
  */
1116
+ function candidateOf(cwd, slug, plan) {
1117
+ return plan.stored
1118
+ ? /** @type {Candidate} */ (storedCandidate(cwd, slug, plan.config))
1119
+ : generate(plan.config, paletteFiles(slug).config, cwd);
1120
+ }
733
1121
 
734
1122
  /**
735
1123
  * The palette config a theme's settings ask for. The existing config is
@@ -741,22 +1129,182 @@ function paletteContext(cwd, slug, data, base, tokenDefaults = {}) {
741
1129
  * the author's own stay. Null when the config would hold no family.
742
1130
  * @param {string} cwd
743
1131
  * @param {string} slug
744
- * @param {{mode?: string, settings: Setting[], palette?: string}} data
1132
+ * @param {{mode?: string, like?: string, settings: Setting[], palette?: string}} data
745
1133
  * @param {{light: Record<string, string>, dark: Record<string, string>}} [base] the base theme's resolved colors, which the dark check reads
746
1134
  * @returns {PalettePlan | null}
747
1135
  */
748
1136
  function planPalette(cwd, slug, data, base) {
749
1137
  const file = paletteFiles(slug).config;
750
1138
  const existing = readConfig(path.join(cwd, file));
751
- // (Before anything reads it, so the refusal names this project's way to
752
- // a newer CLI.)
753
- refuseUnknownRecipe(existing, file, cwd);
754
1139
  const fams = dialFamilies(data, ownSourceTokenValues(cwd, slug));
755
1140
  if (!existing && !fams.length) return null;
756
1141
  /** @type {string[]} */
757
1142
  const notes = [];
758
1143
  const own =
759
1144
  existing && typeof existing === 'object' && !Array.isArray(existing);
1145
+ // A palette made with a recipe this CLI does not know (a newer CLI's):
1146
+ // its saved colors stay exactly as stored, so opening the theme never
1147
+ // recolors it; only a change to its colors needs a CLI that knows it.
1148
+ if (own && newerRecipe(existing.recipe)) {
1149
+ const stored = storedCandidate(cwd, slug, existing);
1150
+ const dir = path.join(cwd, 'themes', slug);
1151
+ const savedKey = SAVED_COLORS.has(dir)
1152
+ ? SAVED_COLORS.get(dir)
1153
+ : paletteMadeFromKey(savedTheme(cwd, slug));
1154
+ /** The seed the saved palette made a family from. @param {string} id */
1155
+ const seedOfSaved = id =>
1156
+ /** @type {any[]} */ (
1157
+ Array.isArray(existing.families) ? existing.families : []
1158
+ ).find(x => x?.id === id)?.seed;
1159
+ // (A color changed in the settings file by hand is a change too: each
1160
+ // color the settings name is checked against the seed the saved
1161
+ // palette was made from, where it names that family. A color the
1162
+ // saved palette has no shades for is a change too.)
1163
+ /** @param {DialFamily[]} list */
1164
+ const differing = list =>
1165
+ list.find(f => {
1166
+ if (!(/** @type {any} */ (stored?.palette)?.[f.id])) return true;
1167
+ const was = seedOfSaved(f.id);
1168
+ return Boolean(was) && !sameColor(String(was), f.seed);
1169
+ }) ?? null;
1170
+ const madeFrom = !differing(fams);
1171
+ // Settings that already disagree with the saved palette as read (a
1172
+ // color changed or added in the file by hand).
1173
+ const loaded = LOADED_SETTINGS.has(dir)
1174
+ ? LOADED_SETTINGS.get(dir)
1175
+ : savedTheme(cwd, slug);
1176
+ const hand =
1177
+ stored && Array.isArray(loaded?.settings)
1178
+ ? differing(dialFamilies(loaded, ownSourceTokenValues(cwd, slug)))
1179
+ : null;
1180
+ // (From such a file, any change that brings every color back to the
1181
+ // seeds the saved palette was made from is the way back, an undo or a
1182
+ // `set` of the saved seed alike, as long as the vibrancy is the saved
1183
+ // one.)
1184
+ const back =
1185
+ hand != null &&
1186
+ // (Every color the file names still named, so none falls back to the
1187
+ // base theme's.)
1188
+ // (A color the saved palette has no shades for may go.)
1189
+ dialFamilies(loaded, ownSourceTokenValues(cwd, slug)).every(
1190
+ l =>
1191
+ !(/** @type {any} */ (stored?.palette)?.[l.id]) ||
1192
+ fams.some(f => f.id === l.id),
1193
+ ) &&
1194
+ (dialVibrancy(data.settings) ?? VIBRANCY_DEFAULT) ===
1195
+ (existing.vibrancy ?? VIBRANCY_DEFAULT);
1196
+ if (stored && madeFrom && (paletteMadeFromKey(data) === savedKey || back))
1197
+ return {
1198
+ config: existing,
1199
+ // Each accent or status color at the stop its saved palette holds
1200
+ // it, light (its exact anchor, else the nearest shade), and dark
1201
+ // when an exact dark anchor holds it there too.
1202
+ fills: Object.fromEntries(
1203
+ fams
1204
+ .filter(f => f.id !== 'neutral')
1205
+ .map(f => {
1206
+ const anchors = /** @type {any[]} */ (
1207
+ existing.families?.find(
1208
+ (/** @type {any} */ x) => x?.id === f.id,
1209
+ )?.anchors ?? []
1210
+ );
1211
+ const exact = (/** @type {Mode} */ m) =>
1212
+ anchors.find(
1213
+ a =>
1214
+ a?.mode === m &&
1215
+ a.policy === 'exact' &&
1216
+ sameColor(a.color, f.seed),
1217
+ );
1218
+ const ramp = /** @type {any} */ (stored.palette)[f.id]?.light;
1219
+ const stop =
1220
+ exact('light')?.stop ??
1221
+ (ramp ? nearestShade(ramp, f.seed) : null) ??
1222
+ 50;
1223
+ return [
1224
+ f.id,
1225
+ {
1226
+ stop: Number(stop),
1227
+ dark: Boolean(exact('dark')),
1228
+ why: '',
1229
+ ratio: 0,
1230
+ },
1231
+ ];
1232
+ }),
1233
+ ),
1234
+ notes: [`${file}: ${keptPaletteWords(slug, existing.recipe)}`],
1235
+ stored: true,
1236
+ };
1237
+ // (A palette file gone or unreadable leaves nothing to keep: every
1238
+ // command needs it back, or a CLI that can make the colors again.)
1239
+ if (!stored)
1240
+ throw new AstryxError(
1241
+ `${file}: ${slug}'s colors use the ${String(existing.recipe)} recipe, which this Astryx CLI (${cliVersion()}) does not make, and its palette file (${paletteFiles(slug).palette}) is missing or does not read, so the theme cannot be built until that file is back. Nothing was changed.`,
1242
+ [],
1243
+ ERROR_CODES.ERR_PALETTE_GENERATION,
1244
+ );
1245
+ // Settings that already disagree with the saved palette as read refuse
1246
+ // every other command, so the refusal names that setting and the way
1247
+ // back.
1248
+ if (hand) {
1249
+ const name =
1250
+ hand.source ??
1251
+ (loaded.settings.some(
1252
+ (/** @type {any} */ x) =>
1253
+ x?.source === 'dial' && x.thing === hand.dial,
1254
+ )
1255
+ ? hand.dial
1256
+ : '--color-accent');
1257
+ const seed = /** @type {any} */ (stored?.palette)?.[hand.id]
1258
+ ? String(seedOfSaved(hand.id))
1259
+ : null;
1260
+ const was = seed
1261
+ ? `the saved palette was made from ${seed}`
1262
+ : `the saved palette has no shades for ${hand.dial}`;
1263
+ // (The way back named is the one that opens the theme: `set` of the
1264
+ // saved seed when that setting is the only difference, else each
1265
+ // difference to put back by hand.)
1266
+ const own = ownSourceTokenValues(cwd, slug);
1267
+ const diffs = dialFamilies(loaded, own).filter(f => differing([f]));
1268
+ const vibrancyOff =
1269
+ (dialVibrancy(loaded.settings) ?? VIBRANCY_DEFAULT) !==
1270
+ (existing.vibrancy ?? VIBRANCY_DEFAULT);
1271
+ const nameOf = (/** @type {DialFamily} */ f) =>
1272
+ f.source ??
1273
+ (loaded.settings.some(
1274
+ (/** @type {any} */ x) => x?.source === 'dial' && x.thing === f.dial,
1275
+ )
1276
+ ? f.dial
1277
+ : '--color-accent');
1278
+ // (A color the theme's own source sets wins over the settings: it is
1279
+ // put back in that file, never with set.)
1280
+ const sourceFile = `themes/${slug}/${slug}.theme.ts`;
1281
+ const backOf = (/** @type {DialFamily} */ f) =>
1282
+ /** @type {any} */ (stored?.palette)?.[f.id]
1283
+ ? `${nameOf(f)} back to ${String(seedOfSaved(f.id))}${f.source ? ` in ${sourceFile}` : ''}`
1284
+ : `${nameOf(f)} out${f.source ? ` of ${sourceFile}` : ''}`;
1285
+ const way =
1286
+ diffs.length === 1 && !vibrancyOff
1287
+ ? hand.source
1288
+ ? `Change it back in ${sourceFile} to open the theme.`
1289
+ : seed
1290
+ ? `Put it back by hand, or with set ${slug} ${name} ${seed}, to open the theme.`
1291
+ : `Take it out of the file by hand to open the theme.`
1292
+ : `Put every one back by hand to open the theme: ${[
1293
+ ...diffs.map(backOf),
1294
+ ...(vibrancyOff
1295
+ ? [
1296
+ `vibrancy back to ${String(existing.vibrancy ?? VIBRANCY_DEFAULT)}`,
1297
+ ]
1298
+ : []),
1299
+ ].join(', ')}.`;
1300
+ throw new AstryxError(
1301
+ `${slug}'s colors use the ${String(existing.recipe)} recipe, which this Astryx CLI (${cliVersion()}) does not make; its palette is kept as saved. ${hand.source ? sourceFile : `themes/${slug}/${slug}.settings.json`} sets ${name} to ${hand.source ? hand.seed : hand.value}, but ${was}. ${way} Nothing was changed.`,
1302
+ [],
1303
+ ERROR_CODES.ERR_PALETTE_GENERATION,
1304
+ );
1305
+ }
1306
+ throw unknownRecipe(slug, existing.recipe);
1307
+ }
760
1308
  // A new palette is made with the newest recipe; a palette the theme
761
1309
  // already has keeps the one it was made with (none named is the first),
762
1310
  // so its colors never move with a CLI upgrade. Moving it is a choice
@@ -923,6 +1471,12 @@ function planPalette(cwd, slug, data, base) {
923
1471
  if (f.id !== 'neutral') fills[f.id] = fillAt(stop);
924
1472
  families.push(family);
925
1473
  }
1474
+ // The hues the editor grew for the look (lookSeeds) go, and are grown
1475
+ // again below while the theme has a color; any other hue the config
1476
+ // holds is the author's, and stays as written.
1477
+ const grown = isLookFamily;
1478
+ for (let i = families.length - 1; i >= 0; i--)
1479
+ if (grown(families[i])) families.splice(i, 1);
926
1480
  if (!families.length) return null;
927
1481
  // The editor's colors stand in the order of their settings, wherever they
928
1482
  // sit among a config's own families, so a step back writes the same file.
@@ -935,6 +1489,16 @@ function planPalette(cwd, slug, data, base) {
935
1489
  if (inOrder.length === slots.length)
936
1490
  slots.forEach((i, k) => (families[i] = inOrder[k]));
937
1491
  config.families = families;
1492
+ // The category and chart hues grow with the look, after the theme's own
1493
+ // colors, and so do the status roles the theme leaves unset (the
1494
+ // editor's own grownFamilies); a family the author's config already holds stays
1495
+ // theirs. A status family that is not a setting is the editor's, grown
1496
+ // again at every plan.
1497
+ for (const family of editorLook.grownFamilies(fams, {
1498
+ base,
1499
+ reader: {rgb: parseColor, alpha: alphaOf},
1500
+ }))
1501
+ if (!families.some(f => f?.id === family.id)) families.push(family);
938
1502
  // A color change on a palette made with the first recipe says what the
939
1503
  // newer one does, and how to choose it.
940
1504
  /** @param {any} c */
@@ -1105,6 +1669,12 @@ function syncPaletteFiles(cwd, slug, data, base) {
1105
1669
  fs.rmdirSync(tokensDir);
1106
1670
  return notes;
1107
1671
  }
1672
+ // A palette this CLI cannot make again keeps its files as they are.
1673
+ // (Its note rides on the mapping, paletteMapping, once.)
1674
+ if (plan.stored) {
1675
+ data.palette = sha256(fs.readFileSync(abs(f.config)));
1676
+ return [];
1677
+ }
1108
1678
  const text = `${JSON.stringify(plan.config, null, 2)}\n`;
1109
1679
  /** @type {any} */
1110
1680
  let receipt;
@@ -1601,9 +2171,9 @@ export function familyRamp(cwd, slug, data, base, family) {
1601
2171
  const plan = /** @type {PalettePlan} */ (
1602
2172
  planPalette(cwd, slug, data, base)
1603
2173
  );
1604
- const ramp = /** @type {any} */ (
1605
- generate(plan.config, paletteFiles(slug).config, cwd).palette
1606
- )[family];
2174
+ const ramp = /** @type {any} */ (candidateOf(cwd, slug, plan).palette)[
2175
+ family
2176
+ ];
1607
2177
  if (ramp?.light && ramp?.dark) return ramp;
1608
2178
  }
1609
2179
  if (family !== 'neutral') return null;
@@ -1635,27 +2205,163 @@ export function familyRamp(cwd, slug, data, base, family) {
1635
2205
  * in memory, so it matches the palette file `syncPalette` writes.
1636
2206
  * @param {string} cwd
1637
2207
  * @param {string} slug
1638
- * @param {import('./_settings.mjs').ThemeData} data
2208
+ * @param {{mode?: string, settings: Setting[]}} data - The theme's settings (a whole ThemeData, or the settings with one left out).
1639
2209
  * @param {{light: Record<string, string>, dark: Record<string, string>}} base
1640
2210
  * @param {Record<string, unknown>} tokenDefaults
1641
2211
  * @returns {PaletteMapping | null}
1642
2212
  */
1643
2213
  export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
2214
+ if (!dialFamilies(data).length) return null;
2215
+ // One change asks for the mapping several times (to build, to check, to
2216
+ // say what changed), each with the same inputs: what it reads (the
2217
+ // settings, the base, the color config, saved settings and generated
2218
+ // palette on disk, the theme's own token values) names it, and an answer is made once. A
2219
+ // config that does not parse is read again each time, so it is named.
2220
+ const config = readText(path.join(cwd, paletteFiles(slug).config));
2221
+ if (config != null && !parsesAsJson(config))
2222
+ return paletteMappingOf(cwd, slug, data, base, tokenDefaults);
2223
+ const key = sha256(
2224
+ JSON.stringify([
2225
+ cwd,
2226
+ slug,
2227
+ data,
2228
+ base,
2229
+ tokenDefaults,
2230
+ config,
2231
+ readText(path.join(cwd, 'themes', slug, `${slug}.settings.json`)),
2232
+ ownSourceTokenValues(cwd, slug),
2233
+ // (The generated palette and its receipt: a hand edit there is the
2234
+ // mapping's "was edited by hand" note.)
2235
+ readText(path.join(cwd, paletteFiles(slug).palette)),
2236
+ readText(path.join(cwd, paletteFiles(slug).receipt)),
2237
+ ]),
2238
+ );
2239
+ const kept = MAPPINGS.get(key);
2240
+ if (kept) {
2241
+ MAPPINGS.delete(key);
2242
+ MAPPINGS.set(key, kept);
2243
+ return structuredClone(kept);
2244
+ }
2245
+ const made = paletteMappingOf(cwd, slug, data, base, tokenDefaults);
2246
+ if (made) {
2247
+ MAPPINGS.set(key, structuredClone(made));
2248
+ if (MAPPINGS.size > MAPPINGS_KEPT)
2249
+ MAPPINGS.delete(/** @type {string} */ (MAPPINGS.keys().next().value));
2250
+ }
2251
+ return made;
2252
+ }
2253
+
2254
+ /** The mappings made last, by what they were made from (paletteMapping). @type {Map<string, PaletteMapping>} */
2255
+ const MAPPINGS = new Map();
2256
+ /** How many mappings are kept. */
2257
+ const MAPPINGS_KEPT = 8;
2258
+
2259
+ /** A file's text, or null when it cannot be read. @param {string} file */
2260
+ function readText(file) {
2261
+ try {
2262
+ return fs.readFileSync(file, 'utf8');
2263
+ } catch {
2264
+ return null;
2265
+ }
2266
+ }
2267
+
2268
+ /** @param {string} text */
2269
+ function parsesAsJson(text) {
2270
+ try {
2271
+ JSON.parse(text.replace(/^\uFEFF/, ''));
2272
+ return true;
2273
+ } catch {
2274
+ return false;
2275
+ }
2276
+ }
2277
+
2278
+ /**
2279
+ * The mapping, made: see {@link paletteMapping}.
2280
+ * @param {string} cwd
2281
+ * @param {string} slug
2282
+ * @param {{mode?: string, settings: Setting[]}} data
2283
+ * @param {{light: Record<string, string>, dark: Record<string, string>}} base
2284
+ * @param {Record<string, unknown>} tokenDefaults
2285
+ * @returns {PaletteMapping | null}
2286
+ */
2287
+ function paletteMappingOf(cwd, slug, data, base, tokenDefaults) {
1644
2288
  const fams = dialFamilies(data, ownSourceTokenValues(cwd, slug));
1645
2289
  if (!fams.length) return null;
1646
2290
  const plan = /** @type {PalettePlan} */ (planPalette(cwd, slug, data, base));
1647
2291
  const {config} = plan;
1648
- const candidate = generate(config, paletteFiles(slug).config, cwd);
2292
+ const candidate = candidateOf(cwd, slug, plan);
1649
2293
  const mapping = mapPalette(
1650
2294
  candidate,
1651
2295
  fams,
1652
2296
  plan.fills,
1653
2297
  paletteContext(cwd, slug, data, base, tokenDefaults),
1654
2298
  );
2299
+ const {tokens} = mapping;
2300
+ // An accent set as a token for one mode moves that mode only: the other
2301
+ // mode keeps what the theme's palette gives it without that accent (its
2302
+ // other colors, a warm gray, still drawn), else follows the base theme.
2303
+ // (A palette kept as saved has no palette without that accent to make:
2304
+ // its saved shades stand for both modes.)
2305
+ const only = plan.stored ? null : fams.find(f => f.id === 'accent')?.only;
2306
+ if (only) {
2307
+ const other = only === 'light' ? 'dark' : 'light';
2308
+ // The palette's checks for that mode are those of the palette without
2309
+ // the accent, which this change does not move.
2310
+ mapping.contrast = mapping.contrast.filter(c => c.mode !== other);
2311
+ const rest = paletteMapping(
2312
+ cwd,
2313
+ slug,
2314
+ {
2315
+ ...data,
2316
+ settings: data.settings.filter(
2317
+ x =>
2318
+ !(
2319
+ x.source === 'token' &&
2320
+ x.thing === '--color-accent' &&
2321
+ !x.on &&
2322
+ !x.when &&
2323
+ !x.state &&
2324
+ x.mode === only
2325
+ ),
2326
+ ),
2327
+ },
2328
+ base,
2329
+ tokenDefaults,
2330
+ );
2331
+ for (const [k, v] of Object.entries(tokens)) {
2332
+ const before = rest?.tokens?.[k]?.[other];
2333
+ if (before) {
2334
+ // (The same shade where the palette's color there is the same; its
2335
+ // color written out where it differs, as the accent moves the
2336
+ // shades it coordinates.)
2337
+ tokens[k] = {
2338
+ ...v,
2339
+ [other]:
2340
+ String(v[other]?.color).toLowerCase() ===
2341
+ String(before.color).toLowerCase()
2342
+ ? v[other]
2343
+ : {stop: 0, color: String(before.color), family: 'literal'},
2344
+ };
2345
+ continue;
2346
+ }
2347
+ const kept = base?.[other]?.[k];
2348
+ if (kept == null) {
2349
+ delete tokens[k];
2350
+ continue;
2351
+ }
2352
+ // (The base theme's own value: the module reads it from the base,
2353
+ // so the mode keeps following it.)
2354
+ tokens[k] = {
2355
+ ...v,
2356
+ [other]: {stop: 0, color: String(kept), family: 'literal', base: true},
2357
+ };
2358
+ }
2359
+ }
1655
2360
  return {
1656
2361
  candidate,
1657
2362
  families: fams,
1658
2363
  ...mapping,
2364
+ stored: Boolean(plan.stored),
1659
2365
  vibrancy: config.vibrancy ?? VIBRANCY_DEFAULT,
1660
2366
  notes: [
1661
2367
  ...plan.notes,
@@ -1836,6 +2542,167 @@ export function paletteFailedKeys(pal) {
1836
2542
  );
1837
2543
  }
1838
2544
 
2545
+ /**
2546
+ * A text/fill pair the base theme draws, as a person reads it: "the blue
2547
+ * card's primary text", "text on the error tint".
2548
+ * @param {import('../theme/palette/generate/mapping.mjs').BasePair} pair
2549
+ */
2550
+ function pairWords(pair) {
2551
+ if (pair.kind === 'category') return `${pair.hue} category text`;
2552
+ if (pair.kind === 'status')
2553
+ return pair.tint ? `text on the ${pair.role} tint` : `text on ${pair.role}`;
2554
+ const which =
2555
+ /^(?:variant|color):(.+)$/.exec(pair.block)?.[1] ??
2556
+ pair.block.replace(':', ' ');
2557
+ const role =
2558
+ pair.prop === 'color'
2559
+ ? 'text'
2560
+ : `${pair.prop.replace(/^--color-text-/, '')} text`;
2561
+ return `the ${which === 'base' ? '' : `${which} `}${pair.part.replace(/-/g, ' ')}'s ${role}`;
2562
+ }
2563
+
2564
+ /**
2565
+ * What the look did to the category colors (Badge, Token, Card tints), the
2566
+ * chart colors and the status roles: one line with the accent's notes, and
2567
+ * what a set gave up to stay written with every dial's.
2568
+ * @param {PaletteMapping} pal
2569
+ * @param {string} dial
2570
+ * @param {string} [slug]
2571
+ * @param {boolean} [vibrancyRuns] whether `set <theme> vibrancy` changes
2572
+ * anything (vibrancyTakes): only then is a higher vibrancy advised
2573
+ */
2574
+ export function categoryNotes(
2575
+ pal,
2576
+ dial,
2577
+ slug = '<theme>',
2578
+ vibrancyRuns = false,
2579
+ ) {
2580
+ const c = pal.categories;
2581
+ if (!c) return [];
2582
+ /** @type {string[]} */
2583
+ const out = [];
2584
+ const derived = [
2585
+ c.badges === 'derived'
2586
+ ? 'category colors (badges, tokens and card tints)'
2587
+ : '',
2588
+ c.chart === 'derived' ? 'chart colors' : '',
2589
+ Object.keys(pal.tokens).some(k => k.startsWith('--color-syntax-'))
2590
+ ? 'code colors'
2591
+ : '',
2592
+ ].filter(Boolean);
2593
+ if (dial === 'accent' && derived.length)
2594
+ out.push(
2595
+ `${derived.join(', ').replace(/, ([^,]*)$/, ' and $1')} grow from Core's hues at your accent's strength and the palette's vibrancy, so they match the look; card tints stay tints that the page's text reads on where a shade allows, code reads at 4.5:1 on its background, and an exact --color-<role>-<hue>, --color-data-* or --color-syntax-* setting wins`,
2596
+ );
2597
+ // (Every limit no shade meets is said; the colors moved apart are
2598
+ // counted after the first.)
2599
+ if (c.limits.length || c.moved.length) {
2600
+ // (Hues drawn alike come from a low vibrancy: a higher one is advised,
2601
+ // with its command, only where set takes it.)
2602
+ // (A theme at 100 already has no higher vibrancy.)
2603
+ const apart =
2604
+ c.alike && vibrancyRuns && pal.vibrancy < 100
2605
+ ? `; a higher vibrancy draws the hues apart: ${P} set ${slug} vibrancy more`
2606
+ : '';
2607
+ const moves = c.moved.length
2608
+ ? `${c.moved[0]}${c.moved.length > 1 ? `, and ${c.moved.length - 1} more moved apart` : ''}`
2609
+ : '';
2610
+ out.push(
2611
+ `category and chart colors follow your look: ${[...c.limits, ...(moves ? [moves] : [])].join('; ')}${apart}${c.unread ? '; an exact setting of a color that does not read chooses it' : ''}`,
2612
+ );
2613
+ }
2614
+ // Status fills someone red-weak or green-weak may not tell apart: one
2615
+ // note per pair, with a line that sets one of them apart in lightness.
2616
+ /** @type {Set<string>} */
2617
+ const saidPairs = new Set();
2618
+ for (const c of pal.cvd ?? []) {
2619
+ const id = `${c.a}|${c.b}`;
2620
+ if (saidPairs.has(id)) continue;
2621
+ saidPairs.add(id);
2622
+ const visions = [
2623
+ ...new Set(
2624
+ (pal.cvd ?? [])
2625
+ .filter(x => x.a === c.a && x.b === c.b)
2626
+ .map(x => `${x.vision} (${x.mode})`),
2627
+ ),
2628
+ ];
2629
+ // The one to move and its way: the second of the pair first, away
2630
+ // from the first in lightness, then the other way, then the first of
2631
+ // the pair; the first move that keeps the moved fill standing out from
2632
+ // the page (3:1, in every mode the theme shows) is the line. None
2633
+ // that does: the note names no line.
2634
+ const pages = [
2635
+ ...new Set(
2636
+ (pal.cvd ?? [])
2637
+ .filter(z => z.a === c.a && z.b === c.b)
2638
+ .flatMap(z => z.pages ?? (z.page ? [z.page] : [])),
2639
+ ),
2640
+ ];
2641
+ const tries = /** @type {Array<[number, number]>} */ ([
2642
+ [1, 1],
2643
+ [1, -1],
2644
+ [0, 1],
2645
+ [0, -1],
2646
+ ]);
2647
+ const [p0, p1] = c.colors.map(v => hexToOklch(v));
2648
+ // (The smallest move, in steps of lightness, that sets the pair apart
2649
+ // for color-blind readers and still stands out from every page.)
2650
+ const steps = [0.06, 0.09, 0.12, 0.15, 0.18, 0.21, 0.24, 0.27, 0.3];
2651
+ const move = steps
2652
+ .flatMap(d =>
2653
+ tries.map(([who, way]) => {
2654
+ const [me, other] = who === 1 ? [p1, p0] : [p0, p1];
2655
+ const sign = (me.L >= other.L ? 1 : -1) * way;
2656
+ const L = me.L + sign * d;
2657
+ if (L < 0.15 || L > 0.95) return null;
2658
+ const to = oklchClampedHex(L, me.C, me.H);
2659
+ if (!pages.every(pg => contrastRatio(to, pg) >= NON_TEXT))
2660
+ return null;
2661
+ const role = who === 1 ? c.b : c.a;
2662
+ const pair = {
2663
+ [c.a]: role === c.a ? to : c.colors[0],
2664
+ [c.b]: role === c.b ? to : c.colors[1],
2665
+ };
2666
+ if (cvdClashes(pair).some(x => x.a === c.a && x.b === c.b))
2667
+ return null;
2668
+ return {role, to, lighter: sign > 0};
2669
+ }),
2670
+ )
2671
+ .find(Boolean);
2672
+ const dial = move ? (move.role === 'error' ? 'danger' : move.role) : '';
2673
+ out.push(
2674
+ `for color-blind readers, the ${c.a} and ${c.b} fills may look alike (${visions.join(', ')}: ${c.colors.join(' and ')}); ${move ? `a ${move.lighter ? 'lighter' : 'darker'} ${dial} keeps the colors apart: ${P} set ${slug} ${dial} ${quoteCommandArgument(move.to)}` : 'no lighter or darker shade of either keeps both standing out from the page; pick a status color of another hue'}`,
2675
+ );
2676
+ }
2677
+ if (pal.code?.length)
2678
+ out.push(
2679
+ `${pal.code.join(', ')} ${pal.code.length > 1 ? 'keep' : 'keeps'} the base theme's: no shade of ${pal.code.length > 1 ? 'their' : 'its'} color reads at 4.5:1 on the code background and the page`,
2680
+ );
2681
+ const held = pal.kept ?? [];
2682
+ if (held.length) {
2683
+ const tokensHeld = [...new Set(held.map(h => h.token))];
2684
+ const pairs = [
2685
+ ...new Set(held.map(h => `${pairWords(h.pair)} (${h.mode})`)),
2686
+ ];
2687
+ out.push(
2688
+ `${tokensHeld.length} of the colors the look grows keep the base theme's where the base theme draws its own text with them, so it stays readable: ${pairs.slice(0, 3).join(', ')}${pairs.length > 3 ? `, and ${pairs.length - 3} more` : ''}`,
2689
+ );
2690
+ }
2691
+ const st = pal.statuses;
2692
+ const grown = ['info', 'success', 'warning', 'danger'].filter(
2693
+ role => st?.roles[role] === 'derived',
2694
+ );
2695
+ if (dial === 'accent' && grown.length)
2696
+ out.push(
2697
+ `${grown.join(', ')} ${grown.length > 1 ? 'grow' : 'grows'} from the base theme's ${grown.length > 1 ? 'hues' : 'hue'} at your accent's strength and the palette's vibrancy, kept apart from your accent where a shade allows (badges, banners, status dots, field status); an exact setting of ${grown.length > 1 ? 'one' : 'it'} chooses it`,
2698
+ );
2699
+ if (st?.why.length)
2700
+ out.push(
2701
+ `status colors follow your look: ${st.why.join('; ')}; to choose one: ${st.short.map(role => `${P} set ${slug} ${role} <color>`).join(', ')}`,
2702
+ );
2703
+ return out;
2704
+ }
2705
+
1839
2706
  /**
1840
2707
  * What one color dial did, for the result notes: what its main token uses
1841
2708
  * in each mode, every token contrast moved, and last the generated files.
@@ -1845,9 +2712,17 @@ export function paletteFailedKeys(pal) {
1845
2712
  * @param {string} dial
1846
2713
  * @param {string} slug
1847
2714
  * @param {Mode[]} [modes] the modes the theme has
2715
+ * @param {boolean} [vibrancyRuns] whether `set <theme> vibrancy` changes
2716
+ * anything (vibrancyTakes)
1848
2717
  * @returns {string[]}
1849
2718
  */
1850
- export function paletteNotes(pal, dial, slug, modes = ['light', 'dark']) {
2719
+ export function paletteNotes(
2720
+ pal,
2721
+ dial,
2722
+ slug,
2723
+ modes = ['light', 'dark'],
2724
+ vibrancyRuns = false,
2725
+ ) {
1851
2726
  if (!pal) return [];
1852
2727
  const f = paletteFiles(slug);
1853
2728
  const token = paletteToken(dial);
@@ -1893,6 +2768,7 @@ export function paletteNotes(pal, dial, slug, modes = ['light', 'dark']) {
1893
2768
  `${c.token} uses shade ${shade(c.stop)} in ${c.mode}, not ${shade(c.preferred)}, so it reads at ${c.ratio}:1 on ${c.against}`,
1894
2769
  );
1895
2770
  }
2771
+ notes.push(...categoryNotes(pal, dial, slug, vibrancyRuns));
1896
2772
  notes.push(
1897
2773
  `the generated colors are in ${f.palette}, made from ${f.config} (receipt: ${f.receipt}); the theme imports only the shades it uses, from ${f.refs}`,
1898
2774
  );