@mpxjs/webpack-plugin 2.9.66 → 2.9.69-beta.0

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 (158) hide show
  1. package/lib/dependencies/RecordGlobalComponentsDependency.js +11 -12
  2. package/lib/dependencies/RecordRuntimeInfoDependency.js +1 -1
  3. package/lib/index.js +29 -8
  4. package/lib/json-compiler/index.js +2 -11
  5. package/lib/loader.js +24 -45
  6. package/lib/native-loader.js +49 -64
  7. package/lib/platform/json/wx/index.js +24 -18
  8. package/lib/platform/style/wx/index.js +49 -47
  9. package/lib/platform/template/wx/component-config/canvas.js +8 -0
  10. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  11. package/lib/platform/template/wx/component-config/index.js +1 -1
  12. package/lib/platform/template/wx/component-config/input.js +1 -1
  13. package/lib/platform/template/wx/component-config/rich-text.js +8 -0
  14. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  15. package/lib/platform/template/wx/component-config/textarea.js +1 -1
  16. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  17. package/lib/react/index.js +4 -3
  18. package/lib/react/processJSON.js +5 -13
  19. package/lib/react/processMainScript.js +7 -3
  20. package/lib/react/processScript.js +3 -4
  21. package/lib/react/processStyles.js +14 -4
  22. package/lib/react/processTemplate.js +5 -2
  23. package/lib/resolver/AddModePlugin.js +20 -7
  24. package/lib/runtime/components/react/context.ts +6 -0
  25. package/lib/runtime/components/react/dist/context.js +2 -0
  26. package/lib/runtime/components/react/dist/event.config.js +24 -24
  27. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -174
  28. package/lib/runtime/components/react/dist/mpx-button.jsx +78 -50
  29. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  30. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  31. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  32. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  33. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  34. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  35. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  36. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
  37. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  38. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +41 -34
  39. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +30 -39
  40. package/lib/runtime/components/react/dist/mpx-form.jsx +47 -41
  41. package/lib/runtime/components/react/dist/mpx-icon.jsx +9 -17
  42. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  43. package/lib/runtime/components/react/dist/mpx-input.jsx +95 -62
  44. package/lib/runtime/components/react/dist/mpx-label.jsx +24 -28
  45. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +20 -30
  46. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +377 -293
  47. package/lib/runtime/components/react/dist/mpx-navigator.jsx +3 -5
  48. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  49. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  50. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  51. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  52. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  53. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  54. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  55. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +160 -88
  56. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
  57. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +39 -34
  58. package/lib/runtime/components/react/dist/mpx-radio.jsx +28 -43
  59. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  60. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
  61. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +7 -5
  62. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +77 -51
  63. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  64. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +5 -3
  65. package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -0
  66. package/lib/runtime/components/react/dist/mpx-switch.jsx +28 -11
  67. package/lib/runtime/components/react/dist/mpx-text.jsx +12 -11
  68. package/lib/runtime/components/react/dist/mpx-textarea.jsx +9 -4
  69. package/lib/runtime/components/react/dist/mpx-view.jsx +66 -62
  70. package/lib/runtime/components/react/dist/mpx-web-view.jsx +113 -36
  71. package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
  72. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  73. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  74. package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
  75. package/lib/runtime/components/react/dist/useAnimationHooks.js +126 -12
  76. package/lib/runtime/components/react/dist/utils.jsx +80 -24
  77. package/lib/runtime/components/react/event.config.ts +25 -26
  78. package/lib/runtime/components/react/getInnerListeners.ts +237 -198
  79. package/lib/runtime/components/react/mpx-button.tsx +105 -58
  80. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  81. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  82. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  83. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  84. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  85. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  86. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  87. package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
  88. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  89. package/lib/runtime/components/react/mpx-checkbox-group.tsx +77 -51
  90. package/lib/runtime/components/react/mpx-checkbox.tsx +49 -50
  91. package/lib/runtime/components/react/mpx-form.tsx +62 -57
  92. package/lib/runtime/components/react/mpx-icon.tsx +13 -18
  93. package/lib/runtime/components/react/mpx-image.tsx +436 -0
  94. package/lib/runtime/components/react/mpx-input.tsx +139 -117
  95. package/lib/runtime/components/react/mpx-label.tsx +36 -34
  96. package/lib/runtime/components/react/mpx-movable-area.tsx +26 -39
  97. package/lib/runtime/components/react/mpx-movable-view.tsx +455 -337
  98. package/lib/runtime/components/react/mpx-navigator.tsx +3 -9
  99. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  100. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  101. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  102. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  103. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  104. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  105. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  106. package/lib/runtime/components/react/mpx-picker-view-column.tsx +236 -104
  107. package/lib/runtime/components/react/mpx-picker-view.tsx +132 -122
  108. package/lib/runtime/components/react/mpx-radio-group.tsx +77 -54
  109. package/lib/runtime/components/react/mpx-radio.tsx +46 -55
  110. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  111. package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
  112. package/lib/runtime/components/react/mpx-root-portal.tsx +4 -6
  113. package/lib/runtime/components/react/mpx-scroll-view.tsx +122 -76
  114. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  115. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +6 -4
  116. package/lib/runtime/components/react/mpx-swiper/index.tsx +2 -1
  117. package/lib/runtime/components/react/mpx-swiper-item.tsx +4 -3
  118. package/lib/runtime/components/react/mpx-switch.tsx +39 -25
  119. package/lib/runtime/components/react/mpx-text.tsx +15 -19
  120. package/lib/runtime/components/react/mpx-textarea.tsx +12 -11
  121. package/lib/runtime/components/react/mpx-view.tsx +93 -77
  122. package/lib/runtime/components/react/mpx-web-view.tsx +117 -55
  123. package/lib/runtime/components/react/pickerFaces.ts +104 -0
  124. package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
  125. package/lib/runtime/components/react/types/common.ts +2 -0
  126. package/lib/runtime/components/react/types/global.d.ts +5 -17
  127. package/lib/runtime/components/react/useAnimationHooks.ts +127 -18
  128. package/lib/runtime/components/react/useNodesRef.ts +1 -0
  129. package/lib/runtime/components/react/utils.tsx +113 -27
  130. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  131. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  132. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  133. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  134. package/lib/runtime/components/web/mpx-web-view.vue +175 -161
  135. package/lib/runtime/optionProcessor.js +7 -38
  136. package/lib/runtime/optionProcessorReact.js +0 -15
  137. package/lib/runtime/swanHelper.wxs +1 -1
  138. package/lib/runtime/utils.js +2 -0
  139. package/lib/style-compiler/index.js +1 -1
  140. package/lib/style-compiler/plugins/scope-id.js +31 -2
  141. package/lib/template-compiler/bind-this.js +7 -2
  142. package/lib/template-compiler/compiler.js +118 -56
  143. package/lib/template-compiler/gen-node-react.js +3 -3
  144. package/lib/template-compiler/index.js +4 -4
  145. package/lib/utils/pre-process-json.js +117 -0
  146. package/lib/web/index.js +5 -4
  147. package/lib/web/processJSON.js +5 -13
  148. package/lib/web/processTemplate.js +2 -2
  149. package/package.json +6 -4
  150. package/LICENSE +0 -433
  151. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  152. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  153. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  154. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  155. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  156. package/lib/runtime/components/react/mpx-image/index.tsx +0 -346
  157. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
  158. package/lib/runtime/components/web/event.js +0 -105
@@ -45,19 +45,102 @@ const InitialValue = Object.assign({
45
45
  transformOrigin: ['50%', '50%', 0]
46
46
  }, TransformInitial);
47
47
  const TransformOrigin = 'transformOrigin';
48
- // deg 角度
49
- // const isDeg = (key: RuleKey) => ['rotateX', 'rotateY', 'rotateZ', 'rotate', 'skewX', 'skewY'].includes(key)
50
- // 背景色
51
- // const isBg = (key: RuleKey) => key === 'backgroundColor'
52
48
  // transform
53
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
+ };
73
+ // parse string transform, eg: transform: 'rotateX(45deg) rotateZ(0.785398rad)'
74
+ const parseTransform = (transformStr) => {
75
+ const values = parseValues(transformStr);
76
+ const transform = [];
77
+ values.forEach(item => {
78
+ const match = item.match(/([/\w]+)\(([^)]+)\)/);
79
+ if (match && match.length >= 3) {
80
+ let key = match[1];
81
+ const val = match[2];
82
+ switch (key) {
83
+ case 'translateX':
84
+ case 'translateY':
85
+ case 'scaleX':
86
+ case 'scaleY':
87
+ case 'rotateX':
88
+ case 'rotateY':
89
+ case 'rotateZ':
90
+ case 'rotate':
91
+ case 'skewX':
92
+ case 'skewY':
93
+ case 'perspective':
94
+ // 单个值处理
95
+ transform.push({ [key]: global.__formatValue(val) });
96
+ break;
97
+ case 'matrix':
98
+ case 'matrix3d':
99
+ transform.push({ [key]: parseValues(val, ',').map(val => +val) });
100
+ break;
101
+ case 'translate':
102
+ case 'scale':
103
+ case 'skew':
104
+ case 'rotate3d': // x y z angle
105
+ case 'translate3d': // x y 支持 z不支持
106
+ case 'scale3d': // x y 支持 z不支持
107
+ {
108
+ // 2 个以上的值处理
109
+ key = key.replace('3d', '');
110
+ const vals = parseValues(val, ',').splice(0, key === 'rotate' ? 4 : 3);
111
+ // scale(.5) === scaleX(.5) scaleY(.5)
112
+ if (vals.length === 1 && key === 'scale') {
113
+ vals.push(vals[0]);
114
+ }
115
+ const xyz = ['X', 'Y', 'Z'];
116
+ transform.push(...vals.map((v, index) => {
117
+ return { [`${key}${xyz[index] || ''}`]: global.__formatValue(v.trim()) };
118
+ }));
119
+ break;
120
+ }
121
+ }
122
+ }
123
+ });
124
+ return transform;
125
+ };
126
+ // format style
127
+ const formatStyle = (style) => {
128
+ if (!style.transform || Array.isArray(style.transform))
129
+ return style;
130
+ return Object.assign({}, style, {
131
+ transform: parseTransform(style.transform)
132
+ });
133
+ };
54
134
  export default function useAnimationHooks(props) {
55
- const { style: originalStyle = {}, animation } = props;
135
+ const { style = {}, animation } = props;
136
+ const originalStyle = formatStyle(style);
56
137
  // id 标识
57
138
  const id = animation?.id || -1;
58
139
  // 有动画样式的 style key
59
140
  const animatedStyleKeys = useSharedValue([]);
141
+ // 记录动画key的style样式值 没有的话设置为false
60
142
  const animatedKeys = useRef({});
143
+ // const animatedKeys = useRef({} as {[propName: keyof ExtendedViewStyle]: boolean|number|string})
61
144
  // ** 全量 style prop sharedValue
62
145
  // 不能做增量的原因:
63
146
  // 1 尝试用 useRef,但 useAnimatedStyle 访问后的 ref 不能在增加新的值,被冻结
@@ -80,6 +163,16 @@ export default function useAnimationHooks(props) {
80
163
  // 驱动动画
81
164
  createAnimation(keys);
82
165
  }, [id]);
166
+ // 同步style更新
167
+ // useEffect(() => {
168
+ // Object.keys(animatedKeys.current).forEach(key => {
169
+ // const originVal = getOriginalStyleVal(key, isTransform(key))
170
+ // if (originVal && animatedKeys.current[key] !== originVal) {
171
+ // animatedKeys.current[key] = originVal
172
+ // shareValMap[key].value = originVal
173
+ // }
174
+ // })
175
+ // }, [style])
83
176
  // ** 清空动画
84
177
  useEffect(() => {
85
178
  return () => {
@@ -113,11 +206,14 @@ export default function useAnimationHooks(props) {
113
206
  }
114
207
  // 添加每个key的多次step动画
115
208
  animatedKeys.forEach(key => {
116
- let toVal = (rules.get(key) || transform.get(key));
117
209
  // key不存在,第一轮取shareValMap[key]value,非第一轮取上一轮的
118
- if (!toVal) {
119
- toVal = index > 0 ? lastValueMap[key] : shareValMap[key].value;
120
- }
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;
121
217
  const animation = getAnimation({ key, value: toVal }, { delay, duration, easing }, needSetCallback ? setTransformOrigin : undefined);
122
218
  needSetCallback = false;
123
219
  if (!sequence[key]) {
@@ -143,9 +239,8 @@ export default function useAnimationHooks(props) {
143
239
  : withTiming(value, { duration, easing });
144
240
  return delay ? withDelay(delay, animation) : animation;
145
241
  }
146
- // 获取初始值(prop style or 默认值)
147
242
  function getInitialVal(key, isTransform = false) {
148
- if (isTransform && originalStyle.transform?.length) {
243
+ if (isTransform && Array.isArray(originalStyle.transform)) {
149
244
  let initialVal = InitialValue[key];
150
245
  // 仅支持 { transform: [{rotateX: '45deg'}, {rotateZ: '0.785398rad'}] } 格式的初始样式
151
246
  originalStyle.transform.forEach(item => {
@@ -156,12 +251,31 @@ export default function useAnimationHooks(props) {
156
251
  }
157
252
  return originalStyle[key] === undefined ? InitialValue[key] : originalStyle[key];
158
253
  }
254
+ // 从 prop style 中获取样式初始值 没有为undefined
255
+ // function getOriginalStyleVal (key: keyof ExtendedViewStyle, isTransform = false) {
256
+ // if (isTransform && Array.isArray(originalStyle.transform)) {
257
+ // let initialVal = undefined // InitialValue[key]
258
+ // // 仅支持 { transform: [{rotateX: '45deg'}, {rotateZ: '0.785398rad'}] } 格式的初始样式
259
+ // originalStyle.transform.forEach(item => {
260
+ // if (item[key] !== undefined) initialVal = item[key]
261
+ // })
262
+ // return initialVal
263
+ // }
264
+ // return originalStyle[key] // === undefined ? InitialValue[key] : originalStyle[key]
265
+ // }
266
+ // 获取动画shareVal初始值(prop style or 默认值)
267
+ // function getInitialVal (key: keyof ExtendedViewStyle, isTransform = false) {
268
+ // const originalVal = getOriginalStyleVal(key, isTransform)
269
+ // return originalVal === undefined ? InitialValue[key] : originalStyle[key]
270
+ // }
159
271
  // 循环 animation actions 获取所有有动画的 style prop name
160
272
  function getAnimatedStyleKeys() {
161
273
  return (animation?.actions || []).reduce((keyMap, action) => {
162
274
  const { rules, transform } = action;
163
275
  const ruleArr = [...rules.keys(), ...transform.keys()];
164
276
  ruleArr.forEach(key => {
277
+ // const originalVal = getOriginalStyleVal(key, isTransform(key))
278
+ // if (!keyMap[key]) keyMap[key] = originalVal === undefined ? false : originalVal
165
279
  if (!keyMap[key])
166
280
  keyMap[key] = true;
167
281
  });
@@ -210,6 +324,6 @@ export default function useAnimationHooks(props) {
210
324
  styles[key] = shareValMap[key].value;
211
325
  }
212
326
  return styles;
213
- }, Object.assign({}, originalStyle));
327
+ }, {});
214
328
  });
215
329
  }
@@ -1,15 +1,18 @@
1
- import { useEffect, useRef, isValidElement, useContext, useState, Children, cloneElement } from 'react';
2
- import { isObject, hasOwn, diffAndCloneA, error, warn, getFocusedNavigation } from '@mpxjs/utils';
1
+ import { useEffect, useCallback, useMemo, useRef, isValidElement, useContext, useState, Children, cloneElement } from 'react';
2
+ import { Image } from 'react-native';
3
+ import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn, getFocusedNavigation } from '@mpxjs/utils';
3
4
  import { VarContext } 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';
6
8
  export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/;
7
9
  export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/;
8
10
  export const URL_REGEX = /^\s*url\(["']?(.*?)["']?\)\s*$/;
11
+ export const SVG_REGEXP = /https?:\/\/.*\.(?:svg)/i;
9
12
  export const BACKGROUND_REGEX = /^background(Image|Size|Repeat|Position)$/;
10
- export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines/;
13
+ export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines|allowFontScaling/;
11
14
  export const DEFAULT_FONT_SIZE = 16;
12
- export const DEFAULT_UNLAY_STYLE = {
15
+ export const HIDDEN_STYLE = {
13
16
  opacity: 0
14
17
  };
15
18
  const varDecRegExp = /^--.*/;
@@ -24,10 +27,7 @@ const safeAreaInsetMap = {
24
27
  };
25
28
  function getSafeAreaInset(name) {
26
29
  const navigation = getFocusedNavigation();
27
- const insets = {
28
- ...initialWindowMetrics?.insets,
29
- ...navigation?.insets
30
- };
30
+ const insets = extendObject({}, initialWindowMetrics?.insets, navigation?.insets);
31
31
  return insets[safeAreaInsetMap[name]];
32
32
  }
33
33
  export function omit(obj, fields) {
@@ -69,7 +69,7 @@ export const parseInlineStyle = (inlineStyle = '') => {
69
69
  if (rest.length || !v || !k)
70
70
  return styleObj;
71
71
  const key = k.trim().replace(/-./g, c => c.substring(1).toUpperCase());
72
- return Object.assign(styleObj, { [key]: v.trim() });
72
+ return Object.assign(styleObj, { [key]: global.__formatValue(v.trim()) });
73
73
  }, {});
74
74
  };
75
75
  export const parseUrl = (cssUrl = '') => {
@@ -79,23 +79,13 @@ export const parseUrl = (cssUrl = '') => {
79
79
  return match?.[1];
80
80
  };
81
81
  export const getRestProps = (transferProps = {}, originProps = {}, deletePropsKey = []) => {
82
- return {
83
- ...transferProps,
84
- ...omit(originProps, deletePropsKey)
85
- };
82
+ return extendObject({}, transferProps, omit(originProps, deletePropsKey));
86
83
  };
87
84
  export function isText(ele) {
88
85
  if (isValidElement(ele)) {
89
86
  const displayName = ele.type?.displayName;
90
87
  const isCustomText = ele.type?.isCustomText;
91
- return displayName === 'mpx-text' || 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);
88
+ return displayName === 'MpxText' || displayName === 'MpxSimpleText' || displayName === 'Text' || !!isCustomText;
99
89
  }
100
90
  return false;
101
91
  }
@@ -238,6 +228,14 @@ function transformCalc(styleObj, calcKeyPaths, formatter) {
238
228
  });
239
229
  });
240
230
  }
231
+ const stringifyProps = ['fontWeight'];
232
+ function transformStringify(styleObj) {
233
+ stringifyProps.forEach((prop) => {
234
+ if (isNumber(styleObj[prop])) {
235
+ styleObj[prop] = '' + styleObj[prop];
236
+ }
237
+ });
238
+ }
241
239
  export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight }) {
242
240
  const varStyle = {};
243
241
  const normalStyle = {};
@@ -336,6 +334,8 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
336
334
  }
337
335
  }
338
336
  });
337
+ // transform number enum stringify
338
+ transformStringify(normalStyle);
339
339
  return {
340
340
  normalStyle,
341
341
  hasSelfPercent,
@@ -402,7 +402,7 @@ export function splitProps(props) {
402
402
  export const useLayout = ({ props, hasSelfPercent, setWidth, setHeight, onLayout, nodeRef }) => {
403
403
  const layoutRef = useRef({});
404
404
  const hasLayoutRef = useRef(false);
405
- const layoutStyle = !hasLayoutRef.current && hasSelfPercent ? DEFAULT_UNLAY_STYLE : {};
405
+ const layoutStyle = useMemo(() => { return !hasLayoutRef.current && hasSelfPercent ? HIDDEN_STYLE : {}; }, [hasLayoutRef.current]);
406
406
  const layoutProps = {};
407
407
  const enableOffset = props['enable-offset'];
408
408
  if (hasSelfPercent || onLayout || enableOffset) {
@@ -433,8 +433,8 @@ export function wrapChildren(props = {}, { hasVarDec, varContext, textStyle, tex
433
433
  if (textStyle || textProps) {
434
434
  children = Children.map(children, (child) => {
435
435
  if (isText(child)) {
436
- const style = { ...textStyle, ...child.props.style };
437
- return cloneElement(child, { ...textProps, style });
436
+ const style = extendObject({}, textStyle, child.props.style);
437
+ return cloneElement(child, extendObject({}, textProps, { style }));
438
438
  }
439
439
  return child;
440
440
  });
@@ -444,3 +444,59 @@ export function wrapChildren(props = {}, { hasVarDec, varContext, textStyle, tex
444
444
  }
445
445
  return children;
446
446
  }
447
+ export const debounce = (func, delay) => {
448
+ let timer;
449
+ const wrapper = (...args) => {
450
+ clearTimeout(timer);
451
+ timer = setTimeout(() => {
452
+ func(...args);
453
+ }, delay);
454
+ };
455
+ wrapper.clear = () => {
456
+ clearTimeout(timer);
457
+ };
458
+ return wrapper;
459
+ };
460
+ export const useDebounceCallback = (func, delay) => {
461
+ const debounced = useMemo(() => debounce(func, delay), [func]);
462
+ return debounced;
463
+ };
464
+ export const useStableCallback = (callback) => {
465
+ const ref = useRef(callback);
466
+ ref.current = callback;
467
+ return useCallback((...args) => ref.current?.(...args), []);
468
+ };
469
+ export const usePrevious = (value) => {
470
+ const ref = useRef(undefined);
471
+ const prev = ref.current;
472
+ ref.current = value;
473
+ return prev;
474
+ };
475
+ export function flatGesture(gestures = []) {
476
+ return (gestures && gestures.flatMap((gesture) => {
477
+ if (gesture && gesture.nodeRefs) {
478
+ return gesture.nodeRefs
479
+ .map((item) => item.getNodeInstance()?.instance?.gestureRef || {});
480
+ }
481
+ return gesture?.current ? [gesture] : [];
482
+ })) || [];
483
+ }
484
+ export const extendObject = Object.assign;
485
+ export function getCurrentPage(pageId) {
486
+ if (!global.getCurrentPages)
487
+ return;
488
+ const pages = global.getCurrentPages();
489
+ return pages.find((page) => isFunction(page.getPageId) && page.getPageId() === pageId);
490
+ }
491
+ export function renderImage(imageProps, enableFastImage = false) {
492
+ const Component = enableFastImage ? FastImage : Image;
493
+ return <Component {...imageProps}/>;
494
+ }
495
+ export function pickStyle(styleObj = {}, pickedKeys, callback) {
496
+ return pickedKeys.reduce((acc, key) => {
497
+ if (key in styleObj) {
498
+ acc[key] = callback ? callback(key, styleObj[key]) : styleObj[key];
499
+ }
500
+ return acc;
501
+ }, {});
502
+ }
@@ -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