@conloca/astro-cms 0.1.16 → 0.2.0

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 (422) hide show
  1. package/README.md +250 -298
  2. package/dist/internal/acorn-default.mjs +11 -3
  3. package/dist/internal/page-handler.astro +137 -358
  4. package/dist/ts/node/content.d.ts +4 -0
  5. package/dist/ts/node/content.d.ts.map +1 -0
  6. package/dist/ts/node/content.js +3 -0
  7. package/dist/ts/node/content.js.map +1 -0
  8. package/dist/ts/node/index.d.ts +9 -0
  9. package/dist/ts/node/index.d.ts.map +1 -0
  10. package/dist/ts/node/index.js +14 -0
  11. package/dist/ts/node/index.js.map +1 -0
  12. package/dist/ts/src/asset-ref-base.d.ts +3 -0
  13. package/dist/ts/src/asset-ref-base.d.ts.map +1 -0
  14. package/dist/ts/src/asset-ref-base.js +48 -0
  15. package/dist/ts/src/asset-ref-base.js.map +1 -0
  16. package/dist/ts/src/checks.d.ts +7 -0
  17. package/dist/ts/src/checks.d.ts.map +1 -0
  18. package/dist/ts/src/checks.js +7 -0
  19. package/dist/ts/src/checks.js.map +1 -0
  20. package/dist/{src → ts/src}/cms-handler.d.ts +0 -1
  21. package/dist/ts/src/cms-handler.d.ts.map +1 -0
  22. package/dist/{src → ts/src}/cms-handler.js +9 -130
  23. package/dist/ts/src/cms-handler.js.map +1 -0
  24. package/dist/ts/src/collections.d.ts +160 -0
  25. package/dist/ts/src/collections.d.ts.map +1 -0
  26. package/dist/ts/src/collections.js +170 -0
  27. package/dist/ts/src/collections.js.map +1 -0
  28. package/dist/{src → ts/src}/components/HydrationWrapper.d.ts +1 -1
  29. package/dist/ts/src/components/HydrationWrapper.d.ts.map +1 -0
  30. package/dist/{src → ts/src}/components/HydrationWrapper.js +1 -0
  31. package/dist/ts/src/components/HydrationWrapper.js.map +1 -0
  32. package/dist/{src/components/RenderWithBlocks.d.ts → ts/src/components/RenderWithFragments.d.ts} +8 -4
  33. package/dist/ts/src/components/RenderWithFragments.d.ts.map +1 -0
  34. package/dist/ts/src/components/RenderWithFragments.js +133 -0
  35. package/dist/ts/src/components/RenderWithFragments.js.map +1 -0
  36. package/dist/{src → ts/src}/components/RenderWithHydration.d.ts +6 -2
  37. package/dist/ts/src/components/RenderWithHydration.d.ts.map +1 -0
  38. package/dist/{src → ts/src}/components/RenderWithHydration.js +6 -3
  39. package/dist/ts/src/components/RenderWithHydration.js.map +1 -0
  40. package/dist/ts/src/components.d.ts +4 -0
  41. package/dist/ts/src/components.d.ts.map +1 -0
  42. package/dist/ts/src/components.js +4 -0
  43. package/dist/ts/src/components.js.map +1 -0
  44. package/dist/ts/src/discovery/astro-frontmatter.d.ts.map +1 -0
  45. package/dist/{src → ts/src}/discovery/astro-frontmatter.js +1 -0
  46. package/dist/ts/src/discovery/astro-frontmatter.js.map +1 -0
  47. package/dist/ts/src/discovery/discover.d.ts +43 -0
  48. package/dist/ts/src/discovery/discover.d.ts.map +1 -0
  49. package/dist/ts/src/discovery/discover.js +87 -0
  50. package/dist/ts/src/discovery/discover.js.map +1 -0
  51. package/dist/ts/src/discovery/extract-props-ts.d.ts.map +1 -0
  52. package/dist/{src → ts/src}/discovery/extract-props-ts.js +1 -0
  53. package/dist/ts/src/discovery/extract-props-ts.js.map +1 -0
  54. package/dist/{src → ts/src}/discovery/merge-registry.d.ts +3 -3
  55. package/dist/ts/src/discovery/merge-registry.d.ts.map +1 -0
  56. package/dist/{src → ts/src}/discovery/merge-registry.js +1 -0
  57. package/dist/ts/src/discovery/merge-registry.js.map +1 -0
  58. package/dist/ts/src/discovery/registry-endpoint.d.ts +27 -0
  59. package/dist/ts/src/discovery/registry-endpoint.d.ts.map +1 -0
  60. package/dist/ts/src/discovery/registry-endpoint.js +76 -0
  61. package/dist/ts/src/discovery/registry-endpoint.js.map +1 -0
  62. package/dist/{src → ts/src}/discovery/scan-components.d.ts +3 -7
  63. package/dist/ts/src/discovery/scan-components.d.ts.map +1 -0
  64. package/dist/{src → ts/src}/discovery/scan-components.js +4 -6
  65. package/dist/ts/src/discovery/scan-components.js.map +1 -0
  66. package/dist/ts/src/discovery/scan-mdx.d.ts.map +1 -0
  67. package/dist/{src → ts/src}/discovery/scan-mdx.js +1 -0
  68. package/dist/ts/src/discovery/scan-mdx.js.map +1 -0
  69. package/dist/ts/src/discovery/scan-overrides.d.ts.map +1 -0
  70. package/dist/{src → ts/src}/discovery/scan-overrides.js +1 -0
  71. package/dist/ts/src/discovery/scan-overrides.js.map +1 -0
  72. package/dist/ts/src/editor-descriptors.d.ts +31 -0
  73. package/dist/ts/src/editor-descriptors.d.ts.map +1 -0
  74. package/dist/ts/src/editor-descriptors.js +84 -0
  75. package/dist/ts/src/editor-descriptors.js.map +1 -0
  76. package/dist/ts/src/handlers/collection-content-api.d.ts +32 -0
  77. package/dist/ts/src/handlers/collection-content-api.d.ts.map +1 -0
  78. package/dist/ts/src/handlers/collection-content-api.js +166 -0
  79. package/dist/ts/src/handlers/collection-content-api.js.map +1 -0
  80. package/dist/ts/src/handlers/page-render-core.d.ts +137 -0
  81. package/dist/ts/src/handlers/page-render-core.d.ts.map +1 -0
  82. package/dist/ts/src/handlers/page-render-core.js +315 -0
  83. package/dist/ts/src/handlers/page-render-core.js.map +1 -0
  84. package/dist/ts/src/hydration.d.ts.map +1 -0
  85. package/dist/{src → ts/src}/hydration.js +1 -0
  86. package/dist/ts/src/hydration.js.map +1 -0
  87. package/dist/ts/src/index.d.ts +21 -0
  88. package/dist/ts/src/index.d.ts.map +1 -0
  89. package/dist/ts/src/index.js +45 -0
  90. package/dist/ts/src/index.js.map +1 -0
  91. package/dist/ts/src/internal/declared-collections.d.ts +30 -0
  92. package/dist/ts/src/internal/declared-collections.d.ts.map +1 -0
  93. package/dist/ts/src/internal/declared-collections.js +84 -0
  94. package/dist/ts/src/internal/declared-collections.js.map +1 -0
  95. package/dist/ts/src/internal/page-collection-schema.d.ts +44 -0
  96. package/dist/ts/src/internal/page-collection-schema.d.ts.map +1 -0
  97. package/dist/ts/src/internal/page-collection-schema.js +152 -0
  98. package/dist/ts/src/internal/page-collection-schema.js.map +1 -0
  99. package/dist/ts/src/lib/content-config-guard.d.ts +11 -0
  100. package/dist/ts/src/lib/content-config-guard.d.ts.map +1 -0
  101. package/dist/ts/src/lib/content-config-guard.js +41 -0
  102. package/dist/ts/src/lib/content-config-guard.js.map +1 -0
  103. package/dist/ts/src/lib/hydration-scanner.d.ts.map +1 -0
  104. package/dist/{src → ts/src}/lib/hydration-scanner.js +1 -0
  105. package/dist/ts/src/lib/hydration-scanner.js.map +1 -0
  106. package/dist/ts/src/lib/hydration-script.d.ts.map +1 -0
  107. package/dist/{src → ts/src}/lib/hydration-script.js +1 -0
  108. package/dist/ts/src/lib/hydration-script.js.map +1 -0
  109. package/dist/ts/src/lib/hydration-utils.d.ts.map +1 -0
  110. package/dist/{src → ts/src}/lib/hydration-utils.js +1 -0
  111. package/dist/ts/src/lib/hydration-utils.js.map +1 -0
  112. package/dist/ts/src/lib/resolve-locale.d.ts +15 -0
  113. package/dist/ts/src/lib/resolve-locale.d.ts.map +1 -0
  114. package/dist/ts/src/lib/resolve-locale.js +16 -0
  115. package/dist/ts/src/lib/resolve-locale.js.map +1 -0
  116. package/dist/ts/src/lib/resolve-site-name.d.ts +8 -0
  117. package/dist/ts/src/lib/resolve-site-name.d.ts.map +1 -0
  118. package/dist/ts/src/lib/resolve-site-name.js +12 -0
  119. package/dist/ts/src/lib/resolve-site-name.js.map +1 -0
  120. package/dist/{src → ts/src}/lib/route-utils.d.ts +26 -6
  121. package/dist/ts/src/lib/route-utils.d.ts.map +1 -0
  122. package/dist/{src → ts/src}/lib/route-utils.js +33 -15
  123. package/dist/ts/src/lib/route-utils.js.map +1 -0
  124. package/dist/{src → ts/src}/lib/routing-config.d.ts +7 -1
  125. package/dist/ts/src/lib/routing-config.d.ts.map +1 -0
  126. package/dist/{src → ts/src}/lib/routing-config.js +13 -0
  127. package/dist/ts/src/lib/routing-config.js.map +1 -0
  128. package/dist/ts/src/lib/serialize-props.d.ts.map +1 -0
  129. package/dist/{src → ts/src}/lib/serialize-props.js +1 -0
  130. package/dist/ts/src/lib/serialize-props.js.map +1 -0
  131. package/dist/ts/src/lib/unknown-components.d.ts +21 -0
  132. package/dist/ts/src/lib/unknown-components.d.ts.map +1 -0
  133. package/dist/ts/src/lib/unknown-components.js +49 -0
  134. package/dist/ts/src/lib/unknown-components.js.map +1 -0
  135. package/dist/{src → ts/src}/lib/virtual-module-generators.d.ts +0 -24
  136. package/dist/ts/src/lib/virtual-module-generators.d.ts.map +1 -0
  137. package/dist/ts/src/lib/virtual-module-generators.js +51 -0
  138. package/dist/ts/src/lib/virtual-module-generators.js.map +1 -0
  139. package/dist/ts/src/lib/withHydration.d.ts.map +1 -0
  140. package/dist/{src → ts/src}/lib/withHydration.js +1 -0
  141. package/dist/ts/src/lib/withHydration.js.map +1 -0
  142. package/dist/ts/src/loader.d.ts +27 -0
  143. package/dist/ts/src/loader.d.ts.map +1 -0
  144. package/dist/{src → ts/src}/loader.js +33 -4
  145. package/dist/ts/src/loader.js.map +1 -0
  146. package/dist/ts/src/locales-helpers.d.ts.map +1 -0
  147. package/dist/{src → ts/src}/locales-helpers.js +1 -0
  148. package/dist/ts/src/locales-helpers.js.map +1 -0
  149. package/dist/ts/src/mime-types.d.ts.map +1 -0
  150. package/dist/{src → ts/src}/mime-types.js +1 -0
  151. package/dist/ts/src/mime-types.js.map +1 -0
  152. package/dist/ts/src/page-feed.d.ts +13 -0
  153. package/dist/ts/src/page-feed.d.ts.map +1 -0
  154. package/dist/ts/src/page-feed.js +20 -0
  155. package/dist/ts/src/page-feed.js.map +1 -0
  156. package/dist/ts/src/page-schemas.d.ts +6 -0
  157. package/dist/ts/src/page-schemas.d.ts.map +1 -0
  158. package/dist/ts/src/page-schemas.js +6 -0
  159. package/dist/ts/src/page-schemas.js.map +1 -0
  160. package/dist/ts/src/path-validation.d.ts.map +1 -0
  161. package/dist/{src → ts/src}/path-validation.js +1 -0
  162. package/dist/ts/src/path-validation.js.map +1 -0
  163. package/dist/{src → ts/src}/plugin-spa.d.ts +28 -10
  164. package/dist/ts/src/plugin-spa.d.ts.map +1 -0
  165. package/dist/{src → ts/src}/plugin-spa.js +280 -87
  166. package/dist/ts/src/plugin-spa.js.map +1 -0
  167. package/dist/ts/src/puck-manifest/components-endpoint.d.ts +30 -0
  168. package/dist/ts/src/puck-manifest/components-endpoint.d.ts.map +1 -0
  169. package/dist/ts/src/puck-manifest/components-endpoint.js +54 -0
  170. package/dist/ts/src/puck-manifest/components-endpoint.js.map +1 -0
  171. package/dist/ts/src/puck-manifest/field-projection.d.ts +91 -0
  172. package/dist/ts/src/puck-manifest/field-projection.d.ts.map +1 -0
  173. package/dist/ts/src/puck-manifest/field-projection.js +422 -0
  174. package/dist/ts/src/puck-manifest/field-projection.js.map +1 -0
  175. package/dist/ts/src/puck-manifest/index.d.ts +4 -0
  176. package/dist/ts/src/puck-manifest/index.d.ts.map +1 -0
  177. package/dist/ts/src/puck-manifest/index.js +3 -0
  178. package/dist/ts/src/puck-manifest/index.js.map +1 -0
  179. package/dist/ts/src/puck-manifest/literal.d.ts +163 -0
  180. package/dist/ts/src/puck-manifest/literal.d.ts.map +1 -0
  181. package/dist/ts/src/puck-manifest/literal.js +354 -0
  182. package/dist/ts/src/puck-manifest/literal.js.map +1 -0
  183. package/dist/ts/src/puck-manifest/read-config.d.ts +42 -0
  184. package/dist/ts/src/puck-manifest/read-config.d.ts.map +1 -0
  185. package/dist/ts/src/puck-manifest/read-config.js +517 -0
  186. package/dist/ts/src/puck-manifest/read-config.js.map +1 -0
  187. package/dist/ts/src/puck-manifest/read-field.d.ts +7 -0
  188. package/dist/ts/src/puck-manifest/read-field.d.ts.map +1 -0
  189. package/dist/ts/src/puck-manifest/read-field.js +11 -0
  190. package/dist/ts/src/puck-manifest/read-field.js.map +1 -0
  191. package/dist/ts/src/puck-manifest/read-wrapper.d.ts +147 -0
  192. package/dist/ts/src/puck-manifest/read-wrapper.d.ts.map +1 -0
  193. package/dist/ts/src/puck-manifest/read-wrapper.js +889 -0
  194. package/dist/ts/src/puck-manifest/read-wrapper.js.map +1 -0
  195. package/dist/ts/src/puck-manifest/reading-budget.d.ts +50 -0
  196. package/dist/ts/src/puck-manifest/reading-budget.d.ts.map +1 -0
  197. package/dist/ts/src/puck-manifest/reading-budget.js +113 -0
  198. package/dist/ts/src/puck-manifest/reading-budget.js.map +1 -0
  199. package/dist/ts/src/puck-manifest/resolve-reference.d.ts +4 -0
  200. package/dist/ts/src/puck-manifest/resolve-reference.d.ts.map +1 -0
  201. package/dist/ts/src/puck-manifest/resolve-reference.js +4 -0
  202. package/dist/ts/src/puck-manifest/resolve-reference.js.map +1 -0
  203. package/dist/ts/src/puck-manifest/source-reference.d.ts +96 -0
  204. package/dist/ts/src/puck-manifest/source-reference.d.ts.map +1 -0
  205. package/dist/ts/src/puck-manifest/source-reference.js +424 -0
  206. package/dist/ts/src/puck-manifest/source-reference.js.map +1 -0
  207. package/dist/ts/src/puck-manifest/syntax.d.ts +29 -0
  208. package/dist/ts/src/puck-manifest/syntax.d.ts.map +1 -0
  209. package/dist/ts/src/puck-manifest/syntax.js +79 -0
  210. package/dist/ts/src/puck-manifest/syntax.js.map +1 -0
  211. package/dist/ts/src/puck-manifest/types.d.ts +145 -0
  212. package/dist/ts/src/puck-manifest/types.d.ts.map +1 -0
  213. package/dist/ts/src/puck-manifest/types.js +2 -0
  214. package/dist/ts/src/puck-manifest/types.js.map +1 -0
  215. package/dist/ts/src/safe-json-stringify.d.ts.map +1 -0
  216. package/dist/{src → ts/src}/safe-json-stringify.js +1 -0
  217. package/dist/ts/src/safe-json-stringify.js.map +1 -0
  218. package/dist/ts/src/sandbox-frame-handler.d.ts +19 -0
  219. package/dist/ts/src/sandbox-frame-handler.d.ts.map +1 -0
  220. package/dist/ts/src/sandbox-frame-handler.js +27 -0
  221. package/dist/ts/src/sandbox-frame-handler.js.map +1 -0
  222. package/dist/{src → ts/src}/site-styles/content-wrapper-endpoint.d.ts +2 -5
  223. package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -0
  224. package/dist/{src → ts/src}/site-styles/content-wrapper-endpoint.js +5 -8
  225. package/dist/ts/src/site-styles/content-wrapper-endpoint.js.map +1 -0
  226. package/dist/{src → ts/src}/site-styles/render-endpoint.d.ts +4 -9
  227. package/dist/ts/src/site-styles/render-endpoint.d.ts.map +1 -0
  228. package/dist/{src → ts/src}/site-styles/render-endpoint.js +1 -0
  229. package/dist/ts/src/site-styles/render-endpoint.js.map +1 -0
  230. package/dist/{src → ts/src}/site-styles/styles-endpoint.d.ts +2 -4
  231. package/dist/ts/src/site-styles/styles-endpoint.d.ts.map +1 -0
  232. package/dist/{src → ts/src}/site-styles/styles-endpoint.js +3 -5
  233. package/dist/ts/src/site-styles/styles-endpoint.js.map +1 -0
  234. package/dist/ts/src/sitemap-options.d.ts +21 -0
  235. package/dist/ts/src/sitemap-options.d.ts.map +1 -0
  236. package/dist/ts/src/sitemap-options.js +92 -0
  237. package/dist/ts/src/sitemap-options.js.map +1 -0
  238. package/dist/ts/src/tiptap-html-static.d.ts +15 -0
  239. package/dist/ts/src/tiptap-html-static.d.ts.map +1 -0
  240. package/dist/ts/src/tiptap-html-static.js +67 -0
  241. package/dist/ts/src/tiptap-html-static.js.map +1 -0
  242. package/dist/{src → ts/src}/types.d.ts +26 -110
  243. package/dist/ts/src/types.d.ts.map +1 -0
  244. package/dist/ts/src/types.js +2 -0
  245. package/dist/ts/src/types.js.map +1 -0
  246. package/dist/virtual-modules.d.ts +12 -93
  247. package/node/content.ts +14 -0
  248. package/node/index.ts +22 -0
  249. package/package.json +159 -73
  250. package/src/asset-ref-base.ts +48 -0
  251. package/src/checks.ts +10 -0
  252. package/src/cms-handler.ts +280 -0
  253. package/src/collections.ts +262 -0
  254. package/src/components/HydrationWrapper.tsx +41 -0
  255. package/src/components/RenderWithFragments.tsx +204 -0
  256. package/src/components/RenderWithHydration.tsx +55 -0
  257. package/src/components.ts +3 -0
  258. package/src/discovery/astro-frontmatter.ts +24 -0
  259. package/src/discovery/discover.ts +108 -0
  260. package/src/discovery/extract-props-ts.ts +255 -0
  261. package/src/discovery/merge-registry.ts +411 -0
  262. package/src/discovery/registry-endpoint.ts +80 -0
  263. package/src/discovery/scan-components.ts +458 -0
  264. package/src/discovery/scan-mdx.ts +190 -0
  265. package/src/discovery/scan-overrides.ts +92 -0
  266. package/src/editor-descriptors.ts +96 -0
  267. package/src/env.d.ts +31 -0
  268. package/src/handlers/collection-content-api.ts +196 -0
  269. package/src/handlers/page-handler.astro +320 -0
  270. package/src/handlers/page-render-core.ts +456 -0
  271. package/src/hydration.ts +7 -0
  272. package/src/index.ts +111 -0
  273. package/src/internal/acorn-default.mjs +37 -0
  274. package/src/internal/declared-collections.ts +98 -0
  275. package/src/internal/page-collection-schema.ts +210 -0
  276. package/src/lib/content-config-guard.ts +48 -0
  277. package/src/lib/hydration-scanner.ts +176 -0
  278. package/src/lib/hydration-script.ts +126 -0
  279. package/src/lib/hydration-utils.ts +120 -0
  280. package/src/lib/resolve-locale.ts +22 -0
  281. package/src/lib/resolve-site-name.ts +10 -0
  282. package/src/lib/route-utils.ts +106 -0
  283. package/src/lib/routing-config.ts +126 -0
  284. package/src/lib/serialize-props.ts +7 -0
  285. package/src/lib/unknown-components.ts +64 -0
  286. package/src/lib/virtual-module-generators.ts +58 -0
  287. package/{dist/withHydration-DkKpkmzJ.d.mts → src/lib/withHydration.ts} +25 -8
  288. package/src/loader.ts +145 -0
  289. package/{dist/locales-helpers-BvYYqnJ5.d.mts → src/locales-helpers.ts} +21 -17
  290. package/src/mime-types.ts +19 -0
  291. package/src/page-feed.ts +26 -0
  292. package/src/page-schemas.ts +19 -0
  293. package/src/path-validation.ts +13 -0
  294. package/src/plugin-spa.ts +1480 -0
  295. package/src/puck-manifest/components-endpoint.ts +55 -0
  296. package/src/puck-manifest/field-projection.ts +510 -0
  297. package/src/puck-manifest/index.ts +3 -0
  298. package/src/puck-manifest/literal.ts +459 -0
  299. package/src/puck-manifest/read-config.ts +577 -0
  300. package/src/puck-manifest/read-field.ts +19 -0
  301. package/src/puck-manifest/read-wrapper.ts +1056 -0
  302. package/src/puck-manifest/reading-budget.ts +127 -0
  303. package/src/puck-manifest/resolve-reference.ts +9 -0
  304. package/src/puck-manifest/source-reference.ts +484 -0
  305. package/src/puck-manifest/syntax.ts +104 -0
  306. package/src/puck-manifest/types.ts +139 -0
  307. package/src/safe-json-stringify.ts +17 -0
  308. package/src/sandbox-frame-handler.ts +31 -0
  309. package/src/site-styles/content-wrapper-endpoint.ts +327 -0
  310. package/src/site-styles/render-endpoint.ts +331 -0
  311. package/src/site-styles/styles-endpoint.ts +184 -0
  312. package/src/sitemap-options.ts +115 -0
  313. package/src/tiptap-html-static.ts +84 -0
  314. package/{dist/types-CS9neadI.d.mts → src/types.ts} +87 -124
  315. package/src/virtual-modules.d.ts +74 -0
  316. package/dist/collections-Bd7EME4b.mjs +0 -129
  317. package/dist/collections-Bd7EME4b.mjs.map +0 -1
  318. package/dist/collections.d.mts +0 -35
  319. package/dist/collections.d.mts.map +0 -1
  320. package/dist/collections.mjs +0 -2
  321. package/dist/components.d.mts +0 -41
  322. package/dist/components.d.mts.map +0 -1
  323. package/dist/components.mjs +0 -223
  324. package/dist/components.mjs.map +0 -1
  325. package/dist/hydration.d.mts +0 -4
  326. package/dist/hydration.mjs +0 -2
  327. package/dist/index.d.mts +0 -108
  328. package/dist/index.d.mts.map +0 -1
  329. package/dist/index.mjs +0 -67
  330. package/dist/index.mjs.map +0 -1
  331. package/dist/internal/cms-handler.d.mts +0 -25
  332. package/dist/internal/cms-handler.d.mts.map +0 -1
  333. package/dist/internal/cms-handler.mjs +0 -314
  334. package/dist/internal/cms-handler.mjs.map +0 -1
  335. package/dist/lib/hydration-script.d.mts +0 -30
  336. package/dist/lib/hydration-script.d.mts.map +0 -1
  337. package/dist/lib/hydration-script.mjs +0 -84
  338. package/dist/lib/hydration-script.mjs.map +0 -1
  339. package/dist/locales-helpers-BvYYqnJ5.d.mts.map +0 -1
  340. package/dist/locales-helpers-qiwh7nxS.mjs +0 -54
  341. package/dist/locales-helpers-qiwh7nxS.mjs.map +0 -1
  342. package/dist/node/content.d.mts +0 -18
  343. package/dist/node/content.d.mts.map +0 -1
  344. package/dist/node/content.d.ts +0 -3
  345. package/dist/node/content.d.ts.map +0 -1
  346. package/dist/node/content.js +0 -2
  347. package/dist/node/content.mjs +0 -2
  348. package/dist/node/index.d.mts +0 -200
  349. package/dist/node/index.d.mts.map +0 -1
  350. package/dist/node/index.d.ts +0 -4
  351. package/dist/node/index.d.ts.map +0 -1
  352. package/dist/node/index.js +0 -3
  353. package/dist/node/index.mjs +0 -2513
  354. package/dist/node/index.mjs.map +0 -1
  355. package/dist/serialize-props-BHoNpzH6.mjs +0 -72
  356. package/dist/serialize-props-BHoNpzH6.mjs.map +0 -1
  357. package/dist/src/cms-handler.d.ts.map +0 -1
  358. package/dist/src/collections.d.ts +0 -32
  359. package/dist/src/collections.d.ts.map +0 -1
  360. package/dist/src/collections.js +0 -50
  361. package/dist/src/components/HydrationWrapper.d.ts.map +0 -1
  362. package/dist/src/components/RenderWithBlocks.d.ts.map +0 -1
  363. package/dist/src/components/RenderWithBlocks.js +0 -129
  364. package/dist/src/components/RenderWithHydration.d.ts.map +0 -1
  365. package/dist/src/components.d.ts +0 -4
  366. package/dist/src/components.d.ts.map +0 -1
  367. package/dist/src/components.js +0 -3
  368. package/dist/src/discovery/astro-frontmatter.d.ts.map +0 -1
  369. package/dist/src/discovery/extract-props-ts.d.ts.map +0 -1
  370. package/dist/src/discovery/merge-registry.d.ts.map +0 -1
  371. package/dist/src/discovery/registry-endpoint.d.ts +0 -42
  372. package/dist/src/discovery/registry-endpoint.d.ts.map +0 -1
  373. package/dist/src/discovery/registry-endpoint.js +0 -81
  374. package/dist/src/discovery/scan-components.d.ts.map +0 -1
  375. package/dist/src/discovery/scan-mdx.d.ts.map +0 -1
  376. package/dist/src/discovery/scan-overrides.d.ts.map +0 -1
  377. package/dist/src/hydration.d.ts.map +0 -1
  378. package/dist/src/index.d.ts +0 -11
  379. package/dist/src/index.d.ts.map +0 -1
  380. package/dist/src/index.js +0 -25
  381. package/dist/src/lib/hydration-scanner.d.ts.map +0 -1
  382. package/dist/src/lib/hydration-script.d.ts.map +0 -1
  383. package/dist/src/lib/hydration-utils.d.ts.map +0 -1
  384. package/dist/src/lib/page-api.d.ts +0 -77
  385. package/dist/src/lib/page-api.d.ts.map +0 -1
  386. package/dist/src/lib/page-api.js +0 -121
  387. package/dist/src/lib/route-utils.d.ts.map +0 -1
  388. package/dist/src/lib/routing-config.d.ts.map +0 -1
  389. package/dist/src/lib/serialize-props.d.ts.map +0 -1
  390. package/dist/src/lib/virtual-module-generators.d.ts.map +0 -1
  391. package/dist/src/lib/virtual-module-generators.js +0 -263
  392. package/dist/src/lib/withHydration.d.ts.map +0 -1
  393. package/dist/src/loader.d.ts +0 -14
  394. package/dist/src/loader.d.ts.map +0 -1
  395. package/dist/src/locales-helpers.d.ts.map +0 -1
  396. package/dist/src/mime-types.d.ts.map +0 -1
  397. package/dist/src/path-validation.d.ts.map +0 -1
  398. package/dist/src/plugin-spa.d.ts.map +0 -1
  399. package/dist/src/safe-json-stringify.d.ts.map +0 -1
  400. package/dist/src/site-styles/content-wrapper-endpoint.d.ts.map +0 -1
  401. package/dist/src/site-styles/render-endpoint.d.ts.map +0 -1
  402. package/dist/src/site-styles/styles-endpoint.d.ts.map +0 -1
  403. package/dist/src/types.d.ts.map +0 -1
  404. package/dist/src/types.js +0 -1
  405. package/dist/types-CS9neadI.d.mts.map +0 -1
  406. package/dist/withHydration-C256ox_6.mjs +0 -49
  407. package/dist/withHydration-C256ox_6.mjs.map +0 -1
  408. package/dist/withHydration-DkKpkmzJ.d.mts.map +0 -1
  409. /package/dist/{src → ts/src}/discovery/astro-frontmatter.d.ts +0 -0
  410. /package/dist/{src → ts/src}/discovery/extract-props-ts.d.ts +0 -0
  411. /package/dist/{src → ts/src}/discovery/scan-mdx.d.ts +0 -0
  412. /package/dist/{src → ts/src}/discovery/scan-overrides.d.ts +0 -0
  413. /package/dist/{src → ts/src}/hydration.d.ts +0 -0
  414. /package/dist/{src → ts/src}/lib/hydration-scanner.d.ts +0 -0
  415. /package/dist/{src → ts/src}/lib/hydration-script.d.ts +0 -0
  416. /package/dist/{src → ts/src}/lib/hydration-utils.d.ts +0 -0
  417. /package/dist/{src → ts/src}/lib/serialize-props.d.ts +0 -0
  418. /package/dist/{src → ts/src}/lib/withHydration.d.ts +0 -0
  419. /package/dist/{src → ts/src}/locales-helpers.d.ts +0 -0
  420. /package/dist/{src → ts/src}/mime-types.d.ts +0 -0
  421. /package/dist/{src → ts/src}/path-validation.d.ts +0 -0
  422. /package/dist/{src → ts/src}/safe-json-stringify.d.ts +0 -0
@@ -0,0 +1,104 @@
1
+ import {
2
+ type GetAccessorDeclaration,
3
+ type MethodDeclaration,
4
+ type Node,
5
+ type ObjectLiteralExpression,
6
+ type PropertyAssignment,
7
+ type SetAccessorDeclaration,
8
+ type ShorthandPropertyAssignment,
9
+ SyntaxKind,
10
+ } from 'ts-morph';
11
+
12
+ /**
13
+ * Strips the type-only wrappers around an expression until the value itself is
14
+ * reached. Configs are habitually written `… satisfies Config` or `… as const`,
15
+ * and a reader blind to the wrapper reads them as absent rather than as the
16
+ * object they plainly are.
17
+ */
18
+ export function unwrapExpression(node: Node): Node {
19
+ const wrapper =
20
+ node.asKind(SyntaxKind.AsExpression) ??
21
+ node.asKind(SyntaxKind.SatisfiesExpression) ??
22
+ node.asKind(SyntaxKind.ParenthesizedExpression) ??
23
+ node.asKind(SyntaxKind.TypeAssertionExpression) ??
24
+ node.asKind(SyntaxKind.NonNullExpression);
25
+ return wrapper ? unwrapExpression(wrapper.getExpression()) : node;
26
+ }
27
+
28
+ /** The object literal an expression amounts to, seen through its type wrappers. */
29
+ export function asObjectLiteral(node: Node): ObjectLiteralExpression | undefined {
30
+ return unwrapExpression(node).asKind(SyntaxKind.ObjectLiteralExpression);
31
+ }
32
+
33
+ /** A written JSON primitive, without following names or traversing containers. */
34
+ export function literalPrimitive(node: Node): string | number | boolean | null | undefined {
35
+ const expression = unwrapExpression(node);
36
+ const stringLiteral =
37
+ expression.asKind(SyntaxKind.StringLiteral) ?? expression.asKind(SyntaxKind.NoSubstitutionTemplateLiteral);
38
+ if (stringLiteral) return stringLiteral.getLiteralValue();
39
+
40
+ // The compiler hands a number's text over normalized — `1e21` as `1e+21`,
41
+ // `0.0000001` as `1e-7`, `0x10` as `16` — and `getLiteralValue` parses text
42
+ // without a dot as an integer, reading the first two as 1. `Number` reads
43
+ // the whole of it.
44
+ const numeric = expression.asKind(SyntaxKind.NumericLiteral);
45
+ if (numeric) return finite(Number(numeric.compilerNode.text));
46
+
47
+ // Negative numbers parse as a prefix-unary expression, not a numeric literal.
48
+ const unary = expression.asKind(SyntaxKind.PrefixUnaryExpression);
49
+ if (unary && unary.getOperatorToken() === SyntaxKind.MinusToken) {
50
+ const operand = unary.getOperand().asKind(SyntaxKind.NumericLiteral);
51
+ if (operand) return finite(-Number(operand.compilerNode.text));
52
+ return undefined;
53
+ }
54
+
55
+ if (expression.isKind(SyntaxKind.TrueKeyword)) return true;
56
+ if (expression.isKind(SyntaxKind.FalseKeyword)) return false;
57
+ if (expression.isKind(SyntaxKind.NullKeyword)) return null;
58
+ return undefined;
59
+ }
60
+
61
+ /**
62
+ * A number JSON can carry, or no value. `1e999` is Infinity at runtime, and a
63
+ * manifest would carry it as `null` — a wrong answer rather than a missing one.
64
+ */
65
+ function finite(value: number): number | undefined {
66
+ return Number.isFinite(value) ? value : undefined;
67
+ }
68
+
69
+ /** Every shape a named member of an object literal can be written in. */
70
+ export type NamedMember =
71
+ | PropertyAssignment
72
+ | ShorthandPropertyAssignment
73
+ | MethodDeclaration
74
+ | GetAccessorDeclaration
75
+ | SetAccessorDeclaration;
76
+
77
+ /**
78
+ * An object literal's member as one node a reader can ask for a key, or
79
+ * undefined for a spread. Every reader walking a literal asks this rather than
80
+ * listing the kinds itself, because a reader that forgets one — a setter, say —
81
+ * walks past a write that still replaces the key at runtime.
82
+ */
83
+ export function namedMember(property: Node): NamedMember | undefined {
84
+ return (
85
+ property.asKind(SyntaxKind.PropertyAssignment) ??
86
+ property.asKind(SyntaxKind.ShorthandPropertyAssignment) ??
87
+ property.asKind(SyntaxKind.MethodDeclaration) ??
88
+ property.asKind(SyntaxKind.GetAccessor) ??
89
+ property.asKind(SyntaxKind.SetAccessor)
90
+ );
91
+ }
92
+
93
+ /**
94
+ * The node a member hands over as its value: what `key: value` assigns, or the
95
+ * name a shorthand stands for — `{ options }` means `options: options`, and is
96
+ * followed the same way. Undefined for a method or an accessor, which carry
97
+ * code rather than a value.
98
+ */
99
+ export function writtenValue(member: NamedMember): Node | undefined {
100
+ return (
101
+ member.asKind(SyntaxKind.PropertyAssignment)?.getInitializerOrThrow() ??
102
+ member.asKind(SyntaxKind.ShorthandPropertyAssignment)?.getNameNode()
103
+ );
104
+ }
@@ -0,0 +1,139 @@
1
+ import type { JsonValue } from '@conloca/content-api';
2
+
3
+ export type { JsonValue };
4
+
5
+ /**
6
+ * Machine-readable description of a site's Puck config, read from source
7
+ * without executing it. Consumed by agents that edit a site's content and have
8
+ * no checkout — they need to know what components exist and what each accepts
9
+ * before they can compose a page.
10
+ */
11
+ export interface PuckManifest {
12
+ components: Record<string, ManifestComponent>;
13
+ /**
14
+ * Page-level fields from the config's `root`. `fieldsUnreadable` means what
15
+ * it means on a component: some of the set could not be read, the entries
16
+ * listed are the ones it provably declares, and any other prop may exist.
17
+ */
18
+ root?: { fields: Record<string, ManifestField>; fieldsUnreadable?: true };
19
+ /** Sidebar grouping, as declared in `categories`. */
20
+ categories?: Record<string, { title?: string; components: string[] }>;
21
+ /**
22
+ * Some of `categories` could not be read: the value as a whole, a category
23
+ * whose name or entry is written in a shape this reader cannot follow, or a
24
+ * title or component list it could not take. The categories listed are ones
25
+ * the config provably declares, with their components; others may exist,
26
+ * and a listed one may carry a title that is missing here.
27
+ */
28
+ categoriesUnreadable?: true;
29
+ /** Components named in `components` whose definition could not be resolved. */
30
+ unresolved: string[];
31
+ /**
32
+ * Why a name in `unresolved` could not be followed, where a reason is known —
33
+ * e.g. "the function is async, so the call returns a promise rather than a
34
+ * component". Diagnostic prose for humans
35
+ * and doctors, not a contract: keys are a subset of `unresolved`.
36
+ */
37
+ unresolvedReasons?: Record<string, string>;
38
+ /**
39
+ * The config may declare components this manifest cannot name. With no
40
+ * components listed, the names are unknown altogether: the file cannot be
41
+ * opened, it exports no object, its component map is written in a shape
42
+ * this reader cannot follow, or reading it — or sending what it reads — would
43
+ * cost more than the reader allows. The empty manifest is an admission, not
44
+ * a site that declares no components. With components listed, those are provably
45
+ * declared, and a spread, a computed name or a prototype this reader cannot
46
+ * follow may add others.
47
+ */
48
+ unreadable?: true;
49
+ /**
50
+ * Why `unreadable` is set, beside every one. With no components listed: its
51
+ * file could not be opened, it or a file it loads does not parse, it has no
52
+ * default export, its
53
+ * default export or its components map is not an object this reader can
54
+ * read, or reading it — or the manifest it makes — would cost more than the
55
+ * reader allows. With components listed: the write in the components map
56
+ * that may add others. Written for the site's developer; prose, not a
57
+ * contract.
58
+ */
59
+ unreadableReason?: string;
60
+ }
61
+
62
+ export interface ManifestComponent {
63
+ label?: string;
64
+ fields: Record<string, ManifestField>;
65
+ defaultProps?: Record<string, JsonValue>;
66
+ /** Puck's own agent annotations, copied verbatim. */
67
+ ai?: JsonValue;
68
+ /**
69
+ * Some of the `fields` value could not be followed — a getter, a call, a
70
+ * name leading nowhere, or a spread or computed key inside the set that may
71
+ * add or replace any entry. A name that DOES lead somewhere is followed, so
72
+ * this marks what stayed unknown rather than merely what was named. The
73
+ * entries listed above are the ones the set provably declares — none, when
74
+ * the value as a whole was unreadable — and any other prop may exist too.
75
+ */
76
+ fieldsUnreadable?: true;
77
+ /**
78
+ * Keys the source writes that could not be read, in whole or in part —
79
+ * `label: makeLabel()`, a `defaultProps` entry computed at runtime, a
80
+ * computed key that may have replaced any of them. Such a key is absent from
81
+ * this entry, or carries only the part that did read; what is missing is
82
+ * unknown rather than absent. `fields` has `fieldsUnreadable` instead.
83
+ *
84
+ * A behaviour key listed here — `resolveFields`, `resolveData`,
85
+ * `resolvePermissions` — is one a computed key this reader cannot name may
86
+ * have written or erased, so whether its marker below applies cannot be
87
+ * read, and the marker is left off.
88
+ */
89
+ unreadableKeys?: ('label' | 'defaultProps' | 'ai' | 'resolveFields' | 'resolveData' | 'resolvePermissions')[];
90
+ /** Field list is computed at render (`resolveFields`); the read list is a superset. */
91
+ dynamicFields?: true;
92
+ /** Props may be overwritten at render (`resolveData`). */
93
+ derivedProps?: true;
94
+ /** Placement or cardinality limited by `resolvePermissions` — the rule itself is code and unreadable. */
95
+ hasPlacementRules?: true;
96
+ }
97
+
98
+ export interface ManifestField {
99
+ type: string;
100
+ label?: string;
101
+ /** `radio` / `select` choices. */
102
+ options?: Array<{ label: JsonValue; value: JsonValue }>;
103
+ /** `array` item fields. */
104
+ arrayFields?: Record<string, ManifestField>;
105
+ /** `object` sub-fields. */
106
+ objectFields?: Record<string, ManifestField>;
107
+ /** Value bounds on a `number` field; item-count bounds on an `array` field. */
108
+ min?: number;
109
+ max?: number;
110
+ /** `slot` nesting rules — what may and may not be dropped inside. */
111
+ allow?: string[];
112
+ disallow?: string[];
113
+ ai?: JsonValue;
114
+ /** A `custom` or `external` field with no `ai.schema`: nothing can infer its shape. */
115
+ opaque?: true;
116
+ /**
117
+ * Some part of this field is written in a shape this reader cannot follow: a
118
+ * function (`defaultItemProps: () => …`), a spread leading nowhere, a key it
119
+ * cannot name (`[key]: …`), a prototype set with `__proto__`, a name whose
120
+ * declaration could not be reached (`options: buildOptions()`), or an
121
+ * options list that is not `{ label, value }` pairs. A plain name IS
122
+ * followed — `options: sizeOptions` and the shorthand `{ options }` read the
123
+ * list, and a spread of a written-down source merges — so this marks what
124
+ * stayed unknown, not merely what was named. Whatever is missing from the
125
+ * properties above is unknown, not absent, and a write this reader could not
126
+ * name takes every value read before it.
127
+ *
128
+ * On a `slot` it stands for rules written somewhere this reader does not
129
+ * look: Puck takes `allow`/`disallow` from the field or from the slot the
130
+ * component's `render` draws, so a slot writing neither here has nesting
131
+ * rules that are unknown rather than none.
132
+ *
133
+ * Beside `type: 'unknown'` it says something stronger: the entry is not a
134
+ * field declaration this reader could recognise at all — nothing it or its
135
+ * spreads write mentions a type — so the prop is named and nothing about its
136
+ * shape is claimed.
137
+ */
138
+ unreadable?: true;
139
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * JSON.stringify replacement that escapes characters dangerous in HTML script contexts.
3
+ *
4
+ * When embedding JSON in `<script>` tags, characters like `<`, `>`, `&`, and `'` can break
5
+ * out of the script context (e.g., `</script>` closes the tag prematurely). This function
6
+ * replaces those characters with their Unicode escape equivalents, which are valid in both
7
+ * JSON and JavaScript string contexts.
8
+ *
9
+ * @see https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html
10
+ */
11
+ export function safeJsonStringify(data: Record<string, unknown> | unknown[] | string | number | boolean | null): string;
12
+ export function safeJsonStringify(data: unknown): string | undefined;
13
+ export function safeJsonStringify(data: unknown): string | undefined {
14
+ const json = JSON.stringify(data);
15
+ if (json === undefined) return undefined;
16
+ return json.replace(/[<>&']/g, (ch) => `\\u${ch.charCodeAt(0).toString(16).padStart(4, '0')}`);
17
+ }
@@ -0,0 +1,31 @@
1
+ import { buildSandboxSrcdoc, SANDBOX_FRAME_CSP } from '@conloca/mdx/sandbox-frame';
2
+ import type { APIRoute } from 'astro';
3
+
4
+ /**
5
+ * GET /api/v1/mdx/sandbox-frame — the opaque-origin iframe document that
6
+ * ContentSandbox loads for MDX fragment previews (canvas chips, fragment
7
+ * editor live preview).
8
+ *
9
+ * The path is root-absolute by contract: `SANDBOX_FRAME_PATH` in
10
+ * `@conloca/mdx` is what the editor requests wherever it runs, so anything
11
+ * that serves the editor must serve this path too. astro-cms routes otherwise
12
+ * live under the cmsRoute prefix, so without this route the frame 404s and
13
+ * chips render the site's 404 page. Response headers are the frame's contract
14
+ * (`SANDBOX_FRAME_CSP`); any other server of the frame must match them.
15
+ *
16
+ * No auth gate: the document is static boilerplate — content only ever enters
17
+ * the frame via postMessage from the editor.
18
+ */
19
+
20
+ export const prerender = false;
21
+
22
+ export const GET: APIRoute = () =>
23
+ new Response(buildSandboxSrcdoc(), {
24
+ status: 200,
25
+ headers: {
26
+ 'content-type': 'text/html; charset=utf-8',
27
+ 'content-security-policy': `${SANDBOX_FRAME_CSP}; frame-ancestors 'self'`,
28
+ 'x-content-type-options': 'nosniff',
29
+ 'cache-control': 'no-store',
30
+ },
31
+ });
@@ -0,0 +1,327 @@
1
+ import type { Connect } from 'vite';
2
+
3
+ /**
4
+ * Per-route content-wrapper discovery endpoint.
5
+ *
6
+ * The editor mirrors the host's content surface by rendering its
7
+ * contenteditable inside a clone of whatever element the host wraps
8
+ * its page content in. This endpoint fetches the live HTML the dev
9
+ * server serves at `?url=<route>`, locates the relevant wrappers
10
+ * (prose content + code-block chrome), and returns them as JSON.
11
+ *
12
+ * Returned shape:
13
+ *
14
+ * {
15
+ * content: { tagName, className } | null,
16
+ * codeBlock: { tagName, className }[] | null,
17
+ * }
18
+ *
19
+ * - `content` is the wrapper for prose (h1-h6, p, lists, etc.). The
20
+ * editor wraps its contenteditable in a clone so the host's prose
21
+ * CSS reaches via the cascade.
22
+ * - `codeBlock` is the ORDERED chain of classed wrappers around the
23
+ * host's `<pre>`, outermost first. For Starlight's expressive-code:
24
+ * `[{ div, 'expressive-code' }, { figure, 'frame has-title …' }]`.
25
+ * The editor's CodeMirror frame renders each link as a nested
26
+ * element (outer→inner) so the host's code-block CSS reaches via
27
+ * the cascade including descendant selectors (`.expressive-code
28
+ * .frame .header`, etc.) — not just single-class targets.
29
+ *
30
+ * Discovery priorities (content):
31
+ *
32
+ * 1. `[data-conloca-content-root]` — explicit opt-in.
33
+ * 2. The smallest classed wrapper inside `<main>` containing the
34
+ * majority of prose tags.
35
+ * 3. `<main>` itself.
36
+ * 4. `null`.
37
+ *
38
+ * Discovery (codeBlock): walk up from a `<pre>` inside `<main>` and
39
+ * collect classed ancestors between the content wrapper and `<pre>`,
40
+ * preserving their nesting order. Returns null when no `<pre>` exists,
41
+ * or when there are no classed wrappers between the prose wrapper and
42
+ * the `<pre>`.
43
+ */
44
+ export interface ContentWrapperInfo {
45
+ /** Lower-case HTML tag name as it appeared in source, eg `'article'`. */
46
+ tagName: string;
47
+ /** Space-separated class list from the source element. Preserved
48
+ * verbatim so Astro-scoped hashes (`astro-e3flfouy`) survive — host
49
+ * scoped CSS only matches when those hashes are present on the
50
+ * element. */
51
+ className: string;
52
+ }
53
+
54
+ export interface DiscoveredWrappers {
55
+ /** The element wrapping the page's prose content (h1-h6, p, etc.).
56
+ * For Starlight: `.sl-markdown-content`. For Tailwind Typography:
57
+ * `.prose`. Null when no prose wrapper exists on the page. */
58
+ content: ContentWrapperInfo | null;
59
+ /** Ordered chain of classed wrappers between the content wrapper
60
+ * and the `<pre>`, outermost first. For Starlight:
61
+ * `[{ div, 'expressive-code' }, { figure, 'frame has-title …' }]`.
62
+ * Null when the page has no code blocks or no classed wrappers
63
+ * between the prose wrapper and the `<pre>`. */
64
+ codeBlock: ContentWrapperInfo[] | null;
65
+ }
66
+
67
+ export function createContentWrapperEndpoint(): Connect.NextHandleFunction {
68
+ return async (req, res, _next) => {
69
+ try {
70
+ const parsed = new URL(req.url ?? '', 'http://localhost');
71
+ const routeUrl = parsed.searchParams.get('url');
72
+ if (!routeUrl) {
73
+ res.statusCode = 400;
74
+ res.setHeader('content-type', 'text/plain');
75
+ res.end('Missing required query parameter: url');
76
+ return;
77
+ }
78
+
79
+ const host = req.headers.host ?? 'localhost:4321';
80
+ const protocol = (req.headers['x-forwarded-proto'] as string) ?? 'http';
81
+ const liveUrl = `${protocol}://${host}${routeUrl}`;
82
+ const html = await fetch(liveUrl, {
83
+ headers: req.headers.cookie ? { cookie: req.headers.cookie } : undefined,
84
+ }).then((r) => r.text());
85
+
86
+ const wrappers = findContentWrapper(html);
87
+
88
+ res.statusCode = 200;
89
+ res.setHeader('content-type', 'application/json; charset=utf-8');
90
+ res.setHeader('cache-control', 'no-store');
91
+ res.end(JSON.stringify(wrappers));
92
+ } catch (err) {
93
+ res.statusCode = 500;
94
+ res.setHeader('content-type', 'text/plain');
95
+ res.end(`Content-wrapper discovery failed: ${err instanceof Error ? err.message : String(err)}`);
96
+ }
97
+ };
98
+ }
99
+
100
+ /** Tags whose presence signals "this element holds prose content."
101
+ * We walk up from the first such element we find inside `<main>` to
102
+ * locate the wrapper. Headings + paragraphs cover every prose-styling
103
+ * convention we've seen — every CSS framework scopes typography
104
+ * through descendant selectors on `h1`–`h6` and `p`. */
105
+ const PROSE_TAGS = new Set(['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p']);
106
+
107
+ /** Tag that anchors code-block wrapper discovery. The host's code-
108
+ * block library (Starlight's expressive-code, Tailwind's `pre`
109
+ * styling, etc.) always renders a `<pre>` containing the code,
110
+ * often wrapped in additional classed elements. */
111
+ const CODE_BLOCK_ANCHOR = 'pre';
112
+
113
+ /** HTML5 void elements — never push onto the open-tag stack since they
114
+ * have no closing tag. */
115
+ const VOID_TAGS = new Set([
116
+ 'area',
117
+ 'base',
118
+ 'br',
119
+ 'col',
120
+ 'embed',
121
+ 'hr',
122
+ 'img',
123
+ 'input',
124
+ 'link',
125
+ 'meta',
126
+ 'source',
127
+ 'track',
128
+ 'wbr',
129
+ ]);
130
+
131
+ interface OpenTag {
132
+ tag: string;
133
+ className: string;
134
+ attrs: Record<string, string>;
135
+ }
136
+
137
+ /**
138
+ * Locate the host's content + code-block wrappers in raw HTML. Single-
139
+ * pass regex walk with a stack so we can recover ancestor chains for
140
+ * both prose tags and `<pre>` tags without a full DOM parser dep.
141
+ *
142
+ * Exported for unit testing.
143
+ */
144
+ export function findContentWrapper(html: string): DiscoveredWrappers {
145
+ // Strip comments and scripts so opening-tag-shaped strings inside
146
+ // them don't pollute the walk.
147
+ const cleaned = html
148
+ .replace(/<!--[\s\S]*?-->/g, '')
149
+ .replace(/<script[\s\S]*?<\/script>/gi, '')
150
+ .replace(/<style[\s\S]*?<\/style>/gi, '');
151
+
152
+ const tagRe = /<(\/?)([a-zA-Z][a-zA-Z0-9-]*)((?:\s+[^>]*)?)\s*(\/?)>/g;
153
+ const stack: OpenTag[] = [];
154
+
155
+ let explicit: ContentWrapperInfo | null = null;
156
+ let mainEl: OpenTag | null = null;
157
+ const proseAncestorChains: OpenTag[][] = [];
158
+ const preAncestorChains: OpenTag[][] = [];
159
+
160
+ for (const match of cleaned.matchAll(tagRe)) {
161
+ const isClose = match[1] === '/';
162
+ const tagName = match[2].toLowerCase();
163
+ const attrBlob = match[3] ?? '';
164
+ const explicitlySelfClosing = match[4] === '/';
165
+
166
+ if (isClose) {
167
+ for (let i = stack.length - 1; i >= 0; i--) {
168
+ if (stack[i].tag === tagName) {
169
+ stack.length = i;
170
+ break;
171
+ }
172
+ }
173
+ continue;
174
+ }
175
+
176
+ const attrs = parseAttributes(attrBlob);
177
+ const className = attrs.class ?? '';
178
+ const el: OpenTag = { tag: tagName, className, attrs };
179
+
180
+ // Priority 1 (content only): explicit opt-in. Capture and keep
181
+ // walking — we still need to discover the code-block wrapper.
182
+ if (!explicit && 'data-conloca-content-root' in attrs) {
183
+ explicit = { tagName, className };
184
+ }
185
+
186
+ if (!mainEl && tagName === 'main') {
187
+ mainEl = el;
188
+ }
189
+
190
+ if (mainEl && PROSE_TAGS.has(tagName)) {
191
+ const mainIdx = stack.indexOf(mainEl);
192
+ if (mainIdx >= 0) {
193
+ proseAncestorChains.push(stack.slice(mainIdx + 1));
194
+ }
195
+ }
196
+
197
+ if (mainEl && tagName === CODE_BLOCK_ANCHOR) {
198
+ const mainIdx = stack.indexOf(mainEl);
199
+ if (mainIdx >= 0) {
200
+ preAncestorChains.push(stack.slice(mainIdx + 1));
201
+ }
202
+ }
203
+
204
+ const isVoid = VOID_TAGS.has(tagName);
205
+ if (!isVoid && !explicitlySelfClosing) {
206
+ stack.push(el);
207
+ }
208
+ }
209
+
210
+ const content = resolveContentWrapper(explicit, mainEl, proseAncestorChains);
211
+ const codeBlock = resolveCodeBlockWrapper(content, preAncestorChains);
212
+
213
+ return { content, codeBlock };
214
+ }
215
+
216
+ /**
217
+ * Pick the content wrapper from the walk's collected data.
218
+ *
219
+ * Priority: explicit opt-in > majority-prose-wrapper-inside-main >
220
+ * `<main>` fallback > null.
221
+ */
222
+ function resolveContentWrapper(
223
+ explicit: ContentWrapperInfo | null,
224
+ mainEl: OpenTag | null,
225
+ proseAncestorChains: OpenTag[][],
226
+ ): ContentWrapperInfo | null {
227
+ if (explicit) return explicit;
228
+ if (!mainEl) return null;
229
+
230
+ if (proseAncestorChains.length === 0) {
231
+ return { tagName: 'main', className: mainEl.className };
232
+ }
233
+
234
+ // Tally classed-ancestor occurrences across all prose chains.
235
+ const scores = new Map<OpenTag, number>();
236
+ for (const chain of proseAncestorChains) {
237
+ for (const ancestor of chain) {
238
+ if (!ancestor.className) continue;
239
+ scores.set(ancestor, (scores.get(ancestor) ?? 0) + 1);
240
+ }
241
+ }
242
+
243
+ // Majority threshold rules out partial-coverage classed ancestors
244
+ // (single Cards holding one of many prose blocks).
245
+ const threshold = proseAncestorChains.length / 2;
246
+ const candidates = [...scores.entries()].filter(([, count]) => count > threshold);
247
+
248
+ if (candidates.length === 0) {
249
+ return { tagName: 'main', className: mainEl.className };
250
+ }
251
+
252
+ // Tie-break by depth: the candidate that appears deepest in any
253
+ // chain is the most specific (closest to the prose tags).
254
+ const maxChainIndex = (el: OpenTag) => Math.max(...proseAncestorChains.map((c) => c.indexOf(el)));
255
+ candidates.sort((a, b) => {
256
+ if (b[1] !== a[1]) return b[1] - a[1];
257
+ return maxChainIndex(b[0]) - maxChainIndex(a[0]);
258
+ });
259
+
260
+ const winner = candidates[0][0];
261
+ return { tagName: winner.tag, className: winner.className };
262
+ }
263
+
264
+ /**
265
+ * Derive the code-block wrapper chain from a representative `<pre>`'s
266
+ * ancestor chain. We strip everything at or above the content wrapper
267
+ * (its styles are already handled by the content-wrapper mirror) and
268
+ * return the remaining classed elements in nesting order, outermost
269
+ * first.
270
+ *
271
+ * Returning a chain (instead of one collapsed element) preserves the
272
+ * shape host CSS expects:
273
+ *
274
+ * - Single-class selectors (`.frame { ... }`) hit on whichever link
275
+ * carries that class.
276
+ * - Descendant selectors (`.expressive-code .frame { ... }`,
277
+ * `.frame .header > .title`) hit because the editor's renderer
278
+ * materialises the chain as nested elements with the host's
279
+ * expected tag names.
280
+ *
281
+ * The editor's code-block frame component (`code-block-frame.tsx` in
282
+ * `@conloca/mdx`) treats the LAST link as the "frame" element (where
283
+ * figcaption/pre/copy children render) and wraps it with the earlier
284
+ * links from inside out. This matches the host's authoring shape for
285
+ * libraries like ExpressiveCode (`.expressive-code > figure.frame >
286
+ * figcaption + pre + .copy`).
287
+ */
288
+ function resolveCodeBlockWrapper(
289
+ content: ContentWrapperInfo | null,
290
+ preAncestorChains: OpenTag[][],
291
+ ): ContentWrapperInfo[] | null {
292
+ if (preAncestorChains.length === 0) return null;
293
+
294
+ // Pick the first <pre>'s chain as representative. Code blocks on a
295
+ // single page are uniformly wrapped, so chains are interchangeable.
296
+ const chain = preAncestorChains[0];
297
+
298
+ // Strip everything at-or-above the content wrapper; the rest is
299
+ // code-block-specific chrome that this endpoint is responsible for.
300
+ const contentIdx = content
301
+ ? chain.findIndex((el) => el.tag === content.tagName && el.className === content.className)
302
+ : -1;
303
+ const codeBlockChain = chain.slice(contentIdx + 1);
304
+
305
+ const classedAncestors = codeBlockChain.filter((el) => el.className);
306
+ if (classedAncestors.length === 0) return null;
307
+
308
+ return classedAncestors.map((el) => ({ tagName: el.tag, className: el.className }));
309
+ }
310
+
311
+ /**
312
+ * Parse the attribute blob inside an opening tag. Handles `name="v"`,
313
+ * `name='v'`, `name=v`, and boolean (no-value) attributes. Doesn't
314
+ * handle entity decoding (`&amp;` → `&`) since the values we read
315
+ * (tag name, class list, the marker attribute) don't carry entities
316
+ * in practice.
317
+ */
318
+ function parseAttributes(s: string): Record<string, string> {
319
+ const out: Record<string, string> = {};
320
+ const re = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|(\S+)))?/g;
321
+ for (const match of s.matchAll(re)) {
322
+ const name = match[1];
323
+ const value = match[2] ?? match[3] ?? match[4] ?? '';
324
+ out[name] = value;
325
+ }
326
+ return out;
327
+ }