@tenphi/tasty 2.0.3 → 2.1.0

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 (323) hide show
  1. package/dist/{ssr/async-storage.js → async-storage-B7_o6FKt.js} +2 -2
  2. package/dist/async-storage-B7_o6FKt.js.map +1 -0
  3. package/dist/{ssr/collector.js → collector-DrgDE7QB.js} +5 -10
  4. package/dist/collector-DrgDE7QB.js.map +1 -0
  5. package/dist/{ssr/collector.d.ts → collector-LuU1vZ68.d.ts} +3 -3
  6. package/dist/config-_aQ_PZ-P.js +10131 -0
  7. package/dist/config-_aQ_PZ-P.js.map +1 -0
  8. package/dist/config-vuCRkBWX.d.ts +884 -0
  9. package/dist/{ssr/context.js → context-CkSg-kDT.js} +11 -3
  10. package/dist/context-CkSg-kDT.js.map +1 -0
  11. package/dist/core/index.d.ts +5 -34
  12. package/dist/core/index.js +6 -27
  13. package/dist/core-BqO8pplb.js +1592 -0
  14. package/dist/core-BqO8pplb.js.map +1 -0
  15. package/dist/{zero/extractor.js → css-writer-D--REwtp.js} +74 -11
  16. package/dist/css-writer-D--REwtp.js.map +1 -0
  17. package/dist/{ssr/format-global-rules.js → format-global-rules-Dbc_1tc3.js} +2 -2
  18. package/dist/format-global-rules-Dbc_1tc3.js.map +1 -0
  19. package/dist/format-rules-xwteB7a1.js +143 -0
  20. package/dist/format-rules-xwteB7a1.js.map +1 -0
  21. package/dist/{ssr/hydrate.js → hydrate-BvPT4ndL.js} +3 -3
  22. package/dist/hydrate-BvPT4ndL.js.map +1 -0
  23. package/dist/index-ZRxZWzlj.d.ts +1602 -0
  24. package/dist/{styles/types.d.ts → index-dUtwpOux.d.ts} +707 -5
  25. package/dist/index.d.ts +5 -51
  26. package/dist/index.js +732 -36
  27. package/dist/index.js.map +1 -0
  28. package/dist/keyframes-ClPFWy33.js +587 -0
  29. package/dist/keyframes-ClPFWy33.js.map +1 -0
  30. package/dist/{utils/merge-styles.js → merge-styles-BUQsEpbv.js} +3 -4
  31. package/dist/merge-styles-BUQsEpbv.js.map +1 -0
  32. package/dist/{utils/merge-styles.d.ts → merge-styles-CtDJMhpJ.d.ts} +3 -3
  33. package/dist/{utils/resolve-recipes.js → resolve-recipes-C0-AMzCz.js} +4 -6
  34. package/dist/resolve-recipes-C0-AMzCz.js.map +1 -0
  35. package/dist/ssr/astro-client.js +1 -1
  36. package/dist/ssr/astro.js +4 -4
  37. package/dist/ssr/index.d.ts +44 -4
  38. package/dist/ssr/index.js +4 -4
  39. package/dist/ssr/next.d.ts +1 -1
  40. package/dist/ssr/next.js +6 -6
  41. package/dist/ssr/next.js.map +1 -1
  42. package/dist/static/index.d.ts +91 -5
  43. package/dist/static/index.js +49 -3
  44. package/dist/static/index.js.map +1 -0
  45. package/dist/zero/babel.d.ts +1 -1
  46. package/dist/zero/babel.js +10 -6
  47. package/dist/zero/babel.js.map +1 -1
  48. package/dist/zero/index.d.ts +67 -3
  49. package/dist/zero/index.js +1 -2
  50. package/docs/injector.md +2 -2
  51. package/package.json +10 -9
  52. package/dist/_virtual/_rolldown/runtime.js +0 -7
  53. package/dist/chunks/cacheKey.d.ts +0 -1
  54. package/dist/chunks/cacheKey.js +0 -77
  55. package/dist/chunks/cacheKey.js.map +0 -1
  56. package/dist/chunks/definitions.d.ts +0 -37
  57. package/dist/chunks/definitions.js +0 -258
  58. package/dist/chunks/definitions.js.map +0 -1
  59. package/dist/chunks/index.d.ts +0 -1
  60. package/dist/chunks/renderChunk.d.ts +0 -1
  61. package/dist/chunks/renderChunk.js +0 -59
  62. package/dist/chunks/renderChunk.js.map +0 -1
  63. package/dist/compute-styles.d.ts +0 -31
  64. package/dist/compute-styles.js +0 -322
  65. package/dist/compute-styles.js.map +0 -1
  66. package/dist/config.d.ts +0 -407
  67. package/dist/config.js +0 -591
  68. package/dist/config.js.map +0 -1
  69. package/dist/counter-style/index.js +0 -51
  70. package/dist/counter-style/index.js.map +0 -1
  71. package/dist/debug.d.ts +0 -89
  72. package/dist/debug.js +0 -453
  73. package/dist/debug.js.map +0 -1
  74. package/dist/font-face/index.js +0 -63
  75. package/dist/font-face/index.js.map +0 -1
  76. package/dist/hooks/index.d.ts +0 -7
  77. package/dist/hooks/useCounterStyle.d.ts +0 -36
  78. package/dist/hooks/useCounterStyle.js +0 -65
  79. package/dist/hooks/useCounterStyle.js.map +0 -1
  80. package/dist/hooks/useFontFace.d.ts +0 -45
  81. package/dist/hooks/useFontFace.js +0 -66
  82. package/dist/hooks/useFontFace.js.map +0 -1
  83. package/dist/hooks/useGlobalStyles.d.ts +0 -46
  84. package/dist/hooks/useGlobalStyles.js +0 -88
  85. package/dist/hooks/useGlobalStyles.js.map +0 -1
  86. package/dist/hooks/useKeyframes.d.ts +0 -58
  87. package/dist/hooks/useKeyframes.js +0 -55
  88. package/dist/hooks/useKeyframes.js.map +0 -1
  89. package/dist/hooks/useProperty.d.ts +0 -81
  90. package/dist/hooks/useProperty.js +0 -96
  91. package/dist/hooks/useProperty.js.map +0 -1
  92. package/dist/hooks/useRawCSS.d.ts +0 -22
  93. package/dist/hooks/useRawCSS.js +0 -103
  94. package/dist/hooks/useRawCSS.js.map +0 -1
  95. package/dist/hooks/useStyles.d.ts +0 -40
  96. package/dist/hooks/useStyles.js +0 -31
  97. package/dist/hooks/useStyles.js.map +0 -1
  98. package/dist/injector/index.d.ts +0 -182
  99. package/dist/injector/index.js +0 -185
  100. package/dist/injector/index.js.map +0 -1
  101. package/dist/injector/injector.d.ts +0 -198
  102. package/dist/injector/injector.js +0 -651
  103. package/dist/injector/injector.js.map +0 -1
  104. package/dist/injector/sheet-manager.d.ts +0 -132
  105. package/dist/injector/sheet-manager.js +0 -699
  106. package/dist/injector/sheet-manager.js.map +0 -1
  107. package/dist/injector/types.d.ts +0 -235
  108. package/dist/keyframes/index.js +0 -206
  109. package/dist/keyframes/index.js.map +0 -1
  110. package/dist/parser/classify.js +0 -319
  111. package/dist/parser/classify.js.map +0 -1
  112. package/dist/parser/const.js +0 -60
  113. package/dist/parser/const.js.map +0 -1
  114. package/dist/parser/lru.js +0 -109
  115. package/dist/parser/lru.js.map +0 -1
  116. package/dist/parser/parser.d.ts +0 -25
  117. package/dist/parser/parser.js +0 -115
  118. package/dist/parser/parser.js.map +0 -1
  119. package/dist/parser/tokenizer.js +0 -69
  120. package/dist/parser/tokenizer.js.map +0 -1
  121. package/dist/parser/types.d.ts +0 -51
  122. package/dist/parser/types.js +0 -46
  123. package/dist/parser/types.js.map +0 -1
  124. package/dist/pipeline/conditions.d.ts +0 -134
  125. package/dist/pipeline/conditions.js +0 -406
  126. package/dist/pipeline/conditions.js.map +0 -1
  127. package/dist/pipeline/exclusive.js +0 -389
  128. package/dist/pipeline/exclusive.js.map +0 -1
  129. package/dist/pipeline/index.d.ts +0 -55
  130. package/dist/pipeline/index.js +0 -749
  131. package/dist/pipeline/index.js.map +0 -1
  132. package/dist/pipeline/materialize-contradictions.js +0 -125
  133. package/dist/pipeline/materialize-contradictions.js.map +0 -1
  134. package/dist/pipeline/materialize.js +0 -1038
  135. package/dist/pipeline/materialize.js.map +0 -1
  136. package/dist/pipeline/parseStateKey.d.ts +0 -15
  137. package/dist/pipeline/parseStateKey.js +0 -446
  138. package/dist/pipeline/parseStateKey.js.map +0 -1
  139. package/dist/pipeline/simplify.js +0 -725
  140. package/dist/pipeline/simplify.js.map +0 -1
  141. package/dist/pipeline/warnings.js +0 -18
  142. package/dist/pipeline/warnings.js.map +0 -1
  143. package/dist/plugins/index.d.ts +0 -2
  144. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  145. package/dist/plugins/okhsl-plugin.js +0 -97
  146. package/dist/plugins/okhsl-plugin.js.map +0 -1
  147. package/dist/plugins/types.d.ts +0 -87
  148. package/dist/properties/index.js +0 -222
  149. package/dist/properties/index.js.map +0 -1
  150. package/dist/properties/property-type-resolver.d.ts +0 -24
  151. package/dist/properties/property-type-resolver.js +0 -90
  152. package/dist/properties/property-type-resolver.js.map +0 -1
  153. package/dist/rsc-cache.js +0 -79
  154. package/dist/rsc-cache.js.map +0 -1
  155. package/dist/ssr/async-storage.d.ts +0 -17
  156. package/dist/ssr/async-storage.js.map +0 -1
  157. package/dist/ssr/collect-auto-properties.js +0 -58
  158. package/dist/ssr/collect-auto-properties.js.map +0 -1
  159. package/dist/ssr/collector.js.map +0 -1
  160. package/dist/ssr/context.js.map +0 -1
  161. package/dist/ssr/format-global-rules.js.map +0 -1
  162. package/dist/ssr/format-keyframes.js +0 -69
  163. package/dist/ssr/format-keyframes.js.map +0 -1
  164. package/dist/ssr/format-property.js +0 -49
  165. package/dist/ssr/format-property.js.map +0 -1
  166. package/dist/ssr/format-rules.js +0 -73
  167. package/dist/ssr/format-rules.js.map +0 -1
  168. package/dist/ssr/hydrate.d.ts +0 -29
  169. package/dist/ssr/hydrate.js.map +0 -1
  170. package/dist/ssr/ssr-collector-ref.js +0 -29
  171. package/dist/ssr/ssr-collector-ref.js.map +0 -1
  172. package/dist/states/index.d.ts +0 -49
  173. package/dist/states/index.js +0 -170
  174. package/dist/states/index.js.map +0 -1
  175. package/dist/static/tastyStatic.d.ts +0 -46
  176. package/dist/static/tastyStatic.js +0 -30
  177. package/dist/static/tastyStatic.js.map +0 -1
  178. package/dist/static/types.d.ts +0 -49
  179. package/dist/static/types.js +0 -24
  180. package/dist/static/types.js.map +0 -1
  181. package/dist/styles/border.d.ts +0 -25
  182. package/dist/styles/border.js +0 -120
  183. package/dist/styles/border.js.map +0 -1
  184. package/dist/styles/color.d.ts +0 -14
  185. package/dist/styles/color.js +0 -26
  186. package/dist/styles/color.js.map +0 -1
  187. package/dist/styles/const.js +0 -17
  188. package/dist/styles/const.js.map +0 -1
  189. package/dist/styles/createStyle.js +0 -79
  190. package/dist/styles/createStyle.js.map +0 -1
  191. package/dist/styles/dimension.js +0 -109
  192. package/dist/styles/dimension.js.map +0 -1
  193. package/dist/styles/directional.js +0 -133
  194. package/dist/styles/directional.js.map +0 -1
  195. package/dist/styles/display.d.ts +0 -30
  196. package/dist/styles/display.js +0 -73
  197. package/dist/styles/display.js.map +0 -1
  198. package/dist/styles/fade.d.ts +0 -15
  199. package/dist/styles/fade.js +0 -62
  200. package/dist/styles/fade.js.map +0 -1
  201. package/dist/styles/fill.d.ts +0 -42
  202. package/dist/styles/fill.js +0 -51
  203. package/dist/styles/fill.js.map +0 -1
  204. package/dist/styles/flow.d.ts +0 -16
  205. package/dist/styles/flow.js +0 -12
  206. package/dist/styles/flow.js.map +0 -1
  207. package/dist/styles/gap.d.ts +0 -31
  208. package/dist/styles/gap.js +0 -38
  209. package/dist/styles/gap.js.map +0 -1
  210. package/dist/styles/height.d.ts +0 -17
  211. package/dist/styles/height.js +0 -19
  212. package/dist/styles/height.js.map +0 -1
  213. package/dist/styles/index.d.ts +0 -1
  214. package/dist/styles/index.js +0 -8
  215. package/dist/styles/index.js.map +0 -1
  216. package/dist/styles/inset.d.ts +0 -24
  217. package/dist/styles/inset.js +0 -34
  218. package/dist/styles/inset.js.map +0 -1
  219. package/dist/styles/list.d.ts +0 -16
  220. package/dist/styles/list.js +0 -100
  221. package/dist/styles/list.js.map +0 -1
  222. package/dist/styles/margin.d.ts +0 -24
  223. package/dist/styles/margin.js +0 -32
  224. package/dist/styles/margin.js.map +0 -1
  225. package/dist/styles/outline.d.ts +0 -29
  226. package/dist/styles/outline.js +0 -55
  227. package/dist/styles/outline.js.map +0 -1
  228. package/dist/styles/padding.d.ts +0 -24
  229. package/dist/styles/padding.js +0 -32
  230. package/dist/styles/padding.js.map +0 -1
  231. package/dist/styles/placement.d.ts +0 -37
  232. package/dist/styles/placement.js +0 -74
  233. package/dist/styles/placement.js.map +0 -1
  234. package/dist/styles/predefined.d.ts +0 -71
  235. package/dist/styles/predefined.js +0 -237
  236. package/dist/styles/predefined.js.map +0 -1
  237. package/dist/styles/preset.d.ts +0 -52
  238. package/dist/styles/preset.js +0 -127
  239. package/dist/styles/preset.js.map +0 -1
  240. package/dist/styles/radius.d.ts +0 -12
  241. package/dist/styles/radius.js +0 -83
  242. package/dist/styles/radius.js.map +0 -1
  243. package/dist/styles/scrollMargin.d.ts +0 -24
  244. package/dist/styles/scrollMargin.js +0 -32
  245. package/dist/styles/scrollMargin.js.map +0 -1
  246. package/dist/styles/scrollbar.d.ts +0 -25
  247. package/dist/styles/scrollbar.js +0 -51
  248. package/dist/styles/scrollbar.js.map +0 -1
  249. package/dist/styles/shadow.d.ts +0 -14
  250. package/dist/styles/shadow.js +0 -25
  251. package/dist/styles/shadow.js.map +0 -1
  252. package/dist/styles/shared.js +0 -17
  253. package/dist/styles/shared.js.map +0 -1
  254. package/dist/styles/transition.d.ts +0 -14
  255. package/dist/styles/transition.js +0 -159
  256. package/dist/styles/transition.js.map +0 -1
  257. package/dist/styles/width.d.ts +0 -17
  258. package/dist/styles/width.js +0 -19
  259. package/dist/styles/width.js.map +0 -1
  260. package/dist/tasty.d.ts +0 -134
  261. package/dist/tasty.js +0 -248
  262. package/dist/tasty.js.map +0 -1
  263. package/dist/types.d.ts +0 -184
  264. package/dist/utils/cache-wrapper.js +0 -21
  265. package/dist/utils/cache-wrapper.js.map +0 -1
  266. package/dist/utils/case-converter.js +0 -8
  267. package/dist/utils/case-converter.js.map +0 -1
  268. package/dist/utils/color-math.d.ts +0 -46
  269. package/dist/utils/color-math.js +0 -749
  270. package/dist/utils/color-math.js.map +0 -1
  271. package/dist/utils/color-space.d.ts +0 -5
  272. package/dist/utils/color-space.js +0 -228
  273. package/dist/utils/color-space.js.map +0 -1
  274. package/dist/utils/colors.d.ts +0 -5
  275. package/dist/utils/colors.js +0 -10
  276. package/dist/utils/colors.js.map +0 -1
  277. package/dist/utils/css-types.d.ts +0 -7
  278. package/dist/utils/deps-equal.js +0 -15
  279. package/dist/utils/deps-equal.js.map +0 -1
  280. package/dist/utils/dotize.d.ts +0 -26
  281. package/dist/utils/dotize.js +0 -122
  282. package/dist/utils/dotize.js.map +0 -1
  283. package/dist/utils/filter-base-props.d.ts +0 -15
  284. package/dist/utils/filter-base-props.js +0 -45
  285. package/dist/utils/filter-base-props.js.map +0 -1
  286. package/dist/utils/get-display-name.d.ts +0 -7
  287. package/dist/utils/get-display-name.js +0 -10
  288. package/dist/utils/get-display-name.js.map +0 -1
  289. package/dist/utils/has-keys.js +0 -13
  290. package/dist/utils/has-keys.js.map +0 -1
  291. package/dist/utils/hash.js +0 -14
  292. package/dist/utils/hash.js.map +0 -1
  293. package/dist/utils/is-dev-env.js +0 -19
  294. package/dist/utils/is-dev-env.js.map +0 -1
  295. package/dist/utils/is-valid-element-type.js +0 -15
  296. package/dist/utils/is-valid-element-type.js.map +0 -1
  297. package/dist/utils/merge-styles.js.map +0 -1
  298. package/dist/utils/mod-attrs.d.ts +0 -6
  299. package/dist/utils/mod-attrs.js +0 -20
  300. package/dist/utils/mod-attrs.js.map +0 -1
  301. package/dist/utils/process-tokens.d.ts +0 -17
  302. package/dist/utils/process-tokens.js +0 -83
  303. package/dist/utils/process-tokens.js.map +0 -1
  304. package/dist/utils/resolve-recipes.d.ts +0 -17
  305. package/dist/utils/resolve-recipes.js.map +0 -1
  306. package/dist/utils/selector-transform.js +0 -32
  307. package/dist/utils/selector-transform.js.map +0 -1
  308. package/dist/utils/string.js +0 -8
  309. package/dist/utils/string.js.map +0 -1
  310. package/dist/utils/styles.d.ts +0 -99
  311. package/dist/utils/styles.js +0 -220
  312. package/dist/utils/styles.js.map +0 -1
  313. package/dist/utils/typography.d.ts +0 -58
  314. package/dist/utils/typography.js +0 -51
  315. package/dist/utils/typography.js.map +0 -1
  316. package/dist/utils/warnings.d.ts +0 -16
  317. package/dist/utils/warnings.js +0 -16
  318. package/dist/utils/warnings.js.map +0 -1
  319. package/dist/zero/css-writer.d.ts +0 -45
  320. package/dist/zero/css-writer.js +0 -73
  321. package/dist/zero/css-writer.js.map +0 -1
  322. package/dist/zero/extractor.d.ts +0 -24
  323. package/dist/zero/extractor.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"useProperty.js","names":[],"sources":["../../src/hooks/useProperty.ts"],"sourcesContent":["import { getGlobalInjector } from '../config';\nimport { getStyleTarget, pushRSCCSS } from '../rsc-cache';\nimport { formatPropertyCSS } from '../ssr/format-property';\n\nexport interface UsePropertyOptions {\n /**\n * CSS syntax string for the property (e.g., '<color>', '<length>', '<angle>').\n * For color tokens (#name), this is auto-set to '<color>' and cannot be overridden.\n * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@property/syntax\n */\n syntax?: string;\n /**\n * Whether the property inherits from parent elements\n * @default true\n */\n inherits?: boolean;\n /**\n * Initial value for the property.\n * For color tokens (#name), this defaults to 'transparent' if not specified.\n */\n initialValue?: string | number;\n /**\n * Shadow root or document to inject into\n */\n root?: Document | ShadowRoot;\n}\n\n/**\n * Register a CSS @property custom property.\n * This enables advanced features like animating custom properties.\n *\n * Note: @property rules are global and persistent once defined.\n * The function ensures the property is only registered once per root.\n *\n * Accepts tasty token syntax for the property name:\n * - `$name` → defines `--name`\n * - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')\n * - `--name` → defines `--name` (legacy format)\n *\n * Works in all environments: client, SSR with collector, and React Server Components.\n *\n * @param name - The property token ($name, #name) or CSS property name (--name)\n * @param options - Property configuration\n *\n * @example Basic property with token syntax\n * ```tsx\n * function Spinner() {\n * useProperty('$rotation', {\n * syntax: '<angle>',\n * inherits: false,\n * initialValue: '0deg',\n * });\n *\n * return <div className=\"spinner\" />;\n * }\n * ```\n *\n * @example Color property with token syntax (auto-sets syntax)\n * ```tsx\n * function MyComponent() {\n * useProperty('#theme', {\n * initialValue: 'red', // syntax: '<color>' is auto-set\n * });\n *\n * // Now --theme-color can be animated with CSS transitions\n * return <div style={{ '--theme-color': 'blue' } as React.CSSProperties}>Colored</div>;\n * }\n * ```\n *\n * @example Legacy format (still supported)\n * ```tsx\n * function ResizableBox() {\n * useProperty('--box-size', {\n * syntax: '<length>',\n * initialValue: '100px',\n * });\n *\n * return <div style={{ width: 'var(--box-size)' }} />;\n * }\n * ```\n */\nexport function useProperty(name: string, options?: UsePropertyOptions): void {\n if (!name) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`[Tasty] useProperty: property name is required`);\n }\n return;\n }\n\n const target = getStyleTarget();\n\n if (target.mode === 'ssr') {\n target.collector.collectInternals();\n\n const css = formatPropertyCSS(name, {\n syntax: options?.syntax,\n inherits: options?.inherits,\n initialValue: options?.initialValue,\n });\n if (css) {\n target.collector.collectProperty(name, css);\n }\n return;\n }\n\n if (target.mode === 'rsc') {\n const css = formatPropertyCSS(name, {\n syntax: options?.syntax,\n inherits: options?.inherits,\n initialValue: options?.initialValue,\n });\n if (css) {\n pushRSCCSS(target.cache, `__prop:${name}`, css);\n }\n return;\n }\n\n const injector = getGlobalInjector();\n\n if (injector.isPropertyDefined(name, { root: options?.root })) {\n return;\n }\n\n injector.property(name, {\n syntax: options?.syntax,\n inherits: options?.inherits,\n initialValue: options?.initialValue,\n root: options?.root,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,SAAgB,YAAY,MAAc,SAAoC;AAC5E,KAAI,CAAC,MAAM;AAEP,UAAQ,KAAK,iDAAiD;AAEhE;;CAGF,MAAM,SAAS,gBAAgB;AAE/B,KAAI,OAAO,SAAS,OAAO;AACzB,SAAO,UAAU,kBAAkB;EAEnC,MAAM,MAAM,kBAAkB,MAAM;GAClC,QAAQ,SAAS;GACjB,UAAU,SAAS;GACnB,cAAc,SAAS;GACxB,CAAC;AACF,MAAI,IACF,QAAO,UAAU,gBAAgB,MAAM,IAAI;AAE7C;;AAGF,KAAI,OAAO,SAAS,OAAO;EACzB,MAAM,MAAM,kBAAkB,MAAM;GAClC,QAAQ,SAAS;GACjB,UAAU,SAAS;GACnB,cAAc,SAAS;GACxB,CAAC;AACF,MAAI,IACF,YAAW,OAAO,OAAO,UAAU,QAAQ,IAAI;AAEjD;;CAGF,MAAM,WAAW,mBAAmB;AAEpC,KAAI,SAAS,kBAAkB,MAAM,EAAE,MAAM,SAAS,MAAM,CAAC,CAC3D;AAGF,UAAS,SAAS,MAAM;EACtB,QAAQ,SAAS;EACjB,UAAU,SAAS;EACnB,cAAc,SAAS;EACvB,MAAM,SAAS;EAChB,CAAC"}
@@ -1,22 +0,0 @@
1
- //#region src/hooks/useRawCSS.d.ts
2
- interface UseRawCSSOptions {
3
- /**
4
- * Shadow root or document to inject into.
5
- * Note: `root` is not part of the update-tracking comparison — changing
6
- * only the root for the same id/content will not re-inject.
7
- */
8
- root?: Document | ShadowRoot;
9
- /**
10
- * Stable identifier for update tracking (client-only). When provided,
11
- * changing the CSS content will dispose the previous injection and inject
12
- * the new one. Without an id, deduplication is purely content-based (same
13
- * CSS is injected only once). In RSC mode, renders are single-pass so
14
- * update tracking does not apply.
15
- */
16
- id?: string;
17
- }
18
- declare function useRawCSS(css: string, options?: UseRawCSSOptions): void;
19
- declare function useRawCSS(factory: () => string, deps: readonly unknown[], options?: UseRawCSSOptions): void;
20
- //#endregion
21
- export { useRawCSS };
22
- //# sourceMappingURL=useRawCSS.d.ts.map
@@ -1,103 +0,0 @@
1
- import { hashString } from "../utils/hash.js";
2
- import { injectRawCSS } from "../injector/index.js";
3
- import { getStyleTarget, pushRSCCSS } from "../rsc-cache.js";
4
- import { depsEqual } from "../utils/deps-equal.js";
5
- //#region src/hooks/useRawCSS.ts
6
- const clientEntries = /* @__PURE__ */ new Map();
7
- const clientContentDedup = /* @__PURE__ */ new Set();
8
- const factoryDepsCache = /* @__PURE__ */ new Map();
9
- /**
10
- * Inject raw CSS text directly without parsing.
11
- * This is a low-overhead alternative for injecting global CSS that doesn't need tasty processing.
12
- *
13
- * The CSS is inserted into a separate style element (data-tasty-raw) to avoid conflicts
14
- * with tasty's chunked style sheets.
15
- *
16
- * Works in all environments: client, SSR with collector, and React Server Components.
17
- *
18
- * Injected styles are permanent — they are not cleaned up on component unmount.
19
- * Use the `id` option for update tracking when styles change over the
20
- * component lifecycle.
21
- *
22
- * @example Static CSS string
23
- * ```tsx
24
- * function GlobalStyles() {
25
- * useRawCSS(`
26
- * body {
27
- * margin: 0;
28
- * padding: 0;
29
- * font-family: sans-serif;
30
- * }
31
- * `);
32
- *
33
- * return null;
34
- * }
35
- * ```
36
- *
37
- * @example Factory function with dependencies
38
- * ```tsx
39
- * function ThemeStyles({ theme }: { theme: 'light' | 'dark' }) {
40
- * useRawCSS(() => `
41
- * :root {
42
- * --bg-color: ${theme === 'dark' ? '#1a1a1a' : '#ffffff'};
43
- * --text-color: ${theme === 'dark' ? '#ffffff' : '#1a1a1a'};
44
- * }
45
- * `, [theme], { id: 'theme-vars' });
46
- *
47
- * return null;
48
- * }
49
- * ```
50
- *
51
- * @example With options
52
- * ```tsx
53
- * function ShadowStyles({ shadowRoot }) {
54
- * useRawCSS(() => `.scoped { color: red; }`, [], { root: shadowRoot });
55
- * return null;
56
- * }
57
- * ```
58
- */
59
- function useRawCSS(cssOrFactory, depsOrOptions, options) {
60
- const isFactory = typeof cssOrFactory === "function";
61
- const deps = isFactory && Array.isArray(depsOrOptions) ? depsOrOptions : void 0;
62
- const opts = isFactory ? options : depsOrOptions;
63
- const target = getStyleTarget();
64
- if (isFactory && deps && opts?.id && target.mode === "client") {
65
- const cachedDeps = factoryDepsCache.get(opts.id);
66
- if (cachedDeps && depsEqual(cachedDeps, deps)) return;
67
- }
68
- const css = isFactory ? cssOrFactory() : cssOrFactory;
69
- if (!css.trim()) return;
70
- if (target.mode === "ssr") {
71
- const key = opts?.id ? `raw:${opts.id}` : `raw:${hashString(css)}`;
72
- target.collector.collectRawCSS(key, css);
73
- return;
74
- }
75
- if (target.mode === "rsc") {
76
- const key = opts?.id ? `__raw:${opts.id}` : `__raw:${hashString(css)}`;
77
- pushRSCCSS(target.cache, key, css);
78
- return;
79
- }
80
- const id = opts?.id;
81
- if (id) {
82
- const existing = clientEntries.get(id);
83
- if (existing) {
84
- if (existing.contentKey === css) return;
85
- existing.dispose();
86
- }
87
- const { dispose } = injectRawCSS(css, opts);
88
- clientEntries.set(id, {
89
- contentKey: css,
90
- dispose
91
- });
92
- if (deps) factoryDepsCache.set(id, deps);
93
- } else {
94
- const contentKey = hashString(css);
95
- if (clientContentDedup.has(contentKey)) return;
96
- clientContentDedup.add(contentKey);
97
- injectRawCSS(css, opts);
98
- }
99
- }
100
- //#endregion
101
- export { useRawCSS };
102
-
103
- //# sourceMappingURL=useRawCSS.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useRawCSS.js","names":[],"sources":["../../src/hooks/useRawCSS.ts"],"sourcesContent":["import { injectRawCSS } from '../injector';\nimport { getStyleTarget, pushRSCCSS } from '../rsc-cache';\nimport { depsEqual } from '../utils/deps-equal';\nimport { hashString } from '../utils/hash';\n\ninterface UseRawCSSOptions {\n /**\n * Shadow root or document to inject into.\n * Note: `root` is not part of the update-tracking comparison — changing\n * only the root for the same id/content will not re-inject.\n */\n root?: Document | ShadowRoot;\n /**\n * Stable identifier for update tracking (client-only). When provided,\n * changing the CSS content will dispose the previous injection and inject\n * the new one. Without an id, deduplication is purely content-based (same\n * CSS is injected only once). In RSC mode, renders are single-pass so\n * update tracking does not apply.\n */\n id?: string;\n}\n\ninterface ClientEntry {\n contentKey: string;\n dispose: () => void;\n}\n\nconst clientEntries = new Map<string, ClientEntry>();\nconst clientContentDedup = new Set<string>();\nconst factoryDepsCache = new Map<string, readonly unknown[]>();\n\n/* @internal — used only for tests */\nexport function _resetRawCSSCache(): void {\n clientEntries.clear();\n clientContentDedup.clear();\n factoryDepsCache.clear();\n}\n\n// Overload 1: Static CSS string\nexport function useRawCSS(css: string, options?: UseRawCSSOptions): void;\n\n// Overload 2: Factory function with dependencies\nexport function useRawCSS(\n factory: () => string,\n deps: readonly unknown[],\n options?: UseRawCSSOptions,\n): void;\n\n/**\n * Inject raw CSS text directly without parsing.\n * This is a low-overhead alternative for injecting global CSS that doesn't need tasty processing.\n *\n * The CSS is inserted into a separate style element (data-tasty-raw) to avoid conflicts\n * with tasty's chunked style sheets.\n *\n * Works in all environments: client, SSR with collector, and React Server Components.\n *\n * Injected styles are permanent — they are not cleaned up on component unmount.\n * Use the `id` option for update tracking when styles change over the\n * component lifecycle.\n *\n * @example Static CSS string\n * ```tsx\n * function GlobalStyles() {\n * useRawCSS(`\n * body {\n * margin: 0;\n * padding: 0;\n * font-family: sans-serif;\n * }\n * `);\n *\n * return null;\n * }\n * ```\n *\n * @example Factory function with dependencies\n * ```tsx\n * function ThemeStyles({ theme }: { theme: 'light' | 'dark' }) {\n * useRawCSS(() => `\n * :root {\n * --bg-color: ${theme === 'dark' ? '#1a1a1a' : '#ffffff'};\n * --text-color: ${theme === 'dark' ? '#ffffff' : '#1a1a1a'};\n * }\n * `, [theme], { id: 'theme-vars' });\n *\n * return null;\n * }\n * ```\n *\n * @example With options\n * ```tsx\n * function ShadowStyles({ shadowRoot }) {\n * useRawCSS(() => `.scoped { color: red; }`, [], { root: shadowRoot });\n * return null;\n * }\n * ```\n */\nexport function useRawCSS(\n cssOrFactory: string | (() => string),\n depsOrOptions?: readonly unknown[] | UseRawCSSOptions,\n options?: UseRawCSSOptions,\n): void {\n const isFactory = typeof cssOrFactory === 'function';\n\n const deps =\n isFactory && Array.isArray(depsOrOptions) ? depsOrOptions : undefined;\n const opts = isFactory\n ? options\n : (depsOrOptions as UseRawCSSOptions | undefined);\n\n const target = getStyleTarget();\n\n // Client deps cache: skip factory re-evaluation when deps haven't changed\n if (isFactory && deps && opts?.id && target.mode === 'client') {\n const cachedDeps = factoryDepsCache.get(opts.id);\n if (cachedDeps && depsEqual(cachedDeps, deps)) {\n return;\n }\n }\n\n const css = isFactory\n ? (cssOrFactory as () => string)()\n : (cssOrFactory as string);\n\n if (!css.trim()) return;\n\n if (target.mode === 'ssr') {\n const key = opts?.id ? `raw:${opts.id}` : `raw:${hashString(css)}`;\n target.collector.collectRawCSS(key, css);\n return;\n }\n\n if (target.mode === 'rsc') {\n const key = opts?.id ? `__raw:${opts.id}` : `__raw:${hashString(css)}`;\n pushRSCCSS(target.cache, key, css);\n return;\n }\n\n // Client path\n const id = opts?.id;\n\n if (id) {\n const existing = clientEntries.get(id);\n if (existing) {\n if (existing.contentKey === css) return;\n existing.dispose();\n }\n\n const { dispose } = injectRawCSS(css, opts);\n clientEntries.set(id, { contentKey: css, dispose });\n if (deps) factoryDepsCache.set(id, deps);\n } else {\n const contentKey = hashString(css);\n if (clientContentDedup.has(contentKey)) return;\n clientContentDedup.add(contentKey);\n injectRawCSS(css, opts);\n }\n}\n"],"mappings":";;;;;AA2BA,MAAM,gCAAgB,IAAI,KAA0B;AACpD,MAAM,qCAAqB,IAAI,KAAa;AAC5C,MAAM,mCAAmB,IAAI,KAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqE9D,SAAgB,UACd,cACA,eACA,SACM;CACN,MAAM,YAAY,OAAO,iBAAiB;CAE1C,MAAM,OACJ,aAAa,MAAM,QAAQ,cAAc,GAAG,gBAAgB,KAAA;CAC9D,MAAM,OAAO,YACT,UACC;CAEL,MAAM,SAAS,gBAAgB;AAG/B,KAAI,aAAa,QAAQ,MAAM,MAAM,OAAO,SAAS,UAAU;EAC7D,MAAM,aAAa,iBAAiB,IAAI,KAAK,GAAG;AAChD,MAAI,cAAc,UAAU,YAAY,KAAK,CAC3C;;CAIJ,MAAM,MAAM,YACP,cAA+B,GAC/B;AAEL,KAAI,CAAC,IAAI,MAAM,CAAE;AAEjB,KAAI,OAAO,SAAS,OAAO;EACzB,MAAM,MAAM,MAAM,KAAK,OAAO,KAAK,OAAO,OAAO,WAAW,IAAI;AAChE,SAAO,UAAU,cAAc,KAAK,IAAI;AACxC;;AAGF,KAAI,OAAO,SAAS,OAAO;EACzB,MAAM,MAAM,MAAM,KAAK,SAAS,KAAK,OAAO,SAAS,WAAW,IAAI;AACpE,aAAW,OAAO,OAAO,KAAK,IAAI;AAClC;;CAIF,MAAM,KAAK,MAAM;AAEjB,KAAI,IAAI;EACN,MAAM,WAAW,cAAc,IAAI,GAAG;AACtC,MAAI,UAAU;AACZ,OAAI,SAAS,eAAe,IAAK;AACjC,YAAS,SAAS;;EAGpB,MAAM,EAAE,YAAY,aAAa,KAAK,KAAK;AAC3C,gBAAc,IAAI,IAAI;GAAE,YAAY;GAAK;GAAS,CAAC;AACnD,MAAI,KAAM,kBAAiB,IAAI,IAAI,KAAK;QACnC;EACL,MAAM,aAAa,WAAW,IAAI;AAClC,MAAI,mBAAmB,IAAI,WAAW,CAAE;AACxC,qBAAmB,IAAI,WAAW;AAClC,eAAa,KAAK,KAAK"}
@@ -1,40 +0,0 @@
1
- import { Styles } from "../styles/types.js";
2
-
3
- //#region src/hooks/useStyles.d.ts
4
- /**
5
- * Tasty styles object to generate CSS classes for.
6
- * Can be undefined or empty object for no styles.
7
- */
8
- type UseStylesOptions = Styles | undefined;
9
- interface UseStylesResult {
10
- /**
11
- * Generated className(s) to apply to the element.
12
- * Can be empty string if no styles are provided.
13
- * With chunking enabled, may contain multiple space-separated class names.
14
- */
15
- className: string;
16
- }
17
- /**
18
- * Hook to generate CSS classes from Tasty styles.
19
- * Thin wrapper around `computeStyles()` that adds React context-based
20
- * SSR collector discovery for backward compatibility with TastyRegistry.
21
- *
22
- * For hook-free usage (e.g. in server components), use `computeStyles()` directly.
23
- *
24
- * @example
25
- * ```tsx
26
- * function MyComponent() {
27
- * const { className } = useStyles({
28
- * padding: '2x',
29
- * fill: '#purple',
30
- * radius: '1r',
31
- * });
32
- *
33
- * return <div className={className}>Styled content</div>;
34
- * }
35
- * ```
36
- */
37
- declare function useStyles(styles: UseStylesOptions): UseStylesResult;
38
- //#endregion
39
- export { UseStylesOptions, UseStylesResult, useStyles };
40
- //# sourceMappingURL=useStyles.d.ts.map
@@ -1,31 +0,0 @@
1
- import { computeStyles } from "../compute-styles.js";
2
- import { TastySSRContext } from "../ssr/context.js";
3
- import { useContext } from "react";
4
- //#region src/hooks/useStyles.ts
5
- /**
6
- * Hook to generate CSS classes from Tasty styles.
7
- * Thin wrapper around `computeStyles()` that adds React context-based
8
- * SSR collector discovery for backward compatibility with TastyRegistry.
9
- *
10
- * For hook-free usage (e.g. in server components), use `computeStyles()` directly.
11
- *
12
- * @example
13
- * ```tsx
14
- * function MyComponent() {
15
- * const { className } = useStyles({
16
- * padding: '2x',
17
- * fill: '#purple',
18
- * radius: '1r',
19
- * });
20
- *
21
- * return <div className={className}>Styled content</div>;
22
- * }
23
- * ```
24
- */
25
- function useStyles(styles) {
26
- return computeStyles(styles, { ssrCollector: useContext(TastySSRContext) });
27
- }
28
- //#endregion
29
- export { useStyles };
30
-
31
- //# sourceMappingURL=useStyles.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useStyles.js","names":[],"sources":["../../src/hooks/useStyles.ts"],"sourcesContent":["import { useContext } from 'react';\n\nimport { computeStyles } from '../compute-styles';\nimport { TastySSRContext } from '../ssr/context';\nimport type { Styles } from '../styles/types';\n\n/**\n * Tasty styles object to generate CSS classes for.\n * Can be undefined or empty object for no styles.\n */\nexport type UseStylesOptions = Styles | undefined;\n\nexport interface UseStylesResult {\n /**\n * Generated className(s) to apply to the element.\n * Can be empty string if no styles are provided.\n * With chunking enabled, may contain multiple space-separated class names.\n */\n className: string;\n}\n\n/**\n * Hook to generate CSS classes from Tasty styles.\n * Thin wrapper around `computeStyles()` that adds React context-based\n * SSR collector discovery for backward compatibility with TastyRegistry.\n *\n * For hook-free usage (e.g. in server components), use `computeStyles()` directly.\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const { className } = useStyles({\n * padding: '2x',\n * fill: '#purple',\n * radius: '1r',\n * });\n *\n * return <div className={className}>Styled content</div>;\n * }\n * ```\n */\nexport function useStyles(styles: UseStylesOptions): UseStylesResult {\n return computeStyles(styles, { ssrCollector: useContext(TastySSRContext) });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,UAAU,QAA2C;AACnE,QAAO,cAAc,QAAQ,EAAE,cAAc,WAAW,gBAAgB,EAAE,CAAC"}
@@ -1,182 +0,0 @@
1
- import { CacheMetrics, CounterStyleDescriptors, DisposeFunction, FontFaceDescriptors, FontFaceInput, GCConfig, GCOptions, GlobalInjectResult, InjectResult, KeyframesCacheEntry, KeyframesInfo, KeyframesResult, KeyframesSteps, PropertyDefinition, RawCSSResult, RootRegistry, RuleInfo, SheetInfo, StyleInjectorConfig, StyleRule, StyleUsage } from "./types.js";
2
- import { StyleResult } from "../pipeline/index.js";
3
- import { SheetManager } from "./sheet-manager.js";
4
- import { StyleInjector } from "./injector.js";
5
-
6
- //#region src/injector/index.d.ts
7
- /**
8
- * Inject styles and return className with dispose function
9
- */
10
- declare function inject(rules: StyleResult[], options?: {
11
- root?: Document | ShadowRoot;
12
- cacheKey?: string;
13
- }): InjectResult;
14
- /**
15
- * Inject global rules that should not reserve tasty class names
16
- */
17
- declare function injectGlobal(rules: StyleResult[], options?: {
18
- root?: Document | ShadowRoot;
19
- }): GlobalInjectResult;
20
- /**
21
- * Inject raw CSS text directly without parsing
22
- * This is a low-overhead method for injecting raw CSS that doesn't need tasty processing.
23
- * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking.
24
- *
25
- * @example
26
- * ```tsx
27
- * // Inject raw CSS
28
- * const { dispose } = injectRawCSS(`
29
- * body { margin: 0; padding: 0; }
30
- * .my-class { color: red; }
31
- * `);
32
- *
33
- * // Later, remove the injected CSS
34
- * dispose();
35
- * ```
36
- */
37
- declare function injectRawCSS(css: string, options?: {
38
- root?: Document | ShadowRoot;
39
- }): {
40
- dispose: () => void;
41
- };
42
- /**
43
- * Get raw CSS text for SSR
44
- */
45
- declare function getRawCSSText(options?: {
46
- root?: Document | ShadowRoot;
47
- }): string;
48
- /**
49
- * Inject keyframes and return object with toString() and dispose()
50
- */
51
- declare function keyframes(steps: KeyframesSteps, nameOrOptions?: string | {
52
- root?: Document | ShadowRoot;
53
- name?: string;
54
- }): KeyframesResult;
55
- interface PropertyOptions {
56
- /**
57
- * CSS syntax string for the property (e.g., '<color>', '<length>', '<angle>')
58
- * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@property/syntax
59
- */
60
- syntax?: string;
61
- /**
62
- * Whether the property inherits from parent elements
63
- * @default true
64
- */
65
- inherits?: boolean;
66
- /**
67
- * Initial value for the property
68
- */
69
- initialValue?: string | number;
70
- /**
71
- * Shadow root or document to inject into
72
- */
73
- root?: Document | ShadowRoot;
74
- }
75
- /**
76
- * Define a CSS @property custom property.
77
- * This enables advanced features like animating custom properties.
78
- *
79
- * Note: @property rules are global and persistent once defined.
80
- * Re-registering the same property name is a no-op.
81
- *
82
- * @param name - The custom property name (must start with --)
83
- * @param options - Property configuration
84
- *
85
- * @example
86
- * ```ts
87
- * // Define a color property that can be animated
88
- * property('--my-color', {
89
- * syntax: '<color>',
90
- * initialValue: 'red',
91
- * });
92
- *
93
- * // Define an angle property
94
- * property('--rotation', {
95
- * syntax: '<angle>',
96
- * inherits: false,
97
- * initialValue: '0deg',
98
- * });
99
- * ```
100
- */
101
- declare function property(name: string, options?: PropertyOptions): void;
102
- /**
103
- * Check if a CSS @property has already been defined
104
- *
105
- * @param name - The custom property name to check
106
- * @param options - Options including root
107
- */
108
- declare function isPropertyDefined(name: string, options?: {
109
- root?: Document | ShadowRoot;
110
- }): boolean;
111
- /**
112
- * Inject a CSS @font-face rule.
113
- *
114
- * Permanent and global — no dispose or ref-counting.
115
- * Deduplicates by content hash (family + descriptors).
116
- */
117
- declare function fontFace(family: string, descriptors: FontFaceDescriptors, options?: {
118
- root?: Document | ShadowRoot;
119
- }): void;
120
- /**
121
- * Inject a CSS @counter-style rule.
122
- *
123
- * Permanent and global — no dispose or ref-counting.
124
- * Deduplicates by name (first definition wins).
125
- */
126
- declare function counterStyle(name: string, descriptors: CounterStyleDescriptors, options?: {
127
- root?: Document | ShadowRoot;
128
- }): void;
129
- /**
130
- * Get CSS text from all sheets (for SSR)
131
- */
132
- declare function getCssText(options?: {
133
- root?: Document | ShadowRoot;
134
- }): string;
135
- /**
136
- * Collect only CSS used by a rendered subtree (like jest-styled-components).
137
- * Pass the container returned by render(...).
138
- */
139
- declare function getCssTextForNode(node: ParentNode | Element | DocumentFragment, options?: {
140
- root?: Document | ShadowRoot;
141
- }): string;
142
- /**
143
- * Force cleanup of unused rules
144
- */
145
- declare function cleanup(root?: Document | ShadowRoot): void;
146
- /**
147
- * Record a render-time usage hit for one or more classNames.
148
- * Used internally by computeStyles and tasty() to track usage for GC.
149
- * When the global touch counter reaches `touchInterval`, schedules GC.
150
- */
151
- declare function touch(className: string, options?: {
152
- root?: Document | ShadowRoot;
153
- }): void;
154
- /**
155
- * Synchronous garbage collection of unused styles.
156
- * Evicts the oldest unused styles when usageMap exceeds capacity.
157
- * With `{ force: true }`, removes ALL unused styles regardless of capacity.
158
- *
159
- * @returns Number of styles evicted.
160
- */
161
- declare function gc(options?: GCOptions): number;
162
- /**
163
- * Check if we're currently running in a test environment
164
- */
165
- declare function getIsTestEnvironment(): boolean;
166
- /**
167
- * Get the global injector instance for debugging
168
- */
169
- declare const injector: {
170
- readonly instance: StyleInjector;
171
- };
172
- /**
173
- * Destroy all resources and clean up
174
- */
175
- declare function destroy(root?: Document | ShadowRoot): void;
176
- /**
177
- * Create a new isolated injector instance
178
- */
179
- declare function createInjector(config?: Partial<StyleInjectorConfig>): StyleInjector;
180
- //#endregion
181
- export { PropertyOptions, cleanup, counterStyle, createInjector, destroy, fontFace, gc, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, touch };
182
- //# sourceMappingURL=index.d.ts.map
@@ -1,185 +0,0 @@
1
- import "./sheet-manager.js";
2
- import { StyleInjector } from "./injector.js";
3
- import { getConfig, getGlobalInjector, isTestEnvironment, markStylesGenerated } from "../config.js";
4
- //#region src/injector/index.ts
5
- /**
6
- * Inject styles and return className with dispose function
7
- */
8
- function inject(rules, options) {
9
- const injector = getGlobalInjector();
10
- markStylesGenerated();
11
- return injector.inject(rules, options);
12
- }
13
- /**
14
- * Inject global rules that should not reserve tasty class names
15
- */
16
- function injectGlobal(rules, options) {
17
- return getGlobalInjector().injectGlobal(rules, options);
18
- }
19
- /**
20
- * Inject raw CSS text directly without parsing
21
- * This is a low-overhead method for injecting raw CSS that doesn't need tasty processing.
22
- * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking.
23
- *
24
- * @example
25
- * ```tsx
26
- * // Inject raw CSS
27
- * const { dispose } = injectRawCSS(`
28
- * body { margin: 0; padding: 0; }
29
- * .my-class { color: red; }
30
- * `);
31
- *
32
- * // Later, remove the injected CSS
33
- * dispose();
34
- * ```
35
- */
36
- function injectRawCSS(css, options) {
37
- return getGlobalInjector().injectRawCSS(css, options);
38
- }
39
- /**
40
- * Get raw CSS text for SSR
41
- */
42
- function getRawCSSText(options) {
43
- return getGlobalInjector().getRawCSSText(options);
44
- }
45
- /**
46
- * Inject keyframes and return object with toString() and dispose()
47
- */
48
- function keyframes(steps, nameOrOptions) {
49
- return getGlobalInjector().keyframes(steps, nameOrOptions);
50
- }
51
- /**
52
- * Define a CSS @property custom property.
53
- * This enables advanced features like animating custom properties.
54
- *
55
- * Note: @property rules are global and persistent once defined.
56
- * Re-registering the same property name is a no-op.
57
- *
58
- * @param name - The custom property name (must start with --)
59
- * @param options - Property configuration
60
- *
61
- * @example
62
- * ```ts
63
- * // Define a color property that can be animated
64
- * property('--my-color', {
65
- * syntax: '<color>',
66
- * initialValue: 'red',
67
- * });
68
- *
69
- * // Define an angle property
70
- * property('--rotation', {
71
- * syntax: '<angle>',
72
- * inherits: false,
73
- * initialValue: '0deg',
74
- * });
75
- * ```
76
- */
77
- function property(name, options) {
78
- return getGlobalInjector().property(name, options);
79
- }
80
- /**
81
- * Check if a CSS @property has already been defined
82
- *
83
- * @param name - The custom property name to check
84
- * @param options - Options including root
85
- */
86
- function isPropertyDefined(name, options) {
87
- return getGlobalInjector().isPropertyDefined(name, options);
88
- }
89
- /**
90
- * Inject a CSS @font-face rule.
91
- *
92
- * Permanent and global — no dispose or ref-counting.
93
- * Deduplicates by content hash (family + descriptors).
94
- */
95
- function fontFace(family, descriptors, options) {
96
- return getGlobalInjector().fontFace(family, descriptors, options);
97
- }
98
- /**
99
- * Inject a CSS @counter-style rule.
100
- *
101
- * Permanent and global — no dispose or ref-counting.
102
- * Deduplicates by name (first definition wins).
103
- */
104
- function counterStyle(name, descriptors, options) {
105
- return getGlobalInjector().counterStyle(name, descriptors, options);
106
- }
107
- /**
108
- * Get CSS text from all sheets (for SSR)
109
- */
110
- function getCssText(options) {
111
- return getGlobalInjector().getCssText(options);
112
- }
113
- /**
114
- * Collect only CSS used by a rendered subtree (like jest-styled-components).
115
- * Pass the container returned by render(...).
116
- */
117
- function getCssTextForNode(node, options) {
118
- const classSet = /* @__PURE__ */ new Set();
119
- const readClasses = (el) => {
120
- const cls = el.getAttribute("class");
121
- if (!cls) return;
122
- for (const token of cls.split(/\s+/)) if (/^t[a-z0-9]+$/.test(token)) classSet.add(token);
123
- };
124
- if (node.getAttribute) readClasses(node);
125
- const elements = node.querySelectorAll ? node.querySelectorAll("[class]") : [];
126
- if (elements) elements.forEach(readClasses);
127
- return getGlobalInjector().getCssTextForClasses(classSet, options);
128
- }
129
- /**
130
- * Force cleanup of unused rules
131
- */
132
- function cleanup(root) {
133
- return getGlobalInjector().cleanup(root);
134
- }
135
- /**
136
- * Record a render-time usage hit for one or more classNames.
137
- * Used internally by computeStyles and tasty() to track usage for GC.
138
- * When the global touch counter reaches `touchInterval`, schedules GC.
139
- */
140
- function touch(className, options) {
141
- if (!getConfig().gc) return;
142
- getGlobalInjector().touch(className, options);
143
- }
144
- /**
145
- * Synchronous garbage collection of unused styles.
146
- * Evicts the oldest unused styles when usageMap exceeds capacity.
147
- * With `{ force: true }`, removes ALL unused styles regardless of capacity.
148
- *
149
- * @returns Number of styles evicted.
150
- */
151
- function gc(options) {
152
- return getGlobalInjector().gc(options);
153
- }
154
- /**
155
- * Check if we're currently running in a test environment
156
- */
157
- function getIsTestEnvironment() {
158
- return isTestEnvironment();
159
- }
160
- /**
161
- * Get the global injector instance for debugging
162
- */
163
- const injector = { get instance() {
164
- return getGlobalInjector();
165
- } };
166
- /**
167
- * Destroy all resources and clean up
168
- */
169
- function destroy(root) {
170
- return getGlobalInjector().destroy(root);
171
- }
172
- /**
173
- * Create a new isolated injector instance
174
- */
175
- function createInjector(config = {}) {
176
- return new StyleInjector({
177
- ...getConfig(),
178
- forceTextInjection: config.forceTextInjection ?? isTestEnvironment(),
179
- ...config
180
- });
181
- }
182
- //#endregion
183
- export { cleanup, counterStyle, createInjector, destroy, fontFace, gc, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, touch };
184
-
185
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/injector/index.ts"],"sourcesContent":["import {\n getConfig,\n getGlobalInjector,\n isTestEnvironment,\n markStylesGenerated,\n} from '../config';\nimport type { StyleResult } from '../pipeline';\n\nimport { StyleInjector } from './injector';\nimport type {\n CounterStyleDescriptors,\n FontFaceDescriptors,\n GCOptions,\n GlobalInjectResult,\n InjectResult,\n KeyframesResult,\n KeyframesSteps,\n StyleInjectorConfig,\n} from './types';\n\n/**\n * Inject styles and return className with dispose function\n */\nexport function inject(\n rules: StyleResult[],\n options?: { root?: Document | ShadowRoot; cacheKey?: string },\n): InjectResult {\n const injector = getGlobalInjector();\n\n markStylesGenerated();\n\n return injector.inject(rules, options);\n}\n\n/**\n * Inject global rules that should not reserve tasty class names\n */\nexport function injectGlobal(\n rules: StyleResult[],\n options?: { root?: Document | ShadowRoot },\n): GlobalInjectResult {\n return getGlobalInjector().injectGlobal(rules, options);\n}\n\n/**\n * Inject raw CSS text directly without parsing\n * This is a low-overhead method for injecting raw CSS that doesn't need tasty processing.\n * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking.\n *\n * @example\n * ```tsx\n * // Inject raw CSS\n * const { dispose } = injectRawCSS(`\n * body { margin: 0; padding: 0; }\n * .my-class { color: red; }\n * `);\n *\n * // Later, remove the injected CSS\n * dispose();\n * ```\n */\nexport function injectRawCSS(\n css: string,\n options?: { root?: Document | ShadowRoot },\n): { dispose: () => void } {\n return getGlobalInjector().injectRawCSS(css, options);\n}\n\n/**\n * Get raw CSS text for SSR\n */\nexport function getRawCSSText(options?: {\n root?: Document | ShadowRoot;\n}): string {\n return getGlobalInjector().getRawCSSText(options);\n}\n\n/**\n * Inject keyframes and return object with toString() and dispose()\n */\nexport function keyframes(\n steps: KeyframesSteps,\n nameOrOptions?: string | { root?: Document | ShadowRoot; name?: string },\n): KeyframesResult {\n return getGlobalInjector().keyframes(steps, nameOrOptions);\n}\n\nexport interface PropertyOptions {\n /**\n * CSS syntax string for the property (e.g., '<color>', '<length>', '<angle>')\n * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@property/syntax\n */\n syntax?: string;\n /**\n * Whether the property inherits from parent elements\n * @default true\n */\n inherits?: boolean;\n /**\n * Initial value for the property\n */\n initialValue?: string | number;\n /**\n * Shadow root or document to inject into\n */\n root?: Document | ShadowRoot;\n}\n\n/**\n * Define a CSS @property custom property.\n * This enables advanced features like animating custom properties.\n *\n * Note: @property rules are global and persistent once defined.\n * Re-registering the same property name is a no-op.\n *\n * @param name - The custom property name (must start with --)\n * @param options - Property configuration\n *\n * @example\n * ```ts\n * // Define a color property that can be animated\n * property('--my-color', {\n * syntax: '<color>',\n * initialValue: 'red',\n * });\n *\n * // Define an angle property\n * property('--rotation', {\n * syntax: '<angle>',\n * inherits: false,\n * initialValue: '0deg',\n * });\n * ```\n */\nexport function property(name: string, options?: PropertyOptions): void {\n return getGlobalInjector().property(name, options);\n}\n\n/**\n * Check if a CSS @property has already been defined\n *\n * @param name - The custom property name to check\n * @param options - Options including root\n */\nexport function isPropertyDefined(\n name: string,\n options?: { root?: Document | ShadowRoot },\n): boolean {\n return getGlobalInjector().isPropertyDefined(name, options);\n}\n\n/**\n * Inject a CSS @font-face rule.\n *\n * Permanent and global — no dispose or ref-counting.\n * Deduplicates by content hash (family + descriptors).\n */\nexport function fontFace(\n family: string,\n descriptors: FontFaceDescriptors,\n options?: { root?: Document | ShadowRoot },\n): void {\n return getGlobalInjector().fontFace(family, descriptors, options);\n}\n\n/**\n * Inject a CSS @counter-style rule.\n *\n * Permanent and global — no dispose or ref-counting.\n * Deduplicates by name (first definition wins).\n */\nexport function counterStyle(\n name: string,\n descriptors: CounterStyleDescriptors,\n options?: { root?: Document | ShadowRoot },\n): void {\n return getGlobalInjector().counterStyle(name, descriptors, options);\n}\n\n/**\n * Get CSS text from all sheets (for SSR)\n */\nexport function getCssText(options?: { root?: Document | ShadowRoot }): string {\n return getGlobalInjector().getCssText(options);\n}\n\n/**\n * Collect only CSS used by a rendered subtree (like jest-styled-components).\n * Pass the container returned by render(...).\n */\nexport function getCssTextForNode(\n node: ParentNode | Element | DocumentFragment,\n options?: { root?: Document | ShadowRoot },\n): string {\n // Collect tasty-generated class names (t<number>) from the subtree\n const classSet = new Set<string>();\n\n const readClasses = (el: Element) => {\n const cls = el.getAttribute('class');\n if (!cls) return;\n for (const token of cls.split(/\\s+/)) {\n if (/^t[a-z0-9]+$/.test(token)) classSet.add(token);\n }\n };\n\n // Include node itself if it's an Element\n if ((node as Element).getAttribute) {\n readClasses(node as Element);\n }\n // Walk descendants\n const elements = (node as ParentNode).querySelectorAll\n ? (node as ParentNode).querySelectorAll('[class]')\n : ([] as unknown as NodeListOf<Element>);\n if (elements) elements.forEach(readClasses);\n\n return getGlobalInjector().getCssTextForClasses(classSet, options);\n}\n\n/**\n * Force cleanup of unused rules\n */\nexport function cleanup(root?: Document | ShadowRoot): void {\n return getGlobalInjector().cleanup(root);\n}\n\n/**\n * Record a render-time usage hit for one or more classNames.\n * Used internally by computeStyles and tasty() to track usage for GC.\n * When the global touch counter reaches `touchInterval`, schedules GC.\n */\nexport function touch(\n className: string,\n options?: { root?: Document | ShadowRoot },\n): void {\n if (!getConfig().gc) return;\n getGlobalInjector().touch(className, options);\n}\n\n/**\n * Synchronous garbage collection of unused styles.\n * Evicts the oldest unused styles when usageMap exceeds capacity.\n * With `{ force: true }`, removes ALL unused styles regardless of capacity.\n *\n * @returns Number of styles evicted.\n */\nexport function gc(options?: GCOptions): number {\n return getGlobalInjector().gc(options);\n}\n\n/**\n * Check if we're currently running in a test environment\n */\nexport function getIsTestEnvironment(): boolean {\n return isTestEnvironment();\n}\n\n/**\n * Get the global injector instance for debugging\n */\nexport const injector = {\n get instance() {\n return getGlobalInjector();\n },\n};\n\n/**\n * Destroy all resources and clean up\n */\nexport function destroy(root?: Document | ShadowRoot): void {\n return getGlobalInjector().destroy(root);\n}\n\n/**\n * Create a new isolated injector instance\n */\nexport function createInjector(\n config: Partial<StyleInjectorConfig> = {},\n): StyleInjector {\n const defaultConfig = getConfig();\n\n const fullConfig: StyleInjectorConfig = {\n ...defaultConfig,\n // Auto-enable forceTextInjection in test environments\n forceTextInjection: config.forceTextInjection ?? isTestEnvironment(),\n ...config,\n };\n\n return new StyleInjector(fullConfig);\n}\n\n// Re-export types\nexport type {\n StyleInjectorConfig,\n InjectResult,\n DisposeFunction,\n RuleInfo,\n SheetInfo,\n RootRegistry,\n StyleRule,\n KeyframesInfo,\n KeyframesResult,\n KeyframesSteps,\n KeyframesCacheEntry,\n CacheMetrics,\n RawCSSResult,\n PropertyDefinition,\n FontFaceDescriptors,\n FontFaceInput,\n CounterStyleDescriptors,\n StyleUsage,\n GCConfig,\n GCOptions,\n} from './types';\n\nexport { StyleInjector } from './injector';\nexport { SheetManager } from './sheet-manager';\n"],"mappings":";;;;;;;AAuBA,SAAgB,OACd,OACA,SACc;CACd,MAAM,WAAW,mBAAmB;AAEpC,sBAAqB;AAErB,QAAO,SAAS,OAAO,OAAO,QAAQ;;;;;AAMxC,SAAgB,aACd,OACA,SACoB;AACpB,QAAO,mBAAmB,CAAC,aAAa,OAAO,QAAQ;;;;;;;;;;;;;;;;;;;AAoBzD,SAAgB,aACd,KACA,SACyB;AACzB,QAAO,mBAAmB,CAAC,aAAa,KAAK,QAAQ;;;;;AAMvD,SAAgB,cAAc,SAEnB;AACT,QAAO,mBAAmB,CAAC,cAAc,QAAQ;;;;;AAMnD,SAAgB,UACd,OACA,eACiB;AACjB,QAAO,mBAAmB,CAAC,UAAU,OAAO,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkD5D,SAAgB,SAAS,MAAc,SAAiC;AACtE,QAAO,mBAAmB,CAAC,SAAS,MAAM,QAAQ;;;;;;;;AASpD,SAAgB,kBACd,MACA,SACS;AACT,QAAO,mBAAmB,CAAC,kBAAkB,MAAM,QAAQ;;;;;;;;AAS7D,SAAgB,SACd,QACA,aACA,SACM;AACN,QAAO,mBAAmB,CAAC,SAAS,QAAQ,aAAa,QAAQ;;;;;;;;AASnE,SAAgB,aACd,MACA,aACA,SACM;AACN,QAAO,mBAAmB,CAAC,aAAa,MAAM,aAAa,QAAQ;;;;;AAMrE,SAAgB,WAAW,SAAoD;AAC7E,QAAO,mBAAmB,CAAC,WAAW,QAAQ;;;;;;AAOhD,SAAgB,kBACd,MACA,SACQ;CAER,MAAM,2BAAW,IAAI,KAAa;CAElC,MAAM,eAAe,OAAgB;EACnC,MAAM,MAAM,GAAG,aAAa,QAAQ;AACpC,MAAI,CAAC,IAAK;AACV,OAAK,MAAM,SAAS,IAAI,MAAM,MAAM,CAClC,KAAI,eAAe,KAAK,MAAM,CAAE,UAAS,IAAI,MAAM;;AAKvD,KAAK,KAAiB,aACpB,aAAY,KAAgB;CAG9B,MAAM,WAAY,KAAoB,mBACjC,KAAoB,iBAAiB,UAAU,GAC/C,EAAE;AACP,KAAI,SAAU,UAAS,QAAQ,YAAY;AAE3C,QAAO,mBAAmB,CAAC,qBAAqB,UAAU,QAAQ;;;;;AAMpE,SAAgB,QAAQ,MAAoC;AAC1D,QAAO,mBAAmB,CAAC,QAAQ,KAAK;;;;;;;AAQ1C,SAAgB,MACd,WACA,SACM;AACN,KAAI,CAAC,WAAW,CAAC,GAAI;AACrB,oBAAmB,CAAC,MAAM,WAAW,QAAQ;;;;;;;;;AAU/C,SAAgB,GAAG,SAA6B;AAC9C,QAAO,mBAAmB,CAAC,GAAG,QAAQ;;;;;AAMxC,SAAgB,uBAAgC;AAC9C,QAAO,mBAAmB;;;;;AAM5B,MAAa,WAAW,EACtB,IAAI,WAAW;AACb,QAAO,mBAAmB;GAE7B;;;;AAKD,SAAgB,QAAQ,MAAoC;AAC1D,QAAO,mBAAmB,CAAC,QAAQ,KAAK;;;;;AAM1C,SAAgB,eACd,SAAuC,EAAE,EAC1B;AAUf,QAAO,IAAI,cAP6B;EACtC,GAHoB,WAAW;EAK/B,oBAAoB,OAAO,sBAAsB,mBAAmB;EACpE,GAAG;EACJ,CAEmC"}