@tenphi/tasty 0.0.0-snapshot.4edfcbd → 0.0.0-snapshot.4fb5b7d

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.
Files changed (132) hide show
  1. package/README.md +440 -372
  2. package/dist/babel-types-BOABQvEI.d.ts +16 -0
  3. package/dist/chunks/async-storage-CzSKAyrI.js +36 -0
  4. package/dist/chunks/async-storage-CzSKAyrI.js.map +1 -0
  5. package/dist/chunks/build-config-CKiw8Irz.js +59 -0
  6. package/dist/chunks/build-config-CKiw8Irz.js.map +1 -0
  7. package/dist/{collector-C-keQH9m.js → chunks/collector-EKAsDdmQ.js} +69 -103
  8. package/dist/chunks/collector-EKAsDdmQ.js.map +1 -0
  9. package/dist/chunks/config-engine-Br1Z5kEh.js +269 -0
  10. package/dist/chunks/config-engine-Br1Z5kEh.js.map +1 -0
  11. package/dist/chunks/config-file-BX3F_61U.js +24 -0
  12. package/dist/chunks/config-file-BX3F_61U.js.map +1 -0
  13. package/dist/chunks/css-definitions-CuohiBRl.js +896 -0
  14. package/dist/chunks/css-definitions-CuohiBRl.js.map +1 -0
  15. package/dist/chunks/css-resources-C0zT36nQ.js +141 -0
  16. package/dist/chunks/css-resources-C0zT36nQ.js.map +1 -0
  17. package/dist/chunks/debug-I3LGrxPm.js +501 -0
  18. package/dist/chunks/debug-I3LGrxPm.js.map +1 -0
  19. package/dist/chunks/dsl-BAwiOznp.js +1442 -0
  20. package/dist/chunks/dsl-BAwiOznp.js.map +1 -0
  21. package/dist/chunks/hydration-DEmoq1sQ.js +39 -0
  22. package/dist/chunks/hydration-DEmoq1sQ.js.map +1 -0
  23. package/dist/chunks/react-runtime-CrZHuNgA.js +678 -0
  24. package/dist/chunks/react-runtime-CrZHuNgA.js.map +1 -0
  25. package/dist/chunks/runtime-engine-BUiX_aR8.js +2418 -0
  26. package/dist/chunks/runtime-engine-BUiX_aR8.js.map +1 -0
  27. package/dist/chunks/runtime-state-BqEnurQk.js +150 -0
  28. package/dist/chunks/runtime-state-BqEnurQk.js.map +1 -0
  29. package/dist/{merge-styles-Cd2vBl9b.js → chunks/shared-utils-CYgOs2mp.js} +58 -57
  30. package/dist/chunks/shared-utils-CYgOs2mp.js.map +1 -0
  31. package/dist/chunks/style-engine-D8FKtEaC.js +5549 -0
  32. package/dist/chunks/style-engine-D8FKtEaC.js.map +1 -0
  33. package/dist/{css-writer-BWvwQzz0.js → chunks/zero-engine-C17ezpgd.js} +97 -140
  34. package/dist/chunks/zero-engine-C17ezpgd.js.map +1 -0
  35. package/dist/{collector-osfWTeRd.d.ts → collector-BN6hCWIx.d.ts} +62 -10
  36. package/dist/{config-BoZDUHW5.d.ts → config-Chmu-PnP.d.ts} +508 -104
  37. package/dist/core/index.d.ts +5 -5
  38. package/dist/core/index.js +9 -6
  39. package/dist/hydrate-CTh8SGd9.d.ts +20 -0
  40. package/dist/{index-B_k47mc_.d.ts → index-szujmf6W.d.ts} +687 -494
  41. package/dist/index.d.ts +5 -5
  42. package/dist/index.js +11 -732
  43. package/dist/merge-styles-Cx25bpax.d.ts +4 -0
  44. package/dist/ssr/astro-client.d.ts +1 -1
  45. package/dist/ssr/astro-client.js +2 -16
  46. package/dist/ssr/astro-client.js.map +1 -1
  47. package/dist/ssr/astro-middleware-extract-static.d.ts +8 -0
  48. package/dist/ssr/astro-middleware-extract-static.js +8 -0
  49. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  50. package/dist/ssr/astro-middleware-extract.d.ts +8 -0
  51. package/dist/ssr/astro-middleware-extract.js +8 -0
  52. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  53. package/dist/ssr/astro-middleware-static.d.ts +15 -0
  54. package/dist/ssr/astro-middleware-static.js +6 -0
  55. package/dist/ssr/astro-middleware-static.js.map +1 -0
  56. package/dist/ssr/astro-middleware.d.ts +11 -10
  57. package/dist/ssr/astro-middleware.js +3 -16
  58. package/dist/ssr/astro-middleware.js.map +1 -1
  59. package/dist/ssr/astro.d.ts +40 -12
  60. package/dist/ssr/astro.js +163 -93
  61. package/dist/ssr/astro.js.map +1 -1
  62. package/dist/ssr/client.d.ts +2 -0
  63. package/dist/ssr/client.js +1 -0
  64. package/dist/ssr/index.d.ts +5 -34
  65. package/dist/ssr/index.js +7 -8
  66. package/dist/ssr/index.js.map +1 -1
  67. package/dist/ssr/next-config.d.ts +63 -0
  68. package/dist/ssr/next-config.js +122 -0
  69. package/dist/ssr/next-config.js.map +1 -0
  70. package/dist/ssr/next.d.ts +9 -11
  71. package/dist/ssr/next.js +30 -46
  72. package/dist/ssr/next.js.map +1 -1
  73. package/dist/static/index.d.ts +8 -13
  74. package/dist/static/index.js +6 -26
  75. package/dist/static/index.js.map +1 -1
  76. package/dist/static/inject.d.ts +1 -4
  77. package/dist/static/inject.js +1 -2
  78. package/dist/static/inject.js.map +1 -1
  79. package/dist/{index-tcHuMPFt.d.ts → types-DbMN-Yyn.d.ts} +851 -592
  80. package/dist/zero/babel.d.ts +12 -22
  81. package/dist/zero/babel.js +98 -160
  82. package/dist/zero/babel.js.map +1 -1
  83. package/dist/zero/index.d.ts +74 -11
  84. package/dist/zero/index.js +24 -2
  85. package/dist/zero/index.js.map +1 -0
  86. package/dist/zero/next.d.ts +5 -7
  87. package/dist/zero/next.js +4 -40
  88. package/dist/zero/next.js.map +1 -1
  89. package/docs/README.md +20 -9
  90. package/docs/adoption.md +69 -36
  91. package/docs/ai-agents.md +259 -0
  92. package/docs/comparison.md +77 -47
  93. package/docs/configuration.md +617 -98
  94. package/docs/debug.md +28 -15
  95. package/docs/design-system.md +154 -33
  96. package/docs/dsl.md +715 -194
  97. package/docs/getting-started.md +130 -50
  98. package/docs/injector.md +160 -69
  99. package/docs/methodology.md +82 -51
  100. package/docs/migration-v3.md +285 -0
  101. package/docs/pipeline.md +102 -33
  102. package/docs/plugins.md +333 -0
  103. package/docs/react-api.md +215 -50
  104. package/docs/runtime-benchmarks.md +388 -0
  105. package/docs/ssr.md +310 -118
  106. package/docs/styles.md +225 -42
  107. package/docs/tasty-static.md +289 -136
  108. package/package.json +146 -41
  109. package/tasty.config.ts +6 -0
  110. package/dist/async-storage-B7_o6FKt.js +0 -44
  111. package/dist/async-storage-B7_o6FKt.js.map +0 -1
  112. package/dist/collector-C-keQH9m.js.map +0 -1
  113. package/dist/config-BBiyxMCe.js +0 -10559
  114. package/dist/config-BBiyxMCe.js.map +0 -1
  115. package/dist/context-CkSg-kDT.js +0 -24
  116. package/dist/context-CkSg-kDT.js.map +0 -1
  117. package/dist/core-BO4319td.js +0 -1598
  118. package/dist/core-BO4319td.js.map +0 -1
  119. package/dist/css-writer-BWvwQzz0.js.map +0 -1
  120. package/dist/format-global-rules-Dbc_1tc3.js +0 -22
  121. package/dist/format-global-rules-Dbc_1tc3.js.map +0 -1
  122. package/dist/format-rules-BSjeH4Z7.js +0 -143
  123. package/dist/format-rules-BSjeH4Z7.js.map +0 -1
  124. package/dist/hydrate-CcvrP4qJ.js +0 -45
  125. package/dist/hydrate-CcvrP4qJ.js.map +0 -1
  126. package/dist/index.js.map +0 -1
  127. package/dist/keyframes-BUQhdOSJ.js +0 -588
  128. package/dist/keyframes-BUQhdOSJ.js.map +0 -1
  129. package/dist/merge-styles-BMWcH6MF.d.ts +0 -7
  130. package/dist/merge-styles-Cd2vBl9b.js.map +0 -1
  131. package/dist/resolve-recipes-C1nrvnYh.js +0 -144
  132. package/dist/resolve-recipes-C1nrvnYh.js.map +0 -1
@@ -0,0 +1,4 @@
1
+ import { Y as Styles } from "./types-DbMN-Yyn.js";
2
+ declare function mergeStyles(...objects: (Styles | undefined | null)[]): Styles;
3
+ export { mergeStyles as t };
4
+ //# sourceMappingURL=merge-styles-Cx25bpax.d.ts.map
@@ -1 +1 @@
1
- export { };
1
+ export {}
@@ -1,19 +1,5 @@
1
- import { n as hydrateTastyClasses } from "../hydrate-CcvrP4qJ.js";
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
- */
1
+ import { t as hydrateTastyClasses } from "../chunks/hydration-DEmoq1sQ.js";
2
+ // src/ssr/astro-client.ts
16
3
  if (typeof window !== "undefined") hydrateTastyClasses();
17
- //#endregion
18
4
 
19
5
  //# sourceMappingURL=astro-client.js.map
@@ -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":";;;;;;;;;;;;;;;AAgBA,IAAI,OAAO,WAAW,aACpB,qBAAqB"}
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,8 @@
1
+ /**
2
+ * Prerender-extraction middleware entrypoint for sites without islands.
3
+ * Exported only so Astro can resolve it through the package exports map.
4
+ */
5
+ export declare const onRequest: (context: {
6
+ isPrerendered?: boolean;
7
+ }, next: () => Promise<Response>) => Promise<Response>;
8
+ //# sourceMappingURL=astro-middleware-extract-static.d.ts.map
@@ -0,0 +1,8 @@
1
+ import { tastyMiddleware } from "./astro.js";
2
+ const onRequest = tastyMiddleware({
3
+ transferCache: false,
4
+ extractionMetadata: true
5
+ });
6
+ export { onRequest };
7
+
8
+ //# sourceMappingURL=astro-middleware-extract-static.js.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,8 @@
1
+ /**
2
+ * Prerender-extraction middleware entrypoint with island cache transfer.
3
+ * Exported only so Astro can resolve it through the package exports map.
4
+ */
5
+ export declare const onRequest: (context: {
6
+ isPrerendered?: boolean;
7
+ }, next: () => Promise<Response>) => Promise<Response>;
8
+ //# sourceMappingURL=astro-middleware-extract.d.ts.map
@@ -0,0 +1,8 @@
1
+ import { tastyMiddleware } from "./astro.js";
2
+ const onRequest = tastyMiddleware({
3
+ transferCache: true,
4
+ extractionMetadata: true
5
+ });
6
+ export { onRequest };
7
+
8
+ //# sourceMappingURL=astro-middleware-extract.js.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,15 @@
1
+ /**
2
+ * Astro middleware entrypoint for `tastyIntegration({ islands: false })`.
3
+ *
4
+ * Registered via `addMiddleware()` as
5
+ * `@tenphi/tasty/ssr/astro-middleware-static`. Exposed as a package subpath
6
+ * only so Astro can resolve it — use `tastyMiddleware({ transferCache: false })`
7
+ * directly if you need manual middleware composition.
8
+ *
9
+ * Identical to `./astro-middleware` except that no class-list `<script>` is
10
+ * emitted, so a site without `client:*` islands ships zero client JavaScript.
11
+ */
12
+ export declare const onRequest: (context: {
13
+ isPrerendered?: boolean;
14
+ }, next: () => Promise<Response>) => Promise<Response>;
15
+ //# sourceMappingURL=astro-middleware-static.d.ts.map
@@ -0,0 +1,6 @@
1
+ import { tastyMiddleware } from "./astro.js";
2
+ // src/ssr/astro-middleware-static.ts
3
+ const onRequest = tastyMiddleware({ transferCache: false });
4
+ export { onRequest };
5
+
6
+ //# sourceMappingURL=astro-middleware-static.js.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,16 @@
1
- //#region src/ssr/astro-middleware.d.ts
2
1
  /**
3
- * Astro middleware entrypoint for tastyIntegration().
2
+ * Astro middleware entrypoint for `tastyIntegration()`.
4
3
  *
5
- * Referenced by the integration via addMiddleware(). Not intended
6
- * as a public package export — use tastyMiddleware() directly if
7
- * you need manual middleware composition.
4
+ * Registered via `addMiddleware()` as `@tenphi/tasty/ssr/astro-middleware`.
5
+ * Exposed as a package subpath only so Astro can resolve it — use
6
+ * `tastyMiddleware()` directly if you need manual middleware composition.
8
7
  *
9
- * The transferCache setting is controlled by setMiddlewareTransferCache(),
10
- * called by tastyIntegration() before middleware is loaded.
8
+ * This is the islands variant: the rendered class list is transferred to the
9
+ * client so hydrating islands skip the style pipeline. See
10
+ * `./astro-middleware-static` for the variant used by
11
+ * `tastyIntegration({ islands: false })`.
11
12
  */
12
- declare const onRequest: (_context: unknown, next: () => Promise<Response>) => Promise<Response>;
13
- //#endregion
14
- export { onRequest };
13
+ export declare const onRequest: (context: {
14
+ isPrerendered?: boolean;
15
+ }, next: () => Promise<Response>) => Promise<Response>;
15
16
  //# sourceMappingURL=astro-middleware.d.ts.map
@@ -1,19 +1,6 @@
1
- import { getMiddlewareTransferCache, tastyMiddleware } from "./astro.js";
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
- } });
16
- //#endregion
1
+ import { tastyMiddleware } from "./astro.js";
2
+ // src/ssr/astro-middleware.ts
3
+ const onRequest = tastyMiddleware({ transferCache: true });
17
4
  export { onRequest };
18
5
 
19
6
  //# sourceMappingURL=astro-middleware.js.map
@@ -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 * Referenced by the integration via addMiddleware(). Not intended\n * as a public package export — use tastyMiddleware() directly if\n * you need manual middleware composition.\n *\n * The transferCache setting is controlled by setMiddlewareTransferCache(),\n * called by tastyIntegration() before middleware is loaded.\n */\n\nimport { getMiddlewareTransferCache, tastyMiddleware } from './astro';\n\nexport const onRequest = tastyMiddleware({\n get transferCache() {\n return getMiddlewareTransferCache();\n },\n});\n"],"mappings":";;;;;;;;;;;;AAaA,MAAa,YAAY,gBAAgB,EACvC,IAAI,gBAAgB;CAClB,OAAO,4BAA4B;GAEtC,CAAC"}
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"}
@@ -1,4 +1,3 @@
1
- //#region src/ssr/astro.d.ts
2
1
  /**
3
2
  * Astro integration for Tasty SSR.
4
3
  *
@@ -8,7 +7,7 @@
8
7
  *
9
8
  * Import from '@tenphi/tasty/ssr/astro'.
10
9
  */
11
- interface TastyMiddlewareOptions {
10
+ export interface TastyMiddlewareOptions {
12
11
  /**
13
12
  * Whether to embed the class-list script for client hydration.
14
13
  * Set to false to skip class transfer (e.g. for CSP restrictions).
@@ -43,12 +42,20 @@ interface TastyMiddlewareOptions {
43
42
  * );
44
43
  * ```
45
44
  */
46
- declare function tastyMiddleware(options?: TastyMiddlewareOptions): (_context: unknown, next: () => Promise<Response>) => Promise<Response>;
47
- /** @internal */
48
- declare function setMiddlewareTransferCache(value: boolean): void;
49
- /** @internal */
50
- declare function getMiddlewareTransferCache(): boolean;
51
- interface TastyIntegrationOptions {
45
+ export declare function tastyMiddleware(options?: TastyMiddlewareOptions): (context: {
46
+ isPrerendered?: boolean;
47
+ }, next: () => Promise<Response>) => Promise<Response>;
48
+ export interface TastyIntegrationCSSOptions {
49
+ /**
50
+ * CSS delivery mode. Extraction only applies to prerendered builds.
51
+ * Extracted CSS preserves resource URLs verbatim, so use absolute URLs or
52
+ * data URLs. Root-relative URLs are also supported unless `assetsPrefix`
53
+ * sends CSS to an external origin. The build rejects resource URLs whose
54
+ * targets would change after extraction.
55
+ */
56
+ mode?: 'inline' | 'extract';
57
+ }
58
+ export interface TastyIntegrationOptions {
52
59
  /**
53
60
  * Enable island hydration support.
54
61
  *
@@ -61,6 +68,8 @@ interface TastyIntegrationOptions {
61
68
  * directives.
62
69
  */
63
70
  islands?: boolean;
71
+ /** Configure inline or build-wide extracted CSS delivery. */
72
+ css?: TastyIntegrationCSSOptions;
64
73
  }
65
74
  /**
66
75
  * Astro integration that automatically sets up Tasty SSR.
@@ -88,10 +97,29 @@ interface TastyIntegrationOptions {
88
97
  * });
89
98
  * ```
90
99
  */
91
- declare function tastyIntegration(options?: TastyIntegrationOptions): {
100
+ export declare function tastyIntegration(options?: TastyIntegrationOptions): {
92
101
  name: string;
93
- hooks: Record<string, (...args: never[]) => void>;
102
+ hooks: {
103
+ 'astro:config:setup': ({ addMiddleware, injectScript }: {
104
+ addMiddleware: (middleware: {
105
+ entrypoint: string | URL;
106
+ order: "pre" | "post";
107
+ }) => void;
108
+ injectScript: (stage: "head-inline" | "before-hydration" | "page" | "page-ssr", content: string) => void;
109
+ }) => void;
110
+ 'astro:config:done': ({ config }: {
111
+ config: {
112
+ base?: string;
113
+ site?: URL;
114
+ build?: {
115
+ assets?: string;
116
+ assetsPrefix?: string | Record<string, string>;
117
+ };
118
+ };
119
+ }) => void;
120
+ 'astro:build:done': ({ dir }: {
121
+ dir: URL;
122
+ }) => Promise<void>;
123
+ };
94
124
  };
95
- //#endregion
96
- export { TastyIntegrationOptions, TastyMiddlewareOptions, getMiddlewareTransferCache, setMiddlewareTransferCache, tastyIntegration, tastyMiddleware };
97
125
  //# sourceMappingURL=astro.d.ts.map
package/dist/ssr/astro.js CHANGED
@@ -1,56 +1,134 @@
1
- import { n as getConfig } from "../config-BBiyxMCe.js";
2
- import { a as registerSSRCollectorGetterGlobal } from "../format-rules-BSjeH4Z7.js";
3
- import { t as ServerStyleCollector } from "../collector-C-keQH9m.js";
4
- import { n as runWithCollector, t as getSSRCollector } from "../async-storage-B7_o6FKt.js";
5
- //#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
- */
1
+ import { f as getRuntimeConfigState, r as registerSSRCollectorGetterGlobal } from "../chunks/runtime-state-BqEnurQk.js";
2
+ import { t as ServerStyleCollector } from "../chunks/collector-EKAsDdmQ.js";
3
+ import { r as runWithCollector, t as getSSRCollector } from "../chunks/async-storage-CzSKAyrI.js";
4
+ import { t as findUnsafeCSSResource } from "../chunks/css-resources-C0zT36nQ.js";
5
+ import { join } from "node:path";
6
+ import { createHash } from "node:crypto";
7
+ import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
8
+ import { fileURLToPath } from "node:url";
9
+ // 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
+ // src/ssr/astro.ts
15
120
  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
121
  function tastyMiddleware(options) {
43
- return async (_context, next) => {
122
+ const internalOptions = options;
123
+ return async (context, next) => {
44
124
  const transferCache = options?.transferCache ?? true;
125
+ const extractionMetadata = internalOptions?.extractionMetadata === true && context.isPrerendered === true;
45
126
  const collector = new ServerStyleCollector();
46
127
  const rendered = await runWithCollector(collector, async () => {
47
128
  const response = await next();
48
129
  const body = response.body;
49
- if (!body) return {
50
- html: null,
51
- status: response.status,
52
- headers: response.headers
53
- };
130
+ const contentType = response.headers.get("content-type") ?? "";
131
+ if (!body || !contentType.includes("text/html")) return { response };
54
132
  const reader = body.pipeThrough(new TextDecoderStream()).getReader();
55
133
  const parts = [];
56
134
  for (;;) {
@@ -64,6 +142,7 @@ function tastyMiddleware(options) {
64
142
  headers: response.headers
65
143
  };
66
144
  });
145
+ if ("response" in rendered) return rendered.response;
67
146
  if (!rendered.html) return new Response(null, {
68
147
  status: rendered.status,
69
148
  headers: rendered.headers
@@ -74,15 +153,16 @@ function tastyMiddleware(options) {
74
153
  status: rendered.status,
75
154
  headers: rendered.headers
76
155
  });
77
- const nonce = getConfig().nonce;
156
+ const nonce = getRuntimeConfigState()?.nonce;
78
157
  const nonceAttr = nonce ? ` nonce="${nonce}"` : "";
79
158
  const styleTag = `<style data-tasty-ssr${nonceAttr}>${css}</style>`;
159
+ const metadataTag = extractionMetadata ? createExtractionMetadata(collector.getArtifacts()) : "";
80
160
  let cacheTag = "";
81
161
  if (transferCache) {
82
162
  const classNames = collector.getRenderedClassNames();
83
163
  if (classNames.length > 0) cacheTag = `<script${nonceAttr}>(window.__TASTY__=window.__TASTY__||[]).push(${classNames.map((n) => `"${n}"`).join(",")})<\/script>`;
84
164
  }
85
- const injection = styleTag + cacheTag;
165
+ const injection = styleTag + metadataTag + cacheTag;
86
166
  const idx = html.indexOf("</head>");
87
167
  if (idx !== -1) html = html.slice(0, idx) + injection + html.slice(idx);
88
168
  else html = injection + html;
@@ -94,56 +174,46 @@ function tastyMiddleware(options) {
94
174
  });
95
175
  };
96
176
  }
97
- let _middlewareTransferCache = true;
98
- /** @internal */
99
- function setMiddlewareTransferCache(value) {
100
- _middlewareTransferCache = value;
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
- */
177
+ const MIDDLEWARE_ENTRYPOINT = "@tenphi/tasty/ssr/astro-middleware";
178
+ const MIDDLEWARE_ENTRYPOINT_STATIC = "@tenphi/tasty/ssr/astro-middleware-static";
179
+ const MIDDLEWARE_ENTRYPOINT_EXTRACT = "@tenphi/tasty/ssr/astro-middleware-extract";
180
+ const MIDDLEWARE_ENTRYPOINT_EXTRACT_STATIC = "@tenphi/tasty/ssr/astro-middleware-extract-static";
132
181
  function tastyIntegration(options) {
133
182
  const { islands = true } = options ?? {};
134
- setMiddlewareTransferCache(islands);
183
+ const cssMode = options?.css?.mode ?? "inline";
184
+ let base = "/";
185
+ let assets = "_astro";
186
+ let assetsPrefix;
187
+ let site;
135
188
  return {
136
189
  name: "@tenphi/tasty",
137
- hooks: { "astro:config:setup": ({ addMiddleware, injectScript }) => {
138
- addMiddleware({
139
- entrypoint: new URL("./astro-middleware.js", import.meta.url),
140
- order: "pre"
141
- });
142
- if (islands) injectScript("before-hydration", `import "@tenphi/tasty/ssr/astro-client";`);
143
- } }
190
+ hooks: {
191
+ "astro:config:setup": ({ addMiddleware, injectScript }) => {
192
+ addMiddleware({
193
+ entrypoint: cssMode === "extract" ? islands ? MIDDLEWARE_ENTRYPOINT_EXTRACT : MIDDLEWARE_ENTRYPOINT_EXTRACT_STATIC : islands ? MIDDLEWARE_ENTRYPOINT : MIDDLEWARE_ENTRYPOINT_STATIC,
194
+ order: "pre"
195
+ });
196
+ if (islands) injectScript("before-hydration", `import "@tenphi/tasty/ssr/astro-client";`);
197
+ },
198
+ "astro:config:done": ({ config }) => {
199
+ base = config.base ?? "/";
200
+ assets = config.build?.assets ?? "_astro";
201
+ assetsPrefix = config.build?.assetsPrefix;
202
+ site = config.site;
203
+ },
204
+ "astro:build:done": async ({ dir }) => {
205
+ if (cssMode !== "extract") return;
206
+ await extractAstroCSS({
207
+ dir,
208
+ base,
209
+ assets,
210
+ assetsPrefix,
211
+ site
212
+ });
213
+ }
214
+ }
144
215
  };
145
216
  }
146
- //#endregion
147
- export { getMiddlewareTransferCache, setMiddlewareTransferCache, tastyIntegration, tastyMiddleware };
217
+ export { tastyIntegration, tastyMiddleware };
148
218
 
149
219
  //# sourceMappingURL=astro.js.map