@conloca/astro-cms 0.1.15 → 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.
- package/README.md +259 -247
- package/dist/internal/acorn-default.mjs +11 -3
- package/dist/internal/page-handler.astro +137 -358
- package/dist/ts/node/content.d.ts +4 -0
- package/dist/ts/node/content.d.ts.map +1 -0
- package/dist/ts/node/content.js +3 -0
- package/dist/ts/node/content.js.map +1 -0
- package/dist/ts/node/index.d.ts +9 -0
- package/dist/ts/node/index.d.ts.map +1 -0
- package/dist/ts/node/index.js +14 -0
- package/dist/ts/node/index.js.map +1 -0
- package/dist/ts/src/asset-ref-base.d.ts +3 -0
- package/dist/ts/src/asset-ref-base.d.ts.map +1 -0
- package/dist/ts/src/asset-ref-base.js +48 -0
- package/dist/ts/src/asset-ref-base.js.map +1 -0
- package/dist/ts/src/checks.d.ts +7 -0
- package/dist/ts/src/checks.d.ts.map +1 -0
- package/dist/ts/src/checks.js +7 -0
- package/dist/ts/src/checks.js.map +1 -0
- package/dist/ts/src/cms-handler.d.ts +18 -0
- package/dist/ts/src/cms-handler.d.ts.map +1 -0
- package/dist/ts/src/cms-handler.js +245 -0
- package/dist/ts/src/cms-handler.js.map +1 -0
- package/dist/ts/src/collections.d.ts +160 -0
- package/dist/ts/src/collections.d.ts.map +1 -0
- package/dist/ts/src/collections.js +170 -0
- package/dist/ts/src/collections.js.map +1 -0
- package/dist/ts/src/components/HydrationWrapper.d.ts +18 -0
- package/dist/ts/src/components/HydrationWrapper.d.ts.map +1 -0
- package/dist/ts/src/components/HydrationWrapper.js +22 -0
- package/dist/ts/src/components/HydrationWrapper.js.map +1 -0
- package/dist/ts/src/components/RenderWithFragments.d.ts +27 -0
- package/dist/ts/src/components/RenderWithFragments.d.ts.map +1 -0
- package/dist/ts/src/components/RenderWithFragments.js +133 -0
- package/dist/ts/src/components/RenderWithFragments.js.map +1 -0
- package/dist/ts/src/components/RenderWithHydration.d.ts +21 -0
- package/dist/ts/src/components/RenderWithHydration.d.ts.map +1 -0
- package/dist/ts/src/components/RenderWithHydration.js +39 -0
- package/dist/ts/src/components/RenderWithHydration.js.map +1 -0
- package/dist/ts/src/components.d.ts +4 -0
- package/dist/ts/src/components.d.ts.map +1 -0
- package/dist/ts/src/components.js +4 -0
- package/dist/ts/src/components.js.map +1 -0
- package/dist/ts/src/discovery/astro-frontmatter.d.ts +18 -0
- package/dist/ts/src/discovery/astro-frontmatter.d.ts.map +1 -0
- package/dist/ts/src/discovery/astro-frontmatter.js +25 -0
- package/dist/ts/src/discovery/astro-frontmatter.js.map +1 -0
- package/dist/ts/src/discovery/discover.d.ts +43 -0
- package/dist/ts/src/discovery/discover.d.ts.map +1 -0
- package/dist/ts/src/discovery/discover.js +87 -0
- package/dist/ts/src/discovery/discover.js.map +1 -0
- package/dist/ts/src/discovery/extract-props-ts.d.ts +41 -0
- package/dist/ts/src/discovery/extract-props-ts.d.ts.map +1 -0
- package/dist/ts/src/discovery/extract-props-ts.js +232 -0
- package/dist/ts/src/discovery/extract-props-ts.js.map +1 -0
- package/dist/ts/src/discovery/merge-registry.d.ts +58 -0
- package/dist/ts/src/discovery/merge-registry.d.ts.map +1 -0
- package/dist/ts/src/discovery/merge-registry.js +333 -0
- package/dist/ts/src/discovery/merge-registry.js.map +1 -0
- package/dist/ts/src/discovery/registry-endpoint.d.ts +27 -0
- package/dist/ts/src/discovery/registry-endpoint.d.ts.map +1 -0
- package/dist/ts/src/discovery/registry-endpoint.js +76 -0
- package/dist/ts/src/discovery/registry-endpoint.js.map +1 -0
- package/dist/ts/src/discovery/scan-components.d.ts +94 -0
- package/dist/ts/src/discovery/scan-components.d.ts.map +1 -0
- package/dist/ts/src/discovery/scan-components.js +397 -0
- package/dist/ts/src/discovery/scan-components.js.map +1 -0
- package/dist/ts/src/discovery/scan-mdx.d.ts +63 -0
- package/dist/ts/src/discovery/scan-mdx.d.ts.map +1 -0
- package/dist/ts/src/discovery/scan-mdx.js +113 -0
- package/dist/ts/src/discovery/scan-mdx.js.map +1 -0
- package/dist/ts/src/discovery/scan-overrides.d.ts +71 -0
- package/dist/ts/src/discovery/scan-overrides.d.ts.map +1 -0
- package/dist/ts/src/discovery/scan-overrides.js +34 -0
- package/dist/ts/src/discovery/scan-overrides.js.map +1 -0
- package/dist/ts/src/editor-descriptors.d.ts +31 -0
- package/dist/ts/src/editor-descriptors.d.ts.map +1 -0
- package/dist/ts/src/editor-descriptors.js +84 -0
- package/dist/ts/src/editor-descriptors.js.map +1 -0
- package/dist/ts/src/handlers/collection-content-api.d.ts +32 -0
- package/dist/ts/src/handlers/collection-content-api.d.ts.map +1 -0
- package/dist/ts/src/handlers/collection-content-api.js +166 -0
- package/dist/ts/src/handlers/collection-content-api.js.map +1 -0
- package/dist/ts/src/handlers/page-render-core.d.ts +137 -0
- package/dist/ts/src/handlers/page-render-core.d.ts.map +1 -0
- package/dist/ts/src/handlers/page-render-core.js +315 -0
- package/dist/ts/src/handlers/page-render-core.js.map +1 -0
- package/dist/ts/src/hydration.d.ts +4 -0
- package/dist/ts/src/hydration.d.ts.map +1 -0
- package/dist/ts/src/hydration.js +5 -0
- package/dist/ts/src/hydration.js.map +1 -0
- package/dist/ts/src/index.d.ts +21 -0
- package/dist/ts/src/index.d.ts.map +1 -0
- package/dist/ts/src/index.js +45 -0
- package/dist/ts/src/index.js.map +1 -0
- package/dist/ts/src/internal/declared-collections.d.ts +30 -0
- package/dist/ts/src/internal/declared-collections.d.ts.map +1 -0
- package/dist/ts/src/internal/declared-collections.js +84 -0
- package/dist/ts/src/internal/declared-collections.js.map +1 -0
- package/dist/ts/src/internal/page-collection-schema.d.ts +44 -0
- package/dist/ts/src/internal/page-collection-schema.d.ts.map +1 -0
- package/dist/ts/src/internal/page-collection-schema.js +152 -0
- package/dist/ts/src/internal/page-collection-schema.js.map +1 -0
- package/dist/ts/src/lib/content-config-guard.d.ts +11 -0
- package/dist/ts/src/lib/content-config-guard.d.ts.map +1 -0
- package/dist/ts/src/lib/content-config-guard.js +41 -0
- package/dist/ts/src/lib/content-config-guard.js.map +1 -0
- package/dist/ts/src/lib/hydration-scanner.d.ts +47 -0
- package/dist/ts/src/lib/hydration-scanner.d.ts.map +1 -0
- package/dist/ts/src/lib/hydration-scanner.js +136 -0
- package/dist/ts/src/lib/hydration-scanner.js.map +1 -0
- package/dist/{lib/hydration-script.d.mts → ts/src/lib/hydration-script.d.ts} +7 -10
- package/dist/ts/src/lib/hydration-script.d.ts.map +1 -0
- package/dist/ts/src/lib/hydration-script.js +89 -0
- package/dist/ts/src/lib/hydration-script.js.map +1 -0
- package/dist/ts/src/lib/hydration-utils.d.ts +51 -0
- package/dist/ts/src/lib/hydration-utils.d.ts.map +1 -0
- package/dist/ts/src/lib/hydration-utils.js +84 -0
- package/dist/ts/src/lib/hydration-utils.js.map +1 -0
- package/dist/ts/src/lib/resolve-locale.d.ts +15 -0
- package/dist/ts/src/lib/resolve-locale.d.ts.map +1 -0
- package/dist/ts/src/lib/resolve-locale.js +16 -0
- package/dist/ts/src/lib/resolve-locale.js.map +1 -0
- package/dist/ts/src/lib/resolve-site-name.d.ts +8 -0
- package/dist/ts/src/lib/resolve-site-name.d.ts.map +1 -0
- package/dist/ts/src/lib/resolve-site-name.js +12 -0
- package/dist/ts/src/lib/resolve-site-name.js.map +1 -0
- package/dist/ts/src/lib/route-utils.d.ts +61 -0
- package/dist/ts/src/lib/route-utils.d.ts.map +1 -0
- package/dist/ts/src/lib/route-utils.js +96 -0
- package/dist/ts/src/lib/route-utils.js.map +1 -0
- package/dist/ts/src/lib/routing-config.d.ts +38 -0
- package/dist/ts/src/lib/routing-config.d.ts.map +1 -0
- package/dist/ts/src/lib/routing-config.js +106 -0
- package/dist/ts/src/lib/routing-config.js.map +1 -0
- package/dist/ts/src/lib/serialize-props.d.ts +6 -0
- package/dist/ts/src/lib/serialize-props.d.ts.map +1 -0
- package/dist/ts/src/lib/serialize-props.js +8 -0
- package/dist/ts/src/lib/serialize-props.js.map +1 -0
- package/dist/ts/src/lib/unknown-components.d.ts +21 -0
- package/dist/ts/src/lib/unknown-components.d.ts.map +1 -0
- package/dist/ts/src/lib/unknown-components.js +49 -0
- package/dist/ts/src/lib/unknown-components.js.map +1 -0
- package/dist/ts/src/lib/virtual-module-generators.d.ts +33 -0
- package/dist/ts/src/lib/virtual-module-generators.d.ts.map +1 -0
- package/dist/ts/src/lib/virtual-module-generators.js +51 -0
- package/dist/ts/src/lib/virtual-module-generators.js.map +1 -0
- package/dist/{withHydration-HIvO9ysY.d.mts → ts/src/lib/withHydration.d.ts} +7 -11
- package/dist/ts/src/lib/withHydration.d.ts.map +1 -0
- package/dist/ts/src/lib/withHydration.js +50 -0
- package/dist/ts/src/lib/withHydration.js.map +1 -0
- package/dist/ts/src/loader.d.ts +27 -0
- package/dist/ts/src/loader.d.ts.map +1 -0
- package/dist/ts/src/loader.js +118 -0
- package/dist/ts/src/loader.js.map +1 -0
- package/dist/ts/src/locales-helpers.d.ts +61 -0
- package/dist/ts/src/locales-helpers.d.ts.map +1 -0
- package/dist/ts/src/locales-helpers.js +50 -0
- package/dist/ts/src/locales-helpers.js.map +1 -0
- package/dist/ts/src/mime-types.d.ts +3 -0
- package/dist/ts/src/mime-types.d.ts.map +1 -0
- package/dist/ts/src/mime-types.js +20 -0
- package/dist/ts/src/mime-types.js.map +1 -0
- package/dist/ts/src/page-feed.d.ts +13 -0
- package/dist/ts/src/page-feed.d.ts.map +1 -0
- package/dist/ts/src/page-feed.js +20 -0
- package/dist/ts/src/page-feed.js.map +1 -0
- package/dist/ts/src/page-schemas.d.ts +6 -0
- package/dist/ts/src/page-schemas.d.ts.map +1 -0
- package/dist/ts/src/page-schemas.js +6 -0
- package/dist/ts/src/page-schemas.js.map +1 -0
- package/dist/ts/src/path-validation.d.ts +8 -0
- package/dist/ts/src/path-validation.d.ts.map +1 -0
- package/dist/ts/src/path-validation.js +13 -0
- package/dist/ts/src/path-validation.js.map +1 -0
- package/dist/ts/src/plugin-spa.d.ts +182 -0
- package/dist/ts/src/plugin-spa.d.ts.map +1 -0
- package/dist/ts/src/plugin-spa.js +1165 -0
- package/dist/ts/src/plugin-spa.js.map +1 -0
- package/dist/ts/src/puck-manifest/components-endpoint.d.ts +30 -0
- package/dist/ts/src/puck-manifest/components-endpoint.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/components-endpoint.js +54 -0
- package/dist/ts/src/puck-manifest/components-endpoint.js.map +1 -0
- package/dist/ts/src/puck-manifest/field-projection.d.ts +91 -0
- package/dist/ts/src/puck-manifest/field-projection.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/field-projection.js +422 -0
- package/dist/ts/src/puck-manifest/field-projection.js.map +1 -0
- package/dist/ts/src/puck-manifest/index.d.ts +4 -0
- package/dist/ts/src/puck-manifest/index.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/index.js +3 -0
- package/dist/ts/src/puck-manifest/index.js.map +1 -0
- package/dist/ts/src/puck-manifest/literal.d.ts +163 -0
- package/dist/ts/src/puck-manifest/literal.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/literal.js +354 -0
- package/dist/ts/src/puck-manifest/literal.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-config.d.ts +42 -0
- package/dist/ts/src/puck-manifest/read-config.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-config.js +517 -0
- package/dist/ts/src/puck-manifest/read-config.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-field.d.ts +7 -0
- package/dist/ts/src/puck-manifest/read-field.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-field.js +11 -0
- package/dist/ts/src/puck-manifest/read-field.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-wrapper.d.ts +147 -0
- package/dist/ts/src/puck-manifest/read-wrapper.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-wrapper.js +889 -0
- package/dist/ts/src/puck-manifest/read-wrapper.js.map +1 -0
- package/dist/ts/src/puck-manifest/reading-budget.d.ts +50 -0
- package/dist/ts/src/puck-manifest/reading-budget.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/reading-budget.js +113 -0
- package/dist/ts/src/puck-manifest/reading-budget.js.map +1 -0
- package/dist/ts/src/puck-manifest/resolve-reference.d.ts +4 -0
- package/dist/ts/src/puck-manifest/resolve-reference.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/resolve-reference.js +4 -0
- package/dist/ts/src/puck-manifest/resolve-reference.js.map +1 -0
- package/dist/ts/src/puck-manifest/source-reference.d.ts +96 -0
- package/dist/ts/src/puck-manifest/source-reference.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/source-reference.js +424 -0
- package/dist/ts/src/puck-manifest/source-reference.js.map +1 -0
- package/dist/ts/src/puck-manifest/syntax.d.ts +29 -0
- package/dist/ts/src/puck-manifest/syntax.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/syntax.js +79 -0
- package/dist/ts/src/puck-manifest/syntax.js.map +1 -0
- package/dist/ts/src/puck-manifest/types.d.ts +145 -0
- package/dist/ts/src/puck-manifest/types.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/types.js +2 -0
- package/dist/ts/src/puck-manifest/types.js.map +1 -0
- package/dist/ts/src/safe-json-stringify.d.ts +13 -0
- package/dist/ts/src/safe-json-stringify.d.ts.map +1 -0
- package/dist/ts/src/safe-json-stringify.js +7 -0
- package/dist/ts/src/safe-json-stringify.js.map +1 -0
- package/dist/ts/src/sandbox-frame-handler.d.ts +19 -0
- package/dist/ts/src/sandbox-frame-handler.d.ts.map +1 -0
- package/dist/ts/src/sandbox-frame-handler.js +27 -0
- package/dist/ts/src/sandbox-frame-handler.js.map +1 -0
- package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts +73 -0
- package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -0
- package/dist/ts/src/site-styles/content-wrapper-endpoint.js +224 -0
- package/dist/ts/src/site-styles/content-wrapper-endpoint.js.map +1 -0
- package/dist/ts/src/site-styles/render-endpoint.d.ts +50 -0
- package/dist/ts/src/site-styles/render-endpoint.d.ts.map +1 -0
- package/dist/ts/src/site-styles/render-endpoint.js +264 -0
- package/dist/ts/src/site-styles/render-endpoint.js.map +1 -0
- package/dist/ts/src/site-styles/styles-endpoint.d.ts +59 -0
- package/dist/ts/src/site-styles/styles-endpoint.d.ts.map +1 -0
- package/dist/ts/src/site-styles/styles-endpoint.js +156 -0
- package/dist/ts/src/site-styles/styles-endpoint.js.map +1 -0
- package/dist/ts/src/sitemap-options.d.ts +21 -0
- package/dist/ts/src/sitemap-options.d.ts.map +1 -0
- package/dist/ts/src/sitemap-options.js +92 -0
- package/dist/ts/src/sitemap-options.js.map +1 -0
- package/dist/ts/src/tiptap-html-static.d.ts +15 -0
- package/dist/ts/src/tiptap-html-static.d.ts.map +1 -0
- package/dist/ts/src/tiptap-html-static.js +67 -0
- package/dist/ts/src/tiptap-html-static.js.map +1 -0
- package/dist/ts/src/types.d.ts +543 -0
- package/dist/ts/src/types.d.ts.map +1 -0
- package/dist/ts/src/types.js +2 -0
- package/dist/ts/src/types.js.map +1 -0
- package/dist/virtual-modules.d.ts +74 -0
- package/node/content.ts +14 -0
- package/node/index.ts +22 -0
- package/package.json +198 -56
- package/src/asset-ref-base.ts +48 -0
- package/src/checks.ts +10 -0
- package/src/cms-handler.ts +280 -0
- package/src/collections.ts +262 -0
- package/src/components/HydrationWrapper.tsx +41 -0
- package/src/components/RenderWithFragments.tsx +204 -0
- package/src/components/RenderWithHydration.tsx +55 -0
- package/src/components.ts +3 -0
- package/src/discovery/astro-frontmatter.ts +24 -0
- package/src/discovery/discover.ts +108 -0
- package/src/discovery/extract-props-ts.ts +255 -0
- package/src/discovery/merge-registry.ts +411 -0
- package/src/discovery/registry-endpoint.ts +80 -0
- package/src/discovery/scan-components.ts +458 -0
- package/src/discovery/scan-mdx.ts +190 -0
- package/src/discovery/scan-overrides.ts +92 -0
- package/src/editor-descriptors.ts +96 -0
- package/src/env.d.ts +31 -0
- package/src/handlers/collection-content-api.ts +196 -0
- package/src/handlers/page-handler.astro +320 -0
- package/src/handlers/page-render-core.ts +456 -0
- package/src/hydration.ts +7 -0
- package/src/index.ts +111 -0
- package/src/internal/acorn-default.mjs +37 -0
- package/src/internal/declared-collections.ts +98 -0
- package/src/internal/page-collection-schema.ts +210 -0
- package/src/lib/content-config-guard.ts +48 -0
- package/src/lib/hydration-scanner.ts +176 -0
- package/src/lib/hydration-script.ts +126 -0
- package/src/lib/hydration-utils.ts +120 -0
- package/src/lib/resolve-locale.ts +22 -0
- package/src/lib/resolve-site-name.ts +10 -0
- package/src/lib/route-utils.ts +106 -0
- package/src/lib/routing-config.ts +126 -0
- package/src/lib/serialize-props.ts +7 -0
- package/src/lib/unknown-components.ts +64 -0
- package/src/lib/virtual-module-generators.ts +58 -0
- package/src/lib/withHydration.ts +71 -0
- package/src/loader.ts +145 -0
- package/src/locales-helpers.ts +68 -0
- package/src/mime-types.ts +19 -0
- package/src/page-feed.ts +26 -0
- package/src/page-schemas.ts +19 -0
- package/src/path-validation.ts +13 -0
- package/src/plugin-spa.ts +1480 -0
- package/src/puck-manifest/components-endpoint.ts +55 -0
- package/src/puck-manifest/field-projection.ts +510 -0
- package/src/puck-manifest/index.ts +3 -0
- package/src/puck-manifest/literal.ts +459 -0
- package/src/puck-manifest/read-config.ts +577 -0
- package/src/puck-manifest/read-field.ts +19 -0
- package/src/puck-manifest/read-wrapper.ts +1056 -0
- package/src/puck-manifest/reading-budget.ts +127 -0
- package/src/puck-manifest/resolve-reference.ts +9 -0
- package/src/puck-manifest/source-reference.ts +484 -0
- package/src/puck-manifest/syntax.ts +104 -0
- package/src/puck-manifest/types.ts +139 -0
- package/src/safe-json-stringify.ts +17 -0
- package/src/sandbox-frame-handler.ts +31 -0
- package/src/site-styles/content-wrapper-endpoint.ts +327 -0
- package/src/site-styles/render-endpoint.ts +331 -0
- package/src/site-styles/styles-endpoint.ts +184 -0
- package/src/sitemap-options.ts +115 -0
- package/src/tiptap-html-static.ts +84 -0
- package/{dist/types-CVQNmPxF.d.mts → src/types.ts} +232 -79
- package/src/virtual-modules.d.ts +74 -0
- package/dist/collections.d.mts +0 -36
- package/dist/collections.d.mts.map +0 -1
- package/dist/collections.mjs +0 -65
- package/dist/collections.mjs.map +0 -1
- package/dist/components.d.mts +0 -46
- package/dist/components.d.mts.map +0 -1
- package/dist/components.mjs +0 -226
- package/dist/components.mjs.map +0 -1
- package/dist/hydration-scanner-B0NjYkZ_.mjs +0 -109
- package/dist/hydration-scanner-B0NjYkZ_.mjs.map +0 -1
- package/dist/hydration.d.mts +0 -4
- package/dist/hydration.mjs +0 -3
- package/dist/index.d.mts +0 -139
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -66
- package/dist/index.mjs.map +0 -1
- package/dist/internal/cms-handler.d.mts +0 -26
- package/dist/internal/cms-handler.d.mts.map +0 -1
- package/dist/internal/cms-handler.mjs +0 -267
- package/dist/internal/cms-handler.mjs.map +0 -1
- package/dist/lib/hydration-script.d.mts.map +0 -1
- package/dist/lib/hydration-script.mjs +0 -85
- package/dist/lib/hydration-script.mjs.map +0 -1
- package/dist/loader-By-AQWHc.mjs +0 -68
- package/dist/loader-By-AQWHc.mjs.map +0 -1
- package/dist/node/content.d.mts +0 -19
- package/dist/node/content.d.mts.map +0 -1
- package/dist/node/content.mjs +0 -4
- package/dist/node/index.d.mts +0 -52
- package/dist/node/index.d.mts.map +0 -1
- package/dist/node/index.mjs +0 -753
- package/dist/node/index.mjs.map +0 -1
- package/dist/serialize-props-Dhv_MnkY.mjs +0 -73
- package/dist/serialize-props-Dhv_MnkY.mjs.map +0 -1
- package/dist/types-CVQNmPxF.d.mts.map +0 -1
- package/dist/withHydration-EzyzBQ-Y.mjs +0 -49
- package/dist/withHydration-EzyzBQ-Y.mjs.map +0 -1
- package/dist/withHydration-HIvO9ysY.d.mts.map +0 -1
|
@@ -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 (`&` → `&`) 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
|
+
}
|