@conloca/astro-cms 0.1.14 → 0.1.16
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 +65 -5
- package/dist/collections-Bd7EME4b.mjs +129 -0
- package/dist/collections-Bd7EME4b.mjs.map +1 -0
- package/dist/collections.d.mts +3 -3
- package/dist/collections.d.mts.map +1 -1
- package/dist/collections.mjs +2 -56
- package/dist/components.d.mts +6 -31
- package/dist/components.d.mts.map +1 -1
- package/dist/components.mjs +100 -45
- package/dist/components.mjs.map +1 -1
- package/dist/hydration.d.mts +2 -2
- package/dist/hydration.mjs +2 -3
- package/dist/index.d.mts +12 -88
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +19 -797
- package/dist/index.mjs.map +1 -1
- package/dist/internal/acorn-default.mjs +29 -0
- package/dist/{cms-handler.d.mts → internal/cms-handler.d.mts} +0 -1
- package/dist/internal/cms-handler.d.mts.map +1 -0
- package/dist/{cms-handler.mjs → internal/cms-handler.mjs} +57 -8
- package/dist/internal/cms-handler.mjs.map +1 -0
- package/dist/internal/page-handler.astro +541 -0
- package/dist/lib/hydration-script.d.mts +1 -2
- package/dist/lib/hydration-script.d.mts.map +1 -1
- package/dist/lib/hydration-script.mjs +1 -2
- package/dist/lib/hydration-script.mjs.map +1 -1
- package/dist/locales-helpers-BvYYqnJ5.d.mts +64 -0
- package/dist/locales-helpers-BvYYqnJ5.d.mts.map +1 -0
- package/dist/locales-helpers-qiwh7nxS.mjs +54 -0
- package/dist/locales-helpers-qiwh7nxS.mjs.map +1 -0
- package/dist/node/content.d.mts +18 -0
- package/dist/node/content.d.mts.map +1 -0
- package/dist/node/content.d.ts +3 -0
- package/dist/node/content.d.ts.map +1 -0
- package/dist/node/content.js +2 -0
- package/dist/node/content.mjs +2 -0
- package/dist/node/index.d.mts +200 -0
- package/dist/node/index.d.mts.map +1 -0
- package/dist/node/index.d.ts +4 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +3 -0
- package/dist/node/index.mjs +2513 -0
- package/dist/node/index.mjs.map +1 -0
- package/dist/{serialize-props-DqfDQeFl.mjs → serialize-props-BHoNpzH6.mjs} +4 -5
- package/dist/{serialize-props-DqfDQeFl.mjs.map → serialize-props-BHoNpzH6.mjs.map} +1 -1
- package/dist/src/cms-handler.d.ts +19 -0
- package/dist/src/cms-handler.d.ts.map +1 -0
- package/dist/src/cms-handler.js +366 -0
- package/dist/src/collections.d.ts +32 -0
- package/dist/src/collections.d.ts.map +1 -0
- package/dist/src/collections.js +50 -0
- package/dist/src/components/HydrationWrapper.d.ts +18 -0
- package/dist/src/components/HydrationWrapper.d.ts.map +1 -0
- package/dist/src/components/HydrationWrapper.js +21 -0
- package/dist/src/components/RenderWithBlocks.d.ts +23 -0
- package/dist/src/components/RenderWithBlocks.d.ts.map +1 -0
- package/dist/src/components/RenderWithBlocks.js +129 -0
- package/dist/src/components/RenderWithHydration.d.ts +17 -0
- package/dist/src/components/RenderWithHydration.d.ts.map +1 -0
- package/dist/src/components/RenderWithHydration.js +36 -0
- package/dist/src/components.d.ts +4 -0
- package/dist/src/components.d.ts.map +1 -0
- package/dist/src/components.js +3 -0
- package/dist/src/discovery/astro-frontmatter.d.ts +18 -0
- package/dist/src/discovery/astro-frontmatter.d.ts.map +1 -0
- package/dist/src/discovery/astro-frontmatter.js +24 -0
- package/dist/src/discovery/extract-props-ts.d.ts +41 -0
- package/dist/src/discovery/extract-props-ts.d.ts.map +1 -0
- package/dist/src/discovery/extract-props-ts.js +231 -0
- package/dist/src/discovery/merge-registry.d.ts +58 -0
- package/dist/src/discovery/merge-registry.d.ts.map +1 -0
- package/dist/src/discovery/merge-registry.js +332 -0
- package/dist/src/discovery/registry-endpoint.d.ts +42 -0
- package/dist/src/discovery/registry-endpoint.d.ts.map +1 -0
- package/dist/src/discovery/registry-endpoint.js +81 -0
- package/dist/src/discovery/scan-components.d.ts +98 -0
- package/dist/src/discovery/scan-components.d.ts.map +1 -0
- package/dist/src/discovery/scan-components.js +399 -0
- package/dist/src/discovery/scan-mdx.d.ts +63 -0
- package/dist/src/discovery/scan-mdx.d.ts.map +1 -0
- package/dist/src/discovery/scan-mdx.js +112 -0
- package/dist/src/discovery/scan-overrides.d.ts +71 -0
- package/dist/src/discovery/scan-overrides.d.ts.map +1 -0
- package/dist/src/discovery/scan-overrides.js +33 -0
- package/dist/src/hydration.d.ts +4 -0
- package/dist/src/hydration.d.ts.map +1 -0
- package/dist/src/hydration.js +4 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +25 -0
- package/dist/src/lib/hydration-scanner.d.ts +47 -0
- package/dist/src/lib/hydration-scanner.d.ts.map +1 -0
- package/dist/src/lib/hydration-scanner.js +135 -0
- package/dist/src/lib/hydration-script.d.ts +28 -0
- package/dist/src/lib/hydration-script.d.ts.map +1 -0
- package/dist/src/lib/hydration-script.js +88 -0
- package/dist/src/lib/hydration-utils.d.ts +51 -0
- package/dist/src/lib/hydration-utils.d.ts.map +1 -0
- package/dist/src/lib/hydration-utils.js +83 -0
- package/dist/src/lib/page-api.d.ts +77 -0
- package/dist/src/lib/page-api.d.ts.map +1 -0
- package/dist/src/lib/page-api.js +121 -0
- package/dist/src/lib/route-utils.d.ts +41 -0
- package/dist/src/lib/route-utils.d.ts.map +1 -0
- package/dist/src/lib/route-utils.js +78 -0
- package/dist/src/lib/routing-config.d.ts +32 -0
- package/dist/src/lib/routing-config.d.ts.map +1 -0
- package/dist/src/lib/routing-config.js +93 -0
- package/dist/src/lib/serialize-props.d.ts +6 -0
- package/dist/src/lib/serialize-props.d.ts.map +1 -0
- package/dist/src/lib/serialize-props.js +7 -0
- package/dist/src/lib/virtual-module-generators.d.ts +57 -0
- package/dist/src/lib/virtual-module-generators.d.ts.map +1 -0
- package/dist/src/lib/virtual-module-generators.js +263 -0
- package/dist/src/lib/withHydration.d.ts +51 -0
- package/dist/src/lib/withHydration.d.ts.map +1 -0
- package/dist/src/lib/withHydration.js +49 -0
- package/dist/src/loader.d.ts +14 -0
- package/dist/src/loader.d.ts.map +1 -0
- package/dist/src/loader.js +89 -0
- package/dist/src/locales-helpers.d.ts +61 -0
- package/dist/src/locales-helpers.d.ts.map +1 -0
- package/dist/src/locales-helpers.js +49 -0
- package/dist/src/mime-types.d.ts +3 -0
- package/dist/src/mime-types.d.ts.map +1 -0
- package/dist/src/mime-types.js +19 -0
- package/dist/src/path-validation.d.ts +8 -0
- package/dist/src/path-validation.d.ts.map +1 -0
- package/dist/src/path-validation.js +12 -0
- package/dist/src/plugin-spa.d.ts +164 -0
- package/dist/src/plugin-spa.d.ts.map +1 -0
- package/dist/src/plugin-spa.js +972 -0
- package/dist/src/safe-json-stringify.d.ts +13 -0
- package/dist/src/safe-json-stringify.d.ts.map +1 -0
- package/dist/src/safe-json-stringify.js +6 -0
- package/dist/src/site-styles/content-wrapper-endpoint.d.ts +76 -0
- package/dist/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -0
- package/dist/src/site-styles/content-wrapper-endpoint.js +227 -0
- package/dist/src/site-styles/render-endpoint.d.ts +55 -0
- package/dist/src/site-styles/render-endpoint.d.ts.map +1 -0
- package/dist/src/site-styles/render-endpoint.js +263 -0
- package/dist/src/site-styles/styles-endpoint.d.ts +61 -0
- package/dist/src/site-styles/styles-endpoint.d.ts.map +1 -0
- package/dist/src/site-styles/styles-endpoint.js +158 -0
- package/dist/src/types.d.ts +627 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +1 -0
- package/dist/{types-Bsd_qENn.d.mts → types-CS9neadI.d.mts} +193 -3
- package/dist/types-CS9neadI.d.mts.map +1 -0
- package/dist/virtual-modules.d.ts +155 -0
- package/dist/{withHydration-692fMySA.mjs → withHydration-C256ox_6.mjs} +6 -2
- package/dist/withHydration-C256ox_6.mjs.map +1 -0
- package/dist/{withHydration-BGgQDE-H.d.mts → withHydration-DkKpkmzJ.d.mts} +5 -2
- package/dist/withHydration-DkKpkmzJ.d.mts.map +1 -0
- package/package.json +106 -40
- package/dist/cms-handler.d.mts.map +0 -1
- package/dist/cms-handler.mjs.map +0 -1
- package/dist/collections.mjs.map +0 -1
- package/dist/handlers/page-handler.astro +0 -299
- package/dist/loader-W3i9kf3p.mjs +0 -61
- package/dist/loader-W3i9kf3p.mjs.map +0 -1
- package/dist/types-Bsd_qENn.d.mts.map +0 -1
- package/dist/withHydration-692fMySA.mjs.map +0 -1
- package/dist/withHydration-BGgQDE-H.d.mts.map +0 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
/** Connect-compatible middleware handler — see render-endpoint.ts. */
|
|
3
|
+
type NextHandleFunction = (req: IncomingMessage, res: ServerResponse, next: (err?: unknown) => void) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Vite middleware that returns the concatenated CSS for a route URL.
|
|
6
|
+
*
|
|
7
|
+
* Used by the CMS editor SPA to fetch the styles that apply to the page
|
|
8
|
+
* being edited so the editor renders content with the same CSS as the
|
|
9
|
+
* published page.
|
|
10
|
+
*
|
|
11
|
+
* Mechanism (host-agnostic):
|
|
12
|
+
*
|
|
13
|
+
* 1. HTTP-fetch the live HTML at the route URL from the running dev
|
|
14
|
+
* server. This is the same HTML a browser would receive — it lists
|
|
15
|
+
* every stylesheet the page actually loads.
|
|
16
|
+
* 2. Pull the content of every `<style>...</style>` block (where dev-
|
|
17
|
+
* mode Astro inlines its component / Tailwind / user CSS).
|
|
18
|
+
* 3. Pull every `<link rel="stylesheet" href="…">` (excluding
|
|
19
|
+
* `media="print"`) and fetch each one with `?direct` so the dev
|
|
20
|
+
* server returns the raw CSS instead of the HMR JS wrapper.
|
|
21
|
+
* 4. Concatenate in source order and return as `text/css`.
|
|
22
|
+
*
|
|
23
|
+
* Why this instead of Astro's `devCSSMap`:
|
|
24
|
+
*
|
|
25
|
+
* - `devCSSMap` is an Astro-internal virtual module. It only surfaces
|
|
26
|
+
* CSS that flows through Astro's `.astro` component graph. Anything
|
|
27
|
+
* emitted by an Astro integration as a STANDALONE asset (the
|
|
28
|
+
* canonical example is expressive-code's `/_astro/ec.*.css`) sits
|
|
29
|
+
* outside that graph and never reaches the editor through devCSSMap.
|
|
30
|
+
* - Scraping the live HTML reads what the published page actually
|
|
31
|
+
* paints with — the same stylesheets the user will see in the
|
|
32
|
+
* browser. No dependency on a specific framework's internal API.
|
|
33
|
+
*
|
|
34
|
+
* Known limitations (rare on Astro sites):
|
|
35
|
+
*
|
|
36
|
+
* - CSS injected by JavaScript at runtime (`document.head.appendChild`)
|
|
37
|
+
* isn't in the initial HTML, so we don't see it. Affects view-
|
|
38
|
+
* transition handlers and third-party widget snippets.
|
|
39
|
+
* - CSS-in-JS libraries (styled-components, emotion) generate styles
|
|
40
|
+
* during client render and have the same blind spot.
|
|
41
|
+
* - Cross-origin stylesheets the dev server can't reach get logged
|
|
42
|
+
* and skipped (graceful degradation, not silent failure).
|
|
43
|
+
*/
|
|
44
|
+
export declare function createStylesEndpoint(): NextHandleFunction;
|
|
45
|
+
interface DiscoveredStyle {
|
|
46
|
+
/** Diagnostic label — either an inline `<style>` marker or the link href. */
|
|
47
|
+
url: string;
|
|
48
|
+
/** Raw CSS text. */
|
|
49
|
+
css: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Read every `<style>` block and `<link rel="stylesheet">` from the
|
|
53
|
+
* HTML in their original source order. Inline `<style>` blocks are
|
|
54
|
+
* captured verbatim; link tags are fetched separately (raw CSS via
|
|
55
|
+
* `?direct`). Print-media stylesheets are skipped.
|
|
56
|
+
*
|
|
57
|
+
* Exported for unit testing.
|
|
58
|
+
*/
|
|
59
|
+
export declare function collectStylesFromHtml(html: string, origin: string, cookie: string | undefined): Promise<DiscoveredStyle[]>;
|
|
60
|
+
export {};
|
|
61
|
+
//# sourceMappingURL=styles-endpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles-endpoint.d.ts","sourceRoot":"","sources":["../../../src/site-styles/styles-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEjE,sEAAsE;AACtE,KAAK,kBAAkB,GAAG,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,KAAK,IAAI,KAAK,IAAI,CAAC;AAE7G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,oBAAoB,IAAI,kBAAkB,CAgDzD;AAED,UAAU,eAAe;IACvB,6EAA6E;IAC7E,GAAG,EAAE,MAAM,CAAC;IACZ,oBAAoB;IACpB,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,OAAO,CAAC,eAAe,EAAE,CAAC,CA2C5B"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite middleware that returns the concatenated CSS for a route URL.
|
|
3
|
+
*
|
|
4
|
+
* Used by the CMS editor SPA to fetch the styles that apply to the page
|
|
5
|
+
* being edited so the editor renders content with the same CSS as the
|
|
6
|
+
* published page.
|
|
7
|
+
*
|
|
8
|
+
* Mechanism (host-agnostic):
|
|
9
|
+
*
|
|
10
|
+
* 1. HTTP-fetch the live HTML at the route URL from the running dev
|
|
11
|
+
* server. This is the same HTML a browser would receive — it lists
|
|
12
|
+
* every stylesheet the page actually loads.
|
|
13
|
+
* 2. Pull the content of every `<style>...</style>` block (where dev-
|
|
14
|
+
* mode Astro inlines its component / Tailwind / user CSS).
|
|
15
|
+
* 3. Pull every `<link rel="stylesheet" href="…">` (excluding
|
|
16
|
+
* `media="print"`) and fetch each one with `?direct` so the dev
|
|
17
|
+
* server returns the raw CSS instead of the HMR JS wrapper.
|
|
18
|
+
* 4. Concatenate in source order and return as `text/css`.
|
|
19
|
+
*
|
|
20
|
+
* Why this instead of Astro's `devCSSMap`:
|
|
21
|
+
*
|
|
22
|
+
* - `devCSSMap` is an Astro-internal virtual module. It only surfaces
|
|
23
|
+
* CSS that flows through Astro's `.astro` component graph. Anything
|
|
24
|
+
* emitted by an Astro integration as a STANDALONE asset (the
|
|
25
|
+
* canonical example is expressive-code's `/_astro/ec.*.css`) sits
|
|
26
|
+
* outside that graph and never reaches the editor through devCSSMap.
|
|
27
|
+
* - Scraping the live HTML reads what the published page actually
|
|
28
|
+
* paints with — the same stylesheets the user will see in the
|
|
29
|
+
* browser. No dependency on a specific framework's internal API.
|
|
30
|
+
*
|
|
31
|
+
* Known limitations (rare on Astro sites):
|
|
32
|
+
*
|
|
33
|
+
* - CSS injected by JavaScript at runtime (`document.head.appendChild`)
|
|
34
|
+
* isn't in the initial HTML, so we don't see it. Affects view-
|
|
35
|
+
* transition handlers and third-party widget snippets.
|
|
36
|
+
* - CSS-in-JS libraries (styled-components, emotion) generate styles
|
|
37
|
+
* during client render and have the same blind spot.
|
|
38
|
+
* - Cross-origin stylesheets the dev server can't reach get logged
|
|
39
|
+
* and skipped (graceful degradation, not silent failure).
|
|
40
|
+
*/
|
|
41
|
+
export function createStylesEndpoint() {
|
|
42
|
+
return async (req, res, _next) => {
|
|
43
|
+
try {
|
|
44
|
+
const parsed = new URL(req.url ?? '', 'http://localhost');
|
|
45
|
+
const routeUrl = parsed.searchParams.get('url');
|
|
46
|
+
if (!routeUrl) {
|
|
47
|
+
res.statusCode = 400;
|
|
48
|
+
res.setHeader('content-type', 'text/plain');
|
|
49
|
+
res.end('Missing required query parameter: url');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const host = req.headers.host ?? 'localhost:4321';
|
|
53
|
+
const protocol = req.headers['x-forwarded-proto'] ?? 'http';
|
|
54
|
+
const origin = `${protocol}://${host}`;
|
|
55
|
+
const cookie = req.headers.cookie;
|
|
56
|
+
const liveResponse = await fetch(`${origin}${routeUrl}`, {
|
|
57
|
+
headers: cookie ? { cookie } : undefined,
|
|
58
|
+
});
|
|
59
|
+
// Propagate upstream non-200 status (eg 404 for unknown routes)
|
|
60
|
+
// so the editor doesn't accidentally render a 404 page's CSS.
|
|
61
|
+
if (!liveResponse.ok) {
|
|
62
|
+
res.statusCode = liveResponse.status;
|
|
63
|
+
res.setHeader('content-type', 'text/plain');
|
|
64
|
+
res.end(`Upstream route returned ${liveResponse.status}: ${routeUrl}`);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const html = await liveResponse.text();
|
|
68
|
+
const styles = await collectStylesFromHtml(html, origin, cookie);
|
|
69
|
+
const body = styles.map((s) => `/* ${s.url} */\n${s.css}`).join('\n\n');
|
|
70
|
+
res.statusCode = 200;
|
|
71
|
+
res.setHeader('content-type', 'text/css; charset=utf-8');
|
|
72
|
+
// No-cache: dev HMR rewrites stylesheet contents in place; the
|
|
73
|
+
// editor refetches on page switch, so cache invalidation is the
|
|
74
|
+
// client's job, not the server's.
|
|
75
|
+
res.setHeader('cache-control', 'no-store');
|
|
76
|
+
res.end(body);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
res.statusCode = 500;
|
|
80
|
+
res.setHeader('content-type', 'text/plain');
|
|
81
|
+
res.end(`Styles discovery failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Read every `<style>` block and `<link rel="stylesheet">` from the
|
|
87
|
+
* HTML in their original source order. Inline `<style>` blocks are
|
|
88
|
+
* captured verbatim; link tags are fetched separately (raw CSS via
|
|
89
|
+
* `?direct`). Print-media stylesheets are skipped.
|
|
90
|
+
*
|
|
91
|
+
* Exported for unit testing.
|
|
92
|
+
*/
|
|
93
|
+
export async function collectStylesFromHtml(html, origin, cookie) {
|
|
94
|
+
// Strip comments first so opening-tag-shaped strings inside them
|
|
95
|
+
// don't pollute the regex walk.
|
|
96
|
+
const cleaned = html.replace(/<!--[\s\S]*?-->/g, '');
|
|
97
|
+
const entries = [];
|
|
98
|
+
const styleRe = /<style\b([^>]*)>([\s\S]*?)<\/style>/gi;
|
|
99
|
+
let match;
|
|
100
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: regex exec iterator
|
|
101
|
+
while ((match = styleRe.exec(cleaned)) !== null) {
|
|
102
|
+
const attrs = match[1];
|
|
103
|
+
if (/media\s*=\s*["']?print/i.test(attrs))
|
|
104
|
+
continue;
|
|
105
|
+
const css = match[2];
|
|
106
|
+
const idAttr = attrs.match(/data-vite-dev-id="([^"]+)"/);
|
|
107
|
+
const label = idAttr ? idAttr[1] : `<style#${match.index}>`;
|
|
108
|
+
const captured = { url: label, css };
|
|
109
|
+
entries.push({ index: match.index, fetch: () => Promise.resolve(captured) });
|
|
110
|
+
}
|
|
111
|
+
const linkRe = /<link\b([^>]*)\/?>/gi;
|
|
112
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: regex exec iterator
|
|
113
|
+
while ((match = linkRe.exec(cleaned)) !== null) {
|
|
114
|
+
const attrs = match[1];
|
|
115
|
+
if (!/rel\s*=\s*["']?stylesheet["']?/i.test(attrs))
|
|
116
|
+
continue;
|
|
117
|
+
if (/media\s*=\s*["']?print/i.test(attrs))
|
|
118
|
+
continue;
|
|
119
|
+
const hrefMatch = attrs.match(/href\s*=\s*"([^"]+)"|href\s*=\s*'([^']+)'/);
|
|
120
|
+
if (!hrefMatch)
|
|
121
|
+
continue;
|
|
122
|
+
const href = hrefMatch[1] ?? hrefMatch[2];
|
|
123
|
+
const index = match.index;
|
|
124
|
+
entries.push({ index, fetch: () => fetchStylesheet(href, origin, cookie) });
|
|
125
|
+
}
|
|
126
|
+
// Source-order sort (style blocks and link tags interleave in HTML).
|
|
127
|
+
entries.sort((a, b) => a.index - b.index);
|
|
128
|
+
const results = await Promise.all(entries.map((e) => e.fetch()));
|
|
129
|
+
return results.filter((r) => r !== null);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Fetch a stylesheet by href and return its raw CSS. Vite serves CSS
|
|
133
|
+
* files as JS HMR wrappers by default; `?direct` flips that to raw CSS
|
|
134
|
+
* output. Absolute URLs are fetched as-is; root-relative paths are
|
|
135
|
+
* resolved against the dev server origin so cross-page link tags work.
|
|
136
|
+
*/
|
|
137
|
+
async function fetchStylesheet(href, origin, cookie) {
|
|
138
|
+
// Absolute URL (`https://…`) or relative — both need `?direct` only
|
|
139
|
+
// when targeting our own dev server. External CDNs serve raw CSS
|
|
140
|
+
// already; appending `?direct` would 404 there.
|
|
141
|
+
const isLocal = !/^https?:\/\//i.test(href) || href.startsWith(origin);
|
|
142
|
+
const target = isLocal
|
|
143
|
+
? `${origin}${href.startsWith('/') ? href : `/${href}`}${href.includes('?') ? '&direct' : '?direct'}`
|
|
144
|
+
: href;
|
|
145
|
+
try {
|
|
146
|
+
const res = await fetch(target, { headers: cookie ? { cookie } : undefined });
|
|
147
|
+
if (!res.ok) {
|
|
148
|
+
console.warn(`[conloca:css] link fetch returned ${res.status} for ${href}`);
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
const css = await res.text();
|
|
152
|
+
return { url: href, css };
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
console.warn(`[conloca:css] link fetch failed for ${href}:`, err);
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
}
|