@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
@@ -3,9 +3,11 @@
3
3
  /**
4
4
  * @file A small, forgiving HTML reader for `astryx experimental render
5
5
  * --reverse`: enough for rendered markup, plus the helpers that ask it which
6
- * Astryx component an element came from.
6
+ * Astryx component an element came from. Its scanner also finds the parts of
7
+ * a rendered file that a reverse compares.
7
8
  *
8
- * @position foundation/render — used by rebuild.mjs and the render subject
9
+ * @position foundation/render — used by rebuild.mjs, markup-edits.mjs,
10
+ * source-block.mjs and the render subject
9
11
  */
10
12
 
11
13
  /** @typedef {{tag: string, attrs: Record<string, string>, children: Node[]}} ElementNode */
@@ -27,6 +29,136 @@ export const decode = s =>
27
29
  .replace(/&nbsp;/g, '\u00a0')
28
30
  .replace(/&amp;/g, '&');
29
31
 
32
+ /** Elements whose content is raw text: a tag or a comment opener in it is text. */
33
+ export const RAW_TEXT = new Set(['script', 'style', 'textarea', 'title']);
34
+
35
+ /**
36
+ * One piece of an HTML document, by its place in the text. `raw` is the
37
+ * content of a raw-text element.
38
+ * @typedef {{kind: 'text' | 'raw' | 'comment' | 'doctype', start: number, end: number}
39
+ * | {kind: 'end', tag: string, start: number, end: number}
40
+ * | {kind: 'start', tag: string, attrs: Array<[string, string]>, selfClosing: boolean, start: number, end: number}} HtmlToken
41
+ */
42
+
43
+ const SPACE = /[\t\n\f\r ]/;
44
+ const LETTER = /[a-zA-Z]/;
45
+ const NAME_CHAR = /[\w:-]/;
46
+ const DOCTYPE = /<!doctype/iy;
47
+
48
+ /**
49
+ * The tag whose name starts at `i`, read as a browser reads it: an attribute
50
+ * value is quoted or runs to a space or `>`, and a `/` just before `>` makes
51
+ * the tag self-closing.
52
+ * @param {string} html
53
+ * @param {number} i the first letter of the name
54
+ * @returns {{tag: string, attrs: Array<[string, string]>, selfClosing: boolean, end: number} | 'text' | 'open'}
55
+ * 'text' when the name is not a tag name, so the `<` is text; 'open' when
56
+ * no `>` ends the tag, so the rest of the document is text
57
+ */
58
+ export function readTag(html, i) {
59
+ const n = html.length;
60
+ const nameStart = i;
61
+ while (i < n && NAME_CHAR.test(html[i])) i++;
62
+ if (i >= n || !(SPACE.test(html[i]) || html[i] === '/' || html[i] === '>')) return 'text';
63
+ const tag = html.slice(nameStart, i).toLowerCase();
64
+ /** @type {Array<[string, string]>} */
65
+ const attrs = [];
66
+ let selfClosing = false;
67
+ while (i < n && html[i] !== '>') {
68
+ if (SPACE.test(html[i])) {
69
+ i++;
70
+ continue;
71
+ }
72
+ if (html[i] === '/') {
73
+ selfClosing = html[i + 1] === '>';
74
+ i++;
75
+ continue;
76
+ }
77
+ const nameAt = i++;
78
+ while (i < n && !SPACE.test(html[i]) && html[i] !== '/' && html[i] !== '>' && html[i] !== '=') i++;
79
+ const name = html.slice(nameAt, i).toLowerCase();
80
+ let j = i;
81
+ while (j < n && SPACE.test(html[j])) j++;
82
+ let value = '';
83
+ if (html[j] === '=') {
84
+ j++;
85
+ while (j < n && SPACE.test(html[j])) j++;
86
+ const quote = html[j];
87
+ if (quote === '"' || quote === "'") {
88
+ const close = html.indexOf(quote, j + 1);
89
+ if (close < 0) return 'open';
90
+ value = html.slice(j + 1, close);
91
+ i = close + 1;
92
+ } else {
93
+ const from = j;
94
+ while (j < n && !SPACE.test(html[j]) && html[j] !== '>') j++;
95
+ value = html.slice(from, j);
96
+ i = j;
97
+ }
98
+ }
99
+ attrs.push([name, value]);
100
+ }
101
+ return i >= n ? 'open' : {tag, attrs, selfClosing, end: i + 1};
102
+ }
103
+
104
+ /**
105
+ * Split an HTML document into its pieces, in order, as a browser does for
106
+ * the markup a render writes. A comment ends at the first `-->` after its
107
+ * `<!--` (so `<!-->` and `<!--->` are whole comments), or at the end. The
108
+ * content of a raw-text element up to its end tag is one `raw` piece, so a
109
+ * tag or a comment in a stylesheet is text. A `<` that starts no tag is
110
+ * text, and a tag that no `>` ends makes the rest text. Each character is
111
+ * read a fixed number of times, so the time grows with the document's length.
112
+ * @param {string} html
113
+ * @returns {Generator<HtmlToken>}
114
+ */
115
+ export function* scanHtml(html) {
116
+ const n = html.length;
117
+ let at = 0;
118
+ let text = 0;
119
+ while (at < n) {
120
+ const lt = html.indexOf('<', at);
121
+ if (lt < 0) break;
122
+ const next = html[lt + 1] ?? '';
123
+ /** @type {HtmlToken | null} */
124
+ let token = null;
125
+ DOCTYPE.lastIndex = lt;
126
+ if (html.startsWith('<!--', lt)) {
127
+ const close = html.indexOf('-->', lt + 2);
128
+ token = {kind: 'comment', start: lt, end: close < 0 ? n : close + 3};
129
+ } else if (DOCTYPE.test(html)) {
130
+ const close = html.indexOf('>', lt);
131
+ if (close < 0) break;
132
+ token = {kind: 'doctype', start: lt, end: close + 1};
133
+ } else if (LETTER.test(next) || (next === '/' && LETTER.test(html[lt + 2] ?? ''))) {
134
+ const closing = next === '/';
135
+ const read = readTag(html, lt + (closing ? 2 : 1));
136
+ if (read === 'open') break;
137
+ if (read !== 'text') {
138
+ token = closing
139
+ ? {kind: 'end', tag: read.tag, start: lt, end: read.end}
140
+ : {kind: 'start', tag: read.tag, attrs: read.attrs, selfClosing: read.selfClosing, start: lt, end: read.end};
141
+ }
142
+ }
143
+ if (!token) {
144
+ at = lt + 1;
145
+ continue;
146
+ }
147
+ if (lt > text) yield {kind: 'text', start: text, end: lt};
148
+ yield token;
149
+ at = text = token.end;
150
+ // A self-closing raw-text element (an SVG `<title />`) holds nothing.
151
+ if (token.kind === 'start' && RAW_TEXT.has(token.tag) && !token.selfClosing) {
152
+ const closing = new RegExp(`</${token.tag}`, 'gi');
153
+ closing.lastIndex = at;
154
+ const stop = closing.exec(html)?.index ?? n;
155
+ yield {kind: 'raw', start: at, end: stop};
156
+ at = text = stop;
157
+ }
158
+ }
159
+ if (n > text) yield {kind: 'text', start: text, end: n};
160
+ }
161
+
30
162
  /**
31
163
  * A small, forgiving HTML parser: enough for rendered markup.
32
164
  * @param {string} html
@@ -37,36 +169,23 @@ export function parseHtml(html) {
37
169
  const root = {tag: '#root', attrs: {}, children: []};
38
170
  /** @type {ElementNode[]} */
39
171
  const stack = [root];
40
- const re = /<!--[\s\S]*?-->|<!doctype[^>]*>|<\/([a-zA-Z][\w:-]*)\s*>|<([a-zA-Z][\w:-]*)((?:\s+[^\s"'>/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]+))?)*)\s*(\/?)>|([^<]+|<)/gi;
41
- /** @type {RegExpExecArray | null} */
42
- let m;
43
- while ((m = re.exec(html))) {
172
+ for (const token of scanHtml(html)) {
44
173
  const top = stack[stack.length - 1];
45
- if (m[1]) {
46
- const tag = m[1].toLowerCase();
47
- const at = stack.map(n => n.tag).lastIndexOf(tag);
174
+ if (token.kind === 'text') {
175
+ top.children.push({text: decode(html.slice(token.start, token.end))});
176
+ } else if (token.kind === 'raw') {
177
+ top.children.push({text: html.slice(token.start, token.end)});
178
+ } else if (token.kind === 'end') {
179
+ const at = stack.map(n => n.tag).lastIndexOf(token.tag);
48
180
  if (at > 0) stack.length = at;
49
- } else if (m[2]) {
50
- const tag = m[2].toLowerCase();
181
+ } else if (token.kind === 'start') {
51
182
  /** @type {Record<string, string>} */
52
183
  const attrs = {};
53
- for (const a of (m[3] ?? '').matchAll(/([^\s"'>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+)))?/g)) {
54
- attrs[a[1].toLowerCase()] = decode(a[2] ?? a[3] ?? a[4] ?? '');
55
- }
184
+ for (const [name, value] of token.attrs) attrs[name] = decode(value);
56
185
  /** @type {ElementNode} */
57
- const node = {tag, attrs, children: []};
186
+ const node = {tag: token.tag, attrs, children: []};
58
187
  top.children.push(node);
59
- if (tag === 'script' || tag === 'style' || tag === 'textarea' || tag === 'title') {
60
- const end = html.toLowerCase().indexOf(`</${tag}`, re.lastIndex);
61
- const stop = end < 0 ? html.length : end;
62
- node.children.push({text: html.slice(re.lastIndex, stop)});
63
- re.lastIndex = stop;
64
- stack.push(node);
65
- } else if (!VOID.has(tag) && !m[4]) {
66
- stack.push(node);
67
- }
68
- } else if (m[5]) {
69
- top.children.push({text: decode(m[5])});
188
+ if (!token.selfClosing && (RAW_TEXT.has(token.tag) || !VOID.has(token.tag))) stack.push(node);
70
189
  }
71
190
  }
72
191
  return root;
@@ -0,0 +1,57 @@
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
+ * The text of rendered markup, as the runs a reader sees: each text node with
6
+ * its white space collapsed, empty ones left out, scripts and styles skipped.
7
+ * @param {string} markup
8
+ * @returns {string[]}
9
+ */
10
+ export function textRuns(markup: string): string[];
11
+ /**
12
+ * @typedef {object} TextEdit
13
+ * @property {string | null} was - The text as rendered; null for text added after the render.
14
+ * @property {string | null} now - The text the file holds now; null for text removed.
15
+ */
16
+ /**
17
+ * The runs of text that differ between the markup as rendered and the markup
18
+ * now, paired where one replaced another, whole (a caller that shows them
19
+ * cuts them with {@link clip}).
20
+ * @param {string[]} before
21
+ * @param {string[]} after
22
+ * @returns {{edits: TextEdit[], more: number}} at most MAX_EDITS changes, and how many more there are
23
+ */
24
+ export function textEdits(before: string[], after: string[]): {
25
+ edits: TextEdit[];
26
+ more: number;
27
+ };
28
+ /**
29
+ * Where a run of text sits in the restored source: the file and line where
30
+ * it starts, when it appears exactly once across the files. A run is text
31
+ * with its white space collapsed, and in source the same text may wrap
32
+ * across lines (JSX joins them with one space), so the run is found in each
33
+ * module's text collapsed the same way.
34
+ * @param {string} text a whole run of text
35
+ * @param {{file: string, text: string}[]} files the restored modules and JSON files
36
+ * @returns {{file: string, line: number} | null}
37
+ */
38
+ export function locate(text: string, files: {
39
+ file: string;
40
+ text: string;
41
+ }[]): {
42
+ file: string;
43
+ line: number;
44
+ } | null;
45
+ /** The most changes a reverse lists. */
46
+ export const MAX_EDITS: 50;
47
+ export function clip(text: string): string;
48
+ export type TextEdit = {
49
+ /**
50
+ * - The text as rendered; null for text added after the render.
51
+ */
52
+ was: string | null;
53
+ /**
54
+ * - The text the file holds now; null for text removed.
55
+ */
56
+ now: string | null;
57
+ };
@@ -0,0 +1,182 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file What changed in a rendered file's markup after the render, for
5
+ * `astryx experimental render --reverse`. A render records the text of its
6
+ * markup, in order; a reverse reads the text the file holds now and names
7
+ * each run of text that differs, with where the old text sits in the restored
8
+ * source when it appears there once. The restored source never takes these
9
+ * changes: it is the page as rendered.
10
+ *
11
+ * @position foundation/render — used by render-page.mjs and the render subject
12
+ */
13
+
14
+ import {decode, isEl, parseHtml} from './html-reader.mjs';
15
+
16
+ /** The most changes a reverse lists. */
17
+ export const MAX_EDITS = 50;
18
+
19
+ /** The longest piece of text a change shows. */
20
+ const MAX_TEXT = 300;
21
+
22
+ /** The largest table the text comparison builds before it gives up on detail. */
23
+ const MAX_CELLS = 4_000_000;
24
+
25
+ /**
26
+ * The text of rendered markup, as the runs a reader sees: each text node with
27
+ * its white space collapsed, empty ones left out, scripts and styles skipped.
28
+ * @param {string} markup
29
+ * @returns {string[]}
30
+ */
31
+ export function textRuns(markup) {
32
+ /** @type {string[]} */
33
+ const runs = [];
34
+ /** @param {import('./html-reader.mjs').Node} node @param {boolean} raw */
35
+ const walk = (node, raw) => {
36
+ if (!isEl(node)) {
37
+ const text = (raw ? decode(node.text) : node.text).replace(/\s+/g, ' ').trim();
38
+ if (text) runs.push(text);
39
+ return;
40
+ }
41
+ if (node.tag === 'script' || node.tag === 'style') return;
42
+ for (const child of node.children) walk(child, node.tag === 'textarea' || node.tag === 'title');
43
+ };
44
+ walk(parseHtml(markup), false);
45
+ return runs;
46
+ }
47
+
48
+ /**
49
+ * A piece of text as a change shows it: cut to MAX_TEXT characters.
50
+ * @param {string} text
51
+ */
52
+ export const clip = text => (text.length > MAX_TEXT ? `${text.slice(0, MAX_TEXT - 3)}...` : text);
53
+
54
+ /**
55
+ * @typedef {object} TextEdit
56
+ * @property {string | null} was - The text as rendered; null for text added after the render.
57
+ * @property {string | null} now - The text the file holds now; null for text removed.
58
+ */
59
+
60
+ /**
61
+ * The runs of text that differ between the markup as rendered and the markup
62
+ * now, paired where one replaced another, whole (a caller that shows them
63
+ * cuts them with {@link clip}).
64
+ * @param {string[]} before
65
+ * @param {string[]} after
66
+ * @returns {{edits: TextEdit[], more: number}} at most MAX_EDITS changes, and how many more there are
67
+ */
68
+ export function textEdits(before, after) {
69
+ let start = 0;
70
+ while (start < before.length && start < after.length && before[start] === after[start]) start++;
71
+ let endBefore = before.length;
72
+ let endAfter = after.length;
73
+ while (endBefore > start && endAfter > start && before[endBefore - 1] === after[endAfter - 1]) {
74
+ endBefore--;
75
+ endAfter--;
76
+ }
77
+ const a = before.slice(start, endBefore);
78
+ const b = after.slice(start, endAfter);
79
+ /** @type {{removed: string[], added: string[]}[]} */
80
+ const hunks = [];
81
+ if (a.length * b.length > MAX_CELLS) {
82
+ hunks.push({removed: a, added: b});
83
+ } else {
84
+ // Longest common subsequence over the changed middle; the common runs
85
+ // split it into hunks of removed and added text.
86
+ const width = b.length + 1;
87
+ const table = new Uint32Array((a.length + 1) * width);
88
+ for (let i = a.length - 1; i >= 0; i--) {
89
+ for (let j = b.length - 1; j >= 0; j--) {
90
+ table[i * width + j] =
91
+ a[i] === b[j] ? table[(i + 1) * width + j + 1] + 1 : Math.max(table[(i + 1) * width + j], table[i * width + j + 1]);
92
+ }
93
+ }
94
+ /** @type {{removed: string[], added: string[]}} */
95
+ let hunk = {removed: [], added: []};
96
+ const close = () => {
97
+ if (hunk.removed.length > 0 || hunk.added.length > 0) hunks.push(hunk);
98
+ hunk = {removed: [], added: []};
99
+ };
100
+ let i = 0;
101
+ let j = 0;
102
+ while (i < a.length || j < b.length) {
103
+ if (i < a.length && j < b.length && a[i] === b[j]) {
104
+ close();
105
+ i++;
106
+ j++;
107
+ } else if (j < b.length && (i === a.length || table[i * width + j + 1] >= table[(i + 1) * width + j])) {
108
+ hunk.added.push(b[j++]);
109
+ } else {
110
+ hunk.removed.push(a[i++]);
111
+ }
112
+ }
113
+ close();
114
+ }
115
+ /** @type {TextEdit[]} */
116
+ const all = [];
117
+ for (const {removed, added} of hunks) {
118
+ const pairs = Math.max(removed.length, added.length);
119
+ for (let k = 0; k < pairs; k++) {
120
+ all.push({
121
+ was: k < removed.length ? removed[k] : null,
122
+ now: k < added.length ? added[k] : null,
123
+ });
124
+ }
125
+ }
126
+ return {edits: all.slice(0, MAX_EDITS), more: Math.max(0, all.length - MAX_EDITS)};
127
+ }
128
+
129
+ /**
130
+ * A module's text with its white space collapsed the way a run of text's is,
131
+ * and the line of the source each of its characters comes from; kept per
132
+ * module, so every run is found in one pass over each.
133
+ * @type {WeakMap<{file: string, text: string}, {text: string, lines: number[]}>}
134
+ */
135
+ const collapsedModules = new WeakMap();
136
+
137
+ /** @param {{file: string, text: string}} module */
138
+ function collapsedOf(module) {
139
+ let found = collapsedModules.get(module);
140
+ if (!found) {
141
+ let text = '';
142
+ /** @type {number[]} */
143
+ const lines = [];
144
+ let line = 1;
145
+ for (const part of module.text.split(/(\s+)/)) {
146
+ if (part === '') continue;
147
+ const space = /^\s/.test(part);
148
+ text += space ? ' ' : part;
149
+ for (let i = 0; i < (space ? 1 : part.length); i++) lines.push(line);
150
+ line += part.split('\n').length - 1;
151
+ }
152
+ found = {text, lines};
153
+ collapsedModules.set(module, found);
154
+ }
155
+ return found;
156
+ }
157
+
158
+ /**
159
+ * Where a run of text sits in the restored source: the file and line where
160
+ * it starts, when it appears exactly once across the files. A run is text
161
+ * with its white space collapsed, and in source the same text may wrap
162
+ * across lines (JSX joins them with one space), so the run is found in each
163
+ * module's text collapsed the same way.
164
+ * @param {string} text a whole run of text
165
+ * @param {{file: string, text: string}[]} files the restored modules and JSON files
166
+ * @returns {{file: string, line: number} | null}
167
+ */
168
+ export function locate(text, files) {
169
+ if (!text) return null;
170
+ /** @type {{file: string, line: number} | null} */
171
+ let found = null;
172
+ for (const module of files) {
173
+ const collapsed = collapsedOf(module);
174
+ let at = collapsed.text.indexOf(text);
175
+ while (at >= 0) {
176
+ if (found) return null;
177
+ found = {file: module.file, line: collapsed.lines[at]};
178
+ at = collapsed.text.indexOf(text, at + 1);
179
+ }
180
+ }
181
+ return found;
182
+ }
@@ -14,30 +14,24 @@
14
14
  * wrote to stderr. Each way the host itself ends without an answer has its own
15
15
  * exit code (HOST_EXIT), so none of them reads as a clean exit.
16
16
  *
17
- * @input argv[2]: JSON {entry, root, served, withoutSegmenter, timeoutMs}
17
+ * @input argv[2]: JSON {entry, root, scope, served, withoutSegmenter, timeoutMs, stateFile}, where stateFile is a file in the CLI's per-run temporary folder
18
18
  * @output one IPC message: the worker's answer, or {hostError, stage}, or
19
- * {hostExit, reason, stage, elapsedMs, rssMb, freeMb, stderrTail}
19
+ * {hostExit, reason, stage, elapsedMs, rssMb, freeMb, stderrTail}; and its
20
+ * state in stateFile (stage, time, memory, and whether it sent its answer)
20
21
  * @position foundation/render — started by render-page.mjs
21
22
  */
22
23
 
24
+ import * as fs from 'node:fs';
23
25
  import * as os from 'node:os';
24
26
  import {Worker} from 'node:worker_threads';
25
27
  import {HOST_EXIT} from './host-exit.mjs';
28
+ import {makeAnswer} from './host-answer.mjs';
26
29
 
27
- /** @type {{entry: string, root: string, served: {dir: string, integrations: string[]} | null, withoutSegmenter: boolean, timeoutMs: number}} */
30
+ /** @type {{entry: string, root: string, scope: string, served: {dir: string, integrations: string[]} | null, withoutSegmenter: boolean, timeoutMs: number, stateFile?: string}} */
28
31
  const input = JSON.parse(process.argv[2] ?? '{}');
29
32
  const started = Date.now();
30
33
  let stage = 'starting';
31
34
  let stderrTail = '';
32
- let answered = false;
33
-
34
- /** @param {unknown} message */
35
- function answer(message) {
36
- if (answered) return;
37
- answered = true;
38
- if (!process.connected) process.exit(HOST_EXIT.noChannel);
39
- process.send?.(message, () => process.exit(0));
40
- }
41
35
 
42
36
  /** What the page was doing and what it had left, for an end without an answer. */
43
37
  function state() {
@@ -50,6 +44,28 @@ function state() {
50
44
  };
51
45
  }
52
46
 
47
+ /**
48
+ * The page's state in the CLI's per-run temporary folder, so that the CLI can
49
+ * say why when the host ends without an answer reaching it.
50
+ * @param {string} answered
51
+ */
52
+ function saveState(answered) {
53
+ if (!input.stateFile) return;
54
+ try {
55
+ fs.writeFileSync(input.stateFile, JSON.stringify({...state(), answered}));
56
+ } catch {
57
+ // The state file only explains a failure; a failed write never ends the render.
58
+ }
59
+ }
60
+
61
+ const answer = makeAnswer({
62
+ send: (message, done) => process.send?.(message, done),
63
+ exit: code => process.exit(code),
64
+ connected: () => process.connected === true,
65
+ record: saveState,
66
+ });
67
+
68
+ saveState('no');
53
69
  process.once('disconnect', () => process.exit(HOST_EXIT.disconnected));
54
70
  // A margin past the CLI's own limit, so the CLI reports the timeout first.
55
71
  setTimeout(() => {
@@ -79,6 +95,7 @@ worker.on('message', (/** @type {any} */ message) => {
79
95
  Object.keys(message).length === 1
80
96
  ) {
81
97
  stage = message.stage;
98
+ saveState('no');
82
99
  return;
83
100
  }
84
101
  answer(message);