@tamagui/web 1.45.11 → 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/createComponent.js +4 -36
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/createTamagui.js +45 -43
- package/dist/cjs/createTamagui.js.map +1 -1
- package/dist/cjs/helpers/createPropMapper.js +2 -10
- package/dist/cjs/helpers/createPropMapper.js.map +1 -1
- package/dist/cjs/helpers/expandStyles.js +8 -5
- package/dist/cjs/helpers/expandStyles.js.map +1 -1
- package/dist/cjs/helpers/getSplitStyles.js +17 -25
- 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/cjs/helpers/swapFontFaceOnWeight.js +63 -0
- package/dist/cjs/helpers/swapFontFaceOnWeight.js.map +6 -0
- package/dist/esm/createComponent.js +4 -36
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/createTamagui.js +45 -43
- package/dist/esm/createTamagui.js.map +1 -1
- package/dist/esm/helpers/createPropMapper.js +2 -10
- package/dist/esm/helpers/createPropMapper.js.map +1 -1
- package/dist/esm/helpers/expandStyles.js +8 -5
- package/dist/esm/helpers/expandStyles.js.map +1 -1
- package/dist/esm/helpers/getSplitStyles.js +17 -25
- 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/dist/esm/helpers/swapFontFaceOnWeight.js +39 -0
- package/dist/esm/helpers/swapFontFaceOnWeight.js.map +6 -0
- package/package.json +9 -9
- package/src/createComponent.tsx +2 -38
- package/src/createTamagui.ts +56 -54
- package/src/helpers/createPropMapper.ts +3 -16
- package/src/helpers/expandStyles.ts +11 -9
- package/src/helpers/getSplitStyles.tsx +23 -39
- package/src/helpers/getThemeCSSRules.ts +127 -126
- package/src/types.tsx +1 -1
- package/types/createComponent.d.ts.map +1 -1
- package/types/createTamagui.d.ts.map +1 -1
- package/types/helpers/createPropMapper.d.ts +1 -1
- package/types/helpers/createPropMapper.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
- package/types/helpers/swapFontFaceOnWeight.d.ts +4 -0
- package/types/helpers/swapFontFaceOnWeight.d.ts.map +1 -0
- package/types/types.d.ts +1 -1
- package/types/types.d.ts.map +1 -1
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
|
}
|
|
@@ -18,12 +18,7 @@ import { isObj } from './isObj'
|
|
|
18
18
|
import { mergeProps } from './mergeProps'
|
|
19
19
|
import { pseudoDescriptors } from './pseudoDescriptors'
|
|
20
20
|
|
|
21
|
-
export type ResolveVariableTypes =
|
|
22
|
-
| 'auto'
|
|
23
|
-
| 'value'
|
|
24
|
-
| 'variable'
|
|
25
|
-
| 'both'
|
|
26
|
-
| 'non-color-value'
|
|
21
|
+
export type ResolveVariableTypes = 'auto' | 'value' | 'variable' | 'both'
|
|
27
22
|
|
|
28
23
|
export const createPropMapper = (staticConfig: StaticConfigParsed) => {
|
|
29
24
|
// temp remove classnames
|
|
@@ -441,7 +436,7 @@ const getToken = (
|
|
|
441
436
|
for (const cat in tokenCategories) {
|
|
442
437
|
if (key in tokenCategories[cat]) {
|
|
443
438
|
const res = tokensParsed[cat][value]
|
|
444
|
-
if (res) {
|
|
439
|
+
if (res != null) {
|
|
445
440
|
valOrVar = res
|
|
446
441
|
hasSet = true
|
|
447
442
|
}
|
|
@@ -449,7 +444,7 @@ const getToken = (
|
|
|
449
444
|
}
|
|
450
445
|
if (!hasSet) {
|
|
451
446
|
const spaceVar = tokensParsed.space[value]
|
|
452
|
-
if (spaceVar) {
|
|
447
|
+
if (spaceVar != null) {
|
|
453
448
|
valOrVar = spaceVar
|
|
454
449
|
hasSet = true
|
|
455
450
|
}
|
|
@@ -481,14 +476,6 @@ function resolveVariableValue(
|
|
|
481
476
|
if (resolveAs === 'variable') {
|
|
482
477
|
return valOrVar
|
|
483
478
|
}
|
|
484
|
-
if (resolveAs === 'non-color-value') {
|
|
485
|
-
if (isWeb) {
|
|
486
|
-
if (key in tokenCategories.color) {
|
|
487
|
-
return valOrVar.variable
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
return valOrVar.val
|
|
491
|
-
}
|
|
492
479
|
if (!isWeb || resolveAs === 'value') {
|
|
493
480
|
return valOrVar.val
|
|
494
481
|
}
|
|
@@ -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
|
|
@@ -46,6 +39,15 @@ export function expandStylesAndRemoveNullishValues(
|
|
|
46
39
|
}
|
|
47
40
|
|
|
48
41
|
export function fixStyles(style: Record<string, any>) {
|
|
42
|
+
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
43
|
+
if ('elevationAndroid' in style) {
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
style['elevation'] = style.elevationAndroid
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
delete style.elevationAndroid
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
49
51
|
if (
|
|
50
52
|
style.shadowRadius ||
|
|
51
53
|
style.shadowColor ||
|
|
@@ -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) {
|
|
@@ -933,35 +927,6 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
933
927
|
styleToCSS(style)
|
|
934
928
|
}
|
|
935
929
|
|
|
936
|
-
// native: swap out the right family based on weight/style
|
|
937
|
-
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
938
|
-
if (fontFamilyKey in style && style.fontFamily) {
|
|
939
|
-
const faceInfo = getFont(style.fontFamily as string)?.face
|
|
940
|
-
if (faceInfo) {
|
|
941
|
-
const overrideFace =
|
|
942
|
-
faceInfo[style.fontWeight as string]?.[style.fontStyle || 'normal']?.val
|
|
943
|
-
if (overrideFace) {
|
|
944
|
-
style.fontFamily = overrideFace
|
|
945
|
-
styleState.fontFamily = overrideFace
|
|
946
|
-
delete style.fontWeight
|
|
947
|
-
delete style.fontStyle
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
if (process.env.NODE_ENV === 'development') {
|
|
951
|
-
if (debug) {
|
|
952
|
-
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
953
|
-
console.log(`Found fontFamily native: ${style.fontFamily}`, faceInfo)
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
if ('elevationAndroid' in style) {
|
|
958
|
-
// @ts-ignore
|
|
959
|
-
style['elevation'] = style.elevationAndroid
|
|
960
|
-
// @ts-ignore
|
|
961
|
-
delete style.elevationAndroid
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
|
|
965
930
|
// always do this at the very end to preserve the order strictly (animations, origin)
|
|
966
931
|
// and allow proper merging of all pseudos before applying
|
|
967
932
|
if (flatTransforms) {
|
|
@@ -1089,6 +1054,25 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
1089
1054
|
dynamicThemeAccess,
|
|
1090
1055
|
}
|
|
1091
1056
|
|
|
1057
|
+
// native: swap out the right family based on weight/style
|
|
1058
|
+
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
1059
|
+
if (style.fontFamily) {
|
|
1060
|
+
const faceInfo = getFont(style.fontFamily as string)?.face
|
|
1061
|
+
if (faceInfo) {
|
|
1062
|
+
const overrideFace =
|
|
1063
|
+
faceInfo[style.fontWeight as string]?.[style.fontStyle || 'normal']?.val
|
|
1064
|
+
if (overrideFace) {
|
|
1065
|
+
style.fontFamily = overrideFace
|
|
1066
|
+
styleState.fontFamily = overrideFace
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
if (process.env.NODE_ENV === 'development' && debug) {
|
|
1070
|
+
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
1071
|
+
console.log(`Found fontFamily native: ${style.fontFamily}`, faceInfo)
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1092
1076
|
if (className) {
|
|
1093
1077
|
classNames.className = className
|
|
1094
1078
|
}
|
|
@@ -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
|
|
package/src/types.tsx
CHANGED
|
@@ -1302,7 +1302,7 @@ export type StyleResolver<Response = PropMappedValue> = (
|
|
|
1302
1302
|
value: any,
|
|
1303
1303
|
state: GetStyleState,
|
|
1304
1304
|
defaultProps: any,
|
|
1305
|
-
returnVariablesAs: 'auto' | 'value'
|
|
1305
|
+
returnVariablesAs: 'auto' | 'value',
|
|
1306
1306
|
parentVariantKey: string,
|
|
1307
1307
|
avoidDefaultProps?: boolean
|
|
1308
1308
|
) => Response
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createComponent.d.ts","sourceRoot":"","sources":["../src/createComponent.tsx"],"names":[],"mappings":"AAGA,OAAO,KAWN,MAAM,OAAO,CAAA;AAiBd,OAAO,EACL,SAAS,EACT,cAAc,EACd,UAAU,EACV,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAEhB,qBAAqB,EACrB,cAAc,EAIf,MAAM,SAAS,CAAA;AAoBhB,eAAO,MAAM,qBAAqB,EAAE,qBAMnC,CAAA;AAwBD,eAAO,MAAM,QAAQ,eAAsB,CAAA;AAqB3C,wBAAgB,eAAe,CAC7B,kBAAkB,SAAS,MAAM,GAAG,EAAE,EACtC,GAAG,GAAG,cAAc,EACpB,SAAS,GAAG,KAAK,EACjB,cAAc,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,kBAAkB,
|
|
1
|
+
{"version":3,"file":"createComponent.d.ts","sourceRoot":"","sources":["../src/createComponent.tsx"],"names":[],"mappings":"AAGA,OAAO,KAWN,MAAM,OAAO,CAAA;AAiBd,OAAO,EACL,SAAS,EACT,cAAc,EACd,UAAU,EACV,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAEhB,qBAAqB,EACrB,cAAc,EAIf,MAAM,SAAS,CAAA;AAoBhB,eAAO,MAAM,qBAAqB,EAAE,qBAMnC,CAAA;AAwBD,eAAO,MAAM,QAAQ,eAAsB,CAAA;AAqB3C,wBAAgB,eAAe,CAC7B,kBAAkB,SAAS,MAAM,GAAG,EAAE,EACtC,GAAG,GAAG,cAAc,EACpB,SAAS,GAAG,KAAK,EACjB,cAAc,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,kBAAkB,4DA80B3D;AAGD,eAAO,MAAM,QAAQ;YAAW;QAAE,QAAQ,CAAC,EAAE,GAAG,CAAA;KAAE;;CAAmB,CAAA;AAMrE,eAAO,MAAM,MAAM,0DA8CjB,CAAA;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC5B,SAAS,CAAC,EAAE,cAAc,CAAA;IAC1B,SAAS,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC3B,KAAK,CAAC,EAAE,SAAS,CAAA;CAClB,CAAA;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,mBAkGxD"}
|
|
@@ -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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PropMapper, StaticConfigParsed, TamaguiInternalConfig } from '../types';
|
|
2
|
-
export type ResolveVariableTypes = 'auto' | 'value' | 'variable' | 'both'
|
|
2
|
+
export type ResolveVariableTypes = 'auto' | 'value' | 'variable' | 'both';
|
|
3
3
|
export declare const createPropMapper: (staticConfig: StaticConfigParsed) => PropMapper;
|
|
4
4
|
export declare function getFontFamilyFromNameOrVariable(input: any, conf: TamaguiInternalConfig): string | undefined;
|
|
5
5
|
export declare const getPropMappedFontFamily: (expanded?: any) => any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPropMapper.d.ts","sourceRoot":"","sources":["../../src/helpers/createPropMapper.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAGV,UAAU,EACV,kBAAkB,EAElB,qBAAqB,EAEtB,MAAM,UAAU,CAAA;AAQjB,MAAM,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"createPropMapper.d.ts","sourceRoot":"","sources":["../../src/helpers/createPropMapper.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAGV,UAAU,EACV,kBAAkB,EAElB,qBAAqB,EAEtB,MAAM,UAAU,CAAA;AAQjB,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,MAAM,CAAA;AAEzE,eAAO,MAAM,gBAAgB,iBAAkB,kBAAkB,eAuEhE,CAAA;AA2HD,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,qBAAqB,sBAkBtF;AAMD,eAAO,MAAM,uBAAuB,cAAe,GAAG,QAErD,CAAA"}
|
|
@@ -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"}
|