@mpxjs/webpack-plugin 2.9.70-alpha.0 → 2.9.70

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 (99) hide show
  1. package/LICENSE +433 -0
  2. package/README.md +1 -1
  3. package/lib/config.js +0 -14
  4. package/lib/dependencies/ResolveDependency.js +0 -5
  5. package/lib/index.js +7 -38
  6. package/lib/json-compiler/helper.js +3 -3
  7. package/lib/loader.js +0 -53
  8. package/lib/parser.js +1 -1
  9. package/lib/platform/json/wx/index.js +21 -8
  10. package/lib/platform/style/wx/index.js +51 -54
  11. package/lib/platform/template/wx/component-config/button.js +2 -14
  12. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  13. package/lib/platform/template/wx/component-config/image.js +0 -4
  14. package/lib/platform/template/wx/component-config/index.js +1 -1
  15. package/lib/platform/template/wx/component-config/input.js +0 -4
  16. package/lib/platform/template/wx/component-config/rich-text.js +6 -2
  17. package/lib/platform/template/wx/component-config/scroll-view.js +0 -4
  18. package/lib/platform/template/wx/component-config/switch.js +0 -4
  19. package/lib/platform/template/wx/component-config/text.js +0 -4
  20. package/lib/platform/template/wx/component-config/textarea.js +0 -5
  21. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  22. package/lib/platform/template/wx/component-config/view.js +0 -4
  23. package/lib/platform/template/wx/index.js +1 -127
  24. package/lib/resolve-loader.js +1 -4
  25. package/lib/runtime/components/react/dist/getInnerListeners.js +5 -6
  26. package/lib/runtime/components/react/dist/mpx-canvas/html.js +2 -4
  27. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +5 -1
  28. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +96 -107
  29. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +26 -27
  30. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +480 -0
  31. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +68 -0
  32. package/lib/runtime/components/react/dist/mpx-swiper/type.js +1 -0
  33. package/lib/runtime/components/react/dist/mpx-view.jsx +6 -3
  34. package/lib/runtime/components/react/dist/pickerFaces.js +6 -12
  35. package/lib/runtime/components/react/dist/{pickerViewOverlay.jsx → pickerOverlay.jsx} +3 -5
  36. package/lib/runtime/components/react/dist/useAnimationHooks.js +7 -8
  37. package/lib/runtime/components/react/dist/utils.jsx +89 -60
  38. package/lib/runtime/components/react/event.config.ts +25 -26
  39. package/lib/runtime/components/react/getInnerListeners.ts +212 -169
  40. package/lib/runtime/components/react/mpx-button.tsx +9 -14
  41. package/lib/runtime/components/react/mpx-canvas/html.ts +2 -4
  42. package/lib/runtime/components/react/mpx-canvas/index.tsx +44 -46
  43. package/lib/runtime/components/react/mpx-checkbox-group.tsx +15 -13
  44. package/lib/runtime/components/react/mpx-checkbox.tsx +20 -21
  45. package/lib/runtime/components/react/mpx-form.tsx +15 -20
  46. package/lib/runtime/components/react/mpx-icon.tsx +2 -2
  47. package/lib/runtime/components/react/mpx-image.tsx +87 -47
  48. package/lib/runtime/components/react/mpx-input.tsx +24 -32
  49. package/lib/runtime/components/react/mpx-label.tsx +12 -14
  50. package/lib/runtime/components/react/mpx-movable-area.tsx +10 -16
  51. package/lib/runtime/components/react/mpx-movable-view.tsx +20 -24
  52. package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
  53. package/lib/runtime/components/react/mpx-radio-group.tsx +13 -15
  54. package/lib/runtime/components/react/mpx-radio.tsx +19 -25
  55. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  56. package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
  57. package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
  58. package/lib/runtime/components/react/mpx-scroll-view.tsx +40 -41
  59. package/lib/runtime/components/react/mpx-switch.tsx +19 -15
  60. package/lib/runtime/components/react/mpx-text.tsx +8 -16
  61. package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
  62. package/lib/runtime/components/react/mpx-view.tsx +18 -20
  63. package/lib/runtime/components/react/mpx-web-view.tsx +94 -59
  64. package/lib/runtime/components/react/types/global.d.ts +2 -1
  65. package/lib/runtime/components/react/useAnimationHooks.ts +36 -12
  66. package/lib/runtime/components/react/utils.tsx +91 -60
  67. package/lib/runtime/components/web/mpx-web-view.vue +34 -20
  68. package/lib/runtime/optionProcessor.js +0 -22
  69. package/lib/style-compiler/index.js +1 -1
  70. package/lib/style-compiler/plugins/scope-id.js +30 -2
  71. package/lib/template-compiler/compiler.js +30 -26
  72. package/lib/utils/env.js +1 -6
  73. package/lib/utils/pre-process-json.js +9 -5
  74. package/package.json +4 -7
  75. package/lib/dependencies/AddEntryDependency.js +0 -24
  76. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +0 -39
  77. package/lib/runtime/components/react/dist/mpx-swiper.jsx +0 -606
  78. package/lib/runtime/components/react/dist/pickerVIewContext.js +0 -9
  79. package/lib/runtime/components/react/dist/pickerViewMask.jsx +0 -18
  80. package/lib/runtime/components/tenon/getInnerListeners.js +0 -334
  81. package/lib/runtime/components/tenon/tenon-button.vue +0 -309
  82. package/lib/runtime/components/tenon/tenon-image.vue +0 -66
  83. package/lib/runtime/components/tenon/tenon-input.vue +0 -171
  84. package/lib/runtime/components/tenon/tenon-rich-text.vue +0 -26
  85. package/lib/runtime/components/tenon/tenon-scroll-view.vue +0 -127
  86. package/lib/runtime/components/tenon/tenon-switch.vue +0 -96
  87. package/lib/runtime/components/tenon/tenon-text.vue +0 -70
  88. package/lib/runtime/components/tenon/tenon-textarea.vue +0 -86
  89. package/lib/runtime/components/tenon/tenon-view.vue +0 -93
  90. package/lib/runtime/components/web/event.js +0 -105
  91. package/lib/runtime/optionProcessor.tenon.js +0 -84
  92. package/lib/style-compiler/plugins/hm.js +0 -20
  93. package/lib/tenon/index.js +0 -117
  94. package/lib/tenon/processJSON.js +0 -352
  95. package/lib/tenon/processScript.js +0 -203
  96. package/lib/tenon/processStyles.js +0 -21
  97. package/lib/tenon/processTemplate.js +0 -126
  98. package/lib/tenon/script-helper.js +0 -223
  99. package/lib/utils/get-relative-path.js +0 -25
@@ -75,7 +75,7 @@ const parseTransform = (transformStr) => {
75
75
  const values = parseValues(transformStr);
76
76
  const transform = [];
77
77
  values.forEach(item => {
78
- const match = item.match(/([/\w]+)\(([^)]+)\)/);
78
+ const match = item.match(/([/\w]+)\((.+)\)/);
79
79
  if (match && match.length >= 3) {
80
80
  let key = match[1];
81
81
  const val = match[2];
@@ -206,14 +206,13 @@ export default function useAnimationHooks(props) {
206
206
  }
207
207
  // 添加每个key的多次step动画
208
208
  animatedKeys.forEach(key => {
209
+ const ruleV = isTransform(key) ? transform.get(key) : rules.get(key);
209
210
  // key不存在,第一轮取shareValMap[key]value,非第一轮取上一轮的
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;
211
+ const toVal = ruleV !== undefined
212
+ ? ruleV
213
+ : index > 0
214
+ ? lastValueMap[key]
215
+ : shareValMap[key].value;
217
216
  const animation = getAnimation({ key, value: toVal }, { delay, duration, easing }, needSetCallback ? setTransformOrigin : undefined);
218
217
  needSetCallback = false;
219
218
  if (!sequence[key]) {
@@ -15,8 +15,10 @@ export const DEFAULT_FONT_SIZE = 16;
15
15
  export const HIDDEN_STYLE = {
16
16
  opacity: 0
17
17
  };
18
- const varDecRegExp = /^--.*/;
18
+ const varDecRegExp = /^--/;
19
19
  const varUseRegExp = /var\(/;
20
+ const unoVarDecRegExp = /^--un-/;
21
+ const unoVarUseRegExp = /var\(--un-/;
20
22
  const calcUseRegExp = /calc\(/;
21
23
  const envUseRegExp = /env\(/;
22
24
  const safeAreaInsetMap = {
@@ -31,7 +33,7 @@ function getSafeAreaInset(name) {
31
33
  return insets[safeAreaInsetMap[name]];
32
34
  }
33
35
  export function omit(obj, fields) {
34
- const shallowCopy = Object.assign({}, obj);
36
+ const shallowCopy = extendObject({}, obj);
35
37
  for (let i = 0; i < fields.length; i += 1) {
36
38
  const key = fields[i];
37
39
  delete shallowCopy[key];
@@ -69,7 +71,7 @@ export const parseInlineStyle = (inlineStyle = '') => {
69
71
  if (rest.length || !v || !k)
70
72
  return styleObj;
71
73
  const key = k.trim().replace(/-./g, c => c.substring(1).toUpperCase());
72
- return Object.assign(styleObj, { [key]: global.__formatValue(v.trim()) });
74
+ return extendObject(styleObj, { [key]: global.__formatValue(v.trim()) });
73
75
  }, {});
74
76
  };
75
77
  export const parseUrl = (cssUrl = '') => {
@@ -238,11 +240,15 @@ function transformStringify(styleObj) {
238
240
  }
239
241
  export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight }) {
240
242
  const varStyle = {};
243
+ const unoVarStyle = {};
241
244
  const normalStyle = {};
245
+ const normalStyleRef = useRef({});
246
+ const normalStyleChangedRef = useRef(false);
242
247
  let hasVarDec = false;
243
248
  let hasVarUse = false;
244
249
  let hasSelfPercent = false;
245
250
  const varKeyPaths = [];
251
+ const unoVarKeyPaths = [];
246
252
  const percentKeyPaths = [];
247
253
  const calcKeyPaths = [];
248
254
  const envKeyPaths = [];
@@ -250,7 +256,10 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
250
256
  const [height, setHeight] = useState(0);
251
257
  function varVisitor({ key, value, keyPath }) {
252
258
  if (keyPath.length === 1) {
253
- if (varDecRegExp.test(key)) {
259
+ if (unoVarDecRegExp.test(key)) {
260
+ unoVarStyle[key] = value;
261
+ }
262
+ else if (varDecRegExp.test(key)) {
254
263
  hasVarDec = true;
255
264
  varStyle[key] = value;
256
265
  }
@@ -260,12 +269,18 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
260
269
  }
261
270
  }
262
271
  // 对于var定义中使用的var无需替换值,可以通过resolveVar递归解析出值
263
- if (!varDecRegExp.test(key) && varUseRegExp.test(value)) {
264
- hasVarUse = true;
265
- varKeyPaths.push(keyPath.slice());
272
+ if (!varDecRegExp.test(key)) {
273
+ // 一般情况下一个样式属性中不会混用unocss var和普通css var,可分开进行互斥处理
274
+ if (unoVarUseRegExp.test(value)) {
275
+ unoVarKeyPaths.push(keyPath.slice());
276
+ }
277
+ else if (varUseRegExp.test(value)) {
278
+ hasVarUse = true;
279
+ varKeyPaths.push(keyPath.slice());
280
+ }
266
281
  }
267
282
  }
268
- // traverse var
283
+ // traverse var & generate normalStyle
269
284
  traverseStyle(styleObj, [varVisitor]);
270
285
  hasVarDec = hasVarDec || !!externalVarContext;
271
286
  enableVar = enableVar || hasVarDec || hasVarUse;
@@ -273,78 +288,92 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
273
288
  if (enableVarRef.current !== enableVar) {
274
289
  error('css variable use/declare should be stable in the component lifecycle, or you can set [enable-var] with true.');
275
290
  }
276
- // apply var
291
+ // apply css var
277
292
  const varContextRef = useRef({});
278
293
  if (enableVarRef.current) {
294
+ // eslint-disable-next-line react-hooks/rules-of-hooks
279
295
  const varContext = useContext(VarContext);
280
- const newVarContext = Object.assign({}, varContext, externalVarContext, varStyle);
296
+ const newVarContext = extendObject({}, varContext, externalVarContext, varStyle);
281
297
  // 缓存比较newVarContext是否发生变化
282
298
  if (diffAndCloneA(varContextRef.current, newVarContext).diff) {
283
299
  varContextRef.current = newVarContext;
284
300
  }
285
301
  transformVar(normalStyle, varKeyPaths, varContextRef.current);
286
302
  }
287
- function envVisitor({ value, keyPath }) {
288
- if (envUseRegExp.test(value)) {
289
- envKeyPaths.push(keyPath.slice());
290
- }
303
+ // apply unocss var
304
+ if (unoVarKeyPaths.length) {
305
+ transformVar(normalStyle, unoVarKeyPaths, unoVarStyle);
291
306
  }
292
- function calcVisitor({ value, keyPath }) {
293
- if (calcUseRegExp.test(value)) {
294
- calcKeyPaths.push(keyPath.slice());
295
- }
307
+ const { clone, diff } = diffAndCloneA(normalStyle, normalStyleRef.current);
308
+ if (diff) {
309
+ normalStyleRef.current = clone;
310
+ normalStyleChangedRef.current = !normalStyleChangedRef.current;
296
311
  }
297
- function percentVisitor({ key, value, keyPath }) {
298
- if (hasOwn(selfPercentRule, key) && PERCENT_REGEX.test(value)) {
299
- hasSelfPercent = true;
300
- percentKeyPaths.push(keyPath.slice());
312
+ const memoResult = useMemo(() => {
313
+ // transform can be memoized
314
+ function envVisitor({ value, keyPath }) {
315
+ if (envUseRegExp.test(value)) {
316
+ envKeyPaths.push(keyPath.slice());
317
+ }
301
318
  }
302
- else if ((key === 'fontSize' || key === 'lineHeight') && PERCENT_REGEX.test(value)) {
303
- percentKeyPaths.push(keyPath.slice());
319
+ function calcVisitor({ value, keyPath }) {
320
+ if (calcUseRegExp.test(value)) {
321
+ calcKeyPaths.push(keyPath.slice());
322
+ }
304
323
  }
305
- }
306
- // traverse env & calc & percent
307
- traverseStyle(normalStyle, [envVisitor, percentVisitor, calcVisitor]);
308
- const percentConfig = {
309
- width,
310
- height,
311
- fontSize: normalStyle.fontSize,
312
- parentWidth,
313
- parentHeight,
314
- parentFontSize
315
- };
316
- // apply env
317
- transformEnv(normalStyle, envKeyPaths);
318
- // apply percent
319
- transformPercent(normalStyle, percentKeyPaths, percentConfig);
320
- // apply calc
321
- transformCalc(normalStyle, calcKeyPaths, (value, key) => {
322
- if (PERCENT_REGEX.test(value)) {
323
- const resolved = resolvePercent(value, key, percentConfig);
324
- return typeof resolved === 'number' ? resolved : 0;
324
+ function percentVisitor({ key, value, keyPath }) {
325
+ if (hasOwn(selfPercentRule, key) && PERCENT_REGEX.test(value)) {
326
+ hasSelfPercent = true;
327
+ percentKeyPaths.push(keyPath.slice());
328
+ }
329
+ else if ((key === 'fontSize' || key === 'lineHeight') && PERCENT_REGEX.test(value)) {
330
+ percentKeyPaths.push(keyPath.slice());
331
+ }
325
332
  }
326
- else {
327
- const formatted = global.__formatValue(value);
328
- if (typeof formatted === 'number') {
329
- return formatted;
333
+ // traverse env & calc & percent
334
+ traverseStyle(normalStyle, [envVisitor, percentVisitor, calcVisitor]);
335
+ const percentConfig = {
336
+ width,
337
+ height,
338
+ fontSize: normalStyle.fontSize,
339
+ parentWidth,
340
+ parentHeight,
341
+ parentFontSize
342
+ };
343
+ // apply env
344
+ transformEnv(normalStyle, envKeyPaths);
345
+ // apply percent
346
+ transformPercent(normalStyle, percentKeyPaths, percentConfig);
347
+ // apply calc
348
+ transformCalc(normalStyle, calcKeyPaths, (value, key) => {
349
+ if (PERCENT_REGEX.test(value)) {
350
+ const resolved = resolvePercent(value, key, percentConfig);
351
+ return typeof resolved === 'number' ? resolved : 0;
330
352
  }
331
353
  else {
332
- warn('calc() only support number, px, rpx, % temporarily.');
333
- return 0;
354
+ const formatted = global.__formatValue(value);
355
+ if (typeof formatted === 'number') {
356
+ return formatted;
357
+ }
358
+ else {
359
+ warn('calc() only support number, px, rpx, % temporarily.');
360
+ return 0;
361
+ }
334
362
  }
335
- }
336
- });
337
- // transform number enum stringify
338
- transformStringify(normalStyle);
339
- return {
340
- normalStyle,
341
- hasSelfPercent,
363
+ });
364
+ // transform number enum stringify
365
+ transformStringify(normalStyle);
366
+ return {
367
+ normalStyle,
368
+ hasSelfPercent
369
+ };
370
+ }, [normalStyleChangedRef.current, width, height, parentWidth, parentHeight, parentFontSize]);
371
+ return extendObject({
342
372
  hasVarDec,
343
- enableVarRef,
344
373
  varContextRef,
345
374
  setWidth,
346
375
  setHeight
347
- };
376
+ }, memoResult);
348
377
  }
349
378
  export function traverseStyle(styleObj, visitors) {
350
379
  const keyPath = [];
@@ -467,7 +496,7 @@ export const useStableCallback = (callback) => {
467
496
  return useCallback((...args) => ref.current?.(...args), []);
468
497
  };
469
498
  export const usePrevious = (value) => {
470
- const ref = useRef(undefined);
499
+ const ref = useRef();
471
500
  const prev = ref.current;
472
501
  ref.current = value;
473
502
  return prev;
@@ -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