@tenphi/tasty 0.0.0-snapshot.01d8a9e

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 (332) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +635 -0
  3. package/dist/_virtual/_rolldown/runtime.js +7 -0
  4. package/dist/chunks/cacheKey.d.ts +1 -0
  5. package/dist/chunks/cacheKey.js +77 -0
  6. package/dist/chunks/cacheKey.js.map +1 -0
  7. package/dist/chunks/definitions.d.ts +37 -0
  8. package/dist/chunks/definitions.js +258 -0
  9. package/dist/chunks/definitions.js.map +1 -0
  10. package/dist/chunks/index.d.ts +1 -0
  11. package/dist/chunks/renderChunk.d.ts +1 -0
  12. package/dist/chunks/renderChunk.js +59 -0
  13. package/dist/chunks/renderChunk.js.map +1 -0
  14. package/dist/compute-styles.d.ts +31 -0
  15. package/dist/compute-styles.js +336 -0
  16. package/dist/compute-styles.js.map +1 -0
  17. package/dist/config.d.ts +407 -0
  18. package/dist/config.js +591 -0
  19. package/dist/config.js.map +1 -0
  20. package/dist/core/index.d.ts +34 -0
  21. package/dist/core/index.js +27 -0
  22. package/dist/counter-style/index.js +51 -0
  23. package/dist/counter-style/index.js.map +1 -0
  24. package/dist/debug.d.ts +89 -0
  25. package/dist/debug.js +453 -0
  26. package/dist/debug.js.map +1 -0
  27. package/dist/font-face/index.js +63 -0
  28. package/dist/font-face/index.js.map +1 -0
  29. package/dist/hooks/index.d.ts +7 -0
  30. package/dist/hooks/useCounterStyle.d.ts +36 -0
  31. package/dist/hooks/useCounterStyle.js +65 -0
  32. package/dist/hooks/useCounterStyle.js.map +1 -0
  33. package/dist/hooks/useFontFace.d.ts +45 -0
  34. package/dist/hooks/useFontFace.js +66 -0
  35. package/dist/hooks/useFontFace.js.map +1 -0
  36. package/dist/hooks/useGlobalStyles.d.ts +46 -0
  37. package/dist/hooks/useGlobalStyles.js +88 -0
  38. package/dist/hooks/useGlobalStyles.js.map +1 -0
  39. package/dist/hooks/useKeyframes.d.ts +58 -0
  40. package/dist/hooks/useKeyframes.js +55 -0
  41. package/dist/hooks/useKeyframes.js.map +1 -0
  42. package/dist/hooks/useProperty.d.ts +81 -0
  43. package/dist/hooks/useProperty.js +96 -0
  44. package/dist/hooks/useProperty.js.map +1 -0
  45. package/dist/hooks/useRawCSS.d.ts +22 -0
  46. package/dist/hooks/useRawCSS.js +103 -0
  47. package/dist/hooks/useRawCSS.js.map +1 -0
  48. package/dist/hooks/useStyles.d.ts +40 -0
  49. package/dist/hooks/useStyles.js +31 -0
  50. package/dist/hooks/useStyles.js.map +1 -0
  51. package/dist/index.d.ts +51 -0
  52. package/dist/index.js +36 -0
  53. package/dist/injector/index.d.ts +182 -0
  54. package/dist/injector/index.js +185 -0
  55. package/dist/injector/index.js.map +1 -0
  56. package/dist/injector/injector.d.ts +198 -0
  57. package/dist/injector/injector.js +651 -0
  58. package/dist/injector/injector.js.map +1 -0
  59. package/dist/injector/sheet-manager.d.ts +132 -0
  60. package/dist/injector/sheet-manager.js +699 -0
  61. package/dist/injector/sheet-manager.js.map +1 -0
  62. package/dist/injector/types.d.ts +235 -0
  63. package/dist/keyframes/index.js +206 -0
  64. package/dist/keyframes/index.js.map +1 -0
  65. package/dist/parser/classify.js +319 -0
  66. package/dist/parser/classify.js.map +1 -0
  67. package/dist/parser/const.js +60 -0
  68. package/dist/parser/const.js.map +1 -0
  69. package/dist/parser/lru.js +109 -0
  70. package/dist/parser/lru.js.map +1 -0
  71. package/dist/parser/parser.d.ts +25 -0
  72. package/dist/parser/parser.js +115 -0
  73. package/dist/parser/parser.js.map +1 -0
  74. package/dist/parser/tokenizer.js +69 -0
  75. package/dist/parser/tokenizer.js.map +1 -0
  76. package/dist/parser/types.d.ts +51 -0
  77. package/dist/parser/types.js +46 -0
  78. package/dist/parser/types.js.map +1 -0
  79. package/dist/pipeline/conditions.d.ts +134 -0
  80. package/dist/pipeline/conditions.js +406 -0
  81. package/dist/pipeline/conditions.js.map +1 -0
  82. package/dist/pipeline/exclusive.js +283 -0
  83. package/dist/pipeline/exclusive.js.map +1 -0
  84. package/dist/pipeline/index.d.ts +55 -0
  85. package/dist/pipeline/index.js +708 -0
  86. package/dist/pipeline/index.js.map +1 -0
  87. package/dist/pipeline/materialize.js +1157 -0
  88. package/dist/pipeline/materialize.js.map +1 -0
  89. package/dist/pipeline/parseStateKey.d.ts +15 -0
  90. package/dist/pipeline/parseStateKey.js +446 -0
  91. package/dist/pipeline/parseStateKey.js.map +1 -0
  92. package/dist/pipeline/simplify.js +690 -0
  93. package/dist/pipeline/simplify.js.map +1 -0
  94. package/dist/pipeline/warnings.js +18 -0
  95. package/dist/pipeline/warnings.js.map +1 -0
  96. package/dist/plugins/index.d.ts +2 -0
  97. package/dist/plugins/okhsl-plugin.d.ts +35 -0
  98. package/dist/plugins/okhsl-plugin.js +97 -0
  99. package/dist/plugins/okhsl-plugin.js.map +1 -0
  100. package/dist/plugins/types.d.ts +87 -0
  101. package/dist/properties/index.js +222 -0
  102. package/dist/properties/index.js.map +1 -0
  103. package/dist/properties/property-type-resolver.d.ts +24 -0
  104. package/dist/properties/property-type-resolver.js +90 -0
  105. package/dist/properties/property-type-resolver.js.map +1 -0
  106. package/dist/rsc-cache.js +79 -0
  107. package/dist/rsc-cache.js.map +1 -0
  108. package/dist/ssr/astro-client.d.ts +1 -0
  109. package/dist/ssr/astro-client.js +19 -0
  110. package/dist/ssr/astro-client.js.map +1 -0
  111. package/dist/ssr/astro-middleware.d.ts +15 -0
  112. package/dist/ssr/astro-middleware.js +19 -0
  113. package/dist/ssr/astro-middleware.js.map +1 -0
  114. package/dist/ssr/astro.d.ts +108 -0
  115. package/dist/ssr/astro.js +149 -0
  116. package/dist/ssr/astro.js.map +1 -0
  117. package/dist/ssr/async-storage.d.ts +17 -0
  118. package/dist/ssr/async-storage.js +44 -0
  119. package/dist/ssr/async-storage.js.map +1 -0
  120. package/dist/ssr/collect-auto-properties.js +58 -0
  121. package/dist/ssr/collect-auto-properties.js.map +1 -0
  122. package/dist/ssr/collector.d.ts +94 -0
  123. package/dist/ssr/collector.js +233 -0
  124. package/dist/ssr/collector.js.map +1 -0
  125. package/dist/ssr/context.js +16 -0
  126. package/dist/ssr/context.js.map +1 -0
  127. package/dist/ssr/format-global-rules.js +22 -0
  128. package/dist/ssr/format-global-rules.js.map +1 -0
  129. package/dist/ssr/format-keyframes.js +69 -0
  130. package/dist/ssr/format-keyframes.js.map +1 -0
  131. package/dist/ssr/format-property.js +49 -0
  132. package/dist/ssr/format-property.js.map +1 -0
  133. package/dist/ssr/format-rules.js +73 -0
  134. package/dist/ssr/format-rules.js.map +1 -0
  135. package/dist/ssr/hydrate.d.ts +29 -0
  136. package/dist/ssr/hydrate.js +45 -0
  137. package/dist/ssr/hydrate.js.map +1 -0
  138. package/dist/ssr/index.d.ts +4 -0
  139. package/dist/ssr/index.js +10 -0
  140. package/dist/ssr/index.js.map +1 -0
  141. package/dist/ssr/next.d.ts +46 -0
  142. package/dist/ssr/next.js +75 -0
  143. package/dist/ssr/next.js.map +1 -0
  144. package/dist/ssr/ssr-collector-ref.js +29 -0
  145. package/dist/ssr/ssr-collector-ref.js.map +1 -0
  146. package/dist/states/index.d.ts +49 -0
  147. package/dist/states/index.js +170 -0
  148. package/dist/states/index.js.map +1 -0
  149. package/dist/static/index.d.ts +5 -0
  150. package/dist/static/index.js +4 -0
  151. package/dist/static/inject.d.ts +5 -0
  152. package/dist/static/inject.js +17 -0
  153. package/dist/static/inject.js.map +1 -0
  154. package/dist/static/tastyStatic.d.ts +46 -0
  155. package/dist/static/tastyStatic.js +30 -0
  156. package/dist/static/tastyStatic.js.map +1 -0
  157. package/dist/static/types.d.ts +49 -0
  158. package/dist/static/types.js +24 -0
  159. package/dist/static/types.js.map +1 -0
  160. package/dist/styles/border.d.ts +25 -0
  161. package/dist/styles/border.js +120 -0
  162. package/dist/styles/border.js.map +1 -0
  163. package/dist/styles/color.d.ts +14 -0
  164. package/dist/styles/color.js +26 -0
  165. package/dist/styles/color.js.map +1 -0
  166. package/dist/styles/const.js +17 -0
  167. package/dist/styles/const.js.map +1 -0
  168. package/dist/styles/createStyle.js +79 -0
  169. package/dist/styles/createStyle.js.map +1 -0
  170. package/dist/styles/dimension.js +109 -0
  171. package/dist/styles/dimension.js.map +1 -0
  172. package/dist/styles/directional.js +133 -0
  173. package/dist/styles/directional.js.map +1 -0
  174. package/dist/styles/display.d.ts +30 -0
  175. package/dist/styles/display.js +73 -0
  176. package/dist/styles/display.js.map +1 -0
  177. package/dist/styles/fade.d.ts +15 -0
  178. package/dist/styles/fade.js +62 -0
  179. package/dist/styles/fade.js.map +1 -0
  180. package/dist/styles/fill.d.ts +42 -0
  181. package/dist/styles/fill.js +51 -0
  182. package/dist/styles/fill.js.map +1 -0
  183. package/dist/styles/flow.d.ts +16 -0
  184. package/dist/styles/flow.js +12 -0
  185. package/dist/styles/flow.js.map +1 -0
  186. package/dist/styles/gap.d.ts +31 -0
  187. package/dist/styles/gap.js +38 -0
  188. package/dist/styles/gap.js.map +1 -0
  189. package/dist/styles/height.d.ts +17 -0
  190. package/dist/styles/height.js +19 -0
  191. package/dist/styles/height.js.map +1 -0
  192. package/dist/styles/index.d.ts +1 -0
  193. package/dist/styles/index.js +8 -0
  194. package/dist/styles/index.js.map +1 -0
  195. package/dist/styles/inset.d.ts +24 -0
  196. package/dist/styles/inset.js +34 -0
  197. package/dist/styles/inset.js.map +1 -0
  198. package/dist/styles/list.d.ts +16 -0
  199. package/dist/styles/list.js +100 -0
  200. package/dist/styles/list.js.map +1 -0
  201. package/dist/styles/margin.d.ts +24 -0
  202. package/dist/styles/margin.js +32 -0
  203. package/dist/styles/margin.js.map +1 -0
  204. package/dist/styles/outline.d.ts +29 -0
  205. package/dist/styles/outline.js +55 -0
  206. package/dist/styles/outline.js.map +1 -0
  207. package/dist/styles/padding.d.ts +24 -0
  208. package/dist/styles/padding.js +32 -0
  209. package/dist/styles/padding.js.map +1 -0
  210. package/dist/styles/placement.d.ts +37 -0
  211. package/dist/styles/placement.js +74 -0
  212. package/dist/styles/placement.js.map +1 -0
  213. package/dist/styles/predefined.d.ts +71 -0
  214. package/dist/styles/predefined.js +237 -0
  215. package/dist/styles/predefined.js.map +1 -0
  216. package/dist/styles/preset.d.ts +52 -0
  217. package/dist/styles/preset.js +127 -0
  218. package/dist/styles/preset.js.map +1 -0
  219. package/dist/styles/radius.d.ts +12 -0
  220. package/dist/styles/radius.js +83 -0
  221. package/dist/styles/radius.js.map +1 -0
  222. package/dist/styles/scrollMargin.d.ts +24 -0
  223. package/dist/styles/scrollMargin.js +32 -0
  224. package/dist/styles/scrollMargin.js.map +1 -0
  225. package/dist/styles/scrollbar.d.ts +25 -0
  226. package/dist/styles/scrollbar.js +51 -0
  227. package/dist/styles/scrollbar.js.map +1 -0
  228. package/dist/styles/shadow.d.ts +14 -0
  229. package/dist/styles/shadow.js +25 -0
  230. package/dist/styles/shadow.js.map +1 -0
  231. package/dist/styles/shared.js +17 -0
  232. package/dist/styles/shared.js.map +1 -0
  233. package/dist/styles/transition.d.ts +14 -0
  234. package/dist/styles/transition.js +159 -0
  235. package/dist/styles/transition.js.map +1 -0
  236. package/dist/styles/types.d.ts +564 -0
  237. package/dist/styles/width.d.ts +17 -0
  238. package/dist/styles/width.js +19 -0
  239. package/dist/styles/width.js.map +1 -0
  240. package/dist/tasty.d.ts +134 -0
  241. package/dist/tasty.js +248 -0
  242. package/dist/tasty.js.map +1 -0
  243. package/dist/types.d.ts +184 -0
  244. package/dist/utils/cache-wrapper.js +21 -0
  245. package/dist/utils/cache-wrapper.js.map +1 -0
  246. package/dist/utils/case-converter.js +8 -0
  247. package/dist/utils/case-converter.js.map +1 -0
  248. package/dist/utils/color-math.d.ts +46 -0
  249. package/dist/utils/color-math.js +749 -0
  250. package/dist/utils/color-math.js.map +1 -0
  251. package/dist/utils/color-space.d.ts +5 -0
  252. package/dist/utils/color-space.js +228 -0
  253. package/dist/utils/color-space.js.map +1 -0
  254. package/dist/utils/colors.d.ts +5 -0
  255. package/dist/utils/colors.js +10 -0
  256. package/dist/utils/colors.js.map +1 -0
  257. package/dist/utils/css-types.d.ts +7 -0
  258. package/dist/utils/deps-equal.js +15 -0
  259. package/dist/utils/deps-equal.js.map +1 -0
  260. package/dist/utils/dotize.d.ts +26 -0
  261. package/dist/utils/dotize.js +122 -0
  262. package/dist/utils/dotize.js.map +1 -0
  263. package/dist/utils/filter-base-props.d.ts +15 -0
  264. package/dist/utils/filter-base-props.js +45 -0
  265. package/dist/utils/filter-base-props.js.map +1 -0
  266. package/dist/utils/get-display-name.d.ts +7 -0
  267. package/dist/utils/get-display-name.js +10 -0
  268. package/dist/utils/get-display-name.js.map +1 -0
  269. package/dist/utils/has-keys.js +13 -0
  270. package/dist/utils/has-keys.js.map +1 -0
  271. package/dist/utils/hash.js +14 -0
  272. package/dist/utils/hash.js.map +1 -0
  273. package/dist/utils/is-dev-env.js +19 -0
  274. package/dist/utils/is-dev-env.js.map +1 -0
  275. package/dist/utils/is-valid-element-type.js +15 -0
  276. package/dist/utils/is-valid-element-type.js.map +1 -0
  277. package/dist/utils/merge-styles.d.ts +7 -0
  278. package/dist/utils/merge-styles.js +145 -0
  279. package/dist/utils/merge-styles.js.map +1 -0
  280. package/dist/utils/mod-attrs.d.ts +6 -0
  281. package/dist/utils/mod-attrs.js +20 -0
  282. package/dist/utils/mod-attrs.js.map +1 -0
  283. package/dist/utils/process-tokens.d.ts +17 -0
  284. package/dist/utils/process-tokens.js +83 -0
  285. package/dist/utils/process-tokens.js.map +1 -0
  286. package/dist/utils/resolve-recipes.d.ts +17 -0
  287. package/dist/utils/resolve-recipes.js +146 -0
  288. package/dist/utils/resolve-recipes.js.map +1 -0
  289. package/dist/utils/selector-transform.js +32 -0
  290. package/dist/utils/selector-transform.js.map +1 -0
  291. package/dist/utils/string.js +8 -0
  292. package/dist/utils/string.js.map +1 -0
  293. package/dist/utils/styles.d.ts +99 -0
  294. package/dist/utils/styles.js +220 -0
  295. package/dist/utils/styles.js.map +1 -0
  296. package/dist/utils/typography.d.ts +58 -0
  297. package/dist/utils/typography.js +51 -0
  298. package/dist/utils/typography.js.map +1 -0
  299. package/dist/utils/warnings.d.ts +16 -0
  300. package/dist/utils/warnings.js +16 -0
  301. package/dist/utils/warnings.js.map +1 -0
  302. package/dist/zero/babel.d.ts +81 -0
  303. package/dist/zero/babel.js +462 -0
  304. package/dist/zero/babel.js.map +1 -0
  305. package/dist/zero/css-writer.d.ts +45 -0
  306. package/dist/zero/css-writer.js +73 -0
  307. package/dist/zero/css-writer.js.map +1 -0
  308. package/dist/zero/extractor.d.ts +24 -0
  309. package/dist/zero/extractor.js +266 -0
  310. package/dist/zero/extractor.js.map +1 -0
  311. package/dist/zero/index.d.ts +3 -0
  312. package/dist/zero/index.js +3 -0
  313. package/dist/zero/next.d.ts +86 -0
  314. package/dist/zero/next.js +143 -0
  315. package/dist/zero/next.js.map +1 -0
  316. package/docs/PIPELINE.md +519 -0
  317. package/docs/README.md +31 -0
  318. package/docs/adoption.md +298 -0
  319. package/docs/comparison.md +419 -0
  320. package/docs/configuration.md +394 -0
  321. package/docs/debug.md +318 -0
  322. package/docs/design-system.md +436 -0
  323. package/docs/dsl.md +688 -0
  324. package/docs/getting-started.md +217 -0
  325. package/docs/injector.md +544 -0
  326. package/docs/methodology.md +616 -0
  327. package/docs/react-api.md +557 -0
  328. package/docs/ssr.md +442 -0
  329. package/docs/styles.md +596 -0
  330. package/docs/tasty-static.md +532 -0
  331. package/package.json +221 -0
  332. package/tasty.config.ts +14 -0
@@ -0,0 +1,185 @@
1
+ import "./sheet-manager.js";
2
+ import { StyleInjector } from "./injector.js";
3
+ import { getConfig, getGlobalInjector, isTestEnvironment, markStylesGenerated } from "../config.js";
4
+ //#region src/injector/index.ts
5
+ /**
6
+ * Inject styles and return className with dispose function
7
+ */
8
+ function inject(rules, options) {
9
+ const injector = getGlobalInjector();
10
+ markStylesGenerated();
11
+ return injector.inject(rules, options);
12
+ }
13
+ /**
14
+ * Inject global rules that should not reserve tasty class names
15
+ */
16
+ function injectGlobal(rules, options) {
17
+ return getGlobalInjector().injectGlobal(rules, options);
18
+ }
19
+ /**
20
+ * Inject raw CSS text directly without parsing
21
+ * This is a low-overhead method for injecting raw CSS that doesn't need tasty processing.
22
+ * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking.
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * // Inject raw CSS
27
+ * const { dispose } = injectRawCSS(`
28
+ * body { margin: 0; padding: 0; }
29
+ * .my-class { color: red; }
30
+ * `);
31
+ *
32
+ * // Later, remove the injected CSS
33
+ * dispose();
34
+ * ```
35
+ */
36
+ function injectRawCSS(css, options) {
37
+ return getGlobalInjector().injectRawCSS(css, options);
38
+ }
39
+ /**
40
+ * Get raw CSS text for SSR
41
+ */
42
+ function getRawCSSText(options) {
43
+ return getGlobalInjector().getRawCSSText(options);
44
+ }
45
+ /**
46
+ * Inject keyframes and return object with toString() and dispose()
47
+ */
48
+ function keyframes(steps, nameOrOptions) {
49
+ return getGlobalInjector().keyframes(steps, nameOrOptions);
50
+ }
51
+ /**
52
+ * Define a CSS @property custom property.
53
+ * This enables advanced features like animating custom properties.
54
+ *
55
+ * Note: @property rules are global and persistent once defined.
56
+ * Re-registering the same property name is a no-op.
57
+ *
58
+ * @param name - The custom property name (must start with --)
59
+ * @param options - Property configuration
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * // Define a color property that can be animated
64
+ * property('--my-color', {
65
+ * syntax: '<color>',
66
+ * initialValue: 'red',
67
+ * });
68
+ *
69
+ * // Define an angle property
70
+ * property('--rotation', {
71
+ * syntax: '<angle>',
72
+ * inherits: false,
73
+ * initialValue: '0deg',
74
+ * });
75
+ * ```
76
+ */
77
+ function property(name, options) {
78
+ return getGlobalInjector().property(name, options);
79
+ }
80
+ /**
81
+ * Check if a CSS @property has already been defined
82
+ *
83
+ * @param name - The custom property name to check
84
+ * @param options - Options including root
85
+ */
86
+ function isPropertyDefined(name, options) {
87
+ return getGlobalInjector().isPropertyDefined(name, options);
88
+ }
89
+ /**
90
+ * Inject a CSS @font-face rule.
91
+ *
92
+ * Permanent and global — no dispose or ref-counting.
93
+ * Deduplicates by content hash (family + descriptors).
94
+ */
95
+ function fontFace(family, descriptors, options) {
96
+ return getGlobalInjector().fontFace(family, descriptors, options);
97
+ }
98
+ /**
99
+ * Inject a CSS @counter-style rule.
100
+ *
101
+ * Permanent and global — no dispose or ref-counting.
102
+ * Deduplicates by name (first definition wins).
103
+ */
104
+ function counterStyle(name, descriptors, options) {
105
+ return getGlobalInjector().counterStyle(name, descriptors, options);
106
+ }
107
+ /**
108
+ * Get CSS text from all sheets (for SSR)
109
+ */
110
+ function getCssText(options) {
111
+ return getGlobalInjector().getCssText(options);
112
+ }
113
+ /**
114
+ * Collect only CSS used by a rendered subtree (like jest-styled-components).
115
+ * Pass the container returned by render(...).
116
+ */
117
+ function getCssTextForNode(node, options) {
118
+ const classSet = /* @__PURE__ */ new Set();
119
+ const readClasses = (el) => {
120
+ const cls = el.getAttribute("class");
121
+ if (!cls) return;
122
+ for (const token of cls.split(/\s+/)) if (/^t[a-z0-9]+$/.test(token)) classSet.add(token);
123
+ };
124
+ if (node.getAttribute) readClasses(node);
125
+ const elements = node.querySelectorAll ? node.querySelectorAll("[class]") : [];
126
+ if (elements) elements.forEach(readClasses);
127
+ return getGlobalInjector().getCssTextForClasses(classSet, options);
128
+ }
129
+ /**
130
+ * Force cleanup of unused rules
131
+ */
132
+ function cleanup(root) {
133
+ return getGlobalInjector().cleanup(root);
134
+ }
135
+ /**
136
+ * Record a render-time usage hit for one or more classNames.
137
+ * Used internally by computeStyles and tasty() to track usage for GC.
138
+ * When the global touch counter reaches `touchInterval`, schedules GC.
139
+ */
140
+ function touch(className, options) {
141
+ if (!getConfig().gc) return;
142
+ getGlobalInjector().touch(className, options);
143
+ }
144
+ /**
145
+ * Synchronous garbage collection of unused styles.
146
+ * Evicts the oldest unused styles when usageMap exceeds capacity.
147
+ * With `{ force: true }`, removes ALL unused styles regardless of capacity.
148
+ *
149
+ * @returns Number of styles evicted.
150
+ */
151
+ function gc(options) {
152
+ return getGlobalInjector().gc(options);
153
+ }
154
+ /**
155
+ * Check if we're currently running in a test environment
156
+ */
157
+ function getIsTestEnvironment() {
158
+ return isTestEnvironment();
159
+ }
160
+ /**
161
+ * Get the global injector instance for debugging
162
+ */
163
+ const injector = { get instance() {
164
+ return getGlobalInjector();
165
+ } };
166
+ /**
167
+ * Destroy all resources and clean up
168
+ */
169
+ function destroy(root) {
170
+ return getGlobalInjector().destroy(root);
171
+ }
172
+ /**
173
+ * Create a new isolated injector instance
174
+ */
175
+ function createInjector(config = {}) {
176
+ return new StyleInjector({
177
+ ...getConfig(),
178
+ forceTextInjection: config.forceTextInjection ?? isTestEnvironment(),
179
+ ...config
180
+ });
181
+ }
182
+ //#endregion
183
+ export { cleanup, counterStyle, createInjector, destroy, fontFace, gc, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, touch };
184
+
185
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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 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"}
@@ -0,0 +1,198 @@
1
+ import { CacheMetrics, CounterStyleDescriptors, FontFaceDescriptors, GCOptions, GlobalInjectResult, InjectResult, KeyframesResult, KeyframesSteps, PropertyDefinition, RawCSSResult, StyleInjectorConfig } from "./types.js";
2
+ import { StyleResult } from "../pipeline/index.js";
3
+ import { SheetManager } from "./sheet-manager.js";
4
+
5
+ //#region src/injector/injector.d.ts
6
+ declare class StyleInjector {
7
+ private sheetManager;
8
+ private config;
9
+ private globalRuleCounter;
10
+ private pendingGCHandle;
11
+ /** @internal — exposed for debug utilities only */
12
+ get _sheetManager(): SheetManager;
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;
19
+ /**
20
+ * Allocate a className for a cacheKey without injecting styles yet.
21
+ * This allows separating className allocation (render phase) from style injection (insertion phase).
22
+ */
23
+ allocateClassName(cacheKey: string, options?: {
24
+ root?: Document | ShadowRoot;
25
+ }): {
26
+ className: string;
27
+ isNewAllocation: boolean;
28
+ };
29
+ /**
30
+ * Inject styles from StyleResult objects
31
+ */
32
+ inject(rules: StyleResult[], options?: {
33
+ root?: Document | ShadowRoot;
34
+ cacheKey?: string;
35
+ }): InjectResult;
36
+ /**
37
+ * Inject global styles (rules without a generated tasty class selector)
38
+ * This ensures we don't reserve a tasty class name (t{number}) for global rules,
39
+ * which could otherwise collide with element-level styles and break lookups.
40
+ */
41
+ injectGlobal(rules: StyleResult[], options?: {
42
+ root?: Document | ShadowRoot;
43
+ }): GlobalInjectResult;
44
+ /**
45
+ * Inject raw CSS text directly without parsing
46
+ * This is a low-overhead alternative to createGlobalStyle for raw CSS
47
+ * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking
48
+ */
49
+ injectRawCSS(css: string, options?: {
50
+ root?: Document | ShadowRoot;
51
+ }): RawCSSResult;
52
+ /**
53
+ * Get raw CSS text for SSR
54
+ */
55
+ getRawCSSText(options?: {
56
+ root?: Document | ShadowRoot;
57
+ }): string;
58
+ /**
59
+ * Increment refCount for an already-injected cacheKey and return a dispose.
60
+ * Used by useStyles on cache hits (hydration or runtime reuse) where
61
+ * the pipeline was skipped but refCount tracking is still needed.
62
+ * Returns null if the cacheKey is not found.
63
+ */
64
+ trackRef(cacheKey: string, options?: {
65
+ root?: Document | ShadowRoot;
66
+ }): InjectResult | null;
67
+ /**
68
+ * Dispose of a className (decrements refCount only).
69
+ */
70
+ private dispose;
71
+ /**
72
+ * Force bulk cleanup of unused styles
73
+ */
74
+ cleanup(root?: Document | ShadowRoot): void;
75
+ /**
76
+ * Get CSS text from all sheets (for SSR)
77
+ */
78
+ getCssText(options?: {
79
+ root?: Document | ShadowRoot;
80
+ }): string;
81
+ /**
82
+ * Get CSS only for the provided tasty classNames (e.g., ["t0","t3"])
83
+ */
84
+ getCssTextForClasses(classNames: Iterable<string>, options?: {
85
+ root?: Document | ShadowRoot;
86
+ }): string;
87
+ /**
88
+ * Get cache performance metrics
89
+ */
90
+ getMetrics(options?: {
91
+ root?: Document | ShadowRoot;
92
+ }): CacheMetrics | null;
93
+ /**
94
+ * Reset cache performance metrics
95
+ */
96
+ resetMetrics(options?: {
97
+ root?: Document | ShadowRoot;
98
+ }): void;
99
+ /**
100
+ * Define a CSS @property custom property.
101
+ *
102
+ * Accepts tasty token syntax for the property name:
103
+ * - `$name` → defines `--name`
104
+ * - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')
105
+ * - `--name` → defines `--name` (legacy format)
106
+ *
107
+ * Example:
108
+ * @property --rotation { syntax: "<angle>"; inherits: false; initial-value: 45deg; }
109
+ *
110
+ * Note: No caching or dispose — this defines a global property.
111
+ *
112
+ * If the same property is registered with different options, a warning is emitted
113
+ * but the original definition is preserved (CSS @property cannot be redefined).
114
+ */
115
+ property(name: string, options?: PropertyDefinition & {
116
+ root?: Document | ShadowRoot;
117
+ }): void;
118
+ /**
119
+ * Check whether a given @property name was already injected by this injector.
120
+ *
121
+ * Accepts tasty token syntax:
122
+ * - `$name` → checks `--name`
123
+ * - `#name` → checks `--name-color`
124
+ * - `--name` → checks `--name` (legacy format)
125
+ */
126
+ isPropertyDefined(name: string, options?: {
127
+ root?: Document | ShadowRoot;
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;
147
+ /**
148
+ * Inject keyframes and return object with toString() and dispose()
149
+ *
150
+ * Keyframes are cached by content (steps). If the same content is injected
151
+ * multiple times with different provided names, the first injected name is reused.
152
+ *
153
+ * If the same name is provided with different content (collision), a unique
154
+ * name is generated to avoid overwriting the existing keyframes.
155
+ */
156
+ keyframes(steps: KeyframesSteps, nameOrOptions?: string | {
157
+ root?: Document | ShadowRoot;
158
+ name?: string;
159
+ }): KeyframesResult;
160
+ /**
161
+ * Dispose keyframes
162
+ */
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;
191
+ /**
192
+ * Destroy all resources for a root
193
+ */
194
+ destroy(root?: Document | ShadowRoot): void;
195
+ }
196
+ //#endregion
197
+ export { StyleInjector };
198
+ //# sourceMappingURL=injector.d.ts.map