@tenphi/tasty 2.0.3 → 2.0.4
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/{ssr/async-storage.js → async-storage-B7_o6FKt.js} +2 -2
- package/dist/async-storage-B7_o6FKt.js.map +1 -0
- package/dist/{ssr/collector.d.ts → collector-CkZ517g4.d.ts} +3 -3
- package/dist/{ssr/collector.js → collector-DXqvGOb1.js} +5 -10
- package/dist/collector-DXqvGOb1.js.map +1 -0
- package/dist/config-5jzS6k6B.js +10005 -0
- package/dist/config-5jzS6k6B.js.map +1 -0
- package/dist/config-DknGsfMo.d.ts +857 -0
- package/dist/{ssr/context.js → context-CkSg-kDT.js} +11 -3
- package/dist/context-CkSg-kDT.js.map +1 -0
- package/dist/core/index.d.ts +5 -34
- package/dist/core/index.js +5 -26
- package/dist/core-CtU6-9OC.js +1507 -0
- package/dist/core-CtU6-9OC.js.map +1 -0
- package/dist/{zero/extractor.js → css-writer-DHkX0JuE.js} +74 -11
- package/dist/css-writer-DHkX0JuE.js.map +1 -0
- package/dist/{ssr/format-global-rules.js → format-global-rules-Dbc_1tc3.js} +2 -2
- package/dist/format-global-rules-Dbc_1tc3.js.map +1 -0
- package/dist/format-rules-DH13ewDu.js +143 -0
- package/dist/format-rules-DH13ewDu.js.map +1 -0
- package/dist/{ssr/hydrate.js → hydrate-C1Gv-DoS.js} +3 -3
- package/dist/hydrate-C1Gv-DoS.js.map +1 -0
- package/dist/{styles/types.d.ts → index-PzENbpAq.d.ts} +701 -5
- package/dist/index-o7zV2yCr.d.ts +1561 -0
- package/dist/index.d.ts +5 -51
- package/dist/index.js +728 -35
- package/dist/index.js.map +1 -0
- package/dist/keyframes-b7X3UxDV.js +587 -0
- package/dist/keyframes-b7X3UxDV.js.map +1 -0
- package/dist/{utils/merge-styles.d.ts → merge-styles-C7KTy7MY.d.ts} +3 -3
- package/dist/{utils/merge-styles.js → merge-styles-Tgo3BbL2.js} +3 -4
- package/dist/merge-styles-Tgo3BbL2.js.map +1 -0
- package/dist/{utils/resolve-recipes.js → resolve-recipes-Ca2-5CxM.js} +4 -6
- package/dist/resolve-recipes-Ca2-5CxM.js.map +1 -0
- package/dist/ssr/astro-client.js +1 -1
- package/dist/ssr/astro.js +4 -4
- package/dist/ssr/index.d.ts +44 -4
- package/dist/ssr/index.js +4 -4
- package/dist/ssr/next.d.ts +1 -1
- package/dist/ssr/next.js +6 -6
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +91 -5
- package/dist/static/index.js +49 -3
- package/dist/static/index.js.map +1 -0
- package/dist/zero/babel.d.ts +1 -1
- package/dist/zero/babel.js +10 -6
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +67 -3
- package/dist/zero/index.js +1 -2
- package/package.json +3 -3
- package/dist/_virtual/_rolldown/runtime.js +0 -7
- package/dist/chunks/cacheKey.d.ts +0 -1
- package/dist/chunks/cacheKey.js +0 -77
- package/dist/chunks/cacheKey.js.map +0 -1
- package/dist/chunks/definitions.d.ts +0 -37
- package/dist/chunks/definitions.js +0 -258
- package/dist/chunks/definitions.js.map +0 -1
- package/dist/chunks/index.d.ts +0 -1
- package/dist/chunks/renderChunk.d.ts +0 -1
- package/dist/chunks/renderChunk.js +0 -59
- package/dist/chunks/renderChunk.js.map +0 -1
- package/dist/compute-styles.d.ts +0 -31
- package/dist/compute-styles.js +0 -322
- package/dist/compute-styles.js.map +0 -1
- package/dist/config.d.ts +0 -407
- package/dist/config.js +0 -591
- package/dist/config.js.map +0 -1
- package/dist/counter-style/index.js +0 -51
- package/dist/counter-style/index.js.map +0 -1
- package/dist/debug.d.ts +0 -89
- package/dist/debug.js +0 -453
- package/dist/debug.js.map +0 -1
- package/dist/font-face/index.js +0 -63
- package/dist/font-face/index.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -7
- package/dist/hooks/useCounterStyle.d.ts +0 -36
- package/dist/hooks/useCounterStyle.js +0 -65
- package/dist/hooks/useCounterStyle.js.map +0 -1
- package/dist/hooks/useFontFace.d.ts +0 -45
- package/dist/hooks/useFontFace.js +0 -66
- package/dist/hooks/useFontFace.js.map +0 -1
- package/dist/hooks/useGlobalStyles.d.ts +0 -46
- package/dist/hooks/useGlobalStyles.js +0 -88
- package/dist/hooks/useGlobalStyles.js.map +0 -1
- package/dist/hooks/useKeyframes.d.ts +0 -58
- package/dist/hooks/useKeyframes.js +0 -55
- package/dist/hooks/useKeyframes.js.map +0 -1
- package/dist/hooks/useProperty.d.ts +0 -81
- package/dist/hooks/useProperty.js +0 -96
- package/dist/hooks/useProperty.js.map +0 -1
- package/dist/hooks/useRawCSS.d.ts +0 -22
- package/dist/hooks/useRawCSS.js +0 -103
- package/dist/hooks/useRawCSS.js.map +0 -1
- package/dist/hooks/useStyles.d.ts +0 -40
- package/dist/hooks/useStyles.js +0 -31
- package/dist/hooks/useStyles.js.map +0 -1
- package/dist/injector/index.d.ts +0 -182
- package/dist/injector/index.js +0 -185
- package/dist/injector/index.js.map +0 -1
- package/dist/injector/injector.d.ts +0 -198
- package/dist/injector/injector.js +0 -651
- package/dist/injector/injector.js.map +0 -1
- package/dist/injector/sheet-manager.d.ts +0 -132
- package/dist/injector/sheet-manager.js +0 -699
- package/dist/injector/sheet-manager.js.map +0 -1
- package/dist/injector/types.d.ts +0 -235
- package/dist/keyframes/index.js +0 -206
- package/dist/keyframes/index.js.map +0 -1
- package/dist/parser/classify.js +0 -319
- package/dist/parser/classify.js.map +0 -1
- package/dist/parser/const.js +0 -60
- package/dist/parser/const.js.map +0 -1
- package/dist/parser/lru.js +0 -109
- package/dist/parser/lru.js.map +0 -1
- package/dist/parser/parser.d.ts +0 -25
- package/dist/parser/parser.js +0 -115
- package/dist/parser/parser.js.map +0 -1
- package/dist/parser/tokenizer.js +0 -69
- package/dist/parser/tokenizer.js.map +0 -1
- package/dist/parser/types.d.ts +0 -51
- package/dist/parser/types.js +0 -46
- package/dist/parser/types.js.map +0 -1
- package/dist/pipeline/conditions.d.ts +0 -134
- package/dist/pipeline/conditions.js +0 -406
- package/dist/pipeline/conditions.js.map +0 -1
- package/dist/pipeline/exclusive.js +0 -389
- package/dist/pipeline/exclusive.js.map +0 -1
- package/dist/pipeline/index.d.ts +0 -55
- package/dist/pipeline/index.js +0 -749
- package/dist/pipeline/index.js.map +0 -1
- package/dist/pipeline/materialize-contradictions.js +0 -125
- package/dist/pipeline/materialize-contradictions.js.map +0 -1
- package/dist/pipeline/materialize.js +0 -1038
- package/dist/pipeline/materialize.js.map +0 -1
- package/dist/pipeline/parseStateKey.d.ts +0 -15
- package/dist/pipeline/parseStateKey.js +0 -446
- package/dist/pipeline/parseStateKey.js.map +0 -1
- package/dist/pipeline/simplify.js +0 -725
- package/dist/pipeline/simplify.js.map +0 -1
- package/dist/pipeline/warnings.js +0 -18
- package/dist/pipeline/warnings.js.map +0 -1
- package/dist/plugins/index.d.ts +0 -2
- package/dist/plugins/okhsl-plugin.d.ts +0 -35
- package/dist/plugins/okhsl-plugin.js +0 -97
- package/dist/plugins/okhsl-plugin.js.map +0 -1
- package/dist/plugins/types.d.ts +0 -87
- package/dist/properties/index.js +0 -222
- package/dist/properties/index.js.map +0 -1
- package/dist/properties/property-type-resolver.d.ts +0 -24
- package/dist/properties/property-type-resolver.js +0 -90
- package/dist/properties/property-type-resolver.js.map +0 -1
- package/dist/rsc-cache.js +0 -79
- package/dist/rsc-cache.js.map +0 -1
- package/dist/ssr/async-storage.d.ts +0 -17
- package/dist/ssr/async-storage.js.map +0 -1
- package/dist/ssr/collect-auto-properties.js +0 -58
- package/dist/ssr/collect-auto-properties.js.map +0 -1
- package/dist/ssr/collector.js.map +0 -1
- package/dist/ssr/context.js.map +0 -1
- package/dist/ssr/format-global-rules.js.map +0 -1
- package/dist/ssr/format-keyframes.js +0 -69
- package/dist/ssr/format-keyframes.js.map +0 -1
- package/dist/ssr/format-property.js +0 -49
- package/dist/ssr/format-property.js.map +0 -1
- package/dist/ssr/format-rules.js +0 -73
- package/dist/ssr/format-rules.js.map +0 -1
- package/dist/ssr/hydrate.d.ts +0 -29
- package/dist/ssr/hydrate.js.map +0 -1
- package/dist/ssr/ssr-collector-ref.js +0 -29
- package/dist/ssr/ssr-collector-ref.js.map +0 -1
- package/dist/states/index.d.ts +0 -49
- package/dist/states/index.js +0 -170
- package/dist/states/index.js.map +0 -1
- package/dist/static/tastyStatic.d.ts +0 -46
- package/dist/static/tastyStatic.js +0 -30
- package/dist/static/tastyStatic.js.map +0 -1
- package/dist/static/types.d.ts +0 -49
- package/dist/static/types.js +0 -24
- package/dist/static/types.js.map +0 -1
- package/dist/styles/border.d.ts +0 -25
- package/dist/styles/border.js +0 -120
- package/dist/styles/border.js.map +0 -1
- package/dist/styles/color.d.ts +0 -14
- package/dist/styles/color.js +0 -26
- package/dist/styles/color.js.map +0 -1
- package/dist/styles/const.js +0 -17
- package/dist/styles/const.js.map +0 -1
- package/dist/styles/createStyle.js +0 -79
- package/dist/styles/createStyle.js.map +0 -1
- package/dist/styles/dimension.js +0 -109
- package/dist/styles/dimension.js.map +0 -1
- package/dist/styles/directional.js +0 -133
- package/dist/styles/directional.js.map +0 -1
- package/dist/styles/display.d.ts +0 -30
- package/dist/styles/display.js +0 -73
- package/dist/styles/display.js.map +0 -1
- package/dist/styles/fade.d.ts +0 -15
- package/dist/styles/fade.js +0 -62
- package/dist/styles/fade.js.map +0 -1
- package/dist/styles/fill.d.ts +0 -42
- package/dist/styles/fill.js +0 -51
- package/dist/styles/fill.js.map +0 -1
- package/dist/styles/flow.d.ts +0 -16
- package/dist/styles/flow.js +0 -12
- package/dist/styles/flow.js.map +0 -1
- package/dist/styles/gap.d.ts +0 -31
- package/dist/styles/gap.js +0 -38
- package/dist/styles/gap.js.map +0 -1
- package/dist/styles/height.d.ts +0 -17
- package/dist/styles/height.js +0 -19
- package/dist/styles/height.js.map +0 -1
- package/dist/styles/index.d.ts +0 -1
- package/dist/styles/index.js +0 -8
- package/dist/styles/index.js.map +0 -1
- package/dist/styles/inset.d.ts +0 -24
- package/dist/styles/inset.js +0 -34
- package/dist/styles/inset.js.map +0 -1
- package/dist/styles/list.d.ts +0 -16
- package/dist/styles/list.js +0 -100
- package/dist/styles/list.js.map +0 -1
- package/dist/styles/margin.d.ts +0 -24
- package/dist/styles/margin.js +0 -32
- package/dist/styles/margin.js.map +0 -1
- package/dist/styles/outline.d.ts +0 -29
- package/dist/styles/outline.js +0 -55
- package/dist/styles/outline.js.map +0 -1
- package/dist/styles/padding.d.ts +0 -24
- package/dist/styles/padding.js +0 -32
- package/dist/styles/padding.js.map +0 -1
- package/dist/styles/placement.d.ts +0 -37
- package/dist/styles/placement.js +0 -74
- package/dist/styles/placement.js.map +0 -1
- package/dist/styles/predefined.d.ts +0 -71
- package/dist/styles/predefined.js +0 -237
- package/dist/styles/predefined.js.map +0 -1
- package/dist/styles/preset.d.ts +0 -52
- package/dist/styles/preset.js +0 -127
- package/dist/styles/preset.js.map +0 -1
- package/dist/styles/radius.d.ts +0 -12
- package/dist/styles/radius.js +0 -83
- package/dist/styles/radius.js.map +0 -1
- package/dist/styles/scrollMargin.d.ts +0 -24
- package/dist/styles/scrollMargin.js +0 -32
- package/dist/styles/scrollMargin.js.map +0 -1
- package/dist/styles/scrollbar.d.ts +0 -25
- package/dist/styles/scrollbar.js +0 -51
- package/dist/styles/scrollbar.js.map +0 -1
- package/dist/styles/shadow.d.ts +0 -14
- package/dist/styles/shadow.js +0 -25
- package/dist/styles/shadow.js.map +0 -1
- package/dist/styles/shared.js +0 -17
- package/dist/styles/shared.js.map +0 -1
- package/dist/styles/transition.d.ts +0 -14
- package/dist/styles/transition.js +0 -159
- package/dist/styles/transition.js.map +0 -1
- package/dist/styles/width.d.ts +0 -17
- package/dist/styles/width.js +0 -19
- package/dist/styles/width.js.map +0 -1
- package/dist/tasty.d.ts +0 -134
- package/dist/tasty.js +0 -248
- package/dist/tasty.js.map +0 -1
- package/dist/types.d.ts +0 -184
- package/dist/utils/cache-wrapper.js +0 -21
- package/dist/utils/cache-wrapper.js.map +0 -1
- package/dist/utils/case-converter.js +0 -8
- package/dist/utils/case-converter.js.map +0 -1
- package/dist/utils/color-math.d.ts +0 -46
- package/dist/utils/color-math.js +0 -749
- package/dist/utils/color-math.js.map +0 -1
- package/dist/utils/color-space.d.ts +0 -5
- package/dist/utils/color-space.js +0 -228
- package/dist/utils/color-space.js.map +0 -1
- package/dist/utils/colors.d.ts +0 -5
- package/dist/utils/colors.js +0 -10
- package/dist/utils/colors.js.map +0 -1
- package/dist/utils/css-types.d.ts +0 -7
- package/dist/utils/deps-equal.js +0 -15
- package/dist/utils/deps-equal.js.map +0 -1
- package/dist/utils/dotize.d.ts +0 -26
- package/dist/utils/dotize.js +0 -122
- package/dist/utils/dotize.js.map +0 -1
- package/dist/utils/filter-base-props.d.ts +0 -15
- package/dist/utils/filter-base-props.js +0 -45
- package/dist/utils/filter-base-props.js.map +0 -1
- package/dist/utils/get-display-name.d.ts +0 -7
- package/dist/utils/get-display-name.js +0 -10
- package/dist/utils/get-display-name.js.map +0 -1
- package/dist/utils/has-keys.js +0 -13
- package/dist/utils/has-keys.js.map +0 -1
- package/dist/utils/hash.js +0 -14
- package/dist/utils/hash.js.map +0 -1
- package/dist/utils/is-dev-env.js +0 -19
- package/dist/utils/is-dev-env.js.map +0 -1
- package/dist/utils/is-valid-element-type.js +0 -15
- package/dist/utils/is-valid-element-type.js.map +0 -1
- package/dist/utils/merge-styles.js.map +0 -1
- package/dist/utils/mod-attrs.d.ts +0 -6
- package/dist/utils/mod-attrs.js +0 -20
- package/dist/utils/mod-attrs.js.map +0 -1
- package/dist/utils/process-tokens.d.ts +0 -17
- package/dist/utils/process-tokens.js +0 -83
- package/dist/utils/process-tokens.js.map +0 -1
- package/dist/utils/resolve-recipes.d.ts +0 -17
- package/dist/utils/resolve-recipes.js.map +0 -1
- package/dist/utils/selector-transform.js +0 -32
- package/dist/utils/selector-transform.js.map +0 -1
- package/dist/utils/string.js +0 -8
- package/dist/utils/string.js.map +0 -1
- package/dist/utils/styles.d.ts +0 -99
- package/dist/utils/styles.js +0 -220
- package/dist/utils/styles.js.map +0 -1
- package/dist/utils/typography.d.ts +0 -58
- package/dist/utils/typography.js +0 -51
- package/dist/utils/typography.js.map +0 -1
- package/dist/utils/warnings.d.ts +0 -16
- package/dist/utils/warnings.js +0 -16
- package/dist/utils/warnings.js.map +0 -1
- package/dist/zero/css-writer.d.ts +0 -45
- package/dist/zero/css-writer.js +0 -73
- package/dist/zero/css-writer.js.map +0 -1
- package/dist/zero/extractor.d.ts +0 -24
- package/dist/zero/extractor.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,36 +1,729 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
import { $ as parseStyle, B as deprecationWarning, D as getGlobalPredefinedStates, F as formatFontFaceRule, G as DIRECTIONS, J as getGlobalFuncs, K as customFunc, L as SheetManager, O as setGlobalPredefinedStates, P as fontFaceContentHash, Q as parseColor, S as parseStateKey, St as strToRgb, V as warn, W as CUSTOM_UNITS, X as getGlobalPredefinedTokens, Y as getGlobalParser, Z as normalizeColorTokenValue, _ as resetConfig, a as getGlobalCounterStyle, at as StyleParser, b as isSelector, bt as hexToRgb, c as getGlobalKeyframes, ct as hashString, d as hasGlobalKeyframes, et as resetGlobalPredefinedTokens, f as hasGlobalRecipes, h as isTestEnvironment, it as okhslPlugin, j as formatCounterStyleRule, k as StyleInjector, l as getGlobalRecipes, m as isConfigLocked, n as getConfig, nt as stringifyStyles, o as getGlobalFontFace, ot as Bucket, p as hasStylesGenerated, q as filterMods, rt as okhslFunc, s as getGlobalInjector, t as configure, tt as setGlobalPredefinedTokens, v as generateTypographyTokens, vt as getNamedColorHex, w as createStateParserContext, x as renderStyles, xt as hslToRgbValues, yt as getRgbValuesFromRgbaString, z as styleHandlers } from "./config-5jzS6k6B.js";
|
|
2
|
+
import { d as categorizeStyleKeys, l as CHUNK_NAMES, u as STYLE_TO_CHUNK } from "./keyframes-b7X3UxDV.js";
|
|
3
|
+
import { A as property, B as INNER_STYLES, C as getRawCSSText, D as injector, E as injectRawCSS, F as BLOCK_STYLES, H as POSITION_STYLES, I as COLOR_STYLES, L as CONTAINER_STYLES, M as BASE_STYLES, N as BLOCK_INNER_STYLES, O as isPropertyDefined, P as BLOCK_OUTER_STYLES, R as DIMENSION_STYLES, S as getIsTestEnvironment, T as injectGlobal, U as TEXT_STYLES, V as OUTER_STYLES, _ as destroy, a as color, b as getCssText, c as hasKeys, d as collectAutoInferredPropertiesRSC, f as getStyleTarget, g as createInjector, h as counterStyle, i as _modAttrs, j as touch, k as keyframes, l as formatKeyframesCSS, m as cleanup, n as processTokens, o as filterBaseProps, p as pushRSCCSS, r as dotize, s as computeStyles, t as tastyDebug, u as collectAutoInferredProperties, v as fontFace, w as inject, x as getCssTextForNode, y as gc, z as FLOW_STYLES } from "./core-CtU6-9OC.js";
|
|
4
|
+
import { n as formatPropertyCSS } from "./format-rules-DH13ewDu.js";
|
|
5
|
+
import { t as mergeStyles } from "./merge-styles-Tgo3BbL2.js";
|
|
6
|
+
import { t as resolveRecipes } from "./resolve-recipes-Ca2-5CxM.js";
|
|
7
|
+
import { t as getTastySSRContext } from "./context-CkSg-kDT.js";
|
|
8
|
+
import { t as formatGlobalRules } from "./format-global-rules-Dbc_1tc3.js";
|
|
9
|
+
import { Fragment, createElement, forwardRef, useContext } 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/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, ...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 propsToCheck = styleProps ? styleProps.concat(BASE_STYLES) : BASE_STYLES;
|
|
158
|
+
const modPropsKeys = modPropsDef ? Array.isArray(modPropsDef) ? modPropsDef : Object.keys(modPropsDef) : void 0;
|
|
159
|
+
const tokenPropsMapping = tokenPropsDef ? buildTokenPropsMapping(tokenPropsDef) : void 0;
|
|
160
|
+
const classNameCache = /* @__PURE__ */ new Map();
|
|
161
|
+
const _TastyComponent = forwardRef((allProps, ref) => {
|
|
162
|
+
const { as, styles: rawStyles, variant, mods, element, qa, qaVal, className: userClassName, tokens, style, ...otherProps } = allProps;
|
|
163
|
+
let styles = rawStyles;
|
|
164
|
+
let propStyles = null;
|
|
165
|
+
for (const prop of propsToCheck) {
|
|
166
|
+
const key = prop;
|
|
167
|
+
if (key in otherProps) {
|
|
168
|
+
if (!propStyles) propStyles = {};
|
|
169
|
+
const value = otherProps[key];
|
|
170
|
+
propStyles[key] = value;
|
|
171
|
+
delete otherProps[key];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (!styles || styles && !hasKeys(styles)) styles = void 0;
|
|
175
|
+
let propMods;
|
|
176
|
+
if (modPropsKeys) {
|
|
177
|
+
for (const key of modPropsKeys) if (key in otherProps) {
|
|
178
|
+
if (!propMods) propMods = {};
|
|
179
|
+
propMods[key] = otherProps[key];
|
|
180
|
+
delete otherProps[key];
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
let propTokens;
|
|
184
|
+
if (tokenPropsMapping) {
|
|
185
|
+
for (const [propName, tokenKey] of tokenPropsMapping) if (propName in otherProps) {
|
|
186
|
+
if (!propTokens) propTokens = {};
|
|
187
|
+
propTokens[tokenKey] = otherProps[propName];
|
|
188
|
+
delete otherProps[propName];
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const baseStyles = variantStylesMap ? variantStylesMap[variant || "default"] ?? variantStylesMap["default"] : defaultStyles;
|
|
192
|
+
const hasInstanceStyles = styles && hasKeys(styles);
|
|
193
|
+
const hasPropStyles = propStyles && hasKeys(propStyles);
|
|
194
|
+
const allStyles = hasInstanceStyles || hasPropStyles ? mergeStyles(baseStyles, styles, propStyles) : baseStyles;
|
|
195
|
+
const useFactoryCache = typeof document !== "undefined";
|
|
196
|
+
let stylesResult;
|
|
197
|
+
if (useFactoryCache && allStyles === baseStyles && classNameCache.has(allStyles)) {
|
|
198
|
+
stylesResult = { className: classNameCache.get(allStyles) };
|
|
199
|
+
touch(stylesResult.className);
|
|
200
|
+
} else {
|
|
201
|
+
stylesResult = computeStyles(allStyles);
|
|
202
|
+
if (useFactoryCache && allStyles === baseStyles) classNameCache.set(allStyles, stylesResult.className);
|
|
203
|
+
}
|
|
204
|
+
let mergedTokens;
|
|
205
|
+
if (defaultTokens || tokens || propTokens) if (!defaultTokens && !propTokens) mergedTokens = tokens;
|
|
206
|
+
else if (!tokens && !propTokens) mergedTokens = defaultTokens;
|
|
207
|
+
else mergedTokens = {
|
|
208
|
+
...defaultTokens,
|
|
209
|
+
...tokens,
|
|
210
|
+
...propTokens
|
|
211
|
+
};
|
|
212
|
+
const processedTokenStyle = processTokens(mergedTokens);
|
|
213
|
+
let mergedStyle;
|
|
214
|
+
if (processedTokenStyle || style) if (!processedTokenStyle) mergedStyle = style;
|
|
215
|
+
else if (!style) mergedStyle = processedTokenStyle;
|
|
216
|
+
else mergedStyle = {
|
|
217
|
+
...processedTokenStyle,
|
|
218
|
+
...style
|
|
219
|
+
};
|
|
220
|
+
const mergedMods = propMods ? {
|
|
221
|
+
...mods,
|
|
222
|
+
...propMods
|
|
223
|
+
} : mods;
|
|
224
|
+
let modDataAttrs;
|
|
225
|
+
if (mergedMods) modDataAttrs = _modAttrs(mergedMods);
|
|
226
|
+
const finalClassName = [userClassName || "", stylesResult.className].filter(Boolean).join(" ");
|
|
227
|
+
const elementProps = {
|
|
228
|
+
"data-element": element || defaultElement,
|
|
229
|
+
"data-qa": qa || defaultQa,
|
|
230
|
+
"data-qaval": qaVal || defaultQaVal,
|
|
231
|
+
...otherDefaultProps,
|
|
232
|
+
...modDataAttrs || {},
|
|
233
|
+
...otherProps,
|
|
234
|
+
className: finalClassName,
|
|
235
|
+
style: mergedStyle,
|
|
236
|
+
ref
|
|
237
|
+
};
|
|
238
|
+
handleIsProperties(elementProps);
|
|
239
|
+
const el = createElement(as ?? originalAs, elementProps);
|
|
240
|
+
if (stylesResult.css) {
|
|
241
|
+
const nonce = getConfig().nonce;
|
|
242
|
+
return createElement(Fragment, null, createElement("style", {
|
|
243
|
+
"data-tasty-rsc": "",
|
|
244
|
+
nonce,
|
|
245
|
+
dangerouslySetInnerHTML: { __html: stylesResult.css }
|
|
246
|
+
}), el);
|
|
247
|
+
}
|
|
248
|
+
return el;
|
|
249
|
+
});
|
|
250
|
+
_TastyComponent.displayName = `TastyComponent(${defaultProps.qa || originalAs})`;
|
|
251
|
+
if (elements) {
|
|
252
|
+
const subElements = Object.entries(elements).reduce((acc, [name, definition]) => {
|
|
253
|
+
acc[name] = createSubElement(name, definition);
|
|
254
|
+
return acc;
|
|
255
|
+
}, {});
|
|
256
|
+
return Object.assign(_TastyComponent, subElements);
|
|
257
|
+
}
|
|
258
|
+
return _TastyComponent;
|
|
259
|
+
}
|
|
260
|
+
const Element = tasty({});
|
|
261
|
+
//#endregion
|
|
262
|
+
//#region src/hooks/useStyles.ts
|
|
263
|
+
/**
|
|
264
|
+
* Hook to generate CSS classes from Tasty styles.
|
|
265
|
+
* Thin wrapper around `computeStyles()` that adds React context-based
|
|
266
|
+
* SSR collector discovery for backward compatibility with TastyRegistry.
|
|
267
|
+
*
|
|
268
|
+
* For hook-free usage (e.g. in server components), use `computeStyles()` directly.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```tsx
|
|
272
|
+
* function MyComponent() {
|
|
273
|
+
* const { className } = useStyles({
|
|
274
|
+
* padding: '2x',
|
|
275
|
+
* fill: '#purple',
|
|
276
|
+
* radius: '1r',
|
|
277
|
+
* });
|
|
278
|
+
*
|
|
279
|
+
* return <div className={className}>Styled content</div>;
|
|
280
|
+
* }
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
function useStyles(styles) {
|
|
284
|
+
return computeStyles(styles, { ssrCollector: useContext(getTastySSRContext()) });
|
|
285
|
+
}
|
|
286
|
+
//#endregion
|
|
287
|
+
//#region src/hooks/useGlobalStyles.ts
|
|
288
|
+
const clientGlobalEntries = /* @__PURE__ */ new Map();
|
|
289
|
+
/**
|
|
290
|
+
* Inject global styles for a given selector.
|
|
291
|
+
* Useful for styling elements by selector without generating classNames.
|
|
292
|
+
*
|
|
293
|
+
* SSR-aware: when a ServerStyleCollector is available, CSS is collected
|
|
294
|
+
* during the render phase instead of being injected into the DOM.
|
|
295
|
+
*
|
|
296
|
+
* Works in all environments: client, SSR with collector, and React Server Components.
|
|
297
|
+
*
|
|
298
|
+
* Injected styles are permanent — they are not cleaned up on component unmount.
|
|
299
|
+
* Use the `id` option for update tracking when styles change over the
|
|
300
|
+
* component lifecycle.
|
|
301
|
+
*
|
|
302
|
+
* @param selector - CSS selector to apply styles to (e.g., '.my-class', ':root', 'body')
|
|
303
|
+
* @param styles - Tasty styles object
|
|
304
|
+
* @param options - Optional settings including `id` for update tracking
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```tsx
|
|
308
|
+
* function MyComponent() {
|
|
309
|
+
* useGlobalStyles('.card', {
|
|
310
|
+
* padding: '2x',
|
|
311
|
+
* radius: '1r',
|
|
312
|
+
* fill: '#white',
|
|
313
|
+
* });
|
|
314
|
+
*
|
|
315
|
+
* return <div className="card">Content</div>;
|
|
316
|
+
* }
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
function useGlobalStyles(selector, styles, options) {
|
|
320
|
+
if (!styles) return;
|
|
321
|
+
if (!selector) {
|
|
322
|
+
console.warn("[Tasty] useGlobalStyles: selector is required and cannot be empty. Styles will not be injected.");
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
const target = getStyleTarget();
|
|
326
|
+
if (target.mode === "client") {
|
|
327
|
+
const slotKey = options?.id ?? selector;
|
|
328
|
+
const stylesKey = JSON.stringify(styles);
|
|
329
|
+
const existing = clientGlobalEntries.get(slotKey);
|
|
330
|
+
if (existing && existing.stylesKey === stylesKey) return;
|
|
331
|
+
}
|
|
332
|
+
const resolvedStyles = resolveRecipes(styles);
|
|
333
|
+
const styleResults = renderStyles(resolvedStyles, selector);
|
|
334
|
+
if (styleResults.length === 0) return;
|
|
335
|
+
if (target.mode === "ssr") {
|
|
336
|
+
target.collector.collectInternals();
|
|
337
|
+
const css = formatGlobalRules(styleResults);
|
|
338
|
+
if (css) {
|
|
339
|
+
const key = options?.id ? `global:${options.id}` : `global:${selector}:${hashString(css)}`;
|
|
340
|
+
target.collector.collectGlobalStyles(key, css);
|
|
341
|
+
}
|
|
342
|
+
if (getConfig().autoPropertyTypes !== false) collectAutoInferredProperties(styleResults, target.collector, resolvedStyles);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (target.mode === "rsc") {
|
|
346
|
+
const css = formatGlobalRules(styleResults);
|
|
347
|
+
if (css) {
|
|
348
|
+
const key = options?.id ? `__global:${options.id}` : `__global:${selector}:${hashString(css)}`;
|
|
349
|
+
pushRSCCSS(target.cache, key, css);
|
|
350
|
+
}
|
|
351
|
+
if (getConfig().autoPropertyTypes !== false) collectAutoInferredPropertiesRSC(styleResults, target.cache, resolvedStyles);
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
const slotKey = options?.id ?? selector;
|
|
355
|
+
const existing = clientGlobalEntries.get(slotKey);
|
|
356
|
+
if (existing) existing.dispose();
|
|
357
|
+
const { dispose } = injectGlobal(styleResults);
|
|
358
|
+
clientGlobalEntries.set(slotKey, {
|
|
359
|
+
stylesKey: JSON.stringify(styles),
|
|
360
|
+
dispose
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
//#endregion
|
|
364
|
+
//#region src/utils/deps-equal.ts
|
|
365
|
+
/**
|
|
366
|
+
* Shallow comparison of two dependency arrays using Object.is semantics.
|
|
367
|
+
* Returns true when both arrays have the same length and every element
|
|
368
|
+
* at the same index is identical.
|
|
369
|
+
*/
|
|
370
|
+
function depsEqual(a, b) {
|
|
371
|
+
if (a.length !== b.length) return false;
|
|
372
|
+
for (let i = 0; i < a.length; i++) if (!Object.is(a[i], b[i])) return false;
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/hooks/useRawCSS.ts
|
|
377
|
+
const clientEntries = /* @__PURE__ */ new Map();
|
|
378
|
+
const clientContentDedup = /* @__PURE__ */ new Set();
|
|
379
|
+
const factoryDepsCache$1 = /* @__PURE__ */ new Map();
|
|
380
|
+
/**
|
|
381
|
+
* Inject raw CSS text directly without parsing.
|
|
382
|
+
* This is a low-overhead alternative for injecting global CSS that doesn't need tasty processing.
|
|
383
|
+
*
|
|
384
|
+
* The CSS is inserted into a separate style element (data-tasty-raw) to avoid conflicts
|
|
385
|
+
* with tasty's chunked style sheets.
|
|
386
|
+
*
|
|
387
|
+
* Works in all environments: client, SSR with collector, and React Server Components.
|
|
388
|
+
*
|
|
389
|
+
* Injected styles are permanent — they are not cleaned up on component unmount.
|
|
390
|
+
* Use the `id` option for update tracking when styles change over the
|
|
391
|
+
* component lifecycle.
|
|
392
|
+
*
|
|
393
|
+
* @example Static CSS string
|
|
394
|
+
* ```tsx
|
|
395
|
+
* function GlobalStyles() {
|
|
396
|
+
* useRawCSS(`
|
|
397
|
+
* body {
|
|
398
|
+
* margin: 0;
|
|
399
|
+
* padding: 0;
|
|
400
|
+
* font-family: sans-serif;
|
|
401
|
+
* }
|
|
402
|
+
* `);
|
|
403
|
+
*
|
|
404
|
+
* return null;
|
|
405
|
+
* }
|
|
406
|
+
* ```
|
|
407
|
+
*
|
|
408
|
+
* @example Factory function with dependencies
|
|
409
|
+
* ```tsx
|
|
410
|
+
* function ThemeStyles({ theme }: { theme: 'light' | 'dark' }) {
|
|
411
|
+
* useRawCSS(() => `
|
|
412
|
+
* :root {
|
|
413
|
+
* --bg-color: ${theme === 'dark' ? '#1a1a1a' : '#ffffff'};
|
|
414
|
+
* --text-color: ${theme === 'dark' ? '#ffffff' : '#1a1a1a'};
|
|
415
|
+
* }
|
|
416
|
+
* `, [theme], { id: 'theme-vars' });
|
|
417
|
+
*
|
|
418
|
+
* return null;
|
|
419
|
+
* }
|
|
420
|
+
* ```
|
|
421
|
+
*
|
|
422
|
+
* @example With options
|
|
423
|
+
* ```tsx
|
|
424
|
+
* function ShadowStyles({ shadowRoot }) {
|
|
425
|
+
* useRawCSS(() => `.scoped { color: red; }`, [], { root: shadowRoot });
|
|
426
|
+
* return null;
|
|
427
|
+
* }
|
|
428
|
+
* ```
|
|
429
|
+
*/
|
|
430
|
+
function useRawCSS(cssOrFactory, depsOrOptions, options) {
|
|
431
|
+
const isFactory = typeof cssOrFactory === "function";
|
|
432
|
+
const deps = isFactory && Array.isArray(depsOrOptions) ? depsOrOptions : void 0;
|
|
433
|
+
const opts = isFactory ? options : depsOrOptions;
|
|
434
|
+
const target = getStyleTarget();
|
|
435
|
+
if (isFactory && deps && opts?.id && target.mode === "client") {
|
|
436
|
+
const cachedDeps = factoryDepsCache$1.get(opts.id);
|
|
437
|
+
if (cachedDeps && depsEqual(cachedDeps, deps)) return;
|
|
438
|
+
}
|
|
439
|
+
const css = isFactory ? cssOrFactory() : cssOrFactory;
|
|
440
|
+
if (!css.trim()) return;
|
|
441
|
+
if (target.mode === "ssr") {
|
|
442
|
+
const key = opts?.id ? `raw:${opts.id}` : `raw:${hashString(css)}`;
|
|
443
|
+
target.collector.collectRawCSS(key, css);
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
if (target.mode === "rsc") {
|
|
447
|
+
const key = opts?.id ? `__raw:${opts.id}` : `__raw:${hashString(css)}`;
|
|
448
|
+
pushRSCCSS(target.cache, key, css);
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
const id = opts?.id;
|
|
452
|
+
if (id) {
|
|
453
|
+
const existing = clientEntries.get(id);
|
|
454
|
+
if (existing) {
|
|
455
|
+
if (existing.contentKey === css) return;
|
|
456
|
+
existing.dispose();
|
|
457
|
+
}
|
|
458
|
+
const { dispose } = injectRawCSS(css, opts);
|
|
459
|
+
clientEntries.set(id, {
|
|
460
|
+
contentKey: css,
|
|
461
|
+
dispose
|
|
462
|
+
});
|
|
463
|
+
if (deps) factoryDepsCache$1.set(id, deps);
|
|
464
|
+
} else {
|
|
465
|
+
const contentKey = hashString(css);
|
|
466
|
+
if (clientContentDedup.has(contentKey)) return;
|
|
467
|
+
clientContentDedup.add(contentKey);
|
|
468
|
+
injectRawCSS(css, opts);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
//#endregion
|
|
472
|
+
//#region src/hooks/useKeyframes.ts
|
|
473
|
+
const clientContentToName$1 = /* @__PURE__ */ new Map();
|
|
474
|
+
const factoryDepsCache = /* @__PURE__ */ new Map();
|
|
475
|
+
function useKeyframes(stepsOrFactory, depsOrOptions, options) {
|
|
476
|
+
const isFactory = typeof stepsOrFactory === "function";
|
|
477
|
+
const deps = isFactory && Array.isArray(depsOrOptions) ? depsOrOptions : void 0;
|
|
478
|
+
const opts = isFactory ? options : depsOrOptions;
|
|
479
|
+
const target = getStyleTarget();
|
|
480
|
+
if (isFactory && deps && opts?.name && target.mode === "client") {
|
|
481
|
+
const cached = factoryDepsCache.get(opts.name);
|
|
482
|
+
if (cached && depsEqual(cached.deps, deps)) return cached.name;
|
|
483
|
+
}
|
|
484
|
+
const steps = isFactory ? stepsOrFactory() : stepsOrFactory;
|
|
485
|
+
if (!steps || Object.keys(steps).length === 0) return "";
|
|
486
|
+
if (target.mode === "ssr") {
|
|
487
|
+
const actualName = target.collector.allocateKeyframeName(opts?.name);
|
|
488
|
+
const css = formatKeyframesCSS(actualName, steps);
|
|
489
|
+
target.collector.collectKeyframes(actualName, css);
|
|
490
|
+
return actualName;
|
|
491
|
+
}
|
|
492
|
+
if (target.mode === "rsc") {
|
|
493
|
+
const serializedContent = JSON.stringify(steps);
|
|
494
|
+
const key = `__kf:${opts?.name ?? ""}:${serializedContent}`;
|
|
495
|
+
const existingName = target.cache.generatedNames.get(key);
|
|
496
|
+
if (existingName) return existingName;
|
|
497
|
+
const actualName = opts?.name ?? `k${hashString(serializedContent)}`;
|
|
498
|
+
const css = formatKeyframesCSS(actualName, steps);
|
|
499
|
+
pushRSCCSS(target.cache, key, css);
|
|
500
|
+
target.cache.generatedNames.set(key, actualName);
|
|
501
|
+
return actualName;
|
|
502
|
+
}
|
|
503
|
+
const serializedContent = JSON.stringify(steps);
|
|
504
|
+
const cacheKey = `${opts?.name ?? ""}:${serializedContent}`;
|
|
505
|
+
const cachedName = clientContentToName$1.get(cacheKey);
|
|
506
|
+
if (cachedName) return cachedName;
|
|
507
|
+
const name = keyframes(steps, {
|
|
508
|
+
name: opts?.name,
|
|
509
|
+
root: opts?.root
|
|
510
|
+
}).toString();
|
|
511
|
+
clientContentToName$1.set(cacheKey, name);
|
|
512
|
+
if (deps && opts?.name) factoryDepsCache.set(opts.name, {
|
|
513
|
+
deps,
|
|
514
|
+
name
|
|
515
|
+
});
|
|
516
|
+
return name;
|
|
517
|
+
}
|
|
518
|
+
//#endregion
|
|
519
|
+
//#region src/hooks/useProperty.ts
|
|
520
|
+
/**
|
|
521
|
+
* Register a CSS @property custom property.
|
|
522
|
+
* This enables advanced features like animating custom properties.
|
|
523
|
+
*
|
|
524
|
+
* Note: @property rules are global and persistent once defined.
|
|
525
|
+
* The function ensures the property is only registered once per root.
|
|
526
|
+
*
|
|
527
|
+
* Accepts tasty token syntax for the property name:
|
|
528
|
+
* - `$name` → defines `--name`
|
|
529
|
+
* - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')
|
|
530
|
+
* - `--name` → defines `--name` (legacy format)
|
|
531
|
+
*
|
|
532
|
+
* Works in all environments: client, SSR with collector, and React Server Components.
|
|
533
|
+
*
|
|
534
|
+
* @param name - The property token ($name, #name) or CSS property name (--name)
|
|
535
|
+
* @param options - Property configuration
|
|
536
|
+
*
|
|
537
|
+
* @example Basic property with token syntax
|
|
538
|
+
* ```tsx
|
|
539
|
+
* function Spinner() {
|
|
540
|
+
* useProperty('$rotation', {
|
|
541
|
+
* syntax: '<angle>',
|
|
542
|
+
* inherits: false,
|
|
543
|
+
* initialValue: '0deg',
|
|
544
|
+
* });
|
|
545
|
+
*
|
|
546
|
+
* return <div className="spinner" />;
|
|
547
|
+
* }
|
|
548
|
+
* ```
|
|
549
|
+
*
|
|
550
|
+
* @example Color property with token syntax (auto-sets syntax)
|
|
551
|
+
* ```tsx
|
|
552
|
+
* function MyComponent() {
|
|
553
|
+
* useProperty('#theme', {
|
|
554
|
+
* initialValue: 'red', // syntax: '<color>' is auto-set
|
|
555
|
+
* });
|
|
556
|
+
*
|
|
557
|
+
* // Now --theme-color can be animated with CSS transitions
|
|
558
|
+
* return <div style={{ '--theme-color': 'blue' } as React.CSSProperties}>Colored</div>;
|
|
559
|
+
* }
|
|
560
|
+
* ```
|
|
561
|
+
*
|
|
562
|
+
* @example Legacy format (still supported)
|
|
563
|
+
* ```tsx
|
|
564
|
+
* function ResizableBox() {
|
|
565
|
+
* useProperty('--box-size', {
|
|
566
|
+
* syntax: '<length>',
|
|
567
|
+
* initialValue: '100px',
|
|
568
|
+
* });
|
|
569
|
+
*
|
|
570
|
+
* return <div style={{ width: 'var(--box-size)' }} />;
|
|
571
|
+
* }
|
|
572
|
+
* ```
|
|
573
|
+
*/
|
|
574
|
+
function useProperty(name, options) {
|
|
575
|
+
if (!name) {
|
|
576
|
+
console.warn(`[Tasty] useProperty: property name is required`);
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
const target = getStyleTarget();
|
|
580
|
+
if (target.mode === "ssr") {
|
|
581
|
+
target.collector.collectInternals();
|
|
582
|
+
const css = formatPropertyCSS(name, {
|
|
583
|
+
syntax: options?.syntax,
|
|
584
|
+
inherits: options?.inherits,
|
|
585
|
+
initialValue: options?.initialValue
|
|
586
|
+
});
|
|
587
|
+
if (css) target.collector.collectProperty(name, css);
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
if (target.mode === "rsc") {
|
|
591
|
+
const css = formatPropertyCSS(name, {
|
|
592
|
+
syntax: options?.syntax,
|
|
593
|
+
inherits: options?.inherits,
|
|
594
|
+
initialValue: options?.initialValue
|
|
595
|
+
});
|
|
596
|
+
if (css) pushRSCCSS(target.cache, `__prop:${name}`, css);
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
const injector = getGlobalInjector();
|
|
600
|
+
if (injector.isPropertyDefined(name, { root: options?.root })) return;
|
|
601
|
+
injector.property(name, {
|
|
602
|
+
syntax: options?.syntax,
|
|
603
|
+
inherits: options?.inherits,
|
|
604
|
+
initialValue: options?.initialValue,
|
|
605
|
+
root: options?.root
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
//#endregion
|
|
609
|
+
//#region src/hooks/useFontFace.ts
|
|
610
|
+
/**
|
|
611
|
+
* Inject CSS @font-face rules.
|
|
612
|
+
* Permanent — no cleanup on unmount. Deduplicates by content hash.
|
|
613
|
+
*
|
|
614
|
+
* Works in all environments: client, SSR with collector, and React Server Components.
|
|
615
|
+
*
|
|
616
|
+
* @param family - The font-family name
|
|
617
|
+
* @param input - Single descriptor object or array of descriptors (for multiple weights/styles)
|
|
618
|
+
* @param options - Optional settings (e.g. Shadow DOM root)
|
|
619
|
+
*
|
|
620
|
+
* @example Single weight
|
|
621
|
+
* ```tsx
|
|
622
|
+
* function App() {
|
|
623
|
+
* useFontFace('Brand Sans', {
|
|
624
|
+
* src: 'url("/fonts/brand-sans.woff2") format("woff2")',
|
|
625
|
+
* fontWeight: '400 700',
|
|
626
|
+
* fontDisplay: 'swap',
|
|
627
|
+
* });
|
|
628
|
+
*
|
|
629
|
+
* return <div style={{ fontFamily: '"Brand Sans", sans-serif' }}>Hello</div>;
|
|
630
|
+
* }
|
|
631
|
+
* ```
|
|
632
|
+
*
|
|
633
|
+
* @example Multiple weights
|
|
634
|
+
* ```tsx
|
|
635
|
+
* function App() {
|
|
636
|
+
* useFontFace('Brand Sans', [
|
|
637
|
+
* { src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
|
|
638
|
+
* { src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
|
|
639
|
+
* ]);
|
|
640
|
+
*
|
|
641
|
+
* return <div style={{ fontFamily: '"Brand Sans", sans-serif' }}>Hello</div>;
|
|
642
|
+
* }
|
|
643
|
+
* ```
|
|
644
|
+
*/
|
|
645
|
+
function useFontFace(family, input, options) {
|
|
646
|
+
if (!family) return;
|
|
647
|
+
const descriptors = Array.isArray(input) ? input : [input];
|
|
648
|
+
const target = getStyleTarget();
|
|
649
|
+
if (target.mode === "ssr") {
|
|
650
|
+
for (const desc of descriptors) {
|
|
651
|
+
const hash = fontFaceContentHash(family, desc);
|
|
652
|
+
const css = formatFontFaceRule(family, desc);
|
|
653
|
+
target.collector.collectFontFace(hash, css);
|
|
654
|
+
}
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
if (target.mode === "rsc") {
|
|
658
|
+
for (const desc of descriptors) {
|
|
659
|
+
const hash = fontFaceContentHash(family, desc);
|
|
660
|
+
const css = formatFontFaceRule(family, desc);
|
|
661
|
+
pushRSCCSS(target.cache, `__ff:${hash}`, css);
|
|
662
|
+
}
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
const injector = getGlobalInjector();
|
|
666
|
+
for (const desc of descriptors) injector.fontFace(family, desc, { root: options?.root });
|
|
667
|
+
}
|
|
668
|
+
//#endregion
|
|
669
|
+
//#region src/hooks/useCounterStyle.ts
|
|
670
|
+
let clientCounterStyleCounter = 0;
|
|
671
|
+
const clientContentToName = /* @__PURE__ */ new Map();
|
|
672
|
+
/**
|
|
673
|
+
* Inject a CSS @counter-style rule and return the generated name.
|
|
674
|
+
* Permanent — no cleanup on unmount. Deduplicates by name.
|
|
675
|
+
*
|
|
676
|
+
* Works in all environments: client, SSR with collector, and React Server Components.
|
|
677
|
+
*
|
|
678
|
+
* @example Basic usage
|
|
679
|
+
* ```tsx
|
|
680
|
+
* function EmojiList() {
|
|
681
|
+
* const styleName = useCounterStyle({
|
|
682
|
+
* system: 'cyclic',
|
|
683
|
+
* symbols: '"👍"',
|
|
684
|
+
* suffix: '" "',
|
|
685
|
+
* }, { name: 'thumbs' });
|
|
686
|
+
*
|
|
687
|
+
* return (
|
|
688
|
+
* <ol style={{ listStyleType: styleName }}>
|
|
689
|
+
* <li>First</li>
|
|
690
|
+
* <li>Second</li>
|
|
691
|
+
* </ol>
|
|
692
|
+
* );
|
|
693
|
+
* }
|
|
694
|
+
* ```
|
|
695
|
+
*
|
|
696
|
+
*/
|
|
697
|
+
function useCounterStyle(descriptors, options) {
|
|
698
|
+
if (!descriptors || !descriptors.system) return "";
|
|
699
|
+
const target = getStyleTarget();
|
|
700
|
+
if (target.mode === "ssr") {
|
|
701
|
+
const actualName = target.collector.allocateCounterStyleName(options?.name);
|
|
702
|
+
const css = formatCounterStyleRule(actualName, descriptors);
|
|
703
|
+
target.collector.collectCounterStyle(actualName, css);
|
|
704
|
+
return actualName;
|
|
705
|
+
}
|
|
706
|
+
if (target.mode === "rsc") {
|
|
707
|
+
const serializedContent = JSON.stringify(descriptors);
|
|
708
|
+
const key = `__cs:${options?.name ?? ""}:${serializedContent}`;
|
|
709
|
+
const existingName = target.cache.generatedNames.get(key);
|
|
710
|
+
if (existingName) return existingName;
|
|
711
|
+
const actualName = options?.name ?? `cs${hashString(serializedContent)}`;
|
|
712
|
+
const css = formatCounterStyleRule(actualName, descriptors);
|
|
713
|
+
pushRSCCSS(target.cache, key, css);
|
|
714
|
+
target.cache.generatedNames.set(key, actualName);
|
|
715
|
+
return actualName;
|
|
716
|
+
}
|
|
717
|
+
const serializedContent = JSON.stringify(descriptors);
|
|
718
|
+
const cacheKey = `${options?.name ?? ""}:${serializedContent}`;
|
|
719
|
+
const existingName = clientContentToName.get(cacheKey);
|
|
720
|
+
if (existingName) return existingName;
|
|
721
|
+
const name = options?.name ?? `cs${clientCounterStyleCounter++}`;
|
|
722
|
+
clientContentToName.set(cacheKey, name);
|
|
723
|
+
getGlobalInjector().counterStyle(name, descriptors, { root: options?.root });
|
|
724
|
+
return name;
|
|
725
|
+
}
|
|
726
|
+
//#endregion
|
|
36
727
|
export { BASE_STYLES, BLOCK_INNER_STYLES, BLOCK_OUTER_STYLES, BLOCK_STYLES, Bucket, CHUNK_NAMES, COLOR_STYLES, CONTAINER_STYLES, CUSTOM_UNITS, DIMENSION_STYLES, DIRECTIONS, Element, FLOW_STYLES, INNER_STYLES, OUTER_STYLES, POSITION_STYLES, STYLE_TO_CHUNK, SheetManager, StyleInjector, StyleParser, TEXT_STYLES, categorizeStyleKeys, cleanup, color, computeStyles, configure, counterStyle, createInjector, createStateParserContext, customFunc, deprecationWarning, destroy, dotize, filterBaseProps, filterMods, fontFace, gc, generateTypographyTokens, getConfig, getCssText, getCssTextForNode, getDisplayName, getGlobalCounterStyle, getGlobalFontFace, getGlobalFuncs, getGlobalKeyframes, getGlobalParser, getGlobalPredefinedStates, getGlobalPredefinedTokens, getGlobalRecipes, getIsTestEnvironment, getNamedColorHex, getRawCSSText, getRgbValuesFromRgbaString, hasGlobalKeyframes, hasGlobalRecipes, hasStylesGenerated, hexToRgb, hslToRgbValues, inject, injectGlobal, injectRawCSS, injector, isConfigLocked, isPropertyDefined, isSelector, isTestEnvironment, keyframes, mergeStyles, _modAttrs as modAttrs, normalizeColorTokenValue, okhslFunc, okhslPlugin, parseColor, parseStateKey, parseStyle, processTokens, property, renderStyles, resetConfig, resetGlobalPredefinedTokens, resolveRecipes, setGlobalPredefinedStates, setGlobalPredefinedTokens, strToRgb, stringifyStyles, styleHandlers, tasty, tastyDebug, touch, useCounterStyle, useFontFace, useGlobalStyles, useKeyframes, useProperty, useRawCSS, useStyles, warn };
|
|
728
|
+
|
|
729
|
+
//# sourceMappingURL=index.js.map
|