@tenphi/tasty 0.0.0-snapshot.a85ade8 → 0.0.0-snapshot.a8a2a5d
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 +418 -381
- package/dist/babel-types-BOABQvEI.d.ts +16 -0
- package/dist/chunks/async-storage-CzSKAyrI.js +36 -0
- package/dist/chunks/async-storage-CzSKAyrI.js.map +1 -0
- package/dist/chunks/build-config-DQkT3Wru.js +59 -0
- package/dist/chunks/build-config-DQkT3Wru.js.map +1 -0
- package/dist/{collector-C6TtL8HJ.js → chunks/collector-Df9zcabl.js} +11 -129
- package/dist/chunks/collector-Df9zcabl.js.map +1 -0
- package/dist/chunks/config-engine-C7OUmM1J.js +269 -0
- package/dist/chunks/config-engine-C7OUmM1J.js.map +1 -0
- package/dist/chunks/config-file-BX3F_61U.js +24 -0
- package/dist/chunks/config-file-BX3F_61U.js.map +1 -0
- package/dist/chunks/css-definitions-BkdTqT7G.js +896 -0
- package/dist/chunks/css-definitions-BkdTqT7G.js.map +1 -0
- package/dist/chunks/css-resources-C0zT36nQ.js +141 -0
- package/dist/chunks/css-resources-C0zT36nQ.js.map +1 -0
- package/dist/chunks/debug-CwGMB2RI.js +501 -0
- package/dist/chunks/debug-CwGMB2RI.js.map +1 -0
- package/dist/chunks/dsl-BAwiOznp.js +1442 -0
- package/dist/chunks/dsl-BAwiOznp.js.map +1 -0
- package/dist/chunks/hydration-DEmoq1sQ.js +39 -0
- package/dist/chunks/hydration-DEmoq1sQ.js.map +1 -0
- package/dist/chunks/react-runtime-B8YqpFx7.js +678 -0
- package/dist/chunks/react-runtime-B8YqpFx7.js.map +1 -0
- package/dist/chunks/runtime-engine-CHNH2nGy.js +2418 -0
- package/dist/chunks/runtime-engine-CHNH2nGy.js.map +1 -0
- package/dist/chunks/runtime-state-BxLKsQzs.js +150 -0
- package/dist/chunks/runtime-state-BxLKsQzs.js.map +1 -0
- package/dist/{merge-styles-DuoZEsm9.js → chunks/shared-utils-CYgOs2mp.js} +58 -57
- package/dist/chunks/shared-utils-CYgOs2mp.js.map +1 -0
- package/dist/chunks/style-engine-DkKH-TqL.js +5573 -0
- package/dist/chunks/style-engine-DkKH-TqL.js.map +1 -0
- package/dist/{css-writer-Bgowobbx.js → chunks/zero-engine-C-0ar_PT.js} +67 -149
- package/dist/chunks/zero-engine-C-0ar_PT.js.map +1 -0
- package/dist/{collector-BTVXj2hS.d.ts → collector-BN6hCWIx.d.ts} +3 -6
- package/dist/{config-LfIDmVHx.d.ts → config-Chmu-PnP.d.ts} +49 -63
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +9 -6
- package/dist/hydrate-CTh8SGd9.d.ts +20 -0
- package/dist/{index-Bm9ltvdH.d.ts → index-szujmf6W.d.ts} +263 -348
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -922
- package/dist/merge-styles-Cx25bpax.d.ts +4 -0
- package/dist/ssr/astro-client.d.ts +1 -1
- package/dist/ssr/astro-client.js +2 -16
- package/dist/ssr/astro-client.js.map +1 -1
- package/dist/ssr/astro-middleware-extract-static.d.ts +1 -4
- package/dist/ssr/astro-middleware-extract-static.js +1 -2
- package/dist/ssr/astro-middleware-extract.d.ts +1 -4
- package/dist/ssr/astro-middleware-extract.js +1 -2
- package/dist/ssr/astro-middleware-static.d.ts +1 -4
- package/dist/ssr/astro-middleware-static.js +2 -14
- package/dist/ssr/astro-middleware-static.js.map +1 -1
- package/dist/ssr/astro-middleware.d.ts +1 -4
- package/dist/ssr/astro-middleware.js +2 -15
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +17 -19
- package/dist/ssr/astro.js +218 -1
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/client.d.ts +2 -0
- package/dist/ssr/client.js +1 -0
- package/dist/ssr/index.d.ts +5 -27
- package/dist/ssr/index.js +6 -7
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +63 -0
- package/dist/ssr/next-config.js +122 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +9 -10
- package/dist/ssr/next.js +30 -45
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +8 -13
- package/dist/static/index.js +6 -26
- package/dist/static/index.js.map +1 -1
- package/dist/static/inject.d.ts +1 -4
- package/dist/static/inject.js +1 -2
- package/dist/{index-BmogEzTo.d.ts → types-DbMN-Yyn.d.ts} +1013 -1043
- package/dist/zero/babel.d.ts +71 -2
- package/dist/zero/babel.js +84 -150
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +61 -12
- package/dist/zero/index.js +24 -2
- package/dist/zero/index.js.map +1 -0
- package/dist/zero/next.d.ts +5 -7
- package/dist/zero/next.js +4 -40
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +4 -1
- package/docs/adoption.md +25 -17
- package/docs/ai-agents.md +69 -34
- package/docs/comparison.md +9 -8
- package/docs/configuration.md +204 -70
- package/docs/debug.md +18 -7
- package/docs/design-system.md +129 -15
- package/docs/dsl.md +327 -117
- package/docs/getting-started.md +81 -22
- package/docs/injector.md +41 -40
- package/docs/llms.txt +31 -0
- package/docs/methodology.md +48 -23
- package/docs/migration-v3.md +3 -3
- package/docs/pipeline.md +55 -28
- package/docs/plugins.md +22 -42
- package/docs/react-api.md +76 -11
- package/docs/runtime-benchmarks.md +257 -47
- package/docs/ssr.md +226 -80
- package/docs/styles.md +169 -33
- package/docs/tasty-static.md +176 -58
- package/harness/dev.harnesspm/rules/usage.md +12 -0
- package/harness/dev.harnesspm/scripts/render.mjs +320 -0
- package/harness/dev.harnesspm/scripts/styles.mjs +299 -0
- package/harness/plugin.json +20 -0
- package/package.json +116 -48
- package/tasty.config.ts +1 -0
- package/dist/astro-ib7E7V4Y.js +0 -307
- package/dist/astro-ib7E7V4Y.js.map +0 -1
- package/dist/async-storage-DKK-wTD4.js +0 -44
- package/dist/async-storage-DKK-wTD4.js.map +0 -1
- package/dist/babel-DWCsafYw.d.ts +0 -83
- package/dist/collector-C6TtL8HJ.js.map +0 -1
- package/dist/config-B3gPdCqd.js +0 -12421
- package/dist/config-B3gPdCqd.js.map +0 -1
- package/dist/context-CA8YKeMn.js +0 -24
- package/dist/context-CA8YKeMn.js.map +0 -1
- package/dist/core-Bq7w2kti.js +0 -1686
- package/dist/core-Bq7w2kti.js.map +0 -1
- package/dist/css-writer-Bgowobbx.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-rCZ37rqY.js +0 -130
- package/dist/format-rules-rCZ37rqY.js.map +0 -1
- package/dist/hydrate-CNOmZprz.js +0 -37
- package/dist/hydrate-CNOmZprz.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-DE-OE76F.js +0 -535
- package/dist/keyframes-DE-OE76F.js.map +0 -1
- package/dist/merge-styles-BcLl1u_d.d.ts +0 -7
- package/dist/merge-styles-DuoZEsm9.js.map +0 -1
- package/dist/resolve-recipes-H9NqOQuP.js +0 -144
- package/dist/resolve-recipes-H9NqOQuP.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tenphi/tasty",
|
|
3
|
-
"version": "0.0.0-snapshot.
|
|
3
|
+
"version": "0.0.0-snapshot.a8a2a5d",
|
|
4
4
|
"description": "A design-system-integrated styling system and DSL for concise, state-aware UI styling",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -52,11 +52,21 @@
|
|
|
52
52
|
"import": "./dist/ssr/next.js",
|
|
53
53
|
"default": "./dist/ssr/next.js"
|
|
54
54
|
},
|
|
55
|
+
"./ssr/next-config": {
|
|
56
|
+
"types": "./dist/ssr/next-config.d.ts",
|
|
57
|
+
"import": "./dist/ssr/next-config.js",
|
|
58
|
+
"default": "./dist/ssr/next-config.js"
|
|
59
|
+
},
|
|
55
60
|
"./ssr/astro": {
|
|
56
61
|
"types": "./dist/ssr/astro.d.ts",
|
|
57
62
|
"import": "./dist/ssr/astro.js",
|
|
58
63
|
"default": "./dist/ssr/astro.js"
|
|
59
64
|
},
|
|
65
|
+
"./ssr/client": {
|
|
66
|
+
"types": "./dist/ssr/client.d.ts",
|
|
67
|
+
"import": "./dist/ssr/client.js",
|
|
68
|
+
"default": "./dist/ssr/client.js"
|
|
69
|
+
},
|
|
60
70
|
"./ssr/astro-client": {
|
|
61
71
|
"types": "./dist/ssr/astro-client.d.ts",
|
|
62
72
|
"import": "./dist/ssr/astro-client.js",
|
|
@@ -87,6 +97,7 @@
|
|
|
87
97
|
"files": [
|
|
88
98
|
"dist",
|
|
89
99
|
"docs",
|
|
100
|
+
"harness",
|
|
90
101
|
"tasty.config.ts"
|
|
91
102
|
],
|
|
92
103
|
"sideEffects": [
|
|
@@ -111,20 +122,27 @@
|
|
|
111
122
|
"test:watch": "vitest",
|
|
112
123
|
"test:coverage": "vitest run --coverage",
|
|
113
124
|
"typecheck": "tsc --noEmit",
|
|
114
|
-
"lint": "eslint src",
|
|
115
|
-
"lint:fix": "eslint src --fix",
|
|
116
|
-
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
|
|
117
|
-
"format:check": "prettier --check \"src/**/*.{ts,tsx}\"",
|
|
125
|
+
"lint": "eslint src harness",
|
|
126
|
+
"lint:fix": "eslint src harness --fix",
|
|
127
|
+
"format": "prettier --write \"src/**/*.{ts,tsx}\" \"harness/**/*.mjs\"",
|
|
128
|
+
"format:check": "prettier --check \"src/**/*.{ts,tsx}\" \"harness/**/*.mjs\"",
|
|
118
129
|
"size": "size-limit",
|
|
119
|
-
"bench": "vitest bench --project node",
|
|
120
|
-
"bench:browser": "vitest bench --project browser",
|
|
130
|
+
"bench": "vitest bench --project \"node (bench)\"",
|
|
131
|
+
"bench:browser": "vitest bench --project \"browser (chromium) (bench)\"",
|
|
121
132
|
"bench:overhead": "vitest bench --config vitest.production-browser-bench.config.ts src/tasty-overhead.bench.tsx",
|
|
122
133
|
"bench:injection": "vitest bench --config vitest.production-browser-bench.config.ts src/tasty-injection.bench.ts",
|
|
134
|
+
"bench:interaction": "vitest bench --config vitest.production-browser-bench.config.ts src/tasty-interaction.bench.tsx",
|
|
135
|
+
"bench:tree": "vitest bench --config vitest.production-browser-bench.config.ts src/tasty-tree.bench.tsx",
|
|
136
|
+
"bench:cold-start": "node scripts/cold-start/index.mjs",
|
|
123
137
|
"prepublishOnly": "pnpm run build",
|
|
124
138
|
"changeset": "changeset",
|
|
125
139
|
"version": "changeset version",
|
|
126
140
|
"release": "changeset publish",
|
|
127
141
|
"knip": "knip",
|
|
142
|
+
"check:harness": "harnesspm check",
|
|
143
|
+
"check:build": "node scripts/check-built-entries.mjs",
|
|
144
|
+
"check:react-compat": "node scripts/check-react-compat.mjs",
|
|
145
|
+
"check:babel-compat": "node scripts/check-babel-compat.mjs",
|
|
128
146
|
"check:test-only": "node scripts/check-test-only-code.mjs",
|
|
129
147
|
"hygiene": "pnpm lint && pnpm format:check && pnpm typecheck",
|
|
130
148
|
"hygiene:fix": "pnpm lint:fix && pnpm format && pnpm typecheck"
|
|
@@ -151,9 +169,9 @@
|
|
|
151
169
|
},
|
|
152
170
|
"homepage": "https://github.com/tenphi/tasty#readme",
|
|
153
171
|
"peerDependencies": {
|
|
154
|
-
"@babel/core": "^7.24.0",
|
|
155
|
-
"@babel/helper-plugin-utils": "^7.24.0",
|
|
156
|
-
"@babel/types": "^8.0.
|
|
172
|
+
"@babel/core": "^7.24.0 || ^8.0.0",
|
|
173
|
+
"@babel/helper-plugin-utils": "^7.24.0 || ^8.0.0",
|
|
174
|
+
"@babel/types": "^7.24.0 || ^8.0.0",
|
|
157
175
|
"jiti": "^2.6.1",
|
|
158
176
|
"next": ">=14.0.0",
|
|
159
177
|
"react": "^18.0.0 || ^19.0.0"
|
|
@@ -182,59 +200,83 @@
|
|
|
182
200
|
"csstype": "^3.1.0"
|
|
183
201
|
},
|
|
184
202
|
"devDependencies": {
|
|
185
|
-
"@astrojs/react": "^
|
|
186
|
-
"@babel/core": "^
|
|
187
|
-
"@babel/helper-plugin-utils": "^
|
|
188
|
-
"@babel/types": "^8.0.
|
|
189
|
-
"@changesets/changelog-github": "^0.
|
|
190
|
-
"@changesets/cli": "^
|
|
203
|
+
"@astrojs/react": "^7.0.1",
|
|
204
|
+
"@babel/core": "^8.0.6",
|
|
205
|
+
"@babel/helper-plugin-utils": "^8.0.1",
|
|
206
|
+
"@babel/types": "^8.0.6",
|
|
207
|
+
"@changesets/changelog-github": "^1.0.1",
|
|
208
|
+
"@changesets/cli": "^3.0.3",
|
|
191
209
|
"@eslint/js": "^10.0.1",
|
|
192
|
-
"@size-limit/esbuild": "^
|
|
193
|
-
"@size-limit/file": "^
|
|
194
|
-
"@tenphi/eslint-plugin-tasty": "^1.0
|
|
195
|
-
"@
|
|
196
|
-
"@testing-library/
|
|
197
|
-
"@
|
|
198
|
-
"@types/
|
|
199
|
-
"@types/
|
|
200
|
-
"@types/react": "^19.
|
|
201
|
-
"@
|
|
202
|
-
"
|
|
203
|
-
"
|
|
204
|
-
"eslint": "^10.
|
|
210
|
+
"@size-limit/esbuild": "^14.1.0",
|
|
211
|
+
"@size-limit/file": "^14.1.0",
|
|
212
|
+
"@tenphi/eslint-plugin-tasty": "^1.17.0",
|
|
213
|
+
"@tenphi/harnesspm": "^0.1.0",
|
|
214
|
+
"@testing-library/jest-dom": "^7.0.1",
|
|
215
|
+
"@testing-library/react": "^16.3.3",
|
|
216
|
+
"@types/node": "^24.19.1",
|
|
217
|
+
"@types/react": "^19.3.0",
|
|
218
|
+
"@types/react-dom": "^19.3.0",
|
|
219
|
+
"@vitest/browser-playwright": "^5.0.3",
|
|
220
|
+
"astro": "^7.3.6",
|
|
221
|
+
"esbuild": "^0.28.2",
|
|
222
|
+
"eslint": "^10.12.0",
|
|
205
223
|
"eslint-config-prettier": "^10.1.8",
|
|
206
|
-
"jiti": "^2.
|
|
207
|
-
"knip": "^
|
|
208
|
-
"next": "^16.
|
|
209
|
-
"playwright": "^1.
|
|
210
|
-
"prettier": "^3.9.
|
|
211
|
-
"react": "^19.
|
|
212
|
-
"react-dom": "^19.
|
|
213
|
-
"size-limit": "^
|
|
214
|
-
"tsdown": "^0.
|
|
215
|
-
"typescript": "^6.0.
|
|
216
|
-
"typescript-eslint": "^8.
|
|
217
|
-
"vitest": "^
|
|
224
|
+
"jiti": "^2.7.0",
|
|
225
|
+
"knip": "^6.40.0",
|
|
226
|
+
"next": "^16.4.0",
|
|
227
|
+
"playwright": "^1.63.0",
|
|
228
|
+
"prettier": "^3.9.9",
|
|
229
|
+
"react": "^19.3.0",
|
|
230
|
+
"react-dom": "^19.3.0",
|
|
231
|
+
"size-limit": "^14.1.0",
|
|
232
|
+
"tsdown": "^0.23.0",
|
|
233
|
+
"typescript": "^6.0.3",
|
|
234
|
+
"typescript-eslint": "^8.71.1",
|
|
235
|
+
"vitest": "^5.0.3"
|
|
218
236
|
},
|
|
219
|
-
"packageManager": "pnpm@11.
|
|
237
|
+
"packageManager": "pnpm@11.27.1",
|
|
220
238
|
"size-limit": [
|
|
221
239
|
{
|
|
222
240
|
"name": "main (import *)",
|
|
223
241
|
"path": "dist/index.js",
|
|
224
242
|
"import": "*",
|
|
225
|
-
"limit": "
|
|
243
|
+
"limit": "62.08 kB"
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
"name": "main (tasty)",
|
|
247
|
+
"path": "dist/index.js",
|
|
248
|
+
"import": "{ tasty }",
|
|
249
|
+
"limit": "54.99 kB"
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
"name": "main (StyleParser)",
|
|
253
|
+
"path": "dist/index.js",
|
|
254
|
+
"import": "{ StyleParser }",
|
|
255
|
+
"limit": "8 kB"
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
"name": "main (parseColor)",
|
|
259
|
+
"path": "dist/index.js",
|
|
260
|
+
"import": "{ parseColor }",
|
|
261
|
+
"limit": "8.67 kB"
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
"name": "main (useRawCSS)",
|
|
265
|
+
"path": "dist/index.js",
|
|
266
|
+
"import": "{ useRawCSS }",
|
|
267
|
+
"limit": "33.63 kB"
|
|
226
268
|
},
|
|
227
269
|
{
|
|
228
270
|
"name": "core (import *)",
|
|
229
271
|
"path": "dist/core/index.js",
|
|
230
272
|
"import": "*",
|
|
231
|
-
"limit": "
|
|
273
|
+
"limit": "57.38 kB"
|
|
232
274
|
},
|
|
233
275
|
{
|
|
234
276
|
"name": "static",
|
|
235
277
|
"path": "dist/static/index.js",
|
|
236
278
|
"import": "*",
|
|
237
|
-
"limit": "
|
|
279
|
+
"limit": "1.08 kB"
|
|
238
280
|
},
|
|
239
281
|
{
|
|
240
282
|
"name": "zero",
|
|
@@ -245,7 +287,7 @@
|
|
|
245
287
|
"path",
|
|
246
288
|
"crypto"
|
|
247
289
|
],
|
|
248
|
-
"limit": "
|
|
290
|
+
"limit": "41.3 kB"
|
|
249
291
|
},
|
|
250
292
|
{
|
|
251
293
|
"name": "babel-plugin",
|
|
@@ -254,9 +296,35 @@
|
|
|
254
296
|
"ignore": [
|
|
255
297
|
"fs",
|
|
256
298
|
"path",
|
|
257
|
-
"crypto"
|
|
299
|
+
"crypto",
|
|
300
|
+
"node:module",
|
|
301
|
+
"node:path"
|
|
302
|
+
],
|
|
303
|
+
"limit": "45.95 kB"
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
"name": "astro client",
|
|
307
|
+
"path": "dist/ssr/astro-client.js",
|
|
308
|
+
"import": "*",
|
|
309
|
+
"limit": "0.5 kB"
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
"name": "ssr client",
|
|
313
|
+
"path": "dist/ssr/client.js",
|
|
314
|
+
"import": "{ hydrateTastyClasses }",
|
|
315
|
+
"limit": "0.5 kB"
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
"name": "Next.js config",
|
|
319
|
+
"path": "dist/ssr/next-config.js",
|
|
320
|
+
"import": "{ withTastyNext }",
|
|
321
|
+
"ignore": [
|
|
322
|
+
"node:crypto",
|
|
323
|
+
"node:fs",
|
|
324
|
+
"node:module",
|
|
325
|
+
"node:path"
|
|
258
326
|
],
|
|
259
|
-
"limit": "
|
|
327
|
+
"limit": "41.48 kB"
|
|
260
328
|
}
|
|
261
329
|
]
|
|
262
330
|
}
|
package/tasty.config.ts
CHANGED
package/dist/astro-ib7E7V4Y.js
DELETED
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
import { n as getConfig } from "./config-B3gPdCqd.js";
|
|
2
|
-
import { a as registerSSRCollectorGetterGlobal } from "./format-rules-rCZ37rqY.js";
|
|
3
|
-
import { t as ServerStyleCollector } from "./collector-C6TtL8HJ.js";
|
|
4
|
-
import { n as runWithCollector, t as getSSRCollector } from "./async-storage-DKK-wTD4.js";
|
|
5
|
-
import { createHash } from "node:crypto";
|
|
6
|
-
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
7
|
-
import { join } from "node:path";
|
|
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
|
-
return `${METADATA_START}${Buffer.from(JSON.stringify(artifacts), "utf8").toString("base64")}${METADATA_END}`;
|
|
14
|
-
}
|
|
15
|
-
function parseExtractablePage(path, html) {
|
|
16
|
-
const metadataStart = html.indexOf(METADATA_START);
|
|
17
|
-
if (metadataStart === -1) return null;
|
|
18
|
-
const metadataContentStart = metadataStart + 29;
|
|
19
|
-
const metadataEnd = html.indexOf(METADATA_END, metadataContentStart);
|
|
20
|
-
if (metadataEnd === -1) return null;
|
|
21
|
-
const encoded = html.slice(metadataContentStart, metadataEnd);
|
|
22
|
-
let artifacts;
|
|
23
|
-
try {
|
|
24
|
-
artifacts = JSON.parse(Buffer.from(encoded, "base64").toString("utf8"));
|
|
25
|
-
} catch {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
const styleStart = html.lastIndexOf("<style data-tasty-ssr", metadataStart);
|
|
29
|
-
if (styleStart === -1) return null;
|
|
30
|
-
const styleOpenEnd = html.indexOf(">", styleStart);
|
|
31
|
-
const styleEnd = html.indexOf("</style>", styleOpenEnd + 1);
|
|
32
|
-
if (styleOpenEnd === -1 || styleEnd === -1 || styleEnd + 8 !== metadataStart) return null;
|
|
33
|
-
return {
|
|
34
|
-
path,
|
|
35
|
-
html,
|
|
36
|
-
artifacts,
|
|
37
|
-
styleStart,
|
|
38
|
-
replacementEnd: metadataEnd + 11,
|
|
39
|
-
styleOpen: html.slice(styleStart, styleOpenEnd + 1)
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
async function findHTMLFiles(dir) {
|
|
43
|
-
const paths = [];
|
|
44
|
-
const entries = await readdir(dir, { withFileTypes: true });
|
|
45
|
-
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
46
|
-
for (const entry of entries) {
|
|
47
|
-
const path = join(dir, entry.name);
|
|
48
|
-
if (entry.isDirectory()) paths.push(...await findHTMLFiles(path));
|
|
49
|
-
else if (entry.isFile() && entry.name.endsWith(".html")) paths.push(path);
|
|
50
|
-
}
|
|
51
|
-
return paths;
|
|
52
|
-
}
|
|
53
|
-
function findSequence(haystack, needle) {
|
|
54
|
-
if (needle.length === 0) return -1;
|
|
55
|
-
outer: for (let i = 0; i <= haystack.length - needle.length; i++) {
|
|
56
|
-
for (let j = 0; j < needle.length; j++) if (haystack[i + j] !== needle[j]) continue outer;
|
|
57
|
-
return i;
|
|
58
|
-
}
|
|
59
|
-
return -1;
|
|
60
|
-
}
|
|
61
|
-
/** Find the largest byte-sized artifact block that is contiguous on every page. */
|
|
62
|
-
function selectSharedArtifacts(pages) {
|
|
63
|
-
if (pages.length < 2) return [];
|
|
64
|
-
const source = pages.reduce((shortest, page) => page.artifacts.length < shortest.artifacts.length ? page : shortest);
|
|
65
|
-
const otherIds = pages.filter((page) => page !== source).map((page) => page.artifacts.map(({ id }) => id));
|
|
66
|
-
const sourceIds = source.artifacts.map(({ id }) => id);
|
|
67
|
-
let best = [];
|
|
68
|
-
let bestBytes = 0;
|
|
69
|
-
for (let start = 0; start < source.artifacts.length; start++) {
|
|
70
|
-
let length = source.artifacts.length - start;
|
|
71
|
-
for (const pageIds of otherIds) {
|
|
72
|
-
let pageLength = 0;
|
|
73
|
-
for (let pageStart = 0; pageStart < pageIds.length; pageStart++) {
|
|
74
|
-
if (pageIds[pageStart] !== sourceIds[start]) continue;
|
|
75
|
-
let matchLength = 1;
|
|
76
|
-
while (start + matchLength < sourceIds.length && pageStart + matchLength < pageIds.length && sourceIds[start + matchLength] === pageIds[pageStart + matchLength]) matchLength++;
|
|
77
|
-
pageLength = Math.max(pageLength, matchLength);
|
|
78
|
-
}
|
|
79
|
-
length = Math.min(length, pageLength);
|
|
80
|
-
if (length === 0) break;
|
|
81
|
-
}
|
|
82
|
-
const candidate = source.artifacts.slice(start, start + length);
|
|
83
|
-
const bytes = candidate.reduce((total, item) => total + item.css.length, 0);
|
|
84
|
-
if (bytes > bestBytes) {
|
|
85
|
-
best = candidate;
|
|
86
|
-
bestBytes = bytes;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return best;
|
|
90
|
-
}
|
|
91
|
-
function stylesheetHref(base, assets, filename) {
|
|
92
|
-
return `${base === "/" ? "" : `/${base.replace(/^\/+|\/+$/g, "")}`}/${assets.replace(/^\/+|\/+$/g, "")}/${filename}`;
|
|
93
|
-
}
|
|
94
|
-
function styleTag(styleOpen, artifacts) {
|
|
95
|
-
if (artifacts.length === 0) return "";
|
|
96
|
-
return `${styleOpen}${artifacts.map(({ css }) => css).join("\n")}</style>`;
|
|
97
|
-
}
|
|
98
|
-
function transformPage(page, selected, href) {
|
|
99
|
-
const selectedIds = selected.map(({ id }) => id);
|
|
100
|
-
const first = findSequence(page.artifacts.map(({ id }) => id), selectedIds);
|
|
101
|
-
if (first === -1) {
|
|
102
|
-
const metadataStart = page.html.indexOf(METADATA_START, page.styleStart);
|
|
103
|
-
return page.html.slice(0, metadataStart) + page.html.slice(page.replacementEnd);
|
|
104
|
-
}
|
|
105
|
-
const before = page.artifacts.slice(0, first);
|
|
106
|
-
const after = page.artifacts.slice(first + selected.length);
|
|
107
|
-
const link = `<link rel="stylesheet" href="${href}" data-tasty-ssr${page.styleOpen.match(/\snonce="[^"]*"/)?.[0] ?? ""}>`;
|
|
108
|
-
const replacement = styleTag(page.styleOpen, before) + link + styleTag(page.styleOpen, after);
|
|
109
|
-
return page.html.slice(0, page.styleStart) + replacement + page.html.slice(page.replacementEnd);
|
|
110
|
-
}
|
|
111
|
-
async function extractAstroCSS(options) {
|
|
112
|
-
const outputDir = fileURLToPath(options.dir);
|
|
113
|
-
const paths = await findHTMLFiles(outputDir);
|
|
114
|
-
const pages = (await Promise.all(paths.map(async (path) => parseExtractablePage(path, await readFile(path, "utf8"))))).filter((page) => page !== null);
|
|
115
|
-
if (pages.length === 0) return;
|
|
116
|
-
const selected = selectSharedArtifacts(pages);
|
|
117
|
-
if (selected.length === 0) {
|
|
118
|
-
for (const page of pages) {
|
|
119
|
-
const metadataStart = page.html.indexOf(METADATA_START, page.styleStart);
|
|
120
|
-
await writeFile(page.path, page.html.slice(0, metadataStart) + page.html.slice(page.replacementEnd));
|
|
121
|
-
}
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
const css = selected.map(({ css }) => css).join("\n");
|
|
125
|
-
const filename = `tasty.${createHash("sha256").update(css).digest("hex").slice(0, 12)}.css`;
|
|
126
|
-
const assetDir = join(outputDir, options.assets);
|
|
127
|
-
await mkdir(assetDir, { recursive: true });
|
|
128
|
-
await writeFile(join(assetDir, filename), css);
|
|
129
|
-
const href = stylesheetHref(options.base, options.assets, filename);
|
|
130
|
-
for (const page of pages) await writeFile(page.path, transformPage(page, selected, href));
|
|
131
|
-
}
|
|
132
|
-
//#endregion
|
|
133
|
-
//#region src/ssr/astro.ts
|
|
134
|
-
/**
|
|
135
|
-
* Astro integration for Tasty SSR.
|
|
136
|
-
*
|
|
137
|
-
* Provides:
|
|
138
|
-
* - tastyIntegration() — Astro Integration API (recommended)
|
|
139
|
-
* - tastyMiddleware() — manual middleware for advanced composition
|
|
140
|
-
*
|
|
141
|
-
* Import from '@tenphi/tasty/ssr/astro'.
|
|
142
|
-
*/
|
|
143
|
-
registerSSRCollectorGetterGlobal(getSSRCollector);
|
|
144
|
-
/**
|
|
145
|
-
* Create an Astro middleware that collects Tasty styles during SSR.
|
|
146
|
-
*
|
|
147
|
-
* All React components rendered during the request will have their
|
|
148
|
-
* computeStyles() calls captured by the collector via AsyncLocalStorage.
|
|
149
|
-
* After rendering, the middleware injects the collected CSS into </head>.
|
|
150
|
-
*
|
|
151
|
-
* @example Manual middleware setup
|
|
152
|
-
* ```ts
|
|
153
|
-
* // src/middleware.ts
|
|
154
|
-
* import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
|
|
155
|
-
* export const onRequest = tastyMiddleware();
|
|
156
|
-
* ```
|
|
157
|
-
*
|
|
158
|
-
* @example Composing with other middleware
|
|
159
|
-
* ```ts
|
|
160
|
-
* // src/middleware.ts
|
|
161
|
-
* import { sequence } from 'astro:middleware';
|
|
162
|
-
* import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
|
|
163
|
-
*
|
|
164
|
-
* export const onRequest = sequence(
|
|
165
|
-
* tastyMiddleware(),
|
|
166
|
-
* myOtherMiddleware,
|
|
167
|
-
* );
|
|
168
|
-
* ```
|
|
169
|
-
*/
|
|
170
|
-
function tastyMiddleware(options) {
|
|
171
|
-
const internalOptions = options;
|
|
172
|
-
return async (context, next) => {
|
|
173
|
-
const transferCache = options?.transferCache ?? true;
|
|
174
|
-
const extractionMetadata = internalOptions?.extractionMetadata === true && context.isPrerendered === true;
|
|
175
|
-
const collector = new ServerStyleCollector();
|
|
176
|
-
const rendered = await runWithCollector(collector, async () => {
|
|
177
|
-
const response = await next();
|
|
178
|
-
const body = response.body;
|
|
179
|
-
const contentType = response.headers.get("content-type") ?? "";
|
|
180
|
-
if (!body || !contentType.includes("text/html")) return { response };
|
|
181
|
-
const reader = body.pipeThrough(new TextDecoderStream()).getReader();
|
|
182
|
-
const parts = [];
|
|
183
|
-
for (;;) {
|
|
184
|
-
const { done, value } = await reader.read();
|
|
185
|
-
if (done) break;
|
|
186
|
-
parts.push(value);
|
|
187
|
-
}
|
|
188
|
-
return {
|
|
189
|
-
html: parts.join(""),
|
|
190
|
-
status: response.status,
|
|
191
|
-
headers: response.headers
|
|
192
|
-
};
|
|
193
|
-
});
|
|
194
|
-
if ("response" in rendered) return rendered.response;
|
|
195
|
-
if (!rendered.html) return new Response(null, {
|
|
196
|
-
status: rendered.status,
|
|
197
|
-
headers: rendered.headers
|
|
198
|
-
});
|
|
199
|
-
let { html } = rendered;
|
|
200
|
-
const css = collector.getCSS();
|
|
201
|
-
if (!css) return new Response(html, {
|
|
202
|
-
status: rendered.status,
|
|
203
|
-
headers: rendered.headers
|
|
204
|
-
});
|
|
205
|
-
const nonce = getConfig().nonce;
|
|
206
|
-
const nonceAttr = nonce ? ` nonce="${nonce}"` : "";
|
|
207
|
-
const styleTag = `<style data-tasty-ssr${nonceAttr}>${css}</style>`;
|
|
208
|
-
const metadataTag = extractionMetadata ? createExtractionMetadata(collector.getArtifacts()) : "";
|
|
209
|
-
let cacheTag = "";
|
|
210
|
-
if (transferCache) {
|
|
211
|
-
const classNames = collector.getRenderedClassNames();
|
|
212
|
-
if (classNames.length > 0) cacheTag = `<script${nonceAttr}>(window.__TASTY__=window.__TASTY__||[]).push(${classNames.map((n) => `"${n}"`).join(",")})<\/script>`;
|
|
213
|
-
}
|
|
214
|
-
const injection = styleTag + metadataTag + cacheTag;
|
|
215
|
-
const idx = html.indexOf("</head>");
|
|
216
|
-
if (idx !== -1) html = html.slice(0, idx) + injection + html.slice(idx);
|
|
217
|
-
else html = injection + html;
|
|
218
|
-
const headers = new Headers(rendered.headers);
|
|
219
|
-
headers.delete("content-length");
|
|
220
|
-
return new Response(html, {
|
|
221
|
-
status: rendered.status,
|
|
222
|
-
headers
|
|
223
|
-
});
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Package subpaths of the middleware entrypoints registered by
|
|
228
|
-
* `tastyIntegration()`.
|
|
229
|
-
*
|
|
230
|
-
* These must be bare specifiers rather than
|
|
231
|
-
* `new URL('./astro-middleware.js', import.meta.url)`. The bundler is free to
|
|
232
|
-
* hoist `tastyIntegration` into a shared chunk at a different directory depth
|
|
233
|
-
* than `dist/ssr/`, which makes a relative URL resolve to a file that does not
|
|
234
|
-
* exist and breaks the build for every consumer. A package subpath is resolved
|
|
235
|
-
* by the consumer through our `exports` map, so it never depends on the
|
|
236
|
-
* chunk layout.
|
|
237
|
-
*
|
|
238
|
-
* There are separate entrypoints instead of one parameterised entrypoint because
|
|
239
|
-
* `addMiddleware()` cannot pass options: the integration runs when the Astro
|
|
240
|
-
* config is loaded, while the middleware module is evaluated in the server
|
|
241
|
-
* runtime — a different process for built output — so module-level state set
|
|
242
|
-
* by the integration is not visible to the middleware.
|
|
243
|
-
*/
|
|
244
|
-
const MIDDLEWARE_ENTRYPOINT = "@tenphi/tasty/ssr/astro-middleware";
|
|
245
|
-
const MIDDLEWARE_ENTRYPOINT_STATIC = "@tenphi/tasty/ssr/astro-middleware-static";
|
|
246
|
-
const MIDDLEWARE_ENTRYPOINT_EXTRACT = "@tenphi/tasty/ssr/astro-middleware-extract";
|
|
247
|
-
const MIDDLEWARE_ENTRYPOINT_EXTRACT_STATIC = "@tenphi/tasty/ssr/astro-middleware-extract-static";
|
|
248
|
-
/**
|
|
249
|
-
* Astro integration that automatically sets up Tasty SSR.
|
|
250
|
-
*
|
|
251
|
-
* Registers middleware for cross-component CSS deduplication and
|
|
252
|
-
* optionally injects a client hydration script for island support.
|
|
253
|
-
*
|
|
254
|
-
* @example Basic setup (with islands)
|
|
255
|
-
* ```ts
|
|
256
|
-
* // astro.config.mjs
|
|
257
|
-
* import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
|
|
258
|
-
*
|
|
259
|
-
* export default defineConfig({
|
|
260
|
-
* integrations: [tastyIntegration()],
|
|
261
|
-
* });
|
|
262
|
-
* ```
|
|
263
|
-
*
|
|
264
|
-
* @example Static-only (no client JS)
|
|
265
|
-
* ```ts
|
|
266
|
-
* // astro.config.mjs
|
|
267
|
-
* import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
|
|
268
|
-
*
|
|
269
|
-
* export default defineConfig({
|
|
270
|
-
* integrations: [tastyIntegration({ islands: false })],
|
|
271
|
-
* });
|
|
272
|
-
* ```
|
|
273
|
-
*/
|
|
274
|
-
function tastyIntegration(options) {
|
|
275
|
-
const { islands = true } = options ?? {};
|
|
276
|
-
const cssMode = options?.css?.mode ?? "inline";
|
|
277
|
-
let base = "/";
|
|
278
|
-
let assets = "_astro";
|
|
279
|
-
return {
|
|
280
|
-
name: "@tenphi/tasty",
|
|
281
|
-
hooks: {
|
|
282
|
-
"astro:config:setup": ({ addMiddleware, injectScript }) => {
|
|
283
|
-
addMiddleware({
|
|
284
|
-
entrypoint: cssMode === "extract" ? islands ? MIDDLEWARE_ENTRYPOINT_EXTRACT : MIDDLEWARE_ENTRYPOINT_EXTRACT_STATIC : islands ? MIDDLEWARE_ENTRYPOINT : MIDDLEWARE_ENTRYPOINT_STATIC,
|
|
285
|
-
order: "pre"
|
|
286
|
-
});
|
|
287
|
-
if (islands) injectScript("before-hydration", `import "@tenphi/tasty/ssr/astro-client";`);
|
|
288
|
-
},
|
|
289
|
-
"astro:config:done": ({ config }) => {
|
|
290
|
-
base = config.base ?? "/";
|
|
291
|
-
assets = config.build?.assets ?? "_astro";
|
|
292
|
-
},
|
|
293
|
-
"astro:build:done": async ({ dir }) => {
|
|
294
|
-
if (cssMode !== "extract") return;
|
|
295
|
-
await extractAstroCSS({
|
|
296
|
-
dir,
|
|
297
|
-
base,
|
|
298
|
-
assets
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
//#endregion
|
|
305
|
-
export { tastyMiddleware as n, tastyIntegration as t };
|
|
306
|
-
|
|
307
|
-
//# sourceMappingURL=astro-ib7E7V4Y.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"astro-ib7E7V4Y.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';\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 findSequence(haystack: string[], needle: string[]): number {\n if (needle.length === 0) return -1;\n outer: for (let i = 0; i <= haystack.length - needle.length; i++) {\n for (let j = 0; j < needle.length; j++) {\n if (haystack[i + j] !== needle[j]) continue outer;\n }\n return i;\n }\n return -1;\n}\n\n/** Find the largest byte-sized artifact block that is contiguous on every page. */\nfunction selectSharedArtifacts(\n pages: ExtractablePage[],\n): ServerStyleArtifact[] {\n if (pages.length < 2) return [];\n\n const source = pages.reduce((shortest, page) =>\n page.artifacts.length < shortest.artifacts.length ? page : shortest,\n );\n const otherIds = pages\n .filter((page) => page !== source)\n .map((page) => page.artifacts.map(({ id }) => id));\n const sourceIds = source.artifacts.map(({ id }) => id);\n\n let best: ServerStyleArtifact[] = [];\n let bestBytes = 0;\n for (let start = 0; start < source.artifacts.length; start++) {\n let length = source.artifacts.length - start;\n for (const pageIds of otherIds) {\n let pageLength = 0;\n for (let pageStart = 0; pageStart < pageIds.length; pageStart++) {\n if (pageIds[pageStart] !== sourceIds[start]) continue;\n let matchLength = 1;\n while (\n start + matchLength < sourceIds.length &&\n pageStart + matchLength < pageIds.length &&\n sourceIds[start + matchLength] === pageIds[pageStart + matchLength]\n ) {\n matchLength++;\n }\n pageLength = Math.max(pageLength, matchLength);\n }\n length = Math.min(length, pageLength);\n if (length === 0) break;\n }\n\n const candidate = source.artifacts.slice(start, start + length);\n const bytes = candidate.reduce((total, item) => total + item.css.length, 0);\n if (bytes > bestBytes) {\n best = candidate;\n bestBytes = bytes;\n }\n }\n\n return best;\n}\n\nfunction stylesheetHref(\n base: string,\n assets: string,\n filename: string,\n): string {\n const basePath = base === '/' ? '' : `/${base.replace(/^\\/+|\\/+$/g, '')}`;\n const assetsPath = assets.replace(/^\\/+|\\/+$/g, '');\n return `${basePath}/${assetsPath}/${filename}`;\n}\n\nfunction styleTag(styleOpen: string, artifacts: ServerStyleArtifact[]): string {\n if (artifacts.length === 0) return '';\n return `${styleOpen}${artifacts.map(({ css }) => css).join('\\n')}</style>`;\n}\n\nfunction transformPage(\n page: ExtractablePage,\n selected: ServerStyleArtifact[],\n href: string,\n): string {\n const selectedIds = selected.map(({ id }) => id);\n const pageIds = page.artifacts.map(({ id }) => id);\n const first = findSequence(pageIds, selectedIds);\n if (first === -1) {\n const metadataStart = page.html.indexOf(METADATA_START, page.styleStart);\n return (\n page.html.slice(0, metadataStart) + page.html.slice(page.replacementEnd)\n );\n }\n\n const before = page.artifacts.slice(0, first);\n const after = page.artifacts.slice(first + selected.length);\n const nonceAttr = page.styleOpen.match(/\\snonce=\"[^\"]*\"/)?.[0] ?? '';\n const link = `<link rel=\"stylesheet\" href=\"${href}\" data-tasty-ssr${nonceAttr}>`;\n const replacement =\n styleTag(page.styleOpen, before) + link + styleTag(page.styleOpen, after);\n\n return (\n page.html.slice(0, page.styleStart) +\n replacement +\n page.html.slice(page.replacementEnd)\n );\n}\n\nexport async function extractAstroCSS(options: {\n dir: URL;\n base: string;\n assets: string;\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\n const selected = selectSharedArtifacts(pages);\n if (selected.length === 0) {\n for (const page of pages) {\n const metadataStart = page.html.indexOf(METADATA_START, page.styleStart);\n await writeFile(\n page.path,\n page.html.slice(0, metadataStart) +\n page.html.slice(page.replacementEnd),\n );\n }\n return;\n }\n\n const css = selected.map(({ css }) => css).join('\\n');\n const hash = createHash('sha256').update(css).digest('hex').slice(0, 12);\n const filename = `tasty.${hash}.css`;\n const assetDir = join(outputDir, options.assets);\n await mkdir(assetDir, { recursive: true });\n await writeFile(join(assetDir, filename), css);\n\n const href = stylesheetHref(options.base, options.assets, filename);\n for (const page of pages) {\n await writeFile(page.path, transformPage(page, selected, href));\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 { getConfig } from '../config';\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 = getConfig().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 /** CSS delivery mode. Extraction only applies to prerendered builds. */\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\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: { base?: string; build?: { assets?: string } };\n }) => {\n base = config.base ?? '/';\n assets = config.build?.assets ?? '_astro';\n },\n 'astro:build:done': async ({ dir }: { dir: URL }) => {\n if (cssMode !== 'extract') return;\n await extractAstroCSS({ dir, base, assets });\n },\n },\n };\n}\n"],"mappings":";;;;;;;;;AAOA,MAAM,iBAAiB;AACvB,MAAM,eAAe;AAWrB,SAAgB,yBACd,WACQ;CAIR,OAAO,GAAG,iBAHM,OAAO,KAAK,KAAK,UAAU,SAAS,GAAG,MAAM,CAAC,CAAC,SAC7D,QAE+B,IAAI;AACvC;AAEA,SAAS,qBACP,MACA,MACwB;CACxB,MAAM,gBAAgB,KAAK,QAAQ,cAAc;CACjD,IAAI,kBAAkB,IAAI,OAAO;CAEjC,MAAM,uBAAuB,gBAAgB;CAC7C,MAAM,cAAc,KAAK,QAAQ,cAAc,oBAAoB;CACnE,IAAI,gBAAgB,IAAI,OAAO;CAE/B,MAAM,UAAU,KAAK,MAAM,sBAAsB,WAAW;CAC5D,IAAI;CACJ,IAAI;EACF,YAAY,KAAK,MACf,OAAO,KAAK,SAAS,QAAQ,CAAC,CAAC,SAAS,MAAM,CAChD;CACF,QAAQ;EACN,OAAO;CACT;CAEA,MAAM,aAAa,KAAK,YAAY,yBAAyB,aAAa;CAC1E,IAAI,eAAe,IAAI,OAAO;CAC9B,MAAM,eAAe,KAAK,QAAQ,KAAK,UAAU;CACjD,MAAM,WAAW,KAAK,QAAQ,YAAY,eAAe,CAAC;CAC1D,IACE,iBAAiB,MACjB,aAAa,MACb,WAAW,MAAsB,eAEjC,OAAO;CAGT,OAAO;EACL;EACA;EACA;EACA;EACA,gBAAgB,cAAc;EAC9B,WAAW,KAAK,MAAM,YAAY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OAAO,OAAO,UAAU;GACnC;GACA,oBAAoB,OAAO,EAAE,UAAwB;IACnD,IAAI,YAAY,WAAW;IAC3B,MAAM,gBAAgB;KAAE;KAAK;KAAM;IAAO,CAAC;GAC7C;EACF;CACF;AACF"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
//#region src/ssr/async-storage.ts
|
|
3
|
-
/**
|
|
4
|
-
* AsyncLocalStorage integration for SSR collector discovery.
|
|
5
|
-
*
|
|
6
|
-
* Used by Astro middleware and generic framework integrations where
|
|
7
|
-
* the library cannot wrap the React tree with a context provider.
|
|
8
|
-
* The middleware calls runWithCollector() around the render, and
|
|
9
|
-
* useStyles() calls getSSRCollector() to find it.
|
|
10
|
-
*
|
|
11
|
-
* Uses globalThis to ensure the AsyncLocalStorage instance is shared
|
|
12
|
-
* across module instances — frameworks like Astro may load middleware
|
|
13
|
-
* and page components from separate module graphs.
|
|
14
|
-
*
|
|
15
|
-
* This module imports from 'node:async_hooks' — it must be excluded
|
|
16
|
-
* from client bundles via the build configuration.
|
|
17
|
-
*/
|
|
18
|
-
const ALS_KEY = "__tasty_ssr_als__";
|
|
19
|
-
function getSharedStorage() {
|
|
20
|
-
const g = globalThis;
|
|
21
|
-
if (!g[ALS_KEY]) g[ALS_KEY] = new AsyncLocalStorage();
|
|
22
|
-
return g[ALS_KEY];
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Run a function with a ServerStyleCollector bound to the current
|
|
26
|
-
* async context. All useStyles() calls within `fn` (and any async
|
|
27
|
-
* continuations) will find this collector via getSSRCollector().
|
|
28
|
-
*/
|
|
29
|
-
function runWithCollector(collector, fn) {
|
|
30
|
-
return getSharedStorage().run(collector, fn);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Retrieve the ServerStyleCollector bound to the current async context.
|
|
34
|
-
* Returns null when called outside of runWithCollector() or on the client.
|
|
35
|
-
*/
|
|
36
|
-
function getSSRCollector() {
|
|
37
|
-
const storage = getSharedStorage();
|
|
38
|
-
if (typeof storage?.getStore !== "function") return null;
|
|
39
|
-
return storage.getStore() ?? null;
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
|
-
export { runWithCollector as n, getSSRCollector as t };
|
|
43
|
-
|
|
44
|
-
//# sourceMappingURL=async-storage-DKK-wTD4.js.map
|