@astryxdesign/cli 0.7.16 → 0.7.17-canary.g0135e03

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 (369) hide show
  1. package/README.md +76 -86
  2. package/api/build/_adapter.d.mts +12 -0
  3. package/api/build/_adapter.mjs +51 -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 +4 -3
  7. package/api/build/build.type.d.mts +2 -2
  8. package/api/build/build.type.mjs +3 -3
  9. package/api/build/kit/kind.d.mts +2 -1
  10. package/api/build/kit/kind.mjs +199 -10
  11. package/api/build/kit/kit.mjs +6 -4
  12. package/api/build/kit/rank.d.mts +4 -2
  13. package/api/build/kit/rank.mjs +125 -24
  14. package/api/build/kit/start.d.mts +5 -4
  15. package/api/build/kit/start.mjs +12 -8
  16. package/api/build/kit/weights.d.mts +39 -3
  17. package/api/build/kit/weights.json +1 -1
  18. package/api/build/kit/weights.mjs +340 -43
  19. package/api/build/kit/word-model.d.mts +23 -0
  20. package/api/build/kit/word-model.mjs +46 -0
  21. package/api/build/kit/words.d.mts +48 -0
  22. package/api/build/kit/words.mjs +90 -1
  23. package/api/component/__fixtures__/resolutions/modules.txt +4 -5
  24. package/api/component/list/list.d.mts +1 -1
  25. package/api/component/list/list.mjs +48 -6
  26. package/api/discover/_adapter.d.mts +1 -1
  27. package/api/discover/search/search.mjs +3 -2
  28. package/api/docs/_adapter.d.mts +26 -2
  29. package/api/docs/_adapter.mjs +219 -6
  30. package/api/docs/docs.d.mts +3 -0
  31. package/api/docs/docs.doc.mjs +7 -1
  32. package/api/docs/docs.mjs +12 -0
  33. package/api/docs/docs.type.d.mts +5 -0
  34. package/api/docs/docs.type.mjs +2 -0
  35. package/api/docs/node/node.mjs +1 -1
  36. package/api/doctor/_adapter.d.mts +27 -5
  37. package/api/doctor/_adapter.mjs +83 -10
  38. package/api/doctor/built-checks.mjs +40 -14
  39. package/api/doctor/doctor.d.mts +4 -3
  40. package/api/doctor/doctor.mjs +14 -7
  41. package/api/doctor/theme-checks.mjs +121 -17
  42. package/api/icon/_records.mjs +2 -1
  43. package/api/index.d.mts +2 -0
  44. package/api/index.mjs +2 -0
  45. package/api/integration/_adapter.d.mts +44 -0
  46. package/api/integration/_adapter.mjs +77 -1
  47. package/api/integration/authoring-checks.mjs +6 -6
  48. package/api/integration/example-scope.d.mts +14 -0
  49. package/api/integration/example-scope.mjs +44 -0
  50. package/api/integration/example-scope.type.d.mts +29 -0
  51. package/api/integration/example-scope.type.mjs +25 -0
  52. package/api/integration/integrationExampleScope.doc.d.mts +11 -0
  53. package/api/integration/integrationExampleScope.doc.mjs +59 -0
  54. package/api/integration/validate-integration.mjs +19 -1
  55. package/api/integration/validate-integration.type.d.mts +9 -0
  56. package/api/integration/validate-integration.type.mjs +1 -1
  57. package/api/integration/validateIntegration.doc.mjs +1 -1
  58. package/api/render/_adapter.mjs +591 -195
  59. package/api/render/render.doc.mjs +11 -3
  60. package/api/render/render.type.d.mts +52 -0
  61. package/api/render/render.type.mjs +31 -1
  62. package/api/search/ORDERING.md +1 -1
  63. package/api/search/_adapter.d.mts +9 -0
  64. package/api/search/_adapter.mjs +85 -0
  65. package/api/search/_candidate-score.mjs +51 -32
  66. package/api/search/_fit-order.mjs +3 -3
  67. package/api/search/_gather-components.d.mts +3 -2
  68. package/api/search/_gather-components.mjs +12 -3
  69. package/api/search/_lexical.d.mts +5 -0
  70. package/api/search/_lexical.mjs +8 -2
  71. package/api/search/_result.d.mts +11 -9
  72. package/api/search/_result.mjs +4 -4
  73. package/api/search/_score.d.mts +6 -1
  74. package/api/search/_score.mjs +15 -3
  75. package/api/search/search-index.mjs +7 -1
  76. package/api/search/search.d.mts +1 -1
  77. package/api/theme/_adapter.mjs +12 -1
  78. package/api/theme/build/build.d.mts +122 -1
  79. package/api/theme/build/build.mjs +412 -84
  80. package/api/theme/build/core-interception.d.mts +10 -0
  81. package/api/theme/build/core-interception.mjs +10 -0
  82. package/api/theme/build/font-warning.d.mts +23 -3
  83. package/api/theme/build/font-warning.mjs +54 -5
  84. package/api/theme/build/icon-imports.mjs +25 -2
  85. package/api/theme/theme.type.d.mts +10 -0
  86. package/api/theme/theme.type.mjs +7 -1
  87. package/api/theme-edit/_adapter.d.mts +103 -3
  88. package/api/theme-edit/_adapter.mjs +961 -82
  89. package/api/theme-edit/_catalog.mjs +19 -4
  90. package/api/theme-edit/_check.d.mts +63 -24
  91. package/api/theme-edit/_check.mjs +2467 -362
  92. package/api/theme-edit/_color.d.mts +10 -0
  93. package/api/theme-edit/_color.mjs +49 -1
  94. package/api/theme-edit/_compiler.mjs +89 -6
  95. package/api/theme-edit/_context.d.mts +3 -3
  96. package/api/theme-edit/_context.mjs +165 -54
  97. package/api/theme-edit/_css.d.mts +14 -0
  98. package/api/theme-edit/_css.mjs +46 -1
  99. package/api/theme-edit/_edit.d.mts +31 -4
  100. package/api/theme-edit/_edit.mjs +2433 -204
  101. package/api/theme-edit/_how-commands.d.mts +72 -1
  102. package/api/theme-edit/_how-commands.mjs +759 -9
  103. package/api/theme-edit/_how-question.d.mts +82 -5
  104. package/api/theme-edit/_how-question.mjs +6473 -553
  105. package/api/theme-edit/_how.d.mts +2 -1
  106. package/api/theme-edit/_how.mjs +237 -41
  107. package/api/theme-edit/_marks.d.mts +31 -5
  108. package/api/theme-edit/_marks.mjs +57 -5
  109. package/api/theme-edit/_name-rule.d.mts +11 -0
  110. package/api/theme-edit/_name-rule.mjs +12 -0
  111. package/api/theme-edit/_normal.d.mts +292 -0
  112. package/api/theme-edit/_normal.mjs +1454 -0
  113. package/api/theme-edit/_palette.mjs +10 -4
  114. package/api/theme-edit/_part-words.d.mts +31 -0
  115. package/api/theme-edit/_part-words.mjs +126 -0
  116. package/api/theme-edit/_parts.d.mts +18 -1
  117. package/api/theme-edit/_parts.mjs +246 -23
  118. package/api/theme-edit/_preview-app.d.mts +7 -1
  119. package/api/theme-edit/_preview-app.mjs +776 -187
  120. package/api/theme-edit/_preview.d.mts +100 -14
  121. package/api/theme-edit/_preview.mjs +582 -139
  122. package/api/theme-edit/_project.d.mts +4 -0
  123. package/api/theme-edit/_project.mjs +3 -1
  124. package/api/theme-edit/_settings.d.mts +417 -42
  125. package/api/theme-edit/_settings.mjs +3262 -424
  126. package/api/theme-edit/_tables.d.mts +15 -0
  127. package/api/theme-edit/_tables.mjs +63 -1
  128. package/api/theme-edit/_vet.d.mts +20 -0
  129. package/api/theme-edit/_vet.mjs +47 -2
  130. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  131. package/api/theme-edit/theme-edit.type.mjs +4 -1
  132. package/api/theme-edit/themeEditHow.doc.mjs +1 -1
  133. package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
  134. package/api/theme-edit/themeEditNew.doc.mjs +7 -4
  135. package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
  136. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
  137. package/api/upgrade/run/run.mjs +4 -3
  138. package/assets/codemods/integration-discovery.mjs +2 -1
  139. package/assets/codemods/run-codemod.mjs +87 -7
  140. package/assets/codemods/transforms/next/index.mjs +11 -1
  141. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  142. package/assets/component-list.generated.json +1 -0
  143. package/assets/docs/author-a-theme.doc.mjs +1 -0
  144. package/assets/docs/theme.doc.dense.mjs +2 -2
  145. package/assets/docs/theme.doc.mjs +1 -1
  146. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  147. package/assets/docs/tree/checks.doc.mjs +1 -1
  148. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  149. package/assets/docs/tree/render-pages.doc.mjs +44 -3
  150. package/assets/docs/tree/single-component.doc.mjs +4 -0
  151. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  152. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  153. package/assets/docs/use-a-theme.doc.mjs +1 -1
  154. package/assets/docs.generated.json +2 -2
  155. package/assets/search-catalog.generated.json +2 -0
  156. package/assets/self-audit.generated.json +1 -1
  157. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  158. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  159. package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
  160. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  161. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  162. package/assets/templates/components.generated.json +1 -1
  163. package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
  164. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +5 -1
  165. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  166. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  167. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  168. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  169. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  170. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  171. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  172. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  173. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  174. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  175. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  176. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  177. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  178. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  179. package/assets/templates/pages/editor/template.doc.mjs +2 -8
  180. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  181. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  182. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  183. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  184. package/assets/templates/pages/ide/page.tsx +24 -2
  185. package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
  186. package/assets/templates/pages/library/template.doc.mjs +4 -1
  187. package/assets/templates/pages/login/template.doc.mjs +2 -1
  188. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  189. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  190. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  191. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  192. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  193. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  194. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  195. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  196. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  197. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  198. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  199. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  200. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  201. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  202. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  203. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  204. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
  205. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  206. package/assets/theme.template.ts +6 -0
  207. package/authoring/debug/parse.d.mts +3 -3
  208. package/authoring/doctypes/_schema.d.mts +3 -3
  209. package/authoring/doctypes/command/command.doc.mjs +1 -1
  210. package/authoring/doctypes/component/categories.d.mts +37 -0
  211. package/authoring/doctypes/component/categories.mjs +54 -0
  212. package/authoring/doctypes/template/template.doc.mjs +1 -1
  213. package/authoring/doctypes/template/type.ts +9 -0
  214. package/authoring/example/example.doc.d.mts +12 -0
  215. package/authoring/example/example.doc.mjs +69 -0
  216. package/authoring/example/preview.d.mts +92 -0
  217. package/authoring/example/preview.mjs +994 -0
  218. package/authoring/example/type.ts +102 -0
  219. package/authoring/index.d.mts +1 -0
  220. package/authoring/index.d.ts +12 -0
  221. package/authoring/index.mjs +3 -1
  222. package/clients/cli/bin/astryx.mjs +6 -9
  223. package/clients/cli/build-id.generated.json +1 -1
  224. package/clients/cli/commands/component.doc.mjs +1 -1
  225. package/clients/cli/commands/component.mjs +22 -3
  226. package/clients/cli/commands/docs.doc.mjs +7 -1
  227. package/clients/cli/commands/docs.mjs +3 -1
  228. package/clients/cli/commands/doctor.mjs +32 -14
  229. package/clients/cli/commands/experimental/render.mjs +42 -1
  230. package/clients/cli/commands/experimental/theme.mjs +358 -63
  231. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  232. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  233. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
  234. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
  235. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
  236. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  237. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  238. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  239. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  240. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  241. package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
  242. package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
  243. package/clients/cli/commands/search.doc.mjs +2 -1
  244. package/clients/cli/commands/search.mjs +6 -1
  245. package/clients/cli/commands/template.mjs +4 -2
  246. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  247. package/clients/cli/commands/theme.doc.mjs +1 -1
  248. package/clients/cli/commands/theme.mjs +317 -47
  249. package/clients/cli/commands/upgrade.mjs +42 -7
  250. package/clients/cli/index.mjs +1 -1
  251. package/clients/cli/lib/cli-error.mjs +2 -1
  252. package/clients/cli/lib/component-format.mjs +205 -98
  253. package/clients/cli/lib/hook-format.mjs +9 -19
  254. package/clients/cli/lib/json-shim.mjs +92 -21
  255. package/clients/cli/lib/manifest.mjs +3 -2
  256. package/clients/cli/manifest.generated.json +1 -1
  257. package/foundation/agent-docs/agent-docs.mjs +1 -1
  258. package/foundation/config/theme-state.d.mts +13 -1
  259. package/foundation/config/theme-state.mjs +47 -7
  260. package/foundation/discovery/authoring-self-docs.mjs +1 -0
  261. package/foundation/discovery/component-discovery.d.mts +11 -0
  262. package/foundation/discovery/component-discovery.mjs +56 -8
  263. package/foundation/discovery/component-replacement.mjs +130 -1
  264. package/foundation/discovery/copied-passages.mjs +2 -1
  265. package/foundation/discovery/doc-types.mjs +4 -3
  266. package/foundation/discovery/entry-name-files.d.mts +43 -0
  267. package/foundation/discovery/entry-name-files.mjs +264 -0
  268. package/foundation/discovery/hook-discovery.d.mts +8 -2
  269. package/foundation/discovery/hook-discovery.mjs +22 -8
  270. package/foundation/discovery/icon-definition-discovery.mjs +2 -1
  271. package/foundation/discovery/icon-set-checks.mjs +2 -1
  272. package/foundation/discovery/icon-set-discovery.mjs +2 -1
  273. package/foundation/discovery/integration-doc-files.mjs +2 -1
  274. package/foundation/discovery/package-exports.d.mts +10 -0
  275. package/foundation/discovery/package-exports.mjs +56 -3
  276. package/foundation/discovery/prop-drift.mjs +9 -9
  277. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  278. package/foundation/discovery/runner-allowlist.mjs +2 -0
  279. package/foundation/discovery/stored-component-list.d.mts +43 -0
  280. package/foundation/discovery/stored-component-list.mjs +90 -0
  281. package/foundation/discovery/stored-search-catalog.d.mts +115 -0
  282. package/foundation/discovery/stored-search-catalog.mjs +297 -0
  283. package/foundation/discovery/stored-self-audit.d.mts +26 -10
  284. package/foundation/discovery/stored-self-audit.mjs +38 -18
  285. package/foundation/discovery/template-adapter.d.mts +53 -1
  286. package/foundation/discovery/template-adapter.mjs +176 -12
  287. package/foundation/discovery/template-icons.mjs +2 -1
  288. package/foundation/discovery/theme-discovery.mjs +31 -4
  289. package/foundation/discovery/theme-imports.d.mts +14 -0
  290. package/foundation/discovery/theme-imports.mjs +43 -1
  291. package/foundation/discovery/theming-targets.mjs +3 -2
  292. package/foundation/doc-compiler/import.mjs +7 -1
  293. package/foundation/doc-compiler/inputs.mjs +3 -2
  294. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  295. package/foundation/doc-compiler/stored-docs.d.mts +22 -0
  296. package/foundation/doc-compiler/stored-docs.mjs +49 -0
  297. package/foundation/env/semver.mjs +3 -1
  298. package/foundation/fonts/font-stylesheet.d.mts +31 -0
  299. package/foundation/fonts/font-stylesheet.mjs +115 -0
  300. package/foundation/fs/cache-eviction.d.mts +21 -0
  301. package/foundation/fs/cache-eviction.mjs +73 -0
  302. package/foundation/fs/exact-codec.d.mts +12 -2
  303. package/foundation/fs/exact-codec.mjs +23 -6
  304. package/foundation/fs/file-protection.mjs +4 -3
  305. package/foundation/fs/gather-cache.d.mts +62 -4
  306. package/foundation/fs/gather-cache.mjs +512 -91
  307. package/foundation/fs/jiti-cache.d.mts +19 -1
  308. package/foundation/fs/jiti-cache.mjs +130 -6
  309. package/foundation/fs/kept-tree.d.mts +60 -0
  310. package/foundation/fs/kept-tree.mjs +154 -0
  311. package/foundation/fs/listing-cache.d.mts +7 -0
  312. package/foundation/fs/listing-cache.mjs +10 -0
  313. package/foundation/fs/module-loader.d.mts +24 -2
  314. package/foundation/fs/module-loader.mjs +94 -21
  315. package/foundation/fs/paths.d.mts +18 -0
  316. package/foundation/fs/paths.mjs +15 -2
  317. package/foundation/fs/read-record.d.mts +9 -0
  318. package/foundation/fs/read-record.mjs +19 -11
  319. package/foundation/fs/stop-cleanup.d.mts +12 -0
  320. package/foundation/fs/stop-cleanup.mjs +66 -0
  321. package/foundation/identity/provider-identity.d.mts +6 -0
  322. package/foundation/identity/provider-identity.mjs +10 -1
  323. package/foundation/integrations/contribution-inventory.mjs +4 -3
  324. package/foundation/integrations/example-code.d.mts +63 -0
  325. package/foundation/integrations/example-code.mjs +416 -0
  326. package/foundation/integrations/public-imports.d.mts +9 -0
  327. package/foundation/integrations/public-imports.mjs +3 -2
  328. package/foundation/integrations/validate-contributions.mjs +17 -45
  329. package/foundation/render/embedded-files.d.mts +6 -0
  330. package/foundation/render/embedded-files.mjs +25 -5
  331. package/foundation/render/embedded-imports.d.mts +39 -7
  332. package/foundation/render/embedded-imports.mjs +66 -27
  333. package/foundation/render/file-header.d.mts +66 -0
  334. package/foundation/render/file-header.mjs +118 -0
  335. package/foundation/render/host-answer.d.mts +18 -0
  336. package/foundation/render/host-answer.mjs +46 -0
  337. package/foundation/render/host-exit.d.mts +1 -0
  338. package/foundation/render/host-exit.mjs +6 -1
  339. package/foundation/render/html-reader.d.mts +55 -2
  340. package/foundation/render/html-reader.mjs +145 -26
  341. package/foundation/render/markup-edits.d.mts +57 -0
  342. package/foundation/render/markup-edits.mjs +182 -0
  343. package/foundation/render/page-host.mjs +29 -12
  344. package/foundation/render/page-worker.mjs +121 -13
  345. package/foundation/render/picture-chrome.d.mts +4 -0
  346. package/foundation/render/picture-chrome.mjs +185 -0
  347. package/foundation/render/picture-playwright.d.mts +4 -0
  348. package/foundation/render/picture-playwright.mjs +34 -0
  349. package/foundation/render/rebuild.mjs +2 -1
  350. package/foundation/render/render-page.d.mts +35 -3
  351. package/foundation/render/render-page.mjs +641 -96
  352. package/foundation/render/source-block.d.mts +85 -6
  353. package/foundation/render/source-block.mjs +211 -20
  354. package/foundation/render/ts-paths.d.mts +69 -6
  355. package/foundation/render/ts-paths.mjs +326 -40
  356. package/foundation/response/error-codes.d.mts +3 -1
  357. package/foundation/response/error-codes.d.ts +1 -0
  358. package/foundation/response/error-codes.doc.mjs +12 -1
  359. package/foundation/response/error-codes.mjs +11 -1
  360. package/foundation/response/response-types.doc.mjs +2 -2
  361. package/foundation/text/compare-text.d.mts +14 -0
  362. package/foundation/text/compare-text.mjs +68 -0
  363. package/foundation/text/string-utils.d.mts +3 -2
  364. package/foundation/text/string-utils.mjs +18 -4
  365. package/foundation/text/suggest-order.d.mts +9 -0
  366. package/foundation/text/suggest-order.mjs +15 -1
  367. package/foundation/xle/expand.mjs +2 -1
  368. package/host/index.mjs +8 -6
  369. package/package.json +7 -6
@@ -63,7 +63,7 @@ import * as path from 'node:path';
63
63
  import {createRequire, isBuiltin} from 'node:module';
64
64
  import {fileURLToPath, pathToFileURL} from 'node:url';
65
65
  import {babelParse as parse} from '../../../foundation/runtime/lazy-dependencies.mjs';
66
- import {createJiti} from 'jiti';
66
+ import {jitiCacheOptions} from '../../../foundation/fs/jiti-cache.mjs';
67
67
  import {
68
68
  formatCliCommand,
69
69
  getCliInvocation,
@@ -92,6 +92,10 @@ import {applyWrites} from '../../integration/add-helpers.mjs';
92
92
  import {logger} from '../../logger.mjs';
93
93
  import {loadComponentDoc} from '../../../foundation/discovery/component-loader.mjs';
94
94
  import {THEME_SOURCE_EXTENSIONS} from '../../../foundation/discovery/theme-module-extensions.mjs';
95
+ import {
96
+ createJiti,
97
+ withEmptyStylesheets,
98
+ } from '../../../foundation/fs/module-loader.mjs';
95
99
  import {
96
100
  collectThemingTargets,
97
101
  targetsByKey,
@@ -108,6 +112,7 @@ import {
108
112
  } from '../../../foundation/discovery/template-needs.mjs';
109
113
  import {generateFamilyCSS, resolveThemeFamily} from './family.mjs';
110
114
  import {resolveIconImports} from './icon-imports.mjs';
115
+ import {generatedMark} from '../../theme-edit/_marks.mjs';
111
116
 
112
117
  // Import shared theme processing from core. `astryx theme build` MUST produce the
113
118
  // exact same CSS as the `<Theme>` runtime, so it has exactly one generation
@@ -324,7 +329,9 @@ function importTarget(dir, subpath) {
324
329
  /** @param {string} file @returns {string} its real path, or itself */
325
330
  function realOrSelf(file) {
326
331
  try {
327
- return fs.realpathSync(file);
332
+ // The native form spells a path as the disk does (its own case on a
333
+ // case-insensitive disk), so two spellings of one file compare equal.
334
+ return fs.realpathSync.native(file);
328
335
  } catch {
329
336
  return file;
330
337
  }
@@ -333,10 +340,12 @@ function realOrSelf(file) {
333
340
  /**
334
341
  * `target` spelled through real directories: the deepest ancestor that exists
335
342
  * is resolved through its symlinks, and the missing rest is appended as given.
343
+ * The build confines its outputs by it, and the theme editor's compile guard
344
+ * reads paths through it too, so both read a path the same way.
336
345
  * @param {string} target absolute path
337
346
  * @returns {string}
338
347
  */
339
- function realLocation(target) {
348
+ export function realLocation(target) {
340
349
  /** @type {string[]} */
341
350
  const missing = [];
342
351
  let existing = target;
@@ -818,7 +827,7 @@ function confineOutputs(writes, root, remedy) {
818
827
  }
819
828
 
820
829
  /** @param {string} dest absolute output path @param {string} root @returns {boolean} whether a build at `root` refuses to write `dest` */
821
- function refusedOutput(dest, root) {
830
+ export function refusedOutput(dest, root) {
822
831
  try {
823
832
  confineOutput(dest, root, '');
824
833
  return false;
@@ -925,6 +934,82 @@ function isDirectorySync(file) {
925
934
  }
926
935
  }
927
936
 
937
+ /**
938
+ * The marks a file's leading comment carries (see `generatedMark`): a theme
939
+ * build's output, or a file the theme editor writes, with the command it
940
+ * names. The one reader build and doctor share.
941
+ * @param {string} source the start of the file
942
+ * @param {string} [file] its path, for a mark that names no exact command
943
+ */
944
+ export function fileMark(source, file) {
945
+ return generatedMark(source, GENERATED_MARKER, file);
946
+ }
947
+
948
+ /**
949
+ * The command a file's leading comment says writes it, when another CLI
950
+ * command generates it (the theme editor's settings module or app copy):
951
+ * the exact command its mark names. Null for a theme build's own output and
952
+ * a file without a mark, such as a theme source of one's own.
953
+ * @param {string} file
954
+ * @returns {string | null}
955
+ */
956
+ export function generatedFileCommand(file) {
957
+ const mark = fileMark(fileHead(file), file);
958
+ return mark?.kind === 'editor' ? mark.command : null;
959
+ }
960
+
961
+ /**
962
+ * The command that writes a missing `file`: a file beside it carries
963
+ * another command's mark, and a file there names `file` (a build output's
964
+ * header names its source), so it is one that command writes. Null for any
965
+ * other name, such as a typo.
966
+ * @param {string} file
967
+ * @returns {string | null}
968
+ */
969
+ function missingGeneratedCommand(file) {
970
+ const dir = path.dirname(file);
971
+ const base = path.basename(file);
972
+ let names;
973
+ try {
974
+ names = fs.readdirSync(dir).sort();
975
+ } catch {
976
+ return null;
977
+ }
978
+ /** @type {string | null} */
979
+ let by = null;
980
+ let named = false;
981
+ for (const n of names) {
982
+ const f = path.join(dir, n);
983
+ try {
984
+ if (!fs.statSync(f).isFile()) continue;
985
+ } catch {
986
+ continue;
987
+ }
988
+ by ??= generatedFileCommand(f);
989
+ if (!named)
990
+ try {
991
+ named = fs.readFileSync(f, 'utf8').slice(0, 4000).includes(base);
992
+ } catch {
993
+ // A file that does not read names nothing.
994
+ }
995
+ if (by && named) return by;
996
+ }
997
+ return null;
998
+ }
999
+
1000
+ /**
1001
+ * The command that writes `file`: from its own mark, or, when it is
1002
+ * missing, from the files beside it (see `missingGeneratedCommand`); null
1003
+ * otherwise.
1004
+ * @param {string} file
1005
+ * @returns {string | null}
1006
+ */
1007
+ export function generatedSourceCommand(file) {
1008
+ return fs.existsSync(file)
1009
+ ? generatedFileCommand(file)
1010
+ : missingGeneratedCommand(file);
1011
+ }
1012
+
928
1013
  /** @param {string} file @returns {string} the start of a file, or '' when it cannot be read */
929
1014
  function fileHead(file) {
930
1015
  try {
@@ -1121,7 +1206,16 @@ function assertThemeSourceFile(filePath, cwd, mode = {}) {
1121
1206
  * output must stay inside, for a scratch build; `commandWords` names the
1122
1207
  * command in the rebuild hint; `prepareFamily`, `familyLoader`, and
1123
1208
  * `familyInterception` make the build a family member's plan.
1124
- * @typedef {{prepareFamily?: boolean, familyLoader?: any, familyInterception?: any, writeRoot?: string, claimedOutputs?: Map<string, string>, deferredWrites?: Array<Array<{dest: string, content: string}>>, commandWords?: {group: string, build: string}}} ThemeBuildHandOff
1209
+ * `colorModes` is the one color mode a calling command knows the theme has
1210
+ * (the theme editor, from its settings), written into the built module.
1211
+ * @typedef {{prepareFamily?: boolean, familyLoader?: any, familyInterception?: any, writeRoot?: string, claimedOutputs?: Map<string, string>, deferredWrites?: Array<Array<{dest: string, content: string}>>, commandWords?: {group: string, build: string}, colorModes?: ['light'] | ['dark'] | null, fontHelp?: FontHelp | null, loadedFonts?: ((family: string) => boolean) | null}} ThemeBuildHandOff
1212
+ */
1213
+
1214
+ /**
1215
+ * How a caller that loads a theme's fonts itself (the editor's app copy)
1216
+ * says to load a family: the notice per family and the recipe in place of
1217
+ * the generic one.
1218
+ * @typedef {{notice: (family: string) => string, recipe: (families: string[]) => string}} FontHelp
1125
1219
  */
1126
1220
 
1127
1221
  /**
@@ -1157,6 +1251,45 @@ export function setEditorFolderListener(listener) {
1157
1251
  * @typedef {{glob?: boolean, family?: boolean, familyKey?: string}} SuggestionShape
1158
1252
  */
1159
1253
 
1254
+ /**
1255
+ * The refusal a build gives the file it is given before it reads it, or
1256
+ * null: a file that is not there, and a folder. The build throws it, and a
1257
+ * suggested build is checked by it before it is offered.
1258
+ * @param {string} file as typed, from cwd
1259
+ * @param {BuildMode} options
1260
+ * @param {string} cwd
1261
+ * @returns {AstryxError | null}
1262
+ */
1263
+ export function buildInputProblem(file, options, cwd) {
1264
+ const filePath = path.resolve(cwd, file);
1265
+ if (!fs.existsSync(filePath))
1266
+ return new AstryxError(
1267
+ `File not found: ${filePath}`,
1268
+ themeSourceGuesses(file, cwd).map(guess => ({
1269
+ name: buildSuggestion(guess, options, cwd),
1270
+ reason: 'a theme source that exists',
1271
+ })),
1272
+ ERROR_CODES.ERR_FILE_NOT_FOUND,
1273
+ );
1274
+ if (fs.statSync(filePath).isDirectory())
1275
+ return new AstryxError(
1276
+ `${path.relative(cwd, filePath) || '.'} is a folder. Pass the theme file inside it.`,
1277
+ themeFilesIn(filePath).map(name => ({
1278
+ name: buildSuggestion(
1279
+ path
1280
+ .relative(cwd, path.join(filePath, name))
1281
+ .split(path.sep)
1282
+ .join('/'),
1283
+ options,
1284
+ cwd,
1285
+ ),
1286
+ reason: 'a theme source in that folder',
1287
+ })),
1288
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
1289
+ );
1290
+ return null;
1291
+ }
1292
+
1160
1293
  /**
1161
1294
  * The `theme build` command for `source` with the caller's mode flags, so a
1162
1295
  * suggestion never turns a check into a write or moves the outputs.
@@ -1212,11 +1345,12 @@ export function buildSuggestion(source, mode, cwd, words, shape = {}) {
1212
1345
  * @param {Array<{dest: string}>} writes
1213
1346
  * @param {string} filePath the theme source
1214
1347
  * @param {string} cwd
1215
- * @param {{claimed?: Map<string, string>, rerun?: (out: string | null) => string, refuseUnmarked?: boolean, elsewhere?: string, onEditorFolder?: (warning: string) => void}} [options]
1348
+ * @param {{claimed?: Map<string, string>, rerun?: (out: string | null) => string, refuseUnmarked?: boolean, elsewhere?: string, onEditorFolder?: (warning: string) => void, onWarning?: (message: string) => void}} [options]
1216
1349
  * `claimed`: outputs written earlier in this run, by the source that wrote
1217
1350
  * them; `rerun`: this build's command with another --out, or without one;
1218
1351
  * `elsewhere`: the option that moves the outputs; `onEditorFolder`: takes
1219
- * the editor-folder warning instead of the logger (a watcher prints it once)
1352
+ * the editor-folder warning instead of the logger (a watcher prints it
1353
+ * once); `onWarning`: each warning's message too, for the result
1220
1354
  */
1221
1355
  function assertOutputsReplaceable(
1222
1356
  writes,
@@ -1228,6 +1362,7 @@ function assertOutputsReplaceable(
1228
1362
  refuseUnmarked = false,
1229
1363
  elsewhere = '--out',
1230
1364
  onEditorFolder,
1365
+ onWarning,
1231
1366
  } = {},
1232
1367
  ) {
1233
1368
  const rel = (/** @type {string} */ file) => path.relative(cwd, file);
@@ -1309,7 +1444,7 @@ function assertOutputsReplaceable(
1309
1444
  // It is printed after every output passes, so it names a replacement
1310
1445
  // that happens.
1311
1446
  if (warnedOtherSource) continue;
1312
- warnedOtherSource = `Warning: ${rel(write.dest)} was built from ${otherSource}; this build of ${rel(filePath)} replaces it.`;
1447
+ warnedOtherSource = `${rel(write.dest)} was built from ${otherSource}; this build of ${rel(filePath)} replaces it.`;
1313
1448
  } else if (otherSource) {
1314
1449
  throw new AstryxError(
1315
1450
  `${rel(write.dest)} is the build output of another theme source, ${otherSource}, so this build does not replace it. Pick another ${elsewhere}.`,
@@ -1346,12 +1481,16 @@ function assertOutputsReplaceable(
1346
1481
  }
1347
1482
  // Warned only once nothing refuses the build, so it names a write that
1348
1483
  // happens.
1349
- if (warnedOtherSource) logger.warn(warnedOtherSource);
1484
+ if (warnedOtherSource) {
1485
+ logger.warn(`Warning: ${warnedOtherSource}`);
1486
+ onWarning?.(warnedOtherSource);
1487
+ }
1350
1488
  if (editorFolder) {
1351
1489
  const dir = path.dirname(writes[0].dest);
1352
- const warning = `Warning: ${rel(dir) || '.'} is a folder the theme editor made, and ${rel(filePath)} is outside it; the build writes there anyway. Build beside the source, or pick another ${elsewhere}, to keep the editor's folder to its own theme.`;
1353
- if (onEditorFolder) onEditorFolder(warning);
1354
- else logger.warn(warning);
1490
+ const message = `${rel(dir) || '.'} is a folder the theme editor made, and ${rel(filePath)} is outside it; the build writes there anyway. Build beside the source, or pick another ${elsewhere}, to keep the editor's folder to its own theme.`;
1491
+ if (onEditorFolder) onEditorFolder(`Warning: ${message}`);
1492
+ else logger.warn(`Warning: ${message}`);
1493
+ onWarning?.(message);
1355
1494
  }
1356
1495
  }
1357
1496
 
@@ -1443,7 +1582,31 @@ function writeBuildOutputs(writes) {
1443
1582
  })),
1444
1583
  );
1445
1584
  } catch (error) {
1446
- const message = `Failed to write theme outputs: ${/** @type {Error} */ (error).message}`;
1585
+ const e = /** @type {NodeJS.ErrnoException} */ (error);
1586
+ // A place the outputs cannot be written: name it and its fix (the
1587
+ // writes go through temporary files beside each output, whose names
1588
+ // help nobody).
1589
+ if (e.code === 'EACCES' || e.code === 'EPERM' || e.code === 'EROFS') {
1590
+ const failed = e.path ? path.resolve(e.path) : null;
1591
+ const output = writes.find(w => path.resolve(w.dest) === failed);
1592
+ const place = output
1593
+ ? output.dest
1594
+ : failed
1595
+ ? path.dirname(failed)
1596
+ : path.dirname(writes[0].dest);
1597
+ const shownPlace = path.relative(process.cwd(), place) || place;
1598
+ throw new AstryxError(
1599
+ `Could not write the theme's outputs: ${shownPlace} is not writable (${e.code}). Give yourself write permission on it (chmod u+w ${shellWord(shownPlace)}), then build again. Nothing was changed.`,
1600
+ [
1601
+ {
1602
+ name: `ls -ld ${shellWord(shownPlace)}`,
1603
+ reason: 'see its permissions',
1604
+ },
1605
+ ],
1606
+ ERROR_CODES.ERR_WRITE_FAILED,
1607
+ );
1608
+ }
1609
+ const message = `Failed to write theme outputs: ${e.message}`;
1447
1610
  throw new AstryxError(message, undefined, ERROR_CODES.ERR_WRITE_FAILED);
1448
1611
  }
1449
1612
  }
@@ -2630,19 +2793,23 @@ function isSyncLoaderLimitation(error) {
2630
2793
  * source export and old-Core adaptation checks keep treating that path as
2631
2794
  * degraded/fail-closed.
2632
2795
  *
2796
+ * On Node 22.15 and later, on every path, a stylesheet that a module in the
2797
+ * theme's graph imports loads as an empty module (`withEmptyStylesheets`): a
2798
+ * base theme's module can import its own stylesheet for the app's bundler.
2799
+ *
2633
2800
  * @param {string} filePath
2634
2801
  * @param {import('./core-interception.mjs').CoreInterception} [interception]
2635
- * @returns {Promise<{theme: any, exportName: string, degraded: {topLevelAwait: boolean, commonJs: boolean}}>}
2802
+ * @returns {Promise<{theme: any, exportName: string, degraded: {topLevelAwait: boolean, commonJs: boolean}, colorModes: ["light"] | ["dark"] | null}>}
2636
2803
  */
2637
2804
  // prettier-ignore
2638
- async function importThemeModule(filePath, interception, /** @type {any} */ loader = undefined) {
2805
+ async function importThemeModule(filePath, interception, /** @type {any} */ loader = undefined, /** @type {string | undefined} */ pick = undefined) {
2639
2806
  const jiti =
2640
2807
  loader ??
2641
2808
  createJiti(import.meta.url, {
2642
2809
  moduleCache: false,
2643
- // No transpile cache: it is written to the system temp folder, named
2644
- // for the theme, and never removed, so every edit added files there.
2645
- fsCache: false,
2810
+ // The per-user transpile cache: an edited theme is transpiled again,
2811
+ // and the folder stays within its size limit.
2812
+ ...jitiCacheOptions(),
2646
2813
  jsx: true,
2647
2814
  extensions: THEME_MODULE_EXTENSIONS,
2648
2815
  ...(interception ? {virtualModules: interception.modules} : {}),
@@ -2659,7 +2826,7 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
2659
2826
  const commonJsPatch = interception.patchCommonJs(filePath);
2660
2827
  try {
2661
2828
  try {
2662
- mod = jiti(filePath);
2829
+ mod = await withEmptyStylesheets(async () => jiti(filePath));
2663
2830
  } catch (error) {
2664
2831
  // Only a sync-loader limitation may fall back. Anything else is the
2665
2832
  // theme's own failure and belongs to the caller unchanged.
@@ -2668,14 +2835,16 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
2668
2835
  // Force asynchronous transformation instead of native import: this
2669
2836
  // keeps virtual Core interception active even when the module uses
2670
2837
  // top-level await.
2671
- mod = await jiti.evalModule(fs.readFileSync(filePath, 'utf8'), {
2672
- id: filePath,
2673
- filename: filePath,
2674
- ext: path.extname(filePath),
2675
- cache: jiti.cache,
2676
- async: true,
2677
- forceTranspile: true,
2678
- });
2838
+ mod = await withEmptyStylesheets(() =>
2839
+ jiti.evalModule(fs.readFileSync(filePath, 'utf8'), {
2840
+ id: filePath,
2841
+ filename: filePath,
2842
+ ext: path.extname(filePath),
2843
+ cache: jiti.cache,
2844
+ async: true,
2845
+ forceTranspile: true,
2846
+ }),
2847
+ );
2679
2848
  }
2680
2849
  } finally {
2681
2850
  // Read after the load: the root is wrapped when the load requires it.
@@ -2683,7 +2852,7 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
2683
2852
  commonJsPatch.undo();
2684
2853
  }
2685
2854
  } else {
2686
- mod = await jiti.import(filePath);
2855
+ mod = await withEmptyStylesheets(() => jiti.import(filePath));
2687
2856
  }
2688
2857
 
2689
2858
  // Both loads hand back the module. The theme is read from the module's own
@@ -2692,15 +2861,28 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
2692
2861
  // `default` with the module), so the module can pass for the theme while
2693
2862
  // its own keys hide the theme's fields.
2694
2863
  const isModule = mod != null && typeof mod === 'object';
2864
+ // A theme with one color mode says so with a `colorModes` export beside
2865
+ // the theme (`['light']` or `['dark']`); the build carries it into the
2866
+ // built module.
2867
+ const colorModes = oneColorMode(
2868
+ isModule && Object.hasOwn(mod, 'colorModes') ? mod.colorModes : undefined,
2869
+ );
2695
2870
  const hasDefault = isModule && Object.hasOwn(mod, 'default');
2696
2871
  const defaultExport = hasDefault ? mod.default : undefined;
2872
+ // A caller that already knows which export a build reads (from a load
2873
+ // as the build loads it) reads that one.
2874
+ if (pick !== undefined && isModule && Object.hasOwn(mod, pick)) {
2875
+ if (isThemeObject(mod[pick]))
2876
+ return {theme: mod[pick], exportName: pick, degraded, colorModes};
2877
+ }
2697
2878
  if (isThemeObject(defaultExport)) {
2698
- return {theme: defaultExport, exportName: 'default', degraded};
2879
+ return {theme: defaultExport, exportName: 'default', degraded, colorModes};
2699
2880
  }
2700
2881
  if (isModule) {
2701
2882
  for (const [exportName, value] of Object.entries(mod)) {
2702
2883
  if (exportName === 'default' || exportName === 'module.exports') continue;
2703
- if (isThemeObject(value)) return {theme: value, exportName, degraded};
2884
+ if (isThemeObject(value))
2885
+ return {theme: value, exportName, degraded, colorModes};
2704
2886
  }
2705
2887
  }
2706
2888
  // The loader's interop answers a null default with the module itself, so
@@ -2722,7 +2904,7 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
2722
2904
  // be all it defines), or no name: the build's validation says what it
2723
2905
  // lacks.
2724
2906
  if (isPlainObject(defaultExport)) {
2725
- return {theme: defaultExport, exportName: 'default', degraded};
2907
+ return {theme: defaultExport, exportName: 'default', degraded, colorModes};
2726
2908
  }
2727
2909
  // A CommonJS module whose exports are the theme (`module.exports =
2728
2910
  // theme`) has no default of its own: interop answers `default` with
@@ -2731,7 +2913,7 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
2731
2913
  if (isModule && !hasDefault) {
2732
2914
  const exportsObject = mod.default ?? mod;
2733
2915
  if (isThemeObject(exportsObject)) {
2734
- return {theme: exportsObject, exportName: 'default', degraded};
2916
+ return {theme: exportsObject, exportName: 'default', degraded, colorModes};
2735
2917
  }
2736
2918
  }
2737
2919
 
@@ -2800,12 +2982,12 @@ function isThemeObject(value) {
2800
2982
  *
2801
2983
  * @param {string} filePath
2802
2984
  * @param {import('./core-interception.mjs').CoreInterception} [interception]
2803
- * @returns {Promise<{theme: any, exportName?: string, degraded: {topLevelAwait: boolean, commonJs: boolean}}>}
2985
+ * @returns {Promise<{theme: any, exportName?: string, degraded: {topLevelAwait: boolean, commonJs: boolean}, colorModes?: ['light'] | ['dark'] | null}>}
2804
2986
  */
2805
2987
  // prettier-ignore
2806
- async function extractThemeDefinition(filePath, interception, /** @type {any} */ loader = undefined) {
2988
+ async function extractThemeDefinition(filePath, interception, /** @type {any} */ loader = undefined, /** @type {string | undefined} */ pick = undefined) {
2807
2989
  try {
2808
- return await importThemeModule(filePath, interception, loader);
2990
+ return await importThemeModule(filePath, interception, loader, pick);
2809
2991
  } catch (jitiError) {
2810
2992
  const je = /** @type {Error} */ (jitiError);
2811
2993
  throw new Error(
@@ -2815,6 +2997,120 @@ async function extractThemeDefinition(filePath, interception, /** @type {any} */
2815
2997
  }
2816
2998
  }
2817
2999
 
3000
+ /**
3001
+ * The Core interception a standalone build loads a theme module with: none
3002
+ * when the selected Core generates adaptations itself and the theme's folder
3003
+ * resolves a Core of its own; else imports of Core are handed the selected
3004
+ * Core.
3005
+ * @param {string} filePath
3006
+ */
3007
+ function standaloneInterception(filePath) {
3008
+ return _generateAdaptationCSS && themeFolderResolvesCore(filePath)
3009
+ ? undefined
3010
+ : interceptCore(_coreThemeModule, _coreRootModule);
3011
+ }
3012
+
3013
+ /**
3014
+ * Load a theme module as a standalone build of it loads it (the Core the
3015
+ * build selects, the same loader and interception) and name the export the
3016
+ * build reads. Callers that must agree with the build on which theme a
3017
+ * module defines read it here, never from the module's text.
3018
+ *
3019
+ * With `base`, also whether the theme extends that module's export, by
3020
+ * identity, anywhere up its `extends` chain (`extendsBase`): the module is
3021
+ * loaded once, and the theme module's imports of it (by any of
3022
+ * `base.specifiers`) are handed that one load, so the answer is about the
3023
+ * very object, not one that only looks like it.
3024
+ * @param {string} file
3025
+ * @param {{cwd?: string, base?: {file: string, exportName: string, specifiers: string[]}}} [ctx]
3026
+ * @returns {Promise<{theme: any, exportName: string, extendsBase?: boolean}>}
3027
+ */
3028
+ export async function loadThemeExport(file, {cwd = process.cwd(), base} = {}) {
3029
+ const filePath = path.resolve(cwd, file);
3030
+ await selectCore(cwd, {projectOnly: false});
3031
+ const {theme, exportName = 'default'} = await extractThemeDefinition(
3032
+ filePath,
3033
+ standaloneInterception(filePath),
3034
+ );
3035
+ if (!base) return {theme, exportName};
3036
+ const recorder = interceptCore(_coreThemeModule, _coreRootModule);
3037
+ const shared = (
3038
+ await extractThemeDefinition(
3039
+ path.resolve(cwd, base.file),
3040
+ recorder,
3041
+ undefined,
3042
+ base.exportName,
3043
+ )
3044
+ ).theme;
3045
+ const withBase = {
3046
+ ...recorder,
3047
+ modules: {
3048
+ ...recorder.modules,
3049
+ ...Object.fromEntries(
3050
+ base.specifiers.map(s => [s, {[base.exportName]: shared}]),
3051
+ ),
3052
+ },
3053
+ };
3054
+ const again = await extractThemeDefinition(
3055
+ filePath,
3056
+ withBase,
3057
+ undefined,
3058
+ exportName,
3059
+ );
3060
+ let extendsBase = false;
3061
+ for (
3062
+ let at = recorder.parentOf(again.theme), depth = 0;
3063
+ at && depth < 64;
3064
+ at = recorder.parentOf(at), depth++
3065
+ )
3066
+ if (at === shared) {
3067
+ extendsBase = true;
3068
+ break;
3069
+ }
3070
+ return {theme, exportName, extendsBase};
3071
+ }
3072
+
3073
+ /**
3074
+ * The input a theme module gives `defineTheme()` for the theme a build of
3075
+ * it reads, evaluated as the build evaluates the module (an import, an
3076
+ * expression, a spread or a computed key is its value), with the theme Core
3077
+ * made of it. When Core refuses the input, the input the module gave for
3078
+ * the named theme (else its last) and Core's error; null when the module
3079
+ * does not load at all.
3080
+ * @param {string} file
3081
+ * @param {{cwd?: string, name?: string}} [ctx]
3082
+ * @returns {Promise<{input: any, theme: any, error: Error | null} | null>}
3083
+ */
3084
+ export async function loadThemeInput(file, {cwd = process.cwd(), name} = {}) {
3085
+ const filePath = path.resolve(cwd, file);
3086
+ await selectCore(cwd, {projectOnly: false});
3087
+ const interception = interceptCore(_coreThemeModule, _coreRootModule);
3088
+ try {
3089
+ const {theme} = await extractThemeDefinition(filePath, interception);
3090
+ return {input: interception.inputOf(theme) ?? null, theme, error: null};
3091
+ } catch (e) {
3092
+ const given = interception.inputs;
3093
+ const input =
3094
+ given.filter(x => x && typeof x === 'object' && x.name === name).at(-1) ??
3095
+ given.at(-1);
3096
+ return input ? {input, theme: null, error: /** @type {Error} */ (e)} : null;
3097
+ }
3098
+ }
3099
+
3100
+ /**
3101
+ * A one-mode `colorModes` value (`['light']` or `['dark']`), or null for
3102
+ * anything else: a theme with both modes needs no export.
3103
+ * @param {unknown} value
3104
+ * @returns {['light'] | ['dark'] | null}
3105
+ */
3106
+ export function oneColorMode(value) {
3107
+ return Array.isArray(value) &&
3108
+ value.length === 1 &&
3109
+ (value[0] === 'light' || value[0] === 'dark')
3110
+ ? /** @type {['light'] | ['dark']} */ ([value[0]])
3111
+ : null;
3112
+ }
3113
+
2818
3114
  /** Names a theme module's exports must take; ends a shape failure. */
2819
3115
  const THEME_EXPORT_FIX =
2820
3116
  "Export the theme object: `export default defineTheme({name: 'my-theme', tokens: {...}})`, or a plain `export default {name: 'my-theme', tokens: {...}}`.";
@@ -3739,21 +4035,32 @@ async function themeBuildInternal(
3739
4035
  report = {},
3740
4036
  handOff = {},
3741
4037
  ) {
4038
+ // A blank --out names no file: the build would write files named by the
4039
+ // spaces alone.
4040
+ if (
4041
+ typeof options.out === 'string' &&
4042
+ options.out !== '' &&
4043
+ !options.out.trim()
4044
+ )
4045
+ throw new AstryxError(
4046
+ '--out is blank; name a file or folder, or leave out --out to write beside the source.',
4047
+ [
4048
+ {
4049
+ name: buildSuggestion(file, {...options, out: undefined}, cwd),
4050
+ reason: 'do this instead',
4051
+ },
4052
+ ],
4053
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
4054
+ );
3742
4055
  // A backslash in --out separates folders on every platform, as it does in
3743
4056
  // the other theme paths (a Windows path copied into a POSIX shell).
3744
4057
  if (typeof options.out === 'string' && options.out.includes('\\'))
3745
4058
  options = {...options, out: options.out.replace(/\\/g, '/')};
3746
4059
  const filePath = path.resolve(cwd, file);
3747
4060
 
3748
- if (!fs.existsSync(filePath)) {
3749
- throw new AstryxError(
3750
- `File not found: ${filePath}`,
3751
- themeSourceGuesses(file, cwd).map(guess => ({
3752
- name: buildSuggestion(guess, options, cwd),
3753
- reason: 'a theme source that exists',
3754
- })),
3755
- ERROR_CODES.ERR_FILE_NOT_FOUND,
3756
- );
4061
+ {
4062
+ const problem = buildInputProblem(file, options, cwd);
4063
+ if (problem) throw problem;
3757
4064
  }
3758
4065
 
3759
4066
  // A theme the theme editor made is built from its settings by the editor;
@@ -3772,24 +4079,6 @@ async function themeBuildInternal(
3772
4079
  );
3773
4080
  }
3774
4081
 
3775
- if (fs.statSync(filePath).isDirectory()) {
3776
- throw new AstryxError(
3777
- `${path.relative(cwd, filePath) || '.'} is a folder. Pass the theme file inside it.`,
3778
- themeFilesIn(filePath).map(name => ({
3779
- name: buildSuggestion(
3780
- path
3781
- .relative(cwd, path.join(filePath, name))
3782
- .split(path.sep)
3783
- .join('/'),
3784
- options,
3785
- cwd,
3786
- ),
3787
- reason: 'a theme source in that folder',
3788
- })),
3789
- ERROR_CODES.ERR_INVALID_ARGUMENT,
3790
- );
3791
- }
3792
-
3793
4082
  assertThemeSourceFile(filePath, cwd, options);
3794
4083
 
3795
4084
  if (!report.compact) {
@@ -3814,10 +4103,7 @@ async function themeBuildInternal(
3814
4103
  // shared loader so exact authored parent identity stays CLI-private instead
3815
4104
  // of becoming a public DefinedTheme field.
3816
4105
  const interception =
3817
- handOff.familyInterception ??
3818
- (_generateAdaptationCSS && themeFolderResolvesCore(filePath)
3819
- ? undefined
3820
- : interceptCore(_coreThemeModule, _coreRootModule));
4106
+ handOff.familyInterception ?? standaloneInterception(filePath);
3821
4107
 
3822
4108
  // Extract theme definition
3823
4109
  let themeDef;
@@ -3825,6 +4111,9 @@ async function themeBuildInternal(
3825
4111
  let themeExportName;
3826
4112
  /** Paths through the load that interception could not fully observe. */
3827
4113
  let loadDegradation;
4114
+ /** The one color mode the theme module exports, or null for both. */
4115
+ /** @type {['light'] | ['dark'] | null} */
4116
+ let colorModes;
3828
4117
  /**
3829
4118
  * The theme file's bytes as loaded: read before and after the load, and the
3830
4119
  * registry scan below reads these rather than the file again. An editor's
@@ -3851,6 +4140,7 @@ async function themeBuildInternal(
3851
4140
  themeDef = loaded.theme;
3852
4141
  themeExportName = loaded.exportName;
3853
4142
  loadDegradation = loaded.degraded;
4143
+ colorModes = handOff.colorModes ?? loaded.colorModes ?? null;
3854
4144
  } catch (e) {
3855
4145
  const err = /** @type {Error} */ (e);
3856
4146
  const shown = path.relative(cwd, filePath) || filePath;
@@ -4403,9 +4693,10 @@ async function themeBuildInternal(
4403
4693
  .join(path.dirname(options.out), `${stem}.css`)
4404
4694
  .split(path.sep)
4405
4695
  .join('/');
4406
- logger.warn(
4407
- `Warning: --out names the stylesheet, which is CSS; give it a .css name such as ${fixed}.`,
4408
- );
4696
+ // The result's warnings say it too, as text does.
4697
+ const w = `--out names the stylesheet, which is CSS; give it a .css name such as ${fixed}.`;
4698
+ warningMessages.push(w);
4699
+ logger.warn(`Warning: ${w}`);
4409
4700
  }
4410
4701
  // A build keeps the explicit output inside the write root, relative or
4411
4702
  // absolute. Check mode writes nothing, so it refuses only a relative path
@@ -4482,11 +4773,21 @@ async function themeBuildInternal(
4482
4773
  ? {}
4483
4774
  : {cssFileName: path.basename(outPath)}),
4484
4775
  },
4485
- );
4776
+ ) +
4777
+ // The one color mode, beside the theme export (a two-mode theme
4778
+ // exports none, so its module is unchanged).
4779
+ (colorModes
4780
+ ? `export const colorModes = [${JSON.stringify(colorModes[0])}];\n`
4781
+ : '');
4486
4782
  const dtsContent =
4487
4783
  generatedHeader(headerSource, 'ts', buildCommand, versions) +
4488
- generateBuiltTypes(resolvedTheme || themeDef, iconInfo, variantsFileName);
4784
+ generateBuiltTypes(resolvedTheme || themeDef, iconInfo, variantsFileName) +
4785
+ (colorModes
4786
+ ? `export declare const colorModes: readonly [${JSON.stringify(colorModes[0])}];\n`
4787
+ : '');
4489
4788
 
4789
+ // A family the caller knows the app loads (a font stylesheet it writes
4790
+ // for the theme) is not named as unloaded.
4490
4791
  const unloadedFonts = [
4491
4792
  ...new Set([
4492
4793
  ...collectUnloadedFonts(resolvedTheme),
@@ -4494,7 +4795,7 @@ async function themeBuildInternal(
4494
4795
  (/** @type {any} */ value) => collectUnloadedFonts(value),
4495
4796
  ),
4496
4797
  ]),
4497
- ];
4798
+ ].filter(family => !handOff.loadedFonts?.(family));
4498
4799
 
4499
4800
  if (handOff.prepareFamily) {
4500
4801
  return {
@@ -4547,6 +4848,8 @@ async function themeBuildInternal(
4547
4848
  rerun,
4548
4849
  refuseUnmarked: Boolean(options.out),
4549
4850
  onEditorFolder: editorFolderListener ?? undefined,
4851
+ // The result's warnings carry what text prints.
4852
+ onWarning: message => warningMessages.push(message),
4550
4853
  });
4551
4854
  }
4552
4855
 
@@ -4637,12 +4940,19 @@ async function themeBuildInternal(
4637
4940
  // permanently in violation of its own "compiles with no warnings" guard).
4638
4941
  // Adaptation rules are resolved theme writes in their own right, so a family
4639
4942
  // named only inside one needs the same notice as one named at the root.
4943
+ // The result names the recipe's command bare, as every machine-read
4944
+ // command is; the printed note starts it the way this project runs the CLI.
4945
+ /** @param {string} family @param {string} recipe */
4946
+ const fontNotice = (family, recipe) =>
4947
+ handOff.fontHelp?.notice(family) ??
4948
+ `Font "${family}" is named by this theme but not loaded; add a <link> or @font-face in your app (recipe: ${recipe})`;
4640
4949
  /** @type {string[]} */
4641
4950
  const fontNotices = [];
4642
4951
  for (const family of unloadedFonts) {
4643
- const msg = `Font "${family}" is named by this theme but not loaded; add a <link> or @font-face in your app (recipe: astryx docs typography)`;
4644
- noticeMessages.push(msg);
4645
- fontNotices.push(msg);
4952
+ noticeMessages.push(fontNotice(family, 'astryx docs typography'));
4953
+ fontNotices.push(
4954
+ fontNotice(family, formatCliCommand('docs typography', cwd)),
4955
+ );
4646
4956
  }
4647
4957
 
4648
4958
  /** @type {ThemeBuildTrailer} */
@@ -4653,6 +4963,7 @@ async function themeBuildInternal(
4653
4963
  cssImport,
4654
4964
  unloadedFonts,
4655
4965
  fontNotices,
4966
+ fontHelp: handOff.fontHelp ?? null,
4656
4967
  };
4657
4968
  // A batch or compact report prints this once for the whole run instead.
4658
4969
  if (report.trailers) report.trailers.push(trailer);
@@ -4689,7 +5000,8 @@ async function themeBuildInternal(
4689
5000
  * @property {string} jsImport Import specifier of the built JS module.
4690
5001
  * @property {string} cssImport Import specifier of the built CSS.
4691
5002
  * @property {string[]} unloadedFonts Font families the theme names but does not load.
4692
- * @property {string[]} fontNotices One notice per unloaded font family.
5003
+ * @property {string[]} fontNotices One notice per unloaded font family, as printed.
5004
+ * @property {FontHelp | null} [fontHelp] How the caller loads fonts, when it does.
4693
5005
  */
4694
5006
 
4695
5007
  /**
@@ -4720,7 +5032,13 @@ Or with a <link> tag:
4720
5032
  `);
4721
5033
  for (const msg of trailer.fontNotices) logger.log(` note: ${msg}`);
4722
5034
  if (trailer.unloadedFonts.length > 0) {
4723
- logger.log(formatFontLoadingHelp(trailer.themeName, trailer.unloadedFonts));
5035
+ logger.log(
5036
+ formatFontLoadingHelp(
5037
+ trailer.themeName,
5038
+ trailer.unloadedFonts,
5039
+ trailer.fontHelp?.recipe,
5040
+ ),
5041
+ );
4724
5042
  }
4725
5043
  }
4726
5044
 
@@ -4763,7 +5081,10 @@ Or with a <link> tag:
4763
5081
  }
4764
5082
  }
4765
5083
  const fonts = groupUnloadedFonts(trailers);
4766
- if (fonts.length > 0) logger.log(formatBatchFontLoadingHelp(fonts));
5084
+ // One caller's recipe serves the batch only when every theme takes it.
5085
+ const help = trailers.every(t => t.fontHelp) ? trailers[0].fontHelp : null;
5086
+ if (fonts.length > 0)
5087
+ logger.log(formatBatchFontLoadingHelp(fonts, help?.recipe));
4767
5088
  }
4768
5089
 
4769
5090
  /**
@@ -4998,7 +5319,7 @@ function planFamilySources(files, cwd) {
4998
5319
  // prettier-ignore
4999
5320
  async function preloadFamilySource(filePath, loader, interception) {
5000
5321
  const patch = interception.patchCommonJs(filePath);
5001
- try { try { loader(filePath); } catch (error) { if (!isSyncLoaderLimitation(error)) throw error; await loader.evalModule(fs.readFileSync(filePath, 'utf8'), {id: filePath, filename: filePath, ext: path.extname(filePath), cache: loader.cache, async: true, forceTranspile: true}); } }
5322
+ try { try { await withEmptyStylesheets(async () => loader(filePath)); } catch (error) { if (!isSyncLoaderLimitation(error)) throw error; await withEmptyStylesheets(() => loader.evalModule(fs.readFileSync(filePath, 'utf8'), {id: filePath, filename: filePath, ext: path.extname(filePath), cache: loader.cache, async: true, forceTranspile: true})); } }
5002
5323
  finally { patch.undo(); }
5003
5324
  }
5004
5325
 
@@ -5026,7 +5347,7 @@ export async function themeBuildFamily(
5026
5347
  await selectCore(cwd);
5027
5348
  const familyInterception = interceptCore(_coreThemeModule, _coreRootModule);
5028
5349
  // prettier-ignore
5029
- const familyLoader = createJiti(import.meta.url, {moduleCache: true, fsCache: false, interopDefault: false, jsx: true, extensions: THEME_MODULE_EXTENSIONS, virtualModules: familyInterception.modules});
5350
+ const familyLoader = createJiti(import.meta.url, {moduleCache: true, ...jitiCacheOptions(), interopDefault: false, jsx: true, extensions: THEME_MODULE_EXTENSIONS, virtualModules: familyInterception.modules});
5030
5351
  /** @type {any[]} */
5031
5352
  const prepared = [];
5032
5353
  for (const source of planFamilySources(files, cwd)) {
@@ -5318,11 +5639,18 @@ Or load the same stylesheet natively:
5318
5639
  const unloadedFonts = [
5319
5640
  ...new Set(members.flatMap(member => member.unloadedFonts)),
5320
5641
  ];
5321
- const notices = unloadedFonts.map(
5322
- family =>
5323
- `Font "${family}" is named by this theme family but not loaded; add a <link> or @font-face in your app (recipe: astryx docs typography)`,
5642
+ /** @param {string} family @param {string} recipe */
5643
+ const familyNotice = (family, recipe) =>
5644
+ `Font "${family}" is named by this theme family but not loaded; add a <link> or @font-face in your app (recipe: ${recipe})`;
5645
+ // The result names the command bare; the printed note as this project
5646
+ // runs the CLI.
5647
+ const notices = unloadedFonts.map(family =>
5648
+ familyNotice(family, 'astryx docs typography'),
5324
5649
  );
5325
- for (const notice of notices) logger.log(` note: ${notice}`);
5650
+ for (const family of unloadedFonts)
5651
+ logger.log(
5652
+ ` note: ${familyNotice(family, formatCliCommand('docs typography', cwd))}`,
5653
+ );
5326
5654
  return {
5327
5655
  type: 'theme.build',
5328
5656
  data: {