@mpxjs/webpack-plugin 2.10.17-beta.2 → 2.10.17-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.
Files changed (98) hide show
  1. package/lib/config.js +60 -0
  2. package/lib/file-loader.js +4 -1
  3. package/lib/global.d.ts +16 -0
  4. package/lib/index.js +22 -2
  5. package/lib/json-compiler/index.js +13 -4
  6. package/lib/platform/json/wx/index.js +6 -0
  7. package/lib/platform/style/wx/index.js +57 -33
  8. package/lib/platform/template/wx/component-config/ad.js +5 -0
  9. package/lib/platform/template/wx/component-config/button.js +9 -2
  10. package/lib/platform/template/wx/component-config/camera.js +25 -3
  11. package/lib/platform/template/wx/component-config/canvas.js +8 -1
  12. package/lib/platform/template/wx/component-config/cover-image.js +7 -2
  13. package/lib/platform/template/wx/component-config/cover-view.js +3 -1
  14. package/lib/platform/template/wx/component-config/form.js +27 -2
  15. package/lib/platform/template/wx/component-config/image.js +5 -0
  16. package/lib/platform/template/wx/component-config/input.js +10 -0
  17. package/lib/platform/template/wx/component-config/label.js +10 -2
  18. package/lib/platform/template/wx/component-config/map.js +11 -0
  19. package/lib/platform/template/wx/component-config/movable-area.js +4 -1
  20. package/lib/platform/template/wx/component-config/movable-view.js +17 -2
  21. package/lib/platform/template/wx/component-config/navigator.js +26 -0
  22. package/lib/platform/template/wx/component-config/picker-view.js +12 -0
  23. package/lib/platform/template/wx/component-config/picker.js +3 -1
  24. package/lib/platform/template/wx/component-config/progress.js +11 -1
  25. package/lib/platform/template/wx/component-config/rich-text.js +5 -0
  26. package/lib/platform/template/wx/component-config/scroll-view.js +12 -1
  27. package/lib/platform/template/wx/component-config/slider.js +8 -0
  28. package/lib/platform/template/wx/component-config/swiper-item.js +5 -2
  29. package/lib/platform/template/wx/component-config/swiper.js +10 -0
  30. package/lib/platform/template/wx/component-config/text.js +5 -0
  31. package/lib/platform/template/wx/component-config/textarea.js +19 -2
  32. package/lib/platform/template/wx/component-config/unsupported.js +10 -1
  33. package/lib/platform/template/wx/component-config/video.js +10 -0
  34. package/lib/platform/template/wx/index.js +21 -1
  35. package/lib/react/LoadAsyncChunkModule.js +1 -1
  36. package/lib/react/processStyles.js +21 -9
  37. package/lib/react/style-helper.js +76 -13
  38. package/lib/resolver/AddModePlugin.js +23 -8
  39. package/lib/runtime/components/react/animationHooks/index.ts +75 -0
  40. package/lib/runtime/components/react/animationHooks/useAnimationAPIHooks.ts +198 -0
  41. package/lib/runtime/components/react/animationHooks/useTransitionHooks.ts +297 -0
  42. package/lib/runtime/components/react/animationHooks/utils.ts +196 -0
  43. package/lib/runtime/components/react/context.ts +7 -1
  44. package/lib/runtime/components/react/dist/animationHooks/index.d.ts +16 -0
  45. package/lib/runtime/components/react/dist/animationHooks/index.d.ts.map +1 -0
  46. package/lib/runtime/components/react/dist/animationHooks/index.js +67 -0
  47. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts +4 -0
  48. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts.map +1 -0
  49. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.js +182 -0
  50. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts +4 -0
  51. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts.map +1 -0
  52. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.js +274 -0
  53. package/lib/runtime/components/react/dist/animationHooks/utils.d.ts +110 -0
  54. package/lib/runtime/components/react/dist/animationHooks/utils.d.ts.map +1 -0
  55. package/lib/runtime/components/react/dist/animationHooks/utils.js +150 -0
  56. package/lib/runtime/components/react/dist/context.d.ts +6 -1
  57. package/lib/runtime/components/react/dist/context.d.ts.map +1 -1
  58. package/lib/runtime/components/react/dist/mpx-camera.d.ts +32 -0
  59. package/lib/runtime/components/react/dist/mpx-camera.d.ts.map +1 -0
  60. package/lib/runtime/components/react/dist/mpx-camera.jsx +236 -0
  61. package/lib/runtime/components/react/dist/mpx-input.d.ts +2 -0
  62. package/lib/runtime/components/react/dist/mpx-input.d.ts.map +1 -1
  63. package/lib/runtime/components/react/dist/mpx-input.jsx +21 -10
  64. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +1 -1
  65. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +3 -0
  66. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +2 -2
  67. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +10 -0
  68. package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +1 -1
  69. package/lib/runtime/components/react/dist/mpx-swiper.jsx +28 -16
  70. package/lib/runtime/components/react/dist/mpx-view.d.ts +3 -2
  71. package/lib/runtime/components/react/dist/mpx-view.d.ts.map +1 -1
  72. package/lib/runtime/components/react/dist/mpx-view.jsx +2 -2
  73. package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
  74. package/lib/runtime/components/react/dist/utils.d.ts +1 -0
  75. package/lib/runtime/components/react/dist/utils.d.ts.map +1 -1
  76. package/lib/runtime/components/react/dist/utils.jsx +34 -13
  77. package/lib/runtime/components/react/mpx-camera.tsx +327 -0
  78. package/lib/runtime/components/react/mpx-input.tsx +26 -10
  79. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +3 -0
  80. package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +2 -2
  81. package/lib/runtime/components/react/mpx-swiper.tsx +43 -15
  82. package/lib/runtime/components/react/mpx-view.tsx +4 -5
  83. package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
  84. package/lib/runtime/components/react/types/global.d.ts +1 -0
  85. package/lib/runtime/components/react/utils.tsx +34 -16
  86. package/lib/runtime/optionProcessor.js +5 -0
  87. package/lib/runtime/optionProcessorReact.js +7 -0
  88. package/lib/runtime/stringify.wxs +2 -2
  89. package/lib/style-compiler/strip-conditional-loader/rebaseUrl.js +225 -0
  90. package/lib/style-compiler/strip-conditional-loader.js +55 -180
  91. package/lib/template-compiler/compiler.js +1 -3
  92. package/lib/utils/dom-tag-config.js +1 -1
  93. package/lib/utils/string.js +25 -1
  94. package/package.json +2 -1
  95. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +0 -33
  96. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +0 -1
  97. package/lib/runtime/components/react/dist/useAnimationHooks.js +0 -289
  98. package/lib/runtime/components/react/useAnimationHooks.ts +0 -320
@@ -18,7 +18,7 @@
18
18
  * ✔ selection-start
19
19
  * ✔ selection-end
20
20
  * ✔ adjust-position
21
- * hold-keyboard
21
+ * hold-keyboard
22
22
  * ✘ safe-password-cert-path
23
23
  * ✘ safe-password-length
24
24
  * ✘ safe-password-time-stamp
@@ -95,13 +95,16 @@ export interface InputProps {
95
95
  'selection-start'?: number
96
96
  'selection-end'?: number
97
97
  'placeholder-style'?: { color?: string }
98
- 'enable-offset'?: boolean,
98
+ 'enable-offset'?: boolean
99
99
  'enable-var'?: boolean
100
100
  'external-var-context'?: Record<string, any>
101
101
  'parent-font-size'?: number
102
102
  'parent-width'?: number
103
103
  'parent-height'?: number
104
- 'adjust-position': boolean,
104
+ // 只有 RN 环境读取
105
+ 'keyboard-type'?: string
106
+ 'adjust-position': boolean
107
+ 'hold-keyboard'?: boolean
105
108
  bindinput?: (evt: NativeSyntheticEvent<TextInputTextInputEventData> | unknown) => void
106
109
  bindfocus?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void
107
110
  bindblur?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void
@@ -118,11 +121,11 @@ export interface PrivateInputProps {
118
121
 
119
122
  type FinalInputProps = InputProps & PrivateInputProps
120
123
 
121
- const keyboardTypeMap: Record<Type, string> = {
122
- text: 'default',
124
+ const inputModeMap: Record<Type, string> = {
125
+ text: 'text',
123
126
  number: 'numeric',
124
- idcard: 'default',
125
- digit: isIOS ? 'decimal-pad' : 'numeric'
127
+ idcard: 'text',
128
+ digit: 'decimal'
126
129
  }
127
130
 
128
131
  const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps>((props: FinalInputProps, ref): JSX.Element => {
@@ -150,6 +153,8 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
150
153
  'parent-width': parentWidth,
151
154
  'parent-height': parentHeight,
152
155
  'adjust-position': adjustPosition = true,
156
+ 'keyboard-type': originalKeyboardType,
157
+ 'hold-keyboard': holdKeyboard = false,
153
158
  bindinput,
154
159
  bindfocus,
155
160
  bindblur,
@@ -182,7 +187,6 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
182
187
  return ''
183
188
  }
184
189
 
185
- const keyboardType = keyboardTypeMap[type]
186
190
  const defaultValue = parseValue(value)
187
191
  const textAlignVertical = multiline ? 'top' : 'auto'
188
192
 
@@ -281,7 +285,15 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
281
285
 
282
286
  const setKeyboardAvoidContext = () => {
283
287
  if (keyboardAvoid) {
284
- keyboardAvoid.current = { cursorSpacing, ref: nodeRef, adjustPosition }
288
+ keyboardAvoid.current = { cursorSpacing, ref: nodeRef, adjustPosition, holdKeyboard }
289
+ keyboardAvoid.current = {
290
+ cursorSpacing,
291
+ ref: nodeRef,
292
+ adjustPosition,
293
+ // fix: iOS 会在 onFocus 之前触发 keyboardWillShow 并且赋值 keyboardHeight
294
+ // 这里手动同步下 keyboardHeight,防止 onFocus setKeyboardAvoidContext 删掉 keyboardHeight
295
+ keyboardHeight: keyboardAvoid?.current?.keyboardHeight
296
+ }
285
297
  }
286
298
  }
287
299
 
@@ -316,6 +328,9 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
316
328
  if (keyboardAvoid?.current?.onKeyboardShow) {
317
329
  keyboardAvoid.current.onKeyboardShow = undefined
318
330
  }
331
+ if (keyboardAvoid?.current?.keyboardHeight) {
332
+ keyboardAvoid.current.keyboardHeight = undefined
333
+ }
319
334
  }
320
335
  if (keyboardAvoid?.current) {
321
336
  // 有 keyboardAvoiding
@@ -463,7 +478,8 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
463
478
  ref: nodeRef,
464
479
  style: extendObject({}, normalStyle, layoutStyle),
465
480
  allowFontScaling,
466
- keyboardType: keyboardType,
481
+ inputMode: originalKeyboardType ? undefined : inputModeMap[type],
482
+ keyboardType: originalKeyboardType,
467
483
  secureTextEntry: !!password,
468
484
  defaultValue: defaultValue,
469
485
  value: inputValue,
@@ -53,6 +53,9 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
53
53
 
54
54
  const onTouchEnd = ({ nativeEvent }: NativeSyntheticEvent<NativeTouchEvent & { origin?: string }>) => {
55
55
  if (nativeEvent.origin !== 'input') {
56
+ if (keyboardAvoid?.current?.holdKeyboard) {
57
+ return
58
+ }
56
59
  Keyboard.isVisible() && Keyboard.dismiss()
57
60
  }
58
61
  }
@@ -19,7 +19,7 @@ const _PortalManager = forwardRef((props: PortalManagerProps, ref:ForwardedRef<u
19
19
  setState((prevState) => ({
20
20
  portals: [...prevState.portals, { key, children }]
21
21
  }))
22
- }, [state])
22
+ }, [])
23
23
 
24
24
  const update = useCallback((key: number, children: ReactNode) => {
25
25
  setState((prevState) => ({
@@ -30,7 +30,7 @@ const _PortalManager = forwardRef((props: PortalManagerProps, ref:ForwardedRef<u
30
30
  return item
31
31
  })
32
32
  }))
33
- }, [state])
33
+ }, [])
34
34
 
35
35
  const unmount = useCallback((key: number) => {
36
36
  setState((prevState) => ({
@@ -11,6 +11,11 @@ import Portal from './mpx-portal'
11
11
  /**
12
12
  * ✔ indicator-dots
13
13
  * ✔ indicator-color
14
+ * ✔ indicator-width
15
+ * ✔ indicator-height
16
+ * ✔ indicator-radius
17
+ * ✔ indicator-spacing
18
+ * ✔ indicator-margin
14
19
  * ✔ indicator-active-color
15
20
  * ✔ autoplay
16
21
  * ✔ current
@@ -46,6 +51,11 @@ interface SwiperProps {
46
51
  scale?: boolean
47
52
  'indicator-dots'?: boolean
48
53
  'indicator-color'?: string
54
+ 'indicator-width'?: number
55
+ 'indicator-height'?: number
56
+ 'indicator-spacing'?: number
57
+ 'indicator-radius'?: number
58
+ 'indicator-margin'?: number
49
59
  'indicator-active-color'?: string
50
60
  vertical?: boolean
51
61
  style: {
@@ -72,23 +82,23 @@ interface SwiperProps {
72
82
  const styles: { [key: string]: Object } = {
73
83
  pagination_x: {
74
84
  position: 'absolute',
75
- bottom: 25,
85
+ bottom: 0,
76
86
  left: 0,
77
87
  right: 0,
78
88
  flexDirection: 'row',
79
89
  flex: 1,
80
90
  justifyContent: 'center',
81
- alignItems: 'center'
91
+ alignItems: 'flex-end'
82
92
  },
83
93
  pagination_y: {
84
94
  position: 'absolute',
85
- right: 15,
95
+ right: 0,
86
96
  top: 0,
87
97
  bottom: 0,
88
98
  flexDirection: 'column',
89
99
  flex: 1,
90
100
  justifyContent: 'center',
91
- alignItems: 'center'
101
+ alignItems: 'flex-end'
92
102
  },
93
103
  pagerWrapperx: {
94
104
  position: 'absolute',
@@ -109,16 +119,6 @@ const styles: { [key: string]: Object } = {
109
119
  }
110
120
  }
111
121
 
112
- const dotCommonStyle = {
113
- width: 8,
114
- height: 8,
115
- borderRadius: 4,
116
- marginLeft: 3,
117
- marginRight: 3,
118
- marginTop: 3,
119
- marginBottom: 3,
120
- zIndex: 98
121
- }
122
122
  const activeDotStyle = {
123
123
  zIndex: 99
124
124
  }
@@ -136,6 +136,11 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
136
136
  const {
137
137
  'indicator-dots': showPagination,
138
138
  'indicator-color': dotColor = 'rgba(0, 0, 0, .3)',
139
+ 'indicator-width': dotWidth = 8,
140
+ 'indicator-height': dotHeight = 8,
141
+ 'indicator-radius': dotRadius = 4,
142
+ 'indicator-spacing': dotSpacing = 4,
143
+ 'indicator-margin': paginationMargin = 10,
139
144
  'indicator-active-color': activeDotColor = '#000000',
140
145
  'enable-var': enableVar = false,
141
146
  'parent-font-size': parentFontSize,
@@ -151,6 +156,17 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
151
156
  current: propCurrent = 0,
152
157
  bindchange
153
158
  } = props
159
+
160
+ const dotCommonStyle = {
161
+ width: dotWidth,
162
+ height: dotHeight,
163
+ borderRadius: dotRadius,
164
+ marginLeft: dotSpacing,
165
+ marginRight: dotSpacing,
166
+ marginTop: dotSpacing,
167
+ marginBottom: dotSpacing,
168
+ zIndex: 98
169
+ }
154
170
  const easeingFunc = props['easing-function'] || 'default'
155
171
  const easeDuration = props.duration || 500
156
172
  const horizontal = props.vertical !== undefined ? !props.vertical : true
@@ -252,6 +268,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
252
268
  'style',
253
269
  'indicator-dots',
254
270
  'indicator-color',
271
+ 'indicator-width',
255
272
  'indicator-active-color',
256
273
  'previous-margin',
257
274
  'vertical',
@@ -294,8 +311,18 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
294
311
  for (let i = 0; i < children.length; i++) {
295
312
  dots.push(<View style={[dotCommonStyle, { backgroundColor: unActionColor }]} key={i}></View>)
296
313
  }
314
+ let paginationStyle = styles['pagination_' + dir]
315
+ if (paginationMargin) {
316
+ paginationStyle = {
317
+ ...paginationStyle,
318
+ marginBottom: paginationMargin,
319
+ marginLeft: paginationMargin,
320
+ marginRight: paginationMargin,
321
+ marginTop: paginationMargin
322
+ }
323
+ }
297
324
  return (
298
- <View pointerEvents="none" style={styles['pagination_' + dir]}>
325
+ <View pointerEvents="none" style={paginationStyle} key="pagination">
299
326
  <View style={[styles['pagerWrapper' + dir]]}>
300
327
  <Animated.View style={[
301
328
  dotCommonStyle,
@@ -861,6 +888,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
861
888
  style: [normalStyle, layoutStyle, styles.swiper]
862
889
  }, layoutProps, innerProps)
863
890
  const animateComponent = createElement(Animated.View, {
891
+ key: 'swiperContainer',
864
892
  style: [{ flexDirection: dir === 'x' ? 'row' : 'column', width: '100%', height: '100%' }, animatedStyles]
865
893
  }, wrapChildren({
866
894
  children: arrPages
@@ -8,8 +8,8 @@ import { View, TextStyle, NativeSyntheticEvent, ViewProps, ImageStyle, StyleShee
8
8
  import { useRef, useState, useEffect, forwardRef, ReactNode, JSX, createElement } from 'react'
9
9
  import useInnerProps from './getInnerListeners'
10
10
  import Animated from 'react-native-reanimated'
11
- import useAnimationHooks from './useAnimationHooks'
12
- import type { AnimationProp } from './useAnimationHooks'
11
+ import useAnimationHooks, { AnimationType } from './animationHooks/index'
12
+ import type { AnimationProp } from './animationHooks/utils'
13
13
  import { ExtendedViewStyle } from './types/common'
14
14
  import useNodesRef, { HandlerRef } from './useNodesRef'
15
15
  import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout, renderImage, pickStyle, extendObject, useHover } from './utils'
@@ -32,7 +32,7 @@ export interface _ViewProps extends ViewProps {
32
32
  'parent-font-size'?: number
33
33
  'parent-width'?: number
34
34
  'parent-height'?: number
35
- 'enable-animation'?: boolean
35
+ 'enable-animation'?: boolean | AnimationType
36
36
  bindtouchstart?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
37
37
  bindtouchmove?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
38
38
  bindtouchend?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
@@ -287,7 +287,7 @@ function backgroundSize (imageProps: ImageProps, preImageInfo: PreImageInfo, ima
287
287
  } else { // 数值类型 ImageStyle
288
288
  // 数值类型设置为 stretch
289
289
  imageProps.resizeMode = 'stretch'
290
- if (type === 'linear' && (!layoutWidth || !layoutHeight)) {
290
+ if (type === 'linear' && (!layoutWidth || !layoutHeight) && (isPercent(width) || isPercent(height))) {
291
291
  // ios 上 linear 组件只要重新触发渲染,在渲染过程中外层容器 width 或者 height 被设置为 0,通过设置 % 的方式会渲染不出来,即使后面再更新为正常宽高也渲染不出来
292
292
  // 所以 hack 手动先将 linear 宽高也设置为 0,后面再更新为正确的数值或 %。
293
293
  dimensions = {
@@ -777,7 +777,6 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
777
777
  ref: nodeRef,
778
778
  style: enableStyleAnimation ? [viewStyle, animationStyle] : viewStyle
779
779
  }
780
-
781
780
  ),
782
781
  [
783
782
  'hover-start-time',
@@ -234,7 +234,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
234
234
  }
235
235
  break
236
236
  case 'postMessage':
237
- bindmessage && bindmessage(getCustomEvent('messsage', {}, { // RN组件销毁顺序与小程序不一致,所以改成和支付宝消息一致
237
+ bindmessage && bindmessage(getCustomEvent('message', {}, { // RN组件销毁顺序与小程序不一致,所以改成和支付宝消息一致
238
238
  detail: {
239
239
  data: params[0]?.data
240
240
  }
@@ -34,6 +34,7 @@ declare module '@mpxjs/utils' {
34
34
  },
35
35
  setOptions: (params: Record<string, any>) => void
36
36
  } | undefined
37
+ export function dash2hump (str: string): string
37
38
  }
38
39
 
39
40
  declare let global: {
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useCallback, useMemo, useRef, ReactNode, ReactElement, isValidElement, useContext, useState, Dispatch, SetStateAction, Children, cloneElement, createElement, MutableRefObject } from 'react'
2
2
  import { LayoutChangeEvent, TextStyle, ImageProps, Image } from 'react-native'
3
- import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn } from '@mpxjs/utils'
3
+ import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn, isEmptyObject } from '@mpxjs/utils'
4
4
  import { VarContext, ScrollViewContext, RouteContext } from './context'
5
5
  import { ExpressionParser, parseFunc, ReplaceSource } from './parser'
6
6
  import { initialWindowMetrics } from 'react-native-safe-area-context'
@@ -238,7 +238,7 @@ function transformVar (styleObj: Record<string, any>, varKeyPaths: Array<Array<s
238
238
  const resolved = resolveVar(value, varContext)
239
239
  if (resolved === undefined) {
240
240
  delete target[key]
241
- error(`Can not resolve css var at ${varKeyPath.join('.')}:${value}.`)
241
+ // error(`Can not resolve css var at ${varKeyPath.join('.')}:${value}.`)
242
242
  return
243
243
  }
244
244
  target[key] = resolved
@@ -288,6 +288,10 @@ function transformStringify (styleObj: Record<string, any>) {
288
288
  if (isNumber(styleObj.fontWeight)) {
289
289
  styleObj.fontWeight = '' + styleObj.fontWeight
290
290
  }
291
+ // transformOrigin 20px 需要转换为 transformOrigin '20'
292
+ if (isNumber(styleObj.transformOrigin)) {
293
+ styleObj.transformOrigin = '' + styleObj.transformOrigin
294
+ }
291
295
  }
292
296
 
293
297
  function transformPosition (styleObj: Record<string, any>, meta: PositionMeta) {
@@ -297,7 +301,7 @@ function transformPosition (styleObj: Record<string, any>, meta: PositionMeta) {
297
301
  }
298
302
  }
299
303
  // 多value解析
300
- function parseValues (str: string, char = ' ') {
304
+ export function parseValues (str: string, char = ' ') {
301
305
  let stack = 0
302
306
  let temp = ''
303
307
  const result = []
@@ -308,11 +312,11 @@ function parseValues (str: string, char = ' ') {
308
312
  stack--
309
313
  }
310
314
  // 非括号内 或者 非分隔字符且非空
311
- if (stack !== 0 || (str[i] !== char && str[i] !== ' ')) {
315
+ if (stack !== 0 || str[i] !== char) {
312
316
  temp += str[i]
313
317
  }
314
318
  if ((stack === 0 && str[i] === char) || i === str.length - 1) {
315
- result.push(temp)
319
+ result.push(temp.trim())
316
320
  temp = ''
317
321
  }
318
322
  }
@@ -321,6 +325,8 @@ function parseValues (str: string, char = ' ') {
321
325
  // parse string transform, eg: transform: 'rotateX(45deg) rotateZ(0.785398rad)'
322
326
  function parseTransform (transformStr: string) {
323
327
  const values = parseValues(transformStr)
328
+ // Todo transform 排序不一致时,transform动画会闪烁,故这里同样的排序输出 transform
329
+ values.sort()
324
330
  const transform: { [propName: string]: string | number | number[] }[] = []
325
331
  values.forEach(item => {
326
332
  const match = item.match(/([/\w]+)\((.+)\)/)
@@ -384,6 +390,14 @@ function transformBoxShadow (styleObj: Record<string, any>) {
384
390
  }, '')
385
391
  }
386
392
 
393
+ function transformZIndex (styleObj: Record<string, any>) {
394
+ if (!styleObj.zIndex || typeof styleObj.zIndex === 'number') return
395
+ if (styleObj.zIndex === 'auto') {
396
+ error('Property [z-index] does not supported [auto], please check again!')
397
+ styleObj.zIndex = 0
398
+ }
399
+ }
400
+
387
401
  interface TransformStyleConfig {
388
402
  enableVar?: boolean
389
403
  externalVarContext?: Record<string, any>
@@ -440,17 +454,20 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
440
454
  }
441
455
  }
442
456
 
443
- function calcVisitor ({ value, keyPath }: VisitorArg) {
457
+ function calcVisitor ({ key, value, keyPath }: VisitorArg) {
444
458
  if (calcUseRegExp.test(value)) {
459
+ // calc translate & border-radius 的百分比计算
460
+ if (hasOwn(selfPercentRule, key) && /%/.test(value)) {
461
+ hasSelfPercent = true
462
+ percentKeyPaths.push(keyPath.slice())
463
+ }
445
464
  calcKeyPaths.push(keyPath.slice())
446
465
  }
447
466
  }
448
467
 
449
468
  function percentVisitor ({ key, value, keyPath }: VisitorArg) {
450
- if (hasOwn(selfPercentRule, key) && PERCENT_REGEX.test(value)) {
451
- hasSelfPercent = true
452
- percentKeyPaths.push(keyPath.slice())
453
- } else if ((key === 'fontSize' || key === 'lineHeight') && PERCENT_REGEX.test(value)) {
469
+ // fixme 去掉 translate & border-radius 的百分比计算
470
+ if ((key === 'fontSize' || key === 'lineHeight') && PERCENT_REGEX.test(value)) {
454
471
  percentKeyPaths.push(keyPath.slice())
455
472
  }
456
473
  }
@@ -460,10 +477,10 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
460
477
  [envVisitor, percentVisitor, calcVisitor].forEach(visitor => visitor({ target, key, value, keyPath }))
461
478
  }
462
479
  }
463
-
480
+ // transform 字符串格式转化数组格式(先转数组再处理css var)
481
+ transformTransform(styleObj)
464
482
  // traverse var & generate normalStyle
465
483
  traverseStyle(styleObj, [varVisitor])
466
-
467
484
  hasVarDec = hasVarDec || !!externalVarContext
468
485
  enableVar = enableVar || hasVarDec || hasVarUse
469
486
  const enableVarRef = useRef(enableVar)
@@ -527,10 +544,11 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
527
544
  transformStringify(normalStyle)
528
545
  // transform rpx to px
529
546
  transformBoxShadow(normalStyle)
530
-
531
- // transform 字符串格式转化数组格式
532
- transformTransform(normalStyle)
533
-
547
+ // transform z-index auto to 0
548
+ transformZIndex(normalStyle)
549
+ if (Array.isArray(normalStyle.transform)) {
550
+ normalStyle.transform = normalStyle.transform.filter(item => !isEmptyObject(item))
551
+ }
534
552
  return {
535
553
  hasVarDec,
536
554
  varContextRef,
@@ -2,6 +2,7 @@ import { hasOwn, isEmptyObject, extend } from './utils'
2
2
  import { isBrowser } from './env'
3
3
  import transRpxStyle from './transRpxStyle'
4
4
  import animation from './animation'
5
+ import { error } from '@mpxjs/utils'
5
6
  const dash2hump = require('../utils/hump-dash').dash2hump
6
7
 
7
8
  export function processComponentOption (
@@ -107,6 +108,10 @@ registered in parent context!`)
107
108
 
108
109
  export function getComponent (component, extendOptions) {
109
110
  component = component.__esModule ? component.default : component
111
+ if (!component) {
112
+ error('getComponent() expected component options as the first argument, but got undefined.')
113
+ return null
114
+ }
110
115
  // eslint-disable-next-line
111
116
  if (extendOptions && !component.__mpxExtended) {
112
117
  extend(component, extendOptions, { __mpxExtended: true })
@@ -1,9 +1,16 @@
1
1
  import AsyncSuspense from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/mpx-async-suspense'
2
2
  import { memo, forwardRef, createElement } from 'react'
3
+ import { error } from '@mpxjs/utils'
3
4
  import { extend } from './utils'
4
5
 
5
6
  export function getComponent (component, extendOptions) {
6
7
  component = component.__esModule ? component.default : component
8
+ if (!component) {
9
+ error(
10
+ `getComponent expecting function/class component ${extendOptions?.displayName ? `[${extendOptions.displayName}] ` : ''}as the first argument, but got undefined.`
11
+ )
12
+ return null
13
+ }
7
14
  // eslint-disable-next-line
8
15
  if (extendOptions && !component.__mpxExtended) {
9
16
  extend(component, extendOptions, { __mpxExtended: true })
@@ -45,7 +45,7 @@ function objectKeys (obj) {
45
45
  }
46
46
 
47
47
  function genRegExp (str, flags) {
48
- if (!__mpx_wxs__) {
48
+ if (!__mpx_wxs__ || __mpx_mode__ === 'ks') {
49
49
  return new RegExp(str, flags)
50
50
  } else {
51
51
  return getRegExp(str, flags)
@@ -234,4 +234,4 @@ module.exports = {
234
234
  var parsedStaticStyle = typeof staticStyle === 'string' ? parseStyleText(staticStyle) : {}
235
235
  return genStyleText(extend(parsedStaticStyle, normalizedDynamicStyle))
236
236
  }
237
- }
237
+ }