@tenphi/tasty 0.0.0-snapshot.b2ad8a7 → 0.0.0-snapshot.b317d64

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 (119) hide show
  1. package/README.md +6 -6
  2. package/dist/babel-types-C_7kRP38.d.ts +18 -0
  3. package/dist/chunks/async-storage-CG5HnUT5.js +20 -0
  4. package/dist/chunks/async-storage-CG5HnUT5.js.map +1 -0
  5. package/dist/chunks/build-config-BDLYGmKn.js +60 -0
  6. package/dist/chunks/build-config-BDLYGmKn.js.map +1 -0
  7. package/dist/{collector-DCI2yzwx.js → chunks/collector-DqcB0UUT.js} +25 -119
  8. package/dist/chunks/collector-DqcB0UUT.js.map +1 -0
  9. package/dist/chunks/config-engine-CGIMO2PV.js +272 -0
  10. package/dist/chunks/config-engine-CGIMO2PV.js.map +1 -0
  11. package/dist/chunks/css-definitions-BibU6ZnP.js +904 -0
  12. package/dist/chunks/css-definitions-BibU6ZnP.js.map +1 -0
  13. package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
  14. package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
  15. package/dist/chunks/debug-Dy36S1sU.js +502 -0
  16. package/dist/chunks/debug-Dy36S1sU.js.map +1 -0
  17. package/dist/chunks/dsl-DRhFWQzo.js +1378 -0
  18. package/dist/chunks/dsl-DRhFWQzo.js.map +1 -0
  19. package/dist/chunks/hydration-TRcz5vnk.js +41 -0
  20. package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
  21. package/dist/chunks/react-runtime-BljxMd6C.js +582 -0
  22. package/dist/chunks/react-runtime-BljxMd6C.js.map +1 -0
  23. package/dist/chunks/runtime-engine-CPYI2bA8.js +2415 -0
  24. package/dist/chunks/runtime-engine-CPYI2bA8.js.map +1 -0
  25. package/dist/chunks/runtime-state-C0u1jp-Q.js +141 -0
  26. package/dist/chunks/runtime-state-C0u1jp-Q.js.map +1 -0
  27. package/dist/{merge-styles-CzVxdtav.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
  28. package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
  29. package/dist/chunks/style-engine-D35rvcdB.js +5420 -0
  30. package/dist/chunks/style-engine-D35rvcdB.js.map +1 -0
  31. package/dist/{css-writer-Cq0fg5v8.js → chunks/zero-engine-b--JCZad.js} +51 -146
  32. package/dist/chunks/zero-engine-b--JCZad.js.map +1 -0
  33. package/dist/{collector-CQDeU7WS.d.ts → collector-w4mBj5gd.d.ts} +23 -4
  34. package/dist/{config-CwRr6-fG.d.ts → config-CrZOfNJ5.d.ts} +110 -96
  35. package/dist/core/index.d.ts +5 -5
  36. package/dist/core/index.js +9 -6
  37. package/dist/{index-C0W21Qcb.d.ts → index-CYJtAI9a.d.ts} +243 -281
  38. package/dist/index.d.ts +5 -5
  39. package/dist/index.js +11 -998
  40. package/dist/{merge-styles-Bpwfy1CS.d.ts → merge-styles-VXwJ0Frr.d.ts} +2 -3
  41. package/dist/ssr/astro-client.d.ts +1 -1
  42. package/dist/ssr/astro-client.js +1 -14
  43. package/dist/ssr/astro-client.js.map +1 -1
  44. package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
  45. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  46. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  47. package/dist/ssr/astro-middleware-extract.d.ts +10 -0
  48. package/dist/ssr/astro-middleware-extract.js +9 -0
  49. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  50. package/dist/ssr/astro-middleware-static.d.ts +3 -2
  51. package/dist/ssr/astro-middleware-static.js +0 -11
  52. package/dist/ssr/astro-middleware-static.js.map +1 -1
  53. package/dist/ssr/astro-middleware.d.ts +3 -2
  54. package/dist/ssr/astro-middleware.js +0 -12
  55. package/dist/ssr/astro-middleware.js.map +1 -1
  56. package/dist/ssr/astro.d.ts +40 -6
  57. package/dist/ssr/astro.js +157 -93
  58. package/dist/ssr/astro.js.map +1 -1
  59. package/dist/ssr/index.d.ts +10 -11
  60. package/dist/ssr/index.js +4 -4
  61. package/dist/ssr/index.js.map +1 -1
  62. package/dist/ssr/next-config.d.ts +64 -0
  63. package/dist/ssr/next-config.js +134 -0
  64. package/dist/ssr/next-config.js.map +1 -0
  65. package/dist/ssr/next.d.ts +9 -8
  66. package/dist/ssr/next.js +29 -43
  67. package/dist/ssr/next.js.map +1 -1
  68. package/dist/static/index.d.ts +8 -9
  69. package/dist/static/index.js +4 -22
  70. package/dist/static/index.js.map +1 -1
  71. package/dist/static/inject.d.ts +1 -2
  72. package/dist/{index-DpykQKO8.d.ts → types-JEY8PVYP.d.ts} +986 -972
  73. package/dist/zero/babel.d.ts +67 -2
  74. package/dist/zero/babel.js +57 -131
  75. package/dist/zero/babel.js.map +1 -1
  76. package/dist/zero/index.d.ts +44 -8
  77. package/dist/zero/index.js +24 -2
  78. package/dist/zero/index.js.map +1 -0
  79. package/dist/zero/next.d.ts +4 -5
  80. package/dist/zero/next.js +0 -31
  81. package/dist/zero/next.js.map +1 -1
  82. package/docs/ai-agents.md +31 -5
  83. package/docs/configuration.md +18 -2
  84. package/docs/debug.md +15 -5
  85. package/docs/dsl.md +56 -8
  86. package/docs/getting-started.md +13 -11
  87. package/docs/injector.md +21 -7
  88. package/docs/methodology.md +5 -5
  89. package/docs/pipeline.md +34 -10
  90. package/docs/plugins.md +1 -1
  91. package/docs/react-api.md +9 -0
  92. package/docs/runtime-benchmarks.md +282 -110
  93. package/docs/ssr.md +179 -20
  94. package/docs/styles.md +89 -19
  95. package/docs/tasty-static.md +34 -1
  96. package/package.json +101 -36
  97. package/dist/async-storage-DKK-wTD4.js +0 -44
  98. package/dist/async-storage-DKK-wTD4.js.map +0 -1
  99. package/dist/babel-B_P8t-f0.d.ts +0 -83
  100. package/dist/collector-DCI2yzwx.js.map +0 -1
  101. package/dist/config-B97n_EIv.js +0 -12612
  102. package/dist/config-B97n_EIv.js.map +0 -1
  103. package/dist/context-CA8YKeMn.js +0 -24
  104. package/dist/context-CA8YKeMn.js.map +0 -1
  105. package/dist/core-DWrUWxog.js +0 -1645
  106. package/dist/core-DWrUWxog.js.map +0 -1
  107. package/dist/css-writer-Cq0fg5v8.js.map +0 -1
  108. package/dist/format-global-rules-DklyaXv-.js +0 -22
  109. package/dist/format-global-rules-DklyaXv-.js.map +0 -1
  110. package/dist/format-rules-Wb7dJOoL.js +0 -130
  111. package/dist/format-rules-Wb7dJOoL.js.map +0 -1
  112. package/dist/hydrate-gFTLBDK9.js +0 -37
  113. package/dist/hydrate-gFTLBDK9.js.map +0 -1
  114. package/dist/index.js.map +0 -1
  115. package/dist/merge-styles-CzVxdtav.js.map +0 -1
  116. package/dist/renderChunk-COXABoQz.js +0 -290
  117. package/dist/renderChunk-COXABoQz.js.map +0 -1
  118. package/dist/resolve-recipes-BnrUEjWV.js +0 -144
  119. package/dist/resolve-recipes-BnrUEjWV.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,998 +1,11 @@
1
- import { $t as stringifyStyles, A as DIMENSION_STYLES, At as APPEARANCE_CHUNK_STYLES, C as baseStylePropsRegistry, D as BLOCK_STYLES, E as BLOCK_OUTER_STYLES, F as TEXT_STYLES, Ft as LAYOUT_CHUNK_STYLES, G as setGlobalPredefinedStates, Gt as DIRECTIONS, Ht as registerFunctionPolyfill, It as POSITION_CHUNK_STYLES, J as formatCounterStyleRule, Jt as getGlobalParser, K as StyleInjector, Kt as filterMods, L as isSelector, Lt as STYLE_TO_CHUNK, M as INNER_STYLES, Mt as DIMENSION_CHUNK_STYLES, N as OUTER_STYLES, Nt as DISPLAY_CHUNK_STYLES, O as COLOR_STYLES, P as POSITION_STYLES, Pt as FONT_CHUNK_STYLES, Qt as parseStyle, R as renderStyles, S as generateTypographyTokens, T as BLOCK_INNER_STYLES, V as createStateParserContext, Vt as parseFunctionName, W as getGlobalPredefinedStates, Wt as CUSTOM_UNITS, Xt as normalizeColorTokenValue, Yt as getGlobalPredefinedTokens, Zt as parseColor, _ as isConfigLocked, _t as DEFAULT_NAME_PREFIX, a as getGlobalCounterStyles, bt as makeCounterStyleName, c as getGlobalInjector, ct as defineHandler, dn as hexToRgb, en as okhstFunction, f as getNamePrefix, fn as hslToRgbValues, ft as closeBatchWindow, g as hasStylesGenerated, gt as resetStyleBatch, h as hasGlobalRecipes, ht as openBatchWindow, in as createColorFunc, it as formatFontFaceRule, j as FLOW_STYLES, jt as CHUNK_NAMES, k as CONTAINER_STYLES, kt as propHandlerRegistry, l as getGlobalKeyframes, ln as getNamedColorHex, lt as styleHandlers, m as hasGlobalKeyframes, mt as hasPendingStyleWrites, n as getConfig, nn as okhslFunction, o as getGlobalFontFaces, on as StyleParser, ot as SheetManager, p as getStyleEpoch, pn as strToRgb, pt as flushStyles, rn as okhslPlugin, rt as fontFaceContentHash, s as getGlobalFunctions, t as configure, tn as okhstPlugin, u as getGlobalRecipes, un as getRgbValuesFromRgbaString, v as isFunctionsPolyfillEnabled, vt as DEFAULT_ZERO_NAME_PREFIX, w as BASE_STYLES, wt as hashString, x as resetConfig, xt as makeKeyframeName, y as isTestEnvironment, z as parseStateKey, zt as formatFunctionRule } from "./config-B97n_EIv.js";
2
- import { A as injector, C as getCSSText, D as inject, E as hasRecipe, F as resolveChunk, I as touch, L as ChunkSheetRegistry, M as keyframes, N as property, O as injectGlobal, P as releaseStyles, R as chunkSheetRegistry, S as gc, T as getRawCSSText, _ as createInjector, a as color, b as fontFace, c as hasKeys, d as collectAutoInferredPropertiesRSC, f as getStyleTarget, g as counterStyle, h as cleanup, i as _modAttrs, j as isPropertyDefined, k as injectRawCSS, l as formatKeyframesCSS, m as acquireStyles, n as processTokens, o as filterBaseProps, p as pushRSCCSS, r as dotize, s as computeStyles, t as tastyDebug, u as collectAutoInferredProperties, v as defineRecipe, w as getCSSTextForNode, x as func, y as destroy, z as resolveFunctionColor } from "./core-DWrUWxog.js";
3
- import { r as categorizeStyleKeys } from "./renderChunk-COXABoQz.js";
4
- import { n as formatPropertyCSS } from "./format-rules-Wb7dJOoL.js";
5
- import { t as mergeStyles } from "./merge-styles-CzVxdtav.js";
6
- import { t as resolveRecipes } from "./resolve-recipes-BnrUEjWV.js";
7
- import { t as getTastySSRContext } from "./context-CA8YKeMn.js";
8
- import { t as formatGlobalRules } from "./format-global-rules-DklyaXv-.js";
9
- import { Fragment, createElement, forwardRef, useContext, useInsertionEffect } from "react";
10
- //#region src/utils/get-display-name.ts
11
- const DEFAULT_NAME = "Anonymous";
12
- function getDisplayName(Component, fallbackName = DEFAULT_NAME) {
13
- if (typeof Component === "function") return Component.displayName ?? Component.name ?? fallbackName;
14
- return fallbackName;
15
- }
16
- //#endregion
17
- //#region src/utils/is-valid-element-type.ts
18
- /**
19
- * Lightweight replacement for `react-is`'s isValidElementType.
20
- * Detects string tags, function/class components, and React exotic types
21
- * (forwardRef, memo, lazy, etc.) via their internal $$typeof symbol.
22
- */
23
- function isValidElementType(value) {
24
- if (typeof value === "string" || typeof value === "function") return true;
25
- if (typeof value === "object" && value !== null) return typeof value.$$typeof === "symbol";
26
- return false;
27
- }
28
- //#endregion
29
- //#region src/hooks/useStyles.ts
30
- /**
31
- * Hook to generate CSS classes from Tasty styles.
32
- * Thin wrapper around `computeStyles()` that adds React context-based
33
- * SSR collector discovery for backward compatibility with TastyRegistry.
34
- *
35
- * For hook-free usage (e.g. in server components), use `computeStyles()` directly.
36
- *
37
- * @example
38
- * ```tsx
39
- * function MyComponent() {
40
- * const { className } = useStyles({
41
- * padding: '2x',
42
- * fill: '#purple',
43
- * radius: '1r',
44
- * });
45
- *
46
- * return <div className={className}>Styled content</div>;
47
- * }
48
- * ```
49
- */
50
- function useStyles(styles, options) {
51
- const root = options?.root;
52
- const managed = commitManaged$1();
53
- const result = computeStyles(styles, {
54
- ssrCollector: useContext(getTastySSRContext()),
55
- root,
56
- managed
57
- });
58
- if (managed) useStyleCommit(result.className, root);
59
- return result;
60
- }
61
- const CAN_COMMIT$1 = typeof document !== "undefined";
62
- let commitManagedMemo$1 = false;
63
- let commitManagedEpoch$1 = -1;
64
- /**
65
- * Whether styles should be held through the commit rather than written during
66
- * render — see the same gate in `tasty()`. Only applications that configured
67
- * `gc` take the insertion effect; everything else keeps the synchronous path.
68
- */
69
- function commitManaged$1() {
70
- const epoch = getStyleEpoch();
71
- if (commitManagedEpoch$1 !== epoch) {
72
- commitManagedEpoch$1 = epoch;
73
- commitManagedMemo$1 = CAN_COMMIT$1 && getConfig().gc != null;
74
- }
75
- return commitManagedMemo$1;
76
- }
77
- /**
78
- * Hold the styles this render resolved for as long as the component is mounted.
79
- *
80
- * Rendering only names the classes and records what they stand for; this is
81
- * where they reach the sheet. `useInsertionEffect` is React's insertion phase —
82
- * it runs after every render in the commit and before any layout effect, so the
83
- * rules are in place before anything can measure them.
84
- *
85
- * The dependency is the class-name string itself, so an unchanged rerender —
86
- * the overwhelmingly common case — costs one string comparison and nothing
87
- * else. Because setup re-inserts whatever is missing, a class collected while
88
- * this render was still pending simply comes back here.
89
- */
90
- function useStyleCommit(className, root) {
91
- useInsertionEffect(() => {
92
- if (!className) return;
93
- acquireStyles(className, { root });
94
- return () => releaseStyles(className, { root });
95
- }, [className, root]);
96
- }
97
- //#endregion
98
- //#region src/tasty.tsx
99
- /**
100
- * Whether this environment ever commits. Server renders (SSR and RSC) resolve
101
- * class names and hand them to a collector; only a browser mounts them.
102
- */
103
- const CAN_COMMIT = typeof document !== "undefined";
104
- let commitManagedMemo = false;
105
- let commitManagedEpoch = -1;
106
- /**
107
- * Whether styles should be held through the commit rather than written during
108
- * render.
109
- *
110
- * Only applications that asked for collection pay for it. Without `gc`
111
- * configured there is nothing to collect, so components take the synchronous
112
- * path and no insertion effect at all — no hook slot, no dependency array, no
113
- * setup closure per render.
114
- *
115
- * Memoized because it decides whether a hook is taken: it must not change
116
- * between renders of one component. `configure()` locks once the first styles
117
- * are generated, so this settles on the first render and only a whole new
118
- * injector — a new style epoch — can move it.
119
- */
120
- function commitManaged() {
121
- const epoch = getStyleEpoch();
122
- if (commitManagedEpoch !== epoch) {
123
- commitManagedEpoch = epoch;
124
- commitManagedMemo = CAN_COMMIT && getConfig().gc != null;
125
- }
126
- return commitManagedMemo;
127
- }
128
- /**
129
- * Precalculated entries for performance optimization
130
- */
131
- const IS_PROPERTIES_ENTRIES = Object.entries({
132
- isDisabled: "disabled",
133
- isHidden: "hidden",
134
- isChecked: "checked"
135
- });
136
- /**
137
- * Helper function to handle is* properties consistently
138
- * Transforms is* props to HTML attributes and adds corresponding data-* attributes
139
- */
140
- function handleIsProperties(props) {
141
- for (const [isProperty, targetAttribute] of IS_PROPERTIES_ENTRIES) {
142
- if (isProperty in props) {
143
- props[targetAttribute] = props[isProperty];
144
- delete props[isProperty];
145
- }
146
- const dataAttribute = `data-${targetAttribute}`;
147
- if (!(dataAttribute in props) && props[targetAttribute]) props[dataAttribute] = "";
148
- }
149
- }
150
- /**
151
- * Creates a sub-element component for compound component patterns.
152
- * Sub-elements are lightweight components with data-element attribute for CSS targeting.
153
- */
154
- function createSubElement(elementName, definition) {
155
- const config = typeof definition === "string" ? { as: definition } : definition;
156
- const tag = config.as ?? "div";
157
- const defaultQa = config.qa;
158
- const defaultQaVal = config.qaVal;
159
- const SubElement = forwardRef((props, ref) => {
160
- const { qa, qaVal, mods, tokens, isDisabled, isHidden, isChecked, className, style, ...htmlProps } = props;
161
- let modDataAttrs;
162
- if (mods) modDataAttrs = _modAttrs(mods);
163
- const tokenStyle = tokens ? processTokens(tokens) : void 0;
164
- let mergedStyle;
165
- if (tokenStyle || style) mergedStyle = tokenStyle && style ? {
166
- ...tokenStyle,
167
- ...style
168
- } : tokenStyle ?? style;
169
- const elementProps = {
170
- "data-element": elementName,
171
- "data-qa": qa ?? defaultQa,
172
- "data-qaval": qaVal ?? defaultQaVal,
173
- ...modDataAttrs || {},
174
- ...htmlProps,
175
- className,
176
- style: mergedStyle,
177
- isDisabled,
178
- isHidden,
179
- isChecked,
180
- ref
181
- };
182
- handleIsProperties(elementProps);
183
- if (elementProps["data-qa"] === void 0) delete elementProps["data-qa"];
184
- if (elementProps["data-qaval"] === void 0) delete elementProps["data-qaval"];
185
- return createElement(tag, elementProps);
186
- });
187
- SubElement.displayName = `SubElement(${elementName})`;
188
- return SubElement;
189
- }
190
- /**
191
- * Pre-compute the mapping from prop name to token key at component-creation time.
192
- * Array form: `'progress'` -> `'$progress'`, `'accentColor'` -> `'#accent'`.
193
- * Object form: entries used as-is.
194
- */
195
- function buildTokenPropsMapping(def) {
196
- if (Array.isArray(def)) return def.map((propName) => {
197
- if (propName.endsWith("Color") && propName.length > 5) return [propName, `#${propName.slice(0, -5)}`];
198
- return [propName, `$${propName}`];
199
- });
200
- return Object.entries(def);
201
- }
202
- function tasty(Component, options) {
203
- if (isValidElementType(Component)) return tastyWrap(Component, options);
204
- return tastyElement(Component);
205
- }
206
- function tastyWrap(Component, options) {
207
- const { as: extendTag, element: extendElement, styleProps: _styleProps, modProps: _modProps, tokenProps: _tokenProps, variants: _variants, elements: _elements, ...defaultProps } = options ?? {};
208
- const propsWithStyles = ["styles"].concat(Object.keys(defaultProps).filter((prop) => prop.endsWith("Styles")));
209
- const _WrappedComponent = forwardRef((props, ref) => {
210
- const { as, element, ...restProps } = props;
211
- const mergedStylesMap = propsWithStyles.reduce((map, prop) => {
212
- const restValue = restProps[prop];
213
- const defaultValue = defaultProps[prop];
214
- if (restValue != null && defaultValue != null) map[prop] = mergeStyles(defaultValue, restValue);
215
- else map[prop] = restValue ?? defaultValue;
216
- return map;
217
- }, {});
218
- return createElement(Component, {
219
- ...defaultProps,
220
- ...restProps,
221
- ...mergedStylesMap,
222
- as: as ?? extendTag,
223
- element: element || extendElement,
224
- ref
225
- });
226
- });
227
- _WrappedComponent.displayName = `TastyWrappedComponent(${getDisplayName(Component, defaultProps.qa ?? extendTag ?? "Anonymous")})`;
228
- return _WrappedComponent;
229
- }
230
- function tastyElement(tastyOptions) {
231
- const { as: originalAs = "div", element: defaultElement, styles: defaultStyles, styleProps, modProps: modPropsDef, tokenProps: tokenPropsDef, variants, tokens: defaultTokens, elements, ...defaultProps } = tastyOptions;
232
- let variantStylesMap;
233
- if (variants) {
234
- let baseStyles = defaultStyles;
235
- let extensionStyles;
236
- if (defaultStyles) for (const key of Object.keys(defaultStyles)) {
237
- if (isSelector(key)) continue;
238
- const value = defaultStyles[key];
239
- if (typeof value === "object" && value !== null && !Array.isArray(value) && !("" in value)) {
240
- if (!extensionStyles) {
241
- baseStyles = { ...defaultStyles };
242
- extensionStyles = {};
243
- }
244
- extensionStyles[key] = value;
245
- delete baseStyles[key];
246
- }
247
- }
248
- variantStylesMap = Object.entries(variants).reduce((map, [variant, variantStyles]) => {
249
- map[variant] = extensionStyles ? mergeStyles(baseStyles, variantStyles, extensionStyles) : mergeStyles(baseStyles, variantStyles);
250
- return map;
251
- }, {});
252
- if (!variantStylesMap["default"]) variantStylesMap["default"] = defaultStyles;
253
- }
254
- const { qa: defaultQa, qaVal: defaultQaVal, ...otherDefaultProps } = defaultProps ?? {};
255
- const ownPropsToCheck = styleProps ? styleProps.concat(BASE_STYLES) : BASE_STYLES;
256
- let propsToCheck = ownPropsToCheck;
257
- let propsToCheckVersion = -1;
258
- const modPropsKeys = modPropsDef ? Array.isArray(modPropsDef) ? modPropsDef : Object.keys(modPropsDef) : void 0;
259
- const tokenPropsMapping = tokenPropsDef ? buildTokenPropsMapping(tokenPropsDef) : void 0;
260
- const classNameCache = /* @__PURE__ */ new Map();
261
- const STABLE_STYLES = { stableStyles: true };
262
- const STABLE_STYLES_MANAGED = {
263
- stableStyles: true,
264
- managed: true
265
- };
266
- const MANAGED = { managed: true };
267
- const _TastyComponent = forwardRef((incomingProps, ref) => {
268
- const applyPropHandlers = propHandlerRegistry.apply;
269
- const { as, styles: rawStyles, variant, mods, element, qa, qaVal, className: userClassName, tokens, style, theme, ...otherProps } = applyPropHandlers ? applyPropHandlers(incomingProps) : incomingProps;
270
- let styles = rawStyles;
271
- let propStyles = null;
272
- if (propsToCheckVersion !== baseStylePropsRegistry.version) {
273
- const promoted = baseStylePropsRegistry.list;
274
- propsToCheck = promoted.length === 0 ? ownPropsToCheck : ownPropsToCheck.concat(promoted);
275
- propsToCheckVersion = baseStylePropsRegistry.version;
276
- }
277
- for (const prop of propsToCheck) {
278
- const key = prop;
279
- if (key in otherProps) {
280
- if (!propStyles) propStyles = {};
281
- const value = otherProps[key];
282
- propStyles[key] = value;
283
- delete otherProps[key];
284
- }
285
- }
286
- if (!styles || styles && !hasKeys(styles)) styles = void 0;
287
- let propMods;
288
- if (modPropsKeys) {
289
- for (const key of modPropsKeys) if (key in otherProps) {
290
- if (!propMods) propMods = {};
291
- propMods[key] = otherProps[key];
292
- delete otherProps[key];
293
- }
294
- }
295
- let propTokens;
296
- if (tokenPropsMapping) {
297
- for (const [propName, tokenKey] of tokenPropsMapping) if (propName in otherProps) {
298
- if (!propTokens) propTokens = {};
299
- propTokens[tokenKey] = otherProps[propName];
300
- delete otherProps[propName];
301
- }
302
- }
303
- const baseStyles = variantStylesMap ? variantStylesMap[variant || "default"] ?? variantStylesMap["default"] : defaultStyles;
304
- const hasInstanceStyles = styles && hasKeys(styles);
305
- const hasPropStyles = propStyles && hasKeys(propStyles);
306
- const allStyles = hasInstanceStyles || hasPropStyles ? mergeStyles(baseStyles, styles, propStyles) : baseStyles;
307
- const managed = commitManaged();
308
- const useFactoryCache = typeof document !== "undefined";
309
- const cached = useFactoryCache && allStyles === baseStyles ? classNameCache.get(allStyles) : void 0;
310
- let stylesResult;
311
- if (cached && cached[1] === getStyleEpoch()) stylesResult = { className: cached[0] };
312
- else {
313
- stylesResult = computeStyles(allStyles, !useFactoryCache && allStyles === baseStyles ? managed ? STABLE_STYLES_MANAGED : STABLE_STYLES : managed ? MANAGED : void 0);
314
- if (useFactoryCache && allStyles === baseStyles) classNameCache.set(allStyles, [stylesResult.className, getStyleEpoch()]);
315
- }
316
- if (managed) useStyleCommit(stylesResult.className);
317
- let mergedTokens;
318
- if (defaultTokens || tokens || propTokens) if (!defaultTokens && !propTokens) mergedTokens = tokens;
319
- else if (!tokens && !propTokens) mergedTokens = defaultTokens;
320
- else mergedTokens = {
321
- ...defaultTokens,
322
- ...tokens,
323
- ...propTokens
324
- };
325
- const processedTokenStyle = processTokens(mergedTokens);
326
- let mergedStyle;
327
- if (processedTokenStyle || style) if (!processedTokenStyle) mergedStyle = style;
328
- else if (!style) mergedStyle = processedTokenStyle;
329
- else mergedStyle = {
330
- ...processedTokenStyle,
331
- ...style
332
- };
333
- const mergedMods = propMods ? {
334
- ...mods,
335
- ...propMods
336
- } : mods;
337
- let modDataAttrs;
338
- if (mergedMods) modDataAttrs = _modAttrs(mergedMods);
339
- const finalClassName = [userClassName || "", stylesResult.className].filter(Boolean).join(" ");
340
- const elementProps = {
341
- "data-element": element || defaultElement,
342
- "data-qa": qa || defaultQa,
343
- "data-qaval": qaVal || defaultQaVal,
344
- "data-theme": theme,
345
- ...otherDefaultProps,
346
- ...modDataAttrs || {},
347
- ...otherProps,
348
- className: finalClassName,
349
- style: mergedStyle,
350
- ref
351
- };
352
- handleIsProperties(elementProps);
353
- if (elementProps["data-theme"] === void 0) delete elementProps["data-theme"];
354
- const el = createElement(as ?? originalAs, elementProps);
355
- if (stylesResult.css) {
356
- const nonce = getConfig().nonce;
357
- return createElement(Fragment, null, createElement("style", {
358
- "data-tasty-rsc": "",
359
- nonce,
360
- dangerouslySetInnerHTML: { __html: stylesResult.css }
361
- }), el);
362
- }
363
- return el;
364
- });
365
- _TastyComponent.displayName = `TastyComponent(${defaultProps.qa || originalAs})`;
366
- if (elements) {
367
- const subElements = Object.entries(elements).reduce((acc, [name, definition]) => {
368
- acc[name] = createSubElement(name, definition);
369
- return acc;
370
- }, {});
371
- return Object.assign(_TastyComponent, subElements);
372
- }
373
- return _TastyComponent;
374
- }
375
- const Element = tasty({});
376
- //#endregion
377
- //#region src/utils/client-state.ts
378
- /**
379
- * Build a per-(injector, root) client state cache for the standalone style
380
- * functions (`useGlobalStyles`, `useRawCSS`, `useKeyframes`, `useCounterStyle`).
381
- *
382
- * Two levels, both weak:
383
- *
384
- * - **injector** — `configure()` replaces the global injector, and every dispose
385
- * handle and generated name we cache belongs to the one that produced it.
386
- * Keying by injector makes stale state fall away with it, instead of letting
387
- * change-detection keys suppress re-injection into the new sheets.
388
- * - **root** — the same selector or slot name can be used in several shadow
389
- * roots, and each holds its own injection.
390
- */
391
- function createClientState(create) {
392
- const byInjector = /* @__PURE__ */ new WeakMap();
393
- return (root) => {
394
- const injector = getGlobalInjector();
395
- let byRoot = byInjector.get(injector);
396
- if (!byRoot) {
397
- byRoot = /* @__PURE__ */ new WeakMap();
398
- byInjector.set(injector, byRoot);
399
- }
400
- let state = byRoot.get(root);
401
- if (!state) {
402
- state = create();
403
- byRoot.set(root, state);
404
- }
405
- return state;
406
- };
407
- }
408
- //#endregion
409
- //#region src/hooks/useGlobalStyles.ts
410
- const getClientGlobalSlots = createClientState(() => /* @__PURE__ */ new Map());
411
- const noop = () => {};
412
- /**
413
- * Inject global styles for a given selector.
414
- * Useful for styling elements by selector without generating classNames.
415
- *
416
- * SSR-aware: when a ServerStyleCollector is available, CSS is collected
417
- * during the render phase instead of being injected into the DOM.
418
- *
419
- * Works in all environments: client, SSR with collector, and React Server Components.
420
- *
421
- * Injected styles are permanent — they are not cleaned up on component unmount.
422
- * Use the `id` option for update tracking when styles change over the
423
- * component lifecycle.
424
- *
425
- * Update tracking is per-slot and per-root: a slot (`id`, or the selector when
426
- * no `id` is given) holds exactly one injection per `root`. Changing the styles
427
- * replaces it; rendering styles that produce no CSS clears it.
428
- *
429
- * @param selector - CSS selector to apply styles to (e.g., '.my-class', ':root', 'body')
430
- * @param styles - Tasty styles object
431
- * @param options - Optional settings including `id` for update tracking
432
- *
433
- * @example
434
- * ```tsx
435
- * function MyComponent() {
436
- * useGlobalStyles('.card', {
437
- * padding: '2x',
438
- * radius: '1r',
439
- * fill: '#white',
440
- * });
441
- *
442
- * return <div className="card">Content</div>;
443
- * }
444
- * ```
445
- */
446
- function useGlobalStyles(selector, styles, options) {
447
- if (!styles) return;
448
- if (!selector) {
449
- console.warn("[Tasty] useGlobalStyles: selector is required and cannot be empty. Styles will not be injected.");
450
- return;
451
- }
452
- const target = getStyleTarget();
453
- const slots = target.mode === "client" ? getClientGlobalSlots(options?.root ?? document) : null;
454
- const slotKey = options?.id ?? selector;
455
- const stylesKey = slots ? JSON.stringify(styles) : "";
456
- const existing = slots?.get(slotKey);
457
- if (existing && existing.stylesKey === stylesKey) return;
458
- const resolvedStyles = resolveRecipes(styles);
459
- const styleResults = renderStyles(resolvedStyles, selector);
460
- if (styleResults.length === 0) {
461
- if (slots) {
462
- existing?.dispose();
463
- slots.set(slotKey, {
464
- stylesKey,
465
- dispose: noop
466
- });
467
- }
468
- return;
469
- }
470
- if (target.mode === "ssr") {
471
- target.collector.collectInternals();
472
- const css = formatGlobalRules(styleResults);
473
- if (css) {
474
- const key = options?.id ? `global:${options.id}` : `global:${selector}:${hashString(css)}`;
475
- target.collector.collectGlobalStyles(key, css, options?.id != null);
476
- }
477
- if (getConfig().autoPropertyTypes !== false) collectAutoInferredProperties(styleResults, target.collector, resolvedStyles);
478
- return;
479
- }
480
- if (target.mode === "rsc") {
481
- const css = formatGlobalRules(styleResults);
482
- if (css) {
483
- const key = options?.id ? `__global:${options.id}` : `__global:${selector}:${hashString(css)}`;
484
- pushRSCCSS(target.cache, key, css, options?.id != null);
485
- }
486
- if (getConfig().autoPropertyTypes !== false) collectAutoInferredPropertiesRSC(styleResults, target.cache, resolvedStyles);
487
- return;
488
- }
489
- if (slots) {
490
- existing?.dispose();
491
- const { dispose } = injectGlobal(styleResults, { root: options?.root });
492
- slots.set(slotKey, {
493
- stylesKey,
494
- dispose
495
- });
496
- }
497
- }
498
- //#endregion
499
- //#region src/utils/deps-equal.ts
500
- /**
501
- * Shallow comparison of two dependency arrays using Object.is semantics.
502
- * Returns true when both arrays have the same length and every element
503
- * at the same index is identical.
504
- */
505
- function depsEqual(a, b) {
506
- if (a.length !== b.length) return false;
507
- for (let i = 0; i < a.length; i++) if (!Object.is(a[i], b[i])) return false;
508
- return true;
509
- }
510
- //#endregion
511
- //#region src/hooks/useRawCSS.ts
512
- const getClientState$1 = createClientState(() => ({
513
- entries: /* @__PURE__ */ new Map(),
514
- contentDedup: /* @__PURE__ */ new Set(),
515
- factoryDeps: /* @__PURE__ */ new Map()
516
- }));
517
- /**
518
- * Inject raw CSS text directly without parsing.
519
- * This is a low-overhead alternative for injecting global CSS that doesn't need tasty processing.
520
- *
521
- * The CSS is inserted into a separate style element (data-tasty-raw) to avoid conflicts
522
- * with tasty's chunked style sheets.
523
- *
524
- * Works in all environments: client, SSR with collector, and React Server Components.
525
- *
526
- * Injected styles are permanent — they are not cleaned up on component unmount.
527
- * Use the `id` option for update tracking when styles change over the
528
- * component lifecycle.
529
- *
530
- * @example Static CSS string
531
- * ```tsx
532
- * function GlobalStyles() {
533
- * useRawCSS(`
534
- * body {
535
- * margin: 0;
536
- * padding: 0;
537
- * font-family: sans-serif;
538
- * }
539
- * `);
540
- *
541
- * return null;
542
- * }
543
- * ```
544
- *
545
- * @example Factory function with dependencies
546
- * ```tsx
547
- * function ThemeStyles({ theme }: { theme: 'light' | 'dark' }) {
548
- * useRawCSS(() => `
549
- * :root {
550
- * --bg-color: ${theme === 'dark' ? '#1a1a1a' : '#ffffff'};
551
- * --text-color: ${theme === 'dark' ? '#ffffff' : '#1a1a1a'};
552
- * }
553
- * `, [theme], { id: 'theme-vars' });
554
- *
555
- * return null;
556
- * }
557
- * ```
558
- *
559
- * @example With options
560
- * ```tsx
561
- * function ShadowStyles({ shadowRoot }) {
562
- * useRawCSS(() => `.scoped { color: red; }`, [], { root: shadowRoot });
563
- * return null;
564
- * }
565
- * ```
566
- */
567
- function useRawCSS(cssOrFactory, depsOrOptions, options) {
568
- const isFactory = typeof cssOrFactory === "function";
569
- const deps = isFactory && Array.isArray(depsOrOptions) ? depsOrOptions : void 0;
570
- const opts = isFactory ? options : depsOrOptions;
571
- const target = getStyleTarget();
572
- const state = target.mode === "client" ? getClientState$1(opts?.root ?? document) : null;
573
- if (isFactory && deps && opts?.id && state) {
574
- const cachedDeps = state.factoryDeps.get(opts.id);
575
- if (cachedDeps && depsEqual(cachedDeps, deps)) return;
576
- }
577
- const css = isFactory ? cssOrFactory() : cssOrFactory;
578
- if (!css.trim()) return;
579
- if (target.mode === "ssr") {
580
- const key = opts?.id ? `raw:${opts.id}` : `raw:${hashString(css)}`;
581
- target.collector.collectRawCSS(key, css, opts?.id != null);
582
- return;
583
- }
584
- if (target.mode === "rsc") {
585
- const key = opts?.id ? `__raw:${opts.id}` : `__raw:${hashString(css)}`;
586
- pushRSCCSS(target.cache, key, css, opts?.id != null);
587
- return;
588
- }
589
- if (!state) return;
590
- const id = opts?.id;
591
- if (id) {
592
- const existing = state.entries.get(id);
593
- if (existing) {
594
- if (existing.contentKey === css) return;
595
- existing.dispose();
596
- }
597
- const { dispose } = injectRawCSS(css, opts);
598
- state.entries.set(id, {
599
- contentKey: css,
600
- dispose
601
- });
602
- if (deps) state.factoryDeps.set(id, deps);
603
- } else {
604
- const contentKey = hashString(css);
605
- if (state.contentDedup.has(contentKey)) return;
606
- state.contentDedup.add(contentKey);
607
- injectRawCSS(css, opts);
608
- }
609
- }
610
- //#endregion
611
- //#region src/hooks/useKeyframes.ts
612
- const getClientState = createClientState(() => ({
613
- contentToName: /* @__PURE__ */ new Map(),
614
- namedSlots: /* @__PURE__ */ new Map(),
615
- factoryDeps: /* @__PURE__ */ new Map()
616
- }));
617
- function useKeyframes(stepsOrFactory, depsOrOptions, options) {
618
- const isFactory = typeof stepsOrFactory === "function";
619
- const deps = isFactory && Array.isArray(depsOrOptions) ? depsOrOptions : void 0;
620
- const opts = isFactory ? options : depsOrOptions;
621
- const target = getStyleTarget();
622
- const clientState = target.mode === "client" ? getClientState(opts?.root ?? document) : null;
623
- if (isFactory && deps && opts?.name && clientState) {
624
- const cached = clientState.factoryDeps.get(opts.name);
625
- if (cached && depsEqual(cached.deps, deps)) return cached.name;
626
- }
627
- const steps = isFactory ? stepsOrFactory() : stepsOrFactory;
628
- if (!steps || Object.keys(steps).length === 0) return "";
629
- if (target.mode === "ssr") {
630
- const actualName = target.collector.allocateKeyframeName(opts?.name);
631
- const css = formatKeyframesCSS(actualName, steps);
632
- target.collector.collectKeyframes(actualName, css);
633
- return actualName;
634
- }
635
- if (target.mode === "rsc") {
636
- const serializedContent = JSON.stringify(steps);
637
- const key = `__kf:${opts?.name ?? ""}:${serializedContent}`;
638
- const existingName = target.cache.generatedNames.get(key);
639
- if (existingName) return existingName;
640
- const actualName = opts?.name ?? makeKeyframeName(getNamePrefix(), hashString(serializedContent));
641
- const css = formatKeyframesCSS(actualName, steps);
642
- pushRSCCSS(target.cache, key, css);
643
- target.cache.generatedNames.set(key, actualName);
644
- return actualName;
645
- }
646
- const state = clientState ?? getClientState(opts?.root ?? document);
647
- const serializedContent = JSON.stringify(steps);
648
- const cacheKey = `${opts?.name ?? ""}:${serializedContent}`;
649
- const cachedName = state.contentToName.get(cacheKey);
650
- if (cachedName) return cachedName;
651
- const providedName = opts?.name;
652
- if (providedName) {
653
- const slot = state.namedSlots.get(providedName);
654
- if (slot && slot.cacheKey !== cacheKey) {
655
- slot.dispose();
656
- state.contentToName.delete(slot.cacheKey);
657
- state.namedSlots.delete(providedName);
658
- }
659
- }
660
- const result = keyframes(steps, {
661
- name: providedName,
662
- root: opts?.root
663
- });
664
- const name = result.toString();
665
- state.contentToName.set(cacheKey, name);
666
- if (providedName) {
667
- state.namedSlots.set(providedName, {
668
- cacheKey,
669
- dispose: result.dispose
670
- });
671
- if (deps) state.factoryDeps.set(providedName, {
672
- deps,
673
- name
674
- });
675
- }
676
- return name;
677
- }
678
- //#endregion
679
- //#region src/hooks/useProperty.ts
680
- /**
681
- * Register a CSS @property custom property.
682
- * This enables advanced features like animating custom properties.
683
- *
684
- * Note: @property rules are global and persistent once defined.
685
- * The function ensures the property is only registered once per root.
686
- *
687
- * Accepts tasty token syntax for the property name:
688
- * - `$name` → defines `--name`
689
- * - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')
690
- * - `--name` → defines `--name` (legacy format)
691
- *
692
- * Works in all environments: client, SSR with collector, and React Server Components.
693
- *
694
- * @param name - The property token ($name, #name) or CSS property name (--name)
695
- * @param options - Property configuration
696
- *
697
- * @example Basic property with token syntax
698
- * ```tsx
699
- * function Spinner() {
700
- * useProperty('$rotation', {
701
- * syntax: '<angle>',
702
- * inherits: false,
703
- * initialValue: '0deg',
704
- * });
705
- *
706
- * return <div className="spinner" />;
707
- * }
708
- * ```
709
- *
710
- * @example Color property with token syntax (auto-sets syntax)
711
- * ```tsx
712
- * function MyComponent() {
713
- * useProperty('#theme', {
714
- * initialValue: 'red', // syntax: '<color>' is auto-set
715
- * });
716
- *
717
- * // Now --theme-color can be animated with CSS transitions
718
- * return <div style={{ '--theme-color': 'blue' } as React.CSSProperties}>Colored</div>;
719
- * }
720
- * ```
721
- *
722
- * @example Legacy format (still supported)
723
- * ```tsx
724
- * function ResizableBox() {
725
- * useProperty('--box-size', {
726
- * syntax: '<length>',
727
- * initialValue: '100px',
728
- * });
729
- *
730
- * return <div style={{ width: 'var(--box-size)' }} />;
731
- * }
732
- * ```
733
- */
734
- function useProperty(name, options) {
735
- if (!name) {
736
- console.warn(`[Tasty] useProperty: property name is required`);
737
- return;
738
- }
739
- const target = getStyleTarget();
740
- if (target.mode === "ssr") {
741
- target.collector.collectInternals();
742
- const css = formatPropertyCSS(name, {
743
- syntax: options?.syntax,
744
- inherits: options?.inherits,
745
- initialValue: options?.initialValue
746
- });
747
- if (css) target.collector.collectProperty(name, css);
748
- return;
749
- }
750
- if (target.mode === "rsc") {
751
- const css = formatPropertyCSS(name, {
752
- syntax: options?.syntax,
753
- inherits: options?.inherits,
754
- initialValue: options?.initialValue
755
- });
756
- if (css) pushRSCCSS(target.cache, `__prop:${name}`, css);
757
- return;
758
- }
759
- const injector = getGlobalInjector();
760
- if (injector.isPropertyDefined(name, { root: options?.root })) return;
761
- injector.property(name, {
762
- syntax: options?.syntax,
763
- inherits: options?.inherits,
764
- initialValue: options?.initialValue,
765
- root: options?.root
766
- });
767
- }
768
- //#endregion
769
- //#region src/hooks/useFontFace.ts
770
- /**
771
- * Inject CSS @font-face rules.
772
- * Permanent — no cleanup on unmount. Deduplicates by content hash.
773
- *
774
- * Works in all environments: client, SSR with collector, and React Server Components.
775
- *
776
- * @param family - The font-family name
777
- * @param input - Single descriptor object or array of descriptors (for multiple weights/styles)
778
- * @param options - Optional settings (e.g. Shadow DOM root)
779
- *
780
- * @example Single weight
781
- * ```tsx
782
- * function App() {
783
- * useFontFace('Brand Sans', {
784
- * src: 'url("/fonts/brand-sans.woff2") format("woff2")',
785
- * fontWeight: '400 700',
786
- * fontDisplay: 'swap',
787
- * });
788
- *
789
- * return <div style={{ fontFamily: '"Brand Sans", sans-serif' }}>Hello</div>;
790
- * }
791
- * ```
792
- *
793
- * @example Multiple weights
794
- * ```tsx
795
- * function App() {
796
- * useFontFace('Brand Sans', [
797
- * { src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
798
- * { src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
799
- * ]);
800
- *
801
- * return <div style={{ fontFamily: '"Brand Sans", sans-serif' }}>Hello</div>;
802
- * }
803
- * ```
804
- */
805
- function useFontFace(family, input, options) {
806
- if (!family) return;
807
- const descriptors = Array.isArray(input) ? input : [input];
808
- const target = getStyleTarget();
809
- if (target.mode === "ssr") {
810
- for (const desc of descriptors) {
811
- const hash = fontFaceContentHash(family, desc);
812
- const css = formatFontFaceRule(family, desc);
813
- target.collector.collectFontFace(hash, css);
814
- }
815
- return;
816
- }
817
- if (target.mode === "rsc") {
818
- for (const desc of descriptors) {
819
- const hash = fontFaceContentHash(family, desc);
820
- const css = formatFontFaceRule(family, desc);
821
- pushRSCCSS(target.cache, `__ff:${hash}`, css);
822
- }
823
- return;
824
- }
825
- const injector = getGlobalInjector();
826
- for (const desc of descriptors) injector.fontFace(family, desc, { root: options?.root });
827
- }
828
- //#endregion
829
- //#region src/hooks/useCounterStyle.ts
830
- let clientCounterStyleCounter = 0;
831
- const getClientContentToName = createClientState(() => /* @__PURE__ */ new Map());
832
- /**
833
- * Inject a CSS @counter-style rule and return the generated name.
834
- * Permanent — no cleanup on unmount. Deduplicates by name.
835
- *
836
- * Works in all environments: client, SSR with collector, and React Server Components.
837
- *
838
- * @example Basic usage
839
- * ```tsx
840
- * function EmojiList() {
841
- * const styleName = useCounterStyle({
842
- * system: 'cyclic',
843
- * symbols: '"👍"',
844
- * suffix: '" "',
845
- * }, { name: 'thumbs' });
846
- *
847
- * return (
848
- * <ol style={{ listStyleType: styleName }}>
849
- * <li>First</li>
850
- * <li>Second</li>
851
- * </ol>
852
- * );
853
- * }
854
- * ```
855
- *
856
- */
857
- function useCounterStyle(descriptors, options) {
858
- if (!descriptors || !descriptors.system) return "";
859
- const target = getStyleTarget();
860
- if (target.mode === "ssr") {
861
- const actualName = target.collector.allocateCounterStyleName(options?.name);
862
- const css = formatCounterStyleRule(actualName, descriptors);
863
- target.collector.collectCounterStyle(actualName, css);
864
- return actualName;
865
- }
866
- if (target.mode === "rsc") {
867
- const serializedContent = JSON.stringify(descriptors);
868
- const key = `__cs:${options?.name ?? ""}:${serializedContent}`;
869
- const existingName = target.cache.generatedNames.get(key);
870
- if (existingName) return existingName;
871
- const actualName = options?.name ?? makeCounterStyleName(getNamePrefix(), hashString(serializedContent));
872
- const css = formatCounterStyleRule(actualName, descriptors);
873
- pushRSCCSS(target.cache, key, css);
874
- target.cache.generatedNames.set(key, actualName);
875
- return actualName;
876
- }
877
- const contentToName = getClientContentToName(options?.root ?? document);
878
- const serializedContent = JSON.stringify(descriptors);
879
- const cacheKey = `${options?.name ?? ""}:${serializedContent}`;
880
- const existingName = contentToName.get(cacheKey);
881
- if (existingName) return existingName;
882
- const name = options?.name ?? makeCounterStyleName(getNamePrefix(), String(clientCounterStyleCounter++));
883
- contentToName.set(cacheKey, name);
884
- getGlobalInjector().counterStyle(name, descriptors, { root: options?.root });
885
- return name;
886
- }
887
- //#endregion
888
- //#region src/hooks/useFunction.ts
889
- /**
890
- * Register a CSS @function (custom function).
891
- *
892
- * @function rules are global and persistent once defined. The hook ensures the
893
- * function is only registered once per root (deduplicated by function name).
894
- *
895
- * Accepts tasty token syntax for the function name:
896
- * - `$$name` → defines `--name` (matches the call site `$$name(...)`)
897
- * - `$name` / `--name` → also accepted
898
- *
899
- * Works in all environments: client, SSR with collector, and React Server Components.
900
- *
901
- * @param name - The function name token (`$$name`, `$name`, or `--name`)
902
- * @param definition - Function definition (args, returns, result, local vars)
903
- *
904
- * Call the function through the Tasty DSL, not a raw `style` prop: an inline
905
- * `style` value reaches the browser unparsed, so the `$$name(...)` sugar is never
906
- * expanded and `polyfills.functions` cannot rewrite it either.
907
- *
908
- * @example
909
- * ```tsx
910
- * const Box = tasty({ styles: { marginTop: '$$negative(10px)' } });
911
- *
912
- * function Layout() {
913
- * useFunction('$$negative', { args: ['$value'], result: '(-1 * $value)' });
914
- * return <Box />;
915
- * }
916
- * ```
917
- */
918
- function useFunction(name, definition, options) {
919
- if (!name) {
920
- console.warn(`[Tasty] useFunction: function name is required`);
921
- return;
922
- }
923
- if (isFunctionsPolyfillEnabled()) {
924
- registerFunctionPolyfill(name, definition);
925
- return;
926
- }
927
- const target = getStyleTarget();
928
- if (target.mode === "ssr") {
929
- target.collector.collectInternals();
930
- const css = formatFunctionRule(name, definition);
931
- if (css) target.collector.collectFunction(parseFunctionName(name), css);
932
- return;
933
- }
934
- if (target.mode === "rsc") {
935
- const css = formatFunctionRule(name, definition);
936
- if (css) pushRSCCSS(target.cache, `__func:${parseFunctionName(name)}`, css);
937
- return;
938
- }
939
- getGlobalInjector().func(name, definition, { root: options?.root });
940
- }
941
- //#endregion
942
- //#region src/batch-provider.tsx
943
- /**
944
- * Opens a *batch window* for the commit it renders in, so `batchInjection`
945
- * can defer stylesheet writes without ever letting a layout effect measure an
946
- * unstyled element.
947
- *
948
- * Every `insertRule()` on a live sheet invalidates style for that sheet's
949
- * scope. When components inject during React's render phase while others read
950
- * layout in the same pass, the two interleave and the browser recalculates
951
- * style between every injection. Batching collapses that into one invalidation
952
- * per flush — but only if the flush happens before anything can measure.
953
- *
954
- * ```
955
- * provider renders -> window OPEN
956
- * children render -> injections queued
957
- * provider insertionEffect -> FLUSH, window CLOSED
958
- * layout effects run -> rules are in the sheet
959
- * ```
960
- *
961
- * `useInsertionEffect` runs in React's mutation phase, after every render in
962
- * the commit and before any `useLayoutEffect` — which is exactly why React
963
- * added it for CSS-in-JS libraries. Effects fire child-first, so this
964
- * provider's runs after every descendant's and still before all layout
965
- * effects.
966
- *
967
- * A commit that does not re-render this provider gets no window, and those
968
- * injections are written synchronously instead. That is the point: turning
969
- * `batchInjection: true` on can only ever make injection cheaper, never make a
970
- * measurement wrong. It also means batching applies to commits this provider
971
- * takes part in, so mount it as high in the tree as you can.
972
- *
973
- * Requires `configure({ batchInjection: true })`; without it this component
974
- * only renders its children. `batchInjection: 'always'` does not need the
975
- * provider at all — see that option's docs for the trade-off it accepts.
976
- *
977
- * @example
978
- * ```tsx
979
- * configure({ batchInjection: true });
980
- *
981
- * createRoot(el).render(
982
- * <TastyBatchProvider>
983
- * <App />
984
- * </TastyBatchProvider>,
985
- * );
986
- * ```
987
- */
988
- function TastyBatchProvider({ children }) {
989
- openBatchWindow();
990
- useInsertionEffect(() => {
991
- closeBatchWindow();
992
- });
993
- return children;
994
- }
995
- //#endregion
996
- export { APPEARANCE_CHUNK_STYLES, BASE_STYLES, BLOCK_INNER_STYLES, BLOCK_OUTER_STYLES, BLOCK_STYLES, CHUNK_NAMES, COLOR_STYLES, CONTAINER_STYLES, CUSTOM_UNITS, ChunkSheetRegistry, DEFAULT_NAME_PREFIX, DEFAULT_ZERO_NAME_PREFIX, DIMENSION_CHUNK_STYLES, DIMENSION_STYLES, DIRECTIONS, DISPLAY_CHUNK_STYLES, Element, FLOW_STYLES, FONT_CHUNK_STYLES, INNER_STYLES, LAYOUT_CHUNK_STYLES, OUTER_STYLES, POSITION_CHUNK_STYLES, POSITION_STYLES, STYLE_TO_CHUNK, SheetManager, StyleInjector, StyleParser, TEXT_STYLES, TastyBatchProvider, acquireStyles, categorizeStyleKeys, chunkSheetRegistry, cleanup, color, computeStyles, configure, counterStyle, createColorFunc, createInjector, createStateParserContext, defineHandler, defineRecipe, destroy, dotize, filterBaseProps, filterMods, flushStyles, fontFace, func, gc, generateTypographyTokens, getCSSText, getCSSTextForNode, getConfig, getDisplayName, getGlobalCounterStyles, getGlobalFontFaces, getGlobalFunctions, getGlobalKeyframes, getGlobalParser, getGlobalPredefinedStates, getGlobalPredefinedTokens, getGlobalRecipes, getNamePrefix, getNamedColorHex, getRawCSSText, getRgbValuesFromRgbaString, hasGlobalKeyframes, hasGlobalRecipes, hasPendingStyleWrites, hasRecipe, hasStylesGenerated, hexToRgb, hslToRgbValues, inject, injectGlobal, injectRawCSS, injector, isConfigLocked, isPropertyDefined, isSelector, isTestEnvironment, keyframes, mergeStyles, _modAttrs as modAttrs, normalizeColorTokenValue, okhslFunction, okhslPlugin, okhstFunction, okhstPlugin, parseColor, parseStateKey, parseStyle, processTokens, property, releaseStyles, renderStyles, resetConfig, resetStyleBatch, resolveChunk, resolveFunctionColor, resolveRecipes, setGlobalPredefinedStates, strToRgb, stringifyStyles, styleHandlers, tasty, tastyDebug, touch, useCounterStyle, useFontFace, useFunction, useGlobalStyles, useKeyframes, useProperty, useRawCSS, useStyles };
997
-
998
- //# sourceMappingURL=index.js.map
1
+ import { A as strToRgb, C as StyleParser, D as getRgbValuesFromRgbaString, E as getNamedColorHex, O as hexToRgb, S as createColorFunc, _ as stringifyStyles, b as okhslFunction, c as getGlobalParser, d as parseColor, f as parseStyle, i as DIRECTIONS, k as hslToRgbValues, l as getGlobalPredefinedTokens, n as resolveFunctionColor, o as filterMods, r as CUSTOM_UNITS, t as color, u as normalizeColorTokenValue, v as okhstFunction, x as okhslPlugin, y as okhstPlugin } from "./chunks/dsl-DRhFWQzo.js";
2
+ import { n as isSelector, t as mergeStyles } from "./chunks/shared-utils-y-HjvPN4.js";
3
+ import { E as DEFAULT_ZERO_NAME_PREFIX, T as DEFAULT_NAME_PREFIX } from "./chunks/css-definitions-BibU6ZnP.js";
4
+ import { A as styleHandlers, B as STYLE_TO_CHUNK, E as defineHandler, F as DIMENSION_CHUNK_STYLES, G as setGlobalPredefinedStates, I as DISPLAY_CHUNK_STYLES, K as hasStylesGenerated, L as FONT_CHUNK_STYLES, N as APPEARANCE_CHUNK_STYLES, P as CHUNK_NAMES, R as LAYOUT_CHUNK_STYLES, S as parseStateKey, U as createStateParserContext, W as getGlobalPredefinedStates, _ as POSITION_STYLES, b as renderStyles, c as BLOCK_INNER_STYLES, d as COLOR_STYLES, f as CONTAINER_STYLES, g as OUTER_STYLES, h as INNER_STYLES, l as BLOCK_OUTER_STYLES, m as FLOW_STYLES, p as DIMENSION_STYLES, r as categorizeStyleKeys, s as BASE_STYLES, u as BLOCK_STYLES, v as TEXT_STYLES, z as POSITION_CHUNK_STYLES } from "./chunks/style-engine-D35rvcdB.js";
5
+ import { i as generateTypographyTokens } from "./chunks/config-engine-CGIMO2PV.js";
6
+ import { c as getGlobalFunctions, l as getGlobalKeyframes, o as getGlobalCounterStyles, s as getGlobalFontFaces } from "./chunks/runtime-state-C0u1jp-Q.js";
7
+ import { A as ownKeyframes, B as hasGlobalKeyframes, C as holdKeyframes, D as injector, E as injectRawCSS, F as configure, G as StyleInjector, H as isConfigLocked, I as getConfig, J as flushStyles, K as SheetManager, M as touch, N as ChunkSheetRegistry, O as isPropertyDefined, P as chunkSheetRegistry, R as getGlobalRecipes, S as getRawCSSText, T as injectGlobal, U as isTestEnvironment, V as hasGlobalRecipes, W as resetConfig, Y as hasPendingStyleWrites, Z as resetStyleBatch, _ as fontFace, a as filterBaseProps, b as getCSSText, g as destroy, h as createInjector, i as modAttrs, j as property, k as keyframes, m as counterStyle, o as computeStyles, p as cleanup, r as processTokens, s as resolveRecipes, v as func, w as inject, x as getCSSTextForNode, y as gc, z as getNamePrefix } from "./chunks/runtime-engine-CPYI2bA8.js";
8
+ import { t as tastyDebug } from "./chunks/debug-Dy36S1sU.js";
9
+ import "./core/index.js";
10
+ import { a as useProperty, c as useGlobalStyles, d as Element, f as tasty, i as useFontFace, l as useStyles, n as useFunction, o as useKeyframes, p as getDisplayName, r as useCounterStyle, s as useRawCSS, t as TastyBatchProvider } from "./chunks/react-runtime-BljxMd6C.js";
11
+ export { APPEARANCE_CHUNK_STYLES, BASE_STYLES, BLOCK_INNER_STYLES, BLOCK_OUTER_STYLES, BLOCK_STYLES, CHUNK_NAMES, COLOR_STYLES, CONTAINER_STYLES, CUSTOM_UNITS, ChunkSheetRegistry, DEFAULT_NAME_PREFIX, DEFAULT_ZERO_NAME_PREFIX, DIMENSION_CHUNK_STYLES, DIMENSION_STYLES, DIRECTIONS, DISPLAY_CHUNK_STYLES, Element, FLOW_STYLES, FONT_CHUNK_STYLES, INNER_STYLES, LAYOUT_CHUNK_STYLES, OUTER_STYLES, POSITION_CHUNK_STYLES, POSITION_STYLES, STYLE_TO_CHUNK, SheetManager, StyleInjector, StyleParser, TEXT_STYLES, TastyBatchProvider, categorizeStyleKeys, chunkSheetRegistry, cleanup, color, computeStyles, configure, counterStyle, createColorFunc, createInjector, createStateParserContext, defineHandler, destroy, filterBaseProps, filterMods, flushStyles, fontFace, func, gc, generateTypographyTokens, getCSSText, getCSSTextForNode, getConfig, getDisplayName, getGlobalCounterStyles, getGlobalFontFaces, getGlobalFunctions, getGlobalKeyframes, getGlobalParser, getGlobalPredefinedStates, getGlobalPredefinedTokens, getGlobalRecipes, getNamePrefix, getNamedColorHex, getRawCSSText, getRgbValuesFromRgbaString, hasGlobalKeyframes, hasGlobalRecipes, hasPendingStyleWrites, hasStylesGenerated, hexToRgb, holdKeyframes, hslToRgbValues, inject, injectGlobal, injectRawCSS, injector, isConfigLocked, isPropertyDefined, isSelector, isTestEnvironment, keyframes, mergeStyles, modAttrs, normalizeColorTokenValue, okhslFunction, okhslPlugin, okhstFunction, okhstPlugin, ownKeyframes, parseColor, parseStateKey, parseStyle, processTokens, property, renderStyles, resetConfig, resetStyleBatch, resolveFunctionColor, resolveRecipes, setGlobalPredefinedStates, strToRgb, stringifyStyles, styleHandlers, tasty, tastyDebug, touch, useCounterStyle, useFontFace, useFunction, useGlobalStyles, useKeyframes, useProperty, useRawCSS, useStyles };