@tamagui/web 1.46.2 → 1.47.0
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/constants/constants.js +15 -15
- package/dist/cjs/constants/constants.js.map +1 -1
- package/dist/cjs/createComponent.js +83 -106
- package/dist/cjs/createComponent.js.map +1 -1
- package/dist/cjs/createTamagui.js +0 -1
- package/dist/cjs/createTamagui.js.map +1 -1
- package/dist/cjs/helpers/ThemeManager.js +6 -5
- package/dist/cjs/helpers/ThemeManager.js.map +1 -1
- package/dist/cjs/helpers/getSplitStyles.js +75 -98
- package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
- package/dist/cjs/helpers/getStylesAtomic.js +7 -7
- package/dist/cjs/helpers/getStylesAtomic.js.map +1 -1
- package/dist/cjs/helpers/getVariantExtras.js +2 -10
- package/dist/cjs/helpers/getVariantExtras.js.map +1 -1
- package/dist/cjs/helpers/isTamaguiComponent.js +1 -1
- package/dist/cjs/helpers/isTamaguiComponent.js.map +1 -1
- package/dist/cjs/helpers/mergeProps.js +6 -14
- package/dist/cjs/helpers/mergeProps.js.map +1 -1
- package/dist/cjs/helpers/normalizeColor.js +2 -1
- package/dist/cjs/helpers/normalizeColor.js.map +1 -1
- package/dist/cjs/helpers/normalizeValueWithProperty.js +5 -56
- package/dist/cjs/helpers/normalizeValueWithProperty.js.map +1 -1
- package/dist/cjs/helpers/{createPropMapper.js → propMapper.js} +63 -139
- package/dist/cjs/helpers/propMapper.js.map +6 -0
- package/dist/cjs/helpers/pseudoDescriptors.js +0 -1
- package/dist/cjs/helpers/pseudoDescriptors.js.map +1 -1
- package/dist/cjs/helpers/useShallowSetState.js +9 -17
- package/dist/cjs/helpers/useShallowSetState.js.map +1 -1
- package/dist/cjs/helpers/withStaticProperties.js +9 -0
- package/dist/cjs/helpers/withStaticProperties.js.map +1 -1
- package/dist/cjs/hooks/useMedia.js +7 -9
- package/dist/cjs/hooks/useMedia.js.map +1 -1
- package/dist/cjs/hooks/useStyle.js +5 -2
- package/dist/cjs/hooks/useStyle.js.map +1 -1
- package/dist/cjs/hooks/useTheme.js +28 -32
- package/dist/cjs/hooks/useTheme.js.map +1 -1
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/views/Stack.js +1 -4
- package/dist/cjs/views/Stack.js.map +1 -1
- package/dist/cjs/views/Theme.js +2 -2
- package/dist/cjs/views/Theme.js.map +1 -1
- package/dist/cjs/views/ThemeDebug.js +2 -2
- package/dist/cjs/views/ThemeDebug.js.map +1 -1
- package/dist/esm/constants/constants.js +14 -13
- package/dist/esm/constants/constants.js.map +1 -1
- package/dist/esm/createComponent.js +83 -106
- package/dist/esm/createComponent.js.map +1 -1
- package/dist/esm/createTamagui.js +0 -1
- package/dist/esm/createTamagui.js.map +1 -1
- package/dist/esm/helpers/ThemeManager.js +6 -5
- package/dist/esm/helpers/ThemeManager.js.map +1 -1
- package/dist/esm/helpers/getSplitStyles.js +74 -97
- package/dist/esm/helpers/getSplitStyles.js.map +2 -2
- package/dist/esm/helpers/getStylesAtomic.js +7 -7
- package/dist/esm/helpers/getStylesAtomic.js.map +1 -1
- package/dist/esm/helpers/getVariantExtras.js +2 -10
- package/dist/esm/helpers/getVariantExtras.js.map +1 -1
- package/dist/esm/helpers/isTamaguiComponent.js +1 -1
- package/dist/esm/helpers/isTamaguiComponent.js.map +1 -1
- package/dist/esm/helpers/mergeProps.js +6 -14
- package/dist/esm/helpers/mergeProps.js.map +1 -1
- package/dist/esm/helpers/normalizeColor.js +2 -1
- package/dist/esm/helpers/normalizeColor.js.map +1 -1
- package/dist/esm/helpers/normalizeValueWithProperty.js +5 -56
- package/dist/esm/helpers/normalizeValueWithProperty.js.map +1 -1
- package/dist/esm/helpers/{createPropMapper.js → propMapper.js} +56 -132
- package/dist/esm/helpers/propMapper.js.map +6 -0
- package/dist/esm/helpers/pseudoDescriptors.js +0 -1
- package/dist/esm/helpers/pseudoDescriptors.js.map +1 -1
- package/dist/esm/helpers/useShallowSetState.js +9 -17
- package/dist/esm/helpers/useShallowSetState.js.map +1 -1
- package/dist/esm/helpers/withStaticProperties.js +9 -0
- package/dist/esm/helpers/withStaticProperties.js.map +1 -1
- package/dist/esm/hooks/useMedia.js +8 -10
- package/dist/esm/hooks/useMedia.js.map +1 -1
- package/dist/esm/hooks/useStyle.js +5 -2
- package/dist/esm/hooks/useStyle.js.map +1 -1
- package/dist/esm/hooks/useTheme.js +28 -32
- package/dist/esm/hooks/useTheme.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/views/Stack.js +1 -4
- package/dist/esm/views/Stack.js.map +1 -1
- package/dist/esm/views/Theme.js +2 -2
- package/dist/esm/views/Theme.js.map +1 -1
- package/dist/esm/views/ThemeDebug.js +2 -2
- package/dist/esm/views/ThemeDebug.js.map +1 -1
- package/package.json +9 -9
- package/src/constants/constants.ts +15 -11
- package/src/createComponent.tsx +143 -140
- package/src/createTamagui.ts +0 -1
- package/src/helpers/ThemeManager.tsx +10 -6
- package/src/helpers/getSplitStyles.tsx +139 -172
- package/src/helpers/getStylesAtomic.ts +7 -7
- package/src/helpers/getVariantExtras.tsx +15 -31
- package/src/helpers/isTamaguiComponent.tsx +3 -3
- package/src/helpers/mergeProps.ts +5 -20
- package/src/helpers/normalizeColor.ts +2 -1
- package/src/helpers/normalizeValueWithProperty.ts +8 -64
- package/src/helpers/{createPropMapper.ts → propMapper.ts} +71 -165
- package/src/helpers/pseudoDescriptors.ts +0 -1
- package/src/helpers/useShallowSetState.tsx +10 -16
- package/src/helpers/withStaticProperties.tsx +13 -0
- package/src/hooks/useMedia.tsx +15 -10
- package/src/hooks/useStyle.tsx +7 -4
- package/src/hooks/useTheme.tsx +36 -47
- package/src/index.ts +1 -1
- package/src/types.tsx +20 -33
- package/src/views/Stack.tsx +1 -4
- package/src/views/Theme.tsx +3 -3
- package/src/views/ThemeDebug.tsx +2 -2
- package/types/constants/constants.d.ts +0 -15
- package/types/constants/constants.d.ts.map +1 -1
- package/types/createComponent.d.ts +5 -8
- package/types/createComponent.d.ts.map +1 -1
- package/types/createTamagui.d.ts.map +1 -1
- package/types/helpers/ThemeManager.d.ts +1 -1
- package/types/helpers/ThemeManager.d.ts.map +1 -1
- package/types/helpers/getSplitStyles.d.ts +3 -7
- package/types/helpers/getSplitStyles.d.ts.map +1 -1
- package/types/helpers/getVariantExtras.d.ts +1 -1
- package/types/helpers/getVariantExtras.d.ts.map +1 -1
- package/types/helpers/isTamaguiComponent.d.ts.map +1 -1
- package/types/helpers/mergeProps.d.ts +1 -1
- package/types/helpers/mergeProps.d.ts.map +1 -1
- package/types/helpers/normalizeColor.d.ts.map +1 -1
- package/types/helpers/normalizeValueWithProperty.d.ts.map +1 -1
- package/types/helpers/{createPropMapper.d.ts → propMapper.d.ts} +3 -3
- package/types/helpers/propMapper.d.ts.map +1 -0
- package/types/helpers/pseudoDescriptors.d.ts.map +1 -1
- package/types/helpers/useShallowSetState.d.ts.map +1 -1
- package/types/helpers/withStaticProperties.d.ts.map +1 -1
- package/types/hooks/useMedia.d.ts.map +1 -1
- package/types/hooks/useStyle.d.ts +2 -2
- package/types/hooks/useStyle.d.ts.map +1 -1
- package/types/hooks/useTheme.d.ts +7 -13
- package/types/hooks/useTheme.d.ts.map +1 -1
- package/types/index.d.ts +1 -1
- package/types/index.d.ts.map +1 -1
- package/types/styled.d.ts +1 -1
- package/types/types.d.ts +17 -25
- package/types/types.d.ts.map +1 -1
- package/types/views/Stack.d.ts.map +1 -1
- package/dist/cjs/helpers/createPropMapper.js.map +0 -6
- package/dist/cjs/helpers/parseStaticConfig.js +0 -40
- package/dist/cjs/helpers/parseStaticConfig.js.map +0 -6
- package/dist/cjs/helpers/swapFontFaceOnWeight.js +0 -63
- package/dist/cjs/helpers/swapFontFaceOnWeight.js.map +0 -6
- package/dist/cjs/hooks/useSafeRef.js +0 -59
- package/dist/cjs/hooks/useSafeRef.js.map +0 -6
- package/dist/cjs/hooks/useServerHooks.js +0 -36
- package/dist/cjs/hooks/useServerHooks.js.map +0 -6
- package/dist/esm/helpers/createPropMapper.js.map +0 -6
- package/dist/esm/helpers/parseStaticConfig.js +0 -16
- package/dist/esm/helpers/parseStaticConfig.js.map +0 -6
- package/dist/esm/helpers/swapFontFaceOnWeight.js +0 -39
- package/dist/esm/helpers/swapFontFaceOnWeight.js.map +0 -6
- package/dist/esm/hooks/useSafeRef.js +0 -35
- package/dist/esm/hooks/useSafeRef.js.map +0 -6
- package/dist/esm/hooks/useServerHooks.js +0 -11
- package/dist/esm/hooks/useServerHooks.js.map +0 -6
- package/src/helpers/parseStaticConfig.ts +0 -14
- package/src/hooks/useSafeRef.ts +0 -45
- package/types/helpers/createPropMapper.d.ts.map +0 -1
- package/types/helpers/parseStaticConfig.d.ts +0 -3
- package/types/helpers/parseStaticConfig.d.ts.map +0 -1
- package/types/helpers/swapFontFaceOnWeight.d.ts +0 -4
- package/types/helpers/swapFontFaceOnWeight.d.ts.map +0 -1
- package/types/hooks/useSafeRef.d.ts +0 -4
- package/types/hooks/useSafeRef.d.ts.map +0 -1
- package/types/hooks/useServerHooks.d.ts +0 -4
- package/types/hooks/useServerHooks.d.ts.map +0 -1
|
@@ -3,11 +3,7 @@ import { GenericFonts, GetStyleState } from '../types'
|
|
|
3
3
|
import { LanguageContextType } from '../views/FontLanguage.types'
|
|
4
4
|
import { createProxy } from './createProxy'
|
|
5
5
|
|
|
6
|
-
export function getVariantExtras(
|
|
7
|
-
styleState: GetStyleState,
|
|
8
|
-
defaultProps?: any,
|
|
9
|
-
avoidDefaultProps = false
|
|
10
|
-
) {
|
|
6
|
+
export function getVariantExtras(styleState: GetStyleState) {
|
|
11
7
|
const { curProps, conf, languageContext, theme } = styleState
|
|
12
8
|
let fonts = conf.fontsParsed
|
|
13
9
|
if (languageContext) {
|
|
@@ -27,32 +23,20 @@ export function getVariantExtras(
|
|
|
27
23
|
font: fonts[fontFamily],
|
|
28
24
|
// TODO do this in splitstlye
|
|
29
25
|
// we avoid passing in default props for media queries because that would confuse things like SizableText.size:
|
|
30
|
-
props:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// these props may be extracted into classNames, but we still want to access them
|
|
45
|
-
// at runtime, so we proxy back to defaultProps but don't pass them
|
|
46
|
-
if (defaultProps) {
|
|
47
|
-
if (shorthand && Reflect.has(defaultProps, shorthand)) {
|
|
48
|
-
return Reflect.get(defaultProps, shorthand)
|
|
49
|
-
}
|
|
50
|
-
if (Reflect.has(defaultProps, key)) {
|
|
51
|
-
return Reflect.get(defaultProps, key)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
}),
|
|
26
|
+
props: createProxy(curProps, {
|
|
27
|
+
// handles shorthands
|
|
28
|
+
get(target, key) {
|
|
29
|
+
const shorthand = conf.inverseShorthands[key as any]
|
|
30
|
+
// shorthands before longhand because a styled() with longhand combined with inline shorthand
|
|
31
|
+
// shorthand will always be the overriding key
|
|
32
|
+
if (shorthand && Reflect.has(target, shorthand)) {
|
|
33
|
+
return Reflect.get(target, shorthand)
|
|
34
|
+
}
|
|
35
|
+
if (Reflect.has(target, key)) {
|
|
36
|
+
return Reflect.get(target, key)
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
}),
|
|
56
40
|
}
|
|
57
41
|
|
|
58
42
|
return next as any
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StaticConfig
|
|
1
|
+
import { StaticConfig } from '../types'
|
|
2
2
|
|
|
3
3
|
export function isTamaguiComponent<A>(
|
|
4
4
|
comp: A,
|
|
@@ -6,6 +6,6 @@ export function isTamaguiComponent<A>(
|
|
|
6
6
|
): comp is A & {
|
|
7
7
|
staticConfig: StaticConfig
|
|
8
8
|
} {
|
|
9
|
-
const config = comp?.['staticConfig'] as
|
|
10
|
-
return (config
|
|
9
|
+
const config = comp?.['staticConfig'] as StaticConfig | undefined
|
|
10
|
+
return Boolean(config && (name ? name === config.componentName : true))
|
|
11
11
|
}
|
|
@@ -16,32 +16,24 @@ import { pseudoDescriptors } from './pseudoDescriptors'
|
|
|
16
16
|
|
|
17
17
|
type AnyRecord = Record<string, any>
|
|
18
18
|
|
|
19
|
-
export const mergeProps = (
|
|
20
|
-
a: Object,
|
|
21
|
-
b?: Object,
|
|
22
|
-
leaveOutClassNames = false,
|
|
23
|
-
inverseShorthands?: AnyRecord
|
|
24
|
-
) => {
|
|
19
|
+
export const mergeProps = (a: Object, b?: Object, inverseShorthands?: AnyRecord) => {
|
|
25
20
|
const out: AnyRecord = {}
|
|
26
|
-
const outCns: AnyRecord = leaveOutClassNames ? {} : (null as any)
|
|
27
21
|
for (const key in a) {
|
|
28
|
-
mergeProp(out,
|
|
22
|
+
mergeProp(out, a, b, key, inverseShorthands)
|
|
29
23
|
}
|
|
30
24
|
if (b) {
|
|
31
25
|
for (const key in b) {
|
|
32
|
-
mergeProp(out,
|
|
26
|
+
mergeProp(out, b, undefined, key, inverseShorthands)
|
|
33
27
|
}
|
|
34
28
|
}
|
|
35
|
-
return
|
|
29
|
+
return out
|
|
36
30
|
}
|
|
37
31
|
|
|
38
32
|
function mergeProp(
|
|
39
33
|
out: AnyRecord,
|
|
40
|
-
outCns: AnyRecord,
|
|
41
34
|
a: Object,
|
|
42
35
|
b: Object | undefined,
|
|
43
36
|
key: string,
|
|
44
|
-
leaveOutClassNames: boolean,
|
|
45
37
|
inverseShorthands?: AnyRecord
|
|
46
38
|
) {
|
|
47
39
|
const shorthand = inverseShorthands?.[key] || null
|
|
@@ -56,12 +48,5 @@ function mergeProp(
|
|
|
56
48
|
}
|
|
57
49
|
return
|
|
58
50
|
}
|
|
59
|
-
|
|
60
|
-
key = shorthand
|
|
61
|
-
}
|
|
62
|
-
if (leaveOutClassNames && val?.[0] === '_') {
|
|
63
|
-
outCns[key] = val
|
|
64
|
-
} else {
|
|
65
|
-
out[key] = val
|
|
66
|
-
}
|
|
51
|
+
out[shorthand || key] = val
|
|
67
52
|
}
|
|
@@ -11,7 +11,8 @@ export const normalizeColor = (color?: string | null, opacity?: number) => {
|
|
|
11
11
|
const colorProcessed = NCC.normalizeCSSColor(color)
|
|
12
12
|
if (typeof colorProcessed === 'number') {
|
|
13
13
|
const { r, g, b, a } = rgba(colorProcessed)
|
|
14
|
-
const
|
|
14
|
+
const o = +(opacity ?? a ?? 1)
|
|
15
|
+
const alpha = o.toFixed(2)
|
|
15
16
|
return `rgba(${r},${g},${b},${alpha})`
|
|
16
17
|
}
|
|
17
18
|
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
@@ -4,82 +4,26 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { isWeb } from '@tamagui/constants'
|
|
7
|
+
import { stylePropsUnitless } from '@tamagui/helpers'
|
|
7
8
|
|
|
8
9
|
import { getAllSelectors } from './insertStyleRule'
|
|
9
|
-
import { names, normalizeColor } from './normalizeColor'
|
|
10
|
-
import { normalizeStylePropKeys } from './normalizeStylePropKeys'
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
// only doing this on web on native it accepts pixel values
|
|
13
12
|
|
|
14
13
|
export function normalizeValueWithProperty(value: any, property?: string): any {
|
|
15
|
-
if (
|
|
16
|
-
return value
|
|
17
|
-
}
|
|
14
|
+
if (!isWeb) return value
|
|
18
15
|
let res = value
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
res = normalizeColor(value)
|
|
24
|
-
// avoid memory pressure
|
|
25
|
-
if (colorCache.size > 1000) {
|
|
26
|
-
colorCache.clear()
|
|
27
|
-
}
|
|
28
|
-
colorCache.set(value, res)
|
|
29
|
-
} else if (
|
|
30
|
-
isWeb &&
|
|
31
|
-
typeof value === 'number' &&
|
|
32
|
-
(property === undefined ||
|
|
33
|
-
!(property in unitlessNumbers || property in stringNumbers))
|
|
16
|
+
if (
|
|
17
|
+
(property === undefined || !(property in stylePropsUnitless)) &&
|
|
18
|
+
typeof value === 'number'
|
|
34
19
|
) {
|
|
35
20
|
res = `${value}px`
|
|
36
|
-
} else if (
|
|
21
|
+
} else if (property !== undefined) {
|
|
37
22
|
res = `${res}`
|
|
38
23
|
}
|
|
39
24
|
return res
|
|
40
25
|
}
|
|
41
26
|
|
|
42
|
-
const stringNumbers = {
|
|
43
|
-
zIndex: true,
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const unitlessNumbers = {
|
|
47
|
-
WebkitLineClamp: true,
|
|
48
|
-
animationIterationCount: true,
|
|
49
|
-
aspectRatio: true,
|
|
50
|
-
borderImageOutset: true,
|
|
51
|
-
borderImageSlice: true,
|
|
52
|
-
borderImageWidth: true,
|
|
53
|
-
columnCount: true,
|
|
54
|
-
flex: true,
|
|
55
|
-
flexGrow: true,
|
|
56
|
-
flexOrder: true,
|
|
57
|
-
flexPositive: true,
|
|
58
|
-
flexShrink: true,
|
|
59
|
-
flexNegative: true,
|
|
60
|
-
fontWeight: true,
|
|
61
|
-
gridRow: true,
|
|
62
|
-
gridRowEnd: true,
|
|
63
|
-
gridRowGap: true,
|
|
64
|
-
gridRowStart: true,
|
|
65
|
-
gridColumn: true,
|
|
66
|
-
gridColumnEnd: true,
|
|
67
|
-
gridColumnGap: true,
|
|
68
|
-
gridColumnStart: true,
|
|
69
|
-
lineClamp: true,
|
|
70
|
-
opacity: true,
|
|
71
|
-
order: true,
|
|
72
|
-
orphans: true,
|
|
73
|
-
tabSize: true,
|
|
74
|
-
widows: true,
|
|
75
|
-
zoom: true,
|
|
76
|
-
scale: true,
|
|
77
|
-
scaleX: true,
|
|
78
|
-
scaleY: true,
|
|
79
|
-
scaleZ: true,
|
|
80
|
-
shadowOpacity: true,
|
|
81
|
-
}
|
|
82
|
-
|
|
83
27
|
// getting real values for colors for animations (reverse mapped from CSS)
|
|
84
28
|
// this isn't beautiful, but will do relatively fine performance for now
|
|
85
29
|
const rcache = {}
|
|
@@ -102,7 +46,7 @@ export function reverseMapClassNameToValue(key: string, className: string) {
|
|
|
102
46
|
let res: any
|
|
103
47
|
if (cssVal.startsWith('var(')) {
|
|
104
48
|
res = cssVal
|
|
105
|
-
} else if (
|
|
49
|
+
} else if (stylePropsUnitless[key]) {
|
|
106
50
|
res = +cssVal
|
|
107
51
|
} else if (cssVal.endsWith('px')) {
|
|
108
52
|
res = +cssVal.replace('px', '')
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { isAndroid, isWeb } from '@tamagui/constants'
|
|
2
|
+
import { tokenCategories } from '@tamagui/helpers'
|
|
2
3
|
|
|
3
4
|
import { isDevTools } from '../constants/isDevTools'
|
|
4
5
|
import { Variable, getVariableValue, isVariable } from '../createVariable'
|
|
5
6
|
import type {
|
|
6
|
-
DebugProp,
|
|
7
7
|
GetStyleState,
|
|
8
8
|
PropMapper,
|
|
9
|
-
|
|
9
|
+
SplitStyleProps,
|
|
10
10
|
StyleResolver,
|
|
11
11
|
TamaguiInternalConfig,
|
|
12
12
|
VariantSpreadFunction,
|
|
@@ -15,99 +15,76 @@ import { expandStyle } from './expandStyle'
|
|
|
15
15
|
import { expandStylesAndRemoveNullishValues } from './expandStyles'
|
|
16
16
|
import { getFontsForLanguage, getVariantExtras } from './getVariantExtras'
|
|
17
17
|
import { isObj } from './isObj'
|
|
18
|
-
import { mergeProps } from './mergeProps'
|
|
19
18
|
import { pseudoDescriptors } from './pseudoDescriptors'
|
|
20
19
|
|
|
21
20
|
export type ResolveVariableTypes = 'auto' | 'value' | 'variable' | 'both'
|
|
22
21
|
|
|
23
|
-
export const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
key,
|
|
29
|
-
value,
|
|
30
|
-
styleStateIn,
|
|
31
|
-
subPropsIn,
|
|
32
|
-
avoidDefaultProps = false
|
|
33
|
-
) => {
|
|
34
|
-
if (!(process.env.TAMAGUI_TARGET === 'native' && isAndroid)) {
|
|
35
|
-
if (key === 'elevationAndroid') return
|
|
36
|
-
}
|
|
22
|
+
export const propMapper: PropMapper = (key, value, styleStateIn, subPropsIn) => {
|
|
23
|
+
if (!(process.env.TAMAGUI_TARGET === 'native' && isAndroid)) {
|
|
24
|
+
// this shouldnt be necessary and handled in the outer loop
|
|
25
|
+
if (key === 'elevationAndroid') return
|
|
26
|
+
}
|
|
37
27
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const styleState = subProps
|
|
43
|
-
? {
|
|
44
|
-
...styleStateIn,
|
|
45
|
-
curProps: subProps,
|
|
46
|
-
}
|
|
47
|
-
: styleStateIn
|
|
28
|
+
// we use this for the sub-props like pseudos so we need to overwrite the "props" in styleState
|
|
29
|
+
// fallbackProps is awkward thanks to static
|
|
30
|
+
// also we need to override the props here because subStyles pass in a sub-style props object
|
|
31
|
+
const subProps = styleStateIn.styleProps.fallbackProps || subPropsIn
|
|
48
32
|
|
|
49
|
-
|
|
50
|
-
|
|
33
|
+
const styleState = subProps
|
|
34
|
+
? new Proxy(styleStateIn, {
|
|
35
|
+
get(_, k) {
|
|
36
|
+
return k === 'curProps' ? subProps : Reflect.get(_, k)
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
: styleStateIn
|
|
51
40
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// prettier-ignore
|
|
55
|
-
console.warn(`Warning: no fontFamily "${fontFamily}" found in config: ${Object.keys(conf.fontsParsed).join(', ')}`)
|
|
56
|
-
}
|
|
41
|
+
const { conf, styleProps, fontFamily, staticConfig } = styleState
|
|
42
|
+
const { variants } = staticConfig
|
|
57
43
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
returnVariablesAs,
|
|
64
|
-
'',
|
|
65
|
-
avoidDefaultProps
|
|
66
|
-
)
|
|
44
|
+
// prettier-ignore
|
|
45
|
+
if (process.env.NODE_ENV === 'development' && fontFamily && fontFamily[0] === '$' && !(fontFamily in conf.fontsParsed)) {
|
|
46
|
+
// prettier-ignore
|
|
47
|
+
console.warn(`Warning: no fontFamily "${fontFamily}" found in config: ${Object.keys(conf.fontsParsed).join(', ')}`)
|
|
48
|
+
}
|
|
67
49
|
|
|
50
|
+
if (variants && key in variants && value != null) {
|
|
51
|
+
const variantValue = resolveVariants(key, value, styleProps, styleState, '')
|
|
68
52
|
if (variantValue) {
|
|
69
53
|
return variantValue
|
|
70
54
|
}
|
|
55
|
+
}
|
|
71
56
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// handle shorthands
|
|
75
|
-
if (key in conf.shorthands) {
|
|
76
|
-
shouldReturn = true
|
|
77
|
-
key = conf.shorthands[key]
|
|
78
|
-
}
|
|
57
|
+
let shouldReturn = false
|
|
79
58
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
}
|
|
59
|
+
// handle shorthands
|
|
60
|
+
if (key in conf.shorthands) {
|
|
61
|
+
shouldReturn = true
|
|
62
|
+
key = conf.shorthands[key]
|
|
63
|
+
}
|
|
87
64
|
|
|
88
|
-
|
|
89
|
-
|
|
65
|
+
if (value) {
|
|
66
|
+
if (value[0] === '$') {
|
|
67
|
+
value = getToken(key, value, styleProps, styleState)
|
|
68
|
+
} else if (isVariable(value)) {
|
|
69
|
+
value = resolveVariableValue(value, styleProps)
|
|
90
70
|
}
|
|
91
71
|
}
|
|
92
72
|
|
|
93
|
-
|
|
73
|
+
if (shouldReturn || value != null) {
|
|
74
|
+
return expandStyle(key, value) || [[key, value]]
|
|
75
|
+
}
|
|
94
76
|
}
|
|
95
77
|
|
|
96
78
|
const resolveVariants: StyleResolver = (
|
|
97
79
|
key,
|
|
98
80
|
value,
|
|
81
|
+
styleProps,
|
|
99
82
|
styleState,
|
|
100
|
-
|
|
101
|
-
returnVariablesAs,
|
|
102
|
-
parentVariantKey,
|
|
103
|
-
avoidDefaultProps = false
|
|
83
|
+
parentVariantKey
|
|
104
84
|
) => {
|
|
105
85
|
const { staticConfig, conf, debug } = styleState
|
|
106
86
|
const { variants } = staticConfig
|
|
107
|
-
|
|
108
|
-
if (!variants || !(key in variants) || value == null) {
|
|
109
|
-
return
|
|
110
|
-
}
|
|
87
|
+
if (!variants) return
|
|
111
88
|
|
|
112
89
|
let variantValue = getVariantDefinition(variants[key], key, value, conf)
|
|
113
90
|
|
|
@@ -142,10 +119,7 @@ const resolveVariants: StyleResolver = (
|
|
|
142
119
|
if (typeof variantValue === 'function') {
|
|
143
120
|
const fn = variantValue as VariantSpreadFunction<any>
|
|
144
121
|
|
|
145
|
-
variantValue = fn(
|
|
146
|
-
value,
|
|
147
|
-
getVariantExtras(styleState, defaultProps, avoidDefaultProps)
|
|
148
|
-
)
|
|
122
|
+
variantValue = fn(value, getVariantExtras(styleState))
|
|
149
123
|
|
|
150
124
|
if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
|
|
151
125
|
console.groupCollapsed(' expanded functional variant', key)
|
|
@@ -155,23 +129,6 @@ const resolveVariants: StyleResolver = (
|
|
|
155
129
|
}
|
|
156
130
|
}
|
|
157
131
|
|
|
158
|
-
// update curProps for variants expanded:
|
|
159
|
-
if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
|
|
160
|
-
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
161
|
-
console.log(` attaching updated curProps`, {
|
|
162
|
-
new: variantValue,
|
|
163
|
-
before: styleState.curProps,
|
|
164
|
-
after: {
|
|
165
|
-
...styleState.curProps,
|
|
166
|
-
...variantValue,
|
|
167
|
-
},
|
|
168
|
-
})
|
|
169
|
-
}
|
|
170
|
-
styleState.curProps = {
|
|
171
|
-
...styleState.curProps,
|
|
172
|
-
...variantValue,
|
|
173
|
-
}
|
|
174
|
-
|
|
175
132
|
let fontFamilyResult: any
|
|
176
133
|
|
|
177
134
|
if (isObj(variantValue)) {
|
|
@@ -191,11 +148,9 @@ const resolveVariants: StyleResolver = (
|
|
|
191
148
|
variantValue = resolveTokensAndVariants(
|
|
192
149
|
key,
|
|
193
150
|
variantValue,
|
|
151
|
+
styleProps,
|
|
194
152
|
styleState,
|
|
195
|
-
|
|
196
|
-
returnVariablesAs,
|
|
197
|
-
parentVariantKey,
|
|
198
|
-
avoidDefaultProps
|
|
153
|
+
parentVariantKey
|
|
199
154
|
)
|
|
200
155
|
}
|
|
201
156
|
|
|
@@ -228,7 +183,7 @@ export function getFontFamilyFromNameOrVariable(input: any, conf: TamaguiInterna
|
|
|
228
183
|
}
|
|
229
184
|
}
|
|
230
185
|
} else if (typeof input === 'string') {
|
|
231
|
-
if (input
|
|
186
|
+
if (input[0] === '$') {
|
|
232
187
|
return input
|
|
233
188
|
}
|
|
234
189
|
}
|
|
@@ -245,11 +200,9 @@ export const getPropMappedFontFamily = (expanded?: any) => {
|
|
|
245
200
|
const resolveTokensAndVariants: StyleResolver<Object> = (
|
|
246
201
|
key, // we dont use key assume value is object instead
|
|
247
202
|
value,
|
|
203
|
+
styleProps,
|
|
248
204
|
styleState,
|
|
249
|
-
|
|
250
|
-
returnVariablesAs,
|
|
251
|
-
parentVariantKey,
|
|
252
|
-
avoidDefaultProps
|
|
205
|
+
parentVariantKey
|
|
253
206
|
) => {
|
|
254
207
|
const { conf, staticConfig, debug, theme } = styleState
|
|
255
208
|
const { variants } = staticConfig
|
|
@@ -265,22 +218,17 @@ const resolveTokensAndVariants: StyleResolver<Object> = (
|
|
|
265
218
|
const val = value[rKey]
|
|
266
219
|
|
|
267
220
|
if (variants && fKey in variants) {
|
|
221
|
+
// if its a variant expanded, attach to curProps
|
|
222
|
+
styleState.curProps[fKey] = val
|
|
223
|
+
|
|
268
224
|
// avoids infinite loop if variant is matching a style prop
|
|
269
225
|
// eg: { variants: { flex: { true: { flex: 2 } } } }
|
|
270
226
|
if (parentVariantKey && parentVariantKey === key) {
|
|
271
227
|
res[fKey] =
|
|
272
228
|
// SYNC WITH *1
|
|
273
|
-
val[0] === '$' ? getToken(fKey, val,
|
|
229
|
+
val[0] === '$' ? getToken(fKey, val, styleProps, styleState) : val
|
|
274
230
|
} else {
|
|
275
|
-
const variantOut = resolveVariants(
|
|
276
|
-
fKey,
|
|
277
|
-
val,
|
|
278
|
-
styleState,
|
|
279
|
-
defaultProps,
|
|
280
|
-
returnVariablesAs,
|
|
281
|
-
key,
|
|
282
|
-
avoidDefaultProps
|
|
283
|
-
)
|
|
231
|
+
const variantOut = resolveVariants(fKey, val, styleProps, styleState, key)
|
|
284
232
|
|
|
285
233
|
// apply, merging sub-styles
|
|
286
234
|
if (variantOut) {
|
|
@@ -299,28 +247,20 @@ const resolveTokensAndVariants: StyleResolver<Object> = (
|
|
|
299
247
|
}
|
|
300
248
|
|
|
301
249
|
if (isVariable(val)) {
|
|
302
|
-
res[fKey] =
|
|
250
|
+
res[fKey] = resolveVariableValue(val, styleProps)
|
|
303
251
|
continue
|
|
304
252
|
}
|
|
305
253
|
|
|
306
254
|
if (typeof val === 'string') {
|
|
307
255
|
const fVal =
|
|
308
256
|
// SYNC WITH *1
|
|
309
|
-
val[0] === '$' ? getToken(fKey, val,
|
|
257
|
+
val[0] === '$' ? getToken(fKey, val, styleProps, styleState) : val
|
|
310
258
|
res[fKey] = fVal
|
|
311
259
|
continue
|
|
312
260
|
}
|
|
313
261
|
|
|
314
262
|
if (isObj(val)) {
|
|
315
|
-
const subObject = resolveTokensAndVariants(
|
|
316
|
-
fKey,
|
|
317
|
-
val,
|
|
318
|
-
styleState,
|
|
319
|
-
defaultProps,
|
|
320
|
-
returnVariablesAs,
|
|
321
|
-
key,
|
|
322
|
-
avoidDefaultProps
|
|
323
|
-
)
|
|
263
|
+
const subObject = resolveTokensAndVariants(fKey, val, styleProps, styleState, key)
|
|
324
264
|
|
|
325
265
|
if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
|
|
326
266
|
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
@@ -387,9 +327,8 @@ const fontShorthand = {
|
|
|
387
327
|
const getToken = (
|
|
388
328
|
key: string,
|
|
389
329
|
value: string,
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
debug?: DebugProp
|
|
330
|
+
styleProps: SplitStyleProps,
|
|
331
|
+
styleState: GetStyleState
|
|
393
332
|
) => {
|
|
394
333
|
const { theme, conf, languageContext, fontFamily } = styleState
|
|
395
334
|
|
|
@@ -397,7 +336,7 @@ const getToken = (
|
|
|
397
336
|
let valOrVar: any
|
|
398
337
|
let hasSet = false
|
|
399
338
|
if (value in theme) {
|
|
400
|
-
if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
|
|
339
|
+
if (process.env.NODE_ENV === 'development' && styleState.debug === 'verbose') {
|
|
401
340
|
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
402
341
|
console.log(` - getting theme value for ${key} from ${value} = ${theme[value].val}`)
|
|
403
342
|
}
|
|
@@ -453,14 +392,18 @@ const getToken = (
|
|
|
453
392
|
}
|
|
454
393
|
|
|
455
394
|
if (hasSet) {
|
|
456
|
-
const out = resolveVariableValue(
|
|
395
|
+
const out = resolveVariableValue(valOrVar, styleProps)
|
|
457
396
|
return out
|
|
458
397
|
}
|
|
459
398
|
|
|
460
|
-
if (
|
|
399
|
+
if (
|
|
400
|
+
process.env.NODE_ENV === 'development' &&
|
|
401
|
+
isDevTools &&
|
|
402
|
+
styleState.debug === 'verbose'
|
|
403
|
+
) {
|
|
461
404
|
console.groupCollapsed(' ﹒ propMap (val)', key, value)
|
|
462
405
|
// rome-ignore lint/nursery/noConsoleLog: ok
|
|
463
|
-
console.log({ valOrVar, theme, hasSet
|
|
406
|
+
console.log({ valOrVar, theme, hasSet }, theme[key])
|
|
464
407
|
console.groupEnd()
|
|
465
408
|
}
|
|
466
409
|
|
|
@@ -468,51 +411,14 @@ const getToken = (
|
|
|
468
411
|
}
|
|
469
412
|
|
|
470
413
|
function resolveVariableValue(
|
|
471
|
-
key: string,
|
|
472
414
|
valOrVar: Variable | any,
|
|
473
|
-
|
|
415
|
+
{ resolveVariablesAs }: SplitStyleProps
|
|
474
416
|
) {
|
|
475
417
|
if (isVariable(valOrVar)) {
|
|
476
|
-
if (
|
|
477
|
-
return valOrVar
|
|
478
|
-
}
|
|
479
|
-
if (!isWeb || resolveAs === 'value') {
|
|
418
|
+
if (!isWeb || resolveVariablesAs === 'value') {
|
|
480
419
|
return valOrVar.val
|
|
481
420
|
}
|
|
482
421
|
return valOrVar.variable
|
|
483
422
|
}
|
|
484
423
|
return valOrVar
|
|
485
424
|
}
|
|
486
|
-
|
|
487
|
-
// TODO move to validStyleProps to merge
|
|
488
|
-
|
|
489
|
-
// just specificy the least costly, all else go to `space` (most keys - we can exclude)
|
|
490
|
-
const tokenCategories = {
|
|
491
|
-
radius: {
|
|
492
|
-
borderRadius: true,
|
|
493
|
-
borderTopLeftRadius: true,
|
|
494
|
-
borderTopRightRadius: true,
|
|
495
|
-
borderBottomLeftRadius: true,
|
|
496
|
-
borderBottomRightRadius: true,
|
|
497
|
-
},
|
|
498
|
-
size: {
|
|
499
|
-
width: true,
|
|
500
|
-
height: true,
|
|
501
|
-
minWidth: true,
|
|
502
|
-
minHeight: true,
|
|
503
|
-
maxWidth: true,
|
|
504
|
-
maxHeight: true,
|
|
505
|
-
},
|
|
506
|
-
zIndex: {
|
|
507
|
-
zIndex: true,
|
|
508
|
-
},
|
|
509
|
-
color: {
|
|
510
|
-
color: true,
|
|
511
|
-
backgroundColor: true,
|
|
512
|
-
borderColor: true,
|
|
513
|
-
borderBottomColor: true,
|
|
514
|
-
borderTopColor: true,
|
|
515
|
-
borderLeftColor: true,
|
|
516
|
-
borderRightColor: true,
|
|
517
|
-
},
|
|
518
|
-
}
|
|
@@ -7,20 +7,14 @@ export function useShallowSetState<State extends TamaguiComponentState>(
|
|
|
7
7
|
debug?: DebugProp,
|
|
8
8
|
debugName?: string
|
|
9
9
|
) {
|
|
10
|
-
return
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
return prev
|
|
22
|
-
})
|
|
23
|
-
},
|
|
24
|
-
[setter]
|
|
25
|
-
)
|
|
10
|
+
return (next: Partial<State>) => setter((prev) => shallow(prev, next))
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function shallow(prev, next) {
|
|
14
|
+
for (const key in next) {
|
|
15
|
+
if (prev[key] !== next[key]) {
|
|
16
|
+
return { ...prev, ...next }
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return prev
|
|
26
20
|
}
|
|
@@ -1,9 +1,22 @@
|
|
|
1
|
+
const WarnReAssignSymbol = Symbol()
|
|
2
|
+
|
|
1
3
|
export const withStaticProperties = function <A extends Function, B>(
|
|
2
4
|
component: A,
|
|
3
5
|
staticProps: B
|
|
4
6
|
): A & B {
|
|
5
7
|
// clone if object to stay immutable
|
|
6
8
|
const next = typeof component === 'function' ? component : { ...(component as any) }
|
|
9
|
+
|
|
10
|
+
// nice dev helper that avoids super confusing errors
|
|
11
|
+
if (process.env.NODE_ENV === 'development') {
|
|
12
|
+
if (next[WarnReAssignSymbol]) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
`Error: You're calling withStaticProperties() on a component that already has withStaticProperties() assigned to it! This will cause super strange errors.`
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
next[WarnReAssignSymbol] = true
|
|
18
|
+
}
|
|
19
|
+
|
|
7
20
|
Object.assign(next, staticProps)
|
|
8
21
|
return next as A & B
|
|
9
22
|
}
|