@rocket/js 0.0.0 → 0.1.1

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 (340) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +233 -2
  3. package/dist-types/exports/MainMenu.d.ts +2 -0
  4. package/dist-types/exports/MainMenu.d.ts.map +1 -0
  5. package/dist-types/exports/PageData.d.ts +2 -0
  6. package/dist-types/exports/PageData.d.ts.map +1 -0
  7. package/dist-types/exports/RocketCodeBlock.d.ts +2 -0
  8. package/dist-types/exports/RocketCodeBlock.d.ts.map +1 -0
  9. package/dist-types/exports/RocketIcon.d.ts +2 -0
  10. package/dist-types/exports/RocketIcon.d.ts.map +1 -0
  11. package/dist-types/exports/RocketJsDemo.d.ts +2 -0
  12. package/dist-types/exports/RocketJsDemo.d.ts.map +1 -0
  13. package/dist-types/exports/RocketRequestDemo.d.ts +2 -0
  14. package/dist-types/exports/RocketRequestDemo.d.ts.map +1 -0
  15. package/dist-types/exports/SocialPreviewPlayground.d.ts +2 -0
  16. package/dist-types/exports/SocialPreviewPlayground.d.ts.map +1 -0
  17. package/dist-types/exports/adapters/netlify.d.ts +2 -0
  18. package/dist-types/exports/adapters/netlify.d.ts.map +1 -0
  19. package/dist-types/exports/asyncMessage.d.ts +2 -0
  20. package/dist-types/exports/asyncMessage.d.ts.map +1 -0
  21. package/dist-types/exports/component-hydration.d.ts +2 -0
  22. package/dist-types/exports/component-hydration.d.ts.map +1 -0
  23. package/dist-types/exports/components/web-awesome.d.ts +3 -0
  24. package/dist-types/exports/components/web-awesome.d.ts.map +1 -0
  25. package/dist-types/exports/components.d.ts +2 -0
  26. package/dist-types/exports/components.d.ts.map +1 -0
  27. package/dist-types/exports/config.d.ts +2 -0
  28. package/dist-types/exports/config.d.ts.map +1 -0
  29. package/dist-types/exports/debounce.d.ts +2 -0
  30. package/dist-types/exports/debounce.d.ts.map +1 -0
  31. package/dist-types/exports/define/RocketCodeBlock.d.ts +2 -0
  32. package/dist-types/exports/define/RocketCodeBlock.d.ts.map +1 -0
  33. package/dist-types/exports/define/RocketIcon.d.ts +2 -0
  34. package/dist-types/exports/define/RocketIcon.d.ts.map +1 -0
  35. package/dist-types/exports/define/RocketJsDemo.d.ts +2 -0
  36. package/dist-types/exports/define/RocketJsDemo.d.ts.map +1 -0
  37. package/dist-types/exports/define/RocketRequestDemo.d.ts +2 -0
  38. package/dist-types/exports/define/RocketRequestDemo.d.ts.map +1 -0
  39. package/dist-types/exports/define/menus.d.ts +2 -0
  40. package/dist-types/exports/define/menus.d.ts.map +1 -0
  41. package/dist-types/exports/extractCode.d.ts +2 -0
  42. package/dist-types/exports/extractCode.d.ts.map +1 -0
  43. package/dist-types/exports/globalData.d.ts +2 -0
  44. package/dist-types/exports/globalData.d.ts.map +1 -0
  45. package/dist-types/exports/hydration/hydrationLoader.d.ts +2 -0
  46. package/dist-types/exports/hydration/hydrationLoader.d.ts.map +1 -0
  47. package/dist-types/exports/icons.d.ts +2 -0
  48. package/dist-types/exports/icons.d.ts.map +1 -0
  49. package/dist-types/exports/layout-helper.d.ts +2 -0
  50. package/dist-types/exports/layout-helper.d.ts.map +1 -0
  51. package/dist-types/exports/layout.d.ts +2 -0
  52. package/dist-types/exports/layout.d.ts.map +1 -0
  53. package/dist-types/exports/layouts/atlasDoc.d.ts +2 -0
  54. package/dist-types/exports/layouts/atlasDoc.d.ts.map +1 -0
  55. package/dist-types/exports/layouts/atlasHero.d.ts +2 -0
  56. package/dist-types/exports/layouts/atlasHero.d.ts.map +1 -0
  57. package/dist-types/exports/layouts/atlasNotFound.d.ts +2 -0
  58. package/dist-types/exports/layouts/atlasNotFound.d.ts.map +1 -0
  59. package/dist-types/exports/loaded-page-module.d.ts +2 -0
  60. package/dist-types/exports/loaded-page-module.d.ts.map +1 -0
  61. package/dist-types/exports/markdownHook.d.ts +2 -0
  62. package/dist-types/exports/markdownHook.d.ts.map +1 -0
  63. package/dist-types/exports/menu.d.ts +2 -0
  64. package/dist-types/exports/menu.d.ts.map +1 -0
  65. package/dist-types/exports/menus.d.ts +6 -0
  66. package/dist-types/exports/menus.d.ts.map +1 -0
  67. package/dist-types/exports/page-runtime.d.ts +2 -0
  68. package/dist-types/exports/page-runtime.d.ts.map +1 -0
  69. package/dist-types/exports/pages.d.ts +2 -0
  70. package/dist-types/exports/pages.d.ts.map +1 -0
  71. package/dist-types/exports/resolve.d.ts +2 -0
  72. package/dist-types/exports/resolve.d.ts.map +1 -0
  73. package/dist-types/exports/ssr.d.ts +2 -0
  74. package/dist-types/exports/ssr.d.ts.map +1 -0
  75. package/dist-types/exports/standalone-demo-url.d.ts +2 -0
  76. package/dist-types/exports/standalone-demo-url.d.ts.map +1 -0
  77. package/dist-types/exports/transform.d.ts +2 -0
  78. package/dist-types/exports/transform.d.ts.map +1 -0
  79. package/dist-types/exports/types/hydration.d.ts +23 -0
  80. package/dist-types/exports/types/hydration.d.ts.map +1 -0
  81. package/dist-types/exports/types/rocket.d.ts +504 -0
  82. package/dist-types/exports/types/rocket.d.ts.map +1 -0
  83. package/dist-types/exports/types.d.ts +3 -0
  84. package/dist-types/exports/types.d.ts.map +1 -0
  85. package/dist-types/exports/wds-plugin.d.ts +2 -0
  86. package/dist-types/exports/wds-plugin.d.ts.map +1 -0
  87. package/dist-types/src/PageData.d.ts +82 -0
  88. package/dist-types/src/PageData.d.ts.map +1 -0
  89. package/dist-types/src/RocketCodeBlock.d.ts +64 -0
  90. package/dist-types/src/RocketCodeBlock.d.ts.map +1 -0
  91. package/dist-types/src/RocketIcon.d.ts +35 -0
  92. package/dist-types/src/RocketIcon.d.ts.map +1 -0
  93. package/dist-types/src/RocketJsDemo.d.ts +59 -0
  94. package/dist-types/src/RocketJsDemo.d.ts.map +1 -0
  95. package/dist-types/src/RocketJsDemo.test-browser.d.ts +3 -0
  96. package/dist-types/src/RocketJsDemo.test-browser.d.ts.map +1 -0
  97. package/dist-types/src/RocketRequestDemo.d.ts +57 -0
  98. package/dist-types/src/RocketRequestDemo.d.ts.map +1 -0
  99. package/dist-types/src/RocketRequestDemo.test-browser.d.ts +3 -0
  100. package/dist-types/src/RocketRequestDemo.test-browser.d.ts.map +1 -0
  101. package/dist-types/src/SocialPreviewPlayground.d.ts +102 -0
  102. package/dist-types/src/SocialPreviewPlayground.d.ts.map +1 -0
  103. package/dist-types/src/adapters/netlify.d.ts +54 -0
  104. package/dist-types/src/adapters/netlify.d.ts.map +1 -0
  105. package/dist-types/src/asyncMessage.d.ts +14 -0
  106. package/dist-types/src/asyncMessage.d.ts.map +1 -0
  107. package/dist-types/src/cli/RocketBuild.d.ts +78 -0
  108. package/dist-types/src/cli/RocketBuild.d.ts.map +1 -0
  109. package/dist-types/src/cli/RocketCli.d.ts +17 -0
  110. package/dist-types/src/cli/RocketCli.d.ts.map +1 -0
  111. package/dist-types/src/cli/RocketInit.d.ts +22 -0
  112. package/dist-types/src/cli/RocketInit.d.ts.map +1 -0
  113. package/dist-types/src/cli/RocketStart.d.ts +45 -0
  114. package/dist-types/src/cli/RocketStart.d.ts.map +1 -0
  115. package/dist-types/src/cli/cli.d.ts +3 -0
  116. package/dist-types/src/cli/cli.d.ts.map +1 -0
  117. package/dist-types/src/component-hydration.d.ts +26 -0
  118. package/dist-types/src/component-hydration.d.ts.map +1 -0
  119. package/dist-types/src/components/FeatureList.d.ts +15 -0
  120. package/dist-types/src/components/FeatureList.d.ts.map +1 -0
  121. package/dist-types/src/components/Footer.d.ts +17 -0
  122. package/dist-types/src/components/Footer.d.ts.map +1 -0
  123. package/dist-types/src/components/Header.d.ts +6 -0
  124. package/dist-types/src/components/Header.d.ts.map +1 -0
  125. package/dist-types/src/components/RocketDrawer.d.ts +20 -0
  126. package/dist-types/src/components/RocketDrawer.d.ts.map +1 -0
  127. package/dist-types/src/components/RocketSocialLink.d.ts +30 -0
  128. package/dist-types/src/components/RocketSocialLink.d.ts.map +1 -0
  129. package/dist-types/src/components.d.ts +7 -0
  130. package/dist-types/src/components.d.ts.map +1 -0
  131. package/dist-types/src/config.d.ts +6 -0
  132. package/dist-types/src/config.d.ts.map +1 -0
  133. package/dist-types/src/debounce.d.ts +8 -0
  134. package/dist-types/src/debounce.d.ts.map +1 -0
  135. package/dist-types/src/defaultSocialPreviewTemplate.d.ts +31 -0
  136. package/dist-types/src/defaultSocialPreviewTemplate.d.ts.map +1 -0
  137. package/dist-types/src/development-page-module-loader.d.ts +15 -0
  138. package/dist-types/src/development-page-module-loader.d.ts.map +1 -0
  139. package/dist-types/src/extractCode.d.ts +5 -0
  140. package/dist-types/src/extractCode.d.ts.map +1 -0
  141. package/dist-types/src/hydration/evaluate.d.ts +20 -0
  142. package/dist-types/src/hydration/evaluate.d.ts.map +1 -0
  143. package/dist-types/src/hydration/extractStrategies.d.ts +5 -0
  144. package/dist-types/src/hydration/extractStrategies.d.ts.map +1 -0
  145. package/dist-types/src/hydration/hydrationLoader.d.ts +64 -0
  146. package/dist-types/src/hydration/hydrationLoader.d.ts.map +1 -0
  147. package/dist-types/src/icons.d.ts +182 -0
  148. package/dist-types/src/icons.d.ts.map +1 -0
  149. package/dist-types/src/layouts/atlas/atlasDocLayout.d.ts +45 -0
  150. package/dist-types/src/layouts/atlas/atlasDocLayout.d.ts.map +1 -0
  151. package/dist-types/src/layouts/atlas/atlasHeroLayout.d.ts +7 -0
  152. package/dist-types/src/layouts/atlas/atlasHeroLayout.d.ts.map +1 -0
  153. package/dist-types/src/layouts/atlas/atlasNotFoundLayout.d.ts +5 -0
  154. package/dist-types/src/layouts/atlas/atlasNotFoundLayout.d.ts.map +1 -0
  155. package/dist-types/src/layouts/layout-helper.d.ts +16 -0
  156. package/dist-types/src/layouts/layout-helper.d.ts.map +1 -0
  157. package/dist-types/src/layouts/layout.d.ts +7 -0
  158. package/dist-types/src/layouts/layout.d.ts.map +1 -0
  159. package/dist-types/src/loaded-page-module.d.ts +51 -0
  160. package/dist-types/src/loaded-page-module.d.ts.map +1 -0
  161. package/dist-types/src/main.d.ts +2 -0
  162. package/dist-types/src/main.d.ts.map +1 -0
  163. package/dist-types/src/markdownCompiler.d.ts +22 -0
  164. package/dist-types/src/markdownCompiler.d.ts.map +1 -0
  165. package/dist-types/src/markdownHook.d.ts +6 -0
  166. package/dist-types/src/markdownHook.d.ts.map +1 -0
  167. package/dist-types/src/menu.d.ts +22 -0
  168. package/dist-types/src/menu.d.ts.map +1 -0
  169. package/dist-types/src/menus/MainMenu.d.ts +23 -0
  170. package/dist-types/src/menus/MainMenu.d.ts.map +1 -0
  171. package/dist-types/src/menus/RocketMenu.d.ts +23 -0
  172. package/dist-types/src/menus/RocketMenu.d.ts.map +1 -0
  173. package/dist-types/src/menus/RocketNextPage.d.ts +18 -0
  174. package/dist-types/src/menus/RocketNextPage.d.ts.map +1 -0
  175. package/dist-types/src/menus/RocketPreviousPage.d.ts +18 -0
  176. package/dist-types/src/menus/RocketPreviousPage.d.ts.map +1 -0
  177. package/dist-types/src/menus/RocketToc.d.ts +54 -0
  178. package/dist-types/src/menus/RocketToc.d.ts.map +1 -0
  179. package/dist-types/src/menus/pageNavigation.d.ts +41 -0
  180. package/dist-types/src/menus/pageNavigation.d.ts.map +1 -0
  181. package/dist-types/src/page-pagination.d.ts +69 -0
  182. package/dist-types/src/page-pagination.d.ts.map +1 -0
  183. package/dist-types/src/page-runtime.d.ts +110 -0
  184. package/dist-types/src/page-runtime.d.ts.map +1 -0
  185. package/dist-types/src/pages.d.ts +10 -0
  186. package/dist-types/src/pages.d.ts.map +1 -0
  187. package/dist-types/src/publicAssets.d.ts +70 -0
  188. package/dist-types/src/publicAssets.d.ts.map +1 -0
  189. package/dist-types/src/requestDemoMetadata.d.ts +19 -0
  190. package/dist-types/src/requestDemoMetadata.d.ts.map +1 -0
  191. package/dist-types/src/resolve.d.ts +7 -0
  192. package/dist-types/src/resolve.d.ts.map +1 -0
  193. package/dist-types/src/siteDiscoverability.d.ts +33 -0
  194. package/dist-types/src/siteDiscoverability.d.ts.map +1 -0
  195. package/dist-types/src/siteHeadMetadata.d.ts +20 -0
  196. package/dist-types/src/siteHeadMetadata.d.ts.map +1 -0
  197. package/dist-types/src/socialPreviewImages.d.ts +186 -0
  198. package/dist-types/src/socialPreviewImages.d.ts.map +1 -0
  199. package/dist-types/src/socialPreviewTemplatePreview.d.ts +22 -0
  200. package/dist-types/src/socialPreviewTemplatePreview.d.ts.map +1 -0
  201. package/dist-types/src/ssr.d.ts +6 -0
  202. package/dist-types/src/ssr.d.ts.map +1 -0
  203. package/dist-types/src/standalone-demo-url.d.ts +60 -0
  204. package/dist-types/src/standalone-demo-url.d.ts.map +1 -0
  205. package/dist-types/src/static-page-module-loader.d.ts +15 -0
  206. package/dist-types/src/static-page-module-loader.d.ts.map +1 -0
  207. package/dist-types/src/transform.d.ts +10 -0
  208. package/dist-types/src/transform.d.ts.map +1 -0
  209. package/dist-types/src/urlLifecycle.d.ts +23 -0
  210. package/dist-types/src/urlLifecycle.d.ts.map +1 -0
  211. package/dist-types/src/wds-plugin.d.ts +15 -0
  212. package/dist-types/src/wds-plugin.d.ts.map +1 -0
  213. package/docs/assets/home-background.svg +1 -0
  214. package/docs/assets/prism-one-light.css +368 -0
  215. package/docs/assets/rocket-logo-dark-with-text-below.svg +8 -0
  216. package/docs/assets/rocket-logo-dark-with-text.svg +7 -0
  217. package/docs/assets/rocket-logo-dark.svg +7 -0
  218. package/docs/assets/rocket-logo-light-with-text-below.svg +14 -0
  219. package/docs/assets/rocket-logo-light-with-text.svg +13 -0
  220. package/docs/assets/rocket-logo-light.svg +12 -0
  221. package/docs/assets/rocket-text-no-logo.svg +3 -0
  222. package/exports/MainMenu.js +1 -0
  223. package/exports/PageData.js +1 -0
  224. package/exports/RocketCodeBlock.js +1 -0
  225. package/exports/RocketIcon.js +1 -0
  226. package/exports/RocketJsDemo.js +1 -0
  227. package/exports/RocketRequestDemo.js +1 -0
  228. package/exports/SocialPreviewPlayground.js +1 -0
  229. package/exports/adapters/netlify.js +1 -0
  230. package/exports/asyncMessage.js +1 -0
  231. package/exports/component-hydration.js +1 -0
  232. package/exports/components/web-awesome.js +63 -0
  233. package/exports/components.js +1 -0
  234. package/exports/config.js +1 -0
  235. package/exports/debounce.js +1 -0
  236. package/exports/define/RocketCodeBlock.js +2 -0
  237. package/exports/define/RocketIcon.js +3 -0
  238. package/exports/define/RocketJsDemo.js +5 -0
  239. package/exports/define/RocketRequestDemo.js +5 -0
  240. package/exports/define/menus.js +14 -0
  241. package/exports/extractCode.js +1 -0
  242. package/exports/globalData.js +1 -0
  243. package/exports/hydration/hydrationLoader.js +1 -0
  244. package/exports/icons.js +11 -0
  245. package/exports/layout-helper.js +1 -0
  246. package/exports/layout.js +1 -0
  247. package/exports/layouts/_atlas.css +3 -0
  248. package/exports/layouts/atlasDoc.js +5 -0
  249. package/exports/layouts/atlasHero.js +1 -0
  250. package/exports/layouts/atlasNotFound.js +4 -0
  251. package/exports/loaded-page-module.js +5 -0
  252. package/exports/markdownHook.js +4 -0
  253. package/exports/menu.js +4 -0
  254. package/exports/menus.js +5 -0
  255. package/exports/page-runtime.js +5 -0
  256. package/exports/pages.js +1 -0
  257. package/exports/resolve.js +1 -0
  258. package/exports/ssr.js +1 -0
  259. package/exports/standalone-demo-url.js +10 -0
  260. package/exports/transform.js +1 -0
  261. package/exports/types/hydration.ts +26 -0
  262. package/exports/types/rocket.ts +598 -0
  263. package/exports/types.ts +71 -0
  264. package/exports/wds-plugin.js +1 -0
  265. package/package.json +192 -9
  266. package/src/PageData.js +244 -0
  267. package/src/RocketCodeBlock.js +516 -0
  268. package/src/RocketIcon.js +291 -0
  269. package/src/RocketJsDemo.js +397 -0
  270. package/src/RocketJsDemo.test-browser.js +228 -0
  271. package/src/RocketRequestDemo.js +439 -0
  272. package/src/RocketRequestDemo.test-browser.js +301 -0
  273. package/src/SocialPreviewPlayground.js +573 -0
  274. package/src/adapters/netlify.js +814 -0
  275. package/src/asyncMessage.js +21 -0
  276. package/src/cli/RocketBuild.js +581 -0
  277. package/src/cli/RocketCli.js +47 -0
  278. package/src/cli/RocketInit.js +636 -0
  279. package/src/cli/RocketStart.js +145 -0
  280. package/src/cli/cli.js +7 -0
  281. package/src/component-hydration.js +86 -0
  282. package/src/components/FeatureList.js +114 -0
  283. package/src/components/Footer.js +116 -0
  284. package/src/components/Header.js +122 -0
  285. package/src/components/RocketDrawer.js +193 -0
  286. package/src/components/RocketSocialLink.js +128 -0
  287. package/src/components/assets/discord.svg +7 -0
  288. package/src/components/assets/github.svg +4 -0
  289. package/src/components/assets/gitlab.svg +1 -0
  290. package/src/components/assets/info.txt +1 -0
  291. package/src/components/assets/license.svg +3 -0
  292. package/src/components/assets/npm.svg +5 -0
  293. package/src/components/assets/slack.svg +5 -0
  294. package/src/components/assets/telegram.svg +4 -0
  295. package/src/components/assets/twitter.svg +1 -0
  296. package/src/components.js +34 -0
  297. package/src/config.js +319 -0
  298. package/src/debounce.js +21 -0
  299. package/src/defaultSocialPreviewTemplate.js +118 -0
  300. package/src/development-page-module-loader.js +29 -0
  301. package/src/extractCode.js +41 -0
  302. package/src/hydration/evaluate.js +54 -0
  303. package/src/hydration/extractStrategies.js +91 -0
  304. package/src/hydration/hydrationLoader.js +330 -0
  305. package/src/icons.js +898 -0
  306. package/src/layouts/atlas/atlasDoc.css +877 -0
  307. package/src/layouts/atlas/atlasDocLayout.js +275 -0
  308. package/src/layouts/atlas/atlasHero.css +774 -0
  309. package/src/layouts/atlas/atlasHeroLayout.js +337 -0
  310. package/src/layouts/atlas/atlasNotFound.css +365 -0
  311. package/src/layouts/atlas/atlasNotFoundLayout.js +69 -0
  312. package/src/layouts/layout-helper.js +92 -0
  313. package/src/layouts/layout.js +52 -0
  314. package/src/loaded-page-module.js +97 -0
  315. package/src/main.js +72 -0
  316. package/src/markdownCompiler.js +303 -0
  317. package/src/markdownHook.js +148 -0
  318. package/src/menu.js +210 -0
  319. package/src/menus/MainMenu.js +58 -0
  320. package/src/menus/RocketMenu.js +191 -0
  321. package/src/menus/RocketNextPage.js +25 -0
  322. package/src/menus/RocketPreviousPage.js +29 -0
  323. package/src/menus/RocketToc.js +309 -0
  324. package/src/menus/pageNavigation.js +285 -0
  325. package/src/page-pagination.js +241 -0
  326. package/src/page-runtime.js +481 -0
  327. package/src/pages.js +537 -0
  328. package/src/publicAssets.js +336 -0
  329. package/src/requestDemoMetadata.js +97 -0
  330. package/src/resolve.js +15 -0
  331. package/src/siteDiscoverability.js +184 -0
  332. package/src/siteHeadMetadata.js +69 -0
  333. package/src/socialPreviewImages.js +482 -0
  334. package/src/socialPreviewTemplatePreview.js +352 -0
  335. package/src/ssr.js +14 -0
  336. package/src/standalone-demo-url.js +147 -0
  337. package/src/static-page-module-loader.js +29 -0
  338. package/src/transform.js +720 -0
  339. package/src/urlLifecycle.js +57 -0
  340. package/src/wds-plugin.js +307 -0
@@ -0,0 +1,352 @@
1
+ import {
2
+ DEFAULT_SOCIAL_PREVIEW_IMAGE_HEIGHT,
3
+ DEFAULT_SOCIAL_PREVIEW_IMAGE_WIDTH,
4
+ captureSocialPreviewImageWithBrowser,
5
+ createSocialPreviewTemplateHtml,
6
+ createSocialPreviewTemplateData,
7
+ publicSocialPreviewPages,
8
+ } from './socialPreviewImages.js';
9
+ import { createSiteHeadMetadata } from './siteHeadMetadata.js';
10
+ import { readFileSync } from 'node:fs';
11
+
12
+ export const SOCIAL_PREVIEW_TEMPLATE_PREVIEW_BASE_PATH = '/_rocket/social-preview-template-preview';
13
+ export const SOCIAL_PREVIEW_TEMPLATE_PREVIEW_TEMPLATE_PATH = `${SOCIAL_PREVIEW_TEMPLATE_PREVIEW_BASE_PATH}/template`;
14
+ export const SOCIAL_PREVIEW_TEMPLATE_PREVIEW_IMAGE_PATH = `${SOCIAL_PREVIEW_TEMPLATE_PREVIEW_BASE_PATH}/image.png`;
15
+ export const SOCIAL_PREVIEW_TEMPLATE_PREVIEW_COMPONENT_PATH = `${SOCIAL_PREVIEW_TEMPLATE_PREVIEW_BASE_PATH}/SocialPreviewPlayground.js`;
16
+ export const SOCIAL_PREVIEW_TEMPLATE_PREVIEW_DEFAULT_TEMPLATE_PATH = `${SOCIAL_PREVIEW_TEMPLATE_PREVIEW_BASE_PATH}/defaultSocialPreviewTemplate.js`;
17
+
18
+ const socialPreviewPlaygroundModuleUrl = new URL('./SocialPreviewPlayground.js', import.meta.url);
19
+ const defaultSocialPreviewTemplateModuleUrl = new URL(
20
+ './defaultSocialPreviewTemplate.js',
21
+ import.meta.url,
22
+ );
23
+
24
+ /**
25
+ * @param {Request} request
26
+ * @param {{
27
+ * pages: import('@rocket/js/types.js').PageRegistry;
28
+ * siteHeadMetadata?: import('@rocket/js/types.js').SiteHeadMetadataConfig;
29
+ * siteOrigin?: string;
30
+ * captureSocialPreviewImage?: import('./socialPreviewImages.js').SocialPreviewCapture;
31
+ * }} options
32
+ * @returns {Promise<Response | undefined>}
33
+ */
34
+ export async function serveSocialPreviewTemplatePreview(
35
+ request,
36
+ {
37
+ pages,
38
+ siteHeadMetadata,
39
+ siteOrigin,
40
+ captureSocialPreviewImage = captureSocialPreviewImageWithBrowser,
41
+ },
42
+ ) {
43
+ const url = new URL(request.url);
44
+ if (
45
+ !isSocialPreviewTemplatePreviewIndexPath(url.pathname) &&
46
+ !socialPreviewTemplatePreviewResourcePaths.has(url.pathname)
47
+ ) {
48
+ return undefined;
49
+ }
50
+ if (url.pathname === SOCIAL_PREVIEW_TEMPLATE_PREVIEW_COMPONENT_PATH) {
51
+ return socialPreviewTemplatePreviewModuleResponse(
52
+ readFileSync(socialPreviewPlaygroundModuleUrl, 'utf8'),
53
+ );
54
+ }
55
+ if (url.pathname === SOCIAL_PREVIEW_TEMPLATE_PREVIEW_DEFAULT_TEMPLATE_PATH) {
56
+ return socialPreviewTemplatePreviewModuleResponse(
57
+ readFileSync(defaultSocialPreviewTemplateModuleUrl, 'utf8'),
58
+ );
59
+ }
60
+ if (!siteHeadMetadata?.socialPreview) {
61
+ return new Response('Social Preview Template Preview is not configured', { status: 404 });
62
+ }
63
+ const previewPages = publicSocialPreviewPages(pages);
64
+ const selection = selectSocialPreviewTemplatePreviewPage(url, previewPages);
65
+ if (!selection) {
66
+ const pagePath = socialPreviewTemplatePreviewPagePath(url) ?? '(none)';
67
+ return new Response(`Page not found for Social Preview Template Preview: ${pagePath}`, {
68
+ status: 404,
69
+ });
70
+ }
71
+ const { page, pagePath } = selection;
72
+ const previewSiteOrigin = siteOrigin ?? url.origin;
73
+ if (isSocialPreviewTemplatePreviewIndexPath(url.pathname)) {
74
+ return new Response(
75
+ socialPreviewTemplatePreviewWorkflowHtml({
76
+ url,
77
+ page,
78
+ pagePath,
79
+ previewPages,
80
+ siteHeadMetadata,
81
+ siteOrigin: previewSiteOrigin,
82
+ }),
83
+ {
84
+ headers: {
85
+ 'content-type': 'text/html; charset=utf-8',
86
+ },
87
+ },
88
+ );
89
+ }
90
+ const { html } = createSocialPreviewTemplateHtml({
91
+ page,
92
+ pagePath,
93
+ siteHeadMetadata,
94
+ siteOrigin: previewSiteOrigin,
95
+ overrides: socialPreviewTemplatePreviewOverrides(url),
96
+ });
97
+ if (url.pathname === SOCIAL_PREVIEW_TEMPLATE_PREVIEW_IMAGE_PATH) {
98
+ const data = await captureSocialPreviewImage({
99
+ html,
100
+ width: DEFAULT_SOCIAL_PREVIEW_IMAGE_WIDTH,
101
+ height: DEFAULT_SOCIAL_PREVIEW_IMAGE_HEIGHT,
102
+ pathname: pagePath,
103
+ });
104
+ return new Response(arrayBufferBody(data), {
105
+ headers: {
106
+ 'content-type': 'image/png',
107
+ },
108
+ });
109
+ }
110
+ return new Response(html, {
111
+ headers: {
112
+ 'content-type': 'text/html; charset=utf-8',
113
+ 'x-rocket-social-preview-width': String(DEFAULT_SOCIAL_PREVIEW_IMAGE_WIDTH),
114
+ 'x-rocket-social-preview-height': String(DEFAULT_SOCIAL_PREVIEW_IMAGE_HEIGHT),
115
+ },
116
+ });
117
+ }
118
+
119
+ /**
120
+ * @param {string} pathname
121
+ */
122
+ function isSocialPreviewTemplatePreviewIndexPath(pathname) {
123
+ return (
124
+ pathname === SOCIAL_PREVIEW_TEMPLATE_PREVIEW_BASE_PATH ||
125
+ pathname === `${SOCIAL_PREVIEW_TEMPLATE_PREVIEW_BASE_PATH}/`
126
+ );
127
+ }
128
+
129
+ const socialPreviewTemplatePreviewResourcePaths = new Set([
130
+ SOCIAL_PREVIEW_TEMPLATE_PREVIEW_TEMPLATE_PATH,
131
+ SOCIAL_PREVIEW_TEMPLATE_PREVIEW_IMAGE_PATH,
132
+ SOCIAL_PREVIEW_TEMPLATE_PREVIEW_COMPONENT_PATH,
133
+ SOCIAL_PREVIEW_TEMPLATE_PREVIEW_DEFAULT_TEMPLATE_PATH,
134
+ ]);
135
+
136
+ /**
137
+ * @param {URL} url
138
+ * @param {import('@rocket/js/types.js').PageRegistry} pages
139
+ */
140
+ function selectSocialPreviewTemplatePreviewPage(url, pages) {
141
+ const requestedPagePath = socialPreviewTemplatePreviewPagePath(url);
142
+ const pagePath = requestedPagePath ?? pages.keys().next().value;
143
+ if (!pagePath) {
144
+ return undefined;
145
+ }
146
+ const page = pages.get(pagePath) ?? pages.get(stripTrailingSlash(pagePath));
147
+ if (!page) {
148
+ return undefined;
149
+ }
150
+ return { pagePath: pages.has(pagePath) ? pagePath : stripTrailingSlash(pagePath), page };
151
+ }
152
+
153
+ /**
154
+ * @param {URL} url
155
+ */
156
+ function socialPreviewTemplatePreviewPagePath(url) {
157
+ const target =
158
+ url.searchParams.get('page') || url.searchParams.get('path') || url.searchParams.get('url');
159
+ if (!target) {
160
+ return undefined;
161
+ }
162
+ return new URL(target, url.origin).pathname;
163
+ }
164
+
165
+ /**
166
+ * @param {{
167
+ * url: URL;
168
+ * page: import('@rocket/js/types.js').Page;
169
+ * pagePath: string;
170
+ * previewPages: import('@rocket/js/types.js').PageRegistry;
171
+ * siteHeadMetadata: import('@rocket/js/types.js').SiteHeadMetadataConfig;
172
+ * siteOrigin: string;
173
+ * }} options
174
+ */
175
+ function socialPreviewTemplatePreviewWorkflowHtml({
176
+ url,
177
+ page,
178
+ pagePath,
179
+ previewPages,
180
+ siteHeadMetadata,
181
+ siteOrigin,
182
+ }) {
183
+ const pageValues = socialPreviewTemplatePreviewPageValues({
184
+ page,
185
+ pagePath,
186
+ siteHeadMetadata,
187
+ siteOrigin,
188
+ });
189
+ const overrides = socialPreviewTemplatePreviewOverrides(url);
190
+ const formValues = {
191
+ title: overrides.title ?? pageValues.title,
192
+ description: overrides.description ?? pageValues.description,
193
+ };
194
+ const pages = socialPreviewTemplatePreviewPagesData({
195
+ pages: previewPages,
196
+ siteHeadMetadata,
197
+ siteOrigin,
198
+ });
199
+ return `<!doctype html>
200
+ <html lang="en">
201
+ <head>
202
+ <meta charset="utf-8">
203
+ <title>Social Preview Template Preview</title>
204
+ <style>
205
+ *, *::before, *::after { box-sizing: border-box; }
206
+ body { margin: 0; min-height: 100vh; padding: 24px; font-family: system-ui, sans-serif; background: #f4f6f8; color: #111827; }
207
+ rocket-social-preview-playground { display: block; max-width: 1660px; margin: 0 auto; }
208
+ @media (max-width: 920px) { body { padding: 16px; } }
209
+ </style>
210
+ <script type="module">
211
+ import { SocialPreviewPlayground } from '${SOCIAL_PREVIEW_TEMPLATE_PREVIEW_COMPONENT_PATH}';
212
+
213
+ if (!customElements.get('rocket-social-preview-playground')) {
214
+ customElements.define('rocket-social-preview-playground', SocialPreviewPlayground);
215
+ }
216
+ </script>
217
+ </head>
218
+ <body>
219
+ <rocket-social-preview-playground
220
+ show-pages
221
+ show-download
222
+ sync-history
223
+ controls-position="left"
224
+ selected-path="${escapeHtml(pagePath)}"
225
+ preview-title="${escapeHtml(formValues.title)}"
226
+ preview-description="${escapeHtml(formValues.description)}"
227
+ template-url="${SOCIAL_PREVIEW_TEMPLATE_PREVIEW_TEMPLATE_PATH}"
228
+ image-url="${SOCIAL_PREVIEW_TEMPLATE_PREVIEW_IMAGE_PATH}"
229
+ workflow-url="${SOCIAL_PREVIEW_TEMPLATE_PREVIEW_BASE_PATH}/"
230
+ >
231
+ <script type="application/json" data-social-preview-pages>${safeJsonScript(pages)}</script>
232
+ </rocket-social-preview-playground>
233
+ </body>
234
+ </html>`;
235
+ }
236
+
237
+ /**
238
+ * @param {{
239
+ * pages: import('@rocket/js/types.js').PageRegistry;
240
+ * siteHeadMetadata: import('@rocket/js/types.js').SiteHeadMetadataConfig;
241
+ * siteOrigin: string;
242
+ * }} options
243
+ */
244
+ function socialPreviewTemplatePreviewPagesData({ pages, siteHeadMetadata, siteOrigin }) {
245
+ return [...pages].map(([path, page]) => {
246
+ const values = socialPreviewTemplatePreviewPageValues({
247
+ page,
248
+ pagePath: path,
249
+ siteHeadMetadata,
250
+ siteOrigin,
251
+ });
252
+ return {
253
+ path,
254
+ title: values.title,
255
+ description: values.description,
256
+ downloadFilename: socialPreviewTemplatePreviewDownloadFilename(path),
257
+ };
258
+ });
259
+ }
260
+
261
+ /**
262
+ * @param {{
263
+ * page: import('@rocket/js/types.js').Page;
264
+ * pagePath: string;
265
+ * siteHeadMetadata: import('@rocket/js/types.js').SiteHeadMetadataConfig;
266
+ * siteOrigin: string;
267
+ * }} options
268
+ */
269
+ function socialPreviewTemplatePreviewPageValues({ page, pagePath, siteHeadMetadata, siteOrigin }) {
270
+ const metadata = createSiteHeadMetadata({
271
+ config: siteHeadMetadata,
272
+ pageMetadata: page.metadata,
273
+ pageSiteHeadMetadata: page.module.config.siteHeadMetadata,
274
+ pathname: pagePath,
275
+ siteOrigin,
276
+ });
277
+ const templateData = createSocialPreviewTemplateData({
278
+ metadata,
279
+ pageMetadata: page.metadata,
280
+ pathname: pagePath,
281
+ });
282
+ return {
283
+ title: templateData.page.title,
284
+ description: templateData.page.description,
285
+ };
286
+ }
287
+
288
+ /**
289
+ * @param {URL} url
290
+ */
291
+ function socialPreviewTemplatePreviewOverrides(url) {
292
+ const title = url.searchParams.get('title');
293
+ const description = url.searchParams.get('description');
294
+ return {
295
+ ...(title ? { title } : {}),
296
+ ...(description ? { description } : {}),
297
+ };
298
+ }
299
+
300
+ /**
301
+ * @param {string} pagePath
302
+ */
303
+ function socialPreviewTemplatePreviewDownloadFilename(pagePath) {
304
+ const slug = pagePath.replace(/^\/|\/$/g, '').replaceAll('/', '-') || 'home';
305
+ return `social-preview-${slug.replace(/[^a-zA-Z0-9._-]+/g, '-')}.png`;
306
+ }
307
+
308
+ /**
309
+ * @param {string} source
310
+ */
311
+ function socialPreviewTemplatePreviewModuleResponse(source) {
312
+ return new Response(source, {
313
+ headers: {
314
+ 'content-type': 'text/javascript; charset=utf-8',
315
+ },
316
+ });
317
+ }
318
+
319
+ /**
320
+ * @param {unknown} value
321
+ */
322
+ function safeJsonScript(value) {
323
+ return JSON.stringify(value).replaceAll('<', '\\u003c');
324
+ }
325
+
326
+ /**
327
+ * @param {Uint8Array} data
328
+ * @returns {ArrayBuffer}
329
+ */
330
+ function arrayBufferBody(data) {
331
+ const buffer = Buffer.from(data);
332
+ return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
333
+ }
334
+
335
+ /**
336
+ * @param {string} value
337
+ */
338
+ function stripTrailingSlash(value) {
339
+ return value === '/' ? value : value.replace(/\/$/, '');
340
+ }
341
+
342
+ /**
343
+ * @param {string} value
344
+ */
345
+ function escapeHtml(value) {
346
+ return value
347
+ .replaceAll('&', '&amp;')
348
+ .replaceAll('"', '&quot;')
349
+ .replaceAll("'", '&#39;')
350
+ .replaceAll('<', '&lt;')
351
+ .replaceAll('>', '&gt;');
352
+ }
package/src/ssr.js ADDED
@@ -0,0 +1,14 @@
1
+ /** Runs on: imported-js */
2
+ import { render } from '@lit-labs/ssr';
3
+ import { collectResult } from '@lit-labs/ssr/lib/render-result.js';
4
+
5
+ /**
6
+ * @param {string | import('lit').TemplateResult} template
7
+ * @returns {Promise<string>}
8
+ */
9
+ export async function ssrRender(template) {
10
+ if (typeof template === 'string') {
11
+ return template;
12
+ }
13
+ return await collectResult(render(template));
14
+ }
@@ -0,0 +1,147 @@
1
+ import { URLPattern } from 'urlpattern-polyfill';
2
+
3
+ /** @typedef {import('@rocket/js/types.js').PageRegistry} PageRegistry */
4
+ /** @typedef {import('@rocket/js/types.js').Page} Page */
5
+ /** @typedef {{ kind: 'standalone-demo'; demoName: string }} StandaloneDemoPageVariant */
6
+
7
+ /**
8
+ * @param {string} parentUrl
9
+ * @param {string} demoName
10
+ */
11
+ export function standaloneDemoUrl(parentUrl, demoName) {
12
+ const url = new URL(parentUrl);
13
+ url.pathname = standaloneDemoPath(url.pathname, demoName);
14
+ url.search = '';
15
+ url.hash = '';
16
+ return url.href;
17
+ }
18
+
19
+ /**
20
+ * @param {string} parentPathname
21
+ * @param {string} demoName
22
+ */
23
+ export function standaloneDemoPath(parentPathname, demoName) {
24
+ return `${normalizeDocumentPath(parentPathname)}_demo/${demoName}/`;
25
+ }
26
+
27
+ /**
28
+ * @param {string} parentPathname
29
+ */
30
+ export function standaloneDemoRoutePattern(parentPathname) {
31
+ return `${normalizeDocumentPath(parentPathname)}_demo/:demoName/`;
32
+ }
33
+
34
+ /**
35
+ * @param {string} pagePath
36
+ * @param {Page} page
37
+ * @returns {string[]}
38
+ */
39
+ export function standaloneDemoPaths(pagePath, page) {
40
+ if (!isMarkdownPage(page)) {
41
+ return [];
42
+ }
43
+ return (page.demoNames || []).map(demoName => standaloneDemoPath(pagePath, demoName));
44
+ }
45
+
46
+ /**
47
+ * @param {string} pagePath
48
+ * @param {Page} page
49
+ * @returns {string[]}
50
+ */
51
+ export function standaloneDemoRoutePatterns(pagePath, page) {
52
+ if (!isMarkdownPage(page) || !page.demoNames?.length) {
53
+ return [];
54
+ }
55
+ return [standaloneDemoRoutePattern(pagePath)];
56
+ }
57
+
58
+ /**
59
+ * @param {string} pathname
60
+ * @returns {{ parentPathname: string; demoName: string } | null}
61
+ */
62
+ export function parseStandaloneDemoUrl(pathname) {
63
+ if (!pathname.endsWith('/')) {
64
+ return null;
65
+ }
66
+ const segments = pathname.split('/');
67
+ const marker = segments[segments.length - 3];
68
+ const demoName = segments[segments.length - 2];
69
+ if (marker !== '_demo' || !demoName) {
70
+ return null;
71
+ }
72
+ const parentPathname = segments.slice(0, -3).join('/') || '/';
73
+ return { parentPathname, demoName };
74
+ }
75
+
76
+ /**
77
+ * @param {string} pathname
78
+ * @param {string} origin
79
+ * @param {PageRegistry} pages
80
+ * @returns {{ page: Page; routePath: string; params: Record<string, string | undefined>; variant: StandaloneDemoPageVariant } | null}
81
+ */
82
+ export function matchStandaloneDemoUrl(pathname, origin, pages) {
83
+ const standaloneDemo = parseStandaloneDemoUrl(pathname);
84
+ if (!standaloneDemo) {
85
+ return null;
86
+ }
87
+
88
+ for (const [routePath, page] of pages) {
89
+ if (!isMarkdownPage(page) || !page.demoNames?.includes(standaloneDemo.demoName)) {
90
+ continue;
91
+ }
92
+ for (const parentPathname of parentPathnameCandidates(standaloneDemo.parentPathname)) {
93
+ const match = matchPagePath(parentPathname, origin, routePath);
94
+ if (match) {
95
+ return {
96
+ page,
97
+ routePath,
98
+ params: match.pathname.groups,
99
+ variant: { kind: 'standalone-demo', demoName: standaloneDemo.demoName },
100
+ };
101
+ }
102
+ }
103
+ }
104
+ return null;
105
+ }
106
+
107
+ /**
108
+ * @param {string} pagePath
109
+ */
110
+ export function normalizeDocumentPath(pagePath) {
111
+ let path = pagePath;
112
+ if (!path.startsWith('/')) {
113
+ path = '/' + path;
114
+ }
115
+ if (!path.endsWith('/')) {
116
+ path += '/';
117
+ }
118
+ return path;
119
+ }
120
+
121
+ /**
122
+ * @param {string} pathname
123
+ * @param {string} origin
124
+ * @param {string} routePath
125
+ */
126
+ function matchPagePath(pathname, origin, routePath) {
127
+ const pattern = new URLPattern({ pathname: routePath });
128
+ return pattern.exec(pathname, origin);
129
+ }
130
+
131
+ /**
132
+ * @param {string} parentPathname
133
+ */
134
+ function parentPathnameCandidates(parentPathname) {
135
+ const documentPath = normalizeDocumentPath(parentPathname);
136
+ if (documentPath === parentPathname) {
137
+ return [parentPathname];
138
+ }
139
+ return [parentPathname, documentPath];
140
+ }
141
+
142
+ /**
143
+ * @param {Page} page
144
+ */
145
+ function isMarkdownPage(page) {
146
+ return !page.file.endsWith('.js');
147
+ }
@@ -0,0 +1,29 @@
1
+ import { normalizeLoadedPageModule } from './loaded-page-module.js';
2
+ import { parseComponents } from './components.js';
3
+
4
+ /** @typedef {import('./page-runtime.js').PageModuleLoaderOptions} PageModuleLoaderOptions */
5
+
6
+ export function createStaticPageModuleLoader() {
7
+ return {
8
+ /**
9
+ * @param {PageModuleLoaderOptions} options
10
+ */
11
+ async load({ page, variant }) {
12
+ if (page.file.endsWith('.js')) {
13
+ const module = await import(`./${page.file}`, {
14
+ with: { type: 'rocketLoadJsInitial' },
15
+ });
16
+ return normalizeLoadedPageModule({ kind: 'javascript', module });
17
+ }
18
+
19
+ const importAttributes = { type: 'rocketLoadMdInitial' };
20
+ if (typeof variant === 'object' && variant.kind === 'standalone-demo') {
21
+ Object.assign(importAttributes, { singleDemo: variant.demoName });
22
+ }
23
+ const module = await import(`./${page.file}`, {
24
+ with: importAttributes,
25
+ });
26
+ return normalizeLoadedPageModule({ kind: 'markdown', module, parseComponents });
27
+ },
28
+ };
29
+ }