@tamagui/web 1.46.0 → 1.46.2
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/createComponent.js +12 -11
- package/dist/cjs/createComponent.js.map +1 -1
- package/dist/cjs/createTamagui.js +45 -43
- package/dist/cjs/createTamagui.js.map +1 -1
- package/dist/cjs/helpers/expandStyles.js +2 -5
- package/dist/cjs/helpers/expandStyles.js.map +1 -1
- package/dist/cjs/helpers/getSplitStyles.js +2 -2
- package/dist/cjs/helpers/getSplitStyles.js.map +1 -1
- package/dist/cjs/helpers/getThemeCSSRules.js +89 -91
- package/dist/cjs/helpers/getThemeCSSRules.js.map +1 -1
- package/dist/esm/createComponent.js +12 -11
- package/dist/esm/createComponent.js.map +1 -1
- package/dist/esm/createTamagui.js +45 -43
- package/dist/esm/createTamagui.js.map +1 -1
- package/dist/esm/helpers/expandStyles.js +2 -5
- package/dist/esm/helpers/expandStyles.js.map +1 -1
- package/dist/esm/helpers/getSplitStyles.js +2 -2
- package/dist/esm/helpers/getSplitStyles.js.map +1 -1
- package/dist/esm/helpers/getThemeCSSRules.js +89 -91
- package/dist/esm/helpers/getThemeCSSRules.js.map +1 -1
- package/package.json +9 -9
- package/src/createComponent.tsx +19 -13
- package/src/createTamagui.ts +56 -54
- package/src/helpers/expandStyles.ts +2 -9
- package/src/helpers/getSplitStyles.tsx +4 -10
- package/src/helpers/getThemeCSSRules.ts +127 -126
- package/types/createComponent.d.ts.map +1 -1
- package/types/createTamagui.d.ts.map +1 -1
- package/types/helpers/expandStyles.d.ts +1 -1
- package/types/helpers/expandStyles.d.ts.map +1 -1
- package/types/helpers/getSplitStyles.d.ts.map +1 -1
- package/types/helpers/getThemeCSSRules.d.ts +1 -1
- package/types/helpers/getThemeCSSRules.d.ts.map +1 -1
|
@@ -2,106 +2,104 @@ import { simpleHash } from "@tamagui/helpers";
|
|
|
2
2
|
import { THEME_CLASSNAME_PREFIX } from "../constants/constants";
|
|
3
3
|
import { variableToString } from "../createVariable";
|
|
4
4
|
import { tokensValueToVariable } from "./registerCSSVariable";
|
|
5
|
-
function getThemeCSSRules({
|
|
6
|
-
config,
|
|
7
|
-
themeName,
|
|
8
|
-
theme,
|
|
9
|
-
names
|
|
10
|
-
}) {
|
|
5
|
+
function getThemeCSSRules(props) {
|
|
11
6
|
const cssRuleSets = [];
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
value =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
const isDarkOrLightBase = themeName === "dark" || themeName === "light";
|
|
26
|
-
const baseSelectors = names.map((name) => `${CNP}${name}`);
|
|
27
|
-
const selectorsSet = new Set(baseSelectors);
|
|
28
|
-
if (hasDarkLight) {
|
|
29
|
-
for (const subName of names) {
|
|
30
|
-
const isDark = themeName === "dark" || subName.startsWith("dark_");
|
|
31
|
-
const isLight = themeName === "light" || themeName.startsWith("light_");
|
|
32
|
-
const maxDepth = config.maxDarkLightNesting ?? 3;
|
|
33
|
-
if (!(isDark || isLight)) {
|
|
34
|
-
selectorsSet.add(`:root:root ${CNP}${subName}`);
|
|
35
|
-
continue;
|
|
7
|
+
if (process.env.TAMAGUI_DOES_SSR_CSS !== "true") {
|
|
8
|
+
const { config, themeName, theme, names } = props;
|
|
9
|
+
const hasDarkLight = "light" in config.themes && "dark" in config.themes;
|
|
10
|
+
const CNP = `.${THEME_CLASSNAME_PREFIX}`;
|
|
11
|
+
let vars = "";
|
|
12
|
+
for (const themeKey in theme) {
|
|
13
|
+
const variable = theme[themeKey];
|
|
14
|
+
let value = null;
|
|
15
|
+
if (!tokensValueToVariable.has(variable.val)) {
|
|
16
|
+
value = variable.val;
|
|
17
|
+
} else {
|
|
18
|
+
value = tokensValueToVariable.get(variable.val).variable;
|
|
36
19
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
20
|
+
vars += `--${simpleHash(themeKey, 40)}:${value};`;
|
|
21
|
+
}
|
|
22
|
+
const isDarkOrLightBase = themeName === "dark" || themeName === "light";
|
|
23
|
+
const baseSelectors = names.map((name) => `${CNP}${name}`);
|
|
24
|
+
const selectorsSet = new Set(baseSelectors);
|
|
25
|
+
if (hasDarkLight) {
|
|
26
|
+
for (const subName of names) {
|
|
27
|
+
const isDark = themeName === "dark" || subName.startsWith("dark_");
|
|
28
|
+
const isLight = themeName === "light" || themeName.startsWith("light_");
|
|
29
|
+
const maxDepth = config.maxDarkLightNesting ?? 3;
|
|
30
|
+
if (!(isDark || isLight)) {
|
|
31
|
+
selectorsSet.add(`:root:root ${CNP}${subName}`);
|
|
32
|
+
continue;
|
|
45
33
|
}
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
34
|
+
const childSelector = `${CNP}${subName.replace(/^(dark|light)_/, "")}`;
|
|
35
|
+
const [altLightDark, altSubTheme] = [
|
|
36
|
+
isDark ? ["dark", "light"] : ["light", "dark"],
|
|
37
|
+
isDark ? ["dark", "sub_theme"] : ["light", "sub_theme"]
|
|
38
|
+
];
|
|
39
|
+
for (const order of [altLightDark, altSubTheme]) {
|
|
40
|
+
if (isDarkOrLightBase) {
|
|
41
|
+
order.reverse();
|
|
52
42
|
}
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
43
|
+
const [stronger, weaker] = order;
|
|
44
|
+
const numSelectors = Math.round(maxDepth * 1.5);
|
|
45
|
+
for (let depth = 0; depth < numSelectors; depth++) {
|
|
46
|
+
const isOdd = depth % 2 === 1;
|
|
47
|
+
if (isOdd && depth < 3) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const parents = new Array(depth + 1).fill(0).map((_, psi) => {
|
|
51
|
+
return `${CNP}${psi % 2 === 0 ? stronger : weaker}`;
|
|
52
|
+
});
|
|
53
|
+
let parentSelectors = parents.length > 1 ? parents.slice(1) : parents;
|
|
54
|
+
if (isOdd) {
|
|
55
|
+
const [_first, second, ...rest] = parentSelectors;
|
|
56
|
+
parentSelectors = [second, ...rest, second];
|
|
57
|
+
}
|
|
58
|
+
const lastParentSelector = parentSelectors[parentSelectors.length - 1];
|
|
59
|
+
const nextChildSelector = childSelector === lastParentSelector ? "" : childSelector;
|
|
60
|
+
selectorsSet.add(`${parentSelectors.join(" ")} ${nextChildSelector}`.trim());
|
|
60
61
|
}
|
|
61
|
-
const lastParentSelector = parentSelectors[parentSelectors.length - 1];
|
|
62
|
-
const nextChildSelector = childSelector === lastParentSelector ? "" : childSelector;
|
|
63
|
-
selectorsSet.add(`${parentSelectors.join(" ")} ${nextChildSelector}`.trim());
|
|
64
62
|
}
|
|
65
63
|
}
|
|
66
64
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
65
|
+
const selectors = [...selectorsSet].sort((a, b) => a.localeCompare(b));
|
|
66
|
+
const selectorsString = selectors.map((x) => {
|
|
67
|
+
const rootSep = isBaseTheme(x) && config.themeClassNameOnRoot ? "" : " ";
|
|
68
|
+
return `:root${rootSep}${x}`;
|
|
69
|
+
}).join(", ");
|
|
70
|
+
const css = `${selectorsString} {${vars}}`;
|
|
71
|
+
cssRuleSets.push(css);
|
|
72
|
+
if (config.shouldAddPrefersColorThemes) {
|
|
73
|
+
const bgString = theme.background ? `background:${variableToString(theme.background)};` : "";
|
|
74
|
+
const fgString = theme.color ? `color:${variableToString(theme.color)}` : "";
|
|
75
|
+
const bodyRules = `body{${bgString}${fgString}}`;
|
|
76
|
+
const isDark = themeName.startsWith("dark");
|
|
77
|
+
const baseName = isDark ? "dark" : "light";
|
|
78
|
+
const lessSpecificSelectors = selectors.map((x) => {
|
|
79
|
+
if (x == darkSelector || x === lightSelector)
|
|
80
|
+
return `:root`;
|
|
81
|
+
if (isDark && x.startsWith(lightSelector) || !isDark && x.startsWith(darkSelector)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
return x.replace(/^\.t_(dark|light) /, "").trim();
|
|
85
|
+
}).filter(Boolean).join(", ");
|
|
86
|
+
const themeRules = `${lessSpecificSelectors} {${vars}}`;
|
|
87
|
+
const prefersMediaSelectors = `@media(prefers-color-scheme:${baseName}){
|
|
88
|
+
${bodyRules}
|
|
89
|
+
${themeRules}
|
|
90
|
+
}`;
|
|
91
|
+
cssRuleSets.push(prefersMediaSelectors);
|
|
92
|
+
}
|
|
93
|
+
if (config.selectionStyles) {
|
|
94
|
+
const selectionSelectors = baseSelectors.map((s) => `${s} ::selection`).join(", ");
|
|
95
|
+
const rules = config.selectionStyles(theme);
|
|
96
|
+
if (rules) {
|
|
97
|
+
const styles = Object.entries(rules).flatMap(
|
|
98
|
+
([k, v]) => v ? `${k === "backgroundColor" ? "background" : k}:${variableToString(v)}` : []
|
|
99
|
+
).join(";");
|
|
100
|
+
const css2 = `${selectionSelectors} {${styles}}`;
|
|
101
|
+
cssRuleSets.push(css2);
|
|
86
102
|
}
|
|
87
|
-
return x.replace(/^\.t_(dark|light) /, "").trim();
|
|
88
|
-
}).filter(Boolean).join(", ");
|
|
89
|
-
const themeRules = `${lessSpecificSelectors} {${vars}}`;
|
|
90
|
-
const prefersMediaSelectors = `@media(prefers-color-scheme:${baseName}){
|
|
91
|
-
${bodyRules}
|
|
92
|
-
${themeRules}
|
|
93
|
-
}`;
|
|
94
|
-
cssRuleSets.push(prefersMediaSelectors);
|
|
95
|
-
}
|
|
96
|
-
if (config.selectionStyles) {
|
|
97
|
-
const selectionSelectors = baseSelectors.map((s) => `${s} ::selection`).join(", ");
|
|
98
|
-
const rules = config.selectionStyles(theme);
|
|
99
|
-
if (rules) {
|
|
100
|
-
const styles = Object.entries(rules).flatMap(
|
|
101
|
-
([k, v]) => v ? `${k === "backgroundColor" ? "background" : k}:${variableToString(v)}` : []
|
|
102
|
-
).join(";");
|
|
103
|
-
const css2 = `${selectionSelectors} {${styles}}`;
|
|
104
|
-
cssRuleSets.push(css2);
|
|
105
103
|
}
|
|
106
104
|
}
|
|
107
105
|
return cssRuleSets;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/helpers/getThemeCSSRules.ts"],
|
|
4
|
-
"mappings": "AAAA,SAAS,kBAAkB;AAE3B,SAAS,8BAA8B;AACvC,SAAmB,wBAAwB;AAE3C,SAAS,6BAA6B;AAE/B,SAAS,iBAAiB;
|
|
4
|
+
"mappings": "AAAA,SAAS,kBAAkB;AAE3B,SAAS,8BAA8B;AACvC,SAAmB,wBAAwB;AAE3C,SAAS,6BAA6B;AAE/B,SAAS,iBAAiB,OAK9B;AACD,QAAM,cAAwB,CAAC;AAE/B,MAAI,QAAQ,IAAI,yBAAyB,QAAQ;AAC/C,UAAM,EAAE,QAAQ,WAAW,OAAO,MAAM,IAAI;AAG5C,UAAM,eAAe,WAAW,OAAO,UAAU,UAAU,OAAO;AAClE,UAAM,MAAM,IAAI;AAChB,QAAI,OAAO;AAIX,eAAW,YAAY,OAAO;AAC5B,YAAM,WAAW,MAAM,QAAQ;AAC/B,UAAI,QAAa;AAEjB,UAAI,CAAC,sBAAsB,IAAI,SAAS,GAAG,GAAG;AAC5C,gBAAQ,SAAS;AAAA,MACnB,OAAO;AACL,gBAAQ,sBAAsB,IAAI,SAAS,GAAG,EAAG;AAAA,MACnD;AAEA,cAAQ,KAAK,WAAW,UAAU,EAAE,KAAK;AAAA,IAC3C;AAEA,U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AY,KAAK,qBAAqB;AAAA,IACxC;AAEA,QAAI,OAAO,iBAAiB;AAC1B,YAAM,qBAAqB,cAAc,IAAI,CAAC,MAAM,GAAG,eAAe,EAAE,KAAK,IAAI;AACjF,YAAM,QAAQ,OAAO,gBAAgB,KAAK;AAC1C,UAAI,OAAO;AACT,cAAM,SAAS,OAAO,QAAQ,KAAK,EAChC;AAAA,UAAQ,CAAC,CAAC,GAAG,CAAC,MACb,IACI,GAAG,MAAM,oBAAoB,eAAe,KAAK,iBAAiB,CAAC,MACnE,CAAC;AAAA,QACP,EACC,KAAK,GAAG;AACX,cAAMA,OAAM,GAAG,uBAAuB;AACtC,oBAAY,KAAKA,IAAG;AAAA,MACtB;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEA,MAAM,eAAe;AACrB,MAAM,gBAAgB;AACtB,MAAM,cAAc,CAAC,MACnB,MAAM,gBACN,MAAM,iBACN,EAAE,WAAW,UAAU,KACvB,EAAE,WAAW,WAAW;",
|
|
5
5
|
"names": ["css"]
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/web",
|
|
3
|
-
"version": "1.46.
|
|
3
|
+
"version": "1.46.2",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -27,19 +27,19 @@
|
|
|
27
27
|
"reset.css"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@tamagui/compose-refs": "1.46.
|
|
31
|
-
"@tamagui/constants": "1.46.
|
|
32
|
-
"@tamagui/helpers": "1.46.
|
|
33
|
-
"@tamagui/normalize-css-color": "1.46.
|
|
34
|
-
"@tamagui/use-did-finish-ssr": "1.46.
|
|
35
|
-
"@tamagui/use-event": "1.46.
|
|
36
|
-
"@tamagui/use-force-update": "1.46.
|
|
30
|
+
"@tamagui/compose-refs": "1.46.2",
|
|
31
|
+
"@tamagui/constants": "1.46.2",
|
|
32
|
+
"@tamagui/helpers": "1.46.2",
|
|
33
|
+
"@tamagui/normalize-css-color": "1.46.2",
|
|
34
|
+
"@tamagui/use-did-finish-ssr": "1.46.2",
|
|
35
|
+
"@tamagui/use-event": "1.46.2",
|
|
36
|
+
"@tamagui/use-force-update": "1.46.2"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"react": "*"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@tamagui/build": "1.46.
|
|
42
|
+
"@tamagui/build": "1.46.2",
|
|
43
43
|
"@testing-library/react": "^13.4.0",
|
|
44
44
|
"csstype": "^3.0.10",
|
|
45
45
|
"react": "^18.2.0",
|
package/src/createComponent.tsx
CHANGED
|
@@ -263,9 +263,6 @@ export function createComponent<
|
|
|
263
263
|
if (isServer) return false
|
|
264
264
|
const curState = stateRef.current
|
|
265
265
|
const next = !!(hasAnimationProp && !isHOC && useAnimations)
|
|
266
|
-
if (next && !curState.hasAnimated) {
|
|
267
|
-
curState.hasAnimated = true
|
|
268
|
-
}
|
|
269
266
|
return Boolean(next || curState.hasAnimated)
|
|
270
267
|
})()
|
|
271
268
|
|
|
@@ -292,6 +289,8 @@ export function createComponent<
|
|
|
292
289
|
? { ...states[0], [propsIn.forceStyle]: true }
|
|
293
290
|
: states[0]
|
|
294
291
|
const setState = states[1]
|
|
292
|
+
|
|
293
|
+
// TODO performance optimization could avoid useCallback and just have this be setStateShallow(setState, state) at call-sites
|
|
295
294
|
const setStateShallow = useShallowSetState(setState, debugProp, componentName)
|
|
296
295
|
|
|
297
296
|
let isAnimated = willBeAnimated
|
|
@@ -616,19 +615,26 @@ export function createComponent<
|
|
|
616
615
|
|
|
617
616
|
const shouldSetMounted = needsMount && state.unmounted
|
|
618
617
|
|
|
619
|
-
// combined
|
|
620
|
-
// because no need for mouseUp removal effect if its not even mounted yet
|
|
618
|
+
// combined multiple effects into one for performance so be careful with logic
|
|
621
619
|
useIsomorphicLayoutEffect(() => {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
}
|
|
620
|
+
// once animated, always animated to preserve hooks
|
|
621
|
+
if (willBeAnimated && !stateRef.current.hasAnimated) {
|
|
622
|
+
stateRef.current.hasAnimated = true
|
|
626
623
|
}
|
|
627
624
|
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
625
|
+
if (shouldSetMounted) {
|
|
626
|
+
const unmounted =
|
|
627
|
+
state.unmounted === true && hasEnterStyle ? 'should-enter' : false
|
|
628
|
+
setStateShallow({
|
|
629
|
+
unmounted,
|
|
630
|
+
})
|
|
631
|
+
return
|
|
632
|
+
// no need for mouseUp removal effect if its not even mounted yet
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
return () => {
|
|
636
|
+
mouseUps.delete(unPress)
|
|
637
|
+
}
|
|
632
638
|
}, [shouldSetMounted, state.unmounted])
|
|
633
639
|
|
|
634
640
|
let styles: Record<string, any>[] | undefined
|
package/src/createTamagui.ts
CHANGED
|
@@ -74,68 +74,70 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
|
|
|
74
74
|
const themes = { ...configIn.themes }
|
|
75
75
|
const cssRuleSets: string[] = []
|
|
76
76
|
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
for (const
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
77
|
+
if (process.env.TAMAGUI_DOES_SSR_CSS !== 'true') {
|
|
78
|
+
if (isWeb) {
|
|
79
|
+
const declarations: string[] = []
|
|
80
|
+
const fontDeclarations: Record<
|
|
81
|
+
string,
|
|
82
|
+
{ name: string; declarations: string[]; language?: string }
|
|
83
|
+
> = {}
|
|
84
|
+
|
|
85
|
+
for (const key in configIn.tokens) {
|
|
86
|
+
for (const skey in configIn.tokens[key]) {
|
|
87
|
+
const variable = configIn.tokens[key][skey] as Variable
|
|
88
|
+
|
|
89
|
+
// set specific tokens (like $size.sm)
|
|
90
|
+
specificTokens[`$${key}.${skey}`] = variable
|
|
91
|
+
|
|
92
|
+
if (process.env.NODE_ENV === 'development') {
|
|
93
|
+
if (typeof variable === 'undefined') {
|
|
94
|
+
throw new Error(
|
|
95
|
+
`No value for tokens.${key}.${skey}:\n${JSON.stringify(
|
|
96
|
+
variable,
|
|
97
|
+
null,
|
|
98
|
+
2
|
|
99
|
+
)}`
|
|
100
|
+
)
|
|
101
|
+
}
|
|
100
102
|
}
|
|
101
|
-
}
|
|
102
103
|
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
registerCSSVariable(variable)
|
|
105
|
+
declarations.push(variableToCSS(variable, key === 'zIndex'))
|
|
106
|
+
}
|
|
105
107
|
}
|
|
106
|
-
}
|
|
107
108
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
109
|
+
for (const key in fontsParsed) {
|
|
110
|
+
const fontParsed = fontsParsed[key]
|
|
111
|
+
const [name, language] = key.includes('_') ? key.split('_') : [key]
|
|
112
|
+
const fontVars = registerFontVariables(fontParsed)
|
|
113
|
+
fontDeclarations[key] = {
|
|
114
|
+
name: name.slice(1),
|
|
115
|
+
declarations: fontVars,
|
|
116
|
+
language,
|
|
117
|
+
}
|
|
116
118
|
}
|
|
117
|
-
}
|
|
118
119
|
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
const sep =
|
|
121
|
+
process.env.NODE_ENV === 'development' ? configIn.cssStyleSeparator || ' ' : ''
|
|
121
122
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
function declarationsToRuleSet(decs: string[], selector = '') {
|
|
124
|
+
return `:root${selector} {${sep}${[...decs].join(`;${sep}`)}${sep}}`
|
|
125
|
+
}
|
|
125
126
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
127
|
+
// non-font
|
|
128
|
+
cssRuleSets.push(declarationsToRuleSet(declarations))
|
|
129
|
+
|
|
130
|
+
// fonts
|
|
131
|
+
if (fontDeclarations) {
|
|
132
|
+
for (const key in fontDeclarations) {
|
|
133
|
+
const { name, declarations, language = 'default' } = fontDeclarations[key]
|
|
134
|
+
const fontSelector = `.font_${name}`
|
|
135
|
+
const langSelector = `:root .t_lang-${name}-${language} ${fontSelector}`
|
|
136
|
+
const selectors =
|
|
137
|
+
language === 'default' ? ` ${fontSelector}, ${langSelector}` : langSelector
|
|
138
|
+
const specificRuleSet = declarationsToRuleSet(declarations, selectors)
|
|
139
|
+
cssRuleSets.push(specificRuleSet)
|
|
140
|
+
}
|
|
139
141
|
}
|
|
140
142
|
}
|
|
141
143
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isWeb } from '@tamagui/constants'
|
|
2
2
|
|
|
3
|
-
import { getConfig } from '../config'
|
|
4
3
|
import { expandStyle } from './expandStyle'
|
|
5
4
|
import { normalizeShadow } from './normalizeShadow'
|
|
6
5
|
import { normalizeValueWithProperty } from './normalizeValueWithProperty'
|
|
@@ -14,18 +13,12 @@ import { pseudoDescriptors } from './pseudoDescriptors'
|
|
|
14
13
|
* 3. Expands react-native shorthands, ie paddingHorizontal => paddingLeft, paddingRight
|
|
15
14
|
*/
|
|
16
15
|
|
|
17
|
-
export function expandStylesAndRemoveNullishValues(
|
|
18
|
-
style: Record<string, any>,
|
|
19
|
-
{ shorthands } = getConfig()
|
|
20
|
-
) {
|
|
16
|
+
export function expandStylesAndRemoveNullishValues(style: Record<string, any>) {
|
|
21
17
|
const res: Record<string, any> = {}
|
|
22
18
|
|
|
23
19
|
for (let key in style) {
|
|
24
20
|
const valIn = style[key]
|
|
25
|
-
if (valIn == null)
|
|
26
|
-
continue
|
|
27
|
-
}
|
|
28
|
-
key = shorthands?.[key] || key
|
|
21
|
+
if (valIn == null) continue
|
|
29
22
|
if (key in pseudoDescriptors) {
|
|
30
23
|
res[key] = expandStylesAndRemoveNullishValues(valIn)
|
|
31
24
|
continue
|
|
@@ -178,6 +178,8 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
178
178
|
|
|
179
179
|
// handle before the loop so we can mark usedKeys in className
|
|
180
180
|
// since the compiler will optimize to className we just treat className as the more powerful
|
|
181
|
+
// TODO the compiler should probably just leave things inline if its not flattening
|
|
182
|
+
// that way it keeps merging order
|
|
181
183
|
if (typeof props.className === 'string') {
|
|
182
184
|
for (const cn of props.className.split(' ')) {
|
|
183
185
|
if (cn[0] === '_') {
|
|
@@ -630,8 +632,8 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
630
632
|
)
|
|
631
633
|
|
|
632
634
|
const descriptor = pseudoDescriptors[key as keyof typeof pseudoDescriptors]
|
|
633
|
-
const isEnter =
|
|
634
|
-
const isExit =
|
|
635
|
+
const isEnter = key === 'enterStyle'
|
|
636
|
+
const isExit = key === 'exitStyle'
|
|
635
637
|
|
|
636
638
|
// dev-time warning that helps clear confusion around need for animation when using enter/exit style
|
|
637
639
|
if (
|
|
@@ -718,14 +720,6 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
718
720
|
console.groupEnd()
|
|
719
721
|
}
|
|
720
722
|
|
|
721
|
-
// if (!isDisabled) {
|
|
722
|
-
// if (valInit === staticConfig.defaultProps[keyInit]) {
|
|
723
|
-
// // ignore:
|
|
724
|
-
// // if it's a default property given by styled(), we don't mark it as used, so
|
|
725
|
-
// // that props given inline can override:
|
|
726
|
-
// }
|
|
727
|
-
// }
|
|
728
|
-
|
|
729
723
|
const importance = descriptor.priority
|
|
730
724
|
|
|
731
725
|
if (!isDisabled) {
|