@tenphi/tasty 0.0.0-snapshot.ef8cc29 → 0.0.0-snapshot.efb24cc

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 (298) hide show
  1. package/README.md +65 -215
  2. package/dist/_virtual/_rolldown/runtime.js +1 -2
  3. package/dist/chunks/cacheKey.d.ts +1 -0
  4. package/dist/chunks/cacheKey.js +1 -2
  5. package/dist/chunks/cacheKey.js.map +1 -1
  6. package/dist/chunks/definitions.d.ts +1 -1
  7. package/dist/chunks/definitions.js +2 -3
  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 +1 -2
  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 +105 -21
  17. package/dist/config.js +175 -49
  18. package/dist/config.js.map +1 -1
  19. package/dist/core/index.d.ts +7 -7
  20. package/dist/core/index.js +8 -8
  21. package/dist/counter-style/index.js +51 -0
  22. package/dist/counter-style/index.js.map +1 -0
  23. package/dist/debug.js +5 -6
  24. package/dist/debug.js.map +1 -1
  25. package/dist/font-face/index.js +63 -0
  26. package/dist/font-face/index.js.map +1 -0
  27. package/dist/hooks/index.d.ts +7 -0
  28. package/dist/hooks/useCounterStyle.d.ts +36 -0
  29. package/dist/hooks/useCounterStyle.js +65 -0
  30. package/dist/hooks/useCounterStyle.js.map +1 -0
  31. package/dist/hooks/useFontFace.d.ts +45 -0
  32. package/dist/hooks/useFontFace.js +66 -0
  33. package/dist/hooks/useFontFace.js.map +1 -0
  34. package/dist/hooks/useGlobalStyles.d.ts +18 -2
  35. package/dist/hooks/useGlobalStyles.js +52 -47
  36. package/dist/hooks/useGlobalStyles.js.map +1 -1
  37. package/dist/hooks/useKeyframes.d.ts +4 -2
  38. package/dist/hooks/useKeyframes.js +43 -57
  39. package/dist/hooks/useKeyframes.js.map +1 -1
  40. package/dist/hooks/useProperty.d.ts +4 -2
  41. package/dist/hooks/useProperty.js +30 -48
  42. package/dist/hooks/useProperty.js.map +1 -1
  43. package/dist/hooks/useRawCSS.d.ts +13 -44
  44. package/dist/hooks/useRawCSS.js +91 -28
  45. package/dist/hooks/useRawCSS.js.map +1 -1
  46. package/dist/hooks/useStyles.d.ts +3 -8
  47. package/dist/hooks/useStyles.js +7 -225
  48. package/dist/hooks/useStyles.js.map +1 -1
  49. package/dist/index.d.ts +10 -8
  50. package/dist/index.js +11 -9
  51. package/dist/injector/index.d.ts +36 -19
  52. package/dist/injector/index.js +43 -20
  53. package/dist/injector/index.js.map +1 -1
  54. package/dist/injector/injector.d.ts +53 -3
  55. package/dist/injector/injector.js +235 -14
  56. package/dist/injector/injector.js.map +1 -1
  57. package/dist/injector/sheet-manager.d.ts +9 -13
  58. package/dist/injector/sheet-manager.js +41 -71
  59. package/dist/injector/sheet-manager.js.map +1 -1
  60. package/dist/injector/types.d.ts +112 -21
  61. package/dist/keyframes/index.js +1 -1
  62. package/dist/parser/classify.js +4 -5
  63. package/dist/parser/classify.js.map +1 -1
  64. package/dist/parser/const.js +30 -3
  65. package/dist/parser/const.js.map +1 -1
  66. package/dist/parser/lru.js +1 -1
  67. package/dist/parser/lru.js.map +1 -1
  68. package/dist/parser/parser.js +1 -2
  69. package/dist/parser/parser.js.map +1 -1
  70. package/dist/parser/tokenizer.js +1 -1
  71. package/dist/parser/tokenizer.js.map +1 -1
  72. package/dist/parser/types.js +1 -1
  73. package/dist/parser/types.js.map +1 -1
  74. package/dist/pipeline/conditions.js +1 -1
  75. package/dist/pipeline/conditions.js.map +1 -1
  76. package/dist/pipeline/exclusive.js +58 -4
  77. package/dist/pipeline/exclusive.js.map +1 -1
  78. package/dist/pipeline/index.d.ts +2 -0
  79. package/dist/pipeline/index.js +39 -12
  80. package/dist/pipeline/index.js.map +1 -1
  81. package/dist/pipeline/materialize.js +57 -5
  82. package/dist/pipeline/materialize.js.map +1 -1
  83. package/dist/pipeline/parseStateKey.js +5 -6
  84. package/dist/pipeline/parseStateKey.js.map +1 -1
  85. package/dist/pipeline/simplify.js +181 -7
  86. package/dist/pipeline/simplify.js.map +1 -1
  87. package/dist/pipeline/warnings.js +1 -1
  88. package/dist/plugins/index.d.ts +2 -0
  89. package/dist/plugins/okhsl-plugin.js +1 -2
  90. package/dist/plugins/okhsl-plugin.js.map +1 -1
  91. package/dist/plugins/types.d.ts +12 -1
  92. package/dist/properties/index.js +2 -3
  93. package/dist/properties/index.js.map +1 -1
  94. package/dist/properties/property-type-resolver.js +1 -2
  95. package/dist/properties/property-type-resolver.js.map +1 -1
  96. package/dist/rsc-cache.js +79 -0
  97. package/dist/rsc-cache.js.map +1 -0
  98. package/dist/ssr/astro-client.d.ts +1 -0
  99. package/dist/ssr/astro-client.js +19 -0
  100. package/dist/ssr/astro-client.js.map +1 -0
  101. package/dist/ssr/astro-middleware.d.ts +15 -0
  102. package/dist/ssr/astro-middleware.js +19 -0
  103. package/dist/ssr/astro-middleware.js.map +1 -0
  104. package/dist/ssr/astro.d.ts +89 -10
  105. package/dist/ssr/astro.js +113 -29
  106. package/dist/ssr/astro.js.map +1 -1
  107. package/dist/ssr/async-storage.js +15 -6
  108. package/dist/ssr/async-storage.js.map +1 -1
  109. package/dist/ssr/collect-auto-properties.js +29 -11
  110. package/dist/ssr/collect-auto-properties.js.map +1 -1
  111. package/dist/ssr/collector.d.ts +26 -13
  112. package/dist/ssr/collector.js +84 -32
  113. package/dist/ssr/collector.js.map +1 -1
  114. package/dist/ssr/context.js +4 -2
  115. package/dist/ssr/context.js.map +1 -1
  116. package/dist/ssr/format-global-rules.js +1 -1
  117. package/dist/ssr/format-keyframes.js +1 -2
  118. package/dist/ssr/format-keyframes.js.map +1 -1
  119. package/dist/ssr/format-property.js +1 -2
  120. package/dist/ssr/format-property.js.map +1 -1
  121. package/dist/ssr/format-rules.js +8 -5
  122. package/dist/ssr/format-rules.js.map +1 -1
  123. package/dist/ssr/hydrate.d.ts +20 -13
  124. package/dist/ssr/hydrate.js +25 -30
  125. package/dist/ssr/hydrate.js.map +1 -1
  126. package/dist/ssr/index.d.ts +3 -4
  127. package/dist/ssr/index.js +5 -7
  128. package/dist/ssr/index.js.map +1 -1
  129. package/dist/ssr/next.d.ts +6 -5
  130. package/dist/ssr/next.js +14 -10
  131. package/dist/ssr/next.js.map +1 -1
  132. package/dist/ssr/ssr-collector-ref.js +20 -3
  133. package/dist/ssr/ssr-collector-ref.js.map +1 -1
  134. package/dist/states/index.js +3 -2
  135. package/dist/states/index.js.map +1 -1
  136. package/dist/static/index.js +1 -2
  137. package/dist/static/inject.d.ts +5 -0
  138. package/dist/static/inject.js +17 -0
  139. package/dist/static/inject.js.map +1 -0
  140. package/dist/static/tastyStatic.js +1 -2
  141. package/dist/static/tastyStatic.js.map +1 -1
  142. package/dist/static/types.js +1 -1
  143. package/dist/styles/border.d.ts +1 -1
  144. package/dist/styles/border.js +30 -24
  145. package/dist/styles/border.js.map +1 -1
  146. package/dist/styles/color.d.ts +1 -1
  147. package/dist/styles/color.js +2 -3
  148. package/dist/styles/color.js.map +1 -1
  149. package/dist/styles/const.js +17 -0
  150. package/dist/styles/const.js.map +1 -0
  151. package/dist/styles/createStyle.js +4 -5
  152. package/dist/styles/createStyle.js.map +1 -1
  153. package/dist/styles/dimension.js +15 -3
  154. package/dist/styles/dimension.js.map +1 -1
  155. package/dist/styles/directional.js +133 -0
  156. package/dist/styles/directional.js.map +1 -0
  157. package/dist/styles/display.d.ts +3 -10
  158. package/dist/styles/display.js +45 -39
  159. package/dist/styles/display.js.map +1 -1
  160. package/dist/styles/fade.d.ts +1 -1
  161. package/dist/styles/fade.js +9 -5
  162. package/dist/styles/fade.js.map +1 -1
  163. package/dist/styles/fill.d.ts +2 -2
  164. package/dist/styles/fill.js +3 -4
  165. package/dist/styles/fill.js.map +1 -1
  166. package/dist/styles/flow.js +1 -1
  167. package/dist/styles/gap.d.ts +1 -1
  168. package/dist/styles/gap.js +4 -3
  169. package/dist/styles/gap.js.map +1 -1
  170. package/dist/styles/height.d.ts +1 -1
  171. package/dist/styles/height.js +1 -2
  172. package/dist/styles/height.js.map +1 -1
  173. package/dist/styles/index.d.ts +0 -1
  174. package/dist/styles/index.js +3 -4
  175. package/dist/styles/index.js.map +1 -1
  176. package/dist/styles/inset.d.ts +1 -29
  177. package/dist/styles/inset.js +19 -135
  178. package/dist/styles/inset.js.map +1 -1
  179. package/dist/styles/list.d.ts +5 -5
  180. package/dist/styles/list.js +4 -2
  181. package/dist/styles/list.js.map +1 -1
  182. package/dist/styles/margin.d.ts +1 -1
  183. package/dist/styles/margin.js +17 -89
  184. package/dist/styles/margin.js.map +1 -1
  185. package/dist/styles/outline.d.ts +1 -1
  186. package/dist/styles/outline.js +6 -16
  187. package/dist/styles/outline.js.map +1 -1
  188. package/dist/styles/padding.d.ts +1 -1
  189. package/dist/styles/padding.js +17 -89
  190. package/dist/styles/padding.js.map +1 -1
  191. package/dist/styles/placement.d.ts +37 -0
  192. package/dist/styles/placement.js +74 -0
  193. package/dist/styles/placement.js.map +1 -0
  194. package/dist/styles/predefined.d.ts +4 -4
  195. package/dist/styles/predefined.js +8 -9
  196. package/dist/styles/predefined.js.map +1 -1
  197. package/dist/styles/preset.d.ts +6 -1
  198. package/dist/styles/preset.js +54 -53
  199. package/dist/styles/preset.js.map +1 -1
  200. package/dist/styles/radius.d.ts +1 -3
  201. package/dist/styles/radius.js +38 -6
  202. package/dist/styles/radius.js.map +1 -1
  203. package/dist/styles/scrollMargin.d.ts +24 -0
  204. package/dist/styles/scrollMargin.js +32 -0
  205. package/dist/styles/scrollMargin.js.map +1 -0
  206. package/dist/styles/scrollbar.d.ts +1 -1
  207. package/dist/styles/scrollbar.js +8 -5
  208. package/dist/styles/scrollbar.js.map +1 -1
  209. package/dist/styles/shadow.d.ts +1 -1
  210. package/dist/styles/shadow.js +4 -3
  211. package/dist/styles/shadow.js.map +1 -1
  212. package/dist/styles/shared.js +17 -0
  213. package/dist/styles/shared.js.map +1 -0
  214. package/dist/styles/transition.d.ts +1 -1
  215. package/dist/styles/transition.js +5 -4
  216. package/dist/styles/transition.js.map +1 -1
  217. package/dist/styles/types.d.ts +52 -11
  218. package/dist/styles/width.d.ts +1 -1
  219. package/dist/styles/width.js +1 -2
  220. package/dist/styles/width.js.map +1 -1
  221. package/dist/tasty.d.ts +46 -893
  222. package/dist/tasty.js +96 -67
  223. package/dist/tasty.js.map +1 -1
  224. package/dist/utils/cache-wrapper.js +1 -2
  225. package/dist/utils/cache-wrapper.js.map +1 -1
  226. package/dist/utils/case-converter.js +1 -1
  227. package/dist/utils/color-math.js +1 -1
  228. package/dist/utils/color-math.js.map +1 -1
  229. package/dist/utils/color-space.js +1 -2
  230. package/dist/utils/color-space.js.map +1 -1
  231. package/dist/utils/colors.js +1 -2
  232. package/dist/utils/colors.js.map +1 -1
  233. package/dist/utils/deps-equal.js +15 -0
  234. package/dist/utils/deps-equal.js.map +1 -0
  235. package/dist/utils/dotize.js +1 -1
  236. package/dist/utils/dotize.js.map +1 -1
  237. package/dist/utils/filter-base-props.d.ts +1 -1
  238. package/dist/utils/filter-base-props.js +1 -1
  239. package/dist/utils/filter-base-props.js.map +1 -1
  240. package/dist/utils/get-display-name.js +1 -1
  241. package/dist/utils/has-keys.js +1 -1
  242. package/dist/utils/hash.js +14 -0
  243. package/dist/utils/hash.js.map +1 -0
  244. package/dist/utils/is-dev-env.js +1 -1
  245. package/dist/utils/is-dev-env.js.map +1 -1
  246. package/dist/utils/is-valid-element-type.js +1 -1
  247. package/dist/utils/merge-styles.js +1 -2
  248. package/dist/utils/merge-styles.js.map +1 -1
  249. package/dist/utils/mod-attrs.d.ts +0 -2
  250. package/dist/utils/mod-attrs.js +1 -2
  251. package/dist/utils/mod-attrs.js.map +1 -1
  252. package/dist/utils/process-tokens.d.ts +1 -5
  253. package/dist/utils/process-tokens.js +3 -11
  254. package/dist/utils/process-tokens.js.map +1 -1
  255. package/dist/utils/resolve-recipes.js +1 -2
  256. package/dist/utils/resolve-recipes.js.map +1 -1
  257. package/dist/utils/selector-transform.js +1 -1
  258. package/dist/utils/string.js +1 -1
  259. package/dist/utils/styles.d.ts +1 -3
  260. package/dist/utils/styles.js +2 -5
  261. package/dist/utils/styles.js.map +1 -1
  262. package/dist/utils/typography.d.ts +21 -10
  263. package/dist/utils/typography.js +10 -2
  264. package/dist/utils/typography.js.map +1 -1
  265. package/dist/utils/warnings.js +1 -1
  266. package/dist/zero/babel.d.ts +27 -101
  267. package/dist/zero/babel.js +164 -48
  268. package/dist/zero/babel.js.map +1 -1
  269. package/dist/zero/css-writer.js +1 -2
  270. package/dist/zero/css-writer.js.map +1 -1
  271. package/dist/zero/extractor.js +54 -3
  272. package/dist/zero/extractor.js.map +1 -1
  273. package/dist/zero/index.js +1 -2
  274. package/dist/zero/next.d.ts +12 -0
  275. package/dist/zero/next.js +5 -4
  276. package/dist/zero/next.js.map +1 -1
  277. package/docs/README.md +2 -2
  278. package/docs/adoption.md +5 -3
  279. package/docs/comparison.md +24 -25
  280. package/docs/configuration.md +130 -1
  281. package/docs/design-system.md +47 -12
  282. package/docs/dsl.md +115 -9
  283. package/docs/getting-started.md +10 -10
  284. package/docs/injector.md +41 -25
  285. package/docs/methodology.md +119 -6
  286. package/docs/react-api.md +557 -0
  287. package/docs/ssr.md +141 -81
  288. package/docs/styles.md +45 -23
  289. package/docs/tasty-static.md +103 -2
  290. package/package.json +20 -9
  291. package/dist/ssr/context.d.ts +0 -8
  292. package/dist/styles/align.d.ts +0 -15
  293. package/dist/styles/align.js +0 -14
  294. package/dist/styles/align.js.map +0 -1
  295. package/dist/styles/justify.d.ts +0 -15
  296. package/dist/styles/justify.js +0 -14
  297. package/dist/styles/justify.js.map +0 -1
  298. package/docs/runtime.md +0 -317
package/dist/index.js CHANGED
@@ -10,25 +10,27 @@ import { StyleInjector } from "./injector/injector.js";
10
10
  import { createStateParserContext, getGlobalPredefinedStates, setGlobalPredefinedStates } from "./states/index.js";
11
11
  import { parseStateKey } from "./pipeline/parseStateKey.js";
12
12
  import { isSelector, renderStyles } from "./pipeline/index.js";
13
- import { configure, getConfig, getGlobalKeyframes, getGlobalRecipes, hasGlobalKeyframes, hasGlobalRecipes, hasStylesGenerated, isConfigLocked, isTestEnvironment, resetConfig } from "./config.js";
13
+ import { generateTypographyTokens } from "./utils/typography.js";
14
+ import { configure, getConfig, getGlobalCounterStyle, getGlobalFontFace, getGlobalKeyframes, getGlobalRecipes, hasGlobalKeyframes, hasGlobalRecipes, hasStylesGenerated, isConfigLocked, isTestEnvironment, resetConfig } from "./config.js";
14
15
  import { CHUNK_NAMES, STYLE_TO_CHUNK, categorizeStyleKeys } from "./chunks/definitions.js";
15
16
  import { BASE_STYLES, BLOCK_INNER_STYLES, BLOCK_OUTER_STYLES, BLOCK_STYLES, COLOR_STYLES, CONTAINER_STYLES, DIMENSION_STYLES, FLOW_STYLES, INNER_STYLES, OUTER_STYLES, POSITION_STYLES, TEXT_STYLES } from "./styles/list.js";
16
- import { allocateClassName, cleanup, createInjector, destroy, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, trackRef } from "./injector/index.js";
17
+ import { cleanup, counterStyle, createInjector, destroy, fontFace, gc, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, touch } from "./injector/index.js";
18
+ import { mergeStyles } from "./utils/merge-styles.js";
19
+ import { resolveRecipes } from "./utils/resolve-recipes.js";
20
+ import { computeStyles } from "./compute-styles.js";
17
21
  import { filterBaseProps } from "./utils/filter-base-props.js";
18
22
  import { color } from "./utils/colors.js";
19
23
  import { _modAttrs } from "./utils/mod-attrs.js";
20
24
  import { dotize } from "./utils/dotize.js";
21
- import { mergeStyles } from "./utils/merge-styles.js";
22
- import { resolveRecipes } from "./utils/resolve-recipes.js";
23
- import { processTokens, stringifyTokens } from "./utils/process-tokens.js";
24
- import { generateTypographyTokens } from "./utils/typography.js";
25
+ import { processTokens } from "./utils/process-tokens.js";
25
26
  import { tastyDebug } from "./debug.js";
26
- import { useStyles } from "./hooks/useStyles.js";
27
27
  import { getDisplayName } from "./utils/get-display-name.js";
28
28
  import { Element, tasty } from "./tasty.js";
29
+ import { useStyles } from "./hooks/useStyles.js";
29
30
  import { useGlobalStyles } from "./hooks/useGlobalStyles.js";
30
31
  import { useRawCSS } from "./hooks/useRawCSS.js";
31
32
  import { useKeyframes } from "./hooks/useKeyframes.js";
32
33
  import { useProperty } from "./hooks/useProperty.js";
33
-
34
- export { BASE_STYLES, BLOCK_INNER_STYLES, BLOCK_OUTER_STYLES, BLOCK_STYLES, Bucket, CHUNK_NAMES, COLOR_STYLES, CONTAINER_STYLES, CUSTOM_UNITS, DIMENSION_STYLES, DIRECTIONS, Element, FLOW_STYLES, INNER_STYLES, OUTER_STYLES, POSITION_STYLES, STYLE_TO_CHUNK, SheetManager, StyleInjector, StyleParser, TEXT_STYLES, allocateClassName, categorizeStyleKeys, cleanup, color, configure, createInjector, createStateParserContext, customFunc, deprecationWarning, destroy, dotize, filterBaseProps, filterMods, generateTypographyTokens, getConfig, getCssText, getCssTextForNode, getDisplayName, getGlobalFuncs, getGlobalKeyframes, getGlobalParser, getGlobalPredefinedStates, getGlobalPredefinedTokens, getGlobalRecipes, getIsTestEnvironment, getNamedColorHex, getRawCSSText, getRgbValuesFromRgbaString, hasGlobalKeyframes, hasGlobalRecipes, hasStylesGenerated, hexToRgb, hslToRgbValues, inject, injectGlobal, injectRawCSS, injector, isConfigLocked, isPropertyDefined, isSelector, isTestEnvironment, keyframes, mergeStyles, _modAttrs as modAttrs, normalizeColorTokenValue, okhslFunc, okhslPlugin, parseColor, parseStateKey, parseStyle, processTokens, property, renderStyles, resetConfig, resetGlobalPredefinedTokens, resolveRecipes, setGlobalPredefinedStates, setGlobalPredefinedTokens, strToRgb, stringifyStyles, stringifyTokens, styleHandlers, tasty, tastyDebug, trackRef, useGlobalStyles, useKeyframes, useProperty, useRawCSS, useStyles, warn };
34
+ import { useFontFace } from "./hooks/useFontFace.js";
35
+ import { useCounterStyle } from "./hooks/useCounterStyle.js";
36
+ export { BASE_STYLES, BLOCK_INNER_STYLES, BLOCK_OUTER_STYLES, BLOCK_STYLES, Bucket, CHUNK_NAMES, COLOR_STYLES, CONTAINER_STYLES, CUSTOM_UNITS, DIMENSION_STYLES, DIRECTIONS, Element, FLOW_STYLES, INNER_STYLES, OUTER_STYLES, POSITION_STYLES, STYLE_TO_CHUNK, SheetManager, StyleInjector, StyleParser, TEXT_STYLES, categorizeStyleKeys, cleanup, color, computeStyles, configure, counterStyle, createInjector, createStateParserContext, customFunc, deprecationWarning, destroy, dotize, filterBaseProps, filterMods, fontFace, gc, generateTypographyTokens, getConfig, getCssText, getCssTextForNode, getDisplayName, getGlobalCounterStyle, getGlobalFontFace, getGlobalFuncs, getGlobalKeyframes, getGlobalParser, getGlobalPredefinedStates, getGlobalPredefinedTokens, getGlobalRecipes, getIsTestEnvironment, getNamedColorHex, getRawCSSText, getRgbValuesFromRgbaString, hasGlobalKeyframes, hasGlobalRecipes, hasStylesGenerated, hexToRgb, hslToRgbValues, inject, injectGlobal, injectRawCSS, injector, isConfigLocked, isPropertyDefined, isSelector, isTestEnvironment, keyframes, mergeStyles, _modAttrs as modAttrs, normalizeColorTokenValue, okhslFunc, okhslPlugin, parseColor, parseStateKey, parseStyle, processTokens, property, renderStyles, resetConfig, resetGlobalPredefinedTokens, resolveRecipes, setGlobalPredefinedStates, setGlobalPredefinedTokens, strToRgb, stringifyStyles, styleHandlers, tasty, tastyDebug, touch, useCounterStyle, useFontFace, useGlobalStyles, useKeyframes, useProperty, useRawCSS, useStyles, warn };
@@ -1,26 +1,9 @@
1
- import { CacheMetrics, DisposeFunction, GlobalInjectResult, InjectResult, KeyframesCacheEntry, KeyframesInfo, KeyframesResult, KeyframesSteps, PropertyDefinition, RawCSSResult, RootRegistry, RuleInfo, SheetInfo, StyleInjectorConfig, StyleRule } from "./types.js";
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
2
  import { StyleResult } from "../pipeline/index.js";
3
3
  import { SheetManager } from "./sheet-manager.js";
4
4
  import { StyleInjector } from "./injector.js";
5
5
 
6
6
  //#region src/injector/index.d.ts
7
- /**
8
- * Allocate a className for a cacheKey without injecting styles yet
9
- */
10
- declare function allocateClassName(cacheKey: string, options?: {
11
- root?: Document | ShadowRoot;
12
- }): {
13
- className: string;
14
- isNewAllocation: boolean;
15
- };
16
- /**
17
- * Track a reference to an already-injected cacheKey (refCount + dispose).
18
- * Used on cache hits (SSR hydration or runtime reuse) where the pipeline
19
- * was skipped. Returns null if the cacheKey is not in the cache.
20
- */
21
- declare function trackRef(cacheKey: string, options?: {
22
- root?: Document | ShadowRoot;
23
- }): InjectResult | null;
24
7
  /**
25
8
  * Inject styles and return className with dispose function
26
9
  */
@@ -125,6 +108,24 @@ declare function property(name: string, options?: PropertyOptions): void;
125
108
  declare function isPropertyDefined(name: string, options?: {
126
109
  root?: Document | ShadowRoot;
127
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;
128
129
  /**
129
130
  * Get CSS text from all sheets (for SSR)
130
131
  */
@@ -142,6 +143,22 @@ declare function getCssTextForNode(node: ParentNode | Element | DocumentFragment
142
143
  * Force cleanup of unused rules
143
144
  */
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;
145
162
  /**
146
163
  * Check if we're currently running in a test environment
147
164
  */
@@ -161,5 +178,5 @@ declare function destroy(root?: Document | ShadowRoot): void;
161
178
  */
162
179
  declare function createInjector(config?: Partial<StyleInjectorConfig>): StyleInjector;
163
180
  //#endregion
164
- export { PropertyOptions, allocateClassName, cleanup, createInjector, destroy, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, trackRef };
181
+ export { PropertyOptions, cleanup, counterStyle, createInjector, destroy, fontFace, gc, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, touch };
165
182
  //# sourceMappingURL=index.d.ts.map
@@ -1,28 +1,14 @@
1
- import { SheetManager } from "./sheet-manager.js";
1
+ import "./sheet-manager.js";
2
2
  import { StyleInjector } from "./injector.js";
3
3
  import { getConfig, getGlobalInjector, isTestEnvironment, markStylesGenerated } from "../config.js";
4
-
5
4
  //#region src/injector/index.ts
6
5
  /**
7
- * Allocate a className for a cacheKey without injecting styles yet
8
- */
9
- function allocateClassName(cacheKey, options) {
10
- return getGlobalInjector().allocateClassName(cacheKey, options);
11
- }
12
- /**
13
- * Track a reference to an already-injected cacheKey (refCount + dispose).
14
- * Used on cache hits (SSR hydration or runtime reuse) where the pipeline
15
- * was skipped. Returns null if the cacheKey is not in the cache.
16
- */
17
- function trackRef(cacheKey, options) {
18
- return getGlobalInjector().trackRef(cacheKey, options);
19
- }
20
- /**
21
6
  * Inject styles and return className with dispose function
22
7
  */
23
8
  function inject(rules, options) {
9
+ const injector = getGlobalInjector();
24
10
  markStylesGenerated();
25
- return getGlobalInjector().inject(rules, options);
11
+ return injector.inject(rules, options);
26
12
  }
27
13
  /**
28
14
  * Inject global rules that should not reserve tasty class names
@@ -101,6 +87,24 @@ function isPropertyDefined(name, options) {
101
87
  return getGlobalInjector().isPropertyDefined(name, options);
102
88
  }
103
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
+ /**
104
108
  * Get CSS text from all sheets (for SSR)
105
109
  */
106
110
  function getCssText(options) {
@@ -115,7 +119,7 @@ function getCssTextForNode(node, options) {
115
119
  const readClasses = (el) => {
116
120
  const cls = el.getAttribute("class");
117
121
  if (!cls) return;
118
- for (const token of cls.split(/\s+/)) if (/^t\d+$/.test(token)) classSet.add(token);
122
+ for (const token of cls.split(/\s+/)) if (/^t[a-z0-9]+$/.test(token)) classSet.add(token);
119
123
  };
120
124
  if (node.getAttribute) readClasses(node);
121
125
  const elements = node.querySelectorAll ? node.querySelectorAll("[class]") : [];
@@ -129,6 +133,25 @@ function cleanup(root) {
129
133
  return getGlobalInjector().cleanup(root);
130
134
  }
131
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
+ /**
132
155
  * Check if we're currently running in a test environment
133
156
  */
134
157
  function getIsTestEnvironment() {
@@ -156,7 +179,7 @@ function createInjector(config = {}) {
156
179
  ...config
157
180
  });
158
181
  }
159
-
160
182
  //#endregion
161
- export { allocateClassName, cleanup, createInjector, destroy, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, trackRef };
183
+ export { cleanup, counterStyle, createInjector, destroy, fontFace, gc, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, touch };
184
+
162
185
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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 GlobalInjectResult,\n InjectResult,\n KeyframesResult,\n KeyframesSteps,\n StyleInjectorConfig,\n} from './types';\n\n/**\n * Allocate a className for a cacheKey without injecting styles yet\n */\nexport function allocateClassName(\n cacheKey: string,\n options?: { root?: Document | ShadowRoot },\n): { className: string; isNewAllocation: boolean } {\n return getGlobalInjector().allocateClassName(cacheKey, options);\n}\n\n/**\n * Track a reference to an already-injected cacheKey (refCount + dispose).\n * Used on cache hits (SSR hydration or runtime reuse) where the pipeline\n * was skipped. Returns null if the cacheKey is not in the cache.\n */\nexport function trackRef(\n cacheKey: string,\n options?: { root?: Document | ShadowRoot },\n): InjectResult | null {\n return getGlobalInjector().trackRef(cacheKey, options);\n}\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 // Mark that styles have been generated (prevents configuration changes)\n markStylesGenerated();\n\n return getGlobalInjector().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 * 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\\d+$/.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 * 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} from './types';\n\nexport { StyleInjector } from './injector';\nexport { SheetManager } from './sheet-manager';\n"],"mappings":";;;;;;;;AAoBA,SAAgB,kBACd,UACA,SACiD;AACjD,QAAO,mBAAmB,CAAC,kBAAkB,UAAU,QAAQ;;;;;;;AAQjE,SAAgB,SACd,UACA,SACqB;AACrB,QAAO,mBAAmB,CAAC,SAAS,UAAU,QAAQ;;;;;AAMxD,SAAgB,OACd,OACA,SACc;AAEd,sBAAqB;AAErB,QAAO,mBAAmB,CAAC,OAAO,OAAO,QAAQ;;;;;AAMnD,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;;;;;AAM7D,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,SAAS,KAAK,MAAM,CAAE,UAAS,IAAI,MAAM;;AAKjD,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;;;;;AAM1C,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"}
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"}
@@ -1,4 +1,4 @@
1
- import { CacheMetrics, GlobalInjectResult, InjectResult, KeyframesResult, KeyframesSteps, PropertyDefinition, RawCSSResult, StyleInjectorConfig } from "./types.js";
1
+ import { CacheMetrics, CounterStyleDescriptors, FontFaceDescriptors, GCOptions, GlobalInjectResult, InjectResult, KeyframesResult, KeyframesSteps, PropertyDefinition, RawCSSResult, StyleInjectorConfig } from "./types.js";
2
2
  import { StyleResult } from "../pipeline/index.js";
3
3
  import { SheetManager } from "./sheet-manager.js";
4
4
 
@@ -6,11 +6,16 @@ import { SheetManager } from "./sheet-manager.js";
6
6
  declare class StyleInjector {
7
7
  private sheetManager;
8
8
  private config;
9
- private cleanupScheduled;
10
9
  private globalRuleCounter;
10
+ private pendingGCHandle;
11
11
  /** @internal — exposed for debug utilities only */
12
12
  get _sheetManager(): SheetManager;
13
13
  constructor(config?: StyleInjectorConfig);
14
+ /**
15
+ * Check if `className` was hydrated from server-rendered styles and,
16
+ * if so, wire the cacheKey mapping. Returns true on hit.
17
+ */
18
+ private tryHydratedHit;
14
19
  /**
15
20
  * Allocate a className for a cacheKey without injecting styles yet.
16
21
  * This allows separating className allocation (render phase) from style injection (insertion phase).
@@ -60,7 +65,7 @@ declare class StyleInjector {
60
65
  root?: Document | ShadowRoot;
61
66
  }): InjectResult | null;
62
67
  /**
63
- * Dispose of a className
68
+ * Dispose of a className (decrements refCount only).
64
69
  */
65
70
  private dispose;
66
71
  /**
@@ -121,6 +126,24 @@ declare class StyleInjector {
121
126
  isPropertyDefined(name: string, options?: {
122
127
  root?: Document | ShadowRoot;
123
128
  }): boolean;
129
+ /**
130
+ * Inject a CSS @font-face rule.
131
+ *
132
+ * Permanent and global — no dispose or ref-counting.
133
+ * Deduplicates by content hash (family + descriptors).
134
+ */
135
+ fontFace(family: string, descriptors: FontFaceDescriptors, options?: {
136
+ root?: Document | ShadowRoot;
137
+ }): void;
138
+ /**
139
+ * Inject a CSS @counter-style rule.
140
+ *
141
+ * Permanent and global — no dispose or ref-counting.
142
+ * Deduplicates by name (first definition wins).
143
+ */
144
+ counterStyle(name: string, descriptors: CounterStyleDescriptors, options?: {
145
+ root?: Document | ShadowRoot;
146
+ }): void;
124
147
  /**
125
148
  * Inject keyframes and return object with toString() and dispose()
126
149
  *
@@ -138,6 +161,33 @@ declare class StyleInjector {
138
161
  * Dispose keyframes
139
162
  */
140
163
  private disposeKeyframes;
164
+ private static readonly TASTY_CLASS_RE;
165
+ /**
166
+ * Record a render-time usage hit for one or more classNames.
167
+ * Handles space-separated multi-chunk classNames.
168
+ * When the global touch counter reaches `touchInterval`, schedules a GC
169
+ * via `requestIdleCallback`.
170
+ * No-op on the server.
171
+ */
172
+ touch(className: string, options?: {
173
+ root?: Document | ShadowRoot;
174
+ }): void;
175
+ /**
176
+ * Schedule a GC via `requestIdleCallback` (or synchronously as fallback).
177
+ * Runs GC on all active roots. Avoids double-scheduling via `pendingGCHandle`.
178
+ */
179
+ private scheduleGC;
180
+ /**
181
+ * Synchronous garbage collection.
182
+ *
183
+ * 1. Quick upper-bound check: skip if unused count can't exceed capacity.
184
+ * 2. Scans the DOM for live tasty classNames (safety guard).
185
+ * 3. With `force: true`: deletes all unused entries inline.
186
+ * Without `force`: collects unused, sorts oldest-first, evicts over capacity.
187
+ *
188
+ * @returns Number of styles evicted.
189
+ */
190
+ gc(options?: GCOptions): number;
141
191
  /**
142
192
  * Destroy all resources for a root
143
193
  */