@tamagui/web 1.88.13 → 1.89.0-1706308641099
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/LICENSE +21 -0
- package/dist/cjs/createComponent.js +1 -1
- package/dist/cjs/createComponent.js.map +1 -1
- package/dist/cjs/helpers/getSplitStyles.js +1 -1
- package/dist/cjs/helpers/getSplitStyles.js.map +1 -1
- package/dist/cjs/helpers/getSplitStyles.native.js +1 -1
- package/dist/cjs/helpers/getSplitStyles.native.js.map +1 -1
- package/dist/esm/Tamagui.mjs +43 -0
- package/dist/esm/config.mjs +51 -0
- package/dist/esm/constants/accessibilityDirectMap.mjs +50 -0
- package/dist/esm/constants/constants.mjs +16 -0
- package/dist/esm/constants/isDevTools.mjs +7 -0
- package/dist/esm/contexts/ComponentContext.mjs +13 -0
- package/dist/esm/createComponent.js +1 -1
- package/dist/esm/createComponent.js.map +1 -1
- package/dist/esm/createComponent.mjs +771 -0
- package/dist/esm/createFont.mjs +18 -0
- package/dist/esm/createShorthands.mjs +4 -0
- package/dist/esm/createTamagui.mjs +206 -0
- package/dist/esm/createTheme.mjs +2 -0
- package/dist/esm/createTokens.mjs +5 -0
- package/dist/esm/createVariable.mjs +48 -0
- package/dist/esm/createVariables.mjs +35 -0
- package/dist/esm/defaultComponentState.mjs +16 -0
- package/dist/esm/helpers/ThemeManager.mjs +156 -0
- package/dist/esm/helpers/ThemeManagerContext.mjs +3 -0
- package/dist/esm/helpers/createMediaStyle.mjs +71 -0
- package/dist/esm/helpers/createShallowSetState.mjs +17 -0
- package/dist/esm/helpers/createStyledContext.mjs +35 -0
- package/dist/esm/helpers/defaultOffset.mjs +5 -0
- package/dist/esm/helpers/expandStyle.mjs +38 -0
- package/dist/esm/helpers/expandStyles.mjs +15 -0
- package/dist/esm/helpers/getExpandedShorthands.mjs +9 -0
- package/dist/esm/helpers/getFontLanguage.mjs +2 -0
- package/dist/esm/helpers/getGroupPropParts.mjs +13 -0
- package/dist/esm/helpers/getSplitStyles.js +1 -1
- package/dist/esm/helpers/getSplitStyles.js.map +1 -1
- package/dist/esm/helpers/getSplitStyles.mjs +643 -0
- package/dist/esm/helpers/getSplitStyles.native.js +1 -1
- package/dist/esm/helpers/getSplitStyles.native.js.map +1 -1
- package/dist/esm/helpers/getStylesAtomic.mjs +150 -0
- package/dist/esm/helpers/getThemeCSSRules.mjs +87 -0
- package/dist/esm/helpers/getVariantExtras.mjs +43 -0
- package/dist/esm/helpers/insertStyleRule.mjs +177 -0
- package/dist/esm/helpers/isObj.mjs +2 -0
- package/dist/esm/helpers/isTamaguiComponent.mjs +5 -0
- package/dist/esm/helpers/isTamaguiElement.mjs +4 -0
- package/dist/esm/helpers/log.mjs +4 -0
- package/dist/esm/helpers/matchMedia.mjs +11 -0
- package/dist/esm/helpers/mergeProps.mjs +21 -0
- package/dist/esm/helpers/mergeVariants.mjs +16 -0
- package/dist/esm/helpers/normalizeColor.mjs +17 -0
- package/dist/esm/helpers/normalizeShadow.mjs +23 -0
- package/dist/esm/helpers/normalizeStyle.mjs +23 -0
- package/dist/esm/helpers/normalizeStylePropKeys.mjs +2 -0
- package/dist/esm/helpers/normalizeValueWithProperty.mjs +32 -0
- package/dist/esm/helpers/objectIdentityKey.mjs +15 -0
- package/dist/esm/helpers/propMapper.mjs +239 -0
- package/dist/esm/helpers/proxyThemeToParents.mjs +36 -0
- package/dist/esm/helpers/proxyThemeVariables.mjs +12 -0
- package/dist/esm/helpers/pseudoDescriptors.mjs +34 -0
- package/dist/esm/helpers/registerCSSVariable.mjs +7 -0
- package/dist/esm/helpers/themeable.mjs +33 -0
- package/dist/esm/helpers/themes.mjs +14 -0
- package/dist/esm/helpers/timer.mjs +8 -0
- package/dist/esm/hooks/useConfiguration.mjs +20 -0
- package/dist/esm/hooks/useDisableSSR.mjs +5 -0
- package/dist/esm/hooks/useIsTouchDevice.mjs +4 -0
- package/dist/esm/hooks/useMedia.mjs +146 -0
- package/dist/esm/hooks/useProps.mjs +40 -0
- package/dist/esm/hooks/useTheme.mjs +222 -0
- package/dist/esm/hooks/useThemeName.mjs +15 -0
- package/dist/esm/index.mjs +61 -0
- package/dist/esm/inject-styles.mjs +13 -0
- package/dist/esm/insertFont.mjs +44 -0
- package/dist/esm/interfaces/CSSColorNames.mjs +0 -0
- package/dist/esm/interfaces/GetRef.mjs +0 -0
- package/dist/esm/interfaces/KeyTypes.mjs +0 -0
- package/dist/esm/interfaces/RNExclusiveTypes.mjs +0 -0
- package/dist/esm/interfaces/Role.mjs +0 -0
- package/dist/esm/interfaces/TamaguiComponentEvents.mjs +0 -0
- package/dist/esm/interfaces/TamaguiComponentPropsBaseBase.mjs +0 -0
- package/dist/esm/interfaces/TamaguiComponentState.mjs +0 -0
- package/dist/esm/interfaces/WebOnlyPressEvents.mjs +0 -0
- package/dist/esm/internalWithTheme.mjs +14 -0
- package/dist/esm/setupHooks.mjs +5 -0
- package/dist/esm/setupReactNative.mjs +24 -0
- package/dist/esm/styled.mjs +56 -0
- package/dist/esm/type-utils.mjs +0 -0
- package/dist/esm/types.mjs +2 -0
- package/dist/esm/views/Configuration.mjs +12 -0
- package/dist/esm/views/FontLanguage.mjs +13 -0
- package/dist/esm/views/FontLanguage.types.mjs +0 -0
- package/dist/esm/views/Slot.mjs +53 -0
- package/dist/esm/views/Stack.mjs +10 -0
- package/dist/esm/views/TamaguiProvider.mjs +32 -0
- package/dist/esm/views/Text.mjs +64 -0
- package/dist/esm/views/Theme.mjs +104 -0
- package/dist/esm/views/ThemeDebug.mjs +57 -0
- package/dist/esm/views/ThemeProvider.mjs +20 -0
- package/dist/esm/views/View.mjs +9 -0
- package/package.json +10 -10
- package/src/createComponent.tsx +1 -1
- package/src/helpers/getSplitStyles.tsx +5 -0
- package/types/helpers/getSplitStyles.d.ts.map +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { expandStyle } from "./expandStyle.mjs";
|
|
2
|
+
import { fixStyles } from "./expandStyles.mjs";
|
|
3
|
+
import { isObj } from "./isObj.mjs";
|
|
4
|
+
import { normalizeValueWithProperty } from "./normalizeValueWithProperty.mjs";
|
|
5
|
+
import { pseudoDescriptors } from "./pseudoDescriptors.mjs";
|
|
6
|
+
function normalizeStyle(style, disableNormalize = !1) {
|
|
7
|
+
const res = {};
|
|
8
|
+
for (let key in style) {
|
|
9
|
+
const prop = style[key];
|
|
10
|
+
if (prop == null) continue;
|
|
11
|
+
if (key in pseudoDescriptors ||
|
|
12
|
+
// this should capture all parent-based styles like media, group, etc
|
|
13
|
+
key[0] === "$" && isObj(prop)) {
|
|
14
|
+
res[key] = normalizeStyle(prop, disableNormalize);
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const value = disableNormalize ? prop : normalizeValueWithProperty(prop, key),
|
|
18
|
+
out = expandStyle(key, value);
|
|
19
|
+
out ? Object.assign(res, Object.fromEntries(out)) : res[key] = value;
|
|
20
|
+
}
|
|
21
|
+
return fixStyles(res), res;
|
|
22
|
+
}
|
|
23
|
+
export { normalizeStyle };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { isWeb } from "@tamagui/constants";
|
|
2
|
+
import { stylePropsAll, stylePropsUnitless } from "@tamagui/helpers";
|
|
3
|
+
import { getAllSelectors } from "./insertStyleRule.mjs";
|
|
4
|
+
const stylePropsAllPlusTransforms = {
|
|
5
|
+
...stylePropsAll,
|
|
6
|
+
translateX: !0,
|
|
7
|
+
translateY: !0
|
|
8
|
+
};
|
|
9
|
+
function normalizeValueWithProperty(value, property = "") {
|
|
10
|
+
if (!isWeb || stylePropsUnitless[property] || property && !stylePropsAllPlusTransforms[property] || typeof value == "boolean") return value;
|
|
11
|
+
let res = value;
|
|
12
|
+
return value && typeof value == "object" ? value : (typeof value == "number" ? res = `${value}px` : property && (res = `${res}`), res);
|
|
13
|
+
}
|
|
14
|
+
const rcache = {};
|
|
15
|
+
function reverseMapClassNameToValue(key, className) {
|
|
16
|
+
const cssRule = getAllSelectors()[className];
|
|
17
|
+
if (rcache[cssRule]) return rcache[cssRule];
|
|
18
|
+
if (!cssRule) {
|
|
19
|
+
process.env.NODE_ENV === "development" && console.warn(`No CSS rule found for ${key} looking for selector ".${className}", you may not be injecting extracted CSS`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const cssVal = cssRule.replace(/.*:/, "").replace(/;.*/, "").trim();
|
|
23
|
+
let res;
|
|
24
|
+
return cssVal.startsWith("var(") ? res = cssVal : stylePropsUnitless[key] ? res = +cssVal : cssVal.endsWith("px") ? res = +cssVal.replace("px", "") : res = cssVal, rcache[cssRule] = res, process.env.NODE_ENV === "development" && typeof res == "number" && Number.isNaN(res) && console.info("Tamagui invalid parsed value, NaN:", {
|
|
25
|
+
res,
|
|
26
|
+
cssVal,
|
|
27
|
+
cssRule,
|
|
28
|
+
key,
|
|
29
|
+
className
|
|
30
|
+
}), res;
|
|
31
|
+
}
|
|
32
|
+
export { normalizeValueWithProperty, reverseMapClassNameToValue };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function objectIdentityKey(obj) {
|
|
2
|
+
let k = "";
|
|
3
|
+
for (const key in obj) {
|
|
4
|
+
k += key;
|
|
5
|
+
const arg = obj[key];
|
|
6
|
+
let type = typeof arg;
|
|
7
|
+
if (!arg || type !== "object" && type !== "function") k += type + arg;else if (cache.has(arg)) k += cache.get(arg);else {
|
|
8
|
+
let v = Math.random();
|
|
9
|
+
cache.set(arg, v), k += v;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return k;
|
|
13
|
+
}
|
|
14
|
+
const cache = /* @__PURE__ */new WeakMap();
|
|
15
|
+
export { objectIdentityKey };
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import "@tamagui/constants";
|
|
2
|
+
import { tokenCategories } from "@tamagui/helpers";
|
|
3
|
+
import { getConfig } from "../config.mjs";
|
|
4
|
+
import { isDevTools } from "../constants/isDevTools.mjs";
|
|
5
|
+
import { getVariableValue, isVariable } from "../createVariable.mjs";
|
|
6
|
+
import { expandStyle } from "./expandStyle.mjs";
|
|
7
|
+
import { normalizeStyle } from "./normalizeStyle.mjs";
|
|
8
|
+
import { getFontsForLanguage, getVariantExtras } from "./getVariantExtras.mjs";
|
|
9
|
+
import { isObj } from "./isObj.mjs";
|
|
10
|
+
import { pseudoDescriptors } from "./pseudoDescriptors.mjs";
|
|
11
|
+
const propMapper = (key, value, styleStateIn, subPropsIn) => {
|
|
12
|
+
if (lastFontFamilyToken = null, key === "elevationAndroid") return;
|
|
13
|
+
if (value === "unset") {
|
|
14
|
+
const unsetVal = styleStateIn.conf.unset?.[key];
|
|
15
|
+
if (unsetVal != null) value = unsetVal;else return;
|
|
16
|
+
}
|
|
17
|
+
const subProps = styleStateIn.styleProps.fallbackProps || subPropsIn,
|
|
18
|
+
styleState = subProps ? new Proxy(styleStateIn, {
|
|
19
|
+
get(_, k) {
|
|
20
|
+
return k === "curProps" ? subProps : Reflect.get(_, k);
|
|
21
|
+
}
|
|
22
|
+
}) : styleStateIn,
|
|
23
|
+
{
|
|
24
|
+
conf,
|
|
25
|
+
styleProps,
|
|
26
|
+
fontFamily,
|
|
27
|
+
staticConfig
|
|
28
|
+
} = styleState,
|
|
29
|
+
{
|
|
30
|
+
variants
|
|
31
|
+
} = staticConfig;
|
|
32
|
+
if (process.env.NODE_ENV === "development" && fontFamily && fontFamily[0] === "$" && !(fontFamily in conf.fontsParsed) && console.warn(`Warning: no fontFamily "${fontFamily}" found in config: ${Object.keys(conf.fontsParsed).join(", ")}`), !styleProps.noExpand && variants && key in variants) {
|
|
33
|
+
styleState.curProps[key] = value;
|
|
34
|
+
const variantValue = resolveVariants(key, value, styleProps, styleState, "");
|
|
35
|
+
if (variantValue) return variantValue;
|
|
36
|
+
}
|
|
37
|
+
let shouldReturn = !1;
|
|
38
|
+
if (styleProps.disableExpandShorthands || key in conf.shorthands && (shouldReturn = !0, key = conf.shorthands[key]), value && (value[0] === "$" ? value = getTokenForKey(key, value, styleProps.resolveValues, styleState) : isVariable(value) && (value = resolveVariableValue(key, value, styleProps.resolveValues))), shouldReturn || value != null) {
|
|
39
|
+
const result = (styleProps.noExpand ? null : expandStyle(key, value)) || [[key, value]];
|
|
40
|
+
return key === "fontFamily" && lastFontFamilyToken && fontFamilyCache.set(result, lastFontFamilyToken), result;
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
resolveVariants = (key, value, styleProps, styleState, parentVariantKey) => {
|
|
44
|
+
const {
|
|
45
|
+
staticConfig,
|
|
46
|
+
conf,
|
|
47
|
+
debug
|
|
48
|
+
} = styleState,
|
|
49
|
+
{
|
|
50
|
+
variants
|
|
51
|
+
} = staticConfig;
|
|
52
|
+
if (!variants) return;
|
|
53
|
+
let variantValue = getVariantDefinition(variants[key], value, conf);
|
|
54
|
+
if (process.env.NODE_ENV === "development" && debug === "verbose" && (console.groupCollapsed(`\u2666\uFE0F\u2666\uFE0F\u2666\uFE0F resolve variant ${key}`), console.info({
|
|
55
|
+
key,
|
|
56
|
+
value,
|
|
57
|
+
variantValue,
|
|
58
|
+
variants,
|
|
59
|
+
curProps: {
|
|
60
|
+
...styleState.curProps
|
|
61
|
+
}
|
|
62
|
+
}), console.groupEnd()), !variantValue) {
|
|
63
|
+
if (process.env.TAMAGUI_WARN_ON_MISSING_VARIANT === "1" && typeof value != "boolean") {
|
|
64
|
+
const name = staticConfig.componentName || "[UnnamedComponent]";
|
|
65
|
+
console.warn(`No variant found: ${name} has variant "${key}", but no matching value "${value}"`);
|
|
66
|
+
}
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (typeof variantValue == "function") {
|
|
70
|
+
const fn = variantValue,
|
|
71
|
+
extras = getVariantExtras(styleState);
|
|
72
|
+
variantValue = fn(value, extras), process.env.NODE_ENV === "development" && debug === "verbose" && (console.groupCollapsed(" expanded functional variant", key), console.info({
|
|
73
|
+
fn,
|
|
74
|
+
variantValue,
|
|
75
|
+
extras
|
|
76
|
+
}), console.groupEnd());
|
|
77
|
+
}
|
|
78
|
+
let fontFamilyResult;
|
|
79
|
+
if (isObj(variantValue)) {
|
|
80
|
+
const fontFamilyUpdate = variantValue.fontFamily || variantValue[conf.inverseShorthands.fontFamily];
|
|
81
|
+
fontFamilyUpdate && (fontFamilyResult = getFontFamilyFromNameOrVariable(fontFamilyUpdate, conf), styleState.fontFamily = fontFamilyResult, process.env.NODE_ENV === "development" && debug === "verbose" && console.info(" updating font family", fontFamilyResult)), variantValue = resolveTokensAndVariants(key, variantValue, styleProps, styleState, parentVariantKey);
|
|
82
|
+
}
|
|
83
|
+
if (variantValue) {
|
|
84
|
+
const expanded = normalizeStyle(variantValue, !!styleProps.noNormalize);
|
|
85
|
+
process.env.NODE_ENV === "development" && debug === "verbose" && console.info(" expanding styles from ", variantValue, "to", expanded);
|
|
86
|
+
const next = Object.entries(expanded);
|
|
87
|
+
return fontFamilyResult && fontFamilyResult[0] === "$" && fontFamilyCache.set(next, getVariableValue(fontFamilyResult)), next;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
function getFontFamilyFromNameOrVariable(input, conf) {
|
|
91
|
+
if (isVariable(input)) {
|
|
92
|
+
const val = variableToFontNameCache.get(input);
|
|
93
|
+
if (val) return val;
|
|
94
|
+
for (const key in conf.fontsParsed) {
|
|
95
|
+
const familyVariable = conf.fontsParsed[key].family;
|
|
96
|
+
if (isVariable(familyVariable) && (variableToFontNameCache.set(familyVariable, key), familyVariable === input)) return key;
|
|
97
|
+
}
|
|
98
|
+
} else if (typeof input == "string" && input[0] === "$") return input;
|
|
99
|
+
}
|
|
100
|
+
const variableToFontNameCache = /* @__PURE__ */new WeakMap(),
|
|
101
|
+
fontFamilyCache = /* @__PURE__ */new WeakMap(),
|
|
102
|
+
getPropMappedFontFamily = expanded => expanded && fontFamilyCache.get(expanded),
|
|
103
|
+
resolveTokensAndVariants = (key, value, styleProps, styleState, parentVariantKey) => {
|
|
104
|
+
const {
|
|
105
|
+
conf,
|
|
106
|
+
staticConfig,
|
|
107
|
+
debug,
|
|
108
|
+
theme
|
|
109
|
+
} = styleState,
|
|
110
|
+
{
|
|
111
|
+
variants
|
|
112
|
+
} = staticConfig,
|
|
113
|
+
res = {};
|
|
114
|
+
process.env.NODE_ENV === "development" && debug === "verbose" && console.info(" - resolveTokensAndVariants", key, value);
|
|
115
|
+
for (const _key in value) {
|
|
116
|
+
const subKey = conf.shorthands[_key] || _key,
|
|
117
|
+
val = value[_key];
|
|
118
|
+
if (styleProps.noExpand) res[subKey] = val;else if (variants && subKey in variants) {
|
|
119
|
+
if (styleState.curProps[subKey] = val, parentVariantKey && parentVariantKey === key) res[subKey] =
|
|
120
|
+
// SYNC WITH *1
|
|
121
|
+
val[0] === "$" ? getTokenForKey(subKey, val, styleProps.resolveValues, styleState) : val;else {
|
|
122
|
+
const variantOut = resolveVariants(subKey, val, styleProps, styleState, key);
|
|
123
|
+
if (variantOut) for (const [key2, val2] of variantOut) val2 != null && (key2 in pseudoDescriptors ? (res[key2] ??= {}, Object.assign(res[key2], val2)) : res[key2] = val2);
|
|
124
|
+
}
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (isVariable(val)) {
|
|
128
|
+
res[subKey] = resolveVariableValue(subKey, val, styleProps.resolveValues), process.env.NODE_ENV === "development" && debug === "verbose" && console.info("variable", subKey, res[subKey]);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (typeof val == "string") {
|
|
132
|
+
const fVal =
|
|
133
|
+
// SYNC WITH *1
|
|
134
|
+
val[0] === "$" ? getTokenForKey(subKey, val, styleProps.resolveValues, styleState) : val;
|
|
135
|
+
res[subKey] = fVal;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (isObj(val)) {
|
|
139
|
+
const subObject = resolveTokensAndVariants(subKey, val, styleProps, styleState, key);
|
|
140
|
+
process.env.NODE_ENV === "development" && debug === "verbose" && console.info("object", subKey, subObject), res[subKey] ??= {}, Object.assign(res[subKey], subObject);
|
|
141
|
+
} else res[subKey] = val;
|
|
142
|
+
process.env.NODE_ENV === "development" && debug && res[subKey]?.[0] === "$" && console.warn(`\u26A0\uFE0F Missing token in theme ${theme.name}:`, subKey, res[subKey], theme);
|
|
143
|
+
}
|
|
144
|
+
return res;
|
|
145
|
+
},
|
|
146
|
+
tokenCats = ["size", "color", "radius", "space", "zIndex"].map(name => ({
|
|
147
|
+
name,
|
|
148
|
+
spreadName: `...${name}`
|
|
149
|
+
}));
|
|
150
|
+
function getVariantDefinition(variant, value, conf) {
|
|
151
|
+
if (typeof variant == "function") return variant;
|
|
152
|
+
const exact = variant[value];
|
|
153
|
+
if (exact) return exact;
|
|
154
|
+
if (value != null) {
|
|
155
|
+
const {
|
|
156
|
+
tokensParsed
|
|
157
|
+
} = conf;
|
|
158
|
+
for (const {
|
|
159
|
+
name,
|
|
160
|
+
spreadName
|
|
161
|
+
} of tokenCats) if (spreadName in variant && value in tokensParsed[name]) return variant[spreadName];
|
|
162
|
+
const fontSizeVariant = variant["...fontSize"];
|
|
163
|
+
if (fontSizeVariant && conf.fontSizeTokens.has(value)) return fontSizeVariant;
|
|
164
|
+
}
|
|
165
|
+
return variant[`:${typeof value}`] || variant["..."];
|
|
166
|
+
}
|
|
167
|
+
const fontShorthand = {
|
|
168
|
+
fontSize: "size",
|
|
169
|
+
fontWeight: "weight"
|
|
170
|
+
};
|
|
171
|
+
let lastFontFamilyToken = null;
|
|
172
|
+
const getTokenForKey = (key, value, resolveAs = "none", styleState) => {
|
|
173
|
+
if (resolveAs === "none") return value;
|
|
174
|
+
const {
|
|
175
|
+
theme,
|
|
176
|
+
conf = getConfig(),
|
|
177
|
+
context,
|
|
178
|
+
fontFamily,
|
|
179
|
+
staticConfig
|
|
180
|
+
} = styleState,
|
|
181
|
+
tokensParsed = conf.tokensParsed;
|
|
182
|
+
let valOrVar,
|
|
183
|
+
hasSet = !1;
|
|
184
|
+
if (theme && value in theme) valOrVar = theme[value], process.env.NODE_ENV === "development" && styleState.debug === "verbose" && console.info(` - resolving ${key} to theme value ${value}: ${valOrVar?.get?.()}`), hasSet = !0;else if (value in conf.specificTokens) hasSet = !0, valOrVar = conf.specificTokens[value];else {
|
|
185
|
+
const customTokenAccept = staticConfig?.acceptTokens?.[key];
|
|
186
|
+
if (customTokenAccept) {
|
|
187
|
+
const val = tokensParsed[customTokenAccept][value];
|
|
188
|
+
val && (valOrVar = val, hasSet = !0);
|
|
189
|
+
} else {
|
|
190
|
+
switch (key) {
|
|
191
|
+
case "fontFamily":
|
|
192
|
+
{
|
|
193
|
+
valOrVar = (context?.language ? getFontsForLanguage(conf.fontsParsed, context.language) : conf.fontsParsed)[value]?.family || value, lastFontFamilyToken = value, hasSet = !0;
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
case "fontSize":
|
|
197
|
+
case "lineHeight":
|
|
198
|
+
case "letterSpacing":
|
|
199
|
+
case "fontWeight":
|
|
200
|
+
{
|
|
201
|
+
const defaultFont = conf.defaultFont || "$body",
|
|
202
|
+
fam = fontFamily || defaultFont;
|
|
203
|
+
if (fam) {
|
|
204
|
+
const fontsParsed = context?.language ? getFontsForLanguage(conf.fontsParsed, context.language) : conf.fontsParsed;
|
|
205
|
+
valOrVar = (fontsParsed[fam] || fontsParsed[defaultFont])?.[fontShorthand[key] || key]?.[value] || value, hasSet = !0;
|
|
206
|
+
}
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
for (const cat in tokenCategories) if (key in tokenCategories[cat]) {
|
|
211
|
+
const res = tokensParsed[cat][value];
|
|
212
|
+
res != null && (valOrVar = res, hasSet = !0);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (!hasSet) {
|
|
216
|
+
const spaceVar = tokensParsed.space[value];
|
|
217
|
+
spaceVar != null && (valOrVar = spaceVar, hasSet = !0);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (hasSet) {
|
|
221
|
+
const out = resolveVariableValue(key, valOrVar, resolveAs);
|
|
222
|
+
return process.env.NODE_ENV === "development" && styleState.debug === "verbose" && console.info("resolved", resolveAs, valOrVar, out), out;
|
|
223
|
+
}
|
|
224
|
+
return process.env.NODE_ENV === "development" && isDevTools && styleState.debug === "verbose" && (console.groupCollapsed(" \uFE52 propMap (val)", key, value), console.info({
|
|
225
|
+
valOrVar,
|
|
226
|
+
theme,
|
|
227
|
+
hasSet
|
|
228
|
+
}, theme ? theme[key] : ""), console.groupEnd()), value;
|
|
229
|
+
};
|
|
230
|
+
function resolveVariableValue(key, valOrVar, resolveValues) {
|
|
231
|
+
if (resolveValues === "none") return valOrVar;
|
|
232
|
+
if (isVariable(valOrVar)) {
|
|
233
|
+
if (resolveValues === "value") return valOrVar.val;
|
|
234
|
+
const get = valOrVar?.get;
|
|
235
|
+
return typeof get == "function" ? get(resolveValues === "web" ? "web" : void 0) : valOrVar.variable;
|
|
236
|
+
}
|
|
237
|
+
return valOrVar;
|
|
238
|
+
}
|
|
239
|
+
export { getFontFamilyFromNameOrVariable, getPropMappedFontFamily, getTokenForKey, propMapper };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getTokenObject } from "../config.mjs";
|
|
2
|
+
const themesRaw = {};
|
|
3
|
+
function proxyThemesToParents(dedupedThemes) {
|
|
4
|
+
for (const {
|
|
5
|
+
names,
|
|
6
|
+
theme
|
|
7
|
+
} of dedupedThemes) for (const name of names) themesRaw[name] = theme;
|
|
8
|
+
const themes = {};
|
|
9
|
+
for (const {
|
|
10
|
+
names,
|
|
11
|
+
theme
|
|
12
|
+
} of dedupedThemes) for (const themeName of names) {
|
|
13
|
+
const proxiedTheme = proxyThemeToParents(themeName, theme);
|
|
14
|
+
themes[themeName] = proxiedTheme;
|
|
15
|
+
}
|
|
16
|
+
return themes;
|
|
17
|
+
}
|
|
18
|
+
function proxyThemeToParents(themeName, theme) {
|
|
19
|
+
const cur = [],
|
|
20
|
+
parents = themeName.split("_").slice(0, -1).map(part => (cur.push(part), cur.join("_"))),
|
|
21
|
+
numParents = parents.length;
|
|
22
|
+
return new Proxy(theme, {
|
|
23
|
+
get(target, key) {
|
|
24
|
+
if (!key ||
|
|
25
|
+
// dont ask me, idk why but on hermes you can see that useTheme()[undefined] passes in STRING undefined to proxy
|
|
26
|
+
// if someone is crazy enough to use "undefined" as a theme key then this not working is on them
|
|
27
|
+
key == "undefined" || Reflect.has(target, key)) return Reflect.get(target, key);
|
|
28
|
+
for (let i = numParents - 1; i >= 0; i--) {
|
|
29
|
+
const parent = themesRaw[parents[i]];
|
|
30
|
+
if (parent && Reflect.has(parent, key)) return Reflect.get(parent, key);
|
|
31
|
+
}
|
|
32
|
+
return getTokenObject(key);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export { proxyThemeToParents, proxyThemesToParents };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function proxyThemeVariables(obj) {
|
|
2
|
+
return new Proxy(obj || {}, {
|
|
3
|
+
has(target, key) {
|
|
4
|
+
return Reflect.has(target, removeStarting$(key));
|
|
5
|
+
},
|
|
6
|
+
get(target, key) {
|
|
7
|
+
return Reflect.get(target, removeStarting$(key));
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
const removeStarting$ = str => typeof str == "string" && str[0] === "$" ? str.slice(1) : str;
|
|
12
|
+
export { proxyThemeVariables };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const pseudoDescriptorsBase = {
|
|
2
|
+
// order of keys here important! in priority order
|
|
3
|
+
hoverStyle: {
|
|
4
|
+
name: "hover",
|
|
5
|
+
priority: 1
|
|
6
|
+
},
|
|
7
|
+
pressStyle: {
|
|
8
|
+
name: "active",
|
|
9
|
+
stateKey: "press",
|
|
10
|
+
priority: 2
|
|
11
|
+
},
|
|
12
|
+
focusStyle: {
|
|
13
|
+
name: "focus",
|
|
14
|
+
priority: 3
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
pseudoPriorities = {
|
|
18
|
+
hover: 1,
|
|
19
|
+
press: 2,
|
|
20
|
+
focus: 3
|
|
21
|
+
},
|
|
22
|
+
pseudoDescriptors = {
|
|
23
|
+
...pseudoDescriptorsBase,
|
|
24
|
+
enterStyle: {
|
|
25
|
+
name: "enter",
|
|
26
|
+
selector: ".t_unmounted",
|
|
27
|
+
priority: 4
|
|
28
|
+
},
|
|
29
|
+
exitStyle: {
|
|
30
|
+
name: "exit",
|
|
31
|
+
priority: 5
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
export { pseudoDescriptors, pseudoDescriptorsBase, pseudoPriorities };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createCSSVariable, getVariableValue } from "../createVariable.mjs";
|
|
2
|
+
const registerCSSVariable = v => {
|
|
3
|
+
tokensValueToVariable.set(getVariableValue(v), v);
|
|
4
|
+
},
|
|
5
|
+
variableToCSS = (v, unitless = !1) => `--${createCSSVariable(v.name, !1)}:${!unitless && typeof v.val == "number" ? `${v.val}px` : v.val}`,
|
|
6
|
+
tokensValueToVariable = /* @__PURE__ */new Map();
|
|
7
|
+
export { registerCSSVariable, tokensValueToVariable, variableToCSS };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { forwardRef } from "react";
|
|
2
|
+
import { Theme } from "../views/Theme.mjs";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
function themeable(Component, staticConfig) {
|
|
5
|
+
const withTheme = forwardRef(function (props, ref) {
|
|
6
|
+
const {
|
|
7
|
+
themeInverse,
|
|
8
|
+
theme,
|
|
9
|
+
componentName,
|
|
10
|
+
themeReset,
|
|
11
|
+
...rest
|
|
12
|
+
} = props,
|
|
13
|
+
element =
|
|
14
|
+
// @ts-expect-error its ok
|
|
15
|
+
/* @__PURE__ */
|
|
16
|
+
jsx(Component, {
|
|
17
|
+
ref,
|
|
18
|
+
...rest,
|
|
19
|
+
"data-disable-theme": !0
|
|
20
|
+
});
|
|
21
|
+
return /* @__PURE__ */jsx(Theme, {
|
|
22
|
+
componentName: componentName || staticConfig?.componentName,
|
|
23
|
+
name: theme,
|
|
24
|
+
"disable-child-theme": !0,
|
|
25
|
+
debug: props.debug,
|
|
26
|
+
inverse: themeInverse,
|
|
27
|
+
reset: themeReset,
|
|
28
|
+
children: element
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
return withTheme.displayName = `Themed(${Component?.displayName || Component?.name || "Anonymous"})`, withTheme;
|
|
32
|
+
}
|
|
33
|
+
export { themeable };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createVariable, isVariable } from "../createVariable.mjs";
|
|
2
|
+
function ensureThemeVariable(theme, key) {
|
|
3
|
+
const val = theme[key];
|
|
4
|
+
isVariable(val) ? val.name !== key && (theme[key] = createVariable({
|
|
5
|
+
key: val.name,
|
|
6
|
+
name: key,
|
|
7
|
+
val: val.val
|
|
8
|
+
})) : theme[key] = createVariable({
|
|
9
|
+
key,
|
|
10
|
+
name: key,
|
|
11
|
+
val
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export { ensureThemeVariable };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { getConfig } from "../config.mjs";
|
|
3
|
+
import { ComponentContext } from "../contexts/ComponentContext.mjs";
|
|
4
|
+
const useConfiguration = () => {
|
|
5
|
+
const {
|
|
6
|
+
groups,
|
|
7
|
+
animationDriver,
|
|
8
|
+
...restComponentConfig
|
|
9
|
+
} = useContext(ComponentContext),
|
|
10
|
+
{
|
|
11
|
+
animations,
|
|
12
|
+
...restConfig
|
|
13
|
+
} = getConfig();
|
|
14
|
+
return {
|
|
15
|
+
...restConfig,
|
|
16
|
+
...restComponentConfig,
|
|
17
|
+
animationDriver: animationDriver ?? getConfig().animations
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export { useConfiguration };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { isServer, isWeb } from "@tamagui/constants";
|
|
2
|
+
import { useRef, useSyncExternalStore } from "react";
|
|
3
|
+
import { getConfig } from "../config.mjs";
|
|
4
|
+
import { matchMedia } from "../helpers/matchMedia.mjs";
|
|
5
|
+
import { pseudoDescriptors } from "../helpers/pseudoDescriptors.mjs";
|
|
6
|
+
import { getDisableSSR } from "./useDisableSSR.mjs";
|
|
7
|
+
let mediaState =
|
|
8
|
+
// development only safeguard
|
|
9
|
+
process.env.NODE_ENV === "development" ? new Proxy({}, {
|
|
10
|
+
get(target, key) {
|
|
11
|
+
if (typeof key == "string" && key[0] === "$" &&
|
|
12
|
+
// dont error on $$typeof
|
|
13
|
+
key[1] !== "$") throw new Error(`Access mediaState should not use "$": ${key}`);
|
|
14
|
+
return Reflect.get(target, key);
|
|
15
|
+
}
|
|
16
|
+
}) : {};
|
|
17
|
+
const mediaQueryConfig = {},
|
|
18
|
+
getMedia = () => mediaState,
|
|
19
|
+
mediaKeys = /* @__PURE__ */new Set(),
|
|
20
|
+
isMediaKey = key => {
|
|
21
|
+
if (mediaKeys.has(key)) return !0;
|
|
22
|
+
if (key[0] === "$") {
|
|
23
|
+
if (key.startsWith("$platform-")) return "platform";
|
|
24
|
+
if (key.startsWith("$theme-")) return "theme";
|
|
25
|
+
if (key.startsWith("$group-")) return "group";
|
|
26
|
+
}
|
|
27
|
+
return !1;
|
|
28
|
+
};
|
|
29
|
+
let initState;
|
|
30
|
+
const defaultMediaImportance = Object.keys(pseudoDescriptors).length;
|
|
31
|
+
let mediaKeysOrdered;
|
|
32
|
+
const getMediaKeyImportance = key => {
|
|
33
|
+
if (process.env.NODE_ENV === "development" && key[0] === "$") throw new Error("use short key");
|
|
34
|
+
return getConfig().settings.mediaPropOrder ? defaultMediaImportance : mediaKeysOrdered.indexOf(key) + 100;
|
|
35
|
+
},
|
|
36
|
+
dispose = /* @__PURE__ */new Set();
|
|
37
|
+
let mediaVersion = 0;
|
|
38
|
+
const configureMedia = config => {
|
|
39
|
+
const {
|
|
40
|
+
media,
|
|
41
|
+
mediaQueryDefaultActive
|
|
42
|
+
} = config;
|
|
43
|
+
if (media) {
|
|
44
|
+
mediaVersion++;
|
|
45
|
+
for (const key in media) mediaState[key] = mediaQueryDefaultActive?.[key] || !1, mediaKeys.add(`$${key}`);
|
|
46
|
+
Object.assign(mediaQueryConfig, media), initState = {
|
|
47
|
+
...mediaState
|
|
48
|
+
}, mediaKeysOrdered = Object.keys(media), config.disableSSR ? setupMediaListeners() : updateCurrentState();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
function unlisten() {
|
|
52
|
+
dispose.forEach(cb => cb()), dispose.clear();
|
|
53
|
+
}
|
|
54
|
+
let setupVersion = -1;
|
|
55
|
+
function setupMediaListeners() {
|
|
56
|
+
if (!(isWeb && isServer) && setupVersion !== mediaVersion) {
|
|
57
|
+
setupVersion = mediaVersion, unlisten();
|
|
58
|
+
for (const key in mediaQueryConfig) {
|
|
59
|
+
let update = function () {
|
|
60
|
+
const next = !!getMatch().matches;
|
|
61
|
+
next !== mediaState[key] && (mediaState = {
|
|
62
|
+
...mediaState,
|
|
63
|
+
[key]: next
|
|
64
|
+
}, updateCurrentState());
|
|
65
|
+
};
|
|
66
|
+
const str = mediaObjectToString(mediaQueryConfig[key], key),
|
|
67
|
+
getMatch = () => matchMedia(str),
|
|
68
|
+
match = getMatch();
|
|
69
|
+
if (!match) throw new Error("\u26A0\uFE0F No match");
|
|
70
|
+
match.addListener(update), dispose.add(() => {
|
|
71
|
+
match.removeListener(update);
|
|
72
|
+
}), update();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const listeners = /* @__PURE__ */new Set();
|
|
77
|
+
let flushing = !1,
|
|
78
|
+
flushVersion = -1;
|
|
79
|
+
function updateCurrentState() {
|
|
80
|
+
flushing && flushVersion === mediaVersion || (flushVersion = mediaVersion, flushing = !0, Promise.resolve().then(() => {
|
|
81
|
+
flushing = !1, listeners.forEach(cb => cb(mediaState));
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
const shouldUpdate = /* @__PURE__ */new WeakMap();
|
|
85
|
+
function setMediaShouldUpdate(ref, props) {
|
|
86
|
+
return shouldUpdate.set(ref, props);
|
|
87
|
+
}
|
|
88
|
+
function subscribe(subscriber) {
|
|
89
|
+
return listeners.add(subscriber), () => listeners.delete(subscriber);
|
|
90
|
+
}
|
|
91
|
+
function useMedia(uid, componentContext) {
|
|
92
|
+
const internal = useRef(),
|
|
93
|
+
initialState = (getDisableSSR(componentContext) || !isWeb ? mediaState : initState) || {},
|
|
94
|
+
state = useSyncExternalStore(subscribe, () => {
|
|
95
|
+
if (!internal.current) return initialState;
|
|
96
|
+
const {
|
|
97
|
+
touched,
|
|
98
|
+
prev
|
|
99
|
+
} = internal.current,
|
|
100
|
+
componentState = uid ? shouldUpdate.get(uid) : void 0;
|
|
101
|
+
if (componentState && componentState.enabled === !1) return prev;
|
|
102
|
+
const testKeys = componentState?.keys ?? ((!componentState || componentState.enabled) && touched ? [...touched] : null);
|
|
103
|
+
return !testKeys || testKeys?.every(key => mediaState[key] === prev[key]) ? prev : (internal.current.prev = mediaState, mediaState);
|
|
104
|
+
}, () => initialState);
|
|
105
|
+
return new Proxy(state, {
|
|
106
|
+
get(_, key) {
|
|
107
|
+
return typeof key == "string" && (internal.current ||= {
|
|
108
|
+
prev: initialState
|
|
109
|
+
}, internal.current.touched ||= /* @__PURE__ */new Set(), internal.current.touched.add(key)), Reflect.get(state, key);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
const getMediaImportanceIfMoreImportant = (mediaKey, key, importancesUsed, isSizeMedia) => {
|
|
114
|
+
const conf = getConfig(),
|
|
115
|
+
importance = isSizeMedia && !conf.settings.mediaPropOrder ? getMediaKeyImportance(mediaKey) : defaultMediaImportance;
|
|
116
|
+
return !importancesUsed[key] || importance > importancesUsed[key] ? importance : null;
|
|
117
|
+
};
|
|
118
|
+
function mergeMediaByImportance(onto, mediaKey, key, value, importancesUsed, isSizeMedia, importanceBump) {
|
|
119
|
+
let importance = getMediaImportanceIfMoreImportant(mediaKey, key, importancesUsed, isSizeMedia);
|
|
120
|
+
return importanceBump && (importance = (importance || 0) + importanceBump), importance === null ? !1 : (importancesUsed[key] = importance, onto[key] = value, !0);
|
|
121
|
+
}
|
|
122
|
+
function camelToHyphen(str) {
|
|
123
|
+
return str.replace(/[A-Z]/g, m => `-${m.toLowerCase()}`).toLowerCase();
|
|
124
|
+
}
|
|
125
|
+
const cache = /* @__PURE__ */new WeakMap(),
|
|
126
|
+
cachedMediaKeyToQuery = {};
|
|
127
|
+
function mediaObjectToString(query, key) {
|
|
128
|
+
if (typeof query == "string") return query;
|
|
129
|
+
if (cache.has(query)) return cache.get(query);
|
|
130
|
+
const res = Object.entries(query).map(([feature, value]) => (feature = camelToHyphen(feature), typeof value == "string" ? `(${feature}: ${value})` : (typeof value == "number" && /[height|width]$/.test(feature) && (value = `${value}px`), `(${feature}: ${value})`))).join(" and ");
|
|
131
|
+
return key && (cachedMediaKeyToQuery[key] = res), cache.set(query, res), res;
|
|
132
|
+
}
|
|
133
|
+
function mediaKeyToQuery(key) {
|
|
134
|
+
return cachedMediaKeyToQuery[key] || mediaObjectToString(mediaQueryConfig[key], key);
|
|
135
|
+
}
|
|
136
|
+
function mediaKeyMatch(key, dimensions) {
|
|
137
|
+
const mediaQueries = mediaQueryConfig[key];
|
|
138
|
+
return Object.keys(mediaQueries).every(query => {
|
|
139
|
+
const expectedVal = +mediaQueries[query],
|
|
140
|
+
isMax = query.startsWith("max"),
|
|
141
|
+
isWidth = query.endsWith("Width"),
|
|
142
|
+
givenVal = dimensions[isWidth ? "width" : "height"];
|
|
143
|
+
return isMax ? givenVal < expectedVal : givenVal > expectedVal;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
export { configureMedia, getMedia, getMediaImportanceIfMoreImportant, getMediaKeyImportance, isMediaKey, mediaKeyMatch, mediaKeyToQuery, mediaKeys, mediaObjectToString, mediaQueryConfig, mediaState, mergeMediaByImportance, setMediaShouldUpdate, setupMediaListeners, useMedia };
|