@astryxdesign/cli 0.7.13 → 0.7.14-canary.108f354

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 (164) hide show
  1. package/README.md +18 -18
  2. package/api/component/__fixtures__/resolutions/modules.txt +1 -1
  3. package/api/doctor/doctor.mjs +3 -7
  4. package/api/experimental.d.mts +2 -0
  5. package/api/experimental.mjs +12 -0
  6. package/api/icon/_adapter.d.mts +10 -0
  7. package/api/icon/_adapter.mjs +31 -2
  8. package/api/icon/_authoring.d.mts +2 -1
  9. package/api/icon/_authoring.mjs +91 -6
  10. package/api/icon/_options.mjs +1 -0
  11. package/api/icon/_records.d.mts +18 -0
  12. package/api/icon/_records.mjs +26 -0
  13. package/api/icon/add/add.mjs +7 -1
  14. package/api/icon/definitions/definitions.d.mts +12 -0
  15. package/api/icon/definitions/definitions.mjs +83 -0
  16. package/api/icon/icon.doc.mjs +5 -4
  17. package/api/icon/icon.mjs +5 -16
  18. package/api/icon/icon.type.d.mts +29 -2
  19. package/api/icon/icon.type.mjs +17 -3
  20. package/api/icon/iconAdd.doc.mjs +1 -1
  21. package/api/icon/iconMap.doc.mjs +2 -2
  22. package/api/icon/iconNewSet.doc.mjs +8 -2
  23. package/api/icon/map/map.mjs +21 -2
  24. package/api/icon/new-set/new-set.mjs +14 -2
  25. package/api/icon/search/search.mjs +2 -15
  26. package/api/icon/use/use.mjs +4 -3
  27. package/api/integration/validate-integration.mjs +6 -1
  28. package/api/integration/validate-integration.type.d.mts +12 -0
  29. package/api/integration/validate-integration.type.mjs +5 -0
  30. package/api/theme-edit/_adapter.d.mts +116 -0
  31. package/api/theme-edit/_adapter.mjs +1683 -0
  32. package/api/theme-edit/_catalog.d.mts +59 -0
  33. package/api/theme-edit/_catalog.mjs +564 -0
  34. package/api/theme-edit/_check.d.mts +49 -0
  35. package/api/theme-edit/_check.mjs +845 -0
  36. package/api/theme-edit/_color.d.mts +29 -0
  37. package/api/theme-edit/_color.mjs +300 -0
  38. package/api/theme-edit/_compiler.d.mts +61 -0
  39. package/api/theme-edit/_compiler.mjs +522 -0
  40. package/api/theme-edit/_css-properties.d.mts +10 -0
  41. package/api/theme-edit/_css-properties.mjs +556 -0
  42. package/api/theme-edit/_parts.d.mts +111 -0
  43. package/api/theme-edit/_parts.mjs +409 -0
  44. package/api/theme-edit/_png.d.mts +40 -0
  45. package/api/theme-edit/_png.mjs +187 -0
  46. package/api/theme-edit/_preview.d.mts +121 -0
  47. package/api/theme-edit/_preview.mjs +720 -0
  48. package/api/theme-edit/_project.d.mts +83 -0
  49. package/api/theme-edit/_project.mjs +289 -0
  50. package/api/theme-edit/_settings.d.mts +222 -0
  51. package/api/theme-edit/_settings.mjs +861 -0
  52. package/api/theme-edit/_tables.d.mts +132 -0
  53. package/api/theme-edit/_tables.mjs +700 -0
  54. package/api/theme-edit/theme-edit.d.mts +93 -0
  55. package/api/theme-edit/theme-edit.mjs +145 -0
  56. package/api/theme-edit/theme-edit.type.d.mts +413 -0
  57. package/api/theme-edit/theme-edit.type.mjs +233 -0
  58. package/api/theme-edit/themeEditHow.doc.d.mts +6 -0
  59. package/api/theme-edit/themeEditHow.doc.mjs +88 -0
  60. package/api/theme-edit/themeEditNew.doc.d.mts +6 -0
  61. package/api/theme-edit/themeEditNew.doc.mjs +89 -0
  62. package/api/theme-edit/themeEditPreviewAdd.doc.d.mts +6 -0
  63. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +100 -0
  64. package/api/theme-edit/themeEditPreviewApp.doc.d.mts +6 -0
  65. package/api/theme-edit/themeEditPreviewApp.doc.mjs +84 -0
  66. package/api/theme-edit/themeEditPreviewList.doc.d.mts +6 -0
  67. package/api/theme-edit/themeEditPreviewList.doc.mjs +53 -0
  68. package/api/theme-edit/themeEditPreviewRemove.doc.d.mts +6 -0
  69. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +66 -0
  70. package/api/theme-edit/themeEditSet.doc.d.mts +6 -0
  71. package/api/theme-edit/themeEditSet.doc.mjs +165 -0
  72. package/api/theme-edit/themeEditShow.doc.d.mts +6 -0
  73. package/api/theme-edit/themeEditShow.doc.mjs +86 -0
  74. package/api/theme-edit/themeEditUndo.doc.d.mts +6 -0
  75. package/api/theme-edit/themeEditUndo.doc.mjs +124 -0
  76. package/assets/docs/color.doc.mjs +5 -5
  77. package/assets/docs/tree/icon-sets.doc.mjs +6 -2
  78. package/assets/docs/tree/tokens-border.doc.mjs +1 -1
  79. package/assets/docs/tree/tokens-color.doc.mjs +2 -2
  80. package/assets/docs/tree/tokens-data.doc.mjs +2 -2
  81. package/assets/docs/tree/tokens-duration.doc.mjs +1 -1
  82. package/assets/docs/tree/tokens-ease.doc.mjs +1 -1
  83. package/assets/docs/tree/tokens-focus.doc.mjs +1 -1
  84. package/assets/docs/tree/tokens-font-weight.doc.mjs +1 -1
  85. package/assets/docs/tree/tokens-radius.doc.mjs +1 -1
  86. package/assets/docs/tree/tokens-shadow.doc.mjs +1 -1
  87. package/assets/docs/tree/tokens-size.doc.mjs +1 -1
  88. package/assets/docs/tree/tokens-spacing.doc.mjs +1 -1
  89. package/assets/docs/tree/tokens-syntax.doc.mjs +1 -1
  90. package/assets/docs/tree/tokens-text-size.doc.mjs +1 -1
  91. package/assets/docs/tree/tokens-type-scale.doc.mjs +1 -1
  92. package/assets/docs/tree/tokens-typography.doc.mjs +1 -1
  93. package/assets/icons/definitions/bank.doc.mjs +1 -1
  94. package/assets/icons/definitions/save.doc.mjs +1 -1
  95. package/assets/preview-app/README.md +6 -0
  96. package/assets/preview-app/css.d.ts +5 -0
  97. package/assets/preview-app/gitignore +1 -0
  98. package/assets/preview-app/next.config.mjs +6 -0
  99. package/assets/preview-app/package.json +23 -0
  100. package/assets/preview-app/src/app/globals.css +5 -0
  101. package/assets/preview-app/src/app/layout.tsx +21 -0
  102. package/assets/preview-app/src/app/page.tsx +94 -0
  103. package/assets/preview-app/src/app/providers.tsx +16 -0
  104. package/assets/preview-app/tsconfig.json +27 -0
  105. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.doc.mjs +2 -1
  106. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider02Overrides.doc.mjs +2 -1
  107. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider03RtlDirection.doc.mjs +2 -1
  108. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider04Calendar.doc.mjs +2 -1
  109. package/assets/templates/blocks/components/Text/useTruncationHookUsage.doc.mjs +14 -0
  110. package/assets/templates/blocks/components/Text/useTruncationHookUsage.tsx +112 -0
  111. package/authoring/doctypes/_schema.d.mts +1 -0
  112. package/authoring/doctypes/_schema.mjs +1 -0
  113. package/authoring/doctypes/command/command.doc.mjs +7 -0
  114. package/authoring/doctypes/command/type.ts +3 -0
  115. package/authoring/doctypes/icon-set/parse.d.mts +7 -0
  116. package/authoring/doctypes/icon-set/parse.mjs +18 -8
  117. package/clients/cli/commands/doctor.mjs +33 -3
  118. package/clients/cli/commands/experimental/icon.mjs +67 -14
  119. package/clients/cli/commands/experimental/index.mjs +2 -0
  120. package/clients/cli/commands/experimental/theme.mjs +684 -0
  121. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +7 -1
  122. package/clients/cli/commands/experimental-icon.doc.mjs +3 -2
  123. package/clients/cli/commands/experimental-theme-add.doc.mjs +78 -0
  124. package/clients/cli/commands/experimental-theme-compile.doc.mjs +97 -0
  125. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +84 -0
  126. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +66 -0
  127. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +121 -0
  128. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +66 -0
  129. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +104 -0
  130. package/clients/cli/commands/experimental-theme-editor.doc.mjs +49 -0
  131. package/clients/cli/commands/experimental-theme-eject.doc.mjs +71 -0
  132. package/clients/cli/commands/experimental-theme-list.doc.mjs +49 -0
  133. package/clients/cli/commands/experimental-theme-palette-generate.doc.mjs +73 -0
  134. package/clients/cli/commands/experimental-theme-palette.doc.mjs +37 -0
  135. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +86 -0
  136. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +66 -0
  137. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +48 -0
  138. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +59 -0
  139. package/clients/cli/commands/experimental-theme-preview.doc.mjs +40 -0
  140. package/clients/cli/commands/experimental-theme-remove.doc.mjs +55 -0
  141. package/clients/cli/commands/experimental-theme-targets.doc.mjs +61 -0
  142. package/clients/cli/commands/experimental-theme-template.doc.mjs +61 -0
  143. package/clients/cli/commands/experimental-theme-use.doc.mjs +55 -0
  144. package/clients/cli/commands/experimental-theme.doc.mjs +57 -0
  145. package/clients/cli/commands/experimental.doc.mjs +10 -3
  146. package/clients/cli/commands/theme.mjs +101 -34
  147. package/clients/cli/index.mjs +18 -0
  148. package/clients/cli/lib/define-command.mjs +3 -0
  149. package/foundation/discovery/icon-set-checks.d.mts +16 -1
  150. package/foundation/discovery/icon-set-checks.mjs +68 -7
  151. package/foundation/discovery/icon-set-discovery.d.mts +21 -6
  152. package/foundation/discovery/icon-set-discovery.mjs +17 -8
  153. package/foundation/discovery/template-icon-meanings.d.mts +39 -0
  154. package/foundation/discovery/template-icon-meanings.mjs +95 -0
  155. package/foundation/discovery/theming-targets.d.mts +6 -0
  156. package/foundation/discovery/theming-targets.mjs +33 -0
  157. package/foundation/response/error-codes.d.mts +12 -1
  158. package/foundation/response/error-codes.doc.mjs +66 -0
  159. package/foundation/response/error-codes.mjs +55 -0
  160. package/foundation/response/response-types.doc.mjs +55 -0
  161. package/foundation/text/template-meanings-line.d.mts +16 -0
  162. package/foundation/text/template-meanings-line.mjs +37 -0
  163. package/foundation/xle/browser.d.mts +2 -2
  164. package/package.json +6 -6
@@ -0,0 +1,684 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file `astryx experimental theme` — the `editor` group makes and changes a
5
+ * theme one checked change at a time; beside it sit experimental copies of
6
+ * the theme commands. Experimental (spec:AST-017 FR27): it is registered only
7
+ * under the `experimental` group.
8
+ *
9
+ * The command surface comes from the colocated CommandDocs via
10
+ * `defineCommand`; this file reads flags, calls the theme-edit API, and
11
+ * prints its receipt.
12
+ *
13
+ * Usage:
14
+ * astryx experimental theme editor new brand --like neutral
15
+ * astryx experimental theme editor set brand corners pill
16
+ * astryx experimental theme editor how "white text in the banner"
17
+ */
18
+
19
+ import {getCliInvocation} from '../../../../foundation/env/package-manager.mjs';
20
+ import {jsonOut} from '../../../../foundation/response/json.mjs';
21
+ import {NO_RESULT_SET, resultSet} from '../../../../foundation/debug/index.mjs';
22
+ import {ERROR_CODES} from '../../../../foundation/response/error-codes.mjs';
23
+ import {emit, text} from '../../formatters/index.mjs';
24
+ import {cliError} from '../../lib/cli-error.mjs';
25
+ import {defineCommand} from '../../lib/define-command.mjs';
26
+ import {
27
+ themeEditHow,
28
+ themeEditNew,
29
+ themeEditPreviewAdd,
30
+ themeEditPreviewApp,
31
+ themeEditPreviewList,
32
+ themeEditPreviewRemove,
33
+ themeEditSet,
34
+ themeEditShow,
35
+ themeEditUndo,
36
+ } from '../../../../api/theme-edit/theme-edit.mjs';
37
+ import {registerThemeSubcommands} from '../theme.mjs';
38
+ import {doc as groupDoc} from '../experimental-theme.doc.mjs';
39
+ import {doc as editorDoc} from '../experimental-theme-editor.doc.mjs';
40
+ import {doc as newDoc} from '../experimental-theme-editor-new.doc.mjs';
41
+ import {doc as setDoc} from '../experimental-theme-editor-set.doc.mjs';
42
+ import {doc as showDoc} from '../experimental-theme-editor-show.doc.mjs';
43
+ import {doc as undoDoc} from '../experimental-theme-editor-undo.doc.mjs';
44
+ import {doc as previewDoc} from '../experimental-theme-preview.doc.mjs';
45
+ import {doc as previewAddDoc} from '../experimental-theme-preview-add.doc.mjs';
46
+ import {doc as previewAppDoc} from '../experimental-theme-preview-app.doc.mjs';
47
+ import {doc as previewListDoc} from '../experimental-theme-preview-list.doc.mjs';
48
+ import {doc as previewRemoveDoc} from '../experimental-theme-preview-remove.doc.mjs';
49
+ import {doc as howDoc} from '../experimental-theme-editor-how.doc.mjs';
50
+ import {doc as paletteDoc} from '../experimental-theme-palette.doc.mjs';
51
+ import {doc as paletteGenerateDoc} from '../experimental-theme-palette-generate.doc.mjs';
52
+ import {doc as compileDoc} from '../experimental-theme-compile.doc.mjs';
53
+ import {doc as listDoc} from '../experimental-theme-list.doc.mjs';
54
+ import {doc as addDoc} from '../experimental-theme-add.doc.mjs';
55
+ import {doc as removeDoc} from '../experimental-theme-remove.doc.mjs';
56
+ import {doc as useDoc} from '../experimental-theme-use.doc.mjs';
57
+ import {doc as ejectDoc} from '../experimental-theme-eject.doc.mjs';
58
+ import {doc as templateDoc} from '../experimental-theme-template.doc.mjs';
59
+ import {doc as targetsDoc} from '../experimental-theme-targets.doc.mjs';
60
+ import {doc as newFn} from '../../../../api/theme-edit/themeEditNew.doc.mjs';
61
+ import {doc as setFn} from '../../../../api/theme-edit/themeEditSet.doc.mjs';
62
+ import {doc as showFn} from '../../../../api/theme-edit/themeEditShow.doc.mjs';
63
+ import {doc as undoFn} from '../../../../api/theme-edit/themeEditUndo.doc.mjs';
64
+ import {doc as previewAddFn} from '../../../../api/theme-edit/themeEditPreviewAdd.doc.mjs';
65
+ import {doc as previewAppFn} from '../../../../api/theme-edit/themeEditPreviewApp.doc.mjs';
66
+ import {doc as previewListFn} from '../../../../api/theme-edit/themeEditPreviewList.doc.mjs';
67
+ import {doc as previewRemoveFn} from '../../../../api/theme-edit/themeEditPreviewRemove.doc.mjs';
68
+ import {doc as howFn} from '../../../../api/theme-edit/themeEditHow.doc.mjs';
69
+
70
+ const PREFIX = 'astryx experimental theme';
71
+ const EDITOR = `${PREFIX} editor`;
72
+ /** The lookup command, named once: its CommandDoc's last word. */
73
+ const HOW = `${EDITOR} ${howDoc.name.split(' ').pop()}`;
74
+
75
+ /**
76
+ * Commands in a line, with the run prefix this project uses.
77
+ * @param {string} line
78
+ */
79
+ const cmd = line =>
80
+ line.split(PREFIX).join(`${getCliInvocation()} experimental theme`);
81
+
82
+ /** Print lines as one block. @param {string[]} lines */
83
+ const print = lines => emit(text(lines.map(cmd).join('\n')));
84
+
85
+ /**
86
+ * Run one API call: errors become the CLI error envelope, results go to
87
+ * JSON or to `render`.
88
+ * @template T
89
+ * @param {import('commander').Command} program
90
+ * @param {() => Promise<T>} call
91
+ * @param {(result: T) => string[]} render
92
+ * @param {(result: T) => import('../../../../foundation/debug/command-result.mjs').CommandResult} [answer]
93
+ */
94
+ async function run(program, call, render, answer) {
95
+ const json = program.opts().json || false;
96
+ /** @type {T} */
97
+ let result;
98
+ try {
99
+ result = await call();
100
+ } catch (e) {
101
+ const err = /** @type {import('../../../../api/error.mjs').AstryxError} */ (
102
+ e
103
+ );
104
+ return cliError(err.message, {
105
+ suggestions: err.suggestions,
106
+ code: err.code ?? ERROR_CODES.ERR_UNKNOWN,
107
+ });
108
+ }
109
+ const answered = answer
110
+ ? answer(result)
111
+ : resultSet({count: 1, resultKind: 'mixed', directMatch: true});
112
+ if (json) {
113
+ jsonOut(/** @type {any} */ (result));
114
+ return answered;
115
+ }
116
+ print(render(result));
117
+ return answered;
118
+ }
119
+
120
+ /** @param {{pictures: string[], pictureProblem: string | null}} d */
121
+ const pictureLines = d => [
122
+ ...(d.pictures.length ? [` pictures: ${d.pictures.join(', ')}`] : []),
123
+ ...(d.pictureProblem ? [` pictures: none. ${d.pictureProblem}`] : []),
124
+ ];
125
+
126
+ /** @param {import('../../../../api/theme-edit/theme-edit.type.mjs').ThemeEditSetting} s */
127
+ function describe(s) {
128
+ const where = s.on
129
+ ? ` on ${s.on}${s.only ? ' only' : ''}${s.when ? ` when ${s.when}` : ''}${s.state ? ` :${s.state}` : ''}`
130
+ : ' (whole theme)';
131
+ return `${s.thing} = ${s.value}${where}${s.mode ? ` [${s.mode} only]` : ''}`;
132
+ }
133
+
134
+ /**
135
+ * The flags of a change, from Commander's options.
136
+ * @param {any} o
137
+ */
138
+ const changeOptions = o => ({
139
+ cwd: process.cwd(),
140
+ on: o.on,
141
+ when: o.when,
142
+ state: o.state,
143
+ mode: o.mode,
144
+ only: o.only ?? false,
145
+ png: o.png ?? false,
146
+ });
147
+
148
+ /**
149
+ * The receipt of a set or unset.
150
+ * @param {import('../../../../api/theme-edit/theme-edit.type.mjs').ThemeEditChangeResponse} r
151
+ */
152
+ function changeLines(r) {
153
+ const d = r.data;
154
+ const s = d.setting;
155
+ /** @type {string[]} */
156
+ const lines = [];
157
+ if (d.was != null)
158
+ lines.push(`[ok] ${d.theme}: ${s.thing} ${d.was} -> ${s.value}`);
159
+ else
160
+ lines.push(
161
+ `[ok] ${d.theme}: ${d.action === 'set' ? describe(s) : `undid ${describe(s)}: back to the base theme's value`}${d.replaced ? ` (was ${d.replaced.value})` : ''}`,
162
+ );
163
+ if (d.family)
164
+ lines.push(
165
+ ` applied to the ${d.family.name} family: ${d.family.members.join(', ')}${d.family.onlyHint && s.on && !s.only ? ` (add --only to style just ${s.on})` : ''}`,
166
+ );
167
+ for (const n of d.notes) lines.push(` note: ${n}`);
168
+ if (d.changedTokens.length) {
169
+ lines.push(
170
+ ` resolved changes (${d.changedTokens.length}):`,
171
+ ...d.changedTokens.slice(0, 8).map(c => ` ${c}`),
172
+ );
173
+ if (d.changedTokens.length > 8)
174
+ lines.push(` ... ${d.changedTokens.length - 8} more (--json for all)`);
175
+ }
176
+ if (d.styled.length) {
177
+ lines.push(
178
+ ` styled (${d.styled.length}):`,
179
+ ...d.styled.slice(0, 8).map(c => ` ${c}`),
180
+ );
181
+ if (d.styled.length > 8)
182
+ lines.push(` ... ${d.styled.length - 8} more (--json for all)`);
183
+ }
184
+ if (!d.changedTokens.length && !d.styled.length && d.was == null)
185
+ lines.push(' no visible change: the theme already looked this way');
186
+ for (const k of d.kept)
187
+ lines.push(` kept (a part setting beats the whole-theme dial): ${k}`);
188
+ if (d.lifted.length) {
189
+ const keys = [
190
+ ...new Set(d.lifted.map(x => x.split(' ').slice(0, 2).join(' '))),
191
+ ];
192
+ lines.push(
193
+ ` also applied to ${keys.slice(0, 6).join(', ')}${keys.length > 6 ? ` and ${keys.length - 6} more` : ''}: the base theme styles those separately, so the plain setting alone would lose there`,
194
+ );
195
+ }
196
+ for (const w of d.warnings) lines.push(` build: ${w}`);
197
+ for (const p of d.problems) lines.push(` contrast: ${p}`);
198
+ lines.push(` preview: ${d.preview}`, ...pictureLines(d));
199
+ return lines;
200
+ }
201
+
202
+ /**
203
+ * The text of a lookup answer, by its kind.
204
+ * @param {any} d
205
+ * @returns {string[]}
206
+ */
207
+ function lookupLines(d) {
208
+ if (d.kind === 'question') {
209
+ if (!d.results.length) {
210
+ return [
211
+ `No match for "${d.subject}". Name the part (header, nav links, card, button, banner, input...) and what to change (text color, background, gradient, corners, border, shadow, spacing, bold). Or: ${HOW} --list parts`,
212
+ ];
213
+ }
214
+ return [
215
+ `"${d.subject}" -> parts: ${d.understood.parts.join(', ') || 'whole theme'}; aspects: ${d.understood.aspects.join(', ') || '?'}`,
216
+ ...d.results.flatMap((/** @type {any} */ x) => [
217
+ ` ${x.text}`,
218
+ ...x.commands.map((/** @type {string} */ c) => ` ${c}`),
219
+ ]),
220
+ ];
221
+ }
222
+ if (d.kind === 'aspect')
223
+ return [
224
+ `${d.subject} for the whole theme:`,
225
+ ...d.results.flatMap((/** @type {any} */ x) => [
226
+ ` ${x.text}`,
227
+ ...x.commands.map((/** @type {string} */ c) => ` ${c}`),
228
+ ]),
229
+ ];
230
+ if (d.kind === 'picture') {
231
+ if (d.points)
232
+ return [
233
+ `colors in ${d.file} (${d.width}x${d.height}) at:`,
234
+ ...d.points.map(
235
+ (/** @type {any} */ c) =>
236
+ ` (${c.at}) ${c.color ?? 'outside the picture'}`,
237
+ ),
238
+ ];
239
+ return [
240
+ `main colors in ${d.file} (${d.width}x${d.height}; share of the picture, where):`,
241
+ ...d.colors.map(
242
+ (/** @type {any} */ c) => ` ${c.color} ${c.share}% ${c.where}`,
243
+ ),
244
+ ];
245
+ }
246
+ if (d.kind === 'list') {
247
+ const items = /** @type {any[]} */ (d.items);
248
+ if (d.list === 'dials')
249
+ return items.flatMap(x => [
250
+ `${x.name}: ${x.values}`,
251
+ ` ${x.help}`,
252
+ ...x.examples.map((/** @type {string} */ e) => ` e.g. ${e}`),
253
+ ]);
254
+ if (d.list === 'families')
255
+ return items.map(
256
+ x =>
257
+ `${x.name}: ${x.members.join(', ')}${x.spreads ? ' (styling one styles all; --only to opt out)' : ' (--on the family styles all)'}`,
258
+ );
259
+ if (d.list === 'properties')
260
+ return [
261
+ ...items.map(x => x.name),
262
+ ...(d.common
263
+ ? [
264
+ `(the common ones; any standard CSS property works: ${HOW} <filter> --list properties)`,
265
+ ]
266
+ : []),
267
+ ];
268
+ if (d.list === 'tokens')
269
+ return items.map(
270
+ x =>
271
+ `${x.name} [${x.type}] default ${x.default}; read by ${x.readBy} parts`,
272
+ );
273
+ return [
274
+ ...items.map(
275
+ x =>
276
+ `${x.name} (${x.component})${x.family ? ` [${x.family}]` : ''}${Object.entries(
277
+ /** @type {Record<string, string[]>} */ (x.variants),
278
+ )
279
+ .map(
280
+ ([p, v]) => ` --when ${p}:${v.length ? v.join('|') : '<value>'}`,
281
+ )
282
+ .join(
283
+ '',
284
+ )}${x.states.length ? ` --state ${x.states.join('|')}` : ''}${x.recorded ? '' : ' (no compiled record: changes on it are not checked)'}`,
285
+ ),
286
+ `What a part reads: ${HOW} <part>`,
287
+ ];
288
+ }
289
+ return d.lines;
290
+ }
291
+
292
+ /**
293
+ * Refuse an option the command does not have. Set, undo and how take
294
+ * unknown options so a design token (`--color-accent`) can be the thing
295
+ * they name; a `--` word anywhere else is a mistyped option.
296
+ * @param {string} command the subcommand, for the suggestion
297
+ * @param {Array<string | undefined>} rest the operands after the thing
298
+ * @returns {ReturnType<typeof cliError> | null}
299
+ */
300
+ function strayOption(command, rest) {
301
+ const word = rest.find(w => typeof w === 'string' && w.startsWith('--'));
302
+ if (word == null) return null;
303
+ return cliError(
304
+ `unknown option '${word}': only the thing a change names may start with -- (a design token such as --color-accent).`,
305
+ {
306
+ suggestions: [
307
+ {name: `${EDITOR} ${command} --help`, reason: 'every option it takes'},
308
+ ],
309
+ code: ERROR_CODES.ERR_INVALID_OPTION,
310
+ },
311
+ );
312
+ }
313
+
314
+ /**
315
+ * Help that explains exactly what a subcommand does: its whole description
316
+ * under the usage line, while the group's list keeps the one-line summary.
317
+ * Token names start with `--`, so set and unset take unknown options as
318
+ * operands.
319
+ * @param {import('commander').Command} c
320
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc
321
+ * @param {{tokens?: boolean}} [options]
322
+ */
323
+ function explained(c, doc, {tokens = false} = {}) {
324
+ c.summary(c.description());
325
+ c.description(`[experimental] ${doc.description ?? doc.summary ?? ''}`);
326
+ if (tokens) c.allowUnknownOption(true);
327
+ return c;
328
+ }
329
+
330
+ /**
331
+ * A command group: bare, it prints its help; with an unknown word, the
332
+ * unknown-subcommand error with every subcommand as a suggestion.
333
+ * @param {import('commander').Command} parent
334
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc
335
+ * @returns {import('commander').Command}
336
+ */
337
+ function defineGroup(parent, doc) {
338
+ /** @type {import('commander').Command} */
339
+ const cmd = defineCommand(parent, doc, {
340
+ action: (
341
+ /** @type {unknown} */ _options,
342
+ /** @type {import('commander').Command} */ c,
343
+ ) => {
344
+ const extras = c?.args ?? [];
345
+ if (extras.length > 0) {
346
+ return cliError(
347
+ `unknown subcommand '${doc.name} ${String(extras[0])}'`,
348
+ {
349
+ suggestions: (cmd.commands ?? []).map(command => ({
350
+ name: command.name(),
351
+ reason: 'available subcommand',
352
+ })),
353
+ code: ERROR_CODES.ERR_UNKNOWN_SUBCOMMAND,
354
+ },
355
+ );
356
+ }
357
+ cmd.help();
358
+ return NO_RESULT_SET;
359
+ },
360
+ });
361
+ return cmd;
362
+ }
363
+
364
+ /**
365
+ * Register `theme` and its subcommands under the `experimental` group.
366
+ * @param {import('commander').Command} group the `experimental` command
367
+ * @param {import('commander').Command} program the root program
368
+ */
369
+ export function registerExperimentalTheme(group, program) {
370
+ const theme = defineGroup(group, groupDoc);
371
+ explained(theme, groupDoc);
372
+ theme.addHelpText(
373
+ 'after',
374
+ `\nComponent style overrides:\n` +
375
+ ` ${getCliInvocation()} experimental theme targets Every themeable class, with its props and states\n` +
376
+ ` ${getCliInvocation()} experimental theme editor how <part> What one part reads, and the commands that change it\n` +
377
+ ` ${getCliInvocation()} component <Name> One component's theming table\n`,
378
+ );
379
+
380
+ const editor = defineGroup(theme, editorDoc);
381
+ explained(editor, editorDoc);
382
+
383
+ explained(
384
+ defineCommand(editor, newDoc, {
385
+ fn: newFn,
386
+ action: (/** @type {string} */ name, /** @type {any} */ o) =>
387
+ run(
388
+ program,
389
+ () =>
390
+ themeEditNew(name, {
391
+ cwd: process.cwd(),
392
+ like: o.like,
393
+ png: o.png ?? false,
394
+ }),
395
+ r => [
396
+ `[ok] made theme "${r.data.theme}"${r.data.like ? ` on top of ${r.data.like}` : ''}: ${r.data.files.settings} (owned by this command) -> ${r.data.files.source} -> ${r.data.files.css}`,
397
+ ...r.data.problems.map(p => ` contrast: ${p}`),
398
+ ` preview: ${r.data.preview}`,
399
+ ...pictureLines(r.data),
400
+ ` next: ${EDITOR} set ${r.data.theme} <thing> <value> (${HOW} "<what you want>")`,
401
+ ],
402
+ ),
403
+ }),
404
+ newDoc,
405
+ );
406
+
407
+ explained(
408
+ defineCommand(editor, setDoc, {
409
+ fn: setFn,
410
+ action: (
411
+ /** @type {string} */ name,
412
+ /** @type {string} */ thing,
413
+ /** @type {string[]} */ value,
414
+ /** @type {any} */ o,
415
+ ) =>
416
+ strayOption('set', value) ??
417
+ run(
418
+ program,
419
+ () => themeEditSet(name, thing, value.join(' '), changeOptions(o)),
420
+ changeLines,
421
+ ),
422
+ }),
423
+ setDoc,
424
+ {tokens: true},
425
+ );
426
+
427
+ explained(
428
+ defineCommand(editor, showDoc, {
429
+ fn: showFn,
430
+ action: (/** @type {string} */ name, /** @type {any} */ o) =>
431
+ run(
432
+ program,
433
+ () =>
434
+ themeEditShow(name, {
435
+ cwd: process.cwd(),
436
+ png: o.png ?? false,
437
+ group: o.group,
438
+ }),
439
+ r => {
440
+ const d = r.data;
441
+ const modes =
442
+ d.mode === 'light-only'
443
+ ? ['light']
444
+ : d.mode === 'dark-only'
445
+ ? ['dark']
446
+ : ['light', 'dark'];
447
+ return [
448
+ `theme "${d.theme}"${d.like ? ` (on top of ${d.like})` : ''}, mode ${d.mode}, ${d.settings.length} settings:`,
449
+ ...d.settings.map(
450
+ (s, i) =>
451
+ ` ${i + 1}. [${s.source}] ${describe(s)}${s.parts.length > 1 ? ` -> ${s.parts.length} parts` : ''}`,
452
+ ),
453
+ `key values (${modes.join(' / ')}):`,
454
+ ...Object.entries(d.resolved).map(
455
+ ([k, v]) =>
456
+ ` ${k}: ${modes.map(m => v[m] ?? '-').join(' / ')}`,
457
+ ),
458
+ ...(d.problems.length
459
+ ? d.problems.map(p => `contrast: ${p}`)
460
+ : ['problems: none caused by this theme']),
461
+ ...d.notes.map(n => `note: ${n}`),
462
+ `preview (sample app page): ${d.preview}`,
463
+ `every component (theme-building page, ${d.sheetComponents} components): ${d.sheet}`,
464
+ ...d.skipped.map(x => ` left out: ${x}`),
465
+ ...pictureLines(d),
466
+ ];
467
+ },
468
+ ),
469
+ }),
470
+ showDoc,
471
+ );
472
+
473
+ explained(
474
+ defineCommand(editor, undoDoc, {
475
+ fn: undoFn,
476
+ action: (
477
+ /** @type {string} */ name,
478
+ /** @type {string | undefined} */ thing,
479
+ /** @type {string | undefined} */ which,
480
+ /** @type {any} */ o,
481
+ /** @type {import('commander').Command} */ c,
482
+ ) =>
483
+ strayOption('undo', [which, ...(c?.args ?? []).slice(3)]) ??
484
+ run(
485
+ program,
486
+ () =>
487
+ themeEditUndo(name, {
488
+ ...changeOptions(o),
489
+ ...(thing == null ? {} : {thing, value: which}),
490
+ }),
491
+ r =>
492
+ r.data.action === 'step'
493
+ ? [
494
+ `[ok] ${r.data.theme}: undid the last change${r.data.undone.length ? `: ${r.data.undone.join('; ')}` : ''}`,
495
+ ` now ${r.data.settings} settings; ${r.data.stepsLeft} earlier change${r.data.stepsLeft === 1 ? '' : 's'} can still be undone`,
496
+ ` preview: ${r.data.preview}`,
497
+ ...pictureLines(r.data),
498
+ ]
499
+ : changeLines(
500
+ /** @type {import('../../../../api/theme-edit/theme-edit.type.mjs').ThemeEditChangeResponse} */ (
501
+ r
502
+ ),
503
+ ),
504
+ ),
505
+ }),
506
+ undoDoc,
507
+ {tokens: true},
508
+ );
509
+
510
+ const preview = defineGroup(theme, previewDoc);
511
+ explained(preview, previewDoc);
512
+
513
+ explained(
514
+ defineCommand(preview, previewAddDoc, {
515
+ fn: previewAddFn,
516
+ action: (
517
+ /** @type {string[] | string | undefined} */ words,
518
+ /** @type {any} */ o,
519
+ ) =>
520
+ run(
521
+ program,
522
+ () =>
523
+ themeEditPreviewAdd([words ?? []].flat().join(' ') || undefined, {
524
+ cwd: process.cwd(),
525
+ theme: o.theme,
526
+ template: o.template,
527
+ top: o.top == null ? undefined : Number(o.top),
528
+ path: o.path,
529
+ }),
530
+ r => [
531
+ `[ok] theme preview in ${r.data.folder}: ${r.data.added.length ? `added ${r.data.added.join(', ')}` : 'pages refreshed'}; pages: ${r.data.pages.join(', ')}`,
532
+ ` theme: ${r.data.theme ?? "the app's own"}`,
533
+ ...r.data.notes.map(n => ` note: ${n}`),
534
+ ` open: ${r.data.open}`,
535
+ ],
536
+ ),
537
+ }),
538
+ previewAddDoc,
539
+ );
540
+
541
+ explained(
542
+ defineCommand(preview, previewAppDoc, {
543
+ fn: previewAppFn,
544
+ action: (/** @type {string} */ dir, /** @type {any} */ o) =>
545
+ run(
546
+ program,
547
+ () =>
548
+ themeEditPreviewApp(dir, {
549
+ cwd: process.cwd(),
550
+ theme: o.theme,
551
+ overwrite: o.overwrite ?? false,
552
+ }),
553
+ r => [
554
+ `[ok] new app in ${r.data.folder} (${r.data.files.length} files) with the theme preview; pages: ${r.data.pages.join(', ')}`,
555
+ ` theme: ${r.data.theme ?? "the app's own neutral theme"}`,
556
+ ...r.data.notes.map(n => ` note: ${n}`),
557
+ ` open: ${r.data.open}`,
558
+ ],
559
+ ),
560
+ }),
561
+ previewAppDoc,
562
+ );
563
+
564
+ explained(
565
+ defineCommand(preview, previewListDoc, {
566
+ fn: previewListFn,
567
+ action: (/** @type {any} */ o) =>
568
+ run(
569
+ program,
570
+ () => themeEditPreviewList({cwd: process.cwd(), path: o.path}),
571
+ r =>
572
+ r.data.folder
573
+ ? [
574
+ `theme preview in ${r.data.folder} (theme: ${r.data.theme ?? "the app's own"}):`,
575
+ ...r.data.pages.map(p => ` ${p.id} ${p.label}`),
576
+ ]
577
+ : [`no theme preview yet: ${PREFIX} preview add`],
578
+ r =>
579
+ resultSet({
580
+ count: r.data.pages.length,
581
+ resultKind: 'mixed',
582
+ empty: r.data.pages.length === 0,
583
+ }),
584
+ ),
585
+ }),
586
+ previewListDoc,
587
+ );
588
+
589
+ explained(
590
+ defineCommand(preview, previewRemoveDoc, {
591
+ fn: previewRemoveFn,
592
+ action: (/** @type {string | undefined} */ page, /** @type {any} */ o) =>
593
+ run(
594
+ program,
595
+ () =>
596
+ themeEditPreviewRemove(page, {cwd: process.cwd(), path: o.path}),
597
+ r => [
598
+ r.data.pages.length
599
+ ? `[ok] removed ${page} from the theme preview; pages: ${r.data.pages.join(', ')}`
600
+ : `[ok] removed the theme preview in ${r.data.folder}`,
601
+ ...r.data.removed.map(f => ` deleted ${f}`),
602
+ ],
603
+ ),
604
+ }),
605
+ previewRemoveDoc,
606
+ );
607
+
608
+ explained(
609
+ defineCommand(editor, howDoc, {
610
+ fn: howFn,
611
+ action: async (/** @type {string[]} */ words, /** @type {any} */ o) => {
612
+ if (!words.length && o.list == null && !(o.at ?? []).length) {
613
+ const c = editor.commands.find(
614
+ x => x.name() === howDoc.name.split(' ').pop(),
615
+ );
616
+ // In JSON mode outputHelp prints the help envelope.
617
+ if (program.opts().json) c?.outputHelp();
618
+ else
619
+ print([
620
+ `Usage: ${HOW} [<part|setting|"question"|picture.png>] [--at x,y] [--list dials|tokens|parts|families|properties]`,
621
+ '',
622
+ 'Examples:',
623
+ ...(howDoc.examples ?? []).flatMap(e => [
624
+ ` # ${e.label}`,
625
+ ` ${e.cli}`,
626
+ ]),
627
+ ]);
628
+ return NO_RESULT_SET;
629
+ }
630
+ const stray = strayOption('how', words.slice(1));
631
+ if (stray) return stray;
632
+ // A number after a picture is how many colors to list.
633
+ const count =
634
+ words.length === 2 &&
635
+ /\.png$/i.test(words[0]) &&
636
+ /^\d+$/.test(words[1])
637
+ ? Number(words[1])
638
+ : undefined;
639
+ const subject = count == null ? words.join(' ') : words[0];
640
+ return run(
641
+ program,
642
+ () =>
643
+ themeEditHow(subject, {
644
+ cwd: process.cwd(),
645
+ list: o.list,
646
+ at: o.at ?? [],
647
+ count,
648
+ }),
649
+ r => lookupLines(/** @type {any} */ (r.data)),
650
+ r => {
651
+ const d = /** @type {any} */ (r.data);
652
+ const n =
653
+ d.kind === 'list'
654
+ ? d.items.length
655
+ : d.kind === 'question'
656
+ ? d.results.length
657
+ : 1;
658
+ return resultSet({count: n, resultKind: 'mixed', empty: n === 0});
659
+ },
660
+ );
661
+ },
662
+ }),
663
+ howDoc,
664
+ {tokens: true},
665
+ );
666
+
667
+ registerThemeSubcommands(
668
+ theme,
669
+ program,
670
+ {
671
+ palette: paletteDoc,
672
+ paletteGenerate: paletteGenerateDoc,
673
+ build: compileDoc,
674
+ list: listDoc,
675
+ add: addDoc,
676
+ remove: removeDoc,
677
+ use: useDoc,
678
+ eject: ejectDoc,
679
+ template: templateDoc,
680
+ targets: targetsDoc,
681
+ },
682
+ {group: 'experimental theme', build: 'compile'},
683
+ );
684
+ }