@mpxjs/webpack-plugin 2.9.67 → 2.9.69-beta.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.
Files changed (150) hide show
  1. package/lib/index.js +30 -9
  2. package/lib/platform/json/wx/index.js +21 -8
  3. package/lib/platform/style/wx/index.js +51 -54
  4. package/lib/platform/template/wx/component-config/canvas.js +8 -0
  5. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  6. package/lib/platform/template/wx/component-config/index.js +1 -1
  7. package/lib/platform/template/wx/component-config/input.js +1 -1
  8. package/lib/platform/template/wx/component-config/movable-view.js +8 -1
  9. package/lib/platform/template/wx/component-config/rich-text.js +8 -0
  10. package/lib/platform/template/wx/component-config/scroll-view.js +1 -1
  11. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  12. package/lib/platform/template/wx/component-config/textarea.js +1 -1
  13. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  14. package/lib/react/processStyles.js +14 -4
  15. package/lib/react/processTemplate.js +3 -0
  16. package/lib/resolver/AddEnvPlugin.js +1 -0
  17. package/lib/resolver/AddModePlugin.js +9 -8
  18. package/lib/runtime/components/react/context.ts +14 -0
  19. package/lib/runtime/components/react/dist/context.js +4 -0
  20. package/lib/runtime/components/react/dist/event.config.js +24 -24
  21. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -175
  22. package/lib/runtime/components/react/dist/mpx-button.jsx +77 -49
  23. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  24. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  25. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  26. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  27. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  28. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  29. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  30. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
  31. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  32. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  33. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  34. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  35. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  36. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  37. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  38. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  39. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  40. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +14 -14
  41. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  42. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  43. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  44. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  45. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  46. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  47. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  48. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  49. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +171 -88
  50. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
  51. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  52. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  53. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  54. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +62 -0
  55. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
  56. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +53 -42
  57. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  58. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +28 -9
  59. package/lib/runtime/components/react/dist/mpx-swiper.jsx +608 -0
  60. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  61. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  62. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  63. package/lib/runtime/components/react/dist/mpx-view.jsx +67 -94
  64. package/lib/runtime/components/react/dist/mpx-web-view.jsx +152 -37
  65. package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
  66. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  67. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  68. package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
  69. package/lib/runtime/components/react/dist/useAnimationHooks.js +36 -10
  70. package/lib/runtime/components/react/dist/utils.jsx +129 -24
  71. package/lib/runtime/components/react/event.config.ts +25 -26
  72. package/lib/runtime/components/react/getInnerListeners.ts +238 -202
  73. package/lib/runtime/components/react/mpx-button.tsx +104 -57
  74. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  75. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  76. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  77. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  78. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  79. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  80. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  81. package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
  82. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  83. package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
  84. package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
  85. package/lib/runtime/components/react/mpx-form.tsx +25 -28
  86. package/lib/runtime/components/react/mpx-icon.tsx +12 -17
  87. package/lib/runtime/components/react/mpx-image.tsx +436 -0
  88. package/lib/runtime/components/react/mpx-input.tsx +77 -57
  89. package/lib/runtime/components/react/mpx-label.tsx +26 -27
  90. package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
  91. package/lib/runtime/components/react/mpx-movable-view.tsx +22 -26
  92. package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
  93. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  94. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  95. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  96. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  97. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  98. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  99. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  100. package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +88 -0
  101. package/lib/runtime/components/react/mpx-picker-view-column.tsx +276 -112
  102. package/lib/runtime/components/react/mpx-picker-view.tsx +137 -129
  103. package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
  104. package/lib/runtime/components/react/mpx-radio.tsx +45 -54
  105. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  106. package/lib/runtime/components/react/mpx-rich-text/index.tsx +115 -0
  107. package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
  108. package/lib/runtime/components/react/mpx-scroll-view.tsx +83 -73
  109. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  110. package/lib/runtime/components/react/mpx-swiper-item.tsx +41 -12
  111. package/lib/runtime/components/react/mpx-swiper.tsx +690 -0
  112. package/lib/runtime/components/react/mpx-switch.tsx +29 -23
  113. package/lib/runtime/components/react/mpx-text.tsx +14 -18
  114. package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
  115. package/lib/runtime/components/react/mpx-view.tsx +93 -117
  116. package/lib/runtime/components/react/mpx-web-view.tsx +162 -56
  117. package/lib/runtime/components/react/pickerFaces.ts +112 -0
  118. package/lib/runtime/components/react/pickerVIewContext.ts +18 -0
  119. package/lib/runtime/components/react/pickerViewMask.tsx +30 -0
  120. package/lib/runtime/components/react/pickerViewOverlay.tsx +34 -0
  121. package/lib/runtime/components/react/types/common.ts +2 -0
  122. package/lib/runtime/components/react/types/global.d.ts +7 -17
  123. package/lib/runtime/components/react/useAnimationHooks.ts +37 -12
  124. package/lib/runtime/components/react/utils.tsx +169 -29
  125. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  126. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  127. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  128. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  129. package/lib/runtime/components/web/mpx-web-view.vue +175 -161
  130. package/lib/runtime/optionProcessor.js +7 -38
  131. package/lib/runtime/utils.js +2 -0
  132. package/lib/style-compiler/index.js +3 -4
  133. package/lib/style-compiler/plugins/scope-id.js +30 -2
  134. package/lib/style-compiler/strip-conditional-loader.js +118 -0
  135. package/lib/template-compiler/bind-this.js +7 -2
  136. package/lib/template-compiler/compiler.js +66 -39
  137. package/lib/template-compiler/gen-node-react.js +3 -3
  138. package/package.json +6 -4
  139. package/LICENSE +0 -433
  140. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  141. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  142. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  143. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  144. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  145. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  146. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
  147. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +0 -525
  148. package/lib/runtime/components/react/mpx-swiper/index.tsx +0 -80
  149. package/lib/runtime/components/react/mpx-swiper/type.ts +0 -87
  150. package/lib/runtime/components/web/event.js +0 -105
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Borrowed from open-source code: https://github.com/quidone/react-native-wheel-picker
3
+ * Special thanks to the authors for their contribution to the open-source community.
4
+ */
5
+ export const degToRad = (deg) => (Math.PI * deg) / 180;
6
+ // Calculates the height of the element after rotating it relative to the user's screen.
7
+ const calcHeight = (degree, itemHeight) => itemHeight * Math.cos(degToRad(degree));
8
+ export const calcPickerHeight = (faces, itemHeight) => {
9
+ if (faces.length === 7) {
10
+ return itemHeight * 5;
11
+ }
12
+ return faces.reduce((r, v) => r + calcHeight(Math.abs(v.deg), itemHeight), 0);
13
+ };
14
+ export const createFaces = (itemHeight, visibleCount) => {
15
+ // e.g [30, 60, 90]
16
+ const getDegreesRelativeCenter = () => {
17
+ const maxStep = Math.trunc((visibleCount + 2) / 2); // + 2 because there are 2 more faces at 90 degrees
18
+ const stepDegree = 90 / maxStep;
19
+ const result = [];
20
+ for (let i = 1; i <= maxStep; i++) {
21
+ result.push(i * stepDegree);
22
+ }
23
+ return result;
24
+ };
25
+ const getScreenHeightsAndOffsets = (degrees) => {
26
+ const screenHeights = degrees.map((deg) => calcHeight(deg, itemHeight));
27
+ const freeSpaces = screenHeights.map((screenHeight) => itemHeight - screenHeight);
28
+ const offsets = freeSpaces.map((freeSpace, index) => {
29
+ let offset = freeSpace / 2;
30
+ for (let i = 0; i < index; i++) {
31
+ offset += freeSpaces[i];
32
+ }
33
+ if (index === 0) {
34
+ offset *= 0.6;
35
+ }
36
+ return offset;
37
+ });
38
+ return [screenHeights, offsets];
39
+ };
40
+ const getOpacity = (index) => {
41
+ const map = {
42
+ 0: 0,
43
+ 1: 0.8,
44
+ 2: 0.9 // 0.35
45
+ // 3: 0.45, // 0.45
46
+ // 4: 0.5 // 0.5
47
+ };
48
+ return map[index] ?? Math.min(1, map[2] + index * 0.05);
49
+ };
50
+ const degrees = getDegreesRelativeCenter();
51
+ const [screenHeight, offsets] = getScreenHeightsAndOffsets(degrees);
52
+ const scales = [1, 0.925, 0.8];
53
+ return [
54
+ // top items
55
+ ...degrees
56
+ .map((degree, index) => {
57
+ return {
58
+ index: -1 * (index + 1),
59
+ deg: degree,
60
+ opacity: getOpacity(degrees.length - 1 - index),
61
+ offsetY: -1 * offsets[index],
62
+ scale: scales[index],
63
+ screenHeight: screenHeight[index]
64
+ };
65
+ })
66
+ .reverse(),
67
+ // center item
68
+ { index: 0, deg: 0, opacity: 1, offsetY: 0, scale: 1, screenHeight: itemHeight },
69
+ // bottom items
70
+ ...degrees.map((degree, index) => {
71
+ return {
72
+ index: index + 1,
73
+ deg: -1 * degree,
74
+ opacity: getOpacity(degrees.length - 1 - index),
75
+ offsetY: offsets[index],
76
+ scale: scales[index],
77
+ screenHeight: screenHeight[index]
78
+ };
79
+ })
80
+ ];
81
+ };
@@ -0,0 +1,9 @@
1
+ import { createContext, useContext } from 'react';
2
+ export const PickerViewColumnAnimationContext = createContext(undefined);
3
+ export const usePickerViewColumnAnimationContext = () => {
4
+ const value = useContext(PickerViewColumnAnimationContext);
5
+ if (value === undefined) {
6
+ throw new Error('usePickerViewColumnAnimationContext must be called from within PickerViewColumnAnimationContext.Provider!');
7
+ }
8
+ return value;
9
+ };
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { StyleSheet, View } from 'react-native';
3
+ import LinearGradient from 'react-native-linear-gradient';
4
+ const _PickerViewMask = ({ itemHeight, maskContainerStyle }) => {
5
+ return (<View style={[styles.overlayContainer, maskContainerStyle]} pointerEvents={'none'}>
6
+ <LinearGradient colors={['rgba(255,255,255,1)', 'rgba(255,255,255,0.5)']} style={{ flex: 1 }}/>
7
+ <View style={{ height: itemHeight }}/>
8
+ <LinearGradient colors={['rgba(255,255,255,0.5)', 'rgba(255,255,255,1)']} style={{ flex: 1 }}/>
9
+ </View>);
10
+ };
11
+ const styles = StyleSheet.create({
12
+ overlayContainer: {
13
+ ...StyleSheet.absoluteFillObject,
14
+ zIndex: 100
15
+ }
16
+ });
17
+ _PickerViewMask.displayName = 'MpxPickerViewMask';
18
+ export default _PickerViewMask;
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import { StyleSheet, View } from 'react-native';
3
+ const _PickerViewOverlay = ({ itemHeight, overlayItemStyle, overlayContainerStyle }) => {
4
+ return (<View style={[styles.overlayContainer, overlayContainerStyle]} pointerEvents={'none'}>
5
+ <View style={[styles.selection, { height: itemHeight }, overlayItemStyle]}/>
6
+ </View>);
7
+ };
8
+ const styles = StyleSheet.create({
9
+ overlayContainer: {
10
+ ...StyleSheet.absoluteFillObject,
11
+ justifyContent: 'center',
12
+ alignItems: 'center',
13
+ zIndex: 200
14
+ },
15
+ selection: {
16
+ borderTopWidth: 1,
17
+ borderBottomWidth: 1,
18
+ borderColor: 'rgba(0, 0, 0, 0.05)',
19
+ alignSelf: 'stretch'
20
+ }
21
+ });
22
+ _PickerViewOverlay.displayName = 'MpxPickerViewOverlay';
23
+ export default _PickerViewOverlay;
@@ -47,12 +47,35 @@ const InitialValue = Object.assign({
47
47
  const TransformOrigin = 'transformOrigin';
48
48
  // transform
49
49
  const isTransform = (key) => Object.keys(TransformInitial).includes(key);
50
+ // 多value解析
51
+ const parseValues = (str, char = ' ') => {
52
+ let stack = 0;
53
+ let temp = '';
54
+ const result = [];
55
+ for (let i = 0; i < str.length; i++) {
56
+ if (str[i] === '(') {
57
+ stack++;
58
+ }
59
+ else if (str[i] === ')') {
60
+ stack--;
61
+ }
62
+ // 非括号内 或者 非分隔字符且非空
63
+ if (stack !== 0 || (str[i] !== char && str[i] !== ' ')) {
64
+ temp += str[i];
65
+ }
66
+ if ((stack === 0 && str[i] === char) || i === str.length - 1) {
67
+ result.push(temp);
68
+ temp = '';
69
+ }
70
+ }
71
+ return result;
72
+ };
50
73
  // parse string transform, eg: transform: 'rotateX(45deg) rotateZ(0.785398rad)'
51
74
  const parseTransform = (transformStr) => {
52
- const values = transformStr.trim().split(/\s+/);
75
+ const values = parseValues(transformStr);
53
76
  const transform = [];
54
77
  values.forEach(item => {
55
- const match = item.match(/([/\w]+)\(([^)]+)\)/);
78
+ const match = item.match(/([/\w]+)\((.+)\)/);
56
79
  if (match && match.length >= 3) {
57
80
  let key = match[1];
58
81
  const val = match[2];
@@ -73,7 +96,7 @@ const parseTransform = (transformStr) => {
73
96
  break;
74
97
  case 'matrix':
75
98
  case 'matrix3d':
76
- transform.push({ [key]: val.split(',').map(val => +val) });
99
+ transform.push({ [key]: parseValues(val, ',').map(val => +val) });
77
100
  break;
78
101
  case 'translate':
79
102
  case 'scale':
@@ -84,8 +107,8 @@ const parseTransform = (transformStr) => {
84
107
  {
85
108
  // 2 个以上的值处理
86
109
  key = key.replace('3d', '');
87
- const vals = val.split(',', key === 'rotate' ? 4 : 3);
88
- // scale(.5) === scaleX(.5) scaleY(.5) 这里处理一下
110
+ const vals = parseValues(val, ',').splice(0, key === 'rotate' ? 4 : 3);
111
+ // scale(.5) === scaleX(.5) scaleY(.5)
89
112
  if (vals.length === 1 && key === 'scale') {
90
113
  vals.push(vals[0]);
91
114
  }
@@ -183,11 +206,14 @@ export default function useAnimationHooks(props) {
183
206
  }
184
207
  // 添加每个key的多次step动画
185
208
  animatedKeys.forEach(key => {
186
- let toVal = (rules.get(key) || transform.get(key));
187
209
  // key不存在,第一轮取shareValMap[key]value,非第一轮取上一轮的
188
- if (toVal === undefined) {
189
- toVal = index > 0 ? lastValueMap[key] : shareValMap[key].value;
190
- }
210
+ const toVal = rules.get(key) !== undefined
211
+ ? rules.get(key)
212
+ : transform.get(key) !== undefined
213
+ ? transform.get(key)
214
+ : index > 0
215
+ ? lastValueMap[key]
216
+ : shareValMap[key].value;
191
217
  const animation = getAnimation({ key, value: toVal }, { delay, duration, easing }, needSetCallback ? setTransformOrigin : undefined);
192
218
  needSetCallback = false;
193
219
  if (!sequence[key]) {
@@ -298,6 +324,6 @@ export default function useAnimationHooks(props) {
298
324
  styles[key] = shareValMap[key].value;
299
325
  }
300
326
  return styles;
301
- }, Object.assign({}, originalStyle));
327
+ }, {});
302
328
  });
303
329
  }
@@ -1,17 +1,24 @@
1
- import { useEffect, useRef, isValidElement, useContext, useState, Children, cloneElement } from 'react';
2
- import { isObject, hasOwn, diffAndCloneA, error, warn, getFocusedNavigation } from '@mpxjs/utils';
3
- import { VarContext } from './context';
1
+ import { useEffect, useCallback, useMemo, useRef, isValidElement, useContext, useState, Children, cloneElement } from 'react';
2
+ import { Image, Platform } from 'react-native';
3
+ import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn, getFocusedNavigation } from '@mpxjs/utils';
4
+ import { VarContext, ScrollViewContext } from './context';
4
5
  import { ExpressionParser, parseFunc, ReplaceSource } from './parser';
5
6
  import { initialWindowMetrics } from 'react-native-safe-area-context';
7
+ import FastImage from '@d11/react-native-fast-image';
8
+ import { runOnJS } from 'react-native-reanimated';
9
+ import { Gesture } from 'react-native-gesture-handler';
6
10
  export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/;
7
11
  export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/;
8
12
  export const URL_REGEX = /^\s*url\(["']?(.*?)["']?\)\s*$/;
13
+ export const SVG_REGEXP = /https?:\/\/.*\.(?:svg)/i;
9
14
  export const BACKGROUND_REGEX = /^background(Image|Size|Repeat|Position)$/;
10
- export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines/;
15
+ export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines|allowFontScaling/;
11
16
  export const DEFAULT_FONT_SIZE = 16;
12
17
  export const HIDDEN_STYLE = {
13
18
  opacity: 0
14
19
  };
20
+ export const isIOS = Platform.OS === 'ios';
21
+ export const isAndroid = Platform.OS === 'android';
15
22
  const varDecRegExp = /^--.*/;
16
23
  const varUseRegExp = /var\(/;
17
24
  const calcUseRegExp = /calc\(/;
@@ -24,10 +31,7 @@ const safeAreaInsetMap = {
24
31
  };
25
32
  function getSafeAreaInset(name) {
26
33
  const navigation = getFocusedNavigation();
27
- const insets = {
28
- ...initialWindowMetrics?.insets,
29
- ...navigation?.insets
30
- };
34
+ const insets = extendObject({}, initialWindowMetrics?.insets, navigation?.insets);
31
35
  return insets[safeAreaInsetMap[name]];
32
36
  }
33
37
  export function omit(obj, fields) {
@@ -69,7 +73,7 @@ export const parseInlineStyle = (inlineStyle = '') => {
69
73
  if (rest.length || !v || !k)
70
74
  return styleObj;
71
75
  const key = k.trim().replace(/-./g, c => c.substring(1).toUpperCase());
72
- return Object.assign(styleObj, { [key]: v.trim() });
76
+ return Object.assign(styleObj, { [key]: global.__formatValue(v.trim()) });
73
77
  }, {});
74
78
  };
75
79
  export const parseUrl = (cssUrl = '') => {
@@ -79,23 +83,13 @@ export const parseUrl = (cssUrl = '') => {
79
83
  return match?.[1];
80
84
  };
81
85
  export const getRestProps = (transferProps = {}, originProps = {}, deletePropsKey = []) => {
82
- return {
83
- ...transferProps,
84
- ...omit(originProps, deletePropsKey)
85
- };
86
+ return extendObject({}, transferProps, omit(originProps, deletePropsKey));
86
87
  };
87
88
  export function isText(ele) {
88
89
  if (isValidElement(ele)) {
89
90
  const displayName = ele.type?.displayName;
90
91
  const isCustomText = ele.type?.isCustomText;
91
- return displayName === 'MpxText' || displayName === 'Text' || !!isCustomText;
92
- }
93
- return false;
94
- }
95
- export function isEmbedded(ele) {
96
- if (isValidElement(ele)) {
97
- const displayName = ele.type?.displayName || '';
98
- return ['mpx-checkbox', 'mpx-radio', 'mpx-switch'].includes(displayName);
92
+ return displayName === 'MpxText' || displayName === 'MpxSimpleText' || displayName === 'Text' || !!isCustomText;
99
93
  }
100
94
  return false;
101
95
  }
@@ -238,6 +232,14 @@ function transformCalc(styleObj, calcKeyPaths, formatter) {
238
232
  });
239
233
  });
240
234
  }
235
+ const stringifyProps = ['fontWeight'];
236
+ function transformStringify(styleObj) {
237
+ stringifyProps.forEach((prop) => {
238
+ if (isNumber(styleObj[prop])) {
239
+ styleObj[prop] = '' + styleObj[prop];
240
+ }
241
+ });
242
+ }
241
243
  export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight }) {
242
244
  const varStyle = {};
243
245
  const normalStyle = {};
@@ -336,6 +338,8 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
336
338
  }
337
339
  }
338
340
  });
341
+ // transform number enum stringify
342
+ transformStringify(normalStyle);
339
343
  return {
340
344
  normalStyle,
341
345
  hasSelfPercent,
@@ -402,7 +406,7 @@ export function splitProps(props) {
402
406
  export const useLayout = ({ props, hasSelfPercent, setWidth, setHeight, onLayout, nodeRef }) => {
403
407
  const layoutRef = useRef({});
404
408
  const hasLayoutRef = useRef(false);
405
- const layoutStyle = !hasLayoutRef.current && hasSelfPercent ? HIDDEN_STYLE : {};
409
+ const layoutStyle = useMemo(() => { return !hasLayoutRef.current && hasSelfPercent ? HIDDEN_STYLE : {}; }, [hasLayoutRef.current]);
406
410
  const layoutProps = {};
407
411
  const enableOffset = props['enable-offset'];
408
412
  if (hasSelfPercent || onLayout || enableOffset) {
@@ -433,8 +437,8 @@ export function wrapChildren(props = {}, { hasVarDec, varContext, textStyle, tex
433
437
  if (textStyle || textProps) {
434
438
  children = Children.map(children, (child) => {
435
439
  if (isText(child)) {
436
- const style = { ...textStyle, ...child.props.style };
437
- return cloneElement(child, { ...textProps, style });
440
+ const style = extendObject({}, textStyle, child.props.style);
441
+ return cloneElement(child, extendObject({}, textProps, { style }));
438
442
  }
439
443
  return child;
440
444
  });
@@ -444,6 +448,34 @@ export function wrapChildren(props = {}, { hasVarDec, varContext, textStyle, tex
444
448
  }
445
449
  return children;
446
450
  }
451
+ export const debounce = (func, delay) => {
452
+ let timer;
453
+ const wrapper = (...args) => {
454
+ clearTimeout(timer);
455
+ timer = setTimeout(() => {
456
+ func(...args);
457
+ }, delay);
458
+ };
459
+ wrapper.clear = () => {
460
+ clearTimeout(timer);
461
+ };
462
+ return wrapper;
463
+ };
464
+ export const useDebounceCallback = (func, delay) => {
465
+ const debounced = useMemo(() => debounce(func, delay), [func]);
466
+ return debounced;
467
+ };
468
+ export const useStableCallback = (callback) => {
469
+ const ref = useRef(callback);
470
+ ref.current = callback;
471
+ return useCallback((...args) => ref.current?.(...args), []);
472
+ };
473
+ export const usePrevious = (value) => {
474
+ const ref = useRef(undefined);
475
+ const prev = ref.current;
476
+ ref.current = value;
477
+ return prev;
478
+ };
447
479
  export function flatGesture(gestures = []) {
448
480
  return (gestures && gestures.flatMap((gesture) => {
449
481
  if (gesture && gesture.nodeRefs) {
@@ -453,3 +485,76 @@ export function flatGesture(gestures = []) {
453
485
  return gesture?.current ? [gesture] : [];
454
486
  })) || [];
455
487
  }
488
+ export const extendObject = Object.assign;
489
+ export function getCurrentPage(pageId) {
490
+ if (!global.getCurrentPages)
491
+ return;
492
+ const pages = global.getCurrentPages();
493
+ return pages.find((page) => isFunction(page.getPageId) && page.getPageId() === pageId);
494
+ }
495
+ export function renderImage(imageProps, enableFastImage = false) {
496
+ const Component = enableFastImage ? FastImage : Image;
497
+ return <Component {...imageProps}/>;
498
+ }
499
+ export function pickStyle(styleObj = {}, pickedKeys, callback) {
500
+ return pickedKeys.reduce((acc, key) => {
501
+ if (key in styleObj) {
502
+ acc[key] = callback ? callback(key, styleObj[key]) : styleObj[key];
503
+ }
504
+ return acc;
505
+ }, {});
506
+ }
507
+ export function useHoverStyle({ hoverStyle, hoverStartTime, hoverStayTime, disabled }) {
508
+ const enableHoverStyle = !!hoverStyle;
509
+ const enableHoverStyleRef = useRef(enableHoverStyle);
510
+ if (enableHoverStyleRef.current !== enableHoverStyle) {
511
+ throw new Error('[Mpx runtime error]: hover-class use should be stable in the component lifecycle.');
512
+ }
513
+ if (!enableHoverStyle)
514
+ return { enableHoverStyle };
515
+ const gestureRef = useContext(ScrollViewContext).gestureRef;
516
+ const [isHover, setIsHover] = useState(false);
517
+ const dataRef = useRef({});
518
+ useEffect(() => {
519
+ return () => {
520
+ dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer);
521
+ dataRef.current.stayTimer && clearTimeout(dataRef.current.stayTimer);
522
+ };
523
+ }, []);
524
+ const setStartTimer = () => {
525
+ dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer);
526
+ dataRef.current.startTimer = setTimeout(() => {
527
+ setIsHover(true);
528
+ }, +hoverStartTime);
529
+ };
530
+ const setStayTimer = () => {
531
+ dataRef.current.stayTimer && clearTimeout(dataRef.current.stayTimer);
532
+ dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer);
533
+ dataRef.current.stayTimer = setTimeout(() => {
534
+ setIsHover(false);
535
+ }, +hoverStayTime);
536
+ };
537
+ const gesture = useMemo(() => {
538
+ return Gesture.Pan()
539
+ .onTouchesDown(() => {
540
+ 'worklet';
541
+ if (disabled)
542
+ return;
543
+ runOnJS(setStartTimer)();
544
+ })
545
+ .onTouchesUp(() => {
546
+ 'worklet';
547
+ if (disabled)
548
+ return;
549
+ runOnJS(setStayTimer)();
550
+ });
551
+ }, [disabled]);
552
+ if (gestureRef) {
553
+ gesture.simultaneousWithExternalGesture(gestureRef);
554
+ }
555
+ return {
556
+ isHover,
557
+ gesture,
558
+ enableHoverStyle
559
+ };
560
+ }
@@ -2,31 +2,30 @@ interface EventConfig {
2
2
  [key: string]: string[];
3
3
  }
4
4
 
5
- const eventConfigMap: EventConfig = {
6
- bindtap: ['onTouchStart', 'onTouchMove', 'onTouchEnd'],
7
- bindlongpress: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'],
8
- bindtouchstart: ['onTouchStart'],
9
- bindtouchmove: ['onTouchMove'],
10
- bindtouchend: ['onTouchEnd'],
11
- bindtouchcancel: ['onTouchCancel'],
12
- catchtap: ['onTouchStart', 'onTouchMove', 'onTouchEnd'],
13
- catchlongpress: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'],
14
- catchtouchstart: ['onTouchStart'],
15
- catchtouchmove: ['onTouchMove'],
16
- catchtouchend: ['onTouchEnd'],
17
- catchtouchcancel: ['onTouchCancel'],
18
- 'capture-bindtap': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'],
19
- 'capture-bindlongpress': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'],
20
- 'capture-bindtouchstart': ['onTouchStartCapture'],
21
- 'capture-bindtouchmove': ['onTouchMoveCapture'],
22
- 'capture-bindtouchend': ['onTouchEndCapture'],
23
- 'capture-bindtouchcancel': ['onTouchCancelCapture'],
24
- 'capture-catchtap': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'],
25
- 'capture-catchlongpress': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'],
26
- 'capture-catchtouchstart': ['onTouchStartCapture'],
27
- 'capture-catchtouchmove': ['onTouchMoveCapture'],
28
- 'capture-catchtouchend': ['onTouchEndCapture'],
29
- 'capture-catchtouchcancel': ['onTouchCancelCapture']
5
+ const eventConfigMap: { [key: string]: { bitFlag: string; events: string[] } } = {
6
+ bindtap: { bitFlag: '0', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd'] },
7
+ bindlongpress: { bitFlag: '1', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'] },
8
+ bindtouchstart: { bitFlag: '2', events: ['onTouchStart'] },
9
+ bindtouchmove: { bitFlag: '3', events: ['onTouchMove'] },
10
+ bindtouchend: { bitFlag: '4', events: ['onTouchEnd'] },
11
+ bindtouchcancel: { bitFlag: '5', events: ['onTouchCancel'] },
12
+ catchtap: { bitFlag: '6', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd'] },
13
+ catchlongpress: { bitFlag: '7', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'] },
14
+ catchtouchstart: { bitFlag: '8', events: ['onTouchStart'] },
15
+ catchtouchmove: { bitFlag: '9', events: ['onTouchMove'] },
16
+ catchtouchend: { bitFlag: 'a', events: ['onTouchEnd'] },
17
+ catchtouchcancel: { bitFlag: 'b', events: ['onTouchCancel'] },
18
+ 'capture-bindtap': { bitFlag: 'c', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'] },
19
+ 'capture-bindlongpress': { bitFlag: 'd', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'] },
20
+ 'capture-bindtouchstart': { bitFlag: 'e', events: ['onTouchStartCapture'] },
21
+ 'capture-bindtouchmove': { bitFlag: 'f', events: ['onTouchMoveCapture'] },
22
+ 'capture-bindtouchend': { bitFlag: 'g', events: ['onTouchEndCapture'] },
23
+ 'capture-bindtouchcancel': { bitFlag: 'h', events: ['onTouchCancelCapture'] },
24
+ 'capture-catchtap': { bitFlag: 'i', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'] },
25
+ 'capture-catchlongpress': { bitFlag: 'j', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'] },
26
+ 'capture-catchtouchstart': { bitFlag: 'k', events: ['onTouchStartCapture'] },
27
+ 'capture-catchtouchmove': { bitFlag: 'l', events: ['onTouchMoveCapture'] },
28
+ 'capture-catchtouchend': { bitFlag: 'm', events: ['onTouchEndCapture'] },
29
+ 'capture-catchtouchcancel': { bitFlag: 'n', events: ['onTouchCancelCapture'] }
30
30
  }
31
-
32
31
  export default eventConfigMap