@mpxjs/webpack-plugin 2.10.24-test.1 → 2.11.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 (128) hide show
  1. package/LICENSE +433 -0
  2. package/lib/index.js +4 -1
  3. package/lib/platform/style/wx/index.js +44 -38
  4. package/lib/platform/template/wx/component-config/picker.js +0 -6
  5. package/lib/resolver/AddEnvPlugin.js +1 -1
  6. package/lib/resolver/AddModePlugin.js +1 -1
  7. package/lib/resolver/ExtendComponentsPlugin.js +68 -0
  8. package/lib/runtime/components/extends/section-list.mpx +14 -0
  9. package/lib/runtime/components/react/dist/mpx-button.d.ts +0 -1
  10. package/lib/runtime/components/react/dist/mpx-button.jsx +2 -2
  11. package/lib/runtime/components/react/dist/mpx-camera.d.ts +0 -1
  12. package/lib/runtime/components/react/dist/mpx-camera.jsx +36 -4
  13. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +0 -1
  14. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -2
  15. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +0 -1
  16. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +2 -2
  17. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +0 -1
  18. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +2 -2
  19. package/lib/runtime/components/react/dist/mpx-form.d.ts +0 -1
  20. package/lib/runtime/components/react/dist/mpx-form.jsx +2 -2
  21. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +0 -1
  22. package/lib/runtime/components/react/dist/mpx-icon/index.jsx +2 -2
  23. package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -1
  24. package/lib/runtime/components/react/dist/mpx-image.jsx +2 -2
  25. package/lib/runtime/components/react/dist/mpx-inline-text.jsx +13 -4
  26. package/lib/runtime/components/react/dist/mpx-input.d.ts +0 -1
  27. package/lib/runtime/components/react/dist/mpx-input.jsx +16 -8
  28. package/lib/runtime/components/react/dist/mpx-label.d.ts +0 -1
  29. package/lib/runtime/components/react/dist/mpx-label.jsx +2 -2
  30. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +0 -1
  31. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +2 -2
  32. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +0 -1
  33. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +2 -2
  34. package/lib/runtime/components/react/dist/mpx-nav.jsx +1 -1
  35. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +72 -23
  36. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +2 -2
  37. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +4 -0
  38. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +6 -8
  39. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +0 -2
  40. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.js +0 -5
  41. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +1 -0
  42. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +34 -14
  43. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +0 -2
  44. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +4 -5
  45. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +0 -2
  46. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.jsx +3 -5
  47. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +5 -4
  48. package/lib/runtime/components/react/dist/mpx-popup/index.jsx +2 -2
  49. package/lib/runtime/components/react/dist/mpx-popup/popupBase.jsx +3 -2
  50. package/lib/runtime/components/react/dist/mpx-progress.d.ts +0 -1
  51. package/lib/runtime/components/react/dist/mpx-progress.jsx +1 -2
  52. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +0 -1
  53. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +2 -2
  54. package/lib/runtime/components/react/dist/mpx-radio.d.ts +0 -1
  55. package/lib/runtime/components/react/dist/mpx-radio.jsx +2 -2
  56. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +0 -1
  57. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +1 -2
  58. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +0 -1
  59. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +2 -2
  60. package/lib/runtime/components/react/dist/mpx-section-list.d.ts +51 -0
  61. package/lib/runtime/components/react/dist/mpx-section-list.jsx +376 -0
  62. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +27 -14
  63. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +1 -0
  64. package/lib/runtime/components/react/dist/mpx-slider.d.ts +0 -1
  65. package/lib/runtime/components/react/dist/mpx-slider.jsx +1 -2
  66. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +0 -1
  67. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +2 -2
  68. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +0 -1
  69. package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +2 -2
  70. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +0 -1
  71. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +0 -1
  72. package/lib/runtime/components/react/dist/mpx-swiper.jsx +1 -2
  73. package/lib/runtime/components/react/dist/mpx-switch.d.ts +0 -1
  74. package/lib/runtime/components/react/dist/mpx-switch.jsx +1 -2
  75. package/lib/runtime/components/react/dist/mpx-text.d.ts +0 -1
  76. package/lib/runtime/components/react/dist/mpx-text.jsx +22 -8
  77. package/lib/runtime/components/react/dist/mpx-video.d.ts +0 -1
  78. package/lib/runtime/components/react/dist/mpx-video.jsx +1 -2
  79. package/lib/runtime/components/react/dist/mpx-view.d.ts +0 -1
  80. package/lib/runtime/components/react/dist/mpx-view.jsx +1 -2
  81. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +2 -1
  82. package/lib/runtime/components/react/dist/utils.d.ts +6 -9
  83. package/lib/runtime/components/react/dist/utils.jsx +70 -84
  84. package/lib/runtime/components/react/mpx-button.tsx +1 -3
  85. package/lib/runtime/components/react/mpx-camera.tsx +40 -5
  86. package/lib/runtime/components/react/mpx-canvas/index.tsx +5 -5
  87. package/lib/runtime/components/react/mpx-checkbox-group.tsx +1 -3
  88. package/lib/runtime/components/react/mpx-checkbox.tsx +1 -3
  89. package/lib/runtime/components/react/mpx-form.tsx +1 -3
  90. package/lib/runtime/components/react/mpx-icon/index.tsx +1 -3
  91. package/lib/runtime/components/react/mpx-image.tsx +2 -5
  92. package/lib/runtime/components/react/mpx-inline-text.tsx +13 -4
  93. package/lib/runtime/components/react/mpx-input.tsx +19 -10
  94. package/lib/runtime/components/react/mpx-label.tsx +1 -3
  95. package/lib/runtime/components/react/mpx-movable-area.tsx +2 -3
  96. package/lib/runtime/components/react/mpx-movable-view.tsx +1 -3
  97. package/lib/runtime/components/react/mpx-nav.tsx +1 -1
  98. package/lib/runtime/components/react/mpx-picker/index.tsx +100 -29
  99. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +3 -3
  100. package/lib/runtime/components/react/mpx-picker/selector.tsx +1 -1
  101. package/lib/runtime/components/react/mpx-picker/type.ts +4 -0
  102. package/lib/runtime/components/react/mpx-picker-view/index.tsx +12 -17
  103. package/lib/runtime/components/react/mpx-picker-view/pickerVIewContext.ts +0 -9
  104. package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +44 -21
  105. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +1 -9
  106. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +0 -9
  107. package/lib/runtime/components/react/mpx-popup/index.tsx +7 -3
  108. package/lib/runtime/components/react/mpx-popup/popupBase.tsx +3 -2
  109. package/lib/runtime/components/react/mpx-progress.tsx +0 -3
  110. package/lib/runtime/components/react/mpx-radio-group.tsx +1 -3
  111. package/lib/runtime/components/react/mpx-radio.tsx +1 -3
  112. package/lib/runtime/components/react/mpx-rich-text/index.tsx +0 -3
  113. package/lib/runtime/components/react/mpx-scroll-view.tsx +1 -3
  114. package/lib/runtime/components/react/mpx-section-list.tsx +557 -0
  115. package/lib/runtime/components/react/mpx-simple-text.tsx +26 -13
  116. package/lib/runtime/components/react/mpx-slider.tsx +0 -3
  117. package/lib/runtime/components/react/mpx-sticky-header.tsx +1 -3
  118. package/lib/runtime/components/react/mpx-sticky-section.tsx +1 -3
  119. package/lib/runtime/components/react/mpx-swiper-item.tsx +0 -1
  120. package/lib/runtime/components/react/mpx-swiper.tsx +0 -3
  121. package/lib/runtime/components/react/mpx-switch.tsx +0 -3
  122. package/lib/runtime/components/react/mpx-text.tsx +21 -9
  123. package/lib/runtime/components/react/mpx-video.tsx +0 -3
  124. package/lib/runtime/components/react/mpx-view.tsx +0 -3
  125. package/lib/runtime/components/react/mpx-web-view.tsx +4 -3
  126. package/lib/runtime/components/react/utils.tsx +82 -88
  127. package/lib/template-compiler/compiler.js +6 -0
  128. package/package.json +5 -5
@@ -11,7 +11,6 @@ interface SwiperItemProps {
11
11
  'enable-offset'?: boolean
12
12
  'enable-var': boolean
13
13
  'enable-text-pass-through'?: boolean
14
- 'parent-font-size'?: number
15
14
  'parent-width'?: number
16
15
  'parent-height'?: number
17
16
  children?: ReactNode
@@ -71,7 +71,6 @@ interface SwiperProps {
71
71
  'enable-offset'?: boolean
72
72
  'enable-var': boolean
73
73
  'enable-text-pass-through'?: boolean
74
- 'parent-font-size'?: number
75
74
  'parent-width'?: number
76
75
  'parent-height'?: number
77
76
  'wait-for'?: Array<GestureHandler>
@@ -148,7 +147,6 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
148
147
  'indicator-active-color': activeDotColor = '#000000',
149
148
  'enable-var': enableVar = false,
150
149
  'enable-text-pass-through': enableTextPassThrough,
151
- 'parent-font-size': parentFontSize,
152
150
  'parent-width': parentWidth,
153
151
  'parent-height': parentHeight,
154
152
  'simultaneous-handlers': originSimultaneousHandlers = [],
@@ -192,7 +190,6 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
192
190
  setHeight
193
191
  } = useTransformStyle(style, {
194
192
  enableVar,
195
- parentFontSize,
196
193
  parentWidth,
197
194
  parentHeight
198
195
  })
@@ -23,7 +23,6 @@ interface _SwitchProps extends SwitchProps {
23
23
  disabled: boolean
24
24
  color: string
25
25
  'enable-var'?: boolean
26
- 'parent-font-size'?: number
27
26
  'parent-width'?: number
28
27
  'parent-height'?: number
29
28
  bindchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
@@ -38,7 +37,6 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
38
37
  disabled = false,
39
38
  color = '#04BE02',
40
39
  'enable-var': enableVar,
41
- 'parent-font-size': parentFontSize,
42
40
  'parent-width': parentWidth,
43
41
  'parent-height': parentHeight,
44
42
  bindchange,
@@ -65,7 +63,6 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
65
63
  hasPositionFixed
66
64
  } = useTransformStyle(style, {
67
65
  enableVar,
68
- parentFontSize,
69
66
  parentWidth,
70
67
  parentHeight
71
68
  })
@@ -5,12 +5,14 @@
5
5
  * ✔ decode
6
6
  */
7
7
  import { Text, TextStyle, TextProps } from 'react-native'
8
- import { useRef, forwardRef, ReactNode, JSX, createElement, Children } from 'react'
8
+ import { useRef, forwardRef, ReactNode, JSX, createElement, Children, useContext } from 'react'
9
9
  import Portal from './mpx-portal'
10
10
  import useInnerProps from './getInnerListeners'
11
11
  import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
12
- import { useTransformStyle, wrapChildren, extendObject, getDefaultAllowFontScaling, useTextPassThroughText, isStringChildren, splitStyle } from './utils'
12
+ import { useTransformStyle, wrapChildren, extendObject, getDefaultAllowFontScaling, isStringChildren, splitStyle, resolveTextFontSizePercentStyle, resolveTextLineHeightPercentStyle } from './utils'
13
13
  import * as perf from '@mpxjs/perf'
14
+ import { diffAndCloneA } from '@mpxjs/utils'
15
+ import { TextPassThroughContext, TextPassThroughContextValue } from './context'
14
16
 
15
17
  const decodeMap = {
16
18
  '&lt;': '<',
@@ -48,7 +50,6 @@ interface _TextProps extends TextProps {
48
50
  selectable?: boolean
49
51
  'user-select'?: boolean
50
52
  'enable-var'?: boolean
51
- 'parent-font-size'?: number
52
53
  'parent-width'?: number
53
54
  'parent-height'?: number
54
55
  decode?: boolean
@@ -67,7 +68,6 @@ const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref):
67
68
  selectable,
68
69
  'enable-var': enableVar,
69
70
  'user-select': userSelect,
70
- 'parent-font-size': parentFontSize,
71
71
  'parent-width': parentWidth,
72
72
  'parent-height': parentHeight,
73
73
  decode
@@ -84,7 +84,6 @@ const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref):
84
84
  hasPositionFixed
85
85
  } = useTransformStyle(currentStyle, {
86
86
  enableVar,
87
- parentFontSize,
88
87
  parentWidth,
89
88
  parentHeight
90
89
  })
@@ -97,15 +96,28 @@ const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref):
97
96
  children = props.children
98
97
  isStringOnly = isStringChildren(children)
99
98
  }
100
- const childTextStyle = !isStringOnly ? (splitStyle(normalStyle).textStyle as TextStyle | undefined) : undefined
101
- const { inheritedText, textPassThrough } = useTextPassThroughText(childTextStyle)
99
+ const inheritedText = useContext(TextPassThroughContext)
100
+ const resolvedNormalStyle = resolveTextFontSizePercentStyle(normalStyle, inheritedText?.textStyle)
101
+ const childTextStyle = !isStringOnly ? (splitStyle(resolvedNormalStyle).textStyle as TextStyle | undefined) : undefined
102
+ const textPassThroughRef = useRef<TextPassThroughContextValue | null>(null)
103
+ let textPassThrough: TextPassThroughContextValue | null = null
104
+ if (childTextStyle) {
105
+ const nextTextPassThrough = {
106
+ textStyle: extendObject({}, inheritedText?.textStyle, childTextStyle)
107
+ }
108
+ if (diffAndCloneA(textPassThroughRef.current, nextTextPassThrough).diff) {
109
+ textPassThroughRef.current = nextTextPassThrough
110
+ }
111
+ textPassThrough = textPassThroughRef.current
112
+ }
102
113
 
103
114
  const mergedProps = inheritedText?.pendingTextProps
104
115
  ? extendObject({}, inheritedText.pendingTextProps, props)
105
116
  : props
106
117
  const finalStyle = inheritedText?.textStyle
107
- ? extendObject({}, inheritedText.textStyle, normalStyle)
108
- : normalStyle
118
+ ? extendObject({}, inheritedText.textStyle, resolvedNormalStyle)
119
+ : resolvedNormalStyle
120
+ resolveTextLineHeightPercentStyle(finalStyle, inheritedText?.textStyle)
109
121
 
110
122
  const nodeRef = useRef(null)
111
123
  useNodesRef<Text, _TextProps>(mergedProps, ref, nodeRef, {
@@ -93,7 +93,6 @@ interface VideoProps {
93
93
  'preferred-peak-bit-rate'?: number
94
94
  'enable-auto-rotation'?: number
95
95
  'enable-var'?: boolean
96
- 'parent-font-size'?: number
97
96
  'parent-width'?: number
98
97
  'parent-height'?: number
99
98
  bindplay?: (event: Record<string, any>) => void
@@ -154,7 +153,6 @@ const MpxVideo = forwardRef<HandlerRef<View, VideoProps>, VideoProps>((videoProp
154
153
  'preferred-peak-bit-rate': preferredPeakBitRate = 0,
155
154
  'enable-auto-rotation': enableAutoRotation = false,
156
155
  'enable-var': enableVar,
157
- 'parent-font-size': parentFontSize,
158
156
  'parent-width': parentWidth,
159
157
  'parent-height': parentHeight
160
158
  } = props
@@ -172,7 +170,6 @@ const MpxVideo = forwardRef<HandlerRef<View, VideoProps>, VideoProps>((videoProp
172
170
  const { normalStyle, hasSelfPercent, setWidth, setHeight, hasPositionFixed } =
173
171
  useTransformStyle(style, {
174
172
  enableVar,
175
- parentFontSize,
176
173
  parentWidth,
177
174
  parentHeight,
178
175
  defaultStyle: styles.container
@@ -31,7 +31,6 @@ export interface _ViewProps extends ViewProps {
31
31
  'enable-text-pass-through'?: boolean
32
32
  'enable-var'?: boolean
33
33
  'enable-fast-image'?: boolean
34
- 'parent-font-size'?: number
35
34
  'parent-width'?: number
36
35
  'parent-height'?: number
37
36
  'enable-animation'?: boolean | AnimationType
@@ -834,7 +833,6 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
834
833
  'enable-text-pass-through': enableTextPassThrough,
835
834
  'enable-fast-image': enableFastImage,
836
835
  'enable-animation': enableAnimation,
837
- 'parent-font-size': parentFontSize,
838
836
  'parent-width': parentWidth,
839
837
  'parent-height': parentHeight,
840
838
  animation,
@@ -863,7 +861,6 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
863
861
  setHeight
864
862
  } = useTransformStyle(styleObj, {
865
863
  enableVar,
866
- parentFontSize,
867
864
  parentWidth,
868
865
  parentHeight,
869
866
  // 基于合并后的 styleObj 判断(hover 状态切换 display 也能触发)
@@ -35,6 +35,7 @@ interface WebViewProps {
35
35
  binderror?: (event: CommonCallbackEvent) => void
36
36
  [x: string]: any
37
37
  }
38
+ type WebViewInstance = WebView<any>
38
39
  type Listener = (type: string, callback: (e: Event) => void) => () => void
39
40
 
40
41
  interface PayloadData {
@@ -82,7 +83,7 @@ const styles = StyleSheet.create({
82
83
  }
83
84
  })
84
85
 
85
- const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((props, ref): JSX.Element | null => {
86
+ const _WebView = forwardRef<HandlerRef<WebViewInstance, WebViewProps>, WebViewProps>((props, ref): JSX.Element | null => {
86
87
  const { src, bindmessage, bindload, binderror } = props
87
88
  const mpx = global.__mpx
88
89
  const errorText: ErrorTextMap = {
@@ -103,7 +104,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
103
104
  const { pageId } = useContext(RouteContext) || {}
104
105
  const [pageLoadErr, setPageLoadErr] = useState<boolean>(false)
105
106
  const currentPage = useMemo(() => getCurrentPage(pageId), [pageId])
106
- const webViewRef = useRef<WebView>(null)
107
+ const webViewRef = useRef<WebViewInstance>(null)
107
108
  const fristLoaded = useRef<boolean>(false)
108
109
  const isLoadError = useRef<boolean>(false)
109
110
  const isNavigateBack = useRef<boolean>(false)
@@ -128,7 +129,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
128
129
  isNavigateBack.current = false
129
130
  })
130
131
 
131
- useNodesRef<WebView, WebViewProps>(props, ref, webViewRef, {
132
+ useNodesRef<WebViewInstance, WebViewProps>(props, ref, webViewRef, {
132
133
  style: defaultWebViewStyle
133
134
  })
134
135
 
@@ -38,6 +38,7 @@ const varUseRegExp = /var\(/
38
38
  const unoVarDecRegExp = /^--un-/
39
39
  const unoVarUseRegExp = /var\(--un-/
40
40
  const lengthValueRegExp = /^(-?(?:\d+(?:\.\d+)?|\.\d+)(?:rpx|px|%|vw|vh)?|hairlineWidth)$/
41
+ const DEFAULT_FONT_SIZE = 16
41
42
  // transform: 'rotateX(45deg) ...' 单段拆出 fn 名与括号内值
42
43
  const transformFnRegExp = /([/\w]+)\((.+)\)/
43
44
  // boxShadow 子值识别 rpx 单位(仅 rpx 需要换算为 px,其它单位保留原样)
@@ -97,7 +98,7 @@ const runtimeAbbreviationMap: Record<string, string[]> = {
97
98
  // 因此进入 runtimeForceExpandCompositeMap,避免「单值透传」捷径放过这类多值串残留。
98
99
  // 百分比(`gap: 50%` / `gap: 10px 50%`)由 transformShorthand 写回阶段就地 resolvePercent 落成 number
99
100
  gap: ['rowGap', 'columnGap'],
100
- // inset:4 槽位等价 margin 四值语法;RN inset 长属性非稳定,单值也必须展开到 top/right/bottom/left
101
+ // inset:4 槽位等价 margin 四值语法;RN 0.74+ 原生支持单值 DimensionValue,单值走 runtimeCompositeStyleMap 短路透传
101
102
  inset: ['top', 'right', 'bottom', 'left'],
102
103
  // outline: <outline-width> || <outline-style> || <outline-color>,顺序不敏感
103
104
  outline: ['outlineWidth', 'outlineStyle', 'outlineColor']
@@ -111,15 +112,6 @@ const runtimeCompositeStyleMap: Record<string, boolean> = {
111
112
  gap: true,
112
113
  inset: true
113
114
  }
114
- // 即使单值也必须展开(不走「单值透传」捷径):
115
- // - inset:RN inset 长属性不稳定,单值透传会留下不可靠的 inset key
116
- // - gap:RN gap / rowGap / columnGap 严格要求 number;单值串虽已在 __getStyle 阶段被 __formatValue 换算,
117
- // 但多值串(如 '10px 20px')会原样透传到这里,需展开后逐 token 再过 __formatValue 才能落成 number;
118
- // `%` 在写回阶段由 transformShorthand 调 resolvePercent 落成 number(rowGap 基 parentHeight、columnGap 基 parentWidth)
119
- const runtimeForceExpandCompositeMap: Record<string, boolean> = {
120
- inset: true,
121
- gap: true
122
- }
123
115
  const runtimeUnorderedAbbreviationMap: Record<string, boolean> = {
124
116
  border: true,
125
117
  borderTop: true,
@@ -132,13 +124,18 @@ const runtimeUnorderedAbbreviationMap: Record<string, boolean> = {
132
124
  // outline 与 border 简写共享同一套缺省值处理
133
125
  outline: true
134
126
  }
135
- const runtimeBorderLikeShorthandMap: Record<string, boolean> = {
127
+ // 单值简写在 __getStyle 阶段经 __formatValue 把带单位长度换算为 number 后,
128
+ // 需要在 transformShorthand 入口转回字符串 token 交给展开逻辑的 key 集合。
129
+ // margin / padding / borderRadius / borderWidth / borderColor / inset 不在此列:
130
+ // RN 原生支持这些 key 直接吃单值 number,无需展开。
131
+ const runtimeNumericExpandShorthandMap: Record<string, boolean> = {
136
132
  border: true,
137
133
  borderTop: true,
138
134
  borderRight: true,
139
135
  borderBottom: true,
140
136
  borderLeft: true,
141
- outline: true
137
+ outline: true,
138
+ gap: true
142
139
  }
143
140
  // CSS border-width: medium 的实测值(各主流浏览器一致取 3px)
144
141
  // 与编译期 wx/index.js 同名常量保持一致;调整需两侧一起改
@@ -250,14 +247,12 @@ interface PercentConfig {
250
247
  fontSize?: number | string
251
248
  width?: number
252
249
  height?: number
253
- parentFontSize?: number
254
250
  parentWidth?: number
255
251
  parentHeight?: number
256
252
  }
257
253
 
258
254
  interface TransformStyleConfig {
259
255
  enableVar?: boolean
260
- parentFontSize?: number
261
256
  parentWidth?: number
262
257
  parentHeight?: number
263
258
  transformRadiusPercent?: boolean
@@ -293,6 +288,7 @@ export interface TextPassThroughValueOptions {
293
288
  export interface GestureHandler {
294
289
  nodeRefs?: Array<{ getNodeInstance: () => { nodeRef: unknown } }>
295
290
  current?: unknown
291
+ handlerTag?: number
296
292
  }
297
293
 
298
294
  // ============================================================
@@ -413,7 +409,7 @@ export function transformBoxSizing (style: Record<string, any> = {}) {
413
409
  }
414
410
  }
415
411
 
416
- export function splitStyle<T extends Record<string, any>> (styleObj: T, sideEffect?: (key: string, val: T[keyof T]) => void): {
412
+ export function splitStyle<T extends Record<string, any>> (styleObj: T = {} as T, sideEffect?: (key: string, val: T[keyof T]) => void): {
417
413
  textStyle?: Partial<T>
418
414
  backgroundStyle?: Partial<T>
419
415
  innerStyle?: Partial<T>
@@ -455,7 +451,7 @@ export function splitStyle<T extends Record<string, any>> (styleObj: T, sideEffe
455
451
  return { textStyle, backgroundStyle, innerStyle }
456
452
  }
457
453
 
458
- export function splitProps<T extends Record<string, any>> (props: T): {
454
+ export function splitProps<T extends Record<string, any>> (props: T = {} as T): {
459
455
  textProps?: Partial<T>
460
456
  innerProps?: Partial<T>
461
457
  } {
@@ -572,8 +568,8 @@ function resolvePercent (value: string | number | undefined, key: string, percen
572
568
  let base
573
569
  let reason
574
570
  if (key === 'fontSize') {
575
- base = percentConfig.parentFontSize
576
- reason = 'parent-font-size'
571
+ base = DEFAULT_FONT_SIZE
572
+ reason = 'default-font-size'
577
573
  } else if (key === 'lineHeight') {
578
574
  base = resolvePercent(percentConfig.fontSize, 'fontSize', percentConfig)
579
575
  reason = 'font-size'
@@ -924,7 +920,7 @@ function expandFlex (value: string): Array<[string, any]> | null {
924
920
  // RN 等效子集语法:font: [ <font-style> ] [ <font-variant-css2> ] [ <font-weight> ] <font-size> [ / <line-height> ] <font-family>
925
921
  // - 必填项:font-size 与 font-family;缺其一整条 font 声明丢弃(error)
926
922
  // - 非必填 token(font-stretch / 数字型 font-variant-numeric / system 关键字等):warn 提示并忽略,保留其余槽位
927
- function transformFont (styleObj: Record<string, any>, percentConfig: PercentConfig) {
923
+ function transformFont (styleObj: Record<string, any>) {
928
924
  const value = styleObj.font
929
925
  if (typeof value !== 'string') return
930
926
  const tokens = parseValues(value)
@@ -934,7 +930,7 @@ function transformFont (styleObj: Record<string, any>, percentConfig: PercentCon
934
930
  // 1. 定位 font-size(第一个 length,可能带 /<line-height>)
935
931
  // 注意:unit-less 数字也命中 length 正则,需要先排除 font-weight 数字(100..900 / bold / normal),
936
932
  // 否则 `font: 500 16px Arial` 会把 500 误判为 fontSize。
937
- // fontSize 自身可能是 %(如 `font: 50% Arial`),就地用 resolvePercent 按 parentFontSize 解析;
933
+ // fontSize 自身可能是 %(如 `font: 50% Arial`),保留给文本透传阶段按继承 fontSize 解析;
938
934
  // fontSize % 校验通过的是 `isLengthValue`(length 正则含 %),主流程已用 length 分支接住,无需特判
939
935
  for (let i = 0; i < tokens.length; i++) {
940
936
  let t = tokens[i]
@@ -952,10 +948,7 @@ function transformFont (styleObj: Record<string, any>, percentConfig: PercentCon
952
948
  if (hasOwn(fontWeightMap, sizePart)) continue
953
949
  if (isLengthValue(sizePart)) {
954
950
  sizeIdx = i
955
- const sizeVal = percentRegExp.test(sizePart)
956
- ? resolvePercent(sizePart, 'fontSize', percentConfig)
957
- : global.__formatValue(sizePart)
958
- result.push(['fontSize', sizeVal])
951
+ result.push(['fontSize', global.__formatValue(sizePart)])
959
952
  if (lhPart) lineHeight = lhPart
960
953
  break
961
954
  }
@@ -983,33 +976,17 @@ function transformFont (styleObj: Record<string, any>, percentConfig: PercentCon
983
976
  warn(`Token [${t}] in [font: ${value}] is not supported (only font-style / small-caps / font-weight are valid before <font-size>), dropped.`)
984
977
  }
985
978
  }
986
- // 3. line-height:RN lineHeight 不接受百分比字符串,必须当场数值化。
987
- // - unit-less 数字(1.5)→ '150%' 后走 resolvePercent
988
- // - 显式百分比(120%)→ 直接走 resolvePercent
989
- // - 带单位(40px / 40rpx)→ __formatValue
990
- // 基数 fontSize 取值(「长属性不覆盖简写」一致):
991
- // - user 已显式写 fontSize 长属性 → 优先(先经 __formatValue 归一 '24px' → 24)
992
- // - 否则用 font 简写解析出的 fontSize(result[0][1],已可能是 number / 解析后的 % 值)
979
+ // 3. line-height:文本透传阶段会基于当前 / 继承 fontSize 解析百分比。
980
+ // - unit-less 数字(1.5)→ '150%' 中间态,避免和已格式化 RN 绝对 number 混淆
981
+ // - 其它值(120% / 40px / 40rpx)→ __formatValue
993
982
  if (lineHeight !== undefined) {
994
- // percentConfig.fontSize 用于 resolvePercent 的 base:
995
- // - user 已显式写 fontSize 长属性 → 外层用 normalStyle.fontSize 初始化,已被前置 styleHelperMixin
996
- // 的 transformStyleObj 经 __formatValue 归一为 number,可直接用,不覆盖(「长属性优先」一致)
997
- // - 否则用 font 简写解析出的 fontSize(result[0][1],本身已 number 或解析后的 % 值)回填
998
- if (percentConfig.fontSize === undefined) percentConfig.fontSize = result[0][1]
999
- let lh: string | number | undefined
1000
- if (percentRegExp.test(lineHeight)) {
1001
- lh = resolvePercent(lineHeight, 'lineHeight', percentConfig)
1002
- } else if (!isNaN(+lineHeight)) {
1003
- lh = resolvePercent(`${+lineHeight * 100}%`, 'lineHeight', percentConfig)
1004
- } else {
1005
- lh = global.__formatValue(lineHeight)
1006
- }
1007
- // lh 仍是字符串说明 resolvePercent 因 base 非 number 原样返回(已 error 过)或带单位 __formatValue
1008
- // 未能换算成 number(如 fontSize 是未解析的 var())。RN lineHeight 不接受字符串,丢弃避免运行时报错
1009
- if (typeof lh === 'number') {
983
+ const lh = !isNaN(+lineHeight)
984
+ ? `${+lineHeight * 100}%`
985
+ : global.__formatValue(lineHeight)
986
+ if (lh !== undefined) {
1010
987
  result.push(['lineHeight', lh])
1011
988
  } else {
1012
- warn(`Line-height [${lineHeight}] in [font: ${value}] could not be resolved to a number (font-size unresolved?), dropped.`)
989
+ warn(`Line-height [${lineHeight}] in [font: ${value}] could not be resolved, dropped.`)
1013
990
  }
1014
991
  }
1015
992
  // 4. font-family(font-size 之后剩余部分;多字体取首值、去引号)
@@ -1051,19 +1028,24 @@ export function transformShorthand (styleObj: Record<string, any>, shorthandKeys
1051
1028
  let values: string[]
1052
1029
  if (typeof value === 'string') {
1053
1030
  values = parseValues(value)
1054
- } else if (value === 0 && hasOwn(runtimeBorderLikeShorthandMap, key)) {
1055
- values = ['0']
1031
+ } else if (typeof value === 'number' && hasOwn(runtimeNumericExpandShorthandMap, key)) {
1032
+ // runtimeNumericExpandShorthandMap 中的简写(border / outline / gap)在 __getStyle 的 transformStyleObj
1033
+ // 阶段已被 __formatValue 把带单位长度换算为 number;这里转回字符串 token 交给后续展开,
1034
+ // 否则会原样残留为 RN 不认识或行为不一致的简写 key。
1035
+ values = ['' + value]
1056
1036
  } else {
1057
1037
  continue
1058
1038
  }
1059
1039
  const props = runtimeAbbreviationMap[key]
1060
1040
  if (!props) continue
1061
- // 单值短路:composite 且单值通常透传(RN 原生支持 margin / padding 单值 DimensionValue);
1062
- // 但 inset / gap 必须展开(理由见 runtimeForceExpandCompositeMap 注释)
1041
+ // 单值短路:composite 且单值通常透传(RN 原生支持 margin / padding / inset / border-* 单值 DimensionValue);
1042
+ // 但 gap 必须展开 —— RN gap / rowGap / columnGap 严格要求 number,单值串虽已在 __getStyle 阶段被 __formatValue 换算,
1043
+ // 多值串(如 '10px 20px')仍会原样透传到这里,需展开后逐 token 再过 __formatValue 才能落成 number;
1044
+ // `%` 在写回阶段由 transformShorthand 调 resolvePercent 落成 number(rowGap 基 parentHeight、columnGap 基 parentWidth)
1063
1045
  if (
1064
1046
  hasOwn(runtimeCompositeStyleMap, key) &&
1065
1047
  values.length === 1 &&
1066
- !hasOwn(runtimeForceExpandCompositeMap, key)
1048
+ key !== 'gap'
1067
1049
  ) continue
1068
1050
  let expandedValues = values
1069
1051
  let pairs: Array<[string, any]>
@@ -1236,7 +1218,7 @@ export function setStyle (styleObj: Record<string, any>, keyPath: Array<string>,
1236
1218
  // core style hook
1237
1219
  // ============================================================
1238
1220
 
1239
- export function useTransformStyle (styleObj: Record<string, any> = {}, { enableVar, transformRadiusPercent, parentFontSize, parentWidth, parentHeight, defaultStyle }: TransformStyleConfig) {
1221
+ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableVar, transformRadiusPercent, parentWidth, parentHeight, defaultStyle }: TransformStyleConfig) {
1240
1222
  const varStyle: Record<string, any> = {}
1241
1223
  const unoVarStyle: Record<string, any> = {}
1242
1224
  const normalStyle: Record<string, any> = {}
@@ -1307,10 +1289,9 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
1307
1289
  // fixme 去掉 translate & border-radius 的百分比计算
1308
1290
  // fixme Image 组件 borderRadius 仅支持 number
1309
1291
  const needRadiusPercent = transformRadiusPercent && hasOwn(radiusPercentRule, key)
1310
- const needFontPercent = key === 'fontSize' || key === 'lineHeight'
1311
1292
  // RN gap / rowGap / columnGap 不支持 %,需要运行时换算为 number 喂给 RN
1312
1293
  const needGapPercent = key === 'rowGap' || key === 'columnGap'
1313
- if ((needRadiusPercent || needFontPercent || needGapPercent) && percentRegExp.test(value)) {
1294
+ if ((needRadiusPercent || needGapPercent) && percentRegExp.test(value)) {
1314
1295
  if (needRadiusPercent) hasSelfPercent = true
1315
1296
  resolvedKeyPath = resolvedKeyPath ?? keyPath.slice()
1316
1297
  percentKeyPaths.push(resolvedKeyPath)
@@ -1390,11 +1371,9 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
1390
1371
  height,
1391
1372
  fontSize: normalStyle.fontSize,
1392
1373
  parentWidth,
1393
- parentHeight,
1394
- parentFontSize
1374
+ parentHeight
1395
1375
  }
1396
- // transformFont 可能会更新 percentConfig 配置,必须在 transformPercent 之前执行,保证 fontSize / lineHeight 的百分比能被正确解析
1397
- if (hasFont) transformFont(normalStyle, percentConfig)
1376
+ if (hasFont) transformFont(normalStyle)
1398
1377
  if (percentKeyPaths.length) transformPercent(normalStyle, percentKeyPaths, percentConfig)
1399
1378
  if (calcKeyPaths.length) {
1400
1379
  transformCalc(normalStyle, calcKeyPaths, (value: string, key: string) => {
@@ -1465,6 +1444,42 @@ export function useNavigation (): Record<string, any> | undefined {
1465
1444
  return navigation
1466
1445
  }
1467
1446
 
1447
+ function getTextPercentBase (currentFontSize?: string | number, parentTextStyle?: TextStyle) {
1448
+ return typeof currentFontSize === 'number'
1449
+ ? currentFontSize
1450
+ : typeof parentTextStyle?.fontSize === 'number'
1451
+ ? parentTextStyle.fontSize
1452
+ : DEFAULT_FONT_SIZE
1453
+ }
1454
+
1455
+ export function resolveTextFontSizePercentStyle<T extends TextStyle | undefined> (
1456
+ textStyle: T,
1457
+ parentTextStyle?: TextStyle
1458
+ ): T {
1459
+ if (!textStyle) return textStyle
1460
+
1461
+ if (typeof textStyle.fontSize === 'string' && percentRegExp.test(textStyle.fontSize)) {
1462
+ const base = getTextPercentBase(undefined, parentTextStyle)
1463
+ textStyle.fontSize = parseFloat(textStyle.fontSize) / 100 * base
1464
+ }
1465
+
1466
+ return textStyle
1467
+ }
1468
+
1469
+ export function resolveTextLineHeightPercentStyle<T extends TextStyle | undefined> (
1470
+ textStyle: T,
1471
+ parentTextStyle?: TextStyle
1472
+ ): T {
1473
+ if (!textStyle) return textStyle
1474
+
1475
+ if (typeof textStyle.lineHeight === 'string' && percentRegExp.test(textStyle.lineHeight)) {
1476
+ const base = getTextPercentBase(textStyle.fontSize, parentTextStyle)
1477
+ textStyle.lineHeight = parseFloat(textStyle.lineHeight) / 100 * base
1478
+ }
1479
+
1480
+ return textStyle
1481
+ }
1482
+
1468
1483
  /**
1469
1484
  * 用法等同于 useEffect,但是会忽略首次执行,只在依赖更新时执行
1470
1485
  */
@@ -1543,8 +1558,9 @@ export function useTextPassThrough (
1543
1558
  // eslint-disable-next-line react-hooks/rules-of-hooks
1544
1559
  const valueRef = useRef<TextPassThroughContextValue | null>(null)
1545
1560
 
1546
- const nextTextStyle = textStyle
1547
- ? extendObject({}, parent?.textStyle, textStyle)
1561
+ const resolvedTextStyle = resolveTextFontSizePercentStyle(textStyle, parent?.textStyle)
1562
+ const nextTextStyle = resolvedTextStyle
1563
+ ? extendObject({}, parent?.textStyle, resolvedTextStyle)
1548
1564
  : parent?.textStyle
1549
1565
  const nextTextProps = textProps
1550
1566
  ? extendObject({}, parent?.pendingTextProps, textProps)
@@ -1561,31 +1577,6 @@ export function useTextPassThrough (
1561
1577
  return valueRef.current
1562
1578
  }
1563
1579
 
1564
- export function useTextPassThroughText (textStyle?: TextStyle) {
1565
- const inheritedText = useContext(TextPassThroughContext)
1566
- const valueRef = useRef<TextPassThroughContextValue | null>(null)
1567
-
1568
- if (!textStyle) {
1569
- return {
1570
- inheritedText,
1571
- textPassThrough: null
1572
- }
1573
- }
1574
-
1575
- const nextValue = {
1576
- textStyle: extendObject({}, inheritedText?.textStyle, textStyle)
1577
- }
1578
-
1579
- if (diffAndCloneA(valueRef.current, nextValue).diff) {
1580
- valueRef.current = nextValue
1581
- }
1582
-
1583
- return {
1584
- inheritedText,
1585
- textPassThrough: valueRef.current
1586
- }
1587
- }
1588
-
1589
1580
  export function useHover ({ enableHover, hoverStartTime, hoverStayTime, disabled }: { enableHover: boolean, hoverStartTime: number, hoverStayTime: number, disabled?: boolean }) {
1590
1581
  const enableHoverRef = useRef(enableHover)
1591
1582
  if (enableHoverRef.current !== enableHover) {
@@ -1732,7 +1723,10 @@ export function flatGesture (gestures: Array<GestureHandler> = []) {
1732
1723
  return gesture.nodeRefs
1733
1724
  .map((item: { getNodeInstance: () => any }) => item.getNodeInstance()?.instance?.gestureRef || {})
1734
1725
  }
1735
- return gesture?.current ? [gesture] : []
1726
+ if (gesture && (gesture.current || gesture.handlerTag !== undefined)) {
1727
+ return [gesture]
1728
+ }
1729
+ return []
1736
1730
  })) || []
1737
1731
  }
1738
1732
 
@@ -20,6 +20,8 @@ const { capitalToHyphen } = require('../utils/string')
20
20
  const { isNativeMiniTag } = require('../utils/dom-tag-config')
21
21
  const { offsetToLoc } = require('../utils/source-location')
22
22
 
23
+ const MPX_HOST_REF = '__mpxHost'
24
+
23
25
  const no = function () {
24
26
  return false
25
27
  }
@@ -2816,6 +2818,10 @@ function getVirtualHostRoot (options, meta) {
2816
2818
  {
2817
2819
  name: 'ishost',
2818
2820
  value: '{{true}}'
2821
+ },
2822
+ {
2823
+ name: config[mode].directive.ref,
2824
+ value: MPX_HOST_REF
2819
2825
  }
2820
2826
  ])
2821
2827
  processElement(rootView, rootView, options, meta)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.24-test.1",
3
+ "version": "2.11.0",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -29,9 +29,9 @@
29
29
  "@better-scroll/wheel": "^2.5.1",
30
30
  "@better-scroll/zoom": "^2.5.1",
31
31
  "@jridgewell/trace-mapping": "^0.3.25",
32
- "@mpxjs/perf": "^2.10.24",
32
+ "@mpxjs/perf": "^2.11.0",
33
33
  "@mpxjs/template-engine": "^2.8.7",
34
- "@mpxjs/utils": "^2.10.21",
34
+ "@mpxjs/utils": "^2.11.0",
35
35
  "acorn": "^8.11.3",
36
36
  "acorn-walk": "^7.2.0",
37
37
  "async": "^2.6.0",
@@ -93,7 +93,7 @@
93
93
  },
94
94
  "devDependencies": {
95
95
  "@d11/react-native-fast-image": "^8.6.12",
96
- "@mpxjs/api-proxy": "^2.10.21",
96
+ "@mpxjs/api-proxy": "^2.11.0",
97
97
  "@types/babel-traverse": "^6.25.4",
98
98
  "@types/babel-types": "^7.0.4",
99
99
  "@types/glob": "^8.1.0",
@@ -115,5 +115,5 @@
115
115
  "engines": {
116
116
  "node": ">=14.14.0"
117
117
  },
118
- "gitHead": "2d37697869b9bdda3efab92dda8c910b68fd05c0"
118
+ "gitHead": "14548ee8e1f00f6be64f848e4fbdab194d642bf6"
119
119
  }