@tamagui/core 1.0.10 → 1.0.12
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 +1 -1
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/helpers/createPropMapper.js +0 -3
- package/dist/cjs/helpers/createPropMapper.js.map +2 -2
- package/dist/cjs/helpers/insertStyleRule.js +13 -6
- package/dist/cjs/helpers/insertStyleRule.js.map +2 -2
- package/dist/cjs/helpers/normalizeColor.js +8 -2
- package/dist/cjs/helpers/normalizeColor.js.map +2 -2
- package/dist/cjs/helpers/useShallowSetState.js +20 -11
- package/dist/cjs/helpers/useShallowSetState.js.map +2 -2
- package/dist/esm/createComponent.js +1 -1
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/helpers/createPropMapper.js +0 -3
- package/dist/esm/helpers/createPropMapper.js.map +2 -2
- package/dist/esm/helpers/insertStyleRule.js +13 -6
- package/dist/esm/helpers/insertStyleRule.js.map +2 -2
- package/dist/esm/helpers/normalizeColor.js +8 -2
- package/dist/esm/helpers/normalizeColor.js.map +2 -2
- package/dist/esm/helpers/useShallowSetState.js +21 -12
- package/dist/esm/helpers/useShallowSetState.js.map +2 -2
- package/package.json +11 -11
- package/src/createComponent.tsx +1 -1
- package/src/helpers/createPropMapper.ts +0 -4
- package/src/helpers/insertStyleRule.tsx +16 -7
- package/src/helpers/normalizeColor.ts +8 -2
- package/src/helpers/useShallowSetState.tsx +22 -12
- package/types/helpers/useShallowSetState.d.ts +1 -1
- package/types/helpers/cache.d.ts +0 -10
- package/types/helpers/getSize.d.ts +0 -4
|
@@ -14,9 +14,15 @@ const normalizeColor = (color, opacity) => {
|
|
|
14
14
|
const colorProcessed = normalizeCSSColor(color);
|
|
15
15
|
if (colorProcessed !== null) {
|
|
16
16
|
const { r, g, b, a } = rgba(colorProcessed);
|
|
17
|
-
return `rgba(${r},${g},${b},${a.toFixed(2)})`;
|
|
17
|
+
return `rgba(${r},${g},${b},${(opacity ?? a).toFixed(2)})`;
|
|
18
|
+
}
|
|
19
|
+
if (isWeb) {
|
|
20
|
+
return color;
|
|
21
|
+
} else {
|
|
22
|
+
if (process.env.NODE_ENV === "development") {
|
|
23
|
+
console.warn(`Unknown color value: ${color}`);
|
|
24
|
+
}
|
|
18
25
|
}
|
|
19
|
-
return color;
|
|
20
26
|
};
|
|
21
27
|
const webColors = {
|
|
22
28
|
currentColor: true,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/helpers/normalizeColor.ts"],
|
|
4
|
-
"sourcesContent": ["import { isWeb } from '@tamagui/constants'\nimport normalizeCSSColor, { rgba } from '@tamagui/normalize-css-color'\n\nexport { rgba } from '@tamagui/normalize-css-color'\n\nexport const normalizeColor = (color?: string | null, opacity?: number) => {\n if (color === null || color === undefined) {\n return\n }\n if (color === 'transparent') {\n return `rgba(0,0,0,0)`\n }\n if (\n color[0] === '$' ||\n (isWeb && (webColors[color] || color[0] === '_' || color.startsWith('var(')))\n ) {\n return color\n }\n const colorProcessed = normalizeCSSColor(color)\n if (colorProcessed !== null) {\n const { r, g, b, a } = rgba(colorProcessed)\n return `rgba(${r},${g},${b},${a.toFixed(2)})`\n }\n\n return color\n}\n\nconst webColors = {\n currentColor: true,\n currentcolor: true,\n inherit: true,\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,aAAa;AACtB,OAAO,qBAAqB,YAAY;AAExC,SAAS,QAAAA,aAAY;AAEd,MAAM,iBAAiB,CAAC,OAAuB,YAAqB;AACzE,MAAI,UAAU,QAAQ,UAAU,QAAW;AACzC;AAAA,EACF;AACA,MAAI,UAAU,eAAe;AAC3B,WAAO;AAAA,EACT;AACA,MACE,MAAM,OAAO,OACZ,UAAU,UAAU,UAAU,MAAM,OAAO,OAAO,MAAM,WAAW,MAAM,IAC1E;AACA,WAAO;AAAA,EACT;AACA,QAAM,iBAAiB,kBAAkB,KAAK;AAC9C,MAAI,mBAAmB,MAAM;AAC3B,UAAM,EAAE,GAAG,GAAG,GAAG,EAAE,IAAI,KAAK,cAAc;AAC1C,WAAO,QAAQ,KAAK,KAAK,
|
|
4
|
+
"sourcesContent": ["import { isWeb } from '@tamagui/constants'\nimport normalizeCSSColor, { rgba } from '@tamagui/normalize-css-color'\n\nexport { rgba } from '@tamagui/normalize-css-color'\n\nexport const normalizeColor = (color?: string | null, opacity?: number) => {\n if (color === null || color === undefined) {\n return\n }\n if (color === 'transparent') {\n return `rgba(0,0,0,0)`\n }\n if (\n color[0] === '$' ||\n (isWeb && (webColors[color] || color[0] === '_' || color.startsWith('var(')))\n ) {\n return color\n }\n const colorProcessed = normalizeCSSColor(color)\n if (colorProcessed !== null) {\n const { r, g, b, a } = rgba(colorProcessed)\n return `rgba(${r},${g},${b},${(opacity ?? a).toFixed(2)})`\n }\n\n if (isWeb) {\n return color\n } else {\n if (process.env.NODE_ENV === 'development') {\n console.warn(`Unknown color value: ${color}`)\n }\n }\n}\n\nconst webColors = {\n currentColor: true,\n currentcolor: true,\n inherit: true,\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,aAAa;AACtB,OAAO,qBAAqB,YAAY;AAExC,SAAS,QAAAA,aAAY;AAEd,MAAM,iBAAiB,CAAC,OAAuB,YAAqB;AACzE,MAAI,UAAU,QAAQ,UAAU,QAAW;AACzC;AAAA,EACF;AACA,MAAI,UAAU,eAAe;AAC3B,WAAO;AAAA,EACT;AACA,MACE,MAAM,OAAO,OACZ,UAAU,UAAU,UAAU,MAAM,OAAO,OAAO,MAAM,WAAW,MAAM,IAC1E;AACA,WAAO;AAAA,EACT;AACA,QAAM,iBAAiB,kBAAkB,KAAK;AAC9C,MAAI,mBAAmB,MAAM;AAC3B,UAAM,EAAE,GAAG,GAAG,GAAG,EAAE,IAAI,KAAK,cAAc;AAC1C,WAAO,QAAQ,KAAK,KAAK,MAAM,WAAW,GAAG,QAAQ,CAAC;AAAA,EACxD;AAEA,MAAI,OAAO;AACT,WAAO;AAAA,EACT,OAAO;AACL,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,cAAQ,KAAK,wBAAwB,OAAO;AAAA,IAC9C;AAAA,EACF;AACF;AAEA,MAAM,YAAY;AAAA,EAChB,cAAc;AAAA,EACd,cAAc;AAAA,EACd,SAAS;AACX;",
|
|
6
6
|
"names": ["rgba"]
|
|
7
7
|
}
|
|
@@ -1,20 +1,29 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
2
|
-
function useShallowSetState(setter, debug, debugName) {
|
|
1
|
+
import { startTransition, useCallback } from "react";
|
|
2
|
+
function useShallowSetState(setter, transition, debug, debugName) {
|
|
3
3
|
return useCallback(
|
|
4
4
|
(next) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
if (
|
|
10
|
-
|
|
5
|
+
const run = () => {
|
|
6
|
+
setter((prev) => {
|
|
7
|
+
for (const key in next) {
|
|
8
|
+
if (prev[key] !== next[key]) {
|
|
9
|
+
if (process.env.NODE_ENV === "development") {
|
|
10
|
+
if (debug === "verbose") {
|
|
11
|
+
console.log(` \u25B2 setState ${debugName}`, next);
|
|
12
|
+
}
|
|
11
13
|
}
|
|
14
|
+
return { ...prev, ...next };
|
|
12
15
|
}
|
|
13
|
-
return { ...prev, ...next };
|
|
14
16
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
17
|
+
return prev;
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
if (transition) {
|
|
21
|
+
startTransition(() => {
|
|
22
|
+
run();
|
|
23
|
+
});
|
|
24
|
+
} else {
|
|
25
|
+
run();
|
|
26
|
+
}
|
|
18
27
|
},
|
|
19
28
|
[setter]
|
|
20
29
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/helpers/useShallowSetState.tsx"],
|
|
4
|
-
"sourcesContent": ["import React, { useCallback } from 'react'\n\nimport { DebugProp } from '../types'\n\nexport function useShallowSetState<State extends Object>(\n setter: React.Dispatch<React.SetStateAction<State>>,\n debug?: DebugProp,\n debugName?: string\n) {\n return useCallback(\n (next: Partial<State>) => {\n setter((prev) => {\n
|
|
5
|
-
"mappings": "AAAA,SAAgB,mBAAmB;
|
|
4
|
+
"sourcesContent": ["import React, { startTransition, useCallback } from 'react'\n\nimport { DebugProp } from '../types'\n\nexport function useShallowSetState<State extends Object>(\n setter: React.Dispatch<React.SetStateAction<State>>,\n transition?: boolean,\n debug?: DebugProp,\n debugName?: string\n) {\n return useCallback(\n (next: Partial<State>) => {\n const run = () => {\n setter((prev) => {\n for (const key in next) {\n if (prev[key] !== next[key]) {\n if (process.env.NODE_ENV === 'development') {\n if (debug === 'verbose') {\n // eslint-disable-next-line no-console\n console.log(` \u25B2 setState ${debugName}`, next)\n }\n }\n return { ...prev, ...next }\n }\n }\n return prev\n })\n }\n if (transition) {\n startTransition(() => {\n run()\n })\n } else {\n run()\n }\n },\n [setter]\n )\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAgB,iBAAiB,mBAAmB;AAI7C,SAAS,mBACd,QACA,YACA,OACA,WACA;AACA,SAAO;AAAA,IACL,CAAC,SAAyB;AACxB,YAAM,MAAM,MAAM;AAChB,eAAO,CAAC,SAAS;AACf,qBAAW,OAAO,MAAM;AACtB,gBAAI,KAAK,SAAS,KAAK,MAAM;AAC3B,kBAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,oBAAI,UAAU,WAAW;AAEvB,0BAAQ,IAAI,oBAAe,aAAa,IAAI;AAAA,gBAC9C;AAAA,cACF;AACA,qBAAO,EAAE,GAAG,MAAM,GAAG,KAAK;AAAA,YAC5B;AAAA,UACF;AACA,iBAAO;AAAA,QACT,CAAC;AAAA,MACH;AACA,UAAI,YAAY;AACd,wBAAgB,MAAM;AACpB,cAAI;AAAA,QACN,CAAC;AAAA,MACH,OAAO;AACL,YAAI;AAAA,MACN;AAAA,IACF;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -28,22 +28,22 @@
|
|
|
28
28
|
"reset.css"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@tamagui/compose-refs": "^1.0.
|
|
32
|
-
"@tamagui/constants": "^1.0.
|
|
33
|
-
"@tamagui/helpers": "^1.0.
|
|
34
|
-
"@tamagui/normalize-css-color": "^1.0.
|
|
35
|
-
"@tamagui/react-native-use-pressable": "^1.0.
|
|
36
|
-
"@tamagui/react-native-use-responder-events": "^1.0.
|
|
37
|
-
"@tamagui/use-did-finish-ssr": "^1.0.
|
|
38
|
-
"@tamagui/use-event": "^1.0.
|
|
39
|
-
"@tamagui/use-force-update": "^1.0.
|
|
31
|
+
"@tamagui/compose-refs": "^1.0.12",
|
|
32
|
+
"@tamagui/constants": "^1.0.12",
|
|
33
|
+
"@tamagui/helpers": "^1.0.12",
|
|
34
|
+
"@tamagui/normalize-css-color": "^1.0.12",
|
|
35
|
+
"@tamagui/react-native-use-pressable": "^1.0.12",
|
|
36
|
+
"@tamagui/react-native-use-responder-events": "^1.0.12",
|
|
37
|
+
"@tamagui/use-did-finish-ssr": "^1.0.12",
|
|
38
|
+
"@tamagui/use-event": "^1.0.12",
|
|
39
|
+
"@tamagui/use-force-update": "^1.0.12"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"react": "*",
|
|
43
43
|
"react-dom": "*"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@tamagui/build": "^1.0.
|
|
46
|
+
"@tamagui/build": "^1.0.12",
|
|
47
47
|
"@testing-library/react": "^13.4.0",
|
|
48
48
|
"csstype": "^3.0.10",
|
|
49
49
|
"react": "^18.2.0",
|
package/src/createComponent.tsx
CHANGED
|
@@ -189,7 +189,7 @@ export function createComponent<
|
|
|
189
189
|
? { ...states[0], [propsIn.forceStyle]: true }
|
|
190
190
|
: states[0]
|
|
191
191
|
const setState = states[1]
|
|
192
|
-
const setStateShallow = useShallowSetState(setState, debugProp, componentName)
|
|
192
|
+
const setStateShallow = useShallowSetState(setState, true, debugProp, componentName)
|
|
193
193
|
|
|
194
194
|
// conditional but if ever true stays true
|
|
195
195
|
// [animated, inversed]
|
|
@@ -286,10 +286,6 @@ const resolveTokensAndVariants: StyleResolver = (
|
|
|
286
286
|
const fKey = conf.shorthands[rKey] || rKey
|
|
287
287
|
const val = value[rKey]
|
|
288
288
|
|
|
289
|
-
if (debug) {
|
|
290
|
-
console.log('wtf', key, value, rKey, val)
|
|
291
|
-
}
|
|
292
|
-
|
|
293
289
|
if (isVariable(val)) {
|
|
294
290
|
res[fKey] = !isWeb || returnVariablesAs === 'value' ? val.val : val.variable
|
|
295
291
|
} else if (variants[fKey]) {
|
|
@@ -38,7 +38,8 @@ const isClient = typeof document !== 'undefined'
|
|
|
38
38
|
|
|
39
39
|
// multiple sheets could have the same ids so we have to count
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
// only cache tamagui styles
|
|
42
|
+
const scannedCache = new WeakMap<CSSStyleSheet, string>()
|
|
42
43
|
const totalSheetSelectors = new Map<string, number>()
|
|
43
44
|
|
|
44
45
|
export function listenForSheetChanges() {
|
|
@@ -87,17 +88,25 @@ function updateSheetStyles(sheet: CSSStyleSheet, remove = false) {
|
|
|
87
88
|
return
|
|
88
89
|
}
|
|
89
90
|
|
|
90
|
-
|
|
91
|
-
const
|
|
91
|
+
// not tamagui stylesheet
|
|
92
|
+
const firstSelector = getTamaguiSelector(rules[0])?.[0]
|
|
93
|
+
if (!firstSelector) {
|
|
94
|
+
return
|
|
95
|
+
}
|
|
92
96
|
|
|
97
|
+
const lastSelector = getTamaguiSelector(rules[rules.length - 1])?.[0]
|
|
98
|
+
|
|
99
|
+
const cacheKey = `${rules.length}${firstSelector}${lastSelector}`
|
|
100
|
+
const lastScanned = scannedCache.get(sheet)
|
|
93
101
|
if (!remove) {
|
|
94
|
-
// avoid
|
|
95
|
-
if (lastScanned ===
|
|
102
|
+
// avoid re-scanning
|
|
103
|
+
if (lastScanned === cacheKey) {
|
|
96
104
|
return
|
|
97
105
|
}
|
|
98
106
|
}
|
|
99
107
|
|
|
100
|
-
|
|
108
|
+
const len = rules.length
|
|
109
|
+
for (let i = 0; i < len; i++) {
|
|
101
110
|
const rule = rules[i]
|
|
102
111
|
const response = getTamaguiSelector(rule)
|
|
103
112
|
if (!response) {
|
|
@@ -126,7 +135,7 @@ function updateSheetStyles(sheet: CSSStyleSheet, remove = false) {
|
|
|
126
135
|
}
|
|
127
136
|
}
|
|
128
137
|
|
|
129
|
-
|
|
138
|
+
scannedCache.set(sheet, cacheKey)
|
|
130
139
|
}
|
|
131
140
|
|
|
132
141
|
function getTamaguiSelector(
|
|
@@ -19,10 +19,16 @@ export const normalizeColor = (color?: string | null, opacity?: number) => {
|
|
|
19
19
|
const colorProcessed = normalizeCSSColor(color)
|
|
20
20
|
if (colorProcessed !== null) {
|
|
21
21
|
const { r, g, b, a } = rgba(colorProcessed)
|
|
22
|
-
return `rgba(${r},${g},${b},${a.toFixed(2)})`
|
|
22
|
+
return `rgba(${r},${g},${b},${(opacity ?? a).toFixed(2)})`
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
if (isWeb) {
|
|
26
|
+
return color
|
|
27
|
+
} else {
|
|
28
|
+
if (process.env.NODE_ENV === 'development') {
|
|
29
|
+
console.warn(`Unknown color value: ${color}`)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
const webColors = {
|
|
@@ -1,28 +1,38 @@
|
|
|
1
|
-
import React, { useCallback } from 'react'
|
|
1
|
+
import React, { startTransition, useCallback } from 'react'
|
|
2
2
|
|
|
3
3
|
import { DebugProp } from '../types'
|
|
4
4
|
|
|
5
5
|
export function useShallowSetState<State extends Object>(
|
|
6
6
|
setter: React.Dispatch<React.SetStateAction<State>>,
|
|
7
|
+
transition?: boolean,
|
|
7
8
|
debug?: DebugProp,
|
|
8
9
|
debugName?: string
|
|
9
10
|
) {
|
|
10
11
|
return useCallback(
|
|
11
12
|
(next: Partial<State>) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
const run = () => {
|
|
14
|
+
setter((prev) => {
|
|
15
|
+
for (const key in next) {
|
|
16
|
+
if (prev[key] !== next[key]) {
|
|
17
|
+
if (process.env.NODE_ENV === 'development') {
|
|
18
|
+
if (debug === 'verbose') {
|
|
19
|
+
// eslint-disable-next-line no-console
|
|
20
|
+
console.log(` ▲ setState ${debugName}`, next)
|
|
21
|
+
}
|
|
19
22
|
}
|
|
23
|
+
return { ...prev, ...next }
|
|
20
24
|
}
|
|
21
|
-
return { ...prev, ...next }
|
|
22
25
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
+
return prev
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
if (transition) {
|
|
30
|
+
startTransition(() => {
|
|
31
|
+
run()
|
|
32
|
+
})
|
|
33
|
+
} else {
|
|
34
|
+
run()
|
|
35
|
+
}
|
|
26
36
|
},
|
|
27
37
|
[setter]
|
|
28
38
|
)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { DebugProp } from '../types';
|
|
3
|
-
export declare function useShallowSetState<State extends Object>(setter: React.Dispatch<React.SetStateAction<State>>, debug?: DebugProp, debugName?: string): (next: Partial<State>) => void;
|
|
3
|
+
export declare function useShallowSetState<State extends Object>(setter: React.Dispatch<React.SetStateAction<State>>, transition?: boolean, debug?: DebugProp, debugName?: string): (next: Partial<State>) => void;
|
|
4
4
|
//# sourceMappingURL=useShallowSetState.d.ts.map
|
package/types/helpers/cache.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
type Value = Object | Array<any> | string | number;
|
|
2
|
-
export type Style = {
|
|
3
|
-
[key: string]: Value;
|
|
4
|
-
};
|
|
5
|
-
export declare const cache: {
|
|
6
|
-
get: (key: string, valStr: string) => any;
|
|
7
|
-
set: (key: string, valStr: string, object: any) => void;
|
|
8
|
-
};
|
|
9
|
-
export {};
|
|
10
|
-
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { SizeTokens, SpaceTokens } from '../types';
|
|
2
|
-
export declare const getSize: (size?: SizeTokens | undefined, shift?: number, bounds?: number[]) => any;
|
|
3
|
-
export declare const stepTokenUpOrDown: (tokens: Object, current?: SizeTokens | SpaceTokens | string, shift?: number, bounds?: number[]) => any;
|
|
4
|
-
//# sourceMappingURL=getSize.d.ts.map
|