@astryxdesign/cli 0.7.16 → 0.7.17-canary.g16fe6a8

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 (380) 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 +28 -2
  29. package/api/docs/_adapter.mjs +249 -10
  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 +132 -1
  79. package/api/theme/build/build.mjs +482 -157
  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 +44 -5
  83. package/api/theme/build/font-warning.mjs +118 -10
  84. package/api/theme/build/icon-imports.mjs +51 -9
  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 +115 -4
  88. package/api/theme-edit/_adapter.mjs +997 -83
  89. package/api/theme-edit/_catalog.d.mts +20 -2
  90. package/api/theme-edit/_catalog.mjs +50 -10
  91. package/api/theme-edit/_check.d.mts +75 -24
  92. package/api/theme-edit/_check.mjs +2672 -422
  93. package/api/theme-edit/_color.d.mts +10 -0
  94. package/api/theme-edit/_color.mjs +54 -1
  95. package/api/theme-edit/_compiler.d.mts +1 -0
  96. package/api/theme-edit/_compiler.mjs +133 -15
  97. package/api/theme-edit/_context.d.mts +14 -3
  98. package/api/theme-edit/_context.mjs +225 -65
  99. package/api/theme-edit/_css.d.mts +14 -0
  100. package/api/theme-edit/_css.mjs +46 -1
  101. package/api/theme-edit/_edit.d.mts +54 -4
  102. package/api/theme-edit/_edit.mjs +2966 -286
  103. package/api/theme-edit/_how-commands.d.mts +72 -1
  104. package/api/theme-edit/_how-commands.mjs +770 -9
  105. package/api/theme-edit/_how-question.d.mts +82 -5
  106. package/api/theme-edit/_how-question.mjs +6983 -701
  107. package/api/theme-edit/_how.d.mts +2 -1
  108. package/api/theme-edit/_how.mjs +237 -41
  109. package/api/theme-edit/_importers.d.mts +38 -0
  110. package/api/theme-edit/_importers.mjs +188 -0
  111. package/api/theme-edit/_marks.d.mts +31 -5
  112. package/api/theme-edit/_marks.mjs +57 -5
  113. package/api/theme-edit/_name-rule.d.mts +11 -0
  114. package/api/theme-edit/_name-rule.mjs +12 -0
  115. package/api/theme-edit/_normal.d.mts +303 -0
  116. package/api/theme-edit/_normal.mjs +1517 -0
  117. package/api/theme-edit/_palette.d.mts +12 -0
  118. package/api/theme-edit/_palette.mjs +37 -4
  119. package/api/theme-edit/_part-words.d.mts +31 -0
  120. package/api/theme-edit/_part-words.mjs +126 -0
  121. package/api/theme-edit/_parts.d.mts +28 -2
  122. package/api/theme-edit/_parts.mjs +267 -31
  123. package/api/theme-edit/_preview-app.d.mts +7 -13
  124. package/api/theme-edit/_preview-app.mjs +814 -406
  125. package/api/theme-edit/_preview.d.mts +116 -16
  126. package/api/theme-edit/_preview.mjs +649 -152
  127. package/api/theme-edit/_project.d.mts +22 -1
  128. package/api/theme-edit/_project.mjs +83 -3
  129. package/api/theme-edit/_settings.d.mts +467 -42
  130. package/api/theme-edit/_settings.mjs +3527 -468
  131. package/api/theme-edit/_tables.d.mts +21 -0
  132. package/api/theme-edit/_tables.mjs +97 -3
  133. package/api/theme-edit/_vet.d.mts +31 -0
  134. package/api/theme-edit/_vet.mjs +114 -8
  135. package/api/theme-edit/theme-edit.type.d.mts +16 -2
  136. package/api/theme-edit/theme-edit.type.mjs +6 -3
  137. package/api/theme-edit/themeEditHow.doc.mjs +1 -1
  138. package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
  139. package/api/theme-edit/themeEditNew.doc.mjs +7 -4
  140. package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
  141. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
  142. package/api/upgrade/run/run.mjs +4 -3
  143. package/assets/codemods/integration-discovery.mjs +2 -1
  144. package/assets/codemods/run-codemod.mjs +87 -7
  145. package/assets/codemods/transforms/next/index.mjs +11 -1
  146. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  147. package/assets/component-list.generated.json +1 -0
  148. package/assets/docs/author-a-theme.doc.mjs +1 -0
  149. package/assets/docs/theme.doc.dense.mjs +2 -2
  150. package/assets/docs/theme.doc.mjs +1 -1
  151. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  152. package/assets/docs/tree/checks.doc.mjs +1 -1
  153. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  154. package/assets/docs/tree/render-pages.doc.mjs +44 -3
  155. package/assets/docs/tree/share-a-page.doc.mjs +157 -0
  156. package/assets/docs/tree/single-component.doc.mjs +4 -0
  157. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  158. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  159. package/assets/docs/use-a-theme.doc.mjs +1 -1
  160. package/assets/docs.generated.json +2 -2
  161. package/assets/search-catalog.generated.json +2 -0
  162. package/assets/self-audit.generated.json +1 -1
  163. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  164. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  165. package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
  166. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  167. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  168. package/assets/templates/components.generated.json +1 -1
  169. package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
  170. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +5 -1
  171. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  172. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  173. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  174. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  175. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  176. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  177. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  178. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  179. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  180. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  181. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  182. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  183. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  184. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  185. package/assets/templates/pages/editor/template.doc.mjs +2 -8
  186. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  187. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  188. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  189. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  190. package/assets/templates/pages/ide/page.tsx +24 -2
  191. package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
  192. package/assets/templates/pages/library/template.doc.mjs +4 -1
  193. package/assets/templates/pages/login/template.doc.mjs +2 -1
  194. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  195. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  196. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  197. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  198. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  199. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  200. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  201. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  202. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  203. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  204. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  205. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  206. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  207. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  208. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  209. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  210. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
  211. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  212. package/assets/theme.template.ts +6 -0
  213. package/authoring/debug/parse.d.mts +3 -3
  214. package/authoring/doctypes/_schema.d.mts +3 -3
  215. package/authoring/doctypes/command/command.doc.mjs +1 -1
  216. package/authoring/doctypes/component/categories.d.mts +37 -0
  217. package/authoring/doctypes/component/categories.mjs +54 -0
  218. package/authoring/doctypes/template/template.doc.mjs +1 -1
  219. package/authoring/doctypes/template/type.ts +9 -0
  220. package/authoring/example/example.doc.d.mts +12 -0
  221. package/authoring/example/example.doc.mjs +69 -0
  222. package/authoring/example/preview.d.mts +92 -0
  223. package/authoring/example/preview.mjs +994 -0
  224. package/authoring/example/type.ts +102 -0
  225. package/authoring/index.d.mts +1 -0
  226. package/authoring/index.d.ts +12 -0
  227. package/authoring/index.mjs +3 -1
  228. package/clients/cli/bin/astryx.mjs +6 -9
  229. package/clients/cli/build-id.generated.json +1 -1
  230. package/clients/cli/commands/component.doc.mjs +1 -1
  231. package/clients/cli/commands/component.mjs +22 -3
  232. package/clients/cli/commands/docs.doc.mjs +7 -1
  233. package/clients/cli/commands/docs.mjs +3 -1
  234. package/clients/cli/commands/doctor.mjs +32 -14
  235. package/clients/cli/commands/experimental/render.mjs +42 -1
  236. package/clients/cli/commands/experimental/theme.mjs +573 -119
  237. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  238. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  239. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
  240. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
  241. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
  242. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
  243. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  244. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  245. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  246. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  247. package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
  248. package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
  249. package/clients/cli/commands/search.doc.mjs +2 -1
  250. package/clients/cli/commands/search.mjs +6 -1
  251. package/clients/cli/commands/template.mjs +4 -2
  252. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  253. package/clients/cli/commands/theme.doc.mjs +1 -1
  254. package/clients/cli/commands/theme.mjs +718 -438
  255. package/clients/cli/commands/upgrade.mjs +42 -7
  256. package/clients/cli/index.mjs +1 -1
  257. package/clients/cli/lib/cli-error.mjs +2 -1
  258. package/clients/cli/lib/component-format.mjs +205 -98
  259. package/clients/cli/lib/hook-format.mjs +9 -19
  260. package/clients/cli/lib/json-shim.mjs +132 -24
  261. package/clients/cli/lib/manifest.mjs +3 -2
  262. package/clients/cli/manifest.generated.json +1 -1
  263. package/foundation/agent-docs/agent-docs.mjs +1 -1
  264. package/foundation/config/theme-state.d.mts +13 -1
  265. package/foundation/config/theme-state.mjs +47 -7
  266. package/foundation/discovery/authoring-self-docs.mjs +1 -0
  267. package/foundation/discovery/component-discovery.d.mts +11 -0
  268. package/foundation/discovery/component-discovery.mjs +56 -8
  269. package/foundation/discovery/component-replacement.mjs +130 -1
  270. package/foundation/discovery/copied-passages.mjs +2 -1
  271. package/foundation/discovery/core-component-docs.d.mts +29 -0
  272. package/foundation/discovery/core-component-docs.mjs +83 -0
  273. package/foundation/discovery/doc-types.mjs +4 -3
  274. package/foundation/discovery/entry-name-files.d.mts +43 -0
  275. package/foundation/discovery/entry-name-files.mjs +264 -0
  276. package/foundation/discovery/hook-discovery.d.mts +8 -2
  277. package/foundation/discovery/hook-discovery.mjs +22 -8
  278. package/foundation/discovery/icon-definition-discovery.mjs +2 -1
  279. package/foundation/discovery/icon-set-checks.mjs +2 -1
  280. package/foundation/discovery/icon-set-discovery.mjs +2 -1
  281. package/foundation/discovery/integration-doc-files.mjs +2 -1
  282. package/foundation/discovery/package-exports.d.mts +10 -0
  283. package/foundation/discovery/package-exports.mjs +56 -3
  284. package/foundation/discovery/prop-drift.mjs +9 -9
  285. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  286. package/foundation/discovery/runner-allowlist.mjs +2 -0
  287. package/foundation/discovery/stored-component-list.d.mts +43 -0
  288. package/foundation/discovery/stored-component-list.mjs +90 -0
  289. package/foundation/discovery/stored-search-catalog.d.mts +115 -0
  290. package/foundation/discovery/stored-search-catalog.mjs +297 -0
  291. package/foundation/discovery/stored-self-audit.d.mts +26 -10
  292. package/foundation/discovery/stored-self-audit.mjs +38 -18
  293. package/foundation/discovery/template-adapter.d.mts +53 -1
  294. package/foundation/discovery/template-adapter.mjs +176 -12
  295. package/foundation/discovery/template-icons.mjs +2 -1
  296. package/foundation/discovery/theme-discovery.mjs +31 -4
  297. package/foundation/discovery/theme-imports.d.mts +14 -0
  298. package/foundation/discovery/theme-imports.mjs +43 -1
  299. package/foundation/discovery/theming-targets.d.mts +6 -5
  300. package/foundation/discovery/theming-targets.mjs +31 -47
  301. package/foundation/doc-compiler/import.mjs +7 -1
  302. package/foundation/doc-compiler/inputs.mjs +3 -2
  303. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  304. package/foundation/doc-compiler/stored-docs.d.mts +22 -0
  305. package/foundation/doc-compiler/stored-docs.mjs +49 -0
  306. package/foundation/env/semver.mjs +3 -1
  307. package/foundation/fonts/font-stylesheet.d.mts +38 -0
  308. package/foundation/fonts/font-stylesheet.mjs +141 -0
  309. package/foundation/fs/cache-eviction.d.mts +21 -0
  310. package/foundation/fs/cache-eviction.mjs +73 -0
  311. package/foundation/fs/exact-codec.d.mts +12 -2
  312. package/foundation/fs/exact-codec.mjs +23 -6
  313. package/foundation/fs/file-protection.mjs +4 -3
  314. package/foundation/fs/gather-cache.d.mts +62 -4
  315. package/foundation/fs/gather-cache.mjs +517 -91
  316. package/foundation/fs/jiti-cache.d.mts +19 -1
  317. package/foundation/fs/jiti-cache.mjs +130 -6
  318. package/foundation/fs/kept-tree.d.mts +60 -0
  319. package/foundation/fs/kept-tree.mjs +154 -0
  320. package/foundation/fs/listing-cache.d.mts +7 -0
  321. package/foundation/fs/listing-cache.mjs +10 -0
  322. package/foundation/fs/module-loader.d.mts +24 -2
  323. package/foundation/fs/module-loader.mjs +94 -21
  324. package/foundation/fs/paths.d.mts +18 -0
  325. package/foundation/fs/paths.mjs +15 -2
  326. package/foundation/fs/read-record.d.mts +9 -0
  327. package/foundation/fs/read-record.mjs +19 -11
  328. package/foundation/fs/stop-cleanup.d.mts +12 -0
  329. package/foundation/fs/stop-cleanup.mjs +66 -0
  330. package/foundation/identity/provider-identity.d.mts +6 -0
  331. package/foundation/identity/provider-identity.mjs +10 -1
  332. package/foundation/integrations/contribution-inventory.mjs +4 -3
  333. package/foundation/integrations/example-code.d.mts +63 -0
  334. package/foundation/integrations/example-code.mjs +416 -0
  335. package/foundation/integrations/public-imports.d.mts +9 -0
  336. package/foundation/integrations/public-imports.mjs +3 -2
  337. package/foundation/integrations/validate-contributions.mjs +17 -45
  338. package/foundation/render/embedded-files.d.mts +6 -0
  339. package/foundation/render/embedded-files.mjs +25 -5
  340. package/foundation/render/embedded-imports.d.mts +39 -7
  341. package/foundation/render/embedded-imports.mjs +66 -27
  342. package/foundation/render/file-header.d.mts +66 -0
  343. package/foundation/render/file-header.mjs +118 -0
  344. package/foundation/render/host-answer.d.mts +18 -0
  345. package/foundation/render/host-answer.mjs +46 -0
  346. package/foundation/render/host-exit.d.mts +1 -0
  347. package/foundation/render/host-exit.mjs +6 -1
  348. package/foundation/render/html-reader.d.mts +55 -2
  349. package/foundation/render/html-reader.mjs +145 -26
  350. package/foundation/render/markup-edits.d.mts +57 -0
  351. package/foundation/render/markup-edits.mjs +182 -0
  352. package/foundation/render/page-host.mjs +29 -12
  353. package/foundation/render/page-worker.mjs +121 -13
  354. package/foundation/render/picture-chrome.d.mts +4 -0
  355. package/foundation/render/picture-chrome.mjs +185 -0
  356. package/foundation/render/picture-playwright.d.mts +4 -0
  357. package/foundation/render/picture-playwright.mjs +34 -0
  358. package/foundation/render/rebuild.mjs +2 -1
  359. package/foundation/render/render-page.d.mts +35 -3
  360. package/foundation/render/render-page.mjs +641 -96
  361. package/foundation/render/source-block.d.mts +85 -6
  362. package/foundation/render/source-block.mjs +211 -20
  363. package/foundation/render/ts-paths.d.mts +69 -6
  364. package/foundation/render/ts-paths.mjs +326 -40
  365. package/foundation/response/error-codes.d.mts +3 -1
  366. package/foundation/response/error-codes.d.ts +1 -0
  367. package/foundation/response/error-codes.doc.mjs +12 -1
  368. package/foundation/response/error-codes.mjs +11 -1
  369. package/foundation/response/response-types.doc.mjs +2 -2
  370. package/foundation/text/compare-text.d.mts +14 -0
  371. package/foundation/text/compare-text.mjs +68 -0
  372. package/foundation/text/css-escape.d.mts +18 -0
  373. package/foundation/text/css-escape.mjs +35 -0
  374. package/foundation/text/string-utils.d.mts +3 -2
  375. package/foundation/text/string-utils.mjs +18 -4
  376. package/foundation/text/suggest-order.d.mts +9 -0
  377. package/foundation/text/suggest-order.mjs +15 -1
  378. package/foundation/xle/expand.mjs +2 -1
  379. package/host/index.mjs +8 -6
  380. 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,22 @@ import {
48
53
  builtInThemes,
49
54
  dialValueFits,
50
55
  newFlagList,
56
+ editorCheckedLine,
57
+ editorCheckedNewLines,
58
+ booleanWord,
51
59
  editorCompileProblem,
60
+ editorFollowCompile,
61
+ editorThemesAt,
62
+ editorFreeName,
63
+ typoNear,
64
+ typoOf,
65
+ editorAfterBuild,
66
+ editorFontHelp,
67
+ editorInstall,
68
+ editorSourcePath,
69
+ editorBuildExtra,
70
+ editorLoadedFonts,
71
+ editorColorModes,
52
72
  editorThemeHold,
53
73
  editorThemeRefusal,
54
74
  editorMissingSource,
@@ -106,7 +126,6 @@ const cmd = line => {
106
126
  .join(stem);
107
127
  };
108
128
  /** 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
129
 
111
130
  /**
112
131
  * Print blocks, a blank line between them, with this project's run prefix
@@ -412,12 +431,12 @@ function newSettings(o, themeName = '<theme>') {
412
431
  }
413
432
 
414
433
  /**
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}
434
+ * The settings flags of options as commander read them (camelCase keys),
435
+ * by the flag name `new` takes.
436
+ * @param {Record<string, any>} o
437
+ * @returns {Record<string, string | string[]>}
419
438
  */
420
- function newFlagLine(o) {
439
+ function newSettingsGiven(o) {
421
440
  /** @type {Record<string, string | string[]>} */
422
441
  const settings = {};
423
442
  for (const opt of newDoc.options ?? []) {
@@ -426,6 +445,17 @@ function newFlagLine(o) {
426
445
  const value = o[flag.replace(/-([a-z])/g, (_, c) => c.toUpperCase())];
427
446
  if (value != null) settings[flag] = value;
428
447
  }
448
+ return settings;
449
+ }
450
+
451
+ /**
452
+ * The options a `new` was given, as flags for a suggested command, so a
453
+ * corrected command makes the theme that was asked for.
454
+ * @param {any} o
455
+ * @returns {string}
456
+ */
457
+ function newFlagLine(o) {
458
+ const settings = newSettingsGiven(o);
429
459
  const parts = newFlagList(
430
460
  o.like == null ? undefined : String(o.like),
431
461
  settings,
@@ -484,7 +514,16 @@ function flagValues(name) {
484
514
  */
485
515
  function changeBlocks(r) {
486
516
  const d = r.data;
487
- const s = d.setting;
517
+ // The status line names the value as saved, with a quote or space mark
518
+ // the text output would fold written as its CSS escape (\201C), so the
519
+ // text and the JSON name the same value.
520
+ const s = {
521
+ ...d.setting,
522
+ value: String(d.setting.value).replace(
523
+ /[\u00A0\u00AB\u00BB\u2000-\u200B\u2018-\u201F\u2039\u203A\u202F\u3000\u300C-\u300F]/g,
524
+ c => `\\${c.codePointAt(0)?.toString(16).toUpperCase()} `,
525
+ ),
526
+ };
488
527
  const status =
489
528
  d.was != null
490
529
  ? `[ok] ${d.theme}: ${s.thing} ${d.was} -> ${s.value}`
@@ -618,10 +657,11 @@ function lookupBlocks(d) {
618
657
  * unknown options so a design token (`--color-accent`) can be the thing
619
658
  * they name; a `--` word anywhere else is a mistyped option.
620
659
  * @param {string} command the subcommand, for the suggestion
660
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc the command's doc, which lists its options
621
661
  * @param {Array<string | undefined>} rest the operands after the thing
622
662
  * @returns {ReturnType<typeof cliError> | null}
623
663
  */
624
- function strayOption(command, rest) {
664
+ function strayOption(command, doc, rest) {
625
665
  // A scope flag given twice would keep only the last one without a word.
626
666
  for (const flag of ['on', 'when', 'state', 'mode']) {
627
667
  const all = flagValues(flag);
@@ -639,38 +679,317 @@ function strayOption(command, rest) {
639
679
  },
640
680
  );
641
681
  }
642
- const word = rest.find(w => typeof w === 'string' && w.startsWith('--'));
682
+ // A value pasted with a token's label (`'--color-accent: #e11d48'`) is
683
+ // a value, read by the label reader, not an option.
684
+ const word = rest.find(
685
+ w =>
686
+ typeof w === 'string' &&
687
+ w.startsWith('--') &&
688
+ !/^--[a-z0-9-]+\s*:\s*\S/i.test(w),
689
+ );
643
690
  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).`,
646
- {
691
+ return strayRefusal(command, doc, `${EDITOR} ${command}`, {
692
+ option: word,
693
+ note: 'a design token (such as --color-accent) is the thing a change names, before its value',
694
+ });
695
+ }
696
+
697
+ /**
698
+ * What a theme command answers for an option it does not take, or for
699
+ * words past what it takes: the one stray reader every editor and preview
700
+ * command uses. It names the options the command takes; it offers the same
701
+ * command without the stray words only when that is safe to run
702
+ * (`safeLine`: show reads and changes nothing; a preview remove without its
703
+ * option would remove the whole preview), and always the command's help.
704
+ * @param {string} command the command's words after the group (`set`, `preview remove`)
705
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc the command's doc, which lists its options
706
+ * @param {string} head the command line's start, as the project runs it
707
+ * @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
708
+ * @param {string | null} [safeLine] the command without them, when it is safe to run
709
+ * @returns {{message: string, suggestions: Array<{name: string, reason: string}>, code: string}}
710
+ */
711
+ function strayAnswer(command, doc, head, stray, safeLine = null) {
712
+ const takes = [
713
+ ...(doc.options ?? []).flatMap(o =>
714
+ String(o.flag)
715
+ .split(/[\s,]+/)
716
+ .filter(w => w.startsWith('--')),
717
+ ),
718
+ '--json',
719
+ ].filter((w, i, all) => all.indexOf(w) === i);
720
+ const list =
721
+ takes.length > 1
722
+ ? `${takes.slice(0, -1).join(', ')} and ${takes.at(-1)}`
723
+ : takes.join('');
724
+ const message = stray.option
725
+ ? `unknown option '${stray.option}': ${command} takes ${list}${stray.note ? `; ${stray.note}` : ''}.`
726
+ : `${command} does not take "${(stray.extra ?? []).join(' ')}"${stray.note ? `; ${stray.note}` : ''}.`;
727
+ return {
728
+ message,
729
+ suggestions: [
730
+ ...(safeLine ? [{name: cmd(safeLine), reason: 'do this instead'}] : []),
731
+ {
732
+ name: cmd(`${head} --help`),
733
+ reason: stray.option ? 'every option it takes' : 'what it takes',
734
+ },
735
+ ],
736
+ code: stray.option
737
+ ? ERROR_CODES.ERR_INVALID_OPTION
738
+ : ERROR_CODES.ERR_INVALID_ARGUMENT,
739
+ };
740
+ }
741
+
742
+ /**
743
+ * {@link strayAnswer} as the refusal the command prints.
744
+ * @param {string} command
745
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc
746
+ * @param {string} head
747
+ * @param {{option?: string, extra?: string[], note?: string}} stray
748
+ * @param {string | null} [safeLine]
749
+ */
750
+ function strayRefusal(command, doc, head, stray, safeLine = null) {
751
+ const a = strayAnswer(command, doc, head, stray, safeLine);
752
+ return cliError(a.message, {suggestions: a.suggestions, code: a.code});
753
+ }
754
+
755
+ /**
756
+ * Read the options of an editor command as written, the one reading every
757
+ * editor command gives them: an option in other letters, with one dash or
758
+ * a typed dash (`--On`, `-only`, `\u2014only`) or within the one typo limit
759
+ * of an option the command takes (`--olny`) is that option; a boolean
760
+ * option written with a value (`--png=false`, `--only true`) takes none,
761
+ * and its value is read by the one yes/no reader (booleanWord). Null when
762
+ * every option is written as the command takes it; else the reason, and
763
+ * the command as meant (the option as the command takes it; a boolean as
764
+ * itself for yes, left out for no), or no command when a boolean's value
765
+ * reads as neither.
766
+ * @param {string} command the subcommand (`set`, `undo`, `new`, `show`, how's word; `add` under preview)
767
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc the command's doc, which lists its options
768
+ * @param {{group: string, head: string}} [where] the group word the subcommand follows (`editor`, `preview`) and the command line's start
769
+ * @returns {{why: string, line: string | null} | null}
770
+ */
771
+ function optionsAsWritten(
772
+ command,
773
+ doc,
774
+ where = {group: 'editor', head: `${EDITOR} ${command}`},
775
+ ) {
776
+ const flags = (doc.options ?? []).map(opt => String(opt.flag));
777
+ const names = (/** @type {(f: string) => boolean} */ keep) =>
778
+ flags
779
+ .filter(keep)
780
+ .flatMap(f => f.split(/[\s,]+/).filter(w => w.startsWith('--')));
781
+ const booleans = ['--json', ...names(f => !/[<[]/.test(f))];
782
+ const all = [...booleans, ...names(f => /[<[]/.test(f))];
783
+ /** The option a word names, as the command takes it, or null. @param {string} word */
784
+ const meant = word => {
785
+ const w = word.toLowerCase();
786
+ if (all.includes(`--${w}`)) return `--${w}`;
787
+ const near = all.filter(o => typoNear(w, o.slice(2)));
788
+ return near.length === 1 ? near[0] : null;
789
+ };
790
+ const argv = process.argv;
791
+ const at = argv.indexOf(command, argv.indexOf(where.group) + 1);
792
+ if (at < 0) return null;
793
+ /** @type {string[]} */
794
+ const words = [];
795
+ /** @type {string | null} */
796
+ let why = null;
797
+ let unread = false;
798
+ for (let i = at + 1; i < argv.length; i += 1) {
799
+ const a = argv[i];
800
+ if (a === '--') {
801
+ words.push(...argv.slice(i));
802
+ break;
803
+ }
804
+ const m = /^(--?|[\u2013\u2014]-?)([A-Za-z][A-Za-z-]*)(?:=(.*))?$/.exec(a);
805
+ const flag = m ? meant(m[2]) : null;
806
+ if (!m || !flag) {
807
+ if (a !== '--json') words.push(a);
808
+ continue;
809
+ }
810
+ const written = m[3] == null ? `${m[1]}${m[2]}` : a.split('=')[0];
811
+ if (written !== flag)
812
+ why ??= `unknown option '${written}' (did you mean ${flag}?)`;
813
+ const next = argv[i + 1];
814
+ if (booleans.includes(flag)) {
815
+ // A value after a boolean option, joined by `=` or as the next word
816
+ // when that word is a yes or a no.
817
+ const value = m[3] ?? (booleanWord(next) != null ? String(next) : null);
818
+ if (value != null) {
819
+ if (m[3] == null) i += 1;
820
+ const read = booleanWord(value);
821
+ const shown = m[3] == null ? `${a} ${value}` : a;
822
+ if (read == null) unread = true;
823
+ why ??=
824
+ read == null
825
+ ? `${flag} takes no value ("${shown}"), and "${value}" reads as neither yes nor no: give ${flag} alone for yes, or leave it out`
826
+ : `${flag} takes no value ("${shown}"): give it alone for yes, or leave it out`;
827
+ if (read === true && flag !== '--json') words.push(flag);
828
+ continue;
829
+ }
830
+ if (flag !== '--json') words.push(flag);
831
+ continue;
832
+ }
833
+ // An option that takes a value, given none, is left out of the line.
834
+ if (m[3] == null && (next == null || /^-/.test(next))) continue;
835
+ words.push(flag);
836
+ if (m[3] != null) words.push(m[3]);
837
+ }
838
+ if (!why) return null;
839
+ return {
840
+ why,
841
+ line: unread
842
+ ? null
843
+ : `${where.head} ${words.map(w => (/^--[a-z]/.test(w) && all.includes(w) ? w : quoteCommandArgument(w))).join(' ')}`.trim(),
844
+ };
845
+ }
846
+
847
+ /**
848
+ * An option a theme command does not take, as the one option reader reads
849
+ * it (the json shim asks, for the options commander refuses: preview's
850
+ * subcommands): the option meant with the command that works, else what
851
+ * the command takes and its help. Undefined for any other command.
852
+ * @param {any} c the command commander refused
853
+ * @returns {{message: string, suggestions: Array<{name: string, reason: string}>} | undefined}
854
+ */
855
+ function unknownThemeOption(c) {
856
+ const sub = c?.name?.();
857
+ const doc =
858
+ /** @type {Record<string, import('@astryxdesign/cli/authoring').CommandDoc>} */ ({
859
+ add: previewAddDoc,
860
+ app: previewAppDoc,
861
+ list: previewListDoc,
862
+ remove: previewRemoveDoc,
863
+ })[sub];
864
+ if (!doc || c.parent?.name?.() !== 'preview') return undefined;
865
+ const head = `${PREFIX} preview ${sub}`;
866
+ const help = {name: cmd(`${head} --help`), reason: 'every option it takes'};
867
+ const read = optionsAsWritten(sub, doc, {group: 'preview', head});
868
+ if (read)
869
+ return {
870
+ message: `${read.why}.`,
647
871
  suggestions: [
648
- {
649
- name: cmd(`${EDITOR} ${command} --help`),
650
- reason: 'every option it takes',
651
- },
872
+ ...(read.line
873
+ ? [{name: cmd(read.line), reason: 'do this instead'}]
874
+ : []),
875
+ help,
652
876
  ],
653
- code: ERROR_CODES.ERR_INVALID_OPTION,
877
+ };
878
+ const takes = (doc.options ?? []).flatMap(o =>
879
+ String(o.flag)
880
+ .split(/[\s,]+/)
881
+ .filter(w => w.startsWith('--')),
882
+ );
883
+ const argv = process.argv;
884
+ const from = argv.indexOf(sub, argv.indexOf('preview') + 1);
885
+ const stray = argv
886
+ .slice(from + 1)
887
+ .find(
888
+ (w, i, rest) =>
889
+ w.startsWith('-') &&
890
+ !rest.slice(0, i).includes('--') &&
891
+ ![...takes, '--json', '--help', '-h'].includes(w.split('=')[0]),
892
+ );
893
+ // A folder name that starts with "-" reads as an option: it goes after
894
+ // --, and that line is the safe one.
895
+ const folder =
896
+ sub === 'app' && stray && /^-[^-]/.test(stray) && stray.length > 2;
897
+ const a = strayAnswer(
898
+ `preview ${sub}`,
899
+ doc,
900
+ head,
901
+ {
902
+ option: stray ?? '',
903
+ ...(folder
904
+ ? {note: 'a folder name that starts with "-" goes after --'}
905
+ : {}),
654
906
  },
907
+ folder ? `${head} -- ${stray}` : null,
655
908
  );
909
+ return {message: a.message, suggestions: a.suggestions};
656
910
  }
657
911
 
658
912
  /**
659
- * A refusal for words after what a command takes, which would otherwise be
660
- * dropped without a word; null when there are none.
913
+ * The refusal of options not written as the command takes them, with the
914
+ * command as meant when there is one.
661
915
  * @param {string} command
662
- * @param {string[]} extra
916
+ * @param {{why: string, line: string | null}} read
663
917
  */
664
- function extraWords(command, extra) {
665
- if (!extra.length) return null;
666
- return cliError(`${command} does not take "${extra.join(' ')}".`, {
918
+ function optionsRefusal(command, read) {
919
+ return cliError(`${read.why}.`, {
667
920
  suggestions: [
668
- {name: cmd(`${EDITOR} ${command} --help`), reason: 'what it takes'},
921
+ ...(read.line ? [{name: cmd(read.line), reason: 'do this instead'}] : []),
922
+ {
923
+ name: cmd(`${EDITOR} ${command} --help`),
924
+ reason: 'every option it takes',
925
+ },
669
926
  ],
670
- code: ERROR_CODES.ERR_INVALID_ARGUMENT,
927
+ code: ERROR_CODES.ERR_INVALID_OPTION,
671
928
  });
672
929
  }
673
930
 
931
+ /**
932
+ * {@link optionsAsWritten} as a refusal, or null.
933
+ * @param {string} command
934
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc
935
+ */
936
+ function readOptions(command, doc) {
937
+ const read = optionsAsWritten(command, doc);
938
+ return read ? optionsRefusal(command, read) : null;
939
+ }
940
+
941
+ /**
942
+ * {@link readOptions} for `set` and `undo`, whose line is checked as every
943
+ * offered line is (the command's own check, a repair it offers folded in):
944
+ * a line set or undo refuses with no repair is not offered.
945
+ * @param {'set' | 'undo'} command
946
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc
947
+ */
948
+ async function readOptionsChecked(command, doc) {
949
+ const read = optionsAsWritten(command, doc);
950
+ if (!read) return null;
951
+ const line = read.line
952
+ ? await editorCheckedLine(command, read.line, process.cwd())
953
+ : null;
954
+ return optionsRefusal(command, {...read, line});
955
+ }
956
+
957
+ /**
958
+ * Refuse an option `show` does not take with a show that works: the same
959
+ * show without it, and its help (an option the one reader names, and one
960
+ * written with a value, are read first by {@link readOptions}). Null when
961
+ * there is none.
962
+ * @param {string} name
963
+ * @param {unknown[]} rest the words after the theme
964
+ * @param {{png?: boolean, section?: string}} o the options read
965
+ */
966
+ function showStray(name, rest, o) {
967
+ const stray = rest.map(String).find(w => w.startsWith('-'));
968
+ if (stray == null) return null;
969
+ // An option the one reader names never comes here (readOptions reads
970
+ // it first): this one is none show takes, so the show it offers leaves it
971
+ // out and names no guess.
972
+ return strayRefusal(
973
+ 'show',
974
+ showDoc,
975
+ `${EDITOR} show`,
976
+ {option: stray},
977
+ `${EDITOR} show ${name}${o.section ? ` --section ${o.section}` : ''}${o.png ? ' --png' : ''}`,
978
+ );
979
+ }
980
+
981
+ /**
982
+ * A refusal for words after what a command takes, which would otherwise be
983
+ * dropped without a word (the one stray reader); null when there are none.
984
+ * @param {string} command
985
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc
986
+ * @param {string[]} extra
987
+ */
988
+ function extraWords(command, doc, extra) {
989
+ if (!extra.length) return null;
990
+ return strayRefusal(command, doc, `${EDITOR} ${command}`, {extra});
991
+ }
992
+
674
993
  /**
675
994
  * Help that explains exactly what a subcommand does: its whole description
676
995
  * under the usage line, while the group's list keeps the one-line summary.
@@ -727,18 +1046,24 @@ function defineGroup(parent, doc) {
727
1046
  if (extras.length > 0) {
728
1047
  const word = String(extras[0]).toLowerCase();
729
1048
  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
1049
  const ranked = (cmd.commands ?? [])
737
1050
  .map(command => command.name())
738
1051
  .sort(
739
1052
  (a, b) =>
740
1053
  levenshteinDistance(word, a) - levenshteinDistance(word, b),
741
1054
  );
1055
+ // A typo of a subcommand (lst, remve) is that subcommand; any
1056
+ // other word after `preview` that names an editor theme here asks
1057
+ // for that theme's pages.
1058
+ const typo = typoOf(word, ranked[0] ?? '') ? ranked[0] : null;
1059
+ const moved =
1060
+ MOVED[group]?.[word] ??
1061
+ (typo
1062
+ ? null
1063
+ : group === 'preview' &&
1064
+ editorThemesAt(process.cwd()).includes(word)
1065
+ ? `add --theme ${word}`
1066
+ : null);
742
1067
  return cliError(
743
1068
  `unknown subcommand '${doc.name} ${String(extras[0])}'${moved ? `; it is ${here} ${moved}` : ''}`,
744
1069
  {
@@ -777,12 +1102,34 @@ function defineGroup(parent, doc) {
777
1102
  return cmd;
778
1103
  }
779
1104
 
1105
+ /**
1106
+ * A preview command's result, once it is in: this client owns its process,
1107
+ * so a stop that lands while the result is printed is held, and a printed
1108
+ * ok never ends with exit 130. The API itself leaves no listener behind.
1109
+ * @template T
1110
+ * @param {Promise<T>} result
1111
+ * @returns {Promise<T>}
1112
+ */
1113
+ async function resultStands(result) {
1114
+ const r = await result;
1115
+ for (const sig of /** @type {const} */ (['SIGINT', 'SIGTERM']))
1116
+ if (!process.listeners(sig).includes(heldStop)) process.on(sig, heldStop);
1117
+ return r;
1118
+ }
1119
+
1120
+ /** A stop after a preview command finished: its result stands. */
1121
+ function heldStop() {}
1122
+
780
1123
  /**
781
1124
  * Register `theme` and its subcommands under the `experimental` group.
782
1125
  * @param {import('commander').Command} group the `experimental` command
783
1126
  * @param {import('commander').Command} program the root program
784
1127
  */
785
1128
  export function registerExperimentalTheme(group, program) {
1129
+ // A command run with no theme names the app's only theme.
1130
+ setEditorThemeList(editorThemesAt);
1131
+ setEditorFreeName(editorFreeName);
1132
+ setUnknownOptionReader(unknownThemeOption);
786
1133
  const theme = defineGroup(group, groupDoc);
787
1134
  explained(theme, groupDoc);
788
1135
  theme.addHelpText(
@@ -804,9 +1151,13 @@ export function registerExperimentalTheme(group, program) {
804
1151
  /** @type {any} */ o,
805
1152
  /** @type {any} */ cmd,
806
1153
  ) =>
1154
+ // An option given a value is refused before the run, as for every
1155
+ // other editor command: a refusal inside run is thrown, never
1156
+ // printed there.
1157
+ readOptions('new', newDoc) ??
807
1158
  run(
808
1159
  program,
809
- () => {
1160
+ async () => {
810
1161
  // An option new does not take (--force, --dry-run, -t) is refused
811
1162
  // with new's help, as every editor command's unknown option is.
812
1163
  const takes = new Set(
@@ -824,55 +1175,139 @@ export function registerExperimentalTheme(group, program) {
824
1175
  (/** @type {string} */ w) =>
825
1176
  /^-/.test(w) && !takes.has(w.split('=')[0]),
826
1177
  );
1178
+ // `--base` is the dial new takes as --like.
1179
+ if (stray && stray.split('=')[0] === '--base') {
1180
+ const args = (cmd?.args ?? []).slice(1).map(String);
1181
+ const at = args.indexOf(stray);
1182
+ const value = stray.includes('=')
1183
+ ? stray.slice(stray.indexOf('=') + 1)
1184
+ : args[at + 1];
1185
+ // Thrown, as every refusal inside run is: run prints it once
1186
+ // (a refusal printed here and then caught again by run would
1187
+ // print twice where exit does not end the process).
1188
+ throw new AstryxError(
1189
+ `new takes the base theme as --like, not --base.`,
1190
+ value
1191
+ ? [
1192
+ {
1193
+ name: `${EDITOR} new ${quoteCommandArgument(name)}${newFlagLine({...o, like: value})}`,
1194
+ reason: 'do this instead',
1195
+ },
1196
+ ]
1197
+ : [
1198
+ {
1199
+ name: `${EDITOR} new --help`,
1200
+ reason: 'every option it takes',
1201
+ },
1202
+ ],
1203
+ ERROR_CODES.ERR_INVALID_OPTION,
1204
+ );
1205
+ }
827
1206
  if (stray)
828
- return cliError(`unknown option '${stray}'.`, {
829
- suggestions: [
1207
+ throw new AstryxError(
1208
+ `unknown option '${stray}'.`,
1209
+ [
830
1210
  {
831
- name: cliLine(`${EDITOR} new --help`),
1211
+ name: `${EDITOR} new --help`,
832
1212
  reason: 'every option it takes',
833
1213
  },
834
1214
  ],
835
- code: ERROR_CODES.ERR_INVALID_OPTION,
836
- });
1215
+ ERROR_CODES.ERR_INVALID_OPTION,
1216
+ );
837
1217
  // A word after the name is never dropped without a word.
838
1218
  const extra = (cmd?.args ?? []).slice(1);
839
1219
  if (extra.length) {
840
1220
  // Words after `--` that are `--<option> <value>` pairs new
841
1221
  // takes become options; the other words were most likely
842
1222
  // part of the name. The options given stay in the suggestion.
843
- /** @type {Record<string, unknown>} */
1223
+ /** @type {Record<string, any>} */
844
1224
  const given = {...o};
845
1225
  /** @type {string[]} */
846
1226
  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];
1227
+ // Each word in the order typed: one that follows an option's
1228
+ // value with no option between is more of that value, read as
1229
+ // set reads it (`--font Open Sans` is the family Open Sans).
1230
+ const valueFlags = new Set(
1231
+ (newDoc.options ?? [])
1232
+ .filter(opt => /</.test(String(opt.flag)))
1233
+ .map(opt => String(opt.flag).split(' ')[0]),
1234
+ );
1235
+ const camel = (/** @type {string} */ f) =>
1236
+ f.slice(2).replace(/-([a-z])/g, (_, c) => c.toUpperCase());
1237
+ const argv = process.argv;
1238
+ const from = argv.indexOf('new', argv.indexOf('editor') + 1);
1239
+ /** @type {string | null} */
1240
+ let open = null;
1241
+ let named = false;
1242
+ for (let i = from + 1; from >= 0 && i < argv.length; i++) {
1243
+ const w = argv[i];
1244
+ if (w === '--') {
1245
+ // After `--`, `--<option> <value>` pairs new takes.
1246
+ for (let j = i + 1; j < argv.length; j++) {
1247
+ const x = argv[j];
1248
+ if (x.startsWith('--')) {
1249
+ if (argv[j + 1] != null && given[camel(x)] == null)
1250
+ given[camel(x)] = argv[++j];
1251
+ } else words.push(x);
1252
+ }
1253
+ break;
1254
+ }
1255
+ if (w.startsWith('-')) {
1256
+ const flag = w.split('=')[0];
1257
+ open = valueFlags.has(flag) ? camel(flag) : null;
1258
+ if (open && !w.includes('=')) i += 1;
1259
+ continue;
1260
+ }
1261
+ // The name ends the value of an option typed before it: a
1262
+ // word after the name is never more of that value.
1263
+ if (!named) {
1264
+ named = true;
1265
+ open = null;
1266
+ continue;
1267
+ }
1268
+ if (open) {
1269
+ const had = given[open];
1270
+ given[open] = Array.isArray(had)
1271
+ ? [...had.slice(0, -1), `${had.at(-1)} ${w}`]
1272
+ : `${had} ${w}`;
855
1273
  continue;
856
1274
  }
857
1275
  words.push(w);
858
1276
  }
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, '-');
1277
+ // A built-in theme among the words (after a `like` word, or
1278
+ // typed as the name with the real name after it) is the base,
1279
+ // as --like; every other word is part of the name.
1280
+ const all = [String(name), ...words];
1281
+ const baseAt = all.findIndex(
1282
+ (w, i) =>
1283
+ builtInThemes().includes(w.toLowerCase()) &&
1284
+ (i > 0 || all.length > 1),
1285
+ );
1286
+ if (baseAt >= 0 && given.like == null)
1287
+ given.like = all[baseAt].toLowerCase();
1288
+ const nameWords = all.filter(
1289
+ (w, i) =>
1290
+ i !== baseAt &&
1291
+ !(baseAt >= 0 && /^like$/i.test(w) && i === baseAt - 1),
1292
+ );
1293
+ const fixed = nameWords
1294
+ .join('-')
1295
+ .toLowerCase()
1296
+ .replace(/[^a-z0-9-]+/g, '-');
1297
+ // The line is checked as every new line is offered.
1298
+ const read = Object.keys(given).some(k => given[k] !== o[k]);
868
1299
  throw new AstryxError(
869
- `new takes one theme name; "${extra.join(' ')}" is extra. For a base theme, use --like. Nothing was changed.`,
870
- [
1300
+ `new takes one theme name; "${extra.join(' ')}" is extra.${read ? ' A value of more than one word goes in quotes.' : ''} For a base theme, use --like. Nothing was changed.`,
1301
+ await editorCheckedNewLines(
1302
+ `${EDITOR} new ${quoteCommandArgument(fixed)}${newFlagLine(given)}`,
1303
+ fixed,
871
1304
  {
872
- name: `${EDITOR} new ${quoteCommandArgument(fixed)}${newFlagLine(given)}`,
873
- reason: 'do this instead',
1305
+ cwd: process.cwd(),
1306
+ like: given.like,
1307
+ png: given.png ?? false,
1308
+ settings: newSettingsGiven(given),
874
1309
  },
875
- ],
1310
+ ),
876
1311
  ERROR_CODES.ERR_INVALID_ARGUMENT,
877
1312
  );
878
1313
  }
@@ -908,10 +1343,17 @@ export function registerExperimentalTheme(group, program) {
908
1343
  // A declaration pasted as one argument (`--color-accent: #e11d48`,
909
1344
  // or `--color-accent:#e11d48`) is the token and its value; with no
910
1345
  // value otherwise, the missing-argument error the parser gives.
1346
+ // A pasted JSON object of settings goes to the editor whole, which
1347
+ // gives one set line per entry.
1348
+ if (!value.length && /^\s*\{/.test(thing)) value = [''];
911
1349
  if (!value.length) {
912
1350
  // Any thing, a token or a dial, with `:` or `=` (`accent: red`,
913
1351
  // `--color-accent=#e11d48`).
914
- const pasted = /^(\S+?)\s*[:=]\s*(.+?);?\s*$/.exec(thing);
1352
+ // A thing and its value in one word (`'corners pill'`) are the
1353
+ // same as given apart.
1354
+ const pasted =
1355
+ /^(\S+?)\s*[:=]\s*(.+?);?\s*$/.exec(thing) ??
1356
+ /^\s*(\S+)\s+(.+?)\s*$/.exec(thing);
915
1357
  if (!pasted)
916
1358
  return missingSetValue(
917
1359
  editor.commands.find(c => c.name() === 'set'),
@@ -919,14 +1361,20 @@ export function registerExperimentalTheme(group, program) {
919
1361
  thing = pasted[1];
920
1362
  value = [pasted[2]];
921
1363
  }
922
- return (
923
- strayOption('set', value) ??
1364
+ return (async () =>
1365
+ (await readOptionsChecked('set', setDoc)) ??
1366
+ // A token typed after its value (`set t 4px --radius-element`)
1367
+ // is no option: the set reads the two in the other order.
1368
+ (value.length === 1 &&
1369
+ /^--[a-z0-9-]+$/i.test(value[0]) &&
1370
+ !thing.startsWith('-')
1371
+ ? null
1372
+ : strayOption('set', setDoc, value)) ??
924
1373
  run(
925
1374
  program,
926
1375
  () => themeEditSet(name, thing, value.join(' '), changeOptions(o)),
927
1376
  changeBlocks,
928
- )
929
- );
1377
+ ))();
930
1378
  },
931
1379
  }),
932
1380
  setDoc,
@@ -941,7 +1389,9 @@ export function registerExperimentalTheme(group, program) {
941
1389
  /** @type {any} */ o,
942
1390
  /** @type {any} */ c,
943
1391
  ) =>
944
- extraWords('show', (c?.args ?? []).slice(1)) ??
1392
+ readOptions('show', showDoc) ??
1393
+ showStray(name, (c?.args ?? []).slice(1), o) ??
1394
+ extraWords('show', showDoc, (c?.args ?? []).slice(1)) ??
945
1395
  // The sheet is limited to one section (the docs say so): a second
946
1396
  // --section is refused, never kept over the first in silence.
947
1397
  (new Set(flagValues('section')).size > 1
@@ -974,6 +1424,8 @@ export function registerExperimentalTheme(group, program) {
974
1424
  ),
975
1425
  }),
976
1426
  showDoc,
1427
+ // An unknown option reaches the action, which names a show that works.
1428
+ {tokens: true},
977
1429
  );
978
1430
 
979
1431
  explained(
@@ -986,27 +1438,31 @@ export function registerExperimentalTheme(group, program) {
986
1438
  /** @type {any} */ o,
987
1439
  /** @type {import('commander').Command} */ c,
988
1440
  ) =>
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
1441
+ (async () =>
1442
+ (await readOptionsChecked('undo', undoDoc)) ??
1443
+ strayOption('undo', undoDoc, [which, ...(c?.args ?? []).slice(3)]) ??
1444
+ extraWords('undo', undoDoc, (c?.args ?? []).slice(3)) ??
1445
+ run(
1446
+ program,
1447
+ () =>
1448
+ themeEditUndo(name, {
1449
+ ...changeOptions(o),
1450
+ ...(thing == null ? {} : {thing, value: which}),
1451
+ }),
1452
+ r =>
1453
+ r.data.action === 'step'
1454
+ ? [
1455
+ // What was undone is in the headline, so a tail of
1456
+ // the output keeps it.
1457
+ `[ok] ${r.data.theme}: undid ${/** @type {any} */ (r.data).undid ?? 'the last change'}${/** @type {any} */ (r.data).refusedBefore ? ` (${/** @type {any} */ (r.data).refusedBefore})` : ''}`,
1458
+ ...project(/** @type {any} */ (r.data)),
1459
+ ]
1460
+ : changeBlocks(
1461
+ /** @type {import('../../../../api/theme-edit/theme-edit.type.mjs').ThemeEditChangeResponse} */ (
1462
+ r
1463
+ ),
1007
1464
  ),
1008
- ),
1009
- ),
1465
+ ))(),
1010
1466
  }),
1011
1467
  undoDoc,
1012
1468
  {tokens: true},
@@ -1026,13 +1482,15 @@ export function registerExperimentalTheme(group, program) {
1026
1482
  program,
1027
1483
  () =>
1028
1484
  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
- }),
1485
+ resultStands(
1486
+ themeEditPreviewAdd([words ?? []].flat().join(' ') || undefined, {
1487
+ cwd: process.cwd(),
1488
+ theme: o.theme,
1489
+ template: o.template,
1490
+ top: o.top,
1491
+ path: o.path,
1492
+ }),
1493
+ ),
1036
1494
  r => {
1037
1495
  const {matched, skipped, ...rest} = r.data;
1038
1496
  return [
@@ -1073,10 +1531,12 @@ export function registerExperimentalTheme(group, program) {
1073
1531
  program,
1074
1532
  () =>
1075
1533
  previewFlagsOnce('app', ['theme']) ??
1076
- themeEditPreviewApp(dir, {
1077
- cwd: process.cwd(),
1078
- theme: o.theme,
1079
- }),
1534
+ resultStands(
1535
+ themeEditPreviewApp(dir, {
1536
+ cwd: process.cwd(),
1537
+ theme: o.theme,
1538
+ }),
1539
+ ),
1080
1540
  r => [
1081
1541
  `[ok] new app in ${r.data.folder} with the theme preview`,
1082
1542
  ...project(/** @type {any} */ (r.data)),
@@ -1085,25 +1545,6 @@ export function registerExperimentalTheme(group, program) {
1085
1545
  }).allowExcessArguments(false),
1086
1546
  previewAppDoc,
1087
1547
  );
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
1548
 
1108
1549
  explained(
1109
1550
  defineCommand(preview, previewListDoc, {
@@ -1157,7 +1598,9 @@ export function registerExperimentalTheme(group, program) {
1157
1598
  program,
1158
1599
  () =>
1159
1600
  previewFlagsOnce('remove', ['path']) ??
1160
- themeEditPreviewRemove(page, {cwd: process.cwd(), path: o.path}),
1601
+ resultStands(
1602
+ themeEditPreviewRemove(page, {cwd: process.cwd(), path: o.path}),
1603
+ ),
1161
1604
  r => [
1162
1605
  r.data.pages.length
1163
1606
  ? `[ok] removed ${page} from the theme preview`
@@ -1256,7 +1699,10 @@ export function registerExperimentalTheme(group, program) {
1256
1699
  // question); a picture is told by its extension here only to keep
1257
1700
  // option words after it for the count.
1258
1701
  const picture = /\.png$/i.test(rest[0] ?? '');
1259
- const stray = picture ? null : strayOption('how', rest.slice(1));
1702
+ const stray = picture
1703
+ ? null
1704
+ : (readOptions(howDoc.name.split(' ').pop() ?? 'how', howDoc) ??
1705
+ strayOption('how', howDoc, rest.slice(1)));
1260
1706
  if (stray) return stray;
1261
1707
  return run(
1262
1708
  program,
@@ -1303,9 +1749,17 @@ export function registerExperimentalTheme(group, program) {
1303
1749
  build: 'compile',
1304
1750
  explain: editorThemeRefusal,
1305
1751
  preflight: editorCompileProblem,
1752
+ follow: editorFollowCompile,
1306
1753
  missingSource: editorMissingSource,
1307
1754
  template: editorThemeTemplate,
1308
1755
  hold: editorThemeHold,
1756
+ loadedFonts: editorLoadedFonts,
1757
+ extraData: editorBuildExtra,
1758
+ afterBuild: editorAfterBuild,
1759
+ sourcePath: editorSourcePath,
1760
+ fontHelp: editorFontHelp,
1761
+ install: editorInstall,
1762
+ colorModes: editorColorModes,
1309
1763
  },
1310
1764
  );
1311
1765
  }