@tenphi/tasty 0.0.0-snapshot.27b6708 → 0.0.0-snapshot.28b6339

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 (109) hide show
  1. package/README.md +38 -54
  2. package/dist/{babel-BUQGeOXA.d.ts → babel-Zs1Q03qt.d.ts} +2 -2
  3. package/dist/chunks/async-storage-DKK-wTD4.js.map +1 -0
  4. package/dist/chunks/build-config-Mk7waOsw.js +45 -0
  5. package/dist/chunks/build-config-Mk7waOsw.js.map +1 -0
  6. package/dist/{collector-DTahQUiV.js → chunks/collector-Ducc5l3E.js} +29 -15
  7. package/dist/chunks/collector-Ducc5l3E.js.map +1 -0
  8. package/dist/chunks/config-engine-tKK7WxJO.js +331 -0
  9. package/dist/chunks/config-engine-tKK7WxJO.js.map +1 -0
  10. package/dist/chunks/css-definitions-Crstltrf.js +1229 -0
  11. package/dist/chunks/css-definitions-Crstltrf.js.map +1 -0
  12. package/dist/chunks/css-resources-Cyl_axbI.js +149 -0
  13. package/dist/chunks/css-resources-Cyl_axbI.js.map +1 -0
  14. package/dist/chunks/debug-HyyLIf6O.js +543 -0
  15. package/dist/chunks/debug-HyyLIf6O.js.map +1 -0
  16. package/dist/chunks/dsl-D7kBow--.js +1771 -0
  17. package/dist/chunks/dsl-D7kBow--.js.map +1 -0
  18. package/dist/chunks/hydration-CLdVKcH2.js +59 -0
  19. package/dist/chunks/hydration-CLdVKcH2.js.map +1 -0
  20. package/dist/chunks/react-runtime-UlZcbsEN.js +877 -0
  21. package/dist/chunks/react-runtime-UlZcbsEN.js.map +1 -0
  22. package/dist/chunks/runtime-engine-D2WOLvd6.js +3439 -0
  23. package/dist/chunks/runtime-engine-D2WOLvd6.js.map +1 -0
  24. package/dist/chunks/runtime-state-DOeH6rsG.js +138 -0
  25. package/dist/chunks/runtime-state-DOeH6rsG.js.map +1 -0
  26. package/dist/{merge-styles-oklji0KB.js → chunks/shared-utils-Bgl8FNGJ.js} +64 -24
  27. package/dist/chunks/shared-utils-Bgl8FNGJ.js.map +1 -0
  28. package/dist/chunks/style-engine-C4ZcOAPb.js +6915 -0
  29. package/dist/chunks/style-engine-C4ZcOAPb.js.map +1 -0
  30. package/dist/{css-writer-B-J87ncv.js → chunks/zero-engine-D4Rluo7u.js} +3 -3
  31. package/dist/chunks/zero-engine-D4Rluo7u.js.map +1 -0
  32. package/dist/{collector-DUaHCcTS.d.ts → collector-hl5KNH7k.d.ts} +23 -3
  33. package/dist/{config-YsxGv4tq.d.ts → config-DWL1ZYue.d.ts} +150 -55
  34. package/dist/core/index.d.ts +5 -5
  35. package/dist/core/index.js +9 -6
  36. package/dist/{index-PqN-DIpn.d.ts → index-D9N9GV24.d.ts} +129 -93
  37. package/dist/index.d.ts +5 -5
  38. package/dist/index.js +11 -922
  39. package/dist/{merge-styles-CU7JbEwg.d.ts → merge-styles-C_oMoJVd.d.ts} +2 -2
  40. package/dist/ssr/astro-client.js +1 -1
  41. package/dist/ssr/astro-middleware-extract-static.d.ts +11 -0
  42. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  43. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  44. package/dist/ssr/astro-middleware-extract.d.ts +11 -0
  45. package/dist/ssr/astro-middleware-extract.js +9 -0
  46. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  47. package/dist/ssr/astro-middleware-static.d.ts +3 -1
  48. package/dist/ssr/astro-middleware.d.ts +3 -1
  49. package/dist/ssr/astro.d.ts +45 -3
  50. package/dist/ssr/astro.js +158 -15
  51. package/dist/ssr/astro.js.map +1 -1
  52. package/dist/ssr/index.d.ts +7 -7
  53. package/dist/ssr/index.js +4 -4
  54. package/dist/ssr/index.js.map +1 -1
  55. package/dist/ssr/next-config.d.ts +66 -0
  56. package/dist/ssr/next-config.js +135 -0
  57. package/dist/ssr/next-config.js.map +1 -0
  58. package/dist/ssr/next.d.ts +9 -2
  59. package/dist/ssr/next.js +27 -11
  60. package/dist/ssr/next.js.map +1 -1
  61. package/dist/static/index.d.ts +2 -2
  62. package/dist/static/index.js +1 -1
  63. package/dist/{index-Cd45t5NM.d.ts → types-jKZNpias.d.ts} +898 -803
  64. package/dist/zero/babel.d.ts +1 -1
  65. package/dist/zero/babel.js +25 -24
  66. package/dist/zero/babel.js.map +1 -1
  67. package/dist/zero/index.d.ts +1 -1
  68. package/dist/zero/index.js +1 -1
  69. package/dist/zero/next.d.ts +1 -1
  70. package/docs/README.md +5 -3
  71. package/docs/adoption.md +3 -3
  72. package/docs/ai-agents.md +83 -78
  73. package/docs/comparison.md +12 -12
  74. package/docs/configuration.md +47 -47
  75. package/docs/debug.md +19 -7
  76. package/docs/dsl.md +3 -3
  77. package/docs/getting-started.md +10 -10
  78. package/docs/injector.md +62 -25
  79. package/docs/methodology.md +3 -3
  80. package/docs/migration-v3.md +49 -49
  81. package/docs/plugins.md +37 -33
  82. package/docs/react-api.md +2 -2
  83. package/docs/runtime-benchmarks.md +351 -0
  84. package/docs/ssr.md +219 -61
  85. package/docs/styles.md +43 -11
  86. package/docs/tasty-static.md +136 -103
  87. package/package.json +80 -11
  88. package/dist/async-storage-DKK-wTD4.js.map +0 -1
  89. package/dist/collector-DTahQUiV.js.map +0 -1
  90. package/dist/config-B5kHzuNz.js +0 -12269
  91. package/dist/config-B5kHzuNz.js.map +0 -1
  92. package/dist/context-CA8YKeMn.js +0 -24
  93. package/dist/context-CA8YKeMn.js.map +0 -1
  94. package/dist/core-Dr4u1NVD.js +0 -1566
  95. package/dist/core-Dr4u1NVD.js.map +0 -1
  96. package/dist/css-writer-B-J87ncv.js.map +0 -1
  97. package/dist/format-global-rules-DklyaXv-.js +0 -22
  98. package/dist/format-global-rules-DklyaXv-.js.map +0 -1
  99. package/dist/format-rules-DKOA-6qu.js +0 -130
  100. package/dist/format-rules-DKOA-6qu.js.map +0 -1
  101. package/dist/hydrate-OeMX99We.js +0 -37
  102. package/dist/hydrate-OeMX99We.js.map +0 -1
  103. package/dist/index.js.map +0 -1
  104. package/dist/keyframes-CV8azJf3.js +0 -493
  105. package/dist/keyframes-CV8azJf3.js.map +0 -1
  106. package/dist/merge-styles-oklji0KB.js.map +0 -1
  107. package/dist/resolve-recipes-DTG81rzl.js +0 -144
  108. package/dist/resolve-recipes-DTG81rzl.js.map +0 -1
  109. /package/dist/{async-storage-DKK-wTD4.js → chunks/async-storage-DKK-wTD4.js} +0 -0
@@ -0,0 +1,877 @@
1
+ import { n as isSelector, t as mergeStyles } from "./shared-utils-Bgl8FNGJ.js";
2
+ import { D as makeKeyframeName, E as makeCounterStyleName, U as parseFunctionName, V as formatFunctionRule, W as registerFunctionPolyfill, a as formatPropertyCSS, b as formatFontFaceRule, h as formatCounterStyleRule, i as formatKeyframesCSS, j as hashString, n as formatGlobalRules, v as fontFaceContentHash } from "./css-definitions-Crstltrf.js";
3
+ import { U as isFunctionsPolyfillEnabled, b as renderStyles, i as baseStylePropsRegistry, s as BASE_STYLES } from "./style-engine-C4ZcOAPb.js";
4
+ import { $ as propHandlerRegistry, B as getNamePrefix, E as injectRawCSS, I as getConfig, J as closeBatchWindow, L as getGlobalInjector, M as touch, T as injectGlobal, Z as openBatchWindow, c as hasKeys, d as getStyleTarget, f as pushRSCCSS, i as modAttrs, k as keyframes, l as collectAutoInferredProperties, n as createClientState, o as computeStyles, r as processTokens, s as resolveRecipes, t as depsEqual, u as collectAutoInferredPropertiesRSC } from "./runtime-engine-D2WOLvd6.js";
5
+ import { Fragment, createContext, createElement, forwardRef, useContext, useInsertionEffect } from "react";
6
+ //#region src/utils/get-display-name.ts
7
+ const DEFAULT_NAME = "Anonymous";
8
+ function getDisplayName(Component, fallbackName = DEFAULT_NAME) {
9
+ if (typeof Component === "function") return Component.displayName ?? Component.name ?? fallbackName;
10
+ return fallbackName;
11
+ }
12
+ //#endregion
13
+ //#region src/utils/is-valid-element-type.ts
14
+ /**
15
+ * Lightweight replacement for `react-is`'s isValidElementType.
16
+ * Detects string tags, function/class components, and React exotic types
17
+ * (forwardRef, memo, lazy, etc.) via their internal $$typeof symbol.
18
+ */
19
+ function isValidElementType(value) {
20
+ if (typeof value === "string" || typeof value === "function") return true;
21
+ if (typeof value === "object" && value !== null) return typeof value.$$typeof === "symbol";
22
+ return false;
23
+ }
24
+ //#endregion
25
+ //#region src/tasty.tsx
26
+ /** Transform one is* prop to its HTML and matching data attributes. */
27
+ function handleIsProperty(props, isProperty, targetAttribute, dataAttribute) {
28
+ if (isProperty in props) {
29
+ props[targetAttribute] = props[isProperty];
30
+ delete props[isProperty];
31
+ }
32
+ if (!(dataAttribute in props) && props[targetAttribute]) props[dataAttribute] = "";
33
+ }
34
+ function handleIsProperties(props) {
35
+ handleIsProperty(props, "isDisabled", "disabled", "data-disabled");
36
+ handleIsProperty(props, "isHidden", "hidden", "data-hidden");
37
+ handleIsProperty(props, "isChecked", "checked", "data-checked");
38
+ }
39
+ /**
40
+ * Creates a sub-element component for compound component patterns.
41
+ * Sub-elements are lightweight components with data-element attribute for CSS targeting.
42
+ */
43
+ function createSubElement(elementName, definition) {
44
+ const config = typeof definition === "string" ? { as: definition } : definition;
45
+ const tag = config.as ?? "div";
46
+ const defaultQa = config.qa;
47
+ const defaultQaVal = config.qaVal;
48
+ const SubElement = forwardRef((props, ref) => {
49
+ const { qa, qaVal, mods, tokens, isDisabled, isHidden, isChecked, className, style, ...htmlProps } = props;
50
+ let modDataAttrs;
51
+ if (mods) modDataAttrs = modAttrs(mods);
52
+ const tokenStyle = tokens ? processTokens(tokens) : void 0;
53
+ let mergedStyle;
54
+ if (tokenStyle || style) mergedStyle = tokenStyle && style ? {
55
+ ...tokenStyle,
56
+ ...style
57
+ } : tokenStyle ?? style;
58
+ const elementProps = {
59
+ "data-element": elementName,
60
+ "data-qa": qa ?? defaultQa,
61
+ "data-qaval": qaVal ?? defaultQaVal,
62
+ ...modDataAttrs || {},
63
+ ...htmlProps,
64
+ className,
65
+ style: mergedStyle,
66
+ isDisabled: isDisabled ?? htmlProps.disabled,
67
+ isHidden: isHidden ?? htmlProps.hidden,
68
+ isChecked: isChecked ?? htmlProps.checked,
69
+ ref
70
+ };
71
+ handleIsProperties(elementProps);
72
+ if (elementProps["data-qa"] === void 0) delete elementProps["data-qa"];
73
+ if (elementProps["data-qaval"] === void 0) delete elementProps["data-qaval"];
74
+ return createElement(tag, elementProps);
75
+ });
76
+ SubElement.displayName = `SubElement(${elementName})`;
77
+ return SubElement;
78
+ }
79
+ /**
80
+ * Pre-compute the mapping from prop name to token key at component-creation time.
81
+ * Array form: `'progress'` -> `'$progress'`, `'accentColor'` -> `'#accent'`.
82
+ * Object form: entries used as-is.
83
+ */
84
+ function buildTokenPropsMapping(def) {
85
+ if (Array.isArray(def)) return def.map((propName) => {
86
+ if (propName.endsWith("Color") && propName.length > 5) return [propName, `#${propName.slice(0, -5)}`];
87
+ return [propName, `$${propName}`];
88
+ });
89
+ return Object.entries(def);
90
+ }
91
+ function tasty(Component, options) {
92
+ if (isValidElementType(Component)) return tastyWrap(Component, options);
93
+ return tastyElement(Component);
94
+ }
95
+ function tastyWrap(Component, options) {
96
+ const { as: extendTag, element: extendElement, styleProps: _styleProps, modProps: _modProps, tokenProps: _tokenProps, variants: _variants, elements: _elements, ...defaultProps } = options ?? {};
97
+ const propsWithStyles = ["styles"];
98
+ for (const prop of Object.keys(defaultProps)) if (prop.endsWith("Styles")) propsWithStyles.push(prop);
99
+ const _WrappedComponent = forwardRef((props, ref) => {
100
+ const { as, element, ...restProps } = props;
101
+ const mergedStylesMap = {};
102
+ for (const prop of propsWithStyles) {
103
+ const restValue = restProps[prop];
104
+ const defaultValue = defaultProps[prop];
105
+ mergedStylesMap[prop] = restValue != null && defaultValue != null ? mergeStyles(defaultValue, restValue) : restValue ?? defaultValue;
106
+ }
107
+ return createElement(Component, {
108
+ ...defaultProps,
109
+ ...restProps,
110
+ ...mergedStylesMap,
111
+ as: as ?? extendTag,
112
+ element: element || extendElement,
113
+ ref
114
+ });
115
+ });
116
+ _WrappedComponent.displayName = `TastyWrappedComponent(${getDisplayName(Component, defaultProps.qa ?? extendTag ?? "Anonymous")})`;
117
+ return _WrappedComponent;
118
+ }
119
+ function tastyElement(tastyOptions) {
120
+ const { as: originalAs = "div", element: defaultElement, styles: defaultStyles, styleProps, modProps: modPropsDef, tokenProps: tokenPropsDef, variants, tokens: defaultTokens, elements, ...defaultProps } = tastyOptions;
121
+ let variantStylesMap;
122
+ if (variants) {
123
+ let baseStyles = defaultStyles;
124
+ let extensionStyles;
125
+ if (defaultStyles) for (const key of Object.keys(defaultStyles)) {
126
+ if (isSelector(key)) continue;
127
+ const value = defaultStyles[key];
128
+ if (typeof value === "object" && value !== null && !Array.isArray(value) && !("" in value)) {
129
+ if (!extensionStyles) {
130
+ baseStyles = { ...defaultStyles };
131
+ extensionStyles = {};
132
+ }
133
+ extensionStyles[key] = value;
134
+ delete baseStyles[key];
135
+ }
136
+ }
137
+ variantStylesMap = {};
138
+ for (const [variant, variantStyles] of Object.entries(variants)) variantStylesMap[variant] = extensionStyles ? mergeStyles(baseStyles, variantStyles, extensionStyles) : mergeStyles(baseStyles, variantStyles);
139
+ if (!variantStylesMap["default"]) variantStylesMap["default"] = defaultStyles;
140
+ }
141
+ const { qa: defaultQa, qaVal: defaultQaVal, ...otherDefaultProps } = defaultProps;
142
+ const ownPropsToCheck = styleProps ? styleProps.concat(BASE_STYLES) : BASE_STYLES;
143
+ let propsToCheck = ownPropsToCheck;
144
+ let propsToCheckVersion = -1;
145
+ const modPropsKeys = modPropsDef ? Array.isArray(modPropsDef) ? modPropsDef : Object.keys(modPropsDef) : void 0;
146
+ const tokenPropsMapping = tokenPropsDef ? buildTokenPropsMapping(tokenPropsDef) : void 0;
147
+ const classNameCache = /* @__PURE__ */ new Map();
148
+ const STABLE_STYLES = { stableStyles: true };
149
+ const _TastyComponent = forwardRef((incomingProps, ref) => {
150
+ const applyPropHandlers = propHandlerRegistry.apply;
151
+ const { as, styles: rawStyles, variant, mods, element, qa, qaVal, className: userClassName, tokens, style, theme, ...otherProps } = applyPropHandlers ? applyPropHandlers(incomingProps) : incomingProps;
152
+ const styles = rawStyles;
153
+ let propStyles = null;
154
+ if (propsToCheckVersion !== baseStylePropsRegistry.version) {
155
+ const promoted = baseStylePropsRegistry.list;
156
+ propsToCheck = promoted.length === 0 ? ownPropsToCheck : ownPropsToCheck.concat(promoted);
157
+ propsToCheckVersion = baseStylePropsRegistry.version;
158
+ }
159
+ for (const prop of propsToCheck) {
160
+ const key = prop;
161
+ if (key in otherProps) {
162
+ if (!propStyles) propStyles = {};
163
+ const value = otherProps[key];
164
+ propStyles[key] = value;
165
+ delete otherProps[key];
166
+ }
167
+ }
168
+ let propMods;
169
+ if (modPropsKeys) {
170
+ for (const key of modPropsKeys) if (key in otherProps) {
171
+ if (!propMods) propMods = {};
172
+ propMods[key] = otherProps[key];
173
+ delete otherProps[key];
174
+ }
175
+ }
176
+ let propTokens;
177
+ if (tokenPropsMapping) {
178
+ for (const [propName, tokenKey] of tokenPropsMapping) if (propName in otherProps) {
179
+ if (!propTokens) propTokens = {};
180
+ propTokens[tokenKey] = otherProps[propName];
181
+ delete otherProps[propName];
182
+ }
183
+ }
184
+ const baseStyles = variantStylesMap ? variantStylesMap[variant || "default"] ?? variantStylesMap["default"] : defaultStyles;
185
+ const allStyles = styles && hasKeys(styles) || !!propStyles ? mergeStyles(baseStyles, styles, propStyles) : baseStyles;
186
+ const useFactoryCache = typeof document !== "undefined";
187
+ let generatedClassName = useFactoryCache && allStyles === baseStyles ? classNameCache.get(allStyles) : void 0;
188
+ let rscCSS;
189
+ if (generatedClassName !== void 0) touch(generatedClassName);
190
+ else {
191
+ const result = computeStyles(allStyles, !useFactoryCache && allStyles === baseStyles ? STABLE_STYLES : void 0);
192
+ generatedClassName = result.className;
193
+ rscCSS = result.css;
194
+ if (useFactoryCache && allStyles === baseStyles) classNameCache.set(allStyles, generatedClassName);
195
+ }
196
+ let mergedTokens;
197
+ if (defaultTokens || tokens || propTokens) if (!defaultTokens && !propTokens) mergedTokens = tokens;
198
+ else if (!tokens && !propTokens) mergedTokens = defaultTokens;
199
+ else mergedTokens = {
200
+ ...defaultTokens,
201
+ ...tokens,
202
+ ...propTokens
203
+ };
204
+ const processedTokenStyle = processTokens(mergedTokens);
205
+ let mergedStyle;
206
+ if (processedTokenStyle || style) if (!processedTokenStyle) mergedStyle = style;
207
+ else if (!style) mergedStyle = processedTokenStyle;
208
+ else mergedStyle = {
209
+ ...processedTokenStyle,
210
+ ...style
211
+ };
212
+ const mergedMods = propMods ? {
213
+ ...mods,
214
+ ...propMods
215
+ } : mods;
216
+ let modDataAttrs;
217
+ if (mergedMods) modDataAttrs = modAttrs(mergedMods);
218
+ let finalClassName = generatedClassName;
219
+ if (userClassName) finalClassName = finalClassName ? `${userClassName} ${finalClassName}` : userClassName;
220
+ const elementProps = {
221
+ "data-element": element || defaultElement,
222
+ "data-qa": qa || defaultQa,
223
+ "data-qaval": qaVal || defaultQaVal,
224
+ "data-theme": theme,
225
+ ...otherDefaultProps,
226
+ ...modDataAttrs || {},
227
+ ...otherProps,
228
+ className: finalClassName,
229
+ style: mergedStyle,
230
+ ref
231
+ };
232
+ handleIsProperties(elementProps);
233
+ if (elementProps["data-theme"] === void 0) delete elementProps["data-theme"];
234
+ const el = createElement(as ?? originalAs, elementProps);
235
+ if (rscCSS) {
236
+ const nonce = getConfig().nonce;
237
+ return createElement(Fragment, null, createElement("style", {
238
+ "data-tasty-rsc": "",
239
+ nonce,
240
+ dangerouslySetInnerHTML: { __html: rscCSS }
241
+ }), el);
242
+ }
243
+ return el;
244
+ });
245
+ _TastyComponent.displayName = `TastyComponent(${defaultProps.qa || originalAs})`;
246
+ if (elements) {
247
+ const subElements = {};
248
+ for (const [name, definition] of Object.entries(elements)) subElements[name] = createSubElement(name, definition);
249
+ return Object.assign(_TastyComponent, subElements);
250
+ }
251
+ return _TastyComponent;
252
+ }
253
+ const Element = /* @__PURE__ */ tasty({});
254
+ //#endregion
255
+ //#region src/ssr/context.ts
256
+ /**
257
+ * React context for SSR collector discovery.
258
+ *
259
+ * Used by Next.js TastyRegistry to provide the ServerStyleCollector
260
+ * to useStyles() via React context (the streaming-compatible path).
261
+ *
262
+ * This avoids relying on globalThis for cross-layer communication,
263
+ * which leaks between RSC and SSR module graphs in Next.js App Router.
264
+ *
265
+ * The context is created lazily to avoid calling createContext() at
266
+ * module evaluation time, which would break Server Components that
267
+ * import from `@tenphi/tasty` without using any React hooks.
268
+ */
269
+ let _ctx;
270
+ function getTastySSRContext() {
271
+ if (!_ctx) _ctx = createContext(null);
272
+ return _ctx;
273
+ }
274
+ //#endregion
275
+ //#region src/hooks/useStyles.ts
276
+ /**
277
+ * Hook to generate CSS classes from Tasty styles.
278
+ * Thin wrapper around `computeStyles()` that adds React context-based
279
+ * SSR collector discovery for backward compatibility with TastyRegistry.
280
+ *
281
+ * For hook-free usage (e.g. in server components), use `computeStyles()` directly.
282
+ *
283
+ * @example
284
+ * ```tsx
285
+ * function MyComponent() {
286
+ * const { className } = useStyles({
287
+ * padding: '2x',
288
+ * fill: '#purple',
289
+ * radius: '1r',
290
+ * });
291
+ *
292
+ * return <div className={className}>Styled content</div>;
293
+ * }
294
+ * ```
295
+ */
296
+ function useStyles(styles, options) {
297
+ return computeStyles(styles, {
298
+ ssrCollector: useContext(getTastySSRContext()),
299
+ root: options?.root
300
+ });
301
+ }
302
+ //#endregion
303
+ //#region src/hooks/useGlobalStyles.ts
304
+ const getClientGlobalSlots = /* @__PURE__ */ createClientState(() => /* @__PURE__ */ new Map());
305
+ const noop = () => {};
306
+ /**
307
+ * Inject global styles for a given selector.
308
+ * Useful for styling elements by selector without generating classNames.
309
+ *
310
+ * SSR-aware: when a ServerStyleCollector is available, CSS is collected
311
+ * during the render phase instead of being injected into the DOM.
312
+ *
313
+ * Works in all environments: client, SSR with collector, and React Server Components.
314
+ *
315
+ * Injected styles are permanent — they are not cleaned up on component unmount.
316
+ * Use the `id` option for update tracking when styles change over the
317
+ * component lifecycle.
318
+ *
319
+ * Update tracking is per-slot and per-root: a slot (`id`, or the selector when
320
+ * no `id` is given) holds exactly one injection per `root`. Changing the styles
321
+ * replaces it; rendering styles that produce no CSS clears it.
322
+ *
323
+ * @param selector - CSS selector to apply styles to (e.g., '.my-class', ':root', 'body')
324
+ * @param styles - Tasty styles object
325
+ * @param options - Optional settings including `id` for update tracking
326
+ *
327
+ * @example
328
+ * ```tsx
329
+ * function MyComponent() {
330
+ * useGlobalStyles('.card', {
331
+ * padding: '2x',
332
+ * radius: '1r',
333
+ * fill: '#white',
334
+ * });
335
+ *
336
+ * return <div className="card">Content</div>;
337
+ * }
338
+ * ```
339
+ */
340
+ function useGlobalStyles(selector, styles, options) {
341
+ if (!styles) return;
342
+ if (!selector) {
343
+ console.warn("[Tasty] useGlobalStyles: selector is required and cannot be empty. Styles will not be injected.");
344
+ return;
345
+ }
346
+ const target = getStyleTarget();
347
+ const slots = target.mode === "client" ? getClientGlobalSlots(options?.root ?? document) : null;
348
+ const slotKey = options?.id ?? selector;
349
+ const stylesKey = slots ? JSON.stringify(styles) : "";
350
+ const existing = slots?.get(slotKey);
351
+ if (existing && existing.stylesKey === stylesKey) return;
352
+ const resolvedStyles = resolveRecipes(styles);
353
+ const styleResults = renderStyles(resolvedStyles, selector);
354
+ if (styleResults.length === 0) {
355
+ if (slots) {
356
+ existing?.dispose();
357
+ slots.set(slotKey, {
358
+ stylesKey,
359
+ dispose: noop
360
+ });
361
+ }
362
+ return;
363
+ }
364
+ if (target.mode === "ssr") {
365
+ target.collector.collectInternals();
366
+ const css = formatGlobalRules(styleResults);
367
+ if (css) {
368
+ const key = options?.id ? `global:${options.id}` : `global:${selector}:${hashString(css)}`;
369
+ target.collector.collectGlobalStyles(key, css, options?.id != null);
370
+ }
371
+ if (getConfig().autoPropertyTypes !== false) collectAutoInferredProperties(styleResults, target.collector, resolvedStyles);
372
+ return;
373
+ }
374
+ if (target.mode === "rsc") {
375
+ const css = formatGlobalRules(styleResults);
376
+ if (css) {
377
+ const key = options?.id ? `__global:${options.id}` : `__global:${selector}:${hashString(css)}`;
378
+ pushRSCCSS(target.cache, key, css, options?.id != null);
379
+ }
380
+ if (getConfig().autoPropertyTypes !== false) collectAutoInferredPropertiesRSC(styleResults, target.cache, resolvedStyles);
381
+ return;
382
+ }
383
+ if (slots) {
384
+ existing?.dispose();
385
+ const { dispose } = injectGlobal(styleResults, { root: options?.root });
386
+ slots.set(slotKey, {
387
+ stylesKey,
388
+ dispose
389
+ });
390
+ }
391
+ }
392
+ //#endregion
393
+ //#region src/hooks/useRawCSS.ts
394
+ const getClientState$1 = /* @__PURE__ */ createClientState(() => ({
395
+ entries: /* @__PURE__ */ new Map(),
396
+ dedup: /* @__PURE__ */ new Set(),
397
+ deps: /* @__PURE__ */ new Map()
398
+ }));
399
+ /**
400
+ * Inject raw CSS text directly without parsing.
401
+ * This is a low-overhead alternative for injecting global CSS that doesn't need tasty processing.
402
+ *
403
+ * The CSS is inserted into a separate style element (data-tasty-raw) to avoid conflicts
404
+ * with tasty's chunked style sheets.
405
+ *
406
+ * Works in all environments: client, SSR with collector, and React Server Components.
407
+ *
408
+ * Injected styles are permanent — they are not cleaned up on component unmount.
409
+ * Use the `id` option for update tracking when styles change over the
410
+ * component lifecycle.
411
+ *
412
+ * @example Static CSS string
413
+ * ```tsx
414
+ * function GlobalStyles() {
415
+ * useRawCSS(`
416
+ * body {
417
+ * margin: 0;
418
+ * padding: 0;
419
+ * font-family: sans-serif;
420
+ * }
421
+ * `);
422
+ *
423
+ * return null;
424
+ * }
425
+ * ```
426
+ *
427
+ * @example Factory function with dependencies
428
+ * ```tsx
429
+ * function ThemeStyles({ theme }: { theme: 'light' | 'dark' }) {
430
+ * useRawCSS(() => `
431
+ * :root {
432
+ * --bg-color: ${theme === 'dark' ? '#1a1a1a' : '#ffffff'};
433
+ * --text-color: ${theme === 'dark' ? '#ffffff' : '#1a1a1a'};
434
+ * }
435
+ * `, [theme], { id: 'theme-vars' });
436
+ *
437
+ * return null;
438
+ * }
439
+ * ```
440
+ *
441
+ * @example With options
442
+ * ```tsx
443
+ * function ShadowStyles({ shadowRoot }) {
444
+ * useRawCSS(() => `.scoped { color: red; }`, [], { root: shadowRoot });
445
+ * return null;
446
+ * }
447
+ * ```
448
+ */
449
+ function useRawCSS(cssOrFactory, depsOrOptions, options) {
450
+ const isFactory = typeof cssOrFactory === "function";
451
+ const deps = isFactory && Array.isArray(depsOrOptions) ? depsOrOptions : void 0;
452
+ const opts = isFactory ? options : depsOrOptions;
453
+ const id = opts?.id;
454
+ const target = getStyleTarget();
455
+ const state = target.mode === "client" ? getClientState$1(opts?.root ?? document) : null;
456
+ if (isFactory && deps && id && state) {
457
+ const cachedDeps = state.deps.get(id);
458
+ if (cachedDeps && depsEqual(cachedDeps, deps)) return;
459
+ }
460
+ const css = isFactory ? cssOrFactory() : cssOrFactory;
461
+ if (!css.trim()) return;
462
+ if (target.mode !== "client") {
463
+ const key = `${target.mode === "rsc" ? "__" : ""}raw:${id || hashString(css)}`;
464
+ const replace = id != null;
465
+ if (target.mode === "ssr") target.collector.collectRawCSS(key, css, replace);
466
+ else pushRSCCSS(target.cache, key, css, replace);
467
+ return;
468
+ }
469
+ if (!state) return;
470
+ if (id) {
471
+ const existing = state.entries.get(id);
472
+ if (existing) {
473
+ if (existing.css === css) return;
474
+ existing.dispose();
475
+ }
476
+ const { dispose } = injectRawCSS(css, opts);
477
+ state.entries.set(id, {
478
+ css,
479
+ dispose
480
+ });
481
+ if (deps) state.deps.set(id, deps);
482
+ } else {
483
+ const contentKey = hashString(css);
484
+ if (state.dedup.has(contentKey)) return;
485
+ state.dedup.add(contentKey);
486
+ injectRawCSS(css, opts);
487
+ }
488
+ }
489
+ //#endregion
490
+ //#region src/hooks/useKeyframes.ts
491
+ const getClientState = /* @__PURE__ */ createClientState(() => ({
492
+ contentToName: /* @__PURE__ */ new Map(),
493
+ namedSlots: /* @__PURE__ */ new Map(),
494
+ factoryDeps: /* @__PURE__ */ new Map()
495
+ }));
496
+ function useKeyframes(stepsOrFactory, depsOrOptions, options) {
497
+ const isFactory = typeof stepsOrFactory === "function";
498
+ const deps = isFactory && Array.isArray(depsOrOptions) ? depsOrOptions : void 0;
499
+ const opts = isFactory ? options : depsOrOptions;
500
+ const target = getStyleTarget();
501
+ const clientState = target.mode === "client" ? getClientState(opts?.root ?? document) : null;
502
+ if (isFactory && deps && opts?.name && clientState) {
503
+ const cached = clientState.factoryDeps.get(opts.name);
504
+ if (cached && depsEqual(cached.deps, deps)) return cached.name;
505
+ }
506
+ const steps = isFactory ? stepsOrFactory() : stepsOrFactory;
507
+ if (!steps || Object.keys(steps).length === 0) return "";
508
+ if (target.mode === "ssr") {
509
+ const actualName = target.collector.allocateKeyframeName(opts?.name);
510
+ const css = formatKeyframesCSS(actualName, steps);
511
+ target.collector.collectKeyframes(actualName, css);
512
+ return actualName;
513
+ }
514
+ if (target.mode === "rsc") {
515
+ const serializedContent = JSON.stringify(steps);
516
+ const key = `__kf:${opts?.name ?? ""}:${serializedContent}`;
517
+ const existingName = target.cache.generatedNames.get(key);
518
+ if (existingName) return existingName;
519
+ const actualName = opts?.name ?? makeKeyframeName(getNamePrefix(), hashString(serializedContent));
520
+ const css = formatKeyframesCSS(actualName, steps);
521
+ pushRSCCSS(target.cache, key, css);
522
+ target.cache.generatedNames.set(key, actualName);
523
+ return actualName;
524
+ }
525
+ const state = clientState ?? getClientState(opts?.root ?? document);
526
+ const serializedContent = JSON.stringify(steps);
527
+ const cacheKey = `${opts?.name ?? ""}:${serializedContent}`;
528
+ const cachedName = state.contentToName.get(cacheKey);
529
+ if (cachedName) return cachedName;
530
+ const providedName = opts?.name;
531
+ if (providedName) {
532
+ const slot = state.namedSlots.get(providedName);
533
+ if (slot && slot.cacheKey !== cacheKey) {
534
+ slot.dispose();
535
+ state.contentToName.delete(slot.cacheKey);
536
+ state.namedSlots.delete(providedName);
537
+ }
538
+ }
539
+ const result = keyframes(steps, {
540
+ name: providedName,
541
+ root: opts?.root
542
+ });
543
+ const name = result.toString();
544
+ state.contentToName.set(cacheKey, name);
545
+ if (providedName) {
546
+ state.namedSlots.set(providedName, {
547
+ cacheKey,
548
+ dispose: result.dispose
549
+ });
550
+ if (deps) state.factoryDeps.set(providedName, {
551
+ deps,
552
+ name
553
+ });
554
+ }
555
+ return name;
556
+ }
557
+ //#endregion
558
+ //#region src/hooks/useProperty.ts
559
+ /**
560
+ * Register a CSS @property custom property.
561
+ * This enables advanced features like animating custom properties.
562
+ *
563
+ * Note: @property rules are global and persistent once defined.
564
+ * The function ensures the property is only registered once per root.
565
+ *
566
+ * Accepts tasty token syntax for the property name:
567
+ * - `$name` → defines `--name`
568
+ * - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')
569
+ * - `--name` → defines `--name` (legacy format)
570
+ *
571
+ * Works in all environments: client, SSR with collector, and React Server Components.
572
+ *
573
+ * @param name - The property token ($name, #name) or CSS property name (--name)
574
+ * @param options - Property configuration
575
+ *
576
+ * @example Basic property with token syntax
577
+ * ```tsx
578
+ * function Spinner() {
579
+ * useProperty('$rotation', {
580
+ * syntax: '<angle>',
581
+ * inherits: false,
582
+ * initialValue: '0deg',
583
+ * });
584
+ *
585
+ * return <div className="spinner" />;
586
+ * }
587
+ * ```
588
+ *
589
+ * @example Color property with token syntax (auto-sets syntax)
590
+ * ```tsx
591
+ * function MyComponent() {
592
+ * useProperty('#theme', {
593
+ * initialValue: 'red', // syntax: '<color>' is auto-set
594
+ * });
595
+ *
596
+ * // Now --theme-color can be animated with CSS transitions
597
+ * return <div style={{ '--theme-color': 'blue' } as React.CSSProperties}>Colored</div>;
598
+ * }
599
+ * ```
600
+ *
601
+ * @example Legacy format (still supported)
602
+ * ```tsx
603
+ * function ResizableBox() {
604
+ * useProperty('--box-size', {
605
+ * syntax: '<length>',
606
+ * initialValue: '100px',
607
+ * });
608
+ *
609
+ * return <div style={{ width: 'var(--box-size)' }} />;
610
+ * }
611
+ * ```
612
+ */
613
+ function useProperty(name, options) {
614
+ if (!name) {
615
+ console.warn(`[Tasty] useProperty: property name is required`);
616
+ return;
617
+ }
618
+ const target = getStyleTarget();
619
+ if (target.mode === "ssr") {
620
+ target.collector.collectInternals();
621
+ const css = formatPropertyCSS(name, {
622
+ syntax: options?.syntax,
623
+ inherits: options?.inherits,
624
+ initialValue: options?.initialValue
625
+ });
626
+ if (css) target.collector.collectProperty(name, css);
627
+ return;
628
+ }
629
+ if (target.mode === "rsc") {
630
+ const css = formatPropertyCSS(name, {
631
+ syntax: options?.syntax,
632
+ inherits: options?.inherits,
633
+ initialValue: options?.initialValue
634
+ });
635
+ if (css) pushRSCCSS(target.cache, `__prop:${name}`, css);
636
+ return;
637
+ }
638
+ const injector = getGlobalInjector();
639
+ if (injector.isPropertyDefined(name, { root: options?.root })) return;
640
+ injector.property(name, {
641
+ syntax: options?.syntax,
642
+ inherits: options?.inherits,
643
+ initialValue: options?.initialValue,
644
+ root: options?.root
645
+ });
646
+ }
647
+ //#endregion
648
+ //#region src/hooks/useFontFace.ts
649
+ /**
650
+ * Inject CSS @font-face rules.
651
+ * Permanent — no cleanup on unmount. Deduplicates by content hash.
652
+ *
653
+ * Works in all environments: client, SSR with collector, and React Server Components.
654
+ *
655
+ * @param family - The font-family name
656
+ * @param input - Single descriptor object or array of descriptors (for multiple weights/styles)
657
+ * @param options - Optional settings (e.g. Shadow DOM root)
658
+ *
659
+ * @example Single weight
660
+ * ```tsx
661
+ * function App() {
662
+ * useFontFace('Brand Sans', {
663
+ * src: 'url("/fonts/brand-sans.woff2") format("woff2")',
664
+ * fontWeight: '400 700',
665
+ * fontDisplay: 'swap',
666
+ * });
667
+ *
668
+ * return <div style={{ fontFamily: '"Brand Sans", sans-serif' }}>Hello</div>;
669
+ * }
670
+ * ```
671
+ *
672
+ * @example Multiple weights
673
+ * ```tsx
674
+ * function App() {
675
+ * useFontFace('Brand Sans', [
676
+ * { src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
677
+ * { src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
678
+ * ]);
679
+ *
680
+ * return <div style={{ fontFamily: '"Brand Sans", sans-serif' }}>Hello</div>;
681
+ * }
682
+ * ```
683
+ */
684
+ function useFontFace(family, input, options) {
685
+ if (!family) return;
686
+ const descriptors = Array.isArray(input) ? input : [input];
687
+ const target = getStyleTarget();
688
+ if (target.mode === "ssr") {
689
+ for (const desc of descriptors) {
690
+ const hash = fontFaceContentHash(family, desc);
691
+ const css = formatFontFaceRule(family, desc);
692
+ target.collector.collectFontFace(hash, css);
693
+ }
694
+ return;
695
+ }
696
+ if (target.mode === "rsc") {
697
+ for (const desc of descriptors) {
698
+ const hash = fontFaceContentHash(family, desc);
699
+ const css = formatFontFaceRule(family, desc);
700
+ pushRSCCSS(target.cache, `__ff:${hash}`, css);
701
+ }
702
+ return;
703
+ }
704
+ const injector = getGlobalInjector();
705
+ for (const desc of descriptors) injector.fontFace(family, desc, { root: options?.root });
706
+ }
707
+ //#endregion
708
+ //#region src/hooks/useCounterStyle.ts
709
+ let clientCounterStyleCounter = 0;
710
+ const getClientContentToName = /* @__PURE__ */ createClientState(() => /* @__PURE__ */ new Map());
711
+ /**
712
+ * Inject a CSS @counter-style rule and return the generated name.
713
+ * Permanent — no cleanup on unmount. Deduplicates by name.
714
+ *
715
+ * Works in all environments: client, SSR with collector, and React Server Components.
716
+ *
717
+ * @example Basic usage
718
+ * ```tsx
719
+ * function EmojiList() {
720
+ * const styleName = useCounterStyle({
721
+ * system: 'cyclic',
722
+ * symbols: '"👍"',
723
+ * suffix: '" "',
724
+ * }, { name: 'thumbs' });
725
+ *
726
+ * return (
727
+ * <ol style={{ listStyleType: styleName }}>
728
+ * <li>First</li>
729
+ * <li>Second</li>
730
+ * </ol>
731
+ * );
732
+ * }
733
+ * ```
734
+ *
735
+ */
736
+ function useCounterStyle(descriptors, options) {
737
+ if (!descriptors || !descriptors.system) return "";
738
+ const target = getStyleTarget();
739
+ if (target.mode === "ssr") {
740
+ const actualName = target.collector.allocateCounterStyleName(options?.name);
741
+ const css = formatCounterStyleRule(actualName, descriptors);
742
+ target.collector.collectCounterStyle(actualName, css);
743
+ return actualName;
744
+ }
745
+ if (target.mode === "rsc") {
746
+ const serializedContent = JSON.stringify(descriptors);
747
+ const key = `__cs:${options?.name ?? ""}:${serializedContent}`;
748
+ const existingName = target.cache.generatedNames.get(key);
749
+ if (existingName) return existingName;
750
+ const actualName = options?.name ?? makeCounterStyleName(getNamePrefix(), hashString(serializedContent));
751
+ const css = formatCounterStyleRule(actualName, descriptors);
752
+ pushRSCCSS(target.cache, key, css);
753
+ target.cache.generatedNames.set(key, actualName);
754
+ return actualName;
755
+ }
756
+ const contentToName = getClientContentToName(options?.root ?? document);
757
+ const serializedContent = JSON.stringify(descriptors);
758
+ const cacheKey = `${options?.name ?? ""}:${serializedContent}`;
759
+ const existingName = contentToName.get(cacheKey);
760
+ if (existingName) return existingName;
761
+ const name = options?.name ?? makeCounterStyleName(getNamePrefix(), String(clientCounterStyleCounter++));
762
+ contentToName.set(cacheKey, name);
763
+ getGlobalInjector().counterStyle(name, descriptors, { root: options?.root });
764
+ return name;
765
+ }
766
+ //#endregion
767
+ //#region src/hooks/useFunction.ts
768
+ /**
769
+ * Register a CSS @function (custom function).
770
+ *
771
+ * @function rules are global and persistent once defined. The hook ensures the
772
+ * function is only registered once per root (deduplicated by function name).
773
+ *
774
+ * Accepts tasty token syntax for the function name:
775
+ * - `$$name` → defines `--name` (matches the call site `$$name(...)`)
776
+ * - `$name` / `--name` → also accepted
777
+ *
778
+ * Works in all environments: client, SSR with collector, and React Server Components.
779
+ *
780
+ * @param name - The function name token (`$$name`, `$name`, or `--name`)
781
+ * @param definition - Function definition (args, returns, result, local vars)
782
+ *
783
+ * Call the function through the Tasty DSL, not a raw `style` prop: an inline
784
+ * `style` value reaches the browser unparsed, so the `$$name(...)` sugar is never
785
+ * expanded and `polyfills.functions` cannot rewrite it either.
786
+ *
787
+ * @example
788
+ * ```tsx
789
+ * const Box = tasty({ styles: { marginTop: '$$negative(10px)' } });
790
+ *
791
+ * function Layout() {
792
+ * useFunction('$$negative', { args: ['$value'], result: '(-1 * $value)' });
793
+ * return <Box />;
794
+ * }
795
+ * ```
796
+ */
797
+ function useFunction(name, definition, options) {
798
+ if (!name) {
799
+ console.warn(`[Tasty] useFunction: function name is required`);
800
+ return;
801
+ }
802
+ if (isFunctionsPolyfillEnabled()) {
803
+ registerFunctionPolyfill(name, definition);
804
+ return;
805
+ }
806
+ const target = getStyleTarget();
807
+ if (target.mode === "ssr") {
808
+ target.collector.collectInternals();
809
+ const css = formatFunctionRule(name, definition);
810
+ if (css) target.collector.collectFunction(parseFunctionName(name), css);
811
+ return;
812
+ }
813
+ if (target.mode === "rsc") {
814
+ const css = formatFunctionRule(name, definition);
815
+ if (css) pushRSCCSS(target.cache, `__func:${parseFunctionName(name)}`, css);
816
+ return;
817
+ }
818
+ getGlobalInjector().func(name, definition, { root: options?.root });
819
+ }
820
+ //#endregion
821
+ //#region src/batch-provider.tsx
822
+ /**
823
+ * Opens a *batch window* for the commit it renders in, so `batchInjection`
824
+ * can defer stylesheet writes without ever letting a layout effect measure an
825
+ * unstyled element.
826
+ *
827
+ * Every `insertRule()` on a live sheet invalidates style for that sheet's
828
+ * scope. When components inject during React's render phase while others read
829
+ * layout in the same pass, the two interleave and the browser recalculates
830
+ * style between every injection. Batching collapses that into one invalidation
831
+ * per flush — but only if the flush happens before anything can measure.
832
+ *
833
+ * ```
834
+ * provider renders -> window OPEN
835
+ * children render -> injections queued
836
+ * provider insertionEffect -> FLUSH, window CLOSED
837
+ * layout effects run -> rules are in the sheet
838
+ * ```
839
+ *
840
+ * `useInsertionEffect` runs in React's mutation phase, after every render in
841
+ * the commit and before any `useLayoutEffect` — which is exactly why React
842
+ * added it for CSS-in-JS libraries. Effects fire child-first, so this
843
+ * provider's runs after every descendant's and still before all layout
844
+ * effects.
845
+ *
846
+ * A commit that does not re-render this provider gets no window, and those
847
+ * injections are written synchronously instead. That is the point: turning
848
+ * `batchInjection: true` on can only ever make injection cheaper, never make a
849
+ * measurement wrong. It also means batching applies to commits this provider
850
+ * takes part in, so mount it as high in the tree as you can.
851
+ *
852
+ * Requires `configure({ batchInjection: true })`; without it this component
853
+ * only renders its children. `batchInjection: 'always'` does not need the
854
+ * provider at all — see that option's docs for the trade-off it accepts.
855
+ *
856
+ * @example
857
+ * ```tsx
858
+ * configure({ batchInjection: true });
859
+ *
860
+ * createRoot(el).render(
861
+ * <TastyBatchProvider>
862
+ * <App />
863
+ * </TastyBatchProvider>,
864
+ * );
865
+ * ```
866
+ */
867
+ function TastyBatchProvider({ children }) {
868
+ openBatchWindow();
869
+ useInsertionEffect(() => {
870
+ closeBatchWindow();
871
+ });
872
+ return children;
873
+ }
874
+ //#endregion
875
+ export { useProperty as a, useGlobalStyles as c, Element as d, tasty as f, useFontFace as i, useStyles as l, useFunction as n, useKeyframes as o, getDisplayName as p, useCounterStyle as r, useRawCSS as s, TastyBatchProvider as t, getTastySSRContext as u };
876
+
877
+ //# sourceMappingURL=react-runtime-UlZcbsEN.js.map