@astryxdesign/cli 0.7.16 → 0.7.17-canary.g9a957aa

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 (229) hide show
  1. package/README.md +12 -23
  2. package/api/build/_adapter.d.mts +5 -0
  3. package/api/build/_adapter.mjs +49 -34
  4. package/api/build/blocks/blocks.d.mts +7 -5
  5. package/api/build/blocks/blocks.mjs +113 -26
  6. package/api/build/build.doc.mjs +2 -1
  7. package/api/build/kit/rank.mjs +47 -9
  8. package/api/build/kit/weights.d.mts +16 -3
  9. package/api/build/kit/weights.json +1 -1
  10. package/api/build/kit/weights.mjs +238 -31
  11. package/api/build/kit/word-model.d.mts +23 -0
  12. package/api/build/kit/word-model.mjs +46 -0
  13. package/api/build/kit/words.d.mts +32 -0
  14. package/api/build/kit/words.mjs +49 -1
  15. package/api/component/__fixtures__/resolutions/modules.txt +4 -5
  16. package/api/component/list/list.d.mts +1 -1
  17. package/api/component/list/list.mjs +48 -5
  18. package/api/discover/_adapter.d.mts +1 -1
  19. package/api/docs/_adapter.d.mts +26 -2
  20. package/api/docs/_adapter.mjs +217 -5
  21. package/api/docs/docs.d.mts +3 -0
  22. package/api/docs/docs.doc.mjs +7 -1
  23. package/api/docs/docs.mjs +12 -0
  24. package/api/docs/docs.type.d.mts +5 -0
  25. package/api/docs/docs.type.mjs +2 -0
  26. package/api/docs/node/node.mjs +1 -1
  27. package/api/doctor/_adapter.d.mts +27 -5
  28. package/api/doctor/_adapter.mjs +77 -6
  29. package/api/doctor/built-checks.mjs +38 -13
  30. package/api/doctor/doctor.d.mts +4 -3
  31. package/api/doctor/doctor.mjs +14 -7
  32. package/api/doctor/theme-checks.mjs +121 -17
  33. package/api/render/_adapter.mjs +491 -186
  34. package/api/render/render.doc.mjs +10 -3
  35. package/api/render/render.type.d.mts +30 -0
  36. package/api/render/render.type.mjs +19 -0
  37. package/api/search/ORDERING.md +1 -1
  38. package/api/search/_candidate-score.mjs +51 -32
  39. package/api/search/_fit-order.mjs +3 -3
  40. package/api/search/_result.d.mts +5 -5
  41. package/api/search/_score.d.mts +6 -1
  42. package/api/search/_score.mjs +15 -3
  43. package/api/search/search.d.mts +1 -1
  44. package/api/theme/_adapter.mjs +10 -0
  45. package/api/theme/build/build.d.mts +38 -0
  46. package/api/theme/build/build.mjs +144 -24
  47. package/api/theme/theme.type.d.mts +10 -0
  48. package/api/theme/theme.type.mjs +7 -1
  49. package/api/theme-edit/_adapter.d.mts +35 -0
  50. package/api/theme-edit/_adapter.mjs +477 -41
  51. package/api/theme-edit/_check.d.mts +28 -22
  52. package/api/theme-edit/_check.mjs +1077 -200
  53. package/api/theme-edit/_compiler.mjs +9 -0
  54. package/api/theme-edit/_context.mjs +60 -3
  55. package/api/theme-edit/_css.mjs +21 -1
  56. package/api/theme-edit/_edit.d.mts +22 -0
  57. package/api/theme-edit/_edit.mjs +932 -82
  58. package/api/theme-edit/_how-commands.d.mts +49 -0
  59. package/api/theme-edit/_how-commands.mjs +386 -1
  60. package/api/theme-edit/_how-question.d.mts +56 -0
  61. package/api/theme-edit/_how-question.mjs +3509 -168
  62. package/api/theme-edit/_how.mjs +104 -4
  63. package/api/theme-edit/_marks.d.mts +31 -5
  64. package/api/theme-edit/_marks.mjs +57 -5
  65. package/api/theme-edit/_normal.d.mts +137 -0
  66. package/api/theme-edit/_normal.mjs +612 -0
  67. package/api/theme-edit/_palette.mjs +10 -4
  68. package/api/theme-edit/_parts.d.mts +4 -0
  69. package/api/theme-edit/_parts.mjs +28 -2
  70. package/api/theme-edit/_preview-app.d.mts +7 -1
  71. package/api/theme-edit/_preview-app.mjs +191 -15
  72. package/api/theme-edit/_preview.d.mts +64 -8
  73. package/api/theme-edit/_preview.mjs +401 -83
  74. package/api/theme-edit/_settings.d.mts +139 -5
  75. package/api/theme-edit/_settings.mjs +1659 -112
  76. package/api/theme-edit/_tables.mjs +17 -1
  77. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  78. package/api/theme-edit/theme-edit.type.mjs +4 -1
  79. package/api/theme-edit/themeEditPreviewApp.doc.mjs +2 -2
  80. package/assets/codemods/run-codemod.mjs +73 -6
  81. package/assets/codemods/transforms/next/index.mjs +11 -1
  82. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  83. package/assets/docs/author-a-theme.doc.mjs +1 -0
  84. package/assets/docs/theme.doc.dense.mjs +2 -2
  85. package/assets/docs/theme.doc.mjs +1 -1
  86. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  87. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  88. package/assets/docs/tree/render-pages.doc.mjs +43 -2
  89. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  90. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  91. package/assets/docs/use-a-theme.doc.mjs +1 -1
  92. package/assets/docs.generated.json +2 -2
  93. package/assets/self-audit.generated.json +1 -1
  94. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  95. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  96. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  97. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  98. package/assets/templates/components.generated.json +1 -1
  99. package/assets/templates/pages/ai-chat/template.doc.mjs +8 -4
  100. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
  101. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  102. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  103. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  104. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  105. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  106. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  107. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  108. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  109. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  110. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  111. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  112. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  113. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  114. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  115. package/assets/templates/pages/editor/template.doc.mjs +1 -7
  116. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  117. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  118. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  119. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  120. package/assets/templates/pages/ide/page.tsx +24 -2
  121. package/assets/templates/pages/library/template.doc.mjs +4 -1
  122. package/assets/templates/pages/login/template.doc.mjs +2 -1
  123. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  124. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  125. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  126. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  127. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  128. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  129. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  130. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  131. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  132. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  133. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  134. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  135. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  136. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  137. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  138. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  139. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -1
  140. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  141. package/authoring/debug/parse.d.mts +3 -3
  142. package/authoring/doctypes/_schema.d.mts +3 -3
  143. package/authoring/doctypes/command/command.doc.mjs +1 -1
  144. package/authoring/doctypes/template/template.doc.mjs +1 -1
  145. package/authoring/doctypes/template/type.ts +9 -0
  146. package/clients/cli/bin/astryx.mjs +6 -9
  147. package/clients/cli/build-id.generated.json +1 -1
  148. package/clients/cli/commands/component.doc.mjs +1 -1
  149. package/clients/cli/commands/component.mjs +20 -2
  150. package/clients/cli/commands/docs.doc.mjs +7 -1
  151. package/clients/cli/commands/docs.mjs +3 -1
  152. package/clients/cli/commands/doctor.mjs +22 -14
  153. package/clients/cli/commands/experimental/render.mjs +32 -1
  154. package/clients/cli/commands/experimental/theme.mjs +27 -2
  155. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  156. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  157. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  158. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  159. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  160. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  161. package/clients/cli/commands/search.doc.mjs +2 -1
  162. package/clients/cli/commands/search.mjs +6 -1
  163. package/clients/cli/commands/template.mjs +4 -2
  164. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  165. package/clients/cli/commands/theme.doc.mjs +1 -1
  166. package/clients/cli/commands/theme.mjs +138 -3
  167. package/clients/cli/commands/upgrade.mjs +42 -7
  168. package/clients/cli/index.mjs +1 -1
  169. package/clients/cli/lib/component-format.mjs +205 -98
  170. package/clients/cli/lib/hook-format.mjs +9 -19
  171. package/clients/cli/manifest.generated.json +1 -1
  172. package/foundation/agent-docs/agent-docs.mjs +1 -1
  173. package/foundation/config/theme-state.d.mts +13 -1
  174. package/foundation/config/theme-state.mjs +47 -7
  175. package/foundation/discovery/component-discovery.d.mts +11 -0
  176. package/foundation/discovery/component-discovery.mjs +27 -2
  177. package/foundation/discovery/component-replacement.mjs +130 -1
  178. package/foundation/discovery/entry-name-files.d.mts +43 -0
  179. package/foundation/discovery/entry-name-files.mjs +264 -0
  180. package/foundation/discovery/hook-discovery.d.mts +8 -2
  181. package/foundation/discovery/hook-discovery.mjs +20 -7
  182. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  183. package/foundation/discovery/runner-allowlist.mjs +2 -0
  184. package/foundation/discovery/template-adapter.d.mts +52 -0
  185. package/foundation/discovery/template-adapter.mjs +169 -0
  186. package/foundation/discovery/theme-imports.d.mts +14 -0
  187. package/foundation/discovery/theme-imports.mjs +43 -1
  188. package/foundation/doc-compiler/import.mjs +7 -1
  189. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  190. package/foundation/doc-compiler/stored-docs.d.mts +22 -0
  191. package/foundation/doc-compiler/stored-docs.mjs +49 -0
  192. package/foundation/fs/cache-eviction.d.mts +21 -0
  193. package/foundation/fs/cache-eviction.mjs +73 -0
  194. package/foundation/fs/gather-cache.d.mts +25 -4
  195. package/foundation/fs/gather-cache.mjs +138 -52
  196. package/foundation/fs/jiti-cache.d.mts +19 -1
  197. package/foundation/fs/jiti-cache.mjs +130 -6
  198. package/foundation/fs/kept-tree.d.mts +60 -0
  199. package/foundation/fs/kept-tree.mjs +154 -0
  200. package/foundation/fs/module-loader.d.mts +18 -2
  201. package/foundation/fs/module-loader.mjs +92 -20
  202. package/foundation/identity/provider-identity.d.mts +6 -0
  203. package/foundation/identity/provider-identity.mjs +10 -1
  204. package/foundation/render/file-header.d.mts +66 -0
  205. package/foundation/render/file-header.mjs +118 -0
  206. package/foundation/render/host-answer.d.mts +18 -0
  207. package/foundation/render/host-answer.mjs +46 -0
  208. package/foundation/render/host-exit.d.mts +1 -0
  209. package/foundation/render/host-exit.mjs +6 -1
  210. package/foundation/render/html-reader.d.mts +55 -2
  211. package/foundation/render/html-reader.mjs +145 -26
  212. package/foundation/render/markup-edits.d.mts +57 -0
  213. package/foundation/render/markup-edits.mjs +182 -0
  214. package/foundation/render/page-host.mjs +29 -12
  215. package/foundation/render/page-worker.mjs +79 -10
  216. package/foundation/render/render-page.d.mts +34 -2
  217. package/foundation/render/render-page.mjs +210 -29
  218. package/foundation/render/source-block.d.mts +73 -6
  219. package/foundation/render/source-block.mjs +170 -19
  220. package/foundation/render/ts-paths.d.mts +4 -1
  221. package/foundation/render/ts-paths.mjs +7 -3
  222. package/foundation/response/error-codes.d.mts +2 -1
  223. package/foundation/response/error-codes.doc.mjs +7 -1
  224. package/foundation/response/error-codes.mjs +7 -0
  225. package/foundation/text/string-utils.d.mts +3 -2
  226. package/foundation/text/string-utils.mjs +16 -3
  227. package/foundation/text/suggest-order.d.mts +9 -0
  228. package/foundation/text/suggest-order.mjs +13 -0
  229. package/package.json +6 -6
@@ -31,11 +31,12 @@ import {
31
31
  import {SAMPLE_PAGE, elementNames, pageSource} from './_catalog.mjs';
32
32
 
33
33
  /** Bump when the shape of the cached part data changes. */
34
- const PART_DATA_VERSION = 4;
34
+ const PART_DATA_VERSION = 5;
35
35
 
36
36
  /**
37
37
  * @typedef {object} PartRecord
38
38
  * @property {Record<string, {tokens: Record<string, string[]>, values: string[]}>} own - property -> tokens (with conditions) and raw values
39
+ * @property {Record<string, Record<string, string>>} [at] - property -> the value under each condition, private variables resolved
39
40
  * @property {Record<string, string[]>} inside - tokens read by unnamed elements inside the part -> properties
40
41
  * @property {Record<string, string[]>} attrs - data attributes seen on the part
41
42
  * @property {string[]} contains - parts rendered inside it
@@ -666,6 +667,24 @@ function expand(v, env, tokens, seen = new Set(), depth = 0) {
666
667
  return out;
667
668
  }
668
669
 
670
+ /**
671
+ * A value with the private variables set on the element or its ancestors
672
+ * put in (a variable with no fallback only), so it reads public tokens and
673
+ * literal values alone where it can.
674
+ * @param {string} v
675
+ * @param {Record<string, string>} env
676
+ * @param {Set<string>} tokens
677
+ * @param {number} [depth]
678
+ * @returns {string}
679
+ */
680
+ function resolvePrivate(v, env, tokens, depth = 0) {
681
+ if (depth > 8) return v;
682
+ const out = v.replace(/var\((--[a-zA-Z0-9_-]+)\)/g, (m, name) =>
683
+ !tokens.has(name) && env[name] != null ? env[name] : m,
684
+ );
685
+ return out === v ? v : resolvePrivate(out, env, tokens, depth + 1);
686
+ }
687
+
669
688
  /**
670
689
  * Walk server-rendered markup: for each element, its classes' declarations
671
690
  * become what its part reads; text records the color pair it sits on.
@@ -675,7 +694,7 @@ function expand(v, env, tokens, seen = new Set(), depth = 0) {
675
694
  * @returns {{map: Record<string, PartRecord>, pairs: TextPair[]}}
676
695
  */
677
696
  export function walkMarkup(html, decls, tokens) {
678
- /** @type {Record<string, {own: Record<string, {tokens: Record<string, Set<string>>, values: Set<string>}>, inside: Record<string, Set<string>>, attrs: Record<string, Set<string>>, contains: Set<string>}>} */
697
+ /** @type {Record<string, {own: Record<string, {tokens: Record<string, Set<string>>, values: Set<string>}>, at: Record<string, Record<string, string>>, inside: Record<string, Set<string>>, attrs: Record<string, Set<string>>, contains: Set<string>}>} */
679
698
  const map = {};
680
699
  /** @type {Array<{env: Record<string, string>, target: string | null, fg: PaintSide | null, bg: PaintSide | null}>} */
681
700
  const stack = [{env: {}, target: null, fg: null, bg: null}];
@@ -726,6 +745,7 @@ export function walkMarkup(html, decls, tokens) {
726
745
  if (target) {
727
746
  const T = (map[target] ??= {
728
747
  own: {},
748
+ at: {},
729
749
  inside: {},
730
750
  attrs: {},
731
751
  contains: new Set(),
@@ -742,6 +762,11 @@ export function walkMarkup(html, decls, tokens) {
742
762
  const cond = [cond0, d.cond].filter(Boolean).join(' ');
743
763
  if (ownsTarget) {
744
764
  const P = (T.own[d.prop] ??= {tokens: {}, values: new Set()});
765
+ (T.at[d.prop] ??= {})[cond || 'always'] ??= resolvePrivate(
766
+ d.value,
767
+ env,
768
+ tokens,
769
+ );
745
770
  P.values.add(
746
771
  d.value.length > 80 ? `${d.value.slice(0, 80)}...` : d.value,
747
772
  );
@@ -792,6 +817,7 @@ export function walkMarkup(html, decls, tokens) {
792
817
  },
793
818
  ]),
794
819
  ),
820
+ at: v.at,
795
821
  inside: Object.fromEntries(
796
822
  Object.entries(v.inside).map(([k, s]) => [k, [...s]]),
797
823
  ),
@@ -68,12 +68,18 @@ export function refreshPreviewRoute(cwd: string, slug: string): Promise<{
68
68
  * @param {'colors' | 'components' | 'overview'} focus
69
69
  * @param {{code: string, cause: string} | null} [notChecked] why the change
70
70
  * could not be rendered
71
+ * @param {{pictureProblem?: string | null, stale?: string[]}} [extra] this
72
+ * result's picture problem (what kept --png from taking pictures) and its
73
+ * previewStale entries (an in-app preview changed by hand)
71
74
  * @returns {string}
72
75
  */
73
76
  export function seeLine(cwd: string, slug: string, focus: "colors" | "components" | "overview", notChecked?: {
74
77
  code: string;
75
78
  cause: string;
76
- } | null): string;
79
+ } | null, extra?: {
80
+ pictureProblem?: string | null;
81
+ stale?: string[];
82
+ }): string;
77
83
  /**
78
84
  * Add pages to the in-app theme preview, and write the preview route the
79
85
  * first time. With a description, the build ranking picks the template
@@ -1098,11 +1098,30 @@ function previewDir(cwd, where, opts = {}) {
1098
1098
  checkFolderName(where, '--path', retry);
1099
1099
  /** @type {string} */
1100
1100
  let dir;
1101
+ // A --path read from the folder the command ran in; one that names a
1102
+ // preview from the project root (as every printed folder is) is read
1103
+ // from there, so a printed tip works from a subfolder too.
1104
+ const fromRoot = (() => {
1105
+ // The --path as given from the subfolder the command ran in, rebased
1106
+ // onto the project root by the caller: when that names no folder and
1107
+ // the path without the subfolder names a preview, that one.
1108
+ const sub = path.relative(cwd, process.cwd());
1109
+ if (!sub || sub.startsWith('..') || path.isAbsolute(where)) return null;
1110
+ const given = path.normalize(where);
1111
+ if (!given.startsWith(sub + path.sep)) return null;
1112
+ const there = path.resolve(cwd, given.slice(sub.length + 1));
1113
+ return !fs.existsSync(path.resolve(cwd, where)) &&
1114
+ fs.existsSync(path.join(there, PREVIEW_DATA))
1115
+ ? there
1116
+ : null;
1117
+ })();
1101
1118
  try {
1102
- dir = assertWithin(path.resolve(cwd, where), cwd, {
1103
- allowAbsolute: true,
1104
- label: '--path',
1105
- });
1119
+ dir =
1120
+ fromRoot ??
1121
+ assertWithin(path.resolve(cwd, where), cwd, {
1122
+ allowAbsolute: true,
1123
+ label: '--path',
1124
+ });
1106
1125
  } catch (e) {
1107
1126
  if (e instanceof PathSafetyError)
1108
1127
  refuse(
@@ -1324,7 +1343,7 @@ export function appWiring(ctx, slug, data) {
1324
1343
  return [
1325
1344
  ...(blocker
1326
1345
  ? [
1327
- `${blocker} is not the editor's, so the editor does not write the theme's app copy in src/themes/${slug}/ (and theme add does not take it); the steps by hand:`,
1346
+ `the app copy in src/themes/${slug}/ was not updated: ${blocker}; the steps by hand:`,
1328
1347
  ]
1329
1348
  : []),
1330
1349
  `in ${where}, import the theme and its stylesheets: import {Theme} from '@astryxdesign/core/theme'; import {${name}} from '${ti.module.replace(/\.js$/, '')}'; ${ti.css.map(c => `import '${c}';`).join(' ')}`,
@@ -1501,7 +1520,7 @@ function planStarterApp(cwd, where, extra, dependencies, slug = null) {
1501
1520
  if (e instanceof PathSafetyError)
1502
1521
  refuse(
1503
1522
  E.ERR_PATH_TRAVERSAL,
1504
- `${where} is outside the current folder; make the app inside the folder you run the command from.`,
1523
+ `${where} is outside the project; make the app inside the project folder.`,
1505
1524
  {run: [again(null)]},
1506
1525
  );
1507
1526
  throw e;
@@ -3244,7 +3263,7 @@ export async function refreshPreviewRoute(cwd, slug) {
3244
3263
  stale.push(
3245
3264
  standIn
3246
3265
  ? `${shown(cwd, file)} (changed by hand, so it is kept; the theme has no generated colors now, so ${standIn}, which the page imports, holds an empty stand-in that keeps the app building. Give the page another name if you want to keep your changes, then run ${PREVIEW} add)`
3247
- : shown(cwd, file),
3266
+ : `${shown(cwd, file)} (changed by hand, so it does not follow this change: move it out of ${shownDir(cwd, dir)}/, keeping your copy elsewhere in the app and importing nothing from the preview folder, then run ${PREVIEW} add${dirFlag(cwd, dir)} to write it again)`,
3248
3267
  );
3249
3268
  return false;
3250
3269
  }
@@ -3260,7 +3279,20 @@ export async function refreshPreviewRoute(cwd, slug) {
3260
3279
  `${shownDir(cwd, dir)}/ (${slug} has generated colors now; ${PREVIEW} add${dirFlag(cwd, dir)} adds its Colors page)`,
3261
3280
  );
3262
3281
  if (!writes.length) continue;
3263
- commitPreview(cwd, dir, data, writes, [], `${EDITOR} show ${slug}`);
3282
+ // A route that cannot be written (its permissions, a folder in its
3283
+ // place) does not follow this change: said, never a quiet ok.
3284
+ try {
3285
+ commitPreview(cwd, dir, data, writes, [], `${EDITOR} show ${slug}`);
3286
+ } catch (e) {
3287
+ const code =
3288
+ /\b(E[A-Z]{2,})\b/.exec(
3289
+ `${/** @type {any} */ (e)?.code ?? ''} ${e instanceof Error ? e.message : ''}`,
3290
+ )?.[1] ?? 'it could not be written';
3291
+ stale.push(
3292
+ `${shownDir(cwd, dir)}/ (could not be written: ${code}, so the in-app preview does not follow this change; fix its permissions, then ${PREVIEW} add${dirFlag(cwd, dir)} writes it again)`,
3293
+ );
3294
+ continue;
3295
+ }
3264
3296
  changed = true;
3265
3297
  }
3266
3298
  return {changed, stale};
@@ -3339,11 +3371,53 @@ function routesOf(cwd, at) {
3339
3371
  function previewPath(cwd, at) {
3340
3372
  const app = routesOf(cwd, at);
3341
3373
  if (!app) return null;
3374
+ // A folder Next does not serve (_private, @slot, an intercepting route):
3375
+ // no URL, as add refuses it.
3376
+ if (unservedWhy(cwd, at.dir)) return null;
3342
3377
  const segs = urlSegments(app, at.dir);
3343
3378
  if (segs.some(seg => /^\[.+\]$/.test(seg))) return null;
3344
3379
  const base = nextBasePath(cwd);
3345
3380
  if (base == null) return null;
3346
- return `${base}/${segs.map(seg => encodeURIComponent(seg)).join('/')}`;
3381
+ // A folder named %5F… is served at the decoded name (`_x`), encoded as a
3382
+ // URL segment needs it.
3383
+ const decoded = (/** @type {string} */ seg) => {
3384
+ try {
3385
+ return decodeURIComponent(seg);
3386
+ } catch {
3387
+ return seg;
3388
+ }
3389
+ };
3390
+ return `${base}/${segs.map(seg => encodeURIComponent(decoded(seg))).join('/')}`;
3391
+ }
3392
+
3393
+ /**
3394
+ * Why a preview folder found in the routes folder is not served, or null.
3395
+ * @param {string} cwd
3396
+ * @param {string} dir
3397
+ * @returns {string | null}
3398
+ */
3399
+ function unservedWhy(cwd, dir) {
3400
+ const app = routesOf(cwd, {dir, app: null});
3401
+ if (!app) return null;
3402
+ // The same rules add keeps: src/app/ while app/ is what Next serves, and
3403
+ // a next.config whose page extensions leave out page.tsx.
3404
+ const served = [path.join(cwd, 'app'), path.join(cwd, 'src', 'app')].find(
3405
+ r => fs.existsSync(r) && fs.statSync(r).isDirectory(),
3406
+ );
3407
+ if (served && path.resolve(app) !== path.resolve(served))
3408
+ return `Next serves ${shown(cwd, served)}/ instead of ${shown(cwd, app)}/ when both are there`;
3409
+ try {
3410
+ const exts = readNextConfig(cwd).pageExtensions;
3411
+ if (exts && !exts.includes('tsx'))
3412
+ return `next.config sets pageExtensions to ${exts.join(', ')}, so Next does not serve page.tsx`;
3413
+ } catch {
3414
+ // A config this cannot read is not a reason to hide the URL.
3415
+ }
3416
+ // A [param] folder is served, with a value for it; only _private, @slot
3417
+ // and intercepting folders are not.
3418
+ const segs = path.relative(app, dir).split(path.sep);
3419
+ if (!segs.some(x => /^[_@]/.test(x) || INTERCEPT.test(x))) return null;
3420
+ return unroutedSegment(app, dir);
3347
3421
  }
3348
3422
 
3349
3423
  /**
@@ -3374,13 +3448,26 @@ function pageUrls(cwd, at, ids) {
3374
3448
  * @param {'colors' | 'components' | 'overview'} focus
3375
3449
  * @param {{code: string, cause: string} | null} [notChecked] why the change
3376
3450
  * could not be rendered
3451
+ * @param {{pictureProblem?: string | null, stale?: string[]}} [extra] this
3452
+ * result's picture problem (what kept --png from taking pictures) and its
3453
+ * previewStale entries (an in-app preview changed by hand)
3377
3454
  * @returns {string}
3378
3455
  */
3379
- export function seeLine(cwd, slug, focus, notChecked = null) {
3456
+ export function seeLine(cwd, slug, focus, notChecked = null, extra = {}) {
3380
3457
  /** @type {string[]} */
3381
3458
  const urls = [];
3382
3459
  /** Previews whose URL depends on the app's routing. @type {string[]} */
3383
3460
  const unplain = [];
3461
+ /** Previews in a folder Next does not serve. @type {string[]} */
3462
+ const unserved = [];
3463
+ /** Their folders, as --path takes them. @type {string[]} */
3464
+ const unservedDirs = [];
3465
+ /** @type {string[]} */
3466
+ const stale = extra.stale ?? [];
3467
+ /** Previews whose route was changed by hand. @type {string[]} */
3468
+ const handEdited = [];
3469
+ /** Previews whose record is damaged. @type {string[]} */
3470
+ const damaged = [];
3384
3471
  // The previews recorded for the theme, and any found in the routes
3385
3472
  // folders that wear it (a folder renamed by hand), as remove finds them.
3386
3473
  const dirs = [
@@ -3391,10 +3478,33 @@ export function seeLine(cwd, slug, focus, notChecked = null) {
3391
3478
  let data;
3392
3479
  try {
3393
3480
  data = JSON.parse(fs.readFileSync(path.join(dir, PREVIEW_DATA), 'utf8'));
3394
- } catch {
3481
+ } catch (e) {
3482
+ // A record that is there but damaged: the preview commands refuse
3483
+ // it until it is fixed, so no add tip, the repair instead.
3484
+ if (
3485
+ fs.existsSync(path.join(dir, PREVIEW_DATA)) &&
3486
+ !(/** @type {any} */ (e)?.code)
3487
+ )
3488
+ damaged.push(shownDir(cwd, dir));
3395
3489
  continue;
3396
3490
  }
3397
3491
  if (data?.theme !== slug) continue;
3492
+ const why = unservedWhy(cwd, dir);
3493
+ if (why) {
3494
+ unserved.push(`${shownDir(cwd, dir)}/ (${why})`);
3495
+ unservedDirs.push(shownDir(cwd, dir));
3496
+ continue;
3497
+ }
3498
+ if (
3499
+ stale.some(
3500
+ f =>
3501
+ f.startsWith(`${shownDir(cwd, dir)}/`) &&
3502
+ /changed by hand|could not be written/.test(f),
3503
+ )
3504
+ ) {
3505
+ handEdited.push(shownDir(cwd, dir));
3506
+ continue;
3507
+ }
3398
3508
  const ids = Array.isArray(data?.pages)
3399
3509
  ? data.pages.map((/** @type {any} */ x) => String(x?.id))
3400
3510
  : [];
@@ -3408,16 +3518,56 @@ export function seeLine(cwd, slug, focus, notChecked = null) {
3408
3518
  );
3409
3519
  }
3410
3520
  const f = themeFiles(cwd, slug);
3521
+ // What keeps --png from taking pictures, when this result's own picture
3522
+ // run failed (a file of yours named like a picture).
3523
+ // A command that only takes pictures, whatever this one was (an undo run
3524
+ // again undoes another change; new refuses a theme that exists).
3525
+ const pngNote = extra.pictureProblem
3526
+ ? `--png took no pictures: ${extra.pictureProblem}`
3527
+ : `${EDITOR} show ${slug} --png takes pictures in ${shownDir(cwd, f.dir)}/ with no dev server (it needs a Playwright or a Chrome)`;
3411
3528
  const own = notChecked
3412
3529
  ? /could not be written/.test(notChecked.cause)
3413
3530
  ? `the change is saved, but ${notChecked.cause}; --png takes no pictures until that is fixed`
3414
3531
  : `the change is saved, but the components could not be rendered here (${notChecked.cause}), so ${shown(cwd, f.preview)} still shows the theme as it was and --png takes no pictures until that is fixed`
3415
- : `look without changing your app: open or screenshot ${shown(cwd, f.preview)} (one self-contained page, current after this change; ${EDITOR} show ${slug} also writes ${shown(cwd, f.sheet)}, every component), or run it with --png for pictures in ${shownDir(cwd, f.dir)}/ with no dev server (it needs a Playwright or a Chrome)`;
3532
+ : `look without changing your app: open or screenshot ${shown(cwd, f.preview)} (one self-contained page, current after this change; ${EDITOR} show ${slug} also writes ${shown(cwd, f.sheet)}, every component), or ${pngNote}`;
3533
+ const edited = handEdited.length
3534
+ ? `; the in-app preview in ${handEdited.slice(0, 2).join(', ')}/ ${stale.some(f => /could not be written/.test(f)) && !stale.some(f => /changed by hand/.test(f)) ? 'could not be written' : 'was changed by hand'}, so it does not follow this change (previewStale says what to move out, then ${PREVIEW} add writes it again)`
3535
+ : '';
3416
3536
  if (urls.length)
3417
- return `${own}; in the running app: open ${urls.slice(0, 2).join(' or ')}`;
3537
+ return `${own}; in the running app: open ${urls.slice(0, 2).join(' or ')}${edited}`;
3418
3538
  if (unplain.length)
3419
- return `${own}; the in-app preview is in ${unplain.slice(0, 2).join(', ')}, at a URL that depends on the app's routing`;
3420
- return `${own}; to see it inside your app, ${PREVIEW} add puts the preview pages there, each at its own URL`;
3539
+ return `${own}; the in-app preview is in ${unplain.slice(0, 2).join(', ')}, at a URL that depends on the app's routing${edited}`;
3540
+ if (unserved.length) {
3541
+ // What fixes it, by why it is not served: add's own answer for each.
3542
+ const why = unserved.join(' ');
3543
+ const fix = /Next serves .* when both are there/.test(why)
3544
+ ? `${PREVIEW} remove --path ${quoteCommandArgument(unservedDirs[0])}, then ${PREVIEW} add --theme ${slug} puts it in the folder Next serves`
3545
+ : /pageExtensions/.test(why)
3546
+ ? `add "tsx" to pageExtensions in next.config so Next serves the preview's page.tsx`
3547
+ : `move it back into a folder Next routes, or make one there with ${PREVIEW} add --theme ${slug} --path <a routed folder>`;
3548
+ return `${own}; the in-app preview is in ${unserved.slice(0, 2).join(', ')}, which the app does not serve: ${fix}${edited}`;
3549
+ }
3550
+ if (edited) return `${own}${edited}`;
3551
+ if (damaged.length)
3552
+ return `${own}; the in-app preview in ${damaged.slice(0, 2).join(', ')}/ has a damaged ${PREVIEW_DATA}, so it does not follow this change: fix it by hand, or give the folder a new name that starts with _ and run ${PREVIEW} add${editorThemeCount(cwd) > 1 ? ` --theme ${slug}` : ''}`;
3553
+ // With more than one editor theme, a bare add may wear another one.
3554
+ const many = editorThemeCount(cwd) > 1;
3555
+ return `${own}; to see it inside your app, ${PREVIEW} add${many ? ` --theme ${slug}` : ''} puts the preview pages there, each at its own URL`;
3556
+ }
3557
+
3558
+ /**
3559
+ * How many editor themes the project has.
3560
+ * @param {string} cwd
3561
+ */
3562
+ function editorThemeCount(cwd) {
3563
+ const root = themeFiles(cwd, 'x').root;
3564
+ try {
3565
+ return fs
3566
+ .readdirSync(root)
3567
+ .filter(d => fs.existsSync(themeFiles(cwd, d).settings)).length;
3568
+ } catch {
3569
+ return 0;
3570
+ }
3421
3571
  }
3422
3572
 
3423
3573
  /**
@@ -4608,6 +4758,8 @@ export async function themeEditPreviewApp(dir, options = {}) {
4608
4758
  from.sheet,
4609
4759
  from.previewPng,
4610
4760
  from.sheetPng,
4761
+ // The record of pictures, none of which come along.
4762
+ from.pictures,
4611
4763
  ].map(f => path.basename(f)),
4612
4764
  );
4613
4765
  // The whole folder, tokens/ included, as bytes: a font or a picture
@@ -4622,6 +4774,12 @@ export async function themeEditPreviewApp(dir, options = {}) {
4622
4774
  else if (
4623
4775
  entry.isFile() &&
4624
4776
  !(rel === '' && skip.has(entry.name)) &&
4777
+ // No picture or preview page of any kind (dark pictures, section
4778
+ // sheets): the new app builds its own.
4779
+ !(
4780
+ rel === '' &&
4781
+ /^(preview|sheet)(-[a-z0-9-]+)?\.(html|png)$/.test(entry.name)
4782
+ ) &&
4625
4783
  // A temp file a stopped command left is no part of the theme.
4626
4784
  !isEditorTemp(entry.name)
4627
4785
  )
@@ -4994,6 +5152,24 @@ async function removePreview(page, options, box) {
4994
5152
  const retry = (/** @type {string | null} */ p) =>
4995
5153
  `${PREVIEW} remove${page != null ? ` ${quoteCommandArgument(page)}` : ''}${p == null ? '' : ` --path ${quoteCommandArgument(p)}`}`;
4996
5154
  const at = previewDir(cwd, options.path, {retry});
5155
+ // A file given for the preview's folder: its folder when the file is a
5156
+ // preview's own, else the previews there are (as add refuses a file).
5157
+ if (fs.existsSync(at.dir) && !fs.statSync(at.dir).isDirectory()) {
5158
+ const parent = path.dirname(at.dir);
5159
+ const own = fs.existsSync(path.join(parent, PREVIEW_DATA));
5160
+ const others = previewsIn(cwd);
5161
+ refuse(
5162
+ E.ERR_INVALID_ARGUMENT,
5163
+ `${shown(cwd, at.dir)} is a file; a preview is a folder${own ? `, and this file is in the preview ${shownDir(cwd, parent)}/` : ''}.`,
5164
+ {
5165
+ run: own
5166
+ ? [retry(shownDir(cwd, parent))]
5167
+ : others.length
5168
+ ? others.slice(0, 3).map(d => retry(shownDir(cwd, d)))
5169
+ : [`${PREVIEW} list`],
5170
+ },
5171
+ );
5172
+ }
4997
5173
  // The pages a stopped change was removing, read before it is finished.
4998
5174
  /** @type {string[]} */
4999
5175
  let removing = [];
@@ -152,7 +152,7 @@ export function previewRouteSource({ pages, theme, by, }: {
152
152
  * @param {string} html absolute
153
153
  * @param {string} png absolute
154
154
  * @param {'light' | 'dark'} mode
155
- * @returns {Promise<{ok: true, file: string, cut?: boolean} | {ok: false, reason: string}>} `cut` when the picture is of the window, not the whole page
155
+ * @returns {Promise<{ok: true, file: string, cut?: boolean} | {ok: false, reason: string, stopped?: string}>} `cut` when the picture is of the window, not the whole page
156
156
  */
157
157
  export function screenshot(project: import("./_project.mjs").ThemeProject, html: string, png: string, mode: "light" | "dark"): Promise<{
158
158
  ok: true;
@@ -161,7 +161,17 @@ export function screenshot(project: import("./_project.mjs").ThemeProject, html:
161
161
  } | {
162
162
  ok: false;
163
163
  reason: string;
164
+ stopped?: string;
164
165
  }>;
166
+ /**
167
+ * The font stylesheets a theme's app copy imports, from the fonts the theme
168
+ * loads now (an installed font package, the base theme's fonts).
169
+ * @param {import('./_settings.mjs').Ctx} ctx
170
+ * @param {string} slug
171
+ * @param {import('./_settings.mjs').ThemeData} data
172
+ * @returns {string[]}
173
+ */
174
+ export function copyFontsCss(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData): string[];
165
175
  /**
166
176
  * The app's copy of an editor theme: a standard local theme in
167
177
  * src/themes/<theme>/ (a descriptor, a source that re-exports the built
@@ -178,6 +188,17 @@ export function screenshot(project: import("./_project.mjs").ThemeProject, html:
178
188
  * @returns {string | null}
179
189
  */
180
190
  export function writeAppCopy(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData): string | null;
191
+ /**
192
+ * Why a theme's app copy is behind its build, or null when it is current:
193
+ * something in its way (appCopyStale), a copy file missing, or a file
194
+ * whose content is not what the editor would write now.
195
+ * @param {string} cwd
196
+ * @param {string} slug
197
+ * @param {string[] | null} [fontsCss] the font stylesheets the copy should
198
+ * import now (null: the copy's own)
199
+ * @returns {string | null}
200
+ */
201
+ export function appCopyBehind(cwd: string, slug: string, fontsCss?: string[] | null): string | null;
181
202
  /**
182
203
  * {@link writeAppCopy} with the font stylesheets given, or null to keep the
183
204
  * copy's own (a compile, which changes no setting).
@@ -188,13 +209,24 @@ export function writeAppCopy(ctx: import("./_settings.mjs").Ctx, slug: string, d
188
209
  */
189
210
  export function writeAppCopyAt(cwd: string, slug: string, fontsCss: string[] | null): string | null;
190
211
  /**
191
- * Why the editor will not write a theme's app copy, or null when it will:
192
- * the folder is not there yet, or its descriptor carries the editor's mark
193
- * and it holds only the copy's own files (system files such as .DS_Store
194
- * aside). Otherwise the name of what is in the way (a file of yours), or
195
- * the folder itself when it is not the editor's copy. Built bytes are not
196
- * compared, so a stable rebuild of the copy leaves it the editor's. The one
197
- * test the copy's writer and `wiring` both use.
212
+ * The note for a copy a file of yours keeps from being written, as a
213
+ * result field: `{appCopyStale}` when one does, else nothing.
214
+ * @param {string} cwd
215
+ * @param {string} slug
216
+ * @returns {{appCopyStale?: string}}
217
+ */
218
+ export function appCopyStale(cwd: string, slug: string): {
219
+ appCopyStale?: string;
220
+ };
221
+ /**
222
+ * Why the editor will not write a theme's app copy, or null when it will.
223
+ * Only a file of yours AT one of the copy's names stops it: a descriptor,
224
+ * source or font stylesheet without the editor's mark, or any copy file
225
+ * while the descriptor is not the editor's. Other files there (a note, a
226
+ * swap file, desktop.ini) are left as they are and the copy is written
227
+ * around them. Built bytes are not compared, so a stable rebuild of the
228
+ * copy leaves it the editor's. The one test the copy's writer, the change
229
+ * results and `wiring` use. Returns the file in the way.
198
230
  * @param {string} cwd
199
231
  * @param {string} slug
200
232
  * @returns {string | null}
@@ -208,6 +240,30 @@ export function appCopyBlocker(cwd: string, slug: string): string | null;
208
240
  * @returns {string[] | null}
209
241
  */
210
242
  export function takeFirstAppCopy(cwd: string, slug: string): string[] | null;
243
+ /**
244
+ * Run a browser for a picture without blocking this process: a stop that
245
+ * reaches it (SIGINT, SIGTERM) stops the browser too, and is reported.
246
+ * Bounded to 60 seconds, as a picture run always was.
247
+ * @param {string} bin
248
+ * @param {string[]} args
249
+ * @param {number} [bound] milliseconds before the browser is stopped
250
+ * @returns {Promise<{status: number | null, signal: string | null, stderr: string, error?: Error, stoppedBy?: string, timedOut?: boolean}>}
251
+ */
252
+ export function runBrowser(bin: string, args: string[], bound?: number): Promise<{
253
+ status: number | null;
254
+ signal: string | null;
255
+ stderr: string;
256
+ error?: Error;
257
+ stoppedBy?: string;
258
+ timedOut?: boolean;
259
+ }>;
260
+ /**
261
+ * The first stderr line that says something about the picture: Chrome's
262
+ * startup warnings (dbus, GPU, sandbox notices) come first on Linux and
263
+ * say nothing about why no picture was written.
264
+ * @param {string} text
265
+ */
266
+ export function meaningfulLine(text: string): string;
211
267
  /** The groups of the theme-building page, in order. */
212
268
  export const SHOWCASE_GROUPS: string[];
213
269
  export { APP_COPY_MARK } from "./_marks.mjs";