@tamagui/web 1.46.2 → 1.47.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/constants/constants.js +15 -15
- package/dist/cjs/constants/constants.js.map +1 -1
- package/dist/cjs/createComponent.js +82 -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 +78 -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} +64 -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 +82 -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 +77 -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} +57 -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 +142 -140
- package/src/createTamagui.ts +0 -1
- package/src/helpers/ThemeManager.tsx +10 -6
- package/src/helpers/getSplitStyles.tsx +144 -173
- 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} +72 -164
- 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,78 @@ 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
|
|
40
|
+
|
|
41
|
+
const { conf, styleProps, fontFamily, staticConfig } = styleState
|
|
42
|
+
const { variants } = staticConfig
|
|
51
43
|
|
|
44
|
+
// prettier-ignore
|
|
45
|
+
if (process.env.NODE_ENV === 'development' && fontFamily && fontFamily[0] === '$' && !(fontFamily in conf.fontsParsed)) {
|
|
52
46
|
// prettier-ignore
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
console.warn(`Warning: no fontFamily "${fontFamily}" found in config: ${Object.keys(conf.fontsParsed).join(', ')}`)
|
|
56
|
-
}
|
|
47
|
+
console.warn(`Warning: no fontFamily "${fontFamily}" found in config: ${Object.keys(conf.fontsParsed).join(', ')}`)
|
|
48
|
+
}
|
|
57
49
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
value,
|
|
61
|
-
styleState,
|
|
62
|
-
defaultProps,
|
|
63
|
-
returnVariablesAs,
|
|
64
|
-
'',
|
|
65
|
-
avoidDefaultProps
|
|
66
|
-
)
|
|
50
|
+
if (variants && key in variants && value != null) {
|
|
51
|
+
styleState.curProps[key] = value
|
|
67
52
|
|
|
53
|
+
const variantValue = resolveVariants(key, value, styleProps, styleState, '')
|
|
68
54
|
if (variantValue) {
|
|
69
55
|
return variantValue
|
|
70
56
|
}
|
|
57
|
+
}
|
|
71
58
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// handle shorthands
|
|
75
|
-
if (key in conf.shorthands) {
|
|
76
|
-
shouldReturn = true
|
|
77
|
-
key = conf.shorthands[key]
|
|
78
|
-
}
|
|
59
|
+
let shouldReturn = false
|
|
79
60
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
}
|
|
61
|
+
// handle shorthands
|
|
62
|
+
if (key in conf.shorthands) {
|
|
63
|
+
shouldReturn = true
|
|
64
|
+
key = conf.shorthands[key]
|
|
65
|
+
}
|
|
87
66
|
|
|
88
|
-
|
|
89
|
-
|
|
67
|
+
if (value) {
|
|
68
|
+
if (value[0] === '$') {
|
|
69
|
+
value = getToken(key, value, styleProps, styleState)
|
|
70
|
+
} else if (isVariable(value)) {
|
|
71
|
+
value = resolveVariableValue(value, styleProps)
|
|
90
72
|
}
|
|
91
73
|
}
|
|
92
74
|
|
|
93
|
-
|
|
75
|
+
if (shouldReturn || value != null) {
|
|
76
|
+
return expandStyle(key, value) || [[key, value]]
|
|
77
|
+
}
|
|
94
78
|
}
|
|
95
79
|
|
|
96
80
|
const resolveVariants: StyleResolver = (
|
|
97
81
|
key,
|
|
98
82
|
value,
|
|
83
|
+
styleProps,
|
|
99
84
|
styleState,
|
|
100
|
-
|
|
101
|
-
returnVariablesAs,
|
|
102
|
-
parentVariantKey,
|
|
103
|
-
avoidDefaultProps = false
|
|
85
|
+
parentVariantKey
|
|
104
86
|
) => {
|
|
105
87
|
const { staticConfig, conf, debug } = styleState
|
|
106
88
|
const { variants } = staticConfig
|
|
107
|
-
|
|
108
|
-
if (!variants || !(key in variants) || value == null) {
|
|
109
|
-
return
|
|
110
|
-
}
|
|
89
|
+
if (!variants) return
|
|
111
90
|
|
|
112
91
|
let variantValue = getVariantDefinition(variants[key], key, value, conf)
|
|
113
92
|
|
|
@@ -142,10 +121,7 @@ const resolveVariants: StyleResolver = (
|
|
|
142
121
|
if (typeof variantValue === 'function') {
|
|
143
122
|
const fn = variantValue as VariantSpreadFunction<any>
|
|
144
123
|
|
|
145
|
-
variantValue = fn(
|
|
146
|
-
value,
|
|
147
|
-
getVariantExtras(styleState, defaultProps, avoidDefaultProps)
|
|
148
|
-
)
|
|
124
|
+
variantValue = fn(value, getVariantExtras(styleState))
|
|
149
125
|
|
|
150
126
|
if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
|
|
151
127
|
console.groupCollapsed(' expanded functional variant', key)
|
|
@@ -155,23 +131,6 @@ const resolveVariants: StyleResolver = (
|
|
|
155
131
|
}
|
|
156
132
|
}
|
|
157
133
|
|
|
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
134
|
let fontFamilyResult: any
|
|
176
135
|
|
|
177
136
|
if (isObj(variantValue)) {
|
|
@@ -191,11 +150,9 @@ const resolveVariants: StyleResolver = (
|
|
|
191
150
|
variantValue = resolveTokensAndVariants(
|
|
192
151
|
key,
|
|
193
152
|
variantValue,
|
|
153
|
+
styleProps,
|
|
194
154
|
styleState,
|
|
195
|
-
|
|
196
|
-
returnVariablesAs,
|
|
197
|
-
parentVariantKey,
|
|
198
|
-
avoidDefaultProps
|
|
155
|
+
parentVariantKey
|
|
199
156
|
)
|
|
200
157
|
}
|
|
201
158
|
|
|
@@ -228,7 +185,7 @@ export function getFontFamilyFromNameOrVariable(input: any, conf: TamaguiInterna
|
|
|
228
185
|
}
|
|
229
186
|
}
|
|
230
187
|
} else if (typeof input === 'string') {
|
|
231
|
-
if (input
|
|
188
|
+
if (input[0] === '$') {
|
|
232
189
|
return input
|
|
233
190
|
}
|
|
234
191
|
}
|
|
@@ -245,11 +202,9 @@ export const getPropMappedFontFamily = (expanded?: any) => {
|
|
|
245
202
|
const resolveTokensAndVariants: StyleResolver<Object> = (
|
|
246
203
|
key, // we dont use key assume value is object instead
|
|
247
204
|
value,
|
|
205
|
+
styleProps,
|
|
248
206
|
styleState,
|
|
249
|
-
|
|
250
|
-
returnVariablesAs,
|
|
251
|
-
parentVariantKey,
|
|
252
|
-
avoidDefaultProps
|
|
207
|
+
parentVariantKey
|
|
253
208
|
) => {
|
|
254
209
|
const { conf, staticConfig, debug, theme } = styleState
|
|
255
210
|
const { variants } = staticConfig
|
|
@@ -265,22 +220,17 @@ const resolveTokensAndVariants: StyleResolver<Object> = (
|
|
|
265
220
|
const val = value[rKey]
|
|
266
221
|
|
|
267
222
|
if (variants && fKey in variants) {
|
|
223
|
+
// if its a variant expanded, attach to curProps
|
|
224
|
+
styleState.curProps[fKey] = val
|
|
225
|
+
|
|
268
226
|
// avoids infinite loop if variant is matching a style prop
|
|
269
227
|
// eg: { variants: { flex: { true: { flex: 2 } } } }
|
|
270
228
|
if (parentVariantKey && parentVariantKey === key) {
|
|
271
229
|
res[fKey] =
|
|
272
230
|
// SYNC WITH *1
|
|
273
|
-
val[0] === '$' ? getToken(fKey, val,
|
|
231
|
+
val[0] === '$' ? getToken(fKey, val, styleProps, styleState) : val
|
|
274
232
|
} else {
|
|
275
|
-
const variantOut = resolveVariants(
|
|
276
|
-
fKey,
|
|
277
|
-
val,
|
|
278
|
-
styleState,
|
|
279
|
-
defaultProps,
|
|
280
|
-
returnVariablesAs,
|
|
281
|
-
key,
|
|
282
|
-
avoidDefaultProps
|
|
283
|
-
)
|
|
233
|
+
const variantOut = resolveVariants(fKey, val, styleProps, styleState, key)
|
|
284
234
|
|
|
285
235
|
// apply, merging sub-styles
|
|
286
236
|
if (variantOut) {
|
|
@@ -299,28 +249,20 @@ const resolveTokensAndVariants: StyleResolver<Object> = (
|
|
|
299
249
|
}
|
|
300
250
|
|
|
301
251
|
if (isVariable(val)) {
|
|
302
|
-
res[fKey] =
|
|
252
|
+
res[fKey] = resolveVariableValue(val, styleProps)
|
|
303
253
|
continue
|
|
304
254
|
}
|
|
305
255
|
|
|
306
256
|
if (typeof val === 'string') {
|
|
307
257
|
const fVal =
|
|
308
258
|
// SYNC WITH *1
|
|
309
|
-
val[0] === '$' ? getToken(fKey, val,
|
|
259
|
+
val[0] === '$' ? getToken(fKey, val, styleProps, styleState) : val
|
|
310
260
|
res[fKey] = fVal
|
|
311
261
|
continue
|
|
312
262
|
}
|
|
313
263
|
|
|
314
264
|
if (isObj(val)) {
|
|
315
|
-
const subObject = resolveTokensAndVariants(
|
|
316
|
-
fKey,
|
|
317
|
-
val,
|
|
318
|
-
styleState,
|
|
319
|
-
defaultProps,
|
|
320
|
-
returnVariablesAs,
|
|
321
|
-
key,
|
|
322
|
-
avoidDefaultProps
|
|
323
|
-
)
|
|
265
|
+
const subObject = resolveTokensAndVariants(fKey, val, styleProps, styleState, key)
|
|
324
266
|
|
|
325
267
|
if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
|
|
326
268
|
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
@@ -387,9 +329,8 @@ const fontShorthand = {
|
|
|
387
329
|
const getToken = (
|
|
388
330
|
key: string,
|
|
389
331
|
value: string,
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
debug?: DebugProp
|
|
332
|
+
styleProps: SplitStyleProps,
|
|
333
|
+
styleState: GetStyleState
|
|
393
334
|
) => {
|
|
394
335
|
const { theme, conf, languageContext, fontFamily } = styleState
|
|
395
336
|
|
|
@@ -397,7 +338,7 @@ const getToken = (
|
|
|
397
338
|
let valOrVar: any
|
|
398
339
|
let hasSet = false
|
|
399
340
|
if (value in theme) {
|
|
400
|
-
if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
|
|
341
|
+
if (process.env.NODE_ENV === 'development' && styleState.debug === 'verbose') {
|
|
401
342
|
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
402
343
|
console.log(` - getting theme value for ${key} from ${value} = ${theme[value].val}`)
|
|
403
344
|
}
|
|
@@ -453,14 +394,18 @@ const getToken = (
|
|
|
453
394
|
}
|
|
454
395
|
|
|
455
396
|
if (hasSet) {
|
|
456
|
-
const out = resolveVariableValue(
|
|
397
|
+
const out = resolveVariableValue(valOrVar, styleProps)
|
|
457
398
|
return out
|
|
458
399
|
}
|
|
459
400
|
|
|
460
|
-
if (
|
|
401
|
+
if (
|
|
402
|
+
process.env.NODE_ENV === 'development' &&
|
|
403
|
+
isDevTools &&
|
|
404
|
+
styleState.debug === 'verbose'
|
|
405
|
+
) {
|
|
461
406
|
console.groupCollapsed(' ﹒ propMap (val)', key, value)
|
|
462
407
|
// rome-ignore lint/nursery/noConsoleLog: ok
|
|
463
|
-
console.log({ valOrVar, theme, hasSet
|
|
408
|
+
console.log({ valOrVar, theme, hasSet }, theme[key])
|
|
464
409
|
console.groupEnd()
|
|
465
410
|
}
|
|
466
411
|
|
|
@@ -468,51 +413,14 @@ const getToken = (
|
|
|
468
413
|
}
|
|
469
414
|
|
|
470
415
|
function resolveVariableValue(
|
|
471
|
-
key: string,
|
|
472
416
|
valOrVar: Variable | any,
|
|
473
|
-
|
|
417
|
+
{ resolveVariablesAs }: SplitStyleProps
|
|
474
418
|
) {
|
|
475
419
|
if (isVariable(valOrVar)) {
|
|
476
|
-
if (
|
|
477
|
-
return valOrVar
|
|
478
|
-
}
|
|
479
|
-
if (!isWeb || resolveAs === 'value') {
|
|
420
|
+
if (!isWeb || resolveVariablesAs === 'value') {
|
|
480
421
|
return valOrVar.val
|
|
481
422
|
}
|
|
482
423
|
return valOrVar.variable
|
|
483
424
|
}
|
|
484
425
|
return valOrVar
|
|
485
426
|
}
|
|
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
|
}
|