@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,148 @@
1
+ /** Runs on: import-hook */
2
+ import path, { relative } from 'node:path';
3
+ import { fileURLToPath, pathToFileURL } from 'node:url';
4
+ import { makeAsyncPort } from './asyncMessage.js';
5
+ import { compileMarkdownLoad, compileMarkdownSetup } from './markdownCompiler.js';
6
+ import { randomBytes } from 'node:crypto';
7
+
8
+ /** @type {import("./asyncMessage.js").AsyncPort} */
9
+ // @ts-ignore
10
+ let sendPort = null;
11
+
12
+ let lastReload = new Date().getTime();
13
+
14
+ /** @type {(data: {port: import('./asyncMessage.js').AsyncPort}) => Promise<void>} */
15
+ export async function initialize({ port }) {
16
+ sendPort = makeAsyncPort(port);
17
+ sendPort.on('message', message => {
18
+ if (message === 'reload') {
19
+ lastReload = new Date().getTime();
20
+ }
21
+ });
22
+ }
23
+
24
+ /** @type {import("module").LoadHook} */
25
+ export async function load(url, context, nextLoad) {
26
+ const attrs = structuredClone(context.importAttributes);
27
+ // Server-Side Rendering
28
+ if (context.importAttributes?.type?.startsWith('rocketSetupMd')) {
29
+ const module = await nextLoad(url, {
30
+ ...context,
31
+ format: 'module',
32
+ importAttributes: {},
33
+ });
34
+ const finalSource = await compileMarkdownSetup(module.source?.toString() || '');
35
+ if (finalSource === null) {
36
+ throw new Error(
37
+ 'No server code found in markdown file: ' + relative(process.cwd(), fileURLToPath(url)),
38
+ );
39
+ }
40
+ return {
41
+ format: 'module',
42
+ shortCircuit: true,
43
+ source: finalSource,
44
+ };
45
+ } else if (context.importAttributes?.type?.startsWith('rocketLoadMd')) {
46
+ // Client Side Rendering
47
+ const module = await nextLoad(url, {
48
+ ...context,
49
+ format: 'module',
50
+ importAttributes: {},
51
+ });
52
+ if (module.source === undefined) {
53
+ return module;
54
+ }
55
+ const code = await compileMarkdownLoad(module.source.toString(), {
56
+ singleDemo: attrs.singleDemo,
57
+ });
58
+ return { format: 'module', shortCircuit: true, source: code };
59
+ } else if (url.endsWith('.md')) {
60
+ throw new Error(
61
+ "Markdown files must be imported with type: 'rocketSetupMd'not " +
62
+ context.importAttributes.type +
63
+ ', import to ' +
64
+ url,
65
+ );
66
+ // Javascript or other files that ignore the cache
67
+ } else if (context.importAttributes.type?.match(/^(rocket(Setup|Load)Js)|^cache/)) {
68
+ return await nextLoad(url, {
69
+ ...context,
70
+ format: 'module',
71
+ importAttributes: {},
72
+ });
73
+ }
74
+ return nextLoad(url);
75
+ }
76
+
77
+ /** @type {import("module").ResolveHook} */
78
+ export async function resolve(specifier, context, nextResolve) {
79
+ const regex = /^rocket(Setup|Load)(Md|Js)/;
80
+ const match = context.importAttributes?.type?.match(regex) ?? null;
81
+ if (match !== null) {
82
+ const parentURL = /** @type {string} */ (context.parentURL);
83
+ // if importing from page scan, import from root
84
+ const filePath = context.importAttributes.type?.endsWith('Initial')
85
+ ? specifier
86
+ : path.join(path.dirname(fileURLToPath(parentURL)), specifier);
87
+ const url = pathToFileURL(filePath).href;
88
+ /** @type {import("module").ResolveFnOutput} */
89
+ const resolve = {
90
+ format: 'module',
91
+ shortCircuit: true,
92
+ url,
93
+ importAttributes: {
94
+ ...context.importAttributes,
95
+ type:
96
+ 'rocket' +
97
+ match[1] +
98
+ match[2] +
99
+ (context.importAttributes.type?.includes('Load')
100
+ ? randomBytes(8).toString('base64')
101
+ : lastReload.toString(36)),
102
+ },
103
+ };
104
+ if (match[0] === 'Setup' && isLocalFile(url)) {
105
+ await sendPort.sendAndWait({
106
+ parent: getPath(/** @type {string} */ (context.parentURL)),
107
+ url: getPath(resolve.url),
108
+ });
109
+ }
110
+ return resolve;
111
+ } else {
112
+ // Non-Rocket files
113
+ const resolve = await nextResolve(specifier, context);
114
+ if (isLocalFile(resolve.url)) {
115
+ resolve.importAttributes = {
116
+ ...resolve.importAttributes,
117
+ type: 'cache' + lastReload.toString(36),
118
+ };
119
+ await sendPort.sendAndWait({
120
+ parent: getPath(/** @type {string} */ (context.parentURL)),
121
+ url: getPath(resolve.url),
122
+ });
123
+ }
124
+ return resolve;
125
+ }
126
+ }
127
+
128
+ /**
129
+ * not node_modules
130
+ * @param {string} url
131
+ * @returns {boolean}
132
+ */
133
+ function isLocalFile(url) {
134
+ if (!url.startsWith('file:///')) {
135
+ return false;
136
+ }
137
+ const localPath = relative(process.cwd(), fileURLToPath(url));
138
+ return !localPath.includes('node_modules');
139
+ }
140
+
141
+ /**
142
+ * absolute url to relative path
143
+ * @param {string} url
144
+ * @returns {string}
145
+ */
146
+ function getPath(url) {
147
+ return relative(process.cwd(), fileURLToPath(url));
148
+ }
package/src/menu.js ADDED
@@ -0,0 +1,210 @@
1
+ /** Runs on: imported-md-string */
2
+ import { html, nothing } from 'lit';
3
+ import { join } from 'lit/directives/join.js';
4
+ import { unsafeHTML } from 'lit/directives/unsafe-html.js';
5
+
6
+ /**
7
+ * @param {import('@rocket/js/types.js').PageRegistry} pages
8
+ * @returns {import('@rocket/js/types.js').PageTree}
9
+ */
10
+ export function treeFromPages(pages) {
11
+ /** @type {import('@rocket/js/types.js').PageTree[]} */
12
+ const children = [];
13
+ /** @type {import('@rocket/js/types.js').PageTree | undefined} */
14
+ let root = undefined;
15
+ for (const [url, page] of pages.entries()) {
16
+ const { file, module, metadata } = page;
17
+ const { title, linkText } = metadata;
18
+ if (url === '/') {
19
+ // we can't exclude the root page, so at least make it no link
20
+ const menuNoLink = module.config.menu === false ? true : module.config.menu?.noLink;
21
+ root = {
22
+ name: '',
23
+ url,
24
+ file,
25
+ module,
26
+ children,
27
+ linkText: linkText || title,
28
+ menuNoLink,
29
+ ...menuIcon(module),
30
+ };
31
+ continue;
32
+ }
33
+ if (module.config.menu === false) {
34
+ continue;
35
+ }
36
+ const parts = getMenuParts(url, module);
37
+ let obj = children;
38
+ /** @type {any} */
39
+ let last = {};
40
+ for (const part of parts) {
41
+ if (part.startsWith(':')) {
42
+ break;
43
+ }
44
+ const get = obj.find(leaf => leaf.name === part);
45
+ if (!get) {
46
+ /** @type {import('@rocket/js/types.js').PageTree[]} */
47
+ const children = [];
48
+ last = {
49
+ name: part,
50
+ url: '',
51
+ file: '',
52
+ module: { config: { path: '' } },
53
+ children,
54
+ linkText: pathPartToTitle(part),
55
+ menuNoLink: true,
56
+ };
57
+ obj.push(last);
58
+ obj = children;
59
+ } else {
60
+ last = get;
61
+ obj = get.children;
62
+ }
63
+ }
64
+ last.url = url;
65
+ last.file = file;
66
+ last.module = module;
67
+ last.linkText = linkText || title;
68
+ last.menuNoLink = module.config.menu?.noLink;
69
+ const iconName = menuIcon(module).iconName;
70
+ if (iconName) {
71
+ last.iconName = iconName;
72
+ } else {
73
+ delete last.iconName;
74
+ }
75
+ }
76
+ if (root) {
77
+ sortRecursive(children);
78
+ return root;
79
+ }
80
+ throw new Error('No root page was found');
81
+ }
82
+
83
+ /**
84
+ * @param {import('@rocket/js/types.js').Module} module
85
+ * @returns {{ iconName?: string }}
86
+ */
87
+ function menuIcon(module) {
88
+ const menu = module.config.menu;
89
+ return typeof menu === 'object' && menu?.iconName ? { iconName: menu.iconName } : {};
90
+ }
91
+
92
+ /**
93
+ * @param {string} url
94
+ * @param {import('@rocket/js/types.js').Module} module
95
+ * @returns {string[]}
96
+ */
97
+ function getMenuParts(url, module) {
98
+ const parts = url.split('/').filter(Boolean);
99
+ const menu = module.config.menu;
100
+ if (typeof menu !== 'object' || !menu?.parent) {
101
+ return parts;
102
+ }
103
+ const parentParts = menu.parent.split('/').filter(Boolean);
104
+ const leaf = parts.at(-1);
105
+ return leaf ? [...parentParts, leaf] : parentParts;
106
+ }
107
+
108
+ /**
109
+ * @param {string} part
110
+ */
111
+ function pathPartToTitle(part) {
112
+ return part
113
+ .split('-')
114
+ .filter(Boolean)
115
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1))
116
+ .join(' ');
117
+ }
118
+
119
+ /**
120
+ * @param {import('@rocket/js/types.js').PageTree[]} children
121
+ */
122
+ function sortRecursive(children) {
123
+ children.sort((a, b) => {
124
+ if (
125
+ typeof a.module.config?.menu === 'object' &&
126
+ a.module.config.menu?.order &&
127
+ typeof b.module.config?.menu === 'object' &&
128
+ b.module.config.menu?.order
129
+ ) {
130
+ return a.module.config.menu.order - b.module.config.menu.order;
131
+ }
132
+ return (a.linkText || a.name).localeCompare(b.linkText || b.name);
133
+ });
134
+ for (const child of children) {
135
+ sortRecursive(child.children);
136
+ }
137
+ }
138
+
139
+ /**
140
+ * @param {import("@rocket/js/types.js").PageTree} tree
141
+ * @param {string} listTagName
142
+ * @param {(name: string, url: string, module: import("@rocket/js/types.js").Module, linkText: string) => import("lit").TemplateResult} itemFn
143
+ */
144
+ export function treeToHtml(tree, listTagName, itemFn) {
145
+ return html`${unsafeHTML(`<${listTagName}>`)}${join(
146
+ tree.children.map(page => {
147
+ let a = itemFn(page.name, page.url, page.module, page.linkText);
148
+ if (page.children.length) {
149
+ a = html`${a}${treeToHtml(page, listTagName, itemFn)}`;
150
+ }
151
+ return a;
152
+ }),
153
+ nothing,
154
+ )}${unsafeHTML(`</${listTagName}>`)}`;
155
+ }
156
+
157
+ /**
158
+ * @param {import('@rocket/js/types.js').PageTree} pageTree
159
+ */
160
+ export function defaultHtmlMenu(pageTree) {
161
+ return treeToHtml(
162
+ pageTree,
163
+ 'ul',
164
+ (_name, url, _module, linkText) =>
165
+ html`<li>
166
+ <a href=${url}>${linkText}</a>
167
+ </li>`,
168
+ );
169
+ }
170
+
171
+ /** Runs on: import-hook */
172
+ /**
173
+ * @param {import('@rocket/js/types.js').Headline[]} headlines
174
+ * @returns {import('@rocket/js/types.js').TableOfContents}
175
+ */
176
+ export function headLinesToTree(headlines) {
177
+ /** @type {import('@rocket/js/types.js').HeadlineTree[]} */
178
+ let entries = [];
179
+ const subHeadings = entries;
180
+ let stack = [];
181
+ let root = null;
182
+ let level = 2;
183
+ for (const headline of headlines) {
184
+ if (headline.level === 1) {
185
+ if (root === null) {
186
+ root = headline;
187
+ } else {
188
+ throw new Error('Could not create table of contents, multiple h1 headlines were found');
189
+ }
190
+ } else if (headline.level <= level) {
191
+ while (level > headline.level) {
192
+ level--;
193
+ entries = /** @type {import('@rocket/js/types.js').HeadlineTree[]} */ (stack.pop());
194
+ }
195
+ entries.push({ ...headline, children: [] });
196
+ } else if (headline.level === level + 1 && entries.length) {
197
+ entries[entries.length - 1].children.push({ ...headline, children: [] });
198
+ level++;
199
+ stack.push(entries);
200
+ const last = entries.at(-1);
201
+ if (!last) {
202
+ throw new Error('Could not create table of contents, empty headline found');
203
+ }
204
+ entries = last.children;
205
+ } else {
206
+ throw new Error('Could not create table of contents, jump in headline level is too high');
207
+ }
208
+ }
209
+ return { ...root, children: subHeadings };
210
+ }
@@ -0,0 +1,58 @@
1
+ import { LitElement, css, html } from 'lit';
2
+ import { classMap } from 'lit/directives/class-map.js';
3
+ import { ifDefined } from 'lit/directives/if-defined.js';
4
+
5
+ export class MainMenu extends LitElement {
6
+ static properties = {
7
+ pageTree: { type: Array },
8
+ currentPath: { type: String },
9
+ };
10
+
11
+ constructor() {
12
+ super();
13
+ /** @type {import('@rocket/js/types.js').PageTree} */
14
+ // @ts-ignore
15
+ this.pageTree = undefined;
16
+ this.currentPath = '';
17
+ }
18
+
19
+ render() {
20
+ if (!this.pageTree) {
21
+ return;
22
+ }
23
+ return html`<ul>
24
+ ${this.pageTree.children.map(page => this.list(page, 1))}
25
+ </ul>`;
26
+ }
27
+
28
+ /**
29
+ * @param {import('@rocket/js/types.js').PageTree} page
30
+ * @param {number} depth
31
+ * @returns {import('lit').TemplateResult}
32
+ */
33
+ list(page, depth = 0) {
34
+ const title = page.linkText;
35
+ /** @type {any} */
36
+ const classes = { current: page.url === this.currentPath };
37
+ const level = `lvl-${depth}`;
38
+ classes[level] = true;
39
+ return html`
40
+ <li>
41
+ <a href=${ifDefined(page.menuNoLink ? undefined : page.url)} class=${classMap(classes)}
42
+ >${title}</a
43
+ >
44
+ ${page.children.length > 0
45
+ ? html`<ul>
46
+ ${page.children.map(child => this.list(child, depth + 1))}
47
+ </ul>`
48
+ : ''}
49
+ </li>
50
+ `;
51
+ }
52
+
53
+ static styles = css`
54
+ a[href] {
55
+ color: var(--link-color);
56
+ }
57
+ `;
58
+ }
@@ -0,0 +1,191 @@
1
+ import { LitElement, css, html } from 'lit';
2
+ import { classMap } from 'lit/directives/class-map.js';
3
+ import { ifDefined } from 'lit/directives/if-defined.js';
4
+
5
+ export class RocketMenu extends LitElement {
6
+ static properties = {
7
+ pageTree: { type: Array },
8
+ currentPath: { type: String },
9
+ };
10
+
11
+ constructor() {
12
+ super();
13
+ /** @type {import('@rocket/js/types.js').PageTree} */
14
+ // @ts-ignore
15
+ this.pageTree = undefined;
16
+ this.currentPath = '';
17
+ }
18
+
19
+ render() {
20
+ if (!this.pageTree) {
21
+ return;
22
+ }
23
+ return html`<ul class="menu-list">
24
+ ${this.pageTree.children.map(page => this.list(page, 1))}
25
+ </ul>`;
26
+ }
27
+
28
+ /**
29
+ * @param {import('@rocket/js/types.js').PageTree} page
30
+ * @param {number} depth
31
+ * @returns {import('lit').TemplateResult}
32
+ */
33
+ list(page, depth = 0) {
34
+ const title = page.linkText;
35
+ const isCurrent = page.url === this.currentPath;
36
+ const isSection = depth === 1;
37
+ /** @type {any} */
38
+ const classes = {
39
+ current: isCurrent,
40
+ section: isSection,
41
+ 'no-link': page.menuNoLink,
42
+ 'nav-link': !isSection,
43
+ };
44
+ const level = `lvl-${depth}`;
45
+ classes[level] = true;
46
+ const itemClasses = { 'section-item': isSection };
47
+
48
+ return html`
49
+ <li class=${classMap(itemClasses)}>
50
+ ${page.menuNoLink
51
+ ? html`<span class=${classMap(classes)}>${title}</span>`
52
+ : html`<a
53
+ href=${ifDefined(page.url)}
54
+ class=${classMap(classes)}
55
+ aria-current=${ifDefined(isCurrent ? 'page' : undefined)}
56
+ >${page.iconName
57
+ ? html`<rocket-icon
58
+ class="nav-icon"
59
+ name=${page.iconName}
60
+ aria-hidden="true"
61
+ ></rocket-icon>`
62
+ : ''}<span class="nav-text">${title}</span></a
63
+ >`}
64
+ ${page.children.length > 0
65
+ ? html`<ul>
66
+ ${page.children.map(child => this.list(child, depth + 1))}
67
+ </ul>`
68
+ : ''}
69
+ </li>
70
+ `;
71
+ }
72
+
73
+ static styles = css`
74
+ :host {
75
+ display: block;
76
+ --rocket-menu-heading-color: var(--primary-color);
77
+ --rocket-menu-text-color: var(--primary-text-color);
78
+ --rocket-menu-hover-text-color: var(--primary-text-color);
79
+ --rocket-menu-hover-background: #ffffff;
80
+ --rocket-menu-active-background: #fff0f0;
81
+ --rocket-menu-active-color: var(--primary-color);
82
+ }
83
+
84
+ a,
85
+ span {
86
+ text-decoration: none;
87
+ user-select: none;
88
+ }
89
+
90
+ * {
91
+ box-sizing: border-box;
92
+ }
93
+
94
+ ul {
95
+ padding: 0;
96
+ margin: 0;
97
+ list-style-type: none;
98
+ }
99
+
100
+ :host > .menu-list {
101
+ display: flex;
102
+ flex-direction: column;
103
+ gap: 1rem;
104
+ position: relative;
105
+ }
106
+
107
+ li {
108
+ margin: 0;
109
+ padding: 0;
110
+ }
111
+
112
+ li > ul {
113
+ display: grid;
114
+ gap: 0.125rem;
115
+ margin-top: 0.4rem;
116
+ }
117
+
118
+ .section {
119
+ display: block;
120
+ padding: 0 0.6rem;
121
+ color: var(--rocket-menu-heading-color);
122
+ font-size: 0.78rem;
123
+ font-weight: 700;
124
+ letter-spacing: 0.06em;
125
+ line-height: 1.2;
126
+ text-transform: uppercase;
127
+ }
128
+
129
+ .nav-link {
130
+ position: relative;
131
+ display: flex;
132
+ align-items: center;
133
+ gap: 0.7rem;
134
+ min-height: 2.35rem;
135
+ padding: 0.45rem 0.75rem 0.45rem 0.95rem;
136
+ border-radius: 9px;
137
+ color: var(--rocket-menu-text-color);
138
+ font-size: 0.9rem;
139
+ font-weight: 500;
140
+ line-height: 1.25;
141
+ transition:
142
+ background-color 0.2s ease,
143
+ color 0.2s ease,
144
+ box-shadow 0.2s ease;
145
+ }
146
+
147
+ .nav-link:hover {
148
+ color: var(--rocket-menu-hover-text-color);
149
+ background: var(--rocket-menu-hover-background);
150
+ }
151
+
152
+ .nav-link.current {
153
+ color: var(--rocket-menu-active-color);
154
+ font-weight: 700;
155
+ background: var(--rocket-menu-active-background);
156
+ box-shadow: inset 0 0 0 1px hsl(358 88% 47% / 7%);
157
+ }
158
+
159
+ .nav-link:focus-visible {
160
+ outline: 2px solid hsl(358 88% 47% / 45%);
161
+ outline-offset: 2px;
162
+ }
163
+
164
+ .nav-text {
165
+ min-width: 0;
166
+ }
167
+
168
+ rocket-icon.nav-icon {
169
+ width: 1rem;
170
+ height: 1rem;
171
+ flex: 0 0 1rem;
172
+ color: currentColor;
173
+ }
174
+
175
+ .nav-link.current::before {
176
+ position: absolute;
177
+ top: 0.45rem;
178
+ bottom: 0.45rem;
179
+ left: 0.35rem;
180
+ width: 3px;
181
+ border-radius: 999px;
182
+ background: var(--rocket-menu-active-color);
183
+ content: '';
184
+ }
185
+
186
+ .lvl-3 {
187
+ margin-left: 0.7rem;
188
+ font-size: 0.84rem;
189
+ }
190
+ `;
191
+ }
@@ -0,0 +1,25 @@
1
+ import { LitElement, nothing } from 'lit';
2
+ import { nextPageNode, pageNavigationStyles, renderPageNavigationCard } from './pageNavigation.js';
3
+
4
+ export class RocketNextPage extends LitElement {
5
+ static properties = {
6
+ pageTree: { type: Array },
7
+ currentPath: { type: String },
8
+ };
9
+
10
+ constructor() {
11
+ super();
12
+ /** @type {import('@rocket/js/types.js').PageTree} */
13
+ // @ts-ignore
14
+ this.pageTree = undefined;
15
+ this.currentPath = '';
16
+ }
17
+
18
+ render() {
19
+ if (!this.pageTree) {
20
+ return nothing;
21
+ }
22
+ return renderPageNavigationCard(nextPageNode(this.pageTree, this.currentPath), 'next');
23
+ }
24
+ static styles = pageNavigationStyles;
25
+ }
@@ -0,0 +1,29 @@
1
+ import { LitElement, nothing } from 'lit';
2
+ import {
3
+ pageNavigationStyles,
4
+ previousPageNode,
5
+ renderPageNavigationCard,
6
+ } from './pageNavigation.js';
7
+
8
+ export class RocketPreviousPage extends LitElement {
9
+ static properties = {
10
+ pageTree: { type: Array },
11
+ currentPath: { type: String },
12
+ };
13
+
14
+ constructor() {
15
+ super();
16
+ /** @type {import('@rocket/js/types.js').PageTree} */
17
+ // @ts-ignore
18
+ this.pageTree = undefined;
19
+ this.currentPath = '';
20
+ }
21
+
22
+ render() {
23
+ if (!this.pageTree) {
24
+ return nothing;
25
+ }
26
+ return renderPageNavigationCard(previousPageNode(this.pageTree, this.currentPath), 'previous');
27
+ }
28
+ static styles = pageNavigationStyles;
29
+ }