@tamagui/core 1.0.1-beta.54 → 1.0.1-beta.57
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.map +2 -2
- package/dist/cjs/conf.js +11 -2
- package/dist/cjs/conf.js.map +2 -2
- package/dist/cjs/createComponent.js +5 -2
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/createTamagui.js +65 -76
- package/dist/cjs/createTamagui.js.map +2 -2
- package/dist/cjs/createVariable.js +8 -0
- package/dist/cjs/createVariable.js.map +2 -2
- package/dist/cjs/createVariables.js +2 -2
- package/dist/cjs/createVariables.js.map +2 -2
- package/dist/cjs/helpers/calc.js +71 -0
- package/dist/cjs/helpers/calc.js.map +7 -0
- package/dist/cjs/helpers/createPropMapper.js +2 -9
- package/dist/cjs/helpers/createPropMapper.js.map +2 -2
- package/dist/cjs/helpers/getSize.js +16 -7
- package/dist/cjs/helpers/getSize.js.map +2 -2
- package/dist/cjs/helpers/getStackSize.js +11 -39
- package/dist/cjs/helpers/getStackSize.js.map +2 -2
- package/dist/cjs/helpers/getTextSize.js +1 -1
- package/dist/cjs/helpers/getTextSize.js.map +2 -2
- package/dist/cjs/helpers/registerCSSVariable.js +41 -0
- package/dist/cjs/helpers/registerCSSVariable.js.map +7 -0
- package/dist/cjs/hooks/useFeatures.js.map +2 -2
- package/dist/cjs/hooks/useTheme.js +3 -15
- package/dist/cjs/hooks/useTheme.js.map +2 -2
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/insertFont.js +81 -0
- package/dist/cjs/insertFont.js.map +7 -0
- package/dist/cjs/registerCSSVariable.js +41 -0
- package/dist/cjs/registerCSSVariable.js.map +7 -0
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/Tamagui.js.map +2 -2
- package/dist/esm/conf.js +9 -1
- package/dist/esm/conf.js.map +2 -2
- package/dist/esm/createComponent.js +5 -8
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/createTamagui.js +72 -78
- package/dist/esm/createTamagui.js.map +2 -2
- package/dist/esm/createVariable.js +7 -0
- package/dist/esm/createVariable.js.map +2 -2
- package/dist/esm/createVariables.js +2 -2
- package/dist/esm/createVariables.js.map +2 -2
- package/dist/esm/helpers/calc.js +49 -0
- package/dist/esm/helpers/calc.js.map +7 -0
- package/dist/esm/helpers/createPropMapper.js +2 -9
- package/dist/esm/helpers/createPropMapper.js.map +2 -2
- package/dist/esm/helpers/getSize.js +15 -6
- package/dist/esm/helpers/getSize.js.map +2 -2
- package/dist/esm/helpers/getStackSize.js +10 -36
- package/dist/esm/helpers/getStackSize.js.map +2 -2
- package/dist/esm/helpers/getTextSize.js +1 -1
- package/dist/esm/helpers/getTextSize.js.map +2 -2
- package/dist/esm/helpers/registerCSSVariable.js +17 -0
- package/dist/esm/helpers/registerCSSVariable.js.map +7 -0
- package/dist/esm/hooks/useFeatures.js.map +2 -2
- package/dist/esm/hooks/useTheme.js +3 -15
- package/dist/esm/hooks/useTheme.js.map +2 -2
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/insertFont.js +57 -0
- package/dist/esm/insertFont.js.map +7 -0
- package/dist/esm/registerCSSVariable.js +17 -0
- package/dist/esm/registerCSSVariable.js.map +7 -0
- package/dist/jsx/conf.js +9 -1
- package/dist/jsx/createComponent.js +5 -8
- package/dist/jsx/createTamagui.js +72 -78
- package/dist/jsx/createVariable.js +7 -0
- package/dist/jsx/createVariables.js +2 -2
- package/dist/jsx/helpers/calc.js +48 -0
- package/dist/jsx/helpers/createPropMapper.js +2 -9
- package/dist/jsx/helpers/getSize.js +15 -6
- package/dist/jsx/helpers/getStackSize.js +10 -36
- package/dist/jsx/helpers/getTextSize.js +1 -1
- package/dist/jsx/helpers/registerCSSVariable.js +16 -0
- package/dist/jsx/hooks/useTheme.js +3 -15
- package/dist/jsx/index.js +2 -0
- package/dist/jsx/insertFont.js +56 -0
- package/dist/jsx/registerCSSVariable.js +16 -0
- package/package.json +5 -5
- package/reset.css +8 -0
- package/types/Tamagui.d.ts +2 -5
- package/types/Tamagui.d.ts.map +1 -1
- package/types/conf.d.ts +2 -3
- package/types/conf.d.ts.map +1 -1
- package/types/createComponent.d.ts.map +1 -1
- package/types/createTamagui.d.ts +2 -1
- package/types/createTamagui.d.ts.map +1 -1
- package/types/createVariable.d.ts +1 -0
- package/types/createVariable.d.ts.map +1 -1
- package/types/createVariables.d.ts +1 -1
- package/types/createVariables.d.ts.map +1 -1
- package/types/helpers/calc.d.ts +12 -0
- package/types/helpers/calc.d.ts.map +1 -0
- package/types/helpers/getSize.d.ts +3 -2
- package/types/helpers/getSize.d.ts.map +1 -1
- package/types/helpers/getStackSize.d.ts +4 -28
- package/types/helpers/getStackSize.d.ts.map +1 -1
- package/types/helpers/getVariantExtras.d.ts +1 -3
- package/types/helpers/getVariantExtras.d.ts.map +1 -1
- package/types/helpers/registerCSSVariable.d.ts +5 -0
- package/types/helpers/registerCSSVariable.d.ts.map +1 -0
- package/types/hooks/useTheme.d.ts.map +1 -1
- package/types/index.d.ts +2 -0
- package/types/index.d.ts.map +1 -1
- package/types/insertFont.d.ts +6 -0
- package/types/insertFont.d.ts.map +1 -0
- package/types/registerCSSVariable.d.ts +5 -0
- package/types/registerCSSVariable.d.ts.map +1 -0
- package/types/types.d.ts +1 -1
- package/types/types.d.ts.map +1 -1
|
@@ -3,10 +3,17 @@ 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 { createVariable, isVariable } from "./createVariable";
|
|
7
|
+
import { createVariables } from "./createVariables";
|
|
7
8
|
import { createTamaguiProvider } from "./helpers/createTamaguiProvider";
|
|
8
9
|
import { getInsertedRules } from "./helpers/insertStyleRule";
|
|
10
|
+
import {
|
|
11
|
+
registerCSSVariable,
|
|
12
|
+
tokenRules,
|
|
13
|
+
tokensValueToVariable
|
|
14
|
+
} from "./helpers/registerCSSVariable";
|
|
9
15
|
import { configureMedia } from "./hooks/useMedia";
|
|
16
|
+
import { parseFont, registerFontVariables } from "./insertFont";
|
|
10
17
|
const createdConfigs = /* @__PURE__ */ new WeakMap();
|
|
11
18
|
function createTamagui(config) {
|
|
12
19
|
if (createdConfigs.has(config)) {
|
|
@@ -19,55 +26,52 @@ function createTamagui(config) {
|
|
|
19
26
|
if (!config.themes) {
|
|
20
27
|
throw new Error(`No themes provided to Tamagui config`);
|
|
21
28
|
}
|
|
29
|
+
if (!config.fonts) {
|
|
30
|
+
throw new Error(`No fonts provided to Tamagui config`);
|
|
31
|
+
}
|
|
22
32
|
}
|
|
23
33
|
if (getHasConfigured()) {
|
|
24
|
-
console.warn(
|
|
34
|
+
console.warn(`Warning: createTamagui called twice (maybe HMR)`);
|
|
25
35
|
}
|
|
26
36
|
configureMedia({
|
|
27
37
|
queries: config.media,
|
|
28
38
|
defaultActive: config.mediaQueryDefaultActive
|
|
29
39
|
});
|
|
40
|
+
const fontTokens = createVariables(config.fonts);
|
|
41
|
+
const fontsParsed = (() => {
|
|
42
|
+
const res = {};
|
|
43
|
+
for (const familyName in fontTokens) {
|
|
44
|
+
res[`$${familyName}`] = parseFont(fontTokens[familyName]);
|
|
45
|
+
}
|
|
46
|
+
return res;
|
|
47
|
+
})();
|
|
30
48
|
const themeConfig = (() => {
|
|
31
|
-
var _a, _b
|
|
49
|
+
var _a, _b;
|
|
32
50
|
const themes = { ...config.themes };
|
|
33
51
|
let cssRules = [];
|
|
34
|
-
const varsByValue = /* @__PURE__ */ new Map();
|
|
35
52
|
if (isWeb) {
|
|
36
|
-
const tokenRules = /* @__PURE__ */ new Set();
|
|
37
|
-
const addVar = /* @__PURE__ */ __name((v) => {
|
|
38
|
-
varsByValue[v.val] = v;
|
|
39
|
-
const rule = `--${createCSSVariable(v.name, false)}:${typeof v.val === "number" ? `${v.val}px` : v.val}`;
|
|
40
|
-
tokenRules.add(rule);
|
|
41
|
-
}, "addVar");
|
|
42
53
|
for (const key in config.tokens) {
|
|
43
54
|
for (const skey in config.tokens[key]) {
|
|
44
55
|
const val = config.tokens[key][skey];
|
|
45
|
-
|
|
46
|
-
for (const fkey in val) {
|
|
47
|
-
if (fkey === "family") {
|
|
48
|
-
addVar(val[fkey]);
|
|
49
|
-
} else {
|
|
50
|
-
for (const fskey in val[fkey]) {
|
|
51
|
-
addVar(val[fkey][fskey]);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
addVar(val);
|
|
57
|
-
}
|
|
56
|
+
registerCSSVariable(val);
|
|
58
57
|
}
|
|
59
58
|
}
|
|
59
|
+
for (const key in fontsParsed) {
|
|
60
|
+
const val = fontsParsed[key];
|
|
61
|
+
registerFontVariables(val);
|
|
62
|
+
}
|
|
60
63
|
const sep = process.env.NODE_ENV === "development" ? config.cssStyleSeparator || " " : "";
|
|
61
64
|
cssRules.push(`:root {${sep}${[...tokenRules].join(`;${sep}`)}${sep}}`);
|
|
62
65
|
}
|
|
63
66
|
const hasDarkLight = "light" in config.themes && "dark" in config.themes;
|
|
64
67
|
const CNP = `.${THEME_CLASSNAME_PREFIX}`;
|
|
65
|
-
const existing = /* @__PURE__ */ new WeakMap();
|
|
66
68
|
const dedupedThemes = {};
|
|
69
|
+
const existing = /* @__PURE__ */ new WeakMap();
|
|
67
70
|
for (const themeName in themes) {
|
|
68
71
|
const rawTheme = themes[themeName];
|
|
69
72
|
if (existing.has(rawTheme)) {
|
|
70
73
|
const e = existing.get(rawTheme);
|
|
74
|
+
themes[themeName] = e.theme;
|
|
71
75
|
e.names.push(themeName);
|
|
72
76
|
continue;
|
|
73
77
|
}
|
|
@@ -80,33 +84,22 @@ function createTamagui(config) {
|
|
|
80
84
|
names: [themeName],
|
|
81
85
|
theme
|
|
82
86
|
};
|
|
83
|
-
existing.set(
|
|
87
|
+
existing.set(config.themes[themeName], dedupedThemes[themeName]);
|
|
84
88
|
}
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
let
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
varName = val.key;
|
|
95
|
-
varVal = val.isFloating ? val.val : createCSSVariable(varName);
|
|
89
|
+
if (isWeb) {
|
|
90
|
+
for (const themeName in dedupedThemes) {
|
|
91
|
+
const { theme, names } = dedupedThemes[themeName];
|
|
92
|
+
let vars = "";
|
|
93
|
+
for (const themeKey in theme) {
|
|
94
|
+
const variable = theme[themeKey];
|
|
95
|
+
let value = null;
|
|
96
|
+
if (variable.isFloating || !tokensValueToVariable.has(variable.val)) {
|
|
97
|
+
value = variable.val;
|
|
96
98
|
} else {
|
|
97
|
-
|
|
98
|
-
varVal = varName ? createCSSVariable(varName) : `${val}`;
|
|
99
|
+
value = tokensValueToVariable.get(variable.val).variable;
|
|
99
100
|
}
|
|
100
|
-
|
|
101
|
-
if (!varName) {
|
|
102
|
-
console.warn("no var name in theme", themeName, themeKey);
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
vars += `--${themeKey}:${varVal};`;
|
|
101
|
+
vars += `--${themeKey}:${value};`;
|
|
107
102
|
}
|
|
108
|
-
}
|
|
109
|
-
if (isWeb) {
|
|
110
103
|
const isDarkOrLightBase = themeName === "dark" || themeName === "light";
|
|
111
104
|
const isDark = themeName.startsWith("dark");
|
|
112
105
|
const selectors = names.map((name) => {
|
|
@@ -120,7 +113,7 @@ function createTamagui(config) {
|
|
|
120
113
|
order.reverse();
|
|
121
114
|
}
|
|
122
115
|
const [stronger, weaker] = order;
|
|
123
|
-
const max = (
|
|
116
|
+
const max = (_a = config.maxDarkLightNesting) != null ? _a : 3;
|
|
124
117
|
new Array(max * 2).fill(void 0).forEach((_, pi) => {
|
|
125
118
|
if (pi % 2 === 1)
|
|
126
119
|
return;
|
|
@@ -133,17 +126,42 @@ function createTamagui(config) {
|
|
|
133
126
|
}
|
|
134
127
|
const rootSep = config.themeClassNameOnRoot ? "" : " ";
|
|
135
128
|
cssRules.push(`${selectors.map((x) => `:root${rootSep}${x}`).join(", ")} {${vars}}`);
|
|
136
|
-
if ((
|
|
129
|
+
if ((_b = config.shouldAddPrefersColorThemes) != null ? _b : true) {
|
|
137
130
|
if (isDarkOrLightBase) {
|
|
138
131
|
cssRules.push(`@media(prefers-color-scheme: ${isDark ? "dark" : "light"}) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
132
|
+
body { background:${theme.background}; color: ${theme.color} }
|
|
133
|
+
:root {${vars} }
|
|
134
|
+
}`);
|
|
142
135
|
}
|
|
143
136
|
}
|
|
144
137
|
}
|
|
145
138
|
}
|
|
146
|
-
|
|
139
|
+
for (const themeName in themes) {
|
|
140
|
+
const cur = [];
|
|
141
|
+
const parents = themeName.split("_").slice(0, -1).map((part) => {
|
|
142
|
+
cur.push(part);
|
|
143
|
+
return cur.join("_");
|
|
144
|
+
});
|
|
145
|
+
if (!parents.length)
|
|
146
|
+
continue;
|
|
147
|
+
themes[themeName] = new Proxy(themes[themeName], {
|
|
148
|
+
get(target, key) {
|
|
149
|
+
if (Reflect.has(target, key)) {
|
|
150
|
+
return Reflect.get(target, key);
|
|
151
|
+
}
|
|
152
|
+
for (let i = parents.length - 1; i >= 0; i--) {
|
|
153
|
+
const parent = themes[parents[i]];
|
|
154
|
+
if (!parent) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (Reflect.has(parent, key)) {
|
|
158
|
+
return Reflect.get(parent, key);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
tokensValueToVariable.clear();
|
|
147
165
|
Object.freeze(cssRules);
|
|
148
166
|
const css = cssRules.join("\n");
|
|
149
167
|
return {
|
|
@@ -153,29 +171,6 @@ function createTamagui(config) {
|
|
|
153
171
|
};
|
|
154
172
|
})();
|
|
155
173
|
const tokensParsed = parseTokens(config.tokens);
|
|
156
|
-
const fontsParsed = (() => {
|
|
157
|
-
if (!config.fonts) {
|
|
158
|
-
throw new Error(`No fonts defined!`);
|
|
159
|
-
}
|
|
160
|
-
const res = {};
|
|
161
|
-
for (const familyName in config.fonts) {
|
|
162
|
-
const family = config.fonts[familyName];
|
|
163
|
-
const parsed = {};
|
|
164
|
-
for (const attrKey in family) {
|
|
165
|
-
const attr = family[attrKey];
|
|
166
|
-
if (attrKey === "family") {
|
|
167
|
-
parsed[attrKey] = attr;
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
|
-
parsed[attrKey] = Object.keys(attr).reduce((acc, cur) => {
|
|
171
|
-
acc[`$${cur}`] = attr[cur];
|
|
172
|
-
return acc;
|
|
173
|
-
}, {});
|
|
174
|
-
}
|
|
175
|
-
res[`$${familyName}`] = parsed;
|
|
176
|
-
}
|
|
177
|
-
return res;
|
|
178
|
-
})();
|
|
179
174
|
const getCSS = /* @__PURE__ */ __name(() => {
|
|
180
175
|
return `${themeConfig.css}
|
|
181
176
|
${getInsertedRules().join("\n")}`;
|
|
@@ -231,8 +226,7 @@ function ensureThemeVariable(theme, key) {
|
|
|
231
226
|
theme[key] = createVariable({
|
|
232
227
|
key: themeKey,
|
|
233
228
|
name: themeKey,
|
|
234
|
-
val
|
|
235
|
-
isFloating: true
|
|
229
|
+
val
|
|
236
230
|
});
|
|
237
231
|
} else {
|
|
238
232
|
if (val.name !== themeKey) {
|
|
@@ -44,6 +44,12 @@ function getVariableName(v) {
|
|
|
44
44
|
return v;
|
|
45
45
|
}
|
|
46
46
|
__name(getVariableName, "getVariableName");
|
|
47
|
+
function getVariableVariable(v) {
|
|
48
|
+
if (isVariable(v))
|
|
49
|
+
return v.variable;
|
|
50
|
+
return v;
|
|
51
|
+
}
|
|
52
|
+
__name(getVariableVariable, "getVariableVariable");
|
|
47
53
|
const createCSSVariable = /* @__PURE__ */ __name((nameProp, includeVar = true) => {
|
|
48
54
|
if (process.env.NODE_ENV === "development") {
|
|
49
55
|
if (!nameProp || typeof nameProp !== "string") {
|
|
@@ -60,5 +66,6 @@ export {
|
|
|
60
66
|
createVariable,
|
|
61
67
|
getVariableName,
|
|
62
68
|
getVariableValue,
|
|
69
|
+
getVariableVariable,
|
|
63
70
|
isVariable
|
|
64
71
|
};
|
|
@@ -20,10 +20,10 @@ const createVariables = /* @__PURE__ */ __name((tokens, parentPath = "") => {
|
|
|
20
20
|
});
|
|
21
21
|
});
|
|
22
22
|
} else {
|
|
23
|
-
res[key] = createVariables(tokens[key], name);
|
|
23
|
+
res[key] = createVariables(tokens[key], name === "color" ? "" : name);
|
|
24
24
|
}
|
|
25
25
|
} else {
|
|
26
|
-
res[key] = createVariable({ val, name, key });
|
|
26
|
+
res[key] = isVariable(val) ? val : createVariable({ val, name, key });
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
return res;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { isWeb } from "../constants/platform";
|
|
4
|
+
import { getVariableVariable } from "../createVariable";
|
|
5
|
+
const operators = {
|
|
6
|
+
"+": (a, b) => a + b,
|
|
7
|
+
"-": (a, b) => a - b,
|
|
8
|
+
"/": (a, b) => a / b,
|
|
9
|
+
"*": (a, b) => a * b
|
|
10
|
+
};
|
|
11
|
+
const calc = /* @__PURE__ */ __name((...valuesAndOperators) => {
|
|
12
|
+
if (isWeb) {
|
|
13
|
+
let res2 = "calc(";
|
|
14
|
+
for (const cur of valuesAndOperators) {
|
|
15
|
+
if (operators[cur]) {
|
|
16
|
+
res2 += " " + cur + " ";
|
|
17
|
+
} else {
|
|
18
|
+
res2 += convertToVariableOrNumber(cur);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return res2 + ")";
|
|
22
|
+
}
|
|
23
|
+
let res = 0;
|
|
24
|
+
let nextOp = null;
|
|
25
|
+
for (const cur of valuesAndOperators) {
|
|
26
|
+
if (operators[cur]) {
|
|
27
|
+
nextOp = operators[cur];
|
|
28
|
+
} else {
|
|
29
|
+
if (nextOp) {
|
|
30
|
+
res = nextOp(res, cur);
|
|
31
|
+
nextOp = null;
|
|
32
|
+
} else {
|
|
33
|
+
res = +cur;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return res;
|
|
38
|
+
}, "calc");
|
|
39
|
+
const convertToVariableOrNumber = /* @__PURE__ */ __name((v) => {
|
|
40
|
+
const varOrVal = getVariableVariable(v);
|
|
41
|
+
if (typeof varOrVal === "number") {
|
|
42
|
+
return `${varOrVal}px`;
|
|
43
|
+
}
|
|
44
|
+
return varOrVal;
|
|
45
|
+
}, "convertToVariableOrNumber");
|
|
46
|
+
export {
|
|
47
|
+
calc
|
|
48
|
+
};
|
|
@@ -132,7 +132,7 @@ const getToken = /* @__PURE__ */ __name((key, value, { tokensParsed, fontsParsed
|
|
|
132
132
|
var _a, _b, _c;
|
|
133
133
|
let valOrVar;
|
|
134
134
|
let hasSet = false;
|
|
135
|
-
if (value
|
|
135
|
+
if (theme[value]) {
|
|
136
136
|
valOrVar = theme[value];
|
|
137
137
|
hasSet = true;
|
|
138
138
|
} else {
|
|
@@ -200,14 +200,7 @@ const tokenCategories = {
|
|
|
200
200
|
minWidth: true,
|
|
201
201
|
minHeight: true,
|
|
202
202
|
maxWidth: true,
|
|
203
|
-
maxHeight: true
|
|
204
|
-
padding: true,
|
|
205
|
-
paddingLeft: true,
|
|
206
|
-
paddingRight: true,
|
|
207
|
-
paddingTop: true,
|
|
208
|
-
paddingBottom: true,
|
|
209
|
-
paddingVertical: true,
|
|
210
|
-
paddingHorizontal: true
|
|
203
|
+
maxHeight: true
|
|
211
204
|
},
|
|
212
205
|
color: {
|
|
213
206
|
color: true,
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
import { getTokens } from "../conf";
|
|
4
|
-
const getSize = /* @__PURE__ */ __name((size,
|
|
5
|
-
|
|
6
|
-
const sizeNames = Object.keys(sizes);
|
|
7
|
-
const key = sizeNames[Math.max(0, sizeNames.indexOf(String(size || "$4")) + sizeUpOrDownBy)];
|
|
8
|
-
return sizes[key] || sizes["$4"];
|
|
4
|
+
const getSize = /* @__PURE__ */ __name((size, shift = 0, bounds = [0]) => {
|
|
5
|
+
return stepTokenUpOrDown(getTokens().size, size, shift, bounds);
|
|
9
6
|
}, "getSize");
|
|
7
|
+
const stepTokenUpOrDown = /* @__PURE__ */ __name((tokens, current, shift = 0, bounds = [0]) => {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
const sizeNames = Object.keys(tokens);
|
|
10
|
+
const currentKeyNum = (typeof current === "string" ? current.replace("$", "") : current) || "4";
|
|
11
|
+
const nextKeyName = `$${+currentKeyNum + shift}`;
|
|
12
|
+
const min = (_a = bounds[0]) != null ? _a : 0;
|
|
13
|
+
const max = (_b = bounds[1]) != null ? _b : sizeNames.length - 1;
|
|
14
|
+
const index = Math.min(max, Math.max(min, sizeNames.indexOf(nextKeyName)));
|
|
15
|
+
const key = sizeNames[index];
|
|
16
|
+
return tokens[key] || tokens["$4"];
|
|
17
|
+
}, "stepTokenUpOrDown");
|
|
10
18
|
export {
|
|
11
|
-
getSize
|
|
19
|
+
getSize,
|
|
20
|
+
stepTokenUpOrDown
|
|
12
21
|
};
|
|
@@ -1,43 +1,17 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import {
|
|
4
|
-
const
|
|
5
|
-
var _a, _b, _c, _d, _e, _f;
|
|
6
|
-
const size = (_c = (_b = (_a = tokens.size[val]) != null ? _a : val) != null ? _b : tokens.size["$4"]) != null ? _c : 14;
|
|
7
|
-
const radius = (_e = (_d = tokens.radius[val]) != null ? _d : tokens.radius["$4"]) != null ? _e : size;
|
|
8
|
-
const sizePx = +(isVariable(size) ? size.val : size);
|
|
9
|
-
const scaleSize = isVariable(size) ? 2 : 1;
|
|
10
|
-
const px = Math.round(sizePx * sizeX);
|
|
11
|
-
const py = Math.round(sizePx * sizeY);
|
|
12
|
-
const font = fonts[props.fontFamily] || fonts["$body"];
|
|
13
|
-
const lineHeights = font.lineHeight;
|
|
14
|
-
const lineHeight = (_f = lineHeights[val]) != null ? _f : lineHeights["$4"];
|
|
15
|
-
const minHeight = Math.round(getVariableValue(lineHeight) + py * scaleSize);
|
|
16
|
-
return {
|
|
17
|
-
px,
|
|
18
|
-
py,
|
|
19
|
-
radius,
|
|
20
|
-
size,
|
|
21
|
-
lineHeight,
|
|
22
|
-
minHeight
|
|
23
|
-
};
|
|
24
|
-
}, "getSizeScaledToFont");
|
|
25
|
-
const createGetStackSize = /* @__PURE__ */ __name((scale) => (val, extras) => {
|
|
3
|
+
import { getSize, stepTokenUpOrDown } from "./getSize";
|
|
4
|
+
const getButtonSize = /* @__PURE__ */ __name((val, { tokens }) => {
|
|
26
5
|
var _a;
|
|
27
|
-
const
|
|
28
|
-
const
|
|
6
|
+
const ySize = getSize(val, 0);
|
|
7
|
+
const xSize = stepTokenUpOrDown(tokens.space, val);
|
|
8
|
+
const radiusToken = (_a = tokens.radius[val]) != null ? _a : tokens.radius["$4"];
|
|
29
9
|
return {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
paddingVertical: props.circular ? 0 : py
|
|
10
|
+
paddingHorizontal: xSize,
|
|
11
|
+
height: ySize,
|
|
12
|
+
borderRadius: radiusToken
|
|
34
13
|
};
|
|
35
|
-
}, "
|
|
36
|
-
const buttonScaling = { sizeX: 0.75, sizeY: 0.333 };
|
|
37
|
-
const getButtonSize = createGetStackSize(buttonScaling);
|
|
14
|
+
}, "getButtonSize");
|
|
38
15
|
export {
|
|
39
|
-
|
|
40
|
-
createGetStackSize,
|
|
41
|
-
getButtonSize,
|
|
42
|
-
getSizeScaledToFont
|
|
16
|
+
getButtonSize
|
|
43
17
|
};
|
|
@@ -7,7 +7,7 @@ const getTextSize = /* @__PURE__ */ __name((val = "$4", { fonts, theme, props })
|
|
|
7
7
|
const font = fonts[family] || fonts["$body"];
|
|
8
8
|
if (!font) {
|
|
9
9
|
console.warn("\u26A0\uFE0F no font found", { family, fontTokens: Object.keys(fonts), val });
|
|
10
|
-
return;
|
|
10
|
+
return {};
|
|
11
11
|
}
|
|
12
12
|
const fontFamily = font.family;
|
|
13
13
|
const fontSize = props.fontSize || font.size[val];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { createCSSVariable } from "../createVariable";
|
|
4
|
+
const registerCSSVariable = /* @__PURE__ */ __name((v) => {
|
|
5
|
+
tokensValueToVariable.set(v.val, v);
|
|
6
|
+
const val = `--${createCSSVariable(v.name, false)}:${typeof v.val === "number" ? `${v.val}px` : v.val}`;
|
|
7
|
+
tokenRules.add(val);
|
|
8
|
+
return val;
|
|
9
|
+
}, "registerCSSVariable");
|
|
10
|
+
const tokensValueToVariable = /* @__PURE__ */ new Map();
|
|
11
|
+
const tokenRules = /* @__PURE__ */ new Set();
|
|
12
|
+
export {
|
|
13
|
+
registerCSSVariable,
|
|
14
|
+
tokenRules,
|
|
15
|
+
tokensValueToVariable
|
|
16
|
+
};
|
|
@@ -51,14 +51,11 @@ const useTheme = /* @__PURE__ */ __name((themeName, componentName, props, forceU
|
|
|
51
51
|
get(_, key) {
|
|
52
52
|
if (!name || key === "__proto__" || typeof key === "symbol") {
|
|
53
53
|
if (key === GetThemeManager) {
|
|
54
|
-
if (process.env.NODE_ENV === "development") {
|
|
55
|
-
|
|
56
|
-
console.log("did change", { themeName, didChangeTheme, name, componentName }, themeManager == null ? void 0 : themeManager.parentName);
|
|
57
|
-
}
|
|
54
|
+
if (process.env.NODE_ENV === "development" && (props == null ? void 0 : props.debug)) {
|
|
55
|
+
console.log(">>", { themeName, didChangeTheme, name, componentName }, themeManager);
|
|
58
56
|
}
|
|
59
|
-
if (!didChangeTheme)
|
|
57
|
+
if (!didChangeTheme)
|
|
60
58
|
return null;
|
|
61
|
-
}
|
|
62
59
|
return themeManager;
|
|
63
60
|
}
|
|
64
61
|
return Reflect.get(_, key);
|
|
@@ -66,11 +63,6 @@ const useTheme = /* @__PURE__ */ __name((themeName, componentName, props, forceU
|
|
|
66
63
|
if (typeof key !== "string" || key === "$typeof") {
|
|
67
64
|
return Reflect.get(_, key);
|
|
68
65
|
}
|
|
69
|
-
if (process.env.NODE_ENV === "development") {
|
|
70
|
-
if (key === "__state") {
|
|
71
|
-
return state.current;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
66
|
if (key === "name") {
|
|
75
67
|
return name;
|
|
76
68
|
}
|
|
@@ -96,10 +88,6 @@ const useTheme = /* @__PURE__ */ __name((themeName, componentName, props, forceU
|
|
|
96
88
|
}
|
|
97
89
|
return val;
|
|
98
90
|
}
|
|
99
|
-
if (process.env.NODE_ENV === "development") {
|
|
100
|
-
console.log(`No theme value "${String(key)}" in ${name}`);
|
|
101
|
-
}
|
|
102
|
-
return Reflect.get(_, key);
|
|
103
91
|
}
|
|
104
92
|
});
|
|
105
93
|
}, [name, theme, className, didChangeTheme]);
|
package/dist/jsx/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./createFont";
|
|
|
7
7
|
export * from "./createTokens";
|
|
8
8
|
export * from "./createVariable";
|
|
9
9
|
export * from "./createVariables";
|
|
10
|
+
export * from "./insertFont";
|
|
10
11
|
export * from "./styled";
|
|
11
12
|
export * from "./types";
|
|
12
13
|
import { RNWTextProps, RNWViewProps } from "./types-rnw";
|
|
@@ -14,6 +15,7 @@ import { getHasConfigured, getConfig, getThemes, getTokens, onConfiguredOnce } f
|
|
|
14
15
|
export * from "./constants/constants";
|
|
15
16
|
export * from "./constants/platform";
|
|
16
17
|
export * from "./constants/rnw";
|
|
18
|
+
export * from "./helpers/calc";
|
|
17
19
|
export * from "./helpers/createShallowUpdate";
|
|
18
20
|
export * from "./helpers/getStackSize";
|
|
19
21
|
export * from "./helpers/getVariantExtras";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { setConfigFont } from "./conf";
|
|
4
|
+
import { createFont } from "./createFont";
|
|
5
|
+
import { createVariables } from "./createVariables";
|
|
6
|
+
import { registerCSSVariable } from "./helpers/registerCSSVariable";
|
|
7
|
+
function insertFont(name, fontIn) {
|
|
8
|
+
const font = createFont(fontIn);
|
|
9
|
+
const tokened = createVariables(font, name);
|
|
10
|
+
const parsed = parseFont(tokened);
|
|
11
|
+
registerFontVariables(parsed);
|
|
12
|
+
setConfigFont(name, parsed);
|
|
13
|
+
return parsed;
|
|
14
|
+
}
|
|
15
|
+
__name(insertFont, "insertFont");
|
|
16
|
+
function parseFont(definition) {
|
|
17
|
+
const parsed = {};
|
|
18
|
+
for (const attrKey in definition) {
|
|
19
|
+
const attr = definition[attrKey];
|
|
20
|
+
if (attrKey === "family") {
|
|
21
|
+
parsed[attrKey] = attr;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
parsed[attrKey] = {};
|
|
25
|
+
for (const key in attr) {
|
|
26
|
+
let val = attr[key];
|
|
27
|
+
if (val.val[0] === "$") {
|
|
28
|
+
val = val.val;
|
|
29
|
+
}
|
|
30
|
+
parsed[attrKey][`$${key}`] = val;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return parsed;
|
|
34
|
+
}
|
|
35
|
+
__name(parseFont, "parseFont");
|
|
36
|
+
function registerFontVariables(parsedFont) {
|
|
37
|
+
for (const fkey in parsedFont) {
|
|
38
|
+
if (fkey === "family") {
|
|
39
|
+
registerCSSVariable(parsedFont[fkey]);
|
|
40
|
+
} else {
|
|
41
|
+
for (const fskey in parsedFont[fkey]) {
|
|
42
|
+
const fval = parsedFont[fkey][fskey];
|
|
43
|
+
if (typeof fval === "string") {
|
|
44
|
+
} else {
|
|
45
|
+
registerCSSVariable(parsedFont[fkey][fskey]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
__name(registerFontVariables, "registerFontVariables");
|
|
52
|
+
export {
|
|
53
|
+
insertFont,
|
|
54
|
+
parseFont,
|
|
55
|
+
registerFontVariables
|
|
56
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { createCSSVariable } from "./createVariable";
|
|
4
|
+
const registerCSSVariable = /* @__PURE__ */ __name((v) => {
|
|
5
|
+
tokensValueToVariable.set(v.val, v);
|
|
6
|
+
const val = `--${createCSSVariable(v.name, false)}:${typeof v.val === "number" ? `${v.val}px` : v.val}`;
|
|
7
|
+
tokenRules.add(val);
|
|
8
|
+
return val;
|
|
9
|
+
}, "registerCSSVariable");
|
|
10
|
+
const tokensValueToVariable = /* @__PURE__ */ new Map();
|
|
11
|
+
const tokenRules = /* @__PURE__ */ new Set();
|
|
12
|
+
export {
|
|
13
|
+
registerCSSVariable,
|
|
14
|
+
tokenRules,
|
|
15
|
+
tokensValueToVariable
|
|
16
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/core",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.57",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@expo/match-media": "^0.3.0",
|
|
24
|
-
"@tamagui/helpers": "^1.0.1-beta.
|
|
24
|
+
"@tamagui/helpers": "^1.0.1-beta.57",
|
|
25
25
|
"@tamagui/ow": "^0.28.1",
|
|
26
|
-
"@tamagui/use-debounce": "^1.0.1-beta.
|
|
27
|
-
"@tamagui/use-force-update": "^1.0.1-beta.
|
|
26
|
+
"@tamagui/use-debounce": "^1.0.1-beta.57",
|
|
27
|
+
"@tamagui/use-force-update": "^1.0.1-beta.57",
|
|
28
28
|
"expo-screen-orientation": "^4.2.0",
|
|
29
29
|
"hyphenate-style-name": "^1.0.4",
|
|
30
30
|
"inline-style-prefixer": "^6.0.0",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"react-native-web": "*"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@tamagui/build": "^1.0.1-beta.
|
|
39
|
+
"@tamagui/build": "^1.0.1-beta.57",
|
|
40
40
|
"@types/react": "^17.0.35",
|
|
41
41
|
"csstype": "^3.0.10",
|
|
42
42
|
"esbuild": "^0.14.36",
|
package/reset.css
CHANGED
package/types/Tamagui.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as Helpers from '@tamagui/helpers';
|
|
2
|
-
import { TamaguiInternalConfig } from './types';
|
|
3
2
|
declare class TamaguiManager {
|
|
4
3
|
rnw: any;
|
|
5
4
|
Helpers: typeof Helpers;
|
|
6
|
-
get config(): TamaguiInternalConfig<import("./types").CreateTokens<import("./types").VariableVal>, {
|
|
5
|
+
get config(): import("./types").TamaguiInternalConfig<import("./types").CreateTokens<import("./types").VariableVal>, {
|
|
7
6
|
[key: string]: Partial<import("./types").TamaguiBaseTheme> & {
|
|
8
7
|
[key: string]: import("./types").VariableVal;
|
|
9
8
|
};
|
|
@@ -15,9 +14,7 @@ declare class TamaguiManager {
|
|
|
15
14
|
[key: string]: string | {
|
|
16
15
|
[key: string]: any;
|
|
17
16
|
};
|
|
18
|
-
},
|
|
19
|
-
[key: string]: import("./types").GenericFont<string | number>;
|
|
20
|
-
}>;
|
|
17
|
+
}, import("./types").GenericFonts>;
|
|
21
18
|
get insertedRules(): unknown[];
|
|
22
19
|
get allSelectors(): {};
|
|
23
20
|
get allTransforms(): {};
|
package/types/Tamagui.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tamagui.d.ts","sourceRoot":"","sources":["../src/Tamagui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"Tamagui.d.ts","sourceRoot":"","sources":["../src/Tamagui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAA;AAQ3C,cAAM,cAAc;IAClB,GAAG,MAAM;IACT,OAAO,iBAAU;IAEjB,IAAI,MAAM;;;;;;;;;;;;uCAET;IAED,IAAI,aAAa,cAEhB;IAED,IAAI,YAAY,OAEf;IAED,IAAI,aAAa,OAEhB;IAED,IAAI,iBAAiB,qBAEpB;CACF;AAED,eAAO,MAAM,OAAO,gBAAuB,CAAA;AAI3C,eAAO,MAAM,sBAAsB,eAAgB,MAAM,QAExD,CAAA;AAED,eAAO,MAAM,kBAAkB,eAAgB,MAAM,SAAS,GAAG,SAEhE,CAAA"}
|