@tamagui/web 1.46.0 → 1.46.1
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/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/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/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/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
|
@@ -5,12 +5,7 @@ import { Variable, variableToString } from '../createVariable'
|
|
|
5
5
|
import type { CreateTamaguiProps, ThemeParsed } from '../types'
|
|
6
6
|
import { tokensValueToVariable } from './registerCSSVariable'
|
|
7
7
|
|
|
8
|
-
export function getThemeCSSRules({
|
|
9
|
-
config,
|
|
10
|
-
themeName,
|
|
11
|
-
theme,
|
|
12
|
-
names,
|
|
13
|
-
}: {
|
|
8
|
+
export function getThemeCSSRules(props: {
|
|
14
9
|
config: CreateTamaguiProps
|
|
15
10
|
themeName: string
|
|
16
11
|
theme: ThemeParsed
|
|
@@ -18,148 +13,154 @@ export function getThemeCSSRules({
|
|
|
18
13
|
}) {
|
|
19
14
|
const cssRuleSets: string[] = []
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const CNP = `.${THEME_CLASSNAME_PREFIX}`
|
|
24
|
-
let vars = ''
|
|
25
|
-
|
|
26
|
-
// themeToVariableToValueMap.set(theme, {})
|
|
27
|
-
// const varToValMap = themeToVariableToValueMap.get(theme)
|
|
28
|
-
for (const themeKey in theme) {
|
|
29
|
-
const variable = theme[themeKey] as Variable
|
|
30
|
-
let value: any = null
|
|
31
|
-
|
|
32
|
-
if (!tokensValueToVariable.has(variable.val)) {
|
|
33
|
-
value = variable.val
|
|
34
|
-
} else {
|
|
35
|
-
value = tokensValueToVariable.get(variable.val)!.variable
|
|
36
|
-
}
|
|
37
|
-
// Hash themeKey in case it has invalid chars too
|
|
38
|
-
vars += `--${simpleHash(themeKey, 40)}:${value};`
|
|
39
|
-
}
|
|
16
|
+
if (process.env.TAMAGUI_DOES_SSR_CSS !== 'true') {
|
|
17
|
+
const { config, themeName, theme, names } = props
|
|
40
18
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
// since we dont specify dark/light in classnames we have to do an awkward specificity war
|
|
46
|
-
// use config.maxDarkLightNesting to determine how deep you can nest until it breaks
|
|
47
|
-
if (hasDarkLight) {
|
|
48
|
-
for (const subName of names) {
|
|
49
|
-
const isDark = themeName === 'dark' || subName.startsWith('dark_')
|
|
50
|
-
const isLight = themeName === 'light' || themeName.startsWith('light_')
|
|
51
|
-
const maxDepth = config.maxDarkLightNesting ?? 3
|
|
52
|
-
|
|
53
|
-
if (!(isDark || isLight)) {
|
|
54
|
-
// neither light nor dark subtheme, just generate one selector with :root:root which
|
|
55
|
-
// will override all :root light/dark selectors generated below
|
|
56
|
-
selectorsSet.add(`:root:root ${CNP}${subName}`)
|
|
57
|
-
continue
|
|
58
|
-
}
|
|
19
|
+
// special case for SSR
|
|
20
|
+
const hasDarkLight = 'light' in config.themes && 'dark' in config.themes
|
|
21
|
+
const CNP = `.${THEME_CLASSNAME_PREFIX}`
|
|
22
|
+
let vars = ''
|
|
59
23
|
|
|
60
|
-
|
|
24
|
+
// themeToVariableToValueMap.set(theme, {})
|
|
25
|
+
// const varToValMap = themeToVariableToValueMap.get(theme)
|
|
26
|
+
for (const themeKey in theme) {
|
|
27
|
+
const variable = theme[themeKey] as Variable
|
|
28
|
+
let value: any = null
|
|
61
29
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
30
|
+
if (!tokensValueToVariable.has(variable.val)) {
|
|
31
|
+
value = variable.val
|
|
32
|
+
} else {
|
|
33
|
+
value = tokensValueToVariable.get(variable.val)!.variable
|
|
34
|
+
}
|
|
35
|
+
// Hash themeKey in case it has invalid chars too
|
|
36
|
+
vars += `--${simpleHash(themeKey, 40)}:${value};`
|
|
37
|
+
}
|
|
66
38
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
39
|
+
const isDarkOrLightBase = themeName === 'dark' || themeName === 'light'
|
|
40
|
+
const baseSelectors = names.map((name) => `${CNP}${name}`)
|
|
41
|
+
const selectorsSet = new Set(baseSelectors)
|
|
42
|
+
|
|
43
|
+
// since we dont specify dark/light in classnames we have to do an awkward specificity war
|
|
44
|
+
// use config.maxDarkLightNesting to determine how deep you can nest until it breaks
|
|
45
|
+
if (hasDarkLight) {
|
|
46
|
+
for (const subName of names) {
|
|
47
|
+
const isDark = themeName === 'dark' || subName.startsWith('dark_')
|
|
48
|
+
const isLight = themeName === 'light' || themeName.startsWith('light_')
|
|
49
|
+
const maxDepth = config.maxDarkLightNesting ?? 3
|
|
50
|
+
|
|
51
|
+
if (!(isDark || isLight)) {
|
|
52
|
+
// neither light nor dark subtheme, just generate one selector with :root:root which
|
|
53
|
+
// will override all :root light/dark selectors generated below
|
|
54
|
+
selectorsSet.add(`:root:root ${CNP}${subName}`)
|
|
55
|
+
continue
|
|
70
56
|
}
|
|
71
|
-
const [stronger, weaker] = order
|
|
72
|
-
const numSelectors = Math.round(maxDepth * 1.5)
|
|
73
57
|
|
|
74
|
-
|
|
75
|
-
const isOdd = depth % 2 === 1
|
|
58
|
+
const childSelector = `${CNP}${subName.replace(/^(dark|light)_/, '')}`
|
|
76
59
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
60
|
+
const [altLightDark, altSubTheme] = [
|
|
61
|
+
isDark ? ['dark', 'light'] : ['light', 'dark'],
|
|
62
|
+
isDark ? ['dark', 'sub_theme'] : ['light', 'sub_theme'],
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
for (const order of [altLightDark, altSubTheme]) {
|
|
66
|
+
if (isDarkOrLightBase) {
|
|
67
|
+
order.reverse()
|
|
80
68
|
}
|
|
69
|
+
const [stronger, weaker] = order
|
|
70
|
+
const numSelectors = Math.round(maxDepth * 1.5)
|
|
81
71
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
})
|
|
72
|
+
for (let depth = 0; depth < numSelectors; depth++) {
|
|
73
|
+
const isOdd = depth % 2 === 1
|
|
85
74
|
|
|
86
|
-
|
|
75
|
+
// wtf is this continue:
|
|
76
|
+
if (isOdd && depth < 3) {
|
|
77
|
+
continue
|
|
78
|
+
}
|
|
87
79
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
80
|
+
const parents = new Array(depth + 1).fill(0).map((_, psi) => {
|
|
81
|
+
return `${CNP}${psi % 2 === 0 ? stronger : weaker}`
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
let parentSelectors = parents.length > 1 ? parents.slice(1) : parents
|
|
85
|
+
|
|
86
|
+
if (isOdd) {
|
|
87
|
+
const [_first, second, ...rest] = parentSelectors
|
|
88
|
+
parentSelectors = [second, ...rest, second]
|
|
89
|
+
}
|
|
92
90
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
const lastParentSelector = parentSelectors[parentSelectors.length - 1]
|
|
92
|
+
const nextChildSelector =
|
|
93
|
+
childSelector === lastParentSelector ? '' : childSelector
|
|
96
94
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
95
|
+
// for light/dark/light:
|
|
96
|
+
selectorsSet.add(`${parentSelectors.join(' ')} ${nextChildSelector}`.trim())
|
|
97
|
+
// selectorsSet.add(
|
|
98
|
+
// `${parentSelectors.join(' ')} ${nextChildSelector}.t_sub_theme`.trim()
|
|
99
|
+
// )
|
|
100
|
+
}
|
|
102
101
|
}
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
|
-
}
|
|
106
104
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
.map((x) => {
|
|
113
|
-
const rootSep = isBaseTheme(x) && config.themeClassNameOnRoot ? '' : ' '
|
|
114
|
-
return `:root${rootSep}${x}`
|
|
115
|
-
})
|
|
116
|
-
.join(', ')
|
|
117
|
-
|
|
118
|
-
const css = `${selectorsString} {${vars}}`
|
|
119
|
-
cssRuleSets.push(css)
|
|
120
|
-
|
|
121
|
-
if (config.shouldAddPrefersColorThemes) {
|
|
122
|
-
const bgString = theme.background
|
|
123
|
-
? `background:${variableToString(theme.background)};`
|
|
124
|
-
: ''
|
|
125
|
-
const fgString = theme.color ? `color:${variableToString(theme.color)}` : ''
|
|
126
|
-
|
|
127
|
-
const bodyRules = `body{${bgString}${fgString}}`
|
|
128
|
-
const isDark = themeName.startsWith('dark')
|
|
129
|
-
const baseName = isDark ? 'dark' : 'light'
|
|
130
|
-
const lessSpecificSelectors = selectors
|
|
105
|
+
const selectors = [...selectorsSet].sort((a, b) => a.localeCompare(b))
|
|
106
|
+
|
|
107
|
+
// only do our :root attach if it's not light/dark - not support sub themes on root saves a lot of effort/size
|
|
108
|
+
// this isBaseTheme logic could probably be done more efficiently above
|
|
109
|
+
const selectorsString = selectors
|
|
131
110
|
.map((x) => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
(isDark && x.startsWith(lightSelector)) ||
|
|
135
|
-
(!isDark && x.startsWith(darkSelector))
|
|
136
|
-
) {
|
|
137
|
-
return
|
|
138
|
-
}
|
|
139
|
-
return x.replace(/^\.t_(dark|light) /, '').trim()
|
|
111
|
+
const rootSep = isBaseTheme(x) && config.themeClassNameOnRoot ? '' : ' '
|
|
112
|
+
return `:root${rootSep}${x}`
|
|
140
113
|
})
|
|
141
|
-
.filter(Boolean)
|
|
142
114
|
.join(', ')
|
|
143
115
|
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
116
|
+
const css = `${selectorsString} {${vars}}`
|
|
117
|
+
cssRuleSets.push(css)
|
|
118
|
+
|
|
119
|
+
if (config.shouldAddPrefersColorThemes) {
|
|
120
|
+
const bgString = theme.background
|
|
121
|
+
? `background:${variableToString(theme.background)};`
|
|
122
|
+
: ''
|
|
123
|
+
const fgString = theme.color ? `color:${variableToString(theme.color)}` : ''
|
|
124
|
+
|
|
125
|
+
const bodyRules = `body{${bgString}${fgString}}`
|
|
126
|
+
const isDark = themeName.startsWith('dark')
|
|
127
|
+
const baseName = isDark ? 'dark' : 'light'
|
|
128
|
+
const lessSpecificSelectors = selectors
|
|
129
|
+
.map((x) => {
|
|
130
|
+
if (x == darkSelector || x === lightSelector) return `:root`
|
|
131
|
+
if (
|
|
132
|
+
(isDark && x.startsWith(lightSelector)) ||
|
|
133
|
+
(!isDark && x.startsWith(darkSelector))
|
|
134
|
+
) {
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
return x.replace(/^\.t_(dark|light) /, '').trim()
|
|
138
|
+
})
|
|
139
|
+
.filter(Boolean)
|
|
140
|
+
.join(', ')
|
|
141
|
+
|
|
142
|
+
const themeRules = `${lessSpecificSelectors} {${vars}}`
|
|
143
|
+
const prefersMediaSelectors = `@media(prefers-color-scheme:${baseName}){
|
|
144
|
+
${bodyRules}
|
|
145
|
+
${themeRules}
|
|
146
|
+
}`
|
|
147
|
+
cssRuleSets.push(prefersMediaSelectors)
|
|
148
|
+
}
|
|
151
149
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
150
|
+
if (config.selectionStyles) {
|
|
151
|
+
const selectionSelectors = baseSelectors.map((s) => `${s} ::selection`).join(', ')
|
|
152
|
+
const rules = config.selectionStyles(theme)
|
|
153
|
+
if (rules) {
|
|
154
|
+
const styles = Object.entries(rules)
|
|
155
|
+
.flatMap(([k, v]) =>
|
|
156
|
+
v
|
|
157
|
+
? `${k === 'backgroundColor' ? 'background' : k}:${variableToString(v)}`
|
|
158
|
+
: []
|
|
159
|
+
)
|
|
160
|
+
.join(';')
|
|
161
|
+
const css = `${selectionSelectors} {${styles}}`
|
|
162
|
+
cssRuleSets.push(css)
|
|
163
|
+
}
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
166
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTamagui.d.ts","sourceRoot":"","sources":["../src/createTamagui.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,kBAAkB,EAElB,kBAAkB,EAGnB,MAAM,SAAS,CAAA;AAKhB,wBAAgB,aAAa,CAAC,IAAI,SAAS,kBAAkB,EAC3D,QAAQ,EAAE,IAAI,GACb,kBAAkB,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"createTamagui.d.ts","sourceRoot":"","sources":["../src/createTamagui.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,kBAAkB,EAElB,kBAAkB,EAGnB,MAAM,SAAS,CAAA;AAKhB,wBAAgB,aAAa,CAAC,IAAI,SAAS,kBAAkB,EAC3D,QAAQ,EAAE,IAAI,GACb,kBAAkB,CAAC,IAAI,CAAC,CA6S1B"}
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* 2. Normalizes various inconsistent styles to be more consistent
|
|
6
6
|
* 3. Expands react-native shorthands, ie paddingHorizontal => paddingLeft, paddingRight
|
|
7
7
|
*/
|
|
8
|
-
export declare function expandStylesAndRemoveNullishValues(style: Record<string, any
|
|
8
|
+
export declare function expandStylesAndRemoveNullishValues(style: Record<string, any>): Record<string, any>;
|
|
9
9
|
export declare function fixStyles(style: Record<string, any>): void;
|
|
10
10
|
//# sourceMappingURL=expandStyles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expandStyles.d.ts","sourceRoot":"","sources":["../../src/helpers/expandStyles.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"expandStyles.d.ts","sourceRoot":"","sources":["../../src/helpers/expandStyles.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AAEH,wBAAgB,kCAAkC,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,uBAuB5E;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QA0BnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSplitStyles.d.ts","sourceRoot":"","sources":["../../src/helpers/getSplitStyles.tsx"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAEV,SAAS,EACT,cAAc,EACd,aAAa,EAMb,eAAe,EACf,kBAAkB,EAGlB,cAAc,EACd,WAAW,EAEZ,MAAM,UAAU,CAAA;AACjB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAuBtE,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAA;AAE3D,MAAM,MAAM,gBAAgB,GAAG,UAAU,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,MAAM,EACpB,KAAK,CAAC,EAAE,SAAS,KACd,cAAc,CAAA;AAEnB,eAAO,MAAM,UAAU,MAAM,CAAA;AAS7B,eAAO,MAAM,cAAc,EAAE,aA29B5B,CAAA;AAkFD,eAAO,MAAM,WAAW,eACV,aAAa,UACjB,MAAM,WACL,MAAM,sBACK,OAAO,wBACL,OAAO,KAC5B,cA6BF,CAAA;AAOD,eAAO,MAAM,cAAc,EAAE,aAQ5B,CAAA;AA6BD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CreateTamaguiProps, ThemeParsed } from '../types';
|
|
2
|
-
export declare function getThemeCSSRules(
|
|
2
|
+
export declare function getThemeCSSRules(props: {
|
|
3
3
|
config: CreateTamaguiProps;
|
|
4
4
|
themeName: string;
|
|
5
5
|
theme: ThemeParsed;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getThemeCSSRules.d.ts","sourceRoot":"","sources":["../../src/helpers/getThemeCSSRules.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAG/D,wBAAgB,gBAAgB,CAAC,
|
|
1
|
+
{"version":3,"file":"getThemeCSSRules.d.ts","sourceRoot":"","sources":["../../src/helpers/getThemeCSSRules.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAG/D,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACtC,MAAM,EAAE,kBAAkB,CAAA;IAC1B,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,MAAM,EAAE,CAAA;CAChB,YA2JA"}
|