@tamagui/core 1.0.1-rc.8 → 1.0.1-rc.9
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/Pressability.js +32 -0
- package/dist/cjs/Pressability.js.map +7 -0
- package/dist/cjs/Pressability.native.js +32 -0
- package/dist/cjs/Pressability.native.js.map +7 -0
- package/dist/cjs/ThemeContext.js +30 -0
- package/dist/cjs/ThemeContext.js.map +7 -0
- package/dist/cjs/ThemeManager.js +211 -0
- package/dist/cjs/ThemeManager.js.map +7 -0
- package/dist/cjs/conf.js +70 -0
- package/dist/cjs/conf.js.map +7 -0
- package/dist/cjs/constants/platform.js +4 -10
- package/dist/cjs/constants/platform.js.map +2 -2
- package/dist/cjs/constants/rnw.native.js +28 -0
- package/dist/cjs/constants/rnw.native.js.map +7 -0
- package/dist/cjs/contexts/ButtonInsideButtonContext.js.map +1 -1
- package/dist/cjs/createTamagui.js +2 -0
- package/dist/cjs/createTamagui.js.map +2 -2
- package/dist/cjs/defaultComponentState.js +2 -0
- package/dist/cjs/defaultComponentState.js.map +7 -0
- package/dist/cjs/helpers/assignNativePropsToWeb.js.map +1 -1
- package/dist/cjs/helpers/assignNativePropsToWeb.native.js.map +1 -1
- package/dist/cjs/helpers/calc.js.map +2 -2
- package/dist/cjs/helpers/createShallowUpdate.js +9 -12
- package/dist/cjs/helpers/createShallowUpdate.js.map +1 -1
- package/dist/cjs/helpers/createTamaguiProvider.js +65 -0
- package/dist/cjs/helpers/createTamaguiProvider.js.map +7 -0
- package/dist/cjs/helpers/cssHash.js +51 -0
- package/dist/cjs/helpers/cssHash.js.map +7 -0
- package/dist/cjs/helpers/expandStyle.test.js +10 -0
- package/dist/cjs/helpers/expandStyle.test.js.map +7 -0
- package/dist/cjs/helpers/getFont.js +2 -6
- package/dist/cjs/helpers/getFont.js.map +2 -2
- package/dist/cjs/helpers/getSplitStyles.js +14 -9
- package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
- package/dist/cjs/helpers/getStackSize.js.map +1 -1
- package/dist/cjs/helpers/insertStyleRule.js +60 -27
- package/dist/cjs/helpers/insertStyleRule.js.map +3 -3
- package/dist/cjs/helpers/nativeGestureHandler.native.js +19 -0
- package/dist/cjs/helpers/nativeGestureHandler.native.js.map +7 -0
- package/dist/cjs/helpers/normalizeValueWithProperty.js +3 -3
- package/dist/cjs/helpers/normalizeValueWithProperty.js.map +2 -2
- package/dist/cjs/helpers/startTransition.js +1 -4
- package/dist/cjs/helpers/startTransition.js.map +2 -2
- package/dist/cjs/helpers/themeable.js +2 -2
- package/dist/cjs/helpers/themeable.js.map +2 -2
- package/dist/cjs/helpers/wrapThemeManagerContext.js +37 -0
- package/dist/cjs/helpers/wrapThemeManagerContext.js.map +7 -0
- package/dist/cjs/hooks/useConstant.js +0 -3
- package/dist/cjs/hooks/useConstant.js.map +2 -2
- package/dist/cjs/hooks/useElementLayout.js +1 -1
- package/dist/cjs/hooks/useElementLayout.js.map +2 -2
- package/dist/cjs/hooks/useFeatures.js +201 -0
- package/dist/cjs/hooks/useFeatures.js.map +7 -0
- package/dist/cjs/hooks/useIsMounted.js.map +1 -1
- package/dist/cjs/hooks/useIsSSR.js +6 -10
- package/dist/cjs/hooks/useIsSSR.js.map +2 -2
- package/dist/cjs/hooks/useMedia.js +5 -0
- package/dist/cjs/hooks/useMedia.js.map +2 -2
- package/dist/cjs/hooks/usePressable.js.map +1 -1
- package/dist/cjs/hooks/usePrevious.js +1 -0
- package/dist/cjs/hooks/usePrevious.js.map +7 -0
- package/dist/cjs/hooks/useUnmountEffect.js.map +1 -1
- package/dist/cjs/styled.js +12 -0
- package/dist/cjs/styled.js.map +2 -2
- package/dist/cjs/views/TextAncestorContext.js +44 -0
- package/dist/cjs/views/TextAncestorContext.js.map +7 -0
- package/dist/cjs/views/ThemeInverse.js +20 -21
- package/dist/cjs/views/ThemeInverse.js.map +2 -2
- package/dist/cjs/views/ThemeReset.js +5 -10
- package/dist/cjs/views/ThemeReset.js.map +3 -3
- package/dist/esm/Pressability.js +7 -0
- package/dist/esm/Pressability.js.map +7 -0
- package/dist/esm/Pressability.native.js +7 -0
- package/dist/esm/Pressability.native.js.map +7 -0
- package/dist/esm/ThemeContext.js +6 -0
- package/dist/esm/ThemeContext.js.map +7 -0
- package/dist/esm/ThemeManager.js +185 -0
- package/dist/esm/ThemeManager.js.map +7 -0
- package/dist/esm/conf.js +39 -0
- package/dist/esm/conf.js.map +7 -0
- package/dist/esm/constants/platform.js +3 -7
- package/dist/esm/constants/platform.js.map +2 -2
- package/dist/esm/constants/rnw.native.js +5 -0
- package/dist/esm/constants/rnw.native.js.map +7 -0
- package/dist/esm/contexts/ButtonInsideButtonContext.js.map +1 -1
- package/dist/esm/createTamagui.js +7 -1
- package/dist/esm/createTamagui.js.map +2 -2
- package/dist/esm/defaultComponentState.js +1 -0
- package/dist/esm/defaultComponentState.js.map +7 -0
- package/dist/esm/helpers/assignNativePropsToWeb.js.map +1 -1
- package/dist/esm/helpers/assignNativePropsToWeb.native.js.map +1 -1
- package/dist/esm/helpers/calc.js.map +2 -2
- package/dist/esm/helpers/createShallowUpdate.js +9 -12
- package/dist/esm/helpers/createShallowUpdate.js.map +1 -1
- package/dist/esm/helpers/createTamaguiProvider.js +38 -0
- package/dist/esm/helpers/createTamaguiProvider.js.map +7 -0
- package/dist/esm/helpers/cssHash.js +27 -0
- package/dist/esm/helpers/cssHash.js.map +7 -0
- package/dist/esm/helpers/expandStyle.test.js +9 -0
- package/dist/esm/helpers/expandStyle.test.js.map +7 -0
- package/dist/esm/helpers/getFont.js +2 -6
- package/dist/esm/helpers/getFont.js.map +2 -2
- package/dist/esm/helpers/getSplitStyles.js +16 -10
- package/dist/esm/helpers/getSplitStyles.js.map +2 -2
- package/dist/esm/helpers/getStackSize.js.map +1 -1
- package/dist/esm/helpers/insertStyleRule.js +58 -26
- package/dist/esm/helpers/insertStyleRule.js.map +3 -3
- package/dist/esm/helpers/nativeGestureHandler.native.js +2 -0
- package/dist/esm/helpers/nativeGestureHandler.native.js.map +7 -0
- package/dist/esm/helpers/normalizeValueWithProperty.js +3 -3
- package/dist/esm/helpers/normalizeValueWithProperty.js.map +2 -2
- package/dist/esm/helpers/startTransition.js.map +1 -1
- package/dist/esm/helpers/themeable.js +2 -2
- package/dist/esm/helpers/themeable.js.map +2 -2
- package/dist/esm/helpers/wrapThemeManagerContext.js +11 -0
- package/dist/esm/helpers/wrapThemeManagerContext.js.map +7 -0
- package/dist/esm/hooks/useConstant.js +1 -4
- package/dist/esm/hooks/useConstant.js.map +2 -2
- package/dist/esm/hooks/useElementLayout.js +1 -1
- package/dist/esm/hooks/useElementLayout.js.map +2 -2
- package/dist/esm/hooks/useFeatures.js +174 -0
- package/dist/esm/hooks/useFeatures.js.map +7 -0
- package/dist/esm/hooks/useIsMounted.js.map +1 -1
- package/dist/esm/hooks/useIsSSR.js +8 -12
- package/dist/esm/hooks/useIsSSR.js.map +2 -2
- package/dist/esm/hooks/useMedia.js +4 -0
- package/dist/esm/hooks/useMedia.js.map +2 -2
- package/dist/esm/hooks/usePressable.js.map +1 -1
- package/dist/esm/hooks/usePrevious.js +1 -0
- package/dist/esm/hooks/usePrevious.js.map +7 -0
- package/dist/esm/hooks/useUnmountEffect.js.map +1 -1
- package/dist/esm/styled.js +12 -0
- package/dist/esm/styled.js.map +2 -2
- package/dist/esm/views/TextAncestorContext.js +15 -0
- package/dist/esm/views/TextAncestorContext.js.map +7 -0
- package/dist/esm/views/ThemeInverse.js +15 -20
- package/dist/esm/views/ThemeInverse.js.map +2 -2
- package/dist/esm/views/ThemeReset.js +4 -6
- package/dist/esm/views/ThemeReset.js.map +2 -2
- package/package.json +10 -11
- package/src/createTamagui.ts +8 -1
- package/src/helpers/getSplitStyles.tsx +17 -9
- package/src/helpers/insertStyleRule.tsx +70 -38
- package/src/helpers/normalizeValueWithProperty.ts +3 -3
- package/src/helpers/themeable.tsx +3 -3
- package/src/hooks/useElementLayout.tsx +1 -1
- package/src/hooks/useMedia.tsx +3 -0
- package/src/styled.tsx +15 -0
- package/types/helpers/insertStyleRule.d.ts +2 -1
- package/types/helpers/themeable.d.ts +1 -1
- package/types/hooks/useMedia.d.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/core",
|
|
3
|
-
"version": "1.0.1-rc.
|
|
3
|
+
"version": "1.0.1-rc.9",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -28,14 +28,14 @@
|
|
|
28
28
|
"reset.css"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@tamagui/compose-refs": "^1.0.1-rc.
|
|
32
|
-
"@tamagui/constants": "^1.0.1-rc.
|
|
33
|
-
"@tamagui/helpers": "^1.0.1-rc.
|
|
34
|
-
"@tamagui/react-native-use-pressable": "^1.0.1-rc.
|
|
35
|
-
"@tamagui/react-native-use-responder-events": "^1.0.1-rc.
|
|
36
|
-
"@tamagui/use-did-finish-ssr": "^1.0.1-rc.
|
|
37
|
-
"@tamagui/use-event": "^1.0.1-rc.
|
|
38
|
-
"@tamagui/use-force-update": "^1.0.1-rc.
|
|
31
|
+
"@tamagui/compose-refs": "^1.0.1-rc.9",
|
|
32
|
+
"@tamagui/constants": "^1.0.1-rc.9",
|
|
33
|
+
"@tamagui/helpers": "^1.0.1-rc.9",
|
|
34
|
+
"@tamagui/react-native-use-pressable": "^1.0.1-rc.9",
|
|
35
|
+
"@tamagui/react-native-use-responder-events": "^1.0.1-rc.9",
|
|
36
|
+
"@tamagui/use-did-finish-ssr": "^1.0.1-rc.9",
|
|
37
|
+
"@tamagui/use-event": "^1.0.1-rc.9",
|
|
38
|
+
"@tamagui/use-force-update": "^1.0.1-rc.9",
|
|
39
39
|
"normalize-css-color": "^1.0.2"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
@@ -43,10 +43,9 @@
|
|
|
43
43
|
"react-dom": "^18.2.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@tamagui/build": "^1.0.1-rc.
|
|
46
|
+
"@tamagui/build": "^1.0.1-rc.9",
|
|
47
47
|
"@testing-library/react": "^13.4.0",
|
|
48
48
|
"csstype": "^3.0.10",
|
|
49
|
-
"esbuild": "^0.15.11",
|
|
50
49
|
"react": "^18.2.0",
|
|
51
50
|
"react-dom": "^18.2.0",
|
|
52
51
|
"typescript": "^4.7.4",
|
package/src/createTamagui.ts
CHANGED
|
@@ -3,7 +3,11 @@ import { isRSC, isWeb } from '@tamagui/constants'
|
|
|
3
3
|
import { configListeners, setConfig } from './config'
|
|
4
4
|
import { createVariables } from './createVariables'
|
|
5
5
|
import { getThemeCSSRules } from './helpers/getThemeCSSRules'
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
getAllRules,
|
|
8
|
+
listenForSheetChanges,
|
|
9
|
+
scanAllSheets,
|
|
10
|
+
} from './helpers/insertStyleRule'
|
|
7
11
|
import {
|
|
8
12
|
registerCSSVariable,
|
|
9
13
|
tokensValueToVariable,
|
|
@@ -42,6 +46,9 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
|
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
48
|
|
|
49
|
+
scanAllSheets()
|
|
50
|
+
listenForSheetChanges()
|
|
51
|
+
|
|
45
52
|
const fontTokens = Object.fromEntries(
|
|
46
53
|
Object.entries(configIn.fonts!).map(([k, v]) => {
|
|
47
54
|
return [k, createVariables(v, 'f', true)]
|
|
@@ -20,6 +20,7 @@ import { isDevTools } from '../constants/isDevTools'
|
|
|
20
20
|
import {
|
|
21
21
|
getMediaImportanceIfMoreImportant,
|
|
22
22
|
mediaState as globalMediaState,
|
|
23
|
+
mediaKeysWithAndWithout$,
|
|
23
24
|
mediaQueryConfig,
|
|
24
25
|
mergeMediaByImportance,
|
|
25
26
|
} from '../hooks/useMedia'
|
|
@@ -45,8 +46,8 @@ import {
|
|
|
45
46
|
RulesToInsert,
|
|
46
47
|
insertStyleRules,
|
|
47
48
|
insertedTransforms,
|
|
49
|
+
scanAllSheets,
|
|
48
50
|
shouldInsertStyleRules,
|
|
49
|
-
updateInserted,
|
|
50
51
|
updateRules,
|
|
51
52
|
} from './insertStyleRule'
|
|
52
53
|
import { FlatTransforms, mergeTransform, mergeTransforms } from './mergeTransform'
|
|
@@ -205,7 +206,7 @@ const accessibilityRoleToWebRole = {
|
|
|
205
206
|
// const classNames = {}
|
|
206
207
|
|
|
207
208
|
const isMediaKey = (key: string) =>
|
|
208
|
-
Boolean(key[0] === '$' &&
|
|
209
|
+
Boolean(key[0] === '$' && mediaKeysWithAndWithout$.has(key))
|
|
209
210
|
|
|
210
211
|
export const getSplitStyles: StyleSplitter = (
|
|
211
212
|
props,
|
|
@@ -217,6 +218,10 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
217
218
|
elementType,
|
|
218
219
|
debug
|
|
219
220
|
) => {
|
|
221
|
+
if (cache.has(props)) {
|
|
222
|
+
return cache.get(props)
|
|
223
|
+
}
|
|
224
|
+
|
|
220
225
|
conf = conf || getConfig()
|
|
221
226
|
const { shorthands } = conf
|
|
222
227
|
const {
|
|
@@ -320,8 +325,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
320
325
|
const valInit = props[keyInit]
|
|
321
326
|
|
|
322
327
|
// normalize shorthands up front
|
|
323
|
-
|
|
324
|
-
if (expandedKey) {
|
|
328
|
+
if (keyInit in shorthands) {
|
|
325
329
|
keyInit = shorthands[keyInit]
|
|
326
330
|
}
|
|
327
331
|
|
|
@@ -329,8 +333,8 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
329
333
|
if (keyInit in skipProps) continue
|
|
330
334
|
if (!isWeb && keyInit.startsWith('data-')) continue
|
|
331
335
|
|
|
332
|
-
if (
|
|
333
|
-
if (
|
|
336
|
+
if (typeof valInit === 'string' && valInit[0] === '_') {
|
|
337
|
+
if (keyInit in validStyleProps || keyInit.includes('-')) {
|
|
334
338
|
if (shouldDoClasses) {
|
|
335
339
|
classNames[keyInit] = valInit
|
|
336
340
|
} else {
|
|
@@ -538,7 +542,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
538
542
|
)
|
|
539
543
|
) {
|
|
540
544
|
// web-only, exclude all other accessibility props not handled above
|
|
541
|
-
if (isWeb && keyInit.
|
|
545
|
+
if (isWeb && keyInit.indexOf('ccessibility') > 0) {
|
|
542
546
|
continue
|
|
543
547
|
}
|
|
544
548
|
usedKeys[keyInit] = 1
|
|
@@ -766,7 +770,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
766
770
|
fontFamily = valInit[0] === '$' ? valInit : val
|
|
767
771
|
}
|
|
768
772
|
|
|
769
|
-
if (validStyleProps
|
|
773
|
+
if (key in validStyleProps) {
|
|
770
774
|
mergeStyle(styleState, key, val)
|
|
771
775
|
continue
|
|
772
776
|
}
|
|
@@ -887,6 +891,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
887
891
|
rulesToInsert,
|
|
888
892
|
parentSplitStyles,
|
|
889
893
|
flatTransforms,
|
|
894
|
+
result,
|
|
890
895
|
}
|
|
891
896
|
for (const key in { ...result, ...logs }) {
|
|
892
897
|
// eslint-disable-next-line no-console
|
|
@@ -897,6 +902,8 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
897
902
|
}
|
|
898
903
|
}
|
|
899
904
|
|
|
905
|
+
cache.set(props, result)
|
|
906
|
+
|
|
900
907
|
return result
|
|
901
908
|
}
|
|
902
909
|
|
|
@@ -916,7 +923,8 @@ function mergeClassName(
|
|
|
916
923
|
if (isClient) {
|
|
917
924
|
if (!transform) {
|
|
918
925
|
// HMR or loaded a new chunk
|
|
919
|
-
|
|
926
|
+
console.warn(`got a new ting`)
|
|
927
|
+
scanAllSheets()
|
|
920
928
|
transform = insertedTransforms[val]
|
|
921
929
|
if (process.env.NODE_ENV === 'development') {
|
|
922
930
|
if (!transform) {
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
// this needs to check if its inserted already? 99% of the time it is
|
|
2
|
-
// this should avoid re-inserts, but need to test the perf trade-offs
|
|
3
|
-
// i tested with the site itself and the initial insert was trivial
|
|
4
|
-
|
|
5
1
|
import type { StyleObject } from '@tamagui/helpers'
|
|
6
2
|
|
|
7
3
|
const allSelectors: Record<string, string> = {}
|
|
@@ -17,18 +13,7 @@ function addTransform(identifier: string, css: string, rule?: CSSRule) {
|
|
|
17
13
|
const s = css.indexOf('transform:')
|
|
18
14
|
if (s === -1) {
|
|
19
15
|
if (process.env.NODE_ENV === 'development') {
|
|
20
|
-
|
|
21
|
-
console.groupCollapsed(
|
|
22
|
-
`❌ Invalid transform, likely used deg/% improperly ${identifier}`
|
|
23
|
-
)
|
|
24
|
-
// eslint-disable-next-line no-console
|
|
25
|
-
console.log('rule:', rule)
|
|
26
|
-
// eslint-disable-next-line no-console
|
|
27
|
-
console.trace()
|
|
28
|
-
// eslint-disable-next-line no-console
|
|
29
|
-
console.groupEnd()
|
|
30
|
-
} else {
|
|
31
|
-
// missing transform
|
|
16
|
+
console.error(`❌ Invalid transform, likely used deg/% improperly ${identifier}`)
|
|
32
17
|
}
|
|
33
18
|
return false
|
|
34
19
|
}
|
|
@@ -50,9 +35,33 @@ const isClient = typeof document !== 'undefined'
|
|
|
50
35
|
// 1. debugging at dev time
|
|
51
36
|
// 2. avoid duplicate insert styles at runtime
|
|
52
37
|
// 3. used now for merging transforms atomically
|
|
38
|
+
|
|
39
|
+
// multiple sheets could have the same ids so we have to count
|
|
40
|
+
|
|
53
41
|
const scannedNum = new WeakMap<CSSStyleSheet, number>()
|
|
42
|
+
const totalSheetSelectors = new Map<string, number>()
|
|
43
|
+
const referencesInSheet = new WeakMap<CSSStyleSheet>()
|
|
44
|
+
|
|
45
|
+
export function listenForSheetChanges() {
|
|
46
|
+
if (!isClient) return
|
|
47
|
+
function handleNode(node: Node, remove = false) {
|
|
48
|
+
if (node instanceof HTMLStyleElement && node.sheet) {
|
|
49
|
+
console.warn('update', node.sheet)
|
|
50
|
+
updateSheetStyles(node.sheet, remove)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const mo = new MutationObserver((entries) => {
|
|
54
|
+
for (const entry of entries) {
|
|
55
|
+
entry.addedNodes.forEach((node) => handleNode(node))
|
|
56
|
+
entry.removedNodes.forEach((node) => handleNode(node, true))
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
mo.observe(document.head, {
|
|
60
|
+
childList: true,
|
|
61
|
+
})
|
|
62
|
+
}
|
|
54
63
|
|
|
55
|
-
export function
|
|
64
|
+
export function scanAllSheets() {
|
|
56
65
|
if (process.env.NODE_ENV === 'test') return
|
|
57
66
|
if (!isClient) return
|
|
58
67
|
const sheets = document.styleSheets
|
|
@@ -60,28 +69,53 @@ export function updateInserted() {
|
|
|
60
69
|
for (let i = 0; i < sheets.length; i++) {
|
|
61
70
|
const sheet = sheets[i]
|
|
62
71
|
if (!sheet) continue
|
|
72
|
+
updateSheetStyles(sheet)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
63
75
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
} catch {
|
|
70
|
-
continue
|
|
71
|
-
}
|
|
76
|
+
function track(id: string, remove = false) {
|
|
77
|
+
const next = (totalSheetSelectors.get(id) || 0) + (remove ? -1 : 1)
|
|
78
|
+
totalSheetSelectors.set(id, next)
|
|
79
|
+
return next
|
|
80
|
+
}
|
|
72
81
|
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
function updateSheetStyles(sheet: CSSStyleSheet, remove = false) {
|
|
83
|
+
// avoid errors on cross origin sheets
|
|
84
|
+
// https://stackoverflow.com/questions/49993633/uncaught-domexception-failed-to-read-the-cssrules-property
|
|
85
|
+
let rules: CSSRuleList
|
|
86
|
+
try {
|
|
87
|
+
rules = sheet.cssRules
|
|
88
|
+
} catch {
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const len = rules.length
|
|
93
|
+
const lastScanned = scannedNum.get(sheet) || 0
|
|
94
|
+
|
|
95
|
+
if (!remove) {
|
|
96
|
+
// avoid work dumb but works
|
|
75
97
|
if (lastScanned === len) {
|
|
76
|
-
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
for (let i = lastScanned; i < len; i++) {
|
|
103
|
+
const rule = rules[i]
|
|
104
|
+
const response = getTamaguiSelector(rule)
|
|
105
|
+
if (!response) {
|
|
106
|
+
return
|
|
77
107
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
108
|
+
|
|
109
|
+
const [identifier, cssRule] = response
|
|
110
|
+
|
|
111
|
+
// track references
|
|
112
|
+
const total = track(identifier, remove)
|
|
113
|
+
|
|
114
|
+
if (remove) {
|
|
115
|
+
if (total === 0) {
|
|
116
|
+
delete allSelectors[identifier]
|
|
83
117
|
}
|
|
84
|
-
|
|
118
|
+
} else {
|
|
85
119
|
if (!(identifier in allSelectors)) {
|
|
86
120
|
const isTransform = identifier.startsWith('_transform')
|
|
87
121
|
const shouldInsert = isTransform
|
|
@@ -92,8 +126,9 @@ export function updateInserted() {
|
|
|
92
126
|
}
|
|
93
127
|
}
|
|
94
128
|
}
|
|
95
|
-
scannedNum.set(sheet, i)
|
|
96
129
|
}
|
|
130
|
+
|
|
131
|
+
scannedNum.set(sheet, len)
|
|
97
132
|
}
|
|
98
133
|
|
|
99
134
|
function getTamaguiSelector(
|
|
@@ -122,9 +157,6 @@ const getIdentifierFromTamaguiSelector = (selector: string) =>
|
|
|
122
157
|
.replace(/:[a-z]+$/, '')
|
|
123
158
|
.slice(1)
|
|
124
159
|
|
|
125
|
-
// move this to probably inside createTamagui
|
|
126
|
-
updateInserted()
|
|
127
|
-
|
|
128
160
|
const sheet = isClient
|
|
129
161
|
? document.head.appendChild(document.createElement('style')).sheet
|
|
130
162
|
: null
|
|
@@ -11,13 +11,13 @@ import { normalizeColor } from './normalizeColor'
|
|
|
11
11
|
const cache = {}
|
|
12
12
|
|
|
13
13
|
export function normalizeValueWithProperty(value: any, property?: string): any {
|
|
14
|
-
if (property && unitlessNumbers[property]) {
|
|
15
|
-
return value
|
|
16
|
-
}
|
|
17
14
|
const cached = cache[value]
|
|
18
15
|
if (cached !== undefined) {
|
|
19
16
|
return cached
|
|
20
17
|
}
|
|
18
|
+
if (property && property in unitlessNumbers) {
|
|
19
|
+
return value
|
|
20
|
+
}
|
|
21
21
|
let res = value
|
|
22
22
|
if (
|
|
23
23
|
process.env.TAMAGUI_TARGET === 'web' &&
|
|
@@ -6,9 +6,9 @@ import { Theme } from '../views/Theme'
|
|
|
6
6
|
export interface ThemeableProps {
|
|
7
7
|
theme?: ThemeName | null
|
|
8
8
|
themeInverse?: boolean
|
|
9
|
+
themeReset?: boolean
|
|
9
10
|
componentName?: string
|
|
10
11
|
debug?: boolean | 'verbose'
|
|
11
|
-
reset?: boolean
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function themeable<Component extends (props: any) => any>(
|
|
@@ -16,7 +16,7 @@ export function themeable<Component extends (props: any) => any>(
|
|
|
16
16
|
opts?: { componentName?: string }
|
|
17
17
|
) {
|
|
18
18
|
const withThemeComponent = forwardRef(function WithTheme(props: ThemeableProps, ref) {
|
|
19
|
-
const { themeInverse, theme, componentName,
|
|
19
|
+
const { themeInverse, theme, componentName, themeReset, ...rest } = props
|
|
20
20
|
const element = React.createElement(component, { ...rest, ref } as any)
|
|
21
21
|
|
|
22
22
|
return (
|
|
@@ -26,7 +26,7 @@ export function themeable<Component extends (props: any) => any>(
|
|
|
26
26
|
name={(theme as any) || null}
|
|
27
27
|
data-themeable
|
|
28
28
|
debug={props.debug}
|
|
29
|
-
reset={props.
|
|
29
|
+
reset={props.themeReset}
|
|
30
30
|
>
|
|
31
31
|
{element}
|
|
32
32
|
</Theme>
|
|
@@ -73,7 +73,7 @@ export function useElementLayout(
|
|
|
73
73
|
// Observing is done in a separate effect to avoid this effect running
|
|
74
74
|
// when 'onLayout' changes.
|
|
75
75
|
useIsomorphicLayoutEffect(() => {
|
|
76
|
-
if (!
|
|
76
|
+
if (!resizeObserver || !hasLayoutEvent) return
|
|
77
77
|
const node = ref.current
|
|
78
78
|
if (!node) return
|
|
79
79
|
LayoutHandlers.set(node, onLayoutEvent)
|
package/src/hooks/useMedia.tsx
CHANGED
|
@@ -35,6 +35,7 @@ export const mediaState: MediaQueryState =
|
|
|
35
35
|
|
|
36
36
|
export const mediaQueryConfig: MediaQueries = {}
|
|
37
37
|
export const getMedia = () => mediaState
|
|
38
|
+
export const mediaKeysWithAndWithout$ = new Set<string>()
|
|
38
39
|
|
|
39
40
|
// for SSR capture it at time of startup
|
|
40
41
|
let initState: MediaQueryState
|
|
@@ -58,6 +59,8 @@ export const configureMedia = (config: TamaguiInternalConfig) => {
|
|
|
58
59
|
if (!media) return
|
|
59
60
|
for (const key in media) {
|
|
60
61
|
mediaState[key] = mediaQueryDefaultActive?.[key] || false
|
|
62
|
+
mediaKeysWithAndWithout$.add(key)
|
|
63
|
+
mediaKeysWithAndWithout$.add(`$${key}`)
|
|
61
64
|
}
|
|
62
65
|
Object.assign(mediaQueryConfig, media)
|
|
63
66
|
initState = { ...mediaState }
|
package/src/styled.tsx
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { stylePropsAll, validStyles } from '@tamagui/helpers'
|
|
2
|
+
|
|
1
3
|
import { createComponent } from './createComponent'
|
|
2
4
|
import { ReactNativeStaticConfigs } from './setupReactNative'
|
|
3
5
|
import {
|
|
@@ -60,6 +62,19 @@ export function styled<
|
|
|
60
62
|
// }
|
|
61
63
|
// }
|
|
62
64
|
|
|
65
|
+
// validate not using a variant over an existing valid style
|
|
66
|
+
if (process.env.NODE_ENV === 'development') {
|
|
67
|
+
if (options?.variants) {
|
|
68
|
+
for (const key in options.variants) {
|
|
69
|
+
if (key in stylePropsAll) {
|
|
70
|
+
console.error(
|
|
71
|
+
`Invalid variant key overlaps with style key: ${key}. Tamagui prevents defining variants that use valid style keys to reduce implementation complexity.`
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
63
78
|
const staticConfigProps = (() => {
|
|
64
79
|
const parentStaticConfig =
|
|
65
80
|
'staticConfig' in Component ? (Component.staticConfig as StaticConfig) : null
|
|
@@ -3,7 +3,8 @@ export declare const insertedTransforms: {};
|
|
|
3
3
|
export declare const getAllSelectors: () => Record<string, string>;
|
|
4
4
|
export declare const getAllRules: () => string[];
|
|
5
5
|
export declare const getAllTransforms: () => {};
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function listenForSheetChanges(): void;
|
|
7
|
+
export declare function scanAllSheets(): void;
|
|
7
8
|
export declare function updateRules(identifier: string, rules: string[]): boolean;
|
|
8
9
|
export type PartialStyleObject = Pick<StyleObject, 'identifier' | 'property' | 'rules'>;
|
|
9
10
|
export type RulesToInsert = PartialStyleObject[];
|
|
@@ -2,9 +2,9 @@ import { ThemeName } from '../types';
|
|
|
2
2
|
export interface ThemeableProps {
|
|
3
3
|
theme?: ThemeName | null;
|
|
4
4
|
themeInverse?: boolean;
|
|
5
|
+
themeReset?: boolean;
|
|
5
6
|
componentName?: string;
|
|
6
7
|
debug?: boolean | 'verbose';
|
|
7
|
-
reset?: boolean;
|
|
8
8
|
}
|
|
9
9
|
export declare function themeable<Component extends (props: any) => any>(component: Component, opts?: {
|
|
10
10
|
componentName?: string;
|
|
@@ -2,6 +2,7 @@ import { MediaQueries, MediaQueryKey, MediaQueryObject, MediaQueryState, Tamagui
|
|
|
2
2
|
export declare const mediaState: MediaQueryState;
|
|
3
3
|
export declare const mediaQueryConfig: MediaQueries;
|
|
4
4
|
export declare const getMedia: () => MediaQueryState;
|
|
5
|
+
export declare const mediaKeysWithAndWithout$: Set<string>;
|
|
5
6
|
export declare const getInitialMediaState: () => MediaQueryState;
|
|
6
7
|
export declare const getMediaKeyImportance: (key: string) => number;
|
|
7
8
|
export declare const configureMedia: (config: TamaguiInternalConfig) => void;
|