@mpxjs/webpack-plugin 2.10.6-beta.3 → 2.10.6-beta.4

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.
@@ -237,6 +237,88 @@ function transformPosition(styleObj, meta) {
237
237
  meta.hasPositionFixed = true;
238
238
  }
239
239
  }
240
+ // 多value解析
241
+ function parseValues(str, char = ' ') {
242
+ let stack = 0;
243
+ let temp = '';
244
+ const result = [];
245
+ for (let i = 0; i < str.length; i++) {
246
+ if (str[i] === '(') {
247
+ stack++;
248
+ }
249
+ else if (str[i] === ')') {
250
+ stack--;
251
+ }
252
+ // 非括号内 或者 非分隔字符且非空
253
+ if (stack !== 0 || (str[i] !== char && str[i] !== ' ')) {
254
+ temp += str[i];
255
+ }
256
+ if ((stack === 0 && str[i] === char) || i === str.length - 1) {
257
+ result.push(temp);
258
+ temp = '';
259
+ }
260
+ }
261
+ return result;
262
+ }
263
+ // parse string transform, eg: transform: 'rotateX(45deg) rotateZ(0.785398rad)'
264
+ function parseTransform(transformStr) {
265
+ const values = parseValues(transformStr);
266
+ const transform = [];
267
+ values.forEach(item => {
268
+ const match = item.match(/([/\w]+)\((.+)\)/);
269
+ if (match && match.length >= 3) {
270
+ let key = match[1];
271
+ const val = match[2];
272
+ switch (key) {
273
+ case 'translateX':
274
+ case 'translateY':
275
+ case 'scaleX':
276
+ case 'scaleY':
277
+ case 'rotateX':
278
+ case 'rotateY':
279
+ case 'rotateZ':
280
+ case 'rotate':
281
+ case 'skewX':
282
+ case 'skewY':
283
+ case 'perspective':
284
+ // rotate 处理成 rotateZ
285
+ key = key === 'rotate' ? 'rotateZ' : key;
286
+ // 单个值处理
287
+ transform.push({ [key]: global.__formatValue(val) });
288
+ break;
289
+ case 'matrix':
290
+ transform.push({ [key]: parseValues(val, ',').map(val => +val) });
291
+ break;
292
+ case 'translate':
293
+ case 'scale':
294
+ case 'skew':
295
+ case 'translate3d': // x y 支持 z不支持
296
+ case 'scale3d': // x y 支持 z不支持
297
+ {
298
+ // 2 个以上的值处理
299
+ key = key.replace('3d', '');
300
+ const vals = parseValues(val, ',').splice(0, 3);
301
+ // scale(.5) === scaleX(.5) scaleY(.5)
302
+ if (vals.length === 1 && key === 'scale') {
303
+ vals.push(vals[0]);
304
+ }
305
+ const xyz = ['X', 'Y', 'Z'];
306
+ transform.push(...vals.map((v, index) => {
307
+ return { [`${key}${xyz[index] || ''}`]: global.__formatValue(v.trim()) };
308
+ }));
309
+ break;
310
+ }
311
+ }
312
+ }
313
+ });
314
+ return transform;
315
+ }
316
+ // format style transform
317
+ function transformTransform(style) {
318
+ if (!style.transform || Array.isArray(style.transform))
319
+ return;
320
+ style.transform = parseTransform(style.transform);
321
+ }
240
322
  export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight }) {
241
323
  const varStyle = {};
242
324
  const unoVarStyle = {};
@@ -365,6 +447,8 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
365
447
  transformPosition(normalStyle, positionMeta);
366
448
  // transform number enum stringify
367
449
  transformStringify(normalStyle);
450
+ // transform 字符串格式转化数组格式
451
+ transformTransform(normalStyle);
368
452
  return {
369
453
  hasVarDec,
370
454
  varContextRef,
@@ -766,13 +766,6 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
766
766
  const eventData = {
767
767
  translation: moveDistance
768
768
  }
769
- if (childrenLength.value === 1) {
770
- return handleBackInit()
771
- }
772
- // 用户手指按下起来, 需要计算正确的位置, 比如在滑动过程中突然按下然后起来,需要计算到正确的位置
773
- if (!circularShared.value && !canMove(eventData)) {
774
- return
775
- }
776
769
  const strVelocity = moveDistance / (new Date().getTime() - moveTime.value) * 1000
777
770
  if (Math.abs(strVelocity) < longPressRatio) {
778
771
  handleLongPress()
@@ -84,88 +84,6 @@ const InitialValue: ExtendedViewStyle = Object.assign({
84
84
  const TransformOrigin = 'transformOrigin'
85
85
  // transform
86
86
  const isTransform = (key: string) => Object.keys(TransformInitial).includes(key)
87
- // 多value解析
88
- const parseValues = (str: string, char = ' ') => {
89
- let stack = 0
90
- let temp = ''
91
- const result = []
92
- for (let i = 0; i < str.length; i++) {
93
- if (str[i] === '(') {
94
- stack++
95
- } else if (str[i] === ')') {
96
- stack--
97
- }
98
- // 非括号内 或者 非分隔字符且非空
99
- if (stack !== 0 || (str[i] !== char && str[i] !== ' ')) {
100
- temp += str[i]
101
- }
102
- if ((stack === 0 && str[i] === char) || i === str.length - 1) {
103
- result.push(temp)
104
- temp = ''
105
- }
106
- }
107
- return result
108
- }
109
- // parse string transform, eg: transform: 'rotateX(45deg) rotateZ(0.785398rad)'
110
- const parseTransform = (transformStr: string) => {
111
- const values = parseValues(transformStr)
112
- const transform: {[propName: string]: string|number|number[]}[] = []
113
- values.forEach(item => {
114
- const match = item.match(/([/\w]+)\((.+)\)/)
115
- if (match && match.length >= 3) {
116
- let key = match[1]
117
- const val = match[2]
118
- switch (key) {
119
- case 'translateX':
120
- case 'translateY':
121
- case 'scaleX':
122
- case 'scaleY':
123
- case 'rotateX':
124
- case 'rotateY':
125
- case 'rotateZ':
126
- case 'rotate':
127
- case 'skewX':
128
- case 'skewY':
129
- case 'perspective':
130
- // rotate 处理成 rotateZ
131
- key = key === 'rotate' ? 'rotateZ' : key
132
- // 单个值处理
133
- transform.push({ [key]: global.__formatValue(val) })
134
- break
135
- case 'matrix':
136
- transform.push({ [key]: parseValues(val, ',').map(val => +val) })
137
- break
138
- case 'translate':
139
- case 'scale':
140
- case 'skew':
141
- case 'translate3d': // x y 支持 z不支持
142
- case 'scale3d': // x y 支持 z不支持
143
- {
144
- // 2 个以上的值处理
145
- key = key.replace('3d', '')
146
- const vals = parseValues(val, ',').splice(0, 3)
147
- // scale(.5) === scaleX(.5) scaleY(.5)
148
- if (vals.length === 1 && key === 'scale') {
149
- vals.push(vals[0])
150
- }
151
- const xyz = ['X', 'Y', 'Z']
152
- transform.push(...vals.map((v, index) => {
153
- return { [`${key}${xyz[index] || ''}`]: global.__formatValue(v.trim()) }
154
- }))
155
- break
156
- }
157
- }
158
- }
159
- })
160
- return transform
161
- }
162
- // format style
163
- const formatStyle = (style: ExtendedViewStyle): ExtendedViewStyle => {
164
- if (!style.transform || Array.isArray(style.transform)) return style
165
- return Object.assign({}, style, {
166
- transform: parseTransform(style.transform)
167
- })
168
- }
169
87
 
170
88
  // transform 数组转对象
171
89
  function getTransformObj (transforms: { [propName: string]: string | number }[]) {
@@ -176,7 +94,7 @@ function getTransformObj (transforms: { [propName: string]: string | number }[])
176
94
  }
177
95
 
178
96
  export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAnimation?: boolean, layoutRef: MutableRefObject<any>, transitionend?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void }) {
179
- const { style = {}, animation, enableAnimation, transitionend, layoutRef } = props
97
+ const { style: originalStyle = {}, animation, enableAnimation, transitionend, layoutRef } = props
180
98
  const enableStyleAnimation = enableAnimation || !!animation
181
99
  const enableAnimationRef = useRef(enableStyleAnimation)
182
100
  if (enableAnimationRef.current !== enableStyleAnimation) {
@@ -185,7 +103,6 @@ export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAni
185
103
 
186
104
  if (!enableAnimationRef.current) return { enableStyleAnimation: false }
187
105
 
188
- const originalStyle = formatStyle(style)
189
106
  // id 标识
190
107
  const id = animation?.id || -1
191
108
  // 有动画样式的 style key
@@ -214,7 +131,7 @@ export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAni
214
131
  useEffect(() => {
215
132
  // style 更新后同步更新 lastStyleRef & shareValMap
216
133
  updateStyleVal()
217
- }, [style])
134
+ }, [originalStyle])
218
135
  // ** 获取动画样式prop & 驱动动画
219
136
  // eslint-disable-next-line react-hooks/rules-of-hooks
220
137
  useEffect(() => {
@@ -285,7 +285,86 @@ function transformPosition (styleObj: Record<string, any>, meta: PositionMeta) {
285
285
  meta.hasPositionFixed = true
286
286
  }
287
287
  }
288
-
288
+ // 多value解析
289
+ function parseValues (str: string, char = ' ') {
290
+ let stack = 0
291
+ let temp = ''
292
+ const result = []
293
+ for (let i = 0; i < str.length; i++) {
294
+ if (str[i] === '(') {
295
+ stack++
296
+ } else if (str[i] === ')') {
297
+ stack--
298
+ }
299
+ // 非括号内 或者 非分隔字符且非空
300
+ if (stack !== 0 || (str[i] !== char && str[i] !== ' ')) {
301
+ temp += str[i]
302
+ }
303
+ if ((stack === 0 && str[i] === char) || i === str.length - 1) {
304
+ result.push(temp)
305
+ temp = ''
306
+ }
307
+ }
308
+ return result
309
+ }
310
+ // parse string transform, eg: transform: 'rotateX(45deg) rotateZ(0.785398rad)'
311
+ function parseTransform (transformStr: string) {
312
+ const values = parseValues(transformStr)
313
+ const transform: {[propName: string]: string|number|number[]}[] = []
314
+ values.forEach(item => {
315
+ const match = item.match(/([/\w]+)\((.+)\)/)
316
+ if (match && match.length >= 3) {
317
+ let key = match[1]
318
+ const val = match[2]
319
+ switch (key) {
320
+ case 'translateX':
321
+ case 'translateY':
322
+ case 'scaleX':
323
+ case 'scaleY':
324
+ case 'rotateX':
325
+ case 'rotateY':
326
+ case 'rotateZ':
327
+ case 'rotate':
328
+ case 'skewX':
329
+ case 'skewY':
330
+ case 'perspective':
331
+ // rotate 处理成 rotateZ
332
+ key = key === 'rotate' ? 'rotateZ' : key
333
+ // 单个值处理
334
+ transform.push({ [key]: global.__formatValue(val) })
335
+ break
336
+ case 'matrix':
337
+ transform.push({ [key]: parseValues(val, ',').map(val => +val) })
338
+ break
339
+ case 'translate':
340
+ case 'scale':
341
+ case 'skew':
342
+ case 'translate3d': // x y 支持 z不支持
343
+ case 'scale3d': // x y 支持 z不支持
344
+ {
345
+ // 2 个以上的值处理
346
+ key = key.replace('3d', '')
347
+ const vals = parseValues(val, ',').splice(0, 3)
348
+ // scale(.5) === scaleX(.5) scaleY(.5)
349
+ if (vals.length === 1 && key === 'scale') {
350
+ vals.push(vals[0])
351
+ }
352
+ const xyz = ['X', 'Y', 'Z']
353
+ transform.push(...vals.map((v, index) => {
354
+ return { [`${key}${xyz[index] || ''}`]: global.__formatValue(v.trim()) }
355
+ }))
356
+ break
357
+ }
358
+ }
359
+ }
360
+ })
361
+ return transform
362
+ }
363
+ // format style transform
364
+ function transformTransform (style: Record<string, any>) {
365
+ if (!style.transform || Array.isArray(style.transform)) return
366
+ style.transform = parseTransform(style.transform)
367
+ }
289
368
  interface TransformStyleConfig {
290
369
  enableVar?: boolean
291
370
  externalVarContext?: Record<string, any>
@@ -428,6 +507,9 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
428
507
  // transform number enum stringify
429
508
  transformStringify(normalStyle)
430
509
 
510
+ // transform 字符串格式转化数组格式
511
+ transformTransform(normalStyle)
512
+
431
513
  return {
432
514
  hasVarDec,
433
515
  varContextRef,
@@ -180,7 +180,7 @@ const i18nModuleName = '_i'
180
180
  const stringifyWxsPath = '~' + normalize.lib('runtime/stringify.wxs')
181
181
  const stringifyModuleName = '_s'
182
182
  const optionalChainWxsPath = '~' + normalize.lib('runtime/oc.wxs')
183
- const optionalChainWxsName = '_o'
183
+ const optionalChainWxsName = '_oc' // 改成_oc解决web下_o重名问题
184
184
 
185
185
  const tagRES = /(\{\{(?:.|\n|\r)+?\}\})(?!})/
186
186
  const tagRE = /\{\{((?:.|\n|\r)+?)\}\}(?!})/
@@ -2725,8 +2725,8 @@ function processElement (el, root, options, meta) {
2725
2725
  processIf(el)
2726
2726
  processFor(el)
2727
2727
  processRefReact(el, meta)
2728
- processStyleReact(el, options)
2729
2728
  if (!pass) {
2729
+ processStyleReact(el, options)
2730
2730
  processEventReact(el, options)
2731
2731
  processComponentGenerics(el, meta)
2732
2732
  processComponentIs(el, options)
@@ -72,7 +72,7 @@ const isNativeMiniTag = makeMap(
72
72
  * 是否为mpx内置组件
73
73
  * collected from packages/webpack-plugin/lib/runtime/components/web/
74
74
  */
75
- const isBuildInTag = makeMap(
75
+ const isBuildInWebTag = makeMap(
76
76
  'mpx-image,mpx-picker-view,mpx-slider,mpx-textarea,mpx-input,mpx-picker,' +
77
77
  'mpx-swiper-item,mpx-video,mpx-button,mpx-keep-alive,mpx-progress,' +
78
78
  'mpx-swiper,mpx-view,mpx-checkbox-group,mpx-movable-area,mpx-radio-group,' +
@@ -118,7 +118,7 @@ module.exports = {
118
118
  isVoidTag,
119
119
  isNonPhrasingTag,
120
120
  isRichTextTag,
121
- isBuildInTag,
121
+ isBuildInWebTag,
122
122
  isUnaryTag,
123
123
  isSpace,
124
124
  isContWidth,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.6-beta.3",
3
+ "version": "2.10.6-beta.4",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"