@tenphi/tasty 0.0.0-snapshot.05c1c22

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 (314) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +629 -0
  3. package/dist/_virtual/_rolldown/runtime.js +7 -0
  4. package/dist/chunks/cacheKey.d.ts +1 -0
  5. package/dist/chunks/cacheKey.js +77 -0
  6. package/dist/chunks/cacheKey.js.map +1 -0
  7. package/dist/chunks/definitions.d.ts +37 -0
  8. package/dist/chunks/definitions.js +258 -0
  9. package/dist/chunks/definitions.js.map +1 -0
  10. package/dist/chunks/index.d.ts +1 -0
  11. package/dist/chunks/renderChunk.d.ts +1 -0
  12. package/dist/chunks/renderChunk.js +59 -0
  13. package/dist/chunks/renderChunk.js.map +1 -0
  14. package/dist/config.d.ts +366 -0
  15. package/dist/config.js +503 -0
  16. package/dist/config.js.map +1 -0
  17. package/dist/core/index.d.ts +33 -0
  18. package/dist/core/index.js +26 -0
  19. package/dist/counter-style/index.js +51 -0
  20. package/dist/counter-style/index.js.map +1 -0
  21. package/dist/debug.d.ts +89 -0
  22. package/dist/debug.js +453 -0
  23. package/dist/debug.js.map +1 -0
  24. package/dist/font-face/index.js +63 -0
  25. package/dist/font-face/index.js.map +1 -0
  26. package/dist/hooks/index.d.ts +7 -0
  27. package/dist/hooks/resolve-ssr-collector.js +14 -0
  28. package/dist/hooks/resolve-ssr-collector.js.map +1 -0
  29. package/dist/hooks/useCounterStyle.d.ts +50 -0
  30. package/dist/hooks/useCounterStyle.js +46 -0
  31. package/dist/hooks/useCounterStyle.js.map +1 -0
  32. package/dist/hooks/useFontFace.d.ts +43 -0
  33. package/dist/hooks/useFontFace.js +70 -0
  34. package/dist/hooks/useFontFace.js.map +1 -0
  35. package/dist/hooks/useGlobalStyles.d.ts +30 -0
  36. package/dist/hooks/useGlobalStyles.js +78 -0
  37. package/dist/hooks/useGlobalStyles.js.map +1 -0
  38. package/dist/hooks/useKeyframes.d.ts +56 -0
  39. package/dist/hooks/useKeyframes.js +64 -0
  40. package/dist/hooks/useKeyframes.js.map +1 -0
  41. package/dist/hooks/useProperty.d.ts +79 -0
  42. package/dist/hooks/useProperty.js +109 -0
  43. package/dist/hooks/useProperty.js.map +1 -0
  44. package/dist/hooks/useRawCSS.d.ts +53 -0
  45. package/dist/hooks/useRawCSS.js +35 -0
  46. package/dist/hooks/useRawCSS.js.map +1 -0
  47. package/dist/hooks/useStyles.d.ts +45 -0
  48. package/dist/hooks/useStyles.js +237 -0
  49. package/dist/hooks/useStyles.js.map +1 -0
  50. package/dist/index.d.ts +50 -0
  51. package/dist/index.js +35 -0
  52. package/dist/injector/index.d.ts +183 -0
  53. package/dist/injector/index.js +179 -0
  54. package/dist/injector/index.js.map +1 -0
  55. package/dist/injector/injector.d.ts +166 -0
  56. package/dist/injector/injector.js +464 -0
  57. package/dist/injector/injector.js.map +1 -0
  58. package/dist/injector/sheet-manager.d.ts +136 -0
  59. package/dist/injector/sheet-manager.js +733 -0
  60. package/dist/injector/sheet-manager.js.map +1 -0
  61. package/dist/injector/types.d.ts +204 -0
  62. package/dist/keyframes/index.js +206 -0
  63. package/dist/keyframes/index.js.map +1 -0
  64. package/dist/parser/classify.js +319 -0
  65. package/dist/parser/classify.js.map +1 -0
  66. package/dist/parser/const.js +49 -0
  67. package/dist/parser/const.js.map +1 -0
  68. package/dist/parser/lru.js +109 -0
  69. package/dist/parser/lru.js.map +1 -0
  70. package/dist/parser/parser.d.ts +25 -0
  71. package/dist/parser/parser.js +115 -0
  72. package/dist/parser/parser.js.map +1 -0
  73. package/dist/parser/tokenizer.js +69 -0
  74. package/dist/parser/tokenizer.js.map +1 -0
  75. package/dist/parser/types.d.ts +51 -0
  76. package/dist/parser/types.js +46 -0
  77. package/dist/parser/types.js.map +1 -0
  78. package/dist/pipeline/conditions.d.ts +134 -0
  79. package/dist/pipeline/conditions.js +406 -0
  80. package/dist/pipeline/conditions.js.map +1 -0
  81. package/dist/pipeline/exclusive.js +230 -0
  82. package/dist/pipeline/exclusive.js.map +1 -0
  83. package/dist/pipeline/index.d.ts +55 -0
  84. package/dist/pipeline/index.js +708 -0
  85. package/dist/pipeline/index.js.map +1 -0
  86. package/dist/pipeline/materialize.js +1103 -0
  87. package/dist/pipeline/materialize.js.map +1 -0
  88. package/dist/pipeline/parseStateKey.d.ts +15 -0
  89. package/dist/pipeline/parseStateKey.js +446 -0
  90. package/dist/pipeline/parseStateKey.js.map +1 -0
  91. package/dist/pipeline/simplify.js +515 -0
  92. package/dist/pipeline/simplify.js.map +1 -0
  93. package/dist/pipeline/warnings.js +18 -0
  94. package/dist/pipeline/warnings.js.map +1 -0
  95. package/dist/plugins/index.d.ts +2 -0
  96. package/dist/plugins/okhsl-plugin.d.ts +35 -0
  97. package/dist/plugins/okhsl-plugin.js +97 -0
  98. package/dist/plugins/okhsl-plugin.js.map +1 -0
  99. package/dist/plugins/types.d.ts +76 -0
  100. package/dist/properties/index.js +222 -0
  101. package/dist/properties/index.js.map +1 -0
  102. package/dist/properties/property-type-resolver.d.ts +24 -0
  103. package/dist/properties/property-type-resolver.js +90 -0
  104. package/dist/properties/property-type-resolver.js.map +1 -0
  105. package/dist/ssr/astro.d.ts +29 -0
  106. package/dist/ssr/astro.js +64 -0
  107. package/dist/ssr/astro.js.map +1 -0
  108. package/dist/ssr/async-storage.d.ts +17 -0
  109. package/dist/ssr/async-storage.js +34 -0
  110. package/dist/ssr/async-storage.js.map +1 -0
  111. package/dist/ssr/collect-auto-properties.js +39 -0
  112. package/dist/ssr/collect-auto-properties.js.map +1 -0
  113. package/dist/ssr/collector.d.ts +102 -0
  114. package/dist/ssr/collector.js +226 -0
  115. package/dist/ssr/collector.js.map +1 -0
  116. package/dist/ssr/context.d.ts +8 -0
  117. package/dist/ssr/context.js +13 -0
  118. package/dist/ssr/context.js.map +1 -0
  119. package/dist/ssr/format-global-rules.js +22 -0
  120. package/dist/ssr/format-global-rules.js.map +1 -0
  121. package/dist/ssr/format-keyframes.js +69 -0
  122. package/dist/ssr/format-keyframes.js.map +1 -0
  123. package/dist/ssr/format-property.js +49 -0
  124. package/dist/ssr/format-property.js.map +1 -0
  125. package/dist/ssr/format-rules.js +73 -0
  126. package/dist/ssr/format-rules.js.map +1 -0
  127. package/dist/ssr/hydrate.d.ts +22 -0
  128. package/dist/ssr/hydrate.js +49 -0
  129. package/dist/ssr/hydrate.js.map +1 -0
  130. package/dist/ssr/index.d.ts +5 -0
  131. package/dist/ssr/index.js +11 -0
  132. package/dist/ssr/index.js.map +1 -0
  133. package/dist/ssr/next.d.ts +45 -0
  134. package/dist/ssr/next.js +69 -0
  135. package/dist/ssr/next.js.map +1 -0
  136. package/dist/ssr/ssr-collector-ref.js +12 -0
  137. package/dist/ssr/ssr-collector-ref.js.map +1 -0
  138. package/dist/states/index.d.ts +49 -0
  139. package/dist/states/index.js +170 -0
  140. package/dist/states/index.js.map +1 -0
  141. package/dist/static/index.d.ts +5 -0
  142. package/dist/static/index.js +4 -0
  143. package/dist/static/inject.d.ts +5 -0
  144. package/dist/static/inject.js +17 -0
  145. package/dist/static/inject.js.map +1 -0
  146. package/dist/static/tastyStatic.d.ts +46 -0
  147. package/dist/static/tastyStatic.js +30 -0
  148. package/dist/static/tastyStatic.js.map +1 -0
  149. package/dist/static/types.d.ts +49 -0
  150. package/dist/static/types.js +24 -0
  151. package/dist/static/types.js.map +1 -0
  152. package/dist/styles/align.d.ts +15 -0
  153. package/dist/styles/align.js +14 -0
  154. package/dist/styles/align.js.map +1 -0
  155. package/dist/styles/border.d.ts +25 -0
  156. package/dist/styles/border.js +113 -0
  157. package/dist/styles/border.js.map +1 -0
  158. package/dist/styles/color.d.ts +14 -0
  159. package/dist/styles/color.js +26 -0
  160. package/dist/styles/color.js.map +1 -0
  161. package/dist/styles/createStyle.js +79 -0
  162. package/dist/styles/createStyle.js.map +1 -0
  163. package/dist/styles/dimension.js +96 -0
  164. package/dist/styles/dimension.js.map +1 -0
  165. package/dist/styles/display.d.ts +37 -0
  166. package/dist/styles/display.js +66 -0
  167. package/dist/styles/display.js.map +1 -0
  168. package/dist/styles/fade.d.ts +15 -0
  169. package/dist/styles/fade.js +57 -0
  170. package/dist/styles/fade.js.map +1 -0
  171. package/dist/styles/fill.d.ts +42 -0
  172. package/dist/styles/fill.js +51 -0
  173. package/dist/styles/fill.js.map +1 -0
  174. package/dist/styles/flow.d.ts +16 -0
  175. package/dist/styles/flow.js +12 -0
  176. package/dist/styles/flow.js.map +1 -0
  177. package/dist/styles/gap.d.ts +31 -0
  178. package/dist/styles/gap.js +36 -0
  179. package/dist/styles/gap.js.map +1 -0
  180. package/dist/styles/height.d.ts +17 -0
  181. package/dist/styles/height.js +19 -0
  182. package/dist/styles/height.js.map +1 -0
  183. package/dist/styles/index.d.ts +1 -0
  184. package/dist/styles/index.js +8 -0
  185. package/dist/styles/index.js.map +1 -0
  186. package/dist/styles/inset.d.ts +52 -0
  187. package/dist/styles/inset.js +149 -0
  188. package/dist/styles/inset.js.map +1 -0
  189. package/dist/styles/justify.d.ts +15 -0
  190. package/dist/styles/justify.js +14 -0
  191. package/dist/styles/justify.js.map +1 -0
  192. package/dist/styles/list.d.ts +16 -0
  193. package/dist/styles/list.js +98 -0
  194. package/dist/styles/list.js.map +1 -0
  195. package/dist/styles/margin.d.ts +24 -0
  196. package/dist/styles/margin.js +103 -0
  197. package/dist/styles/margin.js.map +1 -0
  198. package/dist/styles/outline.d.ts +29 -0
  199. package/dist/styles/outline.js +64 -0
  200. package/dist/styles/outline.js.map +1 -0
  201. package/dist/styles/padding.d.ts +24 -0
  202. package/dist/styles/padding.js +103 -0
  203. package/dist/styles/padding.js.map +1 -0
  204. package/dist/styles/predefined.d.ts +71 -0
  205. package/dist/styles/predefined.js +237 -0
  206. package/dist/styles/predefined.js.map +1 -0
  207. package/dist/styles/preset.d.ts +52 -0
  208. package/dist/styles/preset.js +126 -0
  209. package/dist/styles/preset.js.map +1 -0
  210. package/dist/styles/radius.d.ts +12 -0
  211. package/dist/styles/radius.js +71 -0
  212. package/dist/styles/radius.js.map +1 -0
  213. package/dist/styles/scrollbar.d.ts +25 -0
  214. package/dist/styles/scrollbar.js +46 -0
  215. package/dist/styles/scrollbar.js.map +1 -0
  216. package/dist/styles/shadow.d.ts +14 -0
  217. package/dist/styles/shadow.js +23 -0
  218. package/dist/styles/shadow.js.map +1 -0
  219. package/dist/styles/transition.d.ts +14 -0
  220. package/dist/styles/transition.js +157 -0
  221. package/dist/styles/transition.js.map +1 -0
  222. package/dist/styles/types.d.ts +549 -0
  223. package/dist/styles/width.d.ts +17 -0
  224. package/dist/styles/width.js +19 -0
  225. package/dist/styles/width.js.map +1 -0
  226. package/dist/tasty.d.ts +119 -0
  227. package/dist/tasty.js +231 -0
  228. package/dist/tasty.js.map +1 -0
  229. package/dist/types.d.ts +184 -0
  230. package/dist/utils/cache-wrapper.js +21 -0
  231. package/dist/utils/cache-wrapper.js.map +1 -0
  232. package/dist/utils/case-converter.js +8 -0
  233. package/dist/utils/case-converter.js.map +1 -0
  234. package/dist/utils/color-math.d.ts +46 -0
  235. package/dist/utils/color-math.js +749 -0
  236. package/dist/utils/color-math.js.map +1 -0
  237. package/dist/utils/color-space.d.ts +5 -0
  238. package/dist/utils/color-space.js +228 -0
  239. package/dist/utils/color-space.js.map +1 -0
  240. package/dist/utils/colors.d.ts +5 -0
  241. package/dist/utils/colors.js +10 -0
  242. package/dist/utils/colors.js.map +1 -0
  243. package/dist/utils/css-types.d.ts +7 -0
  244. package/dist/utils/dotize.d.ts +26 -0
  245. package/dist/utils/dotize.js +122 -0
  246. package/dist/utils/dotize.js.map +1 -0
  247. package/dist/utils/filter-base-props.d.ts +15 -0
  248. package/dist/utils/filter-base-props.js +45 -0
  249. package/dist/utils/filter-base-props.js.map +1 -0
  250. package/dist/utils/get-display-name.d.ts +7 -0
  251. package/dist/utils/get-display-name.js +10 -0
  252. package/dist/utils/get-display-name.js.map +1 -0
  253. package/dist/utils/has-keys.js +13 -0
  254. package/dist/utils/has-keys.js.map +1 -0
  255. package/dist/utils/is-dev-env.js +19 -0
  256. package/dist/utils/is-dev-env.js.map +1 -0
  257. package/dist/utils/is-valid-element-type.js +15 -0
  258. package/dist/utils/is-valid-element-type.js.map +1 -0
  259. package/dist/utils/merge-styles.d.ts +7 -0
  260. package/dist/utils/merge-styles.js +145 -0
  261. package/dist/utils/merge-styles.js.map +1 -0
  262. package/dist/utils/mod-attrs.d.ts +6 -0
  263. package/dist/utils/mod-attrs.js +20 -0
  264. package/dist/utils/mod-attrs.js.map +1 -0
  265. package/dist/utils/process-tokens.d.ts +21 -0
  266. package/dist/utils/process-tokens.js +90 -0
  267. package/dist/utils/process-tokens.js.map +1 -0
  268. package/dist/utils/resolve-recipes.d.ts +17 -0
  269. package/dist/utils/resolve-recipes.js +146 -0
  270. package/dist/utils/resolve-recipes.js.map +1 -0
  271. package/dist/utils/selector-transform.js +32 -0
  272. package/dist/utils/selector-transform.js.map +1 -0
  273. package/dist/utils/string.js +8 -0
  274. package/dist/utils/string.js.map +1 -0
  275. package/dist/utils/styles.d.ts +99 -0
  276. package/dist/utils/styles.js +220 -0
  277. package/dist/utils/styles.js.map +1 -0
  278. package/dist/utils/typography.d.ts +47 -0
  279. package/dist/utils/typography.js +51 -0
  280. package/dist/utils/typography.js.map +1 -0
  281. package/dist/utils/warnings.d.ts +16 -0
  282. package/dist/utils/warnings.js +16 -0
  283. package/dist/utils/warnings.js.map +1 -0
  284. package/dist/zero/babel.d.ts +182 -0
  285. package/dist/zero/babel.js +438 -0
  286. package/dist/zero/babel.js.map +1 -0
  287. package/dist/zero/css-writer.d.ts +45 -0
  288. package/dist/zero/css-writer.js +73 -0
  289. package/dist/zero/css-writer.js.map +1 -0
  290. package/dist/zero/extractor.d.ts +24 -0
  291. package/dist/zero/extractor.js +266 -0
  292. package/dist/zero/extractor.js.map +1 -0
  293. package/dist/zero/index.d.ts +3 -0
  294. package/dist/zero/index.js +3 -0
  295. package/dist/zero/next.d.ts +86 -0
  296. package/dist/zero/next.js +143 -0
  297. package/dist/zero/next.js.map +1 -0
  298. package/docs/PIPELINE.md +519 -0
  299. package/docs/README.md +31 -0
  300. package/docs/adoption.md +296 -0
  301. package/docs/comparison.md +420 -0
  302. package/docs/configuration.md +326 -0
  303. package/docs/debug.md +318 -0
  304. package/docs/design-system.md +424 -0
  305. package/docs/dsl.md +673 -0
  306. package/docs/getting-started.md +217 -0
  307. package/docs/injector.md +528 -0
  308. package/docs/methodology.md +567 -0
  309. package/docs/runtime.md +485 -0
  310. package/docs/ssr.md +384 -0
  311. package/docs/styles.md +582 -0
  312. package/docs/tasty-static.md +520 -0
  313. package/package.json +215 -0
  314. package/tasty.config.ts +14 -0
@@ -0,0 +1,90 @@
1
+ import { inferSyntaxFromValue } from "./index.js";
2
+ //#region src/properties/property-type-resolver.ts
3
+ /**
4
+ * PropertyTypeResolver
5
+ *
6
+ * Automatically infers CSS @property types from custom property values.
7
+ * Supports deferred resolution for var() reference chains of arbitrary depth.
8
+ */
9
+ const CUSTOM_PROP_DECL = /^\s*(--[a-z0-9_-]+)\s*:\s*(.+?)\s*$/i;
10
+ const SINGLE_VAR_REF = /^var\((--[a-z0-9_-]+)\)$/i;
11
+ var PropertyTypeResolver = class {
12
+ /** propName → the prop it depends on */
13
+ pendingDeps = /* @__PURE__ */ new Map();
14
+ /** propName → list of props waiting on it */
15
+ reverseDeps = /* @__PURE__ */ new Map();
16
+ /**
17
+ * Scan CSS declarations and auto-register @property for custom properties
18
+ * whose types can be inferred from their values.
19
+ */
20
+ scanDeclarations(declarations, isPropertyDefined, registerProperty) {
21
+ if (!declarations.includes("--")) return;
22
+ const parts = declarations.split(/;+/);
23
+ for (const part of parts) {
24
+ if (!part.trim()) continue;
25
+ const match = CUSTOM_PROP_DECL.exec(part);
26
+ if (!match) continue;
27
+ const propName = match[1];
28
+ const value = match[2].trim();
29
+ if (isPropertyDefined(propName)) continue;
30
+ if (propName.endsWith("-color")) {
31
+ registerProperty(propName, "<color>", "transparent");
32
+ continue;
33
+ }
34
+ if (propName.endsWith("-line-height")) {
35
+ registerProperty(propName, "<number> | <length-percentage>", "0");
36
+ continue;
37
+ }
38
+ if (propName.endsWith("-opacity")) {
39
+ registerProperty(propName, "<number> | <percentage>", "0");
40
+ continue;
41
+ }
42
+ const varMatch = SINGLE_VAR_REF.exec(value);
43
+ if (varMatch) {
44
+ const depName = varMatch[1];
45
+ this.addDependency(propName, depName);
46
+ continue;
47
+ }
48
+ if (this.isComplexValue(value)) continue;
49
+ const inferred = inferSyntaxFromValue(value);
50
+ if (!inferred) continue;
51
+ this.resolve(propName, inferred.syntax, inferred.initialValue, isPropertyDefined, registerProperty);
52
+ }
53
+ }
54
+ addDependency(propName, depName) {
55
+ if (propName === depName) return;
56
+ this.pendingDeps.set(propName, depName);
57
+ let dependents = this.reverseDeps.get(depName);
58
+ if (!dependents) {
59
+ dependents = [];
60
+ this.reverseDeps.set(depName, dependents);
61
+ }
62
+ if (!dependents.includes(propName)) dependents.push(propName);
63
+ }
64
+ resolve(propName, syntax, initialValue, isPropertyDefined, registerProperty, resolving) {
65
+ if (!resolving) resolving = /* @__PURE__ */ new Set();
66
+ if (resolving.has(propName)) return;
67
+ resolving.add(propName);
68
+ if (!isPropertyDefined(propName)) registerProperty(propName, syntax, initialValue);
69
+ const dependents = this.reverseDeps.get(propName);
70
+ if (dependents) {
71
+ this.reverseDeps.delete(propName);
72
+ for (const dependent of dependents) {
73
+ this.pendingDeps.delete(dependent);
74
+ if (isPropertyDefined(dependent)) continue;
75
+ this.resolve(dependent, syntax, initialValue, isPropertyDefined, registerProperty, resolving);
76
+ }
77
+ }
78
+ }
79
+ isComplexValue(value) {
80
+ if (value.includes("calc(")) return true;
81
+ const firstVar = value.indexOf("var(");
82
+ if (firstVar === -1) return false;
83
+ if (value.indexOf("var(", firstVar + 4) !== -1) return true;
84
+ return !SINGLE_VAR_REF.test(value);
85
+ }
86
+ };
87
+ //#endregion
88
+ export { PropertyTypeResolver };
89
+
90
+ //# sourceMappingURL=property-type-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property-type-resolver.js","names":[],"sources":["../../src/properties/property-type-resolver.ts"],"sourcesContent":["/**\n * PropertyTypeResolver\n *\n * Automatically infers CSS @property types from custom property values.\n * Supports deferred resolution for var() reference chains of arbitrary depth.\n */\n\nimport { inferSyntaxFromValue } from './index';\n\nconst CUSTOM_PROP_DECL = /^\\s*(--[a-z0-9_-]+)\\s*:\\s*(.+?)\\s*$/i;\nconst SINGLE_VAR_REF = /^var\\((--[a-z0-9_-]+)\\)$/i;\n\nexport class PropertyTypeResolver {\n /** propName → the prop it depends on */\n private pendingDeps = new Map<string, string>();\n /** propName → list of props waiting on it */\n private reverseDeps = new Map<string, string[]>();\n\n /**\n * Scan CSS declarations and auto-register @property for custom properties\n * whose types can be inferred from their values.\n */\n scanDeclarations(\n declarations: string,\n isPropertyDefined: (name: string) => boolean,\n registerProperty: (\n name: string,\n syntax: string,\n initialValue: string,\n ) => void,\n ): void {\n if (!declarations.includes('--')) return;\n\n const parts = declarations.split(/;+/);\n\n for (const part of parts) {\n if (!part.trim()) continue;\n\n const match = CUSTOM_PROP_DECL.exec(part);\n if (!match) continue;\n\n const propName = match[1];\n const value = match[2].trim();\n\n if (isPropertyDefined(propName)) continue;\n\n // Name-based: --*-color properties are always <color> (from #name tokens)\n if (propName.endsWith('-color')) {\n registerProperty(propName, '<color>', 'transparent');\n continue;\n }\n\n // Name-based: --*-line-height accepts numbers, lengths, and percentages\n if (propName.endsWith('-line-height')) {\n registerProperty(propName, '<number> | <length-percentage>', '0');\n continue;\n }\n\n // Name-based: --*-opacity accepts numbers and percentages\n if (propName.endsWith('-opacity')) {\n registerProperty(propName, '<number> | <percentage>', '0');\n continue;\n }\n\n // Single var() reference → record dependency for deferred resolution\n const varMatch = SINGLE_VAR_REF.exec(value);\n if (varMatch) {\n const depName = varMatch[1];\n this.addDependency(propName, depName);\n continue;\n }\n\n // Skip complex expressions (calc, multiple var, etc.)\n if (this.isComplexValue(value)) continue;\n\n const inferred = inferSyntaxFromValue(value);\n if (!inferred) continue;\n\n this.resolve(\n propName,\n inferred.syntax,\n inferred.initialValue,\n isPropertyDefined,\n registerProperty,\n );\n }\n }\n\n private addDependency(propName: string, depName: string): void {\n if (propName === depName) return;\n\n this.pendingDeps.set(propName, depName);\n\n let dependents = this.reverseDeps.get(depName);\n if (!dependents) {\n dependents = [];\n this.reverseDeps.set(depName, dependents);\n }\n if (!dependents.includes(propName)) {\n dependents.push(propName);\n }\n }\n\n private resolve(\n propName: string,\n syntax: string,\n initialValue: string,\n isPropertyDefined: (name: string) => boolean,\n registerProperty: (\n name: string,\n syntax: string,\n initialValue: string,\n ) => void,\n resolving?: Set<string>,\n ): void {\n if (!resolving) resolving = new Set();\n if (resolving.has(propName)) return;\n resolving.add(propName);\n\n if (!isPropertyDefined(propName)) {\n registerProperty(propName, syntax, initialValue);\n }\n\n const dependents = this.reverseDeps.get(propName);\n if (dependents) {\n this.reverseDeps.delete(propName);\n\n for (const dependent of dependents) {\n this.pendingDeps.delete(dependent);\n\n if (isPropertyDefined(dependent)) continue;\n\n this.resolve(\n dependent,\n syntax,\n initialValue,\n isPropertyDefined,\n registerProperty,\n resolving,\n );\n }\n }\n }\n\n private isComplexValue(value: string): boolean {\n if (value.includes('calc(')) return true;\n const firstVar = value.indexOf('var(');\n if (firstVar === -1) return false;\n if (value.indexOf('var(', firstVar + 4) !== -1) return true;\n return !SINGLE_VAR_REF.test(value);\n }\n}\n"],"mappings":";;;;;;;;AASA,MAAM,mBAAmB;AACzB,MAAM,iBAAiB;AAEvB,IAAa,uBAAb,MAAkC;;CAEhC,8BAAsB,IAAI,KAAqB;;CAE/C,8BAAsB,IAAI,KAAuB;;;;;CAMjD,iBACE,cACA,mBACA,kBAKM;AACN,MAAI,CAAC,aAAa,SAAS,KAAK,CAAE;EAElC,MAAM,QAAQ,aAAa,MAAM,KAAK;AAEtC,OAAK,MAAM,QAAQ,OAAO;AACxB,OAAI,CAAC,KAAK,MAAM,CAAE;GAElB,MAAM,QAAQ,iBAAiB,KAAK,KAAK;AACzC,OAAI,CAAC,MAAO;GAEZ,MAAM,WAAW,MAAM;GACvB,MAAM,QAAQ,MAAM,GAAG,MAAM;AAE7B,OAAI,kBAAkB,SAAS,CAAE;AAGjC,OAAI,SAAS,SAAS,SAAS,EAAE;AAC/B,qBAAiB,UAAU,WAAW,cAAc;AACpD;;AAIF,OAAI,SAAS,SAAS,eAAe,EAAE;AACrC,qBAAiB,UAAU,kCAAkC,IAAI;AACjE;;AAIF,OAAI,SAAS,SAAS,WAAW,EAAE;AACjC,qBAAiB,UAAU,2BAA2B,IAAI;AAC1D;;GAIF,MAAM,WAAW,eAAe,KAAK,MAAM;AAC3C,OAAI,UAAU;IACZ,MAAM,UAAU,SAAS;AACzB,SAAK,cAAc,UAAU,QAAQ;AACrC;;AAIF,OAAI,KAAK,eAAe,MAAM,CAAE;GAEhC,MAAM,WAAW,qBAAqB,MAAM;AAC5C,OAAI,CAAC,SAAU;AAEf,QAAK,QACH,UACA,SAAS,QACT,SAAS,cACT,mBACA,iBACD;;;CAIL,cAAsB,UAAkB,SAAuB;AAC7D,MAAI,aAAa,QAAS;AAE1B,OAAK,YAAY,IAAI,UAAU,QAAQ;EAEvC,IAAI,aAAa,KAAK,YAAY,IAAI,QAAQ;AAC9C,MAAI,CAAC,YAAY;AACf,gBAAa,EAAE;AACf,QAAK,YAAY,IAAI,SAAS,WAAW;;AAE3C,MAAI,CAAC,WAAW,SAAS,SAAS,CAChC,YAAW,KAAK,SAAS;;CAI7B,QACE,UACA,QACA,cACA,mBACA,kBAKA,WACM;AACN,MAAI,CAAC,UAAW,6BAAY,IAAI,KAAK;AACrC,MAAI,UAAU,IAAI,SAAS,CAAE;AAC7B,YAAU,IAAI,SAAS;AAEvB,MAAI,CAAC,kBAAkB,SAAS,CAC9B,kBAAiB,UAAU,QAAQ,aAAa;EAGlD,MAAM,aAAa,KAAK,YAAY,IAAI,SAAS;AACjD,MAAI,YAAY;AACd,QAAK,YAAY,OAAO,SAAS;AAEjC,QAAK,MAAM,aAAa,YAAY;AAClC,SAAK,YAAY,OAAO,UAAU;AAElC,QAAI,kBAAkB,UAAU,CAAE;AAElC,SAAK,QACH,WACA,QACA,cACA,mBACA,kBACA,UACD;;;;CAKP,eAAuB,OAAwB;AAC7C,MAAI,MAAM,SAAS,QAAQ,CAAE,QAAO;EACpC,MAAM,WAAW,MAAM,QAAQ,OAAO;AACtC,MAAI,aAAa,GAAI,QAAO;AAC5B,MAAI,MAAM,QAAQ,QAAQ,WAAW,EAAE,KAAK,GAAI,QAAO;AACvD,SAAO,CAAC,eAAe,KAAK,MAAM"}
@@ -0,0 +1,29 @@
1
+ import { hydrateTastyCache } from "./hydrate.js";
2
+
3
+ //#region src/ssr/astro.d.ts
4
+ interface TastyMiddlewareOptions {
5
+ /**
6
+ * Whether to embed the cache state script for client hydration.
7
+ * Set to false to skip cache transfer. Default: true.
8
+ */
9
+ transferCache?: boolean;
10
+ }
11
+ /**
12
+ * Create an Astro middleware that collects Tasty styles during SSR.
13
+ *
14
+ * All React components rendered during the request (both static
15
+ * and islands) will have their useStyles() calls captured by the
16
+ * collector via AsyncLocalStorage. After rendering, the middleware
17
+ * injects the collected CSS into </head>.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * // src/middleware.ts
22
+ * import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
23
+ * export const onRequest = tastyMiddleware();
24
+ * ```
25
+ */
26
+ declare function tastyMiddleware(options?: TastyMiddlewareOptions): (_context: unknown, next: () => Promise<Response>) => Promise<Response>;
27
+ //#endregion
28
+ export { TastyMiddlewareOptions, hydrateTastyCache, tastyMiddleware };
29
+ //# sourceMappingURL=astro.d.ts.map
@@ -0,0 +1,64 @@
1
+ import { getConfig } from "../config.js";
2
+ import { registerSSRCollectorGetter } from "./ssr-collector-ref.js";
3
+ import { ServerStyleCollector } from "./collector.js";
4
+ import { getSSRCollector, runWithCollector } from "./async-storage.js";
5
+ import { hydrateTastyCache } from "./hydrate.js";
6
+ //#region src/ssr/astro.ts
7
+ /**
8
+ * Astro integration for Tasty SSR.
9
+ *
10
+ * Provides tastyMiddleware() for Astro's middleware system.
11
+ * The middleware wraps request handling in a ServerStyleCollector
12
+ * via AsyncLocalStorage, then injects collected CSS into </head>.
13
+ *
14
+ * Import from '@tenphi/tasty/ssr/astro'.
15
+ */
16
+ registerSSRCollectorGetter(getSSRCollector);
17
+ /**
18
+ * Create an Astro middleware that collects Tasty styles during SSR.
19
+ *
20
+ * All React components rendered during the request (both static
21
+ * and islands) will have their useStyles() calls captured by the
22
+ * collector via AsyncLocalStorage. After rendering, the middleware
23
+ * injects the collected CSS into </head>.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * // src/middleware.ts
28
+ * import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
29
+ * export const onRequest = tastyMiddleware();
30
+ * ```
31
+ */
32
+ function tastyMiddleware(options) {
33
+ const { transferCache = true } = options ?? {};
34
+ return async (_context, next) => {
35
+ const collector = new ServerStyleCollector();
36
+ const response = await runWithCollector(collector, () => next());
37
+ const css = collector.getCSS();
38
+ if (!css) return response;
39
+ const nonce = getConfig().nonce;
40
+ const nonceAttr = nonce ? ` nonce="${nonce}"` : "";
41
+ const html = await response.text();
42
+ const styleTag = `<style data-tasty-ssr${nonceAttr}>${css}</style>`;
43
+ let cacheTag = "";
44
+ if (transferCache) {
45
+ const cacheState = collector.getCacheState();
46
+ if (Object.keys(cacheState.entries).length > 0) cacheTag = `<script data-tasty-cache type="application/json"${nonceAttr}>${JSON.stringify(cacheState)}<\/script>`;
47
+ }
48
+ const modifiedHtml = html.replace("</head>", `${styleTag}${cacheTag}</head>`);
49
+ return new Response(modifiedHtml, {
50
+ status: response.status,
51
+ headers: response.headers
52
+ });
53
+ };
54
+ }
55
+ if (typeof window !== "undefined") {
56
+ const script = document.querySelector("script[data-tasty-cache]");
57
+ if (script) try {
58
+ hydrateTastyCache(JSON.parse(script.textContent));
59
+ } catch {}
60
+ }
61
+ //#endregion
62
+ export { hydrateTastyCache, tastyMiddleware };
63
+
64
+ //# sourceMappingURL=astro.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro.js","names":[],"sources":["../../src/ssr/astro.ts"],"sourcesContent":["/**\n * Astro integration for Tasty SSR.\n *\n * Provides tastyMiddleware() for Astro's middleware system.\n * The middleware wraps request handling in a ServerStyleCollector\n * via AsyncLocalStorage, then injects collected CSS into </head>.\n *\n * Import from '@tenphi/tasty/ssr/astro'.\n */\n\nimport { getConfig } from '../config';\nimport { getSSRCollector, runWithCollector } from './async-storage';\nimport { ServerStyleCollector } from './collector';\nimport { hydrateTastyCache } from './hydrate';\nimport { registerSSRCollectorGetter } from './ssr-collector-ref';\n\n// Wire up ALS-based collector discovery so useStyles can find\n// the collector set by tastyMiddleware's runWithCollector().\nregisterSSRCollectorGetter(getSSRCollector);\n\n// Re-export for convenience\nexport { hydrateTastyCache };\n\nexport interface TastyMiddlewareOptions {\n /**\n * Whether to embed the cache state script for client hydration.\n * Set to false to skip cache transfer. Default: true.\n */\n transferCache?: boolean;\n}\n\n/**\n * Create an Astro middleware that collects Tasty styles during SSR.\n *\n * All React components rendered during the request (both static\n * and islands) will have their useStyles() calls captured by the\n * collector via AsyncLocalStorage. After rendering, the middleware\n * injects the collected CSS into </head>.\n *\n * @example\n * ```ts\n * // src/middleware.ts\n * import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';\n * export const onRequest = tastyMiddleware();\n * ```\n */\nexport function tastyMiddleware(options?: TastyMiddlewareOptions) {\n const { transferCache = true } = options ?? {};\n\n return async (\n _context: unknown,\n next: () => Promise<Response>,\n ): Promise<Response> => {\n const collector = new ServerStyleCollector();\n\n const response = await runWithCollector(collector, () => next());\n\n const css = collector.getCSS();\n if (!css) return response;\n\n const nonce = getConfig().nonce;\n const nonceAttr = nonce ? ` nonce=\"${nonce}\"` : '';\n const html = await response.text();\n const styleTag = `<style data-tasty-ssr${nonceAttr}>${css}</style>`;\n\n let cacheTag = '';\n if (transferCache) {\n const cacheState = collector.getCacheState();\n const hasHydratableStyles = Object.keys(cacheState.entries).length > 0;\n if (hasHydratableStyles) {\n cacheTag = `<script data-tasty-cache type=\"application/json\"${nonceAttr}>${JSON.stringify(cacheState)}</script>`;\n }\n }\n\n const modifiedHtml = html.replace(\n '</head>',\n `${styleTag}${cacheTag}</head>`,\n );\n\n return new Response(modifiedHtml, {\n status: response.status,\n headers: response.headers,\n });\n };\n}\n\n// Client-side auto-hydration.\n// When imported in the browser, reads the cache state from the DOM\n// and pre-populates the injector before any island hydrates.\nif (typeof window !== 'undefined') {\n const script = document.querySelector('script[data-tasty-cache]');\n if (script) {\n try {\n const state = JSON.parse(script.textContent!);\n hydrateTastyCache(state);\n } catch {\n // Ignore malformed cache state\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,2BAA2B,gBAAgB;;;;;;;;;;;;;;;;AA4B3C,SAAgB,gBAAgB,SAAkC;CAChE,MAAM,EAAE,gBAAgB,SAAS,WAAW,EAAE;AAE9C,QAAO,OACL,UACA,SACsB;EACtB,MAAM,YAAY,IAAI,sBAAsB;EAE5C,MAAM,WAAW,MAAM,iBAAiB,iBAAiB,MAAM,CAAC;EAEhE,MAAM,MAAM,UAAU,QAAQ;AAC9B,MAAI,CAAC,IAAK,QAAO;EAEjB,MAAM,QAAQ,WAAW,CAAC;EAC1B,MAAM,YAAY,QAAQ,WAAW,MAAM,KAAK;EAChD,MAAM,OAAO,MAAM,SAAS,MAAM;EAClC,MAAM,WAAW,wBAAwB,UAAU,GAAG,IAAI;EAE1D,IAAI,WAAW;AACf,MAAI,eAAe;GACjB,MAAM,aAAa,UAAU,eAAe;AAE5C,OAD4B,OAAO,KAAK,WAAW,QAAQ,CAAC,SAAS,EAEnE,YAAW,mDAAmD,UAAU,GAAG,KAAK,UAAU,WAAW,CAAC;;EAI1G,MAAM,eAAe,KAAK,QACxB,WACA,GAAG,WAAW,SAAS,SACxB;AAED,SAAO,IAAI,SAAS,cAAc;GAChC,QAAQ,SAAS;GACjB,SAAS,SAAS;GACnB,CAAC;;;AAON,IAAI,OAAO,WAAW,aAAa;CACjC,MAAM,SAAS,SAAS,cAAc,2BAA2B;AACjE,KAAI,OACF,KAAI;AAEF,oBADc,KAAK,MAAM,OAAO,YAAa,CACrB;SAClB"}
@@ -0,0 +1,17 @@
1
+ import { ServerStyleCollector } from "./collector.js";
2
+
3
+ //#region src/ssr/async-storage.d.ts
4
+ /**
5
+ * Run a function with a ServerStyleCollector bound to the current
6
+ * async context. All useStyles() calls within `fn` (and any async
7
+ * continuations) will find this collector via getSSRCollector().
8
+ */
9
+ declare function runWithCollector<T>(collector: ServerStyleCollector, fn: () => T): T;
10
+ /**
11
+ * Retrieve the ServerStyleCollector bound to the current async context.
12
+ * Returns null when called outside of runWithCollector() or on the client.
13
+ */
14
+ declare function getSSRCollector(): ServerStyleCollector | null;
15
+ //#endregion
16
+ export { getSSRCollector, runWithCollector };
17
+ //# sourceMappingURL=async-storage.d.ts.map
@@ -0,0 +1,34 @@
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
+ * This module imports from 'node:async_hooks' — it must be excluded
12
+ * from client bundles via the build configuration.
13
+ */
14
+ const tastySSRStorage = new AsyncLocalStorage();
15
+ /**
16
+ * Run a function with a ServerStyleCollector bound to the current
17
+ * async context. All useStyles() calls within `fn` (and any async
18
+ * continuations) will find this collector via getSSRCollector().
19
+ */
20
+ function runWithCollector(collector, fn) {
21
+ return tastySSRStorage.run(collector, fn);
22
+ }
23
+ /**
24
+ * Retrieve the ServerStyleCollector bound to the current async context.
25
+ * Returns null when called outside of runWithCollector() or on the client.
26
+ */
27
+ function getSSRCollector() {
28
+ if (typeof tastySSRStorage?.getStore !== "function") return null;
29
+ return tastySSRStorage.getStore() ?? null;
30
+ }
31
+ //#endregion
32
+ export { getSSRCollector, runWithCollector };
33
+
34
+ //# sourceMappingURL=async-storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-storage.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 * 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 tastySSRStorage = new AsyncLocalStorage<ServerStyleCollector>();\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 tastySSRStorage.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 if (typeof tastySSRStorage?.getStore !== 'function') return null;\n return tastySSRStorage.getStore() ?? null;\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,MAAM,kBAAkB,IAAI,mBAAyC;;;;;;AAOrE,SAAgB,iBACd,WACA,IACG;AACH,QAAO,gBAAgB,IAAI,WAAW,GAAG;;;;;;AAO3C,SAAgB,kBAA+C;AAC7D,KAAI,OAAO,iBAAiB,aAAa,WAAY,QAAO;AAC5D,QAAO,gBAAgB,UAAU,IAAI"}
@@ -0,0 +1,39 @@
1
+ import { parsePropertyToken } from "../properties/index.js";
2
+ import { PropertyTypeResolver } from "../properties/property-type-resolver.js";
3
+ import { formatPropertyCSS } from "./format-property.js";
4
+ //#region src/ssr/collect-auto-properties.ts
5
+ /**
6
+ * Scan rendered rules for custom property declarations and collect
7
+ * auto-inferred @property rules via the SSR collector.
8
+ *
9
+ * @param rules - Rendered style rules containing CSS declarations
10
+ * @param collector - SSR collector to emit @property CSS into
11
+ * @param styles - Original styles object (used to skip explicit @properties)
12
+ */
13
+ function collectAutoInferredProperties(rules, collector, styles) {
14
+ const registered = /* @__PURE__ */ new Set();
15
+ if (styles) {
16
+ const localProps = styles["@properties"];
17
+ if (localProps && typeof localProps === "object") for (const token of Object.keys(localProps)) {
18
+ const parsed = parsePropertyToken(token);
19
+ if (parsed.isValid) registered.add(parsed.cssName);
20
+ }
21
+ }
22
+ const resolver = new PropertyTypeResolver();
23
+ for (const rule of rules) {
24
+ if (!rule.declarations) continue;
25
+ resolver.scanDeclarations(rule.declarations, (name) => registered.has(name), (name, syntax, initialValue) => {
26
+ registered.add(name);
27
+ const css = formatPropertyCSS(name, {
28
+ syntax,
29
+ inherits: true,
30
+ initialValue
31
+ });
32
+ if (css) collector.collectProperty(`__auto:${name}`, css);
33
+ });
34
+ }
35
+ }
36
+ //#endregion
37
+ export { collectAutoInferredProperties };
38
+
39
+ //# sourceMappingURL=collect-auto-properties.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collect-auto-properties.js","names":[],"sources":["../../src/ssr/collect-auto-properties.ts"],"sourcesContent":["/**\n * SSR auto-property inference.\n *\n * Scans rendered CSS declarations for custom properties whose types\n * can be inferred from their values (e.g. `--angle: 30deg` → `<angle>`).\n * Mirrors the client-side auto-inference in StyleInjector.inject().\n */\n\nimport type { StyleResult } from '../pipeline';\nimport { parsePropertyToken } from '../properties';\nimport { PropertyTypeResolver } from '../properties/property-type-resolver';\nimport type { Styles } from '../styles/types';\n\nimport type { ServerStyleCollector } from './collector';\nimport { formatPropertyCSS } from './format-property';\n\n/**\n * Scan rendered rules for custom property declarations and collect\n * auto-inferred @property rules via the SSR collector.\n *\n * @param rules - Rendered style rules containing CSS declarations\n * @param collector - SSR collector to emit @property CSS into\n * @param styles - Original styles object (used to skip explicit @properties)\n */\nexport function collectAutoInferredProperties(\n rules: StyleResult[],\n collector: ServerStyleCollector,\n styles?: Styles,\n): void {\n const registered = new Set<string>();\n\n if (styles) {\n const localProps = styles['@properties'];\n if (localProps && typeof localProps === 'object') {\n for (const token of Object.keys(localProps as Record<string, unknown>)) {\n const parsed = parsePropertyToken(token);\n if (parsed.isValid) {\n registered.add(parsed.cssName);\n }\n }\n }\n }\n\n const resolver = new PropertyTypeResolver();\n\n for (const rule of rules) {\n if (!rule.declarations) continue;\n resolver.scanDeclarations(\n rule.declarations,\n (name) => registered.has(name),\n (name, syntax, initialValue) => {\n registered.add(name);\n const css = formatPropertyCSS(name, {\n syntax,\n inherits: true,\n initialValue,\n });\n if (css) {\n collector.collectProperty(`__auto:${name}`, css);\n }\n },\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;AAwBA,SAAgB,8BACd,OACA,WACA,QACM;CACN,MAAM,6BAAa,IAAI,KAAa;AAEpC,KAAI,QAAQ;EACV,MAAM,aAAa,OAAO;AAC1B,MAAI,cAAc,OAAO,eAAe,SACtC,MAAK,MAAM,SAAS,OAAO,KAAK,WAAsC,EAAE;GACtE,MAAM,SAAS,mBAAmB,MAAM;AACxC,OAAI,OAAO,QACT,YAAW,IAAI,OAAO,QAAQ;;;CAMtC,MAAM,WAAW,IAAI,sBAAsB;AAE3C,MAAK,MAAM,QAAQ,OAAO;AACxB,MAAI,CAAC,KAAK,aAAc;AACxB,WAAS,iBACP,KAAK,eACJ,SAAS,WAAW,IAAI,KAAK,GAC7B,MAAM,QAAQ,iBAAiB;AAC9B,cAAW,IAAI,KAAK;GACpB,MAAM,MAAM,kBAAkB,MAAM;IAClC;IACA,UAAU;IACV;IACD,CAAC;AACF,OAAI,IACF,WAAU,gBAAgB,UAAU,QAAQ,IAAI;IAGrD"}
@@ -0,0 +1,102 @@
1
+ import { StyleResult } from "../pipeline/index.js";
2
+
3
+ //#region src/ssr/collector.d.ts
4
+ /**
5
+ * Cache state serialized to the client for hydration.
6
+ */
7
+ interface SSRCacheState {
8
+ /** cacheKey → className map, to pre-populate the client registry */
9
+ entries: Record<string, string>;
10
+ /** Counter value so client allocations don't collide with server ones */
11
+ classCounter: number;
12
+ }
13
+ declare class ServerStyleCollector {
14
+ private chunks;
15
+ private cacheKeyToClassName;
16
+ private classCounter;
17
+ private flushedKeys;
18
+ private propertyRules;
19
+ private flushedPropertyKeys;
20
+ private keyframeRules;
21
+ private flushedKeyframeKeys;
22
+ private globalStyles;
23
+ private flushedGlobalKeys;
24
+ private rawCSS;
25
+ private flushedRawKeys;
26
+ private fontFaceRules;
27
+ private flushedFontFaceKeys;
28
+ private counterStyleRules;
29
+ private flushedCounterStyleKeys;
30
+ private keyframesCounter;
31
+ private counterStyleCounter;
32
+ private internalsCollected;
33
+ /**
34
+ * Collect internal @property rules and :root token defaults.
35
+ * Mirrors markStylesGenerated() from the client-side injector.
36
+ * Called automatically on first chunk collection; idempotent.
37
+ */
38
+ collectInternals(): void;
39
+ /**
40
+ * Allocate a className for a cache key, server-side.
41
+ * Mirrors StyleInjector.allocateClassName but without DOM access.
42
+ */
43
+ allocateClassName(cacheKey: string): {
44
+ className: string;
45
+ isNewAllocation: boolean;
46
+ };
47
+ /**
48
+ * Record CSS rules for a chunk.
49
+ * Called by useStyles during server render.
50
+ */
51
+ collectChunk(cacheKey: string, className: string, rules: StyleResult[]): void;
52
+ /**
53
+ * Record a @property rule. Deduplicated by name.
54
+ */
55
+ collectProperty(name: string, css: string): void;
56
+ /**
57
+ * Record a @keyframes rule. Deduplicated by name.
58
+ */
59
+ collectKeyframes(name: string, css: string): void;
60
+ /**
61
+ * Allocate a keyframe name for SSR. Uses provided name or generates one.
62
+ */
63
+ allocateKeyframeName(providedName?: string): string;
64
+ /**
65
+ * Record a @font-face rule. Deduplicated by key (content hash).
66
+ */
67
+ collectFontFace(key: string, css: string): void;
68
+ /**
69
+ * Record a @counter-style rule. Deduplicated by name.
70
+ */
71
+ collectCounterStyle(name: string, css: string): void;
72
+ /**
73
+ * Allocate a counter-style name for SSR. Uses provided name or generates one.
74
+ */
75
+ allocateCounterStyleName(providedName?: string): string;
76
+ /**
77
+ * Record global styles (from useGlobalStyles). Deduplicated by key.
78
+ */
79
+ collectGlobalStyles(key: string, css: string): void;
80
+ /**
81
+ * Record raw CSS text (from useRawCSS). Deduplicated by key.
82
+ */
83
+ collectRawCSS(key: string, css: string): void;
84
+ /**
85
+ * Extract all CSS collected so far as a single string.
86
+ * Includes @property and @keyframes rules.
87
+ * Used for non-streaming SSR (renderToString).
88
+ */
89
+ getCSS(): string;
90
+ /**
91
+ * Flush only newly collected CSS since the last flush.
92
+ * Used for streaming SSR (renderToPipeableStream + useServerInsertedHTML).
93
+ */
94
+ flushCSS(): string;
95
+ /**
96
+ * Serialize the cache state for client hydration.
97
+ */
98
+ getCacheState(): SSRCacheState;
99
+ }
100
+ //#endregion
101
+ export { SSRCacheState, ServerStyleCollector };
102
+ //# sourceMappingURL=collector.d.ts.map
@@ -0,0 +1,226 @@
1
+ import { fontFaceContentHash, formatFontFaceRule } from "../font-face/index.js";
2
+ import { formatCounterStyleRule } from "../counter-style/index.js";
3
+ import { renderStyles } from "../pipeline/index.js";
4
+ import { INTERNAL_PROPERTIES, getGlobalConfigTokens, getGlobalCounterStyle, getGlobalFontFace, getGlobalProperties, hasGlobalProperties } from "../config.js";
5
+ import { formatPropertyCSS } from "./format-property.js";
6
+ import { formatGlobalRules } from "./format-global-rules.js";
7
+ import { formatRules } from "./format-rules.js";
8
+ //#region src/ssr/collector.ts
9
+ /**
10
+ * ServerStyleCollector — server-safe style collector for SSR.
11
+ *
12
+ * Accumulates CSS rules and cache metadata during server rendering.
13
+ * This is the server-side counterpart to StyleInjector: it allocates
14
+ * sequential class names (t0, t1, …), formats CSS rules into text,
15
+ * and serializes the cache state for client hydration.
16
+ *
17
+ * One instance is created per HTTP request. Concurrent requests
18
+ * each get their own collector (via AsyncLocalStorage or React context).
19
+ */
20
+ function generateClassName(counter) {
21
+ return `t${counter}`;
22
+ }
23
+ var ServerStyleCollector = class {
24
+ chunks = /* @__PURE__ */ new Map();
25
+ cacheKeyToClassName = /* @__PURE__ */ new Map();
26
+ classCounter = 0;
27
+ flushedKeys = /* @__PURE__ */ new Set();
28
+ propertyRules = /* @__PURE__ */ new Map();
29
+ flushedPropertyKeys = /* @__PURE__ */ new Set();
30
+ keyframeRules = /* @__PURE__ */ new Map();
31
+ flushedKeyframeKeys = /* @__PURE__ */ new Set();
32
+ globalStyles = /* @__PURE__ */ new Map();
33
+ flushedGlobalKeys = /* @__PURE__ */ new Set();
34
+ rawCSS = /* @__PURE__ */ new Map();
35
+ flushedRawKeys = /* @__PURE__ */ new Set();
36
+ fontFaceRules = /* @__PURE__ */ new Map();
37
+ flushedFontFaceKeys = /* @__PURE__ */ new Set();
38
+ counterStyleRules = /* @__PURE__ */ new Map();
39
+ flushedCounterStyleKeys = /* @__PURE__ */ new Set();
40
+ keyframesCounter = 0;
41
+ counterStyleCounter = 0;
42
+ internalsCollected = false;
43
+ /**
44
+ * Collect internal @property rules and :root token defaults.
45
+ * Mirrors markStylesGenerated() from the client-side injector.
46
+ * Called automatically on first chunk collection; idempotent.
47
+ */
48
+ collectInternals() {
49
+ if (this.internalsCollected) return;
50
+ this.internalsCollected = true;
51
+ for (const [token, definition] of Object.entries(INTERNAL_PROPERTIES)) {
52
+ const css = formatPropertyCSS(token, definition);
53
+ if (css) this.collectProperty(`__internal:${token}`, css);
54
+ }
55
+ if (hasGlobalProperties()) {
56
+ const globalProps = getGlobalProperties();
57
+ if (globalProps) for (const [token, definition] of Object.entries(globalProps)) {
58
+ const css = formatPropertyCSS(token, definition);
59
+ if (css) this.collectProperty(`__global:${token}`, css);
60
+ }
61
+ }
62
+ const tokenStyles = getGlobalConfigTokens();
63
+ if (tokenStyles && Object.keys(tokenStyles).length > 0) {
64
+ const tokenRules = renderStyles(tokenStyles, ":root");
65
+ if (tokenRules.length > 0) {
66
+ const css = formatGlobalRules(tokenRules);
67
+ if (css) this.collectGlobalStyles("__global:tokens", css);
68
+ }
69
+ }
70
+ const globalFF = getGlobalFontFace();
71
+ if (globalFF) for (const [family, input] of Object.entries(globalFF)) {
72
+ const descriptors = Array.isArray(input) ? input : [input];
73
+ for (const desc of descriptors) {
74
+ const hash = fontFaceContentHash(family, desc);
75
+ const css = formatFontFaceRule(family, desc);
76
+ this.collectFontFace(hash, css);
77
+ }
78
+ }
79
+ const globalCS = getGlobalCounterStyle();
80
+ if (globalCS) for (const [name, descriptors] of Object.entries(globalCS)) {
81
+ const css = formatCounterStyleRule(name, descriptors);
82
+ this.collectCounterStyle(name, css);
83
+ }
84
+ }
85
+ /**
86
+ * Allocate a className for a cache key, server-side.
87
+ * Mirrors StyleInjector.allocateClassName but without DOM access.
88
+ */
89
+ allocateClassName(cacheKey) {
90
+ const existing = this.cacheKeyToClassName.get(cacheKey);
91
+ if (existing) return {
92
+ className: existing,
93
+ isNewAllocation: false
94
+ };
95
+ const className = generateClassName(this.classCounter++);
96
+ this.cacheKeyToClassName.set(cacheKey, className);
97
+ return {
98
+ className,
99
+ isNewAllocation: true
100
+ };
101
+ }
102
+ /**
103
+ * Record CSS rules for a chunk.
104
+ * Called by useStyles during server render.
105
+ */
106
+ collectChunk(cacheKey, className, rules) {
107
+ if (this.chunks.has(cacheKey)) return;
108
+ const css = formatRules(rules, className);
109
+ if (css) this.chunks.set(cacheKey, css);
110
+ }
111
+ /**
112
+ * Record a @property rule. Deduplicated by name.
113
+ */
114
+ collectProperty(name, css) {
115
+ if (!this.propertyRules.has(name)) this.propertyRules.set(name, css);
116
+ }
117
+ /**
118
+ * Record a @keyframes rule. Deduplicated by name.
119
+ */
120
+ collectKeyframes(name, css) {
121
+ if (!this.keyframeRules.has(name)) this.keyframeRules.set(name, css);
122
+ }
123
+ /**
124
+ * Allocate a keyframe name for SSR. Uses provided name or generates one.
125
+ */
126
+ allocateKeyframeName(providedName) {
127
+ return providedName ?? `k${this.keyframesCounter++}`;
128
+ }
129
+ /**
130
+ * Record a @font-face rule. Deduplicated by key (content hash).
131
+ */
132
+ collectFontFace(key, css) {
133
+ if (!this.fontFaceRules.has(key)) this.fontFaceRules.set(key, css);
134
+ }
135
+ /**
136
+ * Record a @counter-style rule. Deduplicated by name.
137
+ */
138
+ collectCounterStyle(name, css) {
139
+ if (!this.counterStyleRules.has(name)) this.counterStyleRules.set(name, css);
140
+ }
141
+ /**
142
+ * Allocate a counter-style name for SSR. Uses provided name or generates one.
143
+ */
144
+ allocateCounterStyleName(providedName) {
145
+ return providedName ?? `cs${this.counterStyleCounter++}`;
146
+ }
147
+ /**
148
+ * Record global styles (from useGlobalStyles). Deduplicated by key.
149
+ */
150
+ collectGlobalStyles(key, css) {
151
+ if (!this.globalStyles.has(key)) this.globalStyles.set(key, css);
152
+ }
153
+ /**
154
+ * Record raw CSS text (from useRawCSS). Deduplicated by key.
155
+ */
156
+ collectRawCSS(key, css) {
157
+ if (!this.rawCSS.has(key)) this.rawCSS.set(key, css);
158
+ }
159
+ /**
160
+ * Extract all CSS collected so far as a single string.
161
+ * Includes @property and @keyframes rules.
162
+ * Used for non-streaming SSR (renderToString).
163
+ */
164
+ getCSS() {
165
+ const parts = [];
166
+ for (const css of this.propertyRules.values()) parts.push(css);
167
+ for (const css of this.fontFaceRules.values()) parts.push(css);
168
+ for (const css of this.counterStyleRules.values()) parts.push(css);
169
+ for (const css of this.rawCSS.values()) parts.push(css);
170
+ for (const css of this.globalStyles.values()) parts.push(css);
171
+ for (const css of this.chunks.values()) parts.push(css);
172
+ for (const css of this.keyframeRules.values()) parts.push(css);
173
+ return parts.join("\n");
174
+ }
175
+ /**
176
+ * Flush only newly collected CSS since the last flush.
177
+ * Used for streaming SSR (renderToPipeableStream + useServerInsertedHTML).
178
+ */
179
+ flushCSS() {
180
+ const parts = [];
181
+ for (const [name, css] of this.propertyRules) if (!this.flushedPropertyKeys.has(name)) {
182
+ parts.push(css);
183
+ this.flushedPropertyKeys.add(name);
184
+ }
185
+ for (const [key, css] of this.fontFaceRules) if (!this.flushedFontFaceKeys.has(key)) {
186
+ parts.push(css);
187
+ this.flushedFontFaceKeys.add(key);
188
+ }
189
+ for (const [key, css] of this.counterStyleRules) if (!this.flushedCounterStyleKeys.has(key)) {
190
+ parts.push(css);
191
+ this.flushedCounterStyleKeys.add(key);
192
+ }
193
+ for (const [key, css] of this.rawCSS) if (!this.flushedRawKeys.has(key)) {
194
+ parts.push(css);
195
+ this.flushedRawKeys.add(key);
196
+ }
197
+ for (const [key, css] of this.globalStyles) if (!this.flushedGlobalKeys.has(key)) {
198
+ parts.push(css);
199
+ this.flushedGlobalKeys.add(key);
200
+ }
201
+ for (const [key, css] of this.chunks) if (!this.flushedKeys.has(key)) {
202
+ parts.push(css);
203
+ this.flushedKeys.add(key);
204
+ }
205
+ for (const [name, css] of this.keyframeRules) if (!this.flushedKeyframeKeys.has(name)) {
206
+ parts.push(css);
207
+ this.flushedKeyframeKeys.add(name);
208
+ }
209
+ return parts.join("\n");
210
+ }
211
+ /**
212
+ * Serialize the cache state for client hydration.
213
+ */
214
+ getCacheState() {
215
+ const entries = {};
216
+ for (const [cacheKey, className] of this.cacheKeyToClassName) entries[cacheKey] = className;
217
+ return {
218
+ entries,
219
+ classCounter: this.classCounter
220
+ };
221
+ }
222
+ };
223
+ //#endregion
224
+ export { ServerStyleCollector };
225
+
226
+ //# sourceMappingURL=collector.js.map