@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
@@ -1,6 +1,16 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * Whether only a path alias can resolve an import: its name cannot be a
6
+ * package's, a Node built-in's, or a package's own subpath import
7
+ * (`@/components/Header` and `~/lib/data` cannot; `react`, `@acme/ui`, `fs`
8
+ * and `#utils`, which a package.json `imports` maps, can). A received file's
9
+ * record of alias imports counts only for these, so it can never remap a
10
+ * package, or the reader's own imports, for the reader.
11
+ * @param {string} spec
12
+ */
13
+ export function aliasOnly(spec: string): boolean;
4
14
  /**
5
15
  * What a stylesheet's `@import` rules load, read with postcss so comments
6
16
  * are ignored.
@@ -23,33 +33,49 @@ export function importSpecifiers(source: string, file: string): string[];
23
33
  */
24
34
  export function assetRefsIn(text: string): string[];
25
35
  /**
26
- * The path aliases (`compilerOptions.paths`) of the project that holds
27
- * `dir`, by TypeScript's rules (see ts-paths.mjs).
28
- * @param {string} dir
36
+ * The images, fonts and media a carried file names by a relative path: in a
37
+ * module's strings, or in a stylesheet. A render carries each one that
38
+ * exists, and {@link reachableFiles} expects each one back.
39
+ * @param {string} source
40
+ * @param {string} file its path; a `.css` file is read as a stylesheet
41
+ * @returns {string[]}
42
+ */
43
+ export function assetRefsOf(source: string, file: string): string[];
44
+ /**
45
+ * The path aliases (`compilerOptions.paths`) that TypeScript reads for a page
46
+ * written at `file`, by its rules (see ts-paths.mjs). The file and its
47
+ * folders need not exist yet.
48
+ * @param {string} file absolute
29
49
  * @returns {import('./ts-paths.mjs').PathPattern[]}
30
50
  */
31
- export function receivingAliases(dir: string): import("./ts-paths.mjs").PathPattern[];
51
+ export function receivingAliases(file: string): import("./ts-paths.mjs").PathPattern[];
32
52
  /**
33
53
  * @typedef {object} Reach
34
54
  * @property {boolean} relative - Reached by a relative import (or it is the
35
55
  * page), so it goes where the page's layout puts it.
36
56
  * @property {Set<string>} aliased - Absolute paths a receiving-project alias
37
57
  * import names for it, so it also goes there.
58
+ * @property {Set<string>} unaliased - Alias imports that name it where no
59
+ * receiving-project alias does: the render recorded the file each named,
60
+ * so it goes where the page's layout puts it, and the page needs the alias.
38
61
  */
39
62
  /**
40
63
  * The embedded files the page reaches through its imports.
41
64
  * @param {{path: string, base64: string}[]} files the embedded files, page
42
65
  * first; every path appears once (callers refuse duplicates first)
43
- * @param {{aliases?: import('./ts-paths.mjs').PathPattern[]}} [options] the
44
- * receiving project's path aliases (see receivingAliases)
66
+ * @param {{aliases?: import('./ts-paths.mjs').PathPattern[], recorded?: unknown}} [options]
67
+ * the receiving project's path aliases (see receivingAliases), and the
68
+ * alias imports the render recorded (an untrusted record: only an entry
69
+ * that names a carried file counts)
45
70
  * @returns {{reached: Map<string, Reach>, missing: string[]}} the reached
46
71
  * tree paths, and the relative imports the file does not carry
47
72
  */
48
73
  export function reachableFiles(files: {
49
74
  path: string;
50
75
  base64: string;
51
- }[], { aliases }?: {
76
+ }[], { aliases, recorded }?: {
52
77
  aliases?: import("./ts-paths.mjs").PathPattern[];
78
+ recorded?: unknown;
53
79
  }): {
54
80
  reached: Map<string, Reach>;
55
81
  missing: string[];
@@ -65,4 +91,10 @@ export type Reach = {
65
91
  * import names for it, so it also goes there.
66
92
  */
67
93
  aliased: Set<string>;
94
+ /**
95
+ * - Alias imports that name it where no
96
+ * receiving-project alias does: the render recorded the file each named,
97
+ * so it goes where the page's layout puts it, and the page needs the alias.
98
+ */
99
+ unaliased: Set<string>;
68
100
  };
@@ -13,13 +13,33 @@
13
13
  * @position foundation/render — used by the render subject's adapter
14
14
  */
15
15
 
16
- import * as fs from 'node:fs';
17
16
  import * as path from 'node:path';
18
17
  import {babelParse as parse} from '../runtime/lazy-dependencies.mjs';
19
- import {PAGE_EXTENSIONS} from './embedded-files.mjs';
18
+ import {MODULE_EXTENSIONS} from './embedded-files.mjs';
20
19
  import postcss from 'postcss';
21
- import {matchPath, readPathsIn} from './ts-paths.mjs';
20
+ import {builtinModules} from 'node:module';
21
+ import {matchPath, pathsFor} from './ts-paths.mjs';
22
22
  import {isAssetPath} from './assets.mjs';
23
+ import {climbsOut} from '../fs/paths.mjs';
24
+
25
+ /** A name npm gives a package, scoped or not (older names may have capitals). */
26
+ const PACKAGE_NAME = /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9-][\w.-]*$/i;
27
+
28
+ /**
29
+ * Whether only a path alias can resolve an import: its name cannot be a
30
+ * package's, a Node built-in's, or a package's own subpath import
31
+ * (`@/components/Header` and `~/lib/data` cannot; `react`, `@acme/ui`, `fs`
32
+ * and `#utils`, which a package.json `imports` maps, can). A received file's
33
+ * record of alias imports counts only for these, so it can never remap a
34
+ * package, or the reader's own imports, for the reader.
35
+ * @param {string} spec
36
+ */
37
+ export function aliasOnly(spec) {
38
+ if (spec.startsWith('node:') || spec.startsWith('#')) return false;
39
+ const segments = spec.split('/');
40
+ const name = spec.startsWith('@') ? segments.slice(0, 2).join('/') : segments[0];
41
+ return !PACKAGE_NAME.test(name) && !builtinModules.includes(name);
42
+ }
23
43
 
24
44
  /**
25
45
  * What a stylesheet's `@import` rules load, read with postcss so comments
@@ -43,7 +63,7 @@ export function cssImports(css) {
43
63
  }
44
64
 
45
65
  /** Extensions an extensionless import may stand for, in resolution order. */
46
- const RESOLVE_EXTENSIONS = ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.json'];
66
+ const RESOLVE_EXTENSIONS = ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.mts', '.cts', '.cjs', '.json'];
47
67
 
48
68
  /**
49
69
  * The string specifiers one module imports.
@@ -71,6 +91,18 @@ export function assetRefsIn(text) {
71
91
  return out;
72
92
  }
73
93
 
94
+ /**
95
+ * The images, fonts and media a carried file names by a relative path: in a
96
+ * module's strings, or in a stylesheet. A render carries each one that
97
+ * exists, and {@link reachableFiles} expects each one back.
98
+ * @param {string} source
99
+ * @param {string} file its path; a `.css` file is read as a stylesheet
100
+ * @returns {string[]}
101
+ */
102
+ export function assetRefsOf(source, file) {
103
+ return /\.css$/i.test(file) ? assetRefsIn(source) : scanModule(source, file).assets;
104
+ }
105
+
74
106
  /**
75
107
  * One module's imports, and the relative asset paths its strings name
76
108
  * (`<img src="./logo.png">`, `url(./bg.png)` in a style).
@@ -132,22 +164,14 @@ function scanModule(source, file) {
132
164
  }
133
165
 
134
166
  /**
135
- * The path aliases (`compilerOptions.paths`) of the project that holds
136
- * `dir`, by TypeScript's rules (see ts-paths.mjs).
137
- * @param {string} dir
167
+ * The path aliases (`compilerOptions.paths`) that TypeScript reads for a page
168
+ * written at `file`, by its rules (see ts-paths.mjs). The file and its
169
+ * folders need not exist yet.
170
+ * @param {string} file absolute
138
171
  * @returns {import('./ts-paths.mjs').PathPattern[]}
139
172
  */
140
- export function receivingAliases(dir) {
141
- let d = dir;
142
- while (!fs.existsSync(d) && path.dirname(d) !== d) d = path.dirname(d);
143
- for (;;) {
144
- const found = readPathsIn(d);
145
- if (found) return found;
146
- if (fs.existsSync(path.join(d, 'package.json'))) return [];
147
- const up = path.dirname(d);
148
- if (up === d) return [];
149
- d = up;
150
- }
173
+ export function receivingAliases(file) {
174
+ return pathsFor(file);
151
175
  }
152
176
 
153
177
  /**
@@ -156,18 +180,23 @@ export function receivingAliases(dir) {
156
180
  * page), so it goes where the page's layout puts it.
157
181
  * @property {Set<string>} aliased - Absolute paths a receiving-project alias
158
182
  * import names for it, so it also goes there.
183
+ * @property {Set<string>} unaliased - Alias imports that name it where no
184
+ * receiving-project alias does: the render recorded the file each named,
185
+ * so it goes where the page's layout puts it, and the page needs the alias.
159
186
  */
160
187
 
161
188
  /**
162
189
  * The embedded files the page reaches through its imports.
163
190
  * @param {{path: string, base64: string}[]} files the embedded files, page
164
191
  * first; every path appears once (callers refuse duplicates first)
165
- * @param {{aliases?: import('./ts-paths.mjs').PathPattern[]}} [options] the
166
- * receiving project's path aliases (see receivingAliases)
192
+ * @param {{aliases?: import('./ts-paths.mjs').PathPattern[], recorded?: unknown}} [options]
193
+ * the receiving project's path aliases (see receivingAliases), and the
194
+ * alias imports the render recorded (an untrusted record: only an entry
195
+ * that names a carried file counts)
167
196
  * @returns {{reached: Map<string, Reach>, missing: string[]}} the reached
168
197
  * tree paths, and the relative imports the file does not carry
169
198
  */
170
- export function reachableFiles(files, {aliases = []} = {}) {
199
+ export function reachableFiles(files, {aliases = [], recorded} = {}) {
171
200
  const byPath = new Map(files.map(f => [f.path, f]));
172
201
  /** @type {Map<string, Reach>} */
173
202
  const reached = new Map();
@@ -203,7 +232,7 @@ export function reachableFiles(files, {aliases = []} = {}) {
203
232
  let r = reached.get(p);
204
233
  const fresh = !r;
205
234
  if (!r) {
206
- r = {relative: false, aliased: new Set()};
235
+ r = {relative: false, aliased: new Set(), unaliased: new Set()};
207
236
  reached.set(p, r);
208
237
  }
209
238
  return {r, fresh};
@@ -217,7 +246,7 @@ export function reachableFiles(files, {aliases = []} = {}) {
217
246
  while (queue.length > 0) {
218
247
  const current = /** @type {string} */ (queue.shift());
219
248
  const ext = path.posix.extname(current).toLowerCase();
220
- const isModule = PAGE_EXTENSIONS.includes(ext);
249
+ const isModule = MODULE_EXTENSIONS.includes(ext);
221
250
  if (!isModule && ext !== '.css') continue;
222
251
  const entry = byPath.get(current);
223
252
  if (!entry) continue;
@@ -225,7 +254,7 @@ export function reachableFiles(files, {aliases = []} = {}) {
225
254
  // Images and fonts a module or stylesheet names by a relative path are
226
255
  // part of the page too.
227
256
  const scanned = isModule
228
- ? scanModule(source, current)
257
+ ? {imports: importSpecifiers(source, current), assets: assetRefsOf(source, current)}
229
258
  : {
230
259
  // A stylesheet's own `@import`s count as imports.
231
260
  // A stylesheet's own relative `@import`s count as imports (read
@@ -237,11 +266,11 @@ export function reachableFiles(files, {aliases = []} = {}) {
237
266
  // carries one, else a package's.
238
267
  .filter(ref => ref.startsWith('.') || byPath.has(path.posix.normalize(path.posix.join(path.posix.dirname(current), ref))))
239
268
  .map(ref => (ref.startsWith('.') ? ref : `./${ref}`)),
240
- assets: assetRefsIn(source),
269
+ assets: assetRefsOf(source, current),
241
270
  };
242
271
  for (const ref of scanned.assets) {
243
272
  const joined = path.posix.normalize(path.posix.join(path.posix.dirname(current), ref));
244
- if (joined.startsWith('..')) continue;
273
+ if (climbsOut(joined)) continue;
245
274
  if (!byPath.has(joined)) {
246
275
  missing.add(joined);
247
276
  continue;
@@ -252,7 +281,7 @@ export function reachableFiles(files, {aliases = []} = {}) {
252
281
  const bare = spec.split('?')[0];
253
282
  if (bare.startsWith('./') || bare.startsWith('../')) {
254
283
  const joined = path.posix.normalize(path.posix.join(path.posix.dirname(current), bare));
255
- const target = joined.startsWith('..') ? null : resolveIn(joined);
284
+ const target = climbsOut(joined) ? null : resolveIn(joined);
256
285
  if (!target) {
257
286
  missing.add(joined);
258
287
  continue;
@@ -317,6 +346,16 @@ export function reachableFiles(files, {aliases = []} = {}) {
317
346
  r.aliased.add(chosen.abs);
318
347
  if (fresh) queue.push(chosen.hit.path);
319
348
  }
349
+ continue;
350
+ }
351
+ // No alias here names it, but the render recorded the carried file it
352
+ // named: that file comes back in the page's own layout.
353
+ const sent = aliasOnly(bare) && recorded && typeof recorded === 'object' && Object.hasOwn(recorded, bare) ? /** @type {Record<string, unknown>} */ (recorded)[bare] : undefined;
354
+ if (typeof sent === 'string' && byPath.has(sent)) {
355
+ const {r, fresh} = reach(sent);
356
+ r.relative = true;
357
+ r.unaliased.add(bare);
358
+ if (fresh) queue.push(sent);
320
359
  }
321
360
  }
322
361
  }
@@ -0,0 +1,66 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * @typedef {object} FileFacts
6
+ * @property {string | null} cli - The CLI version that rendered the file.
7
+ * @property {number} format - The render format of the embedded source.
8
+ * @property {string} file - The rendered file's name.
9
+ * @property {string} page - The page's path from its project's root; outside a project, its path among the files it carries.
10
+ * @property {string} restored - Where --reverse writes the page by default, from the rendered file's folder.
11
+ * @property {string[]} files - The embedded files, page first.
12
+ * @property {Record<string, string>} packages - The packages the page rendered with, by name: their versions.
13
+ * @property {string[]} install - What a render outside a project must install first, as name@version.
14
+ * @property {string} [title] - The title given with --title.
15
+ */
16
+ /**
17
+ * The note at the top of a rendered file.
18
+ * @param {FileFacts} facts
19
+ * @returns {string} an HTML comment on lines of its own
20
+ */
21
+ export function headerNote(facts: FileFacts): string;
22
+ /**
23
+ * The note after the embedded source.
24
+ * @param {Pick<FileFacts, 'cli' | 'format' | 'file'>} facts
25
+ * @returns {string} an HTML comment on one line
26
+ */
27
+ export function endNote(facts: Pick<FileFacts, "cli" | "format" | "file">): string;
28
+ export function cliCommand(version: string | null): string;
29
+ export type FileFacts = {
30
+ /**
31
+ * - The CLI version that rendered the file.
32
+ */
33
+ cli: string | null;
34
+ /**
35
+ * - The render format of the embedded source.
36
+ */
37
+ format: number;
38
+ /**
39
+ * - The rendered file's name.
40
+ */
41
+ file: string;
42
+ /**
43
+ * - The page's path from its project's root; outside a project, its path among the files it carries.
44
+ */
45
+ page: string;
46
+ /**
47
+ * - Where --reverse writes the page by default, from the rendered file's folder.
48
+ */
49
+ restored: string;
50
+ /**
51
+ * - The embedded files, page first.
52
+ */
53
+ files: string[];
54
+ /**
55
+ * - The packages the page rendered with, by name: their versions.
56
+ */
57
+ packages: Record<string, string>;
58
+ /**
59
+ * - What a render outside a project must install first, as name@version.
60
+ */
61
+ install: string[];
62
+ /**
63
+ * - The title given with --title.
64
+ */
65
+ title?: string | undefined;
66
+ };
@@ -0,0 +1,118 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {shellArg} from '../text/shell-arg.mjs';
4
+
5
+ /**
6
+ * @file The plain-text notes a rendered file carries for whoever opens it
7
+ * next, a person or an agent with no other context: what made the file, what
8
+ * it carries, and the exact commands that give the page back and render it
9
+ * again. The note at the top sits in <head> after the charset and generator
10
+ * metas, so browsers and older CLIs still find both in the first bytes. The
11
+ * short note at the end follows the embedded source, for a reader that starts
12
+ * at the end of the file.
13
+ *
14
+ * The notes never spell the opening tag of the embedded block: every CLI
15
+ * finds the block by that tag, and the last match wins.
16
+ *
17
+ * @position foundation/render — used by render-page.mjs
18
+ */
19
+
20
+ /**
21
+ * The command that runs one version of the CLI anywhere npm runs.
22
+ * @param {string | null} version
23
+ */
24
+ export const cliCommand = version => `npx @astryxdesign/cli${version ? `@${version}` : ''}`;
25
+
26
+
27
+ /**
28
+ * Text that cannot end or nest an HTML comment.
29
+ * @param {string} text
30
+ */
31
+ const commentSafe = text => text.replace(/--!?>/g, '- ->').replace(/<!--/g, '<!- -');
32
+
33
+ /** The most file names the note at the top lists. */
34
+ const MAX_LISTED = 24;
35
+
36
+ /**
37
+ * @typedef {object} FileFacts
38
+ * @property {string | null} cli - The CLI version that rendered the file.
39
+ * @property {number} format - The render format of the embedded source.
40
+ * @property {string} file - The rendered file's name.
41
+ * @property {string} page - The page's path from its project's root; outside a project, its path among the files it carries.
42
+ * @property {string} restored - Where --reverse writes the page by default, from the rendered file's folder.
43
+ * @property {string[]} files - The embedded files, page first.
44
+ * @property {Record<string, string>} packages - The packages the page rendered with, by name: their versions.
45
+ * @property {string[]} install - What a render outside a project must install first, as name@version.
46
+ * @property {string} [title] - The title given with --title.
47
+ */
48
+
49
+ /**
50
+ * The note at the top of a rendered file.
51
+ * @param {FileFacts} facts
52
+ * @returns {string} an HTML comment on lines of its own
53
+ */
54
+ export function headerNote(facts) {
55
+ const run = cliCommand(facts.cli);
56
+ const file = shellArg(facts.file);
57
+ const shown = facts.files.slice(0, MAX_LISTED).join(', ');
58
+ const more = facts.files.length > MAX_LISTED ? `, and ${facts.files.length - MAX_LISTED} more` : '';
59
+ const versions = Object.entries(facts.packages).map(([name, version]) => `${name} ${version}`);
60
+ const core = facts.packages['@astryxdesign/core'];
61
+ // A title with < or > stays out of the note, which other tools read as
62
+ // HTML; step 1 prints the command with it.
63
+ const quotable = facts.title !== undefined && !/[<>]/.test(facts.title);
64
+ const title = quotable ? ` --title ${shellArg(/** @type {string} */ (facts.title))}` : '';
65
+ const lines = [
66
+ `Rendered by Astryx: astryx experimental render, @astryxdesign/cli ${facts.cli ?? '(version unknown)'}, render format ${facts.format}.`,
67
+ 'This is one static file. It runs no script and loads nothing from the network.',
68
+ 'It also carries the source of the page, so the page can come back exactly.',
69
+ '',
70
+ `Page: ${facts.page}`,
71
+ `Carried files (${facts.files.length}): ${shown}${more}`,
72
+ ...(versions.length > 0 ? [`Rendered with: ${versions.join(', ')}`] : []),
73
+ '',
74
+ 'To change the page, change its source and render it again. Do not edit this HTML:',
75
+ 'the carried source does not get the edits you make here.',
76
+ 'Run these commands in the folder that holds this file:',
77
+ ` 1. Get the source back. This writes ${facts.restored} and the files it imports`,
78
+ ` (into ${facts.restored.split('/')[0]}-2/ and so on when that folder exists; the output names it):`,
79
+ ` ${run} experimental render --reverse ${file}`,
80
+ ' 2. Edit the restored files.',
81
+ ' 3. Render again. A render replaces a file that a render wrote. Step 1 prints this',
82
+ ' command with the folder it wrote:',
83
+ ` ${run} experimental render ${shellArg(facts.restored)} --out ${file}${title}`,
84
+ ...(facts.title !== undefined && !quotable ? [' The page was rendered with --title; step 1 prints the command with it.'] : []),
85
+ `If you have the project, edit ${facts.page} there instead, and render it in the same way.`,
86
+ "Inside a project, the project's own CLI answers these commands. A project CLI older than",
87
+ `${facts.cli ?? 'the one that rendered this file'} writes the page without this note; to keep the note, update that CLI first:`,
88
+ ` npm install --save-dev @astryxdesign/cli@${facts.cli ?? 'latest'}`,
89
+ ...(facts.install.length > 0
90
+ ? [
91
+ 'Outside a project, the CLI supplies Astryx, React and StyleX. Install the other packages first:',
92
+ ` npm install ${facts.install.join(' ')}`,
93
+ ]
94
+ : []),
95
+ ...(core
96
+ ? [
97
+ `The source was written for @astryxdesign/core ${core}. In a project on a newer Core, update the`,
98
+ "restored code from inside that project (the CLI hands this to the project's own CLI):",
99
+ ` ${cliCommand(null)} upgrade --from ${core} --path ${shellArg(facts.restored.split('/')[0])} --apply`,
100
+ ]
101
+ : []),
102
+ 'Later CLI versions read this file too.',
103
+ 'If someone edits this HTML after the render, step 1 still gives back the page as rendered,',
104
+ 'and it lists the text that changed, so you can make the same change in the source.',
105
+ 'The source is in the script block at the end of this file. Keep it: without it,',
106
+ 'step 1 can rebuild only the text and the layout from the markup.',
107
+ ];
108
+ return `<!--\n${lines.map(line => (line ? ` ${commentSafe(line)}` : '')).join('\n')}\n-->`.replace(/<(?=\/?script)/gi, '&lt;');
109
+ }
110
+
111
+ /**
112
+ * The note after the embedded source.
113
+ * @param {Pick<FileFacts, 'cli' | 'format' | 'file'>} facts
114
+ * @returns {string} an HTML comment on one line
115
+ */
116
+ export function endNote(facts) {
117
+ return `<!-- Astryx render: the block above is the source of the page (render format ${facts.format}), as JSON; each file is base64 with its SHA-256. Get it back: ${commentSafe(cliCommand(facts.cli))} experimental render --reverse ${commentSafe(shellArg(facts.file))} -->`;
118
+ }
@@ -0,0 +1,18 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * @param {{
6
+ * send: (message: unknown, done: (error: Error | null) => void) => unknown,
7
+ * exit: (code: number) => void,
8
+ * connected: () => boolean,
9
+ * record?: (phase: 'no-channel' | 'sending' | 'sent' | 'send-failed') => void,
10
+ * }} io
11
+ * @returns {(message: unknown) => void}
12
+ */
13
+ export function makeAnswer({ send, exit, connected, record }: {
14
+ send: (message: unknown, done: (error: Error | null) => void) => unknown;
15
+ exit: (code: number) => void;
16
+ connected: () => boolean;
17
+ record?: (phase: "no-channel" | "sending" | "sent" | "send-failed") => void;
18
+ }): (message: unknown) => void;
@@ -0,0 +1,46 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file The render host's one answer to the CLI. The host exits 0 only after
5
+ * the channel accepted the answer; a send that fails exits with its own code
6
+ * (HOST_EXIT.sendFailed), so a lost answer never reads as a clean exit. Each
7
+ * phase is recorded, so the CLI can tell "sent but not received" from "ended
8
+ * before it answered".
9
+ * @input send, exit, connected and record functions (process ones in the host)
10
+ * @output an answer(message) function that sends at most once
11
+ * @position foundation/render — used by page-host.mjs
12
+ */
13
+
14
+ import {HOST_EXIT} from './host-exit.mjs';
15
+
16
+ /**
17
+ * @param {{
18
+ * send: (message: unknown, done: (error: Error | null) => void) => unknown,
19
+ * exit: (code: number) => void,
20
+ * connected: () => boolean,
21
+ * record?: (phase: 'no-channel' | 'sending' | 'sent' | 'send-failed') => void,
22
+ * }} io
23
+ * @returns {(message: unknown) => void}
24
+ */
25
+ export function makeAnswer({send, exit, connected, record = () => {}}) {
26
+ let answered = false;
27
+ return message => {
28
+ if (answered) return;
29
+ answered = true;
30
+ if (!connected()) {
31
+ record('no-channel');
32
+ exit(HOST_EXIT.noChannel);
33
+ return;
34
+ }
35
+ record('sending');
36
+ try {
37
+ send(message, error => {
38
+ record(error ? 'send-failed' : 'sent');
39
+ exit(error ? HOST_EXIT.sendFailed : 0);
40
+ });
41
+ } catch {
42
+ record('send-failed');
43
+ exit(HOST_EXIT.sendFailed);
44
+ }
45
+ };
46
+ }
@@ -5,4 +5,5 @@ export namespace HOST_EXIT {
5
5
  let disconnected: number;
6
6
  let timeout: number;
7
7
  let noChannel: number;
8
+ let sendFailed: number;
8
9
  }
@@ -8,4 +8,9 @@
8
8
  */
9
9
 
10
10
  /** Exit codes for each way the host ends without sending an answer. */
11
- export const HOST_EXIT = {disconnected: 70, timeout: 71, noChannel: 72};
11
+ export const HOST_EXIT = {
12
+ disconnected: 70,
13
+ timeout: 71,
14
+ noChannel: 72,
15
+ sendFailed: 73,
16
+ };
@@ -1,6 +1,34 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * The tag whose name starts at `i`, read as a browser reads it: an attribute
6
+ * value is quoted or runs to a space or `>`, and a `/` just before `>` makes
7
+ * the tag self-closing.
8
+ * @param {string} html
9
+ * @param {number} i the first letter of the name
10
+ * @returns {{tag: string, attrs: Array<[string, string]>, selfClosing: boolean, end: number} | 'text' | 'open'}
11
+ * 'text' when the name is not a tag name, so the `<` is text; 'open' when
12
+ * no `>` ends the tag, so the rest of the document is text
13
+ */
14
+ export function readTag(html: string, i: number): {
15
+ tag: string;
16
+ attrs: Array<[string, string]>;
17
+ selfClosing: boolean;
18
+ end: number;
19
+ } | "text" | "open";
20
+ /**
21
+ * Split an HTML document into its pieces, in order, as a browser does for
22
+ * the markup a render writes. A comment ends at the first `-->` after its
23
+ * `<!--` (so `<!-->` and `<!--->` are whole comments), or at the end. The
24
+ * content of a raw-text element up to its end tag is one `raw` piece, so a
25
+ * tag or a comment in a stylesheet is text. A `<` that starts no tag is
26
+ * text, and a tag that no `>` ends makes the rest text. Each character is
27
+ * read a fixed number of times, so the time grows with the document's length.
28
+ * @param {string} html
29
+ * @returns {Generator<HtmlToken>}
30
+ */
31
+ export function scanHtml(html: string): Generator<HtmlToken>;
4
32
  /**
5
33
  * A small, forgiving HTML parser: enough for rendered markup.
6
34
  * @param {string} html
@@ -12,14 +40,18 @@ export function find(n: ElementNode, tag: string): ElementNode | undefined;
12
40
  /**
13
41
  * @file A small, forgiving HTML reader for `astryx experimental render
14
42
  * --reverse`: enough for rendered markup, plus the helpers that ask it which
15
- * Astryx component an element came from.
43
+ * Astryx component an element came from. Its scanner also finds the parts of
44
+ * a rendered file that a reverse compares.
16
45
  *
17
- * @position foundation/render — used by rebuild.mjs and the render subject
46
+ * @position foundation/render — used by rebuild.mjs, markup-edits.mjs,
47
+ * source-block.mjs and the render subject
18
48
  */
19
49
  /** @typedef {{tag: string, attrs: Record<string, string>, children: Node[]}} ElementNode */
20
50
  /** @typedef {ElementNode | {text: string}} Node */
21
51
  export const VOID: Set<string>;
22
52
  export function decode(s: string): string;
53
+ /** Elements whose content is raw text: a tag or a comment opener in it is text. */
54
+ export const RAW_TEXT: Set<string>;
23
55
  export function isEl(n: Node): n is ElementNode;
24
56
  /** Elements whose children React refuses or treats as a value. */
25
57
  export const FORM_TAGS: Set<string>;
@@ -35,3 +67,24 @@ export type ElementNode = {
35
67
  export type Node = ElementNode | {
36
68
  text: string;
37
69
  };
70
+ /**
71
+ * One piece of an HTML document, by its place in the text. `raw` is the
72
+ * content of a raw-text element.
73
+ */
74
+ export type HtmlToken = {
75
+ kind: "text" | "raw" | "comment" | "doctype";
76
+ start: number;
77
+ end: number;
78
+ } | {
79
+ kind: "end";
80
+ tag: string;
81
+ start: number;
82
+ end: number;
83
+ } | {
84
+ kind: "start";
85
+ tag: string;
86
+ attrs: Array<[string, string]>;
87
+ selfClosing: boolean;
88
+ start: number;
89
+ end: number;
90
+ };