@mpxjs/webpack-plugin 2.8.25-alpha.21 → 2.8.25-alpha.22

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 (72) hide show
  1. package/lib/runtime/components/react/dist/KeyboardAvoidingView.jsx +89 -0
  2. package/lib/runtime/components/react/dist/context.js +14 -0
  3. package/lib/runtime/components/react/dist/event.config.js +27 -0
  4. package/lib/runtime/components/react/dist/getInnerListeners.js +262 -0
  5. package/lib/runtime/components/react/dist/mpx-button.jsx +271 -0
  6. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  7. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  8. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  9. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  10. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  11. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  12. package/lib/runtime/components/react/dist/mpx-canvas/html.js +341 -0
  13. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +236 -0
  14. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  15. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +90 -0
  16. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +131 -0
  17. package/lib/runtime/components/react/dist/mpx-form.jsx +68 -0
  18. package/lib/runtime/components/react/dist/mpx-icon/icons/cancel.png +0 -0
  19. package/lib/runtime/components/react/dist/mpx-icon/icons/clear.png +0 -0
  20. package/lib/runtime/components/react/dist/mpx-icon/icons/download.png +0 -0
  21. package/lib/runtime/components/react/dist/mpx-icon/icons/info.png +0 -0
  22. package/lib/runtime/components/react/dist/mpx-icon/icons/search.png +0 -0
  23. package/lib/runtime/components/react/dist/mpx-icon/icons/success.png +0 -0
  24. package/lib/runtime/components/react/dist/mpx-icon/icons/success_no_circle.png +0 -0
  25. package/lib/runtime/components/react/dist/mpx-icon/icons/waiting.png +0 -0
  26. package/lib/runtime/components/react/dist/mpx-icon/icons/warn.png +0 -0
  27. package/lib/runtime/components/react/dist/mpx-icon/index.jsx +50 -0
  28. package/lib/runtime/components/react/dist/mpx-image.jsx +292 -0
  29. package/lib/runtime/components/react/dist/mpx-input.jsx +292 -0
  30. package/lib/runtime/components/react/dist/mpx-label.jsx +52 -0
  31. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +32 -0
  32. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +468 -0
  33. package/lib/runtime/components/react/dist/mpx-navigator.jsx +33 -0
  34. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +74 -0
  35. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +141 -0
  36. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +147 -0
  37. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +99 -0
  38. package/lib/runtime/components/react/dist/mpx-picker/regionData.js +6099 -0
  39. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +81 -0
  40. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +242 -0
  41. package/lib/runtime/components/react/dist/mpx-picker/type.js +1 -0
  42. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +35 -0
  43. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +193 -0
  44. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +125 -0
  45. package/lib/runtime/components/react/dist/mpx-portal/index.jsx +30 -0
  46. package/lib/runtime/components/react/dist/mpx-portal/portal-host.jsx +112 -0
  47. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +41 -0
  48. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +86 -0
  49. package/lib/runtime/components/react/dist/mpx-radio.jsx +140 -0
  50. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  51. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +62 -0
  52. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +17 -0
  53. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +372 -0
  54. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  55. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +59 -0
  56. package/lib/runtime/components/react/dist/mpx-swiper.jsx +671 -0
  57. package/lib/runtime/components/react/dist/mpx-switch.jsx +97 -0
  58. package/lib/runtime/components/react/dist/mpx-text.jsx +41 -0
  59. package/lib/runtime/components/react/dist/mpx-textarea.jsx +40 -0
  60. package/lib/runtime/components/react/dist/mpx-video.jsx +248 -0
  61. package/lib/runtime/components/react/dist/mpx-view.jsx +611 -0
  62. package/lib/runtime/components/react/dist/mpx-web-view.jsx +289 -0
  63. package/lib/runtime/components/react/dist/parser.js +218 -0
  64. package/lib/runtime/components/react/dist/pickerFaces.js +76 -0
  65. package/lib/runtime/components/react/dist/pickerVIewContext.js +14 -0
  66. package/lib/runtime/components/react/dist/pickerViewIndicator.jsx +23 -0
  67. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  68. package/lib/runtime/components/react/dist/useAnimationHooks.js +346 -0
  69. package/lib/runtime/components/react/dist/useNodesRef.js +16 -0
  70. package/lib/runtime/components/react/dist/utils.jsx +599 -0
  71. package/package.json +6 -3
  72. package/LICENSE +0 -433
@@ -0,0 +1,346 @@
1
+ import { useEffect, useMemo, useRef } from 'react';
2
+ import { Easing, useSharedValue, withTiming, useAnimatedStyle, withSequence, withDelay, makeMutable, cancelAnimation } from 'react-native-reanimated';
3
+ import { error } from '@mpxjs/utils';
4
+ // 微信 timingFunction 和 RN Easing 对应关系
5
+ const EasingKey = {
6
+ linear: Easing.linear,
7
+ ease: Easing.inOut(Easing.ease),
8
+ 'ease-in': Easing.in(Easing.poly(3)),
9
+ 'ease-in-out': Easing.inOut(Easing.poly(3)),
10
+ 'ease-out': Easing.out(Easing.poly(3))
11
+ // 'step-start': '',
12
+ // 'step-end': ''
13
+ };
14
+ const TransformInitial = {
15
+ // matrix: 0,
16
+ // matrix3d: 0,
17
+ rotate: '0deg',
18
+ rotateX: '0deg',
19
+ rotateY: '0deg',
20
+ rotateZ: '0deg',
21
+ // rotate3d:[0,0,0]
22
+ scale: 1,
23
+ // scale3d: [1, 1, 1],
24
+ scaleX: 1,
25
+ scaleY: 1,
26
+ // scaleZ: 1,
27
+ skew: 0,
28
+ skewX: '0deg',
29
+ skewY: '0deg',
30
+ translate: 0,
31
+ // translate3d: 0,
32
+ translateX: 0,
33
+ translateY: 0
34
+ // translateZ: 0,
35
+ };
36
+ // 动画默认初始值
37
+ const InitialValue = Object.assign({
38
+ opacity: 1,
39
+ backgroundColor: 'transparent',
40
+ width: 0,
41
+ height: 0,
42
+ top: 0,
43
+ right: 0,
44
+ bottom: 0,
45
+ left: 0,
46
+ transformOrigin: ['50%', '50%', 0]
47
+ }, TransformInitial);
48
+ const TransformOrigin = 'transformOrigin';
49
+ // transform
50
+ const isTransform = (key) => Object.keys(TransformInitial).includes(key);
51
+ // 多value解析
52
+ const parseValues = (str, char = ' ') => {
53
+ let stack = 0;
54
+ let temp = '';
55
+ const result = [];
56
+ for (let i = 0; i < str.length; i++) {
57
+ if (str[i] === '(') {
58
+ stack++;
59
+ }
60
+ else if (str[i] === ')') {
61
+ stack--;
62
+ }
63
+ // 非括号内 或者 非分隔字符且非空
64
+ if (stack !== 0 || (str[i] !== char && str[i] !== ' ')) {
65
+ temp += str[i];
66
+ }
67
+ if ((stack === 0 && str[i] === char) || i === str.length - 1) {
68
+ result.push(temp);
69
+ temp = '';
70
+ }
71
+ }
72
+ return result;
73
+ };
74
+ // parse string transform, eg: transform: 'rotateX(45deg) rotateZ(0.785398rad)'
75
+ const parseTransform = (transformStr) => {
76
+ const values = parseValues(transformStr);
77
+ const transform = [];
78
+ values.forEach(item => {
79
+ const match = item.match(/([/\w]+)\((.+)\)/);
80
+ if (match && match.length >= 3) {
81
+ let key = match[1];
82
+ const val = match[2];
83
+ switch (key) {
84
+ case 'translateX':
85
+ case 'translateY':
86
+ case 'scaleX':
87
+ case 'scaleY':
88
+ case 'rotateX':
89
+ case 'rotateY':
90
+ case 'rotateZ':
91
+ case 'rotate':
92
+ case 'skewX':
93
+ case 'skewY':
94
+ case 'perspective':
95
+ // 单个值处理
96
+ transform.push({ [key]: global.__formatValue(val) });
97
+ break;
98
+ case 'matrix':
99
+ case 'matrix3d':
100
+ transform.push({ [key]: parseValues(val, ',').map(val => +val) });
101
+ break;
102
+ case 'translate':
103
+ case 'scale':
104
+ case 'skew':
105
+ case 'rotate3d': // x y z angle
106
+ case 'translate3d': // x y 支持 z不支持
107
+ case 'scale3d': // x y 支持 z不支持
108
+ {
109
+ // 2 个以上的值处理
110
+ key = key.replace('3d', '');
111
+ const vals = parseValues(val, ',').splice(0, key === 'rotate' ? 4 : 3);
112
+ // scale(.5) === scaleX(.5) scaleY(.5)
113
+ if (vals.length === 1 && key === 'scale') {
114
+ vals.push(vals[0]);
115
+ }
116
+ const xyz = ['X', 'Y', 'Z'];
117
+ transform.push(...vals.map((v, index) => {
118
+ return { [`${key}${xyz[index] || ''}`]: global.__formatValue(v.trim()) };
119
+ }));
120
+ break;
121
+ }
122
+ }
123
+ }
124
+ });
125
+ return transform;
126
+ };
127
+ // format style
128
+ const formatStyle = (style) => {
129
+ if (!style.transform || Array.isArray(style.transform))
130
+ return style;
131
+ return Object.assign({}, style, {
132
+ transform: parseTransform(style.transform)
133
+ });
134
+ };
135
+ export default function useAnimationHooks(props) {
136
+ const { style = {}, animation, enableAnimation } = props;
137
+ const enableStyleAnimation = enableAnimation || !!animation;
138
+ const enableAnimationRef = useRef(enableStyleAnimation);
139
+ if (enableAnimationRef.current !== enableStyleAnimation) {
140
+ error('[Mpx runtime error]: animation use should be stable in the component lifecycle, or you can set [enable-animation] with true.');
141
+ }
142
+ if (!enableAnimationRef.current)
143
+ return { enableStyleAnimation: false };
144
+ const originalStyle = formatStyle(style);
145
+ // id 标识
146
+ const id = animation?.id || -1;
147
+ // 有动画样式的 style key
148
+ // eslint-disable-next-line react-hooks/rules-of-hooks
149
+ const animatedStyleKeys = useSharedValue([]);
150
+ // 记录动画key的style样式值 没有的话设置为false
151
+ // eslint-disable-next-line react-hooks/rules-of-hooks
152
+ const animatedKeys = useRef({});
153
+ // const animatedKeys = useRef({} as {[propName: keyof ExtendedViewStyle]: boolean|number|string})
154
+ // ** 全量 style prop sharedValue
155
+ // 不能做增量的原因:
156
+ // 1 尝试用 useRef,但 useAnimatedStyle 访问后的 ref 不能在增加新的值,被冻结
157
+ // 2 尝试用 useSharedValue,因为实际触发的 style prop 需要是 sharedValue 才能驱动动画,若外层 shareValMap 也是 sharedValue,动画无法驱动。
158
+ // eslint-disable-next-line react-hooks/rules-of-hooks
159
+ const shareValMap = useMemo(() => {
160
+ return Object.keys(InitialValue).reduce((valMap, key) => {
161
+ const defaultVal = getInitialVal(key, isTransform(key));
162
+ valMap[key] = makeMutable(defaultVal);
163
+ return valMap;
164
+ }, {});
165
+ }, []);
166
+ // ** 获取动画样式prop & 驱动动画
167
+ // eslint-disable-next-line react-hooks/rules-of-hooks
168
+ useEffect(() => {
169
+ if (id === -1)
170
+ return;
171
+ // 更新动画样式 key map
172
+ animatedKeys.current = getAnimatedStyleKeys();
173
+ const keys = Object.keys(animatedKeys.current);
174
+ animatedStyleKeys.value = formatAnimatedKeys([TransformOrigin, ...keys]);
175
+ // 驱动动画
176
+ createAnimation(keys);
177
+ }, [id]);
178
+ // 同步style更新
179
+ // useEffect(() => {
180
+ // Object.keys(animatedKeys.current).forEach(key => {
181
+ // const originVal = getOriginalStyleVal(key, isTransform(key))
182
+ // if (originVal && animatedKeys.current[key] !== originVal) {
183
+ // animatedKeys.current[key] = originVal
184
+ // shareValMap[key].value = originVal
185
+ // }
186
+ // })
187
+ // }, [style])
188
+ // ** 清空动画
189
+ // eslint-disable-next-line react-hooks/rules-of-hooks
190
+ useEffect(() => {
191
+ return () => {
192
+ Object.values(shareValMap).forEach((value) => {
193
+ cancelAnimation(value);
194
+ });
195
+ };
196
+ }, []);
197
+ // 根据 animation action 创建&驱动动画 key => wi
198
+ function createAnimation(animatedKeys = []) {
199
+ const actions = animation?.actions || [];
200
+ const sequence = {};
201
+ const lastValueMap = {};
202
+ actions.forEach(({ animatedOption, rules, transform }, index) => {
203
+ const { delay, duration, timingFunction, transformOrigin } = animatedOption;
204
+ const easing = EasingKey[timingFunction] || Easing.inOut(Easing.quad);
205
+ let needSetCallback = true;
206
+ const setTransformOrigin = (finished) => {
207
+ 'worklet';
208
+ // 动画结束后设置下一次transformOrigin
209
+ if (finished) {
210
+ if (index < actions.length - 1) {
211
+ const transformOrigin = actions[index + 1].animatedOption?.transformOrigin;
212
+ transformOrigin && (shareValMap[TransformOrigin].value = transformOrigin);
213
+ }
214
+ }
215
+ };
216
+ if (index === 0) {
217
+ // 设置当次中心
218
+ shareValMap[TransformOrigin].value = transformOrigin;
219
+ }
220
+ // 添加每个key的多次step动画
221
+ animatedKeys.forEach(key => {
222
+ const ruleV = isTransform(key) ? transform.get(key) : rules.get(key);
223
+ // key不存在,第一轮取shareValMap[key]value,非第一轮取上一轮的
224
+ const toVal = ruleV !== undefined
225
+ ? ruleV
226
+ : index > 0
227
+ ? lastValueMap[key]
228
+ : shareValMap[key].value;
229
+ const animation = getAnimation({ key, value: toVal }, { delay, duration, easing }, needSetCallback ? setTransformOrigin : undefined);
230
+ needSetCallback = false;
231
+ if (!sequence[key]) {
232
+ sequence[key] = [animation];
233
+ }
234
+ else {
235
+ sequence[key].push(animation);
236
+ }
237
+ // 更新一下 lastValueMap
238
+ lastValueMap[key] = toVal;
239
+ });
240
+ // 赋值驱动动画
241
+ animatedKeys.forEach((key) => {
242
+ const animations = sequence[key];
243
+ shareValMap[key].value = withSequence(...animations);
244
+ });
245
+ });
246
+ }
247
+ // 创建单个animation
248
+ function getAnimation({ key, value }, { delay, duration, easing }, callback) {
249
+ const animation = typeof callback === 'function'
250
+ ? withTiming(value, { duration, easing }, callback)
251
+ : withTiming(value, { duration, easing });
252
+ return delay ? withDelay(delay, animation) : animation;
253
+ }
254
+ function getInitialVal(key, isTransform = false) {
255
+ if (isTransform && Array.isArray(originalStyle.transform)) {
256
+ let initialVal = InitialValue[key];
257
+ // 仅支持 { transform: [{rotateX: '45deg'}, {rotateZ: '0.785398rad'}] } 格式的初始样式
258
+ originalStyle.transform.forEach(item => {
259
+ if (item[key] !== undefined)
260
+ initialVal = item[key];
261
+ });
262
+ return initialVal;
263
+ }
264
+ return originalStyle[key] === undefined ? InitialValue[key] : originalStyle[key];
265
+ }
266
+ // 从 prop style 中获取样式初始值 没有为undefined
267
+ // function getOriginalStyleVal (key: keyof ExtendedViewStyle, isTransform = false) {
268
+ // if (isTransform && Array.isArray(originalStyle.transform)) {
269
+ // let initialVal = undefined // InitialValue[key]
270
+ // // 仅支持 { transform: [{rotateX: '45deg'}, {rotateZ: '0.785398rad'}] } 格式的初始样式
271
+ // originalStyle.transform.forEach(item => {
272
+ // if (item[key] !== undefined) initialVal = item[key]
273
+ // })
274
+ // return initialVal
275
+ // }
276
+ // return originalStyle[key] // === undefined ? InitialValue[key] : originalStyle[key]
277
+ // }
278
+ // 获取动画shareVal初始值(prop style or 默认值)
279
+ // function getInitialVal (key: keyof ExtendedViewStyle, isTransform = false) {
280
+ // const originalVal = getOriginalStyleVal(key, isTransform)
281
+ // return originalVal === undefined ? InitialValue[key] : originalStyle[key]
282
+ // }
283
+ // 循环 animation actions 获取所有有动画的 style prop name
284
+ function getAnimatedStyleKeys() {
285
+ return (animation?.actions || []).reduce((keyMap, action) => {
286
+ const { rules, transform } = action;
287
+ const ruleArr = [...rules.keys(), ...transform.keys()];
288
+ ruleArr.forEach(key => {
289
+ // const originalVal = getOriginalStyleVal(key, isTransform(key))
290
+ // if (!keyMap[key]) keyMap[key] = originalVal === undefined ? false : originalVal
291
+ if (!keyMap[key])
292
+ keyMap[key] = true;
293
+ });
294
+ return keyMap;
295
+ }, animatedKeys.current);
296
+ }
297
+ // animated key transform 格式化
298
+ function formatAnimatedKeys(keys = []) {
299
+ const animatedKeys = [];
300
+ const transforms = [];
301
+ keys.forEach(key => {
302
+ if (isTransform(key)) {
303
+ transforms.push(key);
304
+ }
305
+ else {
306
+ animatedKeys.push(key);
307
+ }
308
+ });
309
+ if (transforms.length)
310
+ animatedKeys.push(transforms);
311
+ return animatedKeys;
312
+ }
313
+ // transform 数组转对象
314
+ function getTransformObj() {
315
+ 'worklet';
316
+ const transforms = originalStyle.transform || [];
317
+ return transforms.reduce((transformObj, item) => {
318
+ return Object.assign(transformObj, item);
319
+ }, {});
320
+ }
321
+ // ** 生成动画样式
322
+ // eslint-disable-next-line react-hooks/rules-of-hooks
323
+ const animationStyle = useAnimatedStyle(() => {
324
+ // console.info(`useAnimatedStyle styles=`, originalStyle)
325
+ return animatedStyleKeys.value.reduce((styles, key) => {
326
+ // console.info('getAnimationStyles', key, shareValMap[key].value)
327
+ if (Array.isArray(key)) {
328
+ const transformStyle = getTransformObj();
329
+ key.forEach((transformKey) => {
330
+ transformStyle[transformKey] = shareValMap[transformKey].value;
331
+ });
332
+ styles.transform = Object.entries(transformStyle).map(([key, value]) => {
333
+ return { [key]: value };
334
+ });
335
+ }
336
+ else {
337
+ styles[key] = shareValMap[key].value;
338
+ }
339
+ return styles;
340
+ }, {});
341
+ });
342
+ return {
343
+ enableStyleAnimation: enableAnimationRef.current,
344
+ animationStyle
345
+ };
346
+ }
@@ -0,0 +1,16 @@
1
+ import { useRef, useImperativeHandle } from 'react';
2
+ export default function useNodesRef(props, ref, nodeRef, instance = {}) {
3
+ const _props = useRef(null);
4
+ _props.current = props;
5
+ useImperativeHandle(ref, () => {
6
+ return {
7
+ getNodeInstance() {
8
+ return {
9
+ props: _props,
10
+ nodeRef,
11
+ instance
12
+ };
13
+ }
14
+ };
15
+ });
16
+ }