@tenphi/tasty 0.0.0-snapshot.ce10eff → 0.0.0-snapshot.cfcf770

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 (301) hide show
  1. package/README.md +290 -207
  2. package/dist/_virtual/_rolldown/runtime.js +1 -2
  3. package/dist/chunks/cacheKey.d.ts +1 -0
  4. package/dist/chunks/cacheKey.js +17 -10
  5. package/dist/chunks/cacheKey.js.map +1 -1
  6. package/dist/chunks/definitions.d.ts +1 -1
  7. package/dist/chunks/definitions.js +3 -5
  8. package/dist/chunks/definitions.js.map +1 -1
  9. package/dist/chunks/index.d.ts +1 -0
  10. package/dist/chunks/renderChunk.d.ts +1 -0
  11. package/dist/chunks/renderChunk.js +32 -34
  12. package/dist/chunks/renderChunk.js.map +1 -1
  13. package/dist/compute-styles.d.ts +31 -0
  14. package/dist/compute-styles.js +357 -0
  15. package/dist/compute-styles.js.map +1 -0
  16. package/dist/config.d.ts +109 -30
  17. package/dist/config.js +144 -45
  18. package/dist/config.js.map +1 -1
  19. package/dist/core/index.d.ts +12 -11
  20. package/dist/core/index.js +11 -10
  21. package/dist/counter-style/index.js +51 -0
  22. package/dist/counter-style/index.js.map +1 -0
  23. package/dist/debug.d.ts +26 -141
  24. package/dist/debug.js +357 -637
  25. package/dist/debug.js.map +1 -1
  26. package/dist/font-face/index.js +63 -0
  27. package/dist/font-face/index.js.map +1 -0
  28. package/dist/hooks/index.d.ts +7 -0
  29. package/dist/hooks/useCounterStyle.d.ts +50 -0
  30. package/dist/hooks/useCounterStyle.js +45 -0
  31. package/dist/hooks/useCounterStyle.js.map +1 -0
  32. package/dist/hooks/useFontFace.d.ts +43 -0
  33. package/dist/hooks/useFontFace.js +69 -0
  34. package/dist/hooks/useFontFace.js.map +1 -0
  35. package/dist/hooks/useGlobalStyles.d.ts +3 -0
  36. package/dist/hooks/useGlobalStyles.js +23 -2
  37. package/dist/hooks/useGlobalStyles.js.map +1 -1
  38. package/dist/hooks/useKeyframes.js +13 -4
  39. package/dist/hooks/useKeyframes.js.map +1 -1
  40. package/dist/hooks/useProperty.js +31 -14
  41. package/dist/hooks/useProperty.js.map +1 -1
  42. package/dist/hooks/useRawCSS.js +8 -2
  43. package/dist/hooks/useRawCSS.js.map +1 -1
  44. package/dist/hooks/useStyles.d.ts +4 -4
  45. package/dist/hooks/useStyles.js +7 -147
  46. package/dist/hooks/useStyles.js.map +1 -1
  47. package/dist/index.d.ts +15 -12
  48. package/dist/index.js +14 -11
  49. package/dist/injector/index.d.ts +36 -11
  50. package/dist/injector/index.js +42 -11
  51. package/dist/injector/index.js.map +1 -1
  52. package/dist/injector/injector.d.ts +60 -3
  53. package/dist/injector/injector.js +168 -29
  54. package/dist/injector/injector.js.map +1 -1
  55. package/dist/injector/sheet-manager.d.ts +10 -13
  56. package/dist/injector/sheet-manager.js +39 -70
  57. package/dist/injector/sheet-manager.js.map +1 -1
  58. package/dist/injector/types.d.ts +101 -19
  59. package/dist/keyframes/index.js +1 -1
  60. package/dist/parser/classify.js +6 -6
  61. package/dist/parser/classify.js.map +1 -1
  62. package/dist/parser/const.js +30 -3
  63. package/dist/parser/const.js.map +1 -1
  64. package/dist/parser/lru.js +1 -1
  65. package/dist/parser/lru.js.map +1 -1
  66. package/dist/parser/parser.js +2 -3
  67. package/dist/parser/parser.js.map +1 -1
  68. package/dist/parser/tokenizer.js +1 -1
  69. package/dist/parser/tokenizer.js.map +1 -1
  70. package/dist/parser/types.js +1 -1
  71. package/dist/parser/types.js.map +1 -1
  72. package/dist/pipeline/conditions.js +1 -1
  73. package/dist/pipeline/conditions.js.map +1 -1
  74. package/dist/pipeline/exclusive.js +1 -2
  75. package/dist/pipeline/exclusive.js.map +1 -1
  76. package/dist/pipeline/index.d.ts +3 -1
  77. package/dist/pipeline/index.js +80 -32
  78. package/dist/pipeline/index.js.map +1 -1
  79. package/dist/pipeline/materialize.js +381 -122
  80. package/dist/pipeline/materialize.js.map +1 -1
  81. package/dist/pipeline/parseStateKey.d.ts +1 -1
  82. package/dist/pipeline/parseStateKey.js +21 -13
  83. package/dist/pipeline/parseStateKey.js.map +1 -1
  84. package/dist/pipeline/simplify.js +1 -2
  85. package/dist/pipeline/simplify.js.map +1 -1
  86. package/dist/pipeline/warnings.js +1 -1
  87. package/dist/plugins/index.d.ts +2 -0
  88. package/dist/plugins/okhsl-plugin.js +3 -277
  89. package/dist/plugins/okhsl-plugin.js.map +1 -1
  90. package/dist/plugins/types.d.ts +9 -2
  91. package/dist/properties/index.js +24 -60
  92. package/dist/properties/index.js.map +1 -1
  93. package/dist/properties/property-type-resolver.d.ts +0 -5
  94. package/dist/properties/property-type-resolver.js +19 -32
  95. package/dist/properties/property-type-resolver.js.map +1 -1
  96. package/dist/ssr/astro.d.ts +29 -0
  97. package/dist/ssr/astro.js +64 -0
  98. package/dist/ssr/astro.js.map +1 -0
  99. package/dist/ssr/async-storage.d.ts +17 -0
  100. package/dist/ssr/async-storage.js +34 -0
  101. package/dist/ssr/async-storage.js.map +1 -0
  102. package/dist/ssr/collect-auto-properties.js +39 -0
  103. package/dist/ssr/collect-auto-properties.js.map +1 -0
  104. package/dist/ssr/collector.d.ts +102 -0
  105. package/dist/ssr/collector.js +219 -0
  106. package/dist/ssr/collector.js.map +1 -0
  107. package/dist/ssr/format-global-rules.js +22 -0
  108. package/dist/ssr/format-global-rules.js.map +1 -0
  109. package/dist/ssr/format-keyframes.js +69 -0
  110. package/dist/ssr/format-keyframes.js.map +1 -0
  111. package/dist/ssr/format-property.js +49 -0
  112. package/dist/ssr/format-property.js.map +1 -0
  113. package/dist/ssr/format-rules.js +73 -0
  114. package/dist/ssr/format-rules.js.map +1 -0
  115. package/dist/ssr/hydrate.d.ts +22 -0
  116. package/dist/ssr/hydrate.js +49 -0
  117. package/dist/ssr/hydrate.js.map +1 -0
  118. package/dist/ssr/index.d.ts +4 -0
  119. package/dist/ssr/index.js +10 -0
  120. package/dist/ssr/index.js.map +1 -0
  121. package/dist/ssr/next.d.ts +43 -0
  122. package/dist/ssr/next.js +74 -0
  123. package/dist/ssr/next.js.map +1 -0
  124. package/dist/ssr/ssr-collector-ref.js +12 -0
  125. package/dist/ssr/ssr-collector-ref.js.map +1 -0
  126. package/dist/states/index.js +13 -259
  127. package/dist/states/index.js.map +1 -1
  128. package/dist/static/index.js +1 -2
  129. package/dist/static/inject.d.ts +5 -0
  130. package/dist/static/inject.js +17 -0
  131. package/dist/static/inject.js.map +1 -0
  132. package/dist/static/tastyStatic.js +1 -2
  133. package/dist/static/tastyStatic.js.map +1 -1
  134. package/dist/static/types.js +1 -1
  135. package/dist/styles/border.d.ts +1 -1
  136. package/dist/styles/border.js +30 -24
  137. package/dist/styles/border.js.map +1 -1
  138. package/dist/styles/color.d.ts +1 -1
  139. package/dist/styles/color.js +11 -8
  140. package/dist/styles/color.js.map +1 -1
  141. package/dist/styles/const.js +17 -0
  142. package/dist/styles/const.js.map +1 -0
  143. package/dist/styles/createStyle.js +28 -26
  144. package/dist/styles/createStyle.js.map +1 -1
  145. package/dist/styles/dimension.js +15 -3
  146. package/dist/styles/dimension.js.map +1 -1
  147. package/dist/styles/directional.js +133 -0
  148. package/dist/styles/directional.js.map +1 -0
  149. package/dist/styles/display.d.ts +3 -10
  150. package/dist/styles/display.js +45 -39
  151. package/dist/styles/display.js.map +1 -1
  152. package/dist/styles/fade.d.ts +1 -1
  153. package/dist/styles/fade.js +9 -5
  154. package/dist/styles/fade.js.map +1 -1
  155. package/dist/styles/fill.d.ts +2 -2
  156. package/dist/styles/fill.js +3 -4
  157. package/dist/styles/fill.js.map +1 -1
  158. package/dist/styles/flow.js +1 -1
  159. package/dist/styles/gap.d.ts +1 -1
  160. package/dist/styles/gap.js +4 -3
  161. package/dist/styles/gap.js.map +1 -1
  162. package/dist/styles/height.d.ts +1 -1
  163. package/dist/styles/height.js +1 -2
  164. package/dist/styles/height.js.map +1 -1
  165. package/dist/styles/index.d.ts +0 -1
  166. package/dist/styles/index.js +3 -4
  167. package/dist/styles/index.js.map +1 -1
  168. package/dist/styles/inset.d.ts +1 -29
  169. package/dist/styles/inset.js +19 -135
  170. package/dist/styles/inset.js.map +1 -1
  171. package/dist/styles/list.d.ts +5 -5
  172. package/dist/styles/list.js +4 -2
  173. package/dist/styles/list.js.map +1 -1
  174. package/dist/styles/margin.d.ts +1 -1
  175. package/dist/styles/margin.js +17 -89
  176. package/dist/styles/margin.js.map +1 -1
  177. package/dist/styles/outline.d.ts +1 -1
  178. package/dist/styles/outline.js +6 -16
  179. package/dist/styles/outline.js.map +1 -1
  180. package/dist/styles/padding.d.ts +1 -1
  181. package/dist/styles/padding.js +17 -89
  182. package/dist/styles/padding.js.map +1 -1
  183. package/dist/styles/placement.d.ts +37 -0
  184. package/dist/styles/placement.js +74 -0
  185. package/dist/styles/placement.js.map +1 -0
  186. package/dist/styles/predefined.d.ts +4 -6
  187. package/dist/styles/predefined.js +9 -13
  188. package/dist/styles/predefined.js.map +1 -1
  189. package/dist/styles/preset.d.ts +6 -1
  190. package/dist/styles/preset.js +54 -53
  191. package/dist/styles/preset.js.map +1 -1
  192. package/dist/styles/radius.d.ts +1 -3
  193. package/dist/styles/radius.js +38 -6
  194. package/dist/styles/radius.js.map +1 -1
  195. package/dist/styles/scrollMargin.d.ts +24 -0
  196. package/dist/styles/scrollMargin.js +32 -0
  197. package/dist/styles/scrollMargin.js.map +1 -0
  198. package/dist/styles/scrollbar.d.ts +9 -5
  199. package/dist/styles/scrollbar.js +31 -92
  200. package/dist/styles/scrollbar.js.map +1 -1
  201. package/dist/styles/shadow.d.ts +1 -1
  202. package/dist/styles/shadow.js +4 -3
  203. package/dist/styles/shadow.js.map +1 -1
  204. package/dist/styles/shared.js +17 -0
  205. package/dist/styles/shared.js.map +1 -0
  206. package/dist/styles/transition.d.ts +1 -1
  207. package/dist/styles/transition.js +6 -5
  208. package/dist/styles/transition.js.map +1 -1
  209. package/dist/styles/types.d.ts +94 -28
  210. package/dist/styles/width.d.ts +1 -1
  211. package/dist/styles/width.js +1 -2
  212. package/dist/styles/width.js.map +1 -1
  213. package/dist/tasty.d.ts +46 -894
  214. package/dist/tasty.js +96 -59
  215. package/dist/tasty.js.map +1 -1
  216. package/dist/types.d.ts +1 -1
  217. package/dist/utils/cache-wrapper.js +4 -9
  218. package/dist/utils/cache-wrapper.js.map +1 -1
  219. package/dist/utils/case-converter.js +1 -1
  220. package/dist/utils/color-math.d.ts +46 -0
  221. package/dist/utils/color-math.js +749 -0
  222. package/dist/utils/color-math.js.map +1 -0
  223. package/dist/utils/color-space.d.ts +5 -0
  224. package/dist/utils/color-space.js +228 -0
  225. package/dist/utils/color-space.js.map +1 -0
  226. package/dist/utils/colors.js +3 -2
  227. package/dist/utils/colors.js.map +1 -1
  228. package/dist/utils/dotize.js +1 -1
  229. package/dist/utils/dotize.js.map +1 -1
  230. package/dist/utils/filter-base-props.d.ts +1 -1
  231. package/dist/utils/filter-base-props.js +1 -1
  232. package/dist/utils/filter-base-props.js.map +1 -1
  233. package/dist/utils/get-display-name.js +1 -1
  234. package/dist/utils/has-keys.js +13 -0
  235. package/dist/utils/has-keys.js.map +1 -0
  236. package/dist/utils/is-dev-env.js +1 -1
  237. package/dist/utils/is-dev-env.js.map +1 -1
  238. package/dist/utils/is-valid-element-type.js +1 -1
  239. package/dist/utils/merge-styles.js +1 -2
  240. package/dist/utils/merge-styles.js.map +1 -1
  241. package/dist/utils/mod-attrs.d.ts +0 -2
  242. package/dist/utils/mod-attrs.js +3 -4
  243. package/dist/utils/mod-attrs.js.map +1 -1
  244. package/dist/utils/process-tokens.d.ts +3 -17
  245. package/dist/utils/process-tokens.js +19 -107
  246. package/dist/utils/process-tokens.js.map +1 -1
  247. package/dist/utils/resolve-recipes.js +1 -2
  248. package/dist/utils/resolve-recipes.js.map +1 -1
  249. package/dist/utils/selector-transform.js +32 -0
  250. package/dist/utils/selector-transform.js.map +1 -0
  251. package/dist/utils/string.js +1 -1
  252. package/dist/utils/styles.d.ts +3 -82
  253. package/dist/utils/styles.js +29 -560
  254. package/dist/utils/styles.js.map +1 -1
  255. package/dist/utils/typography.d.ts +24 -13
  256. package/dist/utils/typography.js +15 -17
  257. package/dist/utils/typography.js.map +1 -1
  258. package/dist/utils/warnings.js +1 -1
  259. package/dist/zero/babel.d.ts +79 -10
  260. package/dist/zero/babel.js +190 -40
  261. package/dist/zero/babel.js.map +1 -1
  262. package/dist/zero/css-writer.js +1 -2
  263. package/dist/zero/css-writer.js.map +1 -1
  264. package/dist/zero/extractor.js +54 -3
  265. package/dist/zero/extractor.js.map +1 -1
  266. package/dist/zero/index.js +1 -2
  267. package/dist/zero/next.d.ts +56 -30
  268. package/dist/zero/next.js +105 -40
  269. package/dist/zero/next.js.map +1 -1
  270. package/docs/PIPELINE.md +519 -0
  271. package/docs/README.md +31 -0
  272. package/docs/adoption.md +296 -0
  273. package/docs/comparison.md +420 -0
  274. package/docs/configuration.md +326 -0
  275. package/docs/debug.md +318 -0
  276. package/docs/design-system.md +424 -0
  277. package/docs/dsl.md +688 -0
  278. package/docs/getting-started.md +217 -0
  279. package/docs/injector.md +542 -0
  280. package/docs/methodology.md +616 -0
  281. package/docs/runtime.md +572 -0
  282. package/docs/ssr.md +354 -0
  283. package/docs/styles.md +596 -0
  284. package/docs/tasty-static.md +520 -0
  285. package/package.json +61 -35
  286. package/dist/styles/align.d.ts +0 -15
  287. package/dist/styles/align.js +0 -14
  288. package/dist/styles/align.js.map +0 -1
  289. package/dist/styles/justify.d.ts +0 -15
  290. package/dist/styles/justify.js +0 -14
  291. package/dist/styles/justify.js.map +0 -1
  292. package/dist/styles/styledScrollbar.d.ts +0 -47
  293. package/dist/styles/styledScrollbar.js +0 -38
  294. package/dist/styles/styledScrollbar.js.map +0 -1
  295. package/dist/tokens/typography.d.ts +0 -19
  296. package/dist/tokens/typography.js +0 -237
  297. package/dist/tokens/typography.js.map +0 -1
  298. package/dist/utils/hsl-to-rgb.js +0 -38
  299. package/dist/utils/hsl-to-rgb.js.map +0 -1
  300. package/dist/utils/okhsl-to-rgb.js +0 -296
  301. package/dist/utils/okhsl-to-rgb.js.map +0 -1
@@ -1,18 +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
7
  /**
17
8
  * Inject styles and return className with dispose function
18
9
  */
@@ -117,6 +108,24 @@ declare function property(name: string, options?: PropertyOptions): void;
117
108
  declare function isPropertyDefined(name: string, options?: {
118
109
  root?: Document | ShadowRoot;
119
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;
120
129
  /**
121
130
  * Get CSS text from all sheets (for SSR)
122
131
  */
@@ -134,6 +143,22 @@ declare function getCssTextForNode(node: ParentNode | Element | DocumentFragment
134
143
  * Force cleanup of unused rules
135
144
  */
136
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;
137
162
  /**
138
163
  * Check if we're currently running in a test environment
139
164
  */
@@ -153,5 +178,5 @@ declare function destroy(root?: Document | ShadowRoot): void;
153
178
  */
154
179
  declare function createInjector(config?: Partial<StyleInjectorConfig>): StyleInjector;
155
180
  //#endregion
156
- export { PropertyOptions, allocateClassName, cleanup, createInjector, destroy, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property };
181
+ export { PropertyOptions, cleanup, counterStyle, createInjector, destroy, fontFace, gc, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, touch };
157
182
  //# sourceMappingURL=index.d.ts.map
@@ -1,20 +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
6
  * Inject styles and return className with dispose function
14
7
  */
15
8
  function inject(rules, options) {
9
+ const injector = getGlobalInjector();
16
10
  markStylesGenerated();
17
- return getGlobalInjector().inject(rules, options);
11
+ return injector.inject(rules, options);
18
12
  }
19
13
  /**
20
14
  * Inject global rules that should not reserve tasty class names
@@ -93,6 +87,24 @@ function isPropertyDefined(name, options) {
93
87
  return getGlobalInjector().isPropertyDefined(name, options);
94
88
  }
95
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
+ /**
96
108
  * Get CSS text from all sheets (for SSR)
97
109
  */
98
110
  function getCssText(options) {
@@ -121,6 +133,25 @@ function cleanup(root) {
121
133
  return getGlobalInjector().cleanup(root);
122
134
  }
123
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
+ /**
124
155
  * Check if we're currently running in a test environment
125
156
  */
126
157
  function getIsTestEnvironment() {
@@ -148,7 +179,7 @@ function createInjector(config = {}) {
148
179
  ...config
149
180
  });
150
181
  }
151
-
152
182
  //#endregion
153
- export { allocateClassName, cleanup, createInjector, destroy, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property };
183
+ export { cleanup, counterStyle, createInjector, destroy, fontFace, gc, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, touch };
184
+
154
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 * 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;;;;;AAMjE,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\\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 * 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,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;;;;;;;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,8 +6,9 @@ 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 touchCount;
11
+ private pendingGCHandle;
11
12
  /** @internal — exposed for debug utilities only */
12
13
  get _sheetManager(): SheetManager;
13
14
  constructor(config?: StyleInjectorConfig);
@@ -51,7 +52,16 @@ declare class StyleInjector {
51
52
  root?: Document | ShadowRoot;
52
53
  }): string;
53
54
  /**
54
- * Dispose of a className
55
+ * Increment refCount for an already-injected cacheKey and return a dispose.
56
+ * Used by useStyles on cache hits (hydration or runtime reuse) where
57
+ * the pipeline was skipped but refCount tracking is still needed.
58
+ * Returns null if the cacheKey is not found.
59
+ */
60
+ trackRef(cacheKey: string, options?: {
61
+ root?: Document | ShadowRoot;
62
+ }): InjectResult | null;
63
+ /**
64
+ * Dispose of a className (decrements refCount only).
55
65
  */
56
66
  private dispose;
57
67
  /**
@@ -112,6 +122,24 @@ declare class StyleInjector {
112
122
  isPropertyDefined(name: string, options?: {
113
123
  root?: Document | ShadowRoot;
114
124
  }): boolean;
125
+ /**
126
+ * Inject a CSS @font-face rule.
127
+ *
128
+ * Permanent and global — no dispose or ref-counting.
129
+ * Deduplicates by content hash (family + descriptors).
130
+ */
131
+ fontFace(family: string, descriptors: FontFaceDescriptors, options?: {
132
+ root?: Document | ShadowRoot;
133
+ }): void;
134
+ /**
135
+ * Inject a CSS @counter-style rule.
136
+ *
137
+ * Permanent and global — no dispose or ref-counting.
138
+ * Deduplicates by name (first definition wins).
139
+ */
140
+ counterStyle(name: string, descriptors: CounterStyleDescriptors, options?: {
141
+ root?: Document | ShadowRoot;
142
+ }): void;
115
143
  /**
116
144
  * Inject keyframes and return object with toString() and dispose()
117
145
  *
@@ -129,6 +157,35 @@ declare class StyleInjector {
129
157
  * Dispose keyframes
130
158
  */
131
159
  private disposeKeyframes;
160
+ private static readonly TASTY_CLASS_RE;
161
+ /**
162
+ * Record a render-time usage hit for one or more classNames.
163
+ * Handles space-separated multi-chunk classNames.
164
+ * When the global touch counter reaches `touchInterval`, schedules a GC
165
+ * via `requestIdleCallback`.
166
+ * No-op on the server.
167
+ */
168
+ touch(className: string, options?: {
169
+ root?: Document | ShadowRoot;
170
+ }): void;
171
+ /**
172
+ * Schedule a GC via `requestIdleCallback` (or synchronously as fallback).
173
+ * Avoids double-scheduling via `pendingGCHandle`.
174
+ */
175
+ private scheduleGC;
176
+ /**
177
+ * Synchronous garbage collection.
178
+ *
179
+ * 1. Quick check: if non-active entries can't exceed capacity, skip entirely.
180
+ * 2. Scans the DOM for live tasty classNames (safety guard).
181
+ * 3. Collects unused entries (refCount === 0, not in DOM).
182
+ * 4. Checks if unused count exceeds capacity (skip if not, unless `force`).
183
+ * 5. Sorts unused by lastTouchedAt ascending, evicts oldest until at capacity.
184
+ * With `force: true`, evicts ALL unused regardless of capacity.
185
+ *
186
+ * @returns Number of styles evicted.
187
+ */
188
+ gc(options?: GCOptions): number;
132
189
  /**
133
190
  * Destroy all resources for a root
134
191
  */
@@ -1,8 +1,9 @@
1
+ import { getEffectiveDefinition, normalizePropertyDefinition } from "../properties/index.js";
1
2
  import { isDevEnv } from "../utils/is-dev-env.js";
2
3
  import { parseStyle } from "../utils/styles.js";
3
- import { colorInitialValueToRgb, getEffectiveDefinition, normalizePropertyDefinition } from "../properties/index.js";
4
4
  import { SheetManager } from "./sheet-manager.js";
5
-
5
+ import { fontFaceContentHash, formatFontFaceDeclarations } from "../font-face/index.js";
6
+ import { formatCounterStyleDeclarations } from "../counter-style/index.js";
6
7
  //#region src/injector/injector.ts
7
8
  /**
8
9
  * Generate sequential class name with format t{number}
@@ -10,11 +11,12 @@ import { SheetManager } from "./sheet-manager.js";
10
11
  function generateClassName(counter) {
11
12
  return `t${counter}`;
12
13
  }
13
- var StyleInjector = class {
14
+ var StyleInjector = class StyleInjector {
14
15
  sheetManager;
15
16
  config;
16
- cleanupScheduled = false;
17
17
  globalRuleCounter = 0;
18
+ touchCount = 0;
19
+ pendingGCHandle = null;
18
20
  /** @internal — exposed for debug utilities only */
19
21
  get _sheetManager() {
20
22
  return this.sheetManager;
@@ -94,9 +96,10 @@ var StyleInjector = class {
94
96
  });
95
97
  if (this.config.autoPropertyTypes !== false) {
96
98
  const resolver = registry.propertyTypeResolver;
99
+ const defined = registry.injectedProperties;
97
100
  for (const rule of rulesToInsert) {
98
101
  if (!rule.declarations) continue;
99
- resolver.scanDeclarations(rule.declarations, (name) => this.isPropertyDefined(name, { root }), (name, syntax, initialValue) => {
102
+ resolver.scanDeclarations(rule.declarations, (name) => defined.has(name), (name, syntax, initialValue) => {
100
103
  this.property(name, {
101
104
  syntax,
102
105
  inherits: true,
@@ -140,9 +143,10 @@ var StyleInjector = class {
140
143
  if (!rules || rules.length === 0) return { dispose: () => {} };
141
144
  if (this.config.autoPropertyTypes !== false) {
142
145
  const resolver = registry.propertyTypeResolver;
146
+ const defined = registry.injectedProperties;
143
147
  for (const rule of rules) {
144
148
  if (!rule.declarations) continue;
145
- resolver.scanDeclarations(rule.declarations, (name) => this.isPropertyDefined(name, { root }), (name, syntax, initialValue) => {
149
+ resolver.scanDeclarations(rule.declarations, (name) => defined.has(name), (name, syntax, initialValue) => {
146
150
  this.property(name, {
147
151
  syntax,
148
152
  inherits: true,
@@ -176,17 +180,33 @@ var StyleInjector = class {
176
180
  return this.sheetManager.getRawCSSText(root);
177
181
  }
178
182
  /**
179
- * Dispose of a className
183
+ * Increment refCount for an already-injected cacheKey and return a dispose.
184
+ * Used by useStyles on cache hits (hydration or runtime reuse) where
185
+ * the pipeline was skipped but refCount tracking is still needed.
186
+ * Returns null if the cacheKey is not found.
187
+ */
188
+ trackRef(cacheKey, options) {
189
+ const root = options?.root || document;
190
+ const registry = this.sheetManager.getRegistry(root);
191
+ if (!registry.cacheKeyToClassName.has(cacheKey)) return null;
192
+ const className = registry.cacheKeyToClassName.get(cacheKey);
193
+ const currentRefCount = registry.refCounts.get(className) || 0;
194
+ registry.refCounts.set(className, currentRefCount + 1);
195
+ if (registry.metrics) registry.metrics.hits++;
196
+ return {
197
+ className,
198
+ dispose: () => this.dispose(className, registry)
199
+ };
200
+ }
201
+ /**
202
+ * Dispose of a className (decrements refCount only).
180
203
  */
181
204
  dispose(className, registry) {
182
205
  const currentRefCount = registry.refCounts.get(className);
183
206
  if (currentRefCount == null || currentRefCount <= 0) return;
184
207
  const newRefCount = currentRefCount - 1;
185
208
  registry.refCounts.set(className, newRefCount);
186
- if (newRefCount === 0) {
187
- if (registry.metrics) registry.metrics.totalUnused++;
188
- this.sheetManager.checkCleanupNeeded(registry);
189
- }
209
+ if (newRefCount === 0 && registry.metrics) registry.metrics.totalUnused++;
190
210
  }
191
211
  /**
192
212
  * Force bulk cleanup of unused styles
@@ -273,13 +293,7 @@ var StyleInjector = class {
273
293
  const cssName = effectiveResult.cssName;
274
294
  const definition = effectiveResult.definition;
275
295
  const normalizedDef = normalizePropertyDefinition(definition);
276
- const existingDef = registry.injectedProperties.get(cssName);
277
- if (existingDef !== void 0) {
278
- if (existingDef !== normalizedDef) {
279
- if (isDevEnv()) console.warn(`[Tasty] @property ${cssName} was already defined with a different declaration. The new declaration will be ignored. Original: ${existingDef}, New: ${normalizedDef}`);
280
- }
281
- return;
282
- }
296
+ if (registry.injectedProperties.get(cssName) !== void 0) return;
283
297
  const parts = [];
284
298
  if (definition.syntax != null) {
285
299
  let syntax = String(definition.syntax).trim();
@@ -301,15 +315,6 @@ var StyleInjector = class {
301
315
  };
302
316
  if (!this.sheetManager.insertGlobalRule(registry, [rule], `property:${name}`, root)) return;
303
317
  registry.injectedProperties.set(cssName, normalizedDef);
304
- if (effectiveResult.isColor) {
305
- const rgbCssName = `${cssName}-rgb`;
306
- if (!this.isPropertyDefined(rgbCssName, { root })) this.property(rgbCssName, {
307
- syntax: "<number>+",
308
- inherits: definition.inherits,
309
- initialValue: colorInitialValueToRgb(definition.initialValue),
310
- root
311
- });
312
- }
313
318
  }
314
319
  /**
315
320
  * Check whether a given @property name was already injected by this injector.
@@ -327,6 +332,39 @@ var StyleInjector = class {
327
332
  return registry.injectedProperties.has(effectiveResult.cssName);
328
333
  }
329
334
  /**
335
+ * Inject a CSS @font-face rule.
336
+ *
337
+ * Permanent and global — no dispose or ref-counting.
338
+ * Deduplicates by content hash (family + descriptors).
339
+ */
340
+ fontFace(family, descriptors, options) {
341
+ const root = options?.root || document;
342
+ const registry = this.sheetManager.getRegistry(root);
343
+ const hash = fontFaceContentHash(family, descriptors);
344
+ if (registry.injectedFontFaces.has(hash)) return;
345
+ const rule = {
346
+ selector: "@font-face",
347
+ declarations: formatFontFaceDeclarations(family, descriptors)
348
+ };
349
+ if (this.sheetManager.insertGlobalRule(registry, [rule], `fontface:${hash}`, root)) registry.injectedFontFaces.add(hash);
350
+ }
351
+ /**
352
+ * Inject a CSS @counter-style rule.
353
+ *
354
+ * Permanent and global — no dispose or ref-counting.
355
+ * Deduplicates by name (first definition wins).
356
+ */
357
+ counterStyle(name, descriptors, options) {
358
+ const root = options?.root || document;
359
+ const registry = this.sheetManager.getRegistry(root);
360
+ if (registry.injectedCounterStyles.has(name)) return;
361
+ const rule = {
362
+ selector: `@counter-style ${name}`,
363
+ declarations: formatCounterStyleDeclarations(descriptors)
364
+ };
365
+ if (this.sheetManager.insertGlobalRule(registry, [rule], `counterstyle:${name}`, root)) registry.injectedCounterStyles.add(name);
366
+ }
367
+ /**
330
368
  * Inject keyframes and return object with toString() and dispose()
331
369
  *
332
370
  * Keyframes are cached by content (steps). If the same content is injected
@@ -368,7 +406,7 @@ var StyleInjector = class {
368
406
  dispose: () => {}
369
407
  };
370
408
  const { info, declarations } = result;
371
- if (this.config.autoPropertyTypes !== false && declarations) registry.propertyTypeResolver.scanDeclarations(declarations, (name) => this.isPropertyDefined(name, { root }), (name, syntax, initialValue) => {
409
+ if (this.config.autoPropertyTypes !== false && declarations) registry.propertyTypeResolver.scanDeclarations(declarations, (name) => registry.injectedProperties.has(name), (name, syntax, initialValue) => {
372
410
  this.property(name, {
373
411
  syntax,
374
412
  inherits: true,
@@ -410,15 +448,116 @@ var StyleInjector = class {
410
448
  }
411
449
  }
412
450
  }
451
+ static TASTY_CLASS_RE = /^t\d+$/;
452
+ /**
453
+ * Record a render-time usage hit for one or more classNames.
454
+ * Handles space-separated multi-chunk classNames.
455
+ * When the global touch counter reaches `touchInterval`, schedules a GC
456
+ * via `requestIdleCallback`.
457
+ * No-op on the server.
458
+ */
459
+ touch(className, options) {
460
+ if (typeof document === "undefined") return;
461
+ if (!this.config.gc) return;
462
+ const root = options?.root || document;
463
+ const registry = this.sheetManager.getRegistry(root);
464
+ const now = Date.now();
465
+ const parts = className.indexOf(" ") === -1 ? [className] : className.split(" ");
466
+ for (const cls of parts) {
467
+ if (!StyleInjector.TASTY_CLASS_RE.test(cls)) continue;
468
+ if (!registry.rules.has(cls)) continue;
469
+ const entry = registry.usageMap.get(cls);
470
+ if (entry) entry.lastTouchedAt = now;
471
+ else registry.usageMap.set(cls, { lastTouchedAt: now });
472
+ this.touchCount++;
473
+ }
474
+ const touchInterval = this.config.gc.touchInterval ?? 1e3;
475
+ if (this.touchCount >= touchInterval) {
476
+ this.touchCount = 0;
477
+ this.scheduleGC(root);
478
+ }
479
+ }
480
+ /**
481
+ * Schedule a GC via `requestIdleCallback` (or synchronously as fallback).
482
+ * Avoids double-scheduling via `pendingGCHandle`.
483
+ */
484
+ scheduleGC(root) {
485
+ if (this.pendingGCHandle != null) return;
486
+ if (typeof requestIdleCallback !== "undefined") this.pendingGCHandle = requestIdleCallback(() => {
487
+ this.pendingGCHandle = null;
488
+ this.gc({ root });
489
+ });
490
+ else this.gc({ root });
491
+ }
492
+ /**
493
+ * Synchronous garbage collection.
494
+ *
495
+ * 1. Quick check: if non-active entries can't exceed capacity, skip entirely.
496
+ * 2. Scans the DOM for live tasty classNames (safety guard).
497
+ * 3. Collects unused entries (refCount === 0, not in DOM).
498
+ * 4. Checks if unused count exceeds capacity (skip if not, unless `force`).
499
+ * 5. Sorts unused by lastTouchedAt ascending, evicts oldest until at capacity.
500
+ * With `force: true`, evicts ALL unused regardless of capacity.
501
+ *
502
+ * @returns Number of styles evicted.
503
+ */
504
+ gc(options) {
505
+ if (typeof document === "undefined") return 0;
506
+ if (this.pendingGCHandle != null) {
507
+ if (typeof cancelIdleCallback !== "undefined") cancelIdleCallback(this.pendingGCHandle);
508
+ this.pendingGCHandle = null;
509
+ }
510
+ const root = options?.root || document;
511
+ const force = options?.force ?? false;
512
+ const registry = this.sheetManager.getRegistry(root);
513
+ const capacity = this.config.gc?.capacity ?? 1e3;
514
+ if (!force) {
515
+ let activeCount = 0;
516
+ for (const refCount of registry.refCounts.values()) if (refCount > 0) activeCount++;
517
+ if (registry.usageMap.size - activeCount <= capacity) return 0;
518
+ }
519
+ const liveClasses = /* @__PURE__ */ new Set();
520
+ for (const el of root.querySelectorAll("[class]")) for (const token of el.classList) if (StyleInjector.TASTY_CLASS_RE.test(token)) liveClasses.add(token);
521
+ const unused = [];
522
+ for (const [className, usage] of registry.usageMap) {
523
+ if (liveClasses.has(className)) continue;
524
+ if ((registry.refCounts.get(className) ?? 0) > 0) continue;
525
+ unused.push({
526
+ className,
527
+ lastTouchedAt: usage.lastTouchedAt
528
+ });
529
+ }
530
+ if (unused.length === 0) return 0;
531
+ if (!force && unused.length <= capacity) return 0;
532
+ let swept = 0;
533
+ if (force) for (const { className } of unused) {
534
+ registry.usageMap.delete(className);
535
+ swept++;
536
+ }
537
+ else {
538
+ unused.sort((a, b) => a.lastTouchedAt - b.lastTouchedAt);
539
+ const toEvict = unused.length - capacity;
540
+ for (let i = 0; i < toEvict; i++) {
541
+ registry.usageMap.delete(unused[i].className);
542
+ swept++;
543
+ }
544
+ }
545
+ if (swept > 0) this.sheetManager.forceCleanup(registry);
546
+ return swept;
547
+ }
413
548
  /**
414
549
  * Destroy all resources for a root
415
550
  */
416
551
  destroy(root) {
417
552
  const targetRoot = root || document;
418
553
  this.sheetManager.cleanup(targetRoot);
554
+ if (this.pendingGCHandle != null && !this.sheetManager.hasActiveRoots()) {
555
+ if (typeof cancelIdleCallback !== "undefined") cancelIdleCallback(this.pendingGCHandle);
556
+ this.pendingGCHandle = null;
557
+ }
419
558
  }
420
559
  };
421
-
422
560
  //#endregion
423
561
  export { StyleInjector };
562
+
424
563
  //# sourceMappingURL=injector.js.map