@publish.os/nextjs 0.0.1-alpha.90 → 0.0.1-alpha.92

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 (284) hide show
  1. package/compiler-assets/nextjs/defaults/group/index.tsx +16 -11
  2. package/compiler-assets/nextjs/defaults/group/layout.tsx +6 -6
  3. package/compiler-assets/nextjs/defaults/group/page.tsx +36 -26
  4. package/compiler-assets/nextjs/defaults/project/next.config.mjs +21 -11
  5. package/compiler-assets/nextjs/defaults/project/tsconfig.json.template +10 -0
  6. package/compiler-assets/nextjs/defaults/root/css/components/code-block.css +18 -0
  7. package/compiler-assets/nextjs/defaults/root/index.tsx +16 -11
  8. package/compiler-assets/nextjs/defaults/root/layout.tsx +7 -3
  9. package/compiler-assets/nextjs/shims/agent-user-agents.ts +65 -0
  10. package/compiler-assets/nextjs/shims/document.tsx +46 -0
  11. package/compiler-assets/nextjs/shims/generated-leaf-page.tsx +5 -0
  12. package/compiler-assets/nextjs/shims/global-layout.tsx +8 -42
  13. package/compiler-assets/nextjs/shims/global-not-found.tsx +69 -0
  14. package/compiler-assets/nextjs/shims/markdown-route.ts +2 -0
  15. package/compiler-assets/nextjs/shims/metadata-icons.tsx +39 -0
  16. package/compiler-assets/nextjs/shims/not-found-content.tsx +53 -0
  17. package/compiler-assets/nextjs/shims/not-found-navigation.tsx +60 -0
  18. package/compiler-assets/nextjs/shims/proxy.ts +254 -86
  19. package/compiler-assets/nextjs/shims/site-fenced-code-block.tsx +2 -6
  20. package/compiler-assets/nextjs/shims/site-mdx-components.tsx +28 -16
  21. package/compiler-assets/nextjs/shims/site-mdx.tsx +6 -1
  22. package/dist/{build-operation-2JAYBSKF.js → build-operation-CJDUL4OW.js} +29 -23
  23. package/dist/{button-c3WGnxIj.d.ts → button-D6Xp2HBm.d.ts} +4 -4
  24. package/dist/capture-local-source-WGGDIUU2.js +258 -0
  25. package/dist/chunk-22RSSUNV.js +13 -0
  26. package/dist/chunk-3T4HVDSC.js +426 -0
  27. package/dist/{chunk-WKTEO6RS.js → chunk-4BC2L2KA.js} +46 -12
  28. package/dist/{chunk-WDY4IK6Z.js → chunk-5J3YUNRY.js} +3 -10
  29. package/dist/chunk-5KAD7W53.js +248 -0
  30. package/dist/{chunk-DWA3ZRGW.js → chunk-6C65KV7O.js} +2 -2
  31. package/dist/{chunk-GGKFQ3MA.js → chunk-6D2E6UMD.js} +144 -70
  32. package/dist/{chunk-7OGTPSKI.js → chunk-7NY22B5U.js} +8 -3
  33. package/dist/chunk-DX7PXFCM.js +2519 -0
  34. package/dist/{chunk-726GV2NF.js → chunk-DZ3VWEV5.js} +950 -632
  35. package/dist/chunk-EFO6AWXN.js +19 -0
  36. package/dist/chunk-IL4RJOKI.js +186 -0
  37. package/dist/{chunk-H6XILMZX.js → chunk-NHSLTARU.js} +2588 -1493
  38. package/dist/{chunk-DLDFHU7Y.js → chunk-NNBJZPFM.js} +4 -2
  39. package/dist/{chunk-VO2I7MTM.js → chunk-SBMDONTV.js} +10 -7
  40. package/dist/{chunk-YLTOLYWM.js → chunk-WL75GQ5M.js} +6 -18
  41. package/dist/compiler.d.ts +15 -2
  42. package/dist/compiler.js +111 -23
  43. package/dist/components/blocks/agent-actions.d.ts +81 -0
  44. package/dist/components/blocks/agent-actions.js +563 -0
  45. package/dist/components/blocks/toc.d.ts +43 -0
  46. package/dist/components/blocks/toc.js +136 -0
  47. package/dist/components/ui/button.d.ts +4 -0
  48. package/dist/components/ui/button.js +94 -0
  49. package/dist/compose-44GJSMXD.js +16 -0
  50. package/dist/config/createNextConfig.js +19 -3
  51. package/dist/{dev-operation-TZDVJCN7.js → dev-operation-WNECBHZ5.js} +134 -84
  52. package/dist/{framework-selection-X4U6Y6QC.js → framework-selection-ZVO323PK.js} +3 -2
  53. package/dist/ide-support-TG74L4FF.js +16 -0
  54. package/dist/index.d.ts +151 -95
  55. package/dist/index.js +25 -0
  56. package/dist/jsx-dev-runtime.d.ts +6 -0
  57. package/dist/jsx-dev-runtime.js +100 -0
  58. package/dist/jsx-runtime.d.ts +7 -0
  59. package/dist/jsx-runtime.js +97 -0
  60. package/dist/kernel/components/blocks/AgentActions.d.ts +37 -8
  61. package/dist/kernel/components/blocks/AgentActions.js +384 -174
  62. package/dist/kernel/components/blocks/agent-actions.d.ts +4 -0
  63. package/dist/kernel/components/blocks/agent-actions.js +563 -0
  64. package/dist/kernel/components/blocks/animated-icon-swap.d.ts +2 -2
  65. package/dist/kernel/components/blocks/animated-icon-swap.js +1 -1
  66. package/dist/kernel/components/blocks/color-palette.d.ts +2 -2
  67. package/dist/kernel/components/blocks/color-palette.js +4 -4
  68. package/dist/kernel/components/blocks/logo-block.d.ts +2 -2
  69. package/dist/kernel/components/blocks/logo-block.js +1 -1
  70. package/dist/kernel/components/blocks/nav-breadcrumb.d.ts +6 -5
  71. package/dist/kernel/components/blocks/nav-breadcrumb.js +21 -15
  72. package/dist/kernel/components/blocks/navbar.d.ts +5 -4
  73. package/dist/kernel/components/blocks/navbar.js +79 -59
  74. package/dist/kernel/components/blocks/navigation-progress.d.ts +2 -2
  75. package/dist/kernel/components/blocks/navigation-progress.js +2 -2
  76. package/dist/kernel/components/blocks/next-prev.d.ts +4 -4
  77. package/dist/kernel/components/blocks/next-prev.js +30 -7
  78. package/dist/kernel/components/blocks/page-list.d.ts +4 -4
  79. package/dist/kernel/components/blocks/page-list.js +32 -9
  80. package/dist/kernel/components/blocks/search.d.ts +9 -15
  81. package/dist/kernel/components/blocks/search.js +16 -17
  82. package/dist/kernel/components/blocks/sidebar-node.d.ts +3 -5
  83. package/dist/kernel/components/blocks/sidebar-node.js +13 -3
  84. package/dist/kernel/components/blocks/sidebar.d.ts +6 -7
  85. package/dist/kernel/components/blocks/sidebar.js +137 -28
  86. package/dist/kernel/components/blocks/theme-toggle.d.ts +3 -4
  87. package/dist/kernel/components/blocks/theme-toggle.js +5 -5
  88. package/dist/kernel/components/blocks/toc-client.d.ts +40 -0
  89. package/dist/kernel/components/blocks/toc-client.js +495 -0
  90. package/dist/kernel/components/blocks/toc.d.ts +20 -2
  91. package/dist/kernel/components/blocks/toc.js +121 -179
  92. package/dist/kernel/components/mdx/components/blockquote.d.ts +2 -2
  93. package/dist/kernel/components/mdx/components/blockquote.js +1 -1
  94. package/dist/kernel/components/mdx/components/callout.d.ts +3 -3
  95. package/dist/kernel/components/mdx/components/callout.js +1 -1
  96. package/dist/kernel/components/mdx/components/code-block.d.ts +2 -2
  97. package/dist/kernel/components/mdx/components/code-block.js +2 -2
  98. package/dist/kernel/components/mdx/components/copy-code-button.d.ts +2 -2
  99. package/dist/kernel/components/mdx/components/copy-code-button.js +5 -4
  100. package/dist/kernel/components/mdx/components/figure-caption.d.ts +3 -3
  101. package/dist/kernel/components/mdx/components/figure-caption.js +3 -2
  102. package/dist/kernel/components/mdx/components/figure.d.ts +8 -4
  103. package/dist/kernel/components/mdx/components/figure.js +23 -13
  104. package/dist/kernel/components/mdx/components/footnotes.d.ts +2 -2
  105. package/dist/kernel/components/mdx/components/footnotes.js +1 -1
  106. package/dist/kernel/components/mdx/components/heading-copy-link.d.ts +2 -2
  107. package/dist/kernel/components/mdx/components/heading-copy-link.js +1 -1
  108. package/dist/kernel/components/mdx/components/heading.d.ts +2 -2
  109. package/dist/kernel/components/mdx/components/heading.js +6 -3
  110. package/dist/kernel/components/mdx/components/hr.d.ts +4 -4
  111. package/dist/kernel/components/mdx/components/hr.js +2 -2
  112. package/dist/kernel/components/mdx/components/image-zoom.d.ts +3 -3
  113. package/dist/kernel/components/mdx/components/image-zoom.js +4 -3
  114. package/dist/kernel/components/mdx/components/image.d.ts +2 -2
  115. package/dist/kernel/components/mdx/components/image.js +22 -17
  116. package/dist/kernel/components/mdx/components/inline-code.d.ts +2 -2
  117. package/dist/kernel/components/mdx/components/inline-code.js +1 -1
  118. package/dist/kernel/components/mdx/components/kbd.d.ts +3 -3
  119. package/dist/kernel/components/mdx/components/kbd.js +2 -2
  120. package/dist/kernel/components/mdx/components/link.d.ts +6 -6
  121. package/dist/kernel/components/mdx/components/link.js +2 -2
  122. package/dist/kernel/components/mdx/components/paragraph.d.ts +2 -2
  123. package/dist/kernel/components/mdx/components/paragraph.js +1 -1
  124. package/dist/kernel/components/mdx/components/strikethrough.d.ts +2 -2
  125. package/dist/kernel/components/mdx/components/strikethrough.js +1 -1
  126. package/dist/kernel/components/mdx/components/table.d.ts +7 -7
  127. package/dist/kernel/components/mdx/components/table.js +2 -2
  128. package/dist/kernel/components/mdx/components/task-list.d.ts +3 -3
  129. package/dist/kernel/components/mdx/components/task-list.js +1 -1
  130. package/dist/kernel/components/mdx/components/video-player.d.ts +8 -4
  131. package/dist/kernel/components/mdx/components/video-player.js +6 -2
  132. package/dist/kernel/components/mdx/components/video.d.ts +5 -4
  133. package/dist/kernel/components/mdx/components/video.js +7 -5
  134. package/dist/kernel/components/mdx/error-boundary.d.ts +3 -4
  135. package/dist/kernel/components/mdx/error-boundary.js +2 -2
  136. package/dist/kernel/components/mdx/error-fallback.d.ts +2 -2
  137. package/dist/kernel/components/mdx/error-fallback.js +1 -1
  138. package/dist/kernel/components/mdx/mdx.d.ts +57 -16
  139. package/dist/kernel/components/mdx/mdx.js +232 -35
  140. package/dist/kernel/components/mdx/rehype-heading-ids.d.ts +1 -0
  141. package/dist/kernel/components/mdx/rehype-heading-ids.js +5 -3
  142. package/dist/kernel/components/mdx/types.d.ts +1 -1
  143. package/dist/kernel/components/next-image.d.ts +12 -0
  144. package/dist/kernel/components/next-image.js +61 -0
  145. package/dist/kernel/components/ui/accordion.d.ts +7 -7
  146. package/dist/kernel/components/ui/accordion.js +1 -1
  147. package/dist/kernel/components/ui/breadcrumb-trail.d.ts +3 -4
  148. package/dist/kernel/components/ui/breadcrumb-trail.js +2 -2
  149. package/dist/kernel/components/ui/breadcrumb.d.ts +14 -14
  150. package/dist/kernel/components/ui/breadcrumb.js +4 -4
  151. package/dist/kernel/components/ui/button-group.d.ts +6 -6
  152. package/dist/kernel/components/ui/button-group.js +3 -3
  153. package/dist/kernel/components/ui/button.d.ts +59 -7
  154. package/dist/kernel/components/ui/button.js +43 -39
  155. package/dist/kernel/components/ui/card.d.ts +7 -7
  156. package/dist/kernel/components/ui/card.js +1 -1
  157. package/dist/kernel/components/ui/dialog.d.ts +10 -10
  158. package/dist/kernel/components/ui/dialog.js +1 -1
  159. package/dist/kernel/components/ui/drawer.d.ts +12 -12
  160. package/dist/kernel/components/ui/drawer.js +1 -1
  161. package/dist/kernel/components/ui/input.d.ts +2 -2
  162. package/dist/kernel/components/ui/input.js +1 -1
  163. package/dist/kernel/components/ui/kbd.d.ts +4 -4
  164. package/dist/kernel/components/ui/kbd.js +1 -1
  165. package/dist/kernel/components/ui/link.d.ts +11 -5
  166. package/dist/kernel/components/ui/link.js +2 -2
  167. package/dist/kernel/components/ui/menu.d.ts +22 -22
  168. package/dist/kernel/components/ui/menu.js +1 -1
  169. package/dist/kernel/components/ui/mod-key.d.ts +2 -3
  170. package/dist/kernel/components/ui/mod-key.js +2 -2
  171. package/dist/kernel/components/ui/navigation-menu.d.ts +15 -15
  172. package/dist/kernel/components/ui/navigation-menu.js +1 -1
  173. package/dist/kernel/components/ui/popover.d.ts +11 -11
  174. package/dist/kernel/components/ui/popover.js +1 -1
  175. package/dist/kernel/components/ui/progress.d.ts +7 -7
  176. package/dist/kernel/components/ui/progress.js +1 -1
  177. package/dist/kernel/components/ui/scroll-area.d.ts +9 -10
  178. package/dist/kernel/components/ui/scroll-area.js +1 -1
  179. package/dist/kernel/components/ui/select.d.ts +16 -16
  180. package/dist/kernel/components/ui/select.js +1 -1
  181. package/dist/kernel/components/ui/separator.d.ts +3 -3
  182. package/dist/kernel/components/ui/separator.js +1 -1
  183. package/dist/kernel/components/ui/table.d.ts +7 -7
  184. package/dist/kernel/components/ui/table.js +1 -1
  185. package/dist/kernel/components/ui/tabs.d.ts +12 -12
  186. package/dist/kernel/components/ui/tabs.js +1 -1
  187. package/dist/kernel/components/ui/tag.d.ts +3 -3
  188. package/dist/kernel/components/ui/tag.js +1 -1
  189. package/dist/kernel/components/ui/text.d.ts +4 -4
  190. package/dist/kernel/components/ui/text.js +1 -1
  191. package/dist/kernel/components/ui/toast.d.ts +11 -11
  192. package/dist/kernel/components/ui/toast.js +1 -1
  193. package/dist/kernel/components/ui/tooltip.d.ts +9 -9
  194. package/dist/kernel/components/ui/tooltip.js +1 -1
  195. package/dist/kernel/defaults.registry.d.ts +4 -17
  196. package/dist/kernel/defaults.registry.js +4 -19
  197. package/dist/kernel/routes/agent/markdown.d.ts +7 -0
  198. package/dist/kernel/routes/agent/markdown.js +229 -54
  199. package/dist/kernel/routes/layouts/group.d.ts +1 -1
  200. package/dist/kernel/routes/layouts/group.js +5 -7
  201. package/dist/kernel/routes/metadata/feed.d.ts +1 -2
  202. package/dist/kernel/routes/metadata/feed.js +119 -88
  203. package/dist/kernel/routes/metadata/llms.d.ts +3 -23
  204. package/dist/kernel/routes/metadata/llms.js +2 -103
  205. package/dist/kernel/routes/metadata/og-image.js +1 -1
  206. package/dist/kernel/routes/metadata/robots.d.ts +5 -3
  207. package/dist/kernel/routes/metadata/robots.js +4 -25
  208. package/dist/kernel/routes/metadata/sitemap.d.ts +36 -3
  209. package/dist/kernel/routes/metadata/sitemap.js +277 -49
  210. package/dist/kernel/routes/not-found.d.ts +34 -0
  211. package/dist/kernel/routes/not-found.js +213 -0
  212. package/dist/kernel/routes/pages/group.d.ts +5 -5
  213. package/dist/kernel/routes/pages/group.js +11 -5
  214. package/dist/kernel/routes/pages/leaf.d.ts +38 -6
  215. package/dist/kernel/routes/pages/leaf.js +21 -12
  216. package/dist/kernel/routes/pages/root.d.ts +5 -5
  217. package/dist/kernel/routes/pages/root.js +21 -6
  218. package/dist/keyboard-shortcuts.d.ts +2 -2
  219. package/dist/keyboard-shortcuts.js +1 -1
  220. package/dist/manifest-types-CcVPH_jh.d.ts +83 -0
  221. package/dist/resolvers/manifest-resolver.d.ts +2 -2
  222. package/dist/resolvers/manifest-resolver.js +65 -35
  223. package/dist/route-metadata-og-image-BeKKFHg7.d.ts +58 -0
  224. package/dist/search.d.ts +2 -9
  225. package/dist/search.js +9 -16
  226. package/dist/sidebar-types-CMrMM0Nj.d.ts +105 -0
  227. package/dist/theme-scope.d.ts +2 -2
  228. package/dist/theme-scope.js +1 -1
  229. package/dist/types-BbqmOzLC.d.ts +168 -0
  230. package/dist/types-TjH1ek0X.d.ts +22 -0
  231. package/dist/types-sM2g9nW0.d.ts +12 -0
  232. package/dist/types.d.ts +117 -91
  233. package/dist/utils/heading-ids.js +30 -11
  234. package/dist/utils/toc-selection.d.ts +7 -0
  235. package/dist/utils/toc-selection.js +14 -0
  236. package/dist/validate-local-source-EN2GW4FR.js +16 -0
  237. package/dist/validate-publish-os-source-OEWQDB7B.js +14 -0
  238. package/init/seed/minimal/publish.os/assets/blog/hello-world.svg +13 -0
  239. package/init/seed/minimal/publish.os/assets/favicon.dark.svg +13 -0
  240. package/init/seed/minimal/publish.os/assets/favicon.svg +13 -0
  241. package/init/seed/minimal/publish.os/blog/content/hello-world.mdx +48 -0
  242. package/init/seed/minimal/publish.os/blog/content/series-a.mdx +11 -0
  243. package/init/seed/minimal/publish.os/blog/index.tsx +85 -0
  244. package/init/seed/minimal/publish.os/blog/layout.tsx +13 -0
  245. package/init/seed/minimal/publish.os/blog/page.tsx +91 -0
  246. package/init/seed/minimal/publish.os/components/blog/copy-link.tsx +64 -0
  247. package/init/seed/minimal/publish.os/components/blog/frontmatter.ts +41 -0
  248. package/init/seed/minimal/publish.os/docs/content/get-started.mdx +2 -3
  249. package/init/seed/minimal/publish.os/docs/content/groups.mdx +5 -6
  250. package/init/seed/minimal/publish.os/publish.os.config.json +17 -2
  251. package/init/seed/minimal/publish.os/theme.css +3 -3
  252. package/init/seed/minimal/seed.json +12 -4
  253. package/init/seed/scratch/publish.os/docs/content/get-started.mdx +1 -1
  254. package/init/seed/scratch/publish.os/publish.os.config.json +1 -1
  255. package/package.json +48 -23
  256. package/release/app/phosphor/package.json +4 -4
  257. package/release/app/phosphor/pnpm-lock.yaml.template +123 -184
  258. package/release/compiler/package.json +5 -3
  259. package/release/compiler/pnpm-lock.yaml.template +153 -183
  260. package/release/release.json +6 -6
  261. package/dist/button-CtzUJB8u.d.ts +0 -11
  262. package/dist/chunk-535TM4A5.js +0 -1455
  263. package/dist/chunk-B2V22WRT.js +0 -297
  264. package/dist/chunk-NECL5IBJ.js +0 -318
  265. package/dist/chunk-SVYGXXYR.js +0 -36
  266. package/dist/chunk-UF6ATARM.js +0 -1100
  267. package/dist/compose-NN23UJGC.js +0 -13
  268. package/dist/ide-support-ZNW7ODFY.js +0 -15
  269. package/dist/kernel/components/blocks/design-system-preview.d.ts +0 -61
  270. package/dist/kernel/components/blocks/design-system-preview.js +0 -667
  271. package/dist/kernel/components/blocks/link-playground.d.ts +0 -5
  272. package/dist/kernel/components/blocks/link-playground.js +0 -744
  273. package/dist/kernel/components/blocks/navigation-progress-playground.d.ts +0 -5
  274. package/dist/kernel/components/blocks/navigation-progress-playground.js +0 -629
  275. package/dist/kernel/components/ui/theme-toggle.d.ts +0 -24
  276. package/dist/kernel/components/ui/theme-toggle.js +0 -53
  277. package/dist/sidebar-types-DKpR27II.d.ts +0 -25
  278. package/dist/types-BzkZty3r.d.ts +0 -147
  279. package/dist/types-CJWRG05y.d.ts +0 -76
  280. package/dist/types-CUtrppxt.d.ts +0 -69
  281. package/dist/validate-local-source-XRL2Y7XE.js +0 -14
  282. package/dist/validate-publish-os-source-DAPZ4QGE.js +0 -12
  283. package/init/seed/minimal/publish.os/assets/favicon/favicon.dark.png +0 -0
  284. package/init/seed/minimal/publish.os/assets/favicon/favicon.png +0 -0
@@ -0,0 +1,2519 @@
1
+ import {
2
+ SOURCE_ASSET_PREFIX
3
+ } from "./chunk-EFO6AWXN.js";
4
+ import {
5
+ MAX_MEDIA_SVG_BYTES,
6
+ ignoredMediaDocumentWarning,
7
+ ignoredMediaPathWarning,
8
+ mediaFileByteLimit,
9
+ mediaFileTooLarge,
10
+ readBoundedMediaFile
11
+ } from "./chunk-5KAD7W53.js";
12
+ import {
13
+ isExcludedSourcePath,
14
+ isSameOrDescendant
15
+ } from "./chunk-WL75GQ5M.js";
16
+ import {
17
+ AppError
18
+ } from "./chunk-22RSSUNV.js";
19
+
20
+ // src/lib/compiler/source/mdx-component-contract.ts
21
+ import ts from "typescript";
22
+ var groupedMdxExports = {
23
+ figure: { FigureCaption: "figcaption" },
24
+ table: {
25
+ TableHeadGroup: "thead",
26
+ TableBodyGroup: "tbody",
27
+ TableRowGroup: "tr",
28
+ TableHeaderCell: "th",
29
+ TableDataCell: "td"
30
+ }
31
+ }, replacedMdxSourceFiles = {
32
+ a: "link",
33
+ "figure-caption": "figure",
34
+ h1: "heading",
35
+ h2: "heading",
36
+ h3: "heading",
37
+ h4: "heading",
38
+ h5: "heading",
39
+ h6: "heading",
40
+ img: "image",
41
+ pre: "code-block",
42
+ "table-body-group": "table",
43
+ "table-data-cell": "table",
44
+ "table-header-cell": "table",
45
+ "table-head-group": "table",
46
+ "table-row-group": "table"
47
+ };
48
+ function mdxComponentExportName(stem) {
49
+ return stem.split("-").map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`).join("");
50
+ }
51
+ function collectBindingNames(name) {
52
+ return ts.isIdentifier(name) ? [name.text] : name.elements.flatMap(
53
+ (element) => ts.isOmittedExpression(element) ? [] : collectBindingNames(element.name)
54
+ );
55
+ }
56
+ function namedValueExports(sourceFile) {
57
+ let names = /* @__PURE__ */ new Set();
58
+ for (let statement of sourceFile.statements) {
59
+ if (ts.isExportDeclaration(statement) && !statement.isTypeOnly && statement.exportClause && ts.isNamedExports(statement.exportClause)) {
60
+ for (let element of statement.exportClause.elements)
61
+ element.isTypeOnly || names.add(element.name.text);
62
+ continue;
63
+ }
64
+ if (!ts.canHaveModifiers(statement)) continue;
65
+ let modifiers = ts.getModifiers(statement);
66
+ if (!(!modifiers?.some(
67
+ (modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword
68
+ ) || modifiers.some(
69
+ (modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword
70
+ ))) {
71
+ if ((ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) && statement.name)
72
+ names.add(statement.name.text);
73
+ else if (ts.isVariableStatement(statement))
74
+ for (let declaration of statement.declarationList.declarations)
75
+ for (let name of collectBindingNames(declaration.name))
76
+ names.add(name);
77
+ }
78
+ }
79
+ return names;
80
+ }
81
+
82
+ // src/lib/compiler/source/mdx-icon-imports.ts
83
+ import { readFile } from "fs/promises";
84
+ import { createRequire } from "module";
85
+ import { dirname, resolve } from "path";
86
+ import remarkMdx from "remark-mdx";
87
+ import remarkParse from "remark-parse";
88
+ import ts2 from "typescript";
89
+ import { unified } from "unified";
90
+
91
+ // src/lib/compiler/source/frontmatter.ts
92
+ import { isAlias, isMap, isScalar, isSeq, parseDocument } from "yaml";
93
+ function decimalValue(value) {
94
+ let match = /^([+-]?)(\d*)(?:\.(\d*))?(?:e([+-]?\d+))?$/i.exec(value);
95
+ if (!match || !(match[2] || match[3])) return;
96
+ let digits = `${match[2]}${match[3] ?? ""}`.replace(/^0+/, "");
97
+ if (!digits) return "0";
98
+ let trimmed = digits.replace(/0+$/, ""), exponent = BigInt(match[4] ?? "0") - BigInt((match[3] ?? "").length) + BigInt(digits.length - trimmed.length);
99
+ return `${match[1] === "-" ? "-" : ""}${trimmed}e${exponent}`;
100
+ }
101
+ function numberIsExact(source, value) {
102
+ if (!Number.isFinite(value)) return !1;
103
+ if (/^[-+]?0[ox]/i.test(source))
104
+ try {
105
+ return Number.isInteger(value) && BigInt(source.replace(/^\+/, "")) === BigInt(value);
106
+ } catch {
107
+ return !1;
108
+ }
109
+ return decimalValue(source) === decimalValue(String(value));
110
+ }
111
+ var FrontmatterParseError = class extends Error {
112
+ constructor(message, line, column, field) {
113
+ super(`${message} at line ${line}, column ${column}.`);
114
+ this.line = line;
115
+ this.column = column;
116
+ this.field = field;
117
+ this.name = "FrontmatterParseError";
118
+ }
119
+ line;
120
+ column;
121
+ field;
122
+ };
123
+ function parseSourceFrontmatter(source) {
124
+ let firstLine = /^(?:\uFEFF)?---(?:\r?\n|$)/.exec(source);
125
+ if (!firstLine) return { data: {}, content: source };
126
+ let offset = firstLine[0].length, fence, end = -1, bodyStart = -1;
127
+ for (; offset < source.length; ) {
128
+ let next = source.indexOf(`
129
+ `, offset), lineEnd = next < 0 ? source.length : next, line = source.slice(offset, lineEnd).replace(/\r$/, ""), marker = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(line);
130
+ if (marker) {
131
+ let run = marker[1] ?? "";
132
+ fence ? run.charAt(0) === fence.character && run.length >= fence.length && !(marker[2] ?? "").trim() && (fence = void 0) : fence = { character: run.charAt(0), length: run.length };
133
+ } else if (!fence && line === "---") {
134
+ end = offset, bodyStart = next < 0 ? source.length : next + 1;
135
+ break;
136
+ }
137
+ offset = next < 0 ? source.length : next + 1;
138
+ }
139
+ if (end < 0) return { data: {}, content: source };
140
+ let frontmatterOffset = firstLine[0].length;
141
+ function fail(message, offset2 = 0, field) {
142
+ let absoluteOffset = Math.min(frontmatterOffset + offset2, source.length), before = source.slice(0, absoluteOffset), line = before.split(`
143
+ `).length, column = absoluteOffset - before.lastIndexOf(`
144
+ `);
145
+ throw new FrontmatterParseError(message, line, column, field);
146
+ }
147
+ let doc = parseDocument(source.slice(firstLine[0].length, end), {
148
+ schema: "core",
149
+ uniqueKeys: !0
150
+ }), yamlError = doc.errors[0] ?? doc.warnings[0];
151
+ if (yamlError) {
152
+ let message = yamlError.message.replace(
153
+ / at line \d+, column \d+:[\s\S]*$/,
154
+ ""
155
+ );
156
+ fail(message, yamlError.pos[0]);
157
+ }
158
+ doc.contents && !isMap(doc.contents) && fail(
159
+ "Frontmatter must be a mapping with string keys",
160
+ doc.contents.range?.[0]
161
+ );
162
+ let visits = 0, active = /* @__PURE__ */ new Set();
163
+ function validate(node, field) {
164
+ if (node) {
165
+ if (++visits > 1e4 && fail("Frontmatter alias expansion exceeds the limit"), isAlias(node)) {
166
+ let target = node.resolve(doc);
167
+ target || fail(`Invalid alias in ${field}`, node.range?.[0], field), active.has(target) && fail(`Cyclic alias in ${field}`, node.range?.[0], field), validate(target, field);
168
+ return;
169
+ }
170
+ if (!(!isScalar(node) && !isMap(node) && !isSeq(node))) {
171
+ if (node.tag && ![
172
+ "tag:yaml.org,2002:str",
173
+ "tag:yaml.org,2002:int",
174
+ "tag:yaml.org,2002:float",
175
+ "tag:yaml.org,2002:bool",
176
+ "tag:yaml.org,2002:null",
177
+ "tag:yaml.org,2002:map",
178
+ "tag:yaml.org,2002:seq"
179
+ ].includes(node.tag) && fail(`Unsupported YAML tag in ${field}`, node.range?.[0], field), isScalar(node)) {
180
+ typeof node.value == "number" && !numberIsExact(node.source ?? String(node.value), node.value) && fail(
181
+ `Invalid number in ${field}; quote the value to preserve its exact digits`,
182
+ node.range?.[0],
183
+ field
184
+ );
185
+ return;
186
+ }
187
+ if (active.add(node), isMap(node))
188
+ for (let pair of node.items)
189
+ (!isScalar(pair.key) || typeof pair.key.value != "string") && fail(
190
+ `Frontmatter keys in ${field} must be strings`,
191
+ isScalar(pair.key) || isMap(pair.key) || isSeq(pair.key) || isAlias(pair.key) ? pair.key.range?.[0] : void 0,
192
+ field
193
+ ), validate(
194
+ pair.value,
195
+ field === "frontmatter" ? pair.key.value : `${field}.${pair.key.value}`
196
+ );
197
+ else
198
+ for (let item of node.items) validate(item, field);
199
+ active.delete(node);
200
+ }
201
+ }
202
+ }
203
+ validate(doc.contents, "frontmatter");
204
+ let data = doc.toJS({ maxAliasCount: 100 });
205
+ return {
206
+ data: data ? JSON.parse(JSON.stringify(data)) : {},
207
+ content: source.slice(bodyStart)
208
+ };
209
+ }
210
+
211
+ // src/lib/compiler/source/mdx-icon-imports.ts
212
+ var mdxIconPackage = "@phosphor-icons/react/ssr", parser = unified().use(remarkParse).use(remarkMdx), MdxIconImportError = class extends Error {
213
+ constructor(message, line, column, code = "FRAMEWORK_MDX_IMPORT_REJECTED") {
214
+ super(message);
215
+ this.line = line;
216
+ this.column = column;
217
+ this.code = code;
218
+ }
219
+ line;
220
+ column;
221
+ code;
222
+ };
223
+ function mdxIconImportsFromTree(tree, lineOffset = 0) {
224
+ let imports = [];
225
+ for (let node of tree.children)
226
+ if (node.type === "mdxjsEsm")
227
+ for (let statement of node.data?.estree?.body ?? []) {
228
+ let line = (statement.loc?.start.line ?? node.position?.start.line ?? 1) + lineOffset, column = (statement.loc?.start.column ?? 0) + 1;
229
+ if (statement.type !== "ImportDeclaration" || statement.source.value !== mdxIconPackage || statement.specifiers.length === 0 || statement.specifiers.some(
230
+ (specifier) => specifier.type !== "ImportSpecifier"
231
+ ))
232
+ throw new MdxIconImportError(
233
+ `MDX supports named icon imports from "${mdxIconPackage}". Use import { ArrowRightIcon } from "${mdxIconPackage}". Other MDX imports and exports are unsupported.`,
234
+ line,
235
+ column
236
+ );
237
+ for (let specifier of statement.specifiers) {
238
+ if (specifier.type !== "ImportSpecifier") continue;
239
+ if (specifier.imported.type !== "Identifier")
240
+ throw new MdxIconImportError(
241
+ "Import an icon by its exact identifier, such as ArrowRightIcon.",
242
+ line,
243
+ column
244
+ );
245
+ let imported = specifier.imported.name;
246
+ imports.push({ imported, local: specifier.local.name, line, column });
247
+ }
248
+ }
249
+ return imports;
250
+ }
251
+ function readMdxIconImports(source, lineOffset = 0) {
252
+ return /^\s*(?:import|export)\s/m.test(source) ? mdxIconImportsFromTree(parser.parse(source), lineOffset) : [];
253
+ }
254
+ var exportedIcons;
255
+ async function validateMdxIconImports(source) {
256
+ if (!/^\s*(?:import|export)\s/m.test(source)) return [];
257
+ let body = parseSourceFrontmatter(source).content, lineOffset = source.slice(0, source.length - body.length).split(`
258
+ `).length - 1, imports = readMdxIconImports(body, lineOffset);
259
+ if (imports.length === 0) return imports;
260
+ exportedIcons ??= (async () => {
261
+ let require2 = createRequire(import.meta.url), entry = resolve(
262
+ dirname(require2.resolve("@phosphor-icons/react/package.json")),
263
+ "dist/ssr/index.es.js"
264
+ );
265
+ return namedValueExports(
266
+ ts2.createSourceFile(
267
+ entry,
268
+ await readFile(entry, "utf8"),
269
+ ts2.ScriptTarget.Latest,
270
+ !0
271
+ )
272
+ );
273
+ })();
274
+ let exports = await exportedIcons;
275
+ for (let binding of imports)
276
+ if (!exports.has(binding.imported))
277
+ throw new MdxIconImportError(
278
+ `"${binding.imported}" is not exported by "${mdxIconPackage}". Import an exact icon export such as ArrowRightIcon.`,
279
+ binding.line,
280
+ binding.column,
281
+ "FRAMEWORK_MDX_IMPORT_EXPORT_MISSING"
282
+ );
283
+ return imports;
284
+ }
285
+
286
+ // src/lib/shared/root-content-group.ts
287
+ var ROOT_CONTENT_GROUP_KEY = "__root", ROOT_CONTENT_GROUP_TITLE = "Root";
288
+
289
+ // src/lib/compiler/source/assert-source-dependency.ts
290
+ import { lstat } from "fs/promises";
291
+ import { isAbsolute, relative, resolve as resolve2, sep } from "path";
292
+ async function assertSourceDependency({
293
+ publishOsDir,
294
+ path,
295
+ sourceFile
296
+ }) {
297
+ let root = resolve2(publishOsDir), target = resolve2(path), targetRelativePath = relative(root, target), details = {
298
+ file: (isAbsolute(sourceFile) ? relative(root, sourceFile) : sourceFile).split(sep).join("/"),
299
+ target: targetRelativePath.split(sep).join("/")
300
+ };
301
+ if (!isSameOrDescendant(root, target))
302
+ throw new AppError({
303
+ code: "FRAMEWORK_SOURCE_DEPENDENCY_ESCAPE",
304
+ message: "Source dependencies must stay inside publish.os.",
305
+ details
306
+ });
307
+ if (isExcludedSourcePath(details.target))
308
+ throw new AppError({
309
+ code: "FRAMEWORK_SOURCE_DEPENDENCY_EXCLUDED",
310
+ message: "Source dependencies cannot use nested sites, generated output, or root IDE metadata.",
311
+ details
312
+ });
313
+ let segments = targetRelativePath ? targetRelativePath.split(sep) : [], current = root;
314
+ for (let segment of ["", ...segments]) {
315
+ current = resolve2(current, segment);
316
+ let entry = await lstat(current).catch((error) => {
317
+ throw error.code !== "ENOENT" && error.code !== "ENOTDIR" ? error : new AppError({
318
+ code: "FRAMEWORK_SOURCE_DEPENDENCY_MISSING",
319
+ message: "A source dependency does not exist.",
320
+ details
321
+ });
322
+ });
323
+ if (entry.isSymbolicLink())
324
+ throw new AppError({
325
+ code: "FRAMEWORK_SOURCE_DEPENDENCY_SYMLINK",
326
+ message: "Source dependencies cannot use symbolic links.",
327
+ details
328
+ });
329
+ if (current === target ? !entry.isFile() : !entry.isDirectory())
330
+ throw new AppError({
331
+ code: "FRAMEWORK_SOURCE_DEPENDENCY_NOT_FILE",
332
+ message: "A source dependency must resolve to a regular file.",
333
+ details
334
+ });
335
+ }
336
+ }
337
+
338
+ // src/lib/compiler/packages/nextjs-runtime-surface.json
339
+ var nextjs_runtime_surface_default = {
340
+ packageExports: [
341
+ ".",
342
+ "./jsx-runtime",
343
+ "./jsx-dev-runtime",
344
+ "./resolvers/manifest-resolver",
345
+ "./mdx/error-boundary",
346
+ "./mdx/error-fallback",
347
+ "./mdx/mdx",
348
+ "./mdx/rehype-heading-ids",
349
+ "./mdx/types",
350
+ "./mdx/components/blockquote",
351
+ "./mdx/components/callout",
352
+ "./mdx/components/code-block",
353
+ "./mdx/components/figure-caption",
354
+ "./mdx/components/figure",
355
+ "./mdx/components/footnotes",
356
+ "./mdx/components/heading-copy-link",
357
+ "./mdx/components/heading",
358
+ "./mdx/components/hr",
359
+ "./mdx/components/image-zoom",
360
+ "./mdx/components/image",
361
+ "./mdx/components/inline-code",
362
+ "./mdx/components/kbd",
363
+ "./mdx/components/link",
364
+ "./mdx/components/paragraph",
365
+ "./mdx/components/strikethrough",
366
+ "./mdx/components/table",
367
+ "./mdx/components/task-list",
368
+ "./mdx/components/video",
369
+ "./mdx",
370
+ "./cache/tags",
371
+ "./keyboard-shortcuts",
372
+ "./search",
373
+ "./theme-scope",
374
+ "./types",
375
+ "./kernel/defaults.registry",
376
+ "./kernel/routes/agent/markdown",
377
+ "./kernel/routes/not-found",
378
+ "./kernel/routes/layouts/group",
379
+ "./kernel/routes/metadata/feed",
380
+ "./kernel/routes/metadata/llms",
381
+ "./kernel/routes/metadata/og-image",
382
+ "./kernel/routes/metadata/robots",
383
+ "./kernel/routes/metadata/sitemap",
384
+ "./kernel/routes/pages/group",
385
+ "./kernel/routes/pages/leaf",
386
+ "./kernel/routes/pages/root",
387
+ "./kernel/components/blocks/AgentActions",
388
+ "./kernel/components/blocks/agent-actions",
389
+ "./kernel/components/blocks/animated-icon-swap",
390
+ "./kernel/components/blocks/color-palette",
391
+ "./kernel/components/blocks/logo-block",
392
+ "./kernel/components/blocks/nav-breadcrumb",
393
+ "./kernel/components/blocks/navbar",
394
+ "./kernel/components/blocks/navigation-progress",
395
+ "./kernel/components/blocks/next-prev",
396
+ "./kernel/components/blocks/page-list",
397
+ "./kernel/components/blocks/search",
398
+ "./kernel/components/blocks/sidebar-node",
399
+ "./kernel/components/blocks/sidebar",
400
+ "./kernel/components/blocks/theme-toggle",
401
+ "./kernel/components/blocks/toc",
402
+ "./kernel/components/blocks/toc-client",
403
+ "./kernel/components/next-image",
404
+ "./kernel/components/mdx/error-boundary",
405
+ "./kernel/components/mdx/error-fallback",
406
+ "./kernel/components/mdx/mdx",
407
+ "./kernel/components/mdx/rehype-heading-ids",
408
+ "./kernel/components/mdx/types",
409
+ "./kernel/components/mdx/components/blockquote",
410
+ "./kernel/components/mdx/components/callout",
411
+ "./kernel/components/mdx/components/code-block",
412
+ "./kernel/components/mdx/components/copy-code-button",
413
+ "./kernel/components/mdx/components/figure-caption",
414
+ "./kernel/components/mdx/components/figure",
415
+ "./kernel/components/mdx/components/footnotes",
416
+ "./kernel/components/mdx/components/heading-copy-link",
417
+ "./kernel/components/mdx/components/heading",
418
+ "./kernel/components/mdx/components/hr",
419
+ "./kernel/components/mdx/components/image-zoom",
420
+ "./kernel/components/mdx/components/image",
421
+ "./kernel/components/mdx/components/inline-code",
422
+ "./kernel/components/mdx/components/kbd",
423
+ "./kernel/components/mdx/components/link",
424
+ "./kernel/components/mdx/components/paragraph",
425
+ "./kernel/components/mdx/components/strikethrough",
426
+ "./kernel/components/mdx/components/table",
427
+ "./kernel/components/mdx/components/task-list",
428
+ "./kernel/components/mdx/components/video-player",
429
+ "./kernel/components/mdx/components/video",
430
+ "./kernel/components/ui/accordion",
431
+ "./kernel/components/ui/breadcrumb-trail",
432
+ "./kernel/components/ui/breadcrumb",
433
+ "./kernel/components/ui/button-group",
434
+ "./kernel/components/ui/button",
435
+ "./components/ui/button",
436
+ "./components/blocks/toc",
437
+ "./components/blocks/agent-actions",
438
+ "./kernel/components/ui/card",
439
+ "./kernel/components/ui/dialog",
440
+ "./kernel/components/ui/drawer",
441
+ "./kernel/components/ui/input",
442
+ "./kernel/components/ui/kbd",
443
+ "./kernel/components/ui/link",
444
+ "./kernel/components/ui/menu",
445
+ "./kernel/components/ui/mod-key",
446
+ "./kernel/components/ui/navigation-menu",
447
+ "./kernel/components/ui/popover",
448
+ "./kernel/components/ui/progress",
449
+ "./kernel/components/ui/scroll-area",
450
+ "./kernel/components/ui/select",
451
+ "./kernel/components/ui/separator",
452
+ "./kernel/components/ui/table",
453
+ "./kernel/components/ui/tabs",
454
+ "./kernel/components/ui/tag",
455
+ "./kernel/components/ui/text",
456
+ "./kernel/components/ui/toast",
457
+ "./kernel/components/ui/tooltip",
458
+ "./utils/pretty-date",
459
+ "./utils/cn",
460
+ "./utils/heading-ids",
461
+ "./utils/toc-selection",
462
+ "./config/createNextConfig"
463
+ ],
464
+ allowedSourceImports: [
465
+ "@publish.os/nextjs",
466
+ "@publish.os/nextjs/jsx-runtime",
467
+ "@publish.os/nextjs/jsx-dev-runtime",
468
+ "@publish.os/nextjs/cache/tags",
469
+ "@publish.os/nextjs/config/createNextConfig",
470
+ "@publish.os/nextjs/kernel/components/blocks/navigation-progress",
471
+ "@publish.os/nextjs/components/ui/button",
472
+ "@publish.os/nextjs/components/blocks/toc",
473
+ "@publish.os/nextjs/components/blocks/agent-actions",
474
+ "@publish.os/nextjs/kernel/components/blocks/toc-client",
475
+ "@publish.os/nextjs/kernel/routes/layouts/group",
476
+ "@publish.os/nextjs/kernel/routes/metadata/feed",
477
+ "@publish.os/nextjs/kernel/routes/metadata/llms",
478
+ "@publish.os/nextjs/kernel/routes/metadata/og-image",
479
+ "@publish.os/nextjs/kernel/routes/metadata/robots",
480
+ "@publish.os/nextjs/kernel/routes/metadata/sitemap",
481
+ "@publish.os/nextjs/kernel/routes/pages/group",
482
+ "@publish.os/nextjs/kernel/routes/pages/leaf",
483
+ "@publish.os/nextjs/kernel/routes/pages/root",
484
+ "@publish.os/nextjs/keyboard-shortcuts",
485
+ "@publish.os/nextjs/mdx",
486
+ "@publish.os/nextjs/mdx/error-boundary",
487
+ "@publish.os/nextjs/mdx/error-fallback",
488
+ "@publish.os/nextjs/mdx/mdx",
489
+ "@publish.os/nextjs/resolvers/manifest-resolver",
490
+ "@publish.os/nextjs/search",
491
+ "@publish.os/nextjs/theme-scope",
492
+ "@publish.os/nextjs/types",
493
+ "@publish.os/nextjs/utils/cn",
494
+ "@publish.os/nextjs/utils/heading-ids",
495
+ "@publish.os/nextjs/utils/toc-selection",
496
+ "@publish.os/nextjs/utils/pretty-date"
497
+ ],
498
+ allowedSourceDependencyImports: [
499
+ "@phosphor-icons/react/ssr",
500
+ "react",
501
+ "react-dom",
502
+ "class-variance-authority",
503
+ "next/link",
504
+ "next/image",
505
+ "next/navigation",
506
+ "@base-ui/react/accordion",
507
+ "@base-ui/react/button",
508
+ "@base-ui/react/checkbox",
509
+ "@base-ui/react/dialog",
510
+ "@base-ui/react/drawer",
511
+ "@base-ui/react/input",
512
+ "@base-ui/react/menu",
513
+ "@base-ui/react/popover",
514
+ "@base-ui/react/progress",
515
+ "@base-ui/react/scroll-area",
516
+ "@base-ui/react/select",
517
+ "@base-ui/react/separator",
518
+ "@base-ui/react/switch",
519
+ "@base-ui/react/tabs",
520
+ "@base-ui/react/tooltip",
521
+ "@base-ui/react/toast"
522
+ ],
523
+ entries: {
524
+ index: "src/index.ts",
525
+ "jsx-runtime": "src/jsx-runtime.ts",
526
+ "jsx-dev-runtime": "src/jsx-dev-runtime.ts",
527
+ "cache/tags": "src/cache-tags.ts",
528
+ "config/createNextConfig": "src/create-next-config.ts",
529
+ "keyboard-shortcuts": "src/lib/keyboard/keyboard-shortcuts.tsx",
530
+ search: "src/modules/search/search.tsx",
531
+ "theme-scope": "src/lib/theme/theme-scope.tsx",
532
+ "kernel/defaults.registry": "src/defaults-registry.ts",
533
+ "kernel/components/blocks/AgentActions": "src/modules/agent-actions/agent-actions.tsx",
534
+ "kernel/components/blocks/agent-actions": "src/modules/agent-actions/agent-actions.tsx",
535
+ "kernel/components/blocks/animated-icon-swap": "src/components/ui/animated-icon-swap.tsx",
536
+ "kernel/components/blocks/color-palette": "src/modules/design-system/color-palette.tsx",
537
+ "kernel/components/blocks/logo-block": "src/components/block/logo-block.tsx",
538
+ "kernel/components/blocks/nav-breadcrumb": "src/components/block/navbar/nav-breadcrumb.tsx",
539
+ "kernel/components/blocks/navbar": "src/components/block/navbar/navbar.tsx",
540
+ "kernel/components/blocks/navigation-progress": "src/components/block/navigation-progress.tsx",
541
+ "kernel/components/blocks/next-prev": "src/components/block/page-navigation/next-prev.tsx",
542
+ "kernel/components/blocks/page-list": "src/components/block/page-navigation/page-list.tsx",
543
+ "kernel/components/blocks/search": "src/modules/search/search-block.tsx",
544
+ "kernel/components/blocks/sidebar-node": "src/components/block/sidebar/sidebar-node.tsx",
545
+ "kernel/components/blocks/sidebar": "src/components/block/sidebar/sidebar.tsx",
546
+ "kernel/components/blocks/theme-toggle": "src/components/block/theme-toggle.tsx",
547
+ "kernel/components/blocks/toc": "src/components/block/toc/toc.tsx",
548
+ "kernel/components/blocks/toc-client": "src/components/block/toc/toc-client.tsx",
549
+ "kernel/components/next-image": "src/components/next-image.tsx",
550
+ "kernel/components/mdx/error-boundary": "src/components/mdx/error-boundary.tsx",
551
+ "kernel/components/mdx/error-fallback": "src/components/mdx/error-fallback.tsx",
552
+ "kernel/components/mdx/mdx": "src/components/mdx/mdx.tsx",
553
+ "kernel/components/mdx/rehype-heading-ids": "src/components/mdx/plugins/rehype-heading-ids.ts",
554
+ "kernel/components/mdx/types": "src/components/mdx/types.ts",
555
+ "kernel/routes/layouts/group": "src/route-layout-group.tsx",
556
+ "kernel/routes/agent/markdown": "src/route-agent-markdown.ts",
557
+ "kernel/routes/not-found": "src/route-not-found.ts",
558
+ "kernel/routes/metadata/feed": "src/route-metadata-feed.ts",
559
+ "kernel/routes/metadata/llms": "src/route-metadata-llms.ts",
560
+ "kernel/routes/metadata/og-image": "src/route-metadata-og-image.tsx",
561
+ "kernel/routes/metadata/robots": "src/route-metadata-robots.ts",
562
+ "kernel/routes/metadata/sitemap": "src/route-metadata-sitemap.ts",
563
+ "kernel/routes/pages/group": "src/route-page-group.tsx",
564
+ "kernel/routes/pages/leaf": "src/route-page-leaf.tsx",
565
+ "kernel/routes/pages/root": "src/route-page-root.tsx",
566
+ "resolvers/manifest-resolver": "src/manifest-resolver.ts",
567
+ types: "src/types.ts",
568
+ "utils/cn": "src/components/utils/cn.ts",
569
+ "utils/heading-ids": "src/components/mdx/heading-ids.ts",
570
+ "utils/toc-selection": "src/components/block/toc/selection.ts",
571
+ "utils/pretty-date": "src/components/utils/pretty-date.ts",
572
+ "kernel/components/mdx/components/blockquote": "src/components/mdx/blockquote.tsx",
573
+ "kernel/components/mdx/components/callout": "src/components/mdx/callout.tsx",
574
+ "kernel/components/mdx/components/code-block": "src/components/mdx/code-block/code-block.tsx",
575
+ "kernel/components/mdx/components/copy-code-button": "src/components/mdx/code-block/copy-code-button.tsx",
576
+ "kernel/components/mdx/components/figure-caption": "src/components/mdx/figure/figure-caption.tsx",
577
+ "kernel/components/mdx/components/figure": "src/components/mdx/figure/figure.tsx",
578
+ "kernel/components/mdx/components/footnotes": "src/components/mdx/footnotes.tsx",
579
+ "kernel/components/mdx/components/heading-copy-link": "src/components/mdx/heading-copy-link.tsx",
580
+ "kernel/components/mdx/components/heading": "src/components/mdx/heading.tsx",
581
+ "kernel/components/mdx/components/hr": "src/components/mdx/hr.tsx",
582
+ "kernel/components/mdx/components/image-zoom": "src/components/mdx/image/image-zoom.tsx",
583
+ "kernel/components/mdx/components/image": "src/components/mdx/image/image.tsx",
584
+ "kernel/components/mdx/components/inline-code": "src/components/mdx/inline-code.tsx",
585
+ "kernel/components/mdx/components/kbd": "src/components/mdx/kbd.tsx",
586
+ "kernel/components/mdx/components/link": "src/components/mdx/link.tsx",
587
+ "kernel/components/mdx/components/paragraph": "src/components/mdx/paragraph.tsx",
588
+ "kernel/components/mdx/components/strikethrough": "src/components/mdx/strikethrough.tsx",
589
+ "kernel/components/mdx/components/table": "src/components/mdx/table.tsx",
590
+ "kernel/components/mdx/components/task-list": "src/components/mdx/task-list.tsx",
591
+ "kernel/components/mdx/components/video-player": "src/components/mdx/video/video-player.tsx",
592
+ "kernel/components/mdx/components/video": "src/components/mdx/video/video.tsx",
593
+ "kernel/components/ui/accordion": "src/components/ui/accordion.tsx",
594
+ "kernel/components/ui/breadcrumb-trail": "src/components/ui/breadcrumb-trail.tsx",
595
+ "kernel/components/ui/breadcrumb": "src/components/ui/breadcrumb.tsx",
596
+ "kernel/components/ui/button-group": "src/components/ui/button-group.tsx",
597
+ "kernel/components/ui/button": "src/components/ui/button.tsx",
598
+ "components/ui/button": "src/components/ui/button.tsx",
599
+ "components/blocks/toc": "src/components/block/toc/toc.tsx",
600
+ "components/blocks/agent-actions": "src/modules/agent-actions/agent-actions.tsx",
601
+ "kernel/components/ui/card": "src/components/ui/card.tsx",
602
+ "kernel/components/ui/dialog": "src/components/ui/dialog.tsx",
603
+ "kernel/components/ui/drawer": "src/components/ui/drawer.tsx",
604
+ "kernel/components/ui/input": "src/components/ui/input.tsx",
605
+ "kernel/components/ui/kbd": "src/components/ui/kbd.tsx",
606
+ "kernel/components/ui/link": "src/components/ui/link.tsx",
607
+ "kernel/components/ui/menu": "src/components/ui/menu.tsx",
608
+ "kernel/components/ui/mod-key": "src/components/ui/mod-key.tsx",
609
+ "kernel/components/ui/navigation-menu": "src/components/ui/navigation-menu.tsx",
610
+ "kernel/components/ui/popover": "src/components/ui/popover.tsx",
611
+ "kernel/components/ui/progress": "src/components/ui/progress.tsx",
612
+ "kernel/components/ui/scroll-area": "src/components/ui/scroll-area.tsx",
613
+ "kernel/components/ui/select": "src/components/ui/select.tsx",
614
+ "kernel/components/ui/separator": "src/components/ui/separator.tsx",
615
+ "kernel/components/ui/table": "src/components/ui/table.tsx",
616
+ "kernel/components/ui/tabs": "src/components/ui/tabs.tsx",
617
+ "kernel/components/ui/tag": "src/components/ui/tag.tsx",
618
+ "kernel/components/ui/text": "src/components/ui/text.tsx",
619
+ "kernel/components/ui/toast": "src/components/ui/toast.tsx",
620
+ "kernel/components/ui/tooltip": "src/components/ui/tooltip.tsx"
621
+ },
622
+ entryAliases: {},
623
+ browserEntries: [
624
+ "src/lib/keyboard/keyboard-shortcuts.tsx",
625
+ "src/modules/search/search.tsx",
626
+ "src/lib/theme/theme-scope.tsx",
627
+ "src/modules/agent-actions/agent-actions.tsx",
628
+ "src/modules/design-system/color-palette.tsx",
629
+ "src/components/block/navbar/navbar.tsx",
630
+ "src/components/block/navigation-progress.tsx",
631
+ "src/modules/search/search-block.tsx",
632
+ "src/components/block/sidebar/sidebar.tsx",
633
+ "src/components/block/toc/toc-client.tsx",
634
+ "src/components/mdx/error-boundary.tsx",
635
+ "src/components/mdx/types.ts",
636
+ "src/types.ts",
637
+ "src/components/utils/cn.ts",
638
+ "src/components/mdx/heading-ids.ts",
639
+ "src/components/utils/pretty-date.ts",
640
+ "src/components/mdx/heading-copy-link.tsx",
641
+ "src/components/mdx/image/image-zoom.tsx",
642
+ "src/components/mdx/video/video-player.tsx",
643
+ "src/components/ui/accordion.tsx",
644
+ "src/components/ui/breadcrumb-trail.tsx",
645
+ "src/components/ui/dialog.tsx",
646
+ "src/components/ui/drawer.tsx",
647
+ "src/components/ui/menu.tsx",
648
+ "src/components/ui/navigation-menu.tsx",
649
+ "src/components/ui/popover.tsx",
650
+ "src/components/ui/progress.tsx",
651
+ "src/components/ui/scroll-area.tsx",
652
+ "src/components/ui/tabs.tsx",
653
+ "src/components/ui/toast.tsx",
654
+ "src/components/ui/tooltip.tsx"
655
+ ]
656
+ };
657
+
658
+ // src/lib/compiler/packages/nextjs-runtime-surface.ts
659
+ var surface = nextjs_runtime_surface_default, allowedNextjsSourceImports = [...surface.allowedSourceImports], allowedNextjsSourceDependencyImports = [
660
+ ...surface.allowedSourceDependencyImports
661
+ ];
662
+ function supportedNextjsSourceImports() {
663
+ return [
664
+ ...allowedNextjsSourceImports,
665
+ ...allowedNextjsSourceDependencyImports
666
+ ];
667
+ }
668
+ function supportedRuntimeComponentAliases() {
669
+ return Object.keys(surface.entries).filter((name) => name.startsWith("kernel/components/")).map((name) => `@components/${name.slice(18)}`);
670
+ }
671
+ function originalDefaultComponentSourcePath(specifier) {
672
+ let prefix = "@publish.os/nextjs/";
673
+ if (!specifier.startsWith(prefix)) return;
674
+ let subpath = specifier.slice(prefix.length);
675
+ if (!surface.packageExports.includes(`./${subpath}`) || !surface.entries[subpath])
676
+ return;
677
+ let componentPrefix = "kernel/components/";
678
+ if (!subpath.startsWith(componentPrefix)) return;
679
+ let sourcePath = subpath.slice(componentPrefix.length);
680
+ if (sourcePath.startsWith("mdx/components/") && (sourcePath = `mdx/${sourcePath.slice(15)}`), !!/^(?:ui|blocks|mdx)\//.test(sourcePath))
681
+ return `components/${sourcePath}`;
682
+ }
683
+
684
+ // src/lib/compiler/source/assets/favicons-and-logos.ts
685
+ import { extname } from "path";
686
+ var MAX_FAVICON_BYTES = 1 * 1024 * 1024, MAX_LOGO_BYTES = 2 * 1024 * 1024, FAVICON_FORMATS = ["svg", "png", "jpg", "jpeg", "ico"], LOGO_FORMATS = ["svg", "png", "jpg", "jpeg", "webp", "avif"], FORMAT_RANK = {
687
+ svg: 0,
688
+ png: 1,
689
+ jpg: 2,
690
+ jpeg: 2,
691
+ ico: 3
692
+ }, LOGO_FORMAT_RANK = {
693
+ svg: 0,
694
+ png: 1,
695
+ jpg: 2,
696
+ jpeg: 2,
697
+ webp: 3,
698
+ avif: 4
699
+ };
700
+ function formatOf(path) {
701
+ return extname(path).slice(1).toLowerCase();
702
+ }
703
+ function normalizedToken(value) {
704
+ return value.toLowerCase().split(/[._-]+/).filter(Boolean);
705
+ }
706
+ function classifyPath(path) {
707
+ let segments = path.split("/"), file = segments.at(-1) ?? "", format = formatOf(file), stem = file.slice(0, -(format.length + 1)), tokens = normalizedToken(stem), inLogoFolder = segments[0] === "assets" && segments[1]?.toLowerCase() === "logo", inFaviconFolder = segments[0] === "assets" && segments[1]?.toLowerCase() === "favicon", inIdentityFolder = inLogoFolder || inFaviconFolder, explicitRoles = /* @__PURE__ */ new Set();
708
+ if (tokens.includes("logo") && explicitRoles.add("logo"), tokens.includes("mark") && explicitRoles.add("mark"), tokens.includes("wordmark") && explicitRoles.add("wordmark"), tokens.includes("favicon") && explicitRoles.add("favicon"), tokens.includes("apple") && tokens.includes("icon") && explicitRoles.add("apple-icon"), explicitRoles.size > 1)
709
+ throw conflict("FRAMEWORK_IDENTITY_ROLE_CONFLICT", [path]);
710
+ let explicitRole = [...explicitRoles][0];
711
+ if (inLogoFolder && inFaviconFolder)
712
+ throw conflict("FRAMEWORK_IDENTITY_FOLDER_CONFLICT", [path]);
713
+ if (inLogoFolder && ["favicon", "apple-icon"].includes(explicitRole ?? "") || inFaviconFolder && ["logo", "mark", "wordmark"].includes(explicitRole ?? ""))
714
+ throw conflict("FRAMEWORK_IDENTITY_FOLDER_ROLE_CONFLICT", [path]);
715
+ let role = explicitRole;
716
+ !role && inLogoFolder && (role = "logo"), !role && inFaviconFolder && (role = "favicon");
717
+ let hasModeLight = tokens.includes("light"), hasModeDark = tokens.includes("dark");
718
+ if (hasModeLight && hasModeDark)
719
+ throw conflict("FRAMEWORK_IDENTITY_MODE_CONFLICT", [path]);
720
+ let mode = hasModeLight ? "light" : hasModeDark ? "dark" : "default";
721
+ if (!role && !inIdentityFolder && (hasModeLight || hasModeDark) && (role = "logo"), !role) return;
722
+ let roleTokens = tokens.filter(
723
+ (token) => token !== "light" && token !== "dark"
724
+ ), priority = role === "apple-icon" && roleTokens.length === 2 && roleTokens[0] === "apple" && roleTokens[1] === "icon" || role !== "apple-icon" && roleTokens.length === 1 && roleTokens[0] === role ? 1 : explicitRole ? 2 : format === "svg" ? 3 : inIdentityFolder ? 4 : 5;
725
+ if (role === "apple-icon" && (inLogoFolder || format === "svg"))
726
+ throw conflict("FRAMEWORK_IDENTITY_FORMAT_REJECTED", [path]);
727
+ if (role === "favicon" && !FAVICON_FORMATS.includes(format))
728
+ throw conflict("FRAMEWORK_IDENTITY_FORMAT_REJECTED", [path]);
729
+ if (role === "apple-icon" && !["png", "jpg", "jpeg"].includes(format))
730
+ throw conflict("FRAMEWORK_IDENTITY_FORMAT_REJECTED", [path]);
731
+ if (["logo", "mark", "wordmark"].includes(role) && !LOGO_FORMATS.includes(format))
732
+ throw conflict("FRAMEWORK_IDENTITY_FORMAT_REJECTED", [path]);
733
+ if (role === "apple-icon" && mode !== "default")
734
+ throw conflict("FRAMEWORK_IDENTITY_MODE_CONFLICT", [path]);
735
+ return { path, role, mode, format, priority };
736
+ }
737
+ function conflict(code, paths) {
738
+ let candidates = [...paths].sort();
739
+ return new AppError({
740
+ code,
741
+ message: `Identity asset conflict: ${candidates.join(", ")}`,
742
+ details: { candidates }
743
+ });
744
+ }
745
+ function duplicateWarning(role, mode, candidates) {
746
+ let paths = candidates.map((candidate) => candidate.path).sort(), selected = paths[0] ?? "", ignored = paths.slice(1);
747
+ return {
748
+ code: "FRAMEWORK_IDENTITY_DUPLICATE",
749
+ level: "warning",
750
+ message: `Duplicate ${role} identity assets for ${mode} mode; using ${selected} and ignoring ${ignored.join(", ")}.`,
751
+ details: { role, mode, selected, candidates: paths }
752
+ };
753
+ }
754
+ function deduplicateCandidates(candidates, role) {
755
+ let groups = /* @__PURE__ */ new Map();
756
+ for (let candidate of candidates) {
757
+ let format = ["jpg", "jpeg"].includes(candidate.format) ? "jpeg" : candidate.format, key = role === "favicon" ? `${candidate.mode}:${format}:${candidate.size ?? ""}` : role === "apple-icon" ? `${format}:${candidate.size ?? ""}` : `${candidate.mode}:${format}`, group = groups.get(key) ?? [];
758
+ group.push(candidate), groups.set(key, group);
759
+ }
760
+ let selected = [], warnings = [];
761
+ for (let key of [...groups.keys()].sort()) {
762
+ let group = (groups.get(key) ?? []).sort(
763
+ (left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0
764
+ ), winner = group[0];
765
+ winner && selected.push(winner), group.length > 1 && winner && warnings.push(duplicateWarning(role, winner.mode, group));
766
+ }
767
+ return { candidates: selected, warnings };
768
+ }
769
+ function chooseCandidates(candidates, role) {
770
+ let roleCandidates = candidates.filter(
771
+ (candidate) => candidate.role === role
772
+ );
773
+ if (roleCandidates.length === 0) return { selected: [], warnings: [] };
774
+ if (role === "apple-icon") {
775
+ let byFormatAndSize = /* @__PURE__ */ new Map();
776
+ for (let candidate of roleCandidates) {
777
+ let key = `${["jpg", "jpeg"].includes(candidate.format) ? "jpeg" : candidate.format}:${candidate.size ?? ""}`, group = byFormatAndSize.get(key) ?? [];
778
+ group.push(candidate), byFormatAndSize.set(key, group);
779
+ }
780
+ let selected2 = [], warnings = [];
781
+ for (let key of [...byFormatAndSize.keys()].sort()) {
782
+ let group = byFormatAndSize.get(key) ?? [], priority2 = Math.min(
783
+ ...group.map((candidate) => candidate.priority)
784
+ ), deduplicated = deduplicateCandidates(
785
+ group.filter((candidate) => candidate.priority === priority2),
786
+ role
787
+ );
788
+ selected2.push(...deduplicated.candidates), warnings.push(...deduplicated.warnings);
789
+ }
790
+ return { selected: selected2, warnings };
791
+ }
792
+ let priority = Math.min(
793
+ ...roleCandidates.map((candidate) => candidate.priority)
794
+ ), winning = deduplicateCandidates(
795
+ roleCandidates.filter((candidate) => candidate.priority === priority),
796
+ role
797
+ ), selected = [];
798
+ for (let requestedMode of ["light", "dark"]) {
799
+ let modeCandidates = winning.candidates.filter((candidate) => candidate.mode === requestedMode).length > 0 ? winning.candidates.filter(
800
+ (candidate) => candidate.mode === requestedMode
801
+ ) : winning.candidates.filter((candidate) => candidate.mode === "default").length > 0 ? winning.candidates.filter(
802
+ (candidate) => candidate.mode === "default"
803
+ ) : winning.candidates.filter(
804
+ (candidate) => candidate.mode !== requestedMode
805
+ );
806
+ if (role === "favicon") {
807
+ if (modeCandidates.length === 0) continue;
808
+ let formatRank = Math.min(
809
+ ...modeCandidates.map(
810
+ (candidate) => FORMAT_RANK[candidate.format] ?? 99
811
+ )
812
+ );
813
+ selected.push(
814
+ ...modeCandidates.filter(
815
+ (candidate) => (FORMAT_RANK[candidate.format] ?? 99) === formatRank
816
+ )
817
+ );
818
+ } else {
819
+ let formatRank = Math.min(
820
+ ...modeCandidates.map(
821
+ (candidate) => LOGO_FORMAT_RANK[candidate.format] ?? 99
822
+ )
823
+ ), preferred = modeCandidates.filter(
824
+ (candidate) => (LOGO_FORMAT_RANK[candidate.format] ?? 99) === formatRank
825
+ ).sort(
826
+ (left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0
827
+ );
828
+ preferred[0] && selected.push(preferred[0]);
829
+ }
830
+ }
831
+ let unique = /* @__PURE__ */ new Map();
832
+ for (let item of selected) unique.set(item.path, item);
833
+ return {
834
+ selected: [...unique.values()],
835
+ warnings: winning.warnings
836
+ };
837
+ }
838
+ function icoSizes(contents) {
839
+ if (contents.length < 6) return;
840
+ let count = contents.readUInt16LE(4), sizes = /* @__PURE__ */ new Set();
841
+ for (let index = 0; index < count; index += 1) {
842
+ let offset = 6 + index * 16;
843
+ if (offset + 16 > contents.length) break;
844
+ let width = contents[offset] || 256, height = contents[offset + 1] || 256;
845
+ sizes.add(`${width}x${height}`);
846
+ }
847
+ return [...sizes].sort().join(", ") || void 0;
848
+ }
849
+ function assetSizes(asset) {
850
+ return asset.sizes ? asset.sizes : asset.width && asset.height ? `${asset.width}x${asset.height}` : asset.mimeType === "image/svg+xml" ? "any" : void 0;
851
+ }
852
+ function buildFaviconsAndLogos(options) {
853
+ let mediaImages = /* @__PURE__ */ new Map();
854
+ for (let output of options.media.outputs)
855
+ mediaImages.set(output.outputPath, output.contents);
856
+ let candidates = [];
857
+ for (let [sourceUrl, media] of Object.entries(
858
+ options.media.manifest.assets
859
+ )) {
860
+ if (media.mediaType !== "image") continue;
861
+ let path = sourceUrl.slice(1), candidate = classifyPath(path);
862
+ if (!candidate) continue;
863
+ let bytes = mediaImages.get(media.outputPath);
864
+ if (!bytes) continue;
865
+ let limit = ["logo", "mark", "wordmark"].includes(candidate.role) ? MAX_LOGO_BYTES : MAX_FAVICON_BYTES;
866
+ if (media.byteSize > limit)
867
+ throw new AppError({
868
+ code: "FRAMEWORK_IDENTITY_FILE_TOO_LARGE",
869
+ message: `${path} exceeds the ${limit} byte identity image limit`,
870
+ details: { path, bytes: media.byteSize, limit }
871
+ });
872
+ if ((candidate.role === "favicon" || candidate.role === "apple-icon") && (candidate.format === "ico" && (icoSizes(bytes)?.split(", ").some((size) => {
873
+ let [width, height] = size.split("x").map(Number);
874
+ return width !== height;
875
+ }) ?? !1) || media.width && media.height && media.width !== media.height))
876
+ throw conflict("FRAMEWORK_IDENTITY_NOT_SQUARE", [path]);
877
+ candidates.push({
878
+ ...candidate,
879
+ size: candidate.format === "ico" ? icoSizes(bytes) : media.width && media.height ? `${media.width}x${media.height}` : candidate.format === "svg" ? "any" : void 0
880
+ });
881
+ }
882
+ let choices = [
883
+ chooseCandidates(candidates, "favicon"),
884
+ chooseCandidates(candidates, "apple-icon"),
885
+ chooseCandidates(candidates, "logo"),
886
+ chooseCandidates(candidates, "mark"),
887
+ chooseCandidates(candidates, "wordmark")
888
+ ], selected = choices.flatMap((choice) => choice.selected), warnings = choices.flatMap((choice) => choice.warnings), assets = [];
889
+ for (let candidate of selected) {
890
+ let mediaEntry = options.media.manifest.assets[`/${candidate.path}`];
891
+ if (!mediaEntry) continue;
892
+ let contents = mediaImages.get(mediaEntry.outputPath);
893
+ if (!contents) continue;
894
+ let sizes = candidate.format === "ico" ? icoSizes(contents) : void 0, asset = {
895
+ kind: `${candidate.role}-${candidate.mode}`,
896
+ sourcePath: mediaEntry.sourcePath,
897
+ outputPath: mediaEntry.outputPath,
898
+ contentHash: mediaEntry.contentHash,
899
+ mimeType: mediaEntry.mimeType,
900
+ byteSize: mediaEntry.byteSize,
901
+ width: mediaEntry.width,
902
+ height: mediaEntry.height,
903
+ sizes
904
+ };
905
+ assets.push(asset);
906
+ }
907
+ let by = (role, mode) => assets.find((asset) => asset.kind === `${role}-${mode}`), all = (role, mode) => assets.filter((asset) => asset.kind === `${role}-${mode}`), favicon = {
908
+ fallback: all("favicon", "default"),
909
+ light: all("favicon", "light").length ? all("favicon", "light") : all("favicon", "default").length ? all("favicon", "default") : all("favicon", "dark"),
910
+ dark: all("favicon", "dark").length ? all("favicon", "dark") : all("favicon", "default").length ? all("favicon", "default") : all("favicon", "light"),
911
+ apple: all("apple-icon", "default")
912
+ }, logo = {
913
+ light: by("logo", "light") ?? by("logo", "default") ?? by("logo", "dark"),
914
+ dark: by("logo", "dark") ?? by("logo", "default") ?? by("logo", "light"),
915
+ markLight: by("mark", "light") ?? by("mark", "default") ?? by("mark", "dark"),
916
+ markDark: by("mark", "dark") ?? by("mark", "default") ?? by("mark", "light"),
917
+ wordmarkLight: by("wordmark", "light") ?? by("wordmark", "default") ?? by("wordmark", "dark"),
918
+ wordmarkDark: by("wordmark", "dark") ?? by("wordmark", "default") ?? by("wordmark", "light")
919
+ }, icon = [];
920
+ for (let [mode, entries] of [
921
+ ["light", favicon.light],
922
+ ["dark", favicon.dark]
923
+ ])
924
+ for (let entry of entries ?? []) {
925
+ let existing = icon.find((item) => item.url === entry.outputPath);
926
+ existing ? delete existing.media : icon.push({
927
+ url: entry.outputPath,
928
+ type: entry.mimeType,
929
+ sizes: assetSizes(entry),
930
+ media: `(prefers-color-scheme: ${mode})`
931
+ });
932
+ }
933
+ let apple = favicon.apple?.map((entry) => ({
934
+ url: entry.outputPath,
935
+ type: entry.mimeType,
936
+ sizes: assetSizes(entry)
937
+ }));
938
+ return {
939
+ manifest: {
940
+ assets,
941
+ favicon,
942
+ logo,
943
+ metadataIcons: {
944
+ ...icon.length ? { icon } : {},
945
+ ...apple?.length ? { apple } : {}
946
+ }
947
+ },
948
+ warnings
949
+ };
950
+ }
951
+ function faviconsAndLogosManifestModule(manifest) {
952
+ return `export const faviconsAndLogos = ${JSON.stringify(manifest, null, 2)} as const;
953
+
954
+ export type FaviconsAndLogosManifest = typeof faviconsAndLogos;
955
+ export type FaviconAndLogoAssetManifestEntry = FaviconsAndLogosManifest["assets"][number];
956
+ `;
957
+ }
958
+
959
+ // src/lib/compiler/source/assets/media-assets.ts
960
+ import { createHash } from "crypto";
961
+ import { lstat as lstat2, mkdir, readdir, rm, writeFile } from "fs/promises";
962
+ import { dirname as dirname2, join, relative as relative2, resolve as resolve3, sep as sep2 } from "path";
963
+
964
+ // src/lib/compiler/source/assets/image-admission.ts
965
+ import { inflateSync } from "zlib";
966
+ import valueParser from "postcss-value-parser";
967
+ import { SaxesParser } from "saxes";
968
+ import sharp from "sharp";
969
+ var PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
970
+ function pngCrc32(contents) {
971
+ let crc = 4294967295;
972
+ for (let byte of contents) {
973
+ crc ^= byte;
974
+ for (let bit = 0; bit < 8; bit += 1)
975
+ crc = crc >>> 1 ^ (crc & 1 ? 3988292384 : 0);
976
+ }
977
+ return (crc ^ 4294967295) >>> 0;
978
+ }
979
+ function isValidIcoPng(options) {
980
+ let { payload, width, height, directoryBitDepth } = options;
981
+ if (payload.length < 45 || !payload.subarray(0, 8).equals(PNG_SIGNATURE))
982
+ return !1;
983
+ let offset = 8, imageDataSeen = !1, paletteSeen = !1, imageDataEnded = !1, headerSeen = !1, ended = !1, bitDepth = 0, colorType = -1, interlace = -1, imageData = [];
984
+ for (; offset + 12 <= payload.length; ) {
985
+ let length = payload.readUInt32BE(offset), end = offset + 12 + length;
986
+ if (end > payload.length) return !1;
987
+ let type = payload.toString("ascii", offset + 4, offset + 8), data = payload.subarray(offset + 8, offset + 8 + length), checkData = payload.subarray(offset + 4, offset + 8 + length);
988
+ if (pngCrc32(checkData) !== payload.readUInt32BE(offset + 8 + length))
989
+ return !1;
990
+ if (type === "IHDR") {
991
+ if (offset !== 8 || length !== 13 || headerSeen || (headerSeen = !0, data.readUInt32BE(0) !== width || data.readUInt32BE(4) !== height) || (bitDepth = data[8] ?? 0, colorType = data[9] ?? -1, interlace = data[12] ?? -1, !{
992
+ 0: [1, 2, 4, 8, 16],
993
+ 2: [8, 16],
994
+ 3: [1, 2, 4, 8],
995
+ 4: [8, 16],
996
+ 6: [8, 16]
997
+ }[colorType]?.includes(bitDepth) || data[10] !== 0 || data[11] !== 0 || interlace !== 0 && interlace !== 1))
998
+ return !1;
999
+ } else if (type === "PLTE") {
1000
+ if (imageDataSeen || length === 0 || length % 3 !== 0 || length > 768)
1001
+ return !1;
1002
+ paletteSeen = !0;
1003
+ } else if (type === "IDAT") {
1004
+ if (imageDataEnded || colorType === 3 && !paletteSeen) return !1;
1005
+ imageDataSeen = !0, imageData.push(data);
1006
+ } else if (type === "IEND") {
1007
+ if (length !== 0 || !imageDataSeen || end !== payload.length)
1008
+ return !1;
1009
+ ended = !0;
1010
+ break;
1011
+ } else {
1012
+ imageDataSeen && (imageDataEnded = !0);
1013
+ let ancillary = (type.charCodeAt(0) ?? 0) >= 97;
1014
+ if (type === "tRNS" ? imageDataSeen : !ancillary) return !1;
1015
+ }
1016
+ offset = end;
1017
+ }
1018
+ if (!headerSeen || !ended || imageData.length === 0) return !1;
1019
+ let bitsPerPixel = bitDepth * ({
1020
+ 0: 1,
1021
+ 2: 3,
1022
+ 3: 1,
1023
+ 4: 2,
1024
+ 6: 4
1025
+ }[colorType] ?? 0), expectedDirectoryDepth = colorType === 3 ? bitDepth : bitsPerPixel, passRows = (interlace === 0 ? [[0, 0, 1, 1]] : [
1026
+ [0, 0, 8, 8],
1027
+ [4, 0, 8, 8],
1028
+ [0, 4, 4, 8],
1029
+ [2, 0, 4, 4],
1030
+ [0, 2, 2, 4],
1031
+ [1, 0, 2, 2],
1032
+ [0, 1, 1, 2]
1033
+ ]).flatMap(([xStart, yStart, xStep, yStep]) => {
1034
+ let passWidth = width > xStart ? Math.ceil((width - xStart) / xStep) : 0, passHeight = height > yStart ? Math.ceil((height - yStart) / yStep) : 0;
1035
+ if (passWidth === 0 || passHeight === 0) return [];
1036
+ let rowBytes = Math.ceil(passWidth * bitsPerPixel / 8);
1037
+ return Array.from({ length: passHeight }, () => rowBytes);
1038
+ }), expectedInflatedBytes = passRows.reduce(
1039
+ (total, rowBytes) => total + rowBytes + 1,
1040
+ 0
1041
+ );
1042
+ try {
1043
+ let decoded = inflateSync(Buffer.concat(imageData), {
1044
+ maxOutputLength: expectedInflatedBytes
1045
+ });
1046
+ if (decoded.length !== expectedInflatedBytes) return !1;
1047
+ let decodedOffset = 0;
1048
+ for (let rowBytes of passRows) {
1049
+ if ((decoded[decodedOffset] ?? 255) > 4) return !1;
1050
+ decodedOffset += rowBytes + 1;
1051
+ }
1052
+ return expectedDirectoryDepth === directoryBitDepth;
1053
+ } catch {
1054
+ return !1;
1055
+ }
1056
+ }
1057
+ function isValidIcoDib(options) {
1058
+ let { payload, width, height, directoryBitDepth } = options;
1059
+ if (payload.length < 40) return !1;
1060
+ let headerSize = payload.readUInt32LE(0), dibWidth = payload.readInt32LE(4), dibHeight = payload.readInt32LE(8), planes = payload.readUInt16LE(12), bitDepth = payload.readUInt16LE(14), compression = payload.readUInt32LE(16), colorsUsed = payload.readUInt32LE(32);
1061
+ if (headerSize < 40 || headerSize > payload.length || dibWidth !== width || Math.abs(dibHeight) !== height * 2 || planes !== 1 || directoryBitDepth !== bitDepth || ![1, 4, 8, 24, 32].includes(bitDepth) || compression !== 0)
1062
+ return !1;
1063
+ let paletteBytes = (bitDepth <= 8 ? colorsUsed || 1 << bitDepth : 0) * 4, xorBytes = Math.ceil(width * bitDepth / 32) * 4 * height, maskBytes = Math.ceil(width / 32) * 4 * height;
1064
+ return headerSize + paletteBytes + xorBytes + maskBytes <= payload.length;
1065
+ }
1066
+ function hasImageSignature(options) {
1067
+ let { contents, format } = options;
1068
+ if (format === "png")
1069
+ return contents.length >= 8 && contents.readUInt32BE(0) === 2303741511;
1070
+ if (format === "jpeg")
1071
+ return contents.length >= 2 && contents[0] === 255 && contents[1] === 216;
1072
+ if (format === "gif") {
1073
+ let header = contents.subarray(0, 6).toString("ascii");
1074
+ return header === "GIF87a" || header === "GIF89a";
1075
+ }
1076
+ if (format === "webp")
1077
+ return contents.subarray(0, 4).toString("ascii") === "RIFF" && contents.subarray(8, 12).toString("ascii") === "WEBP";
1078
+ if (format === "avif")
1079
+ return contents.subarray(4, 12).toString("ascii").includes("ftyp");
1080
+ if (contents.length < 22 || contents[0] !== 0 || contents[1] !== 0 || contents[2] !== 1 || contents[3] !== 0)
1081
+ return !1;
1082
+ let count = contents.readUInt16LE(4), tableEnd = 6 + count * 16;
1083
+ if (count === 0 || tableEnd > contents.length) return !1;
1084
+ let images = [], totalPixels = 0;
1085
+ for (let index = 0; index < count; index += 1) {
1086
+ let entry = 6 + index * 16, width = contents[entry] || 256, height = contents[entry + 1] || 256, planes = contents.readUInt16LE(entry + 4), bitDepth = contents.readUInt16LE(entry + 6), bytes = contents.readUInt32LE(entry + 8), offset = contents.readUInt32LE(entry + 12);
1087
+ if (bytes === 0 || ![0, 1].includes(planes) || ![1, 4, 8, 24, 32].includes(bitDepth) || offset < tableEnd || offset + bytes > contents.length || (totalPixels += width * height, totalPixels > 4e7)) return !1;
1088
+ images.push({ offset, bytes, width, height, bitDepth });
1089
+ }
1090
+ images.sort((left, right) => left.offset - right.offset);
1091
+ let previousEnd = tableEnd;
1092
+ for (let { offset, bytes, width, height, bitDepth } of images) {
1093
+ if (offset < previousEnd) return !1;
1094
+ previousEnd = offset + bytes;
1095
+ let payload = contents.subarray(offset, offset + bytes);
1096
+ if (payload.subarray(0, 8).equals(PNG_SIGNATURE)) {
1097
+ if (!isValidIcoPng({ payload, width, height, directoryBitDepth: bitDepth }))
1098
+ return !1;
1099
+ continue;
1100
+ }
1101
+ if (!isValidIcoDib({
1102
+ payload,
1103
+ width,
1104
+ height,
1105
+ directoryBitDepth: bitDepth
1106
+ }))
1107
+ return !1;
1108
+ }
1109
+ return !0;
1110
+ }
1111
+ async function readRasterMetadata(options) {
1112
+ let metadata;
1113
+ try {
1114
+ metadata = await sharp(options.contents, { animated: !0 }).metadata();
1115
+ } catch (error) {
1116
+ throw new AppError({
1117
+ code: `${options.errorPrefix}_DIMENSIONS_UNREADABLE`,
1118
+ message: `${options.path} has image metadata that could not be read`,
1119
+ details: {
1120
+ path: options.path,
1121
+ cause: error instanceof Error ? error.message : String(error)
1122
+ }
1123
+ });
1124
+ }
1125
+ let rawWidth = metadata.width, rawHeight = metadata.pageHeight ?? metadata.height;
1126
+ if (!rawWidth || !rawHeight)
1127
+ throw new AppError({
1128
+ code: `${options.errorPrefix}_DIMENSIONS_UNREADABLE`,
1129
+ message: `${options.path} is missing readable raster image dimensions`,
1130
+ details: { path: options.path }
1131
+ });
1132
+ let orientation = metadata.orientation ?? 1, rotated = orientation >= 5 && orientation <= 8, width = rotated ? rawHeight : rawWidth, height = rotated ? rawWidth : rawHeight, { maxRasterMegapixels, maxRasterSidePixels } = options.policy;
1133
+ if (width > maxRasterSidePixels || height > maxRasterSidePixels || width * height > maxRasterMegapixels * 1e6)
1134
+ throw new AppError({
1135
+ code: `${options.errorPrefix}_DIMENSIONS_TOO_LARGE`,
1136
+ message: `${options.path} is ${width}x${height}. Raster images must be no larger than ${maxRasterSidePixels}px on either side and ${maxRasterMegapixels} megapixels.`,
1137
+ details: {
1138
+ path: options.path,
1139
+ width,
1140
+ height,
1141
+ maxSidePixels: maxRasterSidePixels,
1142
+ maxMegapixels: maxRasterMegapixels
1143
+ }
1144
+ });
1145
+ return {
1146
+ width,
1147
+ height,
1148
+ animated: (metadata.pages ?? 1) > 1
1149
+ };
1150
+ }
1151
+ function validateSvg(options) {
1152
+ if (options.contents.byteLength > options.policy.maxSvgBytes)
1153
+ throw new AppError({
1154
+ code: `${options.errorPrefix}_SVG_TOO_LARGE`,
1155
+ message: `${options.path} is larger than the ${Math.round(options.policy.maxSvgBytes / 1024)} KB SVG limit`,
1156
+ details: { path: options.path, bytes: options.contents.byteLength }
1157
+ });
1158
+ let source = options.contents.toString("utf-8");
1159
+ if (!source.toLowerCase().includes("<svg"))
1160
+ throw new AppError({
1161
+ code: `${options.errorPrefix}_SVG_INVALID`,
1162
+ message: `${options.path} is not a valid SVG document`,
1163
+ details: { path: options.path }
1164
+ });
1165
+ let unsafe = () => {
1166
+ throw new AppError({
1167
+ code: `${options.errorPrefix}_SVG_UNSAFE`,
1168
+ message: `${options.path} contains unsafe SVG content`,
1169
+ details: { path: options.path }
1170
+ });
1171
+ }, forbiddenElements = /* @__PURE__ */ new Set([
1172
+ "script",
1173
+ "foreignobject",
1174
+ "iframe",
1175
+ "object",
1176
+ "embed",
1177
+ "audio",
1178
+ "video",
1179
+ "animate",
1180
+ "animatemotion",
1181
+ "animatetransform",
1182
+ "set"
1183
+ ]), decodeCssEscapes = (value) => value.replace(/\\([\da-f]{1,6})\s?|\\(.)/giu, (_match, hex, char) => {
1184
+ if (!hex) return char ?? "";
1185
+ let codePoint = Number.parseInt(hex, 16);
1186
+ return codePoint === 0 || codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343 ? "\uFFFD" : String.fromCodePoint(codePoint);
1187
+ }), hasExternalCssUrl = (value) => {
1188
+ let decoded = decodeCssEscapes(value), external = !1;
1189
+ return valueParser(decoded).walk((node) => {
1190
+ if (node.type !== "function") return;
1191
+ let functionName = node.value.toLowerCase();
1192
+ if (["image-set", "-webkit-image-set", "image"].includes(functionName) && node.nodes.some(
1193
+ (child) => child.type === "string" && child.value.trim() !== "" && !child.value.trim().startsWith("#")
1194
+ ) && (external = !0), functionName !== "url") return;
1195
+ let target = valueParser.stringify(node.nodes).trim().replace(/^(["'])(.*)\1$/su, "$2");
1196
+ target && !target.startsWith("#") && (external = !0);
1197
+ }), external;
1198
+ }, hasExternalCssImport = (value) => {
1199
+ let decoded = decodeCssEscapes(value).replace(/\/\*[\s\S]*?\*\//gu, " ");
1200
+ return /@import(?=\s|["'(])\s*(?:url\(\s*)?(?:"([^"#][^"]*)"|'([^'#][^']*)'|([^\s;)'"#][^\s;)]*))/iu.test(
1201
+ decoded
1202
+ );
1203
+ }, isExternalReference = (value) => {
1204
+ let target = value.trim();
1205
+ return target.length > 0 && !target.startsWith("#");
1206
+ }, rootSeen = !1, styleContents = [], parseFailure, parser2 = new SaxesParser({ xmlns: !0 });
1207
+ parser2.on("doctype", () => unsafe()), parser2.on("processinginstruction", () => unsafe()), parser2.on("error", (error) => {
1208
+ parseFailure ??= error;
1209
+ }), parser2.on("opentag", (tag) => {
1210
+ let localName = tag.local.toLowerCase();
1211
+ styleContents.length > 0 && unsafe(), rootSeen || (rootSeen = !0, localName !== "svg" && unsafe()), forbiddenElements.has(localName) && unsafe(), localName === "style" && styleContents.push("");
1212
+ for (let attribute of Object.values(tag.attributes)) {
1213
+ let name = attribute.local.toLowerCase(), value = attribute.value;
1214
+ name === "base" && attribute.uri === "http://www.w3.org/XML/1998/namespace" && value.trim() !== "" && unsafe(), name.startsWith("on") && unsafe(), (name === "href" || name === "src") && isExternalReference(value) && unsafe(), hasExternalCssUrl(value) && unsafe();
1215
+ }
1216
+ }), parser2.on("closetag", (tag) => {
1217
+ if (tag.local.toLowerCase() === "style") {
1218
+ let contents = styleContents.pop();
1219
+ contents && (hasExternalCssUrl(contents) || hasExternalCssImport(contents)) && unsafe();
1220
+ }
1221
+ });
1222
+ let appendStyleText = (value) => {
1223
+ let last = styleContents.length - 1;
1224
+ last >= 0 && (styleContents[last] = `${styleContents[last]}${value}`);
1225
+ };
1226
+ return parser2.on("text", appendStyleText), parser2.on("cdata", appendStyleText), parser2.write(source).close(), (parseFailure || !rootSeen) && unsafe(), options.contents;
1227
+ }
1228
+
1229
+ // src/lib/compiler/source/assets/media-assets.ts
1230
+ var DEFAULT_MAX_TOTAL_BYTES = 100 * 1024 * 1024, DEFAULT_MAX_FILE_COUNT = 500, MEDIA_IMAGE_ADMISSION_POLICY = {
1231
+ maxRasterMegapixels: 40,
1232
+ maxRasterSidePixels: 8192,
1233
+ maxSvgBytes: MAX_MEDIA_SVG_BYTES
1234
+ }, MEDIA_PUBLIC_PREFIX = SOURCE_ASSET_PREFIX;
1235
+ function mediaAssetBudgets() {
1236
+ return {
1237
+ maxTotalBytes: DEFAULT_MAX_TOTAL_BYTES,
1238
+ maxFileCount: DEFAULT_MAX_FILE_COUNT
1239
+ };
1240
+ }
1241
+ function toPosixPath(path) {
1242
+ return path.split(sep2).join("/");
1243
+ }
1244
+ function hasUnsafeControlCharacters(value) {
1245
+ for (let character of value) {
1246
+ let code = character.codePointAt(0) ?? 0;
1247
+ if (code <= 31 || code >= 127 && code <= 159) return !0;
1248
+ }
1249
+ return !1;
1250
+ }
1251
+ function encodeAssetPath(relativePath) {
1252
+ let segments = relativePath.split("/");
1253
+ if (segments.some(
1254
+ (segment) => segment === "" || segment === "." || segment === ".." || segment.startsWith(".") || segment.includes("\\") || hasUnsafeControlCharacters(segment)
1255
+ ))
1256
+ throw new AppError({
1257
+ code: "FRAMEWORK_MEDIA_PATH_REJECTED",
1258
+ message: `Media asset path "${relativePath}" is not allowed`,
1259
+ details: { path: relativePath }
1260
+ });
1261
+ let encoded;
1262
+ try {
1263
+ encoded = segments.map((segment) => encodeURIComponent(segment)).join("/");
1264
+ } catch {
1265
+ throw new AppError({
1266
+ code: "FRAMEWORK_MEDIA_PATH_REJECTED",
1267
+ message: `Media asset path "${relativePath}" does not produce a safe URL path`,
1268
+ details: { path: relativePath }
1269
+ });
1270
+ }
1271
+ if (encoded.length > 512 || segments.some((segment) => segment.length > 100))
1272
+ throw new AppError({
1273
+ code: "FRAMEWORK_MEDIA_PATH_REJECTED",
1274
+ message: `Media asset path "${relativePath}" exceeds the supported URL length`,
1275
+ details: { path: relativePath }
1276
+ });
1277
+ return encoded;
1278
+ }
1279
+ async function walkAssetFiles(dir, state, root = dir) {
1280
+ let entries = await readdir(dir, { withFileTypes: !0 }).catch((error) => {
1281
+ if (error.code === "ENOENT") return [];
1282
+ throw error;
1283
+ });
1284
+ entries.sort((a, b) => a.name.localeCompare(b.name));
1285
+ for (let entry of entries) {
1286
+ let absolutePath = join(dir, entry.name), relativePath = toPosixPath(relative2(root, absolutePath));
1287
+ if (isExcludedSourcePath(`assets/${relativePath}`)) continue;
1288
+ if (entry.name.startsWith(".")) {
1289
+ state.warnings.push(ignoredMediaPathWarning(`assets/${relativePath}`));
1290
+ continue;
1291
+ }
1292
+ let info = await lstat2(absolutePath);
1293
+ if (info.isSymbolicLink())
1294
+ throw new AppError({
1295
+ code: "FRAMEWORK_MEDIA_SYMLINK_REJECTED",
1296
+ message: `Media asset "${relativePath}" is a symlink. Symlinks are not supported in publish.os/assets.`,
1297
+ details: { path: absolutePath }
1298
+ });
1299
+ if (info.isDirectory()) {
1300
+ await walkAssetFiles(absolutePath, state, root);
1301
+ continue;
1302
+ }
1303
+ if (info.isFile()) {
1304
+ let ignoredDocument = ignoredMediaDocumentWarning(
1305
+ `assets/${relativePath}`
1306
+ );
1307
+ if (ignoredDocument) {
1308
+ encodeAssetPath(relativePath), state.warnings.push(ignoredDocument);
1309
+ continue;
1310
+ }
1311
+ if (state.files.push(relativePath), state.files.length > state.maxFileCount)
1312
+ throw new AppError({
1313
+ code: "FRAMEWORK_MEDIA_FILE_COUNT_EXCEEDED",
1314
+ message: `publish.os/assets contains more than ${state.maxFileCount} files, exceeding the limit of ${state.maxFileCount}`,
1315
+ details: { count: state.files.length, limit: state.maxFileCount }
1316
+ });
1317
+ }
1318
+ }
1319
+ }
1320
+ function hash(contents) {
1321
+ return `sha256-${createHash("sha256").update(contents).digest("hex").slice(0, 16)}`;
1322
+ }
1323
+ async function classifyAsset(relativePath, contents) {
1324
+ let ext = relativePath.split(".").at(-1)?.toLowerCase() ?? "";
1325
+ if (ext === "png" && hasImageSignature({ contents, format: "png" })) {
1326
+ let metadata = await readRasterMetadata({
1327
+ contents,
1328
+ errorPrefix: "FRAMEWORK_MEDIA",
1329
+ path: relativePath,
1330
+ policy: MEDIA_IMAGE_ADMISSION_POLICY
1331
+ });
1332
+ return {
1333
+ contents,
1334
+ mediaType: "image",
1335
+ mimeType: "image/png",
1336
+ outputContents: contents,
1337
+ ...metadata
1338
+ };
1339
+ }
1340
+ if (ext === "ico" && hasImageSignature({ contents, format: "ico" }))
1341
+ return {
1342
+ contents,
1343
+ mediaType: "image",
1344
+ mimeType: "image/x-icon",
1345
+ outputContents: contents
1346
+ };
1347
+ if (ext === "ico")
1348
+ throw new AppError({
1349
+ code: "FRAMEWORK_MEDIA_ICO_INVALID",
1350
+ message: `${relativePath} is not a valid ICO image`,
1351
+ details: { path: relativePath }
1352
+ });
1353
+ if ((ext === "jpg" || ext === "jpeg") && hasImageSignature({ contents, format: "jpeg" })) {
1354
+ let metadata = await readRasterMetadata({
1355
+ contents,
1356
+ errorPrefix: "FRAMEWORK_MEDIA",
1357
+ path: relativePath,
1358
+ policy: MEDIA_IMAGE_ADMISSION_POLICY
1359
+ });
1360
+ return {
1361
+ contents,
1362
+ mediaType: "image",
1363
+ mimeType: "image/jpeg",
1364
+ outputContents: contents,
1365
+ ...metadata
1366
+ };
1367
+ }
1368
+ if (ext === "gif" && hasImageSignature({ contents, format: "gif" })) {
1369
+ let metadata = await readRasterMetadata({
1370
+ contents,
1371
+ errorPrefix: "FRAMEWORK_MEDIA",
1372
+ path: relativePath,
1373
+ policy: MEDIA_IMAGE_ADMISSION_POLICY
1374
+ });
1375
+ return {
1376
+ contents,
1377
+ mediaType: "image",
1378
+ mimeType: "image/gif",
1379
+ outputContents: contents,
1380
+ ...metadata
1381
+ };
1382
+ }
1383
+ if (ext === "webp" && hasImageSignature({ contents, format: "webp" })) {
1384
+ let metadata = await readRasterMetadata({
1385
+ contents,
1386
+ errorPrefix: "FRAMEWORK_MEDIA",
1387
+ path: relativePath,
1388
+ policy: MEDIA_IMAGE_ADMISSION_POLICY
1389
+ });
1390
+ return {
1391
+ contents,
1392
+ mediaType: "image",
1393
+ mimeType: "image/webp",
1394
+ outputContents: contents,
1395
+ ...metadata
1396
+ };
1397
+ }
1398
+ if (ext === "avif" && hasImageSignature({ contents, format: "avif" })) {
1399
+ let metadata = await readRasterMetadata({
1400
+ contents,
1401
+ errorPrefix: "FRAMEWORK_MEDIA",
1402
+ path: relativePath,
1403
+ policy: MEDIA_IMAGE_ADMISSION_POLICY
1404
+ });
1405
+ return {
1406
+ contents,
1407
+ mediaType: "image",
1408
+ mimeType: "image/avif",
1409
+ outputContents: contents,
1410
+ ...metadata
1411
+ };
1412
+ }
1413
+ if (ext === "svg") {
1414
+ let outputContents = validateSvg({
1415
+ contents,
1416
+ errorPrefix: "FRAMEWORK_MEDIA",
1417
+ path: relativePath,
1418
+ policy: MEDIA_IMAGE_ADMISSION_POLICY
1419
+ });
1420
+ return {
1421
+ contents,
1422
+ mediaType: "image",
1423
+ mimeType: "image/svg+xml",
1424
+ outputContents
1425
+ };
1426
+ }
1427
+ if (ext === "mp4" && contents.subarray(4, 8).toString("ascii") === "ftyp")
1428
+ return {
1429
+ contents,
1430
+ mediaType: "video",
1431
+ mimeType: "video/mp4",
1432
+ outputContents: contents
1433
+ };
1434
+ if (ext === "webm" && contents[0] === 26 && contents[1] === 69 && contents[2] === 223 && contents[3] === 163)
1435
+ return {
1436
+ contents,
1437
+ mediaType: "video",
1438
+ mimeType: "video/webm",
1439
+ outputContents: contents
1440
+ };
1441
+ if (ext === "json")
1442
+ return JSON.parse(contents.toString("utf-8")), {
1443
+ contents,
1444
+ mediaType: "file",
1445
+ mimeType: "application/json",
1446
+ outputContents: contents
1447
+ };
1448
+ throw new AppError({
1449
+ code: "FRAMEWORK_MEDIA_TYPE_REJECTED",
1450
+ message: `${relativePath} is not an allowed media type`,
1451
+ details: { path: relativePath }
1452
+ });
1453
+ }
1454
+ async function admitThemeImageResource(options) {
1455
+ let asset = await classifyAsset(options.relativePath, options.contents);
1456
+ if (asset.mediaType !== "image")
1457
+ throw new AppError({
1458
+ code: "FRAMEWORK_MEDIA_TYPE_REJECTED",
1459
+ message: `${options.relativePath} is not an allowed image type`,
1460
+ details: { path: options.relativePath }
1461
+ });
1462
+ return {
1463
+ contents: asset.outputContents,
1464
+ mimeType: asset.mimeType,
1465
+ width: asset.width,
1466
+ height: asset.height
1467
+ };
1468
+ }
1469
+ function assertAssetSize(options) {
1470
+ if (options.asset.contents.byteLength > options.limit)
1471
+ throw mediaFileTooLarge({
1472
+ relativePath: options.relativePath,
1473
+ bytes: options.asset.contents.byteLength,
1474
+ limit: options.limit
1475
+ });
1476
+ }
1477
+ function isOptimizableLocalImage(asset) {
1478
+ return asset.mediaType === "image" && !!(asset.width && asset.height) && !asset.animated && asset.mimeType !== "image/svg+xml" && asset.mimeType !== "image/gif";
1479
+ }
1480
+ async function buildMediaAssets(options) {
1481
+ let assetsDir = resolve3(options.publishOsDir, "assets"), { maxFileCount, maxTotalBytes } = mediaAssetBudgets(), walkState = { files: [], warnings: [], maxFileCount };
1482
+ await walkAssetFiles(assetsDir, walkState);
1483
+ let files = walkState.files.sort(), warnings = walkState.warnings, manifest = {
1484
+ assets: {},
1485
+ totals: {
1486
+ bytes: 0,
1487
+ count: 0,
1488
+ images: 0,
1489
+ videos: 0,
1490
+ documents: 0,
1491
+ files: 0
1492
+ }
1493
+ }, outputs = [], seenPublicPaths = /* @__PURE__ */ new Map();
1494
+ for (let file of files) {
1495
+ let sourcePath = resolve3(assetsDir, file);
1496
+ if (!isSameOrDescendant(assetsDir, sourcePath))
1497
+ throw new AppError({
1498
+ code: "FRAMEWORK_MEDIA_PATH_REJECTED",
1499
+ message: `${file} escapes publish.os/assets`,
1500
+ details: { path: file }
1501
+ });
1502
+ let normalized = encodeAssetPath(file), sourcePublicPath = `/assets/${normalized}`, publicPath = `${MEDIA_PUBLIC_PREFIX}/${normalized}`, existing = seenPublicPaths.get(publicPath);
1503
+ if (existing)
1504
+ throw new AppError({
1505
+ code: "FRAMEWORK_MEDIA_PATH_COLLISION",
1506
+ message: `${file} and ${existing} both resolve to ${publicPath}`,
1507
+ details: { path: file, existing, publicPath }
1508
+ });
1509
+ seenPublicPaths.set(publicPath, file);
1510
+ let byteLimit = mediaFileByteLimit(file), contents = await readBoundedMediaFile({
1511
+ path: sourcePath,
1512
+ relativePath: file,
1513
+ limit: byteLimit
1514
+ }), asset = await classifyAsset(file, contents);
1515
+ assertAssetSize({ asset, relativePath: file, limit: byteLimit });
1516
+ let totalBytes = manifest.totals.bytes + asset.outputContents.byteLength;
1517
+ if (totalBytes > maxTotalBytes)
1518
+ throw new AppError({
1519
+ code: "FRAMEWORK_MEDIA_TOTAL_TOO_LARGE",
1520
+ message: `publish.os/assets is ${totalBytes} bytes, exceeding the limit of ${maxTotalBytes}`,
1521
+ details: { bytes: totalBytes, limit: maxTotalBytes }
1522
+ });
1523
+ let contentHash = hash(asset.outputContents), outputPath = publicPath, optimized = isOptimizableLocalImage(asset), aspect = asset.width && asset.height ? asset.width / asset.height : void 0;
1524
+ manifest.assets[sourcePublicPath] = {
1525
+ sourcePath: `publish.os/assets/${file}`,
1526
+ outputPath,
1527
+ contentHash,
1528
+ mediaType: asset.mediaType,
1529
+ mimeType: asset.mimeType,
1530
+ byteSize: asset.outputContents.byteLength,
1531
+ intrinsicWidth: asset.width,
1532
+ intrinsicHeight: asset.height,
1533
+ width: asset.width,
1534
+ height: asset.height,
1535
+ aspect,
1536
+ animated: asset.animated,
1537
+ optimized,
1538
+ optimizationReason: optimized ? void 0 : asset.mediaType === "image" ? asset.mimeType === "image/svg+xml" ? "svg" : asset.animated ? "animated" : asset.mimeType === "image/gif" ? "gif" : "dimensions-unavailable" : void 0
1539
+ }, manifest.totals.bytes += asset.outputContents.byteLength, manifest.totals.count += 1, asset.mediaType === "image" ? manifest.totals.images += 1 : asset.mediaType === "video" ? manifest.totals.videos += 1 : asset.mediaType === "document" ? manifest.totals.documents += 1 : manifest.totals.files += 1, outputs.push({ contents: asset.outputContents, outputPath: publicPath });
1540
+ }
1541
+ return { manifest, outputs, warnings };
1542
+ }
1543
+ async function writeMediaOutputs(options) {
1544
+ await rm(resolve3(options.outputDir, "public", "_publishos", "assets"), {
1545
+ force: !0,
1546
+ recursive: !0
1547
+ }), await rm(resolve3(options.outputDir, "public", "_publishos", "media"), {
1548
+ force: !0,
1549
+ recursive: !0
1550
+ }), await rm(resolve3(options.outputDir, "public", "assets"), {
1551
+ force: !0,
1552
+ recursive: !0
1553
+ });
1554
+ for (let output of options.media.outputs) {
1555
+ let segments = output.outputPath.replace(/^\/+/, "").split("/").map(decodeURIComponent);
1556
+ if (segments.some(
1557
+ (segment) => !segment || segment === "." || segment === ".." || segment.includes("/") || segment.includes("\\") || hasUnsafeControlCharacters(segment)
1558
+ ))
1559
+ throw new AppError({
1560
+ code: "FRAMEWORK_MEDIA_PATH_REJECTED",
1561
+ message: `Media output path "${output.outputPath}" is not safe`,
1562
+ details: { path: output.outputPath }
1563
+ });
1564
+ let relativeOutput = segments.join(sep2), dest = resolve3(options.outputDir, "public", relativeOutput);
1565
+ await mkdir(dirname2(dest), { recursive: !0 }), await writeFile(dest, output.contents);
1566
+ }
1567
+ }
1568
+ function mediaManifestModule(manifest) {
1569
+ return `export const mediaManifest = ${JSON.stringify(manifest, null, 2)} as const;
1570
+
1571
+ export type MediaManifest = typeof mediaManifest;
1572
+ export type MediaAssetManifestEntry = MediaManifest["assets"][keyof MediaManifest["assets"]];
1573
+ `;
1574
+ }
1575
+
1576
+ // src/lib/compiler/source/routing/slug-path.ts
1577
+ var SLUG_SEGMENT_RE = /^[\p{L}\p{N}][\p{L}\p{M}\p{N}]*(?:[.-][\p{L}\p{N}][\p{L}\p{M}\p{N}]*)*$/u;
1578
+ function issue(code, message, details) {
1579
+ return details ? { code, message, details } : { code, message };
1580
+ }
1581
+ function isWhitespace(code) {
1582
+ return code === 32 || code === 9 || code === 10 || code === 11 || code === 12 || code === 13 || code === 160;
1583
+ }
1584
+ function isUnsafeInvisible(code) {
1585
+ return code <= 31 || code >= 127 && code <= 159 || code >= 8203 && code <= 8207 || code >= 8232 && code <= 8239 || code >= 8288 && code <= 8303 || code === 65279;
1586
+ }
1587
+ function hasPercentEscape(value) {
1588
+ return /%[0-9a-fA-F]{2}/.test(value);
1589
+ }
1590
+ function appendNormalizedChar(output, char, pendingSeparator) {
1591
+ pendingSeparator && output.length > 0 && output.push(pendingSeparator), output.push(char);
1592
+ }
1593
+ function queueSeparator(current, next) {
1594
+ return current === "." || next === "." ? "." : "-";
1595
+ }
1596
+ function normalizeSegmentValue(input) {
1597
+ let output = [], pendingSeparator, sanitized = !1;
1598
+ for (let char of input.normalize("NFC").toLowerCase().normalize("NFC")) {
1599
+ let code = char.codePointAt(0) ?? 0;
1600
+ if (/^[\p{L}\p{M}\p{N}]$/u.test(char)) {
1601
+ pendingSeparator = appendNormalizedChar(output, char, pendingSeparator);
1602
+ continue;
1603
+ }
1604
+ if (char === "." || char === "-") {
1605
+ pendingSeparator = queueSeparator(pendingSeparator, char);
1606
+ continue;
1607
+ }
1608
+ if (isWhitespace(code) || char === "_" || isUnsafeInvisible(code)) {
1609
+ pendingSeparator = queueSeparator(pendingSeparator, "-"), sanitized = !0;
1610
+ continue;
1611
+ }
1612
+ pendingSeparator = queueSeparator(pendingSeparator, "-"), sanitized = !0;
1613
+ }
1614
+ return { value: output.join(""), sanitized };
1615
+ }
1616
+ function validateSegment(slug, options) {
1617
+ return slug ? slug.length > options.maxSegmentLength ? {
1618
+ code: "SLUG_SEGMENT_TOO_LONG",
1619
+ error: `URL path must be ${options.maxSegmentLength} characters or less`,
1620
+ isValid: !1
1621
+ } : slug !== slug.toLowerCase() ? {
1622
+ code: "SLUG_UPPERCASE_INVALID",
1623
+ error: "URL path must be lowercase",
1624
+ isValid: !1
1625
+ } : SLUG_SEGMENT_RE.test(slug) ? { isValid: !0 } : {
1626
+ code: "SLUG_PATTERN_INVALID",
1627
+ error: 'URL path can only include lowercase letters, marks, numbers, and single "." or "-" separators',
1628
+ isValid: !1
1629
+ } : {
1630
+ code: "SLUG_EMPTY",
1631
+ error: "URL path is required",
1632
+ isValid: !1
1633
+ };
1634
+ }
1635
+ function normalizeSlugSegmentInternal(input, options = {}) {
1636
+ let maxSegmentLength = options.maxSegmentLength ?? 100, warnings = [], errors = [], trimmed = input.normalize("NFC").trim(), rawLower = trimmed.toLowerCase();
1637
+ hasPercentEscape(trimmed) && errors.push(
1638
+ issue(
1639
+ "PATH_PERCENT_ESCAPE_INVALID",
1640
+ "Path input must not contain percent escapes",
1641
+ {
1642
+ value: input
1643
+ }
1644
+ )
1645
+ ), (rawLower === "." || rawLower === "..") && errors.push(
1646
+ issue(
1647
+ "PATH_DOT_SEGMENT_INVALID",
1648
+ "Path segments must not be dot traversal segments",
1649
+ {
1650
+ segment: input
1651
+ }
1652
+ )
1653
+ );
1654
+ let normalized = normalizeSegmentValue(trimmed), value = normalized.value;
1655
+ value.length > maxSegmentLength && errors.push(
1656
+ issue(
1657
+ "SLUG_SEGMENT_TOO_LONG",
1658
+ `Path segments must be ${maxSegmentLength} characters or less`,
1659
+ {
1660
+ max: maxSegmentLength,
1661
+ segment: input
1662
+ }
1663
+ )
1664
+ ), (normalized.sanitized || value !== trimmed) && warnings.push(
1665
+ issue("PATH_SEGMENT_NORMALIZED", "Path segment was normalized", {
1666
+ from: input,
1667
+ to: value
1668
+ })
1669
+ ), !value && options.allowEmpty !== !0 && errors.push(
1670
+ issue("PATH_SEGMENT_EMPTY", "Path segment normalized to an empty value", {
1671
+ segment: input
1672
+ })
1673
+ );
1674
+ let validation = value ? validateSegment(value, {
1675
+ maxSegmentLength
1676
+ }) : { isValid: !0 };
1677
+ return validation.isValid || errors.push(issue(validation.code, validation.error, { segment: input })), {
1678
+ changed: value !== input,
1679
+ errors,
1680
+ value,
1681
+ warnings
1682
+ };
1683
+ }
1684
+ function normalizePathParts(input, options = {}) {
1685
+ let warnings = [], errors = [], maxPathLength = options.maxPathLength ?? 512, trimmed = input.normalize("NFC").trim();
1686
+ (/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(trimmed) || /^\/\/[^/]/.test(trimmed)) && errors.push(
1687
+ issue(
1688
+ "PATH_PROTOCOL_INVALID",
1689
+ "Path input must not be a URL or protocol reference",
1690
+ {
1691
+ value: input
1692
+ }
1693
+ )
1694
+ ), /[?#]/.test(trimmed) && errors.push(
1695
+ issue(
1696
+ "PATH_QUERY_HASH_INVALID",
1697
+ "Path input must not include a query string or hash",
1698
+ {
1699
+ value: input
1700
+ }
1701
+ )
1702
+ ), trimmed.includes("\\") && warnings.push(
1703
+ issue(
1704
+ "PATH_BACKSLASH_NORMALIZED",
1705
+ "Backslashes were normalized to slashes",
1706
+ {
1707
+ value: input
1708
+ }
1709
+ )
1710
+ );
1711
+ let rawSegments = trimmed.replace(/\\/g, "/").split("/"), segments = [];
1712
+ for (let rawSegment of rawSegments) {
1713
+ if (!rawSegment) continue;
1714
+ let segment = normalizeSlugSegmentInternal(rawSegment, options);
1715
+ warnings.push(...segment.warnings), errors.push(...segment.errors), segment.value && segments.push(segment.value);
1716
+ }
1717
+ segments.length === 0 && options.allowEmpty !== !0 && errors.push(
1718
+ issue("PATH_EMPTY", "Path input normalized to an empty value", {
1719
+ value: input
1720
+ })
1721
+ );
1722
+ let value = segments.join("/");
1723
+ return value.length > maxPathLength && errors.push(
1724
+ issue(
1725
+ "SLUG_PATH_TOO_LONG",
1726
+ `Path must be ${maxPathLength} characters or less`,
1727
+ {
1728
+ max: maxPathLength,
1729
+ value: input
1730
+ }
1731
+ )
1732
+ ), encodeURI(value).length > 2044 && errors.push(
1733
+ issue(
1734
+ "PATH_ENCODED_TOO_LONG",
1735
+ "Encoded path must leave room for the Markdown route within 2048 characters.",
1736
+ { value: input }
1737
+ )
1738
+ ), { errors, value, warnings };
1739
+ }
1740
+ function normalizeSlugPath(input, options = {}) {
1741
+ let normalized = normalizePathParts(input, options);
1742
+ return {
1743
+ ...normalized,
1744
+ changed: normalized.value !== input
1745
+ };
1746
+ }
1747
+ function normalizeUrlPath(input, options = {}) {
1748
+ let normalized = normalizePathParts(input, options), value = normalized.value ? `/${normalized.value}` : "/";
1749
+ return {
1750
+ ...normalized,
1751
+ value,
1752
+ changed: value !== input
1753
+ };
1754
+ }
1755
+ function joinUrlPath(parentPath, childPath) {
1756
+ if (childPath.startsWith("/"))
1757
+ return normalizeUrlPath(childPath).value;
1758
+ let parent = parentPath === "/" ? "" : parentPath.replace(/\/+$/, "");
1759
+ return normalizeUrlPath(`${parent}/${childPath}`).value;
1760
+ }
1761
+
1762
+ // src/lib/runtime/metadata/authored-date.ts
1763
+ function authoredDate(value) {
1764
+ if (typeof value != "string" || !/^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2}))?$/.test(
1765
+ value
1766
+ ))
1767
+ return;
1768
+ let day = value.slice(0, 10), midnight = /* @__PURE__ */ new Date(`${day}T00:00:00.000Z`);
1769
+ if (!(!Number.isFinite(midnight.getTime()) || midnight.toISOString().slice(0, 10) !== day))
1770
+ return Number.isFinite(Date.parse(value)) ? value : void 0;
1771
+ }
1772
+
1773
+ // src/lib/assets/map-source-asset-url.ts
1774
+ var SOURCE_ASSET_PATH = "/assets/";
1775
+ function hasUnsafeControlCharacters2(value) {
1776
+ for (let character of value) {
1777
+ let code = character.codePointAt(0) ?? 0;
1778
+ if (code <= 31 || code >= 127 && code <= 159) return !0;
1779
+ }
1780
+ return !1;
1781
+ }
1782
+ function assertSafeAssetPath(path) {
1783
+ if (path.includes("\\") || hasUnsafeControlCharacters2(path))
1784
+ throw new TypeError("Local asset URLs must use safe path segments.");
1785
+ for (let segment of path.split("/")) {
1786
+ if (!segment)
1787
+ throw new TypeError("Local asset URLs must use safe path segments.");
1788
+ let decoded;
1789
+ try {
1790
+ decoded = decodeURIComponent(segment);
1791
+ } catch {
1792
+ throw new TypeError("Local asset URLs must use valid URL encoding.");
1793
+ }
1794
+ if (decoded === "." || decoded === ".." || decoded.includes("/") || decoded.includes("\\") || hasUnsafeControlCharacters2(decoded))
1795
+ throw new TypeError("Local asset URLs must use safe path segments.");
1796
+ }
1797
+ }
1798
+ function mapSourceAssetUrl(value) {
1799
+ if (typeof value != "string" || !value.startsWith(SOURCE_ASSET_PATH))
1800
+ return value;
1801
+ let suffixIndex = value.search(/[?#]/u), pathname = suffixIndex < 0 ? value : value.slice(0, suffixIndex), suffix = suffixIndex < 0 ? "" : value.slice(suffixIndex), path = pathname.slice(SOURCE_ASSET_PATH.length);
1802
+ return assertSafeAssetPath(path), `${SOURCE_ASSET_PREFIX}/${path}${suffix}`;
1803
+ }
1804
+
1805
+ // src/lib/compiler/markdown/convert-mdx-to-markdown.ts
1806
+ import remarkGfm from "remark-gfm";
1807
+ import remarkMdx2 from "remark-mdx";
1808
+ import remarkParse2 from "remark-parse";
1809
+ import remarkStringify from "remark-stringify";
1810
+ import { unified as unified2 } from "unified";
1811
+
1812
+ // src/lib/compiler/markdown/utils.ts
1813
+ function text(value) {
1814
+ return { type: "text", value };
1815
+ }
1816
+ function paragraph(children) {
1817
+ if (children.length !== 0)
1818
+ return { type: "paragraph", children };
1819
+ }
1820
+ function paragraphBlock(children) {
1821
+ let node = paragraph(children);
1822
+ return node ? [node] : [];
1823
+ }
1824
+ function strongLabel(value) {
1825
+ return { type: "strong", children: [text(value)] };
1826
+ }
1827
+ function inlineCode(value) {
1828
+ return { type: "inlineCode", value };
1829
+ }
1830
+ function normalizeComponentName(name) {
1831
+ return (name ?? "").trim().toLowerCase();
1832
+ }
1833
+ function addDiagnostic(context, diagnostic) {
1834
+ context.collectDiagnostics && context.diagnostics.push(diagnostic);
1835
+ }
1836
+ function getAttribute(node, name, context) {
1837
+ let attribute = node.attributes?.find(
1838
+ (candidate) => candidate.name === name
1839
+ );
1840
+ if (attribute) {
1841
+ if (attribute.value === null || attribute.value === void 0) return "true";
1842
+ if (typeof attribute.value == "string") return attribute.value;
1843
+ if (attribute.value.type === "mdxJsxAttributeValueExpression")
1844
+ return decodeExpressionValue(attribute.value.value, name, context);
1845
+ addDiagnostic(context, {
1846
+ code: "mdx-invalid-attribute",
1847
+ componentName: node.name ?? void 0,
1848
+ message: `Unsupported MDX attribute value for "${name}".`
1849
+ });
1850
+ }
1851
+ }
1852
+ function firstAttribute(node, names, context) {
1853
+ for (let name of names) {
1854
+ let value = getAttribute(node, name, context);
1855
+ if (value?.trim()) return value.trim();
1856
+ }
1857
+ }
1858
+ function decodeExpressionValue(value, attributeName, context) {
1859
+ let trimmed = value.trim();
1860
+ if (trimmed) {
1861
+ if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'"))
1862
+ try {
1863
+ return JSON.parse(
1864
+ trimmed.startsWith("'") ? `"${trimmed.slice(1, -1).replace(/"/g, '\\"')}"` : trimmed
1865
+ );
1866
+ } catch {
1867
+ return trimmed.slice(1, -1);
1868
+ }
1869
+ return trimmed.startsWith("`") && trimmed.endsWith("`") ? trimmed.slice(1, -1).replace(/\\`/g, "`").replace(/\\n/g, `
1870
+ `).replace(/\\t/g, " ") : (addDiagnostic(context, {
1871
+ code: "mdx-invalid-attribute",
1872
+ message: `MDX expression attribute "${attributeName}" was converted to literal text.`
1873
+ }), trimmed);
1874
+ }
1875
+ }
1876
+ function extractText(nodes) {
1877
+ return nodes.map((node) => {
1878
+ if (node.type === "break") return `
1879
+ `;
1880
+ if (node.type === "html" || node.type === "yaml") return "";
1881
+ if ("value" in node && typeof node.value == "string")
1882
+ return node.type === "code" ? `${node.value}
1883
+ ` : node.value;
1884
+ if ("alt" in node && typeof node.alt == "string") return node.alt;
1885
+ if ("children" in node && Array.isArray(node.children)) {
1886
+ let value = extractText(node.children);
1887
+ return [
1888
+ "emphasis",
1889
+ "strong",
1890
+ "delete",
1891
+ "link",
1892
+ "linkReference"
1893
+ ].includes(node.type) ? value : `${value}
1894
+ `;
1895
+ }
1896
+ return "";
1897
+ }).join("").trim();
1898
+ }
1899
+ function asPhrasing(nodes) {
1900
+ return nodes.flatMap((node) => {
1901
+ if (node.type === "paragraph") return node.children;
1902
+ if (node.type === "text" || node.type === "emphasis" || node.type === "strong" || node.type === "delete" || node.type === "inlineCode" || node.type === "break" || node.type === "link" || node.type === "image" || node.type === "html" || node.type === "footnoteReference")
1903
+ return [node];
1904
+ let label = extractText([node]);
1905
+ return label ? [text(label)] : [];
1906
+ });
1907
+ }
1908
+ function isBlockNode(node) {
1909
+ return node.type === "paragraph" || node.type === "heading" || node.type === "thematicBreak" || node.type === "blockquote" || node.type === "list" || node.type === "code" || node.type === "html" || node.type === "yaml" || node.type === "definition" || node.type === "footnoteDefinition" || node.type === "table";
1910
+ }
1911
+ function asBlocks(nodes) {
1912
+ let blocks = [], pendingPhrasing = [];
1913
+ for (let node of nodes)
1914
+ if (isBlockNode(node)) {
1915
+ let pendingParagraph2 = paragraph(pendingPhrasing);
1916
+ pendingParagraph2 && blocks.push(pendingParagraph2), pendingPhrasing = [], blocks.push(node);
1917
+ } else
1918
+ pendingPhrasing.push(node);
1919
+ let pendingParagraph = paragraph(pendingPhrasing);
1920
+ return pendingParagraph && blocks.push(pendingParagraph), blocks;
1921
+ }
1922
+ function handlerDiagnostic(node, context) {
1923
+ addDiagnostic(context, {
1924
+ code: "mdx-component-converted",
1925
+ componentName: node.name ?? void 0,
1926
+ message: `Converted MDX component "${node.name ?? "unknown"}" to Markdown.`
1927
+ });
1928
+ }
1929
+
1930
+ // src/lib/compiler/markdown/handlers/callout.ts
1931
+ function calloutHandler(node, context, kind) {
1932
+ handlerDiagnostic(node, context);
1933
+ let title = firstAttribute(node, ["title", "label", "type"], context);
1934
+ if (kind === "inline") {
1935
+ let children2 = context.transformChildrenAsPhrasing(node, context);
1936
+ return [
1937
+ ...title ? [strongLabel(`${title}:`), text(" ")] : [],
1938
+ ...children2
1939
+ ];
1940
+ }
1941
+ let children = [];
1942
+ return title && children.push({ type: "paragraph", children: [strongLabel(title)] }), children.push(
1943
+ ...context.transformChildrenAsBlocks(node, context)
1944
+ ), children.length > 0 ? [{ type: "blockquote", children }] : [];
1945
+ }
1946
+
1947
+ // src/lib/compiler/markdown/handlers/code-block.ts
1948
+ function codeBlockHandler(node, context) {
1949
+ handlerDiagnostic(node, context);
1950
+ let code = firstAttribute(node, ["code", "value"], context), language = firstAttribute(node, ["language", "lang"], context), title = firstAttribute(node, ["title"], context);
1951
+ return code !== void 0 ? [{
1952
+ type: "code",
1953
+ lang: language,
1954
+ meta: title === void 0 ? void 0 : `title="${title.replaceAll('"', "&quot;")}"`,
1955
+ value: code
1956
+ }] : context.transformChildrenAsBlocks(node, context);
1957
+ }
1958
+ function tabHandler(node, context) {
1959
+ handlerDiagnostic(node, context);
1960
+ let label = firstAttribute(
1961
+ node,
1962
+ ["title", "label", "value", "name"],
1963
+ context
1964
+ ), children = context.transformChildrenAsBlocks(node, context);
1965
+ return label ? [
1966
+ { type: "paragraph", children: [strongLabel(`Tab: ${label}`)] },
1967
+ ...children
1968
+ ] : children;
1969
+ }
1970
+
1971
+ // src/lib/compiler/markdown/handlers/html.ts
1972
+ function inlineHtmlHandler(node, context) {
1973
+ handlerDiagnostic(node, context);
1974
+ let children = context.transformChildrenAsPhrasing(node, context);
1975
+ switch (normalizeComponentName(node.name)) {
1976
+ case "strong":
1977
+ case "b":
1978
+ return [{ type: "strong", children }];
1979
+ case "em":
1980
+ case "i":
1981
+ return [{ type: "emphasis", children }];
1982
+ case "code":
1983
+ return [{ type: "inlineCode", value: extractText(children) }];
1984
+ case "br":
1985
+ return [{ type: "break" }];
1986
+ default:
1987
+ return children;
1988
+ }
1989
+ }
1990
+ function blockquoteHtmlHandler(node, context) {
1991
+ return handlerDiagnostic(node, context), [
1992
+ {
1993
+ type: "blockquote",
1994
+ children: node.type === "mdxJsxTextElement" ? paragraphBlock(context.transformChildrenAsPhrasing(node, context)) : context.transformChildrenAsBlocks(node, context)
1995
+ }
1996
+ ];
1997
+ }
1998
+ function paragraphHtmlHandler(node, context) {
1999
+ return handlerDiagnostic(node, context), paragraphBlock(context.transformChildrenAsPhrasing(node, context));
2000
+ }
2001
+ function preformattedText(node, context) {
2002
+ if (node.type === "mdxTextExpression" || node.type === "mdxFlowExpression") {
2003
+ let statement = node.data?.estree?.body?.[0], expression = statement?.type === "ExpressionStatement" ? statement.expression : void 0;
2004
+ return expression?.type === "Literal" && typeof expression.value == "string" ? expression.value : expression?.type === "TemplateLiteral" && expression.expressions?.length === 0 ? expression.quasis?.[0]?.value.cooked ?? "" : (addDiagnostic(context, {
2005
+ code: "mdx-expression-dropped",
2006
+ message: "Dropped non-literal MDX expression from preformatted Markdown output."
2007
+ }), "");
2008
+ }
2009
+ return typeof node.value == "string" ? node.value : (node.children ?? []).map((child, index) => (index > 0 && child.type === "paragraph" ? `
2010
+
2011
+ ` : "") + preformattedText(child, context)).join("");
2012
+ }
2013
+ function preHtmlHandler(node, context) {
2014
+ handlerDiagnostic(node, context);
2015
+ let code = node.children?.find((child) => child.name === "code");
2016
+ return [
2017
+ { type: "code", lang: code ? firstAttribute(code, ["className", "class"], context)?.match(
2018
+ /(?:^|\s)language-([^\s]+)/
2019
+ )?.[1] : void 0, value: preformattedText(node, context) }
2020
+ ];
2021
+ }
2022
+
2023
+ // src/lib/compiler/markdown/handlers/inline.ts
2024
+ function iconHandler(node, context) {
2025
+ handlerDiagnostic(node, context);
2026
+ let label = firstAttribute(
2027
+ node,
2028
+ ["aria-label", "label", "title", "alt"],
2029
+ context
2030
+ );
2031
+ return label ? [text(label)] : [];
2032
+ }
2033
+ function linkHandler(node, context) {
2034
+ let href = firstAttribute(node, ["href", "to", "url"], context);
2035
+ if (!href) return context.transformChildrenAsPhrasing(node, context);
2036
+ handlerDiagnostic(node, context);
2037
+ let children = context.transformChildrenAsPhrasing(node, context);
2038
+ return [{
2039
+ type: "link",
2040
+ url: context.resolveMediaUrl(href),
2041
+ children: children.length > 0 ? children : [text(href)]
2042
+ }];
2043
+ }
2044
+ function kbdHandler(node, context) {
2045
+ handlerDiagnostic(node, context);
2046
+ let label = extractText(context.transformChildrenAsPhrasing(node, context)) || firstAttribute(node, ["children", "label"], context);
2047
+ return label ? [inlineCode(label)] : [];
2048
+ }
2049
+ function inlineComponentHandlers() {
2050
+ return [
2051
+ {
2052
+ componentNames: ["icon"],
2053
+ transform: iconHandler
2054
+ },
2055
+ {
2056
+ componentNames: ["a", "link"],
2057
+ transform: linkHandler
2058
+ },
2059
+ {
2060
+ componentNames: ["kbd"],
2061
+ transform: kbdHandler
2062
+ }
2063
+ ];
2064
+ }
2065
+
2066
+ // src/lib/compiler/markdown/handlers/media.ts
2067
+ function imageHandler(node, context, kind) {
2068
+ let src = firstAttribute(node, ["src", "href"], context);
2069
+ if (!src) return [];
2070
+ handlerDiagnostic(node, context);
2071
+ let caption = firstAttribute(node, ["caption"], context), image = {
2072
+ type: "image",
2073
+ url: context.resolveMediaUrl(src),
2074
+ alt: getAttribute(node, "alt", context) ?? firstAttribute(node, ["title", "aria-label"], context) ?? "",
2075
+ title: firstAttribute(node, ["title"], context)
2076
+ };
2077
+ return kind === "inline" ? [image, ...caption ? [text(` ${caption}`)] : []] : [
2078
+ ...paragraphBlock([image]),
2079
+ ...caption ? paragraphBlock([text(caption)]) : []
2080
+ ];
2081
+ }
2082
+ function figureCaptionHandler(node, context) {
2083
+ return handlerDiagnostic(node, context), node.type === "mdxJsxTextElement" ? paragraphBlock(context.transformChildrenAsPhrasing(node, context)) : context.transformChildrenAsBlocks(node, context);
2084
+ }
2085
+ function isCaption(node) {
2086
+ return ["figcaption", "figurecaption", "figure.caption"].includes(
2087
+ normalizeComponentName(node.name)
2088
+ );
2089
+ }
2090
+ function hasDirectCaption(node) {
2091
+ return (node.children ?? []).some(
2092
+ (child) => isCaption(child) || (child.type === "paragraph" || child.type.startsWith("mdxJsx") && child.name === null) && hasDirectCaption(child)
2093
+ );
2094
+ }
2095
+ function figureHandler(node, context) {
2096
+ handlerDiagnostic(node, context);
2097
+ let children = context.transformChildrenAsBlocks(node, context);
2098
+ if (hasDirectCaption(node)) return children;
2099
+ let caption = firstAttribute(node, ["caption"], context);
2100
+ return [...children, ...caption ? paragraphBlock([text(caption)]) : []];
2101
+ }
2102
+ function videoHandler(node, context, kind) {
2103
+ let src = firstAttribute(node, ["src", "url", "href"], context);
2104
+ if (!src) return context.transformChildrenAsBlocks(node, context);
2105
+ handlerDiagnostic(node, context);
2106
+ let label = firstAttribute(node, ["title", "alt", "aria-label"], context) ?? "Video", link = {
2107
+ type: "link",
2108
+ url: context.resolveMediaUrl(src),
2109
+ children: [text(label)]
2110
+ }, children = [text("Video: "), link], caption = firstAttribute(node, ["caption"], context);
2111
+ return kind === "inline" ? [...children, ...caption ? [text(` ${caption}`)] : []] : [
2112
+ ...paragraphBlock(children),
2113
+ ...caption ? paragraphBlock([text(caption)]) : []
2114
+ ];
2115
+ }
2116
+
2117
+ // src/lib/compiler/markdown/handlers/passthrough.ts
2118
+ function passthroughBlockHandler(node, context) {
2119
+ return handlerDiagnostic(node, context), context.transformChildrenAsBlocks(node, context);
2120
+ }
2121
+ function detailsHandler(node, context) {
2122
+ handlerDiagnostic(node, context);
2123
+ let summary = firstAttribute(node, ["summary", "title", "label"], context) ?? "Details";
2124
+ return [
2125
+ { type: "paragraph", children: [strongLabel(summary)] },
2126
+ ...context.transformChildrenAsBlocks(node, context)
2127
+ ];
2128
+ }
2129
+
2130
+ // src/lib/compiler/markdown/handlers/registry.ts
2131
+ var defaultHandlers = [
2132
+ {
2133
+ componentNames: ["image", "img", "picture"],
2134
+ transform: imageHandler
2135
+ },
2136
+ ...inlineComponentHandlers(),
2137
+ {
2138
+ componentNames: ["callout", "admonition", "note", "warning"],
2139
+ transform: calloutHandler
2140
+ },
2141
+ {
2142
+ componentNames: ["codeblock"],
2143
+ transform: codeBlockHandler
2144
+ },
2145
+ {
2146
+ componentNames: ["strong", "b", "em", "i", "code", "span", "br"],
2147
+ transform: inlineHtmlHandler
2148
+ },
2149
+ {
2150
+ componentNames: ["pre"],
2151
+ transform: preHtmlHandler
2152
+ },
2153
+ {
2154
+ componentNames: ["blockquote"],
2155
+ transform: blockquoteHtmlHandler
2156
+ },
2157
+ {
2158
+ componentNames: ["p"],
2159
+ transform: paragraphHtmlHandler
2160
+ },
2161
+ {
2162
+ componentNames: ["div"],
2163
+ transform: passthroughBlockHandler
2164
+ },
2165
+ {
2166
+ componentNames: [
2167
+ "codetab",
2168
+ "codetabs",
2169
+ "tab",
2170
+ "tabpanel",
2171
+ "tabs",
2172
+ "tabscontent"
2173
+ ],
2174
+ transform: tabHandler
2175
+ },
2176
+ {
2177
+ componentNames: ["figure"],
2178
+ transform: figureHandler
2179
+ },
2180
+ {
2181
+ componentNames: ["figcaption", "figurecaption", "figure.caption"],
2182
+ transform: figureCaptionHandler
2183
+ },
2184
+ {
2185
+ componentNames: ["video", "videoiframe", "iframe"],
2186
+ transform: videoHandler
2187
+ },
2188
+ {
2189
+ componentNames: ["details", "accordion", "summary"],
2190
+ transform: detailsHandler
2191
+ },
2192
+ {
2193
+ componentNames: ["step", "steps"],
2194
+ transform: passthroughBlockHandler
2195
+ }
2196
+ ], handlersByName = new Map(
2197
+ defaultHandlers.flatMap(
2198
+ (handler) => handler.componentNames.map((name) => [name, handler])
2199
+ )
2200
+ );
2201
+
2202
+ // src/lib/compiler/markdown/convert-mdx-to-markdown.ts
2203
+ var processor = unified2().use(remarkParse2).use(remarkMdx2).use(remarkGfm).use(remarkStringify, {
2204
+ bullet: "-",
2205
+ fences: !0,
2206
+ incrementListMarker: !0,
2207
+ listItemIndent: "one",
2208
+ rule: "-"
2209
+ });
2210
+ function stripHtmlComments(source) {
2211
+ return source.replace(/<!--[\s\S]*?-->/g, "");
2212
+ }
2213
+ function stripTopLevelImports(source) {
2214
+ return source.split(`
2215
+ `).filter((line) => !/^\s*(?:import|export)\s/.test(line)).join(`
2216
+ `).trim();
2217
+ }
2218
+ function parseSource(source, context) {
2219
+ try {
2220
+ return processor.parse(source);
2221
+ } catch (error) {
2222
+ let withoutComments = stripHtmlComments(source);
2223
+ if (withoutComments !== source)
2224
+ try {
2225
+ return processor.parse(withoutComments);
2226
+ } catch {
2227
+ }
2228
+ addDiagnostic(context, {
2229
+ code: "mdx-parse-failed",
2230
+ message: error instanceof Error ? error.message : "Failed to parse MDX for Markdown output."
2231
+ });
2232
+ return;
2233
+ }
2234
+ }
2235
+ function transformChildrenAsBlocks(node, context) {
2236
+ return (node.children ?? []).flatMap(
2237
+ (child) => transformBlockNode(child, context)
2238
+ );
2239
+ }
2240
+ function transformChildrenAsPhrasing(node, context) {
2241
+ return (node.children ?? []).flatMap(
2242
+ (child) => transformInlineNode(child, context)
2243
+ );
2244
+ }
2245
+ function transformMdxElement(node, context, kind) {
2246
+ if (node.name === null)
2247
+ return kind === "block" ? transformChildrenAsBlocks(node, context) : transformChildrenAsPhrasing(node, context);
2248
+ if (node.name && context.importedIcons.has(node.name)) {
2249
+ let label = firstAttribute(node, ["aria-hidden"], context) === "true" ? "" : firstAttribute(node, ["aria-label", "title"], context), children2 = label ? [{ type: "text", value: label }] : [];
2250
+ return kind === "block" ? paragraphBlock(children2) : children2;
2251
+ }
2252
+ let componentName = normalizeComponentName(node.name), handler = handlersByName.get(componentName);
2253
+ if (handler) {
2254
+ let result = handler.transform(node, context, kind);
2255
+ return kind === "block" ? asBlocks(result) : asPhrasing(result);
2256
+ }
2257
+ if (addDiagnostic(context, {
2258
+ code: "mdx-component-unknown",
2259
+ componentName: node.name ?? void 0,
2260
+ message: `Unknown MDX component "${node.name ?? "unknown"}".`
2261
+ }), context.unknownComponentMode === "error")
2262
+ throw new Error(`Unknown MDX component "${node.name ?? "unknown"}".`);
2263
+ if (context.unknownComponentMode === "html") {
2264
+ let html = htmlFallback(node);
2265
+ return html ? [{ type: "html", value: html }] : [];
2266
+ }
2267
+ let children = kind === "inline" ? transformChildrenAsPhrasing(node, context) : transformChildrenAsBlocks(node, context);
2268
+ return kind === "block" ? asBlocks(children) : asPhrasing(children);
2269
+ }
2270
+ function htmlFallback(node) {
2271
+ if (!node.name) return;
2272
+ let attrs = (node.attributes ?? []).map((attr) => {
2273
+ if (attr.value === null || attr.value === void 0) return attr.name;
2274
+ if (typeof attr.value == "string")
2275
+ return `${attr.name}="${attr.value.replace(/"/g, "&quot;")}"`;
2276
+ }).filter((value) => !!value).join(" ");
2277
+ return `<${node.name}${attrs ? ` ${attrs}` : ""} />`;
2278
+ }
2279
+ function transformInlineNode(node, context) {
2280
+ if (node.type === "mdxJsxTextElement")
2281
+ return asPhrasing(transformMdxElement(node, context, "inline"));
2282
+ if (node.type === "mdxTextExpression")
2283
+ return addDiagnostic(context, {
2284
+ code: "mdx-expression-dropped",
2285
+ message: "Dropped inline MDX expression from Markdown output."
2286
+ }), [];
2287
+ switch (node.type) {
2288
+ case "text":
2289
+ case "inlineCode":
2290
+ case "break":
2291
+ case "footnoteReference":
2292
+ return [node];
2293
+ case "emphasis":
2294
+ return [{
2295
+ ...node,
2296
+ children: transformChildrenAsPhrasing(node, context)
2297
+ }];
2298
+ case "strong":
2299
+ return [{
2300
+ ...node,
2301
+ children: transformChildrenAsPhrasing(node, context)
2302
+ }];
2303
+ case "delete":
2304
+ return [{
2305
+ ...node,
2306
+ children: transformChildrenAsPhrasing(node, context)
2307
+ }];
2308
+ case "link":
2309
+ return [{
2310
+ ...node,
2311
+ url: context.resolveMediaUrl(node.url),
2312
+ children: transformChildrenAsPhrasing(node, context)
2313
+ }];
2314
+ case "image":
2315
+ return [
2316
+ {
2317
+ ...node,
2318
+ url: context.resolveMediaUrl(node.url)
2319
+ }
2320
+ ];
2321
+ case "linkReference":
2322
+ case "imageReference":
2323
+ return [node];
2324
+ case "html":
2325
+ return [node];
2326
+ default:
2327
+ return [];
2328
+ }
2329
+ }
2330
+ function transformListItem(node, context) {
2331
+ return {
2332
+ ...node,
2333
+ children: transformChildrenAsBlocks(node, context)
2334
+ };
2335
+ }
2336
+ function transformTableCell(node, context) {
2337
+ return {
2338
+ ...node,
2339
+ children: transformChildrenAsPhrasing(node, context)
2340
+ };
2341
+ }
2342
+ function transformTableRow(node, context) {
2343
+ return {
2344
+ ...node,
2345
+ children: (node.children ?? []).map(
2346
+ (child) => transformTableCell(child, context)
2347
+ )
2348
+ };
2349
+ }
2350
+ function isFigureBlock(node) {
2351
+ if (node.type !== "mdxJsxTextElement" && node.type !== "mdxJsxFlowElement")
2352
+ return !1;
2353
+ if (node.name === null) return (node.children ?? []).some(isFigureBlock);
2354
+ let name = normalizeComponentName(node.name);
2355
+ return [
2356
+ "figure",
2357
+ "figcaption",
2358
+ "figurecaption",
2359
+ "figure.caption",
2360
+ "pre",
2361
+ "blockquote"
2362
+ ].includes(name) || ["image", "img", "video", "videoiframe", "iframe"].includes(name) && (node.attributes ?? []).some((attribute) => attribute.name === "caption");
2363
+ }
2364
+ function transformBlockNode(node, context) {
2365
+ if (node.type === "mdxjsEsm")
2366
+ return addDiagnostic(context, {
2367
+ code: "mdx-esm-dropped",
2368
+ message: "Dropped MDX import/export from Markdown output."
2369
+ }), [];
2370
+ if (node.type === "mdxFlowExpression")
2371
+ return addDiagnostic(context, {
2372
+ code: "mdx-expression-dropped",
2373
+ message: "Dropped flow MDX expression from Markdown output."
2374
+ }), [];
2375
+ if (node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement")
2376
+ return transformMdxElement(node, context, "block");
2377
+ switch (node.type) {
2378
+ case "paragraph": {
2379
+ if ((node.children ?? []).some(isFigureBlock)) {
2380
+ let blocks = [], pending = [], flushPhrasing = () => {
2381
+ let children = transformChildrenAsPhrasing(
2382
+ { type: "paragraph", children: pending },
2383
+ context
2384
+ );
2385
+ children.some(
2386
+ (child) => child.type !== "text" || child.value.trim()
2387
+ ) && blocks.push(...paragraphBlock(children)), pending = [];
2388
+ };
2389
+ for (let child of node.children ?? [])
2390
+ isFigureBlock(child) ? (flushPhrasing(), blocks.push(...transformBlockNode(child, context))) : pending.push(child);
2391
+ return flushPhrasing(), blocks;
2392
+ }
2393
+ let paragraphNode = paragraph(
2394
+ transformChildrenAsPhrasing(node, context)
2395
+ );
2396
+ return paragraphNode ? [paragraphNode] : [];
2397
+ }
2398
+ case "heading":
2399
+ return [{
2400
+ ...node,
2401
+ children: transformChildrenAsPhrasing(node, context)
2402
+ }];
2403
+ case "blockquote":
2404
+ return [
2405
+ {
2406
+ ...node,
2407
+ children: transformChildrenAsBlocks(node, context)
2408
+ }
2409
+ ];
2410
+ case "list":
2411
+ return [{
2412
+ ...node,
2413
+ children: (node.children ?? []).map(
2414
+ (child) => transformListItem(child, context)
2415
+ )
2416
+ }];
2417
+ case "table":
2418
+ return [{
2419
+ ...node,
2420
+ children: (node.children ?? []).map(
2421
+ (child) => transformTableRow(child, context)
2422
+ )
2423
+ }];
2424
+ case "text":
2425
+ case "inlineCode":
2426
+ case "break":
2427
+ case "emphasis":
2428
+ case "strong":
2429
+ case "delete":
2430
+ case "link":
2431
+ case "image":
2432
+ case "footnoteReference":
2433
+ return paragraphBlock(transformInlineNode(node, context));
2434
+ case "code":
2435
+ case "thematicBreak":
2436
+ case "html":
2437
+ case "yaml":
2438
+ case "footnoteDefinition":
2439
+ return [node];
2440
+ case "definition":
2441
+ return [
2442
+ {
2443
+ ...node,
2444
+ url: context.resolveMediaUrl(node.url)
2445
+ }
2446
+ ];
2447
+ default:
2448
+ return [];
2449
+ }
2450
+ }
2451
+ function convertMdxToMarkdown(options) {
2452
+ let context = {
2453
+ importedIcons: /* @__PURE__ */ new Set(),
2454
+ collectDiagnostics: options.collectDiagnostics ?? !0,
2455
+ diagnostics: [],
2456
+ resolveMediaUrl: (url) => String(mapSourceAssetUrl(url)),
2457
+ transformChildrenAsBlocks,
2458
+ transformChildrenAsPhrasing,
2459
+ unknownComponentMode: options.unknownComponentMode ?? "children"
2460
+ }, parsed = parseSource(options.source, context);
2461
+ if (!parsed)
2462
+ return {
2463
+ diagnostics: context.diagnostics,
2464
+ markdown: stripTopLevelImports(options.source),
2465
+ text: ""
2466
+ };
2467
+ for (let node of parsed.children)
2468
+ if (node.type === "mdxjsEsm") {
2469
+ for (let statement of node.data?.estree?.body ?? [])
2470
+ if (!(statement.type !== "ImportDeclaration" || statement.source.value !== mdxIconPackage))
2471
+ for (let specifier of statement.specifiers)
2472
+ specifier.type === "ImportSpecifier" && context.importedIcons.add(specifier.local.name);
2473
+ }
2474
+ let transformed = {
2475
+ type: "root",
2476
+ children: parsed.children.flatMap(
2477
+ (child) => transformBlockNode(child, context)
2478
+ )
2479
+ }, markdown = String(processor.stringify(transformed)).trim();
2480
+ return {
2481
+ diagnostics: context.diagnostics,
2482
+ markdown,
2483
+ text: extractText(transformed.children)
2484
+ };
2485
+ }
2486
+
2487
+ export {
2488
+ mapSourceAssetUrl,
2489
+ FrontmatterParseError,
2490
+ parseSourceFrontmatter,
2491
+ groupedMdxExports,
2492
+ replacedMdxSourceFiles,
2493
+ mdxComponentExportName,
2494
+ collectBindingNames,
2495
+ namedValueExports,
2496
+ mdxIconPackage,
2497
+ MdxIconImportError,
2498
+ readMdxIconImports,
2499
+ validateMdxIconImports,
2500
+ convertMdxToMarkdown,
2501
+ ROOT_CONTENT_GROUP_KEY,
2502
+ ROOT_CONTENT_GROUP_TITLE,
2503
+ assertSourceDependency,
2504
+ nextjs_runtime_surface_default,
2505
+ supportedNextjsSourceImports,
2506
+ supportedRuntimeComponentAliases,
2507
+ originalDefaultComponentSourcePath,
2508
+ buildFaviconsAndLogos,
2509
+ faviconsAndLogosManifestModule,
2510
+ mediaAssetBudgets,
2511
+ admitThemeImageResource,
2512
+ buildMediaAssets,
2513
+ writeMediaOutputs,
2514
+ mediaManifestModule,
2515
+ normalizeSlugPath,
2516
+ normalizeUrlPath,
2517
+ joinUrlPath,
2518
+ authoredDate
2519
+ };