@tenphi/tasty 0.0.0-snapshot.a8b0eee → 0.0.0-snapshot.a8da86e
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 +181 -136
- package/dist/babel-types-C_7kRP38.d.ts +18 -0
- package/dist/chunks/async-storage-CG5HnUT5.js +20 -0
- package/dist/chunks/async-storage-CG5HnUT5.js.map +1 -0
- package/dist/chunks/build-config-Betc6IB6.js +60 -0
- package/dist/chunks/build-config-Betc6IB6.js.map +1 -0
- package/dist/{collector-Crs9kGJW.js → chunks/collector-DqqisglQ.js} +68 -101
- package/dist/chunks/collector-DqqisglQ.js.map +1 -0
- package/dist/chunks/config-engine-BPeROwq2.js +272 -0
- package/dist/chunks/config-engine-BPeROwq2.js.map +1 -0
- package/dist/chunks/css-definitions-IeuyJTGk.js +899 -0
- package/dist/chunks/css-definitions-IeuyJTGk.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-P1E2jkj7.js +502 -0
- package/dist/chunks/debug-P1E2jkj7.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-XMBbGRes.js +582 -0
- package/dist/chunks/react-runtime-XMBbGRes.js.map +1 -0
- package/dist/chunks/runtime-engine-CsIMtulO.js +2415 -0
- package/dist/chunks/runtime-engine-CsIMtulO.js.map +1 -0
- package/dist/chunks/runtime-state-CyKzDioI.js +141 -0
- package/dist/chunks/runtime-state-CyKzDioI.js.map +1 -0
- package/dist/{merge-styles-BzQutdAK.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-RbokDN6A.js +5427 -0
- package/dist/chunks/style-engine-RbokDN6A.js.map +1 -0
- package/dist/{css-writer-CPy_cbFJ.js → chunks/zero-engine-DbtjMsfo.js} +81 -137
- package/dist/chunks/zero-engine-DbtjMsfo.js.map +1 -0
- package/dist/{collector-osfWTeRd.d.ts → collector-w4mBj5gd.d.ts} +64 -8
- package/dist/{config-BoZDUHW5.d.ts → config-CrZOfNJ5.d.ts} +489 -85
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +9 -6
- package/dist/{index-B_k47mc_.d.ts → index-CYJtAI9a.d.ts} +664 -399
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -732
- package/dist/{merge-styles-BMWcH6MF.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 +17 -0
- package/dist/ssr/astro-middleware-static.js +7 -0
- package/dist/ssr/astro-middleware-static.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +11 -8
- package/dist/ssr/astro-middleware.js +2 -14
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +40 -10
- package/dist/ssr/astro.js +163 -91
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/index.d.ts +10 -18
- package/dist/ssr/index.js +5 -5
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +64 -0
- package/dist/ssr/next-config.js +134 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +9 -9
- package/dist/ssr/next.js +29 -44
- 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/static/inject.js.map +1 -1
- package/dist/{index-tcHuMPFt.d.ts → types-JEY8PVYP.d.ts} +874 -593
- package/dist/zero/babel.d.ts +5 -19
- package/dist/zero/babel.js +74 -144
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +57 -7
- package/dist/zero/index.js +24 -2
- package/dist/zero/index.js.map +1 -0
- package/dist/zero/next.d.ts +4 -5
- package/dist/zero/next.js +0 -31
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +17 -9
- package/docs/adoption.md +56 -31
- package/docs/ai-agents.md +250 -0
- package/docs/comparison.md +69 -40
- package/docs/configuration.md +487 -86
- package/docs/debug.md +26 -14
- package/docs/design-system.md +43 -24
- package/docs/dsl.md +558 -181
- package/docs/getting-started.md +64 -41
- package/docs/injector.md +120 -30
- package/docs/methodology.md +46 -40
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +87 -21
- package/docs/plugins.md +353 -0
- package/docs/react-api.md +151 -42
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +252 -86
- package/docs/styles.md +142 -25
- package/docs/tasty-static.md +174 -106
- package/package.json +127 -35
- package/tasty.config.ts +5 -0
- package/dist/async-storage-B7_o6FKt.js +0 -44
- package/dist/async-storage-B7_o6FKt.js.map +0 -1
- package/dist/collector-Crs9kGJW.js.map +0 -1
- package/dist/config-BaxtQMS3.js +0 -10464
- package/dist/config-BaxtQMS3.js.map +0 -1
- package/dist/context-CkSg-kDT.js +0 -24
- package/dist/context-CkSg-kDT.js.map +0 -1
- package/dist/core-CmxaoZ-N.js +0 -1598
- package/dist/core-CmxaoZ-N.js.map +0 -1
- package/dist/css-writer-CPy_cbFJ.js.map +0 -1
- package/dist/format-global-rules-Dbc_1tc3.js +0 -22
- package/dist/format-global-rules-Dbc_1tc3.js.map +0 -1
- package/dist/format-rules-CPirO_Mj.js +0 -143
- package/dist/format-rules-CPirO_Mj.js.map +0 -1
- package/dist/hydrate-CVn-A_3y.js +0 -45
- package/dist/hydrate-CVn-A_3y.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-vpzoVdUR.js +0 -588
- package/dist/keyframes-vpzoVdUR.js.map +0 -1
- package/dist/merge-styles-BzQutdAK.js.map +0 -1
- package/dist/resolve-recipes-DgH8A3Nn.js +0 -144
- package/dist/resolve-recipes-DgH8A3Nn.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 {
|
|
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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/ssr/astro-middleware-static.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Astro middleware entrypoint for `tastyIntegration({ islands: false })`.
|
|
4
|
+
*
|
|
5
|
+
* Registered via `addMiddleware()` as
|
|
6
|
+
* `@tenphi/tasty/ssr/astro-middleware-static`. Exposed as a package subpath
|
|
7
|
+
* only so Astro can resolve it — use `tastyMiddleware({ transferCache: false })`
|
|
8
|
+
* directly if you need manual middleware composition.
|
|
9
|
+
*
|
|
10
|
+
* Identical to `./astro-middleware` except that no class-list `<script>` is
|
|
11
|
+
* emitted, so a site without `client:*` islands ships zero client JavaScript.
|
|
12
|
+
*/
|
|
13
|
+
export declare const onRequest: (context: {
|
|
14
|
+
isPrerendered?: boolean;
|
|
15
|
+
}, next: () => Promise<Response>) => Promise<Response>;
|
|
16
|
+
//#endregion
|
|
17
|
+
//# sourceMappingURL=astro-middleware-static.d.ts.map
|
|
@@ -0,0 +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":";;AAcA,MAAa,YAAY,gBAAgB,EAAE,eAAe,MAAM,CAAC"}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
//#region src/ssr/astro-middleware.d.ts
|
|
2
2
|
/**
|
|
3
|
-
* Astro middleware entrypoint for tastyIntegration()
|
|
3
|
+
* Astro middleware entrypoint for `tastyIntegration()`.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* as a
|
|
7
|
-
* you need manual middleware composition.
|
|
5
|
+
* Registered via `addMiddleware()` as `@tenphi/tasty/ssr/astro-middleware`.
|
|
6
|
+
* Exposed as a package subpath only so Astro can resolve it — use
|
|
7
|
+
* `tastyMiddleware()` directly if you need manual middleware composition.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* This is the islands variant: the rendered class list is transferred to the
|
|
10
|
+
* client so hydrating islands skip the style pipeline. See
|
|
11
|
+
* `./astro-middleware-static` for the variant used by
|
|
12
|
+
* `tastyIntegration({ islands: false })`.
|
|
11
13
|
*/
|
|
12
|
-
declare const onRequest: (
|
|
14
|
+
export declare const onRequest: (context: {
|
|
15
|
+
isPrerendered?: boolean;
|
|
16
|
+
}, next: () => Promise<Response>) => Promise<Response>;
|
|
13
17
|
//#endregion
|
|
14
|
-
export { onRequest };
|
|
15
18
|
//# sourceMappingURL=astro-middleware.d.ts.map
|
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { tastyMiddleware } from "./astro.js";
|
|
2
2
|
//#region src/ssr/astro-middleware.ts
|
|
3
|
-
|
|
4
|
-
* Astro middleware entrypoint for tastyIntegration().
|
|
5
|
-
*
|
|
6
|
-
* Referenced by the integration via addMiddleware(). Not intended
|
|
7
|
-
* as a public package export — use tastyMiddleware() directly if
|
|
8
|
-
* you need manual middleware composition.
|
|
9
|
-
*
|
|
10
|
-
* The transferCache setting is controlled by setMiddlewareTransferCache(),
|
|
11
|
-
* called by tastyIntegration() before middleware is loaded.
|
|
12
|
-
*/
|
|
13
|
-
const onRequest = tastyMiddleware({ get transferCache() {
|
|
14
|
-
return getMiddlewareTransferCache();
|
|
15
|
-
} });
|
|
3
|
+
const onRequest = tastyMiddleware({ transferCache: true });
|
|
16
4
|
//#endregion
|
|
17
5
|
export { onRequest };
|
|
18
6
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"astro-middleware.js","names":[],"sources":["../../src/ssr/astro-middleware.ts"],"sourcesContent":["/**\n * Astro middleware entrypoint for tastyIntegration()
|
|
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,12 +43,20 @@ interface TastyMiddlewareOptions {
|
|
|
43
43
|
* );
|
|
44
44
|
* ```
|
|
45
45
|
*/
|
|
46
|
-
declare function tastyMiddleware(options?: TastyMiddlewareOptions): (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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 {
|
|
52
60
|
/**
|
|
53
61
|
* Enable island hydration support.
|
|
54
62
|
*
|
|
@@ -61,6 +69,8 @@ interface TastyIntegrationOptions {
|
|
|
61
69
|
* directives.
|
|
62
70
|
*/
|
|
63
71
|
islands?: boolean;
|
|
72
|
+
/** Configure inline or build-wide extracted CSS delivery. */
|
|
73
|
+
css?: TastyIntegrationCSSOptions;
|
|
64
74
|
}
|
|
65
75
|
/**
|
|
66
76
|
* Astro integration that automatically sets up Tasty SSR.
|
|
@@ -88,10 +98,30 @@ interface TastyIntegrationOptions {
|
|
|
88
98
|
* });
|
|
89
99
|
* ```
|
|
90
100
|
*/
|
|
91
|
-
declare function tastyIntegration(options?: TastyIntegrationOptions): {
|
|
101
|
+
export declare function tastyIntegration(options?: TastyIntegrationOptions): {
|
|
92
102
|
name: string;
|
|
93
|
-
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
|
+
};
|
|
94
125
|
};
|
|
95
126
|
//#endregion
|
|
96
|
-
export { TastyIntegrationOptions, TastyMiddlewareOptions, getMiddlewareTransferCache, setMiddlewareTransferCache, tastyIntegration, tastyMiddleware };
|
|
97
127
|
//# sourceMappingURL=astro.d.ts.map
|
package/dist/ssr/astro.js
CHANGED
|
@@ -1,56 +1,135 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as
|
|
4
|
-
import {
|
|
1
|
+
import { d as getRuntimeConfigState, r as registerSSRCollectorGetterGlobal } from "../chunks/runtime-state-CyKzDioI.js";
|
|
2
|
+
import { t as ServerStyleCollector } from "../chunks/collector-DqqisglQ.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();
|
|
48
130
|
const body = response.body;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
status: response.status,
|
|
52
|
-
headers: response.headers
|
|
53
|
-
};
|
|
131
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
132
|
+
if (!body || !contentType.includes("text/html")) return { response };
|
|
54
133
|
const reader = body.pipeThrough(new TextDecoderStream()).getReader();
|
|
55
134
|
const parts = [];
|
|
56
135
|
for (;;) {
|
|
@@ -64,6 +143,7 @@ function tastyMiddleware(options) {
|
|
|
64
143
|
headers: response.headers
|
|
65
144
|
};
|
|
66
145
|
});
|
|
146
|
+
if ("response" in rendered) return rendered.response;
|
|
67
147
|
if (!rendered.html) return new Response(null, {
|
|
68
148
|
status: rendered.status,
|
|
69
149
|
headers: rendered.headers
|
|
@@ -74,15 +154,16 @@ function tastyMiddleware(options) {
|
|
|
74
154
|
status: rendered.status,
|
|
75
155
|
headers: rendered.headers
|
|
76
156
|
});
|
|
77
|
-
const nonce =
|
|
157
|
+
const nonce = getRuntimeConfigState()?.nonce;
|
|
78
158
|
const nonceAttr = nonce ? ` nonce="${nonce}"` : "";
|
|
79
159
|
const styleTag = `<style data-tasty-ssr${nonceAttr}>${css}</style>`;
|
|
160
|
+
const metadataTag = extractionMetadata ? createExtractionMetadata(collector.getArtifacts()) : "";
|
|
80
161
|
let cacheTag = "";
|
|
81
162
|
if (transferCache) {
|
|
82
163
|
const classNames = collector.getRenderedClassNames();
|
|
83
164
|
if (classNames.length > 0) cacheTag = `<script${nonceAttr}>(window.__TASTY__=window.__TASTY__||[]).push(${classNames.map((n) => `"${n}"`).join(",")})<\/script>`;
|
|
84
165
|
}
|
|
85
|
-
const injection = styleTag + cacheTag;
|
|
166
|
+
const injection = styleTag + metadataTag + cacheTag;
|
|
86
167
|
const idx = html.indexOf("</head>");
|
|
87
168
|
if (idx !== -1) html = html.slice(0, idx) + injection + html.slice(idx);
|
|
88
169
|
else html = injection + html;
|
|
@@ -94,56 +175,47 @@ function tastyMiddleware(options) {
|
|
|
94
175
|
});
|
|
95
176
|
};
|
|
96
177
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
/** @internal */
|
|
103
|
-
function getMiddlewareTransferCache() {
|
|
104
|
-
return _middlewareTransferCache;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Astro integration that automatically sets up Tasty SSR.
|
|
108
|
-
*
|
|
109
|
-
* Registers middleware for cross-component CSS deduplication and
|
|
110
|
-
* optionally injects a client hydration script for island support.
|
|
111
|
-
*
|
|
112
|
-
* @example Basic setup (with islands)
|
|
113
|
-
* ```ts
|
|
114
|
-
* // astro.config.mjs
|
|
115
|
-
* import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
|
|
116
|
-
*
|
|
117
|
-
* export default defineConfig({
|
|
118
|
-
* integrations: [tastyIntegration()],
|
|
119
|
-
* });
|
|
120
|
-
* ```
|
|
121
|
-
*
|
|
122
|
-
* @example Static-only (no client JS)
|
|
123
|
-
* ```ts
|
|
124
|
-
* // astro.config.mjs
|
|
125
|
-
* import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
|
|
126
|
-
*
|
|
127
|
-
* export default defineConfig({
|
|
128
|
-
* integrations: [tastyIntegration({ islands: false })],
|
|
129
|
-
* });
|
|
130
|
-
* ```
|
|
131
|
-
*/
|
|
178
|
+
const MIDDLEWARE_ENTRYPOINT = "@tenphi/tasty/ssr/astro-middleware";
|
|
179
|
+
const MIDDLEWARE_ENTRYPOINT_STATIC = "@tenphi/tasty/ssr/astro-middleware-static";
|
|
180
|
+
const MIDDLEWARE_ENTRYPOINT_EXTRACT = "@tenphi/tasty/ssr/astro-middleware-extract";
|
|
181
|
+
const MIDDLEWARE_ENTRYPOINT_EXTRACT_STATIC = "@tenphi/tasty/ssr/astro-middleware-extract-static";
|
|
132
182
|
function tastyIntegration(options) {
|
|
133
183
|
const { islands = true } = options ?? {};
|
|
134
|
-
|
|
184
|
+
const cssMode = options?.css?.mode ?? "inline";
|
|
185
|
+
let base = "/";
|
|
186
|
+
let assets = "_astro";
|
|
187
|
+
let assetsPrefix;
|
|
188
|
+
let site;
|
|
135
189
|
return {
|
|
136
190
|
name: "@tenphi/tasty",
|
|
137
|
-
hooks: {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
+
}
|
|
144
216
|
};
|
|
145
217
|
}
|
|
146
218
|
//#endregion
|
|
147
|
-
export {
|
|
219
|
+
export { tastyIntegration, tastyMiddleware };
|
|
148
220
|
|
|
149
221
|
//# sourceMappingURL=astro.js.map
|