@astryxdesign/cli 0.7.16 → 0.7.17-canary.g0135e03

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (369) hide show
  1. package/README.md +76 -86
  2. package/api/build/_adapter.d.mts +12 -0
  3. package/api/build/_adapter.mjs +51 -34
  4. package/api/build/blocks/blocks.d.mts +7 -5
  5. package/api/build/blocks/blocks.mjs +113 -26
  6. package/api/build/build.doc.mjs +4 -3
  7. package/api/build/build.type.d.mts +2 -2
  8. package/api/build/build.type.mjs +3 -3
  9. package/api/build/kit/kind.d.mts +2 -1
  10. package/api/build/kit/kind.mjs +199 -10
  11. package/api/build/kit/kit.mjs +6 -4
  12. package/api/build/kit/rank.d.mts +4 -2
  13. package/api/build/kit/rank.mjs +125 -24
  14. package/api/build/kit/start.d.mts +5 -4
  15. package/api/build/kit/start.mjs +12 -8
  16. package/api/build/kit/weights.d.mts +39 -3
  17. package/api/build/kit/weights.json +1 -1
  18. package/api/build/kit/weights.mjs +340 -43
  19. package/api/build/kit/word-model.d.mts +23 -0
  20. package/api/build/kit/word-model.mjs +46 -0
  21. package/api/build/kit/words.d.mts +48 -0
  22. package/api/build/kit/words.mjs +90 -1
  23. package/api/component/__fixtures__/resolutions/modules.txt +4 -5
  24. package/api/component/list/list.d.mts +1 -1
  25. package/api/component/list/list.mjs +48 -6
  26. package/api/discover/_adapter.d.mts +1 -1
  27. package/api/discover/search/search.mjs +3 -2
  28. package/api/docs/_adapter.d.mts +26 -2
  29. package/api/docs/_adapter.mjs +219 -6
  30. package/api/docs/docs.d.mts +3 -0
  31. package/api/docs/docs.doc.mjs +7 -1
  32. package/api/docs/docs.mjs +12 -0
  33. package/api/docs/docs.type.d.mts +5 -0
  34. package/api/docs/docs.type.mjs +2 -0
  35. package/api/docs/node/node.mjs +1 -1
  36. package/api/doctor/_adapter.d.mts +27 -5
  37. package/api/doctor/_adapter.mjs +83 -10
  38. package/api/doctor/built-checks.mjs +40 -14
  39. package/api/doctor/doctor.d.mts +4 -3
  40. package/api/doctor/doctor.mjs +14 -7
  41. package/api/doctor/theme-checks.mjs +121 -17
  42. package/api/icon/_records.mjs +2 -1
  43. package/api/index.d.mts +2 -0
  44. package/api/index.mjs +2 -0
  45. package/api/integration/_adapter.d.mts +44 -0
  46. package/api/integration/_adapter.mjs +77 -1
  47. package/api/integration/authoring-checks.mjs +6 -6
  48. package/api/integration/example-scope.d.mts +14 -0
  49. package/api/integration/example-scope.mjs +44 -0
  50. package/api/integration/example-scope.type.d.mts +29 -0
  51. package/api/integration/example-scope.type.mjs +25 -0
  52. package/api/integration/integrationExampleScope.doc.d.mts +11 -0
  53. package/api/integration/integrationExampleScope.doc.mjs +59 -0
  54. package/api/integration/validate-integration.mjs +19 -1
  55. package/api/integration/validate-integration.type.d.mts +9 -0
  56. package/api/integration/validate-integration.type.mjs +1 -1
  57. package/api/integration/validateIntegration.doc.mjs +1 -1
  58. package/api/render/_adapter.mjs +591 -195
  59. package/api/render/render.doc.mjs +11 -3
  60. package/api/render/render.type.d.mts +52 -0
  61. package/api/render/render.type.mjs +31 -1
  62. package/api/search/ORDERING.md +1 -1
  63. package/api/search/_adapter.d.mts +9 -0
  64. package/api/search/_adapter.mjs +85 -0
  65. package/api/search/_candidate-score.mjs +51 -32
  66. package/api/search/_fit-order.mjs +3 -3
  67. package/api/search/_gather-components.d.mts +3 -2
  68. package/api/search/_gather-components.mjs +12 -3
  69. package/api/search/_lexical.d.mts +5 -0
  70. package/api/search/_lexical.mjs +8 -2
  71. package/api/search/_result.d.mts +11 -9
  72. package/api/search/_result.mjs +4 -4
  73. package/api/search/_score.d.mts +6 -1
  74. package/api/search/_score.mjs +15 -3
  75. package/api/search/search-index.mjs +7 -1
  76. package/api/search/search.d.mts +1 -1
  77. package/api/theme/_adapter.mjs +12 -1
  78. package/api/theme/build/build.d.mts +122 -1
  79. package/api/theme/build/build.mjs +412 -84
  80. package/api/theme/build/core-interception.d.mts +10 -0
  81. package/api/theme/build/core-interception.mjs +10 -0
  82. package/api/theme/build/font-warning.d.mts +23 -3
  83. package/api/theme/build/font-warning.mjs +54 -5
  84. package/api/theme/build/icon-imports.mjs +25 -2
  85. package/api/theme/theme.type.d.mts +10 -0
  86. package/api/theme/theme.type.mjs +7 -1
  87. package/api/theme-edit/_adapter.d.mts +103 -3
  88. package/api/theme-edit/_adapter.mjs +961 -82
  89. package/api/theme-edit/_catalog.mjs +19 -4
  90. package/api/theme-edit/_check.d.mts +63 -24
  91. package/api/theme-edit/_check.mjs +2467 -362
  92. package/api/theme-edit/_color.d.mts +10 -0
  93. package/api/theme-edit/_color.mjs +49 -1
  94. package/api/theme-edit/_compiler.mjs +89 -6
  95. package/api/theme-edit/_context.d.mts +3 -3
  96. package/api/theme-edit/_context.mjs +165 -54
  97. package/api/theme-edit/_css.d.mts +14 -0
  98. package/api/theme-edit/_css.mjs +46 -1
  99. package/api/theme-edit/_edit.d.mts +31 -4
  100. package/api/theme-edit/_edit.mjs +2433 -204
  101. package/api/theme-edit/_how-commands.d.mts +72 -1
  102. package/api/theme-edit/_how-commands.mjs +759 -9
  103. package/api/theme-edit/_how-question.d.mts +82 -5
  104. package/api/theme-edit/_how-question.mjs +6473 -553
  105. package/api/theme-edit/_how.d.mts +2 -1
  106. package/api/theme-edit/_how.mjs +237 -41
  107. package/api/theme-edit/_marks.d.mts +31 -5
  108. package/api/theme-edit/_marks.mjs +57 -5
  109. package/api/theme-edit/_name-rule.d.mts +11 -0
  110. package/api/theme-edit/_name-rule.mjs +12 -0
  111. package/api/theme-edit/_normal.d.mts +292 -0
  112. package/api/theme-edit/_normal.mjs +1454 -0
  113. package/api/theme-edit/_palette.mjs +10 -4
  114. package/api/theme-edit/_part-words.d.mts +31 -0
  115. package/api/theme-edit/_part-words.mjs +126 -0
  116. package/api/theme-edit/_parts.d.mts +18 -1
  117. package/api/theme-edit/_parts.mjs +246 -23
  118. package/api/theme-edit/_preview-app.d.mts +7 -1
  119. package/api/theme-edit/_preview-app.mjs +776 -187
  120. package/api/theme-edit/_preview.d.mts +100 -14
  121. package/api/theme-edit/_preview.mjs +582 -139
  122. package/api/theme-edit/_project.d.mts +4 -0
  123. package/api/theme-edit/_project.mjs +3 -1
  124. package/api/theme-edit/_settings.d.mts +417 -42
  125. package/api/theme-edit/_settings.mjs +3262 -424
  126. package/api/theme-edit/_tables.d.mts +15 -0
  127. package/api/theme-edit/_tables.mjs +63 -1
  128. package/api/theme-edit/_vet.d.mts +20 -0
  129. package/api/theme-edit/_vet.mjs +47 -2
  130. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  131. package/api/theme-edit/theme-edit.type.mjs +4 -1
  132. package/api/theme-edit/themeEditHow.doc.mjs +1 -1
  133. package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
  134. package/api/theme-edit/themeEditNew.doc.mjs +7 -4
  135. package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
  136. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
  137. package/api/upgrade/run/run.mjs +4 -3
  138. package/assets/codemods/integration-discovery.mjs +2 -1
  139. package/assets/codemods/run-codemod.mjs +87 -7
  140. package/assets/codemods/transforms/next/index.mjs +11 -1
  141. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  142. package/assets/component-list.generated.json +1 -0
  143. package/assets/docs/author-a-theme.doc.mjs +1 -0
  144. package/assets/docs/theme.doc.dense.mjs +2 -2
  145. package/assets/docs/theme.doc.mjs +1 -1
  146. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  147. package/assets/docs/tree/checks.doc.mjs +1 -1
  148. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  149. package/assets/docs/tree/render-pages.doc.mjs +44 -3
  150. package/assets/docs/tree/single-component.doc.mjs +4 -0
  151. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  152. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  153. package/assets/docs/use-a-theme.doc.mjs +1 -1
  154. package/assets/docs.generated.json +2 -2
  155. package/assets/search-catalog.generated.json +2 -0
  156. package/assets/self-audit.generated.json +1 -1
  157. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  158. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  159. package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
  160. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  161. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  162. package/assets/templates/components.generated.json +1 -1
  163. package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
  164. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +5 -1
  165. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  166. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  167. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  168. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  169. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  170. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  171. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  172. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  173. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  174. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  175. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  176. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  177. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  178. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  179. package/assets/templates/pages/editor/template.doc.mjs +2 -8
  180. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  181. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  182. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  183. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  184. package/assets/templates/pages/ide/page.tsx +24 -2
  185. package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
  186. package/assets/templates/pages/library/template.doc.mjs +4 -1
  187. package/assets/templates/pages/login/template.doc.mjs +2 -1
  188. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  189. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  190. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  191. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  192. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  193. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  194. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  195. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  196. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  197. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  198. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  199. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  200. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  201. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  202. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  203. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  204. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
  205. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  206. package/assets/theme.template.ts +6 -0
  207. package/authoring/debug/parse.d.mts +3 -3
  208. package/authoring/doctypes/_schema.d.mts +3 -3
  209. package/authoring/doctypes/command/command.doc.mjs +1 -1
  210. package/authoring/doctypes/component/categories.d.mts +37 -0
  211. package/authoring/doctypes/component/categories.mjs +54 -0
  212. package/authoring/doctypes/template/template.doc.mjs +1 -1
  213. package/authoring/doctypes/template/type.ts +9 -0
  214. package/authoring/example/example.doc.d.mts +12 -0
  215. package/authoring/example/example.doc.mjs +69 -0
  216. package/authoring/example/preview.d.mts +92 -0
  217. package/authoring/example/preview.mjs +994 -0
  218. package/authoring/example/type.ts +102 -0
  219. package/authoring/index.d.mts +1 -0
  220. package/authoring/index.d.ts +12 -0
  221. package/authoring/index.mjs +3 -1
  222. package/clients/cli/bin/astryx.mjs +6 -9
  223. package/clients/cli/build-id.generated.json +1 -1
  224. package/clients/cli/commands/component.doc.mjs +1 -1
  225. package/clients/cli/commands/component.mjs +22 -3
  226. package/clients/cli/commands/docs.doc.mjs +7 -1
  227. package/clients/cli/commands/docs.mjs +3 -1
  228. package/clients/cli/commands/doctor.mjs +32 -14
  229. package/clients/cli/commands/experimental/render.mjs +42 -1
  230. package/clients/cli/commands/experimental/theme.mjs +358 -63
  231. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  232. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  233. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
  234. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
  235. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
  236. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  237. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  238. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  239. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  240. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  241. package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
  242. package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
  243. package/clients/cli/commands/search.doc.mjs +2 -1
  244. package/clients/cli/commands/search.mjs +6 -1
  245. package/clients/cli/commands/template.mjs +4 -2
  246. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  247. package/clients/cli/commands/theme.doc.mjs +1 -1
  248. package/clients/cli/commands/theme.mjs +317 -47
  249. package/clients/cli/commands/upgrade.mjs +42 -7
  250. package/clients/cli/index.mjs +1 -1
  251. package/clients/cli/lib/cli-error.mjs +2 -1
  252. package/clients/cli/lib/component-format.mjs +205 -98
  253. package/clients/cli/lib/hook-format.mjs +9 -19
  254. package/clients/cli/lib/json-shim.mjs +92 -21
  255. package/clients/cli/lib/manifest.mjs +3 -2
  256. package/clients/cli/manifest.generated.json +1 -1
  257. package/foundation/agent-docs/agent-docs.mjs +1 -1
  258. package/foundation/config/theme-state.d.mts +13 -1
  259. package/foundation/config/theme-state.mjs +47 -7
  260. package/foundation/discovery/authoring-self-docs.mjs +1 -0
  261. package/foundation/discovery/component-discovery.d.mts +11 -0
  262. package/foundation/discovery/component-discovery.mjs +56 -8
  263. package/foundation/discovery/component-replacement.mjs +130 -1
  264. package/foundation/discovery/copied-passages.mjs +2 -1
  265. package/foundation/discovery/doc-types.mjs +4 -3
  266. package/foundation/discovery/entry-name-files.d.mts +43 -0
  267. package/foundation/discovery/entry-name-files.mjs +264 -0
  268. package/foundation/discovery/hook-discovery.d.mts +8 -2
  269. package/foundation/discovery/hook-discovery.mjs +22 -8
  270. package/foundation/discovery/icon-definition-discovery.mjs +2 -1
  271. package/foundation/discovery/icon-set-checks.mjs +2 -1
  272. package/foundation/discovery/icon-set-discovery.mjs +2 -1
  273. package/foundation/discovery/integration-doc-files.mjs +2 -1
  274. package/foundation/discovery/package-exports.d.mts +10 -0
  275. package/foundation/discovery/package-exports.mjs +56 -3
  276. package/foundation/discovery/prop-drift.mjs +9 -9
  277. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  278. package/foundation/discovery/runner-allowlist.mjs +2 -0
  279. package/foundation/discovery/stored-component-list.d.mts +43 -0
  280. package/foundation/discovery/stored-component-list.mjs +90 -0
  281. package/foundation/discovery/stored-search-catalog.d.mts +115 -0
  282. package/foundation/discovery/stored-search-catalog.mjs +297 -0
  283. package/foundation/discovery/stored-self-audit.d.mts +26 -10
  284. package/foundation/discovery/stored-self-audit.mjs +38 -18
  285. package/foundation/discovery/template-adapter.d.mts +53 -1
  286. package/foundation/discovery/template-adapter.mjs +176 -12
  287. package/foundation/discovery/template-icons.mjs +2 -1
  288. package/foundation/discovery/theme-discovery.mjs +31 -4
  289. package/foundation/discovery/theme-imports.d.mts +14 -0
  290. package/foundation/discovery/theme-imports.mjs +43 -1
  291. package/foundation/discovery/theming-targets.mjs +3 -2
  292. package/foundation/doc-compiler/import.mjs +7 -1
  293. package/foundation/doc-compiler/inputs.mjs +3 -2
  294. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  295. package/foundation/doc-compiler/stored-docs.d.mts +22 -0
  296. package/foundation/doc-compiler/stored-docs.mjs +49 -0
  297. package/foundation/env/semver.mjs +3 -1
  298. package/foundation/fonts/font-stylesheet.d.mts +31 -0
  299. package/foundation/fonts/font-stylesheet.mjs +115 -0
  300. package/foundation/fs/cache-eviction.d.mts +21 -0
  301. package/foundation/fs/cache-eviction.mjs +73 -0
  302. package/foundation/fs/exact-codec.d.mts +12 -2
  303. package/foundation/fs/exact-codec.mjs +23 -6
  304. package/foundation/fs/file-protection.mjs +4 -3
  305. package/foundation/fs/gather-cache.d.mts +62 -4
  306. package/foundation/fs/gather-cache.mjs +512 -91
  307. package/foundation/fs/jiti-cache.d.mts +19 -1
  308. package/foundation/fs/jiti-cache.mjs +130 -6
  309. package/foundation/fs/kept-tree.d.mts +60 -0
  310. package/foundation/fs/kept-tree.mjs +154 -0
  311. package/foundation/fs/listing-cache.d.mts +7 -0
  312. package/foundation/fs/listing-cache.mjs +10 -0
  313. package/foundation/fs/module-loader.d.mts +24 -2
  314. package/foundation/fs/module-loader.mjs +94 -21
  315. package/foundation/fs/paths.d.mts +18 -0
  316. package/foundation/fs/paths.mjs +15 -2
  317. package/foundation/fs/read-record.d.mts +9 -0
  318. package/foundation/fs/read-record.mjs +19 -11
  319. package/foundation/fs/stop-cleanup.d.mts +12 -0
  320. package/foundation/fs/stop-cleanup.mjs +66 -0
  321. package/foundation/identity/provider-identity.d.mts +6 -0
  322. package/foundation/identity/provider-identity.mjs +10 -1
  323. package/foundation/integrations/contribution-inventory.mjs +4 -3
  324. package/foundation/integrations/example-code.d.mts +63 -0
  325. package/foundation/integrations/example-code.mjs +416 -0
  326. package/foundation/integrations/public-imports.d.mts +9 -0
  327. package/foundation/integrations/public-imports.mjs +3 -2
  328. package/foundation/integrations/validate-contributions.mjs +17 -45
  329. package/foundation/render/embedded-files.d.mts +6 -0
  330. package/foundation/render/embedded-files.mjs +25 -5
  331. package/foundation/render/embedded-imports.d.mts +39 -7
  332. package/foundation/render/embedded-imports.mjs +66 -27
  333. package/foundation/render/file-header.d.mts +66 -0
  334. package/foundation/render/file-header.mjs +118 -0
  335. package/foundation/render/host-answer.d.mts +18 -0
  336. package/foundation/render/host-answer.mjs +46 -0
  337. package/foundation/render/host-exit.d.mts +1 -0
  338. package/foundation/render/host-exit.mjs +6 -1
  339. package/foundation/render/html-reader.d.mts +55 -2
  340. package/foundation/render/html-reader.mjs +145 -26
  341. package/foundation/render/markup-edits.d.mts +57 -0
  342. package/foundation/render/markup-edits.mjs +182 -0
  343. package/foundation/render/page-host.mjs +29 -12
  344. package/foundation/render/page-worker.mjs +121 -13
  345. package/foundation/render/picture-chrome.d.mts +4 -0
  346. package/foundation/render/picture-chrome.mjs +185 -0
  347. package/foundation/render/picture-playwright.d.mts +4 -0
  348. package/foundation/render/picture-playwright.mjs +34 -0
  349. package/foundation/render/rebuild.mjs +2 -1
  350. package/foundation/render/render-page.d.mts +35 -3
  351. package/foundation/render/render-page.mjs +641 -96
  352. package/foundation/render/source-block.d.mts +85 -6
  353. package/foundation/render/source-block.mjs +211 -20
  354. package/foundation/render/ts-paths.d.mts +69 -6
  355. package/foundation/render/ts-paths.mjs +326 -40
  356. package/foundation/response/error-codes.d.mts +3 -1
  357. package/foundation/response/error-codes.d.ts +1 -0
  358. package/foundation/response/error-codes.doc.mjs +12 -1
  359. package/foundation/response/error-codes.mjs +11 -1
  360. package/foundation/response/response-types.doc.mjs +2 -2
  361. package/foundation/text/compare-text.d.mts +14 -0
  362. package/foundation/text/compare-text.mjs +68 -0
  363. package/foundation/text/string-utils.d.mts +3 -2
  364. package/foundation/text/string-utils.mjs +18 -4
  365. package/foundation/text/suggest-order.d.mts +9 -0
  366. package/foundation/text/suggest-order.mjs +15 -1
  367. package/foundation/xle/expand.mjs +2 -1
  368. package/host/index.mjs +8 -6
  369. package/package.json +7 -6
@@ -36,9 +36,10 @@ export function condition(ctx: import("./_settings.mjs").Ctx, target: string, co
36
36
  * Read `--at` points: "x,y;x,y", "x,y x,y", repeated, or a flat "a,b,c,d".
37
37
  * Each number is a whole pixel; anything else is refused by name.
38
38
  * @param {string[]} at
39
+ * @param {string | null} [file] the picture the points are on
39
40
  * @returns {Array<{x: number, y: number}>}
40
41
  */
41
- export function parsePoints(at: string[]): Array<{
42
+ export function parsePoints(at: string[], file?: string | null): Array<{
42
43
  x: number;
43
44
  y: number;
44
45
  }>;
@@ -33,15 +33,17 @@ import {
33
33
  editedThemes,
34
34
  loadTheme,
35
35
  nearest,
36
+ partComponentDocs,
36
37
  refuse,
38
+ themeSourceParseError,
37
39
  themeSourceProblem,
38
40
  } from './_settings.mjs';
39
- import {ASPECTS, checkSetting} from './_check.mjs';
41
+ import {ASPECTS, settableStates} from './_check.mjs';
40
42
  import {MODAL} from './_compiler.mjs';
41
43
  import {PALETTE_DIALS, mappingRows, paletteFiles} from './_palette.mjs';
42
44
  import {requireProject, context} from './_context.mjs';
43
45
  import {checked, exampleStep, howTheme, render} from './_how-commands.mjs';
44
- import {draftAnswer} from './_how-question.mjs';
46
+ import {draftAnswer, partLexicon, valueAsked} from './_how-question.mjs';
45
47
  import {
46
48
  getCliInvocation,
47
49
  quoteCommandArgument,
@@ -191,6 +193,16 @@ async function answer(subject, options, cwd) {
191
193
  // "½rem": a fraction is a number before anything reads the question.
192
194
  const t = (subject ?? '')
193
195
  .trim()
196
+ // "corners:", "var(--radius-element)": a setting pasted as written is
197
+ // a lookup of it.
198
+ .replace(/^([a-z][a-z -]*):\s*$/i, '$1')
199
+ .replace(/^var\(\s*(--[a-z0-9-]+)\s*\)$/i, '$1')
200
+ // A lone "½" with no unit after it is a share of now ("card padding
201
+ // ½"), never 0.5px.
202
+ .replace(
203
+ /(\d*)(?:½|1\u20442)(?!\s*(?:rem|px|em|%|x\b|×|times\b))/g,
204
+ (_, n) => (n ? `${n}½` : ' half '),
205
+ )
194
206
  .replace(/(\d*)(?:½|1\u20442)/g, (_, n) => `${n ? Number(n) + 0.5 : '0.5'}`)
195
207
  .replace(
196
208
  /(\d*)(?:¼|1\u20444)/g,
@@ -200,6 +212,12 @@ async function answer(subject, options, cwd) {
200
212
  /(\d*)(?:¾|3\u20444)/g,
201
213
  (_, n) => `${n ? Number(n) + 0.75 : '0.75'}`,
202
214
  );
215
+ // "paddingLeft", "borderRadius": a property as JavaScript spells it is
216
+ // that CSS property, as set takes it.
217
+ if (/^[a-z]+(?:[A-Z][a-z]+)+$/.test(t)) {
218
+ const kebab = t.replace(/[A-Z]/g, ch => `-${ch.toLowerCase()}`);
219
+ if (cssProperties().has(kebab)) return answer(kebab, options, cwd);
220
+ }
203
221
  // "explain spacing", "tell me about the accent": the lookup of what is
204
222
  // named, never a change.
205
223
  const explain =
@@ -214,14 +232,36 @@ async function answer(subject, options, cwd) {
214
232
  run: [`${HOW} ${t ? JSON.stringify(t) : 'card'}`],
215
233
  });
216
234
  if (options.theme != null) {
217
- loadTheme(cwd, options.theme);
235
+ try {
236
+ loadTheme(cwd, options.theme);
237
+ } catch (e) {
238
+ // A theme name near the one typed: the same question for it, never
239
+ // only `show` (the question is kept).
240
+ const err = /** @type {any} */ (e);
241
+ // (A name typed in another case or as a path too.)
242
+ if (err?.suggestions)
243
+ for (const s of err.suggestions) {
244
+ const near = / show ([a-z][a-z0-9-]*)$/.exec(
245
+ String(s.name ?? ''),
246
+ )?.[1];
247
+ if (near)
248
+ s.name = `${HOW} ${quoteCommandArgument(t || 'card')} --theme ${near}`;
249
+ }
250
+ throw e;
251
+ }
218
252
  // A theme whose source no longer extends its settings takes no setting:
219
253
  // an answer would suggest commands that cannot run.
220
- const broken = themeSourceProblem(cwd, options.theme);
254
+ const parseError = themeSourceParseError(cwd, options.theme);
255
+ const broken = parseError
256
+ ? {
257
+ problem: parseError,
258
+ fix: `Fix themes/${options.theme}/${options.theme}.theme.ts.`,
259
+ }
260
+ : await themeSourceProblem(cwd, options.theme);
221
261
  if (broken)
222
262
  refuse(
223
263
  E.ERR_THEME_INVALID,
224
- `${broken}, so settings cannot take effect and no command here would change the theme. Put back the import, extends and name lines in themes/${options.theme}/${options.theme}.theme.ts, then ask again.`,
264
+ `${broken.problem}, so settings cannot take effect and no command here would change the theme. ${broken.fix} Then ask again.`,
225
265
  {run: [`${P} show ${options.theme}`]},
226
266
  );
227
267
  }
@@ -247,16 +287,21 @@ async function answer(subject, options, cwd) {
247
287
  }
248
288
  if (isPicture(t, cwd))
249
289
  return {kind: 'picture', subject: t, ...pictureColors(t, cwd, at, count)};
290
+ // What runs instead: the same subject without the picture option (a
291
+ // real command), never a made-up file name.
292
+ const without = t ? `${HOW} ${quoteCommandArgument(t)}` : `${HOW} --help`;
250
293
  if (at.length)
251
294
  refuse(
252
295
  E.ERR_INVALID_ARGUMENT,
253
- '--at reads the color at points of a PNG picture; name the picture first.',
254
- {run: [`${HOW} picture.png --at "40,20"`]},
296
+ `--at reads the color at points of a PNG picture; name your picture first (${HOW} <your .png file> --at x,y).`,
297
+ {run: [without]},
255
298
  );
256
299
  if (count != null)
257
- refuse(E.ERR_INVALID_ARGUMENT, 'A count applies only to a picture.', {
258
- run: [`${HOW} picture.png 5`],
259
- });
300
+ refuse(
301
+ E.ERR_INVALID_ARGUMENT,
302
+ `A count applies only to a picture (${HOW} <your .png file> 5).`,
303
+ {run: [without]},
304
+ );
260
305
  if (!t) {
261
306
  refuse(
262
307
  E.ERR_MISSING_ARGUMENT,
@@ -430,9 +475,31 @@ async function answer(subject, options, cwd) {
430
475
  // "What does --color-accent do", "what's the variable for card padding":
431
476
  // "--focus-outline-width: 3px": a token typed with a value is set exactly,
432
477
  // or refused with the nearest names; never another token.
478
+ // "cards: --color-border red", "--color-border red on inputs": the token
479
+ // on that part.
480
+ const scopeLead = /^\s*([a-z][a-z -]*?)\s*:\s*(?=--)/i.exec(t)?.[1];
481
+ const scopeTail =
482
+ /\s+(?:on|for)\s+(?:the |my |all )?([a-z][a-z -]*?)\s*$/i.exec(t)?.[1];
483
+ const scopeWord = scopeLead ?? scopeTail;
484
+ const scopeOn = scopeWord
485
+ ? (() => {
486
+ const w = ` ${scopeWord.trim().toLowerCase()} `;
487
+ return (
488
+ partLexicon(ctx).parts.find(([re]) => re.test(w))?.[1].on ?? null
489
+ );
490
+ })()
491
+ : null;
433
492
  const typedToken =
434
493
  /^\s*(--[a-z][a-z0-9-]*)\s*(?::|\s+to\s+|\s+)\s*([^;]+?)\s*;?\s*(?:\bin (light|dark) mode\b.*)?$/i.exec(
435
- t.replace(/^\s*(?:change|set|make|token)\s+/i, ' '),
494
+ t
495
+ .replace(/^\s*(?:change|set|make|token)\s+/i, ' ')
496
+ .replace(/^\s*[a-z][a-z -]*?\s*:\s*(?=--)/i, ' ')
497
+ .replace(
498
+ scopeOn && scopeTail
499
+ ? /\s+(?:on|for)\s+(?:the |my |all )?[a-z][a-z -]*?\s*$/i
500
+ : /$^/,
501
+ '',
502
+ ),
436
503
  );
437
504
  if (
438
505
  typedToken &&
@@ -471,6 +538,7 @@ async function answer(subject, options, cwd) {
471
538
  verb: 'set',
472
539
  thing: token,
473
540
  value,
541
+ ...(scopeOn ? {on: scopeOn} : {}),
474
542
  ...(mode && env.data.mode === 'both' ? {mode} : {}),
475
543
  },
476
544
  ],
@@ -510,8 +578,10 @@ async function answer(subject, options, cwd) {
510
578
  results: tool,
511
579
  ...unknown,
512
580
  };
513
- // a question about what something is gets the lookup, not a change.
581
+ // a question about what something is gets the lookup, not a change; a
582
+ // question about a part's value now gets the value (draftAnswer).
514
583
  if (
584
+ !valueAsked(t) &&
515
585
  (/^\s*(what|which|where)\b.*\b(variables?|tokens?|do|does|means?|controls?|for)\b|^\s*what('s| is) the (css )?(variable|token|property)/i.test(
516
586
  t,
517
587
  ) ||
@@ -578,10 +648,13 @@ async function answer(subject, options, cwd) {
578
648
  ...unknown,
579
649
  ...(empty
580
650
  ? {
581
- hint: results.length
582
- ? `No command does all of "${t}" on ${env.slug}; the lines above say why.`
583
- : `No match for "${t}". Name the part (header, nav links, card, button, banner, input...) and what to change (text color, background, gradient, corners, border, shadow, spacing, bold), in English.`,
651
+ hint: `${
652
+ results.length
653
+ ? `No command does all of "${t}" on ${env.slug}; the lines above say why.`
654
+ : `No match for "${t}". Name the part (header, nav links, card, button, banner, input...) and what to change (text color, background, gradient, corners, border, shadow, spacing, bold), in English.`
655
+ } See ${HOW} --help for the asks it understands.`,
584
656
  run: [
657
+ `${HOW} --help`,
585
658
  `${HOW} --list parts`,
586
659
  `${HOW} "rounder buttons"`,
587
660
  `${HOW} colors`,
@@ -591,6 +664,69 @@ async function answer(subject, options, cwd) {
591
664
  };
592
665
  }
593
666
 
667
+ /**
668
+ * The commands a refusal names to run instead that answer the draft: the
669
+ * same thing set, accepted by set's check, and (for a draft that carries
670
+ * what its clause asks) measured to do it.
671
+ * @param {import('./_how-commands.mjs').HowTheme} env
672
+ * @param {import('./_how-question.mjs').Draft} d
673
+ * @param {Array<{command: string, why: string, run?: string[]}>} refused
674
+ * @returns {string[]}
675
+ */
676
+ function insteadOf(env, d, refused) {
677
+ // (The same thing on the same part: another part is another ask.)
678
+ const things = new Set(
679
+ d.options.flat().map(st => `${st.thing}|${st.on ?? ''}`),
680
+ );
681
+ /** @type {string[]} */
682
+ const out = [];
683
+ for (const line of refused.flatMap(r => r.run ?? [])) {
684
+ const words = [
685
+ ...line
686
+ .replace(/^.*? editor /, '')
687
+ .matchAll(/'((?:[^'\\]|\\.)*)'|"((?:[^"\\]|\\.)*)"|(\S+)/g),
688
+ ].map(m => m[1] ?? m[2] ?? m[3]);
689
+ const st = exampleStep(
690
+ words.map(w => (/\s/.test(w) ? `"${w}"` : w)).join(' '),
691
+ );
692
+ if (
693
+ !st ||
694
+ !things.has(`${st.thing}|${st.on ?? ''}`) ||
695
+ /[<>]/.test(String(st.value ?? ''))
696
+ )
697
+ continue;
698
+ if (!env.check([st]).ok) continue;
699
+ // Held to what the draft asks, else to the way its own dial step went
700
+ // ("more"): never offered unmeasured.
701
+ const way = d.options
702
+ .flat()
703
+ .map(x => x.value)
704
+ .find(v => v === 'more' || v === 'less');
705
+ const intent =
706
+ d.intent ??
707
+ (way
708
+ ? /** @type {import('./_how-commands.mjs').MeasureIntent} */ ({
709
+ families: [],
710
+ typed: [],
711
+ opacityDir: null,
712
+ dir: way,
713
+ zero: false,
714
+ lighter: null,
715
+ subjects: [],
716
+ keep: [],
717
+ mode: null,
718
+ })
719
+ : null);
720
+ if (!intent || typeof env.measure !== 'function') continue;
721
+ // A dial word the other way round from the one asked never answers it.
722
+ if (way && (st.value === 'more' || st.value === 'less') && st.value !== way)
723
+ continue;
724
+ if (env.measure([st], intent)) continue;
725
+ out.push(render(st, env.slug));
726
+ }
727
+ return out;
728
+ }
729
+
594
730
  /**
595
731
  * Check each draft's commands and keep what passes; a draft whose commands
596
732
  * are all refused says why, and points to the lookup that helps.
@@ -598,15 +734,83 @@ async function answer(subject, options, cwd) {
598
734
  * @param {import('./_how-question.mjs').Draft[]} drafts
599
735
  */
600
736
  function finish(env, drafts) {
601
- /** @type {Array<{text: string, commands: string[], sequence?: boolean, refused?: Array<{command: string, why: string}>}>} */
737
+ /** @type {Array<{text: string, commands: string[], sequence?: boolean, refused?: Array<{command: string, why: string, run?: string[]}>}>} */
602
738
  const out = [];
739
+ // The measured check runs first on the drafts that carry what their
740
+ // clause asks; a draft that joins them ("all of it, in order") then keeps
741
+ // only the steps some kept option still has, so it never brings back a
742
+ // step the check left out.
743
+ const key = (/** @type {import('./_how-commands.mjs').Step} */ st) =>
744
+ JSON.stringify([
745
+ st.verb,
746
+ st.thing,
747
+ st.value,
748
+ st.on,
749
+ st.when,
750
+ st.state,
751
+ st.mode,
752
+ ]);
753
+ /** @type {Set<string>} */
754
+ const dropped = new Set();
755
+ /** @type {Set<string>} */
756
+ const kept = new Set();
757
+ /** @type {Map<object, string[]>} */
758
+ const unmetOf = new Map();
759
+ if (typeof env.measure === 'function')
760
+ for (const d of drafts) {
761
+ if (!d.intent) continue;
762
+ const intent = d.intent;
763
+ /** @type {string[]} */
764
+ const unmet = [];
765
+ d.options = d.options.filter(o => {
766
+ const why = env.measure(o, intent);
767
+ for (const st of o) (why ? dropped : kept).add(key(st));
768
+ if (why) unmet.push(why);
769
+ return !why;
770
+ });
771
+ unmetOf.set(d, unmet);
772
+ }
603
773
  for (const d of drafts) {
774
+ if (!d.intent && dropped.size) {
775
+ d.options = d.options
776
+ .map(o => o.filter(st => !dropped.has(key(st)) || kept.has(key(st))))
777
+ .filter(o => o.length);
778
+ // A joined answer left holding what another answer already says is
779
+ // that answer: it is not given twice (and never as "all of it").
780
+ const same = (/** @type {import('./_how-commands.mjs').Step[]} */ o) =>
781
+ drafts.some(
782
+ x =>
783
+ x !== d &&
784
+ x.options.some(
785
+ y =>
786
+ y.length === o.length &&
787
+ y.every((st, i) => key(st) === key(o[i])),
788
+ ),
789
+ );
790
+ if (d.options.length && d.options.every(same)) continue;
791
+ }
792
+ // The measured check: an option whose built result does not do what
793
+ // the question asks is left out, with a plain line saying why.
794
+ const unmet = unmetOf.get(d) ?? [];
795
+ if (unmet.length) {
796
+ if (unmet.length && !d.options.length)
797
+ d.text = `couldn't work out a command that does "${d.text}" as asked: ${[...new Set(unmet)].join('; ')}`;
798
+ else if (unmet.length)
799
+ d.text = `${d.text} (left out: ${[...new Set(unmet)].join('; ')})`;
800
+ }
604
801
  const {commands, refused} = checked(env, d.options);
605
802
  const lookups = d.lookup ? [d.lookup] : [];
803
+ if (!commands.length && !d.options.length && unmet.length) {
804
+ out.push({text: d.text, commands: lookups});
805
+ continue;
806
+ }
606
807
  if (!commands.length && d.options.length && !lookups.length) {
607
808
  out.push({
608
809
  text: `${d.text}: no command does it on ${env.slug}${refused[0] ? `: ${refused[0].why}` : ''}`,
609
- commands: [],
810
+ // The command the refusal itself names to run instead, when it
811
+ // sets the same thing, passes set's check and does what the
812
+ // question asks.
813
+ commands: insteadOf(env, d, refused),
610
814
  refused,
611
815
  });
612
816
  continue;
@@ -682,25 +886,7 @@ function partAnswer(ctx, env, subject, key, unknown, themeFields) {
682
886
  ctx.project.target.get(key)
683
887
  );
684
888
  const group = familyOf(key);
685
- // Only the states set takes on this part (it refuses one that never
686
- // applies there).
687
- // Only the states set takes on this part: a state is dropped when the
688
- // same change without it passes and with it is refused.
689
- const takes = (/** @type {string | undefined} */ st) => {
690
- try {
691
- checkSetting(ctx, env.slug, env.data, 'opacity', '1', {
692
- on: key,
693
- ...(st ? {state: st} : {}),
694
- });
695
- return true;
696
- } catch {
697
- return false;
698
- }
699
- };
700
- const plainOk = takes(undefined);
701
- const states = [...new Set([...target.states, ...COMMON_STATES])].filter(
702
- st => !plainOk || takes(st),
703
- );
889
+ const states = settableStates(ctx, env.slug, env.data, key);
704
890
  const reads = Object.fromEntries(
705
891
  Object.keys(GROUPS).map(g => [
706
892
  g,
@@ -721,7 +907,9 @@ function partAnswer(ctx, env, subject, key, unknown, themeFields) {
721
907
  const extra = {};
722
908
  if (!recorded && !ctx.unchecked) {
723
909
  const {commands} = checked(env, [
724
- [{verb: 'set', thing: 'background', value: '#f3f4f6', on: key}],
910
+ // (A fill of one color is the background color: the shorthand would
911
+ // clear the image Core draws its hover tint with.)
912
+ [{verb: 'set', thing: 'background-color', value: '#f3f4f6', on: key}],
725
913
  [{verb: 'set', thing: 'color', value: '#111827', on: key}],
726
914
  [{verb: 'set', thing: 'border-radius', value: '8px', on: key}],
727
915
  ]);
@@ -734,6 +922,9 @@ function partAnswer(ctx, env, subject, key, unknown, themeFields) {
734
922
  kind: 'part',
735
923
  subject,
736
924
  component: target.component ?? null,
925
+ // What the part is, from its component's doc (a side nav heading is the
926
+ // product or account heading at the top, not a section title).
927
+ is: partComponentDocs(ctx, key).at(-1)?.doc.description || null,
737
928
  components,
738
929
  recorded,
739
930
  group,
@@ -1094,7 +1285,8 @@ function toolAnswer(t, env, targets) {
1094
1285
  },
1095
1286
  ];
1096
1287
  if (
1097
- asks ||
1288
+ // A question about a part's value now is answered with that value.
1289
+ (asks && !valueAsked(q)) ||
1098
1290
  /^which parts (are|does|do)\b/.test(q) ||
1099
1291
  (/^why (is|are|does|do)\b/.test(q) && !/\bnot\b|n'?t\b/.test(q))
1100
1292
  ) {
@@ -1342,14 +1534,18 @@ async function listItems(kind, filter, cwd) {
1342
1534
  * Read `--at` points: "x,y;x,y", "x,y x,y", repeated, or a flat "a,b,c,d".
1343
1535
  * Each number is a whole pixel; anything else is refused by name.
1344
1536
  * @param {string[]} at
1537
+ * @param {string | null} [file] the picture the points are on
1345
1538
  * @returns {Array<{x: number, y: number}>}
1346
1539
  */
1347
- export function parsePoints(at) {
1540
+ export function parsePoints(at, file = null) {
1348
1541
  const words = at
1349
1542
  .join(' ')
1350
1543
  .split(/[;\s]+/)
1351
1544
  .filter(Boolean);
1352
- const example = `${HOW} picture.png --at "40,20;300,180"`;
1545
+ // The picture named, never a made-up file.
1546
+ const example = file
1547
+ ? `${HOW} ${quoteCommandArgument(file)} --at "40,20;300,180"`
1548
+ : `${HOW} --help`;
1353
1549
  if (!words.length)
1354
1550
  refuse(E.ERR_INVALID_ARGUMENT, '--at names no point; give x,y pairs.', {
1355
1551
  run: [example],
@@ -1409,7 +1605,7 @@ function pictureColors(file, cwd, at, count) {
1409
1605
  `The count must be a positive whole number, not "${count}".`,
1410
1606
  {run: [`${HOW} ${file} 5`]},
1411
1607
  );
1412
- const points = at.length ? parsePoints(at) : null;
1608
+ const points = at.length ? parsePoints(at, file) : null;
1413
1609
  // The header holds the size, so a huge picture is refused unread.
1414
1610
  const fd = fs.openSync(abs, 'r');
1415
1611
  const head = Buffer.alloc(8);
@@ -2,12 +2,38 @@
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
4
  /**
5
- * @file The markers the theme editor writes at the top of the files it
6
- * generates, in one place for the editor and for doctor.
5
+ * The marks a file's leading comment can carry, and the command it names:
6
+ * `kind` is `build` for a theme build's output, `editor` for a file the theme
7
+ * editor writes (its settings module or app copy); `command` is the words in
8
+ * backquotes after "Written by" or "Generated by" (for a build, the build
9
+ * command). Null for a file without one. One reader for every caller.
10
+ * A mark written before files named their exact command carries the editor
11
+ * group's words alone, which only print its help: given the file's path,
12
+ * the command is the one that writes that theme's files again (`show`, with
13
+ * the theme its folder is named for).
14
+ * @param {string} source the start of the file
15
+ * @param {string} buildMarker the theme build's own marker
16
+ * @param {string} [file] the file's path
17
+ * @returns {{kind: 'build' | 'editor', command: string} | null}
18
+ */
19
+ export function generatedMark(source: string, buildMarker: string, file?: string): {
20
+ kind: "build" | "editor";
21
+ command: string;
22
+ } | null;
23
+ /**
24
+ * @file The marks the theme editor writes at the top of the files it
25
+ * generates, and the one reader of every generated mark (a theme build's
26
+ * included) that the editor, `theme build` and doctor share.
7
27
  *
8
28
  * @position api/theme-edit — internal
9
29
  */
10
30
  /** The first words of a generated settings module the editor writes. */
11
- export const EDITOR_GENERATED_MARK: "Generated by `astryx experimental theme editor`";
12
- /** The words on every file of a theme's app copy (src/themes/<theme>/). */
13
- export const APP_COPY_MARK: "Written by `astryx experimental theme editor`";
31
+ export const EDITOR_GENERATED_MARK: "Generated by `astryx experimental theme editor";
32
+ /**
33
+ * The words on every file of a theme's app copy (src/themes/<theme>/): the
34
+ * start of "Written by `<the command that writes it>`", which a reader takes
35
+ * whole. A copy written before the command was named carries the group's
36
+ * words alone; both begin so.
37
+ */
38
+ export const APP_COPY_MARK: "Written by `astryx experimental theme editor";
39
+ export function appCopyMark(slug: string): string;
@@ -1,15 +1,67 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file The markers the theme editor writes at the top of the files it
5
- * generates, in one place for the editor and for doctor.
4
+ * @file The marks the theme editor writes at the top of the files it
5
+ * generates, and the one reader of every generated mark (a theme build's
6
+ * included) that the editor, `theme build` and doctor share.
6
7
  *
7
8
  * @position api/theme-edit — internal
8
9
  */
9
10
 
10
11
  /** The first words of a generated settings module the editor writes. */
11
12
  export const EDITOR_GENERATED_MARK =
12
- 'Generated by `astryx experimental theme editor`';
13
+ 'Generated by `astryx experimental theme editor';
13
14
 
14
- /** The words on every file of a theme's app copy (src/themes/<theme>/). */
15
- export const APP_COPY_MARK = 'Written by `astryx experimental theme editor`';
15
+ /**
16
+ * The words on every file of a theme's app copy (src/themes/<theme>/): the
17
+ * start of "Written by `<the command that writes it>`", which a reader takes
18
+ * whole. A copy written before the command was named carries the group's
19
+ * words alone; both begin so.
20
+ */
21
+ export const APP_COPY_MARK = 'Written by `astryx experimental theme editor';
22
+
23
+ /**
24
+ * The mark an app copy's files carry, naming the command that writes them.
25
+ * @param {string} slug
26
+ */
27
+ export const appCopyMark = slug =>
28
+ `Written by \`astryx experimental theme editor show ${slug}\``;
29
+
30
+ /**
31
+ * The marks a file's leading comment can carry, and the command it names:
32
+ * `kind` is `build` for a theme build's output, `editor` for a file the theme
33
+ * editor writes (its settings module or app copy); `command` is the words in
34
+ * backquotes after "Written by" or "Generated by" (for a build, the build
35
+ * command). Null for a file without one. One reader for every caller.
36
+ * A mark written before files named their exact command carries the editor
37
+ * group's words alone, which only print its help: given the file's path,
38
+ * the command is the one that writes that theme's files again (`show`, with
39
+ * the theme its folder is named for).
40
+ * @param {string} source the start of the file
41
+ * @param {string} buildMarker the theme build's own marker
42
+ * @param {string} [file] the file's path
43
+ * @returns {{kind: 'build' | 'editor', command: string} | null}
44
+ */
45
+ export function generatedMark(source, buildMarker, file) {
46
+ const leading =
47
+ /^\s*(?:\/\*[\s\S]*?\*\/|(?:\/\/[^\n]*(?:\n|$)\s*)+)/.exec(source)?.[0] ??
48
+ '';
49
+ if (leading.includes(buildMarker))
50
+ return {kind: 'build', command: 'astryx theme build'};
51
+ if (![APP_COPY_MARK, EDITOR_GENERATED_MARK].some(m => leading.includes(m)))
52
+ return null;
53
+ const named = /(?:Written|Generated) by `([^`]+)`/.exec(leading)?.[1];
54
+ const group = 'astryx experimental theme editor';
55
+ if (named && named.trim() !== group) return {kind: 'editor', command: named};
56
+ // A group-only mark: the theme's own command, from its folder's name.
57
+ const slug = file
58
+ ? String(file).split(/[\\/]/).filter(Boolean).slice(-2)[0]
59
+ : null;
60
+ return {
61
+ kind: 'editor',
62
+ command:
63
+ slug && /^[a-z0-9][a-z0-9-]*$/.test(slug)
64
+ ? `${group} show ${slug}`
65
+ : 'the command that made it',
66
+ };
67
+ }
@@ -0,0 +1,11 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * @file What a theme name may be, in words: the one text every theme-name
6
+ * refusal, the help of `new` and its API docs state.
7
+ *
8
+ * @position api/theme-edit — imported by _settings.mjs and the `new` docs
9
+ */
10
+ /** What a theme name may be, in words. */
11
+ export const NAME_RULE: "lowercase letters, digits and dashes, starting with a letter, a dash only between letters or digits (no two in a row, none at the end), 64 characters at most, and not a name Windows reserves (con, prn, aux, nul, com0-com9, lpt0-lpt9, and com\u00B9-com\u00B3, lpt\u00B9-lpt\u00B3)";
@@ -0,0 +1,12 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file What a theme name may be, in words: the one text every theme-name
5
+ * refusal, the help of `new` and its API docs state.
6
+ *
7
+ * @position api/theme-edit — imported by _settings.mjs and the `new` docs
8
+ */
9
+
10
+ /** What a theme name may be, in words. */
11
+ export const NAME_RULE =
12
+ 'lowercase letters, digits and dashes, starting with a letter, a dash only between letters or digits (no two in a row, none at the end), 64 characters at most, and not a name Windows reserves (con, prn, aux, nul, com0-com9, lpt0-lpt9, and com¹-com³, lpt¹-lpt³)';