@tenphi/tasty 0.0.0-snapshot.fafcbfe → 0.0.0-snapshot.fde7ec8

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 (325) hide show
  1. package/README.md +322 -160
  2. package/dist/_virtual/_rolldown/runtime.js +1 -2
  3. package/dist/chunks/cacheKey.d.ts +1 -0
  4. package/dist/chunks/cacheKey.js +17 -10
  5. package/dist/chunks/cacheKey.js.map +1 -1
  6. package/dist/chunks/definitions.d.ts +1 -1
  7. package/dist/chunks/definitions.js +3 -5
  8. package/dist/chunks/definitions.js.map +1 -1
  9. package/dist/chunks/index.d.ts +1 -0
  10. package/dist/chunks/renderChunk.d.ts +1 -0
  11. package/dist/chunks/renderChunk.js +32 -34
  12. package/dist/chunks/renderChunk.js.map +1 -1
  13. package/dist/compute-styles.d.ts +31 -0
  14. package/dist/compute-styles.js +322 -0
  15. package/dist/compute-styles.js.map +1 -0
  16. package/dist/config.d.ts +157 -30
  17. package/dist/config.js +233 -45
  18. package/dist/config.js.map +1 -1
  19. package/dist/core/index.d.ts +12 -11
  20. package/dist/core/index.js +12 -11
  21. package/dist/counter-style/index.js +51 -0
  22. package/dist/counter-style/index.js.map +1 -0
  23. package/dist/debug.d.ts +26 -141
  24. package/dist/debug.js +359 -639
  25. package/dist/debug.js.map +1 -1
  26. package/dist/font-face/index.js +63 -0
  27. package/dist/font-face/index.js.map +1 -0
  28. package/dist/hooks/index.d.ts +7 -0
  29. package/dist/hooks/useCounterStyle.d.ts +36 -0
  30. package/dist/hooks/useCounterStyle.js +65 -0
  31. package/dist/hooks/useCounterStyle.js.map +1 -0
  32. package/dist/hooks/useFontFace.d.ts +45 -0
  33. package/dist/hooks/useFontFace.js +66 -0
  34. package/dist/hooks/useFontFace.js.map +1 -0
  35. package/dist/hooks/useGlobalStyles.d.ts +21 -2
  36. package/dist/hooks/useGlobalStyles.js +60 -28
  37. package/dist/hooks/useGlobalStyles.js.map +1 -1
  38. package/dist/hooks/useKeyframes.d.ts +4 -2
  39. package/dist/hooks/useKeyframes.js +44 -43
  40. package/dist/hooks/useKeyframes.js.map +1 -1
  41. package/dist/hooks/useProperty.d.ts +4 -2
  42. package/dist/hooks/useProperty.js +36 -31
  43. package/dist/hooks/useProperty.js.map +1 -1
  44. package/dist/hooks/useRawCSS.d.ts +13 -44
  45. package/dist/hooks/useRawCSS.js +91 -16
  46. package/dist/hooks/useRawCSS.js.map +1 -1
  47. package/dist/hooks/useStyles.d.ts +3 -3
  48. package/dist/hooks/useStyles.js +8 -146
  49. package/dist/hooks/useStyles.js.map +1 -1
  50. package/dist/index.d.ts +23 -12
  51. package/dist/index.js +15 -12
  52. package/dist/injector/index.d.ts +36 -11
  53. package/dist/injector/index.js +43 -12
  54. package/dist/injector/index.js.map +1 -1
  55. package/dist/injector/injector.d.ts +62 -3
  56. package/dist/injector/injector.js +293 -46
  57. package/dist/injector/injector.js.map +1 -1
  58. package/dist/injector/sheet-manager.d.ts +22 -17
  59. package/dist/injector/sheet-manager.js +64 -79
  60. package/dist/injector/sheet-manager.js.map +1 -1
  61. package/dist/injector/types.d.ts +121 -21
  62. package/dist/keyframes/index.js +1 -1
  63. package/dist/parser/classify.js +6 -6
  64. package/dist/parser/classify.js.map +1 -1
  65. package/dist/parser/const.js +30 -3
  66. package/dist/parser/const.js.map +1 -1
  67. package/dist/parser/lru.js +1 -1
  68. package/dist/parser/lru.js.map +1 -1
  69. package/dist/parser/parser.js +2 -3
  70. package/dist/parser/parser.js.map +1 -1
  71. package/dist/parser/tokenizer.js +1 -1
  72. package/dist/parser/tokenizer.js.map +1 -1
  73. package/dist/parser/types.js +1 -1
  74. package/dist/parser/types.js.map +1 -1
  75. package/dist/pipeline/conditions.js +15 -9
  76. package/dist/pipeline/conditions.js.map +1 -1
  77. package/dist/pipeline/exclusive.js +58 -4
  78. package/dist/pipeline/exclusive.js.map +1 -1
  79. package/dist/pipeline/index.d.ts +3 -1
  80. package/dist/pipeline/index.js +141 -74
  81. package/dist/pipeline/index.js.map +1 -1
  82. package/dist/pipeline/materialize.js +460 -211
  83. package/dist/pipeline/materialize.js.map +1 -1
  84. package/dist/pipeline/parseStateKey.d.ts +1 -1
  85. package/dist/pipeline/parseStateKey.js +38 -22
  86. package/dist/pipeline/parseStateKey.js.map +1 -1
  87. package/dist/pipeline/simplify.js +289 -156
  88. package/dist/pipeline/simplify.js.map +1 -1
  89. package/dist/pipeline/warnings.js +18 -0
  90. package/dist/pipeline/warnings.js.map +1 -0
  91. package/dist/plugins/index.d.ts +2 -0
  92. package/dist/plugins/okhsl-plugin.js +3 -277
  93. package/dist/plugins/okhsl-plugin.js.map +1 -1
  94. package/dist/plugins/types.d.ts +20 -2
  95. package/dist/properties/index.js +83 -19
  96. package/dist/properties/index.js.map +1 -1
  97. package/dist/properties/property-type-resolver.d.ts +24 -0
  98. package/dist/properties/property-type-resolver.js +90 -0
  99. package/dist/properties/property-type-resolver.js.map +1 -0
  100. package/dist/rsc-cache.js +79 -0
  101. package/dist/rsc-cache.js.map +1 -0
  102. package/dist/ssr/astro-client.d.ts +1 -0
  103. package/dist/ssr/astro-client.js +19 -0
  104. package/dist/ssr/astro-client.js.map +1 -0
  105. package/dist/ssr/astro-middleware.d.ts +15 -0
  106. package/dist/ssr/astro-middleware.js +19 -0
  107. package/dist/ssr/astro-middleware.js.map +1 -0
  108. package/dist/ssr/astro.d.ts +108 -0
  109. package/dist/ssr/astro.js +149 -0
  110. package/dist/ssr/astro.js.map +1 -0
  111. package/dist/ssr/async-storage.d.ts +17 -0
  112. package/dist/ssr/async-storage.js +44 -0
  113. package/dist/ssr/async-storage.js.map +1 -0
  114. package/dist/ssr/collect-auto-properties.js +58 -0
  115. package/dist/ssr/collect-auto-properties.js.map +1 -0
  116. package/dist/ssr/collector.d.ts +98 -0
  117. package/dist/ssr/collector.js +235 -0
  118. package/dist/ssr/collector.js.map +1 -0
  119. package/dist/ssr/context.js +16 -0
  120. package/dist/ssr/context.js.map +1 -0
  121. package/dist/ssr/format-global-rules.js +22 -0
  122. package/dist/ssr/format-global-rules.js.map +1 -0
  123. package/dist/ssr/format-keyframes.js +69 -0
  124. package/dist/ssr/format-keyframes.js.map +1 -0
  125. package/dist/ssr/format-property.js +49 -0
  126. package/dist/ssr/format-property.js.map +1 -0
  127. package/dist/ssr/format-rules.js +73 -0
  128. package/dist/ssr/format-rules.js.map +1 -0
  129. package/dist/ssr/hydrate.d.ts +29 -0
  130. package/dist/ssr/hydrate.js +45 -0
  131. package/dist/ssr/hydrate.js.map +1 -0
  132. package/dist/ssr/index.d.ts +4 -0
  133. package/dist/ssr/index.js +10 -0
  134. package/dist/ssr/index.js.map +1 -0
  135. package/dist/ssr/next.d.ts +46 -0
  136. package/dist/ssr/next.js +75 -0
  137. package/dist/ssr/next.js.map +1 -0
  138. package/dist/ssr/ssr-collector-ref.js +29 -0
  139. package/dist/ssr/ssr-collector-ref.js.map +1 -0
  140. package/dist/states/index.js +13 -259
  141. package/dist/states/index.js.map +1 -1
  142. package/dist/static/index.js +1 -2
  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.js +1 -2
  147. package/dist/static/tastyStatic.js.map +1 -1
  148. package/dist/static/types.js +1 -1
  149. package/dist/styles/border.d.ts +2 -2
  150. package/dist/styles/border.js +30 -24
  151. package/dist/styles/border.js.map +1 -1
  152. package/dist/styles/color.d.ts +3 -3
  153. package/dist/styles/color.js +11 -8
  154. package/dist/styles/color.js.map +1 -1
  155. package/dist/styles/const.js +17 -0
  156. package/dist/styles/const.js.map +1 -0
  157. package/dist/styles/createStyle.js +29 -27
  158. package/dist/styles/createStyle.js.map +1 -1
  159. package/dist/styles/dimension.js +15 -3
  160. package/dist/styles/dimension.js.map +1 -1
  161. package/dist/styles/directional.js +133 -0
  162. package/dist/styles/directional.js.map +1 -0
  163. package/dist/styles/display.d.ts +3 -10
  164. package/dist/styles/display.js +45 -39
  165. package/dist/styles/display.js.map +1 -1
  166. package/dist/styles/fade.d.ts +2 -2
  167. package/dist/styles/fade.js +9 -5
  168. package/dist/styles/fade.js.map +1 -1
  169. package/dist/styles/fill.d.ts +15 -17
  170. package/dist/styles/fill.js +9 -9
  171. package/dist/styles/fill.js.map +1 -1
  172. package/dist/styles/flow.d.ts +3 -3
  173. package/dist/styles/flow.js +1 -1
  174. package/dist/styles/flow.js.map +1 -1
  175. package/dist/styles/gap.d.ts +1 -1
  176. package/dist/styles/gap.js +4 -3
  177. package/dist/styles/gap.js.map +1 -1
  178. package/dist/styles/height.d.ts +1 -1
  179. package/dist/styles/height.js +1 -2
  180. package/dist/styles/height.js.map +1 -1
  181. package/dist/styles/index.d.ts +0 -1
  182. package/dist/styles/index.js +3 -4
  183. package/dist/styles/index.js.map +1 -1
  184. package/dist/styles/inset.d.ts +1 -29
  185. package/dist/styles/inset.js +19 -135
  186. package/dist/styles/inset.js.map +1 -1
  187. package/dist/styles/list.d.ts +5 -5
  188. package/dist/styles/list.js +4 -2
  189. package/dist/styles/list.js.map +1 -1
  190. package/dist/styles/margin.d.ts +1 -1
  191. package/dist/styles/margin.js +17 -89
  192. package/dist/styles/margin.js.map +1 -1
  193. package/dist/styles/outline.d.ts +1 -1
  194. package/dist/styles/outline.js +6 -16
  195. package/dist/styles/outline.js.map +1 -1
  196. package/dist/styles/padding.d.ts +1 -1
  197. package/dist/styles/padding.js +17 -89
  198. package/dist/styles/padding.js.map +1 -1
  199. package/dist/styles/placement.d.ts +37 -0
  200. package/dist/styles/placement.js +74 -0
  201. package/dist/styles/placement.js.map +1 -0
  202. package/dist/styles/predefined.d.ts +4 -6
  203. package/dist/styles/predefined.js +9 -13
  204. package/dist/styles/predefined.js.map +1 -1
  205. package/dist/styles/preset.d.ts +6 -1
  206. package/dist/styles/preset.js +54 -53
  207. package/dist/styles/preset.js.map +1 -1
  208. package/dist/styles/radius.d.ts +2 -4
  209. package/dist/styles/radius.js +38 -6
  210. package/dist/styles/radius.js.map +1 -1
  211. package/dist/styles/scrollMargin.d.ts +24 -0
  212. package/dist/styles/scrollMargin.js +32 -0
  213. package/dist/styles/scrollMargin.js.map +1 -0
  214. package/dist/styles/scrollbar.d.ts +9 -5
  215. package/dist/styles/scrollbar.js +31 -85
  216. package/dist/styles/scrollbar.js.map +1 -1
  217. package/dist/styles/shadow.d.ts +3 -3
  218. package/dist/styles/shadow.js +4 -3
  219. package/dist/styles/shadow.js.map +1 -1
  220. package/dist/styles/shared.js +17 -0
  221. package/dist/styles/shared.js.map +1 -0
  222. package/dist/styles/transition.d.ts +2 -2
  223. package/dist/styles/transition.js +6 -5
  224. package/dist/styles/transition.js.map +1 -1
  225. package/dist/styles/types.d.ts +94 -28
  226. package/dist/styles/width.d.ts +1 -1
  227. package/dist/styles/width.js +1 -2
  228. package/dist/styles/width.js.map +1 -1
  229. package/dist/tasty.d.ts +46 -894
  230. package/dist/tasty.js +117 -60
  231. package/dist/tasty.js.map +1 -1
  232. package/dist/types.d.ts +3 -3
  233. package/dist/utils/cache-wrapper.js +4 -9
  234. package/dist/utils/cache-wrapper.js.map +1 -1
  235. package/dist/utils/case-converter.js +1 -1
  236. package/dist/utils/color-math.d.ts +46 -0
  237. package/dist/utils/color-math.js +749 -0
  238. package/dist/utils/color-math.js.map +1 -0
  239. package/dist/utils/color-space.d.ts +5 -0
  240. package/dist/utils/color-space.js +228 -0
  241. package/dist/utils/color-space.js.map +1 -0
  242. package/dist/utils/colors.d.ts +1 -1
  243. package/dist/utils/colors.js +3 -2
  244. package/dist/utils/colors.js.map +1 -1
  245. package/dist/utils/css-types.d.ts +1 -1
  246. package/dist/utils/deps-equal.js +15 -0
  247. package/dist/utils/deps-equal.js.map +1 -0
  248. package/dist/utils/dotize.d.ts +1 -1
  249. package/dist/utils/dotize.js +1 -1
  250. package/dist/utils/dotize.js.map +1 -1
  251. package/dist/utils/filter-base-props.d.ts +1 -1
  252. package/dist/utils/filter-base-props.js +1 -1
  253. package/dist/utils/filter-base-props.js.map +1 -1
  254. package/dist/utils/get-display-name.js +1 -1
  255. package/dist/utils/has-keys.js +13 -0
  256. package/dist/utils/has-keys.js.map +1 -0
  257. package/dist/utils/hash.js +14 -0
  258. package/dist/utils/hash.js.map +1 -0
  259. package/dist/utils/is-dev-env.js +1 -1
  260. package/dist/utils/is-dev-env.js.map +1 -1
  261. package/dist/utils/is-valid-element-type.js +1 -1
  262. package/dist/utils/merge-styles.js +1 -2
  263. package/dist/utils/merge-styles.js.map +1 -1
  264. package/dist/utils/mod-attrs.d.ts +0 -2
  265. package/dist/utils/mod-attrs.js +3 -4
  266. package/dist/utils/mod-attrs.js.map +1 -1
  267. package/dist/utils/process-tokens.d.ts +3 -17
  268. package/dist/utils/process-tokens.js +19 -107
  269. package/dist/utils/process-tokens.js.map +1 -1
  270. package/dist/utils/resolve-recipes.js +1 -2
  271. package/dist/utils/resolve-recipes.js.map +1 -1
  272. package/dist/utils/selector-transform.js +32 -0
  273. package/dist/utils/selector-transform.js.map +1 -0
  274. package/dist/utils/string.js +1 -1
  275. package/dist/utils/string.js.map +1 -1
  276. package/dist/utils/styles.d.ts +5 -89
  277. package/dist/utils/styles.js +35 -400
  278. package/dist/utils/styles.js.map +1 -1
  279. package/dist/utils/typography.d.ts +35 -13
  280. package/dist/utils/typography.js +16 -18
  281. package/dist/utils/typography.js.map +1 -1
  282. package/dist/utils/warnings.js +1 -1
  283. package/dist/zero/babel.d.ts +57 -84
  284. package/dist/zero/babel.js +217 -37
  285. package/dist/zero/babel.js.map +1 -1
  286. package/dist/zero/css-writer.js +1 -2
  287. package/dist/zero/css-writer.js.map +1 -1
  288. package/dist/zero/extractor.js +119 -3
  289. package/dist/zero/extractor.js.map +1 -1
  290. package/dist/zero/index.js +1 -2
  291. package/dist/zero/next.d.ts +56 -30
  292. package/dist/zero/next.js +105 -40
  293. package/dist/zero/next.js.map +1 -1
  294. package/docs/PIPELINE.md +519 -0
  295. package/docs/README.md +31 -0
  296. package/docs/adoption.md +298 -0
  297. package/docs/comparison.md +419 -0
  298. package/docs/configuration.md +394 -0
  299. package/docs/debug.md +318 -0
  300. package/docs/design-system.md +436 -0
  301. package/docs/dsl.md +688 -0
  302. package/docs/getting-started.md +217 -0
  303. package/docs/injector.md +544 -0
  304. package/docs/methodology.md +616 -0
  305. package/docs/react-api.md +557 -0
  306. package/docs/ssr.md +442 -0
  307. package/docs/styles.md +596 -0
  308. package/docs/tasty-static.md +532 -0
  309. package/package.json +112 -31
  310. package/dist/styles/align.d.ts +0 -15
  311. package/dist/styles/align.js +0 -14
  312. package/dist/styles/align.js.map +0 -1
  313. package/dist/styles/justify.d.ts +0 -15
  314. package/dist/styles/justify.js +0 -14
  315. package/dist/styles/justify.js.map +0 -1
  316. package/dist/styles/styledScrollbar.d.ts +0 -47
  317. package/dist/styles/styledScrollbar.js +0 -38
  318. package/dist/styles/styledScrollbar.js.map +0 -1
  319. package/dist/tokens/typography.d.ts +0 -19
  320. package/dist/tokens/typography.js +0 -237
  321. package/dist/tokens/typography.js.map +0 -1
  322. package/dist/utils/hsl-to-rgb.js +0 -38
  323. package/dist/utils/hsl-to-rgb.js.map +0 -1
  324. package/dist/utils/okhsl-to-rgb.js +0 -296
  325. package/dist/utils/okhsl-to-rgb.js.map +0 -1
@@ -1,6 +1,7 @@
1
1
  import { StyleDetails, UnitHandler } from "../parser/types.js";
2
2
  import { StyleHandlerDefinition } from "../utils/styles.js";
3
- import { RecipeStyles } from "../styles/types.js";
3
+ import { ConfigTokens, RecipeStyles, Styles } from "../styles/types.js";
4
+ import { TypographyPreset } from "../utils/typography.js";
4
5
 
5
6
  //#region src/plugins/types.d.ts
6
7
  /**
@@ -29,8 +30,15 @@ interface TastyPlugin {
29
30
  * ```
30
31
  */
31
32
  handlers?: Record<string, StyleHandlerDefinition>;
33
+ /**
34
+ * Design tokens injected as CSS custom properties on `:root`.
35
+ * Values are parsed through the Tasty DSL. Supports state maps.
36
+ * - `$name` → `--name` CSS custom property
37
+ * - `#name` → `--name-color` and `--name-color-{colorSpace}`
38
+ */
39
+ tokens?: ConfigTokens;
32
40
  /** Predefined tokens replaced during style parsing (`$name` or `#name`) */
33
- tokens?: Record<`$${string}` | `#${string}`, string | number>;
41
+ replaceTokens?: Record<`$${string}` | `#${string}`, string | number>;
34
42
  /**
35
43
  * Predefined style recipes -- named style bundles that can be applied via `recipe` style property.
36
44
  * Recipe values are flat tasty styles (no sub-element keys).
@@ -43,6 +51,16 @@ interface TastyPlugin {
43
51
  * ```
44
52
  */
45
53
  recipes?: Record<string, RecipeStyles>;
54
+ /**
55
+ * Typography presets — shorthand for `generateTypographyTokens()`.
56
+ * Generated tokens are merged under explicit `tokens` (tokens win on conflict).
57
+ */
58
+ presets?: Record<string, TypographyPreset>;
59
+ /**
60
+ * Global Tasty styles keyed by CSS selector.
61
+ * Supports the full Tasty style syntax.
62
+ */
63
+ globalStyles?: Record<string, Styles>;
46
64
  }
47
65
  /**
48
66
  * A factory function that creates a TastyPlugin.
@@ -1,5 +1,5 @@
1
- import { getRgbValuesFromRgbaString, strToRgb } from "../utils/styles.js";
2
-
1
+ import { RE_NUMBER, RE_RAW_UNIT } from "../parser/const.js";
2
+ import "../utils/color-space.js";
3
3
  //#region src/properties/index.ts
4
4
  const PROPERTIES_KEY = "@properties";
5
5
  /**
@@ -88,7 +88,11 @@ function parsePropertyToken(token) {
88
88
  }
89
89
  /**
90
90
  * Normalize a property definition to a consistent string representation.
91
- * Used for comparing definitions to detect changes/conflicts.
91
+ * Used for comparing definitions to detect type conflicts.
92
+ *
93
+ * Only `syntax` and `inherits` are compared — `initialValue` is intentionally
94
+ * excluded because different components may set different defaults for the
95
+ * same typed property (e.g. auto-inferred `0px` vs explicit `6px`).
92
96
  *
93
97
  * Keys are sorted alphabetically to ensure consistent comparison:
94
98
  * { inherits: true, syntax: '<color>' } === { syntax: '<color>', inherits: true }
@@ -96,7 +100,6 @@ function parsePropertyToken(token) {
96
100
  function normalizePropertyDefinition(def) {
97
101
  const normalized = {};
98
102
  if (def.inherits !== void 0) normalized.inherits = def.inherits;
99
- if (def.initialValue !== void 0) normalized.initialValue = String(def.initialValue);
100
103
  if (def.syntax !== void 0) normalized.syntax = def.syntax;
101
104
  return JSON.stringify(normalized);
102
105
  }
@@ -134,25 +137,86 @@ function getEffectiveDefinition(token, userDefinition) {
134
137
  isValid: true
135
138
  };
136
139
  }
140
+ const UNIT_TO_SYNTAX = {};
141
+ const LENGTH_UNITS = [
142
+ "px",
143
+ "em",
144
+ "rem",
145
+ "vw",
146
+ "vh",
147
+ "vmin",
148
+ "vmax",
149
+ "ch",
150
+ "ex",
151
+ "cap",
152
+ "ic",
153
+ "lh",
154
+ "rlh",
155
+ "svw",
156
+ "svh",
157
+ "lvw",
158
+ "lvh",
159
+ "dvw",
160
+ "dvh",
161
+ "cqw",
162
+ "cqh",
163
+ "cqi",
164
+ "cqb",
165
+ "cqmin",
166
+ "cqmax"
167
+ ];
168
+ const ANGLE_UNITS = [
169
+ "deg",
170
+ "rad",
171
+ "grad",
172
+ "turn"
173
+ ];
174
+ const TIME_UNITS = ["ms", "s"];
175
+ for (const u of LENGTH_UNITS) UNIT_TO_SYNTAX[u] = {
176
+ syntax: "<length-percentage>",
177
+ initialValue: "0px"
178
+ };
179
+ UNIT_TO_SYNTAX["%"] = {
180
+ syntax: "<length-percentage>",
181
+ initialValue: "0px"
182
+ };
183
+ for (const u of ANGLE_UNITS) UNIT_TO_SYNTAX[u] = {
184
+ syntax: "<angle>",
185
+ initialValue: "0deg"
186
+ };
187
+ for (const u of TIME_UNITS) UNIT_TO_SYNTAX[u] = {
188
+ syntax: "<time>",
189
+ initialValue: "0s"
190
+ };
137
191
  /**
138
- * Extract RGB triplet string from a color initial value.
139
- * Used when auto-creating the companion `-rgb` property for color @property definitions.
192
+ * Infer CSS @property syntax from a concrete value.
193
+ * Detects numeric types: \<number\>, \<length-percentage\>, \<angle\>, \<time\>.
194
+ * Length and percentage values both map to \<length-percentage\> for maximum flexibility.
195
+ * Color properties are handled separately via the #name token convention
196
+ * (--name-color gets \<color\> syntax automatically in getEffectiveDefinition).
140
197
  *
141
- * @param initialValue - The color property's initial value (e.g., 'rgb(255 255 255)', 'transparent', '#fff')
142
- * @returns Space-separated RGB triplet (e.g., '255 255 255'), defaults to '0 0 0'
198
+ * @param value - The CSS value to infer from (e.g. '10px', '1', '45deg')
199
+ * @returns Inferred syntax and initial value, or null if not inferable
143
200
  */
144
- function colorInitialValueToRgb(initialValue) {
145
- if (initialValue == null) return "0 0 0";
146
- const str = String(initialValue).trim();
147
- if (!str || str === "transparent") return "0 0 0";
148
- const rgba = strToRgb(str);
149
- if (rgba) {
150
- const values = getRgbValuesFromRgbaString(rgba);
151
- if (values.length >= 3) return values.slice(0, 3).join(" ");
201
+ function inferSyntaxFromValue(value) {
202
+ if (!value || typeof value !== "string") return null;
203
+ const trimmed = value.trim();
204
+ if (!trimmed) return null;
205
+ if (RE_NUMBER.test(trimmed)) {
206
+ if (parseFloat(trimmed) === 0) return null;
207
+ return {
208
+ syntax: "<number>",
209
+ initialValue: "0"
210
+ };
211
+ }
212
+ const unitMatch = trimmed.match(RE_RAW_UNIT);
213
+ if (unitMatch) {
214
+ const mapping = UNIT_TO_SYNTAX[unitMatch[2]];
215
+ if (mapping) return mapping;
152
216
  }
153
- return "0 0 0";
217
+ return null;
154
218
  }
155
-
156
219
  //#endregion
157
- export { colorInitialValueToRgb, extractLocalProperties, getEffectiveDefinition, hasLocalProperties, normalizePropertyDefinition };
220
+ export { extractLocalProperties, getEffectiveDefinition, hasLocalProperties, inferSyntaxFromValue, normalizePropertyDefinition, parsePropertyToken };
221
+
158
222
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/properties/index.ts"],"sourcesContent":["/**\n * Properties Utilities\n *\n * Utilities for extracting and processing CSS @property definitions in styles.\n * Unlike keyframes, properties are permanent once registered and don't need cleanup.\n *\n * Property names use tasty token syntax:\n * - `$name` for regular properties → `--name`\n * - `#name` for color properties → `--name-color` (auto-sets syntax: '<color>')\n */\n\nimport type { PropertyDefinition } from '../injector/types';\nimport type { Styles } from '../styles/types';\nimport { getRgbValuesFromRgbaString, strToRgb } from '../utils/styles';\n\n// ============================================================================\n// Constants\n// ============================================================================\n\nconst PROPERTIES_KEY = '@properties';\n\n/**\n * Valid CSS custom property name pattern (after the -- prefix).\n * Must start with a letter or underscore, followed by letters, digits, hyphens, or underscores.\n */\nconst VALID_PROPERTY_NAME_PATTERN = /^[a-z_][a-z0-9-_]*$/i;\n\n// ============================================================================\n// Validation Functions\n// ============================================================================\n\n/**\n * Validate a CSS custom property name (the part after --).\n * Returns true if the name is valid for use as a CSS custom property.\n */\nexport function isValidPropertyName(name: string): boolean {\n return VALID_PROPERTY_NAME_PATTERN.test(name);\n}\n\n/**\n * Result of parsing a property token.\n */\nexport interface ParsedPropertyToken {\n /** The CSS custom property name (e.g., '--my-prop') */\n cssName: string;\n /** Whether this is a color property */\n isColor: boolean;\n /** Whether the token was valid */\n isValid: boolean;\n /** Error message if invalid */\n error?: string;\n}\n\n// ============================================================================\n// Extraction Functions\n// ============================================================================\n\n/**\n * Check if styles object has local @properties definition.\n * Fast path: single property lookup.\n */\nexport function hasLocalProperties(styles: Styles): boolean {\n return PROPERTIES_KEY in styles;\n}\n\n/**\n * Extract local @properties from styles object.\n * Returns null if no local properties (fast path).\n */\nexport function extractLocalProperties(\n styles: Styles,\n): Record<string, PropertyDefinition> | null {\n const properties = styles[PROPERTIES_KEY];\n if (!properties || typeof properties !== 'object') {\n return null;\n }\n return properties as Record<string, PropertyDefinition>;\n}\n\n// ============================================================================\n// Token Parsing Functions\n// ============================================================================\n\n/**\n * Parse a property token name and return the CSS property name and whether it's a color.\n * Supports tasty token syntax and validates the property name.\n *\n * Token formats:\n * - `$name` → { cssName: '--name', isColor: false }\n * - `#name` → { cssName: '--name-color', isColor: true }\n * - `--name` → { cssName: '--name', isColor: false } (legacy, auto-detect color by suffix)\n * - `name` → { cssName: '--name', isColor: false } (legacy)\n *\n * @param token - The property token to parse\n * @returns Parsed result with cssName, isColor, isValid, and optional error\n */\nexport function parsePropertyToken(token: string): ParsedPropertyToken {\n if (!token || typeof token !== 'string') {\n return {\n cssName: '',\n isColor: false,\n isValid: false,\n error: 'Property token must be a non-empty string',\n };\n }\n\n let name: string;\n let isColor: boolean;\n\n if (token.startsWith('$')) {\n // Regular property token: $name → --name\n name = token.slice(1);\n isColor = false;\n } else if (token.startsWith('#')) {\n // Color property token: #name → --name-color\n name = token.slice(1);\n isColor = true;\n } else if (token.startsWith('--')) {\n // Legacy format with -- prefix\n name = token.slice(2);\n isColor = token.endsWith('-color');\n } else {\n // Legacy format without prefix\n name = token;\n isColor = token.endsWith('-color');\n }\n\n // Validate the name\n if (!name) {\n return {\n cssName: '',\n isColor,\n isValid: false,\n error: 'Property name cannot be empty',\n };\n }\n\n if (!isValidPropertyName(name)) {\n return {\n cssName: '',\n isColor,\n isValid: false,\n error: `Invalid property name \"${name}\". Must start with a letter or underscore, followed by letters, digits, hyphens, or underscores.`,\n };\n }\n\n // Build the CSS custom property name\n // For #name tokens, we add -color suffix\n // For legacy formats (--name-color or name-color), the name already includes -color\n let cssName: string;\n if (token.startsWith('#')) {\n // Color token: #name → --name-color\n cssName = `--${name}-color`;\n } else {\n // All other formats: just add -- prefix\n cssName = `--${name}`;\n }\n\n return {\n cssName,\n isColor,\n isValid: true,\n };\n}\n\n// ============================================================================\n// Normalization Functions\n// ============================================================================\n\n/**\n * Normalize a property name to the CSS custom property format.\n *\n * @deprecated Use parsePropertyToken instead for proper token handling\n */\nexport function normalizePropertyName(name: string): string {\n const result = parsePropertyToken(name);\n return result.isValid ? result.cssName : `--${name}`;\n}\n\n/**\n * Normalize a property definition to a consistent string representation.\n * Used for comparing definitions to detect changes/conflicts.\n *\n * Keys are sorted alphabetically to ensure consistent comparison:\n * { inherits: true, syntax: '<color>' } === { syntax: '<color>', inherits: true }\n */\nexport function normalizePropertyDefinition(def: PropertyDefinition): string {\n const normalized: Record<string, unknown> = {};\n\n // Add properties in alphabetical order\n if (def.inherits !== undefined) {\n normalized.inherits = def.inherits;\n }\n if (def.initialValue !== undefined) {\n normalized.initialValue = String(def.initialValue);\n }\n if (def.syntax !== undefined) {\n normalized.syntax = def.syntax;\n }\n\n return JSON.stringify(normalized);\n}\n\n/**\n * Result of getEffectiveDefinition.\n */\nexport interface EffectiveDefinitionResult {\n /** The CSS custom property name */\n cssName: string;\n /** The effective property definition */\n definition: PropertyDefinition;\n /** Whether this is a color property */\n isColor: boolean;\n /** Whether the token was valid */\n isValid: boolean;\n /** Error message if invalid */\n error?: string;\n}\n\n/**\n * Get the effective property definition for a token.\n * For color tokens (#name), auto-sets syntax to '<color>' and defaults initialValue to 'transparent'.\n *\n * @param token - Property token ($name, #name, --name, or plain name)\n * @param userDefinition - User-provided definition options\n * @returns Effective definition with cssName, definition, isValid, and optional error\n */\nexport function getEffectiveDefinition(\n token: string,\n userDefinition: PropertyDefinition,\n): EffectiveDefinitionResult {\n const parsed = parsePropertyToken(token);\n\n if (!parsed.isValid) {\n return {\n cssName: '',\n definition: userDefinition,\n isColor: false,\n isValid: false,\n error: parsed.error,\n };\n }\n\n if (parsed.isColor) {\n // Color properties have fixed syntax and default initialValue\n return {\n cssName: parsed.cssName,\n definition: {\n syntax: '<color>', // Always '<color>' for color tokens, cannot be overridden\n inherits: userDefinition.inherits, // Allow inherits to be customized\n initialValue: userDefinition.initialValue ?? 'transparent', // Default to transparent\n },\n isColor: true,\n isValid: true,\n };\n }\n\n // Regular properties use the definition as-is\n return {\n cssName: parsed.cssName,\n definition: userDefinition,\n isColor: false,\n isValid: true,\n };\n}\n\n// ============================================================================\n// Color RGB Companion Helpers\n// ============================================================================\n\n/**\n * Extract RGB triplet string from a color initial value.\n * Used when auto-creating the companion `-rgb` property for color @property definitions.\n *\n * @param initialValue - The color property's initial value (e.g., 'rgb(255 255 255)', 'transparent', '#fff')\n * @returns Space-separated RGB triplet (e.g., '255 255 255'), defaults to '0 0 0'\n */\nexport function colorInitialValueToRgb(initialValue?: string | number): string {\n if (initialValue == null) return '0 0 0';\n\n const str = String(initialValue).trim();\n if (!str || str === 'transparent') return '0 0 0';\n\n const rgba = strToRgb(str);\n if (rgba) {\n const values = getRgbValuesFromRgbaString(rgba);\n if (values.length >= 3) return values.slice(0, 3).join(' ');\n }\n\n return '0 0 0';\n}\n"],"mappings":";;;AAmBA,MAAM,iBAAiB;;;;;AAMvB,MAAM,8BAA8B;;;;;AAUpC,SAAgB,oBAAoB,MAAuB;AACzD,QAAO,4BAA4B,KAAK,KAAK;;;;;;AAyB/C,SAAgB,mBAAmB,QAAyB;AAC1D,QAAO,kBAAkB;;;;;;AAO3B,SAAgB,uBACd,QAC2C;CAC3C,MAAM,aAAa,OAAO;AAC1B,KAAI,CAAC,cAAc,OAAO,eAAe,SACvC,QAAO;AAET,QAAO;;;;;;;;;;;;;;;AAoBT,SAAgB,mBAAmB,OAAoC;AACrE,KAAI,CAAC,SAAS,OAAO,UAAU,SAC7B,QAAO;EACL,SAAS;EACT,SAAS;EACT,SAAS;EACT,OAAO;EACR;CAGH,IAAI;CACJ,IAAI;AAEJ,KAAI,MAAM,WAAW,IAAI,EAAE;AAEzB,SAAO,MAAM,MAAM,EAAE;AACrB,YAAU;YACD,MAAM,WAAW,IAAI,EAAE;AAEhC,SAAO,MAAM,MAAM,EAAE;AACrB,YAAU;YACD,MAAM,WAAW,KAAK,EAAE;AAEjC,SAAO,MAAM,MAAM,EAAE;AACrB,YAAU,MAAM,SAAS,SAAS;QAC7B;AAEL,SAAO;AACP,YAAU,MAAM,SAAS,SAAS;;AAIpC,KAAI,CAAC,KACH,QAAO;EACL,SAAS;EACT;EACA,SAAS;EACT,OAAO;EACR;AAGH,KAAI,CAAC,oBAAoB,KAAK,CAC5B,QAAO;EACL,SAAS;EACT;EACA,SAAS;EACT,OAAO,0BAA0B,KAAK;EACvC;CAMH,IAAI;AACJ,KAAI,MAAM,WAAW,IAAI,CAEvB,WAAU,KAAK,KAAK;KAGpB,WAAU,KAAK;AAGjB,QAAO;EACL;EACA;EACA,SAAS;EACV;;;;;;;;;AAwBH,SAAgB,4BAA4B,KAAiC;CAC3E,MAAM,aAAsC,EAAE;AAG9C,KAAI,IAAI,aAAa,OACnB,YAAW,WAAW,IAAI;AAE5B,KAAI,IAAI,iBAAiB,OACvB,YAAW,eAAe,OAAO,IAAI,aAAa;AAEpD,KAAI,IAAI,WAAW,OACjB,YAAW,SAAS,IAAI;AAG1B,QAAO,KAAK,UAAU,WAAW;;;;;;;;;;AA2BnC,SAAgB,uBACd,OACA,gBAC2B;CAC3B,MAAM,SAAS,mBAAmB,MAAM;AAExC,KAAI,CAAC,OAAO,QACV,QAAO;EACL,SAAS;EACT,YAAY;EACZ,SAAS;EACT,SAAS;EACT,OAAO,OAAO;EACf;AAGH,KAAI,OAAO,QAET,QAAO;EACL,SAAS,OAAO;EAChB,YAAY;GACV,QAAQ;GACR,UAAU,eAAe;GACzB,cAAc,eAAe,gBAAgB;GAC9C;EACD,SAAS;EACT,SAAS;EACV;AAIH,QAAO;EACL,SAAS,OAAO;EAChB,YAAY;EACZ,SAAS;EACT,SAAS;EACV;;;;;;;;;AAcH,SAAgB,uBAAuB,cAAwC;AAC7E,KAAI,gBAAgB,KAAM,QAAO;CAEjC,MAAM,MAAM,OAAO,aAAa,CAAC,MAAM;AACvC,KAAI,CAAC,OAAO,QAAQ,cAAe,QAAO;CAE1C,MAAM,OAAO,SAAS,IAAI;AAC1B,KAAI,MAAM;EACR,MAAM,SAAS,2BAA2B,KAAK;AAC/C,MAAI,OAAO,UAAU,EAAG,QAAO,OAAO,MAAM,GAAG,EAAE,CAAC,KAAK,IAAI;;AAG7D,QAAO"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/properties/index.ts"],"sourcesContent":["/**\n * Properties Utilities\n *\n * Utilities for extracting and processing CSS @property definitions in styles.\n * Unlike keyframes, properties are permanent once registered and don't need cleanup.\n *\n * Property names use tasty token syntax:\n * - `$name` for regular properties → `--name`\n * - `#name` for color properties → `--name-color` (auto-sets syntax: '<color>')\n */\n\nimport type { PropertyDefinition } from '../injector/types';\nimport { RE_NUMBER, RE_RAW_UNIT } from '../parser/const';\nimport type { Styles } from '../styles/types';\n\n// ============================================================================\n// Constants\n// ============================================================================\n\nconst PROPERTIES_KEY = '@properties';\n\n/**\n * Valid CSS custom property name pattern (after the -- prefix).\n * Must start with a letter or underscore, followed by letters, digits, hyphens, or underscores.\n */\nconst VALID_PROPERTY_NAME_PATTERN = /^[a-z_][a-z0-9-_]*$/i;\n\n// ============================================================================\n// Validation Functions\n// ============================================================================\n\n/**\n * Validate a CSS custom property name (the part after --).\n * Returns true if the name is valid for use as a CSS custom property.\n */\nexport function isValidPropertyName(name: string): boolean {\n return VALID_PROPERTY_NAME_PATTERN.test(name);\n}\n\n/**\n * Result of parsing a property token.\n */\nexport interface ParsedPropertyToken {\n /** The CSS custom property name (e.g., '--my-prop') */\n cssName: string;\n /** Whether this is a color property */\n isColor: boolean;\n /** Whether the token was valid */\n isValid: boolean;\n /** Error message if invalid */\n error?: string;\n}\n\n// ============================================================================\n// Extraction Functions\n// ============================================================================\n\n/**\n * Check if styles object has local @properties definition.\n * Fast path: single property lookup.\n */\nexport function hasLocalProperties(styles: Styles): boolean {\n return PROPERTIES_KEY in styles;\n}\n\n/**\n * Extract local @properties from styles object.\n * Returns null if no local properties (fast path).\n */\nexport function extractLocalProperties(\n styles: Styles,\n): Record<string, PropertyDefinition> | null {\n const properties = styles[PROPERTIES_KEY];\n if (!properties || typeof properties !== 'object') {\n return null;\n }\n return properties as Record<string, PropertyDefinition>;\n}\n\n// ============================================================================\n// Token Parsing Functions\n// ============================================================================\n\n/**\n * Parse a property token name and return the CSS property name and whether it's a color.\n * Supports tasty token syntax and validates the property name.\n *\n * Token formats:\n * - `$name` → { cssName: '--name', isColor: false }\n * - `#name` → { cssName: '--name-color', isColor: true }\n * - `--name` → { cssName: '--name', isColor: false } (legacy, auto-detect color by suffix)\n * - `name` → { cssName: '--name', isColor: false } (legacy)\n *\n * @param token - The property token to parse\n * @returns Parsed result with cssName, isColor, isValid, and optional error\n */\nexport function parsePropertyToken(token: string): ParsedPropertyToken {\n if (!token || typeof token !== 'string') {\n return {\n cssName: '',\n isColor: false,\n isValid: false,\n error: 'Property token must be a non-empty string',\n };\n }\n\n let name: string;\n let isColor: boolean;\n\n if (token.startsWith('$')) {\n // Regular property token: $name → --name\n name = token.slice(1);\n isColor = false;\n } else if (token.startsWith('#')) {\n // Color property token: #name → --name-color\n name = token.slice(1);\n isColor = true;\n } else if (token.startsWith('--')) {\n // Legacy format with -- prefix\n name = token.slice(2);\n isColor = token.endsWith('-color');\n } else {\n // Legacy format without prefix\n name = token;\n isColor = token.endsWith('-color');\n }\n\n // Validate the name\n if (!name) {\n return {\n cssName: '',\n isColor,\n isValid: false,\n error: 'Property name cannot be empty',\n };\n }\n\n if (!isValidPropertyName(name)) {\n return {\n cssName: '',\n isColor,\n isValid: false,\n error: `Invalid property name \"${name}\". Must start with a letter or underscore, followed by letters, digits, hyphens, or underscores.`,\n };\n }\n\n // Build the CSS custom property name\n // For #name tokens, we add -color suffix\n // For legacy formats (--name-color or name-color), the name already includes -color\n let cssName: string;\n if (token.startsWith('#')) {\n // Color token: #name → --name-color\n cssName = `--${name}-color`;\n } else {\n // All other formats: just add -- prefix\n cssName = `--${name}`;\n }\n\n return {\n cssName,\n isColor,\n isValid: true,\n };\n}\n\n// ============================================================================\n// Normalization Functions\n// ============================================================================\n\n/**\n * Normalize a property name to the CSS custom property format.\n *\n * @deprecated Use parsePropertyToken instead for proper token handling\n */\nexport function normalizePropertyName(name: string): string {\n const result = parsePropertyToken(name);\n return result.isValid ? result.cssName : `--${name}`;\n}\n\n/**\n * Normalize a property definition to a consistent string representation.\n * Used for comparing definitions to detect type conflicts.\n *\n * Only `syntax` and `inherits` are compared — `initialValue` is intentionally\n * excluded because different components may set different defaults for the\n * same typed property (e.g. auto-inferred `0px` vs explicit `6px`).\n *\n * Keys are sorted alphabetically to ensure consistent comparison:\n * { inherits: true, syntax: '<color>' } === { syntax: '<color>', inherits: true }\n */\nexport function normalizePropertyDefinition(def: PropertyDefinition): string {\n const normalized: Record<string, unknown> = {};\n\n if (def.inherits !== undefined) {\n normalized.inherits = def.inherits;\n }\n if (def.syntax !== undefined) {\n normalized.syntax = def.syntax;\n }\n\n return JSON.stringify(normalized);\n}\n\n/**\n * Result of getEffectiveDefinition.\n */\nexport interface EffectiveDefinitionResult {\n /** The CSS custom property name */\n cssName: string;\n /** The effective property definition */\n definition: PropertyDefinition;\n /** Whether this is a color property */\n isColor: boolean;\n /** Whether the token was valid */\n isValid: boolean;\n /** Error message if invalid */\n error?: string;\n}\n\n/**\n * Get the effective property definition for a token.\n * For color tokens (#name), auto-sets syntax to '<color>' and defaults initialValue to 'transparent'.\n *\n * @param token - Property token ($name, #name, --name, or plain name)\n * @param userDefinition - User-provided definition options\n * @returns Effective definition with cssName, definition, isValid, and optional error\n */\nexport function getEffectiveDefinition(\n token: string,\n userDefinition: PropertyDefinition,\n): EffectiveDefinitionResult {\n const parsed = parsePropertyToken(token);\n\n if (!parsed.isValid) {\n return {\n cssName: '',\n definition: userDefinition,\n isColor: false,\n isValid: false,\n error: parsed.error,\n };\n }\n\n if (parsed.isColor) {\n // Color properties have fixed syntax and default initialValue\n return {\n cssName: parsed.cssName,\n definition: {\n syntax: '<color>', // Always '<color>' for color tokens, cannot be overridden\n inherits: userDefinition.inherits, // Allow inherits to be customized\n initialValue: userDefinition.initialValue ?? 'transparent', // Default to transparent\n },\n isColor: true,\n isValid: true,\n };\n }\n\n // Regular properties use the definition as-is\n return {\n cssName: parsed.cssName,\n definition: userDefinition,\n isColor: false,\n isValid: true,\n };\n}\n\n// ============================================================================\n// Color Utilities\n// ============================================================================\n\nexport { colorInitialValueToComponents } from '../utils/color-space';\n\n// ============================================================================\n// Value Type Inference\n// ============================================================================\n\n/**\n * Result of inferring a CSS @property syntax from a value.\n */\nexport interface InferredSyntax {\n syntax: string;\n initialValue: string;\n}\n\nconst UNIT_TO_SYNTAX: Record<string, InferredSyntax> = {};\n\nconst LENGTH_UNITS = [\n 'px',\n 'em',\n 'rem',\n 'vw',\n 'vh',\n 'vmin',\n 'vmax',\n 'ch',\n 'ex',\n 'cap',\n 'ic',\n 'lh',\n 'rlh',\n 'svw',\n 'svh',\n 'lvw',\n 'lvh',\n 'dvw',\n 'dvh',\n 'cqw',\n 'cqh',\n 'cqi',\n 'cqb',\n 'cqmin',\n 'cqmax',\n];\n\nconst ANGLE_UNITS = ['deg', 'rad', 'grad', 'turn'];\nconst TIME_UNITS = ['ms', 's'];\n\nfor (const u of LENGTH_UNITS) {\n UNIT_TO_SYNTAX[u] = { syntax: '<length-percentage>', initialValue: '0px' };\n}\nUNIT_TO_SYNTAX['%'] = { syntax: '<length-percentage>', initialValue: '0px' };\nfor (const u of ANGLE_UNITS) {\n UNIT_TO_SYNTAX[u] = { syntax: '<angle>', initialValue: '0deg' };\n}\nfor (const u of TIME_UNITS) {\n UNIT_TO_SYNTAX[u] = { syntax: '<time>', initialValue: '0s' };\n}\n\n/**\n * Infer CSS @property syntax from a concrete value.\n * Detects numeric types: \\<number\\>, \\<length-percentage\\>, \\<angle\\>, \\<time\\>.\n * Length and percentage values both map to \\<length-percentage\\> for maximum flexibility.\n * Color properties are handled separately via the #name token convention\n * (--name-color gets \\<color\\> syntax automatically in getEffectiveDefinition).\n *\n * @param value - The CSS value to infer from (e.g. '10px', '1', '45deg')\n * @returns Inferred syntax and initial value, or null if not inferable\n */\nexport function inferSyntaxFromValue(value: string): InferredSyntax | null {\n if (!value || typeof value !== 'string') return null;\n\n const trimmed = value.trim();\n if (!trimmed) return null;\n\n if (RE_NUMBER.test(trimmed)) {\n // Bare zero is ambiguous (could be <length>, <angle>, <percentage>, etc.)\n if (parseFloat(trimmed) === 0) return null;\n return { syntax: '<number>', initialValue: '0' };\n }\n\n const unitMatch = trimmed.match(RE_RAW_UNIT);\n if (unitMatch) {\n const unit = unitMatch[2];\n const mapping = UNIT_TO_SYNTAX[unit];\n if (mapping) return mapping;\n }\n\n return null;\n}\n"],"mappings":";;;AAmBA,MAAM,iBAAiB;;;;;AAMvB,MAAM,8BAA8B;;;;;AAUpC,SAAgB,oBAAoB,MAAuB;AACzD,QAAO,4BAA4B,KAAK,KAAK;;;;;;AAyB/C,SAAgB,mBAAmB,QAAyB;AAC1D,QAAO,kBAAkB;;;;;;AAO3B,SAAgB,uBACd,QAC2C;CAC3C,MAAM,aAAa,OAAO;AAC1B,KAAI,CAAC,cAAc,OAAO,eAAe,SACvC,QAAO;AAET,QAAO;;;;;;;;;;;;;;;AAoBT,SAAgB,mBAAmB,OAAoC;AACrE,KAAI,CAAC,SAAS,OAAO,UAAU,SAC7B,QAAO;EACL,SAAS;EACT,SAAS;EACT,SAAS;EACT,OAAO;EACR;CAGH,IAAI;CACJ,IAAI;AAEJ,KAAI,MAAM,WAAW,IAAI,EAAE;AAEzB,SAAO,MAAM,MAAM,EAAE;AACrB,YAAU;YACD,MAAM,WAAW,IAAI,EAAE;AAEhC,SAAO,MAAM,MAAM,EAAE;AACrB,YAAU;YACD,MAAM,WAAW,KAAK,EAAE;AAEjC,SAAO,MAAM,MAAM,EAAE;AACrB,YAAU,MAAM,SAAS,SAAS;QAC7B;AAEL,SAAO;AACP,YAAU,MAAM,SAAS,SAAS;;AAIpC,KAAI,CAAC,KACH,QAAO;EACL,SAAS;EACT;EACA,SAAS;EACT,OAAO;EACR;AAGH,KAAI,CAAC,oBAAoB,KAAK,CAC5B,QAAO;EACL,SAAS;EACT;EACA,SAAS;EACT,OAAO,0BAA0B,KAAK;EACvC;CAMH,IAAI;AACJ,KAAI,MAAM,WAAW,IAAI,CAEvB,WAAU,KAAK,KAAK;KAGpB,WAAU,KAAK;AAGjB,QAAO;EACL;EACA;EACA,SAAS;EACV;;;;;;;;;;;;;AA4BH,SAAgB,4BAA4B,KAAiC;CAC3E,MAAM,aAAsC,EAAE;AAE9C,KAAI,IAAI,aAAa,KAAA,EACnB,YAAW,WAAW,IAAI;AAE5B,KAAI,IAAI,WAAW,KAAA,EACjB,YAAW,SAAS,IAAI;AAG1B,QAAO,KAAK,UAAU,WAAW;;;;;;;;;;AA2BnC,SAAgB,uBACd,OACA,gBAC2B;CAC3B,MAAM,SAAS,mBAAmB,MAAM;AAExC,KAAI,CAAC,OAAO,QACV,QAAO;EACL,SAAS;EACT,YAAY;EACZ,SAAS;EACT,SAAS;EACT,OAAO,OAAO;EACf;AAGH,KAAI,OAAO,QAET,QAAO;EACL,SAAS,OAAO;EAChB,YAAY;GACV,QAAQ;GACR,UAAU,eAAe;GACzB,cAAc,eAAe,gBAAgB;GAC9C;EACD,SAAS;EACT,SAAS;EACV;AAIH,QAAO;EACL,SAAS,OAAO;EAChB,YAAY;EACZ,SAAS;EACT,SAAS;EACV;;AAqBH,MAAM,iBAAiD,EAAE;AAEzD,MAAM,eAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAM,cAAc;CAAC;CAAO;CAAO;CAAQ;CAAO;AAClD,MAAM,aAAa,CAAC,MAAM,IAAI;AAE9B,KAAK,MAAM,KAAK,aACd,gBAAe,KAAK;CAAE,QAAQ;CAAuB,cAAc;CAAO;AAE5E,eAAe,OAAO;CAAE,QAAQ;CAAuB,cAAc;CAAO;AAC5E,KAAK,MAAM,KAAK,YACd,gBAAe,KAAK;CAAE,QAAQ;CAAW,cAAc;CAAQ;AAEjE,KAAK,MAAM,KAAK,WACd,gBAAe,KAAK;CAAE,QAAQ;CAAU,cAAc;CAAM;;;;;;;;;;;AAa9D,SAAgB,qBAAqB,OAAsC;AACzE,KAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO;CAEhD,MAAM,UAAU,MAAM,MAAM;AAC5B,KAAI,CAAC,QAAS,QAAO;AAErB,KAAI,UAAU,KAAK,QAAQ,EAAE;AAE3B,MAAI,WAAW,QAAQ,KAAK,EAAG,QAAO;AACtC,SAAO;GAAE,QAAQ;GAAY,cAAc;GAAK;;CAGlD,MAAM,YAAY,QAAQ,MAAM,YAAY;AAC5C,KAAI,WAAW;EAEb,MAAM,UAAU,eADH,UAAU;AAEvB,MAAI,QAAS,QAAO;;AAGtB,QAAO"}
@@ -0,0 +1,24 @@
1
+ //#region src/properties/property-type-resolver.d.ts
2
+ /**
3
+ * PropertyTypeResolver
4
+ *
5
+ * Automatically infers CSS @property types from custom property values.
6
+ * Supports deferred resolution for var() reference chains of arbitrary depth.
7
+ */
8
+ declare class PropertyTypeResolver {
9
+ /** propName → the prop it depends on */
10
+ private pendingDeps;
11
+ /** propName → list of props waiting on it */
12
+ private reverseDeps;
13
+ /**
14
+ * Scan CSS declarations and auto-register @property for custom properties
15
+ * whose types can be inferred from their values.
16
+ */
17
+ scanDeclarations(declarations: string, isPropertyDefined: (name: string) => boolean, registerProperty: (name: string, syntax: string, initialValue: string) => void): void;
18
+ private addDependency;
19
+ private resolve;
20
+ private isComplexValue;
21
+ }
22
+ //#endregion
23
+ export { PropertyTypeResolver };
24
+ //# sourceMappingURL=property-type-resolver.d.ts.map
@@ -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,79 @@
1
+ import { hashString } from "./utils/hash.js";
2
+ import { getRegisteredSSRCollector } from "./ssr/ssr-collector-ref.js";
3
+ import { cache } from "react";
4
+ //#region src/rsc-cache.ts
5
+ /**
6
+ * Shared RSC (React Server Components) inline style cache.
7
+ *
8
+ * Uses React.cache for per-request memoization in Server Components.
9
+ * Both computeStyles() and standalone style functions (useGlobalStyles,
10
+ * useRawCSS, useKeyframes, useProperty, useFontFace, useCounterStyle)
11
+ * share this cache so that CSS accumulated by standalone functions is
12
+ * flushed into inline <style> tags by the next tasty() component.
13
+ */
14
+ /**
15
+ * Per-request RSC style cache using React.cache.
16
+ * React.cache provides per-request memoization in Server Components,
17
+ * so each request gets its own isolated cache.
18
+ */
19
+ const getRSCCache = cache(() => ({
20
+ cacheKeyToClassName: /* @__PURE__ */ new Map(),
21
+ emittedKeys: /* @__PURE__ */ new Set(),
22
+ internalsEmitted: false,
23
+ pendingCSS: [],
24
+ generatedNames: /* @__PURE__ */ new Map()
25
+ }));
26
+ function rscAllocateClassName(rscCache, cacheKey) {
27
+ const existing = rscCache.cacheKeyToClassName.get(cacheKey);
28
+ if (existing) return {
29
+ className: existing,
30
+ isNew: false
31
+ };
32
+ const className = `t${hashString(cacheKey)}`;
33
+ rscCache.cacheKeyToClassName.set(cacheKey, className);
34
+ return {
35
+ className,
36
+ isNew: true
37
+ };
38
+ }
39
+ /**
40
+ * Flush any pending CSS accumulated by standalone functions.
41
+ * Returns the CSS string and clears the buffer.
42
+ */
43
+ function flushPendingCSS(rscCache) {
44
+ if (rscCache.pendingCSS.length === 0) return "";
45
+ const css = rscCache.pendingCSS.join("\n");
46
+ rscCache.pendingCSS.length = 0;
47
+ return css;
48
+ }
49
+ /**
50
+ * Push CSS into the RSC pending buffer with dedup via emittedKeys.
51
+ * Returns true if the CSS was added, false if it was already emitted.
52
+ */
53
+ function pushRSCCSS(rscCache, key, css) {
54
+ if (rscCache.emittedKeys.has(key)) return false;
55
+ rscCache.emittedKeys.add(key);
56
+ rscCache.pendingCSS.push(css);
57
+ return true;
58
+ }
59
+ /**
60
+ * Determine the current style injection target.
61
+ * Centralizes the three-way detection (SSR collector / RSC cache / client DOM)
62
+ * used by all style functions.
63
+ */
64
+ function getStyleTarget() {
65
+ const collector = getRegisteredSSRCollector();
66
+ if (collector) return {
67
+ mode: "ssr",
68
+ collector
69
+ };
70
+ if (typeof document === "undefined") return {
71
+ mode: "rsc",
72
+ cache: getRSCCache()
73
+ };
74
+ return { mode: "client" };
75
+ }
76
+ //#endregion
77
+ export { flushPendingCSS, getRSCCache, getStyleTarget, pushRSCCSS, rscAllocateClassName };
78
+
79
+ //# sourceMappingURL=rsc-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rsc-cache.js","names":[],"sources":["../src/rsc-cache.ts"],"sourcesContent":["/**\n * Shared RSC (React Server Components) inline style cache.\n *\n * Uses React.cache for per-request memoization in Server Components.\n * Both computeStyles() and standalone style functions (useGlobalStyles,\n * useRawCSS, useKeyframes, useProperty, useFontFace, useCounterStyle)\n * share this cache so that CSS accumulated by standalone functions is\n * flushed into inline <style> tags by the next tasty() component.\n */\n\nimport { cache } from 'react';\n\nimport type { ServerStyleCollector } from './ssr/collector';\nimport { getRegisteredSSRCollector } from './ssr/ssr-collector-ref';\nimport { hashString } from './utils/hash';\n\nexport interface RSCStyleCache {\n cacheKeyToClassName: Map<string, string>;\n emittedKeys: Set<string>;\n internalsEmitted: boolean;\n pendingCSS: string[];\n /** Maps dedup key -> generated name for keyframes and counter-styles in RSC mode. */\n generatedNames: Map<string, string>;\n}\n\n/**\n * Per-request RSC style cache using React.cache.\n * React.cache provides per-request memoization in Server Components,\n * so each request gets its own isolated cache.\n */\nexport const getRSCCache = cache(\n (): RSCStyleCache => ({\n cacheKeyToClassName: new Map(),\n emittedKeys: new Set(),\n internalsEmitted: false,\n pendingCSS: [],\n generatedNames: new Map(),\n }),\n);\n\nexport function rscAllocateClassName(\n rscCache: RSCStyleCache,\n cacheKey: string,\n): { className: string; isNew: boolean } {\n const existing = rscCache.cacheKeyToClassName.get(cacheKey);\n if (existing) return { className: existing, isNew: false };\n\n // Content-hash ensures stable names across all environments (RSC, SSR, client),\n // enabling cross-environment dedup and preventing class collisions.\n const className = `t${hashString(cacheKey)}`;\n rscCache.cacheKeyToClassName.set(cacheKey, className);\n return { className, isNew: true };\n}\n\n/**\n * Flush any pending CSS accumulated by standalone functions.\n * Returns the CSS string and clears the buffer.\n */\nexport function flushPendingCSS(rscCache: RSCStyleCache): string {\n if (rscCache.pendingCSS.length === 0) return '';\n const css = rscCache.pendingCSS.join('\\n');\n rscCache.pendingCSS.length = 0;\n return css;\n}\n\n/**\n * Push CSS into the RSC pending buffer with dedup via emittedKeys.\n * Returns true if the CSS was added, false if it was already emitted.\n */\nexport function pushRSCCSS(\n rscCache: RSCStyleCache,\n key: string,\n css: string,\n): boolean {\n if (rscCache.emittedKeys.has(key)) return false;\n rscCache.emittedKeys.add(key);\n rscCache.pendingCSS.push(css);\n return true;\n}\n\nexport type StyleTarget =\n | { mode: 'ssr'; collector: ServerStyleCollector }\n | { mode: 'rsc'; cache: RSCStyleCache }\n | { mode: 'client' };\n\n/**\n * Determine the current style injection target.\n * Centralizes the three-way detection (SSR collector / RSC cache / client DOM)\n * used by all style functions.\n */\nexport function getStyleTarget(): StyleTarget {\n const collector = getRegisteredSSRCollector();\n if (collector) return { mode: 'ssr', collector };\n if (typeof document === 'undefined')\n return { mode: 'rsc', cache: getRSCCache() };\n return { mode: 'client' };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA8BA,MAAa,cAAc,aACH;CACpB,qCAAqB,IAAI,KAAK;CAC9B,6BAAa,IAAI,KAAK;CACtB,kBAAkB;CAClB,YAAY,EAAE;CACd,gCAAgB,IAAI,KAAK;CAC1B,EACF;AAED,SAAgB,qBACd,UACA,UACuC;CACvC,MAAM,WAAW,SAAS,oBAAoB,IAAI,SAAS;AAC3D,KAAI,SAAU,QAAO;EAAE,WAAW;EAAU,OAAO;EAAO;CAI1D,MAAM,YAAY,IAAI,WAAW,SAAS;AAC1C,UAAS,oBAAoB,IAAI,UAAU,UAAU;AACrD,QAAO;EAAE;EAAW,OAAO;EAAM;;;;;;AAOnC,SAAgB,gBAAgB,UAAiC;AAC/D,KAAI,SAAS,WAAW,WAAW,EAAG,QAAO;CAC7C,MAAM,MAAM,SAAS,WAAW,KAAK,KAAK;AAC1C,UAAS,WAAW,SAAS;AAC7B,QAAO;;;;;;AAOT,SAAgB,WACd,UACA,KACA,KACS;AACT,KAAI,SAAS,YAAY,IAAI,IAAI,CAAE,QAAO;AAC1C,UAAS,YAAY,IAAI,IAAI;AAC7B,UAAS,WAAW,KAAK,IAAI;AAC7B,QAAO;;;;;;;AAaT,SAAgB,iBAA8B;CAC5C,MAAM,YAAY,2BAA2B;AAC7C,KAAI,UAAW,QAAO;EAAE,MAAM;EAAO;EAAW;AAChD,KAAI,OAAO,aAAa,YACtB,QAAO;EAAE,MAAM;EAAO,OAAO,aAAa;EAAE;AAC9C,QAAO,EAAE,MAAM,UAAU"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,19 @@
1
+ import { hydrateTastyClasses } from "./hydrate.js";
2
+ //#region src/ssr/astro-client.ts
3
+ /**
4
+ * Client-side cache hydration for Astro islands.
5
+ *
6
+ * Reads the class name list from `window.__TASTY__` (populated by
7
+ * inline scripts emitted during SSR) and pre-populates the injector
8
+ * so island hydration skips the style pipeline entirely.
9
+ *
10
+ * This module is browser-safe — it does NOT import node:async_hooks.
11
+ *
12
+ * Usage:
13
+ * - Automatically injected by tastyIntegration() via injectScript('before-hydration')
14
+ * - Can be imported manually: `import '@tenphi/tasty/ssr/astro-client'`
15
+ */
16
+ if (typeof window !== "undefined") hydrateTastyClasses();
17
+ //#endregion
18
+
19
+ //# sourceMappingURL=astro-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-client.js","names":[],"sources":["../../src/ssr/astro-client.ts"],"sourcesContent":["/**\n * Client-side cache hydration for Astro islands.\n *\n * Reads the class name list from `window.__TASTY__` (populated by\n * inline scripts emitted during SSR) and pre-populates the injector\n * so island hydration skips the style pipeline entirely.\n *\n * This module is browser-safe — it does NOT import node:async_hooks.\n *\n * Usage:\n * - Automatically injected by tastyIntegration() via injectScript('before-hydration')\n * - Can be imported manually: `import '@tenphi/tasty/ssr/astro-client'`\n */\n\nimport { hydrateTastyClasses } from './hydrate';\n\nif (typeof window !== 'undefined') {\n hydrateTastyClasses();\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,IAAI,OAAO,WAAW,YACpB,sBAAqB"}
@@ -0,0 +1,15 @@
1
+ //#region src/ssr/astro-middleware.d.ts
2
+ /**
3
+ * Astro middleware entrypoint for tastyIntegration().
4
+ *
5
+ * Referenced by the integration via addMiddleware(). Not intended
6
+ * as a public package export — use tastyMiddleware() directly if
7
+ * you need manual middleware composition.
8
+ *
9
+ * The transferCache setting is controlled by setMiddlewareTransferCache(),
10
+ * called by tastyIntegration() before middleware is loaded.
11
+ */
12
+ declare const onRequest: (_context: unknown, next: () => Promise<Response>) => Promise<Response>;
13
+ //#endregion
14
+ export { onRequest };
15
+ //# sourceMappingURL=astro-middleware.d.ts.map
@@ -0,0 +1,19 @@
1
+ import { getMiddlewareTransferCache, tastyMiddleware } from "./astro.js";
2
+ //#region src/ssr/astro-middleware.ts
3
+ /**
4
+ * Astro middleware entrypoint for tastyIntegration().
5
+ *
6
+ * Referenced by the integration via addMiddleware(). Not intended
7
+ * as a public package export — use tastyMiddleware() directly if
8
+ * you need manual middleware composition.
9
+ *
10
+ * The transferCache setting is controlled by setMiddlewareTransferCache(),
11
+ * called by tastyIntegration() before middleware is loaded.
12
+ */
13
+ const onRequest = tastyMiddleware({ get transferCache() {
14
+ return getMiddlewareTransferCache();
15
+ } });
16
+ //#endregion
17
+ export { onRequest };
18
+
19
+ //# sourceMappingURL=astro-middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-middleware.js","names":[],"sources":["../../src/ssr/astro-middleware.ts"],"sourcesContent":["/**\n * Astro middleware entrypoint for tastyIntegration().\n *\n * Referenced by the integration via addMiddleware(). Not intended\n * as a public package export — use tastyMiddleware() directly if\n * you need manual middleware composition.\n *\n * The transferCache setting is controlled by setMiddlewareTransferCache(),\n * called by tastyIntegration() before middleware is loaded.\n */\n\nimport { getMiddlewareTransferCache, tastyMiddleware } from './astro';\n\nexport const onRequest = tastyMiddleware({\n get transferCache() {\n return getMiddlewareTransferCache();\n },\n});\n"],"mappings":";;;;;;;;;;;;AAaA,MAAa,YAAY,gBAAgB,EACvC,IAAI,gBAAgB;AAClB,QAAO,4BAA4B;GAEtC,CAAC"}
@@ -0,0 +1,108 @@
1
+ //#region src/ssr/astro.d.ts
2
+ /**
3
+ * Astro integration for Tasty SSR.
4
+ *
5
+ * Provides:
6
+ * - tastyIntegration() — Astro Integration API (recommended)
7
+ * - tastyMiddleware() — manual middleware for advanced composition
8
+ *
9
+ * Import from '@tenphi/tasty/ssr/astro'.
10
+ */
11
+ interface TastyMiddlewareOptions {
12
+ /**
13
+ * Whether to embed the class-list script for client hydration.
14
+ * Set to false to skip class transfer (e.g. for CSP restrictions).
15
+ * Without it, client components may re-inject CSS that already exists
16
+ * in server-rendered `<style>` tags. Default: true.
17
+ */
18
+ transferCache?: boolean;
19
+ }
20
+ /**
21
+ * Create an Astro middleware that collects Tasty styles during SSR.
22
+ *
23
+ * All React components rendered during the request will have their
24
+ * computeStyles() calls captured by the collector via AsyncLocalStorage.
25
+ * After rendering, the middleware injects the collected CSS into </head>.
26
+ *
27
+ * @example Manual middleware setup
28
+ * ```ts
29
+ * // src/middleware.ts
30
+ * import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
31
+ * export const onRequest = tastyMiddleware();
32
+ * ```
33
+ *
34
+ * @example Composing with other middleware
35
+ * ```ts
36
+ * // src/middleware.ts
37
+ * import { sequence } from 'astro:middleware';
38
+ * import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
39
+ *
40
+ * export const onRequest = sequence(
41
+ * tastyMiddleware(),
42
+ * myOtherMiddleware,
43
+ * );
44
+ * ```
45
+ */
46
+ declare function tastyMiddleware(options?: TastyMiddlewareOptions): (_context: unknown, next: () => Promise<Response>) => Promise<Response>;
47
+ /** @internal */
48
+ declare function setMiddlewareTransferCache(value: boolean): void;
49
+ /** @internal */
50
+ declare function getMiddlewareTransferCache(): boolean;
51
+ interface TastyIntegrationOptions {
52
+ /**
53
+ * Enable island hydration support.
54
+ *
55
+ * When `true` (default): injects a client hydration script via
56
+ * `injectScript('before-hydration')` and sets `transferCache: true`
57
+ * on the middleware. Islands skip the style pipeline during hydration.
58
+ *
59
+ * When `false`: no client JS is shipped and `transferCache` is set
60
+ * to `false`. Use this for fully static sites without `client:*`
61
+ * directives.
62
+ */
63
+ islands?: boolean;
64
+ }
65
+ /**
66
+ * Astro integration that automatically sets up Tasty SSR.
67
+ *
68
+ * Registers middleware for cross-component CSS deduplication and
69
+ * optionally injects a client hydration script for island support.
70
+ *
71
+ * @example Basic setup (with islands)
72
+ * ```ts
73
+ * // astro.config.mjs
74
+ * import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
75
+ *
76
+ * export default defineConfig({
77
+ * integrations: [tastyIntegration()],
78
+ * });
79
+ * ```
80
+ *
81
+ * @example Static-only (no client JS)
82
+ * ```ts
83
+ * // astro.config.mjs
84
+ * import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
85
+ *
86
+ * export default defineConfig({
87
+ * integrations: [tastyIntegration({ islands: false })],
88
+ * });
89
+ * ```
90
+ */
91
+ declare function tastyIntegration(options?: TastyIntegrationOptions): {
92
+ name: string;
93
+ hooks: {
94
+ 'astro:config:setup': ({
95
+ addMiddleware,
96
+ injectScript
97
+ }: {
98
+ addMiddleware: (middleware: {
99
+ entrypoint: string | URL;
100
+ order: "pre" | "post";
101
+ }) => void;
102
+ injectScript: (stage: string, content: string) => void;
103
+ }) => void;
104
+ };
105
+ };
106
+ //#endregion
107
+ export { TastyIntegrationOptions, TastyMiddlewareOptions, getMiddlewareTransferCache, setMiddlewareTransferCache, tastyIntegration, tastyMiddleware };
108
+ //# sourceMappingURL=astro.d.ts.map