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