@tamagui/web 2.0.0-1768530912818 → 2.0.0-1768586279389

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.
Files changed (34) hide show
  1. package/dist/cjs/helpers/expandStyle.js.map +1 -1
  2. package/dist/cjs/helpers/expandStyle.native.js +62 -13
  3. package/dist/cjs/helpers/expandStyle.native.js.map +1 -1
  4. package/dist/cjs/helpers/propMapper.cjs +34 -12
  5. package/dist/cjs/helpers/propMapper.js +28 -12
  6. package/dist/cjs/helpers/propMapper.js.map +1 -1
  7. package/dist/cjs/helpers/propMapper.native.js +60 -14
  8. package/dist/cjs/helpers/propMapper.native.js.map +1 -1
  9. package/dist/esm/helpers/expandStyle.js.map +1 -1
  10. package/dist/esm/helpers/expandStyle.mjs.map +1 -1
  11. package/dist/esm/helpers/expandStyle.native.js +67 -18
  12. package/dist/esm/helpers/expandStyle.native.js.map +1 -1
  13. package/dist/esm/helpers/propMapper.js +28 -12
  14. package/dist/esm/helpers/propMapper.js.map +1 -1
  15. package/dist/esm/helpers/propMapper.mjs +34 -12
  16. package/dist/esm/helpers/propMapper.mjs.map +1 -1
  17. package/dist/esm/helpers/propMapper.native.js +57 -11
  18. package/dist/esm/helpers/propMapper.native.js.map +1 -1
  19. package/package.json +12 -12
  20. package/src/helpers/expandStyle.native.ts +124 -0
  21. package/src/helpers/expandStyle.ts +1 -9
  22. package/src/helpers/propMapper.native.ts +619 -0
  23. package/src/helpers/propMapper.ts +85 -20
  24. package/src/types.tsx +79 -15
  25. package/types/helpers/expandStyle.d.ts.map +1 -1
  26. package/types/helpers/expandStyle.native.d.ts +7 -0
  27. package/types/helpers/expandStyle.native.d.ts.map +1 -0
  28. package/types/helpers/propMapper.d.ts.map +1 -1
  29. package/types/helpers/propMapper.native.d.ts +5 -0
  30. package/types/helpers/propMapper.native.d.ts.map +1 -0
  31. package/types/helpers/webPropsToSkip.native.d.ts +0 -6
  32. package/types/helpers/webPropsToSkip.native.d.ts.map +1 -1
  33. package/types/types.d.ts +59 -15
  34. package/types/types.d.ts.map +1 -1
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Some parts adapted from react-native-web
3
+ * Copyright (c) Nicolas Gallagher licensed under the MIT license.
4
+ */
5
+
6
+ import { isAndroid } from '@tamagui/constants'
7
+
8
+ import {
9
+ webToNativeDynamicExpansion,
10
+ webToNativeExpansion,
11
+ } from '../constants/webToNativeProps'
12
+ import type { PropMappedValue } from '../types'
13
+
14
+ // Parse CSS boxShadow string to RN object array
15
+ const num = (v: string) => Number.parseFloat(v) || 0
16
+ const parseBoxShadowStr = (s: string) =>
17
+ s.split(/,(?![^(]*\))/).map((sh) => {
18
+ const p = sh.trim().split(/\s+/)
19
+ let i = p[0] === 'inset' ? 1 : 0
20
+ const o: any = { offsetX: num(p[i++]), offsetY: num(p[i++]) }
21
+ if (p[0] === 'inset') o.inset = true
22
+ if (p[i] && /^-?[\d.]/.test(p[i])) o.blurRadius = num(p[i++])
23
+ if (p[i] && /^-?[\d.]/.test(p[i])) o.spreadDistance = num(p[i++])
24
+ if (p[i]) o.color = p.slice(i).join(' ')
25
+ return o
26
+ })
27
+
28
+ // Parse CSS filter string to RN object array
29
+ const simpleFilters = new Set([
30
+ 'brightness',
31
+ 'opacity',
32
+ 'contrast',
33
+ 'grayscale',
34
+ 'invert',
35
+ 'saturate',
36
+ 'sepia',
37
+ 'blur',
38
+ ])
39
+ const parseFilterStr = (s: string): any[] => {
40
+ const r: any[] = []
41
+ for (const [, fn, val] of s.matchAll(/(\w+)\(([^)]+)\)/g)) {
42
+ const n = +val || 0
43
+ if (simpleFilters.has(fn)) r.push({ [fn]: n })
44
+ else if (fn === 'hueRotate' || fn === 'hue-rotate') r.push({ hueRotate: val })
45
+ else if (fn === 'dropShadow' || fn === 'drop-shadow') {
46
+ const p = val.trim().split(/\s+/)
47
+ const ds: any = { offsetX: num(p[0]), offsetY: num(p[1]) }
48
+ if (p[2] && /^-?[\d.]/.test(p[2])) {
49
+ ds.blurRadius = num(p[2])
50
+ if (p[3]) ds.color = p.slice(3).join(' ')
51
+ } else if (p[2]) ds.color = p.slice(2).join(' ')
52
+ r.push({ dropShadow: ds })
53
+ }
54
+ }
55
+ return r
56
+ }
57
+
58
+ export function expandStyle(key: string, value: any): PropMappedValue {
59
+ if (isAndroid && key === 'elevationAndroid') {
60
+ return [['elevation', value]]
61
+ }
62
+
63
+ // Native: convert boxShadow string to object array
64
+ if (key === 'boxShadow') {
65
+ if (typeof value === 'string') {
66
+ return [['boxShadow', parseBoxShadowStr(value)]]
67
+ }
68
+ if (value && !Array.isArray(value)) {
69
+ return [['boxShadow', [value]]]
70
+ }
71
+ }
72
+
73
+ // Native: convert filter string to object array
74
+ if (key === 'filter') {
75
+ if (typeof value === 'string') {
76
+ return [['filter', parseFilterStr(value)]]
77
+ }
78
+ if (value && !Array.isArray(value)) {
79
+ return [['filter', [value]]]
80
+ }
81
+ }
82
+
83
+ if (key in EXPANSIONS) {
84
+ return EXPANSIONS[key].map((key) => {
85
+ return [key, value]
86
+ })
87
+ }
88
+
89
+ if (key in webToNativeExpansion) {
90
+ return webToNativeExpansion[key].map((key) => {
91
+ return [key, value]
92
+ })
93
+ }
94
+
95
+ if (key in webToNativeDynamicExpansion) {
96
+ return webToNativeDynamicExpansion[key](value)
97
+ }
98
+ }
99
+
100
+ const all = ['Top', 'Right', 'Bottom', 'Left']
101
+ const horiz = ['Right', 'Left']
102
+ const vert = ['Top', 'Bottom']
103
+
104
+ const EXPANSIONS: Record<string, string[]> = {
105
+ borderColor: ['TopColor', 'RightColor', 'BottomColor', 'LeftColor'],
106
+ borderRadius: [
107
+ 'TopLeftRadius',
108
+ 'TopRightRadius',
109
+ 'BottomRightRadius',
110
+ 'BottomLeftRadius',
111
+ ],
112
+ borderWidth: ['TopWidth', 'RightWidth', 'BottomWidth', 'LeftWidth'],
113
+ margin: all,
114
+ marginHorizontal: horiz,
115
+ marginVertical: vert,
116
+ padding: all,
117
+ paddingHorizontal: horiz,
118
+ paddingVertical: vert,
119
+ }
120
+
121
+ for (const parent in EXPANSIONS) {
122
+ const prefix = parent.slice(0, /[A-Z]/.exec(parent)?.index ?? parent.length)
123
+ EXPANSIONS[parent] = EXPANSIONS[parent].map((k) => `${prefix}${k}`)
124
+ }
@@ -3,7 +3,7 @@
3
3
  * Copyright (c) Nicolas Gallagher licensed under the MIT license.
4
4
  */
5
5
 
6
- import { isAndroid, isWeb } from '@tamagui/constants'
6
+ import { isWeb } from '@tamagui/constants'
7
7
 
8
8
  import { getSetting } from '../config'
9
9
  import {
@@ -46,14 +46,6 @@ export function expandStyle(key: string, value: any): PropMappedValue {
46
46
  }
47
47
  }
48
48
 
49
- if (
50
- process.env.TAMAGUI_TARGET === 'native' &&
51
- isAndroid &&
52
- key === 'elevationAndroid'
53
- ) {
54
- return [['elevation', value]]
55
- }
56
-
57
49
  if (key in EXPANSIONS) {
58
50
  return EXPANSIONS[key].map((key) => {
59
51
  return [key, value]