@astryxdesign/cli 0.7.16 → 0.7.17-canary.g49a475f

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 (354) 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 +75 -0
  79. package/api/theme/build/build.mjs +243 -58
  80. package/api/theme/build/font-warning.d.mts +7 -0
  81. package/api/theme/build/font-warning.mjs +17 -0
  82. package/api/theme/theme.type.d.mts +10 -0
  83. package/api/theme/theme.type.mjs +7 -1
  84. package/api/theme-edit/_adapter.d.mts +63 -2
  85. package/api/theme-edit/_adapter.mjs +771 -57
  86. package/api/theme-edit/_check.d.mts +40 -22
  87. package/api/theme-edit/_check.mjs +2029 -336
  88. package/api/theme-edit/_color.d.mts +10 -0
  89. package/api/theme-edit/_color.mjs +49 -1
  90. package/api/theme-edit/_compiler.mjs +9 -0
  91. package/api/theme-edit/_context.d.mts +3 -3
  92. package/api/theme-edit/_context.mjs +111 -48
  93. package/api/theme-edit/_css.d.mts +14 -0
  94. package/api/theme-edit/_css.mjs +46 -1
  95. package/api/theme-edit/_edit.d.mts +18 -4
  96. package/api/theme-edit/_edit.mjs +1685 -155
  97. package/api/theme-edit/_how-commands.d.mts +65 -0
  98. package/api/theme-edit/_how-commands.mjs +633 -1
  99. package/api/theme-edit/_how-question.d.mts +84 -0
  100. package/api/theme-edit/_how-question.mjs +5124 -281
  101. package/api/theme-edit/_how.mjs +140 -29
  102. package/api/theme-edit/_marks.d.mts +31 -5
  103. package/api/theme-edit/_marks.mjs +57 -5
  104. package/api/theme-edit/_name-rule.d.mts +11 -0
  105. package/api/theme-edit/_name-rule.mjs +12 -0
  106. package/api/theme-edit/_normal.d.mts +257 -0
  107. package/api/theme-edit/_normal.mjs +1252 -0
  108. package/api/theme-edit/_palette.mjs +10 -4
  109. package/api/theme-edit/_parts.d.mts +10 -1
  110. package/api/theme-edit/_parts.mjs +179 -3
  111. package/api/theme-edit/_preview-app.d.mts +7 -1
  112. package/api/theme-edit/_preview-app.mjs +515 -148
  113. package/api/theme-edit/_preview.d.mts +100 -14
  114. package/api/theme-edit/_preview.mjs +549 -137
  115. package/api/theme-edit/_settings.d.mts +347 -30
  116. package/api/theme-edit/_settings.mjs +2971 -327
  117. package/api/theme-edit/_tables.d.mts +6 -0
  118. package/api/theme-edit/_tables.mjs +44 -1
  119. package/api/theme-edit/_vet.d.mts +18 -0
  120. package/api/theme-edit/_vet.mjs +32 -0
  121. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  122. package/api/theme-edit/theme-edit.type.mjs +4 -1
  123. package/api/theme-edit/themeEditHow.doc.mjs +1 -1
  124. package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
  125. package/api/theme-edit/themeEditNew.doc.mjs +7 -4
  126. package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
  127. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
  128. package/api/upgrade/run/run.mjs +4 -3
  129. package/assets/codemods/integration-discovery.mjs +2 -1
  130. package/assets/codemods/run-codemod.mjs +87 -7
  131. package/assets/codemods/transforms/next/index.mjs +11 -1
  132. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  133. package/assets/component-list.generated.json +1 -0
  134. package/assets/docs/author-a-theme.doc.mjs +1 -0
  135. package/assets/docs/theme.doc.dense.mjs +2 -2
  136. package/assets/docs/theme.doc.mjs +1 -1
  137. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  138. package/assets/docs/tree/checks.doc.mjs +1 -1
  139. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  140. package/assets/docs/tree/render-pages.doc.mjs +44 -3
  141. package/assets/docs/tree/single-component.doc.mjs +4 -0
  142. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  143. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  144. package/assets/docs/use-a-theme.doc.mjs +1 -1
  145. package/assets/docs.generated.json +2 -2
  146. package/assets/search-catalog.generated.json +2 -0
  147. package/assets/self-audit.generated.json +1 -1
  148. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  149. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  150. package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
  151. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  152. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  153. package/assets/templates/components.generated.json +1 -1
  154. package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
  155. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
  156. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  157. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  158. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  159. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  160. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  161. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  162. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  163. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  164. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  165. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  166. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  167. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  168. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  169. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  170. package/assets/templates/pages/editor/template.doc.mjs +2 -8
  171. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  172. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  173. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  174. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  175. package/assets/templates/pages/ide/page.tsx +24 -2
  176. package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
  177. package/assets/templates/pages/library/template.doc.mjs +4 -1
  178. package/assets/templates/pages/login/template.doc.mjs +2 -1
  179. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  180. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  181. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  182. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  183. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  184. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  185. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  186. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  187. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  188. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  189. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  190. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  191. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  192. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  193. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  194. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  195. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
  196. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  197. package/assets/theme.template.ts +6 -0
  198. package/authoring/debug/parse.d.mts +3 -3
  199. package/authoring/doctypes/_schema.d.mts +3 -3
  200. package/authoring/doctypes/command/command.doc.mjs +1 -1
  201. package/authoring/doctypes/component/categories.d.mts +37 -0
  202. package/authoring/doctypes/component/categories.mjs +54 -0
  203. package/authoring/doctypes/template/template.doc.mjs +1 -1
  204. package/authoring/doctypes/template/type.ts +9 -0
  205. package/authoring/example/example.doc.d.mts +12 -0
  206. package/authoring/example/example.doc.mjs +69 -0
  207. package/authoring/example/preview.d.mts +92 -0
  208. package/authoring/example/preview.mjs +994 -0
  209. package/authoring/example/type.ts +102 -0
  210. package/authoring/index.d.mts +1 -0
  211. package/authoring/index.d.ts +12 -0
  212. package/authoring/index.mjs +3 -1
  213. package/clients/cli/bin/astryx.mjs +6 -9
  214. package/clients/cli/build-id.generated.json +1 -1
  215. package/clients/cli/commands/component.doc.mjs +1 -1
  216. package/clients/cli/commands/component.mjs +22 -3
  217. package/clients/cli/commands/docs.doc.mjs +7 -1
  218. package/clients/cli/commands/docs.mjs +3 -1
  219. package/clients/cli/commands/doctor.mjs +32 -14
  220. package/clients/cli/commands/experimental/render.mjs +42 -1
  221. package/clients/cli/commands/experimental/theme.mjs +163 -28
  222. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  223. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  224. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
  225. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
  226. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
  227. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  228. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  229. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  230. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  231. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  232. package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
  233. package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
  234. package/clients/cli/commands/search.doc.mjs +2 -1
  235. package/clients/cli/commands/search.mjs +6 -1
  236. package/clients/cli/commands/template.mjs +4 -2
  237. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  238. package/clients/cli/commands/theme.doc.mjs +1 -1
  239. package/clients/cli/commands/theme.mjs +209 -8
  240. package/clients/cli/commands/upgrade.mjs +42 -7
  241. package/clients/cli/index.mjs +1 -1
  242. package/clients/cli/lib/cli-error.mjs +2 -1
  243. package/clients/cli/lib/component-format.mjs +205 -98
  244. package/clients/cli/lib/hook-format.mjs +9 -19
  245. package/clients/cli/lib/json-shim.mjs +77 -21
  246. package/clients/cli/lib/manifest.mjs +3 -2
  247. package/clients/cli/manifest.generated.json +1 -1
  248. package/foundation/agent-docs/agent-docs.mjs +1 -1
  249. package/foundation/config/theme-state.d.mts +13 -1
  250. package/foundation/config/theme-state.mjs +47 -7
  251. package/foundation/discovery/authoring-self-docs.mjs +1 -0
  252. package/foundation/discovery/component-discovery.d.mts +11 -0
  253. package/foundation/discovery/component-discovery.mjs +56 -8
  254. package/foundation/discovery/component-replacement.mjs +130 -1
  255. package/foundation/discovery/copied-passages.mjs +2 -1
  256. package/foundation/discovery/doc-types.mjs +4 -3
  257. package/foundation/discovery/entry-name-files.d.mts +43 -0
  258. package/foundation/discovery/entry-name-files.mjs +264 -0
  259. package/foundation/discovery/hook-discovery.d.mts +8 -2
  260. package/foundation/discovery/hook-discovery.mjs +22 -8
  261. package/foundation/discovery/icon-definition-discovery.mjs +2 -1
  262. package/foundation/discovery/icon-set-checks.mjs +2 -1
  263. package/foundation/discovery/icon-set-discovery.mjs +2 -1
  264. package/foundation/discovery/integration-doc-files.mjs +2 -1
  265. package/foundation/discovery/package-exports.d.mts +10 -0
  266. package/foundation/discovery/package-exports.mjs +56 -3
  267. package/foundation/discovery/prop-drift.mjs +9 -9
  268. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  269. package/foundation/discovery/runner-allowlist.mjs +2 -0
  270. package/foundation/discovery/stored-component-list.d.mts +43 -0
  271. package/foundation/discovery/stored-component-list.mjs +90 -0
  272. package/foundation/discovery/stored-search-catalog.d.mts +115 -0
  273. package/foundation/discovery/stored-search-catalog.mjs +297 -0
  274. package/foundation/discovery/stored-self-audit.d.mts +26 -10
  275. package/foundation/discovery/stored-self-audit.mjs +38 -18
  276. package/foundation/discovery/template-adapter.d.mts +52 -0
  277. package/foundation/discovery/template-adapter.mjs +176 -12
  278. package/foundation/discovery/template-icons.mjs +2 -1
  279. package/foundation/discovery/theme-discovery.mjs +3 -2
  280. package/foundation/discovery/theme-imports.d.mts +14 -0
  281. package/foundation/discovery/theme-imports.mjs +43 -1
  282. package/foundation/discovery/theming-targets.mjs +3 -2
  283. package/foundation/doc-compiler/import.mjs +7 -1
  284. package/foundation/doc-compiler/inputs.mjs +3 -2
  285. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  286. package/foundation/doc-compiler/stored-docs.d.mts +22 -0
  287. package/foundation/doc-compiler/stored-docs.mjs +49 -0
  288. package/foundation/env/semver.mjs +3 -1
  289. package/foundation/fonts/font-stylesheet.d.mts +31 -0
  290. package/foundation/fonts/font-stylesheet.mjs +115 -0
  291. package/foundation/fs/cache-eviction.d.mts +21 -0
  292. package/foundation/fs/cache-eviction.mjs +73 -0
  293. package/foundation/fs/file-protection.mjs +4 -3
  294. package/foundation/fs/gather-cache.d.mts +25 -4
  295. package/foundation/fs/gather-cache.mjs +164 -55
  296. package/foundation/fs/jiti-cache.d.mts +19 -1
  297. package/foundation/fs/jiti-cache.mjs +130 -6
  298. package/foundation/fs/kept-tree.d.mts +60 -0
  299. package/foundation/fs/kept-tree.mjs +154 -0
  300. package/foundation/fs/listing-cache.d.mts +7 -0
  301. package/foundation/fs/listing-cache.mjs +10 -0
  302. package/foundation/fs/module-loader.d.mts +24 -2
  303. package/foundation/fs/module-loader.mjs +94 -21
  304. package/foundation/fs/paths.d.mts +18 -0
  305. package/foundation/fs/paths.mjs +15 -2
  306. package/foundation/identity/provider-identity.d.mts +6 -0
  307. package/foundation/identity/provider-identity.mjs +10 -1
  308. package/foundation/integrations/contribution-inventory.mjs +4 -3
  309. package/foundation/integrations/example-code.d.mts +63 -0
  310. package/foundation/integrations/example-code.mjs +416 -0
  311. package/foundation/integrations/public-imports.d.mts +9 -0
  312. package/foundation/integrations/public-imports.mjs +3 -2
  313. package/foundation/integrations/validate-contributions.mjs +17 -45
  314. package/foundation/render/embedded-files.d.mts +6 -0
  315. package/foundation/render/embedded-files.mjs +25 -5
  316. package/foundation/render/embedded-imports.d.mts +39 -7
  317. package/foundation/render/embedded-imports.mjs +66 -27
  318. package/foundation/render/file-header.d.mts +66 -0
  319. package/foundation/render/file-header.mjs +118 -0
  320. package/foundation/render/host-answer.d.mts +18 -0
  321. package/foundation/render/host-answer.mjs +46 -0
  322. package/foundation/render/host-exit.d.mts +1 -0
  323. package/foundation/render/host-exit.mjs +6 -1
  324. package/foundation/render/html-reader.d.mts +55 -2
  325. package/foundation/render/html-reader.mjs +145 -26
  326. package/foundation/render/markup-edits.d.mts +57 -0
  327. package/foundation/render/markup-edits.mjs +182 -0
  328. package/foundation/render/page-host.mjs +29 -12
  329. package/foundation/render/page-worker.mjs +121 -13
  330. package/foundation/render/picture-chrome.d.mts +4 -0
  331. package/foundation/render/picture-chrome.mjs +185 -0
  332. package/foundation/render/picture-playwright.d.mts +4 -0
  333. package/foundation/render/picture-playwright.mjs +34 -0
  334. package/foundation/render/rebuild.mjs +2 -1
  335. package/foundation/render/render-page.d.mts +35 -3
  336. package/foundation/render/render-page.mjs +316 -42
  337. package/foundation/render/source-block.d.mts +85 -6
  338. package/foundation/render/source-block.mjs +211 -20
  339. package/foundation/render/ts-paths.d.mts +69 -6
  340. package/foundation/render/ts-paths.mjs +326 -40
  341. package/foundation/response/error-codes.d.mts +3 -1
  342. package/foundation/response/error-codes.d.ts +1 -0
  343. package/foundation/response/error-codes.doc.mjs +12 -1
  344. package/foundation/response/error-codes.mjs +11 -1
  345. package/foundation/response/response-types.doc.mjs +2 -2
  346. package/foundation/text/compare-text.d.mts +14 -0
  347. package/foundation/text/compare-text.mjs +68 -0
  348. package/foundation/text/string-utils.d.mts +3 -2
  349. package/foundation/text/string-utils.mjs +18 -4
  350. package/foundation/text/suggest-order.d.mts +9 -0
  351. package/foundation/text/suggest-order.mjs +15 -1
  352. package/foundation/xle/expand.mjs +2 -1
  353. package/host/index.mjs +8 -6
  354. package/package.json +7 -6
@@ -17,22 +17,28 @@
17
17
  */
18
18
 
19
19
  import * as fs from 'node:fs';
20
+ import * as os from 'node:os';
20
21
  import * as path from 'node:path';
21
22
  import {fork, spawnSync} from 'node:child_process';
23
+ import {builtinModules} from 'node:module';
22
24
  import {fileURLToPath} from 'node:url';
23
25
  import postcss from 'postcss';
24
- import {assetDataUri, isAssetBytes, isAssetPath, RenderAssetError} from './assets.mjs';
26
+ import {assetDataUri, isAssetBytes, isAssetPath, MAX_ASSET_BYTES, RenderAssetError} from './assets.mjs';
25
27
  import {classesIn, cutCss, layerOrderOf} from './css-cut.mjs';
26
- import {sourceBlock} from './source-block.mjs';
28
+ import {asParsed, formatFor, sha256, sourceBlock} from './source-block.mjs';
27
29
  import {embeddedPathProblem} from './embedded-files.mjs';
28
- import {resolveServed} from './served-packages.mjs';
30
+ import {aliasOnly, assetRefsOf} from './embedded-imports.mjs';
31
+ import {isServedPackage, resolveServed} from './served-packages.mjs';
29
32
  import {CHART_CSS} from './charts.mjs';
30
33
  import {HOST_EXIT} from './host-exit.mjs';
34
+ import {endNote, headerNote} from './file-header.mjs';
35
+ import {textRuns} from './markup-edits.mjs';
36
+ import {findNodeModulesPackage, isInside} from '../fs/paths.mjs';
31
37
 
32
38
  /** How long one page may take to render before it is stopped. */
33
39
  export const RENDER_TIMEOUT_MS = 60_000;
34
40
 
35
- export {PAGE_EXTENSIONS} from './embedded-files.mjs';
41
+ export {MODULE_EXTENSIONS, PAGE_EXTENSIONS} from './embedded-files.mjs';
36
42
 
37
43
  /**
38
44
  * @typedef {object} RenderWarning
@@ -68,19 +74,59 @@ export class RenderError extends Error {
68
74
  }
69
75
 
70
76
  /**
71
- * The nearest folder at or above `dir` with a package.json, else `dir`.
77
+ * The nearest folder at or above `dir` with a package.json, or null outside
78
+ * a project.
72
79
  * @param {string} dir
80
+ * @returns {string | null}
73
81
  */
74
- function projectRootOf(dir) {
75
- let d = dir;
76
- for (;;) {
82
+ function projectOf(dir) {
83
+ for (let d = dir; ; d = path.dirname(d)) {
77
84
  if (fs.existsSync(path.join(d, 'package.json'))) return d;
78
- const up = path.dirname(d);
79
- if (up === d) return dir;
80
- d = up;
85
+ if (path.dirname(d) === d) return null;
81
86
  }
82
87
  }
83
88
 
89
+ /**
90
+ * Whether a path names a file. A name the system cannot look up (a segment
91
+ * too long, a folder it may not read) names none.
92
+ * @param {string} file
93
+ */
94
+ function isFileAt(file) {
95
+ try {
96
+ return fs.statSync(file).isFile();
97
+ } catch {
98
+ return false;
99
+ }
100
+ }
101
+
102
+ /**
103
+ * The first bytes of a file, enough to tell its format.
104
+ * @param {string} file
105
+ */
106
+ function headOf(file) {
107
+ const fd = fs.openSync(file, 'r');
108
+ try {
109
+ const head = Buffer.alloc(4096);
110
+ return head.subarray(0, fs.readSync(fd, head, 0, head.length, 0));
111
+ } finally {
112
+ fs.closeSync(fd);
113
+ }
114
+ }
115
+
116
+ /**
117
+ * The folder whose modules the page carries: its project's. Outside a
118
+ * project, the current folder when it holds the page, so a page with
119
+ * neighbours above its own folder (as a restore lays them out) carries them;
120
+ * else the page's folder.
121
+ * @param {string} dir
122
+ * @param {string} [cwd]
123
+ */
124
+ function carryScopeOf(dir, cwd) {
125
+ const project = projectOf(dir);
126
+ if (project) return project;
127
+ return cwd && (dir === cwd || isInside(dir, cwd)) ? cwd : dir;
128
+ }
129
+
84
130
  /** @param {string} s */
85
131
  const escapeHtml = s =>
86
132
  s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
@@ -305,24 +351,61 @@ function hostEndError(/** @type {number | null} */ code) {
305
351
  if (code === HOST_EXIT.timeout) {
306
352
  return new RenderError('ERR_RENDER_TIMEOUT', "The page's process stopped at its own time limit before this process read an answer.", {reason: 'host-timeout', exit: code});
307
353
  }
354
+ if (code === HOST_EXIT.sendFailed) {
355
+ return new RenderError('ERR_RENDER_FAILED', "The page's process could not send its answer to this process.", {reason: 'send-failed', exit: code});
356
+ }
308
357
  return new RenderError('ERR_RENDER_FAILED', `The page's process ended without an answer (exit ${code}).`, {reason: 'host-ended', exit: code});
309
358
  }
310
359
 
360
+ /**
361
+ * The error for a host that ended with no answer reaching this process, from
362
+ * the state it left in its per-run file: an answer it sent that never
363
+ * arrived, or the stage it ended in.
364
+ * @param {number | null} code
365
+ * @param {string | undefined} stateFile
366
+ */
367
+ function noMessageError(code, stateFile) {
368
+ if (code !== 0 && code !== null && Object.values(HOST_EXIT).includes(code)) return hostEndError(code);
369
+ /** @type {any} */
370
+ let saved = null;
371
+ try {
372
+ saved = stateFile ? JSON.parse(fs.readFileSync(stateFile, 'utf8')) : null;
373
+ } catch {
374
+ // No readable state: fall back to the bare message below.
375
+ }
376
+ if (!saved) return hostEndError(code);
377
+ const detail = {exit: code, stage: saved.stage, elapsedMs: saved.elapsedMs, rssMb: saved.rssMb, freeMb: saved.freeMb, ...(saved.stderrTail ? {stderrTail: saved.stderrTail} : {})};
378
+ if (saved.answered === 'sent') {
379
+ return new RenderError('ERR_RENDER_FAILED', `The page's process sent its answer, but this process did not receive it (exit ${code}).`, {reason: 'answer-lost', ...detail});
380
+ }
381
+ if (saved.answered === 'sending') {
382
+ return new RenderError('ERR_RENDER_FAILED', `The page's process ended while it sent its answer (exit ${code}).`, {reason: 'ended-while-sending', ...detail});
383
+ }
384
+ const seconds = Math.round((saved.elapsedMs ?? 0) / 1000);
385
+ const last = saved.stderrTail ? ` Its last output: ${String(saved.stderrTail).split('\n').at(-1)}` : '';
386
+ return new RenderError(
387
+ 'ERR_RENDER_FAILED',
388
+ `The page's process ended without an answer (exit ${code}) while ${saved.stage}, after ${seconds} seconds, with ${saved.freeMb} MB of memory free.${last}`,
389
+ {reason: 'host-ended', ...detail},
390
+ );
391
+ }
392
+
311
393
  /**
312
394
  * Run the page in a host process (page-host.mjs), stopping it after
313
395
  * `timeoutMs`. The host runs the page in a worker thread, and it exits when
314
396
  * this process goes away.
315
- * @param {{entry: string, root: string, served: ServedSet | null, withoutSegmenter: boolean}} input
397
+ * @param {{entry: string, root: string, scope: string, served: ServedSet | null, withoutSegmenter: boolean}} input
316
398
  * @param {number} timeoutMs
317
399
  * @returns {Promise<any>} the page's answer, or `{crashed: how}` when a
318
400
  * native crash ended the host
319
401
  */
320
402
  function runWorker(input, timeoutMs) {
321
- return new Promise((resolve, reject) => {
403
+ return withHostStateFile(stateFile => {
322
404
  const data = {
323
405
  ...input,
324
406
  served: input.served ? {dir: input.served.dir, integrations: [...input.served.integrations]} : null,
325
407
  timeoutMs,
408
+ stateFile,
326
409
  };
327
410
  const host = fork(fileURLToPath(new URL('./page-host.mjs', import.meta.url)), [JSON.stringify(data)], {
328
411
  // Never the CLI's own flags (such as --input-type).
@@ -330,6 +413,52 @@ function runWorker(input, timeoutMs) {
330
413
  stdio: ['ignore', 'ignore', 'ignore', 'ipc'],
331
414
  serialization: 'advanced',
332
415
  });
416
+ return awaitHost(host, {timeoutMs, withoutSegmenter: input.withoutSegmenter, stateFile});
417
+ });
418
+ }
419
+
420
+ /**
421
+ * Run `use` with a state file for one host in a new folder under the system's
422
+ * temporary folder, never in the project, and remove the folder after. The
423
+ * state file only explains a failure: without a temporary folder, `use` gets
424
+ * none and the render runs without it.
425
+ * @template T
426
+ * @param {(stateFile: string | undefined) => Promise<T>} use
427
+ * @param {{makeTempDir?: (prefix: string) => string}} [options]
428
+ * @returns {Promise<T>}
429
+ */
430
+ export async function withHostStateFile(
431
+ use,
432
+ {makeTempDir = prefix => fs.mkdtempSync(prefix)} = {},
433
+ ) {
434
+ /** @type {string} */
435
+ let dir;
436
+ try {
437
+ dir = makeTempDir(path.join(os.tmpdir(), 'astryx-render-'));
438
+ } catch {
439
+ // No temporary folder (missing or read-only): render without the state file.
440
+ return use(undefined);
441
+ }
442
+ try {
443
+ return await use(path.join(dir, 'host-state.json'));
444
+ } finally {
445
+ try {
446
+ fs.rmSync(dir, {recursive: true, force: true, maxRetries: 3});
447
+ } catch {
448
+ // Best effort: a removal that fails (a file still held open) never
449
+ // replaces the render's own result.
450
+ }
451
+ }
452
+ }
453
+
454
+ /**
455
+ * The page's answer from its host process, or the reason it has none.
456
+ * @param {import('node:child_process').ChildProcess} host
457
+ * @param {{timeoutMs: number, withoutSegmenter: boolean, stateFile?: string}} options
458
+ * @returns {Promise<any>}
459
+ */
460
+ export function awaitHost(host, {timeoutMs, withoutSegmenter, stateFile}) {
461
+ return new Promise((resolve, reject) => {
333
462
  let settled = false;
334
463
  /** @param {() => void} settle */
335
464
  const finish = settle => {
@@ -369,12 +498,14 @@ function runWorker(input, timeoutMs) {
369
498
  host.once('error', error => {
370
499
  finish(() => reject(new RenderError('ERR_RENDER_FAILED', `The page could not be rendered: ${String(error?.message ?? error).split('\n')[0]}`)));
371
500
  });
372
- host.once('exit', (code, signal) => {
501
+ // 'close' comes after the IPC channel drains, so an answer the host sent
502
+ // just before it exited still wins; 'exit' can come first under load.
503
+ host.once('close', (code, signal) => {
373
504
  finish(() => {
374
505
  const crash = crashOf(code, signal);
375
506
  if (crash) resolve({crashed: crash});
376
- else if (signal) reject(crashError(signal, {crashed: false, withoutSegmenter: input.withoutSegmenter}));
377
- else reject(hostEndError(code));
507
+ else if (signal) reject(crashError(signal, {crashed: false, withoutSegmenter}));
508
+ else reject(noMessageError(code, stateFile));
378
509
  });
379
510
  });
380
511
  });
@@ -383,7 +514,7 @@ function runWorker(input, timeoutMs) {
383
514
  /**
384
515
  * Run the page. When this Node crashes in Intl.Segmenter, run it once more
385
516
  * without Intl.Segmenter and say so in a warning.
386
- * @param {{entry: string, root: string, served: ServedSet | null}} input
517
+ * @param {{entry: string, root: string, scope: string, served: ServedSet | null}} input
387
518
  * @param {number} timeoutMs
388
519
  * @param {RenderWarning[]} warnings
389
520
  */
@@ -484,6 +615,26 @@ function inlineAssets(text, kind, ctx) {
484
615
  });
485
616
  }
486
617
 
618
+ /**
619
+ * The version of a package the page rendered with: the package set's copy
620
+ * when the page took it from there, else the copy Node's resolver finds from
621
+ * the page's folder.
622
+ * @param {string} name
623
+ * @param {string} dir the page's folder
624
+ * @param {Map<string, string>} setDirs the packages the page took from the package set: their folders
625
+ * @returns {string | null}
626
+ */
627
+ function installedVersion(name, dir, setDirs) {
628
+ const packageDir = setDirs.get(name) ?? findNodeModulesPackage(dir, name)?.packageDir;
629
+ if (!packageDir) return null;
630
+ try {
631
+ const pkg = JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8'));
632
+ return pkg?.name === name && typeof pkg.version === 'string' ? pkg.version : null;
633
+ } catch {
634
+ return null;
635
+ }
636
+ }
637
+
487
638
  /** The light and dark switch every rendered page carries. */
488
639
  const SCHEME_CSS =
489
640
  ':root{color-scheme:light dark}:root[data-theme="light"]{color-scheme:light}:root[data-theme="dark"]{color-scheme:dark}';
@@ -491,18 +642,27 @@ const SCHEME_CSS =
491
642
  /**
492
643
  * Render a page module to one self-contained HTML file.
493
644
  * @param {string} entry absolute path of the page module
494
- * @param {{title?: string, timeoutMs?: number, version?: string, served?: ServedSet | null}} [options]
645
+ * @param {{title?: string, timeoutMs?: number, version?: string, served?: ServedSet | null, output?: string, cwd?: string}} [options]
495
646
  * `served`: the Core of the package set the CLI runs from, for the packages
496
- * the page's folder has no copy of
647
+ * the page's folder has no copy of; `output`: the file the HTML goes to;
648
+ * `cwd`: the current folder, whose files are the page's own outside a
649
+ * project.
650
+ * With `output`, the file describes itself: notes at its top and end name
651
+ * what made it and the commands that give the page back and render it
652
+ * again, and its embedded source records the CLI version, the packages
653
+ * the page rendered with, and the markup as rendered.
497
654
  * @returns {Promise<RenderedPage>}
498
655
  */
499
656
  export async function renderPage(entry, options = {}) {
500
657
  const dir = path.dirname(entry);
501
- const root = projectRootOf(dir);
658
+ // The project's folder, else the page's: where its tsconfig.json and
659
+ // public/ images are read.
660
+ const root = projectOf(dir) ?? dir;
661
+ const scope = carryScopeOf(dir, options.cwd);
502
662
  const served = options.served ?? null;
503
663
  /** @type {RenderWarning[]} */
504
664
  const warnings = [];
505
- const message = await runPage({entry, root, served}, options.timeoutMs ?? RENDER_TIMEOUT_MS, warnings);
665
+ const message = await runPage({entry, root, scope, served}, options.timeoutMs ?? RENDER_TIMEOUT_MS, warnings);
506
666
  if (!message.ok) {
507
667
  throw new RenderError(message.error.code, message.error.message, message.error.detail);
508
668
  }
@@ -696,30 +856,86 @@ export async function renderPage(entry, options = {}) {
696
856
  // (`<img src="./logo.png">`, `url(./bg.png)`) are carried too, so the page
697
857
  // comes back with them; a package's own files are not.
698
858
  for (const sheet of carriedCss) {
699
- const rel = path.relative(root, sheet);
700
- if (rel.startsWith('..') || path.isAbsolute(rel) || rel.split(path.sep).includes('node_modules')) continue;
859
+ if (!isInside(sheet, scope) || path.relative(scope, sheet).split(path.sep).includes('node_modules')) continue;
701
860
  if (!files.includes(sheet)) files.push(sheet);
702
861
  }
703
- for (const asset of ctx.localAssets) {
704
- const rel = path.relative(root, asset);
705
- if (rel.startsWith('..') || path.isAbsolute(rel) || rel.split(path.sep).includes('node_modules')) continue;
706
- if (files.includes(asset)) continue;
707
- // Carried only when its bytes are a known image, font or media format,
708
- // the same test --reverse applies, so the file always comes back.
709
- if (!isAssetBytes(fs.readFileSync(asset))) {
862
+ /** Assets named in a warning already, so each is named once. @type {Set<string>} */
863
+ const notCarried = new Set();
864
+ /**
865
+ * Carry an image, font or media file of the project's own. It is carried
866
+ * only when its bytes are a known image, font or media format, the same
867
+ * test --reverse applies, so the file always comes back.
868
+ * @param {string} asset absolute
869
+ * @param {string} how how the page uses it, for the warning
870
+ */
871
+ const carryAsset = (asset, how) => {
872
+ if (!isInside(asset, scope) || path.relative(scope, asset).split(path.sep).includes('node_modules')) return;
873
+ if (files.includes(asset) || notCarried.has(asset)) return;
874
+ /** @param {string} why */
875
+ const leaveOut = why => {
876
+ notCarried.add(asset);
710
877
  warnings.push({
711
878
  code: 'not-embedded',
712
- message: `${path.relative(dir, asset).split(path.sep).join('/')} is shown inline but not carried in the file: its bytes are not a known image, font or media format, so --reverse cannot give it back.`,
879
+ message: `${path.relative(dir, asset).split(path.sep).join('/')} is ${how} but not carried in the file: ${why}, so --reverse cannot give it back.`,
713
880
  });
714
- continue;
881
+ };
882
+ /** @type {Buffer} */
883
+ let head;
884
+ try {
885
+ // The same limit as a file the page shows, which a render inlines.
886
+ if (fs.statSync(asset).size > MAX_ASSET_BYTES) {
887
+ leaveOut(`it is larger than ${MAX_ASSET_BYTES / 1048576} MB, the most a rendered page carries of one file`);
888
+ return;
889
+ }
890
+ head = headOf(asset);
891
+ } catch (e) {
892
+ leaveOut(`it cannot be read (${/** @type {NodeJS.ErrnoException} */ (e).code ?? 'an error from the file system'})`);
893
+ return;
894
+ }
895
+ if (!isAssetBytes(head)) {
896
+ leaveOut('its bytes are not a known image, font or media format');
897
+ return;
715
898
  }
716
899
  files.push(asset);
900
+ };
901
+ for (const asset of ctx.localAssets) carryAsset(asset, 'shown inline');
902
+ // A carried module or stylesheet can name an image, font or media file by
903
+ // a relative path. --reverse expects each such file back, also when this
904
+ // render does not show it, when it lies inside the folder that holds the
905
+ // carried files (a name that climbs out of it is not the page's file).
906
+ let named = dir;
907
+ for (const f of files) {
908
+ while (!isInside(f, named)) named = path.dirname(named);
909
+ }
910
+ const carriedText = files.filter(
911
+ f => /\.(?:[cm]?[jt]sx?|css)$/i.test(f) && (f === entry || !embeddedPathProblem(path.relative(named, f).split(path.sep).join('/'))),
912
+ );
913
+ for (const file of carriedText) {
914
+ let text;
915
+ try {
916
+ text = fs.readFileSync(file, 'utf8');
917
+ } catch {
918
+ continue;
919
+ }
920
+ for (const ref of assetRefsOf(text, file)) {
921
+ const asset = path.resolve(path.dirname(file), ref);
922
+ if (!isInside(asset, named)) continue;
923
+ if (isFileAt(asset)) {
924
+ carryAsset(asset, `named in ${path.relative(dir, file).split(path.sep).join('/')}`);
925
+ }
926
+ }
717
927
  }
718
928
  // Paths are kept relative to the folder that holds every file: the page's
719
- // folder, or an ancestor when the page imports from above it.
929
+ // folder, or an ancestor when the page imports from above it, but never one
930
+ // from which the page's own path holds a name a reverse refuses (a
931
+ // dot-folder): a file above that stays out of the file, and is named.
720
932
  let base = dir;
721
933
  for (const f of files) {
722
- while (path.relative(base, f).startsWith('..')) base = path.dirname(base);
934
+ while (!isInside(f, base)) {
935
+ const up = path.dirname(base);
936
+ if (up === base || embeddedPathProblem(path.relative(up, entry).split(path.sep).join('/'), {page: true})) break;
937
+ base = up;
938
+ }
723
939
  }
724
940
  // Page first, so the reader knows which file is the page. Only files a
725
941
  // rendered page may carry are embedded (see embedded-files.mjs).
@@ -739,14 +955,72 @@ export async function renderPage(entry, options = {}) {
739
955
  }
740
956
  const heading = /<h1\b[^>]*>([\s\S]*?)<\/h1>/i.exec(markup)?.[1]?.replace(/<[^>]*>/g, '').trim();
741
957
  const title = options.title ?? (heading ? decodeAttr(heading) : path.basename(entry).replace(/\.[^.]+$/, ''));
742
- const html =
743
- '<!doctype html><html lang="en"><head><meta charset="utf-8">' +
744
- '<meta name="viewport" content="width=device-width,initial-scale=1">' +
745
- '<meta name="color-scheme" content="light dark">' +
746
- `<meta name="generator" content="Astryx${options.version ? ` ${escapeHtml(options.version)}` : ''}">` +
747
- `<title>${escapeHtml(title)}</title>` +
748
- `<style>${SCHEME_CSS}${markup.includes('class="recharts-responsive-container"') ? CHART_CSS : ''}${css}</style></head><body>${markup}` +
749
- `${sourceBlock(path.basename(entry), embedded)}</body></html>\n`;
958
+ const generator = `<meta name="generator" content="Astryx${options.version ? ` ${escapeHtml(options.version)}` : ''}">`;
959
+ const style = `<style>${SCHEME_CSS}${markup.includes('class="recharts-responsive-container"') ? CHART_CSS : ''}${css}</style>`;
960
+ let html;
961
+ if (options.output) {
962
+ // The charset and generator metas come first: a browser reads the
963
+ // charset only from the first 1024 bytes, and a CLI decides whether a
964
+ // render wrote a file from its first 4096.
965
+ const setDirs = new Map(/** @type {{name: string, dir: string}[]} */ (message.fromSet ?? []).map(p => [p.name, p.dir]));
966
+ const names = new Set([...(message.packages ?? []), ...setDirs.keys(), 'react', 'react-dom']);
967
+ if (hasCore) names.add('@astryxdesign/core');
968
+ /** @type {Record<string, string>} */
969
+ const packages = {};
970
+ for (const name of [...names].sort()) {
971
+ if (name.startsWith('node:') || builtinModules.includes(name)) continue;
972
+ const version = installedVersion(name, dir, setDirs);
973
+ if (version) packages[name] = version;
974
+ }
975
+ const file = path.basename(options.output);
976
+ const facts = {
977
+ cli: options.version ?? null,
978
+ format: formatFor(embedded),
979
+ file,
980
+ page: projectOf(dir) ? path.relative(root, entry).split(path.sep).join('/') : embedded[0].path,
981
+ restored: `${file.replace(/\.[^.]+$/, '')}-restored/${embedded[0].path}`,
982
+ files: embedded.map(f => f.path),
983
+ packages,
984
+ install: Object.entries(packages)
985
+ .filter(([name]) => !isServedPackage(name, []))
986
+ .map(([name, version]) => `${name}@${version}`),
987
+ ...(options.title === undefined ? {} : {title: options.title}),
988
+ };
989
+ // The file each alias import named, for the files the page carries, so a
990
+ // reverse where no alias names it still finds the file.
991
+ const carried = new Map(embedded.map(f => [path.resolve(base, f.path), f.path]));
992
+ /** @type {Record<string, string>} */
993
+ const aliases = {};
994
+ for (const {spec, file: named} of /** @type {{spec: string, file: string}[]} */ (message.aliasImports ?? []).sort((a, b) => (a.spec < b.spec ? -1 : a.spec > b.spec ? 1 : 0))) {
995
+ const rel = carried.get(path.resolve(named));
996
+ if (rel && aliasOnly(spec)) aliases[spec] = rel;
997
+ }
998
+ const record = {
999
+ ...(facts.cli ? {cli: facts.cli} : {}),
1000
+ page: facts.page,
1001
+ ...(options.title === undefined ? {} : {title: options.title}),
1002
+ packages,
1003
+ ...(Object.keys(aliases).length > 0 ? {aliases} : {}),
1004
+ markup: {
1005
+ sha256: sha256(asParsed(markup)),
1006
+ style: sha256(asParsed(style)),
1007
+ text: Buffer.from(JSON.stringify({title, runs: textRuns(markup)})).toString('base64'),
1008
+ },
1009
+ };
1010
+ html =
1011
+ `<!doctype html><html lang="en"><head><meta charset="utf-8">${generator}\n${headerNote(facts)}\n` +
1012
+ '<meta name="viewport" content="width=device-width,initial-scale=1">' +
1013
+ '<meta name="color-scheme" content="light dark">' +
1014
+ `<title>${escapeHtml(title)}</title>${style}</head><body>${markup}` +
1015
+ `${sourceBlock(path.basename(entry), embedded, record)}\n${endNote(facts)}\n</body></html>\n`;
1016
+ } else {
1017
+ html =
1018
+ '<!doctype html><html lang="en"><head><meta charset="utf-8">' +
1019
+ '<meta name="viewport" content="width=device-width,initial-scale=1">' +
1020
+ '<meta name="color-scheme" content="light dark">' +
1021
+ `${generator}<title>${escapeHtml(title)}</title>${style}</head><body>${markup}` +
1022
+ `${sourceBlock(path.basename(entry), embedded)}</body></html>\n`;
1023
+ }
750
1024
  return {
751
1025
  html,
752
1026
  files: embedded.map(f => f.path),
@@ -1,20 +1,29 @@
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 render format a file that carries these files says, the page first.
6
+ * @param {{path: string}[]} files
7
+ * @returns {number}
8
+ */
9
+ export function formatFor(files: {
10
+ path: string;
11
+ }[]): number;
4
12
  /**
5
13
  * The data block for a page's files.
6
14
  * @param {string} entry the page's file name
7
15
  * @param {{path: string, bytes: Buffer}[]} files the page first
16
+ * @param {RenderRecord} [record] what the render records about itself
8
17
  * @returns {string}
9
18
  */
10
19
  export function sourceBlock(entry: string, files: {
11
20
  path: string;
12
21
  bytes: Buffer;
13
- }[]): string;
22
+ }[], record?: RenderRecord): string;
14
23
  /**
15
24
  * Read the embedded source from a rendered file.
16
25
  * @param {string} html
17
- * @returns {{found: false} | {found: true, source: EmbeddedSource} | {found: true, damaged: string}}
26
+ * @returns {{found: false} | {found: true, source: EmbeddedSource} | {found: true, damaged: string} | {found: true, newer: {format: number, cli: string | null}}}
18
27
  */
19
28
  export function readSourceBlock(html: string): {
20
29
  found: false;
@@ -24,10 +33,49 @@ export function readSourceBlock(html: string): {
24
33
  } | {
25
34
  found: true;
26
35
  damaged: string;
36
+ } | {
37
+ found: true;
38
+ newer: {
39
+ format: number;
40
+ cli: string | null;
41
+ };
42
+ };
43
+ /**
44
+ * The markup between `<body>` and the embedded source: what a render wrote
45
+ * there, unless someone changed it since. Null when the file no longer has
46
+ * that shape.
47
+ * @param {string} html
48
+ * @returns {string | null}
49
+ */
50
+ export function renderedMarkupOf(html: string): string | null;
51
+ /**
52
+ * The title and the <style> element a render wrote in <head>, unless someone
53
+ * changed them since.
54
+ * @param {string} html
55
+ * @returns {{title: string | null, style: string | null}}
56
+ */
57
+ export function renderedHeadOf(html: string): {
58
+ title: string | null;
59
+ style: string | null;
27
60
  };
61
+ /**
62
+ * The title and the runs of text a record keeps, or null when the record
63
+ * keeps none or they do not decode.
64
+ * @param {{text?: unknown}} markup
65
+ * @returns {{title: string | null, runs: string[]} | null}
66
+ */
67
+ export function recordedText(markup: {
68
+ text?: unknown;
69
+ }): {
70
+ title: string | null;
71
+ runs: string[];
72
+ } | null;
28
73
  /** The script type of the embedded-source block. */
29
74
  export const SOURCE_TYPE: "application/x-astryx-source";
30
- export function sha256(bytes: Buffer): string;
75
+ /** The newest render format this CLI reads, and the newest it writes. */
76
+ export const RENDER_FORMAT: 2;
77
+ export function sha256(bytes: Buffer | string): string;
78
+ export function asParsed(text: string): string;
31
79
  export type EmbeddedFile = {
32
80
  /**
33
81
  * - Path relative to the folder that holds every embedded file, `/`-separated; the page itself first.
@@ -42,11 +90,42 @@ export type EmbeddedFile = {
42
90
  */
43
91
  base64: string;
44
92
  };
45
- export type EmbeddedSource = {
46
- version: 1;
93
+ /**
94
+ * What the render records about itself beside the files. Every field is
95
+ * optional: files from older CLIs have none of them.
96
+ */
97
+ export type RenderRecord = {
98
+ /**
99
+ * - The version of the CLI that rendered the file.
100
+ */
101
+ cli?: string | undefined;
47
102
  /**
48
- * - The page's file name.
103
+ * - The page's path from its project's root, `/`-separated; outside a project, its path among the files it carries.
49
104
  */
105
+ page?: string | undefined;
106
+ /**
107
+ * - The title given with --title, which a render again needs too.
108
+ */
109
+ title?: string | undefined;
110
+ /**
111
+ * - The packages the page rendered with, by name: their versions.
112
+ */
113
+ packages?: Record<string, string> | undefined;
114
+ /**
115
+ * - Each path-alias import a carried module makes that cannot be a package name (`@/…`, `~/…`), as written (without a query), with the embedded path of the carried file it names, so a reverse where no alias names it still finds the file.
116
+ */
117
+ aliases?: Record<string, string> | undefined;
118
+ /**
119
+ * - The page as rendered, so a reverse can tell what changed after the render: the SHA-256 of the markup in <body> and of the <style> element, and `text`, the base64 of the JSON `{title, runs}` (the title and the markup's runs of text in order). The text stays encoded so that a find-and-replace over the page's text cannot change the record too.
120
+ */
121
+ markup?: {
122
+ sha256: string;
123
+ style?: string;
124
+ text?: string;
125
+ } | undefined;
126
+ };
127
+ export type EmbeddedSource = RenderRecord & {
128
+ version: number;
50
129
  entry: string;
51
130
  files: EmbeddedFile[];
52
131
  };