@astryxdesign/cli 0.7.16 → 0.7.17-canary.g0404a74

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 (529) hide show
  1. package/README.md +76 -86
  2. package/api/build/_adapter.d.mts +17 -0
  3. package/api/build/_adapter.mjs +53 -34
  4. package/api/build/blocks/blocks.d.mts +7 -5
  5. package/api/build/blocks/blocks.mjs +113 -26
  6. package/api/build/blocks/blocks.weights.json +1 -1
  7. package/api/build/build.doc.mjs +4 -3
  8. package/api/build/build.type.d.mts +2 -2
  9. package/api/build/build.type.mjs +3 -3
  10. package/api/build/kit/kind.d.mts +2 -1
  11. package/api/build/kit/kind.mjs +199 -10
  12. package/api/build/kit/kit.mjs +6 -4
  13. package/api/build/kit/rank.d.mts +6 -4
  14. package/api/build/kit/rank.mjs +132 -28
  15. package/api/build/kit/signals.d.mts +7 -1
  16. package/api/build/kit/signals.mjs +21 -10
  17. package/api/build/kit/start.d.mts +5 -4
  18. package/api/build/kit/start.mjs +14 -9
  19. package/api/build/kit/weights.d.mts +39 -3
  20. package/api/build/kit/weights.json +1 -1
  21. package/api/build/kit/weights.mjs +351 -46
  22. package/api/build/kit/word-model.d.mts +23 -0
  23. package/api/build/kit/word-model.mjs +46 -0
  24. package/api/build/kit/words.d.mts +86 -0
  25. package/api/build/kit/words.mjs +241 -1
  26. package/api/build/tree.mjs +1 -1
  27. package/api/component/__fixtures__/resolutions/modules.txt +5 -6
  28. package/api/component/_adapter.d.mts +26 -2
  29. package/api/component/_adapter.mjs +135 -8
  30. package/api/component/component.mjs +14 -1
  31. package/api/component/list/list.d.mts +1 -1
  32. package/api/component/list/list.mjs +48 -6
  33. package/api/discover/_adapter.d.mts +11 -1
  34. package/api/discover/_adapter.mjs +95 -1
  35. package/api/discover/detail/item/item.mjs +5 -0
  36. package/api/discover/discover.mjs +12 -3
  37. package/api/discover/discover.type.d.mts +16 -3
  38. package/api/discover/discover.type.mjs +13 -3
  39. package/api/discover/search/search.mjs +3 -2
  40. package/api/docs/_adapter.d.mts +57 -2
  41. package/api/docs/_adapter.mjs +266 -33
  42. package/api/docs/_entry-names-lazily.d.mts +22 -0
  43. package/api/docs/_entry-names-lazily.mjs +25 -0
  44. package/api/docs/_entry-names.d.mts +23 -0
  45. package/api/docs/_entry-names.mjs +105 -0
  46. package/api/docs/docs.d.mts +3 -0
  47. package/api/docs/docs.doc.mjs +7 -1
  48. package/api/docs/docs.mjs +12 -0
  49. package/api/docs/docs.type.d.mts +5 -0
  50. package/api/docs/docs.type.mjs +2 -0
  51. package/api/docs/node/node.mjs +1 -1
  52. package/api/doctor/_adapter.d.mts +54 -5
  53. package/api/doctor/_adapter.mjs +162 -11
  54. package/api/doctor/built-checks.mjs +40 -14
  55. package/api/doctor/doctor.d.mts +15 -3
  56. package/api/doctor/doctor.doc.mjs +1 -1
  57. package/api/doctor/doctor.mjs +31 -7
  58. package/api/doctor/theme-checks.d.mts +35 -3
  59. package/api/doctor/theme-checks.mjs +377 -29
  60. package/api/hook/_adapter.d.mts +10 -4
  61. package/api/hook/_adapter.mjs +41 -5
  62. package/api/hook/detail/detail.mjs +5 -2
  63. package/api/hook/detail/params/params.mjs +10 -3
  64. package/api/icon/_records.mjs +2 -1
  65. package/api/index.d.mts +2 -0
  66. package/api/index.mjs +2 -0
  67. package/api/integration/_adapter.d.mts +44 -0
  68. package/api/integration/_adapter.mjs +77 -1
  69. package/api/integration/add-helpers.mjs +10 -0
  70. package/api/integration/authoring-checks.mjs +11 -8
  71. package/api/integration/example-scope.d.mts +14 -0
  72. package/api/integration/example-scope.mjs +44 -0
  73. package/api/integration/example-scope.type.d.mts +29 -0
  74. package/api/integration/example-scope.type.mjs +25 -0
  75. package/api/integration/integrationExampleScope.doc.d.mts +11 -0
  76. package/api/integration/integrationExampleScope.doc.mjs +59 -0
  77. package/api/integration/pack-check.mjs +16 -1
  78. package/api/integration/validate-integration.d.mts +18 -6
  79. package/api/integration/validate-integration.mjs +129 -15
  80. package/api/integration/validate-integration.type.d.mts +22 -0
  81. package/api/integration/validate-integration.type.mjs +2 -1
  82. package/api/integration/validateIntegration.doc.mjs +1 -1
  83. package/api/render/_adapter.mjs +591 -195
  84. package/api/render/render.doc.mjs +11 -3
  85. package/api/render/render.type.d.mts +53 -1
  86. package/api/render/render.type.mjs +32 -2
  87. package/api/search/ORDERING.md +2 -2
  88. package/api/search/_adapter.d.mts +9 -0
  89. package/api/search/_adapter.mjs +85 -0
  90. package/api/search/_candidate-score.d.mts +9 -4
  91. package/api/search/_candidate-score.mjs +133 -46
  92. package/api/search/_fit-order.mjs +3 -3
  93. package/api/search/_gather-components.d.mts +3 -2
  94. package/api/search/_gather-components.mjs +12 -3
  95. package/api/search/_lexical.d.mts +14 -0
  96. package/api/search/_lexical.mjs +93 -11
  97. package/api/search/_result.d.mts +11 -9
  98. package/api/search/_result.mjs +4 -4
  99. package/api/search/_score.d.mts +6 -1
  100. package/api/search/_score.mjs +15 -3
  101. package/api/search/search-index.mjs +7 -1
  102. package/api/search/search.d.mts +1 -1
  103. package/api/template/_adapter.d.mts +16 -0
  104. package/api/template/_adapter.mjs +39 -2
  105. package/api/template/cdn/cdn.mjs +37 -8
  106. package/api/template/copy/copy.d.mts +6 -3
  107. package/api/template/copy/copy.mjs +40 -8
  108. package/api/template/template.doc.mjs +3 -3
  109. package/api/template/template.mjs +63 -11
  110. package/api/template/template.type.d.mts +1 -0
  111. package/api/template/template.type.mjs +1 -0
  112. package/api/theme/_adapter.d.mts +12 -1
  113. package/api/theme/_adapter.mjs +132 -13
  114. package/api/theme/_app-provider.d.mts +31 -0
  115. package/api/theme/_app-provider.mjs +135 -0
  116. package/api/theme/add/add.mjs +3 -1
  117. package/api/theme/build/build.d.mts +142 -1
  118. package/api/theme/build/build.mjs +692 -284
  119. package/api/theme/build/core-interception.d.mts +10 -0
  120. package/api/theme/build/core-interception.mjs +10 -0
  121. package/api/theme/build/font-warning.d.mts +80 -5
  122. package/api/theme/build/font-warning.mjs +323 -55
  123. package/api/theme/build/icon-imports.mjs +51 -9
  124. package/api/theme/build/null-values.d.mts +28 -0
  125. package/api/theme/build/null-values.mjs +191 -0
  126. package/api/theme/list/list.mjs +17 -1
  127. package/api/theme/remove/remove.d.mts +2 -1
  128. package/api/theme/remove/remove.mjs +7 -3
  129. package/api/theme/theme.type.d.mts +78 -1
  130. package/api/theme/theme.type.mjs +38 -2
  131. package/api/theme/themeAdd.doc.mjs +1 -1
  132. package/api/theme/themeListAvailable.doc.mjs +1 -1
  133. package/api/theme/themeRemove.doc.mjs +8 -5
  134. package/api/theme-edit/_adapter.d.mts +116 -4
  135. package/api/theme-edit/_adapter.mjs +1058 -93
  136. package/api/theme-edit/_catalog.d.mts +46 -2
  137. package/api/theme-edit/_catalog.mjs +115 -14
  138. package/api/theme-edit/_check.d.mts +133 -24
  139. package/api/theme-edit/_check.mjs +3392 -531
  140. package/api/theme-edit/_color.d.mts +26 -0
  141. package/api/theme-edit/_color.mjs +92 -2
  142. package/api/theme-edit/_compiler.d.mts +5 -1
  143. package/api/theme-edit/_compiler.mjs +141 -17
  144. package/api/theme-edit/_context.d.mts +74 -6
  145. package/api/theme-edit/_context.mjs +468 -76
  146. package/api/theme-edit/_css.d.mts +21 -0
  147. package/api/theme-edit/_css.mjs +87 -14
  148. package/api/theme-edit/_edit.d.mts +74 -7
  149. package/api/theme-edit/_edit.mjs +4426 -319
  150. package/api/theme-edit/_how-commands.d.mts +76 -1
  151. package/api/theme-edit/_how-commands.mjs +793 -9
  152. package/api/theme-edit/_how-question.d.mts +97 -6
  153. package/api/theme-edit/_how-question.mjs +9184 -747
  154. package/api/theme-edit/_how.d.mts +5 -2
  155. package/api/theme-edit/_how.mjs +255 -46
  156. package/api/theme-edit/_importers.d.mts +38 -0
  157. package/api/theme-edit/_importers.mjs +188 -0
  158. package/api/theme-edit/_marks.d.mts +31 -5
  159. package/api/theme-edit/_marks.mjs +57 -5
  160. package/api/theme-edit/_name-rule.d.mts +11 -0
  161. package/api/theme-edit/_name-rule.mjs +12 -0
  162. package/api/theme-edit/_normal.d.mts +322 -0
  163. package/api/theme-edit/_normal.mjs +1630 -0
  164. package/api/theme-edit/_palette.d.mts +49 -0
  165. package/api/theme-edit/_palette.mjs +180 -38
  166. package/api/theme-edit/_part-words.d.mts +39 -0
  167. package/api/theme-edit/_part-words.mjs +152 -0
  168. package/api/theme-edit/_parts.d.mts +55 -3
  169. package/api/theme-edit/_parts.mjs +421 -36
  170. package/api/theme-edit/_preview-app.d.mts +7 -13
  171. package/api/theme-edit/_preview-app.mjs +1108 -599
  172. package/api/theme-edit/_preview.d.mts +156 -19
  173. package/api/theme-edit/_preview.mjs +809 -180
  174. package/api/theme-edit/_project.d.mts +61 -1
  175. package/api/theme-edit/_project.mjs +177 -6
  176. package/api/theme-edit/_settings.d.mts +619 -48
  177. package/api/theme-edit/_settings.mjs +4910 -617
  178. package/api/theme-edit/_tables.d.mts +41 -0
  179. package/api/theme-edit/_tables.mjs +261 -41
  180. package/api/theme-edit/_vet.d.mts +31 -0
  181. package/api/theme-edit/_vet.mjs +114 -8
  182. package/api/theme-edit/theme-edit.type.d.mts +34 -2
  183. package/api/theme-edit/theme-edit.type.mjs +18 -3
  184. package/api/theme-edit/themeEditHow.doc.mjs +1 -1
  185. package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
  186. package/api/theme-edit/themeEditNew.doc.mjs +7 -4
  187. package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
  188. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
  189. package/api/upgrade/run/run.mjs +4 -3
  190. package/api/upgrade/upgrade.mjs +16 -1
  191. package/assets/codemods/integration-discovery.mjs +2 -1
  192. package/assets/codemods/integration-runner.mjs +1 -1
  193. package/assets/codemods/jscodeshift.d.ts +1 -1
  194. package/assets/codemods/run-codemod.mjs +151 -18
  195. package/assets/codemods/runner.mjs +1 -4
  196. package/assets/codemods/transforms/next/index.mjs +11 -1
  197. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  198. package/assets/component-list.generated.json +1 -0
  199. package/assets/docs/author-a-theme.doc.mjs +2 -0
  200. package/assets/docs/theme.doc.dense.mjs +76 -7
  201. package/assets/docs/theme.doc.mjs +66 -2
  202. package/assets/docs/theme.doc.zh.mjs +51 -1
  203. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  204. package/assets/docs/tree/checks.doc.mjs +2 -2
  205. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  206. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  207. package/assets/docs/tree/font-setup.doc.mjs +1 -1
  208. package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
  209. package/assets/docs/tree/render-pages.doc.mjs +46 -5
  210. package/assets/docs/tree/share-a-page.doc.mjs +157 -0
  211. package/assets/docs/tree/single-component.doc.mjs +4 -0
  212. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  213. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  214. package/assets/docs/tree/write-good-templates.doc.mjs +1 -1
  215. package/assets/docs/use-a-theme.doc.mjs +2 -2
  216. package/assets/docs-routes.generated.json +1 -0
  217. package/assets/docs.generated.json +2 -2
  218. package/assets/search-catalog.generated.json +2 -0
  219. package/assets/self-audit.generated.json +1 -1
  220. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  221. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  222. package/assets/templates/blocks/components/ChatComposerInput/useSpeechRecognitionHookUsage.doc.mjs +14 -0
  223. package/assets/templates/blocks/components/ChatComposerInput/useSpeechRecognitionHookUsage.tsx +43 -0
  224. package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
  225. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  226. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  227. package/assets/templates/components.generated.json +1 -1
  228. package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
  229. package/assets/templates/pages/ai-chat-landing/page.tsx +31 -4
  230. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +5 -1
  231. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  232. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  233. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  234. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  235. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  236. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  237. package/assets/templates/pages/dashboard-alert-rail/page.tsx +1 -1
  238. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  239. package/assets/templates/pages/dashboard-cohort-funnel/page.tsx +1 -1
  240. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  241. package/assets/templates/pages/dashboard-comparison/page.tsx +2 -2
  242. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  243. package/assets/templates/pages/dashboard-progress/page.tsx +1 -1
  244. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  245. package/assets/templates/pages/detail-page/page.tsx +60 -7
  246. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  247. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  248. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  249. package/assets/templates/pages/documentation-technical/page.tsx +13 -13
  250. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  251. package/assets/templates/pages/editor/page.tsx +14 -2
  252. package/assets/templates/pages/editor/template.doc.mjs +2 -8
  253. package/assets/templates/pages/file-explorer/page.tsx +9 -0
  254. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  255. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  256. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  257. package/assets/templates/pages/form-wizard-vertical/page.tsx +23 -3
  258. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  259. package/assets/templates/pages/ide/page.tsx +33 -2
  260. package/assets/templates/pages/kanban-board/page.tsx +12 -2
  261. package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
  262. package/assets/templates/pages/library/template.doc.mjs +4 -1
  263. package/assets/templates/pages/login/template.doc.mjs +2 -1
  264. package/assets/templates/pages/login-card/page.tsx +16 -0
  265. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  266. package/assets/templates/pages/login-split/page.tsx +19 -6
  267. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  268. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  269. package/assets/templates/pages/messaging-shell/template.doc.mjs +6 -0
  270. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  271. package/assets/templates/pages/payment-form/page.tsx +30 -4
  272. package/assets/templates/pages/product-detail/page.tsx +26 -2
  273. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  274. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  275. package/assets/templates/pages/settings-dialog/page.tsx +162 -12
  276. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  277. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  278. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  279. package/assets/templates/pages/shell-side-nav/page.tsx +11 -3
  280. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  281. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  282. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  283. package/assets/templates/pages/table-filter/page.tsx +9 -0
  284. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  285. package/assets/templates/pages/table-grouped/page.tsx +161 -133
  286. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  287. package/assets/templates/pages/table-page/page.tsx +14 -1
  288. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  289. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  290. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
  291. package/assets/templates/pages/work-item-detail/page.tsx +47 -7
  292. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  293. package/assets/theme.template.ts +9 -2
  294. package/authoring/debug/parse.d.mts +3 -3
  295. package/authoring/doctypes/_schema.d.mts +9 -9
  296. package/authoring/doctypes/command/command.doc.mjs +1 -1
  297. package/authoring/doctypes/component/categories.d.mts +37 -0
  298. package/authoring/doctypes/component/categories.mjs +54 -0
  299. package/authoring/doctypes/template/template.doc.mjs +1 -1
  300. package/authoring/doctypes/template/type.ts +9 -0
  301. package/authoring/example/example.doc.d.mts +12 -0
  302. package/authoring/example/example.doc.mjs +69 -0
  303. package/authoring/example/preview.d.mts +92 -0
  304. package/authoring/example/preview.mjs +994 -0
  305. package/authoring/example/type.ts +102 -0
  306. package/authoring/index.d.mts +1 -0
  307. package/authoring/index.d.ts +12 -0
  308. package/authoring/index.mjs +3 -1
  309. package/authoring/integration/integration.doc.mjs +8 -0
  310. package/authoring/integration/schema.d.mts +24 -1
  311. package/authoring/integration/schema.mjs +126 -4
  312. package/authoring/integration/type.ts +14 -0
  313. package/clients/cli/bin/astryx.mjs +6 -9
  314. package/clients/cli/build-id.generated.json +1 -1
  315. package/clients/cli/commands/component.doc.mjs +1 -1
  316. package/clients/cli/commands/component.mjs +22 -3
  317. package/clients/cli/commands/discover.mjs +70 -3
  318. package/clients/cli/commands/docs.doc.mjs +7 -1
  319. package/clients/cli/commands/docs.mjs +44 -6
  320. package/clients/cli/commands/doctor.mjs +84 -16
  321. package/clients/cli/commands/experimental/render.mjs +42 -1
  322. package/clients/cli/commands/experimental/theme.mjs +1032 -134
  323. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  324. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  325. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
  326. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
  327. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
  328. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
  329. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  330. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  331. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +2 -2
  332. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  333. package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
  334. package/clients/cli/commands/experimental-theme-remove.doc.mjs +4 -4
  335. package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
  336. package/clients/cli/commands/search.doc.mjs +2 -1
  337. package/clients/cli/commands/search.mjs +6 -1
  338. package/clients/cli/commands/template.doc.mjs +1 -1
  339. package/clients/cli/commands/template.mjs +15 -2
  340. package/clients/cli/commands/theme-add.doc.mjs +1 -1
  341. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  342. package/clients/cli/commands/theme-list.doc.mjs +1 -1
  343. package/clients/cli/commands/theme-remove.doc.mjs +13 -5
  344. package/clients/cli/commands/theme.doc.mjs +1 -1
  345. package/clients/cli/commands/theme.mjs +849 -441
  346. package/clients/cli/commands/upgrade.mjs +46 -8
  347. package/clients/cli/index.mjs +9 -19
  348. package/clients/cli/lib/cli-error.mjs +2 -1
  349. package/clients/cli/lib/component-format.mjs +205 -98
  350. package/clients/cli/lib/hook-format.mjs +9 -19
  351. package/clients/cli/lib/json-shim.mjs +265 -29
  352. package/clients/cli/lib/manifest.mjs +3 -2
  353. package/clients/cli/lib/stray-option.mjs +478 -0
  354. package/clients/cli/lib/unknown-command.mjs +353 -0
  355. package/clients/cli/manifest.generated.json +1 -1
  356. package/foundation/agent-docs/agent-docs.mjs +1 -1
  357. package/foundation/config/project.d.mts +8 -0
  358. package/foundation/config/project.mjs +26 -29
  359. package/foundation/config/theme-state.d.mts +31 -2
  360. package/foundation/config/theme-state.mjs +140 -8
  361. package/foundation/discovery/authoring-self-docs.mjs +1 -0
  362. package/foundation/discovery/cli-self-doc-names.d.mts +13 -0
  363. package/foundation/discovery/cli-self-doc-names.mjs +51 -0
  364. package/foundation/discovery/cli-self-docs.d.mts +0 -2
  365. package/foundation/discovery/cli-self-docs.mjs +2 -15
  366. package/foundation/discovery/component-discovery.d.mts +11 -0
  367. package/foundation/discovery/component-discovery.mjs +59 -10
  368. package/foundation/discovery/component-replacement.mjs +130 -1
  369. package/foundation/discovery/copied-passages.mjs +2 -1
  370. package/foundation/discovery/core-component-docs.d.mts +29 -0
  371. package/foundation/discovery/core-component-docs.mjs +83 -0
  372. package/foundation/discovery/core-theme-facts.d.mts +70 -0
  373. package/foundation/discovery/core-theme-facts.mjs +384 -0
  374. package/foundation/discovery/doc-types.mjs +4 -3
  375. package/foundation/discovery/docs-discovery.d.mts +66 -9
  376. package/foundation/discovery/docs-discovery.mjs +126 -60
  377. package/foundation/discovery/entry-name-files.d.mts +106 -0
  378. package/foundation/discovery/entry-name-files.mjs +354 -0
  379. package/foundation/discovery/hook-discovery.d.mts +18 -2
  380. package/foundation/discovery/hook-discovery.mjs +93 -42
  381. package/foundation/discovery/icon-definition-discovery.mjs +2 -1
  382. package/foundation/discovery/icon-set-checks.mjs +2 -1
  383. package/foundation/discovery/icon-set-discovery.mjs +2 -1
  384. package/foundation/discovery/integration-component-views.d.mts +15 -0
  385. package/foundation/discovery/integration-component-views.mjs +91 -0
  386. package/foundation/discovery/integration-doc-files.mjs +2 -1
  387. package/foundation/discovery/module-exports.d.mts +26 -1
  388. package/foundation/discovery/module-exports.mjs +114 -40
  389. package/foundation/discovery/name-roots.d.mts +38 -0
  390. package/foundation/discovery/name-roots.mjs +108 -0
  391. package/foundation/discovery/next-routes.d.mts +48 -0
  392. package/foundation/discovery/next-routes.mjs +181 -0
  393. package/foundation/discovery/package-exports.d.mts +10 -0
  394. package/foundation/discovery/package-exports.mjs +56 -3
  395. package/foundation/discovery/prop-drift.mjs +9 -9
  396. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  397. package/foundation/discovery/runner-allowlist.mjs +2 -0
  398. package/foundation/discovery/stored-component-list.d.mts +43 -0
  399. package/foundation/discovery/stored-component-list.mjs +90 -0
  400. package/foundation/discovery/stored-search-catalog.d.mts +115 -0
  401. package/foundation/discovery/stored-search-catalog.mjs +297 -0
  402. package/foundation/discovery/stored-self-audit.d.mts +26 -10
  403. package/foundation/discovery/stored-self-audit.mjs +40 -18
  404. package/foundation/discovery/template-adapter.d.mts +49 -29
  405. package/foundation/discovery/template-adapter.mjs +89 -99
  406. package/foundation/discovery/template-destination.d.mts +28 -0
  407. package/foundation/discovery/template-destination.mjs +104 -0
  408. package/foundation/discovery/template-icons.mjs +2 -1
  409. package/foundation/discovery/template-ids.d.mts +69 -0
  410. package/foundation/discovery/template-ids.mjs +199 -0
  411. package/foundation/discovery/theme-discovery.d.mts +12 -0
  412. package/foundation/discovery/theme-discovery.mjs +34 -4
  413. package/foundation/discovery/theme-imports.d.mts +24 -0
  414. package/foundation/discovery/theme-imports.mjs +61 -4
  415. package/foundation/discovery/theming-targets.d.mts +13 -5
  416. package/foundation/discovery/theming-targets.mjs +41 -47
  417. package/foundation/doc-compiler/generated-levels.d.mts +43 -0
  418. package/foundation/doc-compiler/generated-levels.mjs +72 -0
  419. package/foundation/doc-compiler/import.mjs +7 -1
  420. package/foundation/doc-compiler/inputs.mjs +3 -2
  421. package/foundation/doc-compiler/literal-doc.d.mts +12 -0
  422. package/foundation/doc-compiler/literal-doc.mjs +322 -0
  423. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  424. package/foundation/doc-compiler/stored-docs.d.mts +29 -0
  425. package/foundation/doc-compiler/stored-docs.mjs +63 -1
  426. package/foundation/doc-compiler/tree.d.mts +4 -84
  427. package/foundation/doc-compiler/tree.mjs +4 -62
  428. package/foundation/env/semver.mjs +3 -1
  429. package/foundation/fonts/font-stylesheet.d.mts +46 -0
  430. package/foundation/fonts/font-stylesheet.mjs +173 -0
  431. package/foundation/fs/cache-eviction.d.mts +21 -0
  432. package/foundation/fs/cache-eviction.mjs +73 -0
  433. package/foundation/fs/exact-codec.d.mts +12 -2
  434. package/foundation/fs/exact-codec.mjs +23 -6
  435. package/foundation/fs/file-protection.mjs +16 -5
  436. package/foundation/fs/gather-cache.d.mts +94 -4
  437. package/foundation/fs/gather-cache.mjs +671 -106
  438. package/foundation/fs/glob.d.mts +16 -0
  439. package/foundation/fs/glob.mjs +105 -0
  440. package/foundation/fs/jiti-cache.d.mts +19 -1
  441. package/foundation/fs/jiti-cache.mjs +130 -6
  442. package/foundation/fs/kept-tree.d.mts +80 -0
  443. package/foundation/fs/kept-tree.mjs +240 -0
  444. package/foundation/fs/listing-cache.d.mts +7 -0
  445. package/foundation/fs/listing-cache.mjs +10 -0
  446. package/foundation/fs/module-loader.d.mts +24 -2
  447. package/foundation/fs/module-loader.mjs +94 -21
  448. package/foundation/fs/path-safety.d.mts +11 -2
  449. package/foundation/fs/path-safety.mjs +108 -18
  450. package/foundation/fs/paths.d.mts +18 -0
  451. package/foundation/fs/paths.mjs +15 -2
  452. package/foundation/fs/read-record.d.mts +56 -7
  453. package/foundation/fs/read-record.mjs +280 -56
  454. package/foundation/fs/regular-file.d.mts +29 -0
  455. package/foundation/fs/regular-file.mjs +77 -0
  456. package/foundation/fs/stop-cleanup.d.mts +12 -0
  457. package/foundation/fs/stop-cleanup.mjs +66 -0
  458. package/foundation/identity/provider-identity.d.mts +6 -0
  459. package/foundation/identity/provider-identity.mjs +10 -1
  460. package/foundation/integrations/contribution-inventory.mjs +4 -3
  461. package/foundation/integrations/example-code.d.mts +63 -0
  462. package/foundation/integrations/example-code.mjs +416 -0
  463. package/foundation/integrations/integrations.d.mts +23 -1
  464. package/foundation/integrations/integrations.mjs +18 -1
  465. package/foundation/integrations/pack-state.d.mts +75 -0
  466. package/foundation/integrations/pack-state.mjs +314 -0
  467. package/foundation/integrations/public-imports.d.mts +9 -0
  468. package/foundation/integrations/public-imports.mjs +3 -2
  469. package/foundation/integrations/shipped-imports.d.mts +122 -0
  470. package/foundation/integrations/shipped-imports.mjs +497 -0
  471. package/foundation/integrations/validate-contributions.d.mts +0 -17
  472. package/foundation/integrations/validate-contributions.mjs +59 -333
  473. package/foundation/render/assets.mjs +52 -7
  474. package/foundation/render/charts.d.mts +78 -27
  475. package/foundation/render/charts.mjs +266 -90
  476. package/foundation/render/embedded-files.d.mts +6 -0
  477. package/foundation/render/embedded-files.mjs +25 -5
  478. package/foundation/render/embedded-imports.d.mts +70 -7
  479. package/foundation/render/embedded-imports.mjs +132 -41
  480. package/foundation/render/file-header.d.mts +66 -0
  481. package/foundation/render/file-header.mjs +118 -0
  482. package/foundation/render/host-answer.d.mts +18 -0
  483. package/foundation/render/host-answer.mjs +46 -0
  484. package/foundation/render/host-exit.d.mts +1 -0
  485. package/foundation/render/host-exit.mjs +6 -1
  486. package/foundation/render/html-reader.d.mts +55 -2
  487. package/foundation/render/html-reader.mjs +145 -26
  488. package/foundation/render/layers.d.mts +30 -0
  489. package/foundation/render/layers.mjs +158 -0
  490. package/foundation/render/markup-edits.d.mts +57 -0
  491. package/foundation/render/markup-edits.mjs +182 -0
  492. package/foundation/render/offline.d.mts +32 -0
  493. package/foundation/render/offline.mjs +56 -0
  494. package/foundation/render/page-host.mjs +29 -12
  495. package/foundation/render/page-worker.mjs +354 -21
  496. package/foundation/render/picture-chrome.d.mts +4 -0
  497. package/foundation/render/picture-chrome.mjs +192 -0
  498. package/foundation/render/picture-playwright.d.mts +4 -0
  499. package/foundation/render/picture-playwright.mjs +46 -0
  500. package/foundation/render/rebuild.mjs +2 -1
  501. package/foundation/render/render-page.d.mts +79 -5
  502. package/foundation/render/render-page.mjs +735 -109
  503. package/foundation/render/source-block.d.mts +85 -6
  504. package/foundation/render/source-block.mjs +211 -20
  505. package/foundation/render/ts-paths.d.mts +69 -6
  506. package/foundation/render/ts-paths.mjs +326 -40
  507. package/foundation/response/error-codes.d.mts +3 -1
  508. package/foundation/response/error-codes.d.ts +1 -0
  509. package/foundation/response/error-codes.doc.mjs +12 -1
  510. package/foundation/response/error-codes.mjs +11 -1
  511. package/foundation/response/response-types.doc.mjs +6 -6
  512. package/foundation/suggest/name-index.d.mts +148 -0
  513. package/foundation/suggest/name-index.mjs +317 -0
  514. package/foundation/suggest/other-command.d.mts +140 -0
  515. package/foundation/suggest/other-command.mjs +756 -0
  516. package/foundation/text/compare-text.d.mts +14 -0
  517. package/foundation/text/compare-text.mjs +68 -0
  518. package/foundation/text/css-escape.d.mts +18 -0
  519. package/foundation/text/css-escape.mjs +35 -0
  520. package/foundation/text/entry-names.d.mts +14 -0
  521. package/foundation/text/entry-names.mjs +14 -0
  522. package/foundation/text/string-utils.d.mts +46 -6
  523. package/foundation/text/string-utils.mjs +118 -20
  524. package/foundation/text/suggest-order.d.mts +47 -4
  525. package/foundation/text/suggest-order.mjs +174 -5
  526. package/foundation/xle/browser.d.mts +2 -2
  527. package/foundation/xle/expand.mjs +2 -1
  528. package/host/index.mjs +8 -6
  529. package/package.json +7 -6
@@ -15,13 +15,17 @@
15
15
  import {createHash} from 'node:crypto';
16
16
  import * as fs from 'node:fs';
17
17
  import * as path from 'node:path';
18
- import {spawnSync} from 'node:child_process';
19
- import {fileURLToPath, pathToFileURL} from 'node:url';
18
+ import {spawn} from 'node:child_process';
19
+ import * as os from 'node:os';
20
+ import {fileURLToPath} from 'node:url';
20
21
  import {
21
22
  SAMPLE_PAGE,
22
23
  SHEET_ORDER,
23
24
  elementNames,
24
25
  pageSource,
26
+ bindingFrom,
27
+ SAMPLE_SEARCH_ITEMS,
28
+ SAMPLE_SOURCE,
25
29
  } from './_catalog.mjs';
26
30
  import {
27
31
  catalogVariants,
@@ -32,21 +36,31 @@ import {
32
36
  } from './_parts.mjs';
33
37
  import {OVERVIEW_SECTIONS} from './_overview.mjs';
34
38
  import {
35
- FOLDER_JUNK,
36
- folderIsEmpty,
37
39
  camel,
40
+ folderIsEmpty,
41
+ builtFontWeights,
38
42
  fontPackages,
39
43
  modesOf,
40
- themeFiles,
41
44
  shown,
45
+ themeFiles,
46
+ APP_COPY_BUILT,
47
+ appCopyNames,
42
48
  } from './_settings.mjs';
43
49
  import {writeWhole} from './_palette.mjs';
44
50
  import {cliVersion} from '../../foundation/release/run-context.mjs';
45
51
  import {importPathOf, installLine} from './_project.mjs';
46
- import {COLOR_PROP_PARTS, DIRECT, P, wordTable} from './_tables.mjs';
52
+ import {
53
+ COLOR_PROP_PARTS,
54
+ DIRECT,
55
+ P,
56
+ SHOWCASE_GROUPS,
57
+ wordTable,
58
+ } from './_tables.mjs';
47
59
  import {extractImportedPackages} from '../../foundation/discovery/template-needs.mjs';
48
60
  import {findNodeModulesPackage} from '../../foundation/fs/paths.mjs';
61
+ import {themeFileImports} from '../../foundation/discovery/theme-discovery.mjs';
49
62
  import {withListingCache} from '../../foundation/fs/listing-cache.mjs';
63
+ import {compareText} from '../../foundation/text/compare-text.mjs';
50
64
 
51
65
  const TEMPLATES_DIR = path.resolve(
52
66
  path.dirname(fileURLToPath(import.meta.url)),
@@ -54,17 +68,14 @@ const TEMPLATES_DIR = path.resolve(
54
68
  );
55
69
 
56
70
  /** The groups of the theme-building page, in order. */
57
- export const SHOWCASE_GROUPS = [
58
- 'actions',
59
- 'inputs',
60
- 'selection',
61
- 'navigation',
62
- 'feedback',
63
- 'data',
64
- 'containers',
65
- 'overlays',
66
- 'pages',
67
- ];
71
+ export {SHOWCASE_GROUPS};
72
+
73
+ /**
74
+ * Packages whose output is drawn in the browser once the page runs (a
75
+ * recharts chart measures and draws itself after it mounts): a server
76
+ * render, which the sheet is, has none of it.
77
+ */
78
+ const DRAWN_IN_BROWSER = Object.freeze(['recharts']);
68
79
 
69
80
  /** Real template pages the theme-building page shows in full. */
70
81
  const PAGE_TEMPLATES = ['dashboard', 'contact-form', 'settings'];
@@ -72,6 +83,9 @@ const PAGE_TEMPLATES = ['dashboard', 'contact-form', 'settings'];
72
83
  const SELECTION =
73
84
  /Select|Checkbox|Radio|Switch|Segmented|Toggle|Slider|Typeahead|Tokenizer/;
74
85
 
86
+ /** Props a doc names that open a part's own menu or list. */
87
+ const OPENERS = ['isMenuOpen', 'isDefaultOpen'];
88
+
75
89
  /**
76
90
  * The group a component belongs to on the theme-building page.
77
91
  * @param {string} name
@@ -98,7 +112,7 @@ function groupOf(name, category) {
98
112
  * whose packages the project has.
99
113
  * @param {import('./_project.mjs').ThemeProject} project
100
114
  * @param {string | undefined} group only this group
101
- * @returns {{items: import('./_catalog.mjs').CatalogItem[], imports: Record<string, string>, skipped: string[]}}
115
+ * @returns {{items: import('./_catalog.mjs').CatalogItem[], imports: Record<string, import('./_catalog.mjs').Binding>, skipped: string[], notes: string[]}}
102
116
  */
103
117
  export function showcaseItems(project, group) {
104
118
  /** @type {import('./_catalog.mjs').CatalogItem[]} */
@@ -117,13 +131,44 @@ export function showcaseItems(project, group) {
117
131
  if (!g) continue;
118
132
  const inParent = inParentOf(project, name);
119
133
  if (inParent === null) continue;
120
- for (const v of catalogVariants(project, name, 12, {shown: true}))
134
+ // A component no Core module exports by its name cannot be imported,
135
+ // so it would draw an empty cell: it gets none.
136
+ if (!importPathOf(project, name)) continue;
137
+ const info = project.components[name];
138
+ catalogVariants(project, name, 12, {shown: true}).forEach((v, i) =>
121
139
  items.push({
122
140
  group: g,
123
141
  name,
124
142
  label: v.label,
125
143
  tree: inParent({__element: name, props: v.props}),
126
- });
144
+ // An overlay shown open is drawn open: Core places a popover,
145
+ // tooltip or hover card only once it is mounted. Any other part, as
146
+ // first shown, is shown open with the overlays too when a press
147
+ // opens one from it (the page sees which: _catalog.mjs).
148
+ ...(info?.opens
149
+ ? {open: true}
150
+ : i === 0 && g !== 'overlays'
151
+ ? {
152
+ openable: true,
153
+ // A prop its doc names that opens it opens it; else the
154
+ // drawing's press does.
155
+ ...(OPENERS.some(p => info?.props?.[p])
156
+ ? {
157
+ openTree: inParent({
158
+ __element: name,
159
+ props: {
160
+ ...v.props,
161
+ [/** @type {string} */ (
162
+ OPENERS.find(p => info?.props?.[p])
163
+ )]: true,
164
+ },
165
+ }),
166
+ }
167
+ : {}),
168
+ }
169
+ : {}),
170
+ }),
171
+ );
127
172
  }
128
173
  items.push({
129
174
  group: 'pages',
@@ -133,7 +178,9 @@ export function showcaseItems(project, group) {
133
178
  });
134
179
  /** @type {string[]} */
135
180
  const skipped = [];
136
- /** @type {Record<string, string>} */
181
+ /** What a page in the sheet cannot show, said in the result. @type {string[]} */
182
+ const notes = [];
183
+ /** @type {Record<string, import('./_catalog.mjs').Binding>} */
137
184
  const templateImports = {};
138
185
  for (const t of PAGE_TEMPLATES) {
139
186
  const file = path.join(TEMPLATES_DIR, t, 'page.tsx');
@@ -148,8 +195,16 @@ export function showcaseItems(project, group) {
148
195
  );
149
196
  continue;
150
197
  }
198
+ const drawn = [...extractImportedPackages(src)].filter(pkg =>
199
+ DRAWN_IN_BROWSER.includes(pkg),
200
+ );
201
+ if (drawn.length && (!group || group === 'pages'))
202
+ notes.push(
203
+ `the ${t} page's charts are drawn in the browser (${drawn.join(', ')}), so sheet.html and its pictures show the page with their space empty; the in-app preview draws them (astryx experimental theme preview add --template ${t})`,
204
+ );
151
205
  const local = `Template_${t.replace(/-/g, '_')}`;
152
- templateImports[local] = `./templates/${t}.tsx`;
206
+ // A template page is its file's default export.
207
+ templateImports[local] = {from: `./templates/${t}.tsx`, export: 'default'};
153
208
  items.push({
154
209
  group: 'pages',
155
210
  name: `${t} template`,
@@ -161,10 +216,18 @@ export function showcaseItems(project, group) {
161
216
  const i = SHEET_ORDER.indexOf(it.name);
162
217
  return SHOWCASE_GROUPS.indexOf(it.group ?? '') * 1000 + (i < 0 ? 500 : i);
163
218
  };
219
+ // The overlays section also shows open each part another section holds
220
+ // that opens one (a dropdown's menu), and only open.
164
221
  const chosen = items
165
- .filter(it => !group || it.group === group)
166
- .sort((a, b) => order(a) - order(b) || a.name.localeCompare(b.name));
167
- /** @type {Record<string, string>} */
222
+ .flatMap(it =>
223
+ !group || it.group === group
224
+ ? [it]
225
+ : group === 'overlays' && it.openable
226
+ ? [{...it, onlyOpen: true}]
227
+ : [],
228
+ )
229
+ .sort((a, b) => order(a) - order(b) || compareText(a.name, b.name));
230
+ /** @type {Record<string, import('./_catalog.mjs').Binding>} */
168
231
  const imports = {};
169
232
  for (const n of elementNames(chosen.map(i => i.tree))) {
170
233
  if (templateImports[n]) {
@@ -178,6 +241,7 @@ export function showcaseItems(project, group) {
178
241
  items: chosen,
179
242
  imports,
180
243
  skipped: !group || group === 'pages' ? skipped : [],
244
+ notes,
181
245
  };
182
246
  }
183
247
 
@@ -226,12 +290,12 @@ function inParentOf(project, name) {
226
290
 
227
291
  /**
228
292
  * Template page modules the theme-building page imports, copied beside it.
229
- * @param {Record<string, string>} imports
293
+ * @param {Record<string, import('./_catalog.mjs').Binding>} imports
230
294
  * @returns {Array<{name: string, from: string}>}
231
295
  */
232
296
  function templateFiles(imports) {
233
- return Object.values(imports).flatMap(spec => {
234
- const m = /^\.\/templates\/([a-z0-9-]+)\.tsx$/.exec(spec);
297
+ return Object.values(imports).flatMap(b => {
298
+ const m = /^\.\/templates\/([a-z0-9-]+)\.tsx$/.exec(bindingFrom(b));
235
299
  return m
236
300
  ? [
237
301
  {
@@ -254,7 +318,23 @@ function templateFiles(imports) {
254
318
  * @returns {string[]}
255
319
  */
256
320
  export function baseFontsCss(ctx, data) {
257
- if (!data.like) return [];
321
+ const sheet = baseFontsSheet(ctx, data);
322
+ return sheet ? [sheet.spec] : [];
323
+ }
324
+
325
+ /**
326
+ * The base theme's fonts stylesheet as {@link baseFontsCss} imports it: its
327
+ * import spec, the families it loads, and the remote stylesheets it loads
328
+ * them from (a Google Fonts `@import`), which a static page cannot load.
329
+ * Null when the base ships none or the build names none of its families.
330
+ * @param {import('./_settings.mjs').Ctx} ctx
331
+ * @param {import('./_settings.mjs').ThemeData} data
332
+ * With the weights it loads of each family (`weights`, by family; none
333
+ * for a family whose weights it does not say, such as a variable face).
334
+ * @returns {{spec: string, families: string[], remote: string[], weights: Map<string, number[]>} | null}
335
+ */
336
+ export function baseFontsSheet(ctx, data) {
337
+ if (!data.like) return null;
258
338
  const pkg = `@astryxdesign/theme-${data.like}`;
259
339
  const sheet = `${pkg}/fonts.css`;
260
340
  // Read off disk: the package must export the sheet for an app to import
@@ -263,7 +343,7 @@ export function baseFontsCss(ctx, data) {
263
343
  /** @type {string} */
264
344
  let text;
265
345
  try {
266
- if (!found) return [];
346
+ if (!found) return null;
267
347
  const exportsMap = JSON.parse(
268
348
  fs.readFileSync(path.join(found.packageDir, 'package.json'), 'utf8'),
269
349
  ).exports;
@@ -272,10 +352,10 @@ export function baseFontsCss(ctx, data) {
272
352
  typeof exportsMap !== 'object' ||
273
353
  !('./fonts.css' in exportsMap)
274
354
  )
275
- return [];
355
+ return null;
276
356
  text = fs.readFileSync(path.join(found.packageDir, 'fonts.css'), 'utf8');
277
357
  } catch {
278
- return [];
358
+ return null;
279
359
  }
280
360
  // The families the sheet loads; with the theme's build at hand, the sheet
281
361
  // is imported only while the build still names one of them.
@@ -291,9 +371,101 @@ export function baseFontsCss(ctx, data) {
291
371
  }
292
372
  if (built != null && families.length) {
293
373
  const css = built;
294
- if (!families.some(f => css.includes(f))) return [];
374
+ if (!families.some(f => css.includes(f))) return null;
375
+ }
376
+ const remote = [
377
+ ...text.matchAll(
378
+ /@import\s+(?:url\(\s*)?["']?((?:[a-z]+:)?\/\/[^"')\s]+)/gi,
379
+ ),
380
+ ].map(m => m[1]);
381
+ // The weights a font service request names: its axes (`wght`,
382
+ // `ital,wght`, `opsz,wght`) and one tuple of values per face
383
+ // (`Figtree:wght@400;500`, `Fraunces:opsz,wght@9..144,400`), the weight
384
+ // at the wght axis's place in each tuple.
385
+ /** @type {Map<string, number[]>} */
386
+ const weights = new Map();
387
+ for (const m of text.matchAll(/family=([^:&'")]+):([a-z,]+)@([0-9;,.]+)/gi)) {
388
+ const family = decodeURIComponent(m[1].replace(/\+/g, ' '));
389
+ const at = m[2].toLowerCase().split(',').indexOf('wght');
390
+ if (at < 0) continue;
391
+ const values = m[3].split(';').map(t => t.split(',')[at] ?? '');
392
+ // A range (`100..900`) is a variable face: every weight in it.
393
+ if (values.some(v => v.includes('..'))) continue;
394
+ const list = values.map(Number).filter(n => Number.isInteger(n));
395
+ if (list.length)
396
+ weights.set(
397
+ family,
398
+ [...new Set(list)].sort((a, b) => a - b),
399
+ );
295
400
  }
296
- return [sheet];
401
+ return {spec: sheet, families, remote, weights};
402
+ }
403
+
404
+ /**
405
+ * The stylesheets of an installed font package that load the theme's
406
+ * fonts in every weight it uses: a variable package's one stylesheet
407
+ * (every weight); for a package with a stylesheet per weight, as
408
+ * Fontsource ships them, each weight the theme's build uses that the
409
+ * package has; else its index stylesheet.
410
+ * @param {import('./_settings.mjs').Ctx} ctx
411
+ * @param {string} slug
412
+ * @param {string} pkg
413
+ * @returns {string[]}
414
+ */
415
+ export function fontPackageSheets(ctx, slug, pkg) {
416
+ const index = `${pkg}/index.css`;
417
+ const faces = fontPackageWeights(ctx, pkg);
418
+ if (!faces?.length) return [index];
419
+ // Each weight the theme uses loads the face CSS font matching shows for
420
+ // it (550 shows the 600 face), once.
421
+ const shown = new Set(
422
+ (builtFontWeights(ctx, slug) ?? [400]).map(w => shownWeight(w, faces)),
423
+ );
424
+ return faces.filter(w => shown.has(w)).map(w => `${pkg}/${w}.css`);
425
+ }
426
+
427
+ /**
428
+ * The weights an installed font package has a stylesheet of its own for
429
+ * (`@fontsource/lobster/400.css`), as Fontsource ships a static family;
430
+ * null for a variable package or one with no stylesheet per weight, which
431
+ * loads every weight it has from its index stylesheet.
432
+ * @param {import('./_settings.mjs').Ctx} ctx
433
+ * @param {string} pkg
434
+ * @returns {number[] | null}
435
+ */
436
+ export function fontPackageWeights(ctx, pkg) {
437
+ if (pkg.startsWith('@fontsource-variable/')) return null;
438
+ const faces = [100, 200, 300, 400, 500, 600, 700, 800, 900].filter(w => {
439
+ try {
440
+ ctx.project.req.resolve(`${pkg}/${w}.css`);
441
+ return true;
442
+ } catch {
443
+ return false;
444
+ }
445
+ });
446
+ return faces.length ? faces : null;
447
+ }
448
+
449
+ /**
450
+ * The face a browser shows for a font weight among the weights a family
451
+ * loads, by CSS font matching: from 400 to 500, the weights up to 500
452
+ * first, then lighter, then heavier; below 400, lighter first; above 500,
453
+ * heavier first.
454
+ * @param {number} weight
455
+ * @param {number[]} faces
456
+ * @returns {number}
457
+ */
458
+ export function shownWeight(weight, faces) {
459
+ if (faces.includes(weight)) return weight;
460
+ const up = faces.filter(w => w > weight).sort((a, b) => a - b);
461
+ const down = faces.filter(w => w < weight).sort((a, b) => b - a);
462
+ const order =
463
+ weight >= 400 && weight <= 500
464
+ ? [...up.filter(w => w <= 500), ...down, ...up.filter(w => w > 500)]
465
+ : weight < 400
466
+ ? [...down, ...up]
467
+ : [...up, ...down];
468
+ return order[0] ?? weight;
297
469
  }
298
470
 
299
471
  /**
@@ -314,7 +486,7 @@ export function themeImports(ctx, slug, data, fromDir) {
314
486
  const modes = modesOf(data);
315
487
  const fonts = fontPackages(ctx, data)
316
488
  .filter(x => x.installed)
317
- .map(x => `${x.pkg}/index.css`);
489
+ .flatMap(x => fontPackageSheets(ctx, slug, x.pkg));
318
490
  return {
319
491
  module: rel(f.js),
320
492
  css: [rel(f.css), ...baseFontsCss(ctx, data), ...fonts],
@@ -538,11 +710,14 @@ export async function renderPreview(ctx, slug, data) {
538
710
  * @param {string} slug
539
711
  * @param {import('./_settings.mjs').ThemeData} data
540
712
  * @param {{group?: string, out?: string}} [options]
541
- * @returns {Promise<{file: string, components: number, skipped: string[]}>}
713
+ * @returns {Promise<{file: string, components: number, skipped: string[], notes: string[]}>} `notes`: what a page in the sheet cannot show
542
714
  */
543
715
  export async function renderSheet(ctx, slug, data, options = {}) {
544
716
  const {project} = ctx;
545
- const {items, imports, skipped} = showcaseItems(project, options.group);
717
+ const {items, imports, skipped, notes} = showcaseItems(
718
+ project,
719
+ options.group,
720
+ );
546
721
  const source = pageSource({
547
722
  items,
548
723
  imports,
@@ -562,6 +737,7 @@ export async function renderSheet(ctx, slug, data, options = {}) {
562
737
  file: shown(project.cwd, out),
563
738
  components: new Set(items.map(i => i.name)).size,
564
739
  skipped,
740
+ notes,
565
741
  };
566
742
  // Rendered from the same inputs before: the sheet is as it would be.
567
743
  if (renderedFrom(out, key)) return result;
@@ -578,6 +754,7 @@ export async function renderSheet(ctx, slug, data, options = {}) {
578
754
  file: shown(project.cwd, out),
579
755
  components: new Set(items.map(i => i.name)).size,
580
756
  skipped,
757
+ notes,
581
758
  };
582
759
  }
583
760
 
@@ -741,12 +918,11 @@ const SAFE = [
741
918
  ];
742
919
 
743
920
  /** The search source the page hands a part that needs one: a few fixed items. */
744
- const SAMPLE_SOURCE = [
921
+ const SAMPLE_SOURCE_LINES = [
745
922
  'const SAMPLE_ITEMS = [',
746
- " {id: 'design', label: 'Design'},",
747
- " {id: 'engineering', label: 'Engineering'},",
748
- " {id: 'research', label: 'Research'},",
749
- " {id: 'marketing', label: 'Marketing'},",
923
+ ...SAMPLE_SEARCH_ITEMS.map(
924
+ i => ` {id: ${JSON.stringify(i.id)}, label: ${JSON.stringify(i.label)}},`,
925
+ ),
750
926
  '];',
751
927
  'const SAMPLE_SOURCE = {',
752
928
  ' search: (query: string) => SAMPLE_ITEMS.filter(item => item.label.toLowerCase().includes(query.toLowerCase())),',
@@ -777,7 +953,7 @@ function withSources(project, v) {
777
953
  project.components[v.__element]?.props ?? {},
778
954
  ))
779
955
  if (p.required && p.type.startsWith('SearchSource') && !(k in props))
780
- props[k] = {__code: 'SAMPLE_SOURCE'};
956
+ props[k] = SAMPLE_SOURCE;
781
957
  return {
782
958
  ...v,
783
959
  props,
@@ -832,7 +1008,7 @@ function withHandlers(v) {
832
1008
  */
833
1009
  const usesSource = v =>
834
1010
  isCode(v)
835
- ? v.__code === 'SAMPLE_SOURCE'
1011
+ ? v.__code === SAMPLE_SOURCE.__code
836
1012
  : Boolean(v && typeof v === 'object') &&
837
1013
  Object.values(/** @type {object} */ (v)).some(usesSource);
838
1014
 
@@ -990,7 +1166,7 @@ function componentsPage(project, {theme = null, C}) {
990
1166
  '',
991
1167
  ...CELL,
992
1168
  '',
993
- ...(usesSource(items) ? [...SAMPLE_SOURCE, ''] : []),
1169
+ ...(usesSource(items) ? [...SAMPLE_SOURCE_LINES, ''] : []),
994
1170
  'export default function ComponentsPage() {',
995
1171
  ' return (',
996
1172
  ' <div>',
@@ -1303,7 +1479,9 @@ export function previewRouteSource({
1303
1479
  ' <AppShell',
1304
1480
  ' height="fill"',
1305
1481
  ' topNav={',
1306
- ` <TopNav label="Theme preview" heading={<strong>{${JSON.stringify(name)}}</strong>} endContent={`,
1482
+ // Core's own heading, as an app's top bar draws it, so a setting on the
1483
+ // header (its text color) shows here as it does in the app.
1484
+ ` <TopNav label="Theme preview" heading={<TopNavHeading heading={${JSON.stringify(name)}} />} endContent={`,
1307
1485
  ...(mode.length ? mode : [' null']),
1308
1486
  ' } />',
1309
1487
  ' }',
@@ -1328,7 +1506,7 @@ export function previewRouteSource({
1328
1506
  "import * as React from 'react';",
1329
1507
  "import {AppShell} from '@astryxdesign/core/AppShell';",
1330
1508
  "import {SideNav, SideNavItem} from '@astryxdesign/core/SideNav';",
1331
- "import {TopNav} from '@astryxdesign/core/TopNav';",
1509
+ "import {TopNav, TopNavHeading} from '@astryxdesign/core/TopNav';",
1332
1510
  ...(theme
1333
1511
  ? [
1334
1512
  // The mode switch only for a theme with both modes: an import the
@@ -1408,91 +1586,165 @@ export function previewRouteSource({
1408
1586
  /** @param {string} slug */
1409
1587
  const camelName = camel;
1410
1588
 
1589
+ /** The script that takes one picture through the project's Playwright. */
1590
+ const PLAYWRIGHT_PICTURE = fileURLToPath(
1591
+ new URL('../../foundation/render/picture-playwright.mjs', import.meta.url),
1592
+ );
1593
+
1594
+ /** The script that takes one picture through a Chrome or Chromium. */
1595
+ const CHROME_PICTURE = fileURLToPath(
1596
+ new URL('../../foundation/render/picture-chrome.mjs', import.meta.url),
1597
+ );
1598
+
1599
+ /** How long a stopped browser may take to close before it is killed. */
1600
+ const STOP_GRACE_MS = 5_000;
1601
+
1602
+ /** The signals that stop a picture run, the terminal closing among them. */
1603
+ const STOP_SIGNALS = /** @type {const} */ (['SIGINT', 'SIGTERM', 'SIGHUP']);
1604
+
1605
+ /** How long a browser may take for one picture before it is stopped. */
1606
+ const BROWSER_BOUND_MS = 60_000;
1607
+
1608
+ /**
1609
+ * What the pictures of one run share: the browsers that failed or hung,
1610
+ * each with its reason, so a later picture does not wait on them again.
1611
+ * @typedef {{failed: Map<string, string>}} PictureRun
1612
+ */
1613
+
1614
+ /** A new picture run. @returns {PictureRun} */
1615
+ export function newPictureRun() {
1616
+ return {failed: new Map()};
1617
+ }
1618
+
1411
1619
  /**
1412
- * A PNG of an HTML file, with a Playwright the project has installed, else
1413
- * a Chrome or Chromium found on the machine. Not ok with a reason when
1414
- * neither is there, or when one is there and fails: the reason then names
1415
- * its error.
1620
+ * A whole-page PNG of an HTML file, with a Playwright the project has
1621
+ * installed, else a Chrome or Chromium found on the machine. Each browser
1622
+ * gets its own time bound, and the next one its turn when one fails or
1623
+ * hangs. Not ok with a reason when none is there or every one failed: the
1624
+ * reason then names each one's real error. When a later browser took the
1625
+ * picture, `note` says why an earlier one did not.
1416
1626
  * @param {import('./_project.mjs').ThemeProject} project
1417
1627
  * @param {string} html absolute
1418
1628
  * @param {string} png absolute
1419
1629
  * @param {'light' | 'dark'} mode
1420
- * @returns {Promise<{ok: true, file: string, cut?: boolean} | {ok: false, reason: string}>} `cut` when the picture is of the window, not the whole page
1630
+ * @param {PictureRun} [run] what earlier pictures of the same run learned:
1631
+ * a browser that failed or hung there is not tried again
1632
+ * @returns {Promise<{ok: true, file: string, note?: string} | {ok: false, reason: string, stopped?: string}>}
1421
1633
  */
1422
- export async function screenshot(project, html, png, mode) {
1423
- /** What was found and why it could not take the picture. @type {string[]} */
1424
- const failed = [];
1425
- /** The first line of an error, with no path of this machine. @param {unknown} e */
1426
- const firstLine = e =>
1427
- String(/** @type {any} */ (e)?.message ?? e ?? '')
1634
+ export async function screenshot(
1635
+ project,
1636
+ html,
1637
+ png,
1638
+ mode,
1639
+ run = newPictureRun(),
1640
+ ) {
1641
+ /** What was tried and why it could not take the picture. @type {string[]} */
1642
+ const failed = [...run.failed.values()];
1643
+ /** Whether a Playwright was found without its own browser installed. */
1644
+ let pwMissing = false;
1645
+ /** Whether a Playwright was found at all. */
1646
+ let pwFound = false;
1647
+ /** A line with no path of this machine. @param {string} line */
1648
+ const local = line => line.split(project.cwd).join('.');
1649
+ /**
1650
+ * Why a browser did not take the picture: Playwright's first line names
1651
+ * only the call ("browserType.launch: Target … closed"); the cause, such
1652
+ * as a missing library, is in a later line, so that line comes too.
1653
+ * Chrome's startup warnings (dbus, GPU) are not a cause.
1654
+ * @param {string} text
1655
+ */
1656
+ const causeOf = text => {
1657
+ const lines = String(text ?? '')
1428
1658
  .split('\n')
1429
- .map(l => l.trim())
1430
- .find(Boolean)
1431
- ?.split(project.cwd)
1432
- .join('.') ?? 'it stopped with no message';
1659
+ .map(l => l.replace(/^[\s=<>-]+/, '').trim())
1660
+ .filter(Boolean);
1661
+ const head =
1662
+ meaningfulLine(lines.join('\n')) || 'it stopped with no message';
1663
+ const rest = lines
1664
+ .slice(lines.indexOf(head) + 1)
1665
+ .find(l =>
1666
+ /error|cannot|can't|missing|not found|while loading|no such|failed|denied/i.test(
1667
+ l,
1668
+ ),
1669
+ );
1670
+ return local(rest ? `${head} (${rest})` : head);
1671
+ };
1672
+ /** The browsers to try, in order: each a picture script and its args. */
1673
+ /** @type {Array<{who: string, script: string, args: string[]}>} */
1674
+ const tries = [];
1433
1675
  for (const pkg of ['playwright', 'playwright-core']) {
1434
- /** @type {string} */
1435
- let entry;
1436
1676
  try {
1437
- entry = project.req.resolve(pkg);
1677
+ const entry = project.req.resolve(pkg);
1678
+ pwFound = true;
1679
+ tries.push({
1680
+ who: `${pkg}'s own browser`,
1681
+ script: PLAYWRIGHT_PICTURE,
1682
+ args: [entry, html, png, mode],
1683
+ });
1684
+ break;
1438
1685
  } catch {
1439
- continue;
1440
- }
1441
- try {
1442
- const pw = await import(pathToFileURL(entry).href);
1443
- const chromium = pw.chromium ?? pw.default?.chromium;
1444
- const browser = await chromium.launch(
1445
- chromeBinary() ? {executablePath: chromeBinary()} : {},
1446
- );
1447
- try {
1448
- const page = await browser.newPage({
1449
- viewport: {width: 1280, height: 900},
1450
- colorScheme: mode,
1451
- });
1452
- await page.goto(pathToFileURL(html).href, {waitUntil: 'load'});
1453
- await page.screenshot({path: png, fullPage: true});
1454
- } finally {
1455
- await browser.close();
1456
- }
1457
- return {ok: true, file: shown(project.cwd, png)};
1458
- } catch (e) {
1459
- // This Playwright could not launch its browser: try Chrome directly.
1460
- failed.push(`${pkg}: ${firstLine(e)}`);
1686
+ // Not installed here.
1461
1687
  }
1462
1688
  }
1463
1689
  const chrome = chromeBinary();
1464
- if (chrome) {
1465
- const r = spawnSync(
1466
- chrome,
1467
- [
1468
- '--headless=new',
1469
- '--disable-gpu',
1470
- '--no-sandbox',
1471
- '--hide-scrollbars',
1472
- `--screenshot=${png}`,
1473
- '--window-size=1280,2400',
1474
- ...(mode === 'dark' ? ['--force-dark-mode'] : []),
1475
- pathToFileURL(html).href,
1476
- ],
1477
- {encoding: 'utf8', timeout: 60_000},
1478
- );
1479
- // Chrome alone takes the window, not the whole page.
1690
+ if (chrome)
1691
+ tries.push({
1692
+ who: chrome,
1693
+ script: CHROME_PICTURE,
1694
+ args: [chrome, html, png, mode],
1695
+ });
1696
+ for (const t of tries) {
1697
+ if (run.failed.has(t.who)) continue;
1698
+ const r = await runBrowser(t.script, t.args, BROWSER_BOUND_MS, {
1699
+ drop: [png],
1700
+ });
1701
+ if (r.stoppedBy)
1702
+ return {
1703
+ ok: false,
1704
+ stopped: r.stoppedBy,
1705
+ reason: `the pictures were stopped (${r.stoppedBy}) before the browser finished`,
1706
+ };
1707
+ if (r.noTemp)
1708
+ return {
1709
+ ok: false,
1710
+ reason: `no browser was started: the system temp folder cannot be written (${r.noTemp}), and a browser needs a profile folder of its own there; fix the temp folder (TMPDIR), then run the command again`,
1711
+ };
1480
1712
  if (r.status === 0 && fs.existsSync(png))
1481
- return {ok: true, file: shown(project.cwd, png), cut: true};
1482
- failed.push(
1483
- `${chrome}: ${firstLine(
1484
- r.error ??
1485
- (r.stderr ||
1486
- (r.signal
1487
- ? `stopped by ${r.signal}`
1488
- : `exit ${r.status}, and no picture was written`)),
1489
- )}`,
1490
- );
1713
+ return {
1714
+ ok: true,
1715
+ file: shown(project.cwd, png),
1716
+ ...(failed.length
1717
+ ? {
1718
+ note: `the picture was taken with ${t.who}; ${failed.join('; ')}`,
1719
+ }
1720
+ : {}),
1721
+ };
1722
+ const text = r.error ? String(r.error.message) : r.stderr;
1723
+ if (
1724
+ t.script === PLAYWRIGHT_PICTURE &&
1725
+ /Executable doesn't exist|playwright install/i.test(text)
1726
+ )
1727
+ pwMissing = true;
1728
+ const why = r.timedOut
1729
+ ? `${t.who} did not finish within ${BROWSER_BOUND_MS / 1000} seconds, so it was stopped`
1730
+ : `${t.who} could not take it: ${causeOf(text)}`;
1731
+ run.failed.set(t.who, why);
1732
+ failed.push(why);
1491
1733
  }
1492
1734
  if (failed.length)
1493
1735
  return {
1494
1736
  ok: false,
1495
- reason: `A browser was found, but it could not take the picture (${failed.join('; ')}). Give Playwright its browser (npx playwright install chromium), or check that ${chrome ?? 'Google Chrome or Chromium'} starts on this machine. The HTML preview needs neither.`,
1737
+ // Advice that can change the result: Playwright's browser only when
1738
+ // it is missing; a Chrome to check only when there is one.
1739
+ // What went wrong for this picture, and what can change it; the run
1740
+ // that asked for it says which pictures were and were not taken.
1741
+ reason: `${failed.join('; ')}. ${
1742
+ !pwFound
1743
+ ? `Install Playwright with its browser (${installLine(project.cwd, ['playwright'])}, then npx playwright install chromium), or`
1744
+ : pwMissing
1745
+ ? 'Give Playwright its browser (npx playwright install chromium), or'
1746
+ : "Fix what Playwright's browser needs (the reason is above), or"
1747
+ } ${chrome ? `check that ${chrome} starts on this machine` : 'install Google Chrome or Chromium'}. The HTML preview needs neither.`,
1496
1748
  };
1497
1749
  return {
1498
1750
  ok: false,
@@ -1515,11 +1767,23 @@ function chromeBinary() {
1515
1767
  'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
1516
1768
  'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
1517
1769
  ];
1518
- for (const f of fixed) if (fs.existsSync(f)) return f;
1770
+ // Only a file that runs: a folder or a file with no execute permission
1771
+ // by a browser's name is passed over, and the search goes on.
1772
+ /** @param {string} f */
1773
+ const runs = f => {
1774
+ try {
1775
+ if (!fs.statSync(f).isFile()) return false;
1776
+ if (process.platform !== 'win32') fs.accessSync(f, fs.constants.X_OK);
1777
+ return true;
1778
+ } catch {
1779
+ return false;
1780
+ }
1781
+ };
1782
+ for (const f of fixed) if (runs(f)) return f;
1519
1783
  for (const dir of (process.env.PATH ?? '').split(path.delimiter)) {
1520
1784
  for (const n of names) {
1521
1785
  const f = path.join(dir, n);
1522
- if (dir && fs.existsSync(f)) return f;
1786
+ if (dir && runs(f)) return f;
1523
1787
  }
1524
1788
  }
1525
1789
  return null;
@@ -1527,7 +1791,25 @@ function chromeBinary() {
1527
1791
 
1528
1792
  /** The first line of every file the editor writes into a theme's app copy. */
1529
1793
  export {APP_COPY_MARK} from './_marks.mjs';
1530
- import {APP_COPY_MARK} from './_marks.mjs';
1794
+ import {APP_COPY_MARK, appCopyMark} from './_marks.mjs';
1795
+ import {builtColorMode} from '../../foundation/discovery/theme-imports.mjs';
1796
+
1797
+ /**
1798
+ * The font stylesheets a theme's app copy imports, from the fonts the theme
1799
+ * loads now (an installed font package, the base theme's fonts).
1800
+ * @param {import('./_settings.mjs').Ctx} ctx
1801
+ * @param {string} slug
1802
+ * @param {import('./_settings.mjs').ThemeData} data
1803
+ * @returns {string[]}
1804
+ */
1805
+ export function copyFontsCss(ctx, slug, data) {
1806
+ return themeImports(
1807
+ ctx,
1808
+ slug,
1809
+ data,
1810
+ path.join(ctx.project.cwd, 'src', 'themes', slug),
1811
+ ).css.slice(1);
1812
+ }
1531
1813
 
1532
1814
  /**
1533
1815
  * The app's copy of an editor theme: a standard local theme in
@@ -1545,38 +1827,26 @@ import {APP_COPY_MARK} from './_marks.mjs';
1545
1827
  * @returns {string | null}
1546
1828
  */
1547
1829
  export function writeAppCopy(ctx, slug, data) {
1548
- return writeAppCopyAt(
1549
- ctx.project.cwd,
1550
- slug,
1551
- themeImports(
1552
- ctx,
1553
- slug,
1554
- data,
1555
- path.join(ctx.project.cwd, 'src', 'themes', slug),
1556
- ).css.slice(1),
1557
- );
1830
+ return writeAppCopyAt(ctx.project.cwd, slug, copyFontsCss(ctx, slug, data));
1558
1831
  }
1559
1832
 
1560
1833
  /**
1561
- * {@link writeAppCopy} with the font stylesheets given, or null to keep the
1562
- * copy's own (a compile, which changes no setting).
1834
+ * The files of a theme's app copy as the editor would write them now, by
1835
+ * name; null with no build to copy. Font stylesheets as given, or null for
1836
+ * the copy's own.
1563
1837
  * @param {string} cwd
1564
1838
  * @param {string} slug
1565
1839
  * @param {string[] | null} fontsCss
1566
- * @returns {string | null}
1840
+ * @returns {Record<string, string> | null}
1567
1841
  */
1568
- export function writeAppCopyAt(cwd, slug, fontsCss) {
1842
+ function appCopyFiles(cwd, slug, fontsCss) {
1569
1843
  const f = themeFiles(cwd, slug);
1570
1844
  const dir = path.join(cwd, 'src', 'themes', slug);
1571
1845
  const name = `${camel(slug)}Theme`;
1572
- const first = !fs.existsSync(path.join(dir, `${name}.doc.mjs`));
1573
1846
  if (!fs.existsSync(f.js) || !fs.existsSync(f.css)) return null;
1574
- // The copy's source, as the stable build's header names it.
1575
1847
  const source = `src/themes/${slug}/${name}.ts`;
1576
- // Only the editor's own copy is written over.
1577
- if (appCopyBlocker(cwd, slug) !== null) return null;
1578
1848
  const head = (/** @type {string} */ open, /** @type {string} */ close) =>
1579
- `${open} ${APP_COPY_MARK} after every build of themes/${slug}/; do not edit it here. Change the theme with the editor. ${close}\n`;
1849
+ `${open} ${appCopyMark(slug)} after every build of themes/${slug}/; do not edit it here. Change the theme with the editor. ${close}\n`;
1580
1850
  const keptFonts = path.join(dir, `${slug}.fonts.css`);
1581
1851
  const fonts =
1582
1852
  fontsCss ??
@@ -1598,27 +1868,115 @@ export function writeAppCopyAt(cwd, slug, fontsCss) {
1598
1868
  if (fs.existsSync(from))
1599
1869
  built[`${slug}${ext}`] = asBuilt(fs.readFileSync(from, 'utf8'));
1600
1870
  }
1871
+ // A light-only or dark-only theme's build exports its one color mode
1872
+ // (`colorModes`); the copy's source re-exports it, so a build of the copy
1873
+ // writes it too and `theme add` reads it.
1874
+ const oneMode = builtColorMode(f.js).mode;
1601
1875
  const files = {
1602
1876
  [`${name}.doc.mjs`]: `${head('//', '')}\n/** @type {import('@astryxdesign/cli/authoring').ThemeDoc} */\nexport default {\n type: 'theme',\n name: ${JSON.stringify(slug)},\n displayName: ${JSON.stringify(slug)},\n description: ${JSON.stringify(`The ${slug} theme, made with the theme editor (themes/${slug}/).`)},\n maintained: false,\n};\n`,
1603
- [`${name}.ts`]: `${head('//', '')}export {${name}} from './${slug}';\n`,
1877
+ [`${name}.ts`]: `${head('//', '')}export {${name}${oneMode ? ', colorModes' : ''}} from './${slug}';\n`,
1604
1878
  ...built,
1605
- ...(fonts.length
1606
- ? {
1607
- [`${slug}.fonts.css`]: `${head('/*', '*/')}${fonts.map(c => `@import ${JSON.stringify(c)};`).join('\n')}\n`,
1608
- }
1609
- : {}),
1879
+ // Always there, so the app theme module's import of it holds when the
1880
+ // theme's fonts change (none: a comment only).
1881
+ [`${slug}.fonts.css`]: fonts.length
1882
+ ? `${head('/*', '*/')}${fonts.map(c => `@import ${JSON.stringify(c)};`).join('\n')}\n`
1883
+ : `${head('/*', '*/')}/* No font stylesheets: no installed package loads the theme's fonts. A font the system does not have shows only once its package is installed (experimental theme editor show ${slug} names it). */\n`,
1610
1884
  };
1611
- fs.mkdirSync(dir, {recursive: true});
1885
+ return files;
1886
+ }
1887
+
1888
+ /**
1889
+ * Why a theme's app copy is behind its build, or null when it is current:
1890
+ * something in its way (appCopyStale), a copy file missing, or a file
1891
+ * whose content is not what the editor would write now.
1892
+ * @param {string} cwd
1893
+ * @param {string} slug
1894
+ * @param {string[] | null} [fontsCss] the font stylesheets the copy should
1895
+ * import now (null: the copy's own)
1896
+ * @returns {string | null}
1897
+ */
1898
+ export function appCopyBehind(cwd, slug, fontsCss = null) {
1899
+ const stale = appCopyStale(cwd, slug).appCopyStale;
1900
+ if (stale) return stale;
1901
+ const files = appCopyFiles(cwd, slug, fontsCss);
1902
+ if (!files) return null;
1903
+ const dir = path.join(cwd, 'src', 'themes', slug);
1904
+ if (!fs.existsSync(dir))
1905
+ return `the app copy in src/themes/${slug}/ is gone; the editor writes it again`;
1612
1906
  for (const [n, text] of Object.entries(files)) {
1613
- const file = path.join(dir, n);
1614
- if (fs.existsSync(file) && fs.readFileSync(file, 'utf8') === text) continue;
1615
- writeWhole(file, text);
1907
+ /** @type {string} */
1908
+ let now;
1909
+ try {
1910
+ now = fs.readFileSync(path.join(dir, n), 'utf8');
1911
+ } catch {
1912
+ return `src/themes/${slug}/${n} is missing from the app copy`;
1913
+ }
1914
+ // Line endings as a checkout writes them (CRLF on Windows) are the
1915
+ // same content, as the outputs check reads them.
1916
+ const lf = (/** @type {string} */ x) => x.replace(/\r\n/g, '\n');
1917
+ if (lf(now) !== lf(text))
1918
+ return `src/themes/${slug}/${n} is not the current build of themes/${slug}/`;
1616
1919
  }
1617
- // A file an earlier copy had (a font stylesheet no longer needed) goes;
1618
- // system files stay.
1619
- for (const n of fs.readdirSync(dir))
1620
- if (!(n in files) && !FOLDER_JUNK.has(n))
1621
- fs.rmSync(path.join(dir, n), {force: true});
1920
+ return null;
1921
+ }
1922
+
1923
+ /**
1924
+ * {@link writeAppCopy} with the font stylesheets given, or null to keep the
1925
+ * copy's own (a compile, which changes no setting).
1926
+ * @param {string} cwd
1927
+ * @param {string} slug
1928
+ * @param {string[] | null} fontsCss
1929
+ * @returns {string | null}
1930
+ */
1931
+ export function writeAppCopyAt(cwd, slug, fontsCss) {
1932
+ const f = themeFiles(cwd, slug);
1933
+ const dir = path.join(cwd, 'src', 'themes', slug);
1934
+ const name = `${camel(slug)}Theme`;
1935
+ const first = !fs.existsSync(path.join(dir, `${name}.doc.mjs`));
1936
+ if (!fs.existsSync(f.js) || !fs.existsSync(f.css)) return null;
1937
+ // Only the editor's own copy is written over.
1938
+ if (appCopyBlocker(cwd, slug) !== null) return null;
1939
+ const files = appCopyFiles(cwd, slug, fontsCss);
1940
+ if (!files) return null;
1941
+ const failKey = `${path.resolve(cwd)}\0${slug}`;
1942
+ try {
1943
+ fs.mkdirSync(dir, {recursive: true});
1944
+ for (const [n, text] of Object.entries(files)) {
1945
+ const file = path.join(dir, n);
1946
+ if (fs.existsSync(file) && fs.readFileSync(file, 'utf8') === text)
1947
+ continue;
1948
+ writeWhole(file, text);
1949
+ }
1950
+ // A copy's own file this build no longer writes goes; anything else in
1951
+ // the folder (yours, or the system's) stays as it is.
1952
+ for (const n of fs.readdirSync(dir))
1953
+ if (appCopyNames(slug).has(n) && !(n in files))
1954
+ fs.rmSync(path.join(dir, n), {force: true});
1955
+ } catch (e) {
1956
+ // A copy that cannot be written is said, with the system's reason;
1957
+ // the change itself stands.
1958
+ const code = /** @type {any} */ (e)?.code ?? 'error';
1959
+ // The folder that failed: the copy's, or a parent it could not be
1960
+ // made in.
1961
+ const failed = /** @type {any} */ (e)?.path
1962
+ ? path.resolve(String(/** @type {any} */ (e).path))
1963
+ : dir;
1964
+ const at = fs.existsSync(failed) ? failed : path.dirname(failed);
1965
+ const rel = path.relative(cwd, at).split(path.sep).join('/');
1966
+ const unwritable =
1967
+ code === 'EACCES' || code === 'EPERM' || code === 'EROFS';
1968
+ COPY_FAILED.set(failKey, {
1969
+ why: unwritable
1970
+ ? `${rel} is not writable (${code})`
1971
+ : code === 'ENOSPC'
1972
+ ? `the disk is full (${code})`
1973
+ : `${rel} could not be written (${code})`,
1974
+ // A folder that was not writable, to see whether it still is.
1975
+ ...(unwritable ? {folder: at} : {}),
1976
+ });
1977
+ return null;
1978
+ }
1979
+ COPY_FAILED.delete(failKey);
1622
1980
  // The first write is named in the command's result; later ones are not.
1623
1981
  if (first)
1624
1982
  FIRST_COPIES.set(
@@ -1633,13 +1991,30 @@ export function writeAppCopyAt(cwd, slug, fontsCss) {
1633
1991
  }
1634
1992
 
1635
1993
  /**
1636
- * Why the editor will not write a theme's app copy, or null when it will:
1637
- * the folder is not there yet, or its descriptor carries the editor's mark
1638
- * and it holds only the copy's own files (system files such as .DS_Store
1639
- * aside). Otherwise the name of what is in the way (a file of yours), or
1640
- * the folder itself when it is not the editor's copy. Built bytes are not
1641
- * compared, so a stable rebuild of the copy leaves it the editor's. The one
1642
- * test the copy's writer and `wiring` both use.
1994
+ * The note for a copy a file of yours keeps from being written, as a
1995
+ * result field: `{appCopyStale}` when one does, else nothing.
1996
+ * @param {string} cwd
1997
+ * @param {string} slug
1998
+ * @returns {{appCopyStale?: string}}
1999
+ */
2000
+ export function appCopyStale(cwd, slug) {
2001
+ const blocker = appCopyBlocker(cwd, slug) ?? copyFailure(cwd, slug) ?? null;
2002
+ return blocker
2003
+ ? {
2004
+ appCopyStale: `the app copy in src/themes/${slug}/ was not updated: ${blocker}. The app keeps the theme as it was until that is out of the way; then any set or show writes it.`,
2005
+ }
2006
+ : {};
2007
+ }
2008
+
2009
+ /**
2010
+ * Why the editor will not write a theme's app copy, or null when it will.
2011
+ * Only a file of yours AT one of the copy's names stops it: a descriptor,
2012
+ * source or font stylesheet without the editor's mark, or any copy file
2013
+ * while the descriptor is not the editor's. Other files there (a note, a
2014
+ * swap file, desktop.ini) are left as they are and the copy is written
2015
+ * around them. Built bytes are not compared, so a stable rebuild of the
2016
+ * copy leaves it the editor's. The one test the copy's writer, the change
2017
+ * results and `wiring` use. Returns the file in the way.
1643
2018
  * @param {string} cwd
1644
2019
  * @param {string} slug
1645
2020
  * @returns {string | null}
@@ -1648,36 +2023,129 @@ export function appCopyBlocker(cwd, slug) {
1648
2023
  const dir = path.join(cwd, 'src', 'themes', slug);
1649
2024
  const name = `${camel(slug)}Theme`;
1650
2025
  const rel = path.relative(cwd, dir).split(path.sep).join('/');
2026
+ // The copy carries the built module whole, and a local theme imports
2027
+ // only files of its own folder: a module that imports a file beside it
2028
+ // (an icon registry of the theme's folder) would break in the app.
2029
+ {
2030
+ const built = themeFiles(cwd, slug).js;
2031
+ /** @type {string[]} */
2032
+ let specifiers;
2033
+ try {
2034
+ specifiers = themeFileImports(built);
2035
+ } catch {
2036
+ specifiers = [];
2037
+ }
2038
+ const local = specifiers.find(s => s.startsWith('.'));
2039
+ if (local)
2040
+ return `themes/${slug}/${path.basename(built)} imports ${local}, a file beside the theme, which the copy cannot carry (a local theme imports only files of its own folder); import it from a package instead`;
2041
+ }
2042
+ // Nothing is written through a link on the way from the app to the copy
2043
+ // (src/, src/themes/, the copy's folder), as for themes/.
2044
+ for (const part of ['src', 'src/themes', rel]) {
2045
+ try {
2046
+ const st = fs.lstatSync(path.join(cwd, part));
2047
+ if (st.isSymbolicLink())
2048
+ return `${part} is a link (to ${fs.readlinkSync(path.join(cwd, part))}), and the editor writes nothing through a link`;
2049
+ // A file where a folder on the way goes: nothing is half-written.
2050
+ if (!st.isDirectory())
2051
+ return part === rel
2052
+ ? `${rel} is a file, where the copy's folder goes`
2053
+ : `${part} is a file, where a folder on the way to the copy goes`;
2054
+ } catch {
2055
+ break;
2056
+ }
2057
+ }
2058
+ try {
2059
+ if (!fs.lstatSync(dir).isDirectory())
2060
+ return `${rel} is a file, where the copy's folder goes`;
2061
+ } catch {
2062
+ // Not there yet: the copy makes it.
2063
+ }
1651
2064
  if (folderIsEmpty(dir)) return null;
1652
2065
  /** @type {string[]} */
1653
2066
  let names;
1654
2067
  try {
1655
2068
  names = fs.readdirSync(dir);
1656
- } catch {
1657
- return rel;
2069
+ } catch (e) {
2070
+ return `${rel} cannot be read (${/** @type {any} */ (e)?.code ?? 'error'})`;
1658
2071
  }
1659
- /** @type {boolean} */
1660
- let marked;
1661
- try {
1662
- marked = fs
1663
- .readFileSync(path.join(dir, `${name}.doc.mjs`), 'utf8')
1664
- .includes(APP_COPY_MARK);
1665
- } catch {
1666
- marked = false;
1667
- }
1668
- if (!marked) return rel;
1669
- const own = new Set([
1670
- `${name}.doc.mjs`,
1671
- `${name}.ts`,
1672
- `${slug}.fonts.css`,
1673
- ...APP_COPY_BUILT.map(ext => `${slug}${ext}`),
1674
- ]);
1675
- const other = names.find(n => !own.has(n) && !FOLDER_JUNK.has(n));
1676
- return other ? `${rel}/${other}` : null;
2072
+ /** @param {string} n */
2073
+ const marked = n => {
2074
+ try {
2075
+ return fs.readFileSync(path.join(dir, n), 'utf8').includes(APP_COPY_MARK);
2076
+ } catch {
2077
+ return false;
2078
+ }
2079
+ };
2080
+ const own = appCopyNames(slug);
2081
+ const present = names.filter(n => own.has(n));
2082
+ // A link at a copy name is never written through or replaced.
2083
+ for (const n of present)
2084
+ try {
2085
+ const st = fs.lstatSync(path.join(dir, n));
2086
+ if (st.isSymbolicLink())
2087
+ return `${rel}/${n} is a link (to ${fs.readlinkSync(path.join(dir, n))}), at a name the copy uses, and the editor writes nothing through a link`;
2088
+ if (st.isDirectory())
2089
+ return `${rel}/${n} is a folder, at a name the copy uses for a file`;
2090
+ } catch {
2091
+ // Gone since it was listed.
2092
+ }
2093
+ // The copy is the editor's when any of its marked files carries the
2094
+ // mark (one of them deleted is written back); then only a marked name
2095
+ // without the mark is yours.
2096
+ const markedNames = [`${name}.doc.mjs`, `${name}.ts`, `${slug}.fonts.css`];
2097
+ // A build output of the copy's source carries the build's own header.
2098
+ const generated = (/** @type {string} */ n) => {
2099
+ try {
2100
+ return /@generated by `astryx theme build`/.test(
2101
+ fs.readFileSync(path.join(dir, n), 'utf8').slice(0, 600),
2102
+ );
2103
+ } catch {
2104
+ return false;
2105
+ }
2106
+ };
2107
+ const ours =
2108
+ markedNames.some(n => present.includes(n) && marked(n)) ||
2109
+ (present.length > 0 &&
2110
+ present.every(n => !markedNames.includes(n) && generated(n)));
2111
+ const foreign = ours
2112
+ ? present.find(n => markedNames.includes(n) && !marked(n))
2113
+ : present[0];
2114
+ return foreign
2115
+ ? `${rel}/${foreign} is yours, at a name the copy uses, and the editor never writes over your files`
2116
+ : null;
1677
2117
  }
1678
2118
 
1679
- /** The build outputs of a theme, by their ending after `<theme>`. */
1680
- const APP_COPY_BUILT = ['.css', '.css.d.ts', '.js', '.d.ts', '.variants.d.ts'];
2119
+ /**
2120
+ * Why the last write of a theme's app copy failed, by app and theme, and
2121
+ * the folder that was not writable when that was why.
2122
+ * @type {Map<string, {why: string, folder?: string}>}
2123
+ */
2124
+ const COPY_FAILED = new Map();
2125
+
2126
+ /**
2127
+ * Why the last write of a theme's app copy failed, while that still holds:
2128
+ * a folder that was not writable and is now is no reason any more (a
2129
+ * process that runs several commands, as an API caller does, reads the
2130
+ * folder as it is now).
2131
+ * @param {string} cwd
2132
+ * @param {string} slug
2133
+ * @returns {string | null}
2134
+ */
2135
+ function copyFailure(cwd, slug) {
2136
+ const key = `${path.resolve(cwd)}\0${slug}`;
2137
+ const failed = COPY_FAILED.get(key);
2138
+ if (!failed) return null;
2139
+ if (failed.folder)
2140
+ try {
2141
+ fs.accessSync(failed.folder, fs.constants.W_OK);
2142
+ COPY_FAILED.delete(key);
2143
+ return null;
2144
+ } catch {
2145
+ // Still not writable.
2146
+ }
2147
+ return failed.why;
2148
+ }
1681
2149
 
1682
2150
  /** App copies written for the first time in this process, by app and theme. @type {Map<string, string[]>} */
1683
2151
  const FIRST_COPIES = new Map();
@@ -1695,3 +2163,164 @@ export function takeFirstAppCopy(cwd, slug) {
1695
2163
  FIRST_COPIES.delete(key);
1696
2164
  return wrote;
1697
2165
  }
2166
+
2167
+ /**
2168
+ * Run a picture script (one browser, one picture) as its own process group,
2169
+ * without blocking this process. The one owner of every browser run:
2170
+ * - a temp folder of its own (TMPDIR, TMP, TEMP), where the browser keeps
2171
+ * its profile; with none to make, nothing runs (`noTemp`);
2172
+ * - a time bound (`timedOut`);
2173
+ * - a stop (SIGINT, SIGTERM, SIGHUP) that reaches the run stops it
2174
+ * (`stoppedBy`), then ends this process as the stop would have.
2175
+ * A stop or the bound asks the whole group to close, waits for it (killing
2176
+ * it past a short grace), then removes the temp folder and the `drop` files
2177
+ * (a picture part a stopped run leaves); a run that ends on its own removes
2178
+ * the temp folder only.
2179
+ * @param {string} script a picture script
2180
+ * @param {string[]} args
2181
+ * @param {number} [bound] milliseconds before the run is stopped
2182
+ * @param {{drop?: string[]}} [opts]
2183
+ * @returns {Promise<{status: number | null, signal: string | null, stderr: string, error?: Error, stoppedBy?: string, timedOut?: boolean, noTemp?: string}>}
2184
+ */
2185
+ export function runBrowser(script, args, bound = BROWSER_BOUND_MS, opts = {}) {
2186
+ const drop = opts.drop ?? [];
2187
+ /** @type {string} */
2188
+ let temp;
2189
+ try {
2190
+ temp = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-browser-'));
2191
+ } catch (e) {
2192
+ return Promise.resolve({
2193
+ status: null,
2194
+ signal: null,
2195
+ stderr: '',
2196
+ noTemp: String(/** @type {any} */ (e)?.code ?? e),
2197
+ });
2198
+ }
2199
+ return new Promise(resolve => {
2200
+ let stderr = '';
2201
+ const posix = process.platform !== 'win32';
2202
+ const child = spawn(process.execPath, [script, ...args], {
2203
+ stdio: ['ignore', 'ignore', 'pipe'],
2204
+ env: {...process.env, TMPDIR: temp, TMP: temp, TEMP: temp},
2205
+ // A group of its own, so a stop reaches the browser it starts too.
2206
+ detached: posix,
2207
+ });
2208
+ /** @param {NodeJS.Signals} sig */
2209
+ const signalAll = sig => {
2210
+ try {
2211
+ if (posix && child.pid) process.kill(-child.pid, sig);
2212
+ else child.kill(sig);
2213
+ } catch {
2214
+ // Gone already.
2215
+ }
2216
+ };
2217
+ const closed = new Promise(done => child.once('close', done));
2218
+ /** @param {string[]} files */
2219
+ const remove = files => {
2220
+ for (const f of files)
2221
+ try {
2222
+ fs.rmSync(f, {recursive: true, force: true});
2223
+ } catch {
2224
+ // Gone already.
2225
+ }
2226
+ };
2227
+ /** The temp folder goes on every way out; `drop` only with a stop. */
2228
+ const clean = () => remove([temp]);
2229
+ /** Close the group (killed past the grace), then clean up. */
2230
+ const finish = async () => {
2231
+ signalAll('SIGTERM');
2232
+ const grace = new Promise(done =>
2233
+ setTimeout(done, STOP_GRACE_MS).unref(),
2234
+ );
2235
+ if ((await Promise.race([closed.then(() => true), grace])) !== true) {
2236
+ signalAll('SIGKILL');
2237
+ await closed;
2238
+ }
2239
+ remove([temp, ...drop]);
2240
+ };
2241
+ // This process ending some other way: the group is killed, and the temp
2242
+ // folder and the unfinished files removed, as far as an exit allows.
2243
+ const onExit = () => {
2244
+ signalAll('SIGKILL');
2245
+ remove([temp, ...drop]);
2246
+ };
2247
+ process.once('exit', onExit);
2248
+ child.stderr?.setEncoding('utf8');
2249
+ child.stderr?.on('data', d => {
2250
+ if (stderr.length < 8000) stderr += d;
2251
+ });
2252
+ /** Set once the run is being stopped (bound, signal): it ends there. */
2253
+ let stopping = false;
2254
+ let settled = false;
2255
+ /** @param {Awaited<ReturnType<typeof runBrowser>>} out */
2256
+ const settle = out => {
2257
+ if (settled) return;
2258
+ settled = true;
2259
+ clearTimeout(timer);
2260
+ process.removeListener('exit', onExit);
2261
+ for (const sig of STOP_SIGNALS) process.removeListener(sig, onStop);
2262
+ resolve(out);
2263
+ };
2264
+ const timer = setTimeout(() => {
2265
+ stopping = true;
2266
+ void finish().then(() =>
2267
+ settle({status: null, signal: null, stderr, timedOut: true}),
2268
+ );
2269
+ }, bound);
2270
+ /** @param {NodeJS.Signals} sig */
2271
+ const onStop = async sig => {
2272
+ stopping = true;
2273
+ for (const s of STOP_SIGNALS) process.removeListener(s, onStop);
2274
+ // A second stop during the grace does not wait for it: the group is
2275
+ // killed and the files removed at once, then the process ends.
2276
+ /** @param {NodeJS.Signals} again */
2277
+ const onAgain = again => {
2278
+ for (const s of STOP_SIGNALS) process.removeListener(s, onAgain);
2279
+ signalAll('SIGKILL');
2280
+ remove([temp, ...drop]);
2281
+ if (process.listenerCount(again) === 0)
2282
+ process.kill(process.pid, again);
2283
+ };
2284
+ for (const s of STOP_SIGNALS) process.once(s, onAgain);
2285
+ await finish();
2286
+ for (const s of STOP_SIGNALS) process.removeListener(s, onAgain);
2287
+ settle({status: null, signal: null, stderr, stoppedBy: sig});
2288
+ // Nothing else listening: the stop ends this process, as it would
2289
+ // have without this listener.
2290
+ if (process.listenerCount(sig) === 0) process.kill(process.pid, sig);
2291
+ };
2292
+ for (const sig of STOP_SIGNALS) process.once(sig, onStop);
2293
+ child.once('error', error => {
2294
+ clean();
2295
+ settle({status: null, signal: null, stderr, error});
2296
+ });
2297
+ child.once('close', (status, signal) => {
2298
+ if (stopping) return;
2299
+ clean();
2300
+ settle({status, signal, stderr});
2301
+ });
2302
+ });
2303
+ }
2304
+
2305
+ /**
2306
+ * The first stderr line that says something about the picture: Chrome's
2307
+ * startup warnings (dbus, GPU, sandbox notices) come first on Linux and
2308
+ * say nothing about why no picture was written.
2309
+ * @param {string} text
2310
+ */
2311
+ export function meaningfulLine(text) {
2312
+ const lines = String(text ?? '')
2313
+ .split(/\r?\n/)
2314
+ .map(l => l.trim())
2315
+ .filter(Boolean);
2316
+ return (
2317
+ lines.find(
2318
+ l =>
2319
+ !/dbus|bus\.cc|gpu_|gl_|sandbox|fontconfig|crashpad|DevTools listening|WARNING:/i.test(
2320
+ l,
2321
+ ),
2322
+ ) ??
2323
+ lines[0] ??
2324
+ ''
2325
+ );
2326
+ }