@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
@@ -0,0 +1,800 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file What one part of a theme shows: each CSS property the part reads,
5
+ * at rest and in each variant, with its final value in each mode, the
6
+ * declaration that gives it, the tokens it reads, and who decides it (Core,
7
+ * the theme it extends, or the theme's own file). The theme is any theme
8
+ * the project builds: an editor theme, a local theme or an installed theme
9
+ * package. It is loaded the way `theme build` loads it, and its tokens are
10
+ * resolved by Core. Nothing is written.
11
+ *
12
+ * @input the project folder, a theme name, a part name
13
+ * @output `themePartValues`: the `themeEdit.showPart` answer
14
+ * @position api/theme-edit — `show <theme> --on <part>` (_edit.mjs)
15
+ */
16
+
17
+ import * as path from 'node:path';
18
+ import {AstryxError} from '../error.mjs';
19
+ import {
20
+ coversProperty,
21
+ longhandsOf,
22
+ } from '../../foundation/runtime/css-tree.mjs';
23
+ import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
24
+ import {context} from './_context.mjs';
25
+ import {baseResolved} from './_project.mjs';
26
+ import {
27
+ compileTheme,
28
+ controlOf,
29
+ editedThemes,
30
+ loadTheme,
31
+ stateSlot,
32
+ } from './_settings.mjs';
33
+ import {censusStatesOf} from './_parts.mjs';
34
+ import {
35
+ mergeRules,
36
+ ownTokens,
37
+ partShows,
38
+ partValues,
39
+ resolveIn,
40
+ scopedTokens,
41
+ } from './_how-commands.mjs';
42
+ import {FAMILIES, P} from './_tables.mjs';
43
+ import {condition} from './_how.mjs';
44
+
45
+ /** @typedef {{light: Record<string, string>, dark: Record<string, string>}} ModeTokens */
46
+
47
+ /**
48
+ * A theme as the answer reads it: its tokens and part styles, and those of
49
+ * the theme it extends (Core's defaults when it extends none).
50
+ * @typedef {object} LoadedTheme
51
+ * @property {'editor' | 'local' | 'package' | 'bundled'} kind
52
+ * @property {ModeTokens} tokens
53
+ * @property {Record<string, any>} components
54
+ * @property {ModeTokens} parentTokens
55
+ * @property {Record<string, any>} parentComponents
56
+ * @property {ModeTokens} coreTokens - Core's own defaults
57
+ * @property {(property: string, part: string, when: string, state: string) => {when: string | null, state: string | null, exact: boolean} | null} [settingAt] - The property setting that wrote the theme's rule on the part under a rule key (`when|state` as the build writes them), as `set` took it.
58
+ */
59
+
60
+ /**
61
+ * A logical property as the physical one it sets in a left-to-right,
62
+ * top-to-bottom page (`padding-inline-start` is `padding-left`): the two
63
+ * cascade as one property.
64
+ * @param {string} prop
65
+ */
66
+ const physical = prop =>
67
+ prop
68
+ .replace(/-inline-start(?=$|-)/, '-left')
69
+ .replace(/-inline-end(?=$|-)/, '-right')
70
+ .replace(/-block-start(?=$|-)/, '-top')
71
+ .replace(/-block-end(?=$|-)/, '-bottom')
72
+ .replace(/^border-start-start-radius$/, 'border-top-left-radius')
73
+ .replace(/^border-start-end-radius$/, 'border-top-right-radius')
74
+ .replace(/^border-end-start-radius$/, 'border-bottom-left-radius')
75
+ .replace(/^border-end-end-radius$/, 'border-bottom-right-radius')
76
+ .replace(/^inset-inline-start$/, 'left')
77
+ .replace(/^inset-inline-end$/, 'right')
78
+ .replace(/^inset-block-start$/, 'top')
79
+ .replace(/^inset-block-end$/, 'bottom');
80
+
81
+ /**
82
+ * Whether a rule that sets `a` also sets what `b` shows: `b` is `a`, a
83
+ * longhand of it, or a logical name of one of those.
84
+ * @param {string} a
85
+ * @param {string} b
86
+ */
87
+ const sets = (a, b) =>
88
+ a === b ||
89
+ physical(a) === physical(b) ||
90
+ coversProperty(a, b) ||
91
+ coversProperty(physical(a), physical(b));
92
+
93
+ /**
94
+ * A part's rules with each rule's `@light` and `@dark` blocks taken out,
95
+ * and what those blocks set: a value for one mode of a property under the
96
+ * rule's key, not a condition of its own.
97
+ * @param {Record<string, any> | undefined} comp
98
+ */
99
+ function foldModes(comp) {
100
+ /** @type {Record<string, any>} */
101
+ const rules = {};
102
+ /** @type {{when: string, state: string, property: string, mode: 'light' | 'dark', value: string}[]} */
103
+ const modeSets = [];
104
+ for (const [when, rule] of Object.entries(comp ?? {})) {
105
+ if (!rule || typeof rule !== 'object') {
106
+ rules[when] = rule;
107
+ continue;
108
+ }
109
+ /** @type {Record<string, any>} */
110
+ const kept = {};
111
+ for (const [k, v] of Object.entries(rule)) {
112
+ if (k !== '@light' && k !== '@dark') {
113
+ kept[k] = v;
114
+ continue;
115
+ }
116
+ const mode = k === '@light' ? 'light' : 'dark';
117
+ for (const [k2, v2] of Object.entries(v ?? {}))
118
+ if (v2 && typeof v2 === 'object')
119
+ for (const [k3, v3] of Object.entries(v2))
120
+ modeSets.push({
121
+ when,
122
+ state: k2,
123
+ property: kebab(k3),
124
+ mode,
125
+ value: String(v3),
126
+ });
127
+ else
128
+ modeSets.push({
129
+ when,
130
+ state: '',
131
+ property: kebab(k2),
132
+ mode,
133
+ value: String(v2),
134
+ });
135
+ }
136
+ rules[when] = kept;
137
+ }
138
+ return {rules, modeSets};
139
+ }
140
+
141
+ /**
142
+ * Whether two rule keys name one condition: a theme's own rule writes a
143
+ * variant `variant:ghost`, Core writes `variant=ghost`, in any word order.
144
+ * @param {string} a
145
+ * @param {string} b
146
+ */
147
+ const sameWhen = (a, b) => {
148
+ /** @param {string} w */
149
+ const words = w =>
150
+ w
151
+ .split(/[\s+]/)
152
+ .filter(Boolean)
153
+ .map(x => (/^[a-z][\w-]*:[^\s:]+$/i.test(x) ? x.replace(':', '=') : x))
154
+ .sort()
155
+ .join(' ');
156
+ return words(a) === words(b);
157
+ };
158
+
159
+ /** @param {string} k */
160
+ const kebab = k =>
161
+ k.startsWith('--') ? k : k.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`);
162
+
163
+ /** A token Core keeps to itself (`--_x`, `--astryx-x`). @param {string} t */
164
+ const isPrivate = t => /^--(?:_|astryx-)/.test(t);
165
+
166
+ /**
167
+ * The public tokens a declaration reads, in order, once each.
168
+ * @param {string} value
169
+ */
170
+ function tokensIn(value) {
171
+ return [
172
+ ...new Set(
173
+ [...String(value).matchAll(/var\(\s*(--[a-z0-9-]+)/gi)].map(m => m[1]),
174
+ ),
175
+ ].filter(t => !isPrivate(t));
176
+ }
177
+
178
+ /**
179
+ * The tokens a declaration reads in one mode, following each token's own
180
+ * value to the tokens it reads in turn.
181
+ * @param {string} value
182
+ * @param {Record<string, string>} map
183
+ */
184
+ function tokenChain(value, map) {
185
+ /** @type {string[]} */
186
+ const out = [];
187
+ /** @param {string} v @param {number} depth */
188
+ const walk = (v, depth) => {
189
+ for (const t of tokensIn(v)) {
190
+ if (out.includes(t)) continue;
191
+ out.push(t);
192
+ if (depth < 8 && map[t] != null) walk(map[t], depth + 1);
193
+ }
194
+ };
195
+ walk(value, 0);
196
+ return out;
197
+ }
198
+
199
+ /**
200
+ * Load a theme by name: an editor theme first (it is the one `show` names
201
+ * without more), else a theme the project lists (local, package or
202
+ * bundled), loaded as `theme build` loads it.
203
+ * @param {any} ctx the editor context
204
+ * @param {string} cwd
205
+ * @param {string} name
206
+ * @returns {Promise<LoadedTheme>}
207
+ */
208
+ async function loadNamedTheme(ctx, cwd, name) {
209
+ const {core} = ctx.project;
210
+ const coreDefaults = await baseResolved(ctx.project, undefined);
211
+ if (editedThemes(cwd).includes(name)) {
212
+ const data = loadTheme(cwd, name);
213
+ const base = await baseResolved(ctx.project, data.like);
214
+ const compiled = compileTheme(ctx, data, base);
215
+ /** @param {import('./_settings.mjs').ThemeData['settings'][number]} st @param {string} part */
216
+ const reaches = (st, part) =>
217
+ st.on == null
218
+ ? false
219
+ : st.on === part || (FAMILIES[st.on] ?? []).includes(part);
220
+ // A rule the theme writes on a part comes from a property setting on
221
+ // it, matched by the rule key the build writes for that setting (its
222
+ // `--when` and `--state` placed the way the build places them).
223
+ /** @type {NonNullable<LoadedTheme['settingAt']>} */
224
+ const settingAt = (property, part, when, state) => {
225
+ const t = ctx.project.target.get(part);
226
+ const mine = data.settings.filter(
227
+ s =>
228
+ reaches(s, part) &&
229
+ s.source === 'property' &&
230
+ sets(String(s.thing), property),
231
+ );
232
+ /** @param {any} s */
233
+ const slotOf = s =>
234
+ stateSlot(
235
+ t?.states ?? [],
236
+ s.state,
237
+ s.when,
238
+ controlOf(ctx, part),
239
+ t?.stateValues,
240
+ censusStatesOf(ctx.project, part),
241
+ );
242
+ const exact = mine.find(s => {
243
+ const slot = slotOf(s);
244
+ return slot.key === when && (slot.pseudo ?? '') === state;
245
+ });
246
+ if (exact)
247
+ return {
248
+ when: exact.when ?? null,
249
+ state: exact.state ?? null,
250
+ exact: true,
251
+ };
252
+ // (A setting with no --when that the build copies into each variant
253
+ // rule the part draws, as a card's fill: the part's, under the
254
+ // variant's own condition.)
255
+ const copied = mine.find(s => {
256
+ const slot = slotOf(s);
257
+ return (
258
+ s.when == null &&
259
+ when !== 'base' &&
260
+ slot.key === 'base' &&
261
+ (slot.pseudo ?? '') === state
262
+ );
263
+ });
264
+ return copied
265
+ ? {when: null, state: copied.state ?? null, exact: false}
266
+ : null;
267
+ };
268
+ // (What the theme's settings make. What a person adds by hand below
269
+ // the settings in its theme file is not read here.)
270
+ const tokens = ownTokens(compiled, base, core);
271
+ const components = mergeComponents(
272
+ base.components,
273
+ compiled.components ?? {},
274
+ );
275
+ return {
276
+ kind: 'editor',
277
+ tokens,
278
+ components,
279
+ parentTokens: {light: base.light, dark: base.dark},
280
+ parentComponents: base.components ?? {},
281
+ coreTokens: {light: coreDefaults.light, dark: coreDefaults.dark},
282
+ settingAt,
283
+ };
284
+ }
285
+ const found = await findProjectTheme(cwd, name);
286
+ if (!found)
287
+ throw new AstryxError(
288
+ `No theme named "${name}" in this project: an editor theme, a local theme or an installed theme package.`,
289
+ [
290
+ {name: 'astryx theme list', reason: 'the themes this project has'},
291
+ {name: `${P} new ${name} --like neutral`, reason: 'or start one'},
292
+ ],
293
+ ERROR_CODES.ERR_UNKNOWN_THEME,
294
+ );
295
+ const {loadThemeInput} = await import('../theme/build/build.mjs');
296
+ const file = path.resolve(found.sourceDir, found.entry);
297
+ const loaded = await loadThemeInput(file, {cwd, name: found.slug});
298
+ if (!loaded?.theme)
299
+ throw new AstryxError(
300
+ `The ${found.slug} theme does not load${loaded?.error ? `: ${loaded.error.message}` : ''}.`,
301
+ [
302
+ {
303
+ name: `astryx theme build ${path.relative(cwd, file) || file} --check`,
304
+ reason: 'see why',
305
+ },
306
+ ],
307
+ ERROR_CODES.ERR_THEME_INVALID,
308
+ );
309
+ const theme = loaded.theme;
310
+ // The theme it extends, made again from its input as Core made it; Core's
311
+ // defaults when it extends none.
312
+ const parentInput = loaded.chain[0];
313
+ const parent = parentInput ? core.defineTheme(parentInput) : null;
314
+ return {
315
+ kind: found.source,
316
+ tokens: {
317
+ light: core.resolveThemeTokens(theme, {mode: 'light'}),
318
+ dark: core.resolveThemeTokens(theme, {mode: 'dark'}),
319
+ },
320
+ components: theme.components ?? {},
321
+ parentTokens: parent
322
+ ? {
323
+ light: core.resolveThemeTokens(parent, {mode: 'light'}),
324
+ dark: core.resolveThemeTokens(parent, {mode: 'dark'}),
325
+ }
326
+ : {light: coreDefaults.light, dark: coreDefaults.dark},
327
+ parentComponents: parent?.components ?? {},
328
+ coreTokens: {light: coreDefaults.light, dark: coreDefaults.dark},
329
+ };
330
+ }
331
+
332
+ /**
333
+ * Part styles with another theme's on top, rule by rule (a rule that sets
334
+ * one property keeps the others).
335
+ * @param {Record<string, any>} under
336
+ * @param {Record<string, any>} over
337
+ */
338
+ function mergeComponents(under, over) {
339
+ /** @type {Record<string, any>} */
340
+ const out = {};
341
+ for (const part of new Set([
342
+ ...Object.keys(under ?? {}),
343
+ ...Object.keys(over ?? {}),
344
+ ]))
345
+ out[part] = mergeRules(under?.[part] ?? {}, over?.[part] ?? {});
346
+ return out;
347
+ }
348
+
349
+ /**
350
+ * One property of the part, as the answer gives it.
351
+ * @typedef {import('./theme-edit.type.mjs').ThemeEditPartValue} PartValue
352
+ */
353
+
354
+ /**
355
+ * What one part of a theme shows.
356
+ * @param {string} cwd
357
+ * @param {string} name the theme
358
+ * @param {string} part
359
+ * @returns {Promise<import('./theme-edit.type.mjs').ThemeEditShowPartResponse>}
360
+ */
361
+ export async function themePartValues(cwd, name, part) {
362
+ const ctx = await context(cwd);
363
+ const key = String(part).trim().toLowerCase();
364
+ if (Object.hasOwn(FAMILIES, key) && !ctx.project.target.has(key))
365
+ throw new AstryxError(
366
+ `${key} is a group; --on takes one part of it: ${FAMILIES[key].join(', ')}.`,
367
+ FAMILIES[key].slice(0, 3).map((/** @type {string} */ m) => ({
368
+ name: `${P} show ${name} --on ${m}`,
369
+ reason: 'one part',
370
+ })),
371
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
372
+ );
373
+ if (!ctx.project.target.has(key))
374
+ throw new AstryxError(
375
+ `No part named "${part}". --on takes a part, as \`${P} how --list parts\` lists them.`,
376
+ [{name: `${P} how --list parts`, reason: 'every part'}],
377
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
378
+ );
379
+ if (ctx.unchecked)
380
+ throw new AstryxError(
381
+ `What ${key} reads cannot be worked out here: ${ctx.unchecked}`,
382
+ [{name: 'astryx doctor', reason: 'see why'}],
383
+ ERROR_CODES.ERR_RENDER_FAILED,
384
+ );
385
+ const theme = await loadNamedTheme(ctx, cwd, name);
386
+ // A rule's `@light` or `@dark` block is a value for one mode, read into
387
+ // that mode's value below, not a condition.
388
+ const folded = foldModes(theme.components?.[key]);
389
+ const parentFolded = foldModes(theme.parentComponents?.[key]);
390
+ const shows = partShows(
391
+ ctx.C,
392
+ {},
393
+ {components: {...theme.components, [key]: folded.rules}},
394
+ theme.tokens,
395
+ key,
396
+ );
397
+ const own = partValues(folded.rules);
398
+ const inherited = partValues(parentFolded.rules);
399
+ const themeRules = mergeRules(folded.rules);
400
+ const parentRules = mergeRules(parentFolded.rules);
401
+ /**
402
+ * The tokens inside the part under a condition, in each mode: the
403
+ * theme's, the theme it extends, and Core's, each with what that theme's
404
+ * own rule on the part sets.
405
+ * @param {string} when
406
+ */
407
+ const inside = when => {
408
+ /**
409
+ * A mode's tokens with what the rules' `@light` or `@dark` blocks set
410
+ * for that mode on the part, at rest and under this condition.
411
+ * @param {Record<string, string>} map
412
+ * @param {typeof folded.modeSets} sets
413
+ * @param {'light' | 'dark'} mode
414
+ */
415
+ const withBlocks = (map, sets, mode) => {
416
+ const out = {...map};
417
+ for (const w of ['base', when])
418
+ for (const m of sets)
419
+ if (
420
+ m.mode === mode &&
421
+ !m.state &&
422
+ m.property.startsWith('--') &&
423
+ sameWhen(m.when, w)
424
+ )
425
+ out[m.property] = m.value;
426
+ return out;
427
+ };
428
+ const tl = scopedTokens(themeRules, theme.tokens.light, when);
429
+ const td = scopedTokens(themeRules, theme.tokens.dark, when);
430
+ const pl = scopedTokens(parentRules, theme.parentTokens.light, when);
431
+ const pd = scopedTokens(parentRules, theme.parentTokens.dark, when);
432
+ return {
433
+ theme: {
434
+ light: withBlocks(tl, folded.modeSets, 'light'),
435
+ dark: withBlocks(td, folded.modeSets, 'dark'),
436
+ },
437
+ parent: {
438
+ light: withBlocks(pl, parentFolded.modeSets, 'light'),
439
+ dark: withBlocks(pd, parentFolded.modeSets, 'dark'),
440
+ },
441
+ };
442
+ };
443
+ /**
444
+ * Whether a mode block is the theme's own: not taken unchanged from the
445
+ * theme it extends.
446
+ * @param {(typeof folded.modeSets)[number]} m
447
+ */
448
+ const ownBlock = m =>
449
+ !parentFolded.modeSets.some(
450
+ p =>
451
+ p.mode === m.mode &&
452
+ p.property === m.property &&
453
+ p.state === m.state &&
454
+ p.value === m.value &&
455
+ sameWhen(p.when, m.when),
456
+ );
457
+ /**
458
+ * The tokens the theme's own mode blocks set inside the part under a
459
+ * condition: the ones a value there reads in that mode (a block at rest,
460
+ * or under the same condition, with no state).
461
+ * @param {string} when
462
+ * @param {boolean} [any] the theme's and the base's blocks alike
463
+ */
464
+ const blockTokensAt = (when, any = false) =>
465
+ new Set(
466
+ folded.modeSets
467
+ .filter(
468
+ m =>
469
+ m.property.startsWith('--') &&
470
+ !m.state &&
471
+ ['base', when].some(w => sameWhen(m.when, w)) &&
472
+ (any || ownBlock(m)),
473
+ )
474
+ .map(m => m.property),
475
+ );
476
+ /** @type {PartValue[]} */
477
+ const values = [];
478
+ /** @type {WeakMap<PartValue, {when: string, state: string, own: boolean}>} */
479
+ const rawKey = new WeakMap();
480
+ // The theme layer comes after Core's styles: a property a rule on the
481
+ // part sets, in the same variant or at rest, is what shows for every
482
+ // property it sets, whatever Core writes.
483
+ const ruleProps = [...own.keys()].map(k => k.split('|'));
484
+ /** @param {string} when @param {string} property */
485
+ const ruledOver = (when, property) =>
486
+ ruleProps.some(
487
+ ([w, st, p]) =>
488
+ !st &&
489
+ (w === when || w === 'base') &&
490
+ p !== property &&
491
+ sets(p, property),
492
+ );
493
+ // A shorthand in a rule whose every longhand a later declaration of the
494
+ // same rule sets shows none of its own value.
495
+ const order = [...own.keys()];
496
+ /** @param {string} k */
497
+ const overwritten = k => {
498
+ const [when, state, property] = k.split('|');
499
+ const parts = [...longhandsOf(property)].map(physical);
500
+ if (!parts.length) return false;
501
+ const later = order
502
+ .slice(order.indexOf(k) + 1)
503
+ .map(x => x.split('|'))
504
+ .filter(([w, st]) => w === when && st === state)
505
+ .map(([, , p]) => physical(p));
506
+ return parts.every(p => later.some(l => l === p || longhandsOf(l).has(p)));
507
+ };
508
+ const t = ctx.project.target.get(key);
509
+ /**
510
+ * A rule key's condition as the flags `set` takes, the way `how` gives
511
+ * it: a theme rule a property setting wrote takes that setting's own
512
+ * --when and --state; any other key is read the way Core reads a style
513
+ * key (`variant:ghost+selected`, `variant=ghost`) and given to the same
514
+ * converter `how <part>` uses. A condition no flag reaches keeps Core's
515
+ * words and says why.
516
+ * @param {string} when @param {string} state
517
+ * @param {string | null} ruleProperty the property of the theme's own
518
+ * rule, or null for one of Core's
519
+ * @returns {{when: string | null, state: string | null, notSettable?: string}}
520
+ */
521
+ const condOf = (when, state, ruleProperty) => {
522
+ const wrote =
523
+ ruleProperty != null && theme.settingAt
524
+ ? theme.settingAt(ruleProperty, key, when, state)
525
+ : null;
526
+ if (wrote?.exact) return {when: wrote.when, state: wrote.state};
527
+ const words = [
528
+ ...(when === 'base' ? [] : when.split(/\+|\s+/)),
529
+ ...(state ? [state] : []),
530
+ ]
531
+ .filter(Boolean)
532
+ .map(w =>
533
+ /^[a-z][\w-]*:[^\s:]+$/i.test(w)
534
+ ? w.replace(':', '=')
535
+ : /^[a-z][\w-]*$/i.test(w) && (t?.states ?? []).includes(w)
536
+ ? `${w}=${t?.stateValues?.[w] ?? w}`
537
+ : w,
538
+ );
539
+ const coreCond = words.join(' ');
540
+ const flags = condition(ctx, key, coreCond);
541
+ const unsettable = /\(not settable: (.*)\)$/.exec(flags);
542
+ if (unsettable)
543
+ return {
544
+ // (Core's attribute words in one order, so one condition is one row.)
545
+ when: [
546
+ ...words.filter(w => /^[a-z][\w-]*=/i.test(w)).sort(),
547
+ ...words.filter(w => !/^[a-z][\w-]*=/i.test(w)),
548
+ ].join(' '),
549
+ state: null,
550
+ notSettable: unsettable[1],
551
+ };
552
+ return {
553
+ when: /--when (\S+)/.exec(flags)?.[1] ?? null,
554
+ state: /--state (\S+)/.exec(flags)?.[1] ?? null,
555
+ };
556
+ };
557
+ for (const [k, v] of shows) {
558
+ const [when, state, property] = k.split('|');
559
+ if (!own.has(k) && ruledOver(when, property)) continue;
560
+ if (own.has(k) && overwritten(k)) continue;
561
+ const ruleKey = own.has(k) ? k : `base||${property}`;
562
+ const at = inside(when);
563
+ const light = tokenChain(v.raw, at.theme.light);
564
+ const dark = tokenChain(v.raw, at.theme.dark);
565
+ /** @param {ModeTokens} a @param {ModeTokens} b */
566
+ const changed = (a, b) => [
567
+ ...light.filter(t => a.light[t] !== b.light[t]),
568
+ ...dark.filter(t => a.dark[t] !== b.dark[t]),
569
+ ];
570
+ const mine = changed(at.theme, at.parent);
571
+ /** @type {PartValue['source']} */
572
+ let source = 'core';
573
+ if (own.has(ruleKey) && own.get(ruleKey) === v.raw) {
574
+ // A rule on the part: the theme's own, or the one it extends with
575
+ // the tokens it reads changed inside the part.
576
+ const inheritedRule = inherited.get(ruleKey) === v.raw;
577
+ if (!inheritedRule) source = 'theme';
578
+ else source = mine.length ? 'theme' : 'base';
579
+ } else if (mine.length) {
580
+ source = 'theme';
581
+ } else if (changed(at.parent, theme.coreTokens).length) {
582
+ source = 'base';
583
+ }
584
+ // A value that reads a token a mode block sets on the part is the
585
+ // theme's, through that token.
586
+ const blockTokens = blockTokensAt(when);
587
+ if ([...light, ...dark].some(t => blockTokens.has(t))) source = 'theme';
588
+ const cond = condOf(when, state, own.has(k) ? property : null);
589
+ const row = {
590
+ property,
591
+ ...cond,
592
+ value: pairOf(
593
+ .../** @type {[string, string]} */ (
594
+ [...light, ...dark].some(t => blockTokensAt(when, true).has(t))
595
+ ? [
596
+ resolveIn(v.raw, at.theme.light, 'light'),
597
+ resolveIn(v.raw, at.theme.dark, 'dark'),
598
+ ]
599
+ : [v.light, v.dark]
600
+ ),
601
+ ),
602
+ expression: v.raw,
603
+ tokens: light.join(' ') === dark.join(' ') ? light : {light, dark},
604
+ source,
605
+ };
606
+ values.push(row);
607
+ rawKey.set(row, {when, state, own: own.has(k)});
608
+ }
609
+ // What a rule's `@light` or `@dark` block sets: that mode's value of the
610
+ // property under the rule's condition, with that mode's declaration and
611
+ // tokens; a block with no row of its own (a state Core's map leaves out,
612
+ // a property the part reads nowhere else) is a row of its own.
613
+ for (const m of folded.modeSets) {
614
+ const other = m.mode === 'light' ? 'dark' : 'light';
615
+ const at = inside(m.when);
616
+ const shown = orNull(resolveIn(m.value, at.theme[m.mode], m.mode));
617
+ const chain = tokenChain(m.value, at.theme[m.mode]);
618
+ /** @param {any} x @param {'light' | 'dark'} mode */
619
+ const half = (x, mode) =>
620
+ x && typeof x === 'object' && !Array.isArray(x) ? x[mode] : x;
621
+ /** @param {any} a @param {any} b */
622
+ const pair = (a, b) =>
623
+ JSON.stringify(a) === JSON.stringify(b)
624
+ ? a
625
+ : // (A mode with nothing under it is left out: not shown yet.)
626
+ Object.fromEntries(
627
+ /** @type {[string, any][]} */ (
628
+ m.mode === 'light'
629
+ ? [
630
+ ['light', a],
631
+ ['dark', b],
632
+ ]
633
+ : [
634
+ ['light', b],
635
+ ['dark', a],
636
+ ]
637
+ ).filter(([, x]) => x !== undefined),
638
+ );
639
+ let alone = false;
640
+ let target = values.find(v => {
641
+ const r = rawKey.get(v);
642
+ return (
643
+ v.property === m.property &&
644
+ r != null &&
645
+ sameWhen(r.when, m.when) &&
646
+ r.state === m.state
647
+ );
648
+ });
649
+ if (!target) {
650
+ // The other mode shows what the same condition shows without the
651
+ // block: its own row, else the same variant at rest (Core's state
652
+ // conditions are not rows of their own), else the part at rest.
653
+ const cond = condOf(m.when, m.state, m.property);
654
+ const base =
655
+ values.find(
656
+ v =>
657
+ v.property === m.property &&
658
+ v.when === cond.when &&
659
+ v.state === cond.state,
660
+ ) ??
661
+ (cond.when != null
662
+ ? values.find(
663
+ v =>
664
+ v.property === m.property &&
665
+ v.when === cond.when &&
666
+ v.state == null,
667
+ )
668
+ : undefined) ??
669
+ values.find(
670
+ v => v.property === m.property && v.when == null && v.state == null,
671
+ );
672
+ alone = !base;
673
+ target = {
674
+ property: m.property,
675
+ ...cond,
676
+ value: base ? half(base.value, other) : null,
677
+ expression: base ? half(base.expression, other) : '',
678
+ tokens: base ? half(base.tokens, other) : [],
679
+ source: 'theme',
680
+ };
681
+ // (Filled in for this mode below, as for a row the block joins.)
682
+ target.value = pair(null, target.value);
683
+ target.expression = pair('', target.expression);
684
+ target.tokens = pair([], target.tokens);
685
+ values.push(target);
686
+ rawKey.set(target, {when: m.when, state: m.state, own: true});
687
+ }
688
+ target.value = pair(shown, half(target.value, other));
689
+ target.expression = pair(m.value, half(target.expression, other));
690
+ target.tokens = pair(chain, half(target.tokens, other));
691
+ // (A row of its own with nothing else under its condition: the other
692
+ // mode is not shown yet, so it is left out, not given as no value.)
693
+ if (alone) {
694
+ target.value = /** @type {any} */ ({[m.mode]: shown});
695
+ target.expression = /** @type {any} */ ({[m.mode]: m.value});
696
+ target.tokens = /** @type {any} */ ({[m.mode]: chain});
697
+ }
698
+ // (A block the theme takes as it is from the theme it extends is the
699
+ // base's.)
700
+ const inherited = !ownBlock(m);
701
+ target.source = inherited ? 'base' : 'theme';
702
+ }
703
+ // At rest first, then each variant, in the order the part reads them.
704
+ values.sort((a, b) => Number(a.when != null) - Number(b.when != null));
705
+ // A longhand Core writes beside its own shorthand, with the same value,
706
+ // says nothing more (a button's four corner radii beside its radius).
707
+ // One condition Core writes in two word orders reads as one row.
708
+ const seenRows = new Set();
709
+ // A condition a theme rule sets shows the rule's value, not Core's too.
710
+ const ruled = new Set(
711
+ values
712
+ .filter(v => rawKey.get(v)?.own)
713
+ .map(v => JSON.stringify([v.property, v.when, v.state])),
714
+ );
715
+ const unique = values.filter(v => {
716
+ if (
717
+ !rawKey.get(v)?.own &&
718
+ ruled.has(JSON.stringify([v.property, v.when, v.state]))
719
+ )
720
+ return false;
721
+ const id = JSON.stringify([
722
+ v.property,
723
+ v.when,
724
+ v.state,
725
+ v.value,
726
+ v.expression,
727
+ ]);
728
+ if (seenRows.has(id)) return false;
729
+ seenRows.add(id);
730
+ return true;
731
+ });
732
+ const said = unique.filter(
733
+ v =>
734
+ !unique.some(
735
+ o =>
736
+ o !== v &&
737
+ o.when === v.when &&
738
+ o.state === v.state &&
739
+ o.property !== v.property &&
740
+ sets(o.property, v.property) &&
741
+ !sets(v.property, o.property) &&
742
+ JSON.stringify(o.value) === JSON.stringify(v.value) &&
743
+ o.expression === v.expression,
744
+ ),
745
+ );
746
+ return {
747
+ type: 'themeEdit.showPart',
748
+ data: {theme: name, kind: theme.kind, part: key, values: said},
749
+ };
750
+ }
751
+
752
+ /**
753
+ * A value in each mode, one value when the modes agree; a value with a
754
+ * var() still in it is no value.
755
+ * @param {string} light
756
+ * @param {string} dark
757
+ */
758
+ const pairOf = (light, dark) =>
759
+ light === dark ? orNull(light) : {light: orNull(light), dark: orNull(dark)};
760
+
761
+ /**
762
+ * A value with a var() still in it is no value: null.
763
+ * @param {string} v
764
+ */
765
+ const orNull = v => (/var\(/.test(v) ? null : v);
766
+
767
+ /**
768
+ * A theme the project lists, by slug. A slug two packages provide is the
769
+ * one the app records under that slug; with none recorded, it is refused,
770
+ * naming the packages: `show` selects no package.
771
+ * @param {string} cwd
772
+ * @param {string} name
773
+ */
774
+ async function findProjectTheme(cwd, name) {
775
+ const {findTheme, readThemeListState} = await import('../theme/_adapter.mjs');
776
+ try {
777
+ return await findTheme(name, {cwd, includeLocal: true});
778
+ } catch (e) {
779
+ const err = /** @type {any} */ (e);
780
+ if (err?.code !== ERROR_CODES.ERR_AMBIGUOUS_THEME) throw e;
781
+ const recorded = (() => {
782
+ try {
783
+ return readThemeListState(cwd).themes[name] ?? null;
784
+ } catch {
785
+ return null;
786
+ }
787
+ })();
788
+ if (recorded)
789
+ return findTheme(name, {cwd, includeLocal: true, package: recorded});
790
+ // Each package's `theme add`, which takes --package; once the app
791
+ // records one, show reads that one.
792
+ throw new AstryxError(
793
+ `Theme "${name}" is provided by more than one package, and the app records none of them, so show cannot tell which one to read. Add the one you use to the app; show then reads it.`,
794
+ err.suggestions ?? [
795
+ {name: 'astryx theme list', reason: 'the packages that provide it'},
796
+ ],
797
+ ERROR_CODES.ERR_AMBIGUOUS_THEME,
798
+ );
799
+ }
800
+ }