@mpxjs/webpack-plugin 2.10.17 → 2.10.18

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 (238) hide show
  1. package/lib/config.js +60 -0
  2. package/lib/file-loader.js +4 -1
  3. package/lib/global.d.ts +231 -0
  4. package/lib/index.js +58 -73
  5. package/lib/init.js +3 -0
  6. package/lib/json-compiler/index.js +13 -4
  7. package/lib/loader.js +4 -0
  8. package/lib/platform/json/wx/index.js +6 -0
  9. package/lib/platform/style/wx/index.js +102 -72
  10. package/lib/platform/template/wx/component-config/ad.js +5 -0
  11. package/lib/platform/template/wx/component-config/button.js +10 -3
  12. package/lib/platform/template/wx/component-config/camera.js +13 -3
  13. package/lib/platform/template/wx/component-config/canvas.js +8 -1
  14. package/lib/platform/template/wx/component-config/cover-image.js +7 -2
  15. package/lib/platform/template/wx/component-config/cover-view.js +3 -1
  16. package/lib/platform/template/wx/component-config/form.js +27 -2
  17. package/lib/platform/template/wx/component-config/image.js +5 -0
  18. package/lib/platform/template/wx/component-config/input.js +10 -0
  19. package/lib/platform/template/wx/component-config/label.js +10 -2
  20. package/lib/platform/template/wx/component-config/map.js +11 -0
  21. package/lib/platform/template/wx/component-config/movable-area.js +4 -1
  22. package/lib/platform/template/wx/component-config/movable-view.js +17 -2
  23. package/lib/platform/template/wx/component-config/navigator.js +26 -0
  24. package/lib/platform/template/wx/component-config/picker-view.js +12 -0
  25. package/lib/platform/template/wx/component-config/picker.js +3 -1
  26. package/lib/platform/template/wx/component-config/progress.js +11 -1
  27. package/lib/platform/template/wx/component-config/rich-text.js +5 -0
  28. package/lib/platform/template/wx/component-config/scroll-view.js +12 -1
  29. package/lib/platform/template/wx/component-config/slider.js +8 -0
  30. package/lib/platform/template/wx/component-config/swiper-item.js +5 -2
  31. package/lib/platform/template/wx/component-config/swiper.js +10 -0
  32. package/lib/platform/template/wx/component-config/text.js +5 -0
  33. package/lib/platform/template/wx/component-config/textarea.js +19 -2
  34. package/lib/platform/template/wx/component-config/unsupported.js +9 -0
  35. package/lib/platform/template/wx/component-config/video.js +10 -0
  36. package/lib/platform/template/wx/index.js +21 -1
  37. package/lib/react/LoadAsyncChunkModule.js +1 -1
  38. package/lib/react/processStyles.js +21 -9
  39. package/lib/react/script-helper.js +2 -2
  40. package/lib/react/style-helper.js +76 -13
  41. package/lib/resolver/AddModePlugin.js +17 -7
  42. package/lib/runtime/components/react/animationHooks/index.ts +75 -0
  43. package/lib/runtime/components/react/animationHooks/useAnimationAPIHooks.ts +197 -0
  44. package/lib/runtime/components/react/animationHooks/useTransitionHooks.ts +301 -0
  45. package/lib/runtime/components/react/animationHooks/utils.ts +197 -0
  46. package/lib/runtime/components/react/context.ts +12 -3
  47. package/lib/runtime/components/react/dist/animationHooks/index.d.ts +15 -0
  48. package/lib/runtime/components/react/dist/animationHooks/index.js +67 -0
  49. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts +3 -0
  50. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.js +181 -0
  51. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts +3 -0
  52. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.js +279 -0
  53. package/lib/runtime/components/react/dist/animationHooks/utils.d.ts +109 -0
  54. package/lib/runtime/components/react/dist/animationHooks/utils.js +151 -0
  55. package/lib/runtime/components/react/dist/context.d.ts +10 -3
  56. package/lib/runtime/components/react/dist/context.js +1 -2
  57. package/lib/runtime/components/react/dist/event.config.d.ts +0 -1
  58. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +0 -1
  59. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +0 -1
  60. package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +3 -1
  61. package/lib/runtime/components/react/dist/mpx-button.d.ts +0 -1
  62. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +0 -1
  63. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +0 -1
  64. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +0 -1
  65. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +0 -1
  66. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +0 -1
  67. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +0 -1
  68. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +0 -1
  69. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +0 -1
  70. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +0 -1
  71. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +0 -1
  72. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +0 -1
  73. package/lib/runtime/components/react/dist/mpx-form.d.ts +0 -1
  74. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +0 -1
  75. package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -1
  76. package/lib/runtime/components/react/dist/mpx-image.jsx +2 -2
  77. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +0 -1
  78. package/lib/runtime/components/react/dist/mpx-input.d.ts +2 -1
  79. package/lib/runtime/components/react/dist/mpx-input.jsx +66 -50
  80. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +0 -1
  81. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +35 -6
  82. package/lib/runtime/components/react/dist/mpx-label.d.ts +0 -1
  83. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +0 -1
  84. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +0 -1
  85. package/lib/runtime/components/react/dist/mpx-nav.d.ts +0 -1
  86. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +0 -1
  87. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +0 -1
  88. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +0 -1
  89. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +0 -1
  90. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +0 -1
  91. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +0 -1
  92. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +0 -1
  93. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +0 -1
  94. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +0 -1
  95. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +0 -1
  96. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +0 -1
  97. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +0 -1
  98. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +0 -1
  99. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +0 -1
  100. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +0 -1
  101. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +0 -1
  102. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +0 -1
  103. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +0 -1
  104. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +0 -1
  105. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +0 -1
  106. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +0 -1
  107. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +0 -1
  108. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +0 -1
  109. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +2 -2
  110. package/lib/runtime/components/react/dist/mpx-progress.d.ts +0 -1
  111. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +0 -1
  112. package/lib/runtime/components/react/dist/mpx-radio.d.ts +0 -1
  113. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +0 -1
  114. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +0 -1
  115. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +0 -1
  116. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +0 -1
  117. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +84 -78
  118. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +0 -1
  119. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +0 -1
  120. package/lib/runtime/components/react/dist/mpx-slider.d.ts +0 -1
  121. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +0 -1
  122. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +20 -20
  123. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +0 -1
  124. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +0 -1
  125. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +10 -1
  126. package/lib/runtime/components/react/dist/mpx-swiper.jsx +95 -61
  127. package/lib/runtime/components/react/dist/mpx-switch.d.ts +0 -1
  128. package/lib/runtime/components/react/dist/mpx-text.d.ts +0 -1
  129. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +0 -1
  130. package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -0
  131. package/lib/runtime/components/react/dist/mpx-video.d.ts +0 -1
  132. package/lib/runtime/components/react/dist/mpx-view.d.ts +3 -3
  133. package/lib/runtime/components/react/dist/mpx-view.jsx +22 -8
  134. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +0 -1
  135. package/lib/runtime/components/react/dist/parser.d.ts +0 -1
  136. package/lib/runtime/components/react/dist/useNodesRef.d.ts +0 -1
  137. package/lib/runtime/components/react/dist/utils.d.ts +10 -9
  138. package/lib/runtime/components/react/dist/utils.jsx +47 -24
  139. package/lib/runtime/components/react/mpx-async-suspense.tsx +3 -1
  140. package/lib/runtime/components/react/mpx-image.tsx +2 -2
  141. package/lib/runtime/components/react/mpx-input.tsx +77 -54
  142. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +35 -6
  143. package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +2 -2
  144. package/lib/runtime/components/react/mpx-scroll-view.tsx +110 -114
  145. package/lib/runtime/components/react/mpx-sticky-header.tsx +24 -24
  146. package/lib/runtime/components/react/mpx-swiper.tsx +115 -60
  147. package/lib/runtime/components/react/mpx-textarea.tsx +1 -0
  148. package/lib/runtime/components/react/mpx-view.tsx +27 -12
  149. package/lib/runtime/components/react/tsconfig.json +26 -0
  150. package/lib/runtime/components/react/types/global.d.ts +1 -0
  151. package/lib/runtime/components/react/utils.tsx +51 -27
  152. package/lib/runtime/optionProcessor.js +5 -0
  153. package/lib/runtime/optionProcessorReact.js +7 -0
  154. package/lib/runtime/stringify.wxs +2 -2
  155. package/lib/script-setup-compiler/index.js +1 -2
  156. package/lib/style-compiler/strip-conditional.js +243 -0
  157. package/lib/template-compiler/compiler.js +2 -5
  158. package/lib/utils/string.js +25 -1
  159. package/lib/wxss/loader.js +4 -1
  160. package/lib/wxss/utils.js +7 -2
  161. package/package.json +7 -14
  162. package/lib/runtime/components/react/dist/context.d.ts.map +0 -1
  163. package/lib/runtime/components/react/dist/event.config.d.ts.map +0 -1
  164. package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +0 -1
  165. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +0 -1
  166. package/lib/runtime/components/react/dist/mpx-button.d.ts.map +0 -1
  167. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +0 -1
  168. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +0 -1
  169. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +0 -1
  170. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +0 -1
  171. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +0 -1
  172. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +0 -1
  173. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +0 -1
  174. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +0 -1
  175. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +0 -1
  176. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +0 -1
  177. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +0 -1
  178. package/lib/runtime/components/react/dist/mpx-form.d.ts.map +0 -1
  179. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +0 -1
  180. package/lib/runtime/components/react/dist/mpx-image.d.ts.map +0 -1
  181. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +0 -1
  182. package/lib/runtime/components/react/dist/mpx-input.d.ts.map +0 -1
  183. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +0 -1
  184. package/lib/runtime/components/react/dist/mpx-label.d.ts.map +0 -1
  185. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +0 -1
  186. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +0 -1
  187. package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +0 -1
  188. package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +0 -1
  189. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +0 -1
  190. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +0 -1
  191. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +0 -1
  192. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +0 -1
  193. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +0 -1
  194. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +0 -1
  195. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +0 -1
  196. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +0 -1
  197. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +0 -1
  198. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +0 -1
  199. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +0 -1
  200. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +0 -1
  201. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +0 -1
  202. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +0 -1
  203. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +0 -1
  204. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +0 -1
  205. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +0 -1
  206. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +0 -1
  207. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +0 -1
  208. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +0 -1
  209. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +0 -1
  210. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +0 -1
  211. package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +0 -1
  212. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +0 -1
  213. package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +0 -1
  214. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +0 -1
  215. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +0 -1
  216. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +0 -1
  217. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +0 -1
  218. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +0 -1
  219. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +0 -1
  220. package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +0 -1
  221. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +0 -1
  222. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +0 -1
  223. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +0 -1
  224. package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +0 -1
  225. package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +0 -1
  226. package/lib/runtime/components/react/dist/mpx-text.d.ts.map +0 -1
  227. package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +0 -1
  228. package/lib/runtime/components/react/dist/mpx-video.d.ts.map +0 -1
  229. package/lib/runtime/components/react/dist/mpx-view.d.ts.map +0 -1
  230. package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +0 -1
  231. package/lib/runtime/components/react/dist/parser.d.ts.map +0 -1
  232. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +0 -33
  233. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +0 -1
  234. package/lib/runtime/components/react/dist/useAnimationHooks.js +0 -289
  235. package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +0 -1
  236. package/lib/runtime/components/react/dist/utils.d.ts.map +0 -1
  237. package/lib/runtime/components/react/useAnimationHooks.ts +0 -320
  238. package/lib/style-compiler/strip-conditional-loader.js +0 -289
@@ -4,9 +4,8 @@ import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn } fr
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'
7
- import FastImage, { FastImageProps } from '@d11/react-native-fast-image'
7
+ import type { FastImageProps } from '@d11/react-native-fast-image'
8
8
  import type { AnyFunc, ExtendedFunctionComponent } from './types/common'
9
- import { runOnJS } from 'react-native-reanimated'
10
9
  import { Gesture } from 'react-native-gesture-handler'
11
10
 
12
11
  export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/
@@ -31,6 +30,7 @@ const varUseRegExp = /var\(/
31
30
  const unoVarDecRegExp = /^--un-/
32
31
  const unoVarUseRegExp = /var\(--un-/
33
32
  const calcUseRegExp = /calc\(/
33
+ const calcPercentExp = /^calc\(.*-?\d+(\.\d+)?%.*\)$/
34
34
  const envUseRegExp = /env\(/
35
35
  const filterRegExp = /(calc|env|%)/
36
36
 
@@ -41,6 +41,8 @@ const safeAreaInsetMap: Record<string, 'top' | 'right' | 'bottom' | 'left'> = {
41
41
  'safe-area-inset-left': 'left'
42
42
  }
43
43
 
44
+ export const extendObject = Object.assign
45
+
44
46
  function getSafeAreaInset (name: string, navigation: Record<string, any> | undefined) {
45
47
  const insets = extendObject({}, initialWindowMetrics?.insets, navigation?.insets)
46
48
  return insets[safeAreaInsetMap[name]]
@@ -143,16 +145,17 @@ export function splitStyle<T extends Record<string, any>> (styleObj: T): {
143
145
  innerStyle: Partial<T>
144
146
  }
145
147
  }
146
-
147
- const selfPercentRule: Record<string, 'height' | 'width'> = {
148
- translateX: 'width',
149
- translateY: 'height',
148
+ const radiusPercentRule: Record<string, 'height' | 'width'> = {
150
149
  borderTopLeftRadius: 'width',
151
150
  borderBottomLeftRadius: 'width',
152
151
  borderBottomRightRadius: 'width',
153
152
  borderTopRightRadius: 'width',
154
153
  borderRadius: 'width'
155
154
  }
155
+ const selfPercentRule: Record<string, 'height' | 'width'> = extendObject({
156
+ translateX: 'width',
157
+ translateY: 'height'
158
+ }, radiusPercentRule)
156
159
 
157
160
  const parentHeightPercentRule: Record<string, boolean> = {
158
161
  height: true,
@@ -216,16 +219,22 @@ function resolveVar (input: string, varContext: Record<string, any>) {
216
219
  const replaced = new ReplaceSource(input)
217
220
 
218
221
  for (const { start, end, args } of parsed) {
222
+ // NOTE:
223
+ // - CSS var() fallback 允许包含空格、逗号等字符(如 font-family 的 fallback)
224
+ // - parseFunc 会按逗号分割 args,因此这里把 args[1..] 重新 join 回 fallback
219
225
  const varName = args[0]
220
- const fallback = args[1]
221
- let varValue = hasOwn(varContext, varName) ? varContext[varName] : fallback
222
- if (varValue === undefined) return
223
- if (varUseRegExp.test(varValue)) {
224
- varValue = resolveVar(varValue, varContext)
225
- if (varValue === undefined) return
226
- } else {
227
- varValue = global.__formatValue(varValue)
226
+ const fallback: string | undefined = args.length > 1 ? args.slice(1).join(',').trim() : undefined
227
+
228
+ // 先处理 varValue
229
+ let varValue = hasOwn(varContext, varName) ? varContext[varName] : undefined
230
+ if (varValue !== undefined) {
231
+ varValue = varUseRegExp.test(varValue) ? resolveVar(varValue, varContext) : global.__formatValue(varValue)
232
+ }
233
+ // 再处理 fallback
234
+ if (varValue === undefined && fallback !== undefined) {
235
+ varValue = varUseRegExp.test(fallback) ? resolveVar(fallback, varContext) : global.__formatValue(fallback)
228
236
  }
237
+ if (varValue === undefined) return
229
238
  replaced.replace(start, end - 1, varValue)
230
239
  }
231
240
 
@@ -288,6 +297,10 @@ function transformStringify (styleObj: Record<string, any>) {
288
297
  if (isNumber(styleObj.fontWeight)) {
289
298
  styleObj.fontWeight = '' + styleObj.fontWeight
290
299
  }
300
+ // transformOrigin 20px 需要转换为 transformOrigin '20'
301
+ if (isNumber(styleObj.transformOrigin)) {
302
+ styleObj.transformOrigin = '' + styleObj.transformOrigin
303
+ }
291
304
  }
292
305
 
293
306
  function transformPosition (styleObj: Record<string, any>, meta: PositionMeta) {
@@ -297,7 +310,7 @@ function transformPosition (styleObj: Record<string, any>, meta: PositionMeta) {
297
310
  }
298
311
  }
299
312
  // 多value解析
300
- function parseValues (str: string, char = ' ') {
313
+ export function parseValues (str: string, char = ' ') {
301
314
  let stack = 0
302
315
  let temp = ''
303
316
  const result = []
@@ -308,11 +321,11 @@ function parseValues (str: string, char = ' ') {
308
321
  stack--
309
322
  }
310
323
  // 非括号内 或者 非分隔字符且非空
311
- if (stack !== 0 || (str[i] !== char && str[i] !== ' ')) {
324
+ if (stack !== 0 || str[i] !== char) {
312
325
  temp += str[i]
313
326
  }
314
327
  if ((stack === 0 && str[i] === char) || i === str.length - 1) {
315
- result.push(temp)
328
+ result.push(temp.trim())
316
329
  temp = ''
317
330
  }
318
331
  }
@@ -321,6 +334,8 @@ function parseValues (str: string, char = ' ') {
321
334
  // parse string transform, eg: transform: 'rotateX(45deg) rotateZ(0.785398rad)'
322
335
  function parseTransform (transformStr: string) {
323
336
  const values = parseValues(transformStr)
337
+ // Todo transform 排序不一致时,transform动画会闪烁,故这里同样的排序输出 transform
338
+ values.sort()
324
339
  const transform: { [propName: string]: string | number | number[] }[] = []
325
340
  values.forEach(item => {
326
341
  const match = item.match(/([/\w]+)\((.+)\)/)
@@ -390,9 +405,10 @@ interface TransformStyleConfig {
390
405
  parentFontSize?: number
391
406
  parentWidth?: number
392
407
  parentHeight?: number
408
+ transformRadiusPercent?: boolean
393
409
  }
394
410
 
395
- export function useTransformStyle (styleObj: Record<string, any> = {}, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight }: TransformStyleConfig) {
411
+ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableVar, transformRadiusPercent, externalVarContext, parentFontSize, parentWidth, parentHeight }: TransformStyleConfig) {
396
412
  const varStyle: Record<string, any> = {}
397
413
  const unoVarStyle: Record<string, any> = {}
398
414
  const normalStyle: Record<string, any> = {}
@@ -440,14 +456,21 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
440
456
  }
441
457
  }
442
458
 
443
- function calcVisitor ({ value, keyPath }: VisitorArg) {
459
+ function calcVisitor ({ key, value, keyPath }: VisitorArg) {
444
460
  if (calcUseRegExp.test(value)) {
461
+ // calc translate & border-radius 的百分比计算
462
+ if (hasOwn(selfPercentRule, key) && calcPercentExp.test(value)) {
463
+ hasSelfPercent = true
464
+ percentKeyPaths.push(keyPath.slice())
465
+ }
445
466
  calcKeyPaths.push(keyPath.slice())
446
467
  }
447
468
  }
448
469
 
449
470
  function percentVisitor ({ key, value, keyPath }: VisitorArg) {
450
- if (hasOwn(selfPercentRule, key) && PERCENT_REGEX.test(value)) {
471
+ // fixme 去掉 translate & border-radius 的百分比计算
472
+ // fixme Image 组件 borderRadius 仅支持 number
473
+ if (transformRadiusPercent && hasOwn(radiusPercentRule, key) && PERCENT_REGEX.test(value)) {
451
474
  hasSelfPercent = true
452
475
  percentKeyPaths.push(keyPath.slice())
453
476
  } else if ((key === 'fontSize' || key === 'lineHeight') && PERCENT_REGEX.test(value)) {
@@ -463,7 +486,6 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
463
486
 
464
487
  // traverse var & generate normalStyle
465
488
  traverseStyle(styleObj, [varVisitor])
466
-
467
489
  hasVarDec = hasVarDec || !!externalVarContext
468
490
  enableVar = enableVar || hasVarDec || hasVarUse
469
491
  const enableVarRef = useRef(enableVar)
@@ -527,8 +549,7 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
527
549
  transformStringify(normalStyle)
528
550
  // transform rpx to px
529
551
  transformBoxShadow(normalStyle)
530
-
531
- // transform 字符串格式转化数组格式
552
+ // transform 字符串格式转化数组格式(先转数组再处理css var)
532
553
  transformTransform(normalStyle)
533
554
 
534
555
  return {
@@ -726,8 +747,6 @@ export function flatGesture (gestures: Array<GestureHandler> = []) {
726
747
  })) || []
727
748
  }
728
749
 
729
- export const extendObject = Object.assign
730
-
731
750
  export function getCurrentPage (pageId: number | null | undefined) {
732
751
  if (!global.getCurrentPages) return
733
752
  const pages = global.getCurrentPages()
@@ -736,9 +755,14 @@ export function getCurrentPage (pageId: number | null | undefined) {
736
755
 
737
756
  export function renderImage (
738
757
  imageProps: ImageProps | FastImageProps,
739
- enableFastImage = false
758
+ enableFastImage = true
740
759
  ) {
741
- const Component: React.ComponentType<ImageProps | FastImageProps> = enableFastImage ? FastImage : Image
760
+ let Component: React.ComponentType<ImageProps | FastImageProps> = Image
761
+ if (enableFastImage) {
762
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
763
+ const fastImageModule = require('@d11/react-native-fast-image')
764
+ Component = fastImageModule.default || fastImageModule
765
+ }
742
766
  return createElement(Component, imageProps)
743
767
  }
744
768
 
@@ -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
+ }
@@ -605,8 +605,7 @@ function compileScriptSetup (
605
605
  if (node.key.name === 'properties' && hasDefinePropsCall) {
606
606
  console.warn(`${DEFINE_PROPS} has been called, ${DEFINE_OPTIONS} set properties will be ignored`)
607
607
  } else {
608
- const declCode = content.slice(node.value.start, node.value.end).trim()
609
- runtimeOptions += `\n ${node.key.name}: ${declCode},`
608
+ runtimeOptions += `\n ${content.slice(node.start, node.end).trim()},`
610
609
  }
611
610
  }
612
611
  }
@@ -0,0 +1,243 @@
1
+ const fs = require('fs')
2
+
3
+ class Node {
4
+ constructor(type, condition = null) {
5
+ this.type = type // 'If', 'ElseIf', 'Else' 或 'Text'
6
+ this.condition = condition // If 或 Elif 的条件
7
+ this.children = []
8
+ this.value = ''
9
+ }
10
+ }
11
+
12
+ // 提取 css string 为 token
13
+ function tokenize(cssString) {
14
+ // Support /* ... */, // ..., and <!-- ... --> styles
15
+ // 1. : /\/\*\s*@mpx-(if|elif|else|endif)(?:\s*\(([\s\S]*?)\))?\s*\*\//g
16
+ // 2. : /\/\/\s*@mpx-(if|elif|else|endif)(?:\s*\((.*?)\))?\s*$/gm
17
+ // 3. : /<!--\s*@mpx-(if|elif|else|endif)(?:\s*\(([\s\S]*?)\))?\s*-->/g
18
+ // Combined:
19
+ const regex = /(?:\/\*\s*@mpx-(if|elif|else|endif)(?:\s*\(([\s\S]*?)\))?\s*\*\/)|(?:\/\/\s*@mpx-(if|elif|else|endif)(?:\s*\((.*?)\))?\s*)|(?:<!--\s*@mpx-(if|elif|else|endif)(?:\s*\(([\s\S]*?)\))?\s*-->)/g
20
+ const tokens = []
21
+ let lastIndex = 0
22
+ let match
23
+
24
+ while ((match = regex.exec(cssString)) !== null) {
25
+ // 如果 token 前有普通文本,生成文本 token
26
+ if (match.index > lastIndex) {
27
+ const text = cssString.substring(lastIndex, match.index)
28
+ tokens.push({ type: 'text', content: text })
29
+ }
30
+ // 1,2: (/* ... */)
31
+ // 3,4: (// ...)
32
+ // 5,6: (<!-- ... -->)
33
+ const type = match[1] || match[3] || match[5]
34
+ const condition = (match[2] || match[4] || match[6])
35
+
36
+ tokens.push({
37
+ type: type,
38
+ condition: condition ? condition.trim() : null
39
+ })
40
+ lastIndex = regex.lastIndex
41
+ }
42
+ // 处理结尾剩余的文本
43
+ if (lastIndex < cssString.length) {
44
+ const text = cssString.substring(lastIndex)
45
+ tokens.push({ type: 'text', content: text })
46
+ }
47
+ return tokens
48
+ }
49
+
50
+ // parse:将生成的 token 数组构造成嵌套的 AST
51
+ function parse(cssString) {
52
+ const tokens = tokenize(cssString)
53
+ const ast = []
54
+ const nodeStack = []
55
+ let currentChildren = ast
56
+ tokens.forEach(token => {
57
+ if (token.type === 'text') {
58
+ const node = new Node('Text')
59
+ node.value = token.content
60
+ currentChildren.push(node)
61
+ } else if (token.type === 'if') {
62
+ const node = new Node('If', token.condition)
63
+ currentChildren.push(node)
64
+ nodeStack.push(currentChildren)
65
+ currentChildren = node.children
66
+ } else if (token.type === 'elif') {
67
+ if (nodeStack.length === 0) {
68
+ throw new Error('[Mpx style error]: elif without a preceding if')
69
+ }
70
+ currentChildren = nodeStack[nodeStack.length - 1]
71
+ const node = new Node('ElseIf', token.condition)
72
+ currentChildren.push(node)
73
+ currentChildren = node.children
74
+ } else if (token.type === 'else') {
75
+ if (nodeStack.length === 0) {
76
+ throw new Error('[Mpx style error]: else without a preceding if')
77
+ }
78
+ currentChildren = nodeStack[nodeStack.length - 1]
79
+ const node = new Node('Else')
80
+ currentChildren.push(node)
81
+ currentChildren = node.children
82
+ } else if (token.type === 'endif') {
83
+ if (nodeStack.length > 0) {
84
+ currentChildren = nodeStack.pop()
85
+ }
86
+ }
87
+ })
88
+ if (nodeStack.length > 0) {
89
+ throw new Error('[Mpx strip conditional error]: mpx-if without a matching endif')
90
+ }
91
+ return ast
92
+ }
93
+
94
+ function evaluateCondition(condition, defs) {
95
+ try {
96
+ const keys = Object.keys(defs)
97
+ const values = keys.map(key => defs[key])
98
+ /* eslint-disable no-new-func */
99
+ const func = new Function(...keys, `return (${condition});`)
100
+ return func(...values)
101
+ } catch (e) {
102
+ console.error(`[Mpx style error]:Error evaluating condition: ${condition}`, e)
103
+ return false
104
+ }
105
+ }
106
+
107
+ function traverseAndEvaluate(ast, defs) {
108
+ let output = ''
109
+ let batchedIf = false
110
+ function traverse(nodes) {
111
+ for (const node of nodes) {
112
+ if (node.type === 'Text') {
113
+ output += node.value
114
+ } else if (node.type === 'If') {
115
+ // 直接判断 If 节点
116
+ batchedIf = false
117
+ if (evaluateCondition(node.condition, defs)) {
118
+ traverse(node.children)
119
+ batchedIf = true
120
+ }
121
+ } else if (node.type === 'ElseIf' && !batchedIf) {
122
+ if (evaluateCondition(node.condition, defs)) {
123
+ traverse(node.children)
124
+ batchedIf = true
125
+ }
126
+ } else if (node.type === 'Else' && !batchedIf) {
127
+ traverse(node.children)
128
+ }
129
+ }
130
+ }
131
+ traverse(ast)
132
+ return output
133
+ }
134
+
135
+ /**
136
+ *
137
+ * @param {string} content
138
+ * @param {Record<string, any>} defs
139
+ * @returns
140
+ */
141
+ function stripCondition(content, defs) {
142
+ const ast = parse(content)
143
+ return traverseAndEvaluate(ast, defs)
144
+ }
145
+
146
+ let proxyReadFileSync
147
+ let proxyReadFile
148
+ const rawReadFileSync = fs.readFileSync
149
+ const rawReadFile = fs.readFile
150
+
151
+ let isRewritten = false
152
+ let __compilation = null
153
+
154
+ function registerStripCompilation(compilation) {
155
+ __compilation = compilation
156
+ }
157
+
158
+ function logStripError(path, e) {
159
+ const msg = `[Mpx strip conditional error]\n path: ${path}\n message: ${e && e.message}\n stack:\n${e && e.stack}`
160
+ console.error(msg)
161
+ if (__compilation && Array.isArray(__compilation.errors)) {
162
+ const err = new Error(msg)
163
+ err.file = path
164
+ __compilation.errors.push(err)
165
+ }
166
+ }
167
+
168
+ function rewriteFSForCss() {
169
+ if (isRewritten) return
170
+ isRewritten = true
171
+ fs.readFileSync = function () {
172
+ return (proxyReadFileSync || rawReadFileSync).apply(fs, arguments)
173
+ }
174
+ fs.readFile = function () {
175
+ return (proxyReadFile || rawReadFile).apply(fs, arguments)
176
+ }
177
+ }
178
+
179
+ function startFSStripForCss(defs) {
180
+ function shouldStrip(path) {
181
+ return typeof path === 'string' && /\.(styl|scss|sass|less|css|mpx)$/.test(path)
182
+ }
183
+ proxyReadFileSync = function (path, options) {
184
+ const content = rawReadFileSync.call(fs, path, options)
185
+ if (shouldStrip(path)) {
186
+ try {
187
+ if (typeof content === 'string') {
188
+ return stripCondition(content, defs)
189
+ } else if (Buffer.isBuffer(content)) {
190
+ const str = content.toString('utf-8')
191
+ const result = stripCondition(str, defs)
192
+ if (result !== str) {
193
+ return Buffer.from(result, 'utf-8')
194
+ }
195
+ }
196
+ } catch (e) {
197
+ logStripError(path, e)
198
+ return content
199
+ }
200
+ }
201
+ return content
202
+ }
203
+
204
+ proxyReadFile = function () {
205
+ const args = Array.from(arguments)
206
+ const callback = args[args.length - 1]
207
+ const path = args[0]
208
+
209
+ if (typeof callback !== 'function') {
210
+ return rawReadFile.apply(fs, args)
211
+ }
212
+
213
+ const wrappedCallback = (err, data) => {
214
+ if (err) return callback(err)
215
+ if (shouldStrip(path)) {
216
+ try {
217
+ if (typeof data === 'string') {
218
+ const result = stripCondition(data, defs)
219
+ return callback(null, result)
220
+ } else if (Buffer.isBuffer(data)) {
221
+ const content = data.toString('utf-8')
222
+ const result = stripCondition(content, defs)
223
+ if (result !== content) {
224
+ return callback(null, Buffer.from(result, 'utf-8'))
225
+ }
226
+ }
227
+ } catch (e) {
228
+ logStripError(path, e)
229
+ return callback(null, data)
230
+ }
231
+ }
232
+ callback(null, data)
233
+ }
234
+
235
+ args[args.length - 1] = wrappedCallback
236
+ return rawReadFile.apply(fs, args)
237
+ }
238
+ }
239
+
240
+ module.exports.stripCondition = stripCondition
241
+ module.exports.rewriteFSForCss = rewriteFSForCss
242
+ module.exports.startFSStripForCss = startFSStripForCss
243
+ module.exports.registerStripCompilation = registerStripCompilation
@@ -764,9 +764,7 @@ function parse (template, options) {
764
764
 
765
765
  const children = currentParent.children
766
766
 
767
- const isTextLikeParent = currentParent.tag === 'text' || currentParent.tag === 'mpx-text' || currentParent.tag === 'Text' || currentParent.tag === 'mpx-simple-text'
768
-
769
- if (!isTextLikeParent) {
767
+ if (currentParent.tag !== 'text') {
770
768
  text = text.trim()
771
769
  } else {
772
770
  text = text.trim() ? text : ''
@@ -2247,7 +2245,6 @@ function postProcessIfReact (el) {
2247
2245
  delete el.elseif
2248
2246
  el._if = true
2249
2247
  addIfCondition(ifNode, {
2250
- exp: el.elseif.exp,
2251
2248
  block: el
2252
2249
  })
2253
2250
  removeNode(el, true)
@@ -2720,7 +2717,7 @@ function postProcessTemplate (el) {
2720
2717
  }
2721
2718
  }
2722
2719
 
2723
- const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd,tenon,ios,android,harmony,noMode')
2720
+ const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd,tenon,ios,android,harmony,ks,noMode')
2724
2721
 
2725
2722
  function isValidModeP (i) {
2726
2723
  return isValidMode(i[0] === '_' ? i.slice(1) : i)
@@ -28,9 +28,33 @@ function trimBlankRow (str) {
28
28
  return str.replace(/^\s*[\r\n]/gm, '')
29
29
  }
30
30
 
31
+ // 多value解析
32
+ function parseValues (str, char = ' ') {
33
+ let stack = 0
34
+ let temp = ''
35
+ const result = []
36
+ for (let i = 0; i < str.length; i++) {
37
+ if (str[i] === '(') {
38
+ stack++
39
+ } else if (str[i] === ')') {
40
+ stack--
41
+ }
42
+ // 非括号内 或者 非分隔字符且非空
43
+ if (stack !== 0 || str[i] !== char) {
44
+ temp += str[i]
45
+ }
46
+ if ((stack === 0 && str[i] === char) || i === str.length - 1) {
47
+ result.push(temp.trim())
48
+ temp = ''
49
+ }
50
+ }
51
+ return result
52
+ }
53
+
31
54
  module.exports = {
32
55
  isCapital,
33
56
  isMustache,
34
57
  capitalToHyphen,
35
- trimBlankRow
58
+ trimBlankRow,
59
+ parseValues
36
60
  }
@@ -92,6 +92,9 @@ module.exports = async function loader (content, map, meta) {
92
92
  filter: options.import.filter,
93
93
  urlHandler: (url) => {
94
94
  url = combineRequests(getPreRequester(this)(options.importLoaders), url)
95
+ if (isRN) {
96
+ return stringifyRequest(this, url)
97
+ }
95
98
  return getRequestString('styles', { src: url }, {
96
99
  isStatic: true,
97
100
  issuerResource: this.resource,
@@ -249,7 +252,7 @@ module.exports = async function loader (content, map, meta) {
249
252
  let moduleCode
250
253
 
251
254
  try {
252
- moduleCode = getModuleCode(result, api, replacements, options, this)
255
+ moduleCode = getModuleCode(result, api, replacements, options, isRN, this)
253
256
  } catch (error) {
254
257
  callback(error)
255
258
 
package/lib/wxss/utils.js CHANGED
@@ -1016,6 +1016,7 @@ function getModuleCode (
1016
1016
  api,
1017
1017
  replacements,
1018
1018
  options,
1019
+ isRN,
1019
1020
  loaderContext
1020
1021
  ) {
1021
1022
  if (options.modules.exportOnlyLocals === true) {
@@ -1054,8 +1055,12 @@ function getModuleCode (
1054
1055
  } else {
1055
1056
  // 符合css后缀名的文件经过mpx处理后会带上相应的后缀防止使用 webpack 的默认解析规则,此时 require/import 相应路径时,导出的不是一段 css 代码了,事实上是一个文件路径。
1056
1057
  const printedParam = printParams(media, dedupe, supports, layer)
1057
- const otherParams = printedParam.length > 0 ? printedParam : ''
1058
- beforeCode += `___CSS_LOADER_EXPORT___.push([module.id, '@import "' + ${item.importName} + '";', ${JSON.stringify(otherParams)} ]);\n`
1058
+ const hasParams = printedParam.length > 0
1059
+ if (isRN) {
1060
+ beforeCode += `___CSS_LOADER_EXPORT___.i(${item.importName}${hasParams ? `, ${printedParam}` : ''});\n`
1061
+ } else {
1062
+ beforeCode += `___CSS_LOADER_EXPORT___.push([module.id, '@import "' + ${item.importName} + '";'${hasParams ? `, ${printedParam}` : ''}]);\n`
1063
+ }
1059
1064
  }
1060
1065
  }
1061
1066