@astryxdesign/cli 0.7.14 → 0.7.15-canary.g06b7e61

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 (203) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/README.md +63 -63
  3. package/api/build/_adapter.d.mts +4 -0
  4. package/api/build/_adapter.mjs +28 -2
  5. package/api/build/blocks/blocks.d.mts +10 -1
  6. package/api/build/blocks/blocks.mjs +84 -7
  7. package/api/build/build.mjs +6 -1
  8. package/api/build/tree.d.mts +4 -0
  9. package/api/build/tree.mjs +9 -2
  10. package/api/doctor/_adapter.d.mts +3 -1
  11. package/api/doctor/_adapter.mjs +14 -1
  12. package/api/doctor/_authoring-audit.d.mts +42 -0
  13. package/api/doctor/_authoring-audit.mjs +106 -0
  14. package/api/doctor/doctor.d.mts +7 -0
  15. package/api/doctor/doctor.mjs +24 -39
  16. package/api/doctor/theme-checks.mjs +56 -21
  17. package/api/integration/add-helpers.mjs +5 -0
  18. package/api/integration/add-theme.mjs +15 -110
  19. package/api/integration/validate-integration.mjs +17 -3
  20. package/api/integration/validateIntegration.doc.mjs +1 -1
  21. package/api/search/_adapter.mjs +124 -3
  22. package/api/search/_candidate-score.mjs +63 -9
  23. package/api/search/_entries.d.mts +10 -0
  24. package/api/search/_entries.mjs +68 -1
  25. package/api/search/_gather-templates.d.mts +11 -0
  26. package/api/search/_gather-templates.mjs +22 -2
  27. package/api/search/_words.mjs +26 -6
  28. package/api/swizzle/copy/copy.mjs +1 -1
  29. package/api/theme/_adapter.d.mts +37 -5
  30. package/api/theme/_adapter.mjs +381 -57
  31. package/api/theme/_fork.d.mts +90 -0
  32. package/api/theme/_fork.mjs +246 -0
  33. package/api/theme/build/build.d.mts +40 -2
  34. package/api/theme/build/build.mjs +477 -66
  35. package/api/theme/eject/eject.mjs +36 -15
  36. package/api/theme/list/list.mjs +3 -6
  37. package/api/theme/palette/generate/generator.d.mts +13 -0
  38. package/api/theme/palette/generate/generator.mjs +32 -2
  39. package/api/theme/targets/targets.d.mts +8 -0
  40. package/api/theme/targets/targets.mjs +24 -4
  41. package/api/theme/template/template.mjs +48 -2
  42. package/api/theme/theme.type.d.mts +8 -0
  43. package/api/theme/theme.type.mjs +5 -1
  44. package/api/theme/themeBuild.doc.mjs +7 -4
  45. package/api/theme/themeEject.doc.mjs +3 -3
  46. package/api/theme/themeRemove.doc.mjs +5 -2
  47. package/api/theme/themeTargets.doc.mjs +1 -1
  48. package/api/theme/themeTemplate.doc.mjs +2 -2
  49. package/api/theme/themeUse.doc.mjs +8 -2
  50. package/api/theme-edit/_adapter.d.mts +46 -3
  51. package/api/theme-edit/_adapter.mjs +496 -112
  52. package/api/theme-edit/_catalog.d.mts +1 -6
  53. package/api/theme-edit/_catalog.mjs +5 -268
  54. package/api/theme-edit/_check.d.mts +9 -4
  55. package/api/theme-edit/_check.mjs +1232 -229
  56. package/api/theme-edit/_color.d.mts +19 -0
  57. package/api/theme-edit/_color.mjs +280 -34
  58. package/api/theme-edit/_compiler.d.mts +3 -1
  59. package/api/theme-edit/_compiler.mjs +52 -13
  60. package/api/theme-edit/_context.d.mts +4 -1
  61. package/api/theme-edit/_context.mjs +126 -13
  62. package/api/theme-edit/_css.d.mts +84 -0
  63. package/api/theme-edit/_css.mjs +700 -0
  64. package/api/theme-edit/_edit.d.mts +9 -3
  65. package/api/theme-edit/_edit.mjs +806 -103
  66. package/api/theme-edit/_how-commands.d.mts +38 -7
  67. package/api/theme-edit/_how-commands.mjs +64 -45
  68. package/api/theme-edit/_how-question.d.mts +33 -0
  69. package/api/theme-edit/_how-question.mjs +2553 -381
  70. package/api/theme-edit/_how.mjs +402 -31
  71. package/api/theme-edit/_overview.mjs +2 -7
  72. package/api/theme-edit/_palette.d.mts +60 -13
  73. package/api/theme-edit/_palette.mjs +826 -295
  74. package/api/theme-edit/_parts.d.mts +42 -10
  75. package/api/theme-edit/_parts.mjs +280 -69
  76. package/api/theme-edit/_png.d.mts +4 -4
  77. package/api/theme-edit/_png.mjs +4 -2
  78. package/api/theme-edit/_preview-app.d.mts +14 -0
  79. package/api/theme-edit/_preview-app.mjs +1675 -235
  80. package/api/theme-edit/_preview.d.mts +7 -16
  81. package/api/theme-edit/_preview.mjs +79 -86
  82. package/api/theme-edit/_project.d.mts +32 -2
  83. package/api/theme-edit/_project.mjs +80 -19
  84. package/api/theme-edit/_settings.d.mts +199 -52
  85. package/api/theme-edit/_settings.mjs +1422 -217
  86. package/api/theme-edit/_tables.d.mts +19 -6
  87. package/api/theme-edit/_tables.mjs +150 -92
  88. package/api/theme-edit/theme-edit.type.d.mts +20 -1
  89. package/api/theme-edit/theme-edit.type.mjs +6 -3
  90. package/api/theme-edit/themeEditHow.doc.mjs +6 -0
  91. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  92. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
  93. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  94. package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
  95. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
  96. package/api/theme-edit/themeEditSet.doc.mjs +1 -1
  97. package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
  98. package/api/upgrade/_adapter.d.mts +1 -0
  99. package/assets/codemods/run-codemod.mjs +61 -0
  100. package/assets/codemods/runner.mjs +5 -4
  101. package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
  102. package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
  103. package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
  104. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
  105. package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
  106. package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
  107. package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
  108. package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
  109. package/assets/docs/tree/calendars.doc.mjs +1 -3
  110. package/assets/docs/tree/checks.doc.mjs +22 -1
  111. package/assets/docs/tree/publishing.doc.mjs +1 -0
  112. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  113. package/assets/docs.generated.json +2 -1
  114. package/assets/preview-app/next.config.mjs +7 -1
  115. package/assets/self-audit.generated.json +1 -0
  116. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
  117. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
  118. package/assets/templates/components.generated.json +1 -1
  119. package/authoring/integration/integration.doc.mjs +8 -0
  120. package/authoring/integration/schema.d.mts +8 -0
  121. package/authoring/integration/schema.mjs +1 -0
  122. package/authoring/integration/type.ts +9 -0
  123. package/clients/cli/bin/astryx.mjs +19 -15
  124. package/clients/cli/build-id.generated.json +1 -0
  125. package/clients/cli/commands/ensure-core-built.mjs +12 -5
  126. package/clients/cli/commands/experimental/index.mjs +10 -10
  127. package/clients/cli/commands/experimental/theme.mjs +200 -81
  128. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  129. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
  130. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
  131. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
  132. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  133. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  134. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  135. package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
  136. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  137. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  138. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
  139. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
  140. package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
  141. package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
  142. package/clients/cli/commands/integration.mjs +8 -0
  143. package/clients/cli/commands/manifest.mjs +5 -2
  144. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  145. package/clients/cli/commands/theme-list.doc.mjs +1 -1
  146. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  147. package/clients/cli/commands/theme.mjs +439 -66
  148. package/clients/cli/index.mjs +27 -6
  149. package/clients/cli/lib/cli-error.mjs +118 -3
  150. package/clients/cli/lib/manifest.mjs +37 -0
  151. package/clients/cli/lib/resolve-theme.mjs +2 -1
  152. package/clients/cli/manifest.generated.json +1 -0
  153. package/foundation/config/project.mjs +34 -8
  154. package/foundation/config/theme-state.d.mts +16 -0
  155. package/foundation/config/theme-state.mjs +84 -13
  156. package/foundation/discovery/module-exports.mjs +16 -2
  157. package/foundation/discovery/stored-self-audit.d.mts +31 -0
  158. package/foundation/discovery/stored-self-audit.mjs +119 -0
  159. package/foundation/discovery/template-adapter.d.mts +48 -2
  160. package/foundation/discovery/template-adapter.mjs +51 -19
  161. package/foundation/discovery/template-needs.d.mts +19 -0
  162. package/foundation/discovery/template-needs.mjs +50 -16
  163. package/foundation/discovery/template-source-tree.d.mts +7 -0
  164. package/foundation/discovery/template-source-tree.mjs +15 -0
  165. package/foundation/discovery/theme-discovery.d.mts +2 -1
  166. package/foundation/discovery/theme-discovery.mjs +16 -10
  167. package/foundation/discovery/theme-imports.d.mts +16 -0
  168. package/foundation/discovery/theme-imports.mjs +30 -2
  169. package/foundation/discovery/theme-module-extensions.d.mts +18 -0
  170. package/foundation/discovery/theme-module-extensions.mjs +30 -0
  171. package/foundation/doc-compiler/import.mjs +22 -15
  172. package/foundation/doc-compiler/stored-docs.d.mts +18 -12
  173. package/foundation/doc-compiler/stored-docs.mjs +52 -19
  174. package/foundation/env/private-dir.d.mts +17 -0
  175. package/foundation/env/private-dir.mjs +42 -0
  176. package/foundation/fs/gather-cache.d.mts +108 -0
  177. package/foundation/fs/gather-cache.mjs +783 -0
  178. package/foundation/fs/jiti-cache.d.mts +21 -0
  179. package/foundation/fs/jiti-cache.mjs +66 -0
  180. package/foundation/fs/module-loader.mjs +14 -3
  181. package/foundation/fs/read-record.d.mts +31 -1
  182. package/foundation/fs/read-record.mjs +100 -7
  183. package/foundation/integrations/autolink.d.mts +1 -24
  184. package/foundation/integrations/autolink.mjs +7 -60
  185. package/foundation/integrations/declared-dependencies.d.mts +27 -0
  186. package/foundation/integrations/declared-dependencies.mjs +73 -0
  187. package/foundation/integrations/integrations.d.mts +8 -0
  188. package/foundation/integrations/integrations.mjs +4 -0
  189. package/foundation/integrations/may-have-integrations.d.mts +8 -0
  190. package/foundation/integrations/may-have-integrations.mjs +47 -0
  191. package/foundation/integrations/validate-contributions.d.mts +62 -1
  192. package/foundation/integrations/validate-contributions.mjs +476 -40
  193. package/foundation/release/cache.d.mts +32 -4
  194. package/foundation/release/cache.mjs +105 -16
  195. package/foundation/release/folder-lock.d.mts +28 -0
  196. package/foundation/release/folder-lock.mjs +205 -0
  197. package/foundation/release/lock-lease.d.mts +2 -1
  198. package/foundation/release/lock-lease.mjs +7 -2
  199. package/foundation/response/error-codes.doc.mjs +1 -1
  200. package/foundation/response/response-types.doc.mjs +5 -5
  201. package/package.json +8 -6
  202. package/api/theme-edit/_css-properties.d.mts +0 -10
  203. package/api/theme-edit/_css-properties.mjs +0 -556
@@ -13,7 +13,7 @@
13
13
  import * as fs from 'node:fs';
14
14
  import * as path from 'node:path';
15
15
  import {AstryxError} from '../error.mjs';
16
- import {CSS_PROPERTIES} from './_css-properties.mjs';
16
+ import {cssProperties} from './_css.mjs';
17
17
  import {
18
18
  AUTO_SPREAD,
19
19
  COLOR_PROPS,
@@ -23,18 +23,23 @@ import {
23
23
  FAMILIES,
24
24
  GROUPS,
25
25
  HOW,
26
+ LIKE,
26
27
  P,
27
28
  familyOf,
28
29
  } from './_tables.mjs';
29
30
  import {colorsAt, decodePng, mainColors} from './_png.mjs';
30
- import {loadTheme, nearest, refuse} from './_settings.mjs';
31
- import {ASPECTS} from './_check.mjs';
31
+ import {baseThemeFile, installLine} from './_project.mjs';
32
+ import {loadTheme, nearest, refuse, themeSourceProblem} from './_settings.mjs';
33
+ import {ASPECTS, checkSetting} from './_check.mjs';
32
34
  import {MODAL} from './_compiler.mjs';
33
35
  import {PALETTE_DIALS, mappingRows, paletteFiles} from './_palette.mjs';
34
36
  import {requireProject, context} from './_context.mjs';
35
37
  import {checked, exampleStep, howTheme, render} from './_how-commands.mjs';
36
38
  import {draftAnswer} from './_how-question.mjs';
37
- import {getCliInvocation} from '../../foundation/env/package-manager.mjs';
39
+ import {
40
+ getCliInvocation,
41
+ quoteCommandArgument,
42
+ } from '../../foundation/env/package-manager.mjs';
38
43
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
39
44
 
40
45
  const E = ERROR_CODES;
@@ -66,13 +71,28 @@ const PICTURE_NAME = /\.(png|jpe?g|gif|webp|bmp|avif|heic|tiff?|svg)$/i;
66
71
  * @param {string} cwd
67
72
  */
68
73
  export function isPicture(subject, cwd) {
69
- if (!subject || /\s/.test(subject.trim())) return false;
70
- if (PICTURE_NAME.test(subject)) return true;
74
+ if (!subject) return false;
75
+ // A file that exists is a picture whatever its name: macOS names every
76
+ // screenshot "Screenshot … at 1.23.45 PM.png".
71
77
  try {
72
- return fs.statSync(path.resolve(cwd, subject)).isFile();
78
+ if (fs.statSync(path.resolve(cwd, subject.trim())).isFile()) return true;
73
79
  } catch {
74
- return false;
80
+ // Not a file here.
75
81
  }
82
+ return !/\s/.test(subject.trim()) && PICTURE_NAME.test(subject);
83
+ }
84
+
85
+ /**
86
+ * A dial's help, with what `set` does now where that differs from it: Core
87
+ * gives headings the body family when the theme names no heading family,
88
+ * so `font --on body` moves headings too.
89
+ * @param {string} key
90
+ * @param {{bodyFontReachesHeadings: boolean}} env
91
+ */
92
+ function dialHelp(key, env) {
93
+ return key === 'font' && env.bodyFontReachesHeadings
94
+ ? `${DIALS.font.help} Note: font --on body also sets the heading font while the theme sets no heading font; for body text alone, set --font-family-body.`
95
+ : DIALS[key].help;
76
96
  }
77
97
 
78
98
  /**
@@ -93,6 +113,34 @@ export async function themeEditHow(subject, options = {}) {
93
113
  const {cwd = process.cwd()} = options;
94
114
  requireProject(cwd);
95
115
  try {
116
+ if (options.words) {
117
+ // The words as typed: a picture first takes only a count after it;
118
+ // anything else is one subject.
119
+ const words = options.words;
120
+ const picture = isPicture(words[0] ?? '', cwd);
121
+ const again = `${HOW} ${quoteCommandArgument(words[0] ?? '')} 5`;
122
+ if (picture && words.length > 2)
123
+ throw new AstryxError(
124
+ `After a picture, give only how many colors to list, not "${words.slice(1).join(' ')}".`,
125
+ [{name: again, reason: 'do this instead'}],
126
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
127
+ );
128
+ // A missing picture is the first thing to say, before a bad count.
129
+ if (
130
+ picture &&
131
+ words.length === 2 &&
132
+ !/^[1-9]\d*$/.test(words[1]) &&
133
+ fs.existsSync(path.resolve(cwd, words[0]))
134
+ )
135
+ throw new AstryxError(
136
+ `The count after a picture must be a positive whole number, not "${words[1]}".`,
137
+ [{name: again, reason: 'do this instead'}],
138
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
139
+ );
140
+ subject = picture ? words[0] : words.join(' ');
141
+ if (picture && words.length === 2)
142
+ options = {...options, count: Number(words[1])};
143
+ }
96
144
  const data = await answer(subject, options, cwd);
97
145
  return {type: 'themeEdit.how', data: withPrefix(data, cwd)};
98
146
  } catch (e) {
@@ -141,12 +189,24 @@ async function answer(subject, options, cwd) {
141
189
  refuse(E.ERR_INVALID_ARGUMENT, '--theme was given no name.', {
142
190
  run: [`${HOW} ${t ? JSON.stringify(t) : 'card'}`],
143
191
  });
144
- if (options.theme != null) loadTheme(cwd, options.theme);
192
+ if (options.theme != null) {
193
+ loadTheme(cwd, options.theme);
194
+ // A theme whose source no longer extends its settings takes no setting:
195
+ // an answer would suggest commands that cannot run.
196
+ const broken = themeSourceProblem(cwd, options.theme);
197
+ if (broken)
198
+ refuse(
199
+ E.ERR_THEME_INVALID,
200
+ `${broken}, so settings cannot take effect and no command here would change the theme. Put back the import, extends and name lines in themes/${options.theme}/${options.theme}.theme.ts, then ask again.`,
201
+ {run: [`${P} show ${options.theme}`]},
202
+ );
203
+ }
145
204
  if (list != null) {
146
205
  if (at.length)
147
206
  refuse(
148
207
  E.ERR_INVALID_ARGUMENT,
149
208
  '--at reads a picture; --list lists names, so drop one of them.',
209
+ {run: [`${HOW} --list ${quoteCommandArgument(String(list))}`]},
150
210
  );
151
211
  const kind = listKind(list);
152
212
  if (kind === 'kinds')
@@ -253,12 +313,15 @@ async function answer(subject, options, cwd) {
253
313
  if (key === 'text' || key === 'background')
254
314
  results.unshift(
255
315
  ...['accent', 'neutral'].map(d => ({
256
- text: DIALS[d].help,
316
+ text: dialHelp(d, env),
257
317
  commands: dialCommands(d),
258
318
  })),
259
319
  );
260
320
  if (dial)
261
- results.unshift({text: DIALS[dial].help, commands: dialCommands(dial)});
321
+ results.unshift({
322
+ text: dialHelp(dial, env),
323
+ commands: dialCommands(dial),
324
+ });
262
325
  results.push({
263
326
  text: `for one part: ${HOW} <part> lists what it reads for ${key}`,
264
327
  commands: [`${HOW} button`],
@@ -267,12 +330,33 @@ async function answer(subject, options, cwd) {
267
330
  }
268
331
  if (Object.hasOwn(DIALS, key)) {
269
332
  const d = DIALS[key];
333
+ // A base is named only when it is installed here; the others are
334
+ // listed with the line that installs them.
335
+ const installed = (/** @type {string} */ b) => {
336
+ try {
337
+ baseThemeFile(ctx.project, b);
338
+ return true;
339
+ } catch {
340
+ return false;
341
+ }
342
+ };
343
+ const missing = key === 'base' ? LIKE.filter(b => !installed(b)) : [];
270
344
  return {
271
345
  kind: 'setting',
272
346
  subject: t,
273
347
  source: 'dial',
274
- values: d.values,
275
- help: d.help,
348
+ values:
349
+ key === 'base'
350
+ ? [...LIKE.filter(installed), 'none'].join('|')
351
+ : d.values,
352
+ help:
353
+ dialHelp(key, env) +
354
+ (missing.length
355
+ ? ` Not installed here: ${missing.join(', ')} (${installLine(
356
+ ctx.project.cwd,
357
+ missing.map(b => `@astryxdesign/theme-${b}`),
358
+ )}).`
359
+ : ''),
276
360
  ...(PALETTE_DIALS.includes(key) ? {shades: mappingRows(key)} : {}),
277
361
  ...themeFields,
278
362
  examples: dialCommands(key),
@@ -283,7 +367,7 @@ async function answer(subject, options, cwd) {
283
367
  Object.hasOwn(ctx.project.core.tokenDefaults, key)
284
368
  )
285
369
  return tokenAnswer(ctx, env, t, key, unknown, themeFields);
286
- if (CSS_PROPERTIES.has(key)) {
370
+ if (cssProperties().has(key)) {
287
371
  const setters = Object.keys(C.MAP).filter(p => key in C.MAP[p].own);
288
372
  const value = exampleForProperty(key);
289
373
  const {commands, refused} = value
@@ -310,16 +394,106 @@ async function answer(subject, options, cwd) {
310
394
  };
311
395
  }
312
396
  // "What does --color-accent do", "what's the variable for card padding":
397
+ // "--focus-outline-width: 3px": a token typed with a value is set exactly,
398
+ // or refused with the nearest names; never another token.
399
+ const typedToken =
400
+ /^\s*(--[a-z][a-z0-9-]*)\s*(?::|\s+to\s+|\s+)\s*([^;]+?)\s*;?\s*(?:\bin (light|dark) mode\b.*)?$/i.exec(
401
+ t.replace(/^\s*(?:change|set|make|token)\s+/i, ' '),
402
+ );
403
+ if (
404
+ typedToken &&
405
+ (Object.hasOwn(
406
+ ctx.project.core.tokenDefaults,
407
+ typedToken[1].toLowerCase(),
408
+ ) ||
409
+ nearest(
410
+ typedToken[1].toLowerCase(),
411
+ Object.keys(ctx.project.core.tokenDefaults),
412
+ ).length > 0) &&
413
+ !/^--(on|when|state|mode|theme|list|at)$/.test(typedToken[1]) &&
414
+ // "what does --color-accent do" is a lookup.
415
+ !/^\s*(what|which|where|how|is|are|does|do|explain|why)\b/i.test(t) &&
416
+ !/^(do|does|mean|means|for|control|controls)\b/i.test(typedToken[2].trim())
417
+ ) {
418
+ const token = typedToken[1].toLowerCase();
419
+ const mode = /\bin (light|dark) mode\b/i.exec(t)?.[1]?.toLowerCase();
420
+ const defaults = ctx.project.core.tokenDefaults;
421
+ const near = nearest(token, Object.keys(defaults));
422
+ // A token that does not exist is refused with the nearest real names;
423
+ // a flag-like word with none near is read as words.
424
+ if (!Object.hasOwn(defaults, token) && near.length)
425
+ return refuse(E.ERR_INVALID_ARGUMENT, `There is no token ${token}.`, {
426
+ run: near.map(k => `${HOW} ${k}`),
427
+ });
428
+ // Quotes come off only when the whole value is one quoted string: a
429
+ // font stack keeps its quoted family.
430
+ const typedValue = typedToken[2].trim();
431
+ const value = /^(["'])([^"']*)\1$/.test(typedValue)
432
+ ? typedValue.slice(1, -1)
433
+ : typedValue;
434
+ const {commands, refused} = checked(env, [
435
+ [
436
+ {
437
+ verb: 'set',
438
+ thing: token,
439
+ value,
440
+ ...(mode && env.data.mode === 'both' ? {mode} : {}),
441
+ },
442
+ ],
443
+ ]);
444
+ return {
445
+ kind: 'question',
446
+ subject: t,
447
+ understood: {parts: [], aspects: []},
448
+ ...themeFields,
449
+ results: [
450
+ {
451
+ text: commands.length
452
+ ? `the token ${token}, as you wrote it`
453
+ : `${token} ${value}: ${refused[0]?.why ?? 'no command does it'}`,
454
+ commands,
455
+ ...(refused.length ? {refused} : {}),
456
+ },
457
+ ],
458
+ ...unknown,
459
+ };
460
+ }
461
+ // A question about the tool itself gets the command that answers it.
462
+ const tool = toolAnswer(t, env);
463
+ if (tool === 'list') {
464
+ const kind =
465
+ /\b(dials?|tokens?|parts?|groups?|properties|property)\b/i
466
+ .exec(t)?.[1]
467
+ ?.toLowerCase() ?? 'kinds';
468
+ return answer('', {...options, list: kind}, cwd);
469
+ }
470
+ if (tool)
471
+ return {
472
+ kind: 'question',
473
+ subject: t,
474
+ understood: {parts: [], aspects: []},
475
+ ...themeFields,
476
+ results: tool,
477
+ ...unknown,
478
+ };
313
479
  // a question about what something is gets the lookup, not a change.
314
480
  if (
315
- /^\s*(what|which|where)\b.*\b(variables?|tokens?|do|does|means?|controls?|for)\b|^\s*what('s| is) the (css )?(variable|token|property)/i.test(
481
+ (/^\s*(what|which|where)\b.*\b(variables?|tokens?|do|does|means?|controls?|for)\b|^\s*what('s| is) the (css )?(variable|token|property)/i.test(
316
482
  t,
317
- ) &&
483
+ ) ||
484
+ /^\s*(is there|are there|explain|what is|what's|what are)\b/i.test(t)) &&
318
485
  !/\b(command|make|makes|set|change)\b/i.test(t)
319
486
  ) {
320
487
  const tok = /--[a-z0-9-]+/i.exec(t)?.[0]?.toLowerCase();
321
488
  if (tok && Object.hasOwn(ctx.project.core.tokenDefaults, tok))
322
489
  return tokenAnswer(ctx, env, t, tok, unknown, themeFields);
490
+ // "what does spacing more do": the dial's own lookup, its values and
491
+ // what each does.
492
+ const dial = Object.keys(DIALS).find(d =>
493
+ new RegExp(`\\b${d}\\b`, 'i').test(t.replace(/--[a-z0-9-]+/gi, ' ')),
494
+ );
495
+ if (dial && !/\b(on|for)\s+(the\s+)?[a-z]+s?\b/i.test(t))
496
+ return {...(await answer(dial, options, cwd)), subject: t};
323
497
  const q = draftAnswer(ctx, env, t);
324
498
  const groups = q.aspects.filter(a => Object.hasOwn(GROUPS, a));
325
499
  const results = q.parts
@@ -345,6 +519,18 @@ async function answer(subject, options, cwd) {
345
519
  results,
346
520
  ...unknown,
347
521
  };
522
+ // "which token sets the page background?": the token the answer would
523
+ // set, looked up.
524
+ const token = q.parts.includes('page')
525
+ ? '--color-background-body'
526
+ : q.drafts
527
+ .flatMap(d => d.options.flat())
528
+ .find(st => st.thing.startsWith('--'))?.thing;
529
+ if (token && Object.hasOwn(ctx.project.core.tokenDefaults, token))
530
+ return {
531
+ ...tokenAnswer(ctx, env, token, token, unknown, themeFields),
532
+ subject: t,
533
+ };
348
534
  }
349
535
  const h = draftAnswer(ctx, env, t);
350
536
  const results = finish(env, h.drafts);
@@ -385,7 +571,7 @@ function finish(env, drafts) {
385
571
  const lookups = d.lookup ? [d.lookup] : [];
386
572
  if (!commands.length && d.options.length && !lookups.length) {
387
573
  out.push({
388
- text: `${d.text}: no command does it on ${env.slug}`,
574
+ text: `${d.text}: no command does it on ${env.slug}${refused[0] ? `: ${refused[0].why}` : ''}`,
389
575
  commands: [],
390
576
  refused,
391
577
  });
@@ -435,7 +621,7 @@ function lookupKey(t, ctx) {
435
621
  ctx.project.target.has(x) ||
436
622
  ASPECTS.includes(x) ||
437
623
  Object.hasOwn(DIALS, x) ||
438
- CSS_PROPERTIES.has(x) ||
624
+ cssProperties().has(x) ||
439
625
  x === 'colors' ||
440
626
  x === 'palette';
441
627
  if (known(k)) return k;
@@ -462,7 +648,24 @@ function partAnswer(ctx, env, subject, key, unknown, themeFields) {
462
648
  ctx.project.target.get(key)
463
649
  );
464
650
  const group = familyOf(key);
465
- const states = [...new Set([...target.states, ...COMMON_STATES])];
651
+ // Only the states set takes on this part (it refuses one that never
652
+ // applies there).
653
+ const states = [...new Set([...target.states, ...COMMON_STATES])].filter(
654
+ st => {
655
+ try {
656
+ checkSetting(ctx, env.slug, env.data, 'opacity', '1', {
657
+ on: key,
658
+ state: st,
659
+ });
660
+ return true;
661
+ } catch (e) {
662
+ return !(
663
+ /** @type {any} */ (e)?.code === 'ERR_THEME_NO_EFFECT' &&
664
+ /--state/.test(String(/** @type {any} */ (e)?.message))
665
+ );
666
+ }
667
+ },
668
+ );
466
669
  const reads = Object.fromEntries(
467
670
  Object.keys(GROUPS).map(g => [
468
671
  g,
@@ -728,6 +931,126 @@ function colorsAnswer(env, dialCommands) {
728
931
  ];
729
932
  }
730
933
 
934
+ /**
935
+ * The answer to a question about the tool itself: help, a list, how to see
936
+ * a change, or the difference between two things it names. 'list' means
937
+ * the caller lists the kind the question names.
938
+ * @param {string} t
939
+ * @param {import('./_how-commands.mjs').HowTheme} env
940
+ * @returns {Array<{text: string, commands: string[]}> | 'list' | null}
941
+ */
942
+ function toolAnswer(t, env) {
943
+ const q = t
944
+ .trim()
945
+ .toLowerCase()
946
+ .replace(/[?.!]+$/, '');
947
+ if (
948
+ /^(help|usage|\?|how does (this|it) work|what can (i|you) (ask|do))$/.test(
949
+ q,
950
+ )
951
+ )
952
+ return [
953
+ {
954
+ text: 'how answers a part, a setting, a plain-words question or a PNG picture with the commands that make the change; set makes it, show lists what a theme sets',
955
+ commands: [`${HOW} --help`, `${HOW} --list kinds`],
956
+ },
957
+ ];
958
+ if (
959
+ /^(list|show)( me)? (all|every|the)? ?(the )?(dials?|tokens?|parts?|groups?|properties)\b/.test(
960
+ q,
961
+ )
962
+ )
963
+ return 'list';
964
+ if (/\b(see|view|preview|check) (my |the )?(changes?|theme|edits?)\b/.test(q))
965
+ return [
966
+ {
967
+ text: `show lists what ${env.slug} sets; a preview page shows the theme in the app`,
968
+ commands: [
969
+ `${P} show ${env.slug}`,
970
+ `${PREVIEW} add --theme ${env.slug}`,
971
+ ],
972
+ },
973
+ ];
974
+ // Questions about the theme's files and life.
975
+ if (
976
+ /\b(use|import|apply|add|load) (this|the|my) theme (in|to|into) (my|the) app\b/.test(
977
+ q,
978
+ )
979
+ )
980
+ return [
981
+ {
982
+ text: `the theme is a module in themes/${env.slug}/; show names it and its files, and the theme docs say how an app loads a theme`,
983
+ commands: [`${P} show ${env.slug}`, 'astryx docs theme'],
984
+ },
985
+ ];
986
+ if (/\brename\b/.test(q))
987
+ return [
988
+ {
989
+ text: 'no command renames a theme: make a new one, set what you need on it, and remove the old folder',
990
+ commands: [
991
+ `${P} new ${env.slug}-2 --like ${env.data.like ?? 'none'}`,
992
+ `${P} show ${env.slug}`,
993
+ ],
994
+ },
995
+ ];
996
+ if (
997
+ /\b(what|which) (changed|did i change|have i changed)\b|\bwhat (is|does) (my|this|the) theme set\b/.test(
998
+ q,
999
+ )
1000
+ )
1001
+ return [
1002
+ {
1003
+ text: `show lists every setting ${env.slug} has, in the order they were made`,
1004
+ commands: [`${P} show ${env.slug}`],
1005
+ },
1006
+ ];
1007
+ if (/\b(second|another|new|other) theme\b/.test(q))
1008
+ return [
1009
+ {
1010
+ text: 'new makes a theme beside the ones you have; how and set take --theme to pick one',
1011
+ commands: [`${P} new ${env.slug}-2 --like ${env.data.like ?? 'none'}`],
1012
+ },
1013
+ ];
1014
+ if (/\b(version|which cli|what cli)\b/.test(q))
1015
+ return [{text: 'the CLI says its version', commands: ['astryx --version']}];
1016
+ if (/\bwhere (are|is|do) .*\b(stored|saved|kept|live|files?)\b/.test(q))
1017
+ return [
1018
+ {
1019
+ text: `everything is in themes/${env.slug}/: the settings file is the source, and the CSS and module are built from it`,
1020
+ commands: [`${P} show ${env.slug}`],
1021
+ },
1022
+ ];
1023
+ if (
1024
+ /\b(edit|change) (the )?(css|module|theme)?( files?)? by hand\b|\bhand[- ]edit/.test(
1025
+ q,
1026
+ )
1027
+ )
1028
+ return [
1029
+ {
1030
+ text: `the CSS and module in themes/${env.slug}/ are built from the settings file, so a hand edit is lost at the next set; make the change with set`,
1031
+ commands: [`${HOW} --help`],
1032
+ },
1033
+ ];
1034
+ const diff = /\bdifference between (.+?) and (.+)$/.exec(q);
1035
+ if (diff) {
1036
+ const props = cssProperties();
1037
+ return [diff[1], diff[2]].map(x => {
1038
+ const w = x.trim().replace(/^(the|a) /, '');
1039
+ return {
1040
+ text: Object.hasOwn(DIALS, w)
1041
+ ? `${w} is a dial: ${DIALS[w].help}`
1042
+ : props.has(w)
1043
+ ? `${w} is a CSS property: set it on one part with --on`
1044
+ : w.startsWith('--')
1045
+ ? `${w} is a token: one value the whole theme reads`
1046
+ : `what ${w} is`,
1047
+ commands: [`${HOW} ${w}`],
1048
+ };
1049
+ });
1050
+ }
1051
+ return null;
1052
+ }
1053
+
731
1054
  /**
732
1055
  * The tokens most parts read for one aspect, for a whole-theme change.
733
1056
  * @param {import('./_settings.mjs').Ctx} ctx
@@ -742,17 +1065,22 @@ function wholeThemeTokens(ctx, env, aspect) {
742
1065
  .sort((a, b) => C.anyReader(b).length - C.anyReader(a).length)
743
1066
  .slice(0, 6);
744
1067
  if (!toks.length) return [];
745
- const value = exampleForToken(
746
- C.typeOf(toks[0]),
747
- toks[0],
748
- env.base.light[toks[0]] ?? '',
749
- );
1068
+ // The example uses the most read token whose example changes what shows:
1069
+ // a fully round corner (9999px) scaled up stays fully round.
1070
+ /** @type {string[]} */
1071
+ let commands = [];
1072
+ for (const tok of toks) {
1073
+ const now = env.base.light[tok] ?? '';
1074
+ if (parseFloat(now) >= 999) continue;
1075
+ const value = exampleForToken(C.typeOf(tok), tok, now);
1076
+ if (!value) continue;
1077
+ commands = checked(env, [[{verb: 'set', thing: tok, value}]]).commands;
1078
+ if (commands.length) break;
1079
+ }
750
1080
  return [
751
1081
  {
752
1082
  text: `whole-theme tokens for ${aspect}, most used first: ${toks.map(k => `${k} (${C.anyReader(k).length} parts)`).join(', ')}`,
753
- commands: value
754
- ? checked(env, [[{verb: 'set', thing: toks[0], value}]]).commands
755
- : [`${HOW} ${toks[0]}`],
1083
+ commands: commands.length ? commands : [`${HOW} ${toks[0]}`],
756
1084
  },
757
1085
  ];
758
1086
  }
@@ -798,7 +1126,7 @@ async function listItems(kind, filter, cwd) {
798
1126
  .map(([name, d]) => ({
799
1127
  name,
800
1128
  values: d.values,
801
- help: d.help,
1129
+ help: dialHelp(name, env),
802
1130
  examples: d.examples
803
1131
  .map(exampleStep)
804
1132
  .filter(st => st != null)
@@ -824,7 +1152,7 @@ async function listItems(kind, filter, cwd) {
824
1152
  };
825
1153
  if (kind === 'properties') {
826
1154
  const props = filter
827
- ? [...CSS_PROPERTIES].filter(x => f(x)).slice(0, 60)
1155
+ ? [...cssProperties()].filter(x => f(x)).slice(0, 60)
828
1156
  : COMMON_PROPERTIES;
829
1157
  return {list: kind, items: props.map(name => ({name})), common: !filter};
830
1158
  }
@@ -852,6 +1180,37 @@ async function listItems(kind, filter, cwd) {
852
1180
  for (const s of x.states) if (!e.states.includes(s)) e.states.push(s);
853
1181
  byKey.set(x.key, e);
854
1182
  }
1183
+ // A filter no part name holds lists the closest names, never nothing.
1184
+ if (!byKey.size && filter) {
1185
+ const word = filter.toLowerCase().replace(/s$/, '');
1186
+ // The parts of components whose doc lists the word, else the names
1187
+ // nearest it.
1188
+ const owners = Object.entries(ctx.project.components)
1189
+ .filter(([, info]) =>
1190
+ (info.keywords ?? []).some(
1191
+ k => k.toLowerCase().replace(/s$/, '') === word,
1192
+ ),
1193
+ )
1194
+ .map(([name]) => name);
1195
+ const close = new Set(
1196
+ owners.length
1197
+ ? ctx.project.targets
1198
+ .filter(x => owners.includes(x.component))
1199
+ .map(x => x.key)
1200
+ : nearest(
1201
+ word,
1202
+ ctx.project.targets.map(x => x.key),
1203
+ 5,
1204
+ ),
1205
+ );
1206
+ for (const x of ctx.project.targets) {
1207
+ if (!close.has(x.key)) continue;
1208
+ const e = byKey.get(x.key) ?? {key: x.key, components: [], states: []};
1209
+ if (!e.components.includes(x.component)) e.components.push(x.component);
1210
+ for (const st of x.states) if (!e.states.includes(st)) e.states.push(st);
1211
+ byKey.set(x.key, e);
1212
+ }
1213
+ }
855
1214
  return {
856
1215
  list: kind,
857
1216
  items: [...byKey.values()].map(x => ({
@@ -904,6 +1263,7 @@ export function parsePoints(at) {
904
1263
  refuse(
905
1264
  E.ERR_INVALID_ARGUMENT,
906
1265
  `--at reads at most ${MAX_POINTS} points; it got ${points.length}.`,
1266
+ {run: [example]},
907
1267
  );
908
1268
  return points;
909
1269
  }
@@ -927,6 +1287,7 @@ function pictureColors(file, cwd, at, count) {
927
1287
  refuse(
928
1288
  E.ERR_INVALID_ARGUMENT,
929
1289
  'A count lists main colors; --at reads points. Give one of them.',
1290
+ {run: [`${HOW} ${quoteCommandArgument(file)} ${count}`]},
930
1291
  );
931
1292
  if (count != null && (!Number.isInteger(count) || count <= 0))
932
1293
  refuse(
@@ -947,6 +1308,7 @@ function pictureColors(file, cwd, at, count) {
947
1308
  refuse(
948
1309
  E.ERR_INVALID_ARGUMENT,
949
1310
  `${file} is a ${other[0]} picture; how reads PNG only. Save or convert it as PNG.`,
1311
+ {run: [`${HOW} --list`]},
950
1312
  );
951
1313
  /** @type {import('./_png.mjs').Picture} */
952
1314
  let pic;
@@ -955,7 +1317,7 @@ function pictureColors(file, cwd, at, count) {
955
1317
  } catch (e) {
956
1318
  throw new AstryxError(
957
1319
  `Could not read ${file} as a PNG picture: ${e instanceof Error ? e.message : String(e)}.`,
958
- [],
1320
+ [{name: `${HOW} --list`, reason: 'what how reads'}],
959
1321
  E.ERR_INVALID_ARGUMENT,
960
1322
  );
961
1323
  }
@@ -972,6 +1334,7 @@ function pictureColors(file, cwd, at, count) {
972
1334
  .join(
973
1335
  '; ',
974
1336
  )} ${outside.length > 1 ? 'are' : 'is'} outside the picture, which is ${pic.width}x${pic.height} (x from 0 to ${pic.width - 1}, y from 0 to ${pic.height - 1}).`,
1337
+ {run: [`${HOW} ${quoteCommandArgument(file)} --at 0,0`]},
975
1338
  );
976
1339
  return {
977
1340
  file,
@@ -981,11 +1344,19 @@ function pictureColors(file, cwd, at, count) {
981
1344
  points: colorsAt(pic, points),
982
1345
  };
983
1346
  }
1347
+ const colors = mainColors(pic, count ?? 14);
1348
+ // Every pixel see-through: no color shows, as with a 0-pixel picture.
1349
+ if (!colors.length)
1350
+ throw new AstryxError(
1351
+ `Could not read ${file} as a PNG picture: every pixel is fully see-through, so it has no visible colors.`,
1352
+ [{name: `${HOW} --list`, reason: 'what how reads'}],
1353
+ E.ERR_INVALID_ARGUMENT,
1354
+ );
984
1355
  return {
985
1356
  file,
986
1357
  width: pic.width,
987
1358
  height: pic.height,
988
- colors: mainColors(pic, count ?? 14),
1359
+ colors,
989
1360
  points: null,
990
1361
  };
991
1362
  }
@@ -14,14 +14,9 @@
14
14
  * @position api/theme-edit — imported by _preview.mjs
15
15
  */
16
16
 
17
- /** @typedef {import('./_catalog.mjs').Tree} Tree */
17
+ import {h} from './_catalog.mjs';
18
18
 
19
- /** @param {string} name @param {Record<string, unknown>} [props] @param {...unknown} children @returns {Tree} */
20
- const h = (name, props = {}, ...children) => ({
21
- __element: name,
22
- props,
23
- ...(children.length ? {children} : {}),
24
- });
19
+ /** @typedef {import('./_catalog.mjs').Tree} Tree */
25
20
 
26
21
  const noop = {__code: '() => {}'};
27
22
  const STATUSES = ['info', 'success', 'warning', 'error'];