@tamagui/web 1.101.0 → 1.101.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/createComponent.js +23 -15
- package/dist/cjs/createComponent.js.map +1 -1
- package/dist/cjs/createComponent.native.js +13 -10
- package/dist/cjs/createComponent.native.js.map +2 -2
- package/dist/cjs/createTokens.js.map +1 -1
- package/dist/cjs/createTokens.native.js.map +1 -1
- package/dist/cjs/helpers/createMediaStyle.js +2 -6
- package/dist/cjs/helpers/createMediaStyle.js.map +1 -1
- package/dist/cjs/helpers/createMediaStyle.native.js +51 -7
- package/dist/cjs/helpers/createMediaStyle.native.js.map +2 -2
- package/dist/cjs/helpers/expandStyles.js.map +1 -1
- package/dist/cjs/helpers/expandStyles.native.js.map +1 -1
- package/dist/cjs/helpers/getSplitStyles.js +77 -60
- package/dist/cjs/helpers/getSplitStyles.js.map +1 -1
- package/dist/cjs/helpers/getSplitStyles.native.js +55 -42
- package/dist/cjs/helpers/getSplitStyles.native.js.map +2 -2
- package/dist/cjs/helpers/getStylesAtomic.js +7 -6
- package/dist/cjs/helpers/getStylesAtomic.js.map +1 -1
- package/dist/cjs/helpers/insertStyleRule.js +17 -14
- package/dist/cjs/helpers/insertStyleRule.js.map +1 -1
- package/dist/cjs/helpers/insertStyleRule.native.js +4 -3
- package/dist/cjs/helpers/insertStyleRule.native.js.map +2 -2
- package/dist/cjs/helpers/propMapper.js +1 -1
- package/dist/cjs/helpers/propMapper.js.map +1 -1
- package/dist/cjs/helpers/propMapper.native.js +1 -1
- package/dist/cjs/helpers/propMapper.native.js.map +2 -2
- package/dist/cjs/hooks/useDidHydrateOnce.js +4 -10
- package/dist/cjs/hooks/useDidHydrateOnce.js.map +1 -1
- package/dist/cjs/hooks/useDidHydrateOnce.native.js +11 -1
- package/dist/cjs/hooks/useDidHydrateOnce.native.js.map +2 -2
- package/dist/cjs/hooks/useMedia.js +39 -27
- package/dist/cjs/hooks/useMedia.js.map +2 -2
- package/dist/cjs/hooks/useMedia.native.js +38 -44
- package/dist/cjs/hooks/useMedia.native.js.map +2 -2
- package/dist/cjs/views/TamaguiProvider.js.map +1 -1
- package/dist/cjs/views/TamaguiProvider.native.js.map +1 -1
- package/dist/esm/createComponent.js +29 -16
- package/dist/esm/createComponent.js.map +1 -1
- package/dist/esm/createComponent.mjs +18 -16
- package/dist/esm/createComponent.native.js +14 -11
- package/dist/esm/createComponent.native.js.map +2 -2
- package/dist/esm/createTokens.js.map +1 -1
- package/dist/esm/createTokens.native.js.map +1 -1
- package/dist/esm/helpers/createMediaStyle.js +2 -6
- package/dist/esm/helpers/createMediaStyle.js.map +1 -1
- package/dist/esm/helpers/createMediaStyle.mjs +2 -10
- package/dist/esm/helpers/createMediaStyle.native.js +49 -6
- package/dist/esm/helpers/createMediaStyle.native.js.map +2 -2
- package/dist/esm/helpers/expandStyles.js.map +1 -1
- package/dist/esm/helpers/expandStyles.native.js.map +1 -1
- package/dist/esm/helpers/getSplitStyles.js +81 -60
- package/dist/esm/helpers/getSplitStyles.js.map +1 -1
- package/dist/esm/helpers/getSplitStyles.mjs +83 -64
- package/dist/esm/helpers/getSplitStyles.native.js +56 -43
- package/dist/esm/helpers/getSplitStyles.native.js.map +2 -2
- package/dist/esm/helpers/getStylesAtomic.js +7 -6
- package/dist/esm/helpers/getStylesAtomic.js.map +1 -1
- package/dist/esm/helpers/getStylesAtomic.mjs +3 -7
- package/dist/esm/helpers/insertStyleRule.js +17 -13
- package/dist/esm/helpers/insertStyleRule.js.map +1 -1
- package/dist/esm/helpers/insertStyleRule.mjs +6 -5
- package/dist/esm/helpers/insertStyleRule.native.js +4 -2
- package/dist/esm/helpers/insertStyleRule.native.js.map +2 -2
- package/dist/esm/helpers/propMapper.js +1 -1
- package/dist/esm/helpers/propMapper.js.map +1 -1
- package/dist/esm/helpers/propMapper.mjs +1 -2
- package/dist/esm/helpers/propMapper.native.js +1 -1
- package/dist/esm/helpers/propMapper.native.js.map +2 -2
- package/dist/esm/hooks/useDidHydrateOnce.js +5 -11
- package/dist/esm/hooks/useDidHydrateOnce.js.map +1 -1
- package/dist/esm/hooks/useDidHydrateOnce.mjs +7 -11
- package/dist/esm/hooks/useDidHydrateOnce.native.js +11 -2
- package/dist/esm/hooks/useDidHydrateOnce.native.js.map +2 -2
- package/dist/esm/hooks/useMedia.js +39 -28
- package/dist/esm/hooks/useMedia.js.map +2 -2
- package/dist/esm/hooks/useMedia.mjs +34 -33
- package/dist/esm/hooks/useMedia.native.js +38 -45
- package/dist/esm/hooks/useMedia.native.js.map +2 -2
- package/dist/esm/views/TamaguiProvider.js.map +1 -1
- package/dist/esm/views/TamaguiProvider.native.js.map +1 -1
- package/package.json +12 -12
- package/src/createComponent.tsx +38 -21
- package/src/createTokens.ts +1 -21
- package/src/helpers/createMediaStyle.ts +2 -6
- package/src/helpers/expandStyles.ts +2 -1
- package/src/helpers/getSplitStyles.tsx +116 -88
- package/src/helpers/getStylesAtomic.ts +7 -5
- package/src/helpers/insertStyleRule.tsx +6 -3
- package/src/helpers/propMapper.ts +1 -2
- package/src/hooks/useDidHydrateOnce.tsx +30 -25
- package/src/hooks/useMedia.tsx +74 -54
- package/src/types.tsx +12 -2
- package/src/views/TamaguiProvider.tsx +0 -1
- package/types/_withStableStyle.d.ts +0 -1
- package/types/_withStableStyle.d.ts.map +1 -1
- package/types/config.d.ts +1 -1
- package/types/constants/accessibilityDirectMap.d.ts.map +1 -1
- package/types/constants/webToNativeProps.native.d.ts.map +1 -1
- package/types/createComponent.d.ts.map +1 -1
- package/types/createFont.d.ts.map +1 -1
- package/types/createTheme.d.ts.map +1 -1
- package/types/createTokens.d.ts +1 -1
- package/types/createTokens.d.ts.map +1 -1
- package/types/createVariable.d.ts +1 -1
- package/types/createVariable.d.ts.map +1 -1
- package/types/createVariables.d.ts +1 -1
- package/types/createVariables.d.ts.map +1 -1
- package/types/helpers/ThemeManagerContext.d.ts +0 -1
- package/types/helpers/ThemeManagerContext.d.ts.map +1 -1
- package/types/helpers/createMediaStyle.d.ts.map +1 -1
- package/types/helpers/createShallowSetState.d.ts.map +1 -1
- package/types/helpers/expandStyles.d.ts.map +1 -1
- package/types/helpers/getSplitStyles.d.ts.map +1 -1
- package/types/helpers/getStylesAtomic.d.ts.map +1 -1
- package/types/helpers/insertStyleRule.d.ts.map +1 -1
- package/types/helpers/isTamaguiElement.d.ts +1 -2
- package/types/helpers/isTamaguiElement.d.ts.map +1 -1
- package/types/helpers/propMapper.d.ts.map +1 -1
- package/types/helpers/setElementProps.d.ts.map +1 -1
- package/types/helpers/themeable.d.ts.map +1 -1
- package/types/hooks/useConfiguration.d.ts +50 -52
- package/types/hooks/useConfiguration.d.ts.map +1 -1
- package/types/hooks/useDidHydrateOnce.d.ts +1 -1
- package/types/hooks/useDidHydrateOnce.d.ts.map +1 -1
- package/types/hooks/useMedia.d.ts +6 -7
- package/types/hooks/useMedia.d.ts.map +1 -1
- package/types/hooks/useTheme.d.ts.map +1 -1
- package/types/styled.d.ts.map +1 -1
- package/types/types.d.ts +3 -2
- package/types/types.d.ts.map +1 -1
- package/types/views/Configuration.d.ts +0 -1
- package/types/views/Configuration.d.ts.map +1 -1
- package/types/views/TamaguiProvider.d.ts.map +1 -1
- package/dist/esm/constants/accessibilityDirectMap.native.mjs +0 -6
- package/dist/esm/constants/webToNativeProps.native.mjs +0 -77
- package/dist/esm/helpers/getStylesAtomic.native.mjs +0 -7
- package/dist/esm/helpers/getThemeCSSRules.native.mjs +0 -4
- package/dist/esm/helpers/matchMedia.native.mjs +0 -14
- package/dist/esm/helpers/normalizeStylePropKeys.native.mjs +0 -13
- package/dist/esm/helpers/setElementProps.native.mjs +0 -6
- package/dist/esm/helpers/webPropsToSkip.native.mjs +0 -55
- package/dist/esm/views/FontLanguage.native.mjs +0 -15
- package/dist/esm/views/ThemeDebug.native.mjs +0 -9
package/src/createComponent.tsx
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { composeRefs } from '@tamagui/compose-refs'
|
|
2
2
|
import { isClient, isServer, isWeb } from '@tamagui/constants'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
StyleObjectIdentifier,
|
|
5
|
+
StyleObjectRules,
|
|
6
|
+
composeEventHandlers,
|
|
7
|
+
validStyles,
|
|
8
|
+
} from '@tamagui/helpers'
|
|
4
9
|
import React, {
|
|
5
10
|
Children,
|
|
6
11
|
Fragment,
|
|
@@ -10,7 +15,6 @@ import React, {
|
|
|
10
15
|
useContext,
|
|
11
16
|
useEffect,
|
|
12
17
|
useId,
|
|
13
|
-
useLayoutEffect,
|
|
14
18
|
useMemo,
|
|
15
19
|
useRef,
|
|
16
20
|
useState,
|
|
@@ -36,6 +40,7 @@ import { log } from './helpers/log'
|
|
|
36
40
|
import { mergeProps } from './helpers/mergeProps'
|
|
37
41
|
import { setElementProps } from './helpers/setElementProps'
|
|
38
42
|
import { themeable } from './helpers/themeable'
|
|
43
|
+
import { useDidHydrateOnce } from './hooks/useDidHydrateOnce'
|
|
39
44
|
import { mediaKeyMatch, setMediaShouldUpdate, useMedia } from './hooks/useMedia'
|
|
40
45
|
import { useThemeWithState } from './hooks/useTheme'
|
|
41
46
|
import type { TamaguiComponentEvents } from './interfaces/TamaguiComponentEvents'
|
|
@@ -69,7 +74,6 @@ import type {
|
|
|
69
74
|
import { Slot } from './views/Slot'
|
|
70
75
|
import { getThemedChildren } from './views/Theme'
|
|
71
76
|
import { ThemeDebug } from './views/ThemeDebug'
|
|
72
|
-
import { useDidHydrateOnce } from './hooks/useDidHydrateOnce'
|
|
73
77
|
|
|
74
78
|
/**
|
|
75
79
|
* All things that need one-time setup after createTamagui is called
|
|
@@ -156,7 +160,12 @@ export const useComponentState = (
|
|
|
156
160
|
) => {
|
|
157
161
|
const useAnimations = animationDriver?.useAnimations as UseAnimationHook | undefined
|
|
158
162
|
|
|
159
|
-
const stateRef = useRef<TamaguiComponentStateRef>(
|
|
163
|
+
const stateRef = useRef<TamaguiComponentStateRef>(
|
|
164
|
+
undefined as any as TamaguiComponentStateRef
|
|
165
|
+
)
|
|
166
|
+
if (!stateRef.current) {
|
|
167
|
+
stateRef.current = {}
|
|
168
|
+
}
|
|
160
169
|
|
|
161
170
|
// after we get states mount we need to turn off isAnimated for server side
|
|
162
171
|
const hasAnimationProp = Boolean(
|
|
@@ -197,19 +206,21 @@ export const useComponentState = (
|
|
|
197
206
|
|
|
198
207
|
const hasEnterState = hasEnterStyle || isEntering
|
|
199
208
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
209
|
+
// this can be conditional because its only ever needed with animations
|
|
210
|
+
const didHydrateOnce = willBeAnimated ? useDidHydrateOnce() : true
|
|
211
|
+
const shouldEnter = hasEnterState || (!didHydrateOnce && hasRNAnimation)
|
|
212
|
+
const shouldEnterFromUnhydrated = isWeb && !didHydrateOnce
|
|
213
|
+
|
|
214
|
+
const initialState = shouldEnter
|
|
215
|
+
? // on the very first render we switch all spring animation drivers to css rendering
|
|
216
|
+
// this is because we need to use css variables, which they don't support to do proper SSR
|
|
217
|
+
// without flickers of the wrong colors.
|
|
218
|
+
// but once we do that initial hydration and we are in client side rendering mode,
|
|
219
|
+
// we can avoid the extra re-render on mount
|
|
220
|
+
shouldEnterFromUnhydrated
|
|
221
|
+
? defaultComponentState
|
|
222
|
+
: defaultComponentStateShouldEnter
|
|
223
|
+
: defaultComponentStateMounted
|
|
213
224
|
|
|
214
225
|
// will be nice to deprecate half of these:
|
|
215
226
|
const disabled = isDisabled(props)
|
|
@@ -706,7 +717,7 @@ export function createComponent<
|
|
|
706
717
|
if (process.env.NODE_ENV === 'development' && time) time`theme`
|
|
707
718
|
|
|
708
719
|
// HOOK 14 (-1 if no animation, -1 if disableSSR, -1 if no context, -1 if production)
|
|
709
|
-
const mediaState = useMedia(stateRef, componentContext)
|
|
720
|
+
const mediaState = useMedia(stateRef, componentContext, debugProp)
|
|
710
721
|
|
|
711
722
|
setDidGetVariableValue(false)
|
|
712
723
|
|
|
@@ -725,6 +736,7 @@ export function createComponent<
|
|
|
725
736
|
resolveValues,
|
|
726
737
|
isExiting,
|
|
727
738
|
isAnimated,
|
|
739
|
+
willBeAnimated,
|
|
728
740
|
} as const
|
|
729
741
|
|
|
730
742
|
// HOOK 15 (-1 if no animation, -1 if disableSSR, -1 if no context, -1 if production)
|
|
@@ -758,7 +770,11 @@ export function createComponent<
|
|
|
758
770
|
didGetVariableValue() ||
|
|
759
771
|
isMediaArray ||
|
|
760
772
|
(noClassNames && splitStyles.hasMedia === true)
|
|
761
|
-
|
|
773
|
+
|
|
774
|
+
const mediaListeningKeys = isMediaArray ? (splitStyles.hasMedia as string[]) : null
|
|
775
|
+
if (process.env.NODE_ENV === 'development' && debugProp) {
|
|
776
|
+
console.info(`useMedia() createComponent`, shouldListenForMedia, mediaListeningKeys)
|
|
777
|
+
}
|
|
762
778
|
|
|
763
779
|
setMediaShouldUpdate(stateRef, {
|
|
764
780
|
enabled: shouldListenForMedia,
|
|
@@ -1296,7 +1312,8 @@ export function createComponent<
|
|
|
1296
1312
|
<>
|
|
1297
1313
|
{content}
|
|
1298
1314
|
{/* lets see if we can put a single style tag per rule for optimal de-duping */}
|
|
1299
|
-
{splitStyles.rulesToInsert.map((
|
|
1315
|
+
{splitStyles.rulesToInsert.map((styleObject) => {
|
|
1316
|
+
const identifier = styleObject[StyleObjectIdentifier]
|
|
1300
1317
|
return (
|
|
1301
1318
|
<style
|
|
1302
1319
|
key={identifier}
|
|
@@ -1305,7 +1322,7 @@ export function createComponent<
|
|
|
1305
1322
|
// @ts-ignore
|
|
1306
1323
|
precedence="default"
|
|
1307
1324
|
>
|
|
1308
|
-
{
|
|
1325
|
+
{styleObject[StyleObjectRules].join('\n')}
|
|
1309
1326
|
</style>
|
|
1310
1327
|
)
|
|
1311
1328
|
})}
|
package/src/createTokens.ts
CHANGED
|
@@ -2,20 +2,14 @@ import type { Variable } from './createVariable'
|
|
|
2
2
|
import { createVariables } from './createVariables'
|
|
3
3
|
import type { CreateTokens } from './types'
|
|
4
4
|
|
|
5
|
-
// tokens.color.dark.red ===> { var: `color-dark-red`, val: '' }
|
|
6
5
|
export function createTokens<T extends CreateTokens>(tokens: T): MakeTokens<T> {
|
|
7
6
|
return createVariables(tokens) as any
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
type NormalizeTokens<A, Type = A[keyof A]> = {
|
|
11
|
-
|
|
12
|
-
// which is important because Chrome re-orders numerical-seeming keys :/
|
|
13
|
-
[Key in keyof A extends `$${infer X}` ? X : keyof A]: Variable<Type>
|
|
10
|
+
[Key in keyof A extends number ? `${keyof A}` : keyof A]: Variable<Type>
|
|
14
11
|
}
|
|
15
12
|
|
|
16
|
-
// verbose but gives us nice types...
|
|
17
|
-
// removes $ prefix allowing for defining either as $1: or 1:,
|
|
18
|
-
// which is important because Chrome re-orders numerical-seeming keys :/
|
|
19
13
|
type MakeTokens<T extends CreateTokens> = T extends {
|
|
20
14
|
color?: infer E
|
|
21
15
|
space?: infer F
|
|
@@ -36,17 +30,3 @@ type MakeTokens<T extends CreateTokens> = T extends {
|
|
|
36
30
|
'color' | 'space' | 'size' | 'radius' | 'zIndex'
|
|
37
31
|
>
|
|
38
32
|
: never
|
|
39
|
-
|
|
40
|
-
// // test
|
|
41
|
-
// // TODO move to tests
|
|
42
|
-
// const tokens = createTokens({
|
|
43
|
-
// size: { 0: 1 },
|
|
44
|
-
// space: { 0: 1 },
|
|
45
|
-
// radius: { 0: 1 },
|
|
46
|
-
// zIndex: { 0: 1 },
|
|
47
|
-
// color: { 0: 'hi' },
|
|
48
|
-
// arbitrary: { abc: '123' },
|
|
49
|
-
// })
|
|
50
|
-
|
|
51
|
-
// tokens.arbitrary.abc
|
|
52
|
-
// tokens.size['0']
|
|
@@ -22,7 +22,7 @@ export const createMediaStyle = (
|
|
|
22
22
|
negate?: boolean,
|
|
23
23
|
priority?: number
|
|
24
24
|
): MediaStyleObject => {
|
|
25
|
-
const
|
|
25
|
+
const [property, _value, identifier, _pseudo, rules] = styleObject
|
|
26
26
|
const conf = getConfig()
|
|
27
27
|
const enableMediaPropOrder = conf.settings.mediaPropOrder
|
|
28
28
|
const isTheme = type === 'theme'
|
|
@@ -129,9 +129,5 @@ export const createMediaStyle = (
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
return
|
|
133
|
-
property,
|
|
134
|
-
rules: [styleRule],
|
|
135
|
-
identifier: nextIdentifier,
|
|
136
|
-
}
|
|
132
|
+
return [property, undefined, nextIdentifier, undefined, [styleRule]]
|
|
137
133
|
}
|
|
@@ -12,6 +12,7 @@ export function fixStyles(style: Record<string, any>) {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
// TODO deprecate for web-style shadows
|
|
15
16
|
if (
|
|
16
17
|
style.shadowRadius != null ||
|
|
17
18
|
style.shadowColor ||
|
|
@@ -21,7 +22,7 @@ export function fixStyles(style: Record<string, any>) {
|
|
|
21
22
|
Object.assign(style, normalizeShadow(style))
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
//
|
|
25
|
+
// could be optimized better
|
|
25
26
|
// ensure border style set by default to solid
|
|
26
27
|
for (const key in borderDefaults) {
|
|
27
28
|
if (key in style) {
|
|
@@ -7,6 +7,10 @@ import {
|
|
|
7
7
|
useIsomorphicLayoutEffect,
|
|
8
8
|
} from '@tamagui/constants'
|
|
9
9
|
import {
|
|
10
|
+
StyleObjectIdentifier,
|
|
11
|
+
StyleObjectProperty,
|
|
12
|
+
StyleObjectPseudo,
|
|
13
|
+
StyleObjectRules,
|
|
10
14
|
stylePropsText,
|
|
11
15
|
stylePropsTransform,
|
|
12
16
|
tokenCategories,
|
|
@@ -68,9 +72,6 @@ import { pseudoDescriptors, pseudoPriorities } from './pseudoDescriptors'
|
|
|
68
72
|
import { skipProps } from './skipProps'
|
|
69
73
|
import { transformsToString } from './transformsToString'
|
|
70
74
|
|
|
71
|
-
// bugfix for some reason it gets reset
|
|
72
|
-
const IS_STATIC = process.env.IS_STATIC === 'is_static'
|
|
73
|
-
|
|
74
75
|
export type SplitStyles = ReturnType<typeof getSplitStyles>
|
|
75
76
|
|
|
76
77
|
export type SplitStyleResult = ReturnType<typeof getSplitStyles>
|
|
@@ -185,8 +186,17 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
185
186
|
/**
|
|
186
187
|
* Not the biggest fan of creating an object but it is a nice API
|
|
187
188
|
*/
|
|
189
|
+
let curPropsState
|
|
188
190
|
const styleState: GetStyleState = {
|
|
189
|
-
|
|
191
|
+
// this should go away, right now we're doing really crazy cumulative props,
|
|
192
|
+
// as variants are resolved basically we go back and merge the results onto
|
|
193
|
+
// the curProps, so that each following variant function recieves the current
|
|
194
|
+
// "styles" with variants expanded. powerful, but i think too fancy
|
|
195
|
+
// there's some part of the ui kit that depends on it we'd have to find and fix
|
|
196
|
+
get curProps() {
|
|
197
|
+
curPropsState ||= {}
|
|
198
|
+
return curPropsState
|
|
199
|
+
},
|
|
190
200
|
classNames,
|
|
191
201
|
conf,
|
|
192
202
|
props,
|
|
@@ -221,24 +231,32 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
221
231
|
console.groupEnd()
|
|
222
232
|
}
|
|
223
233
|
|
|
234
|
+
const { asChild } = props
|
|
235
|
+
const { accept } = staticConfig
|
|
236
|
+
const { noSkip, disableExpandShorthands, noExpand } = styleProps
|
|
237
|
+
const { webContainerType } = conf.settings
|
|
238
|
+
const parentVariants = parentStaticConfig?.variants
|
|
239
|
+
|
|
224
240
|
for (const keyOg in props) {
|
|
225
241
|
let keyInit = keyOg
|
|
226
|
-
let valInit = props[
|
|
242
|
+
let valInit = props[keyInit]
|
|
227
243
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
keyInit
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
244
|
+
// for custom accept sub-styles
|
|
245
|
+
if (accept) {
|
|
246
|
+
const accepted = accept[keyInit]
|
|
247
|
+
if (
|
|
248
|
+
(accepted === 'style' || accepted === 'textStyle') &&
|
|
249
|
+
valInit &&
|
|
250
|
+
typeof valInit === 'object'
|
|
251
|
+
) {
|
|
252
|
+
viewProps[keyInit] = getSubStyle(
|
|
253
|
+
styleState,
|
|
254
|
+
keyInit,
|
|
255
|
+
valInit,
|
|
256
|
+
styleProps.noClassNames
|
|
257
|
+
)
|
|
258
|
+
continue
|
|
259
|
+
}
|
|
242
260
|
}
|
|
243
261
|
|
|
244
262
|
if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
|
|
@@ -248,7 +266,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
248
266
|
}
|
|
249
267
|
|
|
250
268
|
// normalize shorthands up front
|
|
251
|
-
if (!
|
|
269
|
+
if (!disableExpandShorthands) {
|
|
252
270
|
if (keyInit in shorthands) {
|
|
253
271
|
keyInit = shorthands[keyInit]
|
|
254
272
|
}
|
|
@@ -259,25 +277,27 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
259
277
|
|
|
260
278
|
if (process.env.TAMAGUI_TARGET === 'web') {
|
|
261
279
|
// skip the webViewFlexCompatStyles when asChild on web
|
|
262
|
-
if (
|
|
280
|
+
if (asChild && webViewFlexCompatStyles[keyInit] === valInit) {
|
|
263
281
|
continue
|
|
264
282
|
}
|
|
265
283
|
}
|
|
266
284
|
|
|
267
285
|
// keyInit === 'style' is handled in skipProps
|
|
268
|
-
if (keyInit in skipProps && !
|
|
286
|
+
if (keyInit in skipProps && !noSkip && !isHOC) {
|
|
269
287
|
if (keyInit === 'group') {
|
|
270
288
|
if (process.env.TAMAGUI_TARGET === 'web') {
|
|
271
289
|
// add container style
|
|
272
290
|
const identifier = `t_group_${valInit}`
|
|
273
|
-
const containerType =
|
|
274
|
-
const containerCSS =
|
|
291
|
+
const containerType = webContainerType || 'inline-size'
|
|
292
|
+
const containerCSS = [
|
|
293
|
+
'continer',
|
|
294
|
+
undefined,
|
|
275
295
|
identifier,
|
|
276
|
-
|
|
277
|
-
|
|
296
|
+
undefined,
|
|
297
|
+
[
|
|
278
298
|
`.${identifier} { container-name: ${valInit}; container-type: ${containerType}; }`,
|
|
279
299
|
],
|
|
280
|
-
|
|
300
|
+
] satisfies StyleObject
|
|
281
301
|
addStyleToInsertRules(rulesToInsert, containerCSS)
|
|
282
302
|
}
|
|
283
303
|
}
|
|
@@ -287,6 +307,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
287
307
|
const valInitType = typeof valInit
|
|
288
308
|
const isValidStyleKeyInit = isValidStyleKey(keyInit, staticConfig)
|
|
289
309
|
|
|
310
|
+
// this is all for partially optimized (not flattened)... maybe worth removing?
|
|
290
311
|
if (process.env.TAMAGUI_TARGET === 'web') {
|
|
291
312
|
if (isValidStyleKeyInit && valInitType === 'string') {
|
|
292
313
|
if (valInit[0] === '_') {
|
|
@@ -315,12 +336,12 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
315
336
|
}
|
|
316
337
|
}
|
|
317
338
|
|
|
318
|
-
if (valInit !== props[keyInit]) {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
}
|
|
339
|
+
// if (valInit !== props[keyInit]) {
|
|
340
|
+
// // we collect updated props as we go, for functional variants later
|
|
341
|
+
// // functional variants receive a prop object that represents the current
|
|
342
|
+
// // props at that point in the loop
|
|
343
|
+
// styleState.curProps[keyInit] = valInit
|
|
344
|
+
// }
|
|
324
345
|
|
|
325
346
|
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
326
347
|
if (!isValidStyleKeyInit) {
|
|
@@ -339,6 +360,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
339
360
|
}
|
|
340
361
|
}
|
|
341
362
|
|
|
363
|
+
// TODO deprecate dataSet be sure we map on native from data-
|
|
342
364
|
if (keyInit === 'dataSet') {
|
|
343
365
|
for (const keyInit in valInit) {
|
|
344
366
|
viewProps[`data-${hyphenate(keyInit)}`] = valInit[keyInit]
|
|
@@ -347,7 +369,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
347
369
|
}
|
|
348
370
|
|
|
349
371
|
if (process.env.TAMAGUI_TARGET === 'web') {
|
|
350
|
-
if (!
|
|
372
|
+
if (!noExpand) {
|
|
351
373
|
/**
|
|
352
374
|
* Copying in the accessibility/prop handling from react-native-web here
|
|
353
375
|
* Keeps it in a single loop, avoids dup de-structuring to avoid bundle size
|
|
@@ -486,25 +508,19 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
486
508
|
}
|
|
487
509
|
|
|
488
510
|
const isStyleProp =
|
|
489
|
-
isValidStyleKeyInit ||
|
|
490
|
-
isMediaOrPseudo ||
|
|
491
|
-
(isVariant && !styleProps.noExpand) ||
|
|
492
|
-
isShorthand
|
|
511
|
+
isValidStyleKeyInit || isMediaOrPseudo || (isVariant && !noExpand) || isShorthand
|
|
493
512
|
|
|
494
|
-
if (
|
|
495
|
-
isStyleProp &&
|
|
496
|
-
(props.asChild === 'except-style' || props.asChild === 'except-style-web')
|
|
497
|
-
) {
|
|
513
|
+
if (isStyleProp && (asChild === 'except-style' || asChild === 'except-style-web')) {
|
|
498
514
|
continue
|
|
499
515
|
}
|
|
500
516
|
|
|
501
517
|
const shouldPassProp =
|
|
502
518
|
!isStyleProp ||
|
|
503
519
|
// is in parent variants
|
|
504
|
-
(isHOC &&
|
|
520
|
+
(isHOC && parentVariants && keyInit in parentVariants) ||
|
|
505
521
|
inlineProps?.has(keyInit)
|
|
506
522
|
|
|
507
|
-
const parentVariant =
|
|
523
|
+
const parentVariant = parentVariants?.[keyInit]
|
|
508
524
|
const isHOCShouldPassThrough = Boolean(
|
|
509
525
|
isHOC &&
|
|
510
526
|
(isShorthand ||
|
|
@@ -571,7 +587,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
571
587
|
}
|
|
572
588
|
|
|
573
589
|
// after shouldPassThrough
|
|
574
|
-
if (!
|
|
590
|
+
if (!noSkip) {
|
|
575
591
|
if (keyInit in skipProps) {
|
|
576
592
|
if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
|
|
577
593
|
console.groupEnd()
|
|
@@ -649,7 +665,10 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
649
665
|
isMediaOrPseudo = Boolean(isMedia || isPseudo)
|
|
650
666
|
isVariant = variants && key in variants
|
|
651
667
|
|
|
652
|
-
if (
|
|
668
|
+
if (
|
|
669
|
+
inlineProps?.has(key) ||
|
|
670
|
+
(process.env.IS_STATIC === 'is_static' && inlineWhenUnflattened?.has(key))
|
|
671
|
+
) {
|
|
653
672
|
viewProps[key] = props[key] ?? val
|
|
654
673
|
}
|
|
655
674
|
|
|
@@ -690,10 +709,10 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
690
709
|
continue
|
|
691
710
|
}
|
|
692
711
|
|
|
693
|
-
if (!shouldDoClasses || IS_STATIC) {
|
|
712
|
+
if (!shouldDoClasses || process.env.IS_STATIC === 'is_static') {
|
|
694
713
|
pseudos ||= {}
|
|
695
714
|
pseudos[key] ||= {}
|
|
696
|
-
if (IS_STATIC) {
|
|
715
|
+
if (process.env.IS_STATIC === 'is_static') {
|
|
697
716
|
Object.assign(pseudos[key], pseudoStyleObject)
|
|
698
717
|
continue
|
|
699
718
|
}
|
|
@@ -712,7 +731,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
712
731
|
}
|
|
713
732
|
|
|
714
733
|
for (const psuedoStyle of pseudoStyles) {
|
|
715
|
-
const fullKey = `${psuedoStyle
|
|
734
|
+
const fullKey = `${psuedoStyle[StyleObjectProperty]}${PROP_SPLIT}${descriptor.name}`
|
|
716
735
|
if (fullKey in usedKeys) continue
|
|
717
736
|
|
|
718
737
|
addStyleToInsertRules(rulesToInsert, psuedoStyle)
|
|
@@ -720,7 +739,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
720
739
|
transforms,
|
|
721
740
|
classNames,
|
|
722
741
|
fullKey,
|
|
723
|
-
psuedoStyle
|
|
742
|
+
psuedoStyle[StyleObjectIdentifier],
|
|
724
743
|
isMediaOrPseudo,
|
|
725
744
|
true
|
|
726
745
|
)
|
|
@@ -803,6 +822,21 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
803
822
|
if (isMedia) {
|
|
804
823
|
if (!val) continue
|
|
805
824
|
|
|
825
|
+
// for some reason 'space' in val upsetting next ssr during prod build
|
|
826
|
+
// technically i guess this also will not apply if 0 space which makes sense?
|
|
827
|
+
const hasSpace = val['space']
|
|
828
|
+
const mediaKeyShort = key.slice(1)
|
|
829
|
+
|
|
830
|
+
hasMedia ||= true
|
|
831
|
+
|
|
832
|
+
if (hasSpace || !shouldDoClasses || styleProps.willBeAnimated) {
|
|
833
|
+
if (!Array.isArray(hasMedia)) {
|
|
834
|
+
hasMedia = []
|
|
835
|
+
}
|
|
836
|
+
hasMedia.push(mediaKeyShort)
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
// can bail early
|
|
806
840
|
if (isMedia === 'platform') {
|
|
807
841
|
const platform = key.slice(10)
|
|
808
842
|
if (
|
|
@@ -815,10 +849,6 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
815
849
|
}
|
|
816
850
|
}
|
|
817
851
|
|
|
818
|
-
hasMedia ||= true
|
|
819
|
-
|
|
820
|
-
const mediaKeyShort = key.slice(1)
|
|
821
|
-
|
|
822
852
|
if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
|
|
823
853
|
log(` 📺 ${key}`, {
|
|
824
854
|
key,
|
|
@@ -827,19 +857,10 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
827
857
|
shouldDoClasses,
|
|
828
858
|
acceptsClassName,
|
|
829
859
|
componentState,
|
|
860
|
+
mediaState,
|
|
830
861
|
})
|
|
831
862
|
}
|
|
832
863
|
|
|
833
|
-
// for some reason 'space' in val upsetting next ssr during prod build
|
|
834
|
-
// technically i guess this also will not apply if 0 space which makes sense?
|
|
835
|
-
const hasSpace = val['space']
|
|
836
|
-
if (hasSpace || !shouldDoClasses) {
|
|
837
|
-
if (!Array.isArray(hasMedia)) {
|
|
838
|
-
hasMedia = []
|
|
839
|
-
}
|
|
840
|
-
hasMedia.push(mediaKeyShort)
|
|
841
|
-
}
|
|
842
|
-
|
|
843
864
|
if (shouldDoClasses) {
|
|
844
865
|
const mediaStyle = getSubStyle(styleState, key, val, false)
|
|
845
866
|
|
|
@@ -881,25 +902,39 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
881
902
|
if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
|
|
882
903
|
log(`📺 media style:`, out)
|
|
883
904
|
}
|
|
884
|
-
const fullKey = `${style
|
|
885
|
-
style
|
|
905
|
+
const fullKey = `${style[StyleObjectProperty]}${PROP_SPLIT}${mediaKeyShort}${
|
|
906
|
+
style[StyleObjectPseudo] || ''
|
|
886
907
|
}`
|
|
887
908
|
if (fullKey in usedKeys) continue
|
|
888
909
|
addStyleToInsertRules(rulesToInsert, out as any)
|
|
889
|
-
mergeClassName(
|
|
910
|
+
mergeClassName(
|
|
911
|
+
transforms,
|
|
912
|
+
classNames,
|
|
913
|
+
fullKey,
|
|
914
|
+
out[StyleObjectIdentifier],
|
|
915
|
+
true,
|
|
916
|
+
true
|
|
917
|
+
)
|
|
890
918
|
}
|
|
891
919
|
} else {
|
|
892
|
-
const mediaStyle = getSubStyle(styleState, key, val, true)
|
|
893
920
|
const isThemeMedia = isMedia === 'theme'
|
|
894
921
|
const isGroupMedia = isMedia === 'group'
|
|
895
922
|
const isPlatformMedia = isMedia === 'platform'
|
|
896
923
|
|
|
897
924
|
if (!isThemeMedia && !isPlatformMedia && !isGroupMedia) {
|
|
898
925
|
if (!mediaState[mediaKeyShort]) {
|
|
926
|
+
if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
|
|
927
|
+
log(` 📺 ❌ DISABLED ${mediaKeyShort}`)
|
|
928
|
+
}
|
|
899
929
|
continue
|
|
900
930
|
}
|
|
931
|
+
if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
|
|
932
|
+
log(` 📺 ✅ ENABLED ${mediaKeyShort}`)
|
|
933
|
+
}
|
|
901
934
|
}
|
|
902
935
|
|
|
936
|
+
const mediaStyle = getSubStyle(styleState, key, val, true)
|
|
937
|
+
|
|
903
938
|
let importanceBump = 0
|
|
904
939
|
|
|
905
940
|
if (isThemeMedia) {
|
|
@@ -1023,8 +1058,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
1023
1058
|
fixStyles(styleState.style)
|
|
1024
1059
|
|
|
1025
1060
|
// shouldn't this be better? but breaks some tests weirdly, need to check
|
|
1026
|
-
|
|
1027
|
-
if (isWeb && !staticConfig.isReactNative) {
|
|
1061
|
+
if (isWeb && !isReactNative) {
|
|
1028
1062
|
styleToCSS(styleState.style)
|
|
1029
1063
|
}
|
|
1030
1064
|
}
|
|
@@ -1095,7 +1129,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
1095
1129
|
const atomic = getStylesAtomic(styleState.style)
|
|
1096
1130
|
|
|
1097
1131
|
for (const atomicStyle of atomic) {
|
|
1098
|
-
const key = atomicStyle
|
|
1132
|
+
const [key, value, identifier] = atomicStyle
|
|
1099
1133
|
const isAnimatedAndAnimateOnly =
|
|
1100
1134
|
styleProps.isAnimated &&
|
|
1101
1135
|
styleProps.noClassNames &&
|
|
@@ -1113,18 +1147,11 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
1113
1147
|
retainedStyles[key] = styleState.style[key]
|
|
1114
1148
|
} else if (nonAnimatedAnimateOnly) {
|
|
1115
1149
|
retainedStyles ||= {}
|
|
1116
|
-
retainedStyles[key] =
|
|
1150
|
+
retainedStyles[key] = value
|
|
1117
1151
|
shouldRetain = true
|
|
1118
1152
|
} else {
|
|
1119
1153
|
addStyleToInsertRules(rulesToInsert, atomicStyle)
|
|
1120
|
-
mergeClassName(
|
|
1121
|
-
transforms,
|
|
1122
|
-
classNames,
|
|
1123
|
-
key,
|
|
1124
|
-
atomicStyle.identifier,
|
|
1125
|
-
false,
|
|
1126
|
-
true
|
|
1127
|
-
)
|
|
1154
|
+
mergeClassName(transforms, classNames, key, identifier, false, true)
|
|
1128
1155
|
}
|
|
1129
1156
|
}
|
|
1130
1157
|
|
|
@@ -1135,7 +1162,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
1135
1162
|
console.groupEnd()
|
|
1136
1163
|
}
|
|
1137
1164
|
|
|
1138
|
-
if (shouldRetain || !IS_STATIC) {
|
|
1165
|
+
if (shouldRetain || !(process.env.IS_STATIC === 'is_static')) {
|
|
1139
1166
|
styleState.style = retainedStyles || {}
|
|
1140
1167
|
}
|
|
1141
1168
|
}
|
|
@@ -1152,11 +1179,13 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
1152
1179
|
const identifier = `_transform${hash}`
|
|
1153
1180
|
if (isClient && !insertedTransforms[identifier]) {
|
|
1154
1181
|
const rule = `.${identifier} { transform: ${val}; }`
|
|
1155
|
-
addStyleToInsertRules(rulesToInsert,
|
|
1182
|
+
addStyleToInsertRules(rulesToInsert, [
|
|
1183
|
+
namespace,
|
|
1184
|
+
val,
|
|
1156
1185
|
identifier,
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1186
|
+
undefined,
|
|
1187
|
+
[rule],
|
|
1188
|
+
] satisfies StyleObject)
|
|
1160
1189
|
}
|
|
1161
1190
|
classNames[namespace] = identifier
|
|
1162
1191
|
}
|
|
@@ -1268,7 +1297,6 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
1268
1297
|
mediaGroups,
|
|
1269
1298
|
}
|
|
1270
1299
|
|
|
1271
|
-
const asChild = props.asChild
|
|
1272
1300
|
const asChildExceptStyleLike =
|
|
1273
1301
|
asChild === 'except-style' || asChild === 'except-style-web'
|
|
1274
1302
|
|
|
@@ -1480,11 +1508,11 @@ export const useSplitStyles: StyleSplitter = (a, b, c, d, e, f, g, h, i, j) => {
|
|
|
1480
1508
|
|
|
1481
1509
|
function addStyleToInsertRules(rulesToInsert: RulesToInsert, styleObject: StyleObject) {
|
|
1482
1510
|
if (process.env.TAMAGUI_TARGET === 'web') {
|
|
1483
|
-
if (!shouldInsertStyleRules(styleObject
|
|
1511
|
+
if (!shouldInsertStyleRules(styleObject[StyleObjectIdentifier])) {
|
|
1484
1512
|
return
|
|
1485
1513
|
}
|
|
1486
1514
|
if (!process.env.TAMAGUI_REACT_19) {
|
|
1487
|
-
updateRules(styleObject
|
|
1515
|
+
updateRules(styleObject[StyleObjectIdentifier], styleObject[StyleObjectRules])
|
|
1488
1516
|
}
|
|
1489
1517
|
rulesToInsert.push(styleObject)
|
|
1490
1518
|
}
|
|
@@ -53,6 +53,7 @@ export const getStyleAtomic = (
|
|
|
53
53
|
|
|
54
54
|
let conf: TamaguiInternalConfig
|
|
55
55
|
|
|
56
|
+
// this could be cached for performance?
|
|
56
57
|
const getStyleObject = (
|
|
57
58
|
style: ViewStyleWithPseudos,
|
|
58
59
|
key: string,
|
|
@@ -71,13 +72,14 @@ const getStyleObject = (
|
|
|
71
72
|
const shortProp = conf.inverseShorthands[key] || key
|
|
72
73
|
const identifier = `_${shortProp}-${pseudoPrefix}${hash}`
|
|
73
74
|
const rules = createAtomicRules(identifier, key, value, pseudo)
|
|
74
|
-
return
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
return [
|
|
76
|
+
// array for performance
|
|
77
|
+
key,
|
|
78
|
+
value,
|
|
77
79
|
identifier,
|
|
80
|
+
pseudo?.name as any,
|
|
78
81
|
rules,
|
|
79
|
-
|
|
80
|
-
}
|
|
82
|
+
]
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
export function styleToCSS(style: Record<string, any>) {
|