@astryxdesign/cli 0.7.17-canary.gffd1c8e → 0.7.17

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 (1112) hide show
  1. package/CHANGELOG.md +1877 -0
  2. package/README.md +90 -85
  3. package/api/build/_adapter.d.mts +51 -0
  4. package/api/build/_adapter.mjs +133 -8
  5. package/api/build/build.doc.mjs +3 -3
  6. package/api/build/build.mjs +1 -1
  7. package/api/build/build.type.d.mts +1 -1
  8. package/api/build/build.type.mjs +2 -2
  9. package/api/build/help/help.d.mts +15 -14
  10. package/api/build/help/help.mjs +65 -6
  11. package/api/build/kit/kit.mjs +1 -1
  12. package/api/build/kit/start.mjs +1 -1
  13. package/api/component/_adapter.d.mts +28 -4
  14. package/api/component/_adapter.mjs +79 -45
  15. package/api/component/component.d.mts +1 -1
  16. package/api/component/component.mjs +18 -7
  17. package/api/component/detail/blocks/blocks.mjs +1 -2
  18. package/api/component/detail/showcase/showcase.mjs +19 -8
  19. package/api/discover/_adapter.d.mts +68 -5
  20. package/api/discover/_adapter.mjs +311 -63
  21. package/api/discover/_catalog-view.d.mts +22 -0
  22. package/api/discover/_catalog-view.mjs +30 -1
  23. package/api/discover/_icon-set-coverage.d.mts +22 -0
  24. package/api/discover/_icon-set-coverage.mjs +32 -0
  25. package/api/discover/detail/detail.d.mts +6 -3
  26. package/api/discover/detail/detail.mjs +14 -6
  27. package/api/discover/detail/doc/doc.mjs +1 -1
  28. package/api/discover/detail/item/item.d.mts +11 -1
  29. package/api/discover/detail/item/item.mjs +29 -8
  30. package/api/discover/discover.d.mts +36 -0
  31. package/api/discover/discover.doc.mjs +1 -1
  32. package/api/discover/discover.mjs +205 -28
  33. package/api/discover/discover.type.d.mts +33 -7
  34. package/api/discover/discover.type.mjs +21 -7
  35. package/api/discover/search/search.d.mts +22 -0
  36. package/api/discover/search/search.mjs +293 -70
  37. package/api/docs/_adapter.d.mts +92 -1
  38. package/api/docs/_adapter.mjs +264 -14
  39. package/api/docs/docs.d.mts +4 -2
  40. package/api/docs/docs.doc.mjs +10 -0
  41. package/api/docs/docs.mjs +25 -5
  42. package/api/docs/docs.type.d.mts +48 -0
  43. package/api/docs/docs.type.mjs +26 -0
  44. package/api/docs/skills/skills.d.mts +51 -0
  45. package/api/docs/skills/skills.mjs +216 -0
  46. package/api/doctor/_adapter.d.mts +254 -9
  47. package/api/doctor/_adapter.mjs +1228 -50
  48. package/api/doctor/built-checks.d.mts +39 -3
  49. package/api/doctor/built-checks.mjs +203 -7
  50. package/api/doctor/doctor.d.mts +205 -4
  51. package/api/doctor/doctor.doc.mjs +4 -4
  52. package/api/doctor/doctor.mjs +962 -22
  53. package/api/doctor/doctor.type.d.mts +6 -1
  54. package/api/doctor/doctor.type.mjs +3 -1
  55. package/api/doctor/theme-checks.d.mts +20 -1
  56. package/api/doctor/theme-checks.mjs +280 -8
  57. package/api/error.d.mts +12 -1
  58. package/api/error.mjs +18 -6
  59. package/api/icon/_adapter.d.mts +11 -1
  60. package/api/icon/_adapter.mjs +22 -1
  61. package/api/icon/_authoring.mjs +21 -7
  62. package/api/icon/add/add.mjs +1 -1
  63. package/api/icon/definitions/definitions.mjs +19 -8
  64. package/api/icon/icon.doc.mjs +3 -3
  65. package/api/icon/icon.type.d.mts +49 -2
  66. package/api/icon/icon.type.mjs +23 -4
  67. package/api/icon/iconMap.doc.mjs +2 -2
  68. package/api/icon/list/list.mjs +4 -5
  69. package/api/icon/map/map.mjs +13 -4
  70. package/api/icon/search/icon-index.mjs +4 -1
  71. package/api/icon/search/search.d.mts +28 -7
  72. package/api/icon/search/search.mjs +177 -26
  73. package/api/init/_adapter.d.mts +87 -3
  74. package/api/init/_adapter.mjs +264 -16
  75. package/api/init/init.d.mts +2 -2
  76. package/api/init/init.doc.mjs +29 -5
  77. package/api/init/init.mjs +149 -10
  78. package/api/init/init.type.d.mts +75 -9
  79. package/api/init/init.type.mjs +32 -4
  80. package/api/init/remove/remove.d.mts +7 -4
  81. package/api/init/remove/remove.mjs +124 -26
  82. package/api/init/run/run.d.mts +38 -3
  83. package/api/init/run/run.mjs +366 -39
  84. package/api/integration/_adapter.d.mts +16 -0
  85. package/api/integration/_adapter.mjs +45 -1
  86. package/api/integration/integrationCheck.doc.mjs +1 -1
  87. package/api/integration/pack-check.d.mts +2 -1
  88. package/api/integration/pack-check.mjs +10 -18
  89. package/api/integration/validate-integration.d.mts +5 -2
  90. package/api/integration/validate-integration.mjs +81 -14
  91. package/api/integration/validate-integration.type.d.mts +9 -4
  92. package/api/integration/validate-integration.type.mjs +9 -4
  93. package/api/integration/validateIntegration.doc.mjs +4 -2
  94. package/api/render/_adapter.d.mts +6 -2
  95. package/api/render/_adapter.mjs +301 -51
  96. package/api/render/render.doc.d.mts +1 -1
  97. package/api/render/render.doc.mjs +20 -10
  98. package/api/render/render.mjs +16 -13
  99. package/api/render/render.type.d.mts +57 -10
  100. package/api/render/render.type.mjs +26 -13
  101. package/api/search/ORDERING.md +3 -3
  102. package/api/search/_adapter.d.mts +31 -0
  103. package/api/search/_adapter.mjs +107 -15
  104. package/api/search/_candidate-score.d.mts +12 -4
  105. package/api/search/_candidate-score.mjs +94 -16
  106. package/api/search/_cards.json +4 -1
  107. package/api/search/_entries.d.mts +8 -3
  108. package/api/search/_entries.mjs +109 -12
  109. package/api/search/_fit-order.d.mts +8 -4
  110. package/api/search/_fit-order.mjs +35 -7
  111. package/api/search/_gather-docs.mjs +71 -28
  112. package/api/search/_gather-templates.mjs +7 -2
  113. package/api/search/_icons.d.mts +50 -0
  114. package/api/search/_icons.mjs +85 -0
  115. package/api/search/_lexical.d.mts +14 -1
  116. package/api/search/_lexical.mjs +240 -12
  117. package/api/search/_main-searcher.mjs +1 -1
  118. package/api/search/_named-keywords.d.mts +6 -3
  119. package/api/search/_named-keywords.mjs +70 -19
  120. package/api/search/_order.d.mts +27 -12
  121. package/api/search/_order.mjs +132 -51
  122. package/api/search/_result.d.mts +30 -0
  123. package/api/search/_result.mjs +38 -0
  124. package/api/search/_score.d.mts +20 -6
  125. package/api/search/_score.mjs +96 -16
  126. package/api/search/_titles.d.mts +14 -0
  127. package/api/search/_titles.mjs +16 -3
  128. package/api/search/_words.d.mts +8 -0
  129. package/api/search/_words.mjs +26 -1
  130. package/api/search/search-index.mjs +23 -12
  131. package/api/search/search.d.mts +3 -1
  132. package/api/search/search.doc.mjs +5 -4
  133. package/api/search/search.mjs +69 -26
  134. package/api/search/search.type.d.mts +55 -1
  135. package/api/search/search.type.mjs +35 -1
  136. package/api/swizzle/_adapter.d.mts +1 -1
  137. package/api/swizzle/_adapter.mjs +1 -5
  138. package/api/swizzle/_moduleGraph.d.mts +0 -6
  139. package/api/swizzle/_moduleGraph.mjs +0 -12
  140. package/api/swizzle/copy/copy.mjs +1 -1
  141. package/api/template/_adapter.d.mts +46 -0
  142. package/api/template/_adapter.mjs +198 -2
  143. package/api/template/cdn/cdn.mjs +5 -3
  144. package/api/template/copy/copy.d.mts +12 -2
  145. package/api/template/copy/copy.mjs +95 -21
  146. package/api/template/list/list.mjs +1 -2
  147. package/api/template/show/show.d.mts +10 -3
  148. package/api/template/show/show.mjs +17 -6
  149. package/api/template/skeleton/skeleton.mjs +1 -2
  150. package/api/template/template.doc.mjs +3 -3
  151. package/api/template/template.mjs +37 -7
  152. package/api/template/template.type.d.mts +3 -0
  153. package/api/template/template.type.mjs +5 -2
  154. package/api/theme/_adapter.d.mts +28 -2
  155. package/api/theme/_adapter.mjs +675 -17
  156. package/api/theme/_app-provider.d.mts +42 -0
  157. package/api/theme/_app-provider.mjs +61 -27
  158. package/api/theme/_shared-source.d.mts +33 -0
  159. package/api/theme/_shared-source.mjs +348 -0
  160. package/api/theme/add/add.d.mts +3 -0
  161. package/api/theme/add/add.mjs +21 -4
  162. package/api/theme/build/build.d.mts +57 -30
  163. package/api/theme/build/build.mjs +403 -441
  164. package/api/theme/build/core-interception.d.mts +10 -0
  165. package/api/theme/build/core-interception.mjs +24 -0
  166. package/api/theme/build/family.mjs +4 -2
  167. package/api/theme/build/import-specifier.d.mts +14 -0
  168. package/api/theme/build/import-specifier.mjs +36 -0
  169. package/api/theme/build/null-values.d.mts +22 -0
  170. package/api/theme/build/null-values.mjs +110 -21
  171. package/api/theme/build/self-contained.mjs +32 -11
  172. package/api/theme/build/setting-effects.d.mts +254 -0
  173. package/api/theme/build/setting-effects.mjs +1065 -0
  174. package/api/theme/build/style-keys.d.mts +33 -0
  175. package/api/theme/build/style-keys.mjs +154 -0
  176. package/api/theme/build/theme-object.d.mts +47 -0
  177. package/api/theme/build/theme-object.mjs +144 -0
  178. package/api/theme/eject/eject.mjs +6 -1
  179. package/api/theme/palette/generate/color.d.mts +41 -9
  180. package/api/theme/palette/generate/color.mjs +108 -39
  181. package/api/theme/palette/generate/generate.mjs +10 -0
  182. package/api/theme/palette/generate/generator.d.mts +45 -27
  183. package/api/theme/palette/generate/generator.mjs +330 -156
  184. package/api/theme/palette/generate/mapping.d.mts +456 -0
  185. package/api/theme/palette/generate/mapping.mjs +1903 -0
  186. package/api/theme/palette/generate/newer-recipe.d.mts +28 -0
  187. package/api/theme/palette/generate/newer-recipe.mjs +87 -0
  188. package/api/theme/palette/generate/types.d.mts +270 -0
  189. package/api/theme/palette/generate/types.mjs +123 -0
  190. package/api/theme/theme.d.mts +25 -4
  191. package/api/theme/theme.mjs +55 -5
  192. package/api/theme/theme.type.d.mts +71 -2
  193. package/api/theme/theme.type.mjs +37 -5
  194. package/api/theme/themeAdd.doc.mjs +3 -2
  195. package/api/theme/themeBuild.doc.mjs +3 -3
  196. package/api/theme/themeEject.doc.mjs +1 -1
  197. package/api/theme/themeRemove.doc.mjs +1 -1
  198. package/api/theme/themeTargets.doc.mjs +1 -1
  199. package/api/theme-edit/_catalog.mjs +1 -1
  200. package/api/theme-edit/_check.mjs +129 -45
  201. package/api/theme-edit/_color.d.mts +2 -74
  202. package/api/theme-edit/_color.mjs +33 -869
  203. package/api/theme-edit/_context.d.mts +3 -1
  204. package/api/theme-edit/_context.mjs +16 -3
  205. package/api/theme-edit/_css.d.mts +4 -35
  206. package/api/theme-edit/_css.mjs +10 -91
  207. package/api/theme-edit/_edit.mjs +244 -32
  208. package/api/theme-edit/_how-question.d.mts +1 -0
  209. package/api/theme-edit/_how-question.mjs +1188 -52
  210. package/api/theme-edit/_how.mjs +19 -3
  211. package/api/theme-edit/_missed.d.mts +2 -1
  212. package/api/theme-edit/_missed.mjs +21 -2
  213. package/api/theme-edit/_normal.d.mts +5 -2
  214. package/api/theme-edit/_normal.mjs +11 -1
  215. package/api/theme-edit/_palette.d.mts +26 -75
  216. package/api/theme-edit/_palette.mjs +242 -1384
  217. package/api/theme-edit/_part-words.mjs +13 -3
  218. package/api/theme-edit/_parts.d.mts +8 -2
  219. package/api/theme-edit/_parts.mjs +56 -11
  220. package/api/theme-edit/_preview-app.d.mts +16 -0
  221. package/api/theme-edit/_preview-app.mjs +47 -15
  222. package/api/theme-edit/_preview.mjs +49 -22
  223. package/api/theme-edit/_project.d.mts +14 -2
  224. package/api/theme-edit/_project.mjs +25 -3
  225. package/api/theme-edit/_settings.d.mts +3 -2
  226. package/api/theme-edit/_settings.mjs +166 -45
  227. package/api/theme-edit/_tables.d.mts +3 -11
  228. package/api/theme-edit/_tables.mjs +21 -33
  229. package/api/theme-edit/theme-edit.type.d.mts +7 -1
  230. package/api/theme-edit/theme-edit.type.mjs +3 -2
  231. package/api/upgrade/_adapter.d.mts +38 -0
  232. package/api/upgrade/_adapter.mjs +274 -3
  233. package/api/upgrade/run/run.mjs +4 -0
  234. package/api/upgrade/upgrade.mjs +1 -1
  235. package/api/upgrade/upgrade.type.d.mts +46 -7
  236. package/api/upgrade/upgrade.type.mjs +24 -9
  237. package/assets/codemods/registry.mjs +1 -0
  238. package/assets/codemods/transforms/next/index.mjs +1 -11
  239. package/assets/codemods/transforms/v0.7.17/index.mjs +28 -0
  240. package/assets/codemods/transforms/v0.7.17/migrate-item-swipe-actions-to-swipe.mjs +2160 -0
  241. package/assets/codemods/transforms/v0.7.17/preserve-chat-radius.mjs +515 -0
  242. package/assets/component-list.generated.json +1 -1
  243. package/assets/discover/official-packages.json +72 -0
  244. package/assets/docs/author-a-theme.doc.mjs +7 -4
  245. package/assets/docs/getting-started.doc.mjs +1 -1
  246. package/assets/docs/principles.doc.dense.mjs +1 -1
  247. package/assets/docs/principles.doc.mjs +1 -1
  248. package/assets/docs/principles.doc.zh.mjs +1 -1
  249. package/assets/docs/styling-overview.doc.mjs +5 -1
  250. package/assets/docs/tree/agent-guidance.doc.mjs +33 -2
  251. package/assets/docs/tree/check-the-props.doc.mjs +1 -1
  252. package/assets/docs/tree/checks.doc.mjs +1 -1
  253. package/assets/docs/tree/computer-integrations.doc.mjs +1 -1
  254. package/assets/docs/tree/doc-syntax.doc.mjs +1 -1
  255. package/assets/docs/tree/export-pages.doc.mjs +164 -0
  256. package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
  257. package/assets/docs/tree/host-entry.doc.mjs +4 -0
  258. package/assets/docs/tree/i18n-library-integration.doc.mjs +7 -3
  259. package/assets/docs/tree/icon-sets.doc.mjs +85 -9
  260. package/assets/docs/tree/layout.doc.mjs +16 -5
  261. package/assets/docs/tree/problems.doc.mjs +2 -2
  262. package/assets/docs/tree/responsive.doc.mjs +2 -2
  263. package/assets/docs/tree/scaffold.doc.mjs +1 -0
  264. package/assets/docs/tree/share-a-page.doc.mjs +14 -16
  265. package/assets/docs/tree/skill-places.doc.mjs +91 -0
  266. package/assets/docs/tree/styling.doc.mjs +41 -3
  267. package/assets/docs/tree/template-grading-rubric.doc.mjs +1 -1
  268. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  269. package/assets/docs/tree/tokens-and-setup.doc.mjs +2 -4
  270. package/assets/docs/tree/tokens-color.doc.mjs +2 -2
  271. package/assets/docs/tree/tokens-radius.doc.mjs +1 -1
  272. package/assets/docs/tree/tokens.doc.mjs +32 -0
  273. package/assets/docs/tree/troubleshooting.doc.mjs +8 -0
  274. package/assets/docs/tree/typography.doc.mjs +31 -2
  275. package/assets/docs/use-a-theme.doc.mjs +4 -0
  276. package/assets/docs/working-with-ai.doc.mjs +4 -4
  277. package/assets/docs-routes.generated.json +1 -1
  278. package/assets/docs.generated.json +2 -2
  279. package/assets/icons/definitions/alert.doc.mjs +9 -0
  280. package/assets/icons/definitions/alignBottom.doc.mjs +1 -0
  281. package/assets/icons/definitions/alignCenter.doc.mjs +1 -0
  282. package/assets/icons/definitions/alignEnd.doc.mjs +1 -0
  283. package/assets/icons/definitions/alignJustify.doc.mjs +1 -0
  284. package/assets/icons/definitions/alignMiddle.doc.mjs +1 -0
  285. package/assets/icons/definitions/alignStart.doc.mjs +1 -0
  286. package/assets/icons/definitions/alignTop.doc.mjs +1 -0
  287. package/assets/icons/definitions/arrowDown.doc.mjs +1 -0
  288. package/assets/icons/definitions/arrowLeft.doc.mjs +1 -0
  289. package/assets/icons/definitions/arrowRight.doc.mjs +1 -0
  290. package/assets/icons/definitions/arrowUp.doc.mjs +1 -0
  291. package/assets/icons/definitions/arrowsUpDown.doc.mjs +1 -0
  292. package/assets/icons/definitions/bank.doc.mjs +1 -0
  293. package/assets/icons/definitions/block.doc.mjs +9 -0
  294. package/assets/icons/definitions/bold.doc.mjs +1 -0
  295. package/assets/icons/definitions/bookmark.doc.mjs +1 -0
  296. package/assets/icons/definitions/bookmarkAdd.doc.mjs +1 -0
  297. package/assets/icons/definitions/cart.doc.mjs +1 -0
  298. package/assets/icons/definitions/channel.doc.mjs +9 -0
  299. package/assets/icons/definitions/check.doc.mjs +1 -0
  300. package/assets/icons/definitions/checkDouble.doc.mjs +1 -0
  301. package/assets/icons/definitions/checklist.doc.mjs +9 -0
  302. package/assets/icons/definitions/chevronDown.doc.mjs +1 -0
  303. package/assets/icons/definitions/chevronLeft.doc.mjs +1 -0
  304. package/assets/icons/definitions/chevronRight.doc.mjs +1 -0
  305. package/assets/icons/definitions/chevronUp.doc.mjs +1 -0
  306. package/assets/icons/definitions/chevronsLeft.doc.mjs +1 -0
  307. package/assets/icons/definitions/chevronsRight.doc.mjs +1 -0
  308. package/assets/icons/definitions/clipboard.doc.mjs +1 -0
  309. package/assets/icons/definitions/cloud.doc.mjs +1 -1
  310. package/assets/icons/definitions/collapse.doc.mjs +1 -0
  311. package/assets/icons/definitions/columnSettings.doc.mjs +9 -0
  312. package/assets/icons/definitions/compose.doc.mjs +1 -0
  313. package/assets/icons/definitions/conversation.doc.mjs +1 -0
  314. package/assets/icons/definitions/copy.doc.mjs +1 -0
  315. package/assets/icons/definitions/copyText.doc.mjs +9 -0
  316. package/assets/icons/definitions/cornerRadius.doc.mjs +1 -0
  317. package/assets/icons/definitions/create.doc.mjs +9 -0
  318. package/assets/icons/definitions/creditCard.doc.mjs +1 -0
  319. package/assets/icons/definitions/currency.doc.mjs +9 -0
  320. package/assets/icons/definitions/cut.doc.mjs +1 -0
  321. package/assets/icons/definitions/desktop.doc.mjs +1 -0
  322. package/assets/icons/definitions/discount.doc.mjs +1 -0
  323. package/assets/icons/definitions/document.doc.mjs +1 -0
  324. package/assets/icons/definitions/documentSearch.doc.mjs +1 -0
  325. package/assets/icons/definitions/download.doc.mjs +1 -0
  326. package/assets/icons/definitions/error.doc.mjs +1 -0
  327. package/assets/icons/definitions/exitFullScreen.doc.mjs +16 -0
  328. package/assets/icons/definitions/expand.doc.mjs +1 -0
  329. package/assets/icons/definitions/eye.doc.mjs +1 -0
  330. package/assets/icons/definitions/eyeSlash.doc.mjs +1 -0
  331. package/assets/icons/definitions/file.doc.mjs +1 -0
  332. package/assets/icons/definitions/flipHorizontal.doc.mjs +1 -0
  333. package/assets/icons/definitions/flipVertical.doc.mjs +1 -0
  334. package/assets/icons/definitions/folder.doc.mjs +1 -0
  335. package/assets/icons/definitions/folderAdd.doc.mjs +1 -0
  336. package/assets/icons/definitions/fullScreen.doc.mjs +16 -0
  337. package/assets/icons/definitions/globe.doc.mjs +1 -1
  338. package/assets/icons/definitions/groupRows.doc.mjs +9 -0
  339. package/assets/icons/definitions/halftone.doc.mjs +9 -0
  340. package/assets/icons/definitions/help.doc.mjs +9 -0
  341. package/assets/icons/definitions/house.doc.mjs +9 -0
  342. package/assets/icons/definitions/info.doc.mjs +1 -0
  343. package/assets/icons/definitions/italic.doc.mjs +1 -0
  344. package/assets/icons/definitions/listView.doc.mjs +9 -0
  345. package/assets/icons/definitions/lock.doc.mjs +1 -0
  346. package/assets/icons/definitions/lowercase.doc.mjs +1 -0
  347. package/assets/icons/definitions/mail.doc.mjs +1 -1
  348. package/assets/icons/definitions/media.doc.mjs +9 -0
  349. package/assets/icons/definitions/message.doc.mjs +2 -1
  350. package/assets/icons/definitions/mobile.doc.mjs +1 -0
  351. package/assets/icons/definitions/money.doc.mjs +1 -0
  352. package/assets/icons/definitions/moon.doc.mjs +1 -0
  353. package/assets/icons/definitions/moveToFolder.doc.mjs +9 -0
  354. package/assets/icons/definitions/notification.doc.mjs +1 -0
  355. package/assets/icons/definitions/notificationActive.doc.mjs +1 -0
  356. package/assets/icons/definitions/notificationOff.doc.mjs +1 -0
  357. package/assets/icons/definitions/paddingHorizontal.doc.mjs +1 -0
  358. package/assets/icons/definitions/paddingPerSide.doc.mjs +1 -0
  359. package/assets/icons/definitions/paddingVertical.doc.mjs +1 -0
  360. package/assets/icons/definitions/panelBottom.doc.mjs +1 -0
  361. package/assets/icons/definitions/panelLeft.doc.mjs +1 -0
  362. package/assets/icons/definitions/panelRight.doc.mjs +1 -0
  363. package/assets/icons/definitions/paste.doc.mjs +9 -0
  364. package/assets/icons/definitions/pause.doc.mjs +1 -0
  365. package/assets/icons/definitions/play.doc.mjs +1 -0
  366. package/assets/icons/definitions/radiusPerCorner.doc.mjs +1 -0
  367. package/assets/icons/definitions/redo.doc.mjs +1 -0
  368. package/assets/icons/definitions/review.doc.mjs +9 -0
  369. package/assets/icons/definitions/rotate.doc.mjs +1 -0
  370. package/assets/icons/definitions/rotateCounterclockwise.doc.mjs +1 -0
  371. package/assets/icons/definitions/scale.doc.mjs +1 -2
  372. package/assets/icons/definitions/schedule.doc.mjs +9 -0
  373. package/assets/icons/definitions/search.doc.mjs +1 -0
  374. package/assets/icons/definitions/send.doc.mjs +1 -0
  375. package/assets/icons/definitions/shoppingBag.doc.mjs +1 -0
  376. package/assets/icons/definitions/signal.doc.mjs +9 -0
  377. package/assets/icons/definitions/stop.doc.mjs +1 -0
  378. package/assets/icons/definitions/strikethrough.doc.mjs +1 -0
  379. package/assets/icons/definitions/success.doc.mjs +1 -0
  380. package/assets/icons/definitions/sun.doc.mjs +1 -0
  381. package/assets/icons/definitions/tablet.doc.mjs +1 -0
  382. package/assets/icons/definitions/team.doc.mjs +9 -0
  383. package/assets/icons/definitions/textCase.doc.mjs +2 -1
  384. package/assets/icons/definitions/textRegular.doc.mjs +1 -0
  385. package/assets/icons/definitions/thumbsDown.doc.mjs +1 -0
  386. package/assets/icons/definitions/thumbsUp.doc.mjs +1 -0
  387. package/assets/icons/definitions/transfer.doc.mjs +1 -0
  388. package/assets/icons/definitions/trendDown.doc.mjs +1 -0
  389. package/assets/icons/definitions/trendUp.doc.mjs +1 -0
  390. package/assets/icons/definitions/underline.doc.mjs +1 -0
  391. package/assets/icons/definitions/undo.doc.mjs +1 -0
  392. package/assets/icons/definitions/unlock.doc.mjs +1 -0
  393. package/assets/icons/definitions/upload.doc.mjs +1 -0
  394. package/assets/icons/definitions/uppercase.doc.mjs +1 -0
  395. package/assets/icons/definitions/user.doc.mjs +1 -0
  396. package/assets/icons/definitions/userAdd.doc.mjs +1 -0
  397. package/assets/icons/definitions/userCircle.doc.mjs +1 -0
  398. package/assets/icons/definitions/userRemove.doc.mjs +1 -0
  399. package/assets/icons/definitions/users.doc.mjs +1 -0
  400. package/assets/icons/definitions/verified.doc.mjs +9 -0
  401. package/assets/icons/definitions/wallet.doc.mjs +1 -0
  402. package/assets/icons/definitions/warning.doc.mjs +1 -0
  403. package/assets/icons/definitions/wrench.doc.mjs +1 -1
  404. package/assets/icons/template-icons.json +661 -0
  405. package/assets/search-catalog.generated.json +2 -2
  406. package/assets/self-audit.generated.json +1 -1
  407. package/assets/templates/blocks/components/AppShell/AppShellShowcase.doc.mjs +0 -7
  408. package/assets/templates/blocks/components/AppShell/AppShellShowcase.tsx +8 -10
  409. package/assets/templates/blocks/components/AppShell/AppShellSideNavOnly.doc.mjs +0 -8
  410. package/assets/templates/blocks/components/AppShell/AppShellSideNavOnly.tsx +10 -8
  411. package/assets/templates/blocks/components/AppShell/AppShellTopNavOnly.doc.mjs +0 -1
  412. package/assets/templates/blocks/components/AppShell/AppShellTopNavOnly.tsx +4 -2
  413. package/assets/templates/blocks/components/AppShell/AppShellTopNavWithSideNav.doc.mjs +0 -8
  414. package/assets/templates/blocks/components/AppShell/AppShellTopNavWithSideNav.tsx +10 -8
  415. package/assets/templates/blocks/components/AppShell/AppShellWithBanner.doc.mjs +0 -8
  416. package/assets/templates/blocks/components/AppShell/AppShellWithBanner.tsx +10 -8
  417. package/assets/templates/blocks/components/AspectRatio/AspectRatioImageGallery.tsx +1 -1
  418. package/assets/templates/blocks/components/AspectRatio/AspectRatioWidescreen.tsx +1 -1
  419. package/assets/templates/blocks/components/AspectRatio/AspectRatioWithSkeleton.tsx +1 -1
  420. package/assets/templates/blocks/components/Avatar/AvatarInteractive.tsx +6 -1
  421. package/assets/templates/blocks/components/Avatar/AvatarShowcase.tsx +1 -1
  422. package/assets/templates/blocks/components/Avatar/AvatarTooltip.tsx +1 -1
  423. package/assets/templates/blocks/components/Avatar/AvatarWithStatus.tsx +1 -1
  424. package/assets/templates/blocks/components/AvatarStatusDot/AvatarStatusDotShowcase.tsx +1 -1
  425. package/assets/templates/blocks/components/AvatarStatusDot/AvatarStatusDotVariants.tsx +1 -1
  426. package/assets/templates/blocks/components/Badge/BadgeShowcase.tsx +2 -2
  427. package/assets/templates/blocks/components/Banner/BannerCollapsibleContent.tsx +14 -1
  428. package/assets/templates/blocks/components/Banner/BannerSectionVariant.tsx +10 -1
  429. package/assets/templates/blocks/components/Banner/BannerWithActionButton.tsx +25 -3
  430. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.doc.mjs +0 -1
  431. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.tsx +2 -2
  432. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadMenu.doc.mjs +0 -1
  433. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadMenu.tsx +1 -1
  434. package/assets/templates/blocks/components/BottomSheet/BottomSheetSnapPoints.doc.mjs +0 -8
  435. package/assets/templates/blocks/components/BottomSheet/BottomSheetSnapPoints.tsx +5 -5
  436. package/assets/templates/blocks/components/BreadcrumbItem/BreadcrumbItemShowcase.doc.mjs +0 -1
  437. package/assets/templates/blocks/components/BreadcrumbItem/BreadcrumbItemShowcase.tsx +1 -1
  438. package/assets/templates/blocks/components/Breadcrumbs/BreadcrumbsDeepHierarchy.doc.mjs +0 -1
  439. package/assets/templates/blocks/components/Breadcrumbs/BreadcrumbsDeepHierarchy.tsx +1 -1
  440. package/assets/templates/blocks/components/Breadcrumbs/BreadcrumbsWithIcons.doc.mjs +0 -1
  441. package/assets/templates/blocks/components/Breadcrumbs/BreadcrumbsWithIcons.tsx +2 -2
  442. package/assets/templates/blocks/components/Button/ButtonFloating.doc.mjs +0 -1
  443. package/assets/templates/blocks/components/Button/ButtonFloating.tsx +25 -2
  444. package/assets/templates/blocks/components/Button/ButtonShowcase.tsx +42 -4
  445. package/assets/templates/blocks/components/Button/ButtonSizeVariants.tsx +24 -2
  446. package/assets/templates/blocks/components/Button/ButtonVariants.tsx +28 -1
  447. package/assets/templates/blocks/components/Button/ButtonWithEndSlot.tsx +9 -0
  448. package/assets/templates/blocks/components/Button/ButtonWithIcon.doc.mjs +0 -6
  449. package/assets/templates/blocks/components/Button/ButtonWithIcon.tsx +35 -9
  450. package/assets/templates/blocks/components/ButtonGroup/ButtonGroupBasic.tsx +20 -3
  451. package/assets/templates/blocks/components/ButtonGroup/ButtonGroupFloating.tsx +16 -3
  452. package/assets/templates/blocks/components/ButtonGroup/ButtonGroupShowcase.doc.mjs +0 -6
  453. package/assets/templates/blocks/components/ButtonGroup/ButtonGroupShowcase.tsx +37 -8
  454. package/assets/templates/blocks/components/Center/CenterHorizontal.doc.mjs +0 -8
  455. package/assets/templates/blocks/components/Center/CenterHorizontal.tsx +23 -5
  456. package/assets/templates/blocks/components/Center/CenterInsideACard.doc.mjs +0 -1
  457. package/assets/templates/blocks/components/Center/CenterInsideACard.tsx +1 -1
  458. package/assets/templates/blocks/components/ChatComposer/ChatComposerFlat.doc.mjs +0 -5
  459. package/assets/templates/blocks/components/ChatComposer/ChatComposerFlat.tsx +8 -3
  460. package/assets/templates/blocks/components/ChatComposer/ChatComposerFooterActions.doc.mjs +0 -5
  461. package/assets/templates/blocks/components/ChatComposer/ChatComposerFooterActions.tsx +8 -3
  462. package/assets/templates/blocks/components/ChatComposer/ChatComposerFullFeatured.doc.mjs +0 -7
  463. package/assets/templates/blocks/components/ChatComposer/ChatComposerFullFeatured.tsx +10 -7
  464. package/assets/templates/blocks/components/ChatComposerDrawer/ChatComposerDrawerShowcase.doc.mjs +0 -1
  465. package/assets/templates/blocks/components/ChatComposerDrawer/ChatComposerDrawerShowcase.tsx +2 -2
  466. package/assets/templates/blocks/components/ChatComposerDrawer/ChatComposerDrawerWithProgress.doc.mjs +0 -1
  467. package/assets/templates/blocks/components/ChatComposerDrawer/ChatComposerDrawerWithProgress.tsx +3 -3
  468. package/assets/templates/blocks/components/ChatMessageMetadata/ChatMessageMetadataFooter.doc.mjs +0 -6
  469. package/assets/templates/blocks/components/ChatMessageMetadata/ChatMessageMetadataFooter.tsx +9 -9
  470. package/assets/templates/blocks/components/ChatMessageMetadata/ChatMessageMetadataShowcase.doc.mjs +0 -6
  471. package/assets/templates/blocks/components/ChatMessageMetadata/ChatMessageMetadataShowcase.tsx +10 -10
  472. package/assets/templates/blocks/components/ChatSendButton/ChatSendButtonCustomIcon.doc.mjs +0 -6
  473. package/assets/templates/blocks/components/ChatSendButton/ChatSendButtonCustomIcon.tsx +8 -5
  474. package/assets/templates/blocks/components/ChatSendButton/ChatSendButtonShowcase.doc.mjs +0 -1
  475. package/assets/templates/blocks/components/ChatSendButton/ChatSendButtonShowcase.tsx +1 -1
  476. package/assets/templates/blocks/components/ChatSystemMessage/ChatSystemMessageStatusUpdates.doc.mjs +0 -5
  477. package/assets/templates/blocks/components/ChatSystemMessage/ChatSystemMessageStatusUpdates.tsx +7 -7
  478. package/assets/templates/blocks/components/ChatSystemMessage/ChatSystemMessageWithIcon.doc.mjs +0 -6
  479. package/assets/templates/blocks/components/ChatSystemMessage/ChatSystemMessageWithIcon.tsx +7 -7
  480. package/assets/templates/blocks/components/ContextMenu/ContextMenuBottomSheet.doc.mjs +0 -6
  481. package/assets/templates/blocks/components/ContextMenu/ContextMenuBottomSheet.tsx +7 -7
  482. package/assets/templates/blocks/components/DropdownMenu/DropdownMenuBottomSheet.doc.mjs +0 -6
  483. package/assets/templates/blocks/components/DropdownMenu/DropdownMenuBottomSheet.tsx +7 -7
  484. package/assets/templates/blocks/components/DropdownMenu/DropdownMenuNoChevron.doc.mjs +0 -1
  485. package/assets/templates/blocks/components/DropdownMenu/DropdownMenuNoChevron.tsx +2 -2
  486. package/assets/templates/blocks/components/EmptyState/EmptyStateActions.doc.mjs +0 -1
  487. package/assets/templates/blocks/components/EmptyState/EmptyStateActions.tsx +2 -2
  488. package/assets/templates/blocks/components/EmptyState/EmptyStateCompact.doc.mjs +0 -1
  489. package/assets/templates/blocks/components/EmptyState/EmptyStateCompact.tsx +1 -1
  490. package/assets/templates/blocks/components/EmptyState/EmptyStateContainer.doc.mjs +0 -1
  491. package/assets/templates/blocks/components/EmptyState/EmptyStateContainer.tsx +2 -2
  492. package/assets/templates/blocks/components/EmptyState/EmptyStateShowcase.doc.mjs +0 -1
  493. package/assets/templates/blocks/components/EmptyState/EmptyStateShowcase.tsx +2 -2
  494. package/assets/templates/blocks/components/Grid/GridShowcase.tsx +1 -1
  495. package/assets/templates/blocks/components/GridSpan/GridSpanColumns.tsx +1 -1
  496. package/assets/templates/blocks/components/GridSpan/GridSpanShowcase.tsx +1 -1
  497. package/assets/templates/blocks/components/Heading/HeadingTruncation.tsx +3 -2
  498. package/assets/templates/blocks/components/Hooks/useClipboardHookUsage.tsx +1 -1
  499. package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.doc.mjs +0 -1
  500. package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +38 -19
  501. package/assets/templates/blocks/components/Hooks/useGridFocusHookUsage.tsx +6 -6
  502. package/assets/templates/blocks/components/Hooks/useHotkeysHookUsage.tsx +1 -1
  503. package/assets/templates/blocks/components/Hooks/useInputContainerHookUsage.doc.mjs +0 -1
  504. package/assets/templates/blocks/components/Hooks/useInputContainerHookUsage.tsx +2 -2
  505. package/assets/templates/blocks/components/Hooks/useKeyboardHintHookUsage.doc.mjs +0 -1
  506. package/assets/templates/blocks/components/Hooks/useKeyboardHintHookUsage.tsx +2 -2
  507. package/assets/templates/blocks/components/Hooks/useListFocusHookUsage.tsx +8 -1
  508. package/assets/templates/blocks/components/Hooks/useOverflowHookUsage.tsx +17 -6
  509. package/assets/templates/blocks/components/Hooks/useStreamingTextHookUsage.tsx +1 -1
  510. package/assets/templates/blocks/components/Hooks/useTreeFocusHookUsage.doc.mjs +0 -1
  511. package/assets/templates/blocks/components/Hooks/useTreeFocusHookUsage.tsx +1 -1
  512. package/assets/templates/blocks/components/HoverCard/HoverCardInteractiveContent.doc.mjs +0 -1
  513. package/assets/templates/blocks/components/HoverCard/HoverCardInteractiveContent.tsx +1 -1
  514. package/assets/templates/blocks/components/HoverCard/HoverCardProfileHoverCard.doc.mjs +0 -1
  515. package/assets/templates/blocks/components/HoverCard/HoverCardProfileHoverCard.tsx +1 -1
  516. package/assets/templates/blocks/components/Icon/useIconHookUsage.doc.mjs +0 -5
  517. package/assets/templates/blocks/components/Icon/useIconHookUsage.tsx +7 -7
  518. package/assets/templates/blocks/components/IconButton/IconButtonActionBar.tsx +11 -0
  519. package/assets/templates/blocks/components/IconButton/IconButtonFloating.doc.mjs +0 -1
  520. package/assets/templates/blocks/components/IconButton/IconButtonFloating.tsx +25 -2
  521. package/assets/templates/blocks/components/IconButton/IconButtonShowcase.tsx +3 -0
  522. package/assets/templates/blocks/components/IconButton/IconButtonTooltipIconButton.tsx +5 -0
  523. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider02Overrides.doc.mjs +3 -3
  524. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider02Overrides.tsx +36 -13
  525. package/assets/templates/blocks/components/Item/ItemDocumentTabs.doc.mjs +0 -1
  526. package/assets/templates/blocks/components/Item/ItemDocumentTabs.tsx +4 -4
  527. package/assets/templates/blocks/components/Item/ItemShowcase.doc.mjs +0 -1
  528. package/assets/templates/blocks/components/Item/ItemShowcase.tsx +7 -3
  529. package/assets/templates/blocks/components/Layout/LayoutBasicCardLayout.tsx +14 -2
  530. package/assets/templates/blocks/components/Layout/LayoutContentWidth.tsx +14 -2
  531. package/assets/templates/blocks/components/Layout/LayoutFullBleedContent.tsx +8 -1
  532. package/assets/templates/blocks/components/Layout/LayoutShowcase.tsx +8 -1
  533. package/assets/templates/blocks/components/Layout/LayoutSidebarLayout.tsx +14 -2
  534. package/assets/templates/blocks/components/LinkProvider/LinkProviderCustomLink.tsx +3 -1
  535. package/assets/templates/blocks/components/Markdown/MarkdownShowcase.tsx +1 -1
  536. package/assets/templates/blocks/components/MediaTheme/MediaThemeImageOverlay.tsx +18 -4
  537. package/assets/templates/blocks/components/MediaTheme/MediaThemeLightScrim.tsx +11 -3
  538. package/assets/templates/blocks/components/MediaTheme/MediaThemeShowcase.tsx +27 -5
  539. package/assets/templates/blocks/components/MobileNav/MobileNavBasicMobileNav.doc.mjs +0 -7
  540. package/assets/templates/blocks/components/MobileNav/MobileNavBasicMobileNav.tsx +5 -9
  541. package/assets/templates/blocks/components/MobileNav/MobileNavEndSideMobileNav.doc.mjs +0 -1
  542. package/assets/templates/blocks/components/MobileNav/MobileNavEndSideMobileNav.tsx +2 -2
  543. package/assets/templates/blocks/components/MobileNav/MobileNavWithoutTitleMobileNav.doc.mjs +0 -1
  544. package/assets/templates/blocks/components/MobileNav/MobileNavWithoutTitleMobileNav.tsx +1 -1
  545. package/assets/templates/blocks/components/MoreMenu/MoreMenuBottomSheet.doc.mjs +0 -6
  546. package/assets/templates/blocks/components/MoreMenu/MoreMenuBottomSheet.tsx +15 -15
  547. package/assets/templates/blocks/components/MoreMenu/MoreMenuWithDividers.doc.mjs +0 -5
  548. package/assets/templates/blocks/components/MoreMenu/MoreMenuWithDividers.tsx +4 -8
  549. package/assets/templates/blocks/components/MoreMenu/MoreMenuWithSections.doc.mjs +0 -5
  550. package/assets/templates/blocks/components/MoreMenu/MoreMenuWithSections.tsx +4 -8
  551. package/assets/templates/blocks/components/MultiSelector/useMultiComboboxHookUsage.doc.mjs +0 -1
  552. package/assets/templates/blocks/components/MultiSelector/useMultiComboboxHookUsage.tsx +1 -1
  553. package/assets/templates/blocks/components/OverflowList/OverflowListCappedToolbar.tsx +38 -2
  554. package/assets/templates/blocks/components/OverflowList/OverflowListCollapseFromStartList.tsx +17 -5
  555. package/assets/templates/blocks/components/OverflowList/OverflowListOverflowDropdownActions.tsx +46 -7
  556. package/assets/templates/blocks/components/OverflowList/OverflowListShowcase.tsx +45 -5
  557. package/assets/templates/blocks/components/Overlay/OverlayHoverReveal.tsx +14 -1
  558. package/assets/templates/blocks/components/Overlay/OverlayShowcase.tsx +10 -1
  559. package/assets/templates/blocks/components/Overlay/useOverlayHookUsage.tsx +12 -1
  560. package/assets/templates/blocks/components/Pagination/PaginationDotsCarousel.doc.mjs +0 -1
  561. package/assets/templates/blocks/components/Pagination/PaginationDotsCarousel.tsx +1 -1
  562. package/assets/templates/blocks/components/Popover/PopoverBottomSheetAlternative.doc.mjs +0 -1
  563. package/assets/templates/blocks/components/Popover/PopoverBottomSheetAlternative.tsx +1 -1
  564. package/assets/templates/blocks/components/Resizable/ResizableShowcase.tsx +12 -2
  565. package/assets/templates/blocks/components/Resizable/ResizableSidebar.tsx +1 -1
  566. package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaInlineRail.tsx +1 -1
  567. package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaOverscrollChaining.tsx +1 -1
  568. package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaShowcase.tsx +1 -1
  569. package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaStickyGroupHeaders.tsx +1 -1
  570. package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaStickyPassthrough.tsx +1 -1
  571. package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaTwoAxisBoard.tsx +1 -1
  572. package/assets/templates/blocks/components/Section/SectionWashHighlight.doc.mjs +0 -1
  573. package/assets/templates/blocks/components/Section/SectionWashHighlight.tsx +10 -2
  574. package/assets/templates/blocks/components/Selector/SelectorOptionDescriptions.doc.mjs +0 -1
  575. package/assets/templates/blocks/components/Selector/SelectorOptionDescriptions.tsx +3 -3
  576. package/assets/templates/blocks/components/SelectorOption/SelectorOptionShowcase.doc.mjs +0 -1
  577. package/assets/templates/blocks/components/SelectorOption/SelectorOptionShowcase.tsx +1 -1
  578. package/assets/templates/blocks/components/Stack/StackAlignment.tsx +50 -6
  579. package/assets/templates/blocks/components/Stack/StackDirections.tsx +1 -1
  580. package/assets/templates/blocks/components/Stack/StackFillItem.tsx +10 -1
  581. package/assets/templates/blocks/components/Step/StepContent.tsx +13 -4
  582. package/assets/templates/blocks/components/Step/StepIndicator.tsx +3 -2
  583. package/assets/templates/blocks/components/Step/StepShowcase.tsx +1 -1
  584. package/assets/templates/blocks/components/Step/StepStates.tsx +3 -2
  585. package/assets/templates/blocks/components/Stepper/StepperCustomContent.tsx +18 -14
  586. package/assets/templates/blocks/components/Stepper/StepperOnTrackHorizontal.tsx +1 -1
  587. package/assets/templates/blocks/components/Table/TableInCard.tsx +1 -1
  588. package/assets/templates/blocks/components/Table/TableShowcase.tsx +1 -1
  589. package/assets/templates/blocks/components/TextArea/TextAreaWithIcon.doc.mjs +0 -1
  590. package/assets/templates/blocks/components/TextArea/TextAreaWithIcon.tsx +2 -2
  591. package/assets/templates/blocks/components/TextInput/TextInputIcon.doc.mjs +0 -1
  592. package/assets/templates/blocks/components/TextInput/TextInputIcon.tsx +3 -7
  593. package/assets/templates/blocks/components/TextInput/TextInputSearch.doc.mjs +0 -1
  594. package/assets/templates/blocks/components/TextInput/TextInputSearch.tsx +3 -3
  595. package/assets/templates/blocks/components/Theme/ThemeApply.tsx +8 -1
  596. package/assets/templates/blocks/components/Theme/ThemeNested.tsx +11 -1
  597. package/assets/templates/blocks/components/Theme/ThemeShowcase.tsx +26 -3
  598. package/assets/templates/blocks/components/Theme/ThemeSwitcher.tsx +8 -1
  599. package/assets/templates/blocks/components/ToggleButton/ToggleButtonColor.doc.mjs +0 -11
  600. package/assets/templates/blocks/components/ToggleButton/ToggleButtonColor.tsx +5 -5
  601. package/assets/templates/blocks/components/ToggleButton/ToggleButtonGroup.doc.mjs +0 -9
  602. package/assets/templates/blocks/components/ToggleButton/ToggleButtonGroup.tsx +5 -9
  603. package/assets/templates/blocks/components/ToggleButton/ToggleButtonIconSwap.doc.mjs +0 -6
  604. package/assets/templates/blocks/components/ToggleButton/ToggleButtonIconSwap.tsx +6 -6
  605. package/assets/templates/blocks/components/ToggleButton/ToggleButtonLabel.doc.mjs +0 -6
  606. package/assets/templates/blocks/components/ToggleButton/ToggleButtonLabel.tsx +3 -3
  607. package/assets/templates/blocks/components/ToggleButton/ToggleButtonShowcase.doc.mjs +0 -6
  608. package/assets/templates/blocks/components/ToggleButton/ToggleButtonShowcase.tsx +6 -6
  609. package/assets/templates/blocks/components/ToggleButton/ToggleButtonStates.doc.mjs +0 -1
  610. package/assets/templates/blocks/components/ToggleButton/ToggleButtonStates.tsx +2 -2
  611. package/assets/templates/blocks/components/Token/TokenIcon.doc.mjs +0 -6
  612. package/assets/templates/blocks/components/Token/TokenIcon.tsx +3 -3
  613. package/assets/templates/blocks/components/Token/TokenShowcase.doc.mjs +0 -1
  614. package/assets/templates/blocks/components/Token/TokenShowcase.tsx +1 -1
  615. package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +14 -1
  616. package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.doc.mjs +0 -1
  617. package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +2 -2
  618. package/assets/templates/blocks/components/Toolbar/ToolbarBulkActions.doc.mjs +0 -1
  619. package/assets/templates/blocks/components/Toolbar/ToolbarBulkActions.tsx +36 -3
  620. package/assets/templates/blocks/components/Toolbar/ToolbarCardHeader.doc.mjs +0 -1
  621. package/assets/templates/blocks/components/Toolbar/ToolbarCardHeader.tsx +4 -3
  622. package/assets/templates/blocks/components/Toolbar/ToolbarSizes.doc.mjs +0 -1
  623. package/assets/templates/blocks/components/Toolbar/ToolbarSizes.tsx +3 -3
  624. package/assets/templates/blocks/components/Toolbar/ToolbarTableFilter.doc.mjs +0 -1
  625. package/assets/templates/blocks/components/Toolbar/ToolbarTableFilter.tsx +8 -3
  626. package/assets/templates/blocks/components/Toolbar/ToolbarThreeSlot.doc.mjs +0 -1
  627. package/assets/templates/blocks/components/Toolbar/ToolbarThreeSlot.tsx +6 -2
  628. package/assets/templates/blocks/components/Toolbar/ToolbarWithTabs.doc.mjs +0 -1
  629. package/assets/templates/blocks/components/Toolbar/ToolbarWithTabs.tsx +11 -2
  630. package/assets/templates/blocks/components/Tooltip/TooltipActionBarTooltips.tsx +33 -3
  631. package/assets/templates/blocks/components/TopNav/TopNavCenteredNavigation.doc.mjs +0 -1
  632. package/assets/templates/blocks/components/TopNav/TopNavCenteredNavigation.tsx +2 -2
  633. package/assets/templates/blocks/components/TopNav/TopNavEnterpriseDashboard.doc.mjs +0 -6
  634. package/assets/templates/blocks/components/TopNav/TopNavEnterpriseDashboard.tsx +7 -7
  635. package/assets/templates/blocks/components/TopNav/TopNavHoverMenu.doc.mjs +0 -8
  636. package/assets/templates/blocks/components/TopNav/TopNavHoverMenu.tsx +14 -9
  637. package/assets/templates/blocks/components/TopNav/TopNavMegaMenu.doc.mjs +0 -8
  638. package/assets/templates/blocks/components/TopNav/TopNavMegaMenu.tsx +11 -11
  639. package/assets/templates/blocks/components/TopNav/TopNavMultipleDropdowns.doc.mjs +0 -5
  640. package/assets/templates/blocks/components/TopNav/TopNavMultipleDropdowns.tsx +4 -8
  641. package/assets/templates/blocks/components/TopNav/TopNavShowcase.doc.mjs +0 -5
  642. package/assets/templates/blocks/components/TopNav/TopNavShowcase.tsx +8 -4
  643. package/assets/templates/blocks/components/TopNav/TopNavWithLogo.doc.mjs +0 -1
  644. package/assets/templates/blocks/components/TopNav/TopNavWithLogo.tsx +7 -2
  645. package/assets/templates/blocks/components/TopNavItem/TopNavItemShowcase.tsx +1 -1
  646. package/assets/templates/blocks/components/TopNavMegaMenu/TopNavMegaMenuBasic.doc.mjs +0 -1
  647. package/assets/templates/blocks/components/TopNavMegaMenu/TopNavMegaMenuBasic.tsx +4 -4
  648. package/assets/templates/blocks/components/TopNavMegaMenu/TopNavMegaMenuShowcase.doc.mjs +0 -7
  649. package/assets/templates/blocks/components/TopNavMegaMenu/TopNavMegaMenuShowcase.tsx +12 -12
  650. package/assets/templates/blocks/components/TopNavMegaMenuItem/TopNavMegaMenuItemBasic.doc.mjs +0 -1
  651. package/assets/templates/blocks/components/TopNavMegaMenuItem/TopNavMegaMenuItemBasic.tsx +2 -2
  652. package/assets/templates/blocks/components/TopNavMenu/TopNavMenuBasic.doc.mjs +0 -1
  653. package/assets/templates/blocks/components/TopNavMenu/TopNavMenuBasic.tsx +4 -4
  654. package/assets/templates/blocks/components/TopNavMenu/TopNavMenuShowcase.doc.mjs +0 -6
  655. package/assets/templates/blocks/components/TopNavMenu/TopNavMenuShowcase.tsx +11 -8
  656. package/assets/templates/blocks/components/TreeList/TreeListFileTreeWithIcons.doc.mjs +0 -1
  657. package/assets/templates/blocks/components/TreeList/TreeListFileTreeWithIcons.tsx +4 -4
  658. package/assets/templates/blocks/components/TreeList/TreeListInteractiveSettings.doc.mjs +0 -1
  659. package/assets/templates/blocks/components/TreeList/TreeListInteractiveSettings.tsx +6 -3
  660. package/assets/templates/blocks/components/Typeahead/TypeaheadSearchField.doc.mjs +0 -1
  661. package/assets/templates/blocks/components/Typeahead/TypeaheadSearchField.tsx +2 -2
  662. package/assets/templates/blocks/components/VisuallyHidden/VisuallyHiddenShowcase.doc.mjs +0 -6
  663. package/assets/templates/blocks/components/VisuallyHidden/VisuallyHiddenShowcase.tsx +30 -7
  664. package/assets/templates/blocks/components/VisuallyHidden/VisuallyHiddenSupplementaryContext.doc.mjs +0 -1
  665. package/assets/templates/blocks/components/VisuallyHidden/VisuallyHiddenSupplementaryContext.tsx +4 -1
  666. package/assets/templates/components.generated.json +1 -1
  667. package/assets/templates/pages/ai-chat/page.tsx +19 -15
  668. package/assets/templates/pages/ai-chat/template.doc.mjs +0 -9
  669. package/assets/templates/pages/ai-chat-landing/page.tsx +16 -16
  670. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +0 -11
  671. package/assets/templates/pages/blank/page.tsx +4 -2
  672. package/assets/templates/pages/canvas-editor/page.tsx +200 -110
  673. package/assets/templates/pages/canvas-editor/template.doc.mjs +0 -46
  674. package/assets/templates/pages/centered-hero/page.tsx +2 -2
  675. package/assets/templates/pages/centered-hero/template.doc.mjs +0 -1
  676. package/assets/templates/pages/checkout-wizard/page.tsx +31 -18
  677. package/assets/templates/pages/checkout-wizard/template.doc.mjs +0 -7
  678. package/assets/templates/pages/classic-gallery/page.tsx +1 -1
  679. package/assets/templates/pages/contact-form/page.tsx +15 -10
  680. package/assets/templates/pages/contact-form/template.doc.mjs +0 -5
  681. package/assets/templates/pages/course-detail/page.tsx +10 -10
  682. package/assets/templates/pages/course-detail/template.doc.mjs +0 -11
  683. package/assets/templates/pages/dashboard/page.tsx +13 -11
  684. package/assets/templates/pages/dashboard/template.doc.mjs +0 -6
  685. package/assets/templates/pages/dashboard-alert-rail/page.tsx +12 -12
  686. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +0 -8
  687. package/assets/templates/pages/dashboard-cohort-funnel/page.tsx +7 -13
  688. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +0 -7
  689. package/assets/templates/pages/dashboard-comparison/page.tsx +12 -10
  690. package/assets/templates/pages/dashboard-comparison/template.doc.mjs +0 -8
  691. package/assets/templates/pages/dashboard-composition/page.tsx +30 -19
  692. package/assets/templates/pages/dashboard-composition/template.doc.mjs +0 -1
  693. package/assets/templates/pages/dashboard-progress/page.tsx +101 -108
  694. package/assets/templates/pages/dashboard-progress/template.doc.mjs +0 -7
  695. package/assets/templates/pages/dashboard-scorecard/page.tsx +61 -33
  696. package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +0 -7
  697. package/assets/templates/pages/detail-page/page.tsx +28 -11
  698. package/assets/templates/pages/detail-page/template.doc.mjs +0 -10
  699. package/assets/templates/pages/documentation/page.tsx +11 -4
  700. package/assets/templates/pages/documentation-design/page.tsx +39 -12
  701. package/assets/templates/pages/documentation-design/template.doc.mjs +0 -5
  702. package/assets/templates/pages/documentation-technical/page.tsx +8 -6
  703. package/assets/templates/pages/documentation-technical/template.doc.mjs +0 -5
  704. package/assets/templates/pages/editor/page.tsx +70 -48
  705. package/assets/templates/pages/editor/template.doc.mjs +0 -26
  706. package/assets/templates/pages/file-explorer/page.tsx +19 -19
  707. package/assets/templates/pages/file-explorer/template.doc.mjs +0 -15
  708. package/assets/templates/pages/form-two-column/page.tsx +1 -1
  709. package/assets/templates/pages/form-wizard/page.tsx +12 -5
  710. package/assets/templates/pages/form-wizard-dialog/page.tsx +6 -2
  711. package/assets/templates/pages/form-wizard-inline/page.tsx +16 -12
  712. package/assets/templates/pages/form-wizard-inline/template.doc.mjs +0 -6
  713. package/assets/templates/pages/form-wizard-vertical/page.tsx +21 -24
  714. package/assets/templates/pages/form-wizard-vertical/template.doc.mjs +0 -13
  715. package/assets/templates/pages/gallery-hero/page.tsx +2 -2
  716. package/assets/templates/pages/gallery-hero/template.doc.mjs +0 -1
  717. package/assets/templates/pages/ide/page.tsx +12 -7
  718. package/assets/templates/pages/ide/template.doc.mjs +0 -5
  719. package/assets/templates/pages/incident-console/page.tsx +4 -4
  720. package/assets/templates/pages/incident-console/template.doc.mjs +0 -1
  721. package/assets/templates/pages/kanban-board/page.tsx +128 -47
  722. package/assets/templates/pages/kanban-board/template.doc.mjs +0 -11
  723. package/assets/templates/pages/library/page.tsx +34 -64
  724. package/assets/templates/pages/library/template.doc.mjs +0 -1
  725. package/assets/templates/pages/login/page.tsx +6 -4
  726. package/assets/templates/pages/login/template.doc.mjs +0 -1
  727. package/assets/templates/pages/login-card/page.tsx +6 -4
  728. package/assets/templates/pages/login-card/template.doc.mjs +0 -1
  729. package/assets/templates/pages/login-split/page.tsx +6 -5
  730. package/assets/templates/pages/login-split/template.doc.mjs +0 -1
  731. package/assets/templates/pages/login-sso/page.tsx +6 -6
  732. package/assets/templates/pages/login-sso/template.doc.mjs +0 -1
  733. package/assets/templates/pages/messaging-shell/page.tsx +14 -14
  734. package/assets/templates/pages/messaging-shell/template.doc.mjs +0 -9
  735. package/assets/templates/pages/mixed-gallery/page.tsx +1 -1
  736. package/assets/templates/pages/payment-form/page.tsx +50 -29
  737. package/assets/templates/pages/payment-form/template.doc.mjs +0 -6
  738. package/assets/templates/pages/product-detail/page.tsx +21 -9
  739. package/assets/templates/pages/product-detail/template.doc.mjs +0 -1
  740. package/assets/templates/pages/product-gallery/page.tsx +3 -3
  741. package/assets/templates/pages/product-gallery/template.doc.mjs +0 -1
  742. package/assets/templates/pages/settings/page.tsx +35 -14
  743. package/assets/templates/pages/settings/template.doc.mjs +0 -1
  744. package/assets/templates/pages/settings-dialog/page.tsx +96 -93
  745. package/assets/templates/pages/settings-dialog/template.doc.mjs +0 -53
  746. package/assets/templates/pages/settings-sidebar/page.tsx +74 -36
  747. package/assets/templates/pages/settings-sidebar/template.doc.mjs +0 -16
  748. package/assets/templates/pages/shell-nav/page.tsx +32 -20
  749. package/assets/templates/pages/shell-nav/template.doc.mjs +0 -6
  750. package/assets/templates/pages/shell-side-nav/page.tsx +23 -22
  751. package/assets/templates/pages/shell-side-nav/template.doc.mjs +0 -11
  752. package/assets/templates/pages/shell-top-nav/page.tsx +13 -13
  753. package/assets/templates/pages/shell-top-nav/template.doc.mjs +0 -19
  754. package/assets/templates/pages/side-gallery/page.tsx +5 -2
  755. package/assets/templates/pages/table/page.tsx +21 -21
  756. package/assets/templates/pages/table/template.doc.mjs +0 -10
  757. package/assets/templates/pages/table-collapsible/page.tsx +8 -8
  758. package/assets/templates/pages/table-collapsible/template.doc.mjs +0 -6
  759. package/assets/templates/pages/table-comparison/page.tsx +23 -23
  760. package/assets/templates/pages/table-comparison/template.doc.mjs +0 -14
  761. package/assets/templates/pages/table-filter/page.tsx +75 -47
  762. package/assets/templates/pages/table-filter/template.doc.mjs +0 -19
  763. package/assets/templates/pages/table-grouped/page.tsx +16 -15
  764. package/assets/templates/pages/table-grouped/template.doc.mjs +0 -11
  765. package/assets/templates/pages/table-inbox/page.tsx +65 -33
  766. package/assets/templates/pages/table-inbox/template.doc.mjs +0 -17
  767. package/assets/templates/pages/table-page/page.tsx +3 -6
  768. package/assets/templates/pages/table-page/template.doc.mjs +0 -1
  769. package/assets/templates/pages/table-tree/page.tsx +35 -35
  770. package/assets/templates/pages/table-tree/template.doc.mjs +0 -15
  771. package/assets/templates/pages/theme-showcase/page.tsx +48 -43
  772. package/assets/templates/pages/theme-showcase/template.doc.mjs +0 -19
  773. package/assets/templates/pages/work-item-detail/page.tsx +60 -33
  774. package/assets/templates/pages/work-item-detail/template.doc.mjs +0 -12
  775. package/assets/templates/themes/butter/butterTheme.ts +50 -9
  776. package/assets/templates/themes/chocolate/chocolateTheme.ts +13 -6
  777. package/assets/templates/themes/gothic/gothicTheme.ts +14 -2
  778. package/assets/templates/themes/matcha/matchaTheme.ts +10 -2
  779. package/assets/templates/themes/neutral/neutralTheme.ts +16 -0
  780. package/assets/templates/themes/stone/stonePaletteRefs.generated.ts +1 -1
  781. package/assets/templates/themes/stone/stoneTheme.ts +32 -10
  782. package/assets/templates/themes/y2k/y2kTheme.ts +11 -3
  783. package/assets/theme.template.ts +17 -7
  784. package/authoring/config/config.doc.mjs +8 -1
  785. package/authoring/config/parse.mjs +15 -0
  786. package/authoring/config/skill-places.d.mts +23 -0
  787. package/authoring/config/skill-places.mjs +35 -0
  788. package/authoring/config/type.ts +16 -0
  789. package/authoring/debug/parse.d.mts +1 -1
  790. package/authoring/debug/type.ts +4 -0
  791. package/authoring/discover/parse.d.mts +2 -1
  792. package/authoring/discover/parse.mjs +73 -38
  793. package/authoring/discover/type.ts +9 -2
  794. package/authoring/doctypes/_schema.d.mts +36 -16
  795. package/authoring/doctypes/_schema.mjs +29 -0
  796. package/authoring/doctypes/base/type.ts +19 -0
  797. package/authoring/doctypes/command/command.doc.mjs +6 -0
  798. package/authoring/doctypes/command/type.ts +7 -0
  799. package/authoring/doctypes/component/component.doc.mjs +1 -1
  800. package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +16 -0
  801. package/authoring/doctypes/icon-definition/parse.mjs +12 -0
  802. package/authoring/doctypes/icon-definition/type.ts +18 -0
  803. package/authoring/doctypes/reference/reference.doc.mjs +13 -0
  804. package/authoring/doctypes/reference/skill.d.mts +29 -0
  805. package/authoring/doctypes/reference/skill.mjs +56 -0
  806. package/authoring/doctypes/reference/type.ts +19 -0
  807. package/authoring/gap-report/parse.d.mts +1 -1
  808. package/authoring/integration/integration.doc.mjs +8 -0
  809. package/authoring/integration/schema.d.mts +21 -3
  810. package/authoring/integration/schema.mjs +25 -5
  811. package/authoring/integration/type.ts +14 -0
  812. package/clients/cli/build-id.generated.json +1 -1
  813. package/clients/cli/commands/build.doc.mjs +1 -1
  814. package/clients/cli/commands/build.mjs +11 -11
  815. package/clients/cli/commands/component.doc.mjs +3 -1
  816. package/clients/cli/commands/component.mjs +7 -3
  817. package/clients/cli/commands/discover.doc.mjs +2 -2
  818. package/clients/cli/commands/discover.mjs +108 -8
  819. package/clients/cli/commands/docs.doc.mjs +7 -2
  820. package/clients/cli/commands/docs.mjs +64 -172
  821. package/clients/cli/commands/doctor-integration-validate.doc.mjs +4 -2
  822. package/clients/cli/commands/doctor.doc.mjs +3 -1
  823. package/clients/cli/commands/doctor.mjs +16 -3
  824. package/clients/cli/commands/experimental/export.mjs +64 -0
  825. package/clients/cli/commands/experimental/icon.mjs +67 -12
  826. package/clients/cli/commands/experimental/import.mjs +70 -0
  827. package/clients/cli/commands/experimental/index.mjs +152 -13
  828. package/clients/cli/commands/experimental/render-output.mjs +242 -0
  829. package/clients/cli/commands/experimental/theme.mjs +34 -13
  830. package/clients/cli/commands/experimental-export.doc.mjs +73 -0
  831. package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
  832. package/clients/cli/commands/experimental-import.doc.mjs +53 -0
  833. package/clients/cli/commands/experimental-theme-add.doc.mjs +1 -1
  834. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +6 -1
  835. package/clients/cli/commands/experimental-theme.doc.mjs +1 -1
  836. package/clients/cli/commands/experimental.doc.mjs +4 -4
  837. package/clients/cli/commands/init.doc.mjs +34 -14
  838. package/clients/cli/commands/integration-check.doc.mjs +1 -1
  839. package/clients/cli/commands/mcp.doc.mjs +5 -1
  840. package/clients/cli/commands/search.mjs +68 -7
  841. package/clients/cli/commands/template.doc.mjs +14 -5
  842. package/clients/cli/commands/template.mjs +18 -0
  843. package/clients/cli/commands/theme-add.doc.mjs +6 -2
  844. package/clients/cli/commands/theme-remove.doc.mjs +1 -1
  845. package/clients/cli/commands/theme-targets.doc.mjs +1 -1
  846. package/clients/cli/commands/theme.mjs +76 -5
  847. package/clients/cli/commands/upgrade.doc.mjs +2 -1
  848. package/clients/cli/commands.generated.json +1 -1
  849. package/clients/cli/index.mjs +30 -31
  850. package/clients/cli/lib/cli-error.mjs +20 -10
  851. package/clients/cli/lib/component-format.mjs +167 -74
  852. package/clients/cli/lib/define-command.mjs +10 -0
  853. package/clients/cli/lib/hook-format.mjs +28 -24
  854. package/clients/cli/lib/json-shim.mjs +9 -3
  855. package/clients/cli/lib/mcp-tools.mjs +8 -2
  856. package/clients/cli/lib/other-cli-words.mjs +99 -0
  857. package/clients/cli/lib/renamed-commands.mjs +21 -0
  858. package/clients/cli/lib/root-args.mjs +10 -3
  859. package/clients/cli/lib/stray-option.mjs +79 -1
  860. package/clients/cli/lib/unknown-command.mjs +406 -13
  861. package/clients/cli/manifest.generated.json +1 -1
  862. package/clients/cli/run.mjs +27 -0
  863. package/foundation/agent-docs/agent-doc-state.d.mts +20 -2
  864. package/foundation/agent-docs/agent-doc-state.mjs +71 -4
  865. package/foundation/agent-docs/agent-docs.d.mts +43 -4
  866. package/foundation/agent-docs/agent-docs.mjs +54 -5
  867. package/foundation/agent-docs/computer-agent-text.d.mts +28 -14
  868. package/foundation/agent-docs/computer-agent-text.mjs +85 -172
  869. package/foundation/agent-docs/folder-scope.d.mts +51 -0
  870. package/foundation/agent-docs/folder-scope.mjs +86 -0
  871. package/foundation/agent-docs/managed-skill-file.d.mts +115 -0
  872. package/foundation/agent-docs/managed-skill-file.mjs +224 -0
  873. package/foundation/agent-docs/skill-place-files.d.mts +119 -0
  874. package/foundation/agent-docs/skill-place-files.mjs +374 -0
  875. package/foundation/agent-docs/skill-places.d.mts +139 -0
  876. package/foundation/agent-docs/skill-places.mjs +321 -0
  877. package/foundation/color/css-color.d.mts +150 -0
  878. package/foundation/color/css-color.mjs +960 -0
  879. package/foundation/config/config-path.d.mts +2 -2
  880. package/foundation/config/config-path.mjs +5 -6
  881. package/foundation/config/config-writer.d.mts +5 -1
  882. package/foundation/config/config-writer.mjs +20 -4
  883. package/foundation/config/project.d.mts +3 -1
  884. package/foundation/config/project.mjs +8 -5
  885. package/foundation/config/theme-state.d.mts +13 -0
  886. package/foundation/config/theme-state.mjs +28 -0
  887. package/foundation/debug/event.d.mts +2 -1
  888. package/foundation/debug/event.mjs +2 -1
  889. package/foundation/discovery/button-actions.d.mts +220 -0
  890. package/foundation/discovery/button-actions.mjs +1527 -0
  891. package/foundation/discovery/cli-self-docs.d.mts +7 -0
  892. package/foundation/discovery/cli-self-docs.mjs +67 -6
  893. package/foundation/discovery/color-modes.d.mts +14 -0
  894. package/foundation/discovery/color-modes.mjs +53 -0
  895. package/foundation/discovery/command-pointers.d.mts +21 -4
  896. package/foundation/discovery/command-pointers.mjs +25 -4
  897. package/foundation/discovery/component-discovery.d.mts +10 -0
  898. package/foundation/discovery/component-discovery.mjs +99 -43
  899. package/foundation/discovery/component-replacement.d.mts +8 -0
  900. package/foundation/discovery/component-replacement.mjs +13 -0
  901. package/foundation/discovery/core-augmentation-points.d.mts +90 -0
  902. package/foundation/discovery/core-augmentation-points.mjs +1030 -0
  903. package/foundation/discovery/core-component-views.d.mts +15 -0
  904. package/foundation/discovery/core-component-views.mjs +176 -0
  905. package/foundation/discovery/core-elements.d.mts +29 -0
  906. package/foundation/discovery/core-elements.mjs +57 -0
  907. package/foundation/discovery/core-prop-types.d.mts +65 -0
  908. package/foundation/discovery/core-prop-types.mjs +221 -0
  909. package/foundation/discovery/core-props.d.mts +33 -0
  910. package/foundation/discovery/core-props.mjs +64 -0
  911. package/foundation/discovery/doc-types.d.mts +10 -42
  912. package/foundation/discovery/doc-types.mjs +26 -7
  913. package/foundation/discovery/docs-discovery.d.mts +33 -2
  914. package/foundation/discovery/docs-discovery.mjs +149 -72
  915. package/foundation/discovery/docs-section-key.d.mts +21 -1
  916. package/foundation/discovery/docs-section-key.mjs +57 -19
  917. package/foundation/discovery/hook-discovery.d.mts +2 -0
  918. package/foundation/discovery/hook-discovery.mjs +6 -5
  919. package/foundation/discovery/icon-definition-discovery.d.mts +155 -3
  920. package/foundation/discovery/icon-definition-discovery.mjs +197 -5
  921. package/foundation/discovery/icon-imports.d.mts +66 -0
  922. package/foundation/discovery/icon-imports.mjs +225 -0
  923. package/foundation/discovery/icon-ranking.d.mts +108 -4
  924. package/foundation/discovery/icon-ranking.mjs +277 -70
  925. package/foundation/discovery/icon-set-checks.d.mts +2 -0
  926. package/foundation/discovery/icon-set-checks.mjs +16 -2
  927. package/foundation/discovery/icon-set-discovery.d.mts +42 -2
  928. package/foundation/discovery/icon-set-discovery.mjs +85 -23
  929. package/foundation/discovery/icon-set-writer.d.mts +7 -2
  930. package/foundation/discovery/icon-set-writer.mjs +86 -7
  931. package/foundation/discovery/integration-skills.d.mts +62 -0
  932. package/foundation/discovery/integration-skills.mjs +116 -0
  933. package/foundation/discovery/module-exports.d.mts +8 -0
  934. package/foundation/discovery/module-exports.mjs +20 -21
  935. package/foundation/discovery/package-exports.d.mts +22 -0
  936. package/foundation/discovery/package-exports.mjs +44 -3
  937. package/foundation/discovery/project-typescript.d.mts +5 -1
  938. package/foundation/discovery/project-typescript.mjs +8 -2
  939. package/foundation/discovery/prop-drift.d.mts +16 -0
  940. package/foundation/discovery/prop-drift.mjs +154 -3
  941. package/foundation/discovery/replacement-aliases.d.mts +51 -0
  942. package/foundation/discovery/replacement-aliases.mjs +95 -0
  943. package/foundation/discovery/runner-allowlist.d.mts +1 -1
  944. package/foundation/discovery/runner-allowlist.mjs +1 -1
  945. package/foundation/discovery/stored-component-list.mjs +34 -2
  946. package/foundation/discovery/template-adapter.d.mts +26 -0
  947. package/foundation/discovery/template-adapter.mjs +221 -10
  948. package/foundation/discovery/template-destination.d.mts +14 -6
  949. package/foundation/discovery/template-destination.mjs +42 -8
  950. package/foundation/discovery/template-icon-meanings.d.mts +7 -2
  951. package/foundation/discovery/template-icon-meanings.mjs +52 -12
  952. package/foundation/discovery/template-icons.d.mts +44 -1
  953. package/foundation/discovery/template-icons.mjs +60 -63
  954. package/foundation/discovery/template-needs.d.mts +17 -8
  955. package/foundation/discovery/template-needs.mjs +119 -31
  956. package/foundation/discovery/template-placeholders.d.mts +149 -0
  957. package/foundation/discovery/template-placeholders.mjs +463 -0
  958. package/foundation/discovery/template-source-tree.d.mts +6 -3
  959. package/foundation/discovery/template-source-tree.mjs +8 -5
  960. package/foundation/discovery/theme-discovery.d.mts +8 -0
  961. package/foundation/discovery/theme-discovery.mjs +23 -6
  962. package/foundation/discovery/theme-imports.d.mts +1 -3
  963. package/foundation/discovery/theme-imports.mjs +5 -30
  964. package/foundation/doc-compiler/compile.mjs +6 -8
  965. package/foundation/doc-compiler/doc-syntax.d.mts +25 -1
  966. package/foundation/doc-compiler/doc-syntax.mjs +85 -10
  967. package/foundation/doc-compiler/doc-text.d.mts +52 -0
  968. package/foundation/doc-compiler/doc-text.mjs +176 -0
  969. package/foundation/doc-compiler/links.d.mts +8 -2
  970. package/foundation/doc-compiler/links.mjs +27 -6
  971. package/foundation/doc-compiler/read.d.mts +1 -1
  972. package/foundation/doc-compiler/stored-docs.d.mts +14 -3
  973. package/foundation/doc-compiler/stored-docs.mjs +12 -6
  974. package/foundation/env/cli-command.d.mts +68 -10
  975. package/foundation/env/cli-command.mjs +116 -22
  976. package/foundation/env/package-manager.d.mts +33 -2
  977. package/foundation/env/package-manager.mjs +68 -6
  978. package/foundation/env/user-dirs.d.mts +14 -0
  979. package/foundation/env/user-dirs.mjs +34 -1
  980. package/foundation/env/user-settings.d.mts +15 -0
  981. package/foundation/env/user-settings.mjs +56 -2
  982. package/foundation/fonts/font-stylesheet.d.mts +11 -0
  983. package/foundation/fonts/font-stylesheet.mjs +62 -7
  984. package/foundation/fs/cache-eviction.d.mts +7 -5
  985. package/foundation/fs/cache-eviction.mjs +20 -13
  986. package/foundation/fs/empty-folder.d.mts +12 -0
  987. package/foundation/fs/empty-folder.mjs +30 -0
  988. package/foundation/fs/file-protection.d.mts +11 -0
  989. package/foundation/fs/file-protection.mjs +49 -3
  990. package/foundation/fs/gather-cache.d.mts +14 -7
  991. package/foundation/fs/gather-cache.mjs +163 -67
  992. package/foundation/fs/import-url.d.mts +7 -5
  993. package/foundation/fs/import-url.mjs +7 -5
  994. package/foundation/fs/jiti-cache.d.mts +47 -26
  995. package/foundation/fs/jiti-cache.mjs +222 -130
  996. package/foundation/fs/loaded-files.d.mts +15 -1
  997. package/foundation/fs/loaded-files.mjs +40 -3
  998. package/foundation/fs/module-loader.d.mts +3 -1
  999. package/foundation/fs/module-loader.mjs +85 -5
  1000. package/foundation/fs/path-safety.d.mts +1 -0
  1001. package/foundation/fs/path-safety.mjs +2 -0
  1002. package/foundation/fs/relative-specifier.d.mts +10 -0
  1003. package/foundation/fs/relative-specifier.mjs +28 -0
  1004. package/foundation/integrations/computer-integrations.mjs +11 -10
  1005. package/foundation/integrations/icon-features.d.mts +1 -1
  1006. package/foundation/integrations/icon-features.mjs +1 -1
  1007. package/foundation/integrations/integration-warnings.d.mts +10 -0
  1008. package/foundation/integrations/integration-warnings.mjs +12 -3
  1009. package/foundation/integrations/integrations.d.mts +16 -2
  1010. package/foundation/integrations/integrations.mjs +50 -8
  1011. package/foundation/integrations/may-have-integrations.mjs +7 -6
  1012. package/foundation/integrations/provider-resolution.mjs +19 -2
  1013. package/foundation/integrations/validate-contributions.d.mts +4 -0
  1014. package/foundation/integrations/validate-contributions.mjs +24 -0
  1015. package/foundation/release/agent-text-worker.mjs +33 -1
  1016. package/foundation/release/cache.d.mts +48 -3
  1017. package/foundation/release/cache.mjs +196 -20
  1018. package/foundation/release/choose.d.mts +5 -2
  1019. package/foundation/release/choose.mjs +54 -4
  1020. package/foundation/release/global-state.mjs +10 -2
  1021. package/foundation/release/handoff.mjs +7 -1
  1022. package/foundation/release/notices.d.mts +97 -9
  1023. package/foundation/release/notices.mjs +381 -56
  1024. package/foundation/release/project.d.mts +21 -4
  1025. package/foundation/release/project.mjs +74 -42
  1026. package/foundation/release/run-context.d.mts +6 -0
  1027. package/foundation/release/run-context.mjs +9 -0
  1028. package/foundation/render/assets.d.mts +7 -0
  1029. package/foundation/render/assets.mjs +30 -17
  1030. package/foundation/render/charts.d.mts +11 -10
  1031. package/foundation/render/charts.mjs +112 -1
  1032. package/foundation/render/class-alias.d.mts +23 -0
  1033. package/foundation/render/class-alias.mjs +333 -0
  1034. package/foundation/render/client-bundle.d.mts +183 -0
  1035. package/foundation/render/client-bundle.mjs +1026 -0
  1036. package/foundation/render/component-map.mjs +1 -1
  1037. package/foundation/render/css-cut.d.mts +26 -0
  1038. package/foundation/render/css-cut.mjs +344 -2
  1039. package/foundation/render/dropped-text.d.mts +43 -0
  1040. package/foundation/render/dropped-text.mjs +90 -0
  1041. package/foundation/render/embedded-files.d.mts +24 -1
  1042. package/foundation/render/embedded-files.mjs +41 -4
  1043. package/foundation/render/embedded-imports.d.mts +72 -12
  1044. package/foundation/render/embedded-imports.mjs +206 -70
  1045. package/foundation/render/esbuild-dependency.d.mts +14 -0
  1046. package/foundation/render/esbuild-dependency.mjs +41 -0
  1047. package/foundation/render/file-header.d.mts +7 -2
  1048. package/foundation/render/file-header.mjs +19 -10
  1049. package/foundation/render/html-reader.d.mts +36 -17
  1050. package/foundation/render/html-reader.mjs +239 -32
  1051. package/foundation/render/image-attributes.d.mts +25 -0
  1052. package/foundation/render/image-attributes.mjs +33 -0
  1053. package/foundation/render/markup-edits.mjs +1 -1
  1054. package/foundation/render/package-resolve-hooks.d.mts +54 -0
  1055. package/foundation/render/package-resolve-hooks.mjs +144 -0
  1056. package/foundation/render/page-host.mjs +1 -1
  1057. package/foundation/render/page-worker.mjs +1307 -107
  1058. package/foundation/render/picture-chrome.mjs +13 -1
  1059. package/foundation/render/picture-playwright.mjs +13 -0
  1060. package/foundation/render/picture-window.d.mts +18 -5
  1061. package/foundation/render/picture-window.mjs +211 -19
  1062. package/foundation/render/rebuild.mjs +2 -2
  1063. package/foundation/render/remote-images.d.mts +83 -0
  1064. package/foundation/render/remote-images.mjs +384 -0
  1065. package/foundation/render/render-page.d.mts +214 -6
  1066. package/foundation/render/render-page.mjs +1673 -163
  1067. package/foundation/render/restore-folder.d.mts +13 -0
  1068. package/foundation/render/restore-folder.mjs +30 -0
  1069. package/foundation/render/served-packages.d.mts +14 -1
  1070. package/foundation/render/served-packages.mjs +50 -6
  1071. package/foundation/render/share-checks.d.mts +35 -0
  1072. package/foundation/render/share-checks.mjs +95 -0
  1073. package/foundation/render/source-block.d.mts +14 -3
  1074. package/foundation/render/source-block.mjs +44 -9
  1075. package/foundation/render/srcset.d.mts +32 -0
  1076. package/foundation/render/srcset.mjs +64 -0
  1077. package/foundation/render/ts-paths.d.mts +52 -1
  1078. package/foundation/render/ts-paths.mjs +114 -4
  1079. package/foundation/render/value-uses.d.mts +43 -0
  1080. package/foundation/render/value-uses.mjs +110 -0
  1081. package/foundation/response/error-codes.d.mts +2 -1
  1082. package/foundation/response/error-codes.doc.mjs +16 -10
  1083. package/foundation/response/error-codes.mjs +19 -8
  1084. package/foundation/response/json.d.mts +0 -15
  1085. package/foundation/response/json.mjs +1 -51
  1086. package/foundation/response/response-types.doc.mjs +24 -13
  1087. package/foundation/runtime/css-tree.d.mts +16 -0
  1088. package/foundation/runtime/css-tree.mjs +46 -3
  1089. package/foundation/runtime/lazy-dependencies.d.mts +7 -0
  1090. package/foundation/runtime/lazy-dependencies.mjs +25 -3
  1091. package/foundation/runtime/locked-versions.d.mts +4 -2
  1092. package/foundation/runtime/locked-versions.mjs +18 -10
  1093. package/foundation/runtime/package-root.d.mts +25 -0
  1094. package/foundation/runtime/package-root.mjs +48 -0
  1095. package/foundation/runtime/word-table.d.mts +18 -0
  1096. package/foundation/runtime/word-table.mjs +33 -0
  1097. package/foundation/suggest/other-command.d.mts +23 -0
  1098. package/foundation/suggest/other-command.mjs +49 -5
  1099. package/foundation/text/default-variant.d.mts +20 -0
  1100. package/foundation/text/default-variant.mjs +24 -0
  1101. package/foundation/text/definition-coverage.d.mts +21 -0
  1102. package/foundation/text/definition-coverage.mjs +20 -0
  1103. package/foundation/text/icon-set-next.d.mts +11 -10
  1104. package/foundation/text/icon-set-next.mjs +19 -11
  1105. package/foundation/text/string-utils.mjs +14 -41
  1106. package/foundation/text/suggest-order.d.mts +10 -4
  1107. package/foundation/text/suggest-order.mjs +20 -13
  1108. package/package.json +8 -6
  1109. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +0 -394
  1110. package/assets/docs/tree/render-pages.doc.mjs +0 -135
  1111. package/clients/cli/commands/experimental/render.mjs +0 -154
  1112. package/clients/cli/commands/experimental-render.doc.mjs +0 -73
@@ -1,15 +1,17 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file `astryx experimental render`, forward: one page module to ONE
4
+ * @file `astryx experimental export`, forward: one page module to ONE
5
5
  * self-contained static HTML file. The page renders on the server with the
6
6
  * project's own React and Astryx components; its own StyleX compiles in
7
7
  * memory; Core's stylesheets are cut to the rules the markup uses; local
8
- * images become data: URIs; and the page's source rides along so
9
- * `--reverse` can give it back exactly.
8
+ * images become data: URIs, and so do the https images the page names,
9
+ * fetched once while it renders (remote-images.mjs); and the page's source
10
+ * rides along so `--reverse` can give it back exactly.
10
11
  *
11
- * The file needs no network and runs no script, so it works inside a
12
- * sandboxed frame with a strict content security policy. Its colors follow
12
+ * The file needs no network, and it carries the page's script, which draws
13
+ * the live page over the markup, so it works inside a sandboxed frame that
14
+ * allows scripts under a strict content security policy. Its colors follow
13
15
  * `color-scheme` (and a `data-theme` of `light` or `dark` on the root), since
14
16
  * Astryx tokens use light-dark().
15
17
  *
@@ -21,8 +23,12 @@ import * as os from 'node:os';
21
23
  import * as path from 'node:path';
22
24
  import {fork, spawnSync} from 'node:child_process';
23
25
  import {builtinModules} from 'node:module';
24
- import {fileURLToPath} from 'node:url';
26
+ import {fileURLToPath, pathToFileURL} from 'node:url';
27
+ import {NOT_AN_IMAGE, showsImage} from './image-attributes.mjs';
28
+ import {formatSrcset, parseSrcset} from './srcset.mjs';
29
+ import * as vm from 'node:vm';
25
30
  import postcss from 'postcss';
31
+ import {importUrl} from '../fs/import-url.mjs';
26
32
  import {
27
33
  assetDataUri,
28
34
  isAssetBytes,
@@ -30,18 +36,29 @@ import {
30
36
  MAX_ASSET_BYTES,
31
37
  RenderAssetError,
32
38
  } from './assets.mjs';
33
- import {classesIn, cutCss, layerOrderOf} from './css-cut.mjs';
39
+ import {classesIn, cutCss, cutFontFaces, layerOrderOf} from './css-cut.mjs';
40
+ import {aliasClasses} from './class-alias.mjs';
34
41
  import {asParsed, formatFor, sha256, sourceBlock} from './source-block.mjs';
35
- import {embeddedPathProblem} from './embedded-files.mjs';
36
- import {scanHtml} from './html-reader.mjs';
42
+ import {LINK_OUT, ROOT_ID, compactSource, imageSinks} from './client-bundle.mjs';
43
+ import {remoteImages} from './remote-images.mjs';
44
+ import {ESBUILD_MISSING, findEsbuild} from './esbuild-dependency.mjs';
45
+ import {carriedNameFor, embeddedPathProblem} from './embedded-files.mjs';
46
+ import {scanHtml, VOID} from './html-reader.mjs';
37
47
  import {removeOnStop} from '../fs/stop-cleanup.mjs';
38
- import {aliasOnly, assetRefsOf} from './embedded-imports.mjs';
39
- import {isServedPackage, resolveServed} from './served-packages.mjs';
40
- import {CHART_CSS} from './charts.mjs';
48
+ import {aliasOnly, assetRefsOf, fileNamed} from './embedded-imports.mjs';
49
+ import {babelParser} from '../runtime/lazy-dependencies.mjs';
50
+ import {isServedPackage, packageOf as specPackageOf, resolveServed} from './served-packages.mjs';
51
+ import {CHART_CSS, smallSvgText} from './charts.mjs';
41
52
  import {HOST_EXIT} from './host-exit.mjs';
42
53
  import {endNote, headerNote} from './file-header.mjs';
43
54
  import {textRuns} from './markup-edits.mjs';
55
+ import {childrenReader, dropperOf} from './dropped-text.mjs';
44
56
  import {findNodeModulesPackage, isInside} from '../fs/paths.mjs';
57
+ import {packageOf} from '../doc-compiler/source.mjs';
58
+ import {declaredColorModes} from '../discovery/color-modes.mjs';
59
+ import {alphaOf, parseColor, relativeLuminance} from '../color/css-color.mjs';
60
+ import {installedPackageOf} from './package-resolve-hooks.mjs';
61
+ import {moduleExportSource, resolvePackageModule} from '../discovery/module-exports.mjs';
45
62
 
46
63
  /** How long one page may take to render before it is stopped. */
47
64
  export const RENDER_TIMEOUT_MS = 60_000;
@@ -50,7 +67,7 @@ export {MODULE_EXTENSIONS, PAGE_EXTENSIONS} from './embedded-files.mjs';
50
67
 
51
68
  /**
52
69
  * @typedef {object} RenderWarning
53
- * @property {'dropped-children' | 'remote-asset' | 'missing-asset' | 'page-output' | 'page-script' | 'no-astryx-styles' | 'chart-size' | 'screen-query' | 'not-embedded' | 'node-crash'} code - What kind of problem.
70
+ * @property {'dropped-children' | 'unknown-prop-value' | 'remote-asset' | 'missing-asset' | 'page-output' | 'page-script' | 'no-astryx-styles' | 'chart-size' | 'screen-query' | 'not-embedded' | 'not-carried' | 'node-crash'} code - What kind of problem.
54
71
  * @property {string} message - What happened and what to do, in one sentence.
55
72
  */
56
73
 
@@ -62,9 +79,15 @@ export {MODULE_EXTENSIONS, PAGE_EXTENSIONS} from './embedded-files.mjs';
62
79
  * @property {number} classes - Distinct class names in the markup.
63
80
  * @property {number} cssBytes - Bytes of inlined CSS.
64
81
  * @property {number} markupBytes - Bytes of rendered markup.
82
+ * @property {number} sourceBytes - Bytes of the embedded source block.
65
83
  * @property {number} images - Local files inlined as data: URIs.
66
84
  * @property {RenderWarning[]} warnings
85
+ * @property {string[]} [notCarried] - Files the page uses that the file does not carry, so experimental import cannot give them back (each also has a warning); present only when there are some.
86
+ * @property {{component: string, prop: string, value: string, file: string, line: number}[]} [propValues] - Each string the page's own files give a Core component's prop, for the caller to check against the component's docs.
67
87
  * @property {{name: string, dir: string}[]} fromSet - Packages that came from the package set the CLI runs from, not the page's folder.
88
+ * @property {number} [scriptBytes] - Bytes of the page's script; none in a markup-only render.
89
+ * @property {number} [scriptModules] - The modules the page's script holds; none in a markup-only render.
90
+ * @property {{fetched: string[], failed: {url: string, reason: string}[]}} [remoteImages] - The https images the page names: each address fetched into the file, and each one left as the page wrote it, with why. Present when the page names a remote image and the render writes a file.
68
91
  */
69
92
 
70
93
  /** An error carrying a render error code. */
@@ -135,6 +158,29 @@ function carryScopeOf(dir, cwd) {
135
158
  return cwd && (dir === cwd || isInside(dir, cwd)) ? cwd : dir;
136
159
  }
137
160
 
161
+ /**
162
+ * The folder whose `public/` holds the files a `/` path names: the page's
163
+ * project, when it holds `public/`. Else the nearest folder at or above the
164
+ * page's that holds `public/`, inside the folder whose files the page
165
+ * carries (a site that shares its project with others). Else the project's
166
+ * folder, else the page's.
167
+ * @param {string} dir the page's folder
168
+ * @param {string} scope the folder whose files the page carries
169
+ */
170
+ function siteRootOf(dir, scope) {
171
+ /** @param {string} d */
172
+ const holdsPublic = d =>
173
+ fs.statSync(path.join(d, 'public'), {throwIfNoEntry: false})?.isDirectory() === true;
174
+ const project = projectOf(dir);
175
+ if (project && holdsPublic(project)) return project;
176
+ for (let d = dir; d === scope || isInside(d, scope); d = path.dirname(d)) {
177
+ if (holdsPublic(d)) return d;
178
+ // The walk ends at the scope; at the filesystem root, dirname is the root.
179
+ if (d === scope || path.dirname(d) === d) break;
180
+ }
181
+ return project ?? dir;
182
+ }
183
+
138
184
  /** @param {string} s */
139
185
  const escapeHtml = s =>
140
186
  s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
@@ -149,19 +195,30 @@ const escapeHtml = s =>
149
195
  * @param {string} markup
150
196
  */
151
197
  function rootThemeAttrs(markup) {
198
+ const attrs = rootThemeElement(markup);
199
+ if (!attrs) return '';
200
+ return ['data-astryx-theme', 'data-theme']
201
+ .filter(a => attrs.has(a))
202
+ .map(
203
+ a =>
204
+ ` ${a}="${escapeHtml(String(attrs.get(a))).replace(/"/g, '&quot;')}"`,
205
+ )
206
+ .join('');
207
+ }
208
+
209
+ /**
210
+ * The attributes of the outermost element a theme marks: the root Theme's
211
+ * own. Null for a page with no theme.
212
+ * @param {string} markup
213
+ * @returns {Map<string, string> | null}
214
+ */
215
+ function rootThemeElement(markup) {
152
216
  for (const t of scanHtml(markup)) {
153
217
  if (t.kind !== 'start') continue;
154
- const attrs = new Map(t.attrs);
155
- if (!attrs.has('data-astryx-theme')) continue;
156
- return ['data-astryx-theme', 'data-theme']
157
- .filter(a => attrs.has(a))
158
- .map(
159
- a =>
160
- ` ${a}="${escapeHtml(String(attrs.get(a))).replace(/"/g, '&quot;')}"`,
161
- )
162
- .join('');
218
+ const attrs = new Map(t.attrs.map(([name, value]) => /** @type {[string, string]} */ ([name, value])));
219
+ if (attrs.has('data-astryx-theme')) return attrs;
163
220
  }
164
- return '';
221
+ return null;
165
222
  }
166
223
 
167
224
  /** @param {string} s */
@@ -179,7 +236,7 @@ const decodeAttr = s =>
179
236
  * @param {string} params
180
237
  * @returns {{url: string, layer: string | null, supports: string | null, media: string} | null}
181
238
  */
182
- function importParams(params) {
239
+ export function importParams(params) {
183
240
  const m =
184
241
  /^\s*(?:url\(\s*(['"]?)([\s\S]*?)\1\s*\)|(['"])([\s\S]*?)\3)\s*([\s\S]*)$/.exec(
185
242
  params,
@@ -205,6 +262,148 @@ function importParams(params) {
205
262
  return {url: m[2] ?? m[4] ?? '', layer, supports, media: rest.trim()};
206
263
  }
207
264
 
265
+ /**
266
+ * Where a stylesheet's `@import` of `url` leads, read the way a render inlines
267
+ * it: a relative one from the importing sheet's folder, a package one
268
+ * (`@scope/pkg/x.css`) by Node resolution from the importing sheet.
269
+ * @param {string} url the import's address, as written
270
+ * @param {string} file the importing stylesheet's path
271
+ * @param {ServedSet | null} served
272
+ * @returns {{kind: 'remote'} | {kind: 'preprocessed'} | {kind: 'missing'} | {kind: 'sheet', target: string, fromPackage: boolean}}
273
+ */
274
+ function resolveImport(url, file, served) {
275
+ if (/^([a-z]+:)?\/\//i.test(url)) return {kind: 'remote'};
276
+ if (/\.(scss|sass|less)$/i.test(url)) return {kind: 'preprocessed'};
277
+ const relative = path.resolve(path.dirname(file), url);
278
+ if (/^\.{1,2}\//.test(url) || fs.existsSync(relative)) {
279
+ return fs.existsSync(relative)
280
+ ? {kind: 'sheet', target: relative, fromPackage: false}
281
+ : {kind: 'missing'};
282
+ }
283
+ const target = resolveServed(url.replace(/^~/, ''), file, served);
284
+ return target ? {kind: 'sheet', target, fromPackage: true} : {kind: 'missing'};
285
+ }
286
+
287
+ /**
288
+ * Whether one of the stylesheets a page brings in is an Astryx package's, or
289
+ * reaches one through its `@import`s, followed as {@link expandImports}
290
+ * follows them. A stylesheet counts by the package that holds its file, as a
291
+ * module counts in the page's script; an import that resolves to no file
292
+ * counts by the package it names.
293
+ * @param {string[]} files the page's own stylesheets and the package
294
+ * stylesheets its script imports
295
+ * @param {ServedSet | null} served
296
+ * @returns {boolean}
297
+ */
298
+ function reachesAstryxSheet(files, served) {
299
+ /** @type {Set<string>} */
300
+ const seen = new Set();
301
+ /** @param {string} file @returns {boolean} */
302
+ const visit = file => {
303
+ if (seen.has(file)) return false;
304
+ seen.add(file);
305
+ if (packageOf(file).startsWith('@astryxdesign/')) return true;
306
+ /** @type {import('postcss').Root} */
307
+ let root;
308
+ try {
309
+ const css = fs.readFileSync(file, 'utf8');
310
+ if (!/@import/i.test(css)) return false;
311
+ root = postcss.parse(css, {from: file});
312
+ } catch {
313
+ return false;
314
+ }
315
+ let found = false;
316
+ root.walkAtRules(/^import$/i, rule => {
317
+ const url = importParams(rule.params)?.url;
318
+ if (found || !url) return;
319
+ const to = resolveImport(url, file, served);
320
+ if (to.kind === 'sheet') found = visit(to.target);
321
+ else if (to.kind === 'missing') found = /^@astryxdesign\//.test(url.replace(/^~/, ''));
322
+ });
323
+ return found;
324
+ };
325
+ return files.some(visit);
326
+ }
327
+
328
+ /**
329
+ * A stylesheet's text as an `@import` brings it in: inside the import's
330
+ * `supports()`, media and `layer()` conditions.
331
+ * @param {{layer: string | null, supports: string | null, media: string}} parsed
332
+ * the import's parts, as {@link importParams} reads them
333
+ * @param {string} css
334
+ * @returns {string}
335
+ */
336
+ function underImportConditions(parsed, css) {
337
+ let inner = css;
338
+ if (parsed.supports)
339
+ inner = `@supports (${parsed.supports.replace(/^\((.*)\)$/s, '$1')}){${inner}}`;
340
+ if (parsed.media) inner = `@media ${parsed.media}{${inner}}`;
341
+ if (parsed.layer !== null)
342
+ inner = `@layer${parsed.layer ? ` ${parsed.layer}` : ''}{${inner}}`;
343
+ return inner;
344
+ }
345
+
346
+ /**
347
+ * The stylesheets a page brings in, with every stylesheet their `@import`s
348
+ * reach, followed as {@link expandImports} follows them: each one's file and
349
+ * text, and for a package's stylesheet the package and the file that names
350
+ * it.
351
+ * @param {(ThemeSheet & {css: string})[]} sheets
352
+ * @param {ServedSet | null} served
353
+ * @returns {(ThemeSheet & {css: string})[]}
354
+ */
355
+ function sheetsWithImports(sheets, served) {
356
+ /** @type {(ThemeSheet & {css: string})[]} */
357
+ const out = [];
358
+ /** @type {Set<string>} */
359
+ const seen = new Set();
360
+ /**
361
+ * @param {ThemeSheet & {css: string}} sheet its own text
362
+ * @param {(css: string) => string} scope wraps a text in every condition
363
+ * of the `@import` chain that brought the sheet in
364
+ */
365
+ const visit = (sheet, scope) => {
366
+ if (seen.has(sheet.file)) return;
367
+ seen.add(sheet.file);
368
+ out.push({...sheet, css: scope(sheet.css)});
369
+ if (!/@import/i.test(sheet.css)) return;
370
+ /** @type {import('postcss').Root} */
371
+ let root;
372
+ try {
373
+ root = postcss.parse(sheet.css, {from: sheet.file});
374
+ } catch {
375
+ return;
376
+ }
377
+ root.walkAtRules(/^import$/i, rule => {
378
+ const parsed = importParams(rule.params);
379
+ const url = parsed?.url;
380
+ if (!parsed || !url) return;
381
+ const to = resolveImport(url, sheet.file, served);
382
+ if (to.kind !== 'sheet') return;
383
+ /** @type {string} */
384
+ let css;
385
+ try {
386
+ css = fs.readFileSync(to.target, 'utf8');
387
+ } catch {
388
+ return;
389
+ }
390
+ // Each import's conditions scope the sheet's rules, inside those of
391
+ // the imports before it, as the file inlines them: a sheet imported
392
+ // for one scheme, at any depth, counts as such.
393
+ /** @param {string} text */
394
+ const inner = text => scope(underImportConditions(parsed, text));
395
+ visit(
396
+ to.fromPackage
397
+ ? {file: to.target, css, pkg: specPackageOf(url.replace(/^~/, '')), from: sheet.file}
398
+ : {file: to.target, css},
399
+ inner,
400
+ );
401
+ });
402
+ };
403
+ for (const sheet of sheets) visit(sheet, text => text);
404
+ return out;
405
+ }
406
+
208
407
  /**
209
408
  * Inline a stylesheet's own `@import`s, so a stylesheet pulled in that way is
210
409
  * part of the file: a relative one from the importing sheet's folder
@@ -216,7 +415,9 @@ function importParams(params) {
216
415
  * cut.
217
416
  * @param {string} file the stylesheet's own path
218
417
  * @param {string} css its text
219
- * @param {{warnings: RenderWarning[], carried: Set<string>, included: Set<string>, packageSheets: string[], served: ServedSet | null, seen?: Set<string>}} ctx
418
+ * @param {{warnings: RenderWarning[], carried: Set<string>, importers: Map<string, Set<string>>, included: Set<string>, packageSheets: string[], served: ServedSet | null, seen?: Set<string>}} ctx
419
+ * `importers`: each project stylesheet an `@import` names, with every
420
+ * sheet that imports it
220
421
  * `included`: stylesheet files already in the page (Core's, say), never
221
422
  * inlined twice; `packageSheets`: package stylesheets this pulled in
222
423
  * @returns {string}
@@ -235,7 +436,8 @@ function expandImports(file, css, ctx) {
235
436
  const parsed = importParams(rule.params);
236
437
  if (!parsed || !parsed.url) return;
237
438
  const {url} = parsed;
238
- if (/^([a-z]+:)?\/\//i.test(url)) {
439
+ const to = resolveImport(url, file, ctx.served);
440
+ if (to.kind === 'remote') {
239
441
  ctx.warnings.push({
240
442
  code: 'remote-asset',
241
443
  message: `${path.basename(file)} imports ${url}, which a sandboxed page cannot load, so it is left out; save it beside the stylesheet and import it instead.`,
@@ -243,7 +445,7 @@ function expandImports(file, css, ctx) {
243
445
  rule.remove();
244
446
  return;
245
447
  }
246
- if (/\.(scss|sass|less)$/i.test(url)) {
448
+ if (to.kind === 'preprocessed') {
247
449
  ctx.warnings.push({
248
450
  code: 'missing-asset',
249
451
  message: `${path.basename(file)} imports ${url}, a Sass or Less stylesheet, which a render does not compile, so its styles are missing.`,
@@ -251,17 +453,7 @@ function expandImports(file, css, ctx) {
251
453
  rule.remove();
252
454
  return;
253
455
  }
254
- const relative = path.resolve(path.dirname(file), url);
255
- /** @type {string | null} */
256
- let target;
257
- let fromPackage = false;
258
- if (/^\.{1,2}\//.test(url) || fs.existsSync(relative)) {
259
- target = fs.existsSync(relative) ? relative : null;
260
- } else {
261
- target = resolveServed(url.replace(/^~/, ''), file, ctx.served);
262
- fromPackage = target !== null;
263
- }
264
- if (!target) {
456
+ if (to.kind === 'missing') {
265
457
  ctx.warnings.push({
266
458
  code: 'missing-asset',
267
459
  message: `${path.basename(file)} imports ${url}, which was not found, so its styles are missing.`,
@@ -269,6 +461,8 @@ function expandImports(file, css, ctx) {
269
461
  rule.remove();
270
462
  return;
271
463
  }
464
+ const {target, fromPackage} = to;
465
+ if (!fromPackage) ctx.importers.set(target, (ctx.importers.get(target) ?? new Set()).add(file));
272
466
  if (seen.has(target) || ctx.included.has(target)) {
273
467
  rule.remove();
274
468
  return;
@@ -292,11 +486,7 @@ function expandImports(file, css, ctx) {
292
486
  return `url(${q}${rebased.startsWith('.') ? rebased : `./${rebased}`}${q})`;
293
487
  });
294
488
  // The import's conditions still scope what it brings in.
295
- if (parsed.supports)
296
- inner = `@supports (${parsed.supports.replace(/^\((.*)\)$/s, '$1')}){${inner}}`;
297
- if (parsed.media) inner = `@media ${parsed.media}{${inner}}`;
298
- if (parsed.layer !== null)
299
- inner = `@layer${parsed.layer ? ` ${parsed.layer}` : ''}{${inner}}`;
489
+ inner = underImportConditions(parsed, inner);
300
490
  try {
301
491
  rule.replaceWith(postcss.parse(inner, {from}).nodes);
302
492
  } catch (e) {
@@ -670,7 +860,7 @@ export function awaitHost(host, {timeoutMs, withoutSegmenter, stateFile}) {
670
860
  /**
671
861
  * Run the page. When this Node crashes in Intl.Segmenter, run it once more
672
862
  * without Intl.Segmenter and say so in a warning.
673
- * @param {{entry: string, root: string, scope: string, served: ServedSet | null, openLayers?: boolean}} input
863
+ * @param {{entry: string, root: string, scope: string, served: ServedSet | null, openLayers?: boolean, buildScript?: boolean, esbuild?: string}} input
674
864
  * @param {number} timeoutMs
675
865
  * @param {RenderWarning[]} warnings
676
866
  */
@@ -690,6 +880,258 @@ async function runPage(input, timeoutMs, warnings) {
690
880
  return again;
691
881
  }
692
882
 
883
+ /**
884
+ * The markup with each link out of the file opening in a new tab, as the
885
+ * file's script opens it once it runs (client-bundle.mjs): a viewer's frame
886
+ * cannot follow a link out. A link that names its own target keeps it.
887
+ * @param {string} markup the page's server markup
888
+ * @returns {string}
889
+ */
890
+ export function linksOpenNewTabs(markup) {
891
+ return markup.replace(/<a\b([^>]*)>/g, (tag, /** @type {string} */ attrs) => {
892
+ const href = /\shref="([^"]*)"/.exec(attrs)?.[1];
893
+ if (href === undefined || /\starget="/.test(attrs) || !LINK_OUT.test(href.trim())) return tag;
894
+ const rel = /\srel="([^"]*)"/.exec(attrs);
895
+ const rels = new Set([...(rel ? rel[1].split(/\s+/).filter(Boolean) : []), 'noopener', 'noreferrer']);
896
+ return `<a${rel ? attrs.replace(rel[0], '') : attrs} target="_blank" rel="${[...rels].join(' ')}">`;
897
+ });
898
+ }
899
+
900
+ /**
901
+ * The markup without `autofocus`. The file's script owns focus once it draws
902
+ * the page, as the app does. A viewer's cross-origin frame blocks focus that
903
+ * markup asks for, and logs an error.
904
+ * @param {string} markup the page's server markup
905
+ * @returns {string}
906
+ */
907
+ export function withoutAutofocus(markup) {
908
+ let out = '';
909
+ let at = 0;
910
+ for (const token of scanHtml(markup)) {
911
+ if (token.kind !== 'start') continue;
912
+ for (const [name, , start, end] of token.attrs) {
913
+ if (name !== 'autofocus') continue;
914
+ // The attribute goes with the spaces before it; the reader names
915
+ // where its text starts and ends, so every other attribute stays as
916
+ // written.
917
+ // Not when a `/` follows: `<input title=x/>` would read as title="x/".
918
+ let from = start;
919
+ if (markup[end] !== '/') {
920
+ while (from > token.start && /[\t\n\f\r ]/.test(markup[from - 1])) from--;
921
+ }
922
+ out += markup.slice(at, from);
923
+ at = end;
924
+ }
925
+ }
926
+ return at === 0 ? markup : out + markup.slice(at);
927
+ }
928
+
929
+ /**
930
+ * The render's own attribute on a first-paint element whose `src`, `srcset`
931
+ * or `poster` it carries: each attribute with the number of its value
932
+ * (`src:0 srcset:1`), so the page's script reads the value there
933
+ * ({@link withCarriedPaths}). Only the file's markup has it, never the page's
934
+ * source.
935
+ */
936
+ export const CARRY_ATTR = 'data-astryx-carried';
937
+
938
+ /** The name the script reads the markup's carried values from. */
939
+ const CARRIED_VALUES = '__astryxCarried';
940
+
941
+ /** The script's reader of one candidate of a carried `srcset`, by its place. */
942
+ const CARRIED_CANDIDATE = '__astryxCandidate';
943
+
944
+ /**
945
+ * The script's first statement: each value the markup carries, read from the
946
+ * first paint by its number before the script draws the page again.
947
+ */
948
+ const CARRIED_PRELUDE =
949
+ `var ${CARRIED_VALUES}=(()=>{const v=[];for(const e of document.querySelectorAll('[${CARRY_ATTR}]'))` +
950
+ `for(const c of e.getAttribute('${CARRY_ATTR}').split(' ')){const [a,i]=c.split(':');v[+i]??=e.getAttribute(a)}return v})();`;
951
+
952
+ /**
953
+ * The page's script with each string the markup's rewrite replaced (an
954
+ * image's `src`, `poster` or `srcset`, as the page wrote it) read from the
955
+ * markup, which carries the same data, so the page the script draws shows
956
+ * what the first paint showed and the file holds that data once. A read
957
+ * replaces only a whole string token of the script whose value is exactly
958
+ * that path, found with a JavaScript parser. Every other place the path
959
+ * appears keeps the data itself: a longer string that holds it (inner HTML,
960
+ * a CSS `url()`), a value no first-paint element carries (an image the page
961
+ * shows only later), an object key, or a template a tag reads. A script the
962
+ * parser cannot read, or that would not parse with the reads, keeps the data
963
+ * everywhere.
964
+ * @param {string} script
965
+ * @param {Map<string, string>} rewrites
966
+ * @param {Map<string, number>} carried each value the first paint carries, with
967
+ * the number its mark gives it
968
+ * @param {Set<string>} [srcsets] the carried values a `srcset` marks: only
969
+ * their candidates are read by place
970
+ * @param {Map<string, string>} [painted] what each value became in the first
971
+ * paint (default `rewrites`): a whole value is read only where the script's
972
+ * value is the same, so a srcset that lists an https candidate, which the
973
+ * script keeps as written, is never read whole
974
+ * @param {boolean} [strict] the script is a module script, so it parses in
975
+ * strict mode
976
+ * @returns {string}
977
+ */
978
+ export function withCarriedPaths(script, rewrites, carried, srcsets = new Set(), painted = rewrites, strict = false) {
979
+ const inline = inlineCarried(script, rewrites);
980
+ const tokens = carriedTokens(script, rewrites, carried, srcsets, painted);
981
+ if (tokens.length === 0) return inline;
982
+ // Each token to read becomes a mark no script holds (the script is built
983
+ // ASCII-only, so it never holds a raw private-use character), so the text
984
+ // pass below writes the data everywhere else; then each mark becomes its read.
985
+ let marked = '';
986
+ let at = 0;
987
+ for (const token of tokens) {
988
+ marked += `${script.slice(at, token.start)}\uE000${Array.isArray(token.index) ? token.index.join('.') : token.index}\uE001`;
989
+ at = token.end;
990
+ }
991
+ marked += script.slice(at);
992
+ const candidates = tokens.some(token => Array.isArray(token.index));
993
+ const read =
994
+ CARRIED_PRELUDE +
995
+ (candidates ? `var ${CARRIED_CANDIDATE}=(i,k)=>(${compactSource(parseSrcset)})(${CARRIED_VALUES}[i]??'')[k]?.url;` : '') +
996
+ inlineCarried(marked, rewrites).replace(/\uE000(\d+)(?:\.(\d+))?\uE001/g, (_, i, k, offset, all) =>
997
+ `${/[\w$]/.test(all[offset - 1] ?? '') ? ' ' : ''}${k === undefined ? `${CARRIED_VALUES}[${i}]` : `${CARRIED_CANDIDATE}(${i},${k})`}`,
998
+ );
999
+ try {
1000
+ // A module script parses in strict mode, so the reads must too.
1001
+ new vm.Script(strict ? `"use strict";${read}` : read);
1002
+ return read;
1003
+ } catch {
1004
+ return inline;
1005
+ }
1006
+ }
1007
+
1008
+ /**
1009
+ * The string tokens of the script whose value is exactly a path the first
1010
+ * paint carries, where a read can stand: not an object key, not a template a
1011
+ * tag reads, not text the page shows (`children`). In script order.
1012
+ * @param {string} script
1013
+ * @param {Map<string, string>} rewrites
1014
+ * @param {Map<string, number>} carried
1015
+ * @param {Set<string>} srcsets the carried values a `srcset` marks
1016
+ * @param {Map<string, string>} painted what each value became in the first paint
1017
+ * @returns {{start: number, end: number, index: number | [number, number]}[]}
1018
+ */
1019
+ function carriedTokens(script, rewrites, carried, srcsets, painted) {
1020
+ /** @type {Map<string, number | [number, number]>} */
1021
+ const indexOf = new Map();
1022
+ /** @param {string} value */
1023
+ const quoted = value => !/["'`\\\n]/.test(value) && ['"', "'", '`'].some(q => script.includes(`${q}${value}${q}`));
1024
+ for (const [was] of rewrites) {
1025
+ const index = carried.get(was);
1026
+ if (index !== undefined && painted.get(was) === rewrites.get(was) && quoted(was)) indexOf.set(was, index);
1027
+ }
1028
+ // A local path the script names that a carried srcset lists
1029
+ // (`${a} 1x, ${b} 2x` built in code): read that candidate.
1030
+ for (const [, i, written] of carriedSrcsets(carried, srcsets, rewrites)) {
1031
+ written.forEach(({url}, k) => {
1032
+ if (!indexOf.has(url) && rewrites.has(url) && !/^(https?:)?\/\//i.test(url) && quoted(url)) indexOf.set(url, [i, k]);
1033
+ });
1034
+ }
1035
+ if (indexOf.size === 0) return [];
1036
+ /** @type {any} */
1037
+ let ast;
1038
+ try {
1039
+ ast = babelParser().parse(script, {sourceType: 'script', errorRecovery: false});
1040
+ } catch {
1041
+ return [];
1042
+ }
1043
+ /** @type {{start: number, end: number, index: number | [number, number]}[]} */
1044
+ const found = [];
1045
+ /** @param {any} node @param {any} parent */
1046
+ const visit = (node, parent) => {
1047
+ if (node === null || typeof node !== 'object') return;
1048
+ if (Array.isArray(node)) {
1049
+ for (const child of node) visit(child, parent);
1050
+ return;
1051
+ }
1052
+ if (typeof node.type !== 'string') return;
1053
+ /** @type {string | undefined} */
1054
+ let value;
1055
+ if (node.type === 'StringLiteral') value = node.value;
1056
+ else if (node.type === 'TemplateLiteral' && node.expressions.length === 0 && parent?.type !== 'TaggedTemplateExpression') value = node.quasis[0]?.value?.cooked;
1057
+ if (value !== undefined && indexOf.has(value)) {
1058
+ const key = KEYED.has(parent?.type) && parent.key === node;
1059
+ const shown = parent?.type === 'ObjectProperty' && parent.value === node && !parent.computed && (parent.key?.name ?? parent.key?.value) === 'children';
1060
+ if (!key && !shown) found.push({start: node.start, end: node.end, index: /** @type {number | [number, number]} */ (indexOf.get(value))});
1061
+ }
1062
+ for (const k of Object.keys(node)) {
1063
+ if (k === 'loc' || k === 'start' || k === 'end' || k === 'extra' || k === 'leadingComments' || k === 'trailingComments') continue;
1064
+ visit(node[k], node);
1065
+ }
1066
+ };
1067
+ try {
1068
+ visit(ast.program, null);
1069
+ } catch {
1070
+ // A script nested too deep to walk keeps its inline data.
1071
+ return [];
1072
+ }
1073
+ return found.sort((a, b) => a.start - b.start);
1074
+ }
1075
+
1076
+ /** The nodes whose `key` names a member: a string there is a name, not a value. */
1077
+ const KEYED = new Set(['ObjectProperty', 'ObjectMethod', 'ClassProperty', 'ClassMethod', 'ClassPrivateProperty', 'ClassAccessorProperty']);
1078
+
1079
+ /**
1080
+ * The script with each string that is exactly a path the markup's rewrite
1081
+ * replaced written as the same data, and each CSS url() that names it too.
1082
+ * Text the page shows (`children: "./photo.png"`) stays as written.
1083
+ * @param {string} script
1084
+ * @param {Map<string, string>} rewrites
1085
+ * @returns {string}
1086
+ */
1087
+ function inlineCarried(script, rewrites) {
1088
+ let out = script;
1089
+ for (const [was, now] of rewrites) {
1090
+ if (/["'`\\\n<]/.test(now) || /["'`\\\n]/.test(was)) continue;
1091
+ for (const quote of ['"', "'", '`']) {
1092
+ const literal = `${quote}${was}${quote}`;
1093
+ out = out
1094
+ .split(literal)
1095
+ .map((part, i, parts) =>
1096
+ i === parts.length - 1 ? part : /\bchildren:\s*$/.test(part) ? `${part}${literal}` : `${part}${quote}${now}${quote}`,
1097
+ )
1098
+ .join('');
1099
+ }
1100
+ // A CSS url() in a style the script sets (`backgroundImage:
1101
+ // "url(./bg.png)"`) names the same file. A data: URI with no space,
1102
+ // quote or parenthesis needs no quotes in url().
1103
+ if (/[\s()]/.test(now)) continue;
1104
+ for (const form of [`url(${was})`, `url("${was}")`, `url('${was}')`]) {
1105
+ out = out.split(form).join(`url(${now})`);
1106
+ }
1107
+ }
1108
+ return out;
1109
+ }
1110
+
1111
+ /**
1112
+ * A call of the script's `carried(sha256, prefix)`, which reads an image from
1113
+ * the embedded source. It starts only where a name starts, so a long run of
1114
+ * name characters (a large string in the page) is read once, not once per
1115
+ * character.
1116
+ */
1117
+ const CARRIED_CALL = /(?<![\w$])[A-Za-z_$][\w$]*\((["'])([0-9a-f]{64})\1,\s*(["'])(data:[^"']*;base64)\3\)/g;
1118
+
1119
+ /**
1120
+ * The script with each image the embedded source does not carry written in
1121
+ * as its data: URI (`uriOf` gives it), so the image still shows once the
1122
+ * script draws the page.
1123
+ * @param {string} script
1124
+ * @param {Set<string>} carried the SHA-256 of each file the source carries
1125
+ * @param {(sha256: string, prefix: string) => string | null} uriOf
1126
+ */
1127
+ export function withUncarriedImages(script, carried, uriOf) {
1128
+ return script.replace(CARRIED_CALL, (call, _q, sha, _p, prefix) => {
1129
+ if (carried.has(sha)) return call;
1130
+ const uri = uriOf(sha, prefix);
1131
+ return uri === null ? call : JSON.stringify(uri);
1132
+ });
1133
+ }
1134
+
693
1135
  /**
694
1136
  * The warning for a page rendered without Intl.Segmenter.
695
1137
  * @returns {RenderWarning}
@@ -718,6 +1160,31 @@ export function cssUrlRef(m) {
718
1160
  return m.groups?.dq ?? m.groups?.sq ?? m.groups?.bare ?? '';
719
1161
  }
720
1162
 
1163
+ /** The rel values of a `<link>` the browser fetches its href for. */
1164
+ const FETCHING_RELS = new Set([
1165
+ 'stylesheet',
1166
+ 'icon',
1167
+ 'apple-touch-icon',
1168
+ 'mask-icon',
1169
+ 'manifest',
1170
+ 'preload',
1171
+ 'modulepreload',
1172
+ 'prefetch',
1173
+ ]);
1174
+
1175
+ /**
1176
+ * A reference that loads nothing when the file opens: inline data, a
1177
+ * fragment, or a scheme that names no file (about:, mailto:, tel:,
1178
+ * javascript:).
1179
+ */
1180
+ const NOT_A_LOAD = /^(data:|blob:|#|about:|mailto:|tel:|javascript:)/i;
1181
+
1182
+ /**
1183
+ * Whether a reference, as written, makes the browser load something.
1184
+ * @param {string} ref
1185
+ */
1186
+ export const isLoad = ref => ref.trim() !== '' && !NOT_A_LOAD.test(ref.trim());
1187
+
721
1188
  /**
722
1189
  * What a local file reference of a page or stylesheet names: nothing to
723
1190
  * inline (inline data, a fragment, a non-asset path), a remote file, a file
@@ -726,32 +1193,29 @@ export function cssUrlRef(m) {
726
1193
  * and for callers that say what a page will not show.
727
1194
  * @param {string} ref as written in src, poster or url()
728
1195
  * @param {{dir: string, root: string}} at the folder it is relative to,
729
- * and the project root (for `/` paths, `public/` first)
1196
+ * and the site's root, whose `public/` holds the files `/` paths name
730
1197
  * A reference is URL text: it names the file its percent-escapes decode to
731
1198
  * (`a%20b.png` is "a b.png"), as a browser and the app's bundler read it.
732
1199
  * A file that cannot be read (no permission) is `unreadable`.
733
- * @returns {null | {kind: 'remote', ref: string} | {kind: 'missing', ref: string} | {kind: 'not-file' | 'unreadable' | 'file', ref: string, file: string}}
1200
+ * A remote file's `url` is the whole address the page wrote, its query too.
1201
+ * @returns {null | {kind: 'remote', ref: string, url: string} | {kind: 'missing', ref: string} | {kind: 'not-file' | 'unreadable' | 'file', ref: string, file: string}}
734
1202
  */
735
1203
  export function assetRef(ref, at) {
736
1204
  const clean = decodeAttr(ref).trim().split(/[?#]/)[0];
737
1205
  if (!clean) return null;
738
- if (/^(data:|blob:|#|about:|mailto:|tel:|javascript:)/i.test(clean))
739
- return null;
740
- if (/^(https?:)?\/\//i.test(clean)) return {kind: 'remote', ref: clean};
741
- /** @type {string} */
742
- let named;
743
- try {
744
- named = decodeURIComponent(clean);
745
- } catch {
746
- // A % that starts no escape is the character itself.
747
- named = clean;
748
- }
1206
+ if (NOT_A_LOAD.test(clean)) return null;
1207
+ if (/^(https?:)?\/\//i.test(clean)) return {kind: 'remote', ref: clean, url: decodeAttr(ref).trim()};
1208
+ const named = fileNamed(clean);
749
1209
  if (!isAssetPath(named)) return null;
750
- const candidates = named.startsWith('/')
751
- ? [path.join(at.root, 'public', named), path.join(at.root, named)]
752
- : [path.resolve(at.dir, named)];
753
- const found = candidates.find(c => fs.existsSync(c));
754
- if (!found) return {kind: 'missing', ref: clean};
1210
+ const publicDir = path.join(at.root, 'public');
1211
+ const found = named.startsWith('/')
1212
+ ? path.join(publicDir, named)
1213
+ : path.resolve(at.dir, named);
1214
+ // A `/` path is served from public/ only; one that climbs out of it names
1215
+ // no file of the site.
1216
+ if (named.startsWith('/') && !isInside(found, publicDir))
1217
+ return {kind: 'missing', ref: clean};
1218
+ if (!fs.existsSync(found)) return {kind: 'missing', ref: clean};
755
1219
  /** @type {fs.Stats | undefined} */
756
1220
  let st;
757
1221
  try {
@@ -768,28 +1232,50 @@ export function assetRef(ref, at) {
768
1232
  return {kind: 'file', ref: clean, file: found};
769
1233
  }
770
1234
 
1235
+ /**
1236
+ * The public/ folder a `/` path is read from, as a path from the page's
1237
+ * folder (`public/`, `../../public/`), whichever file names it: the page or
1238
+ * a stylesheet in another folder.
1239
+ * @param {{dir: string, root: string, pageDir?: string}} at
1240
+ */
1241
+ function publicFolderOf(at) {
1242
+ const rel = path.relative(at.pageDir ?? at.dir, path.join(at.root, 'public')).split(path.sep).join('/');
1243
+ return `${rel}/`;
1244
+ }
1245
+
771
1246
  /**
772
1247
  * Inline local images (src, srcset, poster and CSS url()) as data: URIs. A
773
1248
  * link (`href`) loads nothing, so it is left alone.
774
1249
  * @param {string} text markup or CSS
775
1250
  * @param {'html' | 'css'} kind
776
- * @param {{dir: string, root: string, warnings: RenderWarning[], counted: Set<string>, localAssets: Set<string>, leaveLargeStyleAssets?: boolean}} ctx
1251
+ * @param {{dir: string, pageDir?: string, root: string, warnings: RenderWarning[], counted: Set<string>, localAssets: Set<string>, leaveLargeStyleAssets?: boolean, rewrites?: Map<string, string>, carried?: Map<string, number>, srcsets?: Set<string>, remote?: Map<string, import('./remote-images.mjs').RemoteImage>}} ctx
777
1252
  * `leaveLargeStyleAssets`: a stylesheet's file too large to inline is left
778
- * as it is and named, as a missing one is, rather than refused
1253
+ * as it is and named, as a missing one is, rather than refused;
1254
+ * `rewrites`: each attribute value the markup's rewrite replaced, as the
1255
+ * page wrote it, with what it became; `carried`: gets each one the markup
1256
+ * numbers for the page's script (none in a markup-only render); `remote`: the remote images fetched
1257
+ * for this render, by the address the page wrote
779
1258
  */
780
1259
  function inlineAssets(text, kind, ctx) {
781
- /** @param {string} ref */
782
- const resolveRef = ref => {
1260
+ /** @param {string} ref @param {AssetPlace} [place] */
1261
+ const resolveRef = (ref, place) => {
783
1262
  const named = assetRef(ref, ctx);
784
1263
  if (!named) return null;
785
1264
  const clean = named.ref;
786
1265
  if (named.kind === 'remote') {
787
- const key = `remote:${clean}`;
1266
+ // The fetched images go only where an element shows an image, or in a
1267
+ // CSS `url()`: a frame's or a video's `src` keeps its address.
1268
+ const shows = !place || showsImage(place.tag, place.attr);
1269
+ const fetched = shows ? ctx.remote?.get(named.url) : undefined;
1270
+ if (fetched && 'uri' in fetched) return fetched.uri;
1271
+ // Keyed by the whole address, as the later-drawn pass keys it, so one
1272
+ // image gets one warning.
1273
+ const key = `remote:${named.url}`;
788
1274
  if (!ctx.counted.has(key)) {
789
1275
  ctx.counted.add(key);
790
1276
  ctx.warnings.push({
791
1277
  code: 'remote-asset',
792
- message: `${clean} is loaded from the network, which a sandboxed page cannot reach; save it beside the page and import it instead.`,
1278
+ message: `${named.url} is loaded from the network, which a sandboxed page cannot reach; save it beside the page and import it instead.${fetched ? ` The render could not fetch it: ${fetched.reason}.` : ''}`,
793
1279
  });
794
1280
  }
795
1281
  return null;
@@ -802,7 +1288,9 @@ function inlineAssets(text, kind, ctx) {
802
1288
  code: 'missing-asset',
803
1289
  message:
804
1290
  named.kind === 'missing'
805
- ? `${clean} was not found next to the page, so it is left as is and will not show.`
1291
+ ? clean.startsWith('/')
1292
+ ? `${clean} was not found in ${publicFolderOf(ctx)}, where a path from the site's root is read, so it is left as is and will not show.`
1293
+ : `${clean} was not found next to the page, so it is left as is and will not show.`
806
1294
  : named.kind === 'unreadable'
807
1295
  ? `${clean} cannot be read (no permission), so it is left as is and will not show.`
808
1296
  : `${clean} is not a regular file (a pipe, a device or a folder), so it is not read and will not show.`,
@@ -830,40 +1318,426 @@ function inlineAssets(text, kind, ctx) {
830
1318
  return null;
831
1319
  }
832
1320
  ctx.counted.add(`file:${found}`);
833
- // A relative path names a file that is part of the page: carry it.
834
- if (!clean.startsWith('/')) ctx.localAssets.add(found);
1321
+ ctx.localAssets.add(found);
835
1322
  return assetDataUri(found);
836
1323
  };
837
- /** @param {string} value */
838
- const urls = value =>
1324
+ return rewriteRefs(text, kind, resolveRef, ctx.rewrites, ctx.carried, ctx.srcsets);
1325
+ }
1326
+
1327
+ /**
1328
+ * Where markup names a file: an element's name and the attribute's, in lower
1329
+ * case. A CSS `url()` has none.
1330
+ * @typedef {{tag: string, attr: string}} AssetPlace
1331
+ */
1332
+
1333
+ /**
1334
+ * Where the first paint holds an https image's data, for the image sinks to
1335
+ * read: the marked value that is the address, or else a marked `srcset` that
1336
+ * lists it, with the candidate's place there.
1337
+ * @param {string} url
1338
+ * @param {Map<string, number> | undefined} carried
1339
+ * @param {Map<string, [number, number]>} listed each address a marked
1340
+ * `srcset` lists, with its mark and place ({@link listedCandidates})
1341
+ * @returns {[string, number] | [string, number, number] | null}
1342
+ */
1343
+ function firstPaintRead(url, carried, listed) {
1344
+ if (!carried) return null;
1345
+ const mark = carried.get(url);
1346
+ if (mark !== undefined) return [url, mark];
1347
+ const place = listed.get(url);
1348
+ return place ? [url, ...place] : null;
1349
+ }
1350
+
1351
+ /**
1352
+ * Each address a marked `srcset` lists, with that srcset's mark and the
1353
+ * candidate's place in it: the first such place, read once per render.
1354
+ * @param {Map<string, number> | undefined} carried
1355
+ * @param {Set<string>} srcsets the carried values a `srcset` marks
1356
+ * @param {Map<string, string>} rewrites
1357
+ * @returns {Map<string, [number, number]>}
1358
+ */
1359
+ function listedCandidates(carried, srcsets, rewrites) {
1360
+ /** @type {Map<string, [number, number]>} */
1361
+ const listed = new Map();
1362
+ if (!carried) return listed;
1363
+ for (const [, i, written] of carriedSrcsets(carried, srcsets, rewrites)) {
1364
+ written.forEach(({url}, k) => {
1365
+ if (!listed.has(url)) listed.set(url, [i, k]);
1366
+ });
1367
+ }
1368
+ return listed;
1369
+ }
1370
+
1371
+ /**
1372
+ * Each marked `srcset` value whose data lists the same number of candidates
1373
+ * as the page wrote, with its mark: only such a value can give one
1374
+ * candidate's data by its place. A `src` or `poster` that holds a comma and
1375
+ * a space is one address, never a list.
1376
+ * @param {Map<string, number>} carried
1377
+ * @param {Set<string>} srcsets the carried values a `srcset` marks
1378
+ * @param {Map<string, string>} rewrites
1379
+ * @returns {Array<[string, number, import('./srcset.mjs').SrcsetCandidate[]]>}
1380
+ */
1381
+ function carriedSrcsets(carried, srcsets, rewrites) {
1382
+ /** @type {Array<[string, number, import('./srcset.mjs').SrcsetCandidate[]]>} */
1383
+ const lists = [];
1384
+ for (const [was, i] of carried) {
1385
+ const now = rewrites.get(was);
1386
+ if (!srcsets.has(was) || now === undefined) continue;
1387
+ const written = parseSrcset(was);
1388
+ if (parseSrcset(now).length === written.length) lists.push([was, i, written]);
1389
+ }
1390
+ return lists;
1391
+ }
1392
+
1393
+ /** Elements whose content a browser running scripts builds no image of. */
1394
+ const UNBUILT = new Set(['noscript', 'template', 'select']);
1395
+
1396
+ /**
1397
+ * Where `text` holds markup a browser running scripts never makes elements
1398
+ * of, as [start, end] pairs: a comment (a bogus one too), a CDATA section,
1399
+ * the text of a raw-text element (`<textarea>`, `<iframe>`, `<xmp>` and the
1400
+ * others the scanner names, everything after `<plaintext>`), and each
1401
+ * outermost `<noscript>`, `<template>` or `<select>` (whose content Firefox's
1402
+ * parser drops), which runs to its own close tag past any nested in it. The
1403
+ * pieces are the HTML scanner's own.
1404
+ * @param {string} text
1405
+ * @returns {[number, number][]}
1406
+ */
1407
+ function unread(text) {
1408
+ /** @type {[number, number][]} */
1409
+ const ranges = [];
1410
+ /** @type {string[]} */
1411
+ const open = [];
1412
+ let start = 0;
1413
+ for (const piece of scanHtml(text)) {
1414
+ if (open.length === 0 && (piece.kind === 'comment' || piece.kind === 'cdata' || piece.kind === 'raw')) {
1415
+ // A `<![CDATA[` the scanner reads as a bogus comment (outside a foreign
1416
+ // root it tracks) can still be CDATA in a browser: range it to `]]>`.
1417
+ const cdata = piece.kind === 'comment' && text.startsWith('<![CDATA[', piece.start);
1418
+ const close = cdata ? text.indexOf(']]>', piece.start + 9) : -1;
1419
+ ranges.push([piece.start, cdata ? (close < 0 ? text.length : close + 3) : piece.end]);
1420
+ continue;
1421
+ }
1422
+ if ((piece.kind !== 'start' && piece.kind !== 'end') || !UNBUILT.has(piece.tag)) continue;
1423
+ if (piece.kind === 'start') {
1424
+ if (piece.selfClosing) continue;
1425
+ if (open.length === 0) start = piece.start;
1426
+ open.push(piece.tag);
1427
+ continue;
1428
+ }
1429
+ const at = open.lastIndexOf(piece.tag);
1430
+ if (at === -1) continue;
1431
+ open.length = at;
1432
+ if (open.length === 0) ranges.push([start, piece.end]);
1433
+ }
1434
+ if (open.length > 0) ranges.push([start, text.length]);
1435
+ const off = offScript(text);
1436
+ if (off >= 0) ranges.push([off, text.length]);
1437
+ return ranges;
1438
+ }
1439
+
1440
+ /** The tags a serializer writes inside a `<select>`. */
1441
+ const SELECT_CONTENT = new Set(['option', 'optgroup', 'hr']);
1442
+
1443
+ /**
1444
+ * Where `text` first holds a shape a serializer such as React's never writes,
1445
+ * or -1: an end tag that does not close the element open last, CDATA, a
1446
+ * bogus comment, a comment holding `--!>` (which also ends one), a
1447
+ * self-closing HTML tag that is not void, `<plaintext>`, `<frameset>`, a
1448
+ * start tag inside a `<select>` other than option, optgroup or hr, or a
1449
+ * `<noscript>` that a browser running scripts ends elsewhere: it reads the
1450
+ * content as text up to the first `</noscript`, where the scanner reads
1451
+ * markup. Up to that point the scanner and a browser agree on the
1452
+ * elements; past it they may not, so nothing after it marks a carried
1453
+ * value, and each image there keeps its own copy in the script. A gap in
1454
+ * the scanner then costs bytes, never a missing picture.
1455
+ * @param {string} text
1456
+ * @returns {number}
1457
+ */
1458
+ function offScript(text) {
1459
+ /** @type {string[]} */
1460
+ const open = [];
1461
+ /** Each open `<noscript>`: where it starts, and where a browser ends it. @type {{start: number, end: number}[]} */
1462
+ const noscripts = [];
1463
+ const NOSCRIPT_END = /<\/noscript[\t\n\f\r />]/gi;
1464
+ for (const piece of scanHtml(text)) {
1465
+ const outer = noscripts[0];
1466
+ if (outer && piece.start > outer.end) return outer.start;
1467
+ const written = text.slice(piece.start, piece.end);
1468
+ if (piece.kind === 'cdata' || (piece.kind === 'comment' && (!written.startsWith('<!--') || written.includes('--!>')))) return piece.start;
1469
+ if (piece.kind === 'start') {
1470
+ if (piece.tag === 'plaintext' || piece.tag === 'frameset') return piece.start;
1471
+ if (open.includes('select') && !SELECT_CONTENT.has(piece.tag)) return piece.start;
1472
+ if (VOID.has(piece.tag)) continue;
1473
+ if (written.endsWith('/>') && !piece.selfClosing) return piece.start;
1474
+ if (!piece.selfClosing) open.push(piece.tag);
1475
+ if (piece.tag === 'noscript' && !piece.selfClosing) {
1476
+ NOSCRIPT_END.lastIndex = piece.end;
1477
+ const close = NOSCRIPT_END.exec(text);
1478
+ noscripts.push({start: piece.start, end: close ? close.index : text.length});
1479
+ }
1480
+ } else if (piece.kind === 'end') {
1481
+ if (open[open.length - 1] !== piece.tag) return piece.start;
1482
+ open.pop();
1483
+ if (piece.tag === 'noscript') {
1484
+ const own = /** @type {{start: number, end: number}} */ (noscripts.pop());
1485
+ // A browser running scripts ends the outermost one at its first `</noscript`.
1486
+ if (noscripts.length === 0 && piece.start !== own.end) return own.start;
1487
+ }
1488
+ }
1489
+ }
1490
+ return -1;
1491
+ }
1492
+
1493
+
1494
+ /**
1495
+ * Each reference a page's markup or stylesheet loads, read once for every
1496
+ * caller: the render inlines them, and the checks on a written file name
1497
+ * every one it left. In markup: src, poster and srcset attributes, and url() in
1498
+ * style attributes, each read within its own element; in a stylesheet: url().
1499
+ * `resolve` gets each reference as written, with the element and attribute
1500
+ * that hold it in markup, and returns what replaces it, or null to keep it.
1501
+ * @param {string} text markup or CSS
1502
+ * @param {'html' | 'css'} kind
1503
+ * @param {(ref: string, place?: AssetPlace) => string | null} resolve
1504
+ * @param {Map<string, string>} [rewrites] gets each attribute value replaced,
1505
+ * as the page wrote it, with what it became
1506
+ * @param {Map<string, number>} [marked] number each replaced value in the
1507
+ * markup ({@link CARRY_ATTR}), so the page's script reads it there, and
1508
+ * add it to this map with its number
1509
+ * @param {Set<string>} [srcsets] gets each marked value a `srcset` holds
1510
+ * @returns {string} the text with the replacements made
1511
+ */
1512
+ export function rewriteRefs(text, kind, resolve, rewrites, marked, srcsets) {
1513
+ /**
1514
+ * What each replaced value became, for the marks the first paint gets.
1515
+ * @type {Map<string, string[]>}
1516
+ */
1517
+ const became = new Map();
1518
+ /**
1519
+ * Record a replaced value.
1520
+ * @param {string} was
1521
+ * @param {string} now
1522
+ */
1523
+ const carry = (was, now) => {
1524
+ if (!rewrites) return;
1525
+ // The last rewrite of a value is the one the script reads, as without
1526
+ // marks; an element that shows an earlier one is not marked.
1527
+ rewrites.set(was, now);
1528
+ became.set(now, [...(became.get(now) ?? []), was]);
1529
+ };
1530
+ /**
1531
+ * @param {string} value
1532
+ * @param {boolean} [record] keep each rewrite, for a style the script sets
1533
+ */
1534
+ const urls = (value, record = false) =>
839
1535
  value.replace(new RegExp(CSS_URL.source, 'g'), (whole, ...rest) => {
840
- const uri = resolveRef(
841
- cssUrlRef(/** @type {any} */ ({groups: rest.at(-1)})),
842
- );
1536
+ const ref = cssUrlRef(/** @type {any} */ ({groups: rest.at(-1)}));
1537
+ const uri = resolve(ref);
1538
+ if (uri && record && ref) rewrites?.set(ref, uri);
843
1539
  return uri ? `url("${uri}")` : whole;
844
1540
  });
845
1541
  if (kind === 'css') return urls(text);
846
- return text
847
- .replace(/\s(src|poster)="([^"]*)"/g, (whole, attr, ref) => {
848
- const uri = resolveRef(ref);
849
- return uri ? ` ${attr}="${uri}"` : whole;
850
- })
851
- .replace(/\ssrcset="([^"]*)"/g, (whole, set) => {
852
- const parts = decodeAttr(set)
853
- .split(',')
854
- .map(part => {
855
- const [ref, ...rest] = part.trim().split(/\s+/);
856
- const uri = ref ? resolveRef(ref) : null;
857
- return [uri ?? ref, ...rest].join(' ');
1542
+ /**
1543
+ * @param {string} attrs one element's attributes
1544
+ * @param {string} tag the element's name, in lower case
1545
+ */
1546
+ const mapAttributes = (attrs, tag) =>
1547
+ attrs
1548
+ // React writes `srcSet` as it is spelled in JSX; HTML reads attribute
1549
+ // names in any case.
1550
+ .replace(/\s(src|poster)="([^"]*)"/gi, (whole, attr, ref) => {
1551
+ const uri = resolve(ref, {tag, attr: attr.toLowerCase()});
1552
+ if (uri) carry(decodeAttr(ref), uri);
1553
+ return uri ? ` ${attr}="${uri}"` : whole;
1554
+ })
1555
+ .replace(/\s(srcset)="([^"]*)"/gi, (whole, attr, set) => {
1556
+ const written = decodeAttr(set);
1557
+ let carried = false;
1558
+ const candidates = parseSrcset(written).map(({url, descriptor}) => {
1559
+ const uri = resolve(url, {tag, attr: 'srcset'});
1560
+ if (uri) carried = true;
1561
+ return {url: uri ?? url, descriptor};
858
1562
  });
859
- return ` srcset="${parts.join(', ').replace(/"/g, '&quot;')}"`;
860
- })
861
- .replace(/\sstyle="([^"]*)"/g, (whole, style) => {
862
- // The attribute holds escaped text: rewrite the CSS it means, then
863
- // escape it again, so a data: URI's quotes cannot end the attribute.
864
- const css = urls(decodeAttr(style));
865
- return ` style="${css.replace(/&/g, '&amp;').replace(/"/g, '&quot;')}"`;
866
- });
1563
+ if (!carried) return whole;
1564
+ const rewritten = formatSrcset(candidates);
1565
+ carry(written, rewritten);
1566
+ return ` ${attr}="${rewritten.replace(/"/g, '&quot;')}"`;
1567
+ })
1568
+ .replace(/\sstyle="([^"]*)"/g, (whole, style) => {
1569
+ // The attribute holds escaped text: rewrite the CSS it means, then
1570
+ // escape it again, so a data: URI's quotes cannot end the attribute.
1571
+ const css = urls(decodeAttr(style), true);
1572
+ return ` style="${css.replace(/&/g, '&amp;').replace(/"/g, '&quot;')}"`;
1573
+ });
1574
+ // Each element by itself, so a reference knows the element it is in. A
1575
+ // quoted value may hold a `>`, which does not end the tag.
1576
+ const written = text.replace(/<([a-zA-Z][\w-]*)\b((?:[^>"']|"[^"]*"|'[^']*')*)>/g, (tagText, name, attrs) => {
1577
+ const mapped = mapAttributes(attrs, name.toLowerCase());
1578
+ return mapped === attrs ? tagText : `<${name}${mapped}>`;
1579
+ });
1580
+ return marked && rewrites && became.size > 0 ? withCarryMarks(written, became, rewrites, marked, srcsets ?? new Set()) : written;
1581
+ }
1582
+
1583
+ /** The elements whose `src`, `srcset` or `poster` is an image the page shows. */
1584
+ const IMAGE_TAGS = new Set(['img', 'source', 'input', 'video']);
1585
+
1586
+ /**
1587
+ * The markup with each element a browser builds that shows a replaced value
1588
+ * marked ({@link CARRY_ATTR}) with that value's number, once per element,
1589
+ * after its last attribute. Only the first attribute of each name on a real
1590
+ * `img`, `source`, `input` or `video` start tag counts, outside the ranges
1591
+ * {@link unread} names; the pieces are the HTML scanner's own.
1592
+ * @param {string} text
1593
+ * @param {Map<string, string[]>} became what each value became, and the
1594
+ * values written that became it
1595
+ * @param {Map<string, string>} rewrites
1596
+ * @param {Map<string, number>} marked gets each marked value, with its number
1597
+ * @param {Set<string>} srcsets gets each marked value a `srcset` holds
1598
+ * @returns {string}
1599
+ */
1600
+ function withCarryMarks(text, became, rewrites, marked, srcsets) {
1601
+ const ranges = unread(text);
1602
+ /** @type {Array<[number, string]>} */
1603
+ const inserts = [];
1604
+ for (const piece of scanHtml(text)) {
1605
+ if (piece.kind !== 'start' || !IMAGE_TAGS.has(piece.tag) || piece.attrs.length === 0) continue;
1606
+ if (ranges.some(([from, to]) => piece.start > from && piece.start < to)) continue;
1607
+ /** @type {string[]} */
1608
+ const marks = [];
1609
+ const seen = new Set();
1610
+ for (const [name, value] of piece.attrs) {
1611
+ if (seen.has(name)) continue;
1612
+ seen.add(name);
1613
+ if (name !== 'src' && name !== 'srcset' && name !== 'poster') continue;
1614
+ const now = decodeAttr(value);
1615
+ for (const was of became.get(now) ?? []) {
1616
+ if (rewrites.get(was) !== now) continue;
1617
+ // The number stays the value's own, whatever later leaves the rewrites.
1618
+ if (!marked.has(was)) marked.set(was, [...rewrites.keys()].indexOf(was));
1619
+ if (name === 'srcset') srcsets.add(was);
1620
+ marks.push(`${name}:${marked.get(was)}`);
1621
+ }
1622
+ }
1623
+ if (marks.length > 0) inserts.push([/** @type {[string, string, number, number]} */ (piece.attrs.at(-1))[3], ` ${CARRY_ATTR}="${[...new Set(marks)].join(' ')}"`]);
1624
+ }
1625
+ let out = '';
1626
+ let at = 0;
1627
+ for (const [where, mark] of inserts) {
1628
+ out += text.slice(at, where) + mark;
1629
+ at = where;
1630
+ }
1631
+ return out + text.slice(at);
1632
+ }
1633
+
1634
+ /**
1635
+ * The remote addresses markup or CSS names where an image goes, as the page
1636
+ * wrote them: where an element shows an image (showsImage), and `url()` in a
1637
+ * `style` attribute or a stylesheet, except an address that names a font,
1638
+ * media or a document.
1639
+ * @param {string} text
1640
+ * @param {'html' | 'css'} kind
1641
+ * @param {{dir: string, root: string}} at
1642
+ * @returns {Set<string>}
1643
+ */
1644
+ function remoteRefsIn(text, kind, at) {
1645
+ /** @type {Set<string>} */
1646
+ const found = new Set();
1647
+ /** @param {string} ref @param {AssetPlace} [place] */
1648
+ const take = (ref, place) => {
1649
+ if (place && !showsImage(place.tag, place.attr)) return null;
1650
+ const named = assetRef(ref, at);
1651
+ if (named?.kind === 'remote' && !NOT_AN_IMAGE.test(named.ref)) found.add(named.url);
1652
+ return null;
1653
+ };
1654
+ rewriteRefs(text, kind, take);
1655
+ return found;
1656
+ }
1657
+
1658
+ /**
1659
+ * The function Core's naming module builds a part's class with, from the Core
1660
+ * the page uses, so the namespace comes from Core and not from the CLI. Null
1661
+ * when the page has no Core, or its Core has no naming module that loads.
1662
+ * @param {string} entry
1663
+ * @param {ServedSet | null} served
1664
+ * @returns {Promise<((part: string) => string) | null>}
1665
+ */
1666
+ async function coreClassNamer(entry, served) {
1667
+ const file = resolveServed('@astryxdesign/core/naming', entry, served);
1668
+ if (!file) return null;
1669
+ try {
1670
+ const {stableClassName} = await importUrl(pathToFileURL(file).href);
1671
+ return typeof stableClassName === 'function' ? stableClassName : null;
1672
+ } catch {
1673
+ // A Core whose naming module does not load keeps the cut as before.
1674
+ return null;
1675
+ }
1676
+ }
1677
+
1678
+ /**
1679
+ * What a page's markup loads that the render does not carry, each once
1680
+ * (a reference that loads nothing, NOT_A_LOAD, aside): the href of a link
1681
+ * with a rel the browser fetches (FETCHING_RELS), the src or data of
1682
+ * iframe, object and embed elements, the href or xlink:href of SVG image,
1683
+ * use and feImage elements,
1684
+ * the url(), CSS import rules and image-set() strings of style elements, and
1685
+ * the image-set() strings of style attributes. The render warns about each,
1686
+ * and the checks on a written file name every one of them.
1687
+ * @param {string} markup
1688
+ * @returns {Array<{tag: string, ref: string}>}
1689
+ */
1690
+ export function embeddedLoads(markup) {
1691
+ /** @type {Array<{tag: string, ref: string}>} */
1692
+ const loads = [];
1693
+ /** @type {Set<string>} */
1694
+ const seen = new Set();
1695
+ /** @param {string} tag @param {string} ref */
1696
+ const add = (tag, ref) => {
1697
+ const key = `${tag} ${ref}`;
1698
+ if (!ref || NOT_A_LOAD.test(ref.trim()) || seen.has(key)) return;
1699
+ seen.add(key);
1700
+ loads.push({tag, ref});
1701
+ };
1702
+ /** The strings an image-set() names, which url() does not cover. @param {string} tag @param {string} css */
1703
+ const imageSets = (tag, css) => {
1704
+ for (const [, inner] of css.matchAll(/(?:-webkit-)?image-set\(([^()]*(?:\([^()]*\)[^()]*)*)\)/gi)) {
1705
+ for (const m of inner.matchAll(/(?<![\w(])(["'])([^"']*)\1/g)) add(tag, m[2]);
1706
+ }
1707
+ };
1708
+ /** @param {string} css */
1709
+ const styleSheet = css => {
1710
+ for (const m of css.matchAll(/@import\s+([^;]+);?/gi)) add('style', importParams(m[1])?.url ?? '');
1711
+ for (const m of css.matchAll(new RegExp(CSS_URL.source, 'g'))) add('style', cssUrlRef(m));
1712
+ imageSets('style', css);
1713
+ };
1714
+ let inStyle = false;
1715
+ // Tags and attributes are read as a browser reads them (scanHtml): an
1716
+ // attribute's place in the tag does not matter.
1717
+ for (const token of scanHtml(markup)) {
1718
+ if (token.kind === 'raw') {
1719
+ if (inStyle) styleSheet(markup.slice(token.start, token.end));
1720
+ continue;
1721
+ }
1722
+ if (token.kind !== 'start') continue;
1723
+ inStyle = token.tag === 'style';
1724
+ const attrs = new Map(token.attrs.map(([name, value]) => [name, decodeAttr(value)]));
1725
+ const style = attrs.get('style');
1726
+ if (style) imageSets(token.tag, style);
1727
+ if (token.tag === 'link') {
1728
+ // A link loads only for a rel the browser fetches; a canonical or
1729
+ // author link names a page and loads nothing.
1730
+ const rels = (attrs.get('rel') ?? '').toLowerCase().split(/\s+/);
1731
+ if (rels.some(r => FETCHING_RELS.has(r))) add('link', attrs.get('href') ?? '');
1732
+ } else if (token.tag === 'iframe' || token.tag === 'embed') {
1733
+ add(token.tag, attrs.get('src') ?? '');
1734
+ } else if (token.tag === 'object') {
1735
+ add(token.tag, attrs.get('data') ?? '');
1736
+ } else if (token.tag === 'image' || token.tag === 'use' || token.tag === 'feimage') {
1737
+ add(token.tag, attrs.get('href') ?? attrs.get('xlink:href') ?? '');
1738
+ }
1739
+ }
1740
+ return loads;
867
1741
  }
868
1742
 
869
1743
  /**
@@ -895,10 +1769,208 @@ function installedVersion(name, dir, setDirs) {
895
1769
  const SCHEME_CSS =
896
1770
  ':root{color-scheme:light dark}:root[data-theme="light"]{color-scheme:light}:root[data-theme="dark"]{color-scheme:dark}';
897
1771
 
1772
+ /** The tokens that set a page's own surface and text colors. */
1773
+ const PAGE_COLOR_TOKEN = /^--color-(background-(body|surface)|text-primary)$/;
1774
+
1775
+ /** A page color token that sets the page's background, not its text. */
1776
+ const BACKGROUND_TOKEN = /^--color-background-/;
1777
+
1778
+ /**
1779
+ * A condition that applies a rule in one scheme only: a
1780
+ * `prefers-color-scheme` query (`not` forms included), a `data-theme` or
1781
+ * scheme attribute, or a `.light`/`.dark` class, in a selector or an
1782
+ * at-rule around it.
1783
+ */
1784
+ const MODE_CONDITION = /prefers-color-scheme|\[data-(?:theme|astryx-scheme)="(?:light|dark)"\]|\.(?:light|dark)(?![\w-])/;
1785
+
1786
+ /**
1787
+ * A selector or condition without its `:not(...)` groups.
1788
+ * @param {string} text
1789
+ */
1790
+ const withoutNegations = text => text.replace(/:not\((?:[^()]|\([^()]*\))*\)/g, '');
1791
+
1792
+ /**
1793
+ * A stylesheet with every `data-*` attribute selector written one way,
1794
+ * `[data-x="v"]`, however it was quoted (`[data-x='v']`, `[data-x=v]`)
1795
+ * or flagged (`[data-x="V" i]`).
1796
+ * @param {string} text
1797
+ */
1798
+ const withQuotedAttributes = text =>
1799
+ text.replace(/\[\s*(data-[\w-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s\]'"]+))\s*(?:([iIsS])\s*)?\]/g, (_, attr, dq, sq, bare, flag) => {
1800
+ const value = dq ?? sq ?? bare;
1801
+ // A value matches case-sensitively unless the `i` flag says otherwise.
1802
+ return `[${attr}="${flag === 'i' || flag === 'I' ? value.toLowerCase() : value}"]`;
1803
+ });
1804
+
1805
+ /**
1806
+ * The one color mode the page's root theme draws in, or null when it draws
1807
+ * in both (or the page has no theme). The theme module's `colorModes`
1808
+ * export says it when the module has one. Else the page and text colors the
1809
+ * stylesheets the page imports set on the theme's root say it: a light page with
1810
+ * dark text draws in light only, a dark page with light text in dark only.
1811
+ * A theme that sets neither (its fonts, its accent), sets a `light-dark()`
1812
+ * color, one the color reader cannot fix (a `var()`) or a translucent
1813
+ * page color, or sets any page or text color under a light or dark condition,
1814
+ * draws in both, as the reader's scheme decides.
1815
+ * @param {string} markup
1816
+ * @param {'light' | 'dark' | 'both' | null} declared the theme module's
1817
+ * `colorModes`, as {@link declaredColorModes} reads it
1818
+ * @param {string[]} sheets the text of the stylesheets the page imports
1819
+ * @returns {'light' | 'dark' | null}
1820
+ */
1821
+ export function oneColorModeOf(markup, declared, sheets) {
1822
+ if (declared === 'light' || declared === 'dark') return declared;
1823
+ if (declared === 'both') return null;
1824
+ const name = rootThemeElement(markup)?.get('data-astryx-theme');
1825
+ if (!name) return null;
1826
+ const root = `[data-astryx-theme="${name}"]`;
1827
+ /** @type {{background: boolean, value: string}[]} */
1828
+ const colors = [];
1829
+ let conditional = false;
1830
+ for (const sheet of sheets) {
1831
+ const text = withQuotedAttributes(sheet);
1832
+ if (!text.includes(root)) continue;
1833
+ /** @type {any} */
1834
+ let tree;
1835
+ try {
1836
+ tree = postcss.parse(text);
1837
+ } catch {
1838
+ return null;
1839
+ }
1840
+ tree.walkDecls(PAGE_COLOR_TOKEN, (/** @type {any} */ decl) => {
1841
+ /** The selectors and at-rule conditions around the declaration. */
1842
+ const contexts = [];
1843
+ for (let at = decl.parent; at && at.type !== 'root'; at = at.parent) {
1844
+ contexts.push(at.type === 'rule' ? at.selector : `@${at.name} ${at.params}`);
1845
+ }
1846
+ // A media surface fixes its own mode; it says nothing of the theme's. A
1847
+ // rule that only keeps out of media surfaces (`:not(… [data-astryx-media]
1848
+ // …)`) still counts.
1849
+ if (contexts.some(context => withoutNegations(context).includes('data-astryx-media'))) return;
1850
+ // A page color set for one scheme only, anywhere in the theme's sheet,
1851
+ // makes the theme follow the viewer.
1852
+ if (contexts.some(context => MODE_CONDITION.test(context))) {
1853
+ conditional = true;
1854
+ return;
1855
+ }
1856
+ const rule = decl.parent;
1857
+ if (rule?.type !== 'rule' || contexts.slice(1).some(context => !context.startsWith('@'))) return;
1858
+ const selector = rule.selector.trim();
1859
+ // Only the theme's own root sets the page's colors: its attribute, or
1860
+ // `:scope` in an @scope that starts there (its `to (...)` limit names
1861
+ // no root).
1862
+ const scope =
1863
+ rule.parent?.type === 'atrule' && rule.parent.name === 'scope'
1864
+ ? rule.parent.params.split(/\)\s*to\s*\(/)[0].replace(/^\s*\(\s*|\s*\)\s*$/g, '')
1865
+ : null;
1866
+ if (selector === root || (selector === ':scope' && scope === root)) {
1867
+ colors.push({background: BACKGROUND_TOKEN.test(decl.prop), value: decl.value});
1868
+ }
1869
+ });
1870
+ }
1871
+ if (conditional || colors.length === 0) return null;
1872
+ /** @type {Set<'light' | 'dark'>} */
1873
+ const modes = new Set();
1874
+ for (const {background, value} of colors) {
1875
+ const rgb = parseColor(value);
1876
+ // A color the reader cannot fix (a var(), light-dark()), or a page color
1877
+ // that shows what is behind it, leaves the reader's scheme to decide.
1878
+ // Text is light or dark by its own color, whatever its alpha.
1879
+ if (!rgb || (background && alphaOf(value) < 1)) return null;
1880
+ const lightColor = relativeLuminance(rgb) > 0.18;
1881
+ // A light page, or dark text, is a light theme's.
1882
+ modes.add(background === lightColor ? 'light' : 'dark');
1883
+ }
1884
+ return modes.size === 1 ? [...modes][0] : null;
1885
+ }
1886
+
1887
+ /**
1888
+ * A stylesheet the page imports: its file, and for a package's stylesheet
1889
+ * the package name and the file that imports it.
1890
+ * @typedef {{file: string, pkg?: string, from?: string}} ThemeSheet
1891
+ */
1892
+
1893
+ /**
1894
+ * The `colorModes` the module of the page's root theme declares, read
1895
+ * without running it. The module sits beside the theme's stylesheet: a
1896
+ * package's entry (or its `./built` entry) when the page imports the
1897
+ * package's stylesheet, or a module with the stylesheet's name beside it.
1898
+ * Only a module that names the root theme counts.
1899
+ * @param {string} markup
1900
+ * @param {ThemeSheet[]} sheets the stylesheets the page imports
1901
+ * @param {(specifier: string, from: string) => string | null} resolve the
1902
+ * module file a bare specifier names from a file
1903
+ * @returns {'light' | 'dark' | 'both' | null}
1904
+ */
1905
+ function rootThemeColorModes(markup, sheets, resolve) {
1906
+ const name = rootThemeElement(markup)?.get('data-astryx-theme');
1907
+ if (!name) return null;
1908
+ /** @type {Set<string>} */
1909
+ const candidates = new Set();
1910
+ for (const {file, pkg, from} of sheets) {
1911
+ const base = file.replace(/\.css$/i, '');
1912
+ for (const ext of ['.js', '.mjs', '.ts', '.tsx']) candidates.add(base + ext);
1913
+ // The package by the name the page imports it as, as `theme add` finds
1914
+ // it (a linked package's real path holds no node_modules); else the
1915
+ // installed package folder that holds the file.
1916
+ let pkgName = pkg ?? null;
1917
+ let at = from ?? file;
1918
+ if (!pkgName) {
1919
+ const pkgDir = installedPackageOf(file);
1920
+ if (!pkgDir) continue;
1921
+ try {
1922
+ pkgName = JSON.parse(fs.readFileSync(path.join(pkgDir, 'package.json'), 'utf8'))?.name ?? null;
1923
+ } catch {
1924
+ continue;
1925
+ }
1926
+ at = file;
1927
+ }
1928
+ if (typeof pkgName !== 'string' || pkgName === '@astryxdesign/core') continue;
1929
+ // The built entry first, which `theme add` reads and which carries the
1930
+ // export, then the package's own.
1931
+ for (const specifier of [`${pkgName}/built`, pkgName]) {
1932
+ const target = resolve(specifier, at);
1933
+ if (target) candidates.add(target);
1934
+ }
1935
+ }
1936
+ const named = new RegExp(`name:\\s*["']${name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}["']`);
1937
+ for (const file of candidates) {
1938
+ if (!isFileAt(file)) continue;
1939
+ // The module must hold the root theme: its name, as a built theme
1940
+ // writes it, in the module or in the file its colorModes come from.
1941
+ const holds = [file, moduleExportSource(file, 'colorModes')].some(f => {
1942
+ if (!f) return false;
1943
+ try {
1944
+ return named.test(fs.readFileSync(f, 'utf8'));
1945
+ } catch {
1946
+ return false;
1947
+ }
1948
+ });
1949
+ if (!holds) continue;
1950
+ // A module that holds the theme but declares no modes (a package's
1951
+ // source entry, beside its built one that does) leaves the next to say.
1952
+ const declared = declaredColorModes(file);
1953
+ if (declared !== null) return declared;
1954
+ }
1955
+ return null;
1956
+ }
1957
+
1958
+ /**
1959
+ * The page's scheme rules. A page that draws in one mode keeps that scheme
1960
+ * whatever the viewer's, and paints the theme's own page color on the
1961
+ * document, so a viewer of the other scheme never shows its own canvas
1962
+ * behind the theme's text. It adds no specificity: a page's own unlayered
1963
+ * `html` rule still wins, but a rule inside `@layer` does not.
1964
+ * @param {'light' | 'dark' | null} mode
1965
+ */
1966
+ function schemeCssFor(mode) {
1967
+ return mode ? `:where(:root){color-scheme:${mode};background-color:var(--color-background-body)}` : SCHEME_CSS;
1968
+ }
1969
+
898
1970
  /**
899
1971
  * Render a page module to one self-contained HTML file.
900
1972
  * @param {string} entry absolute path of the page module
901
- * @param {{title?: string, timeoutMs?: number, version?: string, served?: ServedSet | null, output?: string, cwd?: string, openLayers?: boolean, leaveLargeStyleAssets?: boolean}} [options]
1973
+ * @param {{title?: string, timeoutMs?: number, version?: string, served?: ServedSet | null, output?: string, cwd?: string, openLayers?: boolean, leaveLargeStyleAssets?: boolean, markupOnly?: boolean, esbuildFrom?: string, remoteImages?: Parameters<typeof remoteImages>[0], cutFontFaces?: boolean, keepClassNames?: boolean}} [options]
902
1974
  * `served`: the Core of the package set the CLI runs from, for the packages
903
1975
  * the page's folder has no copy of; `output`: the file the HTML goes to;
904
1976
  * `cwd`: the current folder, whose files are the page's own outside a
@@ -909,20 +1981,49 @@ const SCHEME_CSS =
909
1981
  * names such files itself). With `output`, the file describes itself: notes at its top and end name
910
1982
  * what made it and the commands that give the page back and render it
911
1983
  * again, and its embedded source records the CLI version, the packages
912
- * the page rendered with, and the markup as rendered.
1984
+ * the page rendered with, and the markup as rendered. The file also
1985
+ * carries the page's script (client-bundle.mjs): it draws the page over
1986
+ * its markup in the browser, so the page's controls work. The markup sits
1987
+ * in one element the script draws into, and the stylesheet keeps the rules
1988
+ * any of the page's modules can use, not only the markup's. esbuild, a
1989
+ * dependency of the CLI, builds the script (`esbuildFrom`: the folder it
1990
+ * resolves from); a page whose script cannot be built fails the render.
1991
+ * `keepClassNames` keeps every class of the first paint as written,
1992
+ * for a caller that styles the markup with its own copy of the styles.
1993
+ * `markupOnly` renders the markup and its styles without the script, for a
1994
+ * caller that shows the markup itself (the theme editor); it writes no file
1995
+ * and reaches no network. The render fetches each https image the page
1996
+ * names, once, so the file carries it (remote-images.mjs; `remoteImages`:
1997
+ * the fetch and its time limits, for tests).
1998
+ * `cutFontFaces` drops each font face that no character in the page, its
1999
+ * stylesheet or its script reaches (css-cut.mjs), for a file whose text is
2000
+ * known (export); a page a person types into keeps every face.
913
2001
  * @returns {Promise<RenderedPage>}
914
2002
  */
915
2003
  export async function renderPage(entry, options = {}) {
916
2004
  const dir = path.dirname(entry);
917
- // The project's folder, else the page's: where its tsconfig.json and
918
- // public/ images are read.
2005
+ // The project's folder, else the page's: where its tsconfig.json is read
2006
+ // and paths in messages start.
919
2007
  const root = projectOf(dir) ?? dir;
920
2008
  const scope = carryScopeOf(dir, options.cwd);
2009
+ // Where a `/` path's public/ folder is.
2010
+ const site = siteRootOf(dir, scope);
921
2011
  const served = options.served ?? null;
922
2012
  /** @type {RenderWarning[]} */
923
2013
  const warnings = [];
2014
+ /** @type {string | undefined} */
2015
+ let esbuild;
2016
+ if (!options.markupOnly) {
2017
+ esbuild = findEsbuild(options.esbuildFrom) ?? undefined;
2018
+ if (!esbuild) {
2019
+ throw new RenderError(
2020
+ 'ERR_RENDER_MISSING_DEPENDENCY',
2021
+ `The render builds the page's script, but ${ESBUILD_MISSING}; nothing was written.`,
2022
+ );
2023
+ }
2024
+ }
924
2025
  const message = await runPage(
925
- {entry, root, scope, served, openLayers: options.openLayers === true},
2026
+ {entry, root, scope, served, openLayers: options.openLayers === true, buildScript: esbuild !== undefined, esbuild},
926
2027
  options.timeoutMs ?? RENDER_TIMEOUT_MS,
927
2028
  warnings,
928
2029
  );
@@ -934,7 +2035,7 @@ export async function renderPage(entry, options = {}) {
934
2035
  );
935
2036
  }
936
2037
  /** @type {string} */
937
- let markup = message.markup;
2038
+ let markup = withoutAutofocus(linksOpenNewTabs(message.markup));
938
2039
 
939
2040
  // Stylesheets: Core's reset and components, plus each official package's
940
2041
  // own stylesheet the page imports from.
@@ -944,6 +2045,8 @@ export async function renderPage(entry, options = {}) {
944
2045
  const sheetText = [];
945
2046
  /** Each stylesheet's own file, so its url()s resolve from its folder. @type {string[]} */
946
2047
  const sheetFiles = [];
2048
+ /** Whether each stylesheet is Core's or an official package's (`@astryxdesign/*`). @type {boolean[]} */
2049
+ const sheetIsAstryx = [];
947
2050
  /** @param {string} spec */
948
2051
  const addSheet = spec => {
949
2052
  try {
@@ -952,6 +2055,7 @@ export async function renderPage(entry, options = {}) {
952
2055
  sheets.push(spec);
953
2056
  sheetText.push(fs.readFileSync(file, 'utf8'));
954
2057
  sheetFiles.push(file);
2058
+ sheetIsAstryx.push(true);
955
2059
  return true;
956
2060
  } catch {
957
2061
  return false;
@@ -959,17 +2063,29 @@ export async function renderPage(entry, options = {}) {
959
2063
  };
960
2064
  const hasCore = addSheet('@astryxdesign/core/reset.css');
961
2065
  if (hasCore) addSheet('@astryxdesign/core/astryx.css');
2066
+ /** The package stylesheets the page's modules import. @type {string[]} */
2067
+ const scriptSheets = [];
2068
+ let scriptNamesAstryx = false;
2069
+ /** The text of the stylesheets the page imports itself: its theme's, and its own. @type {string[]} */
2070
+ const themeSheets = [];
2071
+ /** Those package stylesheets: each file, and the package and importer it came by. @type {ThemeSheet[]} */
2072
+ const themeSheetFiles = [];
962
2073
  // Package stylesheets the page imports itself, such as a theme's.
963
2074
  for (const {spec, from} of /** @type {{spec: string, from: string}[]} */ (
964
2075
  message.packageCss ?? []
965
2076
  )) {
966
- if (sheets.includes(spec)) continue;
967
2077
  const file = resolveServed(spec, from, served);
2078
+ if (file) scriptSheets.push(file);
2079
+ else if (spec.startsWith('@astryxdesign/')) scriptNamesAstryx = true;
2080
+ if (sheets.includes(spec)) continue;
968
2081
  try {
969
2082
  if (!file) throw new Error('not found');
970
2083
  sheets.push(spec);
971
2084
  sheetText.push(fs.readFileSync(file, 'utf8'));
972
2085
  sheetFiles.push(file);
2086
+ themeSheets.push(/** @type {string} */ (sheetText.at(-1)));
2087
+ themeSheetFiles.push({file, pkg: specPackageOf(spec), from});
2088
+ sheetIsAstryx.push(spec.startsWith('@astryxdesign/'));
973
2089
  } catch {
974
2090
  warnings.push({
975
2091
  code: 'missing-asset',
@@ -992,18 +2108,71 @@ export async function renderPage(entry, options = {}) {
992
2108
  });
993
2109
  }
994
2110
 
2111
+ // A page that uses nothing from Astryx is not what the command makes: its
2112
+ // own app's build shares it. Its script's module graph (local components,
2113
+ // re-exports and lazy imports included) and the stylesheets it brings in
2114
+ // decide, before any stylesheet is expanded, any asset inlined, any image
2115
+ // fetched or anything written. A markup-only render builds no script and
2116
+ // is not checked.
2117
+ const ownSheets = /** @type {{file: string}[]} */ (message.importedCss ?? []).map(({file}) => file);
2118
+ if (
2119
+ message.astryx === false &&
2120
+ !scriptNamesAstryx &&
2121
+ !reachesAstryxSheet([...ownSheets, ...scriptSheets], served)
2122
+ ) {
2123
+ throw new RenderError(
2124
+ 'ERR_RENDER_NOT_ASTRYX',
2125
+ `${path.basename(entry)} uses no Astryx components or styles; \`astryx experimental export\` only writes pages built with Astryx. Don't add Astryx to this app to export it: share the page with the app's own build instead (for a Vite app, a single-file build); nothing was written.`,
2126
+ );
2127
+ }
2128
+
2129
+ // The https images the page names, fetched once so the file carries them.
2130
+ // A markup-only render reaches no network.
2131
+ const remote = options.markupOnly ? null : remoteImages(options.remoteImages);
995
2132
  const ctx = {
996
2133
  dir,
997
- root,
2134
+ // A stylesheet's own folder replaces `dir` for its url()s; a warning
2135
+ // still names folders from the page's.
2136
+ pageDir: dir,
2137
+ root: site,
998
2138
  warnings,
999
2139
  counted: new Set(),
1000
2140
  localAssets: /** @type {Set<string>} */ (new Set()),
1001
2141
  leaveLargeStyleAssets: options.leaveLargeStyleAssets === true,
2142
+ rewrites: /** @type {Map<string, string>} */ (new Map()),
2143
+ // The page's script reads the data the markup carries; a markup-only
2144
+ // render has no script.
2145
+ carried: options.markupOnly ? undefined : /** @type {Map<string, number>} */ (new Map()),
2146
+ srcsets: /** @type {Set<string>} */ (new Set()),
2147
+ remote: remote?.results,
2148
+ };
2149
+ /**
2150
+ * Inline what `text` names, after fetching the remote images it names that
2151
+ * no earlier text named.
2152
+ * @param {string} text
2153
+ * @param {'html' | 'css'} kind
2154
+ * @param {typeof ctx} at
2155
+ */
2156
+ const inlineWithRemote = async (text, kind, at) => {
2157
+ if (remote) await remote.get(remoteRefsIn(text, kind, at));
2158
+ return inlineAssets(text, kind, at);
1002
2159
  };
1003
2160
  /** Stylesheets pulled in by another's `@import`. @type {Set<string>} */
1004
2161
  const carriedCss = new Set();
2162
+ /** Each project stylesheet an `@import` names, with every sheet that imports it. @type {Map<string, Set<string>>} */
2163
+ const cssImporters = new Map();
2164
+ // The images the markup, the page's own CSS and its literals name are
2165
+ // asked for together, so a machine with no network waits for one answer
2166
+ // window, not one per text.
2167
+ if (remote) {
2168
+ await remote.get([
2169
+ ...remoteRefsIn(markup, 'html', ctx),
2170
+ ...(message.css ? remoteRefsIn(message.css, 'css', ctx) : []),
2171
+ ...(typeof message.script === 'string' ? /** @type {string[]} */ (message.remoteLiterals ?? []) : []),
2172
+ ]);
2173
+ }
1005
2174
  try {
1006
- markup = inlineAssets(markup, 'html', ctx);
2175
+ markup = await inlineWithRemote(markup, 'html', ctx);
1007
2176
  // React adds `<link rel="preload">` hints for images it renders; in one
1008
2177
  // static file they only fetch from the network, so they go.
1009
2178
  markup = markup.replace(/<link rel="preload"[^>]*\/?>/g, '');
@@ -1016,13 +2185,10 @@ export async function renderPage(entry, options = {}) {
1016
2185
  'The page renders a <script> element. A sandboxed viewer blocks it, and anywhere else it runs when the file is opened; remove it from the page.',
1017
2186
  });
1018
2187
  }
1019
- for (const m of markup.matchAll(
1020
- /<(link|iframe|object|embed)\b[^>]*?\s(?:href|src|data)="([^"]*)"/gi,
1021
- )) {
1022
- if (/^(data:|#)/i.test(m[2])) continue;
2188
+ for (const {tag, ref} of embeddedLoads(markup)) {
1023
2189
  warnings.push({
1024
2190
  code: 'remote-asset',
1025
- message: `The page renders a <${m[1].toLowerCase()}> that loads ${m[2]}, which a sandboxed page cannot reach and which loads from the network anywhere else; remove it from the page.`,
2191
+ message: `The page renders a <${tag}> that loads ${ref}, which a sandboxed page cannot reach and which loads from outside the file; remove it from the page.`,
1026
2192
  });
1027
2193
  }
1028
2194
  } catch (e) {
@@ -1032,44 +2198,105 @@ export async function renderPage(entry, options = {}) {
1032
2198
  throw e;
1033
2199
  }
1034
2200
  const used = classesIn(markup);
2201
+ /** The page's script; none in a markup-only render. @type {string | null} */
2202
+ const script = typeof message.script === 'string' ? message.script : null;
2203
+ const scriptIsModule = script !== null && message.scriptIsModule === true;
2204
+ // https images the page's files name as literals that the first paint may
2205
+ // not show (the next view, a feed after a click): fetched the same way, so
2206
+ // the script draws them from the same carried data.
2207
+ if (remote && script !== null) {
2208
+ const literals = /** @type {string[]} */ (message.remoteLiterals ?? []);
2209
+ const namedOnly = new Set(/** @type {string[]} */ (message.remoteNamedOnly ?? []));
2210
+ await remote.get(literals);
2211
+ for (const url of literals) {
2212
+ const fetched = remote.results.get(url);
2213
+ if (!fetched || 'uri' in fetched) continue;
2214
+ // An address that counts only by a name (`imageUploadUrl`, an object's
2215
+ // `src`) can be an API's or a player's: when its server answers with
2216
+ // another type (JSON, a page), the result lists it, with no warning.
2217
+ // Any other later-drawn address warns, as in the first paint.
2218
+ if (fetched.answered && namedOnly.has(url)) continue;
2219
+ const key = `remote:${url}`;
2220
+ if (ctx.counted.has(key)) continue;
2221
+ ctx.counted.add(key);
2222
+ warnings.push({
2223
+ code: 'remote-asset',
2224
+ message: `${url}, which the page's code names as an image, is loaded from the network when the script draws it, which a sandboxed page cannot reach; save it beside the page and import it instead. The render could not fetch it: ${fetched.reason}.`,
2225
+ });
2226
+ }
2227
+ }
2228
+ /** Built addresses named in a warning already. @type {Set<string>} */
2229
+ const builtNamed = new Set();
2230
+ for (const built of /** @type {{text: string, file: string, line: number}[]} */ (message.builtRemote ?? [])) {
2231
+ const where = `${path.relative(dir, built.file).split(path.sep).join('/')}:${built.line}`;
2232
+ if (builtNamed.has(`${where} ${built.text}`)) continue;
2233
+ builtNamed.add(`${where} ${built.text}`);
2234
+ warnings.push({
2235
+ code: 'remote-asset',
2236
+ message: `${built.text} (${where}) builds an image address in code, so the render cannot carry it: the file asks the network for it when the script draws it. Write the address whole, or save the image beside the page and import it.`,
2237
+ });
2238
+ }
2239
+ // The script draws what the markup does not show yet (a menu as it opens,
2240
+ // the next tab), so the rules every class name it holds needs stay too.
2241
+ // Core builds a part's class at run time from the part's name
2242
+ // (`banner-icon` -> `astryx-banner-icon`), so each name also keeps the
2243
+ // class Core's naming module makes from it.
2244
+ const tokens = script?.match(/[A-Za-z_][\w-]*/g) ?? [];
2245
+ const coreClass = script ? await coreClassNamer(entry, served) : null;
2246
+ const kept = script
2247
+ ? new Set([...used, ...tokens, ...(coreClass ? tokens.map(coreClass) : [])])
2248
+ : used;
1035
2249
  // A page that draws elements in a state (hovered, focused, pressed) marks
1036
2250
  // them; its stylesheet then applies those states' rules to them too.
1037
2251
  const states = markup.includes(' data-astryx-state="');
1038
2252
  const layerOrder = sheetText.map(layerOrderOf).find(Boolean) ?? '';
1039
2253
  let css = layerOrder;
2254
+ /** The classes the kept rules of Core's and the official packages' stylesheets name: only these take an alias. @type {Set<string>} */
2255
+ const packageClasses = new Set();
1040
2256
  try {
1041
2257
  // A stylesheet's url()s are relative to the stylesheet, not the page: a
1042
2258
  // theme's font, or an image beside an imported stylesheet.
1043
2259
  const included = new Set(sheetFiles);
1044
2260
  /** @type {string[]} */
1045
2261
  const packageSheets = [];
1046
- /** A stylesheet's rules cut to the page, with its own imports inlined. @param {string} file @param {string} text */
2262
+ /**
2263
+ * A stylesheet's rules cut to the page, with its own imports expanded,
2264
+ * and the warnings that expanding them gave.
2265
+ * @param {string} file @param {string} text
2266
+ * @returns {{file: string, cut: string, expandWarnings: RenderWarning[]}}
2267
+ */
1047
2268
  const sheet = (file, text) => {
2269
+ /** @type {RenderWarning[]} */
2270
+ const expandWarnings = [];
1048
2271
  try {
1049
2272
  const own = expandImports(file, text, {
1050
- warnings,
2273
+ warnings: expandWarnings,
1051
2274
  carried: carriedCss,
2275
+ importers: cssImporters,
1052
2276
  included,
1053
2277
  packageSheets,
1054
2278
  served,
1055
2279
  });
1056
- return inlineAssets(cutCss(own, used, {states}), 'css', {
1057
- ...ctx,
1058
- dir: path.dirname(file),
1059
- });
2280
+ return {file, cut: cutCss(own, kept, {states}), expandWarnings};
1060
2281
  } catch (e) {
1061
- if (e instanceof RenderAssetError || e instanceof RenderError) throw e;
1062
- const reason =
1063
- /** @type {any} */ (e)?.reason ??
1064
- (e instanceof Error ? e.message : String(e));
1065
- throw new RenderError(
1066
- 'ERR_RENDER_COMPILE',
1067
- `${path.relative(dir, file).split(path.sep).join('/')} is not valid CSS: ${reason}`,
1068
- );
2282
+ warnings.push(...expandWarnings);
2283
+ throw invalidSheet(e, file);
1069
2284
  }
1070
2285
  };
1071
- sheetText.forEach((text, i) => {
1072
- css += sheet(sheetFiles[i], text);
2286
+ /** @param {unknown} e @param {string} file */
2287
+ const invalidSheet = (e, file) => {
2288
+ if (e instanceof RenderAssetError || e instanceof RenderError) return e;
2289
+ const reason =
2290
+ /** @type {any} */ (e)?.reason ??
2291
+ (e instanceof Error ? e.message : String(e));
2292
+ return new RenderError(
2293
+ 'ERR_RENDER_COMPILE',
2294
+ `${path.relative(dir, file).split(path.sep).join('/')} is not valid CSS: ${reason}`,
2295
+ );
2296
+ };
2297
+ const parts = sheetText.map((text, i) => sheet(sheetFiles[i], text));
2298
+ parts.forEach(({cut}, i) => {
2299
+ if (sheetIsAstryx[i]) for (const m of cut.matchAll(/\.(-?[_a-zA-Z][\w-]*)/g)) packageClasses.add(m[1]);
1073
2300
  });
1074
2301
  for (const {
1075
2302
  file,
@@ -1077,11 +2304,31 @@ export async function renderPage(entry, options = {}) {
1077
2304
  } of /** @type {{file: string, css: string}[]} */ (
1078
2305
  message.importedCss ?? []
1079
2306
  )) {
1080
- css += sheet(file, text);
2307
+ parts.push(sheet(file, text));
2308
+ }
2309
+ // The font faces the page draws with are known from the whole
2310
+ // stylesheet, the markup and the script; the cut runs before the files
2311
+ // are read, so a face it drops is never read, counted or warned about.
2312
+ const stylesheet = [...parts.map(part => part.cut), message.css ?? ''].join(
2313
+ '\n',
2314
+ );
2315
+ const drawn = markup + (script ?? '');
2316
+ for (const {file, cut, expandWarnings} of parts) {
2317
+ warnings.push(...expandWarnings);
2318
+ try {
2319
+ css += await inlineWithRemote(
2320
+ options.cutFontFaces ? cutFontFaces(cut, drawn, stylesheet) : cut,
2321
+ 'css',
2322
+ {...ctx, dir: path.dirname(file)},
2323
+ );
2324
+ } catch (e) {
2325
+ throw invalidSheet(e, file);
2326
+ }
1081
2327
  }
1082
2328
  for (const spec of packageSheets)
1083
2329
  if (!sheets.includes(spec)) sheets.push(spec);
1084
- if (message.css) css += inlineAssets(message.css, 'css', ctx);
2330
+ if (message.css) css += await inlineWithRemote(message.css, 'css', ctx);
2331
+ remote?.done();
1085
2332
  } catch (e) {
1086
2333
  const err = /** @type {any} */ (e);
1087
2334
  if (err instanceof RenderAssetError)
@@ -1102,6 +2349,10 @@ export async function renderPage(entry, options = {}) {
1102
2349
  .replace(/&#x27;|&#39;/g, "'")
1103
2350
  .replace(/&nbsp;/g, ' ')
1104
2351
  .replace(/\s+/g, ' ');
2352
+ // The components' own docs say which one drops a missing text; they are
2353
+ // read only when a text is missing.
2354
+ /** @type {((entry: import('./dropped-text.mjs').ChainEntry) => Promise<boolean | null>) | null} */
2355
+ let takesChildren = null;
1105
2356
  for (const t of /** @type {any[]} */ (message.texts ?? [])) {
1106
2357
  if (t.hidden || t.text.length < 2 || plainText.includes(t.text)) continue;
1107
2358
  // The code around it ran: other text from the same function rendered.
@@ -1109,13 +2360,32 @@ export async function renderPage(entry, options = {}) {
1109
2360
  message.fnTexts?.[t.fn] ?? []
1110
2361
  ).filter(o => o !== t.text);
1111
2362
  if (!around.some(o => plainText.includes(o))) continue;
2363
+ takesChildren ??= childrenReader(
2364
+ /** @type {{name: string, dir: string}[]} */ (message.fromSet ?? []).find(
2365
+ p => p.name === '@astryxdesign/core',
2366
+ )?.dir ??
2367
+ findNodeModulesPackage(dir, '@astryxdesign/core')?.packageDir ??
2368
+ null,
2369
+ );
2370
+ const dropper = await dropperOf(t.chain ?? [], takesChildren);
2371
+ // Its own component takes children: a later paint shows the text.
2372
+ if (dropper === null) continue;
2373
+ const shown = t.text.length > 60 ? `${t.text.slice(0, 57)}...` : t.text;
2374
+ const where =
2375
+ t.file && t.file !== entry
2376
+ ? ` of ${path.relative(dir, t.file).split(path.sep).join('/')}`
2377
+ : '';
1112
2378
  warnings.push({
1113
2379
  code: 'dropped-children',
1114
- message: `<${t.component}> on line ${t.line} did not render the text "${t.text.length > 60 ? `${t.text.slice(0, 57)}...` : t.text}" it was given; it takes that text through a prop (often label=), so check its props.`,
2380
+ message: dropper
2381
+ ? `<${dropper.component}> on line ${dropper.line}${where} did not render the text "${shown}" it was given; ${dropper.name} takes no children, so pass the text through one of its props (astryx component ${dropper.name}).`
2382
+ : `<${t.component}> on line ${t.line}${where} did not render the text "${shown}" it was given; it takes that text through a prop (often label=), so check its props.`,
1115
2383
  });
1116
2384
  }
1117
- // The file runs no script, so a media query the page asks in JavaScript
1118
- // keeps the answer it got on the server, whatever the reader's screen.
2385
+ // A media query the page asks in JavaScript gets its server answer in the
2386
+ // markup. The file paints that answer first and asks again when its script
2387
+ // runs; a viewer that blocks scripts keeps the server answer, and so does
2388
+ // a markup-only render.
1119
2389
  const screenQueries = [
1120
2390
  ...new Set(
1121
2391
  /** @type {{call: string}[]} */ (message.screenQueries ?? []).map(
@@ -1126,11 +2396,14 @@ export async function renderPage(entry, options = {}) {
1126
2396
  if (screenQueries.length > 0) {
1127
2397
  warnings.push({
1128
2398
  code: 'screen-query',
1129
- message: `The page asks ${screenQueries.join(', ')} in JavaScript, which this file never runs: readers on every screen get its server answer, so fold the layout with CSS: Grid columns={{minWidth}}, or a StyleX @media or @container style.`,
2399
+ message: script
2400
+ ? `The page asks ${screenQueries.join(', ')} in JavaScript: this file paints the server answer first and asks again when its script runs, and a viewer that blocks scripts keeps the server answer. To fit every screen from the first paint, fold the layout with CSS: Grid columns={{minWidth}}, or a StyleX @media or @container style.`
2401
+ : `The page asks ${screenQueries.join(', ')} in JavaScript, which this file never runs: readers on every screen get its server answer, so fold the layout with CSS: Grid columns={{minWidth}}, or a StyleX @media or @container style.`,
1130
2402
  });
1131
2403
  }
1132
2404
  // A chart the render did not draw is an empty box: a ResponsiveContainer
1133
- // holds only its sizing box, and a chart of fixed size an empty wrapper.
2405
+ // holds only its sizing box, and a chart of fixed size an empty wrapper. The
2406
+ // file's script draws it when it runs.
1134
2407
  const blankCharts =
1135
2408
  (
1136
2409
  markup.match(
@@ -1143,7 +2416,17 @@ export async function renderPage(entry, options = {}) {
1143
2416
  if (blankCharts > 0) {
1144
2417
  warnings.push({
1145
2418
  code: 'chart-size',
1146
- message: `${blankCharts === 1 ? 'A chart' : `${blankCharts} charts`} could not be drawn without a browser, so ${blankCharts === 1 ? 'it is' : 'they are'} empty here: the render draws a chart only when a module of the page (not an installed package) imports the chart, and its ResponsiveContainer, from recharts by name (\`import {LineChart} from 'recharts'\`).`,
2419
+ message: script
2420
+ ? `${blankCharts === 1 ? 'A chart' : `${blankCharts} charts`} could not be drawn without a browser, so the file paints ${blankCharts === 1 ? 'it' : 'them'} empty and its script draws ${blankCharts === 1 ? 'it' : 'them'} when it runs; a viewer that blocks scripts keeps ${blankCharts === 1 ? 'it' : 'them'} empty. The render draws a chart into the markup only when a module of the page (not an installed package) imports the chart, and its ResponsiveContainer, from recharts by name (\`import {LineChart} from 'recharts'\`).`
2421
+ : `${blankCharts === 1 ? 'A chart' : `${blankCharts} charts`} could not be drawn without a browser, so ${blankCharts === 1 ? 'it is' : 'they are'} empty here: the render draws a chart only when a module of the page (not an installed package) imports the chart, and its ResponsiveContainer, from recharts by name (\`import {LineChart} from 'recharts'\`).`,
2422
+ });
2423
+ }
2424
+ // Text inside a drawing that scales to its box shrinks with it on a phone.
2425
+ const smallText = smallSvgText(markup);
2426
+ if (smallText) {
2427
+ warnings.push({
2428
+ code: 'chart-size',
2429
+ message: `${smallText.count === 1 ? 'An SVG drawing scales' : `${smallText.count} SVG drawings scale`} to fit ${smallText.count === 1 ? 'its' : 'their'} box with text inside, so on a 375 px phone that text shows at about ${smallText.px} px. Put the labels in HTML beside the drawing, or draw the chart with recharts in a ResponsiveContainer, which keeps its text size.`,
1147
2430
  });
1148
2431
  }
1149
2432
  if (message.chartsAlone) {
@@ -1158,7 +2441,9 @@ export async function renderPage(entry, options = {}) {
1158
2441
  const why = causes[message.chartsAlone] ?? causes.error;
1159
2442
  warnings.push({
1160
2443
  code: 'chart-size',
1161
- message: `${why}, so each chart was drawn by itself, as the first render gave it: a custom tick, label or shape in a chart sees React context defaults, not the values the page provides.`,
2444
+ message: script
2445
+ ? `${why}, so each chart was drawn by itself for the first paint, as the first render gave it: until the file's script draws the page again, a custom tick, label or shape in a chart sees React context defaults, not the values the page provides.`
2446
+ : `${why}, so each chart was drawn by itself, as the first render gave it: a custom tick, label or shape in a chart sees React context defaults, not the values the page provides.`,
1162
2447
  });
1163
2448
  }
1164
2449
  for (const sheet of /** @type {string[]} */ (message.skippedCss ?? [])) {
@@ -1181,12 +2466,41 @@ export async function renderPage(entry, options = {}) {
1181
2466
  // Images and fonts the page or a stylesheet names by a relative path
1182
2467
  // (`<img src="./logo.png">`, `url(./bg.png)`) are carried too, so the page
1183
2468
  // comes back with them; a package's own files are not.
2469
+ /**
2470
+ * Local files the page uses that the file cannot carry: a module, a
2471
+ * stylesheet or an image from outside the folder it carries from, which no
2472
+ * reverse writes, and a Sass or Less stylesheet. A package's own files
2473
+ * are not the page's.
2474
+ * @type {string[]}
2475
+ */
2476
+ const uncarried = [...(/** @type {string[]} */ (message.uncarried ?? []))];
2477
+ // With a package that node_modules links into the carried folder, a sheet
2478
+ // another pulls in is carried only when a carried sheet imports it: the
2479
+ // linked package's own stylesheets are the package's (the worker carries
2480
+ // only the files the page reaches by a path).
2481
+ const linkedRoots = /** @type {string[]} */ (message.linkedRoots ?? []);
2482
+ /** @type {Set<string>} */
2483
+ const importedByCarried = new Set();
2484
+ if (linkedRoots.length > 0) {
2485
+ for (let grew = true; grew; ) {
2486
+ grew = false;
2487
+ for (const [sheet, from] of cssImporters) {
2488
+ if (importedByCarried.has(sheet)) continue;
2489
+ if ([...from].some(f => files.includes(f) || importedByCarried.has(f))) {
2490
+ importedByCarried.add(sheet);
2491
+ grew = true;
2492
+ }
2493
+ }
2494
+ }
2495
+ }
1184
2496
  for (const sheet of carriedCss) {
1185
- if (
1186
- !isInside(sheet, scope) ||
1187
- path.relative(scope, sheet).split(path.sep).includes('node_modules')
1188
- )
2497
+ if (path.relative(scope, sheet).split(path.sep).includes('node_modules'))
1189
2498
  continue;
2499
+ if (linkedRoots.length > 0 && !importedByCarried.has(sheet)) continue;
2500
+ if (!isInside(sheet, scope)) {
2501
+ if (!uncarried.includes(sheet)) uncarried.push(sheet);
2502
+ continue;
2503
+ }
1190
2504
  if (!files.includes(sheet)) files.push(sheet);
1191
2505
  }
1192
2506
  /** Assets named in a warning already, so each is named once. @type {Set<string>} */
@@ -1199,18 +2513,19 @@ export async function renderPage(entry, options = {}) {
1199
2513
  * @param {string} how how the page uses it, for the warning
1200
2514
  */
1201
2515
  const carryAsset = (asset, how) => {
1202
- if (
1203
- !isInside(asset, scope) ||
1204
- path.relative(scope, asset).split(path.sep).includes('node_modules')
1205
- )
2516
+ if (path.relative(scope, asset).split(path.sep).includes('node_modules'))
2517
+ return;
2518
+ if (!isInside(asset, scope)) {
2519
+ if (isFileAt(asset) && !uncarried.includes(asset)) uncarried.push(asset);
1206
2520
  return;
2521
+ }
1207
2522
  if (files.includes(asset) || notCarried.has(asset)) return;
1208
2523
  /** @param {string} why */
1209
2524
  const leaveOut = why => {
1210
2525
  notCarried.add(asset);
1211
2526
  warnings.push({
1212
2527
  code: 'not-embedded',
1213
- message: `${path.relative(dir, asset).split(path.sep).join('/')} is ${how} but not carried in the file: ${why}, so --reverse cannot give it back.`,
2528
+ message: `${path.relative(dir, asset).split(path.sep).join('/')} is ${how} but not carried in the file: ${why}, so experimental import cannot give it back.`,
1214
2529
  });
1215
2530
  };
1216
2531
  /** @type {Buffer} */
@@ -1253,6 +2568,9 @@ export async function renderPage(entry, options = {}) {
1253
2568
  path.relative(named, f).split(path.sep).join('/'),
1254
2569
  )),
1255
2570
  );
2571
+ // A linked package's modules the file does not carry may still name images
2572
+ // the script draws later: those images are carried and shown the same way.
2573
+ carriedText.push(...(/** @type {string[]} */ (message.linkedModules ?? [])));
1256
2574
  for (const file of carriedText) {
1257
2575
  let text;
1258
2576
  try {
@@ -1260,17 +2578,87 @@ export async function renderPage(entry, options = {}) {
1260
2578
  } catch {
1261
2579
  continue;
1262
2580
  }
1263
- for (const ref of assetRefsOf(text, file)) {
1264
- const asset = path.resolve(path.dirname(file), ref);
1265
- if (!isInside(asset, named)) continue;
1266
- if (isFileAt(asset)) {
1267
- carryAsset(
1268
- asset,
1269
- `named in ${path.relative(dir, file).split(path.sep).join('/')}`,
1270
- );
2581
+ for (const {written: ref, file: name} of assetRefsOf(text, file)) {
2582
+ const how = `named in ${path.relative(dir, file).split(path.sep).join('/')}`;
2583
+ /** @param {string} f */
2584
+ const local = f => isInside(f, named) && isFileAt(f);
2585
+ /** The file the string names in the browser: a path from the site's root, or, for a relative string, from the page's folder (the file's address), not the module's. @type {string | null} */
2586
+ let shown;
2587
+ if (ref.startsWith('/')) {
2588
+ const found = assetRef(ref, {dir, root: site});
2589
+ shown = found?.kind === 'file' ? found.file : null;
2590
+ } else {
2591
+ // The file the module names beside it, which a restore lays out
2592
+ // where the module's own folder finds it.
2593
+ const beside = path.resolve(path.dirname(file), name);
2594
+ if (local(beside)) carryAsset(beside, how);
2595
+ // A stylesheet's url() is its own folder's file, which its inlined
2596
+ // rules already carry; only a module's string reaches the script.
2597
+ if (/\.css$/i.test(file)) continue;
2598
+ shown = path.resolve(dir, name);
2599
+ if (!local(shown)) shown = null;
2600
+ }
2601
+ if (!shown) continue;
2602
+ carryAsset(shown, how);
2603
+ // An image the page draws only later (the next view, a row below the
2604
+ // fold) shows from that file's carried data once the script draws it,
2605
+ // as the first paint shows the images it draws. The same string in two
2606
+ // folders names one file in the browser, so it gets one file's data.
2607
+ if (files.includes(shown) && !ctx.rewrites.has(ref)) {
2608
+ ctx.rewrites.set(ref, assetDataUri(shown));
1271
2609
  }
1272
2610
  }
1273
2611
  }
2612
+ // The script draws the page again with the paths the page wrote, so each
2613
+ // carried image keeps showing, the first paint's and the ones drawn later.
2614
+ // A local path becomes its data in the script. An https address stays as
2615
+ // the page wrote it: the file's script gives the carried data where the
2616
+ // browser takes an image's address (imageSinks), so a link, a text or the
2617
+ // URL API still reads the page's own address.
2618
+ // A remote address is one the render fetches: https, or one with no
2619
+ // scheme (`//cdn.example.com/a.png`).
2620
+ const remoteAddress = (/** @type {string} */ url) => /^(https?:)?\/\//i.test(url.trim());
2621
+ /** @type {Map<string, string>} */
2622
+ const localRewrites = new Map();
2623
+ for (const [was, now] of ctx.rewrites) {
2624
+ // A value is read as a `srcset` only when it lists a remote candidate:
2625
+ // a local name may hold a comma and a space (`./Logo, dark.png`).
2626
+ const written = /\s/.test(was.trim()) ? parseSrcset(was) : null;
2627
+ if (!written?.some(candidate => remoteAddress(candidate.url))) {
2628
+ if (!remoteAddress(was)) localRewrites.set(was, now);
2629
+ continue;
2630
+ }
2631
+ // A `srcset` keeps its remote candidates as written.
2632
+ const carried = parseSrcset(now);
2633
+ if (written.length !== carried.length) continue;
2634
+ const mixed = written.map((candidate, i) => (remoteAddress(candidate.url) ? candidate : carried[i]));
2635
+ if (mixed.some((candidate, i) => candidate !== written[i])) localRewrites.set(was, formatSrcset(mixed));
2636
+ }
2637
+ // An https image the first paint shows and marks: the sink reads its data
2638
+ // from that element, so the script holds no second copy of it.
2639
+ /** @type {[string, string][]} */
2640
+ const sinks = [];
2641
+ /** @type {Array<[string, number] | [string, number, number]>} */
2642
+ const reads = [];
2643
+ const listed = listedCandidates(ctx.carried, ctx.srcsets, ctx.rewrites);
2644
+ for (const [url, fetched] of remote?.results ?? []) {
2645
+ if (!('uri' in fetched)) continue;
2646
+ const read = firstPaintRead(url, ctx.carried, listed);
2647
+ if (read) reads.push(read);
2648
+ else sinks.push([url, fetched.uri]);
2649
+ }
2650
+ let pageScriptText = script === null ? null : withCarriedPaths(script, localRewrites, ctx.carried ?? new Map(), ctx.srcsets, ctx.rewrites, scriptIsModule);
2651
+ // The values the first paint carries are read once, before the sinks and
2652
+ // the page's script that use them.
2653
+ let prelude = reads.length > 0 ? CARRIED_PRELUDE : '';
2654
+ if (pageScriptText?.startsWith(CARRIED_PRELUDE)) {
2655
+ prelude = CARRIED_PRELUDE;
2656
+ pageScriptText = pageScriptText.slice(CARRIED_PRELUDE.length);
2657
+ }
2658
+ const drawn =
2659
+ pageScriptText === null
2660
+ ? null
2661
+ : prelude + (sinks.length + reads.length > 0 ? imageSinks(sinks, reads, CARRIED_VALUES) : '') + pageScriptText;
1274
2662
  // Paths are kept relative to the folder that holds every file: the page's
1275
2663
  // folder, or an ancestor when the page imports from above it, but never one
1276
2664
  // from which the page's own path holds a name a reverse refuses (a
@@ -1295,17 +2683,58 @@ export async function renderPage(entry, options = {}) {
1295
2683
  const ordered = [entry, ...files.filter(f => f !== entry)];
1296
2684
  /** @type {{path: string, bytes: Buffer}[]} */
1297
2685
  const embedded = [];
2686
+ /**
2687
+ * Files the page uses that the file does not carry, so --reverse cannot
2688
+ * give them back: the note and the result name each one.
2689
+ * @type {string[]}
2690
+ */
2691
+ const leftOut = [];
1298
2692
  for (const f of ordered) {
1299
2693
  const rel = path.relative(base, f).split(path.sep).join('/');
1300
- if (f !== entry && embeddedPathProblem(rel)) {
2694
+ const problem = f === entry ? null : embeddedPathProblem(rel);
2695
+ if (problem) leftOut.push(rel);
2696
+ if (problem?.toolConfig) {
2697
+ const fix = carriedNameFor(rel);
2698
+ warnings.push({
2699
+ code: 'not-carried',
2700
+ message:
2701
+ fix.action === 'rename'
2702
+ ? `${rel} is not carried: its name reads as a tool's configuration, which experimental import never writes. The page shows it, but experimental import cannot give it back. If it holds the page's data, rename it, such as ${fix.name}, to carry it. If a tool reads it, move the values the page reads into a file of its own, such as page-data.json.`
2703
+ : `${rel} is not carried: it is a tool's configuration, which experimental import never writes. The page shows what it reads from it, but experimental import cannot give it back. Move the values the page reads into a file of its own, such as ${fix.name}, to carry them.`,
2704
+ });
2705
+ continue;
2706
+ }
2707
+ if (problem) {
1301
2708
  warnings.push({
1302
2709
  code: 'not-embedded',
1303
- message: `${rel} is not carried in the file (a rendered page carries the page and the local modules, stylesheets, JSON files and images it imports, but never project or tool configuration, or a file a test, story or benchmark runner would run), so --reverse cannot give it back.`,
2710
+ message: `${rel} is not carried in the file (a rendered page carries the page and the local modules, stylesheets, JSON files and images it imports, but never project or tool configuration, or a file a test, story or benchmark runner would run), so experimental import cannot give it back.`,
1304
2711
  });
1305
2712
  continue;
1306
2713
  }
1307
2714
  embedded.push({path: rel, bytes: fs.readFileSync(f)});
1308
2715
  }
2716
+ for (const asset of notCarried) {
2717
+ leftOut.push(path.relative(base, asset).split(path.sep).join('/'));
2718
+ }
2719
+ // In a project, a render carries from the project's folder wherever it
2720
+ // runs, so only moving the file inside it carries it.
2721
+ const inProject = projectOf(dir) !== null;
2722
+ for (const f of uncarried) {
2723
+ // A file the render carries (a JSON file, stylesheet or image from above
2724
+ // the page's folder widens the folder it carries from) is not left out.
2725
+ if (files.includes(f)) continue;
2726
+ const rel = path.relative(base, f).split(path.sep).join('/');
2727
+ if (leftOut.includes(rel)) continue;
2728
+ leftOut.push(rel);
2729
+ // A Sass or Less stylesheet already has its missing-asset warning.
2730
+ if (/\.(scss|sass|less)$/i.test(f)) continue;
2731
+ warnings.push({
2732
+ code: 'not-embedded',
2733
+ message: inProject
2734
+ ? `${rel} is not carried: it is outside the project's folder, which a render carries from, and experimental import writes nothing outside it. The page shows it, but experimental import cannot give it back. Move it inside the project's folder.`
2735
+ : `${rel} is not carried: it is outside the folder the render carries from, and experimental import writes nothing outside it. The page shows it, but experimental import cannot give it back. Render from a folder that holds it, or move it into the page's folder.`,
2736
+ });
2737
+ }
1309
2738
  const heading = /<h1\b[^>]*>([\s\S]*?)<\/h1>/i
1310
2739
  .exec(markup)?.[1]
1311
2740
  ?.replace(/<[^>]*>/g, '')
@@ -1316,8 +2745,69 @@ export async function renderPage(entry, options = {}) {
1316
2745
  ? decodeAttr(heading)
1317
2746
  : path.basename(entry).replace(/\.[^.]+$/, ''));
1318
2747
  const generator = `<meta name="generator" content="Astryx${options.version ? ` ${escapeHtml(options.version)}` : ''}">`;
1319
- const style = `<style>${SCHEME_CSS}${markup.includes('class="recharts-responsive-container"') ? CHART_CSS : ''}${css}</style>`;
2748
+ const importedSheets = /** @type {{file: string, css: string}[]} */ (message.importedCss ?? []);
2749
+ // The theme editor shows each mode itself, so its markup-only pages keep
2750
+ // both schemes; a written file shows the theme's one mode.
2751
+ // The theme's stylesheet may come through the page's own CSS, by an
2752
+ // `@import` that the file inlines.
2753
+ const modeSheets = options.markupOnly
2754
+ ? []
2755
+ : sheetsWithImports(
2756
+ [
2757
+ ...themeSheetFiles.map((sheet, i) => ({...sheet, css: themeSheets[i]})),
2758
+ ...importedSheets.map(sheet => ({file: sheet.file, css: sheet.css})),
2759
+ ],
2760
+ served,
2761
+ );
2762
+ const mode = options.markupOnly ? null : oneColorModeOf(
2763
+ markup,
2764
+ rootThemeColorModes(markup, modeSheets, (specifier, from) => {
2765
+ try {
2766
+ return resolveServed(specifier, from, served) ?? resolvePackageModule(specifier, from);
2767
+ } catch {
2768
+ return resolvePackageModule(specifier, from);
2769
+ }
2770
+ }),
2771
+ modeSheets.map(sheet => sheet.css),
2772
+ );
2773
+ const drawsCharts = markup.includes('class="recharts-responsive-container"');
2774
+ // A page that repeats an element repeats its StyleX class list: the first
2775
+ // paint names each such list by one alias class (class-alias.mjs). The
2776
+ // script draws its own elements with StyleX's classes.
2777
+ if (script && !options.keepClassNames) ({markup, css} = aliasClasses(markup, css, packageClasses, new Set(tokens)));
2778
+ const style = `<style>${schemeCssFor(mode)}${script ? `#${ROOT_ID}{display:contents}` : ''}${drawsCharts ? CHART_CSS : ''}${css}</style>`;
2779
+ // With a script, the markup sits in the one element the script draws into,
2780
+ // which takes no box of its own.
2781
+ const body = script ? `<div id="${ROOT_ID}">${markup}</div>` : markup;
2782
+ // An image the embedded source leaves out (under a dot-folder, say) keeps
2783
+ // its own data: URI in the script.
2784
+ const carriedSha = new Set(embedded.map(e => sha256(e.bytes)));
2785
+ /** @type {Map<string, Buffer>} */
2786
+ const imageBytes = new Map();
2787
+ for (const f of files) {
2788
+ if (!isAssetPath(f)) continue;
2789
+ try {
2790
+ const bytes = fs.readFileSync(f);
2791
+ imageBytes.set(sha256(bytes), bytes);
2792
+ } catch {
2793
+ // A file that went away since the page imported it stays as written.
2794
+ }
2795
+ }
2796
+ const pageScript =
2797
+ drawn === null
2798
+ ? null
2799
+ : withUncarriedImages(drawn, carriedSha, (sha, prefix) => {
2800
+ const bytes = imageBytes.get(sha);
2801
+ return bytes ? `${prefix},${bytes.toString('base64')}` : null;
2802
+ });
2803
+ // A module script runs once the document is parsed, so a browser that
2804
+ // reaches it before its first paint paints the markup first. A classic
2805
+ // script at the end of the body would run before that paint on a page small
2806
+ // enough to arrive at once. A script that would not run the same in strict
2807
+ // mode (a CommonJS package that does not ask for it) stays classic.
2808
+ const scriptTag = pageScript ? `<script${scriptIsModule ? ' type="module"' : ''}>${pageScript}</script>\n` : '';
1320
2809
  let html;
2810
+ let block;
1321
2811
  if (options.output) {
1322
2812
  // The charset and generator metas come first: a browser reads the
1323
2813
  // charset only from the first 1024 bytes, and a CLI decides whether a
@@ -1351,6 +2841,7 @@ export async function renderPage(entry, options = {}) {
1351
2841
  : embedded[0].path,
1352
2842
  restored: `${file.replace(/\.[^.]+$/, '')}-restored/${embedded[0].path}`,
1353
2843
  files: embedded.map(f => f.path),
2844
+ notCarried: leftOut,
1354
2845
  packages,
1355
2846
  install: Object.entries(packages)
1356
2847
  .filter(([name]) => !isServedPackage(name, []))
@@ -1373,34 +2864,48 @@ export async function renderPage(entry, options = {}) {
1373
2864
  const rel = carried.get(path.resolve(named));
1374
2865
  if (rel && aliasOnly(spec)) aliases[spec] = rel;
1375
2866
  }
2867
+ // The public/ folder the render read `/` paths from, when the file
2868
+ // carries files from it, so a reverse expects them there and not in
2869
+ // another public/ the tree holds.
2870
+ const publicRel = path.relative(base, path.join(site, 'public')).split(path.sep).join('/');
2871
+ const publicDir =
2872
+ publicRel && !publicRel.startsWith('..') && !path.isAbsolute(publicRel) &&
2873
+ embedded.some(f => f.path.startsWith(`${publicRel}/`))
2874
+ ? publicRel
2875
+ : null;
1376
2876
  const record = {
1377
2877
  ...(facts.cli ? {cli: facts.cli} : {}),
1378
2878
  page: facts.page,
1379
2879
  ...(options.title === undefined ? {} : {title: options.title}),
1380
2880
  packages,
1381
2881
  ...(Object.keys(aliases).length > 0 ? {aliases} : {}),
2882
+ ...(leftOut.length > 0 ? {notCarried: leftOut} : {}),
2883
+ ...(publicDir ? {publicDir} : {}),
1382
2884
  markup: {
1383
- sha256: sha256(asParsed(markup)),
2885
+ sha256: sha256(asParsed(body)),
1384
2886
  style: sha256(asParsed(style)),
1385
2887
  text: Buffer.from(
1386
- JSON.stringify({title, runs: textRuns(markup)}),
2888
+ JSON.stringify({title, runs: textRuns(body)}),
1387
2889
  ).toString('base64'),
1388
2890
  },
1389
2891
  };
2892
+ block = sourceBlock(path.basename(entry), embedded, record);
1390
2893
  html =
1391
2894
  `<!doctype html><html lang="en"${rootThemeAttrs(markup)}><head><meta charset="utf-8">${generator}\n${headerNote(facts)}\n` +
1392
2895
  '<meta name="viewport" content="width=device-width,initial-scale=1">' +
1393
- '<meta name="color-scheme" content="light dark">' +
1394
- `<title>${escapeHtml(title)}</title>${style}</head><body>${markup}` +
1395
- `${sourceBlock(path.basename(entry), embedded, record)}\n${endNote(facts)}\n</body></html>\n`;
2896
+ `<meta name="color-scheme" content="${mode ?? 'light dark'}">` +
2897
+ `<title>${escapeHtml(title)}</title>${style}</head><body>${body}` +
2898
+ `${block}\n${endNote(facts)}\n${scriptTag}</body></html>\n`;
1396
2899
  } else {
2900
+ block = sourceBlock(path.basename(entry), embedded);
1397
2901
  html =
1398
2902
  `<!doctype html><html lang="en"${rootThemeAttrs(markup)}><head><meta charset="utf-8">` +
1399
2903
  '<meta name="viewport" content="width=device-width,initial-scale=1">' +
1400
- '<meta name="color-scheme" content="light dark">' +
1401
- `${generator}<title>${escapeHtml(title)}</title>${style}</head><body>${markup}` +
1402
- `${sourceBlock(path.basename(entry), embedded)}</body></html>\n`;
2904
+ `<meta name="color-scheme" content="${mode ?? 'light dark'}">` +
2905
+ `${generator}<title>${escapeHtml(title)}</title>${style}</head><body>${body}` +
2906
+ `${block}${scriptTag}</body></html>\n`;
1403
2907
  }
2908
+ const remoteSummary = remote?.summary();
1404
2909
  return {
1405
2910
  html,
1406
2911
  files: embedded.map(f => f.path),
@@ -1408,6 +2913,7 @@ export async function renderPage(entry, options = {}) {
1408
2913
  classes: used.size,
1409
2914
  cssBytes: Buffer.byteLength(css),
1410
2915
  markupBytes: Buffer.byteLength(markup),
2916
+ sourceBytes: Buffer.byteLength(block),
1411
2917
  images: new Set([
1412
2918
  ...[...ctx.counted]
1413
2919
  .filter(k => k.startsWith('file:'))
@@ -1415,6 +2921,10 @@ export async function renderPage(entry, options = {}) {
1415
2921
  ...(message.assets ?? []),
1416
2922
  ]).size,
1417
2923
  warnings,
2924
+ ...(leftOut.length > 0 ? {notCarried: leftOut} : {}),
2925
+ propValues: message.propValues ?? [],
1418
2926
  fromSet: message.fromSet ?? [],
2927
+ ...(pageScript ? {scriptBytes: Buffer.byteLength(pageScript), scriptModules: message.scriptModules ?? 0} : {}),
2928
+ ...(remoteSummary && remoteSummary.fetched.length + remoteSummary.failed.length > 0 ? {remoteImages: remoteSummary} : {}),
1419
2929
  };
1420
2930
  }