@tenphi/tasty 0.0.0-snapshot.08a6610

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 (288) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +666 -0
  3. package/dist/_virtual/_rolldown/runtime.js +8 -0
  4. package/dist/chunks/cacheKey.js +70 -0
  5. package/dist/chunks/cacheKey.js.map +1 -0
  6. package/dist/chunks/definitions.d.ts +37 -0
  7. package/dist/chunks/definitions.js +259 -0
  8. package/dist/chunks/definitions.js.map +1 -0
  9. package/dist/chunks/renderChunk.js +61 -0
  10. package/dist/chunks/renderChunk.js.map +1 -0
  11. package/dist/config.d.ts +311 -0
  12. package/dist/config.js +458 -0
  13. package/dist/config.js.map +1 -0
  14. package/dist/core/index.d.ts +32 -0
  15. package/dist/core/index.js +26 -0
  16. package/dist/debug.d.ts +204 -0
  17. package/dist/debug.js +733 -0
  18. package/dist/debug.js.map +1 -0
  19. package/dist/hooks/useGlobalStyles.d.ts +30 -0
  20. package/dist/hooks/useGlobalStyles.js +83 -0
  21. package/dist/hooks/useGlobalStyles.js.map +1 -0
  22. package/dist/hooks/useKeyframes.d.ts +56 -0
  23. package/dist/hooks/useKeyframes.js +69 -0
  24. package/dist/hooks/useKeyframes.js.map +1 -0
  25. package/dist/hooks/useProperty.d.ts +79 -0
  26. package/dist/hooks/useProperty.js +114 -0
  27. package/dist/hooks/useProperty.js.map +1 -0
  28. package/dist/hooks/useRawCSS.d.ts +53 -0
  29. package/dist/hooks/useRawCSS.js +40 -0
  30. package/dist/hooks/useRawCSS.js.map +1 -0
  31. package/dist/hooks/useStyles.d.ts +45 -0
  32. package/dist/hooks/useStyles.js +248 -0
  33. package/dist/hooks/useStyles.js.map +1 -0
  34. package/dist/index.d.ts +47 -0
  35. package/dist/index.js +33 -0
  36. package/dist/injector/index.d.ts +165 -0
  37. package/dist/injector/index.js +162 -0
  38. package/dist/injector/index.js.map +1 -0
  39. package/dist/injector/injector.d.ts +148 -0
  40. package/dist/injector/injector.js +430 -0
  41. package/dist/injector/injector.js.map +1 -0
  42. package/dist/injector/sheet-manager.d.ts +136 -0
  43. package/dist/injector/sheet-manager.js +729 -0
  44. package/dist/injector/sheet-manager.js.map +1 -0
  45. package/dist/injector/types.d.ts +144 -0
  46. package/dist/keyframes/index.js +206 -0
  47. package/dist/keyframes/index.js.map +1 -0
  48. package/dist/parser/classify.js +319 -0
  49. package/dist/parser/classify.js.map +1 -0
  50. package/dist/parser/const.js +33 -0
  51. package/dist/parser/const.js.map +1 -0
  52. package/dist/parser/lru.js +109 -0
  53. package/dist/parser/lru.js.map +1 -0
  54. package/dist/parser/parser.d.ts +25 -0
  55. package/dist/parser/parser.js +116 -0
  56. package/dist/parser/parser.js.map +1 -0
  57. package/dist/parser/tokenizer.js +69 -0
  58. package/dist/parser/tokenizer.js.map +1 -0
  59. package/dist/parser/types.d.ts +51 -0
  60. package/dist/parser/types.js +46 -0
  61. package/dist/parser/types.js.map +1 -0
  62. package/dist/pipeline/conditions.d.ts +134 -0
  63. package/dist/pipeline/conditions.js +406 -0
  64. package/dist/pipeline/conditions.js.map +1 -0
  65. package/dist/pipeline/exclusive.js +231 -0
  66. package/dist/pipeline/exclusive.js.map +1 -0
  67. package/dist/pipeline/index.d.ts +53 -0
  68. package/dist/pipeline/index.js +660 -0
  69. package/dist/pipeline/index.js.map +1 -0
  70. package/dist/pipeline/materialize.js +856 -0
  71. package/dist/pipeline/materialize.js.map +1 -0
  72. package/dist/pipeline/parseStateKey.d.ts +15 -0
  73. package/dist/pipeline/parseStateKey.js +451 -0
  74. package/dist/pipeline/parseStateKey.js.map +1 -0
  75. package/dist/pipeline/simplify.js +516 -0
  76. package/dist/pipeline/simplify.js.map +1 -0
  77. package/dist/pipeline/warnings.js +18 -0
  78. package/dist/pipeline/warnings.js.map +1 -0
  79. package/dist/plugins/okhsl-plugin.d.ts +35 -0
  80. package/dist/plugins/okhsl-plugin.js +371 -0
  81. package/dist/plugins/okhsl-plugin.js.map +1 -0
  82. package/dist/plugins/types.d.ts +76 -0
  83. package/dist/properties/index.js +236 -0
  84. package/dist/properties/index.js.map +1 -0
  85. package/dist/properties/property-type-resolver.d.ts +24 -0
  86. package/dist/properties/property-type-resolver.js +91 -0
  87. package/dist/properties/property-type-resolver.js.map +1 -0
  88. package/dist/ssr/astro.d.ts +29 -0
  89. package/dist/ssr/astro.js +65 -0
  90. package/dist/ssr/astro.js.map +1 -0
  91. package/dist/ssr/async-storage.d.ts +17 -0
  92. package/dist/ssr/async-storage.js +35 -0
  93. package/dist/ssr/async-storage.js.map +1 -0
  94. package/dist/ssr/collect-auto-properties.js +40 -0
  95. package/dist/ssr/collect-auto-properties.js.map +1 -0
  96. package/dist/ssr/collector.d.ts +85 -0
  97. package/dist/ssr/collector.js +183 -0
  98. package/dist/ssr/collector.js.map +1 -0
  99. package/dist/ssr/context.d.ts +8 -0
  100. package/dist/ssr/context.js +14 -0
  101. package/dist/ssr/context.js.map +1 -0
  102. package/dist/ssr/format-global-rules.js +22 -0
  103. package/dist/ssr/format-global-rules.js.map +1 -0
  104. package/dist/ssr/format-keyframes.js +70 -0
  105. package/dist/ssr/format-keyframes.js.map +1 -0
  106. package/dist/ssr/format-property.js +48 -0
  107. package/dist/ssr/format-property.js.map +1 -0
  108. package/dist/ssr/format-rules.js +70 -0
  109. package/dist/ssr/format-rules.js.map +1 -0
  110. package/dist/ssr/hydrate.d.ts +22 -0
  111. package/dist/ssr/hydrate.js +50 -0
  112. package/dist/ssr/hydrate.js.map +1 -0
  113. package/dist/ssr/index.d.ts +5 -0
  114. package/dist/ssr/index.js +12 -0
  115. package/dist/ssr/index.js.map +1 -0
  116. package/dist/ssr/next.d.ts +45 -0
  117. package/dist/ssr/next.js +71 -0
  118. package/dist/ssr/next.js.map +1 -0
  119. package/dist/ssr/ssr-collector-ref.js +12 -0
  120. package/dist/ssr/ssr-collector-ref.js.map +1 -0
  121. package/dist/states/index.d.ts +49 -0
  122. package/dist/states/index.js +416 -0
  123. package/dist/states/index.js.map +1 -0
  124. package/dist/static/index.d.ts +5 -0
  125. package/dist/static/index.js +5 -0
  126. package/dist/static/tastyStatic.d.ts +46 -0
  127. package/dist/static/tastyStatic.js +31 -0
  128. package/dist/static/tastyStatic.js.map +1 -0
  129. package/dist/static/types.d.ts +49 -0
  130. package/dist/static/types.js +24 -0
  131. package/dist/static/types.js.map +1 -0
  132. package/dist/styles/align.d.ts +15 -0
  133. package/dist/styles/align.js +14 -0
  134. package/dist/styles/align.js.map +1 -0
  135. package/dist/styles/border.d.ts +25 -0
  136. package/dist/styles/border.js +114 -0
  137. package/dist/styles/border.js.map +1 -0
  138. package/dist/styles/color.d.ts +14 -0
  139. package/dist/styles/color.js +23 -0
  140. package/dist/styles/color.js.map +1 -0
  141. package/dist/styles/createStyle.js +77 -0
  142. package/dist/styles/createStyle.js.map +1 -0
  143. package/dist/styles/dimension.js +97 -0
  144. package/dist/styles/dimension.js.map +1 -0
  145. package/dist/styles/display.d.ts +37 -0
  146. package/dist/styles/display.js +67 -0
  147. package/dist/styles/display.js.map +1 -0
  148. package/dist/styles/fade.d.ts +15 -0
  149. package/dist/styles/fade.js +58 -0
  150. package/dist/styles/fade.js.map +1 -0
  151. package/dist/styles/fill.d.ts +42 -0
  152. package/dist/styles/fill.js +52 -0
  153. package/dist/styles/fill.js.map +1 -0
  154. package/dist/styles/flow.d.ts +16 -0
  155. package/dist/styles/flow.js +12 -0
  156. package/dist/styles/flow.js.map +1 -0
  157. package/dist/styles/gap.d.ts +31 -0
  158. package/dist/styles/gap.js +37 -0
  159. package/dist/styles/gap.js.map +1 -0
  160. package/dist/styles/height.d.ts +17 -0
  161. package/dist/styles/height.js +20 -0
  162. package/dist/styles/height.js.map +1 -0
  163. package/dist/styles/index.d.ts +2 -0
  164. package/dist/styles/index.js +9 -0
  165. package/dist/styles/index.js.map +1 -0
  166. package/dist/styles/inset.d.ts +52 -0
  167. package/dist/styles/inset.js +150 -0
  168. package/dist/styles/inset.js.map +1 -0
  169. package/dist/styles/justify.d.ts +15 -0
  170. package/dist/styles/justify.js +14 -0
  171. package/dist/styles/justify.js.map +1 -0
  172. package/dist/styles/list.d.ts +16 -0
  173. package/dist/styles/list.js +98 -0
  174. package/dist/styles/list.js.map +1 -0
  175. package/dist/styles/margin.d.ts +24 -0
  176. package/dist/styles/margin.js +104 -0
  177. package/dist/styles/margin.js.map +1 -0
  178. package/dist/styles/outline.d.ts +29 -0
  179. package/dist/styles/outline.js +65 -0
  180. package/dist/styles/outline.js.map +1 -0
  181. package/dist/styles/padding.d.ts +24 -0
  182. package/dist/styles/padding.js +104 -0
  183. package/dist/styles/padding.js.map +1 -0
  184. package/dist/styles/predefined.d.ts +71 -0
  185. package/dist/styles/predefined.js +238 -0
  186. package/dist/styles/predefined.js.map +1 -0
  187. package/dist/styles/preset.d.ts +47 -0
  188. package/dist/styles/preset.js +126 -0
  189. package/dist/styles/preset.js.map +1 -0
  190. package/dist/styles/radius.d.ts +14 -0
  191. package/dist/styles/radius.js +51 -0
  192. package/dist/styles/radius.js.map +1 -0
  193. package/dist/styles/scrollbar.d.ts +25 -0
  194. package/dist/styles/scrollbar.js +48 -0
  195. package/dist/styles/scrollbar.js.map +1 -0
  196. package/dist/styles/shadow.d.ts +14 -0
  197. package/dist/styles/shadow.js +24 -0
  198. package/dist/styles/shadow.js.map +1 -0
  199. package/dist/styles/transition.d.ts +14 -0
  200. package/dist/styles/transition.js +158 -0
  201. package/dist/styles/transition.js.map +1 -0
  202. package/dist/styles/types.d.ts +508 -0
  203. package/dist/styles/width.d.ts +17 -0
  204. package/dist/styles/width.js +20 -0
  205. package/dist/styles/width.js.map +1 -0
  206. package/dist/tasty.d.ts +981 -0
  207. package/dist/tasty.js +206 -0
  208. package/dist/tasty.js.map +1 -0
  209. package/dist/types.d.ts +184 -0
  210. package/dist/utils/cache-wrapper.js +26 -0
  211. package/dist/utils/cache-wrapper.js.map +1 -0
  212. package/dist/utils/case-converter.js +8 -0
  213. package/dist/utils/case-converter.js.map +1 -0
  214. package/dist/utils/colors.d.ts +5 -0
  215. package/dist/utils/colors.js +9 -0
  216. package/dist/utils/colors.js.map +1 -0
  217. package/dist/utils/css-types.d.ts +7 -0
  218. package/dist/utils/dotize.d.ts +26 -0
  219. package/dist/utils/dotize.js +122 -0
  220. package/dist/utils/dotize.js.map +1 -0
  221. package/dist/utils/filter-base-props.d.ts +15 -0
  222. package/dist/utils/filter-base-props.js +45 -0
  223. package/dist/utils/filter-base-props.js.map +1 -0
  224. package/dist/utils/get-display-name.d.ts +7 -0
  225. package/dist/utils/get-display-name.js +10 -0
  226. package/dist/utils/get-display-name.js.map +1 -0
  227. package/dist/utils/hsl-to-rgb.js +38 -0
  228. package/dist/utils/hsl-to-rgb.js.map +1 -0
  229. package/dist/utils/is-dev-env.js +19 -0
  230. package/dist/utils/is-dev-env.js.map +1 -0
  231. package/dist/utils/is-valid-element-type.js +15 -0
  232. package/dist/utils/is-valid-element-type.js.map +1 -0
  233. package/dist/utils/merge-styles.d.ts +7 -0
  234. package/dist/utils/merge-styles.js +146 -0
  235. package/dist/utils/merge-styles.js.map +1 -0
  236. package/dist/utils/mod-attrs.d.ts +8 -0
  237. package/dist/utils/mod-attrs.js +21 -0
  238. package/dist/utils/mod-attrs.js.map +1 -0
  239. package/dist/utils/okhsl-to-rgb.js +296 -0
  240. package/dist/utils/okhsl-to-rgb.js.map +1 -0
  241. package/dist/utils/process-tokens.d.ts +31 -0
  242. package/dist/utils/process-tokens.js +171 -0
  243. package/dist/utils/process-tokens.js.map +1 -0
  244. package/dist/utils/resolve-recipes.d.ts +17 -0
  245. package/dist/utils/resolve-recipes.js +147 -0
  246. package/dist/utils/resolve-recipes.js.map +1 -0
  247. package/dist/utils/selector-transform.js +32 -0
  248. package/dist/utils/selector-transform.js.map +1 -0
  249. package/dist/utils/string.js +8 -0
  250. package/dist/utils/string.js.map +1 -0
  251. package/dist/utils/styles.d.ts +177 -0
  252. package/dist/utils/styles.js +730 -0
  253. package/dist/utils/styles.js.map +1 -0
  254. package/dist/utils/typography.d.ts +47 -0
  255. package/dist/utils/typography.js +43 -0
  256. package/dist/utils/typography.js.map +1 -0
  257. package/dist/utils/warnings.d.ts +16 -0
  258. package/dist/utils/warnings.js +16 -0
  259. package/dist/utils/warnings.js.map +1 -0
  260. package/dist/zero/babel.d.ts +147 -0
  261. package/dist/zero/babel.js +331 -0
  262. package/dist/zero/babel.js.map +1 -0
  263. package/dist/zero/css-writer.d.ts +45 -0
  264. package/dist/zero/css-writer.js +74 -0
  265. package/dist/zero/css-writer.js.map +1 -0
  266. package/dist/zero/extractor.d.ts +24 -0
  267. package/dist/zero/extractor.js +215 -0
  268. package/dist/zero/extractor.js.map +1 -0
  269. package/dist/zero/index.d.ts +3 -0
  270. package/dist/zero/index.js +4 -0
  271. package/dist/zero/next.d.ts +74 -0
  272. package/dist/zero/next.js +129 -0
  273. package/dist/zero/next.js.map +1 -0
  274. package/docs/adoption.md +286 -0
  275. package/docs/comparison.md +413 -0
  276. package/docs/configuration.md +242 -0
  277. package/docs/debug.md +505 -0
  278. package/docs/design-system.md +401 -0
  279. package/docs/dsl.md +540 -0
  280. package/docs/getting-started.md +201 -0
  281. package/docs/injector.md +528 -0
  282. package/docs/methodology.md +501 -0
  283. package/docs/runtime.md +291 -0
  284. package/docs/ssr.md +382 -0
  285. package/docs/styles.md +574 -0
  286. package/docs/tasty-static.md +421 -0
  287. package/package.json +209 -0
  288. package/tasty.config.ts +14 -0
@@ -0,0 +1,165 @@
1
+ import { CacheMetrics, DisposeFunction, GlobalInjectResult, InjectResult, KeyframesCacheEntry, KeyframesInfo, KeyframesResult, KeyframesSteps, PropertyDefinition, RawCSSResult, RootRegistry, RuleInfo, SheetInfo, StyleInjectorConfig, StyleRule } from "./types.js";
2
+ import { StyleResult } from "../pipeline/index.js";
3
+ import { SheetManager } from "./sheet-manager.js";
4
+ import { StyleInjector } from "./injector.js";
5
+
6
+ //#region src/injector/index.d.ts
7
+ /**
8
+ * Allocate a className for a cacheKey without injecting styles yet
9
+ */
10
+ declare function allocateClassName(cacheKey: string, options?: {
11
+ root?: Document | ShadowRoot;
12
+ }): {
13
+ className: string;
14
+ isNewAllocation: boolean;
15
+ };
16
+ /**
17
+ * Track a reference to an already-injected cacheKey (refCount + dispose).
18
+ * Used on cache hits (SSR hydration or runtime reuse) where the pipeline
19
+ * was skipped. Returns null if the cacheKey is not in the cache.
20
+ */
21
+ declare function trackRef(cacheKey: string, options?: {
22
+ root?: Document | ShadowRoot;
23
+ }): InjectResult | null;
24
+ /**
25
+ * Inject styles and return className with dispose function
26
+ */
27
+ declare function inject(rules: StyleResult[], options?: {
28
+ root?: Document | ShadowRoot;
29
+ cacheKey?: string;
30
+ }): InjectResult;
31
+ /**
32
+ * Inject global rules that should not reserve tasty class names
33
+ */
34
+ declare function injectGlobal(rules: StyleResult[], options?: {
35
+ root?: Document | ShadowRoot;
36
+ }): GlobalInjectResult;
37
+ /**
38
+ * Inject raw CSS text directly without parsing
39
+ * This is a low-overhead method for injecting raw CSS that doesn't need tasty processing.
40
+ * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking.
41
+ *
42
+ * @example
43
+ * ```tsx
44
+ * // Inject raw CSS
45
+ * const { dispose } = injectRawCSS(`
46
+ * body { margin: 0; padding: 0; }
47
+ * .my-class { color: red; }
48
+ * `);
49
+ *
50
+ * // Later, remove the injected CSS
51
+ * dispose();
52
+ * ```
53
+ */
54
+ declare function injectRawCSS(css: string, options?: {
55
+ root?: Document | ShadowRoot;
56
+ }): {
57
+ dispose: () => void;
58
+ };
59
+ /**
60
+ * Get raw CSS text for SSR
61
+ */
62
+ declare function getRawCSSText(options?: {
63
+ root?: Document | ShadowRoot;
64
+ }): string;
65
+ /**
66
+ * Inject keyframes and return object with toString() and dispose()
67
+ */
68
+ declare function keyframes(steps: KeyframesSteps, nameOrOptions?: string | {
69
+ root?: Document | ShadowRoot;
70
+ name?: string;
71
+ }): KeyframesResult;
72
+ interface PropertyOptions {
73
+ /**
74
+ * CSS syntax string for the property (e.g., '<color>', '<length>', '<angle>')
75
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@property/syntax
76
+ */
77
+ syntax?: string;
78
+ /**
79
+ * Whether the property inherits from parent elements
80
+ * @default true
81
+ */
82
+ inherits?: boolean;
83
+ /**
84
+ * Initial value for the property
85
+ */
86
+ initialValue?: string | number;
87
+ /**
88
+ * Shadow root or document to inject into
89
+ */
90
+ root?: Document | ShadowRoot;
91
+ }
92
+ /**
93
+ * Define a CSS @property custom property.
94
+ * This enables advanced features like animating custom properties.
95
+ *
96
+ * Note: @property rules are global and persistent once defined.
97
+ * Re-registering the same property name is a no-op.
98
+ *
99
+ * @param name - The custom property name (must start with --)
100
+ * @param options - Property configuration
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * // Define a color property that can be animated
105
+ * property('--my-color', {
106
+ * syntax: '<color>',
107
+ * initialValue: 'red',
108
+ * });
109
+ *
110
+ * // Define an angle property
111
+ * property('--rotation', {
112
+ * syntax: '<angle>',
113
+ * inherits: false,
114
+ * initialValue: '0deg',
115
+ * });
116
+ * ```
117
+ */
118
+ declare function property(name: string, options?: PropertyOptions): void;
119
+ /**
120
+ * Check if a CSS @property has already been defined
121
+ *
122
+ * @param name - The custom property name to check
123
+ * @param options - Options including root
124
+ */
125
+ declare function isPropertyDefined(name: string, options?: {
126
+ root?: Document | ShadowRoot;
127
+ }): boolean;
128
+ /**
129
+ * Get CSS text from all sheets (for SSR)
130
+ */
131
+ declare function getCssText(options?: {
132
+ root?: Document | ShadowRoot;
133
+ }): string;
134
+ /**
135
+ * Collect only CSS used by a rendered subtree (like jest-styled-components).
136
+ * Pass the container returned by render(...).
137
+ */
138
+ declare function getCssTextForNode(node: ParentNode | Element | DocumentFragment, options?: {
139
+ root?: Document | ShadowRoot;
140
+ }): string;
141
+ /**
142
+ * Force cleanup of unused rules
143
+ */
144
+ declare function cleanup(root?: Document | ShadowRoot): void;
145
+ /**
146
+ * Check if we're currently running in a test environment
147
+ */
148
+ declare function getIsTestEnvironment(): boolean;
149
+ /**
150
+ * Get the global injector instance for debugging
151
+ */
152
+ declare const injector: {
153
+ readonly instance: StyleInjector;
154
+ };
155
+ /**
156
+ * Destroy all resources and clean up
157
+ */
158
+ declare function destroy(root?: Document | ShadowRoot): void;
159
+ /**
160
+ * Create a new isolated injector instance
161
+ */
162
+ declare function createInjector(config?: Partial<StyleInjectorConfig>): StyleInjector;
163
+ //#endregion
164
+ export { PropertyOptions, allocateClassName, cleanup, createInjector, destroy, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, trackRef };
165
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,162 @@
1
+ import { SheetManager } from "./sheet-manager.js";
2
+ import { StyleInjector } from "./injector.js";
3
+ import { getConfig, getGlobalInjector, isTestEnvironment, markStylesGenerated } from "../config.js";
4
+
5
+ //#region src/injector/index.ts
6
+ /**
7
+ * Allocate a className for a cacheKey without injecting styles yet
8
+ */
9
+ function allocateClassName(cacheKey, options) {
10
+ return getGlobalInjector().allocateClassName(cacheKey, options);
11
+ }
12
+ /**
13
+ * Track a reference to an already-injected cacheKey (refCount + dispose).
14
+ * Used on cache hits (SSR hydration or runtime reuse) where the pipeline
15
+ * was skipped. Returns null if the cacheKey is not in the cache.
16
+ */
17
+ function trackRef(cacheKey, options) {
18
+ return getGlobalInjector().trackRef(cacheKey, options);
19
+ }
20
+ /**
21
+ * Inject styles and return className with dispose function
22
+ */
23
+ function inject(rules, options) {
24
+ markStylesGenerated();
25
+ return getGlobalInjector().inject(rules, options);
26
+ }
27
+ /**
28
+ * Inject global rules that should not reserve tasty class names
29
+ */
30
+ function injectGlobal(rules, options) {
31
+ return getGlobalInjector().injectGlobal(rules, options);
32
+ }
33
+ /**
34
+ * Inject raw CSS text directly without parsing
35
+ * This is a low-overhead method for injecting raw CSS that doesn't need tasty processing.
36
+ * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking.
37
+ *
38
+ * @example
39
+ * ```tsx
40
+ * // Inject raw CSS
41
+ * const { dispose } = injectRawCSS(`
42
+ * body { margin: 0; padding: 0; }
43
+ * .my-class { color: red; }
44
+ * `);
45
+ *
46
+ * // Later, remove the injected CSS
47
+ * dispose();
48
+ * ```
49
+ */
50
+ function injectRawCSS(css, options) {
51
+ return getGlobalInjector().injectRawCSS(css, options);
52
+ }
53
+ /**
54
+ * Get raw CSS text for SSR
55
+ */
56
+ function getRawCSSText(options) {
57
+ return getGlobalInjector().getRawCSSText(options);
58
+ }
59
+ /**
60
+ * Inject keyframes and return object with toString() and dispose()
61
+ */
62
+ function keyframes(steps, nameOrOptions) {
63
+ return getGlobalInjector().keyframes(steps, nameOrOptions);
64
+ }
65
+ /**
66
+ * Define a CSS @property custom property.
67
+ * This enables advanced features like animating custom properties.
68
+ *
69
+ * Note: @property rules are global and persistent once defined.
70
+ * Re-registering the same property name is a no-op.
71
+ *
72
+ * @param name - The custom property name (must start with --)
73
+ * @param options - Property configuration
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * // Define a color property that can be animated
78
+ * property('--my-color', {
79
+ * syntax: '<color>',
80
+ * initialValue: 'red',
81
+ * });
82
+ *
83
+ * // Define an angle property
84
+ * property('--rotation', {
85
+ * syntax: '<angle>',
86
+ * inherits: false,
87
+ * initialValue: '0deg',
88
+ * });
89
+ * ```
90
+ */
91
+ function property(name, options) {
92
+ return getGlobalInjector().property(name, options);
93
+ }
94
+ /**
95
+ * Check if a CSS @property has already been defined
96
+ *
97
+ * @param name - The custom property name to check
98
+ * @param options - Options including root
99
+ */
100
+ function isPropertyDefined(name, options) {
101
+ return getGlobalInjector().isPropertyDefined(name, options);
102
+ }
103
+ /**
104
+ * Get CSS text from all sheets (for SSR)
105
+ */
106
+ function getCssText(options) {
107
+ return getGlobalInjector().getCssText(options);
108
+ }
109
+ /**
110
+ * Collect only CSS used by a rendered subtree (like jest-styled-components).
111
+ * Pass the container returned by render(...).
112
+ */
113
+ function getCssTextForNode(node, options) {
114
+ const classSet = /* @__PURE__ */ new Set();
115
+ const readClasses = (el) => {
116
+ const cls = el.getAttribute("class");
117
+ if (!cls) return;
118
+ for (const token of cls.split(/\s+/)) if (/^t\d+$/.test(token)) classSet.add(token);
119
+ };
120
+ if (node.getAttribute) readClasses(node);
121
+ const elements = node.querySelectorAll ? node.querySelectorAll("[class]") : [];
122
+ if (elements) elements.forEach(readClasses);
123
+ return getGlobalInjector().getCssTextForClasses(classSet, options);
124
+ }
125
+ /**
126
+ * Force cleanup of unused rules
127
+ */
128
+ function cleanup(root) {
129
+ return getGlobalInjector().cleanup(root);
130
+ }
131
+ /**
132
+ * Check if we're currently running in a test environment
133
+ */
134
+ function getIsTestEnvironment() {
135
+ return isTestEnvironment();
136
+ }
137
+ /**
138
+ * Get the global injector instance for debugging
139
+ */
140
+ const injector = { get instance() {
141
+ return getGlobalInjector();
142
+ } };
143
+ /**
144
+ * Destroy all resources and clean up
145
+ */
146
+ function destroy(root) {
147
+ return getGlobalInjector().destroy(root);
148
+ }
149
+ /**
150
+ * Create a new isolated injector instance
151
+ */
152
+ function createInjector(config = {}) {
153
+ return new StyleInjector({
154
+ ...getConfig(),
155
+ forceTextInjection: config.forceTextInjection ?? isTestEnvironment(),
156
+ ...config
157
+ });
158
+ }
159
+
160
+ //#endregion
161
+ export { allocateClassName, cleanup, createInjector, destroy, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, trackRef };
162
+ //# 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 GlobalInjectResult,\n InjectResult,\n KeyframesResult,\n KeyframesSteps,\n StyleInjectorConfig,\n} from './types';\n\n/**\n * Allocate a className for a cacheKey without injecting styles yet\n */\nexport function allocateClassName(\n cacheKey: string,\n options?: { root?: Document | ShadowRoot },\n): { className: string; isNewAllocation: boolean } {\n return getGlobalInjector().allocateClassName(cacheKey, options);\n}\n\n/**\n * Track a reference to an already-injected cacheKey (refCount + dispose).\n * Used on cache hits (SSR hydration or runtime reuse) where the pipeline\n * was skipped. Returns null if the cacheKey is not in the cache.\n */\nexport function trackRef(\n cacheKey: string,\n options?: { root?: Document | ShadowRoot },\n): InjectResult | null {\n return getGlobalInjector().trackRef(cacheKey, options);\n}\n\n/**\n * Inject styles and return className with dispose function\n */\nexport function inject(\n rules: StyleResult[],\n options?: { root?: Document | ShadowRoot; cacheKey?: string },\n): InjectResult {\n // Mark that styles have been generated (prevents configuration changes)\n markStylesGenerated();\n\n return getGlobalInjector().inject(rules, options);\n}\n\n/**\n * Inject global rules that should not reserve tasty class names\n */\nexport function injectGlobal(\n rules: StyleResult[],\n options?: { root?: Document | ShadowRoot },\n): GlobalInjectResult {\n return getGlobalInjector().injectGlobal(rules, options);\n}\n\n/**\n * Inject raw CSS text directly without parsing\n * This is a low-overhead method for injecting raw CSS that doesn't need tasty processing.\n * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking.\n *\n * @example\n * ```tsx\n * // Inject raw CSS\n * const { dispose } = injectRawCSS(`\n * body { margin: 0; padding: 0; }\n * .my-class { color: red; }\n * `);\n *\n * // Later, remove the injected CSS\n * dispose();\n * ```\n */\nexport function injectRawCSS(\n css: string,\n options?: { root?: Document | ShadowRoot },\n): { dispose: () => void } {\n return getGlobalInjector().injectRawCSS(css, options);\n}\n\n/**\n * Get raw CSS text for SSR\n */\nexport function getRawCSSText(options?: {\n root?: Document | ShadowRoot;\n}): string {\n return getGlobalInjector().getRawCSSText(options);\n}\n\n/**\n * Inject keyframes and return object with toString() and dispose()\n */\nexport function keyframes(\n steps: KeyframesSteps,\n nameOrOptions?: string | { root?: Document | ShadowRoot; name?: string },\n): KeyframesResult {\n return getGlobalInjector().keyframes(steps, nameOrOptions);\n}\n\nexport interface PropertyOptions {\n /**\n * CSS syntax string for the property (e.g., '<color>', '<length>', '<angle>')\n * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@property/syntax\n */\n syntax?: string;\n /**\n * Whether the property inherits from parent elements\n * @default true\n */\n inherits?: boolean;\n /**\n * Initial value for the property\n */\n initialValue?: string | number;\n /**\n * Shadow root or document to inject into\n */\n root?: Document | ShadowRoot;\n}\n\n/**\n * Define a CSS @property custom property.\n * This enables advanced features like animating custom properties.\n *\n * Note: @property rules are global and persistent once defined.\n * Re-registering the same property name is a no-op.\n *\n * @param name - The custom property name (must start with --)\n * @param options - Property configuration\n *\n * @example\n * ```ts\n * // Define a color property that can be animated\n * property('--my-color', {\n * syntax: '<color>',\n * initialValue: 'red',\n * });\n *\n * // Define an angle property\n * property('--rotation', {\n * syntax: '<angle>',\n * inherits: false,\n * initialValue: '0deg',\n * });\n * ```\n */\nexport function property(name: string, options?: PropertyOptions): void {\n return getGlobalInjector().property(name, options);\n}\n\n/**\n * Check if a CSS @property has already been defined\n *\n * @param name - The custom property name to check\n * @param options - Options including root\n */\nexport function isPropertyDefined(\n name: string,\n options?: { root?: Document | ShadowRoot },\n): boolean {\n return getGlobalInjector().isPropertyDefined(name, options);\n}\n\n/**\n * Get CSS text from all sheets (for SSR)\n */\nexport function getCssText(options?: { root?: Document | ShadowRoot }): string {\n return getGlobalInjector().getCssText(options);\n}\n\n/**\n * Collect only CSS used by a rendered subtree (like jest-styled-components).\n * Pass the container returned by render(...).\n */\nexport function getCssTextForNode(\n node: ParentNode | Element | DocumentFragment,\n options?: { root?: Document | ShadowRoot },\n): string {\n // Collect tasty-generated class names (t<number>) from the subtree\n const classSet = new Set<string>();\n\n const readClasses = (el: Element) => {\n const cls = el.getAttribute('class');\n if (!cls) return;\n for (const token of cls.split(/\\s+/)) {\n if (/^t\\d+$/.test(token)) classSet.add(token);\n }\n };\n\n // Include node itself if it's an Element\n if ((node as Element).getAttribute) {\n readClasses(node as Element);\n }\n // Walk descendants\n const elements = (node as ParentNode).querySelectorAll\n ? (node as ParentNode).querySelectorAll('[class]')\n : ([] as unknown as NodeListOf<Element>);\n if (elements) elements.forEach(readClasses);\n\n return getGlobalInjector().getCssTextForClasses(classSet, options);\n}\n\n/**\n * Force cleanup of unused rules\n */\nexport function cleanup(root?: Document | ShadowRoot): void {\n return getGlobalInjector().cleanup(root);\n}\n\n/**\n * Check if we're currently running in a test environment\n */\nexport function getIsTestEnvironment(): boolean {\n return isTestEnvironment();\n}\n\n/**\n * Get the global injector instance for debugging\n */\nexport const injector = {\n get instance() {\n return getGlobalInjector();\n },\n};\n\n/**\n * Destroy all resources and clean up\n */\nexport function destroy(root?: Document | ShadowRoot): void {\n return getGlobalInjector().destroy(root);\n}\n\n/**\n * Create a new isolated injector instance\n */\nexport function createInjector(\n config: Partial<StyleInjectorConfig> = {},\n): StyleInjector {\n const defaultConfig = getConfig();\n\n const fullConfig: StyleInjectorConfig = {\n ...defaultConfig,\n // Auto-enable forceTextInjection in test environments\n forceTextInjection: config.forceTextInjection ?? isTestEnvironment(),\n ...config,\n };\n\n return new StyleInjector(fullConfig);\n}\n\n// Re-export types\nexport type {\n StyleInjectorConfig,\n InjectResult,\n DisposeFunction,\n RuleInfo,\n SheetInfo,\n RootRegistry,\n StyleRule,\n KeyframesInfo,\n KeyframesResult,\n KeyframesSteps,\n KeyframesCacheEntry,\n CacheMetrics,\n RawCSSResult,\n PropertyDefinition,\n} from './types';\n\nexport { StyleInjector } from './injector';\nexport { SheetManager } from './sheet-manager';\n"],"mappings":";;;;;;;;AAoBA,SAAgB,kBACd,UACA,SACiD;AACjD,QAAO,mBAAmB,CAAC,kBAAkB,UAAU,QAAQ;;;;;;;AAQjE,SAAgB,SACd,UACA,SACqB;AACrB,QAAO,mBAAmB,CAAC,SAAS,UAAU,QAAQ;;;;;AAMxD,SAAgB,OACd,OACA,SACc;AAEd,sBAAqB;AAErB,QAAO,mBAAmB,CAAC,OAAO,OAAO,QAAQ;;;;;AAMnD,SAAgB,aACd,OACA,SACoB;AACpB,QAAO,mBAAmB,CAAC,aAAa,OAAO,QAAQ;;;;;;;;;;;;;;;;;;;AAoBzD,SAAgB,aACd,KACA,SACyB;AACzB,QAAO,mBAAmB,CAAC,aAAa,KAAK,QAAQ;;;;;AAMvD,SAAgB,cAAc,SAEnB;AACT,QAAO,mBAAmB,CAAC,cAAc,QAAQ;;;;;AAMnD,SAAgB,UACd,OACA,eACiB;AACjB,QAAO,mBAAmB,CAAC,UAAU,OAAO,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkD5D,SAAgB,SAAS,MAAc,SAAiC;AACtE,QAAO,mBAAmB,CAAC,SAAS,MAAM,QAAQ;;;;;;;;AASpD,SAAgB,kBACd,MACA,SACS;AACT,QAAO,mBAAmB,CAAC,kBAAkB,MAAM,QAAQ;;;;;AAM7D,SAAgB,WAAW,SAAoD;AAC7E,QAAO,mBAAmB,CAAC,WAAW,QAAQ;;;;;;AAOhD,SAAgB,kBACd,MACA,SACQ;CAER,MAAM,2BAAW,IAAI,KAAa;CAElC,MAAM,eAAe,OAAgB;EACnC,MAAM,MAAM,GAAG,aAAa,QAAQ;AACpC,MAAI,CAAC,IAAK;AACV,OAAK,MAAM,SAAS,IAAI,MAAM,MAAM,CAClC,KAAI,SAAS,KAAK,MAAM,CAAE,UAAS,IAAI,MAAM;;AAKjD,KAAK,KAAiB,aACpB,aAAY,KAAgB;CAG9B,MAAM,WAAY,KAAoB,mBACjC,KAAoB,iBAAiB,UAAU,GAC/C,EAAE;AACP,KAAI,SAAU,UAAS,QAAQ,YAAY;AAE3C,QAAO,mBAAmB,CAAC,qBAAqB,UAAU,QAAQ;;;;;AAMpE,SAAgB,QAAQ,MAAoC;AAC1D,QAAO,mBAAmB,CAAC,QAAQ,KAAK;;;;;AAM1C,SAAgB,uBAAgC;AAC9C,QAAO,mBAAmB;;;;;AAM5B,MAAa,WAAW,EACtB,IAAI,WAAW;AACb,QAAO,mBAAmB;GAE7B;;;;AAKD,SAAgB,QAAQ,MAAoC;AAC1D,QAAO,mBAAmB,CAAC,QAAQ,KAAK;;;;;AAM1C,SAAgB,eACd,SAAuC,EAAE,EAC1B;AAUf,QAAO,IAAI,cAP6B;EACtC,GAHoB,WAAW;EAK/B,oBAAoB,OAAO,sBAAsB,mBAAmB;EACpE,GAAG;EACJ,CAEmC"}
@@ -0,0 +1,148 @@
1
+ import { CacheMetrics, 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 cleanupScheduled;
10
+ private globalRuleCounter;
11
+ /** @internal — exposed for debug utilities only */
12
+ get _sheetManager(): SheetManager;
13
+ constructor(config?: StyleInjectorConfig);
14
+ /**
15
+ * Allocate a className for a cacheKey without injecting styles yet.
16
+ * This allows separating className allocation (render phase) from style injection (insertion phase).
17
+ */
18
+ allocateClassName(cacheKey: string, options?: {
19
+ root?: Document | ShadowRoot;
20
+ }): {
21
+ className: string;
22
+ isNewAllocation: boolean;
23
+ };
24
+ /**
25
+ * Inject styles from StyleResult objects
26
+ */
27
+ inject(rules: StyleResult[], options?: {
28
+ root?: Document | ShadowRoot;
29
+ cacheKey?: string;
30
+ }): InjectResult;
31
+ /**
32
+ * Inject global styles (rules without a generated tasty class selector)
33
+ * This ensures we don't reserve a tasty class name (t{number}) for global rules,
34
+ * which could otherwise collide with element-level styles and break lookups.
35
+ */
36
+ injectGlobal(rules: StyleResult[], options?: {
37
+ root?: Document | ShadowRoot;
38
+ }): GlobalInjectResult;
39
+ /**
40
+ * Inject raw CSS text directly without parsing
41
+ * This is a low-overhead alternative to createGlobalStyle for raw CSS
42
+ * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking
43
+ */
44
+ injectRawCSS(css: string, options?: {
45
+ root?: Document | ShadowRoot;
46
+ }): RawCSSResult;
47
+ /**
48
+ * Get raw CSS text for SSR
49
+ */
50
+ getRawCSSText(options?: {
51
+ root?: Document | ShadowRoot;
52
+ }): string;
53
+ /**
54
+ * Increment refCount for an already-injected cacheKey and return a dispose.
55
+ * Used by useStyles on cache hits (hydration or runtime reuse) where
56
+ * the pipeline was skipped but refCount tracking is still needed.
57
+ * Returns null if the cacheKey is not found.
58
+ */
59
+ trackRef(cacheKey: string, options?: {
60
+ root?: Document | ShadowRoot;
61
+ }): InjectResult | null;
62
+ /**
63
+ * Dispose of a className
64
+ */
65
+ private dispose;
66
+ /**
67
+ * Force bulk cleanup of unused styles
68
+ */
69
+ cleanup(root?: Document | ShadowRoot): void;
70
+ /**
71
+ * Get CSS text from all sheets (for SSR)
72
+ */
73
+ getCssText(options?: {
74
+ root?: Document | ShadowRoot;
75
+ }): string;
76
+ /**
77
+ * Get CSS only for the provided tasty classNames (e.g., ["t0","t3"])
78
+ */
79
+ getCssTextForClasses(classNames: Iterable<string>, options?: {
80
+ root?: Document | ShadowRoot;
81
+ }): string;
82
+ /**
83
+ * Get cache performance metrics
84
+ */
85
+ getMetrics(options?: {
86
+ root?: Document | ShadowRoot;
87
+ }): CacheMetrics | null;
88
+ /**
89
+ * Reset cache performance metrics
90
+ */
91
+ resetMetrics(options?: {
92
+ root?: Document | ShadowRoot;
93
+ }): void;
94
+ /**
95
+ * Define a CSS @property custom property.
96
+ *
97
+ * Accepts tasty token syntax for the property name:
98
+ * - `$name` → defines `--name`
99
+ * - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')
100
+ * - `--name` → defines `--name` (legacy format)
101
+ *
102
+ * Example:
103
+ * @property --rotation { syntax: "<angle>"; inherits: false; initial-value: 45deg; }
104
+ *
105
+ * Note: No caching or dispose — this defines a global property.
106
+ *
107
+ * If the same property is registered with different options, a warning is emitted
108
+ * but the original definition is preserved (CSS @property cannot be redefined).
109
+ */
110
+ property(name: string, options?: PropertyDefinition & {
111
+ root?: Document | ShadowRoot;
112
+ }): void;
113
+ /**
114
+ * Check whether a given @property name was already injected by this injector.
115
+ *
116
+ * Accepts tasty token syntax:
117
+ * - `$name` → checks `--name`
118
+ * - `#name` → checks `--name-color`
119
+ * - `--name` → checks `--name` (legacy format)
120
+ */
121
+ isPropertyDefined(name: string, options?: {
122
+ root?: Document | ShadowRoot;
123
+ }): boolean;
124
+ /**
125
+ * Inject keyframes and return object with toString() and dispose()
126
+ *
127
+ * Keyframes are cached by content (steps). If the same content is injected
128
+ * multiple times with different provided names, the first injected name is reused.
129
+ *
130
+ * If the same name is provided with different content (collision), a unique
131
+ * name is generated to avoid overwriting the existing keyframes.
132
+ */
133
+ keyframes(steps: KeyframesSteps, nameOrOptions?: string | {
134
+ root?: Document | ShadowRoot;
135
+ name?: string;
136
+ }): KeyframesResult;
137
+ /**
138
+ * Dispose keyframes
139
+ */
140
+ private disposeKeyframes;
141
+ /**
142
+ * Destroy all resources for a root
143
+ */
144
+ destroy(root?: Document | ShadowRoot): void;
145
+ }
146
+ //#endregion
147
+ export { StyleInjector };
148
+ //# sourceMappingURL=injector.d.ts.map