@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,152 @@
|
|
|
1
|
+
import { toPageSchemaDescriptor } from '@conloca/cms-spa/page-schema-define';
|
|
2
|
+
import { pageMetaSchema } from '@conloca/content-api/schemas';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { LOADER_RESERVED_FIELDS } from '../loader.js';
|
|
5
|
+
const CORE_FIELD_NAMES = new Set(Object.keys(pageMetaSchema.shape));
|
|
6
|
+
const RESERVED_FIELD_NAMES = new Set(LOADER_RESERVED_FIELDS);
|
|
7
|
+
/**
|
|
8
|
+
* `seen` breaks cycles through shared schema instances, but a z.lazy whose
|
|
9
|
+
* factory builds fresh instances on every call defeats it — the depth cap is
|
|
10
|
+
* the backstop. No real page-meta schema nests this deep.
|
|
11
|
+
*/
|
|
12
|
+
const MAX_REWRITE_WALK_DEPTH = 32;
|
|
13
|
+
function findRewrite(schema, path, seen, depth = 0) {
|
|
14
|
+
if (seen.has(schema) || depth > MAX_REWRITE_WALK_DEPTH)
|
|
15
|
+
return null;
|
|
16
|
+
seen.add(schema);
|
|
17
|
+
const def = schema.def;
|
|
18
|
+
if (def.type === 'default')
|
|
19
|
+
return { kind: 'default', path };
|
|
20
|
+
if (def.type === 'catch')
|
|
21
|
+
return { kind: 'catch', path };
|
|
22
|
+
if (def.type === 'pipe')
|
|
23
|
+
return { kind: 'transform', path };
|
|
24
|
+
if (def.coerce)
|
|
25
|
+
return { kind: 'coerce', path };
|
|
26
|
+
// Every child schema paired with the path it is reported under, in the
|
|
27
|
+
// order the walk visits them — the first rewrite found is the one named
|
|
28
|
+
// in the error, so this order is part of the contract.
|
|
29
|
+
const shape = typeof def.shape === 'function' ? def.shape() : def.shape;
|
|
30
|
+
const children = [[def.innerType ?? def.in, path]];
|
|
31
|
+
for (const [key, child] of Object.entries(shape ?? {})) {
|
|
32
|
+
children.push([child, path ? `${path}.${key}` : key]);
|
|
33
|
+
}
|
|
34
|
+
children.push([def.element, `${path}[]`]);
|
|
35
|
+
for (const option of def.options ?? []) {
|
|
36
|
+
children.push([option, path]);
|
|
37
|
+
}
|
|
38
|
+
for (const [index, item] of (def.items ?? []).entries()) {
|
|
39
|
+
children.push([item, `${path}[${index}]`]);
|
|
40
|
+
}
|
|
41
|
+
children.push([def.rest, `${path}[]`], [def.keyType, path], [def.valueType, path], [def.left, path], [def.right, path], [def.getter?.(), path], [def.catchall, `${path}[*]`]);
|
|
42
|
+
for (const [child, childPath] of children) {
|
|
43
|
+
if (!child)
|
|
44
|
+
continue;
|
|
45
|
+
const found = findRewrite(child, childPath, seen, depth + 1);
|
|
46
|
+
if (found)
|
|
47
|
+
return found;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
function assertHostFieldsAreSafe(shape) {
|
|
52
|
+
for (const [name, schema] of Object.entries(shape)) {
|
|
53
|
+
if (CORE_FIELD_NAMES.has(name)) {
|
|
54
|
+
throw new Error(`[conloca] pageSchemas cannot redeclare Conloca field "${name}". ` +
|
|
55
|
+
'Title, pathname, locale, and the other core fields come from the CMS — put constraints on them in the editor schema, not here.');
|
|
56
|
+
}
|
|
57
|
+
if (RESERVED_FIELD_NAMES.has(name)) {
|
|
58
|
+
throw new Error(`[conloca] pageSchemas cannot declare "${name}". ` +
|
|
59
|
+
'That field is owned by the content loader; a host schema of the same name would replace page content on every page.');
|
|
60
|
+
}
|
|
61
|
+
const rewrite = findRewrite(schema, name, new Set());
|
|
62
|
+
if (rewrite) {
|
|
63
|
+
throw new Error(`[conloca] pageSchemas field "${rewrite.path}" uses .${rewrite.kind}(), which rewrites values when Astro validates the collection ` +
|
|
64
|
+
'and does not run in the editor preview. Use a plain field (optional string, array, …) and parse in one reader instead.');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Fold every page-schema descriptor into one Zod object of host meta fields.
|
|
70
|
+
* Requiredness is not preserved — the caller always `.partial()`s this for the
|
|
71
|
+
* collection, because Astro validates the whole `pages` pile.
|
|
72
|
+
*
|
|
73
|
+
* The merged object has one slot per field name, so two descriptors may only
|
|
74
|
+
* declare the same name by sharing the same field schema instance — last-wins
|
|
75
|
+
* would silently rewrite what the earlier prefix's pages are validated
|
|
76
|
+
* against, failing them with a Zod error that names neither descriptor.
|
|
77
|
+
*/
|
|
78
|
+
export function hostFieldsFromPageSchemas(pageSchemas) {
|
|
79
|
+
// z.ZodRawShape's index signature is readonly, so the accumulator is spelled
|
|
80
|
+
// with a mutable one.
|
|
81
|
+
const shape = {};
|
|
82
|
+
const fieldOwner = new Map();
|
|
83
|
+
for (const [key, entry] of Object.entries(pageSchemas)) {
|
|
84
|
+
const descriptor = toPageSchemaDescriptor(entry);
|
|
85
|
+
// Rebuilding from .shape below silently drops object-level refinements,
|
|
86
|
+
// so the refusal written for them has to run here, on the public path.
|
|
87
|
+
assertNoObjectRefinements(descriptor.schema);
|
|
88
|
+
// 'minimal'/'none' descriptors declare title for the form; strip those names so the collection guard does not fire.
|
|
89
|
+
const mode = descriptor.coreFields?.mode;
|
|
90
|
+
const stripCore = mode === 'minimal' || mode === 'none';
|
|
91
|
+
for (const [name, field] of Object.entries(descriptor.schema.shape)) {
|
|
92
|
+
if (stripCore && CORE_FIELD_NAMES.has(name))
|
|
93
|
+
continue;
|
|
94
|
+
const owner = fieldOwner.get(name);
|
|
95
|
+
if (owner !== undefined && shape[name] !== field) {
|
|
96
|
+
throw new Error(`[conloca] pageSchemas "${owner}" and "${key}" both declare field "${name}" with different schemas. ` +
|
|
97
|
+
'The merged collection schema has one slot per field name — declare the field once and import it ' +
|
|
98
|
+
'into both schemas, or rename one of the fields.');
|
|
99
|
+
}
|
|
100
|
+
fieldOwner.set(name, owner ?? key);
|
|
101
|
+
shape[name] = field;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return z.object(shape);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The schema Astro validates page entries against: the host's page-meta fields
|
|
108
|
+
* (all optional) with conloca's structural fields layered over them, loose so
|
|
109
|
+
* undeclared top-level fields still reach the rendered page.
|
|
110
|
+
*
|
|
111
|
+
* Looseness is TOP-LEVEL ONLY. A nested `z.object()` still strips undeclared
|
|
112
|
+
* nested keys; a host that wants them preserved has to write `z.looseObject()`.
|
|
113
|
+
*
|
|
114
|
+
* Rewrite bans (.default / .coerce / .transform / .catch) walk nested objects,
|
|
115
|
+
* arrays, and unions. `.partial()` is still shallow.
|
|
116
|
+
*
|
|
117
|
+
* Internal on purpose: `src/collections.ts` is a published entry (the
|
|
118
|
+
* `./collections` subpath), so anything exported from there is frozen under
|
|
119
|
+
* semver. Nothing outside this package consumes it.
|
|
120
|
+
*/
|
|
121
|
+
export function buildPageCollectionSchema(hostFields) {
|
|
122
|
+
assertNoObjectRefinements(hostFields);
|
|
123
|
+
assertHostFieldsAreSafe(hostFields.shape);
|
|
124
|
+
// The one declared seam in the typed-collections design: the runtime
|
|
125
|
+
// schema validates core + host fields and loosely admits the loader-written
|
|
126
|
+
// record fields, but TypeScript cannot see host fields through the loose
|
|
127
|
+
// index. The static type is asserted as the flattened entry instead, which
|
|
128
|
+
// is the same contract listings already rely on — a host declaring
|
|
129
|
+
// `HostPageMeta` promises it matches its `pageSchemas`. Pinned by the type
|
|
130
|
+
// proofs here and in the type proofs of a site that declares `HostPageMeta`.
|
|
131
|
+
return z.looseObject({
|
|
132
|
+
...hostFields.partial().shape,
|
|
133
|
+
...pageMetaSchema.shape,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* .partial() throws on a refined object, and a refined object still satisfies
|
|
138
|
+
* both the host-fields signature and the pageSchemas field type, so the raw
|
|
139
|
+
* zod error would surface while Astro loads content.config.ts naming neither
|
|
140
|
+
* conloca nor pageSchemas. Refuse it with something the host can act on —
|
|
141
|
+
* both on the fold over pageSchemas (which would otherwise silently DROP the
|
|
142
|
+
* refinement while rebuilding from .shape) and on direct host-fields callers.
|
|
143
|
+
*/
|
|
144
|
+
function assertNoObjectRefinements(schema) {
|
|
145
|
+
if ((schema.def.checks?.length ?? 0) > 0) {
|
|
146
|
+
throw new Error('[conloca] pageSchemas cannot carry object-level refinements (.refine, .superRefine or .check). ' +
|
|
147
|
+
'Conloca makes every host field optional — page schemas are prefix-scoped in the editor while ' +
|
|
148
|
+
'Astro validates a whole collection — and Zod cannot make a refined object partial. ' +
|
|
149
|
+
'Move the rule onto the individual field schemas instead.');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=page-collection-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-collection-schema.js","sourceRoot":"","sources":["../../../../src/internal/page-collection-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAE/F,OAAO,EAAiB,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;AACpE,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAS,sBAAsB,CAAC,CAAC;AAsBrE;;;;GAIG;AACH,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAElC,SAAS,WAAW,CAClB,MAAiB,EACjB,IAAY,EACZ,IAAoB,EACpB,KAAK,GAAG,CAAC;IAET,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,GAAG,sBAAsB;QAAE,OAAO,IAAI,CAAC;IACpE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACjB,MAAM,GAAG,GAAG,MAAM,CAAC,GAAa,CAAC;IACjC,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAC7D,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,EAAE,IAAI,EAA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,4BAA4B;oBACnG,kGAAkG;oBAClG,iDAAiD,CACpD,CAAC;YACJ,CAAC;YACD,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC;YACnC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QACtB,CAAC;IACH,CAAC;IACD,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC;AAgBD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,yBAAyB,CAAC,UAAsC;IAC9E,yBAAyB,CAAC,UAAU,CAAC,CAAC;IACtC,uBAAuB,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC1C,qEAAqE;IACrE,4EAA4E;IAC5E,yEAAyE;IACzE,2EAA2E;IAC3E,mEAAmE;IACnE,2EAA2E;IAC3E,6EAA6E;IAC7E,OAAO,CAAC,CAAC,WAAW,CAAC;QACnB,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC,KAAK;QAC7B,GAAG,cAAc,CAAC,KAAK;KACxB,CAA2C,CAAC;AAC/C,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,yBAAyB,CAAC,MAAkC;IACnE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,CACb,iGAAiG;YAC/F,+FAA+F;YAC/F,qFAAqF;YACrF,0DAA0D,CAC7D,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type ContentConfigProblem = 'missing' | 'not-wired';
|
|
2
|
+
/**
|
|
3
|
+
* Detect the single most common Conloca misconfiguration: a project whose
|
|
4
|
+
* content config never registers Conloca's collections, so every page 404s
|
|
5
|
+
* with no other symptom. Astro exposes no hook that reveals resolved
|
|
6
|
+
* collections, so this reads the file instead.
|
|
7
|
+
*/
|
|
8
|
+
export declare function findContentConfigProblem(projectRoot: string): ContentConfigProblem | null;
|
|
9
|
+
/** The copy-pasteable fix printed with either problem. */
|
|
10
|
+
export declare const CONTENT_CONFIG_SNIPPET = "// src/content.config.ts\nimport { conlocaFragments, conlocaPages } from '@conloca/astro-cms/node/content';\n\nexport const collections = {\n pages: conlocaPages(),\n ...conlocaFragments(),\n};";
|
|
11
|
+
//# sourceMappingURL=content-config-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-config-guard.d.ts","sourceRoot":"","sources":["../../../../src/lib/content-config-guard.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,oBAAoB,GAAG,SAAS,GAAG,WAAW,CAAC;AAU3D;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,oBAAoB,GAAG,IAAI,CAQzF;AAED,0DAA0D;AAC1D,eAAO,MAAM,sBAAsB,wMAMhC,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
/** Where Astro looks for a content config, newest location first. */
|
|
4
|
+
const CONTENT_CONFIG_CANDIDATES = [
|
|
5
|
+
'src/content.config.ts',
|
|
6
|
+
'src/content.config.mts',
|
|
7
|
+
'src/content.config.mjs',
|
|
8
|
+
'src/content.config.js',
|
|
9
|
+
'src/content/config.ts',
|
|
10
|
+
'src/content/config.mjs',
|
|
11
|
+
'src/content/config.js',
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* Any of these in the config means Conloca's collections get registered —
|
|
15
|
+
* the factories, the deprecated wrapper, or a hand-rolled
|
|
16
|
+
* `defineCollection({ loader: conlocaLoader(...) })` (a supported shape;
|
|
17
|
+
* the loader carries its own mounted-key guard).
|
|
18
|
+
*/
|
|
19
|
+
const WIRED_MARKERS = ['createConlocaCollections', 'conlocaPages', 'conlocaData', 'conlocaFragments', 'conlocaLoader'];
|
|
20
|
+
/**
|
|
21
|
+
* Detect the single most common Conloca misconfiguration: a project whose
|
|
22
|
+
* content config never registers Conloca's collections, so every page 404s
|
|
23
|
+
* with no other symptom. Astro exposes no hook that reveals resolved
|
|
24
|
+
* collections, so this reads the file instead.
|
|
25
|
+
*/
|
|
26
|
+
export function findContentConfigProblem(projectRoot) {
|
|
27
|
+
const found = CONTENT_CONFIG_CANDIDATES.map((candidate) => join(projectRoot, candidate)).find((path) => existsSync(path));
|
|
28
|
+
if (!found)
|
|
29
|
+
return 'missing';
|
|
30
|
+
const source = readFileSync(found, 'utf8');
|
|
31
|
+
return WIRED_MARKERS.some((marker) => source.includes(marker)) ? null : 'not-wired';
|
|
32
|
+
}
|
|
33
|
+
/** The copy-pasteable fix printed with either problem. */
|
|
34
|
+
export const CONTENT_CONFIG_SNIPPET = `// src/content.config.ts
|
|
35
|
+
import { conlocaFragments, conlocaPages } from '@conloca/astro-cms/node/content';
|
|
36
|
+
|
|
37
|
+
export const collections = {
|
|
38
|
+
pages: conlocaPages(),
|
|
39
|
+
...conlocaFragments(),
|
|
40
|
+
};`;
|
|
41
|
+
//# sourceMappingURL=content-config-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-config-guard.js","sourceRoot":"","sources":["../../../../src/lib/content-config-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,qEAAqE;AACrE,MAAM,yBAAyB,GAAG;IAChC,uBAAuB;IACvB,wBAAwB;IACxB,wBAAwB;IACxB,uBAAuB;IACvB,uBAAuB;IACvB,wBAAwB;IACxB,uBAAuB;CACxB,CAAC;AAIF;;;;;GAKG;AACH,MAAM,aAAa,GAAG,CAAC,0BAA0B,EAAE,cAAc,EAAE,aAAa,EAAE,kBAAkB,EAAE,eAAe,CAAC,CAAC;AAEvH;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,WAAmB;IAC1D,MAAM,KAAK,GAAG,yBAAyB,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CACrG,UAAU,CAAC,IAAI,CAAC,CACjB,CAAC;IACF,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAE7B,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC3C,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC;AACtF,CAAC;AAED,0DAA0D;AAC1D,MAAM,CAAC,MAAM,sBAAsB,GAAG;;;;;;GAMnC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result of scanning a component file for withHydration usage.
|
|
3
|
+
*/
|
|
4
|
+
export interface HydrationDiscovery {
|
|
5
|
+
/** Component name derived from filename (PascalCase) */
|
|
6
|
+
componentName: string;
|
|
7
|
+
/** Absolute path to the component file */
|
|
8
|
+
filePath: string;
|
|
9
|
+
/** Hydration strategy extracted from withHydration call */
|
|
10
|
+
strategy: 'load' | 'visible' | 'idle';
|
|
11
|
+
}
|
|
12
|
+
export declare const HYDRATION_IMPORT_PATTERN: RegExp;
|
|
13
|
+
export declare const HYDRATION_PATTERN: RegExp;
|
|
14
|
+
/**
|
|
15
|
+
* Derives component scan paths from puckConfigPath.
|
|
16
|
+
*
|
|
17
|
+
* Convention: puckConfigPath directory + '/components/puck'
|
|
18
|
+
* Example: './src/puck.config.tsx' -> './src/components/puck'
|
|
19
|
+
*
|
|
20
|
+
* If explicitPaths provided, they extend (not replace) the auto-discovered path.
|
|
21
|
+
*
|
|
22
|
+
* @param puckConfigPath - Path to the puck config (e.g., './src/puck.config.tsx')
|
|
23
|
+
* @param explicitPaths - Optional additional paths to scan
|
|
24
|
+
* @returns Array of paths to scan for hydratable components
|
|
25
|
+
*/
|
|
26
|
+
export declare function deriveComponentPaths(puckConfigPath: string, explicitPaths?: string[]): string[];
|
|
27
|
+
/**
|
|
28
|
+
* Scans component directories for files using withHydration wrapper.
|
|
29
|
+
*
|
|
30
|
+
* This function performs static analysis to discover components marked
|
|
31
|
+
* for hydration, without executing any component code.
|
|
32
|
+
*
|
|
33
|
+
* @param componentPaths - Relative paths to scan (e.g., ['src/components/puck'])
|
|
34
|
+
* @param projectRoot - Absolute path to the project root
|
|
35
|
+
* @returns Array of discovered hydratable components with their strategies
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const discoveries = await scanForHydratableComponents(
|
|
40
|
+
* ['src/components/puck'],
|
|
41
|
+
* '/path/to/project'
|
|
42
|
+
* )
|
|
43
|
+
* // => [{ componentName: 'TestimonialGrid', filePath: '...', strategy: 'visible' }]
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function scanForHydratableComponents(componentPaths: string[], projectRoot: string): Promise<HydrationDiscovery[]>;
|
|
47
|
+
//# sourceMappingURL=hydration-scanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydration-scanner.d.ts","sourceRoot":"","sources":["../../../../src/lib/hydration-scanner.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,wDAAwD;IACxD,aAAa,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC;CACvC;AAID,eAAO,MAAM,wBAAwB,QACwD,CAAC;AAI9F,eAAO,MAAM,iBAAiB,QAAuD,CAAC;AAKtF;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAQ/F;AA4BD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,2BAA2B,CAC/C,cAAc,EAAE,MAAM,EAAE,EACxB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,kBAAkB,EAAE,CAAC,CA6E/B"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { basename, dirname, extname, join, resolve } from 'node:path';
|
|
3
|
+
import fg from 'fast-glob';
|
|
4
|
+
// Regex to check if file imports withHydration from @conloca/astro-cms or @conloca/astro-cms/hydration
|
|
5
|
+
// This is faster than es-module-lexer for JSX files and avoids parse errors
|
|
6
|
+
export const HYDRATION_IMPORT_PATTERN = /import\s+\{[^}]*withHydration[^}]*\}\s+from\s+['"]@conloca\/astro-cms(?:\/hydration)?['"]/;
|
|
7
|
+
// Regex to find withHydration calls and extract strategy
|
|
8
|
+
// Matches: withHydration(ComponentName, 'strategy') or withHydration(ComponentName, "strategy")
|
|
9
|
+
export const HYDRATION_PATTERN = /withHydration\s*\(\s*\w+\s*,\s*['"](\w+)['"]\s*\)/g;
|
|
10
|
+
// Valid hydration strategies
|
|
11
|
+
const VALID_STRATEGIES = new Set(['load', 'visible', 'idle']);
|
|
12
|
+
/**
|
|
13
|
+
* Derives component scan paths from puckConfigPath.
|
|
14
|
+
*
|
|
15
|
+
* Convention: puckConfigPath directory + '/components/puck'
|
|
16
|
+
* Example: './src/puck.config.tsx' -> './src/components/puck'
|
|
17
|
+
*
|
|
18
|
+
* If explicitPaths provided, they extend (not replace) the auto-discovered path.
|
|
19
|
+
*
|
|
20
|
+
* @param puckConfigPath - Path to the puck config (e.g., './src/puck.config.tsx')
|
|
21
|
+
* @param explicitPaths - Optional additional paths to scan
|
|
22
|
+
* @returns Array of paths to scan for hydratable components
|
|
23
|
+
*/
|
|
24
|
+
export function deriveComponentPaths(puckConfigPath, explicitPaths) {
|
|
25
|
+
const puckDir = dirname(puckConfigPath);
|
|
26
|
+
const defaultScanPath = join(puckDir, 'components', 'puck');
|
|
27
|
+
if (explicitPaths && explicitPaths.length > 0) {
|
|
28
|
+
return [defaultScanPath, ...explicitPaths];
|
|
29
|
+
}
|
|
30
|
+
return [defaultScanPath];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Derives a PascalCase component name from a file path.
|
|
34
|
+
*
|
|
35
|
+
* @param filePath - Absolute path to the component file
|
|
36
|
+
* @returns Component name in PascalCase
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* deriveComponentName('/src/components/puck/TestimonialGrid.tsx')
|
|
40
|
+
* // => 'TestimonialGrid'
|
|
41
|
+
*
|
|
42
|
+
* deriveComponentName('/src/components/puck/blog-post-grid.tsx')
|
|
43
|
+
* // => 'BlogPostGrid'
|
|
44
|
+
*/
|
|
45
|
+
function deriveComponentName(filePath) {
|
|
46
|
+
const filename = basename(filePath, extname(filePath));
|
|
47
|
+
// Convert kebab-case to PascalCase if needed
|
|
48
|
+
if (filename.includes('-')) {
|
|
49
|
+
return filename
|
|
50
|
+
.split('-')
|
|
51
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
52
|
+
.join('');
|
|
53
|
+
}
|
|
54
|
+
// Ensure first letter is uppercase
|
|
55
|
+
return filename.charAt(0).toUpperCase() + filename.slice(1);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Scans component directories for files using withHydration wrapper.
|
|
59
|
+
*
|
|
60
|
+
* This function performs static analysis to discover components marked
|
|
61
|
+
* for hydration, without executing any component code.
|
|
62
|
+
*
|
|
63
|
+
* @param componentPaths - Relative paths to scan (e.g., ['src/components/puck'])
|
|
64
|
+
* @param projectRoot - Absolute path to the project root
|
|
65
|
+
* @returns Array of discovered hydratable components with their strategies
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const discoveries = await scanForHydratableComponents(
|
|
70
|
+
* ['src/components/puck'],
|
|
71
|
+
* '/path/to/project'
|
|
72
|
+
* )
|
|
73
|
+
* // => [{ componentName: 'TestimonialGrid', filePath: '...', strategy: 'visible' }]
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export async function scanForHydratableComponents(componentPaths, projectRoot) {
|
|
77
|
+
const discoveries = [];
|
|
78
|
+
const seenNames = new Map(); // componentName -> first filePath
|
|
79
|
+
for (const scanPath of componentPaths) {
|
|
80
|
+
const absolutePath = resolve(projectRoot, scanPath);
|
|
81
|
+
// Find all .tsx files in the directory and subdirectories
|
|
82
|
+
const files = await fg('**/*.tsx', {
|
|
83
|
+
cwd: absolutePath,
|
|
84
|
+
absolute: true,
|
|
85
|
+
onlyFiles: true,
|
|
86
|
+
});
|
|
87
|
+
for (const filePath of files) {
|
|
88
|
+
try {
|
|
89
|
+
const content = await readFile(filePath, 'utf-8');
|
|
90
|
+
// Fast path: check if file imports withHydration from @conloca/astro-cms
|
|
91
|
+
// Using simple regex instead of es-module-lexer to avoid JSX parse errors
|
|
92
|
+
if (!HYDRATION_IMPORT_PATTERN.test(content)) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
// Find withHydration calls with regex
|
|
96
|
+
const matches = [...content.matchAll(HYDRATION_PATTERN)];
|
|
97
|
+
if (matches.length === 0) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (matches.length > 1) {
|
|
101
|
+
console.warn(`[Conloca Hydration] Multiple withHydration calls in ${filePath}. ` +
|
|
102
|
+
'Consider splitting into separate component files. Using first call.');
|
|
103
|
+
}
|
|
104
|
+
const match = matches[0];
|
|
105
|
+
const rawStrategy = match[1];
|
|
106
|
+
// Validate strategy
|
|
107
|
+
if (!VALID_STRATEGIES.has(rawStrategy)) {
|
|
108
|
+
console.warn(`[Conloca Hydration] Invalid strategy '${rawStrategy}' in ${filePath}. ` +
|
|
109
|
+
`Valid options: ${[...VALID_STRATEGIES].join(', ')}. Skipping component.`);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const strategy = rawStrategy;
|
|
113
|
+
const componentName = deriveComponentName(filePath);
|
|
114
|
+
// Check for naming conflicts
|
|
115
|
+
const existingPath = seenNames.get(componentName);
|
|
116
|
+
if (existingPath) {
|
|
117
|
+
console.warn(`[Conloca Hydration] Duplicate component name '${componentName}'. ` +
|
|
118
|
+
`Found in: ${existingPath} and ${filePath}. Using first occurrence.`);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
seenNames.set(componentName, filePath);
|
|
122
|
+
discoveries.push({
|
|
123
|
+
componentName,
|
|
124
|
+
filePath,
|
|
125
|
+
strategy,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
// Log error but continue scanning other files
|
|
130
|
+
console.warn(`[Conloca Hydration] Error reading ${filePath}:`, err);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return discoveries;
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=hydration-scanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydration-scanner.js","sourceRoot":"","sources":["../../../../src/lib/hydration-scanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,MAAM,WAAW,CAAC;AAc3B,uGAAuG;AACvG,4EAA4E;AAC5E,MAAM,CAAC,MAAM,wBAAwB,GACnC,2FAA2F,CAAC;AAE9F,yDAAyD;AACzD,gGAAgG;AAChG,MAAM,CAAC,MAAM,iBAAiB,GAAG,oDAAoD,CAAC;AAEtF,6BA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E,kBAAkB,CAAC,GAAG,gBAAgB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAC5E,CAAC;oBACF,SAAS;gBACX,CAAC;gBAED,MAAM,QAAQ,GAAG,WAA0C,CAAC;gBAC5D,MAAM,aAAa,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;gBAEpD,6BAA6B;gBAC7B,MAAM,YAAY,GAAG,SAAS,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;gBAClD,IAAI,YAAY,EAAE,CAAC;oBACjB,OAAO,CAAC,IAAI,CACV,iDAAiD,aAAa,KAAK;wBACjE,aAAa,YAAY,QAAQ,QAAQ,2BAA2B,CACvE,CAAC;oBACF,SAAS;gBACX,CAAC;gBAED,SAAS,CAAC,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;gBACvC,WAAW,CAAC,IAAI,CAAC;oBACf,aAAa;oBACb,QAAQ;oBACR,QAAQ;iBACT,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,8CAA8C;gBAC9C,OAAO,CAAC,IAAI,CAAC,qCAAqC,QAAQ,GAAG,EAAE,GAAG,CAAC,CAAC;YACtE,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/lib/hydration-script.d.ts
|
|
1
|
+
import type { HydrationStrategy } from '../types.js';
|
|
4
2
|
/**
|
|
5
3
|
* Async loader that returns a React component.
|
|
6
4
|
* The registry generator handles extraction from ComponentConfig at build time.
|
|
@@ -11,21 +9,20 @@ type ComponentLoader = () => Promise<React.ComponentType<unknown>>;
|
|
|
11
9
|
* Generated by the scanner from withHydration metadata.
|
|
12
10
|
*/
|
|
13
11
|
interface ComponentRegistryEntry {
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
loader: ComponentLoader;
|
|
13
|
+
strategy: HydrationStrategy;
|
|
16
14
|
}
|
|
17
15
|
/**
|
|
18
16
|
* Registry mapping component names to their loaders and strategies.
|
|
19
17
|
* Generated by virtual:conloca-hydration-registry at build time.
|
|
20
18
|
*/
|
|
21
|
-
type ComponentRegistry = Record<string, ComponentRegistryEntry>;
|
|
19
|
+
export type ComponentRegistry = Record<string, ComponentRegistryEntry>;
|
|
22
20
|
/**
|
|
23
21
|
* Initialize hydration for all marked components on the page.
|
|
24
22
|
*
|
|
25
23
|
* Finds all elements with [data-hydrate] attribute and hydrates them
|
|
26
24
|
* according to their strategy from the registry.
|
|
27
25
|
*/
|
|
28
|
-
declare function initHydration(registry: ComponentRegistry): void;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
//# sourceMappingURL=hydration-script.d.mts.map
|
|
26
|
+
export declare function initHydration(registry: ComponentRegistry): void;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=hydration-script.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydration-script.d.ts","sourceRoot":"","sources":["../../../../src/lib/hydration-script.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD;;;GAGG;AACH,KAAK,eAAe,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;AAEnE;;;GAGG;AACH,UAAU,sBAAsB;IAC9B,MAAM,EAAE,eAAe,CAAC;IACxB,QAAQ,EAAE,iBAAiB,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;AAiEvE;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CA8B/D"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
import { hydrateRoot } from 'react-dom/client';
|
|
3
|
+
/**
|
|
4
|
+
* Hydrate a single element with its corresponding React component.
|
|
5
|
+
*/
|
|
6
|
+
async function hydrateElement(element, entry) {
|
|
7
|
+
const componentName = element.dataset.hydrate;
|
|
8
|
+
const propsJson = element.dataset.props || '{}';
|
|
9
|
+
if (!componentName) {
|
|
10
|
+
console.warn('[Conloca Hydration] Element missing data-hydrate attribute');
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
const props = JSON.parse(propsJson);
|
|
15
|
+
const Component = await entry.loader();
|
|
16
|
+
hydrateRoot(element, createElement(Component, props));
|
|
17
|
+
// Clean up data attributes after successful hydration
|
|
18
|
+
delete element.dataset.hydrate;
|
|
19
|
+
delete element.dataset.hydrateStrategy;
|
|
20
|
+
delete element.dataset.props;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
console.error(`[Conloca Hydration] Failed to hydrate ${componentName}:`, error);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Hydrate immediately on page load.
|
|
28
|
+
*/
|
|
29
|
+
function hydrateOnLoad(element, entry) {
|
|
30
|
+
hydrateElement(element, entry);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Hydrate when element becomes visible in viewport.
|
|
34
|
+
*/
|
|
35
|
+
function hydrateOnVisible(element, entry) {
|
|
36
|
+
const observer = new IntersectionObserver((entries, obs) => {
|
|
37
|
+
for (const ioEntry of entries) {
|
|
38
|
+
if (ioEntry.isIntersecting) {
|
|
39
|
+
obs.unobserve(ioEntry.target);
|
|
40
|
+
hydrateElement(ioEntry.target, entry);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}, { rootMargin: '50px' });
|
|
44
|
+
observer.observe(element);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Hydrate when browser is idle.
|
|
48
|
+
* Uses requestIdleCallback with setTimeout fallback for Safari.
|
|
49
|
+
*/
|
|
50
|
+
function hydrateOnIdle(element, entry) {
|
|
51
|
+
const scheduleIdle = window.requestIdleCallback ??
|
|
52
|
+
((cb) => window.setTimeout(() => cb({ didTimeout: false, timeRemaining: () => 50 }), 1));
|
|
53
|
+
scheduleIdle(() => hydrateElement(element, entry), { timeout: 2000 });
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Initialize hydration for all marked components on the page.
|
|
57
|
+
*
|
|
58
|
+
* Finds all elements with [data-hydrate] attribute and hydrates them
|
|
59
|
+
* according to their strategy from the registry.
|
|
60
|
+
*/
|
|
61
|
+
export function initHydration(registry) {
|
|
62
|
+
const elements = document.querySelectorAll('[data-hydrate]');
|
|
63
|
+
for (const element of elements) {
|
|
64
|
+
const componentName = element.dataset.hydrate;
|
|
65
|
+
if (!componentName)
|
|
66
|
+
continue;
|
|
67
|
+
const entry = registry[componentName];
|
|
68
|
+
if (!entry) {
|
|
69
|
+
console.warn(`[Conloca Hydration] Unknown component: ${componentName}`);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
// Use strategy from registry (set at build time via withHydration)
|
|
73
|
+
const strategy = entry.strategy;
|
|
74
|
+
switch (strategy) {
|
|
75
|
+
case 'load':
|
|
76
|
+
hydrateOnLoad(element, entry);
|
|
77
|
+
break;
|
|
78
|
+
case 'visible':
|
|
79
|
+
hydrateOnVisible(element, entry);
|
|
80
|
+
break;
|
|
81
|
+
case 'idle':
|
|
82
|
+
hydrateOnIdle(element, entry);
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
hydrateOnLoad(element, entry);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=hydration-script.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydration-script.js","sourceRoot":"","sources":["../../../../src/lib/hydration-script.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,WAAW,EAA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B,KAAK,MAAM;gBACT,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;gBAC9B,MAAM;YACR,KAAK,SAAS;gBACZ,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;gBACjC,MAAM;YACR,KAAK,MAAM;gBACT,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;gBAC9B,MAAM;YACR;gBACE,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Config, Data } from '@puckeditor/core';
|
|
2
|
+
import type { HydrationStrategy } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Extended ComponentConfig with hydration support.
|
|
5
|
+
* @deprecated Use withHydration() wrapper instead of hydration property.
|
|
6
|
+
*/
|
|
7
|
+
export interface HydratableComponentConfig {
|
|
8
|
+
/** @deprecated Use withHydration() wrapper on render function instead */
|
|
9
|
+
hydration?: HydrationStrategy;
|
|
10
|
+
render?: (props: unknown) => unknown;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Component instance requiring hydration.
|
|
14
|
+
* Contains the component name, props, and hydration strategy.
|
|
15
|
+
*/
|
|
16
|
+
export interface HydratableComponent {
|
|
17
|
+
/** Component type name from Puck config */
|
|
18
|
+
type: string;
|
|
19
|
+
/** Props to pass to the component */
|
|
20
|
+
props: Record<string, unknown>;
|
|
21
|
+
/** Hydration strategy from ComponentConfig */
|
|
22
|
+
strategy: Exclude<HydrationStrategy, 'none'>;
|
|
23
|
+
/** Unique ID from Puck data (for keying) */
|
|
24
|
+
id: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Check if a component type has hydration enabled.
|
|
28
|
+
*
|
|
29
|
+
* First checks for __hydration metadata on the render function (new withHydration API),
|
|
30
|
+
* then falls back to hydration property on ComponentConfig (deprecated).
|
|
31
|
+
*
|
|
32
|
+
* @param componentType - The component type name from Puck data
|
|
33
|
+
* @param config - The Puck config with component definitions
|
|
34
|
+
* @returns The hydration strategy ('none', 'load', 'visible', 'idle')
|
|
35
|
+
*/
|
|
36
|
+
export declare function isHydratable(componentType: string, config: Config): HydrationStrategy;
|
|
37
|
+
/**
|
|
38
|
+
* Find all components in a Puck data tree that require hydration.
|
|
39
|
+
* Walks the content array and zones recursively.
|
|
40
|
+
*
|
|
41
|
+
* @param data - Puck data object containing content tree
|
|
42
|
+
* @param config - Puck config with component definitions
|
|
43
|
+
* @returns Array of components that need hydration
|
|
44
|
+
*/
|
|
45
|
+
export declare function findHydratableComponents(data: Data, config: Config): HydratableComponent[];
|
|
46
|
+
/**
|
|
47
|
+
* Check if Puck data contains any hydratable components.
|
|
48
|
+
* Quick check before more expensive operations.
|
|
49
|
+
*/
|
|
50
|
+
export declare function hasHydratableComponents(data: Data, config: Config): boolean;
|
|
51
|
+
//# sourceMappingURL=hydration-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydration-utils.d.ts","sourceRoot":"","sources":["../../../../src/lib/hydration-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGrD;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,yEAAyE;IACzE,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAC9B,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;CACtC;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,qCAAqC;IACrC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,8CAA8C;IAC9C,QAAQ,EAAE,OAAO,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;IAC7C,4CAA4C;IAC5C,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAYrF;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,mBAAmB,EAAE,CAoC1F;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAgB3E"}
|