@astryxdesign/cli 0.7.15 → 0.7.16-canary.g3aa244b

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 (163) hide show
  1. package/README.md +5 -3
  2. package/api/build/_adapter.d.mts +1 -0
  3. package/api/build/blocks/blocks.d.mts +1 -0
  4. package/api/build/blocks/blocks.mjs +18 -1
  5. package/api/component/_adapter.d.mts +1 -1
  6. package/api/component/_adapter.mjs +28 -1
  7. package/api/doctor/_adapter.d.mts +35 -0
  8. package/api/doctor/_adapter.mjs +69 -0
  9. package/api/doctor/built-checks.mjs +1 -1
  10. package/api/doctor/doctor.d.mts +18 -0
  11. package/api/doctor/doctor.doc.mjs +1 -1
  12. package/api/doctor/doctor.mjs +104 -4
  13. package/api/doctor/theme-checks.mjs +6 -10
  14. package/api/integration/add-contribution.mjs +3 -3
  15. package/api/integration/pack-check.mjs +14 -8
  16. package/api/integration/validate-integration.mjs +1 -1
  17. package/api/search/_adapter.mjs +15 -16
  18. package/api/search/_entries.d.mts +2 -1
  19. package/api/search/_entries.mjs +28 -1
  20. package/api/swizzle/_moduleGraph.mjs +1 -1
  21. package/api/theme/_adapter.d.mts +5 -2
  22. package/api/theme/_adapter.mjs +43 -12
  23. package/api/theme/_fork.mjs +1 -1
  24. package/api/theme/build/build.d.mts +116 -32
  25. package/api/theme/build/build.mjs +449 -102
  26. package/api/theme/eject/eject.mjs +22 -1
  27. package/api/theme/template/template.d.mts +19 -0
  28. package/api/theme/template/template.mjs +102 -25
  29. package/api/theme/theme.type.d.mts +5 -1
  30. package/api/theme/theme.type.mjs +2 -1
  31. package/api/theme/themeBuild.doc.mjs +3 -3
  32. package/api/theme/themeEject.doc.mjs +1 -1
  33. package/api/theme/themeTemplate.doc.mjs +9 -3
  34. package/api/theme-edit/_adapter.d.mts +32 -2
  35. package/api/theme-edit/_adapter.mjs +264 -40
  36. package/api/theme-edit/_check.d.mts +93 -4
  37. package/api/theme-edit/_check.mjs +1727 -223
  38. package/api/theme-edit/_color.d.mts +2 -8
  39. package/api/theme-edit/_color.mjs +292 -219
  40. package/api/theme-edit/_compiler.d.mts +1 -0
  41. package/api/theme-edit/_compiler.mjs +20 -1
  42. package/api/theme-edit/_context.d.mts +31 -1
  43. package/api/theme-edit/_context.mjs +445 -41
  44. package/api/theme-edit/_css.d.mts +60 -1
  45. package/api/theme-edit/_css.mjs +404 -28
  46. package/api/theme-edit/_edit.d.mts +25 -0
  47. package/api/theme-edit/_edit.mjs +1532 -149
  48. package/api/theme-edit/_how-commands.d.mts +11 -26
  49. package/api/theme-edit/_how-commands.mjs +30 -2
  50. package/api/theme-edit/_how-question.d.mts +7 -0
  51. package/api/theme-edit/_how-question.mjs +1304 -176
  52. package/api/theme-edit/_how.mjs +144 -30
  53. package/api/theme-edit/_overview.mjs +2 -0
  54. package/api/theme-edit/_palette.d.mts +38 -0
  55. package/api/theme-edit/_palette.mjs +305 -71
  56. package/api/theme-edit/_parts.d.mts +33 -0
  57. package/api/theme-edit/_parts.mjs +138 -9
  58. package/api/theme-edit/_png.d.mts +18 -0
  59. package/api/theme-edit/_png.mjs +95 -14
  60. package/api/theme-edit/_preview-app.d.mts +36 -1
  61. package/api/theme-edit/_preview-app.mjs +1415 -96
  62. package/api/theme-edit/_preview.d.mts +64 -3
  63. package/api/theme-edit/_preview.mjs +514 -31
  64. package/api/theme-edit/_project.d.mts +11 -0
  65. package/api/theme-edit/_project.mjs +46 -12
  66. package/api/theme-edit/_settings.d.mts +278 -5
  67. package/api/theme-edit/_settings.mjs +2741 -195
  68. package/api/theme-edit/_tables.d.mts +24 -0
  69. package/api/theme-edit/_tables.mjs +211 -149
  70. package/api/theme-edit/_vet.d.mts +42 -0
  71. package/api/theme-edit/_vet.mjs +144 -0
  72. package/api/theme-edit/theme-edit.type.d.mts +20 -2
  73. package/api/theme-edit/theme-edit.type.mjs +6 -2
  74. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  75. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  76. package/api/theme-edit/themeEditShow.doc.mjs +11 -3
  77. package/api/upgrade/registry/registry.mjs +6 -1
  78. package/assets/codemods/parse.mjs +2 -2
  79. package/assets/docs/tree/single-component.doc.mjs +11 -2
  80. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  81. package/assets/docs.generated.json +2 -2
  82. package/assets/preview-app/next.config.mjs +7 -1
  83. package/assets/preview-app/package.json +1 -0
  84. package/assets/preview-app/src/app/globals.css +1 -0
  85. package/assets/self-audit.generated.json +1 -1
  86. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
  87. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
  88. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
  89. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
  90. package/assets/templates/components.generated.json +1 -1
  91. package/assets/templates/pages/dashboard/page.tsx +1 -1
  92. package/authoring/doctypes/_schema.d.mts +52 -5
  93. package/authoring/doctypes/_schema.mjs +62 -7
  94. package/authoring/doctypes/base/type.ts +10 -0
  95. package/authoring/doctypes/component/component.doc.mjs +1 -1
  96. package/authoring/doctypes/function/function.doc.mjs +6 -0
  97. package/authoring/doctypes/function/type.ts +3 -0
  98. package/authoring/doctypes/legacy.mjs +5 -1
  99. package/authoring/index.d.ts +1 -0
  100. package/authoring/shadcn/source-variants.d.mts +1 -1
  101. package/authoring/shadcn/source-variants.mjs +32 -10
  102. package/clients/cli/build-id.generated.json +1 -1
  103. package/clients/cli/commands/doctor.doc.mjs +2 -2
  104. package/clients/cli/commands/experimental/theme.mjs +239 -45
  105. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  106. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
  107. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
  108. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +3 -3
  109. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  110. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  111. package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
  112. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  113. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  114. package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
  115. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  116. package/clients/cli/commands/theme-eject.doc.mjs +1 -1
  117. package/clients/cli/commands/theme-template.doc.mjs +3 -1
  118. package/clients/cli/commands/theme.mjs +190 -46
  119. package/clients/cli/formatters/index.mjs +7 -4
  120. package/clients/cli/lib/cli-error.mjs +9 -3
  121. package/clients/cli/lib/component-format.mjs +27 -9
  122. package/clients/cli/lib/json-shim.mjs +72 -2
  123. package/clients/cli/manifest.generated.json +1 -1
  124. package/clients/cli/run.mjs +49 -0
  125. package/foundation/agent-docs/agent-docs-target.d.mts +2 -6
  126. package/foundation/agent-docs/agent-docs-target.mjs +9 -17
  127. package/foundation/agent-docs/agent-docs.mjs +3 -2
  128. package/foundation/config/config-writer.mjs +2 -2
  129. package/foundation/config/project.mjs +60 -14
  130. package/foundation/discovery/component-discovery.mjs +5 -17
  131. package/foundation/discovery/icon-set-writer.mjs +1 -1
  132. package/foundation/discovery/module-exports.mjs +1 -15
  133. package/foundation/discovery/template-adapter.mjs +44 -19
  134. package/foundation/discovery/template-source-tree.mjs +3 -16
  135. package/foundation/discovery/theme-discovery.d.mts +5 -1
  136. package/foundation/discovery/theme-discovery.mjs +61 -43
  137. package/foundation/fs/exact-codec.d.mts +35 -0
  138. package/foundation/fs/exact-codec.mjs +148 -0
  139. package/foundation/fs/gather-cache.d.mts +15 -5
  140. package/foundation/fs/gather-cache.mjs +129 -31
  141. package/foundation/fs/paths.d.mts +39 -0
  142. package/foundation/fs/paths.mjs +44 -11
  143. package/foundation/fs/read-record.mjs +11 -1
  144. package/foundation/integrations/contribution-fixes.mjs +1 -16
  145. package/foundation/integrations/may-have-integrations.mjs +3 -2
  146. package/foundation/integrations/public-imports.mjs +1 -1
  147. package/foundation/render/embedded-imports.mjs +1 -1
  148. package/foundation/render/host-exit.d.mts +8 -0
  149. package/foundation/render/host-exit.mjs +11 -0
  150. package/foundation/render/page-host.mjs +56 -10
  151. package/foundation/render/page-worker.mjs +14 -0
  152. package/foundation/render/render-page.mjs +37 -2
  153. package/foundation/response/error-codes.d.mts +2 -1
  154. package/foundation/response/error-codes.d.ts +1 -0
  155. package/foundation/response/error-codes.doc.mjs +5 -0
  156. package/foundation/response/error-codes.mjs +3 -0
  157. package/foundation/response/json.d.mts +15 -0
  158. package/foundation/response/json.mjs +52 -1
  159. package/foundation/response/response-types.doc.mjs +1 -1
  160. package/foundation/runtime/lazy-dependencies.d.mts +14 -0
  161. package/foundation/runtime/lazy-dependencies.mjs +82 -0
  162. package/foundation/xle/browser.d.mts +2 -2
  163. package/package.json +7 -6
@@ -31,6 +31,8 @@
31
31
  * @position api/theme-edit — adapter for api/theme-edit/theme-edit.mjs
32
32
  */
33
33
 
34
+ import {writeThemeTemplate} from '../theme/template/template.mjs';
35
+ import {buildSuggestion} from '../theme/build/build.mjs';
34
36
  import {createHash} from 'node:crypto';
35
37
  import * as fs from 'node:fs';
36
38
  import * as path from 'node:path';
@@ -39,10 +41,8 @@ import {themeCacheRoot} from './_project.mjs';
39
41
  import * as preview from './_preview-app.mjs';
40
42
  import {AstryxError} from '../error.mjs';
41
43
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
42
- import {
43
- findAstryxProject,
44
- findPackageRoot,
45
- } from '../../foundation/fs/paths.mjs';
44
+ import {findPackageRoot} from '../../foundation/fs/paths.mjs';
45
+ import {coreApp} from './_context.mjs';
46
46
  import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
47
47
  import {withFolderLock} from '../../foundation/release/folder-lock.mjs';
48
48
  import {
@@ -50,10 +50,22 @@ import {
50
50
  quoteCommandArgument,
51
51
  } from '../../foundation/env/package-manager.mjs';
52
52
  import {LIKE, P} from './_tables.mjs';
53
- import {camel} from './_settings.mjs';
53
+ import {setLine} from './_check.mjs';
54
+ import {
55
+ SHOWCASE_GROUPS,
56
+ takeFirstAppCopy,
57
+ writeAppCopy,
58
+ writeAppCopyAt,
59
+ } from './_preview.mjs';
60
+ import {humanWarn} from '../../foundation/response/json.mjs';
61
+ import {folderIsEmpty, setAfterBuild, typedThemeName} from './_settings.mjs';
62
+
63
+ // Every build of a theme writes its app copy (src/themes/<theme>/).
64
+ setAfterBuild(writeAppCopy);
54
65
  import {LOCAL_THEME_ROOT} from '../../foundation/config/theme-state.mjs';
55
66
 
56
67
  export {parsePoints} from './_how.mjs';
68
+ export {newFlagList} from './_edit.mjs';
57
69
  import {themeEditHow as howAt} from './_how.mjs';
58
70
 
59
71
  /**
@@ -90,6 +102,11 @@ export async function themeEditHow(subject, options = {}) {
90
102
  /** The built-in themes a theme can build on (`--like`). */
91
103
  export const builtInThemes = () => [...LIKE];
92
104
 
105
+ /** The sections `show --section` takes. */
106
+ export const showSections = () => [...SHOWCASE_GROUPS];
107
+
108
+ export {dialValueFits} from './_settings.mjs';
109
+
93
110
  /**
94
111
  * The project a command acts on: the Astryx project at or above `cwd`, found
95
112
  * as `upgrade` finds it (the nearest package that declares an Astryx package
@@ -102,7 +119,9 @@ export const builtInThemes = () => [...LIKE];
102
119
  */
103
120
  export function projectRoot(cwd) {
104
121
  const start = path.resolve(cwd);
105
- const project = findAstryxProject(start);
122
+ // One rule: the nearest folder at or above cwd whose package.json lists
123
+ // @astryxdesign/core.
124
+ const project = coreApp(start);
106
125
  const pkg = findPackageRoot(start);
107
126
  const inReach = (/** @type {string} */ dir) =>
108
127
  project ? !path.relative(project, dir).startsWith('..') : true;
@@ -112,13 +131,19 @@ export function projectRoot(cwd) {
112
131
  let json;
113
132
  try {
114
133
  json = JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, ''));
115
- } catch {
134
+ } catch (e) {
135
+ // Name the file and what the parser says is wrong, with its place.
136
+ const rel = path.relative(start, file) || 'package.json';
137
+ const why = String(/** @type {Error} */ (e).message ?? '').replace(
138
+ /^Unexpected token.*?, /,
139
+ '',
140
+ );
116
141
  throw new AstryxError(
117
- `${path.relative(start, file) || 'package.json'} is not valid JSON, so the app it belongs to is unknown. Fix it, then run the command again. Nothing was written.`,
142
+ `${rel} is not valid JSON (${why}), so the app it belongs to is unknown. Fix it, then run the command again. Nothing was written.`,
118
143
  [
119
144
  {
120
- name: runLine(start, 'doctor'),
121
- reason: 'names the file and what is wrong in it',
145
+ name: `\${EDITOR:-vi} ${quoteCommandArgument(rel)}`,
146
+ reason: 'open the file and fix it',
122
147
  },
123
148
  ],
124
149
  ERROR_CODES.ERR_PROJECT_REQUIRED,
@@ -195,9 +220,15 @@ function lockDir(root) {
195
220
  * @param {boolean} [bestEffort] a command that can run read-only runs
196
221
  * without the lock when it cannot be taken (a read-only node_modules),
197
222
  * told so, and then writes nothing
223
+ * @param {string | null} [again] the command's own words after the CLI
224
+ * name, to suggest running it again (never the host process's argv: an
225
+ * API caller is not a CLI run)
198
226
  * @returns {Promise<T>}
199
227
  */
200
- async function withLock(root, name, fn, bestEffort = false) {
228
+ async function withLock(root, name, fn, bestEffort = false, again = null) {
229
+ // A preview command, which holds the preview lock, suggests the list of
230
+ // previews (what the other command may be changing).
231
+ again ??= name === 'preview' ? 'experimental theme preview list' : null;
201
232
  /** @type {string | null} */
202
233
  let dir;
203
234
  try {
@@ -239,16 +270,17 @@ async function withLock(root, name, fn, bestEffort = false) {
239
270
  {
240
271
  onBusy: (o, held) => {
241
272
  throw new AstryxError(
242
- `Another command has been changing ${name.replace(/^theme-/, '')} for 30 seconds${o ? ` (process ${o.pid} on ${o.host}${held != null ? `, holding it ${held} s` : ''})` : ''}. Nothing was changed; run this command again. If no astryx command is running, the lock is left from one that stopped: remove the folder ${lock}.`,
243
- // A look that takes no lock: the last build as it is.
244
- [
245
- {
246
- name: name.startsWith('theme-')
247
- ? `${P} show ${name.replace(/^theme-/, '')}`
248
- : 'astryx experimental theme preview list',
249
- reason: 'see it as it is now',
250
- },
251
- ],
273
+ `Another command has been changing ${name.replace(/^theme-/, '')} for 30 seconds${o ? ` (process ${o.pid} on ${o.host}${held != null ? `, holding it ${held} s` : ''})` : ''}. Nothing was changed; run this command again once the other one ends. If no astryx command is running, the lock is left from one that stopped: remove the folder ${lock}.`,
274
+ // Every editor command (show too) takes this lock, so none of
275
+ // them works meanwhile: this same command, once the other ends.
276
+ again
277
+ ? [
278
+ {
279
+ name: runLine(root, again),
280
+ reason: 'run it again once the other command ends',
281
+ },
282
+ ]
283
+ : [],
252
284
  ERROR_CODES.ERR_THEME_BUSY,
253
285
  );
254
286
  },
@@ -346,9 +378,11 @@ function absolute(result, root, from) {
346
378
  * @param {O} options
347
379
  * @param {string | null} lock
348
380
  * @param {(o: O & {cwd: string}) => Promise<T>} fn
381
+ * @param {boolean} [bestEffort]
382
+ * @param {string | null} [again] the command's own words, for a busy lock
349
383
  * @returns {Promise<T>}
350
384
  */
351
- async function inProject(options, lock, fn, bestEffort = false) {
385
+ async function inProject(options, lock, fn, bestEffort = false, again = null) {
352
386
  const from = options.cwd ?? process.cwd();
353
387
  const o = atRoot(options);
354
388
  try {
@@ -360,6 +394,7 @@ async function inProject(options, lock, fn, bestEffort = false) {
360
394
  lock,
361
395
  locked => fn(locked ? o : {...o, readOnly: true}),
362
396
  bestEffort,
397
+ again,
363
398
  )
364
399
  : await fn(o);
365
400
  return absolute(r, o.cwd, from);
@@ -434,20 +469,74 @@ const withThemeLock = o => ({
434
469
  ) => withLock(o.cwd, lockName(slug), fn),
435
470
  });
436
471
 
472
+ /**
473
+ * A command's own words after the CLI name, from what it was called with,
474
+ * every option kept: set and undo as `set` writes them (scope flags and
475
+ * --only), new with --like and each dial, --png where given.
476
+ * @param {string} line a command as the editor writes one (`astryx …`)
477
+ * @param {{png?: boolean}} [o]
478
+ */
479
+ const words = (line, o = {}) =>
480
+ `${line.replace(/^astryx /, '').trimEnd()}${o.png ? ' --png' : ''}`;
481
+
437
482
  /** @type {typeof edit.themeEditNew} */
438
483
  export const themeEditNew = (name, options = {}) =>
439
- inProject(options, lockName(name), o => edit.themeEditNew(name, o));
484
+ inProject(
485
+ options,
486
+ lockName(name),
487
+ o => edit.themeEditNew(name, o),
488
+ false,
489
+ words(
490
+ `${P} new ${quoteCommandArgument(name)} ${edit
491
+ .newFlagList(
492
+ options.like,
493
+ options.settings ?? {},
494
+ /** @type {boolean} */ (options.png),
495
+ )
496
+ .join(' ')}`,
497
+ ),
498
+ );
440
499
  /** @type {typeof edit.themeEditSet} */
441
500
  export const themeEditSet = (theme, thing, value, options = {}) =>
442
- inProject(options, lockName(theme), o =>
443
- edit.themeEditSet(theme, thing, value, o),
501
+ inProject(
502
+ options,
503
+ lockName(theme),
504
+ o => edit.themeEditSet(theme, thing, value, o),
505
+ false,
506
+ words(setLine(theme, thing, value, options), options),
444
507
  );
445
508
  /** @type {typeof edit.themeEditUndo} */
446
509
  export const themeEditUndo = (theme, options = {}) =>
447
- inProject(options, lockName(theme), o => edit.themeEditUndo(theme, o));
510
+ inProject(
511
+ options,
512
+ lockName(theme),
513
+ o => edit.themeEditUndo(theme, o),
514
+ false,
515
+ words(
516
+ options.thing
517
+ ? setLine(
518
+ theme,
519
+ options.thing,
520
+ /** @type {string} */ (options.value ?? ''),
521
+ options,
522
+ true,
523
+ )
524
+ : `${P} undo ${theme}`,
525
+ options,
526
+ ),
527
+ );
448
528
  /** @type {typeof edit.themeEditShow} */
449
529
  export const themeEditShow = (theme, options = {}) =>
450
- inProject(options, lockName(theme), o => edit.themeEditShow(theme, o), true);
530
+ inProject(
531
+ options,
532
+ lockName(theme),
533
+ o => edit.themeEditShow(theme, o),
534
+ true,
535
+ words(
536
+ `${P} show ${theme}${options.section ? ` --section ${quoteCommandArgument(String(options.section))}` : ''}`,
537
+ options,
538
+ ),
539
+ );
451
540
  /** @type {typeof preview.themeEditPreviewAdd} */
452
541
  export const themeEditPreviewAdd = (description, options = {}) =>
453
542
  inProject(options, 'preview', o =>
@@ -577,20 +666,45 @@ export function editorThemeRefusal(err, cwd) {
577
666
  )
578
667
  return null;
579
668
  const root = projectRoot(cwd);
580
- const named = /"([a-z][a-z0-9-]*)"|'([a-z][a-z0-9-]*)'/.exec(err.message);
581
- const slug = named ? editorThemeOf(root, named[1] ?? named[2]) : null;
669
+ // The name as typed, read the way the editor reads a theme name: a path
670
+ // to its folder or a file in it, in any case, names the theme.
671
+ const named = /"([^"]+)"|'([^']+)'/.exec(err.message);
672
+ const word = named ? typedThemeName(named[1] ?? named[2]) : '';
673
+ const slug = word ? editorThemeOf(root, word) : null;
582
674
  if (!slug) return null;
583
675
  // A local theme of that name (a fork in the app's own themes folder) is
584
676
  // one the stable commands take: their own message stands.
585
- if (fs.existsSync(path.join(root, LOCAL_THEME_ROOT, slug))) return null;
586
- const id = `${camel(slug)}Theme`;
587
- const key = /^[a-z][a-z0-9]*$/i.test(slug) ? slug : JSON.stringify(slug);
677
+ // A folder of only system files (or empty) holds no theme: as absent.
678
+ if (!folderIsEmpty(path.join(root, LOCAL_THEME_ROOT, slug))) return null;
679
+ // No app copy yet (a theme made before the editor wrote one, or the
680
+ // copy removed): the next build writes it, then the same steps every
681
+ // place gives (`wiring` of new and show).
682
+ // A one-mode theme's mode is a step too, as in `wiring`.
683
+ /** @type {'light' | 'dark' | 'system'} */
684
+ let mode = 'system';
685
+ try {
686
+ const m = JSON.parse(
687
+ fs.readFileSync(
688
+ path.join(root, 'themes', slug, `${slug}.settings.json`),
689
+ 'utf8',
690
+ ),
691
+ ).mode;
692
+ if (m === 'light-only') mode = 'light';
693
+ else if (m === 'dark-only') mode = 'dark';
694
+ } catch {
695
+ // Settings that do not read: both modes.
696
+ }
697
+ const steps = preview.addWiring(root, slug, mode);
588
698
  return new AstryxError(
589
- `${slug} is a theme the editor made (themes/${slug}/), not a theme package, so list, add, use, remove and eject do not take it. To use it, import its module and its stylesheet in a file of your own (import {${id}} from './themes/${slug}/${slug}.js'; import './themes/${slug}/${slug}.css';) and merge it into the themes there ({...themes, ${key}: ${id}}); do not add it to src/astryx-themes.ts, which add, use and remove write again. Change it with the editor.`,
699
+ `${slug} is a theme the editor made (themes/${slug}/), and it has no app copy yet: list, add, use, remove and eject take the copy every build of it writes in src/themes/${slug}/, a standard local theme. Build it once, then: ${steps.join('; ')}.`,
590
700
  [
591
701
  {
592
702
  name: runLine(cwd, `experimental theme editor show ${slug}`),
593
- reason: 'see the theme',
703
+ reason: `builds it and writes its app copy, src/themes/${slug}/`,
704
+ },
705
+ {
706
+ name: runLine(cwd, `theme add ${slug}`),
707
+ reason: 'then adds it to the app',
594
708
  },
595
709
  ],
596
710
  ERROR_CODES.ERR_UNKNOWN_THEME,
@@ -603,24 +717,62 @@ export function editorThemeRefusal(err, cwd) {
603
717
  * take an editor theme, and `--check` checks an editor theme by the editor's
604
718
  * own rules (waiting for a change in progress).
605
719
  * @param {string[]} files
606
- * @param {{cwd: string, check?: boolean, family?: boolean}} options
720
+ * @param {{cwd: string, check?: boolean, family?: boolean, iconsSpecifier?: string, out?: string}} options
721
+ * `check`, `out` and `iconsSpecifier` are kept in every compile a refusal
722
+ * suggests
607
723
  * @returns {Promise<AstryxError | null>}
608
724
  */
609
- export async function editorCompileProblem(files, {cwd, check, family}) {
725
+ export async function editorCompileProblem(
726
+ files,
727
+ {cwd, check, family, iconsSpecifier, out},
728
+ ) {
610
729
  const cwdRoot = projectRoot(cwd);
730
+ const COMPILE = {group: 'experimental theme', build: 'compile'};
731
+ /**
732
+ * The compile of `source` (from `from`) with the caller's mode: a check
733
+ * stays a check, and --out names the same file from there.
734
+ * @param {string} source @param {string} from
735
+ */
736
+ const compileLine = (source, from) =>
737
+ buildSuggestion(
738
+ source,
739
+ {
740
+ check,
741
+ iconsSpecifier,
742
+ out: out
743
+ ? path.relative(from, path.resolve(cwd, out)) || out
744
+ : undefined,
745
+ },
746
+ from,
747
+ COMPILE,
748
+ );
611
749
  for (const file of files) {
612
750
  const at = editorThemeAt(cwdRoot, path.resolve(cwd, file));
613
751
  if (!at || !editorOwnFile(at.slug, file)) continue;
614
752
  const {root, slug} = at;
615
753
  const source = `themes/${slug}/${slug}.theme.ts`;
754
+ // An editor theme is built from its project's root, as every editor
755
+ // command runs there: from a subfolder the build would write outside
756
+ // its working folder. The run names the root.
757
+ if (path.resolve(cwd) !== path.resolve(root))
758
+ return new AstryxError(
759
+ `${slug} is a theme the editor made; compile it from the app root (${path.relative(cwd, root) || '.'}), where the editor builds it.`,
760
+ [
761
+ {
762
+ name: `cd ${quoteCommandArgument(path.relative(cwd, root) || '.')} && ${compileLine(source, root)}`,
763
+ reason: 'do this instead',
764
+ },
765
+ ],
766
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
767
+ );
616
768
  if (/\.settings\.(ts|json)$/.test(file))
617
769
  return new AstryxError(
618
770
  `${file} is the editor's own settings for ${slug}, not a theme source; compile the theme source.`,
619
771
  [
620
772
  {
621
- name: runLine(
773
+ name: compileLine(
774
+ path.relative(cwd, path.join(root, source)) || source,
622
775
  cwd,
623
- `experimental theme compile ${quoteCommandArgument(path.relative(cwd, path.join(root, source)) || source)}`,
624
776
  ),
625
777
  reason: 'do this instead',
626
778
  },
@@ -632,9 +784,9 @@ export async function editorCompileProblem(files, {cwd, check, family}) {
632
784
  `${slug} is a theme the editor made; --family builds package theme families, not editor themes. Compile it on its own.`,
633
785
  [
634
786
  {
635
- name: runLine(
787
+ name: compileLine(
788
+ path.relative(cwd, path.join(root, source)) || source,
636
789
  cwd,
637
- `experimental theme compile ${quoteCommandArgument(path.relative(cwd, path.join(root, source)) || source)}`,
638
790
  ),
639
791
  reason: 'do this instead',
640
792
  },
@@ -661,6 +813,28 @@ export async function editorCompileProblem(files, {cwd, check, family}) {
661
813
  if (e instanceof AstryxError) return e;
662
814
  throw e;
663
815
  }
816
+ // An own change to the theme source is what compile builds (and what
817
+ // --check compares): never a reason to refuse it.
818
+ if (
819
+ why &&
820
+ /\.theme\.ts (or a module it imports )?changed since the last build$/.test(
821
+ why,
822
+ )
823
+ )
824
+ why = null;
825
+ // A missing built output is one compile writes itself.
826
+ if (
827
+ why &&
828
+ !check &&
829
+ /^[^/]+\.(css|js|d\.ts|css\.d\.ts) was missing$/.test(why)
830
+ )
831
+ why = null;
832
+ // Saved settings the editor no longer accepts: show refuses them too,
833
+ // so the refusal names the undo that removes each.
834
+ if (why) {
835
+ const stored = await edit.editorStoredRefusal(root, slug);
836
+ if (stored) return stored;
837
+ }
664
838
  if (why && !check)
665
839
  return new AstryxError(
666
840
  `${slug}'s generated settings do not match its settings (${why}), so compile would build the old ones. The editor builds it from its settings.`,
@@ -683,6 +857,13 @@ export async function editorCompileProblem(files, {cwd, check, family}) {
683
857
  ],
684
858
  ERROR_CODES.ERR_THEME_INVALID,
685
859
  );
860
+ // A [light, dark] pair on a token that is not a color, however the
861
+ // file writes it: what the theme builds now is read (never written
862
+ // beside it), as the editor's own build reads it.
863
+ if (path.basename(file) === `${slug}.theme.ts`) {
864
+ const pairs = await edit.editorPairRefusal(root, slug);
865
+ if (pairs) return pairs;
866
+ }
686
867
  }
687
868
  }
688
869
  return null;
@@ -750,9 +931,52 @@ export async function editorThemeHold(files, {cwd}) {
750
931
  throw err;
751
932
  }
752
933
  releases.push(async () => {
934
+ // A compile that wrote the build refreshes the app's copy too
935
+ // (src/themes/<theme>/), under the same lock; a check writes nothing.
936
+ if (!process.argv.includes('--check')) {
937
+ try {
938
+ writeAppCopyAt(root, slug, null);
939
+ // The first write of the app copy is named once (the compile's
940
+ // own JSON envelope is the stable command's).
941
+ const wrote = takeFirstAppCopy(root, slug);
942
+ if (wrote)
943
+ humanWarn(
944
+ `wrote ${slug}'s app copy, a local theme \`theme add ${slug}\` takes, written again after every build: ${wrote.join(', ')}`,
945
+ );
946
+ } catch {
947
+ // A theme that does not load keeps its copy as it was.
948
+ }
949
+ }
753
950
  release();
754
951
  await done;
755
952
  });
756
953
  }
757
954
  return releaseAll;
758
955
  }
956
+
957
+ /**
958
+ * For `compile` of a file that is not there: when it is an editor theme's
959
+ * own source (`themes/<t>/<t>.theme.ts` beside its settings), the command
960
+ * that writes it again; null otherwise.
961
+ * @param {string} file the path as given
962
+ * @param {string} cwd
963
+ * @returns {{name: string, reason: string} | null}
964
+ */
965
+ export function editorMissingSource(file, cwd) {
966
+ const at = editorThemeAt(projectRoot(cwd), path.resolve(cwd, file));
967
+ if (!at || path.basename(file) !== `${at.slug}.theme.ts`) return null;
968
+ return {
969
+ name: runLine(cwd, `experimental theme editor show ${at.slug}`),
970
+ reason: `the editor writes ${at.slug}.theme.ts again from its settings`,
971
+ };
972
+ }
973
+
974
+ /**
975
+ * `theme template` for the experimental command: in a folder the theme
976
+ * editor made, only the editor's own files are protected.
977
+ * @param {{targetPath?: string, overwrite?: boolean, cwd?: string}} options
978
+ * @returns {import('../theme/theme.type.mjs').ThemeTemplateResponse}
979
+ */
980
+ export function editorThemeTemplate(options) {
981
+ return writeThemeTemplate(options, true);
982
+ }
@@ -1,6 +1,27 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * A value pasted as a CSS declaration (`color: #e11d48;`, `font-weight: 700
6
+ * !important`), from devtools or a stylesheet: its property and value, with
7
+ * the `;` and `!important` gone. Null when the value is not a declaration (a
8
+ * URL's `https:` is not a property).
9
+ * @param {string} v
10
+ * @returns {{property: string, value: string} | null}
11
+ */
12
+ export function pastedDeclaration(v: string): {
13
+ property: string;
14
+ value: string;
15
+ } | null;
16
+ /**
17
+ * A font pasted as a declaration (`font-family: Georgia, serif;`, from
18
+ * devtools or a stylesheet), as the family list it names; a `font:`
19
+ * shorthand gives its family; '' when it names the property and no value.
20
+ * Null when the value is not a pasted declaration.
21
+ * @param {string} v
22
+ * @returns {string | null}
23
+ */
24
+ export function pastedFont(v: string): string | null;
4
25
  /**
5
26
  * @typedef {object} SetFlags
6
27
  * @property {string} [on]
@@ -16,13 +37,20 @@
16
37
  * @param {import('./_settings.mjs').Ctx} ctx
17
38
  * @param {string} slug
18
39
  * @param {import('./_settings.mjs').ThemeData} data
19
- * @param {string} [skip]
20
- * @returns {Array<{setting: import('./_settings.mjs').Setting, why: string, scope?: boolean}>} every saved setting the editor no longer accepts
40
+ * @param {string | {thing: string, on?: string, when?: string, state?: string, mode?: string}} [skip]
41
+ * @returns {Array<{setting: import('./_settings.mjs').Setting, why: string, scope?: boolean, fix?: string}>} every saved setting the editor no longer accepts (`fix`: the clean value to set, when one reads)
21
42
  */
22
- export function storedProblems(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData, skip?: string): Array<{
43
+ export function storedProblems(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData, skip?: string | {
44
+ thing: string;
45
+ on?: string;
46
+ when?: string;
47
+ state?: string;
48
+ mode?: string;
49
+ }): Array<{
23
50
  setting: import("./_settings.mjs").Setting;
24
51
  why: string;
25
52
  scope?: boolean;
53
+ fix?: string;
26
54
  }>;
27
55
  /**
28
56
  * A value of a type to put in a suggestion, so a suggested command runs.
@@ -44,7 +72,66 @@ export function exampleOf(type: string, name: string): string;
44
72
  * @returns {import('./_settings.mjs').Setting}
45
73
  */
46
74
  export function checkSetting(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData, thing: string, value: string | undefined, flags: SetFlags, unset?: boolean): import("./_settings.mjs").Setting;
47
- export { lengthPx };
75
+ /**
76
+ * A setting's value as set reads it: one line, and tabs as spaces; in a font
77
+ * value every run of spaces or tabs is one space, so `'Open Sans'` and
78
+ * `'Open\tSans'` both name Open Sans.
79
+ * @param {string} thing
80
+ * @param {string} value
81
+ */
82
+ export function normalValue(thing: string, value: string): string;
83
+ /**
84
+ * The first var() in a value that names no design token and would read
85
+ * nothing (no fallback), or one a letter or two off a token, else null.
86
+ * Dials take their own words, so a dial's var() with no near token passes.
87
+ * @param {string} v
88
+ * @param {Record<string, unknown>} TOKENS
89
+ * @param {string} thing
90
+ * @returns {{message: string, near: string[], close: boolean, fixed?: string} | null}
91
+ */
92
+ export function unknownVarRef(v: string, TOKENS: Record<string, unknown>, thing: string): {
93
+ message: string;
94
+ near: string[];
95
+ close: boolean;
96
+ fixed?: string;
97
+ } | null;
98
+ /**
99
+ * Why a font value names a font file or a link rather than a family
100
+ * (`./fonts/My.woff2`, `Inter.ttf`, `https://fonts.googleapis.com/…`,
101
+ * `url(…)`), or null. A theme names families; a file is loaded with
102
+ * @font-face or a font package.
103
+ * @param {string} value
104
+ * @returns {string | null}
105
+ */
106
+ export function fontFileReason(value: string): string | null;
107
+ /**
108
+ * A value with every Unicode space (no-break, thin, ideographic…) as a plain
109
+ * space and zero-width and format characters dropped, for every value type:
110
+ * the browser reads only a plain space as one.
111
+ * @param {string} v
112
+ */
113
+ export function normalValueText(v: string): string;
114
+ /**
115
+ * The thing and value a setting was typed as, put right before any check: a
116
+ * declaration pasted whole or split (`accent: #e11d48`, `--color-accent=red`,
117
+ * `font:inter`, `accent:` with the value next), a token typed with an em or
118
+ * en dash (`—color-accent`) or as `var(--color-accent)`, and the value's
119
+ * Unicode spaces. A thing it cannot read is left as typed.
120
+ * @param {string} thing
121
+ * @param {string | undefined} value
122
+ * @returns {{thing: string, value: string | undefined}}
123
+ */
124
+ export function normalizeEntry(thing: string, value: string | undefined): {
125
+ thing: string;
126
+ value: string | undefined;
127
+ };
128
+ export function setLine(slug: string, thing: string, value: string, s: {
129
+ on?: string;
130
+ when?: string;
131
+ state?: string;
132
+ mode?: string;
133
+ only?: boolean;
134
+ }, unset?: boolean): string;
48
135
  /** The aspects `how` answers at the whole-theme level. */
49
136
  export const ASPECTS: string[];
50
137
  export type SetFlags = {
@@ -55,3 +142,5 @@ export type SetFlags = {
55
142
  only?: boolean | undefined;
56
143
  };
57
144
  import { lengthPx } from './_settings.mjs';
145
+ import { familySpaces } from './_settings.mjs';
146
+ export { lengthPx, familySpaces };