@astryxdesign/cli 0.7.17-canary.g5a3fd39 → 0.7.17-canary.g5cf5d69

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 (426) hide show
  1. package/README.md +64 -63
  2. package/api/build/_adapter.d.mts +51 -0
  3. package/api/build/_adapter.mjs +122 -6
  4. package/api/build/build.doc.mjs +1 -1
  5. package/api/build/build.mjs +23 -14
  6. package/api/build/build.type.d.mts +1 -1
  7. package/api/build/build.type.mjs +3 -3
  8. package/api/build/help/help.d.mts +15 -14
  9. package/api/build/help/help.mjs +62 -3
  10. package/api/build/kit/answer.mjs +2 -3
  11. package/api/build/kit/signals.d.mts +10 -0
  12. package/api/build/kit/signals.mjs +15 -2
  13. package/api/component/detail/blocks/blocks.mjs +2 -1
  14. package/api/discover/_adapter.d.mts +57 -6
  15. package/api/discover/_adapter.mjs +278 -49
  16. package/api/discover/_catalog-view.d.mts +7 -0
  17. package/api/discover/_catalog-view.mjs +10 -1
  18. package/api/discover/detail/detail.d.mts +3 -2
  19. package/api/discover/detail/detail.mjs +3 -2
  20. package/api/discover/detail/doc/doc.mjs +1 -1
  21. package/api/discover/discover.d.mts +24 -0
  22. package/api/discover/discover.doc.mjs +1 -1
  23. package/api/discover/discover.mjs +146 -25
  24. package/api/discover/discover.type.d.mts +6 -4
  25. package/api/discover/discover.type.mjs +6 -4
  26. package/api/discover/search/search.d.mts +22 -0
  27. package/api/discover/search/search.mjs +290 -70
  28. package/api/docs/_entry-names.mjs +4 -3
  29. package/api/doctor/_adapter.d.mts +43 -3
  30. package/api/doctor/_adapter.mjs +142 -18
  31. package/api/doctor/built-checks.d.mts +30 -3
  32. package/api/doctor/built-checks.mjs +132 -5
  33. package/api/doctor/doctor.d.mts +93 -6
  34. package/api/doctor/doctor.doc.mjs +2 -2
  35. package/api/doctor/doctor.mjs +524 -33
  36. package/api/doctor/doctor.type.d.mts +2 -1
  37. package/api/doctor/doctor.type.mjs +2 -1
  38. package/api/doctor/theme-checks.d.mts +19 -0
  39. package/api/doctor/theme-checks.mjs +74 -6
  40. package/api/hook/hook.type.d.mts +1 -1
  41. package/api/hook/hook.type.mjs +1 -1
  42. package/api/hook/list/list.mjs +11 -7
  43. package/api/icon/_adapter.d.mts +2 -1
  44. package/api/icon/_adapter.mjs +10 -15
  45. package/api/icon/_records.d.mts +3 -1
  46. package/api/icon/_records.mjs +30 -3
  47. package/api/icon/exportIconIndex.doc.mjs +1 -1
  48. package/api/icon/icon.doc.mjs +3 -3
  49. package/api/icon/icon.type.d.mts +32 -1
  50. package/api/icon/icon.type.mjs +19 -3
  51. package/api/icon/list/list.mjs +4 -1
  52. package/api/icon/rankIconIndex.doc.mjs +1 -1
  53. package/api/icon/search/icon-index.mjs +18 -8
  54. package/api/icon/search/search.d.mts +26 -3
  55. package/api/icon/search/search.mjs +155 -9
  56. package/api/init/_adapter.d.mts +14 -0
  57. package/api/init/_adapter.mjs +26 -4
  58. package/api/init/init.d.mts +1 -1
  59. package/api/init/init.doc.mjs +2 -2
  60. package/api/init/init.mjs +1 -1
  61. package/api/init/init.type.d.mts +29 -1
  62. package/api/init/init.type.mjs +14 -1
  63. package/api/init/run/run.d.mts +11 -1
  64. package/api/init/run/run.mjs +84 -5
  65. package/api/integration/_adapter.d.mts +5 -4
  66. package/api/integration/_adapter.mjs +7 -5
  67. package/api/integration/integrationCheck.doc.mjs +1 -1
  68. package/api/integration/pack-check.mjs +8 -9
  69. package/api/integration/validate-integration.d.mts +1 -1
  70. package/api/integration/validate-integration.mjs +26 -24
  71. package/api/integration/validate-integration.type.d.mts +5 -2
  72. package/api/integration/validate-integration.type.mjs +5 -2
  73. package/api/integration/validateIntegration.doc.mjs +1 -1
  74. package/api/render/_adapter.d.mts +4 -2
  75. package/api/render/_adapter.mjs +62 -21
  76. package/api/render/render.doc.mjs +8 -5
  77. package/api/render/render.mjs +1 -1
  78. package/api/render/render.type.d.mts +2 -0
  79. package/api/render/render.type.mjs +2 -0
  80. package/api/search/ORDERING.md +2 -2
  81. package/api/search/_candidate-score.d.mts +3 -0
  82. package/api/search/_candidate-score.mjs +36 -3
  83. package/api/search/_gather-docs.mjs +29 -2
  84. package/api/search/_gather-templates.mjs +2 -1
  85. package/api/search/_main-searcher.mjs +13 -0
  86. package/api/search/_named-keywords.d.mts +2 -1
  87. package/api/search/_named-keywords.mjs +48 -6
  88. package/api/search/_order.d.mts +36 -1
  89. package/api/search/_order.mjs +141 -3
  90. package/api/swizzle/list/list.mjs +8 -1
  91. package/api/swizzle/swizzle.type.d.mts +1 -1
  92. package/api/swizzle/swizzle.type.mjs +1 -1
  93. package/api/template/copy/copy.mjs +3 -4
  94. package/api/template/list/list.mjs +2 -1
  95. package/api/template/show/show.mjs +2 -1
  96. package/api/template/skeleton/skeleton.mjs +2 -1
  97. package/api/template/template.doc.mjs +1 -1
  98. package/api/template/template.mjs +19 -1
  99. package/api/template/template.type.d.mts +1 -0
  100. package/api/template/template.type.mjs +2 -1
  101. package/api/theme/_adapter.d.mts +1 -0
  102. package/api/theme/_adapter.mjs +3 -5
  103. package/api/theme/_app-provider.d.mts +42 -0
  104. package/api/theme/_app-provider.mjs +61 -27
  105. package/api/theme/build/build.d.mts +4 -10
  106. package/api/theme/build/build.mjs +165 -116
  107. package/api/theme/build/input-fields.d.mts +9 -0
  108. package/api/theme/build/input-fields.mjs +155 -16
  109. package/api/theme/build/radius-values.d.mts +18 -0
  110. package/api/theme/build/radius-values.mjs +76 -0
  111. package/api/theme/build/typography-values.mjs +7 -23
  112. package/api/theme/build/written-values.d.mts +18 -0
  113. package/api/theme/build/written-values.mjs +107 -31
  114. package/api/theme/eject/eject.mjs +6 -1
  115. package/api/theme/palette/generate/generator.mjs +24 -0
  116. package/api/theme/theme.type.d.mts +4 -2
  117. package/api/theme/theme.type.mjs +3 -2
  118. package/api/theme/themeBuild.doc.mjs +2 -2
  119. package/api/theme/themeEject.doc.mjs +1 -1
  120. package/api/theme-edit/_catalog.d.mts +40 -0
  121. package/api/theme-edit/_catalog.mjs +100 -22
  122. package/api/theme-edit/_check.mjs +213 -43
  123. package/api/theme-edit/_color.d.mts +14 -0
  124. package/api/theme-edit/_color.mjs +22 -0
  125. package/api/theme-edit/_compiler.mjs +52 -0
  126. package/api/theme-edit/_context.d.mts +20 -2
  127. package/api/theme-edit/_context.mjs +157 -29
  128. package/api/theme-edit/_edit.mjs +426 -58
  129. package/api/theme-edit/_how-question.d.mts +14 -0
  130. package/api/theme-edit/_how-question.mjs +1541 -127
  131. package/api/theme-edit/_how.mjs +43 -0
  132. package/api/theme-edit/_missed.mjs +107 -27
  133. package/api/theme-edit/_normal.d.mts +18 -4
  134. package/api/theme-edit/_normal.mjs +84 -3
  135. package/api/theme-edit/_palette.d.mts +9 -0
  136. package/api/theme-edit/_palette.mjs +158 -33
  137. package/api/theme-edit/_part-words.mjs +16 -3
  138. package/api/theme-edit/_parts.d.mts +8 -0
  139. package/api/theme-edit/_parts.mjs +120 -36
  140. package/api/theme-edit/_png.d.mts +24 -0
  141. package/api/theme-edit/_png.mjs +99 -0
  142. package/api/theme-edit/_preview-app.d.mts +16 -0
  143. package/api/theme-edit/_preview-app.mjs +52 -18
  144. package/api/theme-edit/_preview.d.mts +44 -26
  145. package/api/theme-edit/_preview.mjs +255 -67
  146. package/api/theme-edit/_project.d.mts +12 -1
  147. package/api/theme-edit/_project.mjs +16 -1
  148. package/api/theme-edit/_settings.d.mts +116 -0
  149. package/api/theme-edit/_settings.mjs +1197 -58
  150. package/api/theme-edit/_tables.d.mts +16 -0
  151. package/api/theme-edit/_tables.mjs +34 -4
  152. package/api/theme-edit/theme-edit.type.d.mts +15 -2
  153. package/api/theme-edit/theme-edit.type.mjs +8 -6
  154. package/api/upgrade/_adapter.d.mts +46 -7
  155. package/api/upgrade/_adapter.mjs +110 -15
  156. package/api/upgrade/registry/registry.d.mts +6 -3
  157. package/api/upgrade/registry/registry.mjs +21 -6
  158. package/api/upgrade/run/run.mjs +23 -11
  159. package/api/upgrade/upgrade.doc.mjs +4 -3
  160. package/assets/component-list.generated.json +1 -1
  161. package/assets/docs/tree/agent-guidance.doc.mjs +3 -2
  162. package/assets/docs/tree/checks.doc.mjs +2 -2
  163. package/assets/docs/tree/host-entry.doc.mjs +4 -0
  164. package/assets/docs/tree/icon-definitions.doc.mjs +3 -3
  165. package/assets/docs/tree/icon-sets.doc.mjs +6 -6
  166. package/assets/docs/tree/problems.doc.mjs +3 -3
  167. package/assets/docs/tree/render-pages.doc.mjs +17 -3
  168. package/assets/docs/tree/share-a-page.doc.mjs +5 -5
  169. package/assets/docs/tree/short-and-findable.doc.mjs +3 -3
  170. package/assets/docs/tree/troubleshooting.doc.mjs +8 -0
  171. package/assets/docs/tree/updates.doc.mjs +1 -1
  172. package/assets/docs/tree/versioning.doc.mjs +1 -1
  173. package/assets/docs/working-with-ai.doc.mjs +40 -5
  174. package/assets/docs-routes.generated.json +1 -1
  175. package/assets/docs.generated.json +2 -2
  176. package/assets/icons/installed-icon-set.doc.mjs +30 -0
  177. package/assets/search-catalog.generated.json +2 -2
  178. package/assets/self-audit.generated.json +1 -1
  179. package/assets/templates/blocks/components/Avatar/AvatarInteractive.tsx +6 -1
  180. package/assets/templates/blocks/components/CodeBlock/CodeBlockTerminal.tsx +1 -1
  181. package/assets/templates/blocks/components/LinkProvider/LinkProviderCustomLink.tsx +3 -1
  182. package/assets/templates/components.generated.json +1 -1
  183. package/assets/templates/pages/ai-chat/page.tsx +6 -2
  184. package/assets/templates/pages/ai-chat-landing/page.tsx +1 -1
  185. package/assets/templates/pages/blank/page.tsx +4 -2
  186. package/assets/templates/pages/canvas-editor/page.tsx +3 -1
  187. package/assets/templates/pages/centered-hero/page.tsx +1 -1
  188. package/assets/templates/pages/checkout-wizard/page.tsx +1 -1
  189. package/assets/templates/pages/classic-gallery/page.tsx +1 -1
  190. package/assets/templates/pages/contact-form/page.tsx +2 -2
  191. package/assets/templates/pages/course-detail/page.tsx +1 -1
  192. package/assets/templates/pages/dashboard/page.tsx +24 -8
  193. package/assets/templates/pages/dashboard-alert-rail/page.tsx +4 -2
  194. package/assets/templates/pages/dashboard-cohort-funnel/page.tsx +7 -3
  195. package/assets/templates/pages/dashboard-comparison/page.tsx +5 -2
  196. package/assets/templates/pages/dashboard-composition/page.tsx +10 -4
  197. package/assets/templates/pages/dashboard-progress/page.tsx +6 -3
  198. package/assets/templates/pages/dashboard-scorecard/page.tsx +17 -8
  199. package/assets/templates/pages/detail-page/page.tsx +22 -5
  200. package/assets/templates/pages/documentation/page.tsx +4 -2
  201. package/assets/templates/pages/documentation-design/page.tsx +5 -2
  202. package/assets/templates/pages/documentation-technical/page.tsx +4 -2
  203. package/assets/templates/pages/editor/page.tsx +28 -9
  204. package/assets/templates/pages/file-explorer/page.tsx +3 -1
  205. package/assets/templates/pages/form-two-column/page.tsx +1 -1
  206. package/assets/templates/pages/form-wizard/page.tsx +1 -1
  207. package/assets/templates/pages/form-wizard-dialog/page.tsx +3 -1
  208. package/assets/templates/pages/form-wizard-inline/page.tsx +1 -1
  209. package/assets/templates/pages/form-wizard-vertical/page.tsx +1 -1
  210. package/assets/templates/pages/gallery-hero/page.tsx +1 -1
  211. package/assets/templates/pages/ide/page.tsx +7 -2
  212. package/assets/templates/pages/kanban-board/page.tsx +10 -4
  213. package/assets/templates/pages/library/page.tsx +31 -61
  214. package/assets/templates/pages/login/page.tsx +4 -2
  215. package/assets/templates/pages/login-card/page.tsx +4 -2
  216. package/assets/templates/pages/login-split/page.tsx +3 -2
  217. package/assets/templates/pages/login-sso/page.tsx +4 -4
  218. package/assets/templates/pages/mixed-gallery/page.tsx +1 -1
  219. package/assets/templates/pages/payment-form/page.tsx +1 -1
  220. package/assets/templates/pages/product-detail/page.tsx +16 -4
  221. package/assets/templates/pages/product-gallery/page.tsx +1 -1
  222. package/assets/templates/pages/settings/page.tsx +10 -4
  223. package/assets/templates/pages/settings-dialog/page.tsx +5 -6
  224. package/assets/templates/pages/settings-sidebar/page.tsx +39 -13
  225. package/assets/templates/pages/side-gallery/page.tsx +1 -1
  226. package/assets/templates/pages/table/page.tsx +2 -2
  227. package/assets/templates/pages/table-filter/page.tsx +21 -6
  228. package/assets/templates/pages/table-grouped/page.tsx +23 -2
  229. package/assets/templates/pages/table-inbox/page.tsx +82 -32
  230. package/assets/templates/pages/theme-showcase/page.tsx +3 -2
  231. package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +12 -12
  232. package/assets/templates/themes/butter/butterTheme.ts +197 -4
  233. package/assets/templates/themes/chocolate/chocolateTheme.ts +72 -8
  234. package/assets/templates/themes/gothic/gothicPaletteRefs.generated.ts +3 -3
  235. package/assets/templates/themes/gothic/gothicTheme.ts +114 -4
  236. package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +8 -8
  237. package/assets/templates/themes/matcha/matchaTheme.ts +48 -12
  238. package/assets/templates/themes/neutral/neutralTheme.ts +29 -0
  239. package/assets/templates/themes/stone/stonePaletteRefs.generated.ts +2 -2
  240. package/assets/templates/themes/stone/stoneTheme.ts +69 -0
  241. package/assets/templates/themes/y2k/y2kPaletteRefs.generated.ts +9 -9
  242. package/assets/templates/themes/y2k/y2kTheme.ts +249 -14
  243. package/authoring/codemod/parse.d.mts +0 -36
  244. package/authoring/codemod/parse.mjs +62 -41
  245. package/authoring/config/config.doc.mjs +1 -1
  246. package/authoring/config/parse.d.mts +0 -47
  247. package/authoring/config/parse.mjs +128 -103
  248. package/authoring/config/type.ts +4 -3
  249. package/authoring/debug/parse.d.mts +2 -2
  250. package/authoring/discover/parse.d.mts +2 -2
  251. package/authoring/discover/parse.mjs +52 -38
  252. package/authoring/discover/type.ts +2 -1
  253. package/authoring/doctypes/_schema.d.mts +834 -950
  254. package/authoring/doctypes/_schema.mjs +863 -825
  255. package/authoring/doctypes/command/parse.mjs +2 -2
  256. package/authoring/doctypes/component/parse.mjs +2 -2
  257. package/authoring/doctypes/enum/parse.mjs +2 -2
  258. package/authoring/doctypes/hook/parse.mjs +2 -2
  259. package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +1 -1
  260. package/authoring/doctypes/icon-definition/parse.d.mts +0 -24
  261. package/authoring/doctypes/icon-definition/parse.mjs +59 -43
  262. package/authoring/doctypes/icon-set/parse.d.mts +0 -75
  263. package/authoring/doctypes/icon-set/parse.mjs +239 -210
  264. package/authoring/doctypes/legacy.mjs +3 -3
  265. package/authoring/doctypes/namespace/parse.mjs +2 -2
  266. package/authoring/doctypes/reference/parse.mjs +2 -2
  267. package/authoring/doctypes/schema/parse.mjs +2 -2
  268. package/authoring/doctypes/template/parse.d.mts +0 -101
  269. package/authoring/doctypes/template/parse.mjs +131 -106
  270. package/authoring/doctypes/theme/parse.d.mts +0 -23
  271. package/authoring/doctypes/theme/parse.mjs +52 -36
  272. package/authoring/gap-report/parse.d.mts +1 -1
  273. package/authoring/integration/integration.doc.mjs +8 -0
  274. package/authoring/integration/schema.d.mts +14 -3
  275. package/authoring/integration/schema.mjs +20 -2
  276. package/authoring/integration/type.ts +14 -0
  277. package/clients/cli/build-id.generated.json +1 -1
  278. package/clients/cli/commands/build.mjs +27 -13
  279. package/clients/cli/commands/component.mjs +14 -3
  280. package/clients/cli/commands/discover.doc.mjs +2 -2
  281. package/clients/cli/commands/discover.mjs +20 -3
  282. package/clients/cli/commands/docs.doc.mjs +11 -9
  283. package/clients/cli/commands/docs.mjs +50 -21
  284. package/clients/cli/commands/experimental/icon.mjs +330 -227
  285. package/clients/cli/commands/experimental/render.mjs +16 -1
  286. package/clients/cli/commands/experimental/theme.mjs +42 -17
  287. package/clients/cli/commands/experimental-icon-add.doc.mjs +1 -1
  288. package/clients/cli/commands/experimental-icon-map.doc.mjs +4 -1
  289. package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +4 -1
  290. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +4 -1
  291. package/clients/cli/commands/experimental-icon-use.doc.mjs +1 -1
  292. package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
  293. package/clients/cli/commands/experimental-render.doc.mjs +3 -3
  294. package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
  295. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
  296. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
  297. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  298. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  299. package/clients/cli/commands/init.doc.mjs +36 -24
  300. package/clients/cli/commands/integration-check.doc.mjs +1 -1
  301. package/clients/cli/commands/mcp.doc.mjs +53 -0
  302. package/clients/cli/commands/mcp.mjs +51 -0
  303. package/clients/cli/commands/search.mjs +46 -9
  304. package/clients/cli/commands/template.mjs +3 -2
  305. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  306. package/clients/cli/commands/theme.mjs +12 -2
  307. package/clients/cli/commands/upgrade.doc.mjs +3 -2
  308. package/clients/cli/commands.generated.json +1 -1
  309. package/clients/cli/formatters/index.mjs +52 -6
  310. package/clients/cli/index.mjs +23 -17
  311. package/clients/cli/lib/base-gate.mjs +37 -5
  312. package/clients/cli/lib/define-command.mjs +82 -4
  313. package/clients/cli/lib/json-shim.mjs +61 -4
  314. package/clients/cli/lib/manifest.mjs +9 -1
  315. package/clients/cli/lib/mcp-server.mjs +286 -0
  316. package/clients/cli/lib/mcp-tools.mjs +405 -0
  317. package/clients/cli/lib/other-cli-words.mjs +99 -0
  318. package/clients/cli/lib/stray-option.mjs +27 -1
  319. package/clients/cli/lib/unknown-command.mjs +326 -11
  320. package/clients/cli/manifest.generated.json +1 -1
  321. package/clients/cli/run.mjs +1 -1
  322. package/foundation/agent-docs/agent-docs.d.mts +49 -1
  323. package/foundation/agent-docs/agent-docs.mjs +108 -7
  324. package/foundation/agent-docs/computer-agent-text.mjs +1 -1
  325. package/foundation/bases/core.d.mts +1 -1
  326. package/foundation/bases/core.mjs +3 -3
  327. package/foundation/bases/resolve.d.mts +4 -8
  328. package/foundation/bases/resolve.mjs +15 -21
  329. package/foundation/bases/state.d.mts +15 -9
  330. package/foundation/bases/state.mjs +33 -6
  331. package/foundation/config/project.d.mts +5 -4
  332. package/foundation/config/project.mjs +33 -17
  333. package/foundation/discovery/component-discovery.mjs +15 -28
  334. package/foundation/discovery/icon-imports.d.mts +66 -0
  335. package/foundation/discovery/icon-imports.mjs +225 -0
  336. package/foundation/discovery/icon-ranking.d.mts +12 -2
  337. package/foundation/discovery/icon-ranking.mjs +197 -10
  338. package/foundation/discovery/icon-set-checks.mjs +2 -1
  339. package/foundation/discovery/icon-set-discovery.d.mts +28 -0
  340. package/foundation/discovery/icon-set-discovery.mjs +42 -0
  341. package/foundation/discovery/icon-set-writer.d.mts +2 -11
  342. package/foundation/discovery/icon-set-writer.mjs +3 -29
  343. package/foundation/discovery/module-exports.d.mts +1 -1
  344. package/foundation/discovery/module-exports.mjs +136 -33
  345. package/foundation/discovery/name-roots.d.mts +5 -0
  346. package/foundation/discovery/name-roots.mjs +11 -0
  347. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  348. package/foundation/discovery/runner-allowlist.mjs +2 -0
  349. package/foundation/discovery/runner-commands.mjs +1 -0
  350. package/foundation/discovery/template-adapter.d.mts +1 -1
  351. package/foundation/discovery/template-destination.d.mts +14 -6
  352. package/foundation/discovery/template-destination.mjs +42 -8
  353. package/foundation/discovery/template-icons.d.mts +45 -2
  354. package/foundation/discovery/template-icons.mjs +26 -54
  355. package/foundation/discovery/template-needs.d.mts +28 -2
  356. package/foundation/discovery/template-needs.mjs +92 -11
  357. package/foundation/discovery/theme-discovery.d.mts +8 -0
  358. package/foundation/discovery/theme-discovery.mjs +23 -6
  359. package/foundation/discovery/theme-imports.mjs +2 -4
  360. package/foundation/doc-compiler/parse-readable.mjs +4 -3
  361. package/foundation/doc-compiler/stored-docs.d.mts +13 -0
  362. package/foundation/doc-compiler/stored-docs.mjs +74 -3
  363. package/foundation/env/cli-command.d.mts +68 -10
  364. package/foundation/env/cli-command.mjs +116 -22
  365. package/foundation/env/project-scope.d.mts +9 -0
  366. package/foundation/env/project-scope.mjs +28 -2
  367. package/foundation/fs/gather-cache.d.mts +23 -0
  368. package/foundation/fs/gather-cache.mjs +94 -2
  369. package/foundation/fs/module-loader.d.mts +3 -1
  370. package/foundation/fs/module-loader.mjs +85 -5
  371. package/foundation/fs/read-record.mjs +9 -5
  372. package/foundation/identity/package-names.d.mts +18 -0
  373. package/foundation/identity/package-names.mjs +19 -0
  374. package/foundation/identity/providers.mjs +3 -2
  375. package/foundation/integrations/icon-features.d.mts +63 -0
  376. package/foundation/integrations/icon-features.mjs +54 -0
  377. package/foundation/integrations/integrations.d.mts +13 -1
  378. package/foundation/integrations/integrations.mjs +47 -6
  379. package/foundation/integrations/pack-state.d.mts +21 -0
  380. package/foundation/integrations/pack-state.mjs +42 -19
  381. package/foundation/integrations/validate-contributions.d.mts +11 -3
  382. package/foundation/integrations/validate-contributions.mjs +51 -13
  383. package/foundation/release/cache.d.mts +13 -1
  384. package/foundation/release/cache.mjs +94 -14
  385. package/foundation/release/notices.d.mts +15 -0
  386. package/foundation/release/notices.mjs +111 -7
  387. package/foundation/release/project.d.mts +3 -4
  388. package/foundation/release/project.mjs +5 -6
  389. package/foundation/render/client-bundle.d.mts +126 -0
  390. package/foundation/render/client-bundle.mjs +565 -0
  391. package/foundation/render/cut-short.d.mts +7 -1
  392. package/foundation/render/cut-short.mjs +46 -6
  393. package/foundation/render/embedded-imports.d.mts +4 -3
  394. package/foundation/render/embedded-imports.mjs +13 -8
  395. package/foundation/render/esbuild-dependency.d.mts +14 -0
  396. package/foundation/render/esbuild-dependency.mjs +41 -0
  397. package/foundation/render/file-header.mjs +5 -4
  398. package/foundation/render/page-worker.mjs +562 -86
  399. package/foundation/render/picture-chrome.mjs +54 -29
  400. package/foundation/render/picture-playwright.mjs +78 -42
  401. package/foundation/render/picture-window.d.mts +33 -0
  402. package/foundation/render/picture-window.mjs +78 -0
  403. package/foundation/render/render-page.d.mts +55 -4
  404. package/foundation/render/render-page.mjs +199 -28
  405. package/foundation/render/restore-folder.d.mts +13 -0
  406. package/foundation/render/restore-folder.mjs +30 -0
  407. package/foundation/render/served-packages.d.mts +2 -1
  408. package/foundation/render/served-packages.mjs +5 -3
  409. package/foundation/render/ts-paths.d.mts +11 -0
  410. package/foundation/render/ts-paths.mjs +27 -2
  411. package/foundation/render/value-uses.d.mts +43 -0
  412. package/foundation/render/value-uses.mjs +110 -0
  413. package/foundation/response/error-codes.d.mts +2 -1
  414. package/foundation/response/error-codes.doc.mjs +7 -1
  415. package/foundation/response/error-codes.mjs +10 -2
  416. package/foundation/response/response-types.doc.mjs +12 -12
  417. package/foundation/runtime/package-root.d.mts +8 -0
  418. package/foundation/runtime/package-root.mjs +20 -0
  419. package/foundation/suggest/other-command.d.mts +11 -0
  420. package/foundation/suggest/other-command.mjs +1 -1
  421. package/foundation/text/icon-id.d.mts +20 -0
  422. package/foundation/text/icon-id.mjs +40 -0
  423. package/foundation/text/icon-set-next.d.mts +25 -0
  424. package/foundation/text/icon-set-next.mjs +29 -0
  425. package/foundation/xle/browser.d.mts +2 -2
  426. package/package.json +7 -6
@@ -0,0 +1,565 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file The page's script in a rendered file: the page's modules and the
5
+ * modules they use, bundled by esbuild (a dependency of the CLI, loaded only
6
+ * here) into one script that draws the page in the browser over its server
7
+ * markup, so state, effects and event handlers work. No network, no `eval`,
8
+ * no other file.
9
+ * @input The page's entry file, esbuild, and how the server compiled and
10
+ * resolved the page's modules
11
+ * @output One script's text, safe inside an HTML `<script>` element
12
+ * @position foundation/render — used by page-worker.mjs
13
+ */
14
+
15
+ import * as fs from 'node:fs';
16
+ import {builtinModules} from 'node:module';
17
+ import * as path from 'node:path';
18
+ import {stripVTControlCharacters} from 'node:util';
19
+ import vm from 'node:vm';
20
+ import {SOURCE_TYPE} from './source-block.mjs';
21
+
22
+ /** The id of the element that holds the page's markup in a rendered file. */
23
+ export const ROOT_ID = 'astryx-render-root';
24
+
25
+ /** The module the page's script reads a carried file from. */
26
+ export const CARRIED_MODULE = 'astryx:carried';
27
+
28
+ /** An address that leaves the file: another site, mail or a phone call. */
29
+ export const LINK_OUT = /^(https?:|mailto:|tel:|\/\/)/i;
30
+
31
+ /**
32
+ * What the file does so that the page works in a viewer's sandboxed frame as
33
+ * it works in an app. A link out of the file opens in a new tab, since the
34
+ * frame cannot follow it; a link the page handles itself (it cancels the
35
+ * click) or gives a target keeps its way. A form submits through its submit
36
+ * event: the file cancels the browser's own submission and fires the event
37
+ * itself, since a frame that blocks form submission never fires it, and a
38
+ * file has no server to send a form to; a form whose action is another
39
+ * site's address submits as the browser submits it. Enter in a form's only text field
40
+ * submits a form with no submit button, as a browser does; with a button,
41
+ * the browser clicks it.
42
+ */
43
+ export const IN_A_VIEWER = `{
44
+ const out = ${LINK_OUT};
45
+ const typed = /^(text|search|url|tel|email|password|date|month|week|time|datetime-local|number)$/;
46
+ const elsewhere = (form, submitter) =>
47
+ out.test(((submitter && submitter.getAttribute('formaction')) ?? form.getAttribute('action') ?? '').trim());
48
+ const submit = (form, submitter) => {
49
+ if (!form.noValidate && !(submitter && submitter.formNoValidate) && !form.reportValidity()) return;
50
+ form.dispatchEvent(typeof SubmitEvent === 'function'
51
+ ? new SubmitEvent('submit', {bubbles: true, cancelable: true, submitter})
52
+ : new Event('submit', {bubbles: true, cancelable: true}));
53
+ };
54
+ document.addEventListener('click', event => {
55
+ if (event.defaultPrevented || !(event.target instanceof Element)) return;
56
+ const link = event.target.closest('a[href]');
57
+ if (link) {
58
+ if (!link.hasAttribute('target') && out.test(link.getAttribute('href').trim())) {
59
+ link.target = '_blank';
60
+ link.rel = [...new Set([...link.rel.split(/\\s+/).filter(Boolean), 'noopener', 'noreferrer'])].join(' ');
61
+ }
62
+ return;
63
+ }
64
+ const button = event.target.closest('button, input');
65
+ if (!button || !button.form || (button.type !== 'submit' && button.type !== 'image')) return;
66
+ if (elsewhere(button.form, button)) return;
67
+ event.preventDefault();
68
+ submit(button.form, button);
69
+ });
70
+ document.addEventListener('keydown', event => {
71
+ const field = event.target;
72
+ if (event.key !== 'Enter' || event.defaultPrevented || event.isComposing) return;
73
+ if (!(field instanceof HTMLInputElement) || !field.form || !typed.test(field.type)) return;
74
+ const controls = [...field.form.elements];
75
+ if (controls.some(c => c.type === 'submit' || c.type === 'image')) return;
76
+ if (controls.filter(c => c instanceof HTMLInputElement && typed.test(c.type)).length !== 1) return;
77
+ if (elsewhere(field.form, null)) return;
78
+ event.preventDefault();
79
+ submit(field.form, null);
80
+ });
81
+ }`;
82
+
83
+ /**
84
+ * Storage for a page in a viewer that blocks it. A frame without
85
+ * allow-same-origin has an opaque origin, where touching `localStorage` or
86
+ * `sessionStorage` throws. Then the page gets an in-memory storage for each
87
+ * one that acts as the browser's does: its methods, and its items read,
88
+ * written, listed and deleted as properties (`localStorage.theme`,
89
+ * `Object.keys(localStorage)`). What it saves lasts until the page closes.
90
+ * A file opened from disk or on a real origin keeps its real storage. This
91
+ * runs as the script's first module, before any of the page's own modules.
92
+ */
93
+ export const VIEWER_STORAGE = `for (const name of ['localStorage', 'sessionStorage']) {
94
+ let usable = true;
95
+ try {
96
+ window[name].getItem('');
97
+ } catch {
98
+ usable = false;
99
+ }
100
+ if (usable) continue;
101
+ const items = new Map();
102
+ const methods = {
103
+ get length() {
104
+ return items.size;
105
+ },
106
+ key: index => [...items.keys()][index] ?? null,
107
+ getItem: key => (items.has(String(key)) ? items.get(String(key)) : null),
108
+ setItem: (key, value) => {
109
+ items.set(String(key), String(value));
110
+ },
111
+ removeItem: key => {
112
+ items.delete(String(key));
113
+ },
114
+ clear: () => {
115
+ items.clear();
116
+ },
117
+ };
118
+ const storage = new Proxy(methods, {
119
+ get: (target, key, receiver) =>
120
+ key in target || typeof key !== 'string' ? Reflect.get(target, key, receiver) : items.get(key),
121
+ set: (target, key, value) => {
122
+ if (typeof key === 'string' && !(key in target)) items.set(key, String(value));
123
+ return true;
124
+ },
125
+ has: (target, key) => (typeof key === 'string' && items.has(key)) || key in target,
126
+ deleteProperty: (target, key) => {
127
+ if (typeof key === 'string' && !(key in target)) items.delete(key);
128
+ return true;
129
+ },
130
+ ownKeys: () => [...items.keys()],
131
+ getOwnPropertyDescriptor: (target, key) =>
132
+ typeof key === 'string' && items.has(key)
133
+ ? {value: items.get(key), writable: true, enumerable: true, configurable: true}
134
+ : undefined,
135
+ });
136
+ try {
137
+ Object.defineProperty(window, name, {configurable: true, enumerable: true, get: () => storage});
138
+ } catch {
139
+ // A window that refuses the property keeps the storage it has.
140
+ }
141
+ }`;
142
+
143
+ /**
144
+ * Copying for a page in a viewer that blocks the Clipboard API. It falls
145
+ * back to the copy command where Core's clipboard hook does: when the frame's
146
+ * permissions policy refuses clipboard-write, when `writeText` refuses the
147
+ * write (NotAllowedError), and also when the frame leaves `navigator.clipboard`
148
+ * out or `writeText` throws at once. The copy command runs only in a click or
149
+ * a key press, as in the hook. A write that resolves copied the text; a
150
+ * failed fallback rejects with the browser's own refusal, or NotAllowedError,
151
+ * so the page's own error path runs. `readText` rejects with NotAllowedError,
152
+ * as a browser does. The hook's helpers are private to Core and run only in
153
+ * pages that use the hook; this runs in the file's script before any of the
154
+ * page's modules, for every page.
155
+ */
156
+ export const VIEWER_CLIPBOARD = `{
157
+ const refused = message => new DOMException(message, 'NotAllowedError');
158
+ const copy = text =>
159
+ new Promise((resolve, reject) => {
160
+ if (navigator.userActivation?.isActive === false) {
161
+ reject(refused('The copy command runs only in a click or a key press.'));
162
+ return;
163
+ }
164
+ let written = false;
165
+ const write = event => {
166
+ if (event.clipboardData == null) return;
167
+ event.clipboardData.setData('text/plain', String(text));
168
+ event.preventDefault();
169
+ event.stopImmediatePropagation();
170
+ written = true;
171
+ };
172
+ window.addEventListener('copy', write, true);
173
+ let copied = false;
174
+ try {
175
+ copied = document.execCommand('copy');
176
+ } catch {
177
+ copied = false;
178
+ } finally {
179
+ window.removeEventListener('copy', write, true);
180
+ }
181
+ if (copied && written) resolve();
182
+ else reject(refused('The browser did not copy the text.'));
183
+ });
184
+ const policy = document.permissionsPolicy ?? document.featurePolicy;
185
+ const writeAllowed = () =>
186
+ typeof policy?.allowsFeature === 'function' ? policy.allowsFeature('clipboard-write') : true;
187
+ const clipboard = navigator.clipboard;
188
+ if (clipboard == null) {
189
+ const fallback = {
190
+ writeText: copy,
191
+ readText: () => Promise.reject(refused('This frame does not let a page read the clipboard.')),
192
+ };
193
+ try {
194
+ Object.defineProperty(navigator, 'clipboard', {configurable: true, enumerable: true, get: () => fallback});
195
+ } catch {
196
+ // A navigator that refuses the property keeps what it has.
197
+ }
198
+ } else if (typeof clipboard.writeText === 'function') {
199
+ const writeText = clipboard.writeText;
200
+ try {
201
+ clipboard.writeText = function (text) {
202
+ if (!writeAllowed()) return copy(text);
203
+ let asked;
204
+ try {
205
+ asked = writeText.call(this, text);
206
+ } catch {
207
+ return copy(text);
208
+ }
209
+ return Promise.resolve(asked).catch(error =>
210
+ error instanceof DOMException && error.name === 'NotAllowedError'
211
+ ? copy(text).catch(() => Promise.reject(error))
212
+ : Promise.reject(error),
213
+ );
214
+ };
215
+ } catch {
216
+ // A clipboard that refuses the property keeps its own writeText.
217
+ }
218
+ }
219
+ }`;
220
+
221
+ /** The namespace of the module that fills in what a viewer's frame blocks: storage and the clipboard. */
222
+ const VIEWER = 'astryx-viewer';
223
+ const PAGE = 'astryx-page';
224
+
225
+ /** The namespace of the module that mounts the page. */
226
+ const MOUNT = 'astryx-mount';
227
+
228
+ /** An import of a module that is part of Node. */
229
+ const NODE_MODULE = new RegExp(
230
+ `^(node:.*|(${builtinModules.filter(name => !name.startsWith('_')).map(escapeRegExp).join('|')})(/.*)?)$`,
231
+ );
232
+
233
+ /**
234
+ * An import of one of `names`, or of a file inside one.
235
+ * @param {string[]} names
236
+ */
237
+ const packageFilter = names => new RegExp(`^(${names.map(escapeRegExp).join('|')})(/.*)?$`);
238
+
239
+ /** @param {string} text */
240
+ function escapeRegExp(text) {
241
+ return text.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&');
242
+ }
243
+
244
+ /**
245
+ * The file an esbuild message names: a page file is named with its
246
+ * namespace (`astryx-page:/…/page.tsx`), and the mount is the render's own,
247
+ * so it names none.
248
+ * @param {string} file
249
+ * @returns {string | null}
250
+ */
251
+ function locatedFile(file) {
252
+ if (file.startsWith(`${MOUNT}:`)) return null;
253
+ if (file.startsWith(`${PAGE}:`)) return file.slice(PAGE.length + 1);
254
+ return path.resolve(file);
255
+ }
256
+
257
+ /** @param {string} file */
258
+ const loaderFor = file =>
259
+ /\.[cm]?tsx$/.test(file) ? 'tsx' : /\.[cm]?ts$/.test(file) ? 'ts' : 'jsx';
260
+
261
+ /**
262
+ * Reads a carried file from the page's embedded source, once, by its
263
+ * SHA-256, as a data: URI with the `prefix` it needs (`data:image/png;base64`).
264
+ */
265
+ const CARRIED_SOURCE = `let files;
266
+ export function carried(sha256, prefix) {
267
+ if (files === undefined) {
268
+ files = new Map();
269
+ // The CLI writes its source block last, as readSourceBlock reads it.
270
+ const blocks = document.querySelectorAll('script[type="${SOURCE_TYPE}"]');
271
+ const block = blocks[blocks.length - 1];
272
+ for (const file of block ? JSON.parse(block.textContent).files : []) files.set(file.sha256, file.base64);
273
+ }
274
+ return prefix + ',' + (files.get(sha256) ?? '');
275
+ }
276
+ `;
277
+
278
+ /** Files a package may import for their address; the page's own are inlined before esbuild sees them. */
279
+ const ASSET_LOADERS = Object.fromEntries(
280
+ [
281
+ '.png',
282
+ '.jpg',
283
+ '.jpeg',
284
+ '.gif',
285
+ '.webp',
286
+ '.avif',
287
+ '.svg',
288
+ '.ico',
289
+ '.woff',
290
+ '.woff2',
291
+ '.ttf',
292
+ '.otf',
293
+ '.mp3',
294
+ '.mp4',
295
+ '.webm',
296
+ ].map(ext => [ext, /** @type {const} */ ('dataurl')]),
297
+ );
298
+
299
+ /**
300
+ * Why the page's script cannot run in one file.
301
+ */
302
+ export class BundleError extends Error {
303
+ /**
304
+ * @param {string} message
305
+ * @param {Record<string, unknown>} [detail]
306
+ * @param {unknown} [compile] the error of one of the page's own files that
307
+ * does not compile, which the render reports as a static import's
308
+ * @param {{source: string, line: number, names: string[], module?: string}} [missingExport]
309
+ * a named import or a package subpath that its module does not export:
310
+ * the page's file that imports it, the line, the names and the module
311
+ */
312
+ constructor(message, detail = {}, compile = undefined, missingExport = undefined) {
313
+ super(message);
314
+ this.detail = detail;
315
+ this.compile = compile;
316
+ this.missingExport = missingExport;
317
+ }
318
+ }
319
+
320
+ /**
321
+ * Text that runs the same as `code` and cannot end its `<script>` element or
322
+ * be read as the render's embedded source. `</script` and `<!--` only appear
323
+ * in strings, template literals and regular expressions, where `\x3C` is the
324
+ * same `<`.
325
+ * @param {string} code
326
+ */
327
+ export function scriptSafe(code) {
328
+ return code
329
+ .replace(/<(?=\/script)/gi, '\\x3C')
330
+ .replace(/<!--/g, '\\x3C!--')
331
+ .replace(/x-astryx-source/g, 'x-astryx\\x2dsource');
332
+ }
333
+
334
+ /**
335
+ * Build the page's script.
336
+ * @param {{
337
+ * esbuild: any,
338
+ * entry: string,
339
+ * source: (file: string) => {contents: string, loader: 'tsx' | 'ts' | 'jsx'} | null,
340
+ * isPageFile: (file: string) => boolean,
341
+ * resolveFile: (name: string, dir: string) => string | null,
342
+ * packageDir: (name: string, importerDir: string) => string | null,
343
+ * builtin: (name: string) => boolean,
344
+ * describe: (file: string) => string,
345
+ * oneCopy?: string[],
346
+ * }} options
347
+ * `source` compiles one of the page's own files as the server compiled it
348
+ * (null for any other file, which esbuild loads); `isPageFile` tells the
349
+ * files `source` compiles (the page's own, and a module outside
350
+ * node_modules that the project's path aliases reach), which alone go
351
+ * through the build's plugin; `resolveFile` finds a relative import of one of them with
352
+ * the extensions the server tries; `packageDir`
353
+ * names the folder a package import resolves from when it must come from
354
+ * the copy the server loaded (React outside a project), else null;
355
+ * `builtin` tells a Node built-in; `describe` names a file for a message;
356
+ * `oneCopy` names the packages every module, a package's too, takes from
357
+ * the one copy `packageDir` names (React outside a project).
358
+ * @returns {Promise<{code: string, modules: number}>}
359
+ */
360
+ export async function bundleForBrowser({
361
+ esbuild,
362
+ entry,
363
+ source,
364
+ isPageFile,
365
+ resolveFile,
366
+ packageDir,
367
+ builtin,
368
+ describe,
369
+ oneCopy = [],
370
+ }) {
371
+ // A page whose script throws, in render or in an effect (a cookie write in
372
+ // a frame that blocks cookies, say), keeps its first paint: React would
373
+ // empty the root.
374
+ const mount =
375
+ `import 'astryx:viewer';import {Component, createElement} from 'react';import {createRoot} from 'react-dom/client';import Page from ${JSON.stringify(entry)};` +
376
+ `${IN_A_VIEWER}` +
377
+ `const root = document.getElementById(${JSON.stringify(ROOT_ID)});const painted = root.innerHTML;` +
378
+ `class FirstPaint extends Component {constructor(props) {super(props);this.state = {failed: false};}` +
379
+ `static getDerivedStateFromError() {return {failed: true};}` +
380
+ `render() {return this.state.failed ? createElement('div', {style: {display: 'contents'}, dangerouslySetInnerHTML: {__html: painted}}) : this.props.children;}}` +
381
+ `createRoot(root).render(createElement(FirstPaint, null, createElement(Page)));`;
382
+ // Only the page's own files and the mount go through this plugin: esbuild
383
+ // resolves and loads every package file itself, which keeps the build fast.
384
+ // A package file comes back here only for an import every module must take
385
+ // from one copy (`oneCopy`) or for a Node module, which is refused.
386
+ /** @param {any} args */
387
+ const resolveImport = async args => {
388
+ if (args.pluginData?.astryx) return undefined;
389
+ const name = args.path.split('?')[0];
390
+ if (name.startsWith('.') || path.isAbsolute(name)) {
391
+ const file = resolveFile(name, args.resolveDir);
392
+ if (!file) return undefined;
393
+ return isPageFile(file) ? {path: file, namespace: PAGE} : {path: file};
394
+ }
395
+ const resolveDir = packageDir(name, args.resolveDir) ?? args.resolveDir;
396
+ // A package can map a Node module for the browser (`"browser": {"fs":
397
+ // false}`), and an installed package can stand in for one (`events`),
398
+ // so a Node module is refused only when nothing resolves it.
399
+ const found = await build.resolve(name, {
400
+ kind: args.kind,
401
+ resolveDir,
402
+ importer: args.importer,
403
+ pluginData: {astryx: true},
404
+ });
405
+ // A module a package maps to `false` comes back with no namespace:
406
+ // esbuild's own resolution gives it as an empty module.
407
+ if (found.errors.length === 0) {
408
+ if (found.namespace === '') return undefined;
409
+ return found.namespace === 'file' && isPageFile(found.path)
410
+ ? {...found, namespace: PAGE}
411
+ : found;
412
+ }
413
+ if (builtin(name)) {
414
+ return {
415
+ errors: [
416
+ {
417
+ text: `${describe(args.importer && args.namespace !== MOUNT ? args.importer : entry)} loads ${name}, which is part of Node and not of a browser.`,
418
+ },
419
+ ],
420
+ };
421
+ }
422
+ return {errors: found.errors};
423
+ };
424
+ /** @type {any} */
425
+ let build;
426
+ /** @type {any} */
427
+ const plugin = {
428
+ name: 'astryx-page',
429
+ setup(/** @type {any} */ setupBuild) {
430
+ build = setupBuild;
431
+ // An image the page imports comes from the embedded source, which
432
+ // carries it already, so the script holds no copy of its own.
433
+ build.onResolve({filter: /^astryx:carried$/}, () => ({
434
+ path: 'carried',
435
+ namespace: 'astryx-carried',
436
+ }));
437
+ build.onLoad({filter: /.*/, namespace: 'astryx-carried'}, () => ({
438
+ contents: CARRIED_SOURCE,
439
+ loader: 'js',
440
+ }));
441
+ build.onResolve({filter: /^astryx:mount$/}, () => ({path: 'mount', namespace: MOUNT}));
442
+ build.onResolve({filter: /^astryx:viewer$/, namespace: MOUNT}, () => ({path: 'viewer', namespace: VIEWER}));
443
+ build.onLoad({filter: /.*/, namespace: VIEWER}, () => ({contents: `${VIEWER_STORAGE}\n${VIEWER_CLIPBOARD}`, loader: 'js'}));
444
+ build.onLoad({filter: /.*/, namespace: MOUNT}, () => ({
445
+ contents: mount,
446
+ loader: 'js',
447
+ resolveDir: path.dirname(entry),
448
+ }));
449
+ build.onResolve({filter: /.*/, namespace: MOUNT}, resolveImport);
450
+ build.onResolve({filter: /.*/, namespace: PAGE}, resolveImport);
451
+ if (oneCopy.length > 0) {
452
+ build.onResolve({filter: packageFilter(oneCopy)}, resolveImport);
453
+ }
454
+ build.onResolve({filter: NODE_MODULE}, resolveImport);
455
+ build.onLoad({filter: /.*/, namespace: PAGE}, (/** @type {any} */ args) => {
456
+ const resolveDir = path.dirname(args.path);
457
+ // Stylesheets are already in the page.
458
+ if (/\.(css|scss|sass|less)$/i.test(args.path)) return {contents: '', loader: 'js'};
459
+ if (/\.json$/i.test(args.path)) {
460
+ return {contents: fs.readFileSync(args.path), loader: 'json', resolveDir};
461
+ }
462
+ const asset = ASSET_LOADERS[path.extname(args.path).toLowerCase()];
463
+ if (asset) return {contents: fs.readFileSync(args.path), loader: asset, resolveDir};
464
+ try {
465
+ const compiled = source(args.path);
466
+ return compiled
467
+ ? {...compiled, resolveDir}
468
+ : {contents: fs.readFileSync(args.path), loader: loaderFor(args.path), resolveDir};
469
+ } catch (e) {
470
+ // A page file that does not compile, such as one the page loads
471
+ // lazily: the render reports it as a static import's.
472
+ return {errors: [{text: describe(args.path), detail: {compile: e}}]};
473
+ }
474
+ });
475
+ // A package's own stylesheet import adds nothing to the script.
476
+ build.onLoad({filter: /\.(css|scss|sass|less)$/i}, () => ({
477
+ contents: '',
478
+ loader: 'js',
479
+ }));
480
+ },
481
+ };
482
+ /** @type {any} */
483
+ let result;
484
+ try {
485
+ result = await esbuild.build({
486
+ entryPoints: ['astryx:mount'],
487
+ bundle: true,
488
+ write: false,
489
+ metafile: true,
490
+ format: 'iife',
491
+ platform: 'browser',
492
+ // Browsers that viewers run; syntax newer than this, such as a class
493
+ // decorator, is lowered.
494
+ target: 'es2022',
495
+ minify: true,
496
+ charset: 'ascii',
497
+ legalComments: 'eof',
498
+ jsx: 'automatic',
499
+ define: {'process.env.NODE_ENV': '"production"'},
500
+ loader: ASSET_LOADERS,
501
+ logLevel: 'silent',
502
+ plugins: [plugin],
503
+ });
504
+ } catch (e) {
505
+ const first = /** @type {any} */ (e)?.errors?.[0];
506
+ if (!first) throw e;
507
+ if (first.detail?.compile) {
508
+ throw new BundleError(first.text, {}, first.detail.compile);
509
+ }
510
+ const located = first.location?.file ? locatedFile(first.location.file) : null;
511
+ // A named import its module does not export, in one of the page's own
512
+ // files: refused as a build refuses it. The worker names the file and
513
+ // the module, as for the same import on the server.
514
+ const noExport = /^No matching export in "[^"]+" for import "([^"]+)"$/.exec(first.text);
515
+ if (noExport && located && isPageFile(located)) {
516
+ throw new BundleError(first.text, {}, undefined, {
517
+ source: located,
518
+ line: first.location.line,
519
+ names: [noExport[1]],
520
+ });
521
+ }
522
+ // A package subpath the package's `exports` do not list, likewise.
523
+ const notes = (first.notes ?? []).map((/** @type {any} */ note) => note.text).join('\n');
524
+ const unexported = /^Could not resolve "[^"]+"$/.test(first.text)
525
+ ? /The path "([^"]+)" is not exported by package "([^"]+)"/.exec(notes)
526
+ : null;
527
+ if (unexported && located && isPageFile(located)) {
528
+ throw new BundleError(first.text, {}, undefined, {
529
+ source: located,
530
+ line: first.location.line,
531
+ names: [unexported[1]],
532
+ module: unexported[2],
533
+ });
534
+ }
535
+ const where = located ? `${describe(located)}:${first.location.line}: ` : '';
536
+ // A message that leads with a file's absolute path names it as the page does.
537
+ const text = stripVTControlCharacters(first.text).replace(
538
+ /^(\S+): /,
539
+ (lead, file) => (path.isAbsolute(file) ? `${describe(file)}: ` : lead),
540
+ );
541
+ throw new BundleError(
542
+ `The page's script cannot be built for the browser: ${where}${text}`,
543
+ {
544
+ ...(located ? {module: describe(located), line: first.location.line} : {}),
545
+ },
546
+ );
547
+ } finally {
548
+ esbuild.stop?.();
549
+ }
550
+ const code = scriptSafe(result.outputFiles[0].text);
551
+ try {
552
+ // Parsed here, so a script that would not run never reaches the file.
553
+ new vm.Script(code, {filename: 'page-script.js'});
554
+ } catch (e) {
555
+ throw new BundleError(
556
+ `The page's script could not be written safely into the file: ${/** @type {Error} */ (e).message}`,
557
+ );
558
+ }
559
+ // The modules the script holds: those esbuild kept any of.
560
+ const output = Object.values(result.metafile?.outputs ?? {})[0];
561
+ const modules = Object.values(output?.inputs ?? {}).filter(
562
+ (/** @type {any} */ input) => input.bytesInOutput > 0,
563
+ ).length;
564
+ return {code, modules};
565
+ }
@@ -11,19 +11,25 @@
11
11
  * or null. `whole` says whether the text is drawn whole once every element
12
12
  * of that part keeps its width (`flex-shrink: 0`), measured by applying it
13
13
  * in the page and taking it back.
14
+ * A word drawn broken across lines inside it ("Headi" then "ng": a box
15
+ * narrower than the word) comes back too, the word as its `text`, with
16
+ * `broken`; a word broken where it may break (at a hyphen, a slash, a soft
17
+ * hyphen) is not counted.
14
18
  * Runs in the page: it uses nothing from outside its own body.
15
- * @returns {Array<{part: string | null, text: string, whole: boolean}>}
19
+ * @returns {Array<{part: string | null, text: string, whole: boolean, broken?: boolean}>}
16
20
  */
17
21
  export function cutShortText(): Array<{
18
22
  part: string | null;
19
23
  text: string;
20
24
  whole: boolean;
25
+ broken?: boolean;
21
26
  }>;
22
27
  /**
23
28
  * @file The text a picture's page draws cut short, measured in the page.
24
29
  * @input None: `cutShortText` runs in the page the picture is taken of.
25
30
  * @output `cutShortText`: each text the browser draws cut short (an ellipsis
26
31
  * or a line clamp, or text drawn past the side of a box that clips it),
32
+ * and each word it breaks across two lines inside the word (`broken`),
27
33
  * with the part it sits in and whether keeping that part's width
28
34
  * (`flex-shrink: 0` on it, the line the editor offers) draws it whole;
29
35
  * `CUT_SHORT_PREFIX`, the line prefix a picture script prints it after.
@@ -5,6 +5,7 @@
5
5
  * @input None: `cutShortText` runs in the page the picture is taken of.
6
6
  * @output `cutShortText`: each text the browser draws cut short (an ellipsis
7
7
  * or a line clamp, or text drawn past the side of a box that clips it),
8
+ * and each word it breaks across two lines inside the word (`broken`),
8
9
  * with the part it sits in and whether keeping that part's width
9
10
  * (`flex-shrink: 0` on it, the line the editor offers) draws it whole;
10
11
  * `CUT_SHORT_PREFIX`, the line prefix a picture script prints it after.
@@ -28,8 +29,12 @@ export const CUT_SHORT_PREFIX = 'astryx-cut-short:';
28
29
  * or null. `whole` says whether the text is drawn whole once every element
29
30
  * of that part keeps its width (`flex-shrink: 0`), measured by applying it
30
31
  * in the page and taking it back.
32
+ * A word drawn broken across lines inside it ("Headi" then "ng": a box
33
+ * narrower than the word) comes back too, the word as its `text`, with
34
+ * `broken`; a word broken where it may break (at a hyphen, a slash, a soft
35
+ * hyphen) is not counted.
31
36
  * Runs in the page: it uses nothing from outside its own body.
32
- * @returns {Array<{part: string | null, text: string, whole: boolean}>}
37
+ * @returns {Array<{part: string | null, text: string, whole: boolean, broken?: boolean}>}
33
38
  */
34
39
  export function cutShortText() {
35
40
  /** @param {Element} el */
@@ -92,13 +97,43 @@ export function cutShortText() {
92
97
  };
93
98
  /** @param {HTMLElement} el */
94
99
  const cutShort = el => ellipsized(el) || clipped(el);
95
- /** @type {Array<{el: HTMLElement, part: string | null, text: string}>} */
100
+ /**
101
+ * The words of an element's own text drawn on more than one line: the
102
+ * boxes of a word's letters sit on lines with different tops.
103
+ * @param {HTMLElement} el
104
+ * @returns {string[]}
105
+ */
106
+ const brokenWords = el => {
107
+ /** @type {string[]} */
108
+ const out = [];
109
+ for (const n of el.childNodes) {
110
+ if (n.nodeType !== 3) continue;
111
+ const s = n.textContent ?? '';
112
+ for (const m of s.matchAll(/\S+/g)) {
113
+ const word = m[0];
114
+ if (word.length < 3 || /[-/\u00AD\u200B\u2010-\u2014]/.test(word))
115
+ continue;
116
+ const range = document.createRange();
117
+ range.setStart(n, m.index ?? 0);
118
+ range.setEnd(n, (m.index ?? 0) + word.length);
119
+ const tops = [...range.getClientRects()]
120
+ .filter(r => r.width > 0 && r.height > 0)
121
+ .map(r => Math.round(r.top));
122
+ if (tops.some(t => Math.abs(t - tops[0]) > 2)) out.push(word);
123
+ }
124
+ }
125
+ return out;
126
+ };
127
+ /** @type {Array<{el: HTMLElement, part: string | null, text: string, broken?: boolean}>} */
96
128
  const found = [];
97
129
  for (const el of document.body.querySelectorAll('*')) {
98
130
  if (!(el instanceof HTMLElement)) continue;
99
131
  const text = (el.textContent ?? '').replace(/\s+/g, ' ').trim();
100
- if (text && cutShort(el) && drawn(el))
101
- found.push({el, part: partOf(el), text});
132
+ if (!text || !drawn(el)) continue;
133
+ if (cutShort(el)) found.push({el, part: partOf(el), text});
134
+ else
135
+ for (const word of brokenWords(el))
136
+ found.push({el, part: partOf(el), text: word, broken: true});
102
137
  }
103
138
  /** Whether each text is whole with its part's width kept. @type {Map<string | null, boolean>} */
104
139
  const whole = new Map();
@@ -112,13 +147,18 @@ export function cutShortText() {
112
147
  document.head.append(keep);
113
148
  whole.set(
114
149
  part,
115
- found.filter(f => f.part === part).every(f => !cutShort(f.el)),
150
+ found
151
+ .filter(f => f.part === part)
152
+ .every(f =>
153
+ f.broken ? !brokenWords(f.el).includes(f.text) : !cutShort(f.el),
154
+ ),
116
155
  );
117
156
  keep.remove();
118
157
  }
119
- return found.map(({part, text}) => ({
158
+ return found.map(({part, text, broken}) => ({
120
159
  part,
121
160
  text,
122
161
  whole: whole.get(part) ?? false,
162
+ ...(broken ? {broken: true} : {}),
123
163
  }));
124
164
  }