@tenphi/tasty 0.0.0-snapshot.2f41cf6 → 0.0.0-snapshot.2f4e31d

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 (130) hide show
  1. package/README.md +440 -372
  2. package/dist/babel-types-Dc5zghyE.d.ts +18 -0
  3. package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
  4. package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
  5. package/dist/chunks/build-config-D9Iq8QQm.js +60 -0
  6. package/dist/chunks/build-config-D9Iq8QQm.js.map +1 -0
  7. package/dist/{collector-BMEQCkCn.js → chunks/collector-Cb8ah2JF.js} +68 -101
  8. package/dist/chunks/collector-Cb8ah2JF.js.map +1 -0
  9. package/dist/chunks/config-engine-CMYFZYQh.js +272 -0
  10. package/dist/chunks/config-engine-CMYFZYQh.js.map +1 -0
  11. package/dist/chunks/config-file-DlZXJMj8.js +25 -0
  12. package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
  13. package/dist/chunks/css-definitions-B4aWBkH3.js +910 -0
  14. package/dist/chunks/css-definitions-B4aWBkH3.js.map +1 -0
  15. package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
  16. package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
  17. package/dist/chunks/debug-D2Pu7Xhy.js +502 -0
  18. package/dist/chunks/debug-D2Pu7Xhy.js.map +1 -0
  19. package/dist/chunks/dsl-CsFl9LGn.js +1458 -0
  20. package/dist/chunks/dsl-CsFl9LGn.js.map +1 -0
  21. package/dist/chunks/hydration-TRcz5vnk.js +41 -0
  22. package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
  23. package/dist/chunks/react-runtime-DHiopXCu.js +691 -0
  24. package/dist/chunks/react-runtime-DHiopXCu.js.map +1 -0
  25. package/dist/chunks/runtime-engine-NGCofNXy.js +2435 -0
  26. package/dist/chunks/runtime-engine-NGCofNXy.js.map +1 -0
  27. package/dist/chunks/runtime-state-lZjMbvwV.js +152 -0
  28. package/dist/chunks/runtime-state-lZjMbvwV.js.map +1 -0
  29. package/dist/{merge-styles-3il_ClCF.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
  30. package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
  31. package/dist/chunks/style-engine-DnkV_4Jg.js +5602 -0
  32. package/dist/chunks/style-engine-DnkV_4Jg.js.map +1 -0
  33. package/dist/{css-writer-BSv8PrEX.js → chunks/zero-engine-DcwaCvFs.js} +95 -136
  34. package/dist/chunks/zero-engine-DcwaCvFs.js.map +1 -0
  35. package/dist/{collector-osfWTeRd.d.ts → collector-D2OT6I2G.d.ts} +64 -8
  36. package/dist/{config-BoZDUHW5.d.ts → config-C4ftFxgI.d.ts} +514 -92
  37. package/dist/core/index.d.ts +5 -5
  38. package/dist/core/index.js +9 -6
  39. package/dist/hydrate-CRyjjAyl.d.ts +22 -0
  40. package/dist/{index-D-OA_O6i.d.ts → index-DxQNRj50.d.ts} +718 -502
  41. package/dist/index.d.ts +5 -5
  42. package/dist/index.js +11 -732
  43. package/dist/{merge-styles-BMWcH6MF.d.ts → merge-styles-D39qBtox.d.ts} +2 -3
  44. package/dist/ssr/astro-client.d.ts +1 -1
  45. package/dist/ssr/astro-client.js +1 -14
  46. package/dist/ssr/astro-client.js.map +1 -1
  47. package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
  48. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  49. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  50. package/dist/ssr/astro-middleware-extract.d.ts +10 -0
  51. package/dist/ssr/astro-middleware-extract.js +9 -0
  52. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  53. package/dist/ssr/astro-middleware-static.d.ts +17 -0
  54. package/dist/ssr/astro-middleware-static.js +7 -0
  55. package/dist/ssr/astro-middleware-static.js.map +1 -0
  56. package/dist/ssr/astro-middleware.d.ts +11 -8
  57. package/dist/ssr/astro-middleware.js +2 -14
  58. package/dist/ssr/astro-middleware.js.map +1 -1
  59. package/dist/ssr/astro.d.ts +40 -10
  60. package/dist/ssr/astro.js +163 -91
  61. package/dist/ssr/astro.js.map +1 -1
  62. package/dist/ssr/client.d.ts +2 -0
  63. package/dist/ssr/client.js +2 -0
  64. package/dist/ssr/index.d.ts +5 -32
  65. package/dist/ssr/index.js +6 -6
  66. package/dist/ssr/index.js.map +1 -1
  67. package/dist/ssr/next-config.d.ts +64 -0
  68. package/dist/ssr/next-config.js +123 -0
  69. package/dist/ssr/next-config.js.map +1 -0
  70. package/dist/ssr/next.d.ts +9 -9
  71. package/dist/ssr/next.js +29 -44
  72. package/dist/ssr/next.js.map +1 -1
  73. package/dist/static/index.d.ts +8 -9
  74. package/dist/static/index.js +4 -22
  75. package/dist/static/index.js.map +1 -1
  76. package/dist/static/inject.d.ts +1 -2
  77. package/dist/static/inject.js.map +1 -1
  78. package/dist/{index-tcHuMPFt.d.ts → types-CYQIhUg1.d.ts} +883 -600
  79. package/dist/zero/babel.d.ts +12 -20
  80. package/dist/zero/babel.js +97 -156
  81. package/dist/zero/babel.js.map +1 -1
  82. package/dist/zero/index.d.ts +76 -7
  83. package/dist/zero/index.js +25 -2
  84. package/dist/zero/index.js.map +1 -0
  85. package/dist/zero/next.d.ts +4 -5
  86. package/dist/zero/next.js +3 -38
  87. package/dist/zero/next.js.map +1 -1
  88. package/docs/README.md +20 -9
  89. package/docs/adoption.md +69 -36
  90. package/docs/ai-agents.md +259 -0
  91. package/docs/comparison.md +77 -47
  92. package/docs/configuration.md +617 -98
  93. package/docs/debug.md +28 -15
  94. package/docs/design-system.md +154 -33
  95. package/docs/dsl.md +715 -194
  96. package/docs/getting-started.md +130 -50
  97. package/docs/injector.md +160 -69
  98. package/docs/methodology.md +82 -51
  99. package/docs/migration-v3.md +285 -0
  100. package/docs/pipeline.md +102 -33
  101. package/docs/plugins.md +333 -0
  102. package/docs/react-api.md +215 -50
  103. package/docs/runtime-benchmarks.md +388 -0
  104. package/docs/ssr.md +310 -118
  105. package/docs/styles.md +225 -42
  106. package/docs/tasty-static.md +289 -136
  107. package/package.json +141 -45
  108. package/tasty.config.ts +6 -0
  109. package/dist/async-storage-B7_o6FKt.js +0 -44
  110. package/dist/async-storage-B7_o6FKt.js.map +0 -1
  111. package/dist/collector-BMEQCkCn.js.map +0 -1
  112. package/dist/config-eiremPHv.js +0 -10559
  113. package/dist/config-eiremPHv.js.map +0 -1
  114. package/dist/context-CkSg-kDT.js +0 -24
  115. package/dist/context-CkSg-kDT.js.map +0 -1
  116. package/dist/core-Dm9EkOA_.js +0 -1598
  117. package/dist/core-Dm9EkOA_.js.map +0 -1
  118. package/dist/css-writer-BSv8PrEX.js.map +0 -1
  119. package/dist/format-global-rules-Dbc_1tc3.js +0 -22
  120. package/dist/format-global-rules-Dbc_1tc3.js.map +0 -1
  121. package/dist/format-rules-DcFFQceU.js +0 -143
  122. package/dist/format-rules-DcFFQceU.js.map +0 -1
  123. package/dist/hydrate-B6SjFHhj.js +0 -45
  124. package/dist/hydrate-B6SjFHhj.js.map +0 -1
  125. package/dist/index.js.map +0 -1
  126. package/dist/keyframes-DJ8Geo4L.js +0 -595
  127. package/dist/keyframes-DJ8Geo4L.js.map +0 -1
  128. package/dist/merge-styles-3il_ClCF.js.map +0 -1
  129. package/dist/resolve-recipes-B3MSkfFQ.js +0 -144
  130. package/dist/resolve-recipes-B3MSkfFQ.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.2f41cf6",
3
+ "version": "0.0.0-snapshot.2f4e31d",
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",
@@ -32,7 +32,7 @@
32
32
  "import": "./dist/zero/index.js",
33
33
  "default": "./dist/zero/index.js"
34
34
  },
35
- "./next": {
35
+ "./zero/next": {
36
36
  "types": "./dist/zero/next.d.ts",
37
37
  "import": "./dist/zero/next.js",
38
38
  "default": "./dist/zero/next.js"
@@ -52,16 +52,46 @@
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",
63
73
  "default": "./dist/ssr/astro-client.js"
64
74
  },
75
+ "./ssr/astro-middleware": {
76
+ "types": "./dist/ssr/astro-middleware.d.ts",
77
+ "import": "./dist/ssr/astro-middleware.js",
78
+ "default": "./dist/ssr/astro-middleware.js"
79
+ },
80
+ "./ssr/astro-middleware-static": {
81
+ "types": "./dist/ssr/astro-middleware-static.d.ts",
82
+ "import": "./dist/ssr/astro-middleware-static.js",
83
+ "default": "./dist/ssr/astro-middleware-static.js"
84
+ },
85
+ "./ssr/astro-middleware-extract": {
86
+ "types": "./dist/ssr/astro-middleware-extract.d.ts",
87
+ "import": "./dist/ssr/astro-middleware-extract.js",
88
+ "default": "./dist/ssr/astro-middleware-extract.js"
89
+ },
90
+ "./ssr/astro-middleware-extract-static": {
91
+ "types": "./dist/ssr/astro-middleware-extract-static.d.ts",
92
+ "import": "./dist/ssr/astro-middleware-extract-static.js",
93
+ "default": "./dist/ssr/astro-middleware-extract-static.js"
94
+ },
65
95
  "./tasty.config": "./tasty.config.ts"
66
96
  },
67
97
  "files": [
@@ -73,7 +103,11 @@
73
103
  "./dist/ssr/index.js",
74
104
  "./dist/ssr/next.js",
75
105
  "./dist/ssr/astro.js",
76
- "./dist/ssr/astro-client.js"
106
+ "./dist/ssr/astro-client.js",
107
+ "./dist/ssr/astro-middleware.js",
108
+ "./dist/ssr/astro-middleware-static.js",
109
+ "./dist/ssr/astro-middleware-extract.js",
110
+ "./dist/ssr/astro-middleware-extract-static.js"
77
111
  ],
78
112
  "engines": {
79
113
  "node": ">=20"
@@ -81,6 +115,9 @@
81
115
  "scripts": {
82
116
  "build": "tsdown",
83
117
  "test": "vitest run",
118
+ "test:node": "vitest run --project node",
119
+ "test:browser": "vitest run --project browser",
120
+ "test:setup": "playwright install chromium",
84
121
  "test:watch": "vitest",
85
122
  "test:coverage": "vitest run --coverage",
86
123
  "typecheck": "tsc --noEmit",
@@ -89,12 +126,22 @@
89
126
  "format": "prettier --write \"src/**/*.{ts,tsx}\"",
90
127
  "format:check": "prettier --check \"src/**/*.{ts,tsx}\"",
91
128
  "size": "size-limit",
92
- "bench": "vitest bench",
129
+ "bench": "vitest bench --project \"node (bench)\"",
130
+ "bench:browser": "vitest bench --project \"browser (chromium) (bench)\"",
131
+ "bench:overhead": "vitest bench --config vitest.production-browser-bench.config.ts src/tasty-overhead.bench.tsx",
132
+ "bench:injection": "vitest bench --config vitest.production-browser-bench.config.ts src/tasty-injection.bench.ts",
133
+ "bench:interaction": "vitest bench --config vitest.production-browser-bench.config.ts src/tasty-interaction.bench.tsx",
134
+ "bench:tree": "vitest bench --config vitest.production-browser-bench.config.ts src/tasty-tree.bench.tsx",
135
+ "bench:cold-start": "node scripts/cold-start/index.mjs",
93
136
  "prepublishOnly": "pnpm run build",
94
137
  "changeset": "changeset",
95
138
  "version": "changeset version",
96
139
  "release": "changeset publish",
97
140
  "knip": "knip",
141
+ "check:build": "node scripts/check-built-entries.mjs",
142
+ "check:react-compat": "node scripts/check-react-compat.mjs",
143
+ "check:babel-compat": "node scripts/check-babel-compat.mjs",
144
+ "check:test-only": "node scripts/check-test-only-code.mjs",
98
145
  "hygiene": "pnpm lint && pnpm format:check && pnpm typecheck",
99
146
  "hygiene:fix": "pnpm lint:fix && pnpm format && pnpm typecheck"
100
147
  },
@@ -120,9 +167,9 @@
120
167
  },
121
168
  "homepage": "https://github.com/tenphi/tasty#readme",
122
169
  "peerDependencies": {
123
- "@babel/core": "^7.24.0",
124
- "@babel/helper-plugin-utils": "^7.24.0",
125
- "@babel/types": "^7.24.0",
170
+ "@babel/core": "^7.24.0 || ^8.0.0",
171
+ "@babel/helper-plugin-utils": "^7.24.0 || ^8.0.0",
172
+ "@babel/types": "^7.24.0 || ^8.0.0",
126
173
  "jiti": "^2.6.1",
127
174
  "next": ">=14.0.0",
128
175
  "react": "^18.0.0 || ^19.0.0"
@@ -151,59 +198,82 @@
151
198
  "csstype": "^3.1.0"
152
199
  },
153
200
  "devDependencies": {
154
- "@babel/core": "^7.24.0",
155
- "@babel/helper-plugin-utils": "^7.24.0",
156
- "@babel/types": "^7.24.0",
157
- "@changesets/changelog-github": "^0.7.0",
158
- "@changesets/cli": "^2.29.8",
201
+ "@astrojs/react": "^7.0.1",
202
+ "@babel/core": "^8.0.6",
203
+ "@babel/helper-plugin-utils": "^8.0.1",
204
+ "@babel/types": "^8.0.6",
205
+ "@changesets/changelog-github": "^1.0.1",
206
+ "@changesets/cli": "^3.0.3",
159
207
  "@eslint/js": "^10.0.1",
160
- "@size-limit/esbuild": "^12.0.0",
161
- "@size-limit/file": "^12.0.0",
162
- "@testing-library/jest-dom": "^6.9.1",
163
- "@testing-library/react": "^16.3.2",
164
- "@types/babel__core": "^7.20.5",
165
- "@types/babel__helper-plugin-utils": "^7.10.3",
166
- "@types/node": "^25.3.2",
167
- "@types/react": "^19.0.0",
168
- "eslint": "^10.0.0",
208
+ "@size-limit/esbuild": "^14.1.0",
209
+ "@size-limit/file": "^14.1.0",
210
+ "@tenphi/eslint-plugin-tasty": "^1.16.0",
211
+ "@testing-library/jest-dom": "^7.0.1",
212
+ "@testing-library/react": "^16.3.3",
213
+ "@types/node": "^24.19.1",
214
+ "@types/react": "^19.3.0",
215
+ "@types/react-dom": "^19.3.0",
216
+ "@vitest/browser-playwright": "^5.0.3",
217
+ "astro": "^7.3.6",
218
+ "esbuild": "^0.28.2",
219
+ "eslint": "^10.12.0",
169
220
  "eslint-config-prettier": "^10.1.8",
170
- "happy-dom": "^20.9.0",
171
- "jiti": "^2.6.1",
172
- "jsdom": "^29.0.2",
173
- "knip": "^5.61.3",
174
- "next": "^16.0.0",
175
- "prettier": "^3.8.1",
176
- "react": "^19.0.0",
177
- "size-limit": "^12.0.0",
178
- "tsdown": "^0.22.0",
179
- "typescript": "^6.0.2",
180
- "typescript-eslint": "^8.56.0",
181
- "vitest": "^4.0.18"
182
- },
183
- "pnpm": {
184
- "onlyBuiltDependencies": [
185
- "esbuild"
186
- ]
221
+ "jiti": "^2.7.0",
222
+ "knip": "^6.40.0",
223
+ "next": "^16.4.0",
224
+ "playwright": "^1.63.0",
225
+ "prettier": "^3.9.9",
226
+ "react": "^19.3.0",
227
+ "react-dom": "^19.3.0",
228
+ "size-limit": "^14.1.0",
229
+ "tsdown": "^0.23.0",
230
+ "typescript": "^6.0.3",
231
+ "typescript-eslint": "^8.71.1",
232
+ "vitest": "^5.0.3"
187
233
  },
188
- "packageManager": "pnpm@11.0.8",
234
+ "packageManager": "pnpm@11.27.1",
189
235
  "size-limit": [
190
236
  {
191
237
  "name": "main (import *)",
192
238
  "path": "dist/index.js",
193
239
  "import": "*",
194
- "limit": "52 kB"
240
+ "limit": "62.08 kB"
241
+ },
242
+ {
243
+ "name": "main (tasty)",
244
+ "path": "dist/index.js",
245
+ "import": "{ tasty }",
246
+ "limit": "54.99 kB"
247
+ },
248
+ {
249
+ "name": "main (StyleParser)",
250
+ "path": "dist/index.js",
251
+ "import": "{ StyleParser }",
252
+ "limit": "8 kB"
253
+ },
254
+ {
255
+ "name": "main (parseColor)",
256
+ "path": "dist/index.js",
257
+ "import": "{ parseColor }",
258
+ "limit": "8.67 kB"
259
+ },
260
+ {
261
+ "name": "main (useRawCSS)",
262
+ "path": "dist/index.js",
263
+ "import": "{ useRawCSS }",
264
+ "limit": "33.63 kB"
195
265
  },
196
266
  {
197
267
  "name": "core (import *)",
198
268
  "path": "dist/core/index.js",
199
269
  "import": "*",
200
- "limit": "49.5 kB"
270
+ "limit": "57.38 kB"
201
271
  },
202
272
  {
203
273
  "name": "static",
204
274
  "path": "dist/static/index.js",
205
275
  "import": "*",
206
- "limit": "17 kB"
276
+ "limit": "1.08 kB"
207
277
  },
208
278
  {
209
279
  "name": "zero",
@@ -214,7 +284,7 @@
214
284
  "path",
215
285
  "crypto"
216
286
  ],
217
- "limit": "31 kB"
287
+ "limit": "41.3 kB"
218
288
  },
219
289
  {
220
290
  "name": "babel-plugin",
@@ -223,9 +293,35 @@
223
293
  "ignore": [
224
294
  "fs",
225
295
  "path",
226
- "crypto"
296
+ "crypto",
297
+ "node:module",
298
+ "node:path"
299
+ ],
300
+ "limit": "45.95 kB"
301
+ },
302
+ {
303
+ "name": "astro client",
304
+ "path": "dist/ssr/astro-client.js",
305
+ "import": "*",
306
+ "limit": "0.5 kB"
307
+ },
308
+ {
309
+ "name": "ssr client",
310
+ "path": "dist/ssr/client.js",
311
+ "import": "{ hydrateTastyClasses }",
312
+ "limit": "0.5 kB"
313
+ },
314
+ {
315
+ "name": "Next.js config",
316
+ "path": "dist/ssr/next-config.js",
317
+ "import": "{ withTastyNext }",
318
+ "ignore": [
319
+ "node:crypto",
320
+ "node:fs",
321
+ "node:module",
322
+ "node:path"
227
323
  ],
228
- "limit": "45.65 kB"
324
+ "limit": "41.48 kB"
229
325
  }
230
326
  ]
231
327
  }
package/tasty.config.ts CHANGED
@@ -11,5 +11,11 @@ export default {
11
11
  '$transition',
12
12
  '$sharp-radius',
13
13
  '$bold-font-weight',
14
+ '$icon-size',
14
15
  ],
16
+ styles: ['viewTransitionName'],
17
+ // This repo imports its own API relatively, so the plugin's default
18
+ // `@tenphi/tasty` import tracking never matches. List the local entry points so
19
+ // `tasty({ styles })` call sites are actually linted.
20
+ importSources: ['@tenphi/tasty', './tasty', '../tasty', './src/tasty'],
15
21
  };
@@ -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-B7_o6FKt.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"async-storage-B7_o6FKt.js","names":[],"sources":["../src/ssr/async-storage.ts"],"sourcesContent":["/**\n * AsyncLocalStorage integration for SSR collector discovery.\n *\n * Used by Astro middleware and generic framework integrations where\n * the library cannot wrap the React tree with a context provider.\n * The middleware calls runWithCollector() around the render, and\n * useStyles() calls getSSRCollector() to find it.\n *\n * Uses globalThis to ensure the AsyncLocalStorage instance is shared\n * across module instances — frameworks like Astro may load middleware\n * and page components from separate module graphs.\n *\n * This module imports from 'node:async_hooks' — it must be excluded\n * from client bundles via the build configuration.\n */\n\nimport { AsyncLocalStorage } from 'node:async_hooks';\n\nimport type { ServerStyleCollector } from './collector';\n\nconst ALS_KEY = '__tasty_ssr_als__';\n\nfunction getSharedStorage(): AsyncLocalStorage<ServerStyleCollector> {\n const g = globalThis as Record<string, unknown>;\n if (!g[ALS_KEY]) {\n g[ALS_KEY] = new AsyncLocalStorage<ServerStyleCollector>();\n }\n return g[ALS_KEY] as AsyncLocalStorage<ServerStyleCollector>;\n}\n\n/**\n * Run a function with a ServerStyleCollector bound to the current\n * async context. All useStyles() calls within `fn` (and any async\n * continuations) will find this collector via getSSRCollector().\n */\nexport function runWithCollector<T>(\n collector: ServerStyleCollector,\n fn: () => T,\n): T {\n return getSharedStorage().run(collector, fn);\n}\n\n/**\n * Retrieve the ServerStyleCollector bound to the current async context.\n * Returns null when called outside of runWithCollector() or on the client.\n */\nexport function getSSRCollector(): ServerStyleCollector | null {\n const storage = getSharedStorage();\n if (typeof storage?.getStore !== 'function') return null;\n return storage.getStore() ?? null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,MAAM,UAAU;AAEhB,SAAS,mBAA4D;CACnE,MAAM,IAAI;CACV,IAAI,CAAC,EAAE,UACL,EAAE,WAAW,IAAI,mBAAyC;CAE5D,OAAO,EAAE;;;;;;;AAQX,SAAgB,iBACd,WACA,IACG;CACH,OAAO,kBAAkB,CAAC,IAAI,WAAW,GAAG;;;;;;AAO9C,SAAgB,kBAA+C;CAC7D,MAAM,UAAU,kBAAkB;CAClC,IAAI,OAAO,SAAS,aAAa,YAAY,OAAO;CACpD,OAAO,QAAQ,UAAU,IAAI"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"collector-BMEQCkCn.js","names":[],"sources":["../src/ssr/collector.ts"],"sourcesContent":["/**\n * ServerStyleCollector — server-safe style collector for SSR.\n *\n * Accumulates CSS rules and cache metadata during server rendering.\n * This is the server-side counterpart to StyleInjector: it allocates\n * hash-based class names using the configured `namePrefix` (defaults\n * to `'t'`), formats CSS rules into text, and tracks rendered class\n * names for lightweight client transfer.\n *\n * One instance is created per HTTP request. Concurrent requests\n * each get their own collector (via AsyncLocalStorage or React context).\n */\n\nimport {\n getEffectiveProperties,\n getGlobalStyles,\n getGlobalCounterStyle,\n getGlobalFontFace,\n getGlobalConfigTokens,\n getNamePrefix,\n} from '../config';\nimport { formatCounterStyleRule } from '../counter-style';\nimport { fontFaceContentHash, formatFontFaceRule } from '../font-face';\nimport { renderStyles } from '../pipeline';\nimport type { StyleResult } from '../pipeline';\nimport { hashString } from '../utils/hash';\nimport {\n makeClassName,\n makeCounterStyleName,\n makeKeyframeName,\n validateNamePrefix,\n} from '../utils/name-prefix';\nimport { formatPropertyCSS } from './format-property';\nimport { formatGlobalRules } from './format-global-rules';\nimport { formatRules } from './format-rules';\n\nexport class ServerStyleCollector {\n private chunks = new Map<string, string>();\n private cacheKeyToClassName = new Map<string, string>();\n private flushedKeys = new Set<string>();\n private propertyRules = new Map<string, string>();\n private flushedPropertyKeys = new Set<string>();\n private keyframeRules = new Map<string, string>();\n private flushedKeyframeKeys = new Set<string>();\n private globalStyles = new Map<string, string>();\n private flushedGlobalKeys = new Set<string>();\n private rawCSS = new Map<string, string>();\n private flushedRawKeys = new Set<string>();\n private fontFaceRules = new Map<string, string>();\n private flushedFontFaceKeys = new Set<string>();\n private counterStyleRules = new Map<string, string>();\n private flushedCounterStyleKeys = new Set<string>();\n private keyframesCounter = 0;\n private counterStyleCounter = 0;\n private internalsCollected = false;\n private namePrefix: string;\n\n /**\n * @param namePrefix - Optional override for the configured prefix.\n * Defaults to the value from `configure({ namePrefix })` (or `'t'`).\n * Pass an explicit prefix when constructing a collector outside the\n * normal configure() lifecycle (e.g. in tests). Validated eagerly\n * so misconfiguration fails before any CSS is collected.\n */\n constructor(namePrefix?: string) {\n if (namePrefix !== undefined) {\n validateNamePrefix(namePrefix);\n }\n this.namePrefix = namePrefix ?? getNamePrefix();\n }\n\n private generateClassName(cacheKey: string): string {\n return makeClassName(this.namePrefix, hashString(cacheKey));\n }\n\n /**\n * Collect internal @property rules and :root token defaults.\n * Mirrors markStylesGenerated() from the client-side injector.\n * Called automatically on first chunk collection; idempotent.\n *\n * Internals are always emitted here — the RSC path deliberately\n * defers to SSR so that tokens appear exactly once per page in\n * <style data-tasty-ssr> (avoiding duplication of large token sets).\n */\n collectInternals(): void {\n if (this.internalsCollected) return;\n this.internalsCollected = true;\n\n for (const [token, definition] of Object.entries(\n getEffectiveProperties(),\n )) {\n const css = formatPropertyCSS(token, definition);\n if (css) {\n this.collectProperty(`__prop:${token}`, css);\n }\n }\n\n const tokenStyles = getGlobalConfigTokens();\n if (tokenStyles && Object.keys(tokenStyles).length > 0) {\n const tokenRules = renderStyles(tokenStyles, ':root') as StyleResult[];\n if (tokenRules.length > 0) {\n const css = formatGlobalRules(tokenRules);\n if (css) {\n this.collectGlobalStyles('__global:tokens', css);\n }\n }\n }\n\n const globalFF = getGlobalFontFace();\n if (globalFF) {\n for (const [family, input] of Object.entries(globalFF)) {\n const descriptors = Array.isArray(input) ? input : [input];\n for (const desc of descriptors) {\n const hash = fontFaceContentHash(family, desc);\n const css = formatFontFaceRule(family, desc);\n this.collectFontFace(hash, css);\n }\n }\n }\n\n const globalCS = getGlobalCounterStyle();\n if (globalCS) {\n for (const [name, descriptors] of Object.entries(globalCS)) {\n const css = formatCounterStyleRule(name, descriptors);\n this.collectCounterStyle(name, css);\n }\n }\n\n const globalStyles = getGlobalStyles();\n if (globalStyles) {\n for (const [selector, styles] of Object.entries(globalStyles)) {\n if (Object.keys(styles).length > 0) {\n const rules = renderStyles(styles, selector) as StyleResult[];\n if (rules.length > 0) {\n const css = formatGlobalRules(rules);\n if (css) {\n this.collectGlobalStyles(`__global:styles:${selector}`, css);\n }\n }\n }\n }\n }\n }\n\n /**\n * Allocate a className for a cache key, server-side.\n * Mirrors StyleInjector.allocateClassName but without DOM access.\n */\n allocateClassName(cacheKey: string): {\n className: string;\n isNewAllocation: boolean;\n } {\n const existing = this.cacheKeyToClassName.get(cacheKey);\n if (existing) {\n return { className: existing, isNewAllocation: false };\n }\n\n const className = this.generateClassName(cacheKey);\n this.cacheKeyToClassName.set(cacheKey, className);\n\n return { className, isNewAllocation: true };\n }\n\n /**\n * Record CSS rules for a chunk.\n * Called by useStyles during server render.\n */\n collectChunk(\n cacheKey: string,\n className: string,\n rules: StyleResult[],\n ): void {\n if (this.chunks.has(cacheKey)) return;\n const css = formatRules(rules, className);\n if (css) {\n this.chunks.set(cacheKey, css);\n }\n }\n\n /**\n * Record a @property rule. Deduplicated by name.\n */\n collectProperty(name: string, css: string): void {\n if (!this.propertyRules.has(name)) {\n this.propertyRules.set(name, css);\n }\n }\n\n /**\n * Record a @keyframes rule. Deduplicated by name.\n */\n collectKeyframes(name: string, css: string): void {\n if (!this.keyframeRules.has(name)) {\n this.keyframeRules.set(name, css);\n }\n }\n\n /**\n * Allocate a keyframe name for SSR. Uses provided name or generates one.\n */\n allocateKeyframeName(providedName?: string): string {\n return (\n providedName ??\n makeKeyframeName(this.namePrefix, String(this.keyframesCounter++))\n );\n }\n\n /**\n * Record a @font-face rule. Deduplicated by key (content hash).\n */\n collectFontFace(key: string, css: string): void {\n if (!this.fontFaceRules.has(key)) {\n this.fontFaceRules.set(key, css);\n }\n }\n\n /**\n * Record a @counter-style rule. Deduplicated by name.\n */\n collectCounterStyle(name: string, css: string): void {\n if (!this.counterStyleRules.has(name)) {\n this.counterStyleRules.set(name, css);\n }\n }\n\n /**\n * Allocate a counter-style name for SSR. Uses provided name or generates one.\n */\n allocateCounterStyleName(providedName?: string): string {\n return (\n providedName ??\n makeCounterStyleName(this.namePrefix, String(this.counterStyleCounter++))\n );\n }\n\n /**\n * Record global styles (from useGlobalStyles). Deduplicated by key.\n */\n collectGlobalStyles(key: string, css: string): void {\n if (!this.globalStyles.has(key)) {\n this.globalStyles.set(key, css);\n }\n }\n\n /**\n * Record raw CSS text (from useRawCSS). Deduplicated by key.\n */\n collectRawCSS(key: string, css: string): void {\n if (!this.rawCSS.has(key)) {\n this.rawCSS.set(key, css);\n }\n }\n\n /**\n * Extract all CSS collected so far as a single string.\n * Includes @property and @keyframes rules.\n * Used for non-streaming SSR (renderToString).\n */\n getCSS(): string {\n const parts: string[] = [];\n\n for (const css of this.propertyRules.values()) {\n parts.push(css);\n }\n\n for (const css of this.fontFaceRules.values()) {\n parts.push(css);\n }\n\n for (const css of this.counterStyleRules.values()) {\n parts.push(css);\n }\n\n for (const css of this.rawCSS.values()) {\n parts.push(css);\n }\n\n for (const css of this.globalStyles.values()) {\n parts.push(css);\n }\n\n for (const css of this.chunks.values()) {\n parts.push(css);\n }\n\n for (const css of this.keyframeRules.values()) {\n parts.push(css);\n }\n\n return parts.join('\\n');\n }\n\n /**\n * Flush only newly collected CSS since the last flush.\n * Used for streaming SSR (renderToPipeableStream + useServerInsertedHTML).\n */\n flushCSS(): string {\n const parts: string[] = [];\n\n for (const [name, css] of this.propertyRules) {\n if (!this.flushedPropertyKeys.has(name)) {\n parts.push(css);\n this.flushedPropertyKeys.add(name);\n }\n }\n\n for (const [key, css] of this.fontFaceRules) {\n if (!this.flushedFontFaceKeys.has(key)) {\n parts.push(css);\n this.flushedFontFaceKeys.add(key);\n }\n }\n\n for (const [key, css] of this.counterStyleRules) {\n if (!this.flushedCounterStyleKeys.has(key)) {\n parts.push(css);\n this.flushedCounterStyleKeys.add(key);\n }\n }\n\n for (const [key, css] of this.rawCSS) {\n if (!this.flushedRawKeys.has(key)) {\n parts.push(css);\n this.flushedRawKeys.add(key);\n }\n }\n\n for (const [key, css] of this.globalStyles) {\n if (!this.flushedGlobalKeys.has(key)) {\n parts.push(css);\n this.flushedGlobalKeys.add(key);\n }\n }\n\n for (const [key, css] of this.chunks) {\n if (!this.flushedKeys.has(key)) {\n parts.push(css);\n this.flushedKeys.add(key);\n }\n }\n\n for (const [name, css] of this.keyframeRules) {\n if (!this.flushedKeyframeKeys.has(name)) {\n parts.push(css);\n this.flushedKeyframeKeys.add(name);\n }\n }\n\n return parts.join('\\n');\n }\n\n private flushedClassNames = new Set<string>();\n\n /**\n * Return class names rendered since the last call (for streaming).\n * Used to emit lightweight class-list scripts for client hydration.\n */\n getRenderedClassNames(): string[] {\n const names: string[] = [];\n for (const className of this.cacheKeyToClassName.values()) {\n if (!this.flushedClassNames.has(className)) {\n this.flushedClassNames.add(className);\n names.push(className);\n }\n }\n return names;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAoCA,IAAa,uBAAb,MAAkC;CAChC,yBAAiB,IAAI,KAAqB;CAC1C,sCAA8B,IAAI,KAAqB;CACvD,8BAAsB,IAAI,KAAa;CACvC,gCAAwB,IAAI,KAAqB;CACjD,sCAA8B,IAAI,KAAa;CAC/C,gCAAwB,IAAI,KAAqB;CACjD,sCAA8B,IAAI,KAAa;CAC/C,+BAAuB,IAAI,KAAqB;CAChD,oCAA4B,IAAI,KAAa;CAC7C,yBAAiB,IAAI,KAAqB;CAC1C,iCAAyB,IAAI,KAAa;CAC1C,gCAAwB,IAAI,KAAqB;CACjD,sCAA8B,IAAI,KAAa;CAC/C,oCAA4B,IAAI,KAAqB;CACrD,0CAAkC,IAAI,KAAa;CACnD,mBAA2B;CAC3B,sBAA8B;CAC9B,qBAA6B;CAC7B;;;;;;;;CASA,YAAY,YAAqB;EAC/B,IAAI,eAAe,KAAA,GACjB,mBAAmB,WAAW;EAEhC,KAAK,aAAa,cAAc,eAAe;;CAGjD,kBAA0B,UAA0B;EAClD,OAAO,cAAc,KAAK,YAAY,WAAW,SAAS,CAAC;;;;;;;;;;;CAY7D,mBAAyB;EACvB,IAAI,KAAK,oBAAoB;EAC7B,KAAK,qBAAqB;EAE1B,KAAK,MAAM,CAAC,OAAO,eAAe,OAAO,QACvC,wBAAwB,CACzB,EAAE;GACD,MAAM,MAAM,kBAA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