@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
@@ -30,7 +30,12 @@ import {
30
30
  text,
31
31
  } from '../../formatters/index.mjs';
32
32
  import {cliError} from '../../lib/cli-error.mjs';
33
- import {editorMissingArgument} from '../../lib/json-shim.mjs';
33
+ import {
34
+ editorMissingArgument,
35
+ setEditorFreeName,
36
+ setEditorThemeList,
37
+ setUnknownOptionReader,
38
+ } from '../../lib/json-shim.mjs';
34
39
  import {AstryxError} from '../../../../api/error.mjs';
35
40
  import {defineCommand} from '../../lib/define-command.mjs';
36
41
  import {
@@ -48,7 +53,24 @@ import {
48
53
  builtInThemes,
49
54
  dialValueFits,
50
55
  newFlagList,
56
+ editorCheckedLine,
57
+ editorCheckedNewLines,
58
+ editorCheckedShowLines,
59
+ splitCommand,
60
+ booleanWord,
51
61
  editorCompileProblem,
62
+ editorFollowCompile,
63
+ editorThemesAt,
64
+ editorFreeName,
65
+ typoNear,
66
+ typoOf,
67
+ editorAfterBuild,
68
+ editorFontHelp,
69
+ editorInstall,
70
+ editorSourcePath,
71
+ editorBuildExtra,
72
+ editorLoadedFonts,
73
+ editorColorModes,
52
74
  editorThemeHold,
53
75
  editorThemeRefusal,
54
76
  editorMissingSource,
@@ -106,7 +128,6 @@ const cmd = line => {
106
128
  .join(stem);
107
129
  };
108
130
  /** The project's invocation of a command line (cmd, under a name an action's own `cmd` parameter does not hide). */
109
- const cliLine = (/** @type {string} */ line) => cmd(line);
110
131
 
111
132
  /**
112
133
  * Print blocks, a blank line between them, with this project's run prefix
@@ -412,12 +433,12 @@ function newSettings(o, themeName = '<theme>') {
412
433
  }
413
434
 
414
435
  /**
415
- * The options a `new` was given, as flags for a suggested command, so a
416
- * corrected command makes the theme that was asked for.
417
- * @param {any} o
418
- * @returns {string}
436
+ * The settings flags of options as commander read them (camelCase keys),
437
+ * by the flag name `new` takes.
438
+ * @param {Record<string, any>} o
439
+ * @returns {Record<string, string | string[]>}
419
440
  */
420
- function newFlagLine(o) {
441
+ function newSettingsGiven(o) {
421
442
  /** @type {Record<string, string | string[]>} */
422
443
  const settings = {};
423
444
  for (const opt of newDoc.options ?? []) {
@@ -426,6 +447,17 @@ function newFlagLine(o) {
426
447
  const value = o[flag.replace(/-([a-z])/g, (_, c) => c.toUpperCase())];
427
448
  if (value != null) settings[flag] = value;
428
449
  }
450
+ return settings;
451
+ }
452
+
453
+ /**
454
+ * The options a `new` was given, as flags for a suggested command, so a
455
+ * corrected command makes the theme that was asked for.
456
+ * @param {any} o
457
+ * @returns {string}
458
+ */
459
+ function newFlagLine(o) {
460
+ const settings = newSettingsGiven(o);
429
461
  const parts = newFlagList(
430
462
  o.like == null ? undefined : String(o.like),
431
463
  settings,
@@ -434,6 +466,31 @@ function newFlagLine(o) {
434
466
  return parts.length ? ` ${parts.join(' ')}` : '';
435
467
  }
436
468
 
469
+ /**
470
+ * The options of a preview command as the one option reader reads them
471
+ * ({@link optionsAsWritten}): a typed dash (`—template`, `−−path`), other
472
+ * letters or a typo of an option it takes is that option, refused with
473
+ * the command as meant. Commander reads a word that starts with a typed
474
+ * dash as a word of the command, so it is read here. Null when every
475
+ * option is written as the command takes it.
476
+ * @param {string} command `add` under preview
477
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc
478
+ * @returns {null}
479
+ */
480
+ function previewOptionsRead(command, doc) {
481
+ const head = `${PREFIX} preview ${command}`;
482
+ const read = optionsAsWritten(command, doc, {group: 'preview', head});
483
+ if (!read) return null;
484
+ throw new AstryxError(
485
+ `${read.why}.`,
486
+ [
487
+ ...(read.line ? [{name: cmd(read.line), reason: 'do this instead'}] : []),
488
+ {name: cmd(`${head} --help`), reason: 'every option it takes'},
489
+ ],
490
+ ERROR_CODES.ERR_INVALID_OPTION,
491
+ );
492
+ }
493
+
437
494
  /**
438
495
  * Refuse a preview flag given twice with different values: the command
439
496
  * would keep only the last one without a word. Undefined when each is
@@ -484,14 +541,75 @@ function flagValues(name) {
484
541
  */
485
542
  function changeBlocks(r) {
486
543
  const d = r.data;
487
- const s = d.setting;
488
- const status =
544
+ // The status line names the value as saved, with a quote or space mark
545
+ // the text output would fold written as its CSS escape (\201C), so the
546
+ // text and the JSON name the same value.
547
+ const s = {
548
+ ...d.setting,
549
+ value: String(d.setting.value).replace(
550
+ /[\u00A0\u00AB\u00BB\u2000-\u200B\u2018-\u201F\u2039\u203A\u202F\u3000\u300C-\u300F]/g,
551
+ c => `\\${c.codePointAt(0)?.toString(16).toUpperCase()} `,
552
+ ),
553
+ };
554
+ const done =
489
555
  d.was != null
490
556
  ? `[ok] ${d.theme}: ${s.thing} ${d.was} -> ${s.value}`
491
557
  : `[ok] ${d.theme}: ${d.action === 'set' ? describe(s) : `removed ${describe(s)}; now ${/** @type {any} */ (d).now ?? "the base theme's value"} applies`}`;
558
+ // A problem the change made leads the result, right under the status
559
+ // line, which counts them: a tail-cut or head-cut output still shows it.
560
+ const {newProblems = [], ...rest} = /** @type {any} */ (d);
561
+ const status = newProblems.length
562
+ ? `${done}, but it made ${newProblems.length} new problem${newProblems.length > 1 ? 's' : ''}:`
563
+ : done;
492
564
  // On undo, `setting` and `removed` both name the setting removed, as in
493
565
  // the JSON; the status line says the base theme's value is back.
494
- return [status, ...project(/** @type {any} */ (d))];
566
+ return [
567
+ status,
568
+ ...(newProblems.length ? problemList(newProblems) : []),
569
+ ...changeFields(rest),
570
+ ];
571
+ }
572
+
573
+ /**
574
+ * Problems, one to an item: what is wrong, then the command that fixes it.
575
+ * @param {Array<{problem: string, fix: string | null}>} problems
576
+ */
577
+ function problemList(problems) {
578
+ return cappedList(
579
+ problems.map(p => (p.fix ? [p.problem, `fix: ${p.fix}`] : p.problem)),
580
+ 'every one, each with its fix',
581
+ );
582
+ }
583
+
584
+ /** How many problems the text shows before it counts the rest. */
585
+ const PROBLEMS_SHOWN = 8;
586
+
587
+ /**
588
+ * A list the text cuts after the first few, counting the rest; the JSON has
589
+ * every item.
590
+ * @param {Array<string | string[]>} items
591
+ * @param {string} [jsonHas] What the JSON holds for each item.
592
+ */
593
+ function cappedList(items, jsonHas = 'every one') {
594
+ const rest = items.length - PROBLEMS_SHOWN;
595
+ return [
596
+ list(items.slice(0, PROBLEMS_SHOWN)),
597
+ ...(rest > 0 ? [`and ${rest} more (--json lists ${jsonHas})`] : []),
598
+ ];
599
+ }
600
+
601
+ /**
602
+ * The plain fields of a change's data, with its problems as a cut list.
603
+ * @param {Record<string, unknown>} data
604
+ */
605
+ function changeFields(data) {
606
+ const {problems, ...rest} = /** @type {any} */ (data);
607
+ return [
608
+ ...project(rest),
609
+ ...(Array.isArray(problems) && problems.length
610
+ ? [section('problems:'), ...cappedList(problems)]
611
+ : []),
612
+ ];
495
613
  }
496
614
 
497
615
  /**
@@ -500,7 +618,17 @@ function changeBlocks(r) {
500
618
  * @param {import('../../../../api/theme-edit/theme-edit.type.mjs').ThemeEditShowResponse['data']} d
501
619
  */
502
620
  function showBlocks(d) {
503
- const {settings, colors, colorNotes, colorFiles, ...rest} = d;
621
+ const {
622
+ settings,
623
+ colors,
624
+ colorNotes,
625
+ colorFiles,
626
+ unreached,
627
+ // Every problem is in the open problems at the end, with its fix.
628
+ problems: _problems,
629
+ openProblems = [],
630
+ ...rest
631
+ } = d;
504
632
  const [head, ...others] = project(/** @type {any} */ (rest));
505
633
  return [
506
634
  head,
@@ -510,6 +638,15 @@ function showBlocks(d) {
510
638
  ? [section('settings:'), records(settings.map(s => flatRecord(s)))]
511
639
  : []),
512
640
  ...others,
641
+ // The parts the look leaves as the base has them, on one line: the
642
+ // most visible ten, and how many more (the JSON lists them all).
643
+ ...(unreached?.length
644
+ ? [
645
+ record({
646
+ unreached: `${unreached.slice(0, 10).join(', ')}${unreached.length > 10 ? `, and ${unreached.length - 10} more (show --json)` : ''} (their fill or text color is still the base's, and no setting is on them)`,
647
+ }),
648
+ ]
649
+ : []),
513
650
  ...(colors.length
514
651
  ? [
515
652
  section('colors:'),
@@ -523,6 +660,16 @@ function showBlocks(d) {
523
660
  colorFiles
524
661
  ? [section('colorFiles:'), record(colorFiles)]
525
662
  : record({colorFiles: 'none'}),
663
+ // Last, so the end of the output names what the theme still gets wrong
664
+ // (none, as an empty list in the JSON, prints nothing).
665
+ openProblems.length
666
+ ? [
667
+ section(
668
+ `openProblems: ${openProblems.length} the theme has now; each fix line fixes one`,
669
+ ),
670
+ ...problemList(openProblems),
671
+ ]
672
+ : [],
526
673
  ].flat();
527
674
  }
528
675
 
@@ -618,10 +765,11 @@ function lookupBlocks(d) {
618
765
  * unknown options so a design token (`--color-accent`) can be the thing
619
766
  * they name; a `--` word anywhere else is a mistyped option.
620
767
  * @param {string} command the subcommand, for the suggestion
768
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc the command's doc, which lists its options
621
769
  * @param {Array<string | undefined>} rest the operands after the thing
622
770
  * @returns {ReturnType<typeof cliError> | null}
623
771
  */
624
- function strayOption(command, rest) {
772
+ function strayOption(command, doc, rest) {
625
773
  // A scope flag given twice would keep only the last one without a word.
626
774
  for (const flag of ['on', 'when', 'state', 'mode']) {
627
775
  const all = flagValues(flag);
@@ -639,38 +787,571 @@ function strayOption(command, rest) {
639
787
  },
640
788
  );
641
789
  }
642
- const word = rest.find(w => typeof w === 'string' && w.startsWith('--'));
790
+ // A value pasted with a token's label (`'--color-accent: #e11d48'`) is
791
+ // a value, read by the label reader, not an option.
792
+ const word = rest.find(
793
+ w =>
794
+ typeof w === 'string' &&
795
+ w.startsWith('--') &&
796
+ !/^--[a-z0-9-]+\s*:\s*\S/i.test(w),
797
+ );
643
798
  if (word == null) return null;
644
- return cliError(
645
- `unknown option '${word}': only the thing a change names may start with -- (a design token such as --color-accent).`,
799
+ // An option the command takes, after the POSIX "--": every word after it
800
+ // is a value, so the option was not read. The line without the "--" is
801
+ // the one meant.
802
+ const argv = process.argv;
803
+ const dashes = argv.indexOf('--', argv.indexOf(command) + 1);
804
+ const takes = (doc.options ?? []).flatMap(o =>
805
+ String(o.flag)
806
+ .split(/[\s,]+/)
807
+ .filter(w => w.startsWith('--')),
808
+ );
809
+ if (dashes >= 0 && takes.includes(word) && argv.indexOf(word) > dashes) {
810
+ const words = argv
811
+ .slice(argv.indexOf(command) + 1)
812
+ .filter((w, i) => i !== dashes - argv.indexOf(command) - 1);
813
+ return cliError(
814
+ `every word after "--" is a value, so ${word} after it is not read as the option ${command} takes; write the line without the "--" (a value that starts with a dash, such as -0.5px, needs none). Nothing was changed.`,
815
+ {
816
+ suggestions: [
817
+ {
818
+ name: cmd(
819
+ `${EDITOR} ${command} ${words.map(w => (/^--[a-z]/.test(w) && takes.includes(w) ? w : quoteCommandArgument(w))).join(' ')}`,
820
+ ),
821
+ reason: 'do this instead',
822
+ },
823
+ ],
824
+ code: ERROR_CODES.ERR_INVALID_ARGUMENT,
825
+ },
826
+ );
827
+ }
828
+ return strayRefusal(command, doc, `${EDITOR} ${command}`, {
829
+ option: word,
830
+ note: 'a design token (such as --color-accent) is the thing a change names, before its value',
831
+ });
832
+ }
833
+
834
+ /**
835
+ * What a theme command answers for an option it does not take, or for
836
+ * words past what it takes: the one stray reader every editor and preview
837
+ * command uses. It names the options the command takes; it offers the same
838
+ * command without the stray words only when that is safe to run
839
+ * (`safeLine`: show reads and changes nothing; a preview remove without its
840
+ * option would remove the whole preview), and always the command's help.
841
+ * @param {string} command the command's words after the group (`set`, `preview remove`)
842
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc the command's doc, which lists its options
843
+ * @param {string} head the command line's start, as the project runs it
844
+ * @param {{option?: string, extra?: string[], note?: string}} stray an option it does not take, or words past what it takes, and a sentence about them
845
+ * @param {string | null} [safeLine] the command without them, when it is safe to run
846
+ * @returns {{message: string, suggestions: Array<{name: string, reason: string}>, code: string}}
847
+ */
848
+ function strayAnswer(command, doc, head, stray, safeLine = null) {
849
+ const takes = [
850
+ ...(doc.options ?? []).flatMap(o =>
851
+ String(o.flag)
852
+ .split(/[\s,]+/)
853
+ .filter(w => w.startsWith('--')),
854
+ ),
855
+ '--json',
856
+ ].filter((w, i, all) => all.indexOf(w) === i);
857
+ const list =
858
+ takes.length > 1
859
+ ? `${takes.slice(0, -1).join(', ')} and ${takes.at(-1)}`
860
+ : takes.join('');
861
+ const message = stray.option
862
+ ? `unknown option '${stray.option}': ${command} takes ${list}${stray.note ? `; ${stray.note}` : ''}.`
863
+ : `${command} does not take "${(stray.extra ?? []).join(' ')}"${stray.note ? `; ${stray.note}` : ''}.`;
864
+ return {
865
+ message,
866
+ suggestions: [
867
+ ...(safeLine ? [{name: cmd(safeLine), reason: 'do this instead'}] : []),
868
+ {
869
+ name: cmd(`${head} --help`),
870
+ reason: stray.option ? 'every option it takes' : 'what it takes',
871
+ },
872
+ ],
873
+ code: stray.option
874
+ ? ERROR_CODES.ERR_INVALID_OPTION
875
+ : ERROR_CODES.ERR_INVALID_ARGUMENT,
876
+ };
877
+ }
878
+
879
+ /**
880
+ * {@link strayAnswer} as the refusal the command prints.
881
+ * @param {string} command
882
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc
883
+ * @param {string} head
884
+ * @param {{option?: string, extra?: string[], note?: string}} stray
885
+ * @param {string | null} [safeLine]
886
+ */
887
+ function strayRefusal(command, doc, head, stray, safeLine = null) {
888
+ const a = strayAnswer(command, doc, head, stray, safeLine);
889
+ return cliError(a.message, {suggestions: a.suggestions, code: a.code});
890
+ }
891
+
892
+ /**
893
+ * Read the options of an editor command as written, the one reading every
894
+ * editor command gives them: an option in other letters, with one dash or
895
+ * a typed dash (`--On`, `-only`, `\u2014only`) or within the one typo limit
896
+ * of an option the command takes (`--olny`) is that option; a boolean
897
+ * option written with a value (`--png=false`, `--only true`) takes none,
898
+ * and its value is read by the one yes/no reader (booleanWord). Null when
899
+ * every option is written as the command takes it; else the reason, and
900
+ * the command as meant (the option as the command takes it; a boolean as
901
+ * itself for yes, left out for no), or no command when a boolean's value
902
+ * reads as neither.
903
+ * @param {string} command the subcommand (`set`, `undo`, `new`, `show`, how's word; `add` under preview)
904
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc the command's doc, which lists its options
905
+ * @param {{group: string, head: string}} [where] the group word the subcommand follows (`editor`, `preview`) and the command line's start
906
+ * @returns {{why: string, line: string | null} | null}
907
+ */
908
+ function optionsAsWritten(
909
+ command,
910
+ doc,
911
+ where = {group: 'editor', head: `${EDITOR} ${command}`},
912
+ ) {
913
+ const flags = (doc.options ?? []).map(opt => String(opt.flag));
914
+ const names = (/** @type {(f: string) => boolean} */ keep) =>
915
+ flags
916
+ .filter(keep)
917
+ .flatMap(f => f.split(/[\s,]+/).filter(w => w.startsWith('--')));
918
+ const booleans = ['--json', ...names(f => !/[<[]/.test(f))];
919
+ const all = [...booleans, ...names(f => /[<[]/.test(f))];
920
+ // The options that must have a value (`--section <name>`).
921
+ const valued = names(f => /</.test(f));
922
+ /** The option a word names, as the command takes it, or null. @param {string} word */
923
+ const meant = word => {
924
+ const w = word.toLowerCase();
925
+ if (all.includes(`--${w}`)) return `--${w}`;
926
+ const near = all.filter(o => typoNear(w, o.slice(2)));
927
+ return near.length === 1 ? near[0] : null;
928
+ };
929
+ const argv = process.argv;
930
+ const at = argv.indexOf(command, argv.indexOf(where.group) + 1);
931
+ if (at < 0) return null;
932
+ /** @type {string[]} */
933
+ const words = [];
934
+ /** @type {string | null} */
935
+ let why = null;
936
+ let unread = false;
937
+ for (let i = at + 1; i < argv.length; i += 1) {
938
+ const a = argv[i];
939
+ if (a === '--') {
940
+ words.push(...argv.slice(i));
941
+ break;
942
+ }
943
+ // Any run of up to three hyphens and dash-like characters (an en or em
944
+ // dash, a minus sign, a non-breaking hyphen: `-—on`, `−−on`) is the
945
+ // option's dashes, as normalizeEntry reads a token's.
946
+ const m =
947
+ /^([-\u2010-\u2015\u2212\ufe58\ufe63\uff0d]{1,3})([A-Za-z][A-Za-z-]*)(?:=(.*))?$/.exec(
948
+ a,
949
+ );
950
+ const flag = m ? meant(m[2]) : null;
951
+ if (!m || !flag) {
952
+ if (a !== '--json') words.push(a);
953
+ continue;
954
+ }
955
+ const written = m[3] == null ? `${m[1]}${m[2]}` : a.split('=')[0];
956
+ if (written !== flag)
957
+ why ??= `unknown option '${written}' (did you mean ${flag}?)`;
958
+ const next = argv[i + 1];
959
+ if (booleans.includes(flag)) {
960
+ // A value after a boolean option, joined by `=` or as the next word
961
+ // when that word is a yes or a no.
962
+ const value = m[3] ?? (booleanWord(next) != null ? String(next) : null);
963
+ if (value != null) {
964
+ if (m[3] == null) i += 1;
965
+ const read = booleanWord(value);
966
+ const shown = m[3] == null ? `${a} ${value}` : a;
967
+ if (read == null) unread = true;
968
+ why ??=
969
+ read == null
970
+ ? `${flag} takes no value ("${shown}"), and "${value}" reads as neither yes nor no: give ${flag} alone for yes, or leave it out`
971
+ : `${flag} takes no value ("${shown}"): give it alone for yes, or leave it out`;
972
+ if (read === true && flag !== '--json' && !words.includes(flag))
973
+ words.push(flag);
974
+ continue;
975
+ }
976
+ // A yes/no option given twice is one option.
977
+ if (flag !== '--json' && !words.includes(flag)) words.push(flag);
978
+ // A word right after a mistyped yes/no option that reads as neither
979
+ // (`--olny dark`) is no value of it: the line leaves it out, and says
980
+ // so, never gluing it onto the setting's value.
981
+ if (written !== flag && next != null && !/^-/.test(next)) {
982
+ i += 1;
983
+ why = `${why}; "${next}" after it is no value of ${flag}, so the line leaves it out`;
984
+ }
985
+ continue;
986
+ }
987
+ // An option that takes a value, given none, is left out of the line.
988
+ if (m[3] == null && (next == null || /^-/.test(next))) {
989
+ if (valued.includes(flag)) why ??= `${flag} was given no value`;
990
+ continue;
991
+ }
992
+ words.push(flag);
993
+ if (m[3] != null) words.push(m[3]);
994
+ }
995
+ if (!why) return null;
996
+ return {
997
+ why,
998
+ line: unread
999
+ ? null
1000
+ : `${where.head} ${words.map(w => (/^--[a-z]/.test(w) && all.includes(w) ? w : quoteCommandArgument(w))).join(' ')}`.trim(),
1001
+ };
1002
+ }
1003
+
1004
+ /**
1005
+ * An option a theme command does not take, or one written with no value,
1006
+ * as the one option reader reads it (the json shim asks, for the options
1007
+ * commander refuses): the option meant, or the command without the empty
1008
+ * option, with the command that works, else what the command takes and its
1009
+ * help. Undefined for any other command.
1010
+ * Each offered command is checked as that command checks it (set and undo
1011
+ * by their own checks, new by new's, show's section by show's), so a line
1012
+ * offered is one that works; leaving out an option that narrows what the
1013
+ * command acts on (--on, --when, --state, --mode, --path, --like, --theme)
1014
+ * would widen it, so that line is never offered.
1015
+ * @param {any} c the command commander refused
1016
+ * @param {string} [code] commander's code for the refusal
1017
+ * @returns {Promise<{message: string, suggestions: Array<{name: string, reason: string}>} | undefined> | undefined}
1018
+ */
1019
+ function unknownThemeOption(c, code = 'commander.unknownOption') {
1020
+ const sub = c?.name?.();
1021
+ const group = c?.parent?.name?.();
1022
+ const doc =
1023
+ group === 'preview'
1024
+ ? /** @type {Record<string, import('@astryxdesign/cli/authoring').CommandDoc>} */ ({
1025
+ add: previewAddDoc,
1026
+ app: previewAppDoc,
1027
+ list: previewListDoc,
1028
+ remove: previewRemoveDoc,
1029
+ })[sub]
1030
+ : group === 'editor'
1031
+ ? /** @type {Record<string, import('@astryxdesign/cli/authoring').CommandDoc>} */ ({
1032
+ new: newDoc,
1033
+ set: setDoc,
1034
+ show: showDoc,
1035
+ undo: undoDoc,
1036
+ how: howDoc,
1037
+ })[sub]
1038
+ : undefined;
1039
+ if (!doc) return undefined;
1040
+ return themeOptionAnswer(c, code, sub, group, doc);
1041
+ }
1042
+
1043
+ /**
1044
+ * The commands that carry out a line the option reader built, each checked
1045
+ * as its own command checks it: set and undo by their checks (a repair
1046
+ * folded in), new by new's (its own repairs offered), show's --section by
1047
+ * show's; none when the command refuses it with no repair.
1048
+ * @param {string} group
1049
+ * @param {string} sub
1050
+ * @param {string} line
1051
+ * @returns {Promise<Array<{name: string, reason: string}>>}
1052
+ */
1053
+ async function checkedOptionLines(group, sub, line) {
1054
+ const cwd = process.cwd();
1055
+ const offer = (/** @type {string} */ l) => [
1056
+ {name: cmd(l), reason: 'do this instead'},
1057
+ ];
1058
+ if (group === 'editor' && (sub === 'set' || sub === 'undo')) {
1059
+ const checked = await editorCheckedLine(sub, line, cwd);
1060
+ return checked ? offer(checked) : [];
1061
+ }
1062
+ if (group === 'editor' && sub === 'new') {
1063
+ const words = splitCommand(line.slice(`${EDITOR} new `.length)) ?? [];
1064
+ const [name, ...rest] = words;
1065
+ /** @type {Record<string, string | string[]>} */
1066
+ const settings = {};
1067
+ let like;
1068
+ let png = false;
1069
+ for (let i = 0; i < rest.length; i += 1) {
1070
+ const m = /^--([a-z-]+)$/.exec(rest[i]);
1071
+ if (!m) continue;
1072
+ if (m[1] === 'png') png = true;
1073
+ else if (rest[i + 1] != null) {
1074
+ const v = rest[(i += 1)];
1075
+ if (m[1] === 'like') like = v;
1076
+ else
1077
+ settings[m[1]] =
1078
+ settings[m[1]] == null ? v : [...[settings[m[1]]].flat(), v];
1079
+ }
1080
+ }
1081
+ const lines = await editorCheckedNewLines(line, name, {
1082
+ cwd,
1083
+ ...(like != null ? {like} : {}),
1084
+ settings,
1085
+ png,
1086
+ });
1087
+ return lines.map(x => ({
1088
+ name: cmd(x.name),
1089
+ reason: x.reason ?? 'do this instead',
1090
+ }));
1091
+ }
1092
+ if (group === 'editor' && sub === 'show') {
1093
+ const lines = editorCheckedShowLines(line);
1094
+ return lines.map(x => ({
1095
+ name: cmd(x.name),
1096
+ reason: x.reason ?? 'do this instead',
1097
+ }));
1098
+ }
1099
+ return offer(line);
1100
+ }
1101
+
1102
+ /** Options whose absence widens what a command acts on, or changes it. */
1103
+ const NARROWING_OPTIONS = Object.freeze([
1104
+ 'on',
1105
+ 'when',
1106
+ 'state',
1107
+ 'mode',
1108
+ 'path',
1109
+ 'like',
1110
+ 'theme',
1111
+ ]);
1112
+
1113
+ /**
1114
+ * {@link unknownThemeOption}'s answer for a theme command.
1115
+ * @param {any} c
1116
+ * @param {string} code
1117
+ * @param {string} sub
1118
+ * @param {string} group
1119
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc
1120
+ * @returns {Promise<{message: string, suggestions: Array<{name: string, reason: string}>} | undefined>}
1121
+ */
1122
+ async function themeOptionAnswer(c, code, sub, group, doc) {
1123
+ const head = `${group === 'preview' ? `${PREFIX} preview` : EDITOR} ${sub}`;
1124
+ const help = {name: cmd(`${head} --help`), reason: 'every option it takes'};
1125
+ const read = optionsAsWritten(sub, doc, {group, head});
1126
+ // An option given no value is left out of the offered command, unless
1127
+ // leaving it out widens what the command acts on (a set without its part
1128
+ // styles the whole theme; a preview remove without its page removes the
1129
+ // whole preview).
1130
+ const valued = (doc.options ?? [])
1131
+ .filter(o => /</.test(String(o.flag)))
1132
+ .flatMap(o =>
1133
+ String(o.flag)
1134
+ .split(/[\s,]+/)
1135
+ .filter(w => w.startsWith('--'))
1136
+ .map(w => w.slice(2)),
1137
+ );
1138
+ const argv = process.argv;
1139
+ const at = argv.indexOf(sub, argv.indexOf(group) + 1);
1140
+ const emptied = argv
1141
+ .slice(at + 1)
1142
+ .filter(
1143
+ (w, i, rest) =>
1144
+ /^--[a-z-]+$/.test(w) &&
1145
+ valued.includes(w.slice(2)) &&
1146
+ (rest[i + 1] == null || rest[i + 1].startsWith('-')),
1147
+ )
1148
+ .map(w => w.slice(2));
1149
+ const widens =
1150
+ code === 'commander.optionMissingArgument' &&
1151
+ (emptied.some(o => NARROWING_OPTIONS.includes(o)) ||
1152
+ (group === 'preview' && sub === 'remove'));
1153
+ if (read) {
1154
+ const lines =
1155
+ read.line && !widens
1156
+ ? await checkedOptionLines(group, sub, read.line)
1157
+ : [];
1158
+ return {message: `${read.why}.`, suggestions: [...lines, help]};
1159
+ }
1160
+ if (code === 'commander.excessArguments' && group === 'preview')
1161
+ return previewExtraWords(sub, doc, head);
1162
+ if (code !== 'commander.unknownOption' || group !== 'preview')
1163
+ return undefined;
1164
+ const takes = (doc.options ?? []).flatMap(o =>
1165
+ String(o.flag)
1166
+ .split(/[\s,]+/)
1167
+ .filter(w => w.startsWith('--')),
1168
+ );
1169
+ const from = argv.indexOf(sub, argv.indexOf('preview') + 1);
1170
+ const stray = argv
1171
+ .slice(from + 1)
1172
+ .find(
1173
+ (w, i, rest) =>
1174
+ w.startsWith('-') &&
1175
+ !rest.slice(0, i).includes('--') &&
1176
+ ![...takes, '--json', '--help', '-h'].includes(w.split('=')[0]),
1177
+ );
1178
+ // A folder name that starts with "-" reads as an option: it goes after
1179
+ // --, and that line is the safe one.
1180
+ const folder =
1181
+ sub === 'app' && stray && /^-[^-]/.test(stray) && stray.length > 2;
1182
+ const a = strayAnswer(
1183
+ `preview ${sub}`,
1184
+ doc,
1185
+ head,
646
1186
  {
647
- suggestions: [
648
- {
649
- name: cmd(`${EDITOR} ${command} --help`),
650
- reason: 'every option it takes',
651
- },
652
- ],
653
- code: ERROR_CODES.ERR_INVALID_OPTION,
1187
+ option: stray ?? '',
1188
+ ...(folder
1189
+ ? {note: 'a folder name that starts with "-" goes after --'}
1190
+ : {}),
654
1191
  },
1192
+ folder ? `${head} -- ${stray}` : null,
655
1193
  );
1194
+ return {message: a.message, suggestions: a.suggestions};
656
1195
  }
657
1196
 
658
1197
  /**
659
- * A refusal for words after what a command takes, which would otherwise be
660
- * dropped without a word; null when there are none.
1198
+ * The refusal of options not written as the command takes them, with the
1199
+ * command as meant when there is one.
661
1200
  * @param {string} command
662
- * @param {string[]} extra
1201
+ * @param {{why: string, line: string | null, lines?: Array<{name: string, reason: string}>}} read
1202
+ * `lines`: the commands that carry out the line, checked
663
1203
  */
664
- function extraWords(command, extra) {
665
- if (!extra.length) return null;
666
- return cliError(`${command} does not take "${extra.join(' ')}".`, {
1204
+ function optionsRefusal(command, read) {
1205
+ return cliError(`${read.why}.`, {
667
1206
  suggestions: [
668
- {name: cmd(`${EDITOR} ${command} --help`), reason: 'what it takes'},
1207
+ ...(read.lines ??
1208
+ (read.line ? [{name: cmd(read.line), reason: 'do this instead'}] : [])),
1209
+ {
1210
+ name: cmd(`${EDITOR} ${command} --help`),
1211
+ reason: 'every option it takes',
1212
+ },
669
1213
  ],
670
- code: ERROR_CODES.ERR_INVALID_ARGUMENT,
1214
+ code: ERROR_CODES.ERR_INVALID_OPTION,
671
1215
  });
672
1216
  }
673
1217
 
1218
+ /**
1219
+ * {@link optionsAsWritten} as a refusal, or null.
1220
+ * @param {string} command
1221
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc
1222
+ */
1223
+ function readOptions(command, doc) {
1224
+ const read = optionsAsWritten(command, doc);
1225
+ return read ? optionsRefusal(command, read) : null;
1226
+ }
1227
+
1228
+ /**
1229
+ * {@link readOptions} with its line checked as every offered line is, by
1230
+ * the command's own checks (set and undo with a repair folded in, new with
1231
+ * new's repairs, show's section by show's): a line the command refuses with
1232
+ * no repair is not offered.
1233
+ * @param {string} command
1234
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc
1235
+ */
1236
+ async function readOptionsChecked(command, doc) {
1237
+ const read = optionsAsWritten(command, doc);
1238
+ if (!read) return null;
1239
+ const lines = read.line
1240
+ ? await checkedOptionLines('editor', command, read.line)
1241
+ : [];
1242
+ return optionsRefusal(command, {...read, lines});
1243
+ }
1244
+
1245
+ /**
1246
+ * Words past what a preview command takes (`preview list overview`,
1247
+ * `preview remove colors components`, `preview app my app`), through the
1248
+ * one stray reader: the same command without them when that is safe to run
1249
+ * (list reads only; app with the words as one folder name, which a
1250
+ * folder with a space needs quoted, refused when the folder is not free),
1251
+ * never for remove, whose first word alone would remove a page not meant;
1252
+ * and always the command's help.
1253
+ * @param {string} sub `app`, `list` or `remove`
1254
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc
1255
+ * @param {string} head the command line's start, as the project runs it
1256
+ */
1257
+ function previewExtraWords(sub, doc, head) {
1258
+ const valued = new Set(
1259
+ (doc.options ?? [])
1260
+ .filter(o => /</.test(String(o.flag)))
1261
+ .flatMap(o =>
1262
+ String(o.flag)
1263
+ .split(/[\s,]+/)
1264
+ .filter(w => w.startsWith('-')),
1265
+ ),
1266
+ );
1267
+ const argv = process.argv;
1268
+ const from = argv.indexOf(sub, argv.indexOf('preview') + 1);
1269
+ /** @type {string[]} */
1270
+ const words = [];
1271
+ /** @type {string[]} */
1272
+ const options = [];
1273
+ for (let i = from + 1; from >= 0 && i < argv.length; i++) {
1274
+ const w = argv[i];
1275
+ if (w === '--') {
1276
+ words.push(...argv.slice(i + 1));
1277
+ break;
1278
+ }
1279
+ if (w.startsWith('-')) {
1280
+ if (w === '--json') continue;
1281
+ options.push(w);
1282
+ if (
1283
+ valued.has(w.split('=')[0]) &&
1284
+ !w.includes('=') &&
1285
+ i + 1 < argv.length
1286
+ )
1287
+ options.push(quoteCommandArgument(argv[++i]));
1288
+ continue;
1289
+ }
1290
+ words.push(w);
1291
+ }
1292
+ const takes = sub === 'list' ? 0 : 1;
1293
+ const extra = words.slice(takes);
1294
+ const flags = options.length ? ` ${options.join(' ')}` : '';
1295
+ const safe =
1296
+ sub === 'list'
1297
+ ? `${head}${flags}`
1298
+ : sub === 'app' && words.length
1299
+ ? `${head} ${quoteCommandArgument(words.join(' '))}${flags}`
1300
+ : null;
1301
+ const a = strayAnswer(
1302
+ `preview ${sub}`,
1303
+ doc,
1304
+ head,
1305
+ {
1306
+ extra,
1307
+ note:
1308
+ sub === 'list'
1309
+ ? 'it takes no words'
1310
+ : sub === 'app'
1311
+ ? 'it takes one folder: a folder name with a space goes in quotes'
1312
+ : 'it takes one page; remove pages one at a time',
1313
+ },
1314
+ safe,
1315
+ );
1316
+ return {message: a.message, suggestions: a.suggestions};
1317
+ }
1318
+
1319
+ /**
1320
+ * Refuse an option `show` does not take with a show that works: the same
1321
+ * show without it, and its help (an option the one reader names, and one
1322
+ * written with a value, are read first by {@link readOptions}). Null when
1323
+ * there is none.
1324
+ * @param {string} name
1325
+ * @param {unknown[]} rest the words after the theme
1326
+ * @param {{png?: boolean, section?: string}} o the options read
1327
+ */
1328
+ function showStray(name, rest, o) {
1329
+ const stray = rest.map(String).find(w => w.startsWith('-'));
1330
+ if (stray == null) return null;
1331
+ // An option the one reader names never comes here (readOptions reads
1332
+ // it first): this one is none show takes, so the show it offers leaves it
1333
+ // out and names no guess.
1334
+ return strayRefusal(
1335
+ 'show',
1336
+ showDoc,
1337
+ `${EDITOR} show`,
1338
+ {option: stray},
1339
+ `${EDITOR} show ${name}${o.section ? ` --section ${o.section}` : ''}${o.png ? ' --png' : ''}`,
1340
+ );
1341
+ }
1342
+
1343
+ /**
1344
+ * A refusal for words after what a command takes, which would otherwise be
1345
+ * dropped without a word (the one stray reader); null when there are none.
1346
+ * @param {string} command
1347
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc
1348
+ * @param {string[]} extra
1349
+ */
1350
+ function extraWords(command, doc, extra) {
1351
+ if (!extra.length) return null;
1352
+ return strayRefusal(command, doc, `${EDITOR} ${command}`, {extra});
1353
+ }
1354
+
674
1355
  /**
675
1356
  * Help that explains exactly what a subcommand does: its whole description
676
1357
  * under the usage line, while the group's list keeps the one-line summary.
@@ -727,18 +1408,24 @@ function defineGroup(parent, doc) {
727
1408
  if (extras.length > 0) {
728
1409
  const word = String(extras[0]).toLowerCase();
729
1410
  const group = doc.name.split(' ').at(-1) ?? '';
730
- const moved =
731
- MOVED[group]?.[word] ??
732
- // `preview <theme>`: the pages for a theme.
733
- (group === 'preview' && /^[a-z][a-z0-9-]*$/.test(word)
734
- ? `add --theme ${word}`
735
- : null);
736
1411
  const ranked = (cmd.commands ?? [])
737
1412
  .map(command => command.name())
738
1413
  .sort(
739
1414
  (a, b) =>
740
1415
  levenshteinDistance(word, a) - levenshteinDistance(word, b),
741
1416
  );
1417
+ // A typo of a subcommand (lst, remve) is that subcommand; any
1418
+ // other word after `preview` that names an editor theme here asks
1419
+ // for that theme's pages.
1420
+ const typo = typoOf(word, ranked[0] ?? '') ? ranked[0] : null;
1421
+ const moved =
1422
+ MOVED[group]?.[word] ??
1423
+ (typo
1424
+ ? null
1425
+ : group === 'preview' &&
1426
+ editorThemesAt(process.cwd()).includes(word)
1427
+ ? `add --theme ${word}`
1428
+ : null);
742
1429
  return cliError(
743
1430
  `unknown subcommand '${doc.name} ${String(extras[0])}'${moved ? `; it is ${here} ${moved}` : ''}`,
744
1431
  {
@@ -777,12 +1464,34 @@ function defineGroup(parent, doc) {
777
1464
  return cmd;
778
1465
  }
779
1466
 
1467
+ /**
1468
+ * A preview command's result, once it is in: this client owns its process,
1469
+ * so a stop that lands while the result is printed is held, and a printed
1470
+ * ok never ends with exit 130. The API itself leaves no listener behind.
1471
+ * @template T
1472
+ * @param {Promise<T>} result
1473
+ * @returns {Promise<T>}
1474
+ */
1475
+ async function resultStands(result) {
1476
+ const r = await result;
1477
+ for (const sig of /** @type {const} */ (['SIGINT', 'SIGTERM']))
1478
+ if (!process.listeners(sig).includes(heldStop)) process.on(sig, heldStop);
1479
+ return r;
1480
+ }
1481
+
1482
+ /** A stop after a preview command finished: its result stands. */
1483
+ function heldStop() {}
1484
+
780
1485
  /**
781
1486
  * Register `theme` and its subcommands under the `experimental` group.
782
1487
  * @param {import('commander').Command} group the `experimental` command
783
1488
  * @param {import('commander').Command} program the root program
784
1489
  */
785
1490
  export function registerExperimentalTheme(group, program) {
1491
+ // A command run with no theme names the app's only theme.
1492
+ setEditorThemeList(editorThemesAt);
1493
+ setEditorFreeName(editorFreeName);
1494
+ setUnknownOptionReader(unknownThemeOption);
786
1495
  const theme = defineGroup(group, groupDoc);
787
1496
  explained(theme, groupDoc);
788
1497
  theme.addHelpText(
@@ -799,14 +1508,18 @@ export function registerExperimentalTheme(group, program) {
799
1508
  const newCli = explained(
800
1509
  defineCommand(editor, newDoc, {
801
1510
  fn: newFn,
802
- action: (
1511
+ action: async (
803
1512
  /** @type {string} */ name,
804
1513
  /** @type {any} */ o,
805
1514
  /** @type {any} */ cmd,
806
1515
  ) =>
1516
+ // An option given a value is refused before the run, as for every
1517
+ // other editor command: a refusal inside run is thrown, never
1518
+ // printed there.
1519
+ (await readOptionsChecked('new', newDoc)) ??
807
1520
  run(
808
1521
  program,
809
- () => {
1522
+ async () => {
810
1523
  // An option new does not take (--force, --dry-run, -t) is refused
811
1524
  // with new's help, as every editor command's unknown option is.
812
1525
  const takes = new Set(
@@ -824,55 +1537,183 @@ export function registerExperimentalTheme(group, program) {
824
1537
  (/** @type {string} */ w) =>
825
1538
  /^-/.test(w) && !takes.has(w.split('=')[0]),
826
1539
  );
1540
+ // `--base` is the dial new takes as --like.
1541
+ if (stray && stray.split('=')[0] === '--base') {
1542
+ const args = (cmd?.args ?? []).slice(1).map(String);
1543
+ const at = args.indexOf(stray);
1544
+ const value = stray.includes('=')
1545
+ ? stray.slice(stray.indexOf('=') + 1)
1546
+ : args[at + 1];
1547
+ // Thrown, as every refusal inside run is: run prints it once
1548
+ // (a refusal printed here and then caught again by run would
1549
+ // print twice where exit does not end the process).
1550
+ throw new AstryxError(
1551
+ `new takes the base theme as --like, not --base.`,
1552
+ value
1553
+ ? [
1554
+ {
1555
+ name: `${EDITOR} new ${quoteCommandArgument(name)}${newFlagLine({...o, like: value})}`,
1556
+ reason: 'do this instead',
1557
+ },
1558
+ ]
1559
+ : [
1560
+ {
1561
+ name: `${EDITOR} new --help`,
1562
+ reason: 'every option it takes',
1563
+ },
1564
+ ],
1565
+ ERROR_CODES.ERR_INVALID_OPTION,
1566
+ );
1567
+ }
827
1568
  if (stray)
828
- return cliError(`unknown option '${stray}'.`, {
829
- suggestions: [
1569
+ throw new AstryxError(
1570
+ `unknown option '${stray}'.`,
1571
+ [
830
1572
  {
831
- name: cliLine(`${EDITOR} new --help`),
1573
+ name: `${EDITOR} new --help`,
832
1574
  reason: 'every option it takes',
833
1575
  },
834
1576
  ],
835
- code: ERROR_CODES.ERR_INVALID_OPTION,
836
- });
1577
+ ERROR_CODES.ERR_INVALID_OPTION,
1578
+ );
837
1579
  // A word after the name is never dropped without a word.
838
1580
  const extra = (cmd?.args ?? []).slice(1);
839
1581
  if (extra.length) {
840
1582
  // Words after `--` that are `--<option> <value>` pairs new
841
1583
  // takes become options; the other words were most likely
842
1584
  // part of the name. The options given stay in the suggestion.
843
- /** @type {Record<string, unknown>} */
1585
+ /** @type {Record<string, any>} */
844
1586
  const given = {...o};
845
1587
  /** @type {string[]} */
846
1588
  const words = [];
847
- for (let i = 0; i < extra.length; i++) {
848
- const w = String(extra[i]);
849
- if (w.startsWith('--')) {
850
- const key = w
851
- .slice(2)
852
- .replace(/-([a-z])/g, (_, c) => c.toUpperCase());
853
- if (extra[i + 1] != null && given[key] == null)
854
- given[key] = extra[++i];
1589
+ // Each word in the order typed: one that follows a dial's
1590
+ // value with no option between is more of that value, read as
1591
+ // set reads it (`--font Open Sans` is the family Open Sans,
1592
+ // `--mode Dark Only` the mode dark-only), while a word is left
1593
+ // for the name or the name was typed already; a base name
1594
+ // (--like) takes one word, and a word after it is a word of the
1595
+ // name.
1596
+ const valueFlags = new Set(
1597
+ (newDoc.options ?? [])
1598
+ .filter(opt => /</.test(String(opt.flag)))
1599
+ .map(opt => String(opt.flag).split(' ')[0]),
1600
+ );
1601
+ const dialFlags = new Set(
1602
+ (newDoc.options ?? [])
1603
+ .filter(opt => opt.param === 'options.settings')
1604
+ .map(opt => String(opt.flag).split(' ')[0]),
1605
+ );
1606
+ const camel = (/** @type {string} */ f) =>
1607
+ f.slice(2).replace(/-([a-z])/g, (_, c) => c.toUpperCase());
1608
+ const argv = process.argv;
1609
+ const from = argv.indexOf('new', argv.indexOf('editor') + 1);
1610
+ /** @type {string | null} */
1611
+ let open = null;
1612
+ let named = false;
1613
+ /** The word typed as the name, where it is not the first. @type {string | null} */
1614
+ let nameWord = null;
1615
+ /** The words read as more of a value. @type {string[]} */
1616
+ const intoValues = [];
1617
+ /**
1618
+ * Whether a word is left for the name after argv[i]: a later
1619
+ * word that is no option's value (`--font Open Sans --like
1620
+ * neutral my-theme` leaves my-theme). The last such word is
1621
+ * the name.
1622
+ * @param {number} i
1623
+ */
1624
+ const wordLeft = i => {
1625
+ for (let j = i + 1; j < argv.length; j++) {
1626
+ const x = argv[j];
1627
+ if (x === '--') return false;
1628
+ if (x.startsWith('-')) {
1629
+ if (valueFlags.has(x.split('=')[0]) && !x.includes('='))
1630
+ j += 1;
1631
+ continue;
1632
+ }
1633
+ return true;
1634
+ }
1635
+ return false;
1636
+ };
1637
+ for (let i = from + 1; from >= 0 && i < argv.length; i++) {
1638
+ const w = argv[i];
1639
+ if (w === '--') {
1640
+ // After `--`, `--<option> <value>` pairs new takes.
1641
+ for (let j = i + 1; j < argv.length; j++) {
1642
+ const x = argv[j];
1643
+ if (x.startsWith('--')) {
1644
+ if (argv[j + 1] != null && given[camel(x)] == null)
1645
+ given[camel(x)] = argv[++j];
1646
+ } else words.push(x);
1647
+ }
1648
+ break;
1649
+ }
1650
+ if (w.startsWith('-')) {
1651
+ const flag = w.split('=')[0];
1652
+ if (valueFlags.has(flag) && !w.includes('=')) i += 1;
1653
+ open = dialFlags.has(flag) ? camel(flag) : null;
1654
+ continue;
1655
+ }
1656
+ // Words straight after an option's value are more of it
1657
+ // while a later word is left for the name; the name ends the
1658
+ // value, and a word after the name is never more of it.
1659
+ if (open && !named && wordLeft(i)) {
1660
+ const had = given[open];
1661
+ given[open] = Array.isArray(had)
1662
+ ? [...had.slice(0, -1), `${had.at(-1)} ${w}`]
1663
+ : `${had} ${w}`;
1664
+ intoValues.push(w);
1665
+ continue;
1666
+ }
1667
+ if (!named) {
1668
+ named = true;
1669
+ if (w !== String(name)) nameWord = w;
1670
+ open = null;
1671
+ continue;
1672
+ }
1673
+ if (open) {
1674
+ const had = given[open];
1675
+ given[open] = Array.isArray(had)
1676
+ ? [...had.slice(0, -1), `${had.at(-1)} ${w}`]
1677
+ : `${had} ${w}`;
1678
+ intoValues.push(w);
855
1679
  continue;
856
1680
  }
857
1681
  words.push(w);
858
1682
  }
859
- const builtIn =
860
- words.length && builtInThemes().includes(words[0]);
861
- if (builtIn && given.like == null) given.like = words[0];
862
- const fixed = builtIn
863
- ? name
864
- : [name, ...words]
865
- .join('-')
866
- .toLowerCase()
867
- .replace(/[^a-z0-9-]+/g, '-');
1683
+ // A built-in theme among the words (after a `like` word, or
1684
+ // typed as the name with the real name after it) is the base,
1685
+ // as --like; every other word is part of the name.
1686
+ const all = [nameWord ?? String(name), ...words];
1687
+ const baseAt = all.findIndex(
1688
+ (w, i) =>
1689
+ builtInThemes().includes(w.toLowerCase()) &&
1690
+ (i > 0 || all.length > 1),
1691
+ );
1692
+ if (baseAt >= 0 && given.like == null)
1693
+ given.like = all[baseAt].toLowerCase();
1694
+ const nameWords = all.filter(
1695
+ (w, i) =>
1696
+ i !== baseAt &&
1697
+ !(baseAt >= 0 && /^like$/i.test(w) && i === baseAt - 1),
1698
+ );
1699
+ const fixed = nameWords
1700
+ .join('-')
1701
+ .toLowerCase()
1702
+ .replace(/[^a-z0-9-]+/g, '-');
1703
+ // The line is checked as every new line is offered.
1704
+ const read = Object.keys(given).some(k => given[k] !== o[k]);
868
1705
  throw new AstryxError(
869
- `new takes one theme name; "${extra.join(' ')}" is extra. For a base theme, use --like. Nothing was changed.`,
870
- [
1706
+ `new takes one theme name; "${(nameWord ? [...intoValues, ...words] : extra).join(' ')}" is extra.${read ? ' A value of more than one word goes in quotes.' : ''} For a base theme, use --like. Nothing was changed.`,
1707
+ await editorCheckedNewLines(
1708
+ `${EDITOR} new ${quoteCommandArgument(fixed)}${newFlagLine(given)}`,
1709
+ fixed,
871
1710
  {
872
- name: `${EDITOR} new ${quoteCommandArgument(fixed)}${newFlagLine(given)}`,
873
- reason: 'do this instead',
1711
+ cwd: process.cwd(),
1712
+ like: given.like,
1713
+ png: given.png ?? false,
1714
+ settings: newSettingsGiven(given),
874
1715
  },
875
- ],
1716
+ ),
876
1717
  ERROR_CODES.ERR_INVALID_ARGUMENT,
877
1718
  );
878
1719
  }
@@ -885,9 +1726,9 @@ export function registerExperimentalTheme(group, program) {
885
1726
  },
886
1727
  r => [
887
1728
  `[ok] made theme "${r.data.theme}"${r.data.like ? ` on top of ${r.data.like}` : ''}`,
888
- ...project(/** @type {any} */ (r.data)),
1729
+ ...changeFields(/** @type {any} */ (r.data)),
889
1730
  `Tip: ${EDITOR} set ${r.data.theme} <thing> <value>, or ${HOW} "<what you want>"`,
890
- `Look at it after each change (this changes nothing in your app): ${EDITOR} show ${r.data.theme} --png writes themes/${r.data.theme}/preview.png and sheet.png from real components; open the PNGs and check them against the request`,
1731
+ `Look at it after each change (this changes nothing in your app): ${EDITOR} show ${r.data.theme} --png writes themes/${r.data.theme}/preview.png (a sample page), sheet-overlays.png (every menu, tooltip, popover and list, open) and sheet.png (every component) from real components; open preview.png and sheet-overlays.png and check them against the request`,
891
1732
  ],
892
1733
  ),
893
1734
  }),
@@ -908,25 +1749,42 @@ export function registerExperimentalTheme(group, program) {
908
1749
  // A declaration pasted as one argument (`--color-accent: #e11d48`,
909
1750
  // or `--color-accent:#e11d48`) is the token and its value; with no
910
1751
  // value otherwise, the missing-argument error the parser gives.
1752
+ // A pasted JSON object of settings goes to the editor whole, which
1753
+ // gives one set line per entry.
1754
+ if (!value.length && /^\s*\{/.test(thing)) value = [''];
911
1755
  if (!value.length) {
912
1756
  // Any thing, a token or a dial, with `:` or `=` (`accent: red`,
913
1757
  // `--color-accent=#e11d48`).
914
- const pasted = /^(\S+?)\s*[:=]\s*(.+?);?\s*$/.exec(thing);
915
- if (!pasted)
916
- return missingSetValue(
917
- editor.commands.find(c => c.name() === 'set'),
918
- );
919
- thing = pasted[1];
920
- value = [pasted[2]];
1758
+ // A thing and its value in one word (`'corners pill'`) are the
1759
+ // same as given apart.
1760
+ // A declaration goes to the editor whole: its one reader splits
1761
+ // it, and reads the scope of the editor's own printed line
1762
+ // (`corners = pill (whole theme)`).
1763
+ if (/^(\S+?)\s*[:=]\s*(.+?);?\s*$/.test(thing)) value = [''];
1764
+ else {
1765
+ const pasted = /^\s*(\S+)\s+(.+?)\s*$/.exec(thing);
1766
+ if (!pasted)
1767
+ return missingSetValue(
1768
+ editor.commands.find(c => c.name() === 'set'),
1769
+ );
1770
+ thing = pasted[1];
1771
+ value = [pasted[2]];
1772
+ }
921
1773
  }
922
- return (
923
- strayOption('set', value) ??
1774
+ return (async () =>
1775
+ (await readOptionsChecked('set', setDoc)) ??
1776
+ // A token typed after its value (`set t 4px --radius-element`)
1777
+ // is no option: the set reads the two in the other order.
1778
+ (value.length === 1 &&
1779
+ /^--[a-z0-9-]+$/i.test(value[0]) &&
1780
+ !thing.startsWith('-')
1781
+ ? null
1782
+ : strayOption('set', setDoc, value)) ??
924
1783
  run(
925
1784
  program,
926
1785
  () => themeEditSet(name, thing, value.join(' '), changeOptions(o)),
927
1786
  changeBlocks,
928
- )
929
- );
1787
+ ))();
930
1788
  },
931
1789
  }),
932
1790
  setDoc,
@@ -936,12 +1794,14 @@ export function registerExperimentalTheme(group, program) {
936
1794
  explained(
937
1795
  defineCommand(editor, showDoc, {
938
1796
  fn: showFn,
939
- action: (
1797
+ action: async (
940
1798
  /** @type {string} */ name,
941
1799
  /** @type {any} */ o,
942
1800
  /** @type {any} */ c,
943
1801
  ) =>
944
- extraWords('show', (c?.args ?? []).slice(1)) ??
1802
+ (await readOptionsChecked('show', showDoc)) ??
1803
+ showStray(name, (c?.args ?? []).slice(1), o) ??
1804
+ extraWords('show', showDoc, (c?.args ?? []).slice(1)) ??
945
1805
  // The sheet is limited to one section (the docs say so): a second
946
1806
  // --section is refused, never kept over the first in silence.
947
1807
  (new Set(flagValues('section')).size > 1
@@ -974,6 +1834,8 @@ export function registerExperimentalTheme(group, program) {
974
1834
  ),
975
1835
  }),
976
1836
  showDoc,
1837
+ // An unknown option reaches the action, which names a show that works.
1838
+ {tokens: true},
977
1839
  );
978
1840
 
979
1841
  explained(
@@ -986,27 +1848,64 @@ export function registerExperimentalTheme(group, program) {
986
1848
  /** @type {any} */ o,
987
1849
  /** @type {import('commander').Command} */ c,
988
1850
  ) =>
989
- strayOption('undo', [which, ...(c?.args ?? []).slice(3)]) ??
990
- extraWords('undo', (c?.args ?? []).slice(3)) ??
991
- run(
992
- program,
993
- () =>
994
- themeEditUndo(name, {
995
- ...changeOptions(o),
996
- ...(thing == null ? {} : {thing, value: which}),
997
- }),
998
- r =>
999
- r.data.action === 'step'
1000
- ? [
1001
- `[ok] ${r.data.theme}: undid the last change`,
1002
- ...project(/** @type {any} */ (r.data)),
1003
- ]
1004
- : changeBlocks(
1005
- /** @type {import('../../../../api/theme-edit/theme-edit.type.mjs').ThemeEditChangeResponse} */ (
1006
- r
1007
- ),
1008
- ),
1009
- ),
1851
+ (async () => {
1852
+ // "undo t accent, corners and spacing" unquoted: the words make one
1853
+ // list of settings, read as the quoted list is.
1854
+ const words = [thing, which, ...(c?.args ?? []).slice(3)].filter(
1855
+ w => typeof w === 'string',
1856
+ );
1857
+ const listed =
1858
+ words.length > 1 &&
1859
+ words.some(
1860
+ (w, i) => /,$/.test(String(w)) || (i > 0 && w === 'and'),
1861
+ ) &&
1862
+ !words.some(w => String(w).startsWith('-'));
1863
+ const list = listed ? words.join(' ') : null;
1864
+ return (
1865
+ (await readOptionsChecked('undo', undoDoc)) ??
1866
+ (list
1867
+ ? null
1868
+ : (strayOption('undo', undoDoc, [
1869
+ which,
1870
+ ...(c?.args ?? []).slice(3),
1871
+ ]) ?? extraWords('undo', undoDoc, (c?.args ?? []).slice(3)))) ??
1872
+ run(
1873
+ program,
1874
+ () =>
1875
+ themeEditUndo(name, {
1876
+ ...changeOptions(o),
1877
+ ...(list != null
1878
+ ? {thing: list}
1879
+ : thing == null
1880
+ ? {}
1881
+ : {thing, value: which}),
1882
+ }),
1883
+ r =>
1884
+ r.data.action === 'step'
1885
+ ? [
1886
+ // What was undone is in the headline, so a tail of
1887
+ // the output keeps it.
1888
+ ...(() => {
1889
+ const {newProblems = [], ...rest} = /** @type {any} */ (
1890
+ r.data
1891
+ );
1892
+ return [
1893
+ `[ok] ${rest.theme}: undid ${rest.undid ?? 'the last change'}${rest.refusedBefore ? ` (${rest.refusedBefore})` : ''}${newProblems.length ? `, but it made ${newProblems.length} new problem${newProblems.length > 1 ? 's' : ''}:` : ''}`,
1894
+ ...(newProblems.length
1895
+ ? problemList(newProblems)
1896
+ : []),
1897
+ ...changeFields(rest),
1898
+ ];
1899
+ })(),
1900
+ ]
1901
+ : changeBlocks(
1902
+ /** @type {import('../../../../api/theme-edit/theme-edit.type.mjs').ThemeEditChangeResponse} */ (
1903
+ r
1904
+ ),
1905
+ ),
1906
+ )
1907
+ );
1908
+ })(),
1010
1909
  }),
1011
1910
  undoDoc,
1012
1911
  {tokens: true},
@@ -1026,13 +1925,16 @@ export function registerExperimentalTheme(group, program) {
1026
1925
  program,
1027
1926
  () =>
1028
1927
  previewFlagsOnce('add', ['theme', 'template', 'top', 'path']) ??
1029
- themeEditPreviewAdd([words ?? []].flat().join(' ') || undefined, {
1030
- cwd: process.cwd(),
1031
- theme: o.theme,
1032
- template: o.template,
1033
- top: o.top,
1034
- path: o.path,
1035
- }),
1928
+ previewOptionsRead('add', previewAddDoc) ??
1929
+ resultStands(
1930
+ themeEditPreviewAdd([words ?? []].flat().join(' ') || undefined, {
1931
+ cwd: process.cwd(),
1932
+ theme: o.theme,
1933
+ template: o.template,
1934
+ top: o.top,
1935
+ path: o.path,
1936
+ }),
1937
+ ),
1036
1938
  r => {
1037
1939
  const {matched, skipped, ...rest} = r.data;
1038
1940
  return [
@@ -1073,10 +1975,12 @@ export function registerExperimentalTheme(group, program) {
1073
1975
  program,
1074
1976
  () =>
1075
1977
  previewFlagsOnce('app', ['theme']) ??
1076
- themeEditPreviewApp(dir, {
1077
- cwd: process.cwd(),
1078
- theme: o.theme,
1079
- }),
1978
+ resultStands(
1979
+ themeEditPreviewApp(dir, {
1980
+ cwd: process.cwd(),
1981
+ theme: o.theme,
1982
+ }),
1983
+ ),
1080
1984
  r => [
1081
1985
  `[ok] new app in ${r.data.folder} with the theme preview`,
1082
1986
  ...project(/** @type {any} */ (r.data)),
@@ -1085,25 +1989,6 @@ export function registerExperimentalTheme(group, program) {
1085
1989
  }).allowExcessArguments(false),
1086
1990
  previewAppDoc,
1087
1991
  );
1088
- {
1089
- // A folder name that starts with "-" reads as an option: say how to
1090
- // pass it.
1091
- const app = /** @type {any} */ (
1092
- preview.commands.find(
1093
- (/** @type {any} */ x) =>
1094
- x.name() === previewAppDoc.name.split(' ').pop(),
1095
- )
1096
- );
1097
- const unknown = app?.unknownOption?.bind(app);
1098
- if (app && unknown)
1099
- app.unknownOption = (/** @type {string} */ flag) =>
1100
- /^-[^-]/.test(flag) && flag.length > 2
1101
- ? app.error(
1102
- `error: unknown option '${flag}'. A folder name that starts with "-" goes after --: ${PREFIX} preview app -- ${flag}`,
1103
- {code: 'commander.unknownOption'},
1104
- )
1105
- : unknown(flag);
1106
- }
1107
1992
 
1108
1993
  explained(
1109
1994
  defineCommand(preview, previewListDoc, {
@@ -1157,7 +2042,9 @@ export function registerExperimentalTheme(group, program) {
1157
2042
  program,
1158
2043
  () =>
1159
2044
  previewFlagsOnce('remove', ['path']) ??
1160
- themeEditPreviewRemove(page, {cwd: process.cwd(), path: o.path}),
2045
+ resultStands(
2046
+ themeEditPreviewRemove(page, {cwd: process.cwd(), path: o.path}),
2047
+ ),
1161
2048
  r => [
1162
2049
  r.data.pages.length
1163
2050
  ? `[ok] removed ${page} from the theme preview`
@@ -1256,7 +2143,10 @@ export function registerExperimentalTheme(group, program) {
1256
2143
  // question); a picture is told by its extension here only to keep
1257
2144
  // option words after it for the count.
1258
2145
  const picture = /\.png$/i.test(rest[0] ?? '');
1259
- const stray = picture ? null : strayOption('how', rest.slice(1));
2146
+ const stray = picture
2147
+ ? null
2148
+ : (readOptions(howDoc.name.split(' ').pop() ?? 'how', howDoc) ??
2149
+ strayOption('how', howDoc, rest.slice(1)));
1260
2150
  if (stray) return stray;
1261
2151
  return run(
1262
2152
  program,
@@ -1303,9 +2193,17 @@ export function registerExperimentalTheme(group, program) {
1303
2193
  build: 'compile',
1304
2194
  explain: editorThemeRefusal,
1305
2195
  preflight: editorCompileProblem,
2196
+ follow: editorFollowCompile,
1306
2197
  missingSource: editorMissingSource,
1307
2198
  template: editorThemeTemplate,
1308
2199
  hold: editorThemeHold,
2200
+ loadedFonts: editorLoadedFonts,
2201
+ extraData: editorBuildExtra,
2202
+ afterBuild: editorAfterBuild,
2203
+ sourcePath: editorSourcePath,
2204
+ fontHelp: editorFontHelp,
2205
+ install: editorInstall,
2206
+ colorModes: editorColorModes,
1309
2207
  },
1310
2208
  );
1311
2209
  }