@tenphi/tasty 0.0.0-snapshot.1d29633 → 0.0.0-snapshot.1f1c00a
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 +152 -134
- package/dist/{babel-Cg-mJV_t.d.ts → babel-rZcEwPLM.d.ts} +2 -3
- package/dist/chunks/async-storage-CG5HnUT5.js +20 -0
- package/dist/chunks/async-storage-CG5HnUT5.js.map +1 -0
- package/dist/chunks/build-config-CL4eRu2z.js +42 -0
- package/dist/chunks/build-config-CL4eRu2z.js.map +1 -0
- package/dist/{collector-BMT05AmU.js → chunks/collector-D2ARGT2L.js} +21 -117
- package/dist/chunks/collector-D2ARGT2L.js.map +1 -0
- package/dist/chunks/config-engine-DEmmPPdp.js +272 -0
- package/dist/chunks/config-engine-DEmmPPdp.js.map +1 -0
- package/dist/chunks/css-definitions-DotDkIXt.js +876 -0
- package/dist/chunks/css-definitions-DotDkIXt.js.map +1 -0
- package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
- package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
- package/dist/chunks/debug-D8pg9RGI.js +502 -0
- package/dist/chunks/debug-D8pg9RGI.js.map +1 -0
- package/dist/chunks/dsl-DRhFWQzo.js +1378 -0
- package/dist/chunks/dsl-DRhFWQzo.js.map +1 -0
- package/dist/chunks/hydration-TRcz5vnk.js +41 -0
- package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
- package/dist/chunks/react-runtime-BpxlOTbO.js +562 -0
- package/dist/chunks/react-runtime-BpxlOTbO.js.map +1 -0
- package/dist/chunks/runtime-engine-CKFXUH-A.js +2416 -0
- package/dist/chunks/runtime-engine-CKFXUH-A.js.map +1 -0
- package/dist/chunks/runtime-state-BxaLhVdP.js +127 -0
- package/dist/chunks/runtime-state-BxaLhVdP.js.map +1 -0
- package/dist/{merge-styles-CkAcnd0Z.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
- package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
- package/dist/chunks/style-engine-BBbBuSkT.js +5260 -0
- package/dist/chunks/style-engine-BBbBuSkT.js.map +1 -0
- package/dist/{css-writer-b02uBqNF.js → chunks/zero-engine-gJrKBRiw.js} +6 -121
- package/dist/chunks/zero-engine-gJrKBRiw.js.map +1 -0
- package/dist/{collector-BFuqdF2F.d.ts → collector-w4mBj5gd.d.ts} +23 -4
- package/dist/{config-DmFxnBxg.d.ts → config-CZWCzBr6.d.ts} +171 -72
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +9 -6
- package/dist/{index-D1nMkpUe.d.ts → index-G9JuwM9p.d.ts} +263 -247
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -921
- package/dist/{merge-styles-Cx_6ySBv.d.ts → merge-styles-VXwJ0Frr.d.ts} +2 -3
- package/dist/ssr/astro-client.d.ts +1 -1
- package/dist/ssr/astro-client.js +1 -14
- package/dist/ssr/astro-client.js.map +1 -1
- package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
- package/dist/ssr/astro-middleware-extract-static.js +9 -0
- package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
- package/dist/ssr/astro-middleware-extract.d.ts +10 -0
- package/dist/ssr/astro-middleware-extract.js +9 -0
- package/dist/ssr/astro-middleware-extract.js.map +1 -0
- package/dist/ssr/astro-middleware-static.d.ts +3 -2
- package/dist/ssr/astro-middleware-static.js +0 -11
- package/dist/ssr/astro-middleware-static.js.map +1 -1
- package/dist/ssr/astro-middleware.d.ts +3 -2
- package/dist/ssr/astro-middleware.js +0 -12
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +40 -6
- package/dist/ssr/astro.js +157 -93
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/index.d.ts +10 -11
- package/dist/ssr/index.js +4 -4
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +64 -0
- package/dist/ssr/next-config.js +128 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +9 -8
- package/dist/ssr/next.js +29 -43
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +8 -9
- package/dist/static/index.js +4 -22
- package/dist/static/index.js.map +1 -1
- package/dist/static/inject.d.ts +1 -2
- package/dist/{index-LC3O3Jj4.d.ts → types-JEY8PVYP.d.ts} +862 -811
- package/dist/zero/babel.d.ts +1 -1
- package/dist/zero/babel.js +41 -107
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +6 -7
- package/dist/zero/index.js +1 -1
- package/dist/zero/next.d.ts +3 -5
- package/dist/zero/next.js +0 -31
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +13 -8
- package/docs/adoption.md +56 -31
- package/docs/ai-agents.md +107 -80
- package/docs/comparison.md +69 -40
- package/docs/configuration.md +179 -114
- package/docs/debug.md +19 -7
- package/docs/design-system.md +41 -22
- package/docs/dsl.md +310 -201
- package/docs/getting-started.md +64 -41
- package/docs/injector.md +63 -26
- package/docs/methodology.md +44 -38
- package/docs/migration-v3.md +49 -49
- package/docs/pipeline.md +32 -8
- package/docs/plugins.md +38 -34
- package/docs/react-api.md +67 -44
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +219 -61
- package/docs/styles.md +95 -18
- package/docs/tasty-static.md +138 -105
- package/package.json +104 -33
- package/dist/async-storage-DKK-wTD4.js +0 -44
- package/dist/async-storage-DKK-wTD4.js.map +0 -1
- package/dist/collector-BMT05AmU.js.map +0 -1
- package/dist/config-DF93rL3u.js +0 -12661
- package/dist/config-DF93rL3u.js.map +0 -1
- package/dist/context-CA8YKeMn.js +0 -24
- package/dist/context-CA8YKeMn.js.map +0 -1
- package/dist/core-B5ybnMP1.js +0 -1529
- package/dist/core-B5ybnMP1.js.map +0 -1
- package/dist/css-writer-b02uBqNF.js.map +0 -1
- package/dist/format-global-rules-DklyaXv-.js +0 -22
- package/dist/format-global-rules-DklyaXv-.js.map +0 -1
- package/dist/format-rules-Cs4e3M9m.js +0 -130
- package/dist/format-rules-Cs4e3M9m.js.map +0 -1
- package/dist/hydrate-aaUSNJZJ.js +0 -37
- package/dist/hydrate-aaUSNJZJ.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-BedEzEXk.js +0 -424
- package/dist/keyframes-BedEzEXk.js.map +0 -1
- package/dist/merge-styles-CkAcnd0Z.js.map +0 -1
- package/dist/resolve-recipes-CiyLtJG9.js +0 -144
- package/dist/resolve-recipes-CiyLtJG9.js.map +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Y as Styles } from "./types-JEY8PVYP.js";
|
|
3
2
|
//#region src/utils/merge-styles.d.ts
|
|
4
3
|
declare function mergeStyles(...objects: (Styles | undefined | null)[]): Styles;
|
|
5
4
|
//#endregion
|
|
6
5
|
export { mergeStyles as t };
|
|
7
|
-
//# sourceMappingURL=merge-styles-
|
|
6
|
+
//# sourceMappingURL=merge-styles-VXwJ0Frr.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {}
|
package/dist/ssr/astro-client.js
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
import { t as hydrateTastyClasses } from "../
|
|
1
|
+
import { t as hydrateTastyClasses } from "../chunks/hydration-TRcz5vnk.js";
|
|
2
2
|
//#region src/ssr/astro-client.ts
|
|
3
|
-
/**
|
|
4
|
-
* Client-side cache hydration for Astro islands.
|
|
5
|
-
*
|
|
6
|
-
* Reads the class name list from `window.__TASTY__` (populated by
|
|
7
|
-
* inline scripts emitted during SSR) and pre-populates the injector
|
|
8
|
-
* so island hydration skips the style pipeline entirely.
|
|
9
|
-
*
|
|
10
|
-
* This module is browser-safe — it does NOT import node:async_hooks.
|
|
11
|
-
*
|
|
12
|
-
* Usage:
|
|
13
|
-
* - Automatically injected by tastyIntegration() via injectScript('before-hydration')
|
|
14
|
-
* - Can be imported manually: `import '@tenphi/tasty/ssr/astro-client'`
|
|
15
|
-
*/
|
|
16
3
|
if (typeof window !== "undefined") hydrateTastyClasses();
|
|
17
4
|
//#endregion
|
|
18
5
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"astro-client.js","names":[],"sources":["../../src/ssr/astro-client.ts"],"sourcesContent":["/**\n * Client-side cache hydration for Astro islands.\n *\n * Reads the class name list from `window.__TASTY__` (populated by\n * inline scripts emitted during SSR) and pre-populates the injector\n * so island hydration skips the style pipeline entirely.\n *\n * This module is browser-safe — it does NOT import node:async_hooks.\n *\n * Usage:\n * - Automatically injected by tastyIntegration() via injectScript('before-hydration')\n * - Can be imported manually: `import '@tenphi/tasty/ssr/astro-client'`\n */\n\nimport { hydrateTastyClasses } from './hydrate';\n\nif (typeof window !== 'undefined') {\n hydrateTastyClasses();\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"astro-client.js","names":[],"sources":["../../src/ssr/astro-client.ts"],"sourcesContent":["/**\n * Client-side cache hydration for Astro islands.\n *\n * Reads the class name list from `window.__TASTY__` (populated by\n * inline scripts emitted during SSR) and pre-populates the injector\n * so island hydration skips the style pipeline entirely.\n *\n * This module is browser-safe — it does NOT import node:async_hooks.\n *\n * Usage:\n * - Automatically injected by tastyIntegration() via injectScript('before-hydration')\n * - Can be imported manually: `import '@tenphi/tasty/ssr/astro-client'`\n */\n\nimport { hydrateTastyClasses } from './hydrate';\n\nif (typeof window !== 'undefined') {\n hydrateTastyClasses();\n}\n"],"mappings":";;AAgBA,IAAI,OAAO,WAAW,aACpB,oBAAoB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/ssr/astro-middleware-extract-static.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Prerender-extraction middleware entrypoint for sites without islands.
|
|
4
|
+
* Exported only so Astro can resolve it through the package exports map.
|
|
5
|
+
*/
|
|
6
|
+
export declare const onRequest: (context: {
|
|
7
|
+
isPrerendered?: boolean;
|
|
8
|
+
}, next: () => Promise<Response>) => Promise<Response>;
|
|
9
|
+
//#endregion
|
|
10
|
+
//# sourceMappingURL=astro-middleware-extract-static.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"astro-middleware-extract-static.js","names":[],"sources":["../../src/ssr/astro-middleware-extract-static.ts"],"sourcesContent":["/**\n * Prerender-extraction middleware entrypoint for sites without islands.\n * Exported only so Astro can resolve it through the package exports map.\n */\n\nimport { tastyMiddleware } from './astro';\n\nconst options = {\n transferCache: false,\n extractionMetadata: true,\n};\n\nexport const onRequest = tastyMiddleware(options);\n"],"mappings":";AAYA,MAAa,YAAY,gBAAgB;CAJvC,eAAe;CACf,oBAAoB;AAGmB,CAAO"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/ssr/astro-middleware-extract.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Prerender-extraction middleware entrypoint with island cache transfer.
|
|
4
|
+
* Exported only so Astro can resolve it through the package exports map.
|
|
5
|
+
*/
|
|
6
|
+
export declare const onRequest: (context: {
|
|
7
|
+
isPrerendered?: boolean;
|
|
8
|
+
}, next: () => Promise<Response>) => Promise<Response>;
|
|
9
|
+
//#endregion
|
|
10
|
+
//# sourceMappingURL=astro-middleware-extract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"astro-middleware-extract.js","names":[],"sources":["../../src/ssr/astro-middleware-extract.ts"],"sourcesContent":["/**\n * Prerender-extraction middleware entrypoint with island cache transfer.\n * Exported only so Astro can resolve it through the package exports map.\n */\n\nimport { tastyMiddleware } from './astro';\n\nconst options = {\n transferCache: true,\n extractionMetadata: true,\n};\n\nexport const onRequest = tastyMiddleware(options);\n"],"mappings":";AAYA,MAAa,YAAY,gBAAgB;CAJvC,eAAe;CACf,oBAAoB;AAGmB,CAAO"}
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* Identical to `./astro-middleware` except that no class-list `<script>` is
|
|
11
11
|
* emitted, so a site without `client:*` islands ships zero client JavaScript.
|
|
12
12
|
*/
|
|
13
|
-
declare const onRequest: (
|
|
13
|
+
export declare const onRequest: (context: {
|
|
14
|
+
isPrerendered?: boolean;
|
|
15
|
+
}, next: () => Promise<Response>) => Promise<Response>;
|
|
14
16
|
//#endregion
|
|
15
|
-
export { onRequest };
|
|
16
17
|
//# sourceMappingURL=astro-middleware-static.d.ts.map
|
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
import { tastyMiddleware } from "./astro.js";
|
|
2
2
|
//#region src/ssr/astro-middleware-static.ts
|
|
3
|
-
/**
|
|
4
|
-
* Astro middleware entrypoint for `tastyIntegration({ islands: false })`.
|
|
5
|
-
*
|
|
6
|
-
* Registered via `addMiddleware()` as
|
|
7
|
-
* `@tenphi/tasty/ssr/astro-middleware-static`. Exposed as a package subpath
|
|
8
|
-
* only so Astro can resolve it — use `tastyMiddleware({ transferCache: false })`
|
|
9
|
-
* directly if you need manual middleware composition.
|
|
10
|
-
*
|
|
11
|
-
* Identical to `./astro-middleware` except that no class-list `<script>` is
|
|
12
|
-
* emitted, so a site without `client:*` islands ships zero client JavaScript.
|
|
13
|
-
*/
|
|
14
3
|
const onRequest = tastyMiddleware({ transferCache: false });
|
|
15
4
|
//#endregion
|
|
16
5
|
export { onRequest };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"astro-middleware-static.js","names":[],"sources":["../../src/ssr/astro-middleware-static.ts"],"sourcesContent":["/**\n * Astro middleware entrypoint for `tastyIntegration({ islands: false })`.\n *\n * Registered via `addMiddleware()` as\n * `@tenphi/tasty/ssr/astro-middleware-static`. Exposed as a package subpath\n * only so Astro can resolve it — use `tastyMiddleware({ transferCache: false })`\n * directly if you need manual middleware composition.\n *\n * Identical to `./astro-middleware` except that no class-list `<script>` is\n * emitted, so a site without `client:*` islands ships zero client JavaScript.\n */\n\nimport { tastyMiddleware } from './astro';\n\nexport const onRequest = tastyMiddleware({ transferCache: false });\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"astro-middleware-static.js","names":[],"sources":["../../src/ssr/astro-middleware-static.ts"],"sourcesContent":["/**\n * Astro middleware entrypoint for `tastyIntegration({ islands: false })`.\n *\n * Registered via `addMiddleware()` as\n * `@tenphi/tasty/ssr/astro-middleware-static`. Exposed as a package subpath\n * only so Astro can resolve it — use `tastyMiddleware({ transferCache: false })`\n * directly if you need manual middleware composition.\n *\n * Identical to `./astro-middleware` except that no class-list `<script>` is\n * emitted, so a site without `client:*` islands ships zero client JavaScript.\n */\n\nimport { tastyMiddleware } from './astro';\n\nexport const onRequest = tastyMiddleware({ transferCache: false });\n"],"mappings":";;AAcA,MAAa,YAAY,gBAAgB,EAAE,eAAe,MAAM,CAAC"}
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
* `./astro-middleware-static` for the variant used by
|
|
12
12
|
* `tastyIntegration({ islands: false })`.
|
|
13
13
|
*/
|
|
14
|
-
declare const onRequest: (
|
|
14
|
+
export declare const onRequest: (context: {
|
|
15
|
+
isPrerendered?: boolean;
|
|
16
|
+
}, next: () => Promise<Response>) => Promise<Response>;
|
|
15
17
|
//#endregion
|
|
16
|
-
export { onRequest };
|
|
17
18
|
//# sourceMappingURL=astro-middleware.d.ts.map
|
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
import { tastyMiddleware } from "./astro.js";
|
|
2
2
|
//#region src/ssr/astro-middleware.ts
|
|
3
|
-
/**
|
|
4
|
-
* Astro middleware entrypoint for `tastyIntegration()`.
|
|
5
|
-
*
|
|
6
|
-
* Registered via `addMiddleware()` as `@tenphi/tasty/ssr/astro-middleware`.
|
|
7
|
-
* Exposed as a package subpath only so Astro can resolve it — use
|
|
8
|
-
* `tastyMiddleware()` directly if you need manual middleware composition.
|
|
9
|
-
*
|
|
10
|
-
* This is the islands variant: the rendered class list is transferred to the
|
|
11
|
-
* client so hydrating islands skip the style pipeline. See
|
|
12
|
-
* `./astro-middleware-static` for the variant used by
|
|
13
|
-
* `tastyIntegration({ islands: false })`.
|
|
14
|
-
*/
|
|
15
3
|
const onRequest = tastyMiddleware({ transferCache: true });
|
|
16
4
|
//#endregion
|
|
17
5
|
export { onRequest };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"astro-middleware.js","names":[],"sources":["../../src/ssr/astro-middleware.ts"],"sourcesContent":["/**\n * Astro middleware entrypoint for `tastyIntegration()`.\n *\n * Registered via `addMiddleware()` as `@tenphi/tasty/ssr/astro-middleware`.\n * Exposed as a package subpath only so Astro can resolve it — use\n * `tastyMiddleware()` directly if you need manual middleware composition.\n *\n * This is the islands variant: the rendered class list is transferred to the\n * client so hydrating islands skip the style pipeline. See\n * `./astro-middleware-static` for the variant used by\n * `tastyIntegration({ islands: false })`.\n */\n\nimport { tastyMiddleware } from './astro';\n\nexport const onRequest = tastyMiddleware({ transferCache: true });\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"astro-middleware.js","names":[],"sources":["../../src/ssr/astro-middleware.ts"],"sourcesContent":["/**\n * Astro middleware entrypoint for `tastyIntegration()`.\n *\n * Registered via `addMiddleware()` as `@tenphi/tasty/ssr/astro-middleware`.\n * Exposed as a package subpath only so Astro can resolve it — use\n * `tastyMiddleware()` directly if you need manual middleware composition.\n *\n * This is the islands variant: the rendered class list is transferred to the\n * client so hydrating islands skip the style pipeline. See\n * `./astro-middleware-static` for the variant used by\n * `tastyIntegration({ islands: false })`.\n */\n\nimport { tastyMiddleware } from './astro';\n\nexport const onRequest = tastyMiddleware({ transferCache: true });\n"],"mappings":";;AAeA,MAAa,YAAY,gBAAgB,EAAE,eAAe,KAAK,CAAC"}
|
package/dist/ssr/astro.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* Import from '@tenphi/tasty/ssr/astro'.
|
|
10
10
|
*/
|
|
11
|
-
interface TastyMiddlewareOptions {
|
|
11
|
+
export interface TastyMiddlewareOptions {
|
|
12
12
|
/**
|
|
13
13
|
* Whether to embed the class-list script for client hydration.
|
|
14
14
|
* Set to false to skip class transfer (e.g. for CSP restrictions).
|
|
@@ -43,8 +43,20 @@ interface TastyMiddlewareOptions {
|
|
|
43
43
|
* );
|
|
44
44
|
* ```
|
|
45
45
|
*/
|
|
46
|
-
declare function tastyMiddleware(options?: TastyMiddlewareOptions): (
|
|
47
|
-
|
|
46
|
+
export declare function tastyMiddleware(options?: TastyMiddlewareOptions): (context: {
|
|
47
|
+
isPrerendered?: boolean;
|
|
48
|
+
}, next: () => Promise<Response>) => Promise<Response>;
|
|
49
|
+
export interface TastyIntegrationCSSOptions {
|
|
50
|
+
/**
|
|
51
|
+
* CSS delivery mode. Extraction only applies to prerendered builds.
|
|
52
|
+
* Extracted CSS preserves resource URLs verbatim, so use absolute URLs or
|
|
53
|
+
* data URLs. Root-relative URLs are also supported unless `assetsPrefix`
|
|
54
|
+
* sends CSS to an external origin. The build rejects resource URLs whose
|
|
55
|
+
* targets would change after extraction.
|
|
56
|
+
*/
|
|
57
|
+
mode?: 'inline' | 'extract';
|
|
58
|
+
}
|
|
59
|
+
export interface TastyIntegrationOptions {
|
|
48
60
|
/**
|
|
49
61
|
* Enable island hydration support.
|
|
50
62
|
*
|
|
@@ -57,6 +69,8 @@ interface TastyIntegrationOptions {
|
|
|
57
69
|
* directives.
|
|
58
70
|
*/
|
|
59
71
|
islands?: boolean;
|
|
72
|
+
/** Configure inline or build-wide extracted CSS delivery. */
|
|
73
|
+
css?: TastyIntegrationCSSOptions;
|
|
60
74
|
}
|
|
61
75
|
/**
|
|
62
76
|
* Astro integration that automatically sets up Tasty SSR.
|
|
@@ -84,10 +98,30 @@ interface TastyIntegrationOptions {
|
|
|
84
98
|
* });
|
|
85
99
|
* ```
|
|
86
100
|
*/
|
|
87
|
-
declare function tastyIntegration(options?: TastyIntegrationOptions): {
|
|
101
|
+
export declare function tastyIntegration(options?: TastyIntegrationOptions): {
|
|
88
102
|
name: string;
|
|
89
|
-
hooks:
|
|
103
|
+
hooks: {
|
|
104
|
+
'astro:config:setup': ({ addMiddleware, injectScript }: {
|
|
105
|
+
addMiddleware: (middleware: {
|
|
106
|
+
entrypoint: string | URL;
|
|
107
|
+
order: "pre" | "post";
|
|
108
|
+
}) => void;
|
|
109
|
+
injectScript: (stage: "head-inline" | "before-hydration" | "page" | "page-ssr", content: string) => void;
|
|
110
|
+
}) => void;
|
|
111
|
+
'astro:config:done': ({ config }: {
|
|
112
|
+
config: {
|
|
113
|
+
base?: string;
|
|
114
|
+
site?: URL;
|
|
115
|
+
build?: {
|
|
116
|
+
assets?: string;
|
|
117
|
+
assetsPrefix?: string | Record<string, string>;
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
}) => void;
|
|
121
|
+
'astro:build:done': ({ dir }: {
|
|
122
|
+
dir: URL;
|
|
123
|
+
}) => Promise<void>;
|
|
124
|
+
};
|
|
90
125
|
};
|
|
91
126
|
//#endregion
|
|
92
|
-
export { TastyIntegrationOptions, TastyMiddlewareOptions, tastyIntegration, tastyMiddleware };
|
|
93
127
|
//# sourceMappingURL=astro.d.ts.map
|
package/dist/ssr/astro.js
CHANGED
|
@@ -1,47 +1,129 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as
|
|
4
|
-
import {
|
|
1
|
+
import { r as registerSSRCollectorGetterGlobal, u as getRuntimeConfigState } from "../chunks/runtime-state-BxaLhVdP.js";
|
|
2
|
+
import { t as ServerStyleCollector } from "../chunks/collector-D2ARGT2L.js";
|
|
3
|
+
import { n as runWithCollector, t as getSSRCollector } from "../chunks/async-storage-CG5HnUT5.js";
|
|
4
|
+
import { t as findUnsafeCSSResource } from "../chunks/css-resources-P7IBUUZs.js";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
//#region src/ssr/astro-extraction.ts
|
|
10
|
+
const METADATA_START = "<template data-tasty-extract>";
|
|
11
|
+
const METADATA_END = "</template>";
|
|
12
|
+
function createExtractionMetadata(artifacts) {
|
|
13
|
+
const encoded = Buffer.from(JSON.stringify(artifacts), "utf8").toString("base64");
|
|
14
|
+
return `${METADATA_START}${encoded}${METADATA_END}`;
|
|
15
|
+
}
|
|
16
|
+
function parseExtractablePage(path, html) {
|
|
17
|
+
const metadataStart = html.indexOf(METADATA_START);
|
|
18
|
+
if (metadataStart === -1) return null;
|
|
19
|
+
const metadataContentStart = metadataStart + 29;
|
|
20
|
+
const metadataEnd = html.indexOf(METADATA_END, metadataContentStart);
|
|
21
|
+
if (metadataEnd === -1) return null;
|
|
22
|
+
const encoded = html.slice(metadataContentStart, metadataEnd);
|
|
23
|
+
let artifacts;
|
|
24
|
+
try {
|
|
25
|
+
artifacts = JSON.parse(Buffer.from(encoded, "base64").toString("utf8"));
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const styleStart = html.lastIndexOf("<style data-tasty-ssr", metadataStart);
|
|
30
|
+
if (styleStart === -1) return null;
|
|
31
|
+
const styleOpenEnd = html.indexOf(">", styleStart);
|
|
32
|
+
const styleEnd = html.indexOf("</style>", styleOpenEnd + 1);
|
|
33
|
+
if (styleOpenEnd === -1 || styleEnd === -1 || styleEnd + 8 !== metadataStart) return null;
|
|
34
|
+
return {
|
|
35
|
+
path,
|
|
36
|
+
html,
|
|
37
|
+
artifacts,
|
|
38
|
+
styleStart,
|
|
39
|
+
replacementEnd: metadataEnd + 11,
|
|
40
|
+
styleOpen: html.slice(styleStart, styleOpenEnd + 1)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async function findHTMLFiles(dir) {
|
|
44
|
+
const paths = [];
|
|
45
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
46
|
+
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
47
|
+
for (const entry of entries) {
|
|
48
|
+
const path = join(dir, entry.name);
|
|
49
|
+
if (entry.isDirectory()) paths.push(...await findHTMLFiles(path));
|
|
50
|
+
else if (entry.isFile() && entry.name.endsWith(".html")) paths.push(path);
|
|
51
|
+
}
|
|
52
|
+
return paths;
|
|
53
|
+
}
|
|
54
|
+
function crossOriginAssetsPrefix(assetsPrefix, site) {
|
|
55
|
+
if (!assetsPrefix) return null;
|
|
56
|
+
const prefix = typeof assetsPrefix === "string" ? assetsPrefix : assetsPrefix.css || assetsPrefix.fallback;
|
|
57
|
+
if (!/^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(prefix)) return null;
|
|
58
|
+
if (!site) return prefix;
|
|
59
|
+
try {
|
|
60
|
+
return (prefix.startsWith("//") ? new URL(`${site.protocol}${prefix}`) : new URL(prefix)).origin === site.origin ? null : prefix;
|
|
61
|
+
} catch {
|
|
62
|
+
return prefix;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function validateExtractedURLs(pages, assetsPrefix, site) {
|
|
66
|
+
const externalPrefix = crossOriginAssetsPrefix(assetsPrefix, site);
|
|
67
|
+
for (const page of pages) for (const artifact of page.artifacts) {
|
|
68
|
+
const unsafe = findUnsafeCSSResource(artifact.css, externalPrefix !== null);
|
|
69
|
+
if (unsafe) {
|
|
70
|
+
const reason = unsafe.rootRelative ? `root-relative CSS URL "${unsafe.url}" would resolve against the external assetsPrefix "${externalPrefix}" instead of the page origin` : `page-relative CSS URL "${unsafe.url}" cannot preserve its target`;
|
|
71
|
+
throw new Error(`[Tasty] Astro CSS extraction cannot preserve ${reason} in ${page.path} (${artifact.kind} artifact ${artifact.id}). Use an absolute URL or a data URL${externalPrefix ? "" : ", or a root-relative URL such as url(/path/to/asset)"}.`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function selectSharedArtifacts(pages) {
|
|
76
|
+
if (pages.length < 2) return [];
|
|
77
|
+
const source = pages[0].artifacts;
|
|
78
|
+
const otherIds = pages.slice(1).map((page) => new Set(page.artifacts.map(({ id }) => id)));
|
|
79
|
+
return source.filter(({ id }) => otherIds.every((ids) => ids.has(id)));
|
|
80
|
+
}
|
|
81
|
+
function stylesheetHref(base, assets, filename, assetsPrefix) {
|
|
82
|
+
const assetsPath = assets.replace(/^\/+|\/+$/g, "");
|
|
83
|
+
if (assetsPrefix) return `${(typeof assetsPrefix === "string" ? assetsPrefix : assetsPrefix.css || assetsPrefix.fallback).replace(/\/+$/g, "")}/${assetsPath}/${filename}`;
|
|
84
|
+
return `${base === "/" ? "" : `/${base.replace(/^\/+|\/+$/g, "")}`}/${assetsPath}/${filename}`;
|
|
85
|
+
}
|
|
86
|
+
function stylesheetLink(page, href) {
|
|
87
|
+
return `<link rel="stylesheet" href="${href}" data-tasty-ssr${page.styleOpen.match(/\snonce="[^"]*"/)?.[0] ?? ""}>`;
|
|
88
|
+
}
|
|
89
|
+
function transformPage(page, hrefs) {
|
|
90
|
+
const replacement = hrefs.map((href) => stylesheetLink(page, href)).join("");
|
|
91
|
+
return page.html.slice(0, page.styleStart) + replacement + page.html.slice(page.replacementEnd);
|
|
92
|
+
}
|
|
93
|
+
async function writeStylesheet(assetDir, scope, artifacts) {
|
|
94
|
+
if (artifacts.length === 0) return null;
|
|
95
|
+
const css = artifacts.map(({ css }) => css).join("\n");
|
|
96
|
+
const filename = `tasty.${scope}.${createHash("sha256").update(css).digest("hex").slice(0, 12)}.css`;
|
|
97
|
+
await writeFile(join(assetDir, filename), css);
|
|
98
|
+
return filename;
|
|
99
|
+
}
|
|
100
|
+
async function extractAstroCSS(options) {
|
|
101
|
+
const outputDir = fileURLToPath(options.dir);
|
|
102
|
+
const paths = await findHTMLFiles(outputDir);
|
|
103
|
+
const pages = (await Promise.all(paths.map(async (path) => parseExtractablePage(path, await readFile(path, "utf8"))))).filter((page) => page !== null);
|
|
104
|
+
if (pages.length === 0) return;
|
|
105
|
+
validateExtractedURLs(pages, options.assetsPrefix, options.site);
|
|
106
|
+
const shared = selectSharedArtifacts(pages);
|
|
107
|
+
const assetDir = join(outputDir, options.assets);
|
|
108
|
+
await mkdir(assetDir, { recursive: true });
|
|
109
|
+
const sharedFilename = await writeStylesheet(assetDir, "shared", shared);
|
|
110
|
+
const sharedHref = sharedFilename ? stylesheetHref(options.base, options.assets, sharedFilename, options.assetsPrefix) : null;
|
|
111
|
+
const sharedIds = new Set(shared.map(({ id }) => id));
|
|
112
|
+
for (const page of pages) {
|
|
113
|
+
const pageFilename = await writeStylesheet(assetDir, "page", page.artifacts.filter(({ id }) => !sharedIds.has(id)));
|
|
114
|
+
const hrefs = sharedHref ? [sharedHref] : [];
|
|
115
|
+
if (pageFilename) hrefs.push(stylesheetHref(options.base, options.assets, pageFilename, options.assetsPrefix));
|
|
116
|
+
await writeFile(page.path, transformPage(page, hrefs));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
5
120
|
//#region src/ssr/astro.ts
|
|
6
|
-
/**
|
|
7
|
-
* Astro integration for Tasty SSR.
|
|
8
|
-
*
|
|
9
|
-
* Provides:
|
|
10
|
-
* - tastyIntegration() — Astro Integration API (recommended)
|
|
11
|
-
* - tastyMiddleware() — manual middleware for advanced composition
|
|
12
|
-
*
|
|
13
|
-
* Import from '@tenphi/tasty/ssr/astro'.
|
|
14
|
-
*/
|
|
15
121
|
registerSSRCollectorGetterGlobal(getSSRCollector);
|
|
16
|
-
/**
|
|
17
|
-
* Create an Astro middleware that collects Tasty styles during SSR.
|
|
18
|
-
*
|
|
19
|
-
* All React components rendered during the request will have their
|
|
20
|
-
* computeStyles() calls captured by the collector via AsyncLocalStorage.
|
|
21
|
-
* After rendering, the middleware injects the collected CSS into </head>.
|
|
22
|
-
*
|
|
23
|
-
* @example Manual middleware setup
|
|
24
|
-
* ```ts
|
|
25
|
-
* // src/middleware.ts
|
|
26
|
-
* import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
|
|
27
|
-
* export const onRequest = tastyMiddleware();
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @example Composing with other middleware
|
|
31
|
-
* ```ts
|
|
32
|
-
* // src/middleware.ts
|
|
33
|
-
* import { sequence } from 'astro:middleware';
|
|
34
|
-
* import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
|
|
35
|
-
*
|
|
36
|
-
* export const onRequest = sequence(
|
|
37
|
-
* tastyMiddleware(),
|
|
38
|
-
* myOtherMiddleware,
|
|
39
|
-
* );
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
122
|
function tastyMiddleware(options) {
|
|
43
|
-
|
|
123
|
+
const internalOptions = options;
|
|
124
|
+
return async (context, next) => {
|
|
44
125
|
const transferCache = options?.transferCache ?? true;
|
|
126
|
+
const extractionMetadata = internalOptions?.extractionMetadata === true && context.isPrerendered === true;
|
|
45
127
|
const collector = new ServerStyleCollector();
|
|
46
128
|
const rendered = await runWithCollector(collector, async () => {
|
|
47
129
|
const response = await next();
|
|
@@ -72,15 +154,16 @@ function tastyMiddleware(options) {
|
|
|
72
154
|
status: rendered.status,
|
|
73
155
|
headers: rendered.headers
|
|
74
156
|
});
|
|
75
|
-
const nonce =
|
|
157
|
+
const nonce = getRuntimeConfigState()?.nonce;
|
|
76
158
|
const nonceAttr = nonce ? ` nonce="${nonce}"` : "";
|
|
77
159
|
const styleTag = `<style data-tasty-ssr${nonceAttr}>${css}</style>`;
|
|
160
|
+
const metadataTag = extractionMetadata ? createExtractionMetadata(collector.getArtifacts()) : "";
|
|
78
161
|
let cacheTag = "";
|
|
79
162
|
if (transferCache) {
|
|
80
163
|
const classNames = collector.getRenderedClassNames();
|
|
81
164
|
if (classNames.length > 0) cacheTag = `<script${nonceAttr}>(window.__TASTY__=window.__TASTY__||[]).push(${classNames.map((n) => `"${n}"`).join(",")})<\/script>`;
|
|
82
165
|
}
|
|
83
|
-
const injection = styleTag + cacheTag;
|
|
166
|
+
const injection = styleTag + metadataTag + cacheTag;
|
|
84
167
|
const idx = html.indexOf("</head>");
|
|
85
168
|
if (idx !== -1) html = html.slice(0, idx) + injection + html.slice(idx);
|
|
86
169
|
else html = injection + html;
|
|
@@ -92,63 +175,44 @@ function tastyMiddleware(options) {
|
|
|
92
175
|
});
|
|
93
176
|
};
|
|
94
177
|
}
|
|
95
|
-
/**
|
|
96
|
-
* Package subpaths of the middleware entrypoints registered by
|
|
97
|
-
* `tastyIntegration()`.
|
|
98
|
-
*
|
|
99
|
-
* These must be bare specifiers rather than
|
|
100
|
-
* `new URL('./astro-middleware.js', import.meta.url)`. The bundler is free to
|
|
101
|
-
* hoist `tastyIntegration` into a shared chunk at a different directory depth
|
|
102
|
-
* than `dist/ssr/`, which makes a relative URL resolve to a file that does not
|
|
103
|
-
* exist and breaks the build for every consumer. A package subpath is resolved
|
|
104
|
-
* by the consumer through our `exports` map, so it never depends on the
|
|
105
|
-
* chunk layout.
|
|
106
|
-
*
|
|
107
|
-
* There are two entrypoints instead of one parameterised entrypoint because
|
|
108
|
-
* `addMiddleware()` cannot pass options: the integration runs when the Astro
|
|
109
|
-
* config is loaded, while the middleware module is evaluated in the server
|
|
110
|
-
* runtime — a different process for built output — so module-level state set
|
|
111
|
-
* by the integration is not visible to the middleware.
|
|
112
|
-
*/
|
|
113
178
|
const MIDDLEWARE_ENTRYPOINT = "@tenphi/tasty/ssr/astro-middleware";
|
|
114
179
|
const MIDDLEWARE_ENTRYPOINT_STATIC = "@tenphi/tasty/ssr/astro-middleware-static";
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
*
|
|
118
|
-
* Registers middleware for cross-component CSS deduplication and
|
|
119
|
-
* optionally injects a client hydration script for island support.
|
|
120
|
-
*
|
|
121
|
-
* @example Basic setup (with islands)
|
|
122
|
-
* ```ts
|
|
123
|
-
* // astro.config.mjs
|
|
124
|
-
* import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
|
|
125
|
-
*
|
|
126
|
-
* export default defineConfig({
|
|
127
|
-
* integrations: [tastyIntegration()],
|
|
128
|
-
* });
|
|
129
|
-
* ```
|
|
130
|
-
*
|
|
131
|
-
* @example Static-only (no client JS)
|
|
132
|
-
* ```ts
|
|
133
|
-
* // astro.config.mjs
|
|
134
|
-
* import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
|
|
135
|
-
*
|
|
136
|
-
* export default defineConfig({
|
|
137
|
-
* integrations: [tastyIntegration({ islands: false })],
|
|
138
|
-
* });
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
180
|
+
const MIDDLEWARE_ENTRYPOINT_EXTRACT = "@tenphi/tasty/ssr/astro-middleware-extract";
|
|
181
|
+
const MIDDLEWARE_ENTRYPOINT_EXTRACT_STATIC = "@tenphi/tasty/ssr/astro-middleware-extract-static";
|
|
141
182
|
function tastyIntegration(options) {
|
|
142
183
|
const { islands = true } = options ?? {};
|
|
184
|
+
const cssMode = options?.css?.mode ?? "inline";
|
|
185
|
+
let base = "/";
|
|
186
|
+
let assets = "_astro";
|
|
187
|
+
let assetsPrefix;
|
|
188
|
+
let site;
|
|
143
189
|
return {
|
|
144
190
|
name: "@tenphi/tasty",
|
|
145
|
-
hooks: {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
191
|
+
hooks: {
|
|
192
|
+
"astro:config:setup": ({ addMiddleware, injectScript }) => {
|
|
193
|
+
addMiddleware({
|
|
194
|
+
entrypoint: cssMode === "extract" ? islands ? MIDDLEWARE_ENTRYPOINT_EXTRACT : MIDDLEWARE_ENTRYPOINT_EXTRACT_STATIC : islands ? MIDDLEWARE_ENTRYPOINT : MIDDLEWARE_ENTRYPOINT_STATIC,
|
|
195
|
+
order: "pre"
|
|
196
|
+
});
|
|
197
|
+
if (islands) injectScript("before-hydration", `import "@tenphi/tasty/ssr/astro-client";`);
|
|
198
|
+
},
|
|
199
|
+
"astro:config:done": ({ config }) => {
|
|
200
|
+
base = config.base ?? "/";
|
|
201
|
+
assets = config.build?.assets ?? "_astro";
|
|
202
|
+
assetsPrefix = config.build?.assetsPrefix;
|
|
203
|
+
site = config.site;
|
|
204
|
+
},
|
|
205
|
+
"astro:build:done": async ({ dir }) => {
|
|
206
|
+
if (cssMode !== "extract") return;
|
|
207
|
+
await extractAstroCSS({
|
|
208
|
+
dir,
|
|
209
|
+
base,
|
|
210
|
+
assets,
|
|
211
|
+
assetsPrefix,
|
|
212
|
+
site
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
152
216
|
};
|
|
153
217
|
}
|
|
154
218
|
//#endregion
|
package/dist/ssr/astro.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"astro.js","names":[],"sources":["../../src/ssr/astro.ts"],"sourcesContent":["/**\n * Astro integration for Tasty SSR.\n *\n * Provides:\n * - tastyIntegration() — Astro Integration API (recommended)\n * - tastyMiddleware() — manual middleware for advanced composition\n *\n * Import from '@tenphi/tasty/ssr/astro'.\n */\n\nimport { getConfig } from '../config';\nimport { getSSRCollector, runWithCollector } from './async-storage';\nimport { ServerStyleCollector } from './collector';\nimport { registerSSRCollectorGetterGlobal } from './ssr-collector-ref';\n\n// Wire up ALS-based collector discovery so computeStyles() can find\n// the collector set by tastyMiddleware's runWithCollector().\n// Uses globalThis so the getter is visible across Astro's separate\n// module graphs (middleware vs page components).\nregisterSSRCollectorGetterGlobal(getSSRCollector);\n\nexport interface TastyMiddlewareOptions {\n /**\n * Whether to embed the class-list script for client hydration.\n * Set to false to skip class transfer (e.g. for CSP restrictions).\n * Without it, client components may re-inject CSS that already exists\n * in server-rendered `<style>` tags. Default: true.\n */\n transferCache?: boolean;\n}\n\n/**\n * Create an Astro middleware that collects Tasty styles during SSR.\n *\n * All React components rendered during the request will have their\n * computeStyles() calls captured by the collector via AsyncLocalStorage.\n * After rendering, the middleware injects the collected CSS into </head>.\n *\n * @example Manual middleware setup\n * ```ts\n * // src/middleware.ts\n * import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';\n * export const onRequest = tastyMiddleware();\n * ```\n *\n * @example Composing with other middleware\n * ```ts\n * // src/middleware.ts\n * import { sequence } from 'astro:middleware';\n * import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';\n *\n * export const onRequest = sequence(\n * tastyMiddleware(),\n * myOtherMiddleware,\n * );\n * ```\n */\nexport function tastyMiddleware(options?: TastyMiddlewareOptions) {\n return async (\n _context: unknown,\n next: () => Promise<Response>,\n ): Promise<Response> => {\n const transferCache = options?.transferCache ?? true;\n const collector = new ServerStyleCollector();\n\n // Run the entire request — including body stream consumption — inside\n // the ALS context so that components rendering lazily during stream\n // reads can still find the collector via getSSRCollector().\n type Rendered =\n | { response: Response }\n | { html: string | null; status: number; headers: Headers };\n\n const rendered = await runWithCollector<Promise<Rendered>>(\n collector,\n async (): Promise<Rendered> => {\n const response = await next();\n const body = response.body;\n\n // Only process HTML responses. Reading a non-HTML body (e.g. an\n // image, font, or JSON endpoint) as UTF-8 text corrupts binary\n // payloads: every byte >= 0x80 is decoded to U+FFFD and re-encoded\n // as EF BF BD. Pass anything that isn't HTML straight through.\n const contentType = response.headers.get('content-type') ?? '';\n if (!body || !contentType.includes('text/html')) {\n return { response };\n }\n\n const reader = body.pipeThrough(new TextDecoderStream()).getReader();\n const parts: string[] = [];\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n parts.push(value);\n }\n return {\n html: parts.join(''),\n status: response.status,\n headers: response.headers,\n };\n },\n );\n\n // Non-HTML responses are returned untouched to avoid corrupting\n // binary payloads.\n if ('response' in rendered) {\n return rendered.response;\n }\n\n if (!rendered.html) {\n return new Response(null, {\n status: rendered.status,\n headers: rendered.headers,\n });\n }\n\n let { html } = rendered;\n\n const css = collector.getCSS();\n if (!css) {\n return new Response(html, {\n status: rendered.status,\n headers: rendered.headers,\n });\n }\n\n const nonce = getConfig().nonce;\n const nonceAttr = nonce ? ` nonce=\"${nonce}\"` : '';\n const styleTag = `<style data-tasty-ssr${nonceAttr}>${css}</style>`;\n\n let cacheTag = '';\n if (transferCache) {\n const classNames = collector.getRenderedClassNames();\n if (classNames.length > 0) {\n const classListJSON = classNames.map((n) => `\"${n}\"`).join(',');\n cacheTag = `<script${nonceAttr}>(window.__TASTY__=window.__TASTY__||[]).push(${classListJSON})</script>`;\n }\n }\n\n const injection = styleTag + cacheTag;\n const idx = html.indexOf('</head>');\n if (idx !== -1) {\n html = html.slice(0, idx) + injection + html.slice(idx);\n } else {\n html = injection + html;\n }\n\n const headers = new Headers(rendered.headers);\n headers.delete('content-length');\n\n return new Response(html, {\n status: rendered.status,\n headers,\n });\n };\n}\n\n// ============================================================================\n// Astro Integration API\n// ============================================================================\n\n/**\n * Package subpaths of the middleware entrypoints registered by\n * `tastyIntegration()`.\n *\n * These must be bare specifiers rather than\n * `new URL('./astro-middleware.js', import.meta.url)`. The bundler is free to\n * hoist `tastyIntegration` into a shared chunk at a different directory depth\n * than `dist/ssr/`, which makes a relative URL resolve to a file that does not\n * exist and breaks the build for every consumer. A package subpath is resolved\n * by the consumer through our `exports` map, so it never depends on the\n * chunk layout.\n *\n * There are two entrypoints instead of one parameterised entrypoint because\n * `addMiddleware()` cannot pass options: the integration runs when the Astro\n * config is loaded, while the middleware module is evaluated in the server\n * runtime — a different process for built output — so module-level state set\n * by the integration is not visible to the middleware.\n */\nconst MIDDLEWARE_ENTRYPOINT = '@tenphi/tasty/ssr/astro-middleware';\nconst MIDDLEWARE_ENTRYPOINT_STATIC =\n '@tenphi/tasty/ssr/astro-middleware-static';\n\nexport interface TastyIntegrationOptions {\n /**\n * Enable island hydration support.\n *\n * When `true` (default): injects a client hydration script via\n * `injectScript('before-hydration')` and sets `transferCache: true`\n * on the middleware. Islands skip the style pipeline during hydration.\n *\n * When `false`: no client JS is shipped and `transferCache` is set\n * to `false`. Use this for fully static sites without `client:*`\n * directives.\n */\n islands?: boolean;\n}\n\n/**\n * Astro integration that automatically sets up Tasty SSR.\n *\n * Registers middleware for cross-component CSS deduplication and\n * optionally injects a client hydration script for island support.\n *\n * @example Basic setup (with islands)\n * ```ts\n * // astro.config.mjs\n * import { tastyIntegration } from '@tenphi/tasty/ssr/astro';\n *\n * export default defineConfig({\n * integrations: [tastyIntegration()],\n * });\n * ```\n *\n * @example Static-only (no client JS)\n * ```ts\n * // astro.config.mjs\n * import { tastyIntegration } from '@tenphi/tasty/ssr/astro';\n *\n * export default defineConfig({\n * integrations: [tastyIntegration({ islands: false })],\n * });\n * ```\n */\nexport function tastyIntegration(options?: TastyIntegrationOptions): {\n name: string;\n hooks: Record<string, (...args: never[]) => void>;\n} {\n const { islands = true } = options ?? {};\n\n return {\n name: '@tenphi/tasty',\n hooks: {\n 'astro:config:setup': ({\n addMiddleware,\n injectScript,\n }: {\n addMiddleware: (middleware: {\n entrypoint: string | URL;\n order: 'pre' | 'post';\n }) => void;\n injectScript: (\n stage: 'head-inline' | 'before-hydration' | 'page' | 'page-ssr',\n content: string,\n ) => void;\n }) => {\n addMiddleware({\n entrypoint: islands\n ? MIDDLEWARE_ENTRYPOINT\n : MIDDLEWARE_ENTRYPOINT_STATIC,\n order: 'pre',\n });\n\n if (islands) {\n injectScript(\n 'before-hydration',\n `import \"@tenphi/tasty/ssr/astro-client\";`,\n );\n }\n },\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAmBA,iCAAiC,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsChD,SAAgB,gBAAgB,SAAkC;CAChE,OAAO,OACL,UACA,SACsB;EACtB,MAAM,gBAAgB,SAAS,iBAAiB;EAChD,MAAM,YAAY,IAAI,qBAAqB;EAS3C,MAAM,WAAW,MAAM,iBACrB,WACA,YAA+B;GAC7B,MAAM,WAAW,MAAM,KAAK;GAC5B,MAAM,OAAO,SAAS;GAMtB,MAAM,cAAc,SAAS,QAAQ,IAAI,cAAc,KAAK;GAC5D,IAAI,CAAC,QAAQ,CAAC,YAAY,SAAS,WAAW,GAC5C,OAAO,EAAE,SAAS;GAGpB,MAAM,SAAS,KAAK,YAAY,IAAI,kBAAkB,CAAC,CAAC,CAAC,UAAU;GACnE,MAAM,QAAkB,CAAC;GACzB,SAAS;IACP,MAAM,EAAE,MAAM,UAAU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E,UAAU,SAAS,WAAW,CAAC;CAEvC,OAAO;EACL,MAAM;EACN,OAAO,EACL,uBAAuB,EACrB,eACA,mBAUI;GACJ,cAAc;IACZ,YAAY,UACR,wBACA;IACJ,OAAO;GACT,CAAC;GAED,IAAI,SACF,aACE,oBACA,0CACF;EAEJ,EACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"astro.js","names":[],"sources":["../../src/ssr/astro-extraction.ts","../../src/ssr/astro.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport { readdir, readFile, writeFile, mkdir } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type { ServerStyleArtifact } from './collector';\nimport { findUnsafeCSSResource } from './css-resources';\n\nconst METADATA_START = '<template data-tasty-extract>';\nconst METADATA_END = '</template>';\n\ninterface ExtractablePage {\n path: string;\n html: string;\n artifacts: ServerStyleArtifact[];\n styleStart: number;\n replacementEnd: number;\n styleOpen: string;\n}\n\nexport function createExtractionMetadata(\n artifacts: ServerStyleArtifact[],\n): string {\n const encoded = Buffer.from(JSON.stringify(artifacts), 'utf8').toString(\n 'base64',\n );\n return `${METADATA_START}${encoded}${METADATA_END}`;\n}\n\nfunction parseExtractablePage(\n path: string,\n html: string,\n): ExtractablePage | null {\n const metadataStart = html.indexOf(METADATA_START);\n if (metadataStart === -1) return null;\n\n const metadataContentStart = metadataStart + METADATA_START.length;\n const metadataEnd = html.indexOf(METADATA_END, metadataContentStart);\n if (metadataEnd === -1) return null;\n\n const encoded = html.slice(metadataContentStart, metadataEnd);\n let artifacts: ServerStyleArtifact[];\n try {\n artifacts = JSON.parse(\n Buffer.from(encoded, 'base64').toString('utf8'),\n ) as ServerStyleArtifact[];\n } catch {\n return null;\n }\n\n const styleStart = html.lastIndexOf('<style data-tasty-ssr', metadataStart);\n if (styleStart === -1) return null;\n const styleOpenEnd = html.indexOf('>', styleStart);\n const styleEnd = html.indexOf('</style>', styleOpenEnd + 1);\n if (\n styleOpenEnd === -1 ||\n styleEnd === -1 ||\n styleEnd + '</style>'.length !== metadataStart\n ) {\n return null;\n }\n\n return {\n path,\n html,\n artifacts,\n styleStart,\n replacementEnd: metadataEnd + METADATA_END.length,\n styleOpen: html.slice(styleStart, styleOpenEnd + 1),\n };\n}\n\nasync function findHTMLFiles(dir: string): Promise<string[]> {\n const paths: string[] = [];\n const entries = await readdir(dir, { withFileTypes: true });\n entries.sort((a, b) => a.name.localeCompare(b.name));\n for (const entry of entries) {\n const path = join(dir, entry.name);\n if (entry.isDirectory()) {\n paths.push(...(await findHTMLFiles(path)));\n } else if (entry.isFile() && entry.name.endsWith('.html')) {\n paths.push(path);\n }\n }\n return paths;\n}\n\nfunction crossOriginAssetsPrefix(\n assetsPrefix?: string | Record<string, string>,\n site?: URL,\n): string | null {\n if (!assetsPrefix) return null;\n const prefix =\n typeof assetsPrefix === 'string'\n ? assetsPrefix\n : assetsPrefix.css || assetsPrefix.fallback;\n if (!/^(?:[a-z][a-z\\d+.-]*:|\\/\\/)/i.test(prefix)) return null;\n if (!site) return prefix;\n\n try {\n const prefixURL = prefix.startsWith('//')\n ? new URL(`${site.protocol}${prefix}`)\n : new URL(prefix);\n return prefixURL.origin === site.origin ? null : prefix;\n } catch {\n return prefix;\n }\n}\n\nfunction validateExtractedURLs(\n pages: ExtractablePage[],\n assetsPrefix?: string | Record<string, string>,\n site?: URL,\n): void {\n const externalPrefix = crossOriginAssetsPrefix(assetsPrefix, site);\n for (const page of pages) {\n for (const artifact of page.artifacts) {\n const unsafe = findUnsafeCSSResource(\n artifact.css,\n externalPrefix !== null,\n );\n if (unsafe) {\n const reason = unsafe.rootRelative\n ? `root-relative CSS URL \"${unsafe.url}\" would resolve against the external assetsPrefix \"${externalPrefix}\" instead of the page origin`\n : `page-relative CSS URL \"${unsafe.url}\" cannot preserve its target`;\n throw new Error(\n `[Tasty] Astro CSS extraction cannot preserve ${reason} in ${page.path} (${artifact.kind} artifact ${artifact.id}). Use an absolute URL or a data URL${externalPrefix ? '' : ', or a root-relative URL such as url(/path/to/asset)'}.`,\n );\n }\n }\n }\n}\n\n/** Find artifacts emitted by every styled page, in the first page's order. */\nfunction selectSharedArtifacts(\n pages: ExtractablePage[],\n): ServerStyleArtifact[] {\n if (pages.length < 2) return [];\n\n const source = pages[0].artifacts;\n const otherIds = pages\n .slice(1)\n .map((page) => new Set(page.artifacts.map(({ id }) => id)));\n\n return source.filter(({ id }) => otherIds.every((ids) => ids.has(id)));\n}\n\nfunction stylesheetHref(\n base: string,\n assets: string,\n filename: string,\n assetsPrefix?: string | Record<string, string>,\n): string {\n const assetsPath = assets.replace(/^\\/+|\\/+$/g, '');\n if (assetsPrefix) {\n const prefix =\n typeof assetsPrefix === 'string'\n ? assetsPrefix\n : assetsPrefix.css || assetsPrefix.fallback;\n return `${prefix.replace(/\\/+$/g, '')}/${assetsPath}/${filename}`;\n }\n\n const basePath = base === '/' ? '' : `/${base.replace(/^\\/+|\\/+$/g, '')}`;\n return `${basePath}/${assetsPath}/${filename}`;\n}\n\nfunction stylesheetLink(page: ExtractablePage, href: string): string {\n const nonceAttr = page.styleOpen.match(/\\snonce=\"[^\"]*\"/)?.[0] ?? '';\n return `<link rel=\"stylesheet\" href=\"${href}\" data-tasty-ssr${nonceAttr}>`;\n}\n\nfunction transformPage(page: ExtractablePage, hrefs: string[]): string {\n const replacement = hrefs.map((href) => stylesheetLink(page, href)).join('');\n\n return (\n page.html.slice(0, page.styleStart) +\n replacement +\n page.html.slice(page.replacementEnd)\n );\n}\n\nasync function writeStylesheet(\n assetDir: string,\n scope: 'shared' | 'page',\n artifacts: ServerStyleArtifact[],\n): Promise<string | null> {\n if (artifacts.length === 0) return null;\n\n const css = artifacts.map(({ css }) => css).join('\\n');\n const hash = createHash('sha256').update(css).digest('hex').slice(0, 12);\n const filename = `tasty.${scope}.${hash}.css`;\n await writeFile(join(assetDir, filename), css);\n return filename;\n}\n\nexport async function extractAstroCSS(options: {\n dir: URL;\n base: string;\n assets: string;\n assetsPrefix?: string | Record<string, string>;\n site?: URL;\n}): Promise<void> {\n const outputDir = fileURLToPath(options.dir);\n const paths = await findHTMLFiles(outputDir);\n const pages = (\n await Promise.all(\n paths.map(async (path) =>\n parseExtractablePage(path, await readFile(path, 'utf8')),\n ),\n )\n ).filter((page): page is ExtractablePage => page !== null);\n if (pages.length === 0) return;\n validateExtractedURLs(pages, options.assetsPrefix, options.site);\n\n const shared = selectSharedArtifacts(pages);\n const assetDir = join(outputDir, options.assets);\n await mkdir(assetDir, { recursive: true });\n const sharedFilename = await writeStylesheet(assetDir, 'shared', shared);\n const sharedHref = sharedFilename\n ? stylesheetHref(\n options.base,\n options.assets,\n sharedFilename,\n options.assetsPrefix,\n )\n : null;\n const sharedIds = new Set(shared.map(({ id }) => id));\n\n for (const page of pages) {\n const remainder = page.artifacts.filter(({ id }) => !sharedIds.has(id));\n const pageFilename = await writeStylesheet(assetDir, 'page', remainder);\n const hrefs = sharedHref ? [sharedHref] : [];\n if (pageFilename) {\n hrefs.push(\n stylesheetHref(\n options.base,\n options.assets,\n pageFilename,\n options.assetsPrefix,\n ),\n );\n }\n await writeFile(page.path, transformPage(page, hrefs));\n }\n}\n","/**\n * Astro integration for Tasty SSR.\n *\n * Provides:\n * - tastyIntegration() — Astro Integration API (recommended)\n * - tastyMiddleware() — manual middleware for advanced composition\n *\n * Import from '@tenphi/tasty/ssr/astro'.\n */\n\nimport { getRuntimeConfigState } from '../config-resources';\nimport { getSSRCollector, runWithCollector } from './async-storage';\nimport { createExtractionMetadata, extractAstroCSS } from './astro-extraction';\nimport { ServerStyleCollector } from './collector';\nimport { registerSSRCollectorGetterGlobal } from './ssr-collector-ref';\n\n// Wire up ALS-based collector discovery so computeStyles() can find\n// the collector set by tastyMiddleware's runWithCollector().\n// Uses globalThis so the getter is visible across Astro's separate\n// module graphs (middleware vs page components).\nregisterSSRCollectorGetterGlobal(getSSRCollector);\n\nexport interface TastyMiddlewareOptions {\n /**\n * Whether to embed the class-list script for client hydration.\n * Set to false to skip class transfer (e.g. for CSP restrictions).\n * Without it, client components may re-inject CSS that already exists\n * in server-rendered `<style>` tags. Default: true.\n */\n transferCache?: boolean;\n}\n\ninterface InternalTastyMiddlewareOptions extends TastyMiddlewareOptions {\n extractionMetadata?: boolean;\n}\n\n/**\n * Create an Astro middleware that collects Tasty styles during SSR.\n *\n * All React components rendered during the request will have their\n * computeStyles() calls captured by the collector via AsyncLocalStorage.\n * After rendering, the middleware injects the collected CSS into </head>.\n *\n * @example Manual middleware setup\n * ```ts\n * // src/middleware.ts\n * import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';\n * export const onRequest = tastyMiddleware();\n * ```\n *\n * @example Composing with other middleware\n * ```ts\n * // src/middleware.ts\n * import { sequence } from 'astro:middleware';\n * import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';\n *\n * export const onRequest = sequence(\n * tastyMiddleware(),\n * myOtherMiddleware,\n * );\n * ```\n */\nexport function tastyMiddleware(options?: TastyMiddlewareOptions) {\n const internalOptions = options as InternalTastyMiddlewareOptions | undefined;\n return async (\n context: { isPrerendered?: boolean },\n next: () => Promise<Response>,\n ): Promise<Response> => {\n const transferCache = options?.transferCache ?? true;\n const extractionMetadata =\n internalOptions?.extractionMetadata === true &&\n context.isPrerendered === true;\n const collector = new ServerStyleCollector();\n\n // Run the entire request — including body stream consumption — inside\n // the ALS context so that components rendering lazily during stream\n // reads can still find the collector via getSSRCollector().\n type Rendered =\n | { response: Response }\n | { html: string | null; status: number; headers: Headers };\n\n const rendered = await runWithCollector<Promise<Rendered>>(\n collector,\n async (): Promise<Rendered> => {\n const response = await next();\n const body = response.body;\n\n // Only process HTML responses. Reading a non-HTML body (e.g. an\n // image, font, or JSON endpoint) as UTF-8 text corrupts binary\n // payloads: every byte >= 0x80 is decoded to U+FFFD and re-encoded\n // as EF BF BD. Pass anything that isn't HTML straight through.\n const contentType = response.headers.get('content-type') ?? '';\n if (!body || !contentType.includes('text/html')) {\n return { response };\n }\n\n const reader = body.pipeThrough(new TextDecoderStream()).getReader();\n const parts: string[] = [];\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n parts.push(value);\n }\n return {\n html: parts.join(''),\n status: response.status,\n headers: response.headers,\n };\n },\n );\n\n // Non-HTML responses are returned untouched to avoid corrupting\n // binary payloads.\n if ('response' in rendered) {\n return rendered.response;\n }\n\n if (!rendered.html) {\n return new Response(null, {\n status: rendered.status,\n headers: rendered.headers,\n });\n }\n\n let { html } = rendered;\n\n const css = collector.getCSS();\n if (!css) {\n return new Response(html, {\n status: rendered.status,\n headers: rendered.headers,\n });\n }\n\n const nonce = getRuntimeConfigState()?.nonce;\n const nonceAttr = nonce ? ` nonce=\"${nonce}\"` : '';\n const styleTag = `<style data-tasty-ssr${nonceAttr}>${css}</style>`;\n const metadataTag = extractionMetadata\n ? createExtractionMetadata(collector.getArtifacts())\n : '';\n\n let cacheTag = '';\n if (transferCache) {\n const classNames = collector.getRenderedClassNames();\n if (classNames.length > 0) {\n const classListJSON = classNames.map((n) => `\"${n}\"`).join(',');\n cacheTag = `<script${nonceAttr}>(window.__TASTY__=window.__TASTY__||[]).push(${classListJSON})</script>`;\n }\n }\n\n const injection = styleTag + metadataTag + cacheTag;\n const idx = html.indexOf('</head>');\n if (idx !== -1) {\n html = html.slice(0, idx) + injection + html.slice(idx);\n } else {\n html = injection + html;\n }\n\n const headers = new Headers(rendered.headers);\n headers.delete('content-length');\n\n return new Response(html, {\n status: rendered.status,\n headers,\n });\n };\n}\n\n// ============================================================================\n// Astro Integration API\n// ============================================================================\n\n/**\n * Package subpaths of the middleware entrypoints registered by\n * `tastyIntegration()`.\n *\n * These must be bare specifiers rather than\n * `new URL('./astro-middleware.js', import.meta.url)`. The bundler is free to\n * hoist `tastyIntegration` into a shared chunk at a different directory depth\n * than `dist/ssr/`, which makes a relative URL resolve to a file that does not\n * exist and breaks the build for every consumer. A package subpath is resolved\n * by the consumer through our `exports` map, so it never depends on the\n * chunk layout.\n *\n * There are separate entrypoints instead of one parameterised entrypoint because\n * `addMiddleware()` cannot pass options: the integration runs when the Astro\n * config is loaded, while the middleware module is evaluated in the server\n * runtime — a different process for built output — so module-level state set\n * by the integration is not visible to the middleware.\n */\nconst MIDDLEWARE_ENTRYPOINT = '@tenphi/tasty/ssr/astro-middleware';\nconst MIDDLEWARE_ENTRYPOINT_STATIC =\n '@tenphi/tasty/ssr/astro-middleware-static';\nconst MIDDLEWARE_ENTRYPOINT_EXTRACT =\n '@tenphi/tasty/ssr/astro-middleware-extract';\nconst MIDDLEWARE_ENTRYPOINT_EXTRACT_STATIC =\n '@tenphi/tasty/ssr/astro-middleware-extract-static';\n\nexport interface TastyIntegrationCSSOptions {\n /**\n * CSS delivery mode. Extraction only applies to prerendered builds.\n * Extracted CSS preserves resource URLs verbatim, so use absolute URLs or\n * data URLs. Root-relative URLs are also supported unless `assetsPrefix`\n * sends CSS to an external origin. The build rejects resource URLs whose\n * targets would change after extraction.\n */\n mode?: 'inline' | 'extract';\n}\n\nexport interface TastyIntegrationOptions {\n /**\n * Enable island hydration support.\n *\n * When `true` (default): injects a client hydration script via\n * `injectScript('before-hydration')` and sets `transferCache: true`\n * on the middleware. Islands skip the style pipeline during hydration.\n *\n * When `false`: no client JS is shipped and `transferCache` is set\n * to `false`. Use this for fully static sites without `client:*`\n * directives.\n */\n islands?: boolean;\n /** Configure inline or build-wide extracted CSS delivery. */\n css?: TastyIntegrationCSSOptions;\n}\n\n/**\n * Astro integration that automatically sets up Tasty SSR.\n *\n * Registers middleware for cross-component CSS deduplication and\n * optionally injects a client hydration script for island support.\n *\n * @example Basic setup (with islands)\n * ```ts\n * // astro.config.mjs\n * import { tastyIntegration } from '@tenphi/tasty/ssr/astro';\n *\n * export default defineConfig({\n * integrations: [tastyIntegration()],\n * });\n * ```\n *\n * @example Static-only (no client JS)\n * ```ts\n * // astro.config.mjs\n * import { tastyIntegration } from '@tenphi/tasty/ssr/astro';\n *\n * export default defineConfig({\n * integrations: [tastyIntegration({ islands: false })],\n * });\n * ```\n */\nexport function tastyIntegration(options?: TastyIntegrationOptions) {\n const { islands = true } = options ?? {};\n const cssMode = options?.css?.mode ?? 'inline';\n let base = '/';\n let assets = '_astro';\n let assetsPrefix: string | Record<string, string> | undefined;\n let site: URL | undefined;\n\n return {\n name: '@tenphi/tasty',\n hooks: {\n 'astro:config:setup': ({\n addMiddleware,\n injectScript,\n }: {\n addMiddleware: (middleware: {\n entrypoint: string | URL;\n order: 'pre' | 'post';\n }) => void;\n injectScript: (\n stage: 'head-inline' | 'before-hydration' | 'page' | 'page-ssr',\n content: string,\n ) => void;\n }) => {\n addMiddleware({\n entrypoint:\n cssMode === 'extract'\n ? islands\n ? MIDDLEWARE_ENTRYPOINT_EXTRACT\n : MIDDLEWARE_ENTRYPOINT_EXTRACT_STATIC\n : islands\n ? MIDDLEWARE_ENTRYPOINT\n : MIDDLEWARE_ENTRYPOINT_STATIC,\n order: 'pre',\n });\n\n if (islands) {\n injectScript(\n 'before-hydration',\n `import \"@tenphi/tasty/ssr/astro-client\";`,\n );\n }\n },\n 'astro:config:done': ({\n config,\n }: {\n config: {\n base?: string;\n site?: URL;\n build?: {\n assets?: string;\n assetsPrefix?: string | Record<string, string>;\n };\n };\n }) => {\n base = config.base ?? '/';\n assets = config.build?.assets ?? '_astro';\n assetsPrefix = config.build?.assetsPrefix;\n site = config.site;\n },\n 'astro:build:done': async ({ dir }: { dir: URL }) => {\n if (cssMode !== 'extract') return;\n await extractAstroCSS({ dir, base, assets, assetsPrefix, site });\n },\n },\n };\n}\n"],"mappings":";;;;;;;;;AAQA,MAAM,iBAAiB;AACvB,MAAM,eAAe;AAWrB,SAAgB,yBACd,WACQ;CACR,MAAM,UAAU,OAAO,KAAK,KAAK,UAAU,SAAS,GAAG,MAAM,CAAC,CAAC,SAC7D,QACF;CACA,OAAO,GAAG,iBAAiB,UAAU;AACvC;AAEA,SAAS,qBACP,MACA,MACwB;CACxB,MAAM,gBAAgB,KAAK,QAAQ,cAAc;CACjD,IAAI,kBAAkB,IAAI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