@tamagui/core 1.0.1-beta.46 → 1.0.1-beta.49
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/cjs/Tamagui.js +3 -0
- package/dist/cjs/Tamagui.js.map +2 -2
- package/dist/cjs/ThemeManager.js.map +2 -2
- package/dist/cjs/conf.js +0 -4
- package/dist/cjs/conf.js.map +2 -2
- package/dist/cjs/createComponent.js +172 -167
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/createTamagui.js +71 -29
- package/dist/cjs/createTamagui.js.map +2 -2
- package/dist/cjs/createTheme.js +3 -1
- package/dist/cjs/createTheme.js.map +2 -2
- package/dist/cjs/createTokens.js +4 -19
- package/dist/cjs/createTokens.js.map +2 -2
- package/dist/cjs/createVariable.js +22 -8
- package/dist/cjs/createVariable.js.map +2 -2
- package/dist/cjs/createVariables.js +57 -0
- package/dist/cjs/createVariables.js.map +7 -0
- package/dist/cjs/helpers/createPropMapper.js +81 -51
- package/dist/cjs/helpers/createPropMapper.js.map +2 -2
- package/dist/cjs/helpers/generateAtomicStyles.js +41 -36
- package/dist/cjs/helpers/generateAtomicStyles.js.map +2 -2
- package/dist/cjs/helpers/getSplitStyles.js +36 -5
- package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
- package/dist/cjs/helpers/getStackSize.js +4 -4
- package/dist/cjs/helpers/getStackSize.js.map +2 -2
- package/dist/cjs/helpers/getStylesAtomic.js +9 -2
- package/dist/cjs/helpers/getStylesAtomic.js.map +2 -2
- package/dist/cjs/helpers/insertStyleRule.js +2 -0
- package/dist/cjs/helpers/insertStyleRule.js.map +2 -2
- package/dist/cjs/helpers/validate.js +2 -2
- package/dist/cjs/helpers/validate.js.map +2 -2
- package/dist/cjs/hooks/useIsMounted.js +2 -2
- package/dist/cjs/hooks/useIsMounted.js.map +2 -2
- package/dist/cjs/index.js +2 -3
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/styled.js +5 -0
- package/dist/cjs/styled.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/views/Slot.js +5 -8
- package/dist/cjs/views/Slot.js.map +2 -2
- package/dist/cjs/views/Theme.js +3 -2
- package/dist/cjs/views/Theme.js.map +2 -2
- package/dist/esm/Tamagui.js +3 -0
- package/dist/esm/Tamagui.js.map +2 -2
- package/dist/esm/ThemeManager.js.map +2 -2
- package/dist/esm/conf.js +0 -4
- package/dist/esm/conf.js.map +2 -2
- package/dist/esm/createComponent.js +172 -168
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/createTamagui.js +70 -29
- package/dist/esm/createTamagui.js.map +2 -2
- package/dist/esm/createTheme.js +3 -1
- package/dist/esm/createTheme.js.map +2 -2
- package/dist/esm/createTokens.js +3 -17
- package/dist/esm/createTokens.js.map +2 -2
- package/dist/esm/createVariable.js +22 -7
- package/dist/esm/createVariable.js.map +2 -2
- package/dist/esm/createVariables.js +35 -0
- package/dist/esm/createVariables.js.map +7 -0
- package/dist/esm/helpers/createPropMapper.js +70 -51
- package/dist/esm/helpers/createPropMapper.js.map +2 -2
- package/dist/esm/helpers/generateAtomicStyles.js +41 -36
- package/dist/esm/helpers/generateAtomicStyles.js.map +2 -2
- package/dist/esm/helpers/getSplitStyles.js +37 -6
- package/dist/esm/helpers/getSplitStyles.js.map +2 -2
- package/dist/esm/helpers/getStackSize.js +1 -1
- package/dist/esm/helpers/getStackSize.js.map +2 -2
- package/dist/esm/helpers/getStylesAtomic.js +7 -1
- package/dist/esm/helpers/getStylesAtomic.js.map +2 -2
- package/dist/esm/helpers/insertStyleRule.js +2 -0
- package/dist/esm/helpers/insertStyleRule.js.map +2 -2
- package/dist/esm/helpers/validate.js +2 -2
- package/dist/esm/helpers/validate.js.map +2 -2
- package/dist/esm/hooks/useIsMounted.js +1 -1
- package/dist/esm/hooks/useIsMounted.js.map +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/styled.js +5 -0
- package/dist/esm/styled.js.map +2 -2
- package/dist/esm/views/Slot.js +5 -8
- package/dist/esm/views/Slot.js.map +2 -2
- package/dist/esm/views/Theme.js +3 -2
- package/dist/esm/views/Theme.js.map +2 -2
- package/dist/jsx/Tamagui.js +3 -0
- package/dist/jsx/conf.js +0 -4
- package/dist/jsx/createComponent.js +172 -168
- package/dist/jsx/createTamagui.js +70 -29
- package/dist/jsx/createTheme.js +3 -1
- package/dist/jsx/createTokens.js +3 -17
- package/dist/jsx/createVariable.js +22 -7
- package/dist/jsx/createVariables.js +34 -0
- package/dist/jsx/helpers/createPropMapper.js +70 -51
- package/dist/jsx/helpers/generateAtomicStyles.js +41 -36
- package/dist/jsx/helpers/getSplitStyles.js +37 -6
- package/dist/jsx/helpers/getStackSize.js +1 -1
- package/dist/jsx/helpers/getStylesAtomic.js +7 -1
- package/dist/jsx/helpers/insertStyleRule.js +2 -0
- package/dist/jsx/helpers/validate.js +2 -2
- package/dist/jsx/hooks/useIsMounted.js +1 -1
- package/dist/jsx/index.js +2 -2
- package/dist/jsx/styled.js +5 -0
- package/dist/jsx/views/Slot.js +5 -8
- package/dist/jsx/views/Theme.js +3 -2
- package/package.json +5 -5
- package/reset.css +1 -1
- package/types/ThemeManager.d.ts.map +1 -1
- package/types/conf.d.ts +1 -1
- package/types/conf.d.ts.map +1 -1
- package/types/createComponent.d.ts +1 -0
- package/types/createComponent.d.ts.map +1 -1
- package/types/createTamagui.d.ts.map +1 -1
- package/types/createTheme.d.ts +1 -1
- package/types/createTheme.d.ts.map +1 -1
- package/types/createTokens.d.ts +0 -1
- package/types/createTokens.d.ts.map +1 -1
- package/types/createVariable.d.ts +15 -13
- package/types/createVariable.d.ts.map +1 -1
- package/types/createVariables.d.ts +10 -0
- package/types/createVariables.d.ts.map +1 -0
- package/types/helpers/createPropMapper.d.ts.map +1 -1
- package/types/helpers/generateAtomicStyles.d.ts.map +1 -1
- package/types/helpers/getSize.d.ts +1 -1
- package/types/helpers/getSize.d.ts.map +1 -1
- package/types/helpers/getSplitStyles.d.ts.map +1 -1
- package/types/helpers/getStackSize.d.ts +4 -5
- package/types/helpers/getStackSize.d.ts.map +1 -1
- package/types/helpers/getStylesAtomic.d.ts +5 -0
- package/types/helpers/getStylesAtomic.d.ts.map +1 -1
- package/types/helpers/getVariantExtras.d.ts +1 -1
- package/types/helpers/insertStyleRule.d.ts.map +1 -1
- package/types/hooks/useIsMounted.d.ts.map +1 -1
- package/types/index.d.ts +2 -1
- package/types/index.d.ts.map +1 -1
- package/types/styled.d.ts.map +1 -1
- package/types/types.d.ts +10 -7
- package/types/types.d.ts.map +1 -1
- package/types/views/Slot.d.ts.map +1 -1
- package/types/views/Theme.d.ts.map +1 -1
|
@@ -3,7 +3,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
3
3
|
import { configListeners, getHasConfigured, setConfig } from "./conf";
|
|
4
4
|
import { THEME_CLASSNAME_PREFIX } from "./constants/constants";
|
|
5
5
|
import { isWeb } from "./constants/platform";
|
|
6
|
-
import {
|
|
6
|
+
import { createCSSVariable, createVariable, isVariable } from "./createVariable";
|
|
7
7
|
import { createTamaguiProvider } from "./helpers/createTamaguiProvider";
|
|
8
8
|
import { getInsertedRules } from "./helpers/insertStyleRule";
|
|
9
9
|
import { configureMedia } from "./hooks/useMedia";
|
|
@@ -29,6 +29,7 @@ function createTamagui(config) {
|
|
|
29
29
|
});
|
|
30
30
|
const themeConfig = (() => {
|
|
31
31
|
var _a, _b, _c;
|
|
32
|
+
const themes = { ...config.themes };
|
|
32
33
|
let cssRules = [];
|
|
33
34
|
const varsByValue = /* @__PURE__ */ new Map();
|
|
34
35
|
if (isWeb) {
|
|
@@ -61,39 +62,74 @@ function createTamagui(config) {
|
|
|
61
62
|
}
|
|
62
63
|
const hasDarkLight = "light" in config.themes && "dark" in config.themes;
|
|
63
64
|
const CNP = `.${THEME_CLASSNAME_PREFIX}`;
|
|
64
|
-
|
|
65
|
+
const existing = /* @__PURE__ */ new WeakMap();
|
|
66
|
+
const dedupedThemes = {};
|
|
67
|
+
for (const themeName in themes) {
|
|
68
|
+
const rawTheme = themes[themeName];
|
|
69
|
+
if (existing.has(rawTheme)) {
|
|
70
|
+
const e = existing.get(rawTheme);
|
|
71
|
+
e.names.push(themeName);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
65
74
|
const theme = { ...config.themes[themeName] };
|
|
66
|
-
|
|
75
|
+
for (const key in theme) {
|
|
76
|
+
ensureThemeVariable(theme, key);
|
|
77
|
+
}
|
|
78
|
+
themes[themeName] = theme;
|
|
79
|
+
dedupedThemes[themeName] = {
|
|
80
|
+
names: [themeName],
|
|
81
|
+
theme
|
|
82
|
+
};
|
|
83
|
+
existing.set(theme, dedupedThemes[themeName]);
|
|
84
|
+
}
|
|
85
|
+
for (const themeName in dedupedThemes) {
|
|
86
|
+
const { theme, names } = dedupedThemes[themeName];
|
|
67
87
|
let vars = "";
|
|
68
88
|
for (const themeKey in theme) {
|
|
69
89
|
if (isWeb) {
|
|
70
90
|
const val = theme[themeKey];
|
|
71
|
-
|
|
72
|
-
|
|
91
|
+
let varName;
|
|
92
|
+
let varVal;
|
|
93
|
+
if (isVariable(val)) {
|
|
94
|
+
varName = val.key;
|
|
95
|
+
varVal = val.isFloating ? val.val : createCSSVariable(varName);
|
|
96
|
+
} else {
|
|
97
|
+
varName = (_a = varsByValue[val]) == null ? void 0 : _a.key;
|
|
98
|
+
varVal = varName ? createCSSVariable(varName) : `${val}`;
|
|
99
|
+
}
|
|
100
|
+
if (process.env.NODE_ENV === "development") {
|
|
101
|
+
if (!varName) {
|
|
102
|
+
console.warn("no var name in theme", themeName, themeKey);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
vars += `--${themeKey}:${varVal};`;
|
|
73
107
|
}
|
|
74
|
-
ensureThemeVariable(theme, themeKey);
|
|
75
108
|
}
|
|
76
109
|
if (isWeb) {
|
|
77
110
|
const isDarkOrLightBase = themeName === "dark" || themeName === "light";
|
|
78
111
|
const isDark = themeName.startsWith("dark");
|
|
79
|
-
const
|
|
80
|
-
|
|
112
|
+
const selectors = names.map((name) => {
|
|
113
|
+
return `${CNP}${name}`;
|
|
114
|
+
});
|
|
81
115
|
if (hasDarkLight) {
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
116
|
+
for (const subName of names) {
|
|
117
|
+
const childSelector = `${CNP}${subName.replace("dark_", "").replace("light_", "")}`;
|
|
118
|
+
const order = isDark ? ["dark", "light"] : ["light", "dark"];
|
|
119
|
+
if (isDarkOrLightBase) {
|
|
120
|
+
order.reverse();
|
|
121
|
+
}
|
|
122
|
+
const [stronger, weaker] = order;
|
|
123
|
+
const max = (_b = config.maxDarkLightNesting) != null ? _b : 3;
|
|
124
|
+
new Array(max * 2).fill(void 0).forEach((_, pi) => {
|
|
125
|
+
if (pi % 2 === 1)
|
|
126
|
+
return;
|
|
127
|
+
const parents = new Array(pi + 1).fill(void 0).map((_2, psi) => {
|
|
128
|
+
return `${CNP}${psi % 2 === 0 ? stronger : weaker}`;
|
|
129
|
+
});
|
|
130
|
+
selectors.push(`${(parents.length > 1 ? parents.slice(1) : parents).join(" ")} ${childSelector}`);
|
|
94
131
|
});
|
|
95
|
-
|
|
96
|
-
});
|
|
132
|
+
}
|
|
97
133
|
}
|
|
98
134
|
const rootSep = config.themeClassNameOnRoot ? "" : " ";
|
|
99
135
|
cssRules.push(`${selectors.map((x) => `:root${rootSep}${x}`).join(", ")} {${vars}}`);
|
|
@@ -111,6 +147,7 @@ function createTamagui(config) {
|
|
|
111
147
|
Object.freeze(cssRules);
|
|
112
148
|
const css = cssRules.join("\n");
|
|
113
149
|
return {
|
|
150
|
+
themes,
|
|
114
151
|
cssRules,
|
|
115
152
|
css
|
|
116
153
|
};
|
|
@@ -154,10 +191,12 @@ ${getInsertedRules().join("\n")}`;
|
|
|
154
191
|
shorthands: {},
|
|
155
192
|
media: {},
|
|
156
193
|
...config,
|
|
194
|
+
themes: themeConfig.themes,
|
|
157
195
|
Provider: createTamaguiProvider({
|
|
158
196
|
getCSS,
|
|
159
197
|
defaultTheme: "light",
|
|
160
|
-
...config
|
|
198
|
+
...config,
|
|
199
|
+
themes: themeConfig.themes
|
|
161
200
|
}),
|
|
162
201
|
fontsParsed,
|
|
163
202
|
themeConfig,
|
|
@@ -187,17 +226,19 @@ const parseTokens = /* @__PURE__ */ __name((tokens) => {
|
|
|
187
226
|
}, "parseTokens");
|
|
188
227
|
function ensureThemeVariable(theme, key) {
|
|
189
228
|
const val = theme[key];
|
|
229
|
+
const themeKey = key;
|
|
190
230
|
if (!isVariable(val)) {
|
|
191
231
|
theme[key] = createVariable({
|
|
192
|
-
key,
|
|
193
|
-
name:
|
|
194
|
-
val
|
|
232
|
+
key: themeKey,
|
|
233
|
+
name: themeKey,
|
|
234
|
+
val,
|
|
235
|
+
isFloating: true
|
|
195
236
|
});
|
|
196
237
|
} else {
|
|
197
|
-
if (val.name !==
|
|
238
|
+
if (val.name !== themeKey) {
|
|
198
239
|
theme[key] = createVariable({
|
|
199
|
-
key,
|
|
200
|
-
name:
|
|
240
|
+
key: val.name,
|
|
241
|
+
name: themeKey,
|
|
201
242
|
val: val.val
|
|
202
243
|
});
|
|
203
244
|
}
|
package/dist/jsx/createTheme.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
const createTheme = /* @__PURE__ */ __name((theme) =>
|
|
3
|
+
const createTheme = /* @__PURE__ */ __name((theme) => {
|
|
4
|
+
return theme;
|
|
5
|
+
}, "createTheme");
|
|
4
6
|
export {
|
|
5
7
|
createTheme
|
|
6
8
|
};
|
package/dist/jsx/createTokens.js
CHANGED
|
@@ -1,28 +1,14 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import {
|
|
3
|
+
import { createVariables } from "./createVariables";
|
|
4
4
|
import { validateTokens } from "./helpers/validate";
|
|
5
5
|
function createTokens(tokens) {
|
|
6
6
|
if (process.env.NODE_ENV === "development") {
|
|
7
7
|
validateTokens(tokens);
|
|
8
8
|
}
|
|
9
|
-
return
|
|
9
|
+
return createVariables(tokens);
|
|
10
10
|
}
|
|
11
11
|
__name(createTokens, "createTokens");
|
|
12
|
-
const mapTokensToVariables = /* @__PURE__ */ __name((tokens, parentPath = "") => {
|
|
13
|
-
const res = {};
|
|
14
|
-
for (const key in tokens) {
|
|
15
|
-
let val = tokens[key];
|
|
16
|
-
const name = parentPath ? `${parentPath}-${key}` : key;
|
|
17
|
-
if (val && typeof val === "object") {
|
|
18
|
-
res[key] = mapTokensToVariables(tokens[key], name);
|
|
19
|
-
} else {
|
|
20
|
-
res[key] = createVariable({ val, name, key });
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return res;
|
|
24
|
-
}, "mapTokensToVariables");
|
|
25
12
|
export {
|
|
26
|
-
createTokens
|
|
27
|
-
mapTokensToVariables
|
|
13
|
+
createTokens
|
|
28
14
|
};
|
|
@@ -4,12 +4,17 @@ var _a;
|
|
|
4
4
|
import { isWeb } from "./constants/platform";
|
|
5
5
|
const IS_VARIABLE_SYMBOL = "__isVariable__";
|
|
6
6
|
class Variable {
|
|
7
|
-
constructor(
|
|
7
|
+
constructor(props) {
|
|
8
8
|
this[_a] = true;
|
|
9
|
+
this.isFloating = false;
|
|
10
|
+
const { val, name, key, isFloating } = props;
|
|
9
11
|
this.val = isVariable(val) ? val.val : val;
|
|
10
12
|
this.name = name;
|
|
11
13
|
this.key = key;
|
|
12
|
-
this.variable = isWeb ? createCSSVariable(name) :
|
|
14
|
+
this.variable = isWeb ? createCSSVariable(name) : "";
|
|
15
|
+
if (isFloating) {
|
|
16
|
+
this.isFloating = true;
|
|
17
|
+
}
|
|
13
18
|
}
|
|
14
19
|
toString() {
|
|
15
20
|
return `${isWeb ? this.variable : this.val}`;
|
|
@@ -17,9 +22,14 @@ class Variable {
|
|
|
17
22
|
}
|
|
18
23
|
__name(Variable, "Variable");
|
|
19
24
|
_a = IS_VARIABLE_SYMBOL;
|
|
20
|
-
const createVariable = /* @__PURE__ */ __name((props) =>
|
|
25
|
+
const createVariable = /* @__PURE__ */ __name((props) => {
|
|
26
|
+
if (isVariable(props)) {
|
|
27
|
+
return props;
|
|
28
|
+
}
|
|
29
|
+
return new Variable(props);
|
|
30
|
+
}, "createVariable");
|
|
21
31
|
function isVariable(v) {
|
|
22
|
-
return v instanceof Variable || v && v[IS_VARIABLE_SYMBOL];
|
|
32
|
+
return !!(v instanceof Variable || v && v[IS_VARIABLE_SYMBOL]);
|
|
23
33
|
}
|
|
24
34
|
__name(isVariable, "isVariable");
|
|
25
35
|
function getVariableValue(v) {
|
|
@@ -34,12 +44,17 @@ function getVariableName(v) {
|
|
|
34
44
|
return v;
|
|
35
45
|
}
|
|
36
46
|
__name(getVariableName, "getVariableName");
|
|
37
|
-
const createCSSVariable = /* @__PURE__ */ __name((
|
|
38
|
-
|
|
47
|
+
const createCSSVariable = /* @__PURE__ */ __name((nameProp, includeVar = true) => {
|
|
48
|
+
if (process.env.NODE_ENV === "development") {
|
|
49
|
+
if (!nameProp || typeof nameProp !== "string") {
|
|
50
|
+
console.warn("invalid name", nameProp);
|
|
51
|
+
return ``;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const name = nameProp.replace(/[^a-z0-9\_\-]+/i, "_");
|
|
39
55
|
return includeVar ? `var(--${name})` : name;
|
|
40
56
|
}, "createCSSVariable");
|
|
41
57
|
export {
|
|
42
|
-
IS_VARIABLE_SYMBOL,
|
|
43
58
|
Variable,
|
|
44
59
|
createCSSVariable,
|
|
45
60
|
createVariable,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { createVariable, isVariable } from "./createVariable";
|
|
4
|
+
const createVariables = /* @__PURE__ */ __name((tokens, parentPath = "") => {
|
|
5
|
+
const res = {};
|
|
6
|
+
for (const key in tokens) {
|
|
7
|
+
let val = tokens[key];
|
|
8
|
+
const name = parentPath ? `${parentPath}-${key}` : key;
|
|
9
|
+
if (isVariable(val)) {
|
|
10
|
+
res[key] = val;
|
|
11
|
+
} else if (val && typeof val === "object") {
|
|
12
|
+
if (Array.isArray(val)) {
|
|
13
|
+
res[key] = val.map((val2, i) => {
|
|
14
|
+
const skey = `${key}-${i}`;
|
|
15
|
+
const sname = parentPath ? `${name}-${skey}` : skey;
|
|
16
|
+
console.log("make it", val2, key, sname);
|
|
17
|
+
return isVariable(val2) ? val2 : createVariable({
|
|
18
|
+
val: val2,
|
|
19
|
+
key: skey,
|
|
20
|
+
name: sname
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
} else {
|
|
24
|
+
res[key] = createVariables(tokens[key], name);
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
res[key] = createVariable({ val, name, key });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return res;
|
|
31
|
+
}, "createVariables");
|
|
32
|
+
export {
|
|
33
|
+
createVariables
|
|
34
|
+
};
|
|
@@ -6,30 +6,6 @@ import { isVariable } from "../createVariable";
|
|
|
6
6
|
import { expandStyle, expandStyles } from "./generateAtomicStyles";
|
|
7
7
|
import { getVariantExtras } from "./getVariantExtras";
|
|
8
8
|
import { isObj } from "./isObj";
|
|
9
|
-
function getVariantFunction(variant, key, value) {
|
|
10
|
-
if (typeof variant === "function") {
|
|
11
|
-
return variant;
|
|
12
|
-
}
|
|
13
|
-
for (const cat in tokenCategories) {
|
|
14
|
-
if (key in tokenCategories[cat]) {
|
|
15
|
-
const spreadVariant = variant[`...${cat}`];
|
|
16
|
-
if (spreadVariant) {
|
|
17
|
-
return spreadVariant;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
let fn;
|
|
22
|
-
if (typeof value === "number") {
|
|
23
|
-
fn = variant[":number"];
|
|
24
|
-
} else if (typeof value === "string") {
|
|
25
|
-
fn = variant[":string"];
|
|
26
|
-
} else if (value === true || value === false) {
|
|
27
|
-
fn = variant[":boolean"];
|
|
28
|
-
}
|
|
29
|
-
fn = fn || variant[value];
|
|
30
|
-
return fn || variant["..."] || variant["...size"];
|
|
31
|
-
}
|
|
32
|
-
__name(getVariantFunction, "getVariantFunction");
|
|
33
9
|
const createPropMapper = /* @__PURE__ */ __name((staticConfig) => {
|
|
34
10
|
const variants = staticConfig.variants || {};
|
|
35
11
|
const defaultProps = staticConfig.defaultProps || {};
|
|
@@ -40,26 +16,11 @@ const createPropMapper = /* @__PURE__ */ __name((staticConfig) => {
|
|
|
40
16
|
return;
|
|
41
17
|
}
|
|
42
18
|
const props = state.fallbackProps || propsIn;
|
|
43
|
-
const returnVariablesAs = state.resolveVariablesAs || !!props.animation ? "value" : "auto";
|
|
19
|
+
const returnVariablesAs = state.resolveVariablesAs === "value" || !!props.animation ? "value" : "auto";
|
|
44
20
|
const fontFamily = props.fontFamily || defaultProps.fontFamily || "$body";
|
|
45
|
-
const
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
if (variantValue) {
|
|
49
|
-
if (typeof variantValue === "function") {
|
|
50
|
-
const fn = variantValue;
|
|
51
|
-
variantValue = fn(value, getVariantExtras(props, theme, defaultProps, avoidDefaultProps));
|
|
52
|
-
}
|
|
53
|
-
if (isObj(variantValue)) {
|
|
54
|
-
variantValue = resolveTokens(variantValue, conf, theme, fontFamily, returnVariablesAs);
|
|
55
|
-
}
|
|
56
|
-
return Object.entries(expandStyles(variantValue));
|
|
57
|
-
} else {
|
|
58
|
-
if (process.env.NODE_ENV === "development") {
|
|
59
|
-
console.warn(`No variant found: ${staticConfig.componentName || "[UnnamedComponent]"} has variant "${key}", but no matching value "${value}"`);
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
21
|
+
const variantValue = resolveVariants(key, value, props, defaultProps, theme, variants, fontFamily, conf, returnVariablesAs, staticConfig, "", avoidDefaultProps);
|
|
22
|
+
if (variantValue) {
|
|
23
|
+
return variantValue;
|
|
63
24
|
}
|
|
64
25
|
let shouldReturn = value !== void 0 && value !== null;
|
|
65
26
|
if (conf.shorthands[key]) {
|
|
@@ -79,22 +40,56 @@ const createPropMapper = /* @__PURE__ */ __name((staticConfig) => {
|
|
|
79
40
|
}, "mapper");
|
|
80
41
|
return mapper;
|
|
81
42
|
}, "createPropMapper");
|
|
82
|
-
const
|
|
43
|
+
const resolveVariants = /* @__PURE__ */ __name((key, value, props, defaultProps, theme, variants, fontFamily, conf, returnVariablesAs, staticConfig, parentVariantKey, avoidDefaultProps = false) => {
|
|
44
|
+
var _a;
|
|
45
|
+
const variant = variants && variants[key];
|
|
46
|
+
if (variant && value !== void 0) {
|
|
47
|
+
let variantValue = getVariantDefinition(variant, key, value);
|
|
48
|
+
if (variantValue) {
|
|
49
|
+
if (typeof variantValue === "function") {
|
|
50
|
+
const fn = variantValue;
|
|
51
|
+
variantValue = fn(value, getVariantExtras(props, theme, defaultProps, avoidDefaultProps));
|
|
52
|
+
}
|
|
53
|
+
if (isObj(variantValue)) {
|
|
54
|
+
variantValue = resolveTokensAndVariants(key, variantValue, props, defaultProps, theme, variants, fontFamily, conf, returnVariablesAs, staticConfig, parentVariantKey, avoidDefaultProps);
|
|
55
|
+
}
|
|
56
|
+
return Object.entries(expandStyles(variantValue));
|
|
57
|
+
} else {
|
|
58
|
+
if (process.env.NODE_ENV === "development") {
|
|
59
|
+
if ((_a = staticConfig.validStyles) == null ? void 0 : _a[key]) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
console.warn(`No variant found: ${staticConfig.componentName || "[UnnamedComponent]"} has variant "${key}", but no matching value "${value}"`);
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}, "resolveVariants");
|
|
68
|
+
const resolveTokensAndVariants = /* @__PURE__ */ __name((key, value, props, defaultProps, theme, variants, fontFamily, conf, returnVariablesAs, staticConfig, parentVariantKey, avoidDefaultProps) => {
|
|
83
69
|
var _a;
|
|
84
70
|
let res = {};
|
|
85
|
-
for (const rKey in
|
|
71
|
+
for (const rKey in value) {
|
|
86
72
|
const fKey = conf.shorthands[rKey] || rKey;
|
|
87
|
-
const val =
|
|
73
|
+
const val = value[rKey];
|
|
88
74
|
if (isVariable(val)) {
|
|
89
|
-
res[fKey] =
|
|
75
|
+
res[fKey] = !isWeb || returnVariablesAs === "value" ? val.val : val.variable;
|
|
76
|
+
} else if (variants[fKey]) {
|
|
77
|
+
if (parentVariantKey === key) {
|
|
78
|
+
res[fKey] = val;
|
|
79
|
+
} else {
|
|
80
|
+
res = {
|
|
81
|
+
...res,
|
|
82
|
+
...Object.fromEntries(resolveVariants(fKey, val, props, defaultProps, theme, variants, fontFamily, conf, returnVariablesAs, staticConfig, key, avoidDefaultProps))
|
|
83
|
+
};
|
|
84
|
+
}
|
|
90
85
|
} else if (typeof val === "string") {
|
|
91
|
-
const fVal = val[0] === "$" ? getToken(fKey, val, conf, theme, fontFamily,
|
|
86
|
+
const fVal = val[0] === "$" ? getToken(fKey, val, conf, theme, fontFamily, returnVariablesAs) : val;
|
|
92
87
|
res[fKey] = fVal;
|
|
93
88
|
} else {
|
|
94
89
|
if (isObj(val)) {
|
|
95
|
-
res[fKey] =
|
|
90
|
+
res[fKey] = resolveTokensAndVariants(fKey, val, props, defaultProps, theme, variants, fontFamily, conf, returnVariablesAs, staticConfig, key, avoidDefaultProps);
|
|
96
91
|
} else {
|
|
97
|
-
res[fKey] =
|
|
92
|
+
res[fKey] = value[fKey];
|
|
98
93
|
}
|
|
99
94
|
}
|
|
100
95
|
if (process.env.NODE_ENV === "development") {
|
|
@@ -104,7 +99,31 @@ const resolveTokens = /* @__PURE__ */ __name((input, conf, theme, fontFamily, re
|
|
|
104
99
|
}
|
|
105
100
|
}
|
|
106
101
|
return res;
|
|
107
|
-
}, "
|
|
102
|
+
}, "resolveTokensAndVariants");
|
|
103
|
+
function getVariantDefinition(variant, key, value) {
|
|
104
|
+
if (typeof variant === "function") {
|
|
105
|
+
return variant;
|
|
106
|
+
}
|
|
107
|
+
for (const cat in tokenCategories) {
|
|
108
|
+
if (key in tokenCategories[cat]) {
|
|
109
|
+
const spreadVariant = variant[`...${cat}`];
|
|
110
|
+
if (spreadVariant) {
|
|
111
|
+
return spreadVariant;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
let fn;
|
|
116
|
+
if (typeof value === "number") {
|
|
117
|
+
fn = variant[":number"];
|
|
118
|
+
} else if (typeof value === "string") {
|
|
119
|
+
fn = variant[":string"];
|
|
120
|
+
} else if (value === true || value === false) {
|
|
121
|
+
fn = variant[":boolean"];
|
|
122
|
+
}
|
|
123
|
+
fn = fn || variant[value];
|
|
124
|
+
return fn || variant["..."] || variant["...size"];
|
|
125
|
+
}
|
|
126
|
+
__name(getVariantDefinition, "getVariantDefinition");
|
|
108
127
|
const fontShorthand = {
|
|
109
128
|
fontSize: "size",
|
|
110
129
|
fontWeight: "weight"
|
|
@@ -40,9 +40,16 @@ const generateAtomicStyles = /* @__PURE__ */ __name((style) => {
|
|
|
40
40
|
const res = expandStyles(style);
|
|
41
41
|
if (style.shadowColor != null || style.shadowOffset != null || style.shadowOpacity != null || style.shadowRadius != null) {
|
|
42
42
|
boxShadowReducer(res, style);
|
|
43
|
+
delete res["shadowColor"];
|
|
44
|
+
delete res["shadowOffset"];
|
|
45
|
+
delete res["shadowOpacity"];
|
|
46
|
+
delete res["shadowRadius"];
|
|
43
47
|
}
|
|
44
48
|
if (style.textShadowColor != null || style.textShadowOffset != null || style.textShadowRadius != null) {
|
|
45
49
|
textShadowReducer(res, style);
|
|
50
|
+
delete res["textShadowColor"];
|
|
51
|
+
delete res["textShadowOffset"];
|
|
52
|
+
delete res["textShadowRadius"];
|
|
46
53
|
}
|
|
47
54
|
const out = {};
|
|
48
55
|
for (const key in res) {
|
|
@@ -95,41 +102,39 @@ function expandStyle(key, value) {
|
|
|
95
102
|
}
|
|
96
103
|
return;
|
|
97
104
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
];
|
|
115
|
-
}
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
case "textAlignVertical": {
|
|
119
|
-
return [["verticalAlign", value === "center" ? "middle" : value]];
|
|
120
|
-
}
|
|
121
|
-
case "textDecorationLine": {
|
|
122
|
-
return ["textDecorationLine", value];
|
|
123
|
-
}
|
|
124
|
-
case "transform": {
|
|
125
|
-
if (Array.isArray(value)) {
|
|
126
|
-
return [[key, value.map(mapTransform).join(" ")]];
|
|
127
|
-
}
|
|
128
|
-
break;
|
|
105
|
+
switch (key) {
|
|
106
|
+
case "elevation":
|
|
107
|
+
case "overlayColor":
|
|
108
|
+
case "resizeMode":
|
|
109
|
+
case "tintColor": {
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
case "aspectRatio": {
|
|
113
|
+
return [[key, value.toString()]];
|
|
114
|
+
}
|
|
115
|
+
case "backgroundClip": {
|
|
116
|
+
if (value === "text") {
|
|
117
|
+
return [
|
|
118
|
+
["backgroundClip", value],
|
|
119
|
+
["WebkitBackgroundClip", value]
|
|
120
|
+
];
|
|
129
121
|
}
|
|
130
|
-
|
|
131
|
-
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
case "textAlignVertical": {
|
|
125
|
+
return [["verticalAlign", value === "center" ? "middle" : value]];
|
|
126
|
+
}
|
|
127
|
+
case "textDecorationLine": {
|
|
128
|
+
return [["textDecorationLine", value]];
|
|
129
|
+
}
|
|
130
|
+
case "transform": {
|
|
131
|
+
if (Array.isArray(value)) {
|
|
132
|
+
return [[key, value.map(mapTransform).join(" ")]];
|
|
132
133
|
}
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
case "writingDirection": {
|
|
137
|
+
return [["direction", value]];
|
|
133
138
|
}
|
|
134
139
|
}
|
|
135
140
|
const longKey = STYLE_SHORT_FORM_EXPANSIONS[key];
|
|
@@ -288,8 +293,8 @@ const colorProps = {
|
|
|
288
293
|
textShadowColor: true
|
|
289
294
|
};
|
|
290
295
|
function normalizeValueWithProperty(value, property) {
|
|
291
|
-
if (
|
|
292
|
-
if ((property
|
|
296
|
+
if (process.env.TAMAGUI_TARGET === "web") {
|
|
297
|
+
if ((property === void 0 || property === null || !unitlessNumbers[property]) && typeof value === "number") {
|
|
293
298
|
return `${value}px`;
|
|
294
299
|
}
|
|
295
300
|
}
|
|
@@ -303,7 +308,7 @@ const normalizeColor = /* @__PURE__ */ __name((color, opacity = 1) => {
|
|
|
303
308
|
if (color == null || color == void 0) {
|
|
304
309
|
return;
|
|
305
310
|
}
|
|
306
|
-
if (
|
|
311
|
+
if (process.env.TAMAGUI_TARGET === "web") {
|
|
307
312
|
if (typeof color === "string" && isWebColor(color)) {
|
|
308
313
|
return color;
|
|
309
314
|
}
|
|
@@ -7,7 +7,7 @@ import { isClient, isWeb, useIsomorphicLayoutEffect } from "../constants/platfor
|
|
|
7
7
|
import { mediaQueryConfig, mediaState } from "../hooks/useMedia";
|
|
8
8
|
import { createMediaStyle } from "./createMediaStyle";
|
|
9
9
|
import { fixNativeShadow } from "./fixNativeShadow";
|
|
10
|
-
import { getStylesAtomic } from "./getStylesAtomic";
|
|
10
|
+
import { getStylesAtomic, psuedoCNInverse } from "./getStylesAtomic";
|
|
11
11
|
import {
|
|
12
12
|
insertStyleRule,
|
|
13
13
|
insertedTransforms,
|
|
@@ -114,12 +114,43 @@ const getSplitStyles = /* @__PURE__ */ __name((props, staticConfig, theme, state
|
|
|
114
114
|
for (const key in valInit) {
|
|
115
115
|
if (usedKeys.has(key))
|
|
116
116
|
continue;
|
|
117
|
-
|
|
117
|
+
if (valInit && typeof valInit === "object") {
|
|
118
|
+
for (const skey in valInit) {
|
|
119
|
+
if (usedKeys.has(skey))
|
|
120
|
+
continue;
|
|
121
|
+
usedKeys.add(skey);
|
|
122
|
+
style[skey] = valInit[skey];
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
usedKeys.add(key);
|
|
126
|
+
style[key] = valInit;
|
|
127
|
+
}
|
|
118
128
|
}
|
|
119
129
|
continue;
|
|
120
130
|
}
|
|
121
131
|
if (keyInit === "className") {
|
|
122
|
-
|
|
132
|
+
let nonTamaguis = "";
|
|
133
|
+
for (const cn of valInit.split(" ")) {
|
|
134
|
+
if (cn[0] === "_") {
|
|
135
|
+
const [shorthand, mediaOrPsuedo, rest] = cn.slice(1).split("-");
|
|
136
|
+
let fullKey = conf.shorthands[shorthand];
|
|
137
|
+
if (mediaOrPsuedo[0] === "_") {
|
|
138
|
+
let mediaShortKey = mediaOrPsuedo.slice(1);
|
|
139
|
+
mediaShortKey = mediaShortKey.slice(0, mediaShortKey.indexOf("_"));
|
|
140
|
+
fullKey += `-${mediaShortKey}`;
|
|
141
|
+
} else if (mediaOrPsuedo[0] === "0") {
|
|
142
|
+
const pseudoShortKey = mediaOrPsuedo.slice(1);
|
|
143
|
+
fullKey += `-${psuedoCNInverse[pseudoShortKey]}`;
|
|
144
|
+
}
|
|
145
|
+
usedKeys.add(fullKey);
|
|
146
|
+
mergeClassName(fullKey, cn);
|
|
147
|
+
} else {
|
|
148
|
+
nonTamaguis += " " + cn;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (nonTamaguis) {
|
|
152
|
+
mergeClassName(keyInit, nonTamaguis);
|
|
153
|
+
}
|
|
123
154
|
continue;
|
|
124
155
|
}
|
|
125
156
|
if (validStyleProps[keyInit] && valInit && valInit[0] === "_") {
|
|
@@ -196,7 +227,7 @@ const getSplitStyles = /* @__PURE__ */ __name((props, staticConfig, theme, state
|
|
|
196
227
|
const mediaStyles = getStylesAtomic(mediaStyle);
|
|
197
228
|
for (const style2 of mediaStyles) {
|
|
198
229
|
const out = createMediaStyle(style2, mediaKeyShort, mediaQueryConfig);
|
|
199
|
-
const fullKey = `${
|
|
230
|
+
const fullKey = `${style2.property}-${mediaKeyShort}`;
|
|
200
231
|
if (!usedKeys.has(fullKey)) {
|
|
201
232
|
usedKeys.add(fullKey);
|
|
202
233
|
addStyle(out.identifier, out.styleRule);
|
|
@@ -223,7 +254,7 @@ const getSplitStyles = /* @__PURE__ */ __name((props, staticConfig, theme, state
|
|
|
223
254
|
if (val && val[0] === "_") {
|
|
224
255
|
classNames[key] = val;
|
|
225
256
|
} else {
|
|
226
|
-
if (key in stylePropsTransform
|
|
257
|
+
if (key in stylePropsTransform) {
|
|
227
258
|
mergeTransform(style, key, val, true);
|
|
228
259
|
} else {
|
|
229
260
|
style[key] = val;
|
|
@@ -291,7 +322,7 @@ const insertSplitStyles = /* @__PURE__ */ __name((...args) => {
|
|
|
291
322
|
}
|
|
292
323
|
return res;
|
|
293
324
|
}, "insertSplitStyles");
|
|
294
|
-
const effect = useInsertionEffect || useIsomorphicLayoutEffect;
|
|
325
|
+
const effect = isWeb ? useInsertionEffect || useIsomorphicLayoutEffect : useIsomorphicLayoutEffect;
|
|
295
326
|
const useSplitStyles = /* @__PURE__ */ __name((...args) => {
|
|
296
327
|
const res = getSplitStyles(...args);
|
|
297
328
|
effect(() => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { getVariableValue, isVariable } from "
|
|
3
|
+
import { getVariableValue, isVariable } from "../createVariable";
|
|
4
4
|
const getSizeScaledToFont = /* @__PURE__ */ __name((val, { sizeX = 1, sizeY = 1 }, { tokens, props, fonts }) => {
|
|
5
5
|
var _a, _b, _c, _d, _e, _f;
|
|
6
6
|
const size = (_c = (_b = (_a = tokens.size[val]) != null ? _a : val) != null ? _b : tokens.size["$4"]) != null ? _c : 14;
|
|
@@ -20,6 +20,11 @@ const pseudos = {
|
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
const pseudosOrdered = Object.values(pseudos);
|
|
23
|
+
const psuedoCNInverse = {
|
|
24
|
+
hover: "hoverStyle",
|
|
25
|
+
focus: "focusStyle",
|
|
26
|
+
press: "pressStyle"
|
|
27
|
+
};
|
|
23
28
|
function getStylesAtomic(stylesIn, options = {}) {
|
|
24
29
|
const { hoverStyle, pressStyle, focusStyle, ...base } = stylesIn;
|
|
25
30
|
let res = [];
|
|
@@ -113,5 +118,6 @@ const borderDefaults = {
|
|
|
113
118
|
};
|
|
114
119
|
export {
|
|
115
120
|
getStylesAtomic,
|
|
116
|
-
pseudos
|
|
121
|
+
pseudos,
|
|
122
|
+
psuedoCNInverse
|
|
117
123
|
};
|