@mpxjs/webpack-plugin 2.10.17 → 2.10.18-beta.2

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 (262) 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 +70 -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 +25 -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 +10 -1
  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/resolver/ExtendComponentsPlugin.js +60 -0
  43. package/lib/runtime/components/ali/mpx-section-list.mpx +566 -0
  44. package/lib/runtime/components/ali/mpx-sticky-header.mpx +212 -0
  45. package/lib/runtime/components/ali/mpx-sticky-section.mpx +17 -0
  46. package/lib/runtime/components/react/animationHooks/index.ts +75 -0
  47. package/lib/runtime/components/react/animationHooks/useAnimationAPIHooks.ts +197 -0
  48. package/lib/runtime/components/react/animationHooks/useTransitionHooks.ts +301 -0
  49. package/lib/runtime/components/react/animationHooks/utils.ts +197 -0
  50. package/lib/runtime/components/react/context.ts +12 -3
  51. package/lib/runtime/components/react/dist/animationHooks/index.d.ts +15 -0
  52. package/lib/runtime/components/react/dist/animationHooks/index.js +67 -0
  53. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts +3 -0
  54. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.js +181 -0
  55. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts +3 -0
  56. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.js +279 -0
  57. package/lib/runtime/components/react/dist/animationHooks/utils.d.ts +109 -0
  58. package/lib/runtime/components/react/dist/animationHooks/utils.js +151 -0
  59. package/lib/runtime/components/react/dist/context.d.ts +10 -3
  60. package/lib/runtime/components/react/dist/context.js +1 -2
  61. package/lib/runtime/components/react/dist/event.config.d.ts +0 -1
  62. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +0 -1
  63. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +0 -1
  64. package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +3 -1
  65. package/lib/runtime/components/react/dist/mpx-button.d.ts +0 -1
  66. package/lib/runtime/components/react/dist/mpx-camera.d.ts +31 -0
  67. package/lib/runtime/components/react/dist/mpx-camera.jsx +236 -0
  68. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +0 -1
  69. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +0 -1
  70. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +0 -1
  71. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +0 -1
  72. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +0 -1
  73. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +0 -1
  74. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +0 -1
  75. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +0 -1
  76. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +0 -1
  77. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +0 -1
  78. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +0 -1
  79. package/lib/runtime/components/react/dist/mpx-form.d.ts +0 -1
  80. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +0 -1
  81. package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -1
  82. package/lib/runtime/components/react/dist/mpx-image.jsx +2 -2
  83. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +0 -1
  84. package/lib/runtime/components/react/dist/mpx-input.d.ts +2 -1
  85. package/lib/runtime/components/react/dist/mpx-input.jsx +66 -50
  86. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +0 -1
  87. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +35 -6
  88. package/lib/runtime/components/react/dist/mpx-label.d.ts +0 -1
  89. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +0 -1
  90. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +0 -1
  91. package/lib/runtime/components/react/dist/mpx-nav.d.ts +0 -1
  92. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +0 -1
  93. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +0 -1
  94. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +0 -1
  95. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +0 -1
  96. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +0 -1
  97. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +0 -1
  98. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +0 -1
  99. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +0 -1
  100. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +0 -1
  101. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +0 -1
  102. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +0 -1
  103. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +0 -1
  104. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +0 -1
  105. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +0 -1
  106. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +0 -1
  107. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +0 -1
  108. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +0 -1
  109. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +0 -1
  110. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +0 -1
  111. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +0 -1
  112. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +0 -1
  113. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +0 -1
  114. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +0 -1
  115. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +2 -2
  116. package/lib/runtime/components/react/dist/mpx-progress.d.ts +0 -1
  117. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +0 -1
  118. package/lib/runtime/components/react/dist/mpx-radio.d.ts +0 -1
  119. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +0 -1
  120. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +0 -1
  121. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +0 -1
  122. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +0 -1
  123. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +84 -78
  124. package/lib/runtime/components/react/dist/mpx-section-list.d.ts +48 -0
  125. package/lib/runtime/components/react/dist/mpx-section-list.jsx +292 -0
  126. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +0 -1
  127. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +0 -1
  128. package/lib/runtime/components/react/dist/mpx-slider.d.ts +0 -1
  129. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +0 -1
  130. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +20 -20
  131. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +0 -1
  132. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +0 -1
  133. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +11 -1
  134. package/lib/runtime/components/react/dist/mpx-swiper.jsx +136 -83
  135. package/lib/runtime/components/react/dist/mpx-switch.d.ts +0 -1
  136. package/lib/runtime/components/react/dist/mpx-text.d.ts +0 -1
  137. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +0 -1
  138. package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -0
  139. package/lib/runtime/components/react/dist/mpx-video.d.ts +0 -1
  140. package/lib/runtime/components/react/dist/mpx-view.d.ts +3 -3
  141. package/lib/runtime/components/react/dist/mpx-view.jsx +22 -8
  142. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +0 -1
  143. package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
  144. package/lib/runtime/components/react/dist/parser.d.ts +0 -1
  145. package/lib/runtime/components/react/dist/useNodesRef.d.ts +0 -1
  146. package/lib/runtime/components/react/dist/utils.d.ts +10 -9
  147. package/lib/runtime/components/react/dist/utils.jsx +47 -24
  148. package/lib/runtime/components/react/mpx-async-suspense.tsx +3 -1
  149. package/lib/runtime/components/react/mpx-camera.tsx +327 -0
  150. package/lib/runtime/components/react/mpx-image.tsx +2 -2
  151. package/lib/runtime/components/react/mpx-input.tsx +77 -54
  152. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +35 -6
  153. package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +2 -2
  154. package/lib/runtime/components/react/mpx-scroll-view.tsx +110 -114
  155. package/lib/runtime/components/react/mpx-section-list.tsx +439 -0
  156. package/lib/runtime/components/react/mpx-sticky-header.tsx +24 -24
  157. package/lib/runtime/components/react/mpx-swiper.tsx +156 -81
  158. package/lib/runtime/components/react/mpx-textarea.tsx +1 -0
  159. package/lib/runtime/components/react/mpx-view.tsx +27 -12
  160. package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
  161. package/lib/runtime/components/react/tsconfig.json +26 -0
  162. package/lib/runtime/components/react/types/global.d.ts +1 -0
  163. package/lib/runtime/components/react/utils.tsx +51 -27
  164. package/lib/runtime/components/web/mpx-scroll-view.vue +5 -2
  165. package/lib/runtime/components/web/mpx-section-list.vue +551 -0
  166. package/lib/runtime/components/wx/mpx-section-list-default/list-footer.mpx +26 -0
  167. package/lib/runtime/components/wx/mpx-section-list-default/list-header.mpx +26 -0
  168. package/lib/runtime/components/wx/mpx-section-list-default/list-item.mpx +26 -0
  169. package/lib/runtime/components/wx/mpx-section-list-default/section-header.mpx +26 -0
  170. package/lib/runtime/components/wx/mpx-section-list.mpx +209 -0
  171. package/lib/runtime/components/wx/mpx-sticky-header.mpx +40 -0
  172. package/lib/runtime/components/wx/mpx-sticky-section.mpx +31 -0
  173. package/lib/runtime/optionProcessor.js +5 -0
  174. package/lib/runtime/optionProcessorReact.js +7 -0
  175. package/lib/runtime/stringify.wxs +2 -2
  176. package/lib/script-setup-compiler/index.js +1 -2
  177. package/lib/style-compiler/strip-conditional.js +244 -0
  178. package/lib/template-compiler/compiler.js +9 -8
  179. package/lib/utils/const.js +29 -0
  180. package/lib/utils/dom-tag-config.js +1 -1
  181. package/lib/utils/string.js +25 -1
  182. package/lib/wxss/loader.js +4 -1
  183. package/lib/wxss/utils.js +7 -2
  184. package/package.json +7 -14
  185. package/LICENSE +0 -433
  186. package/lib/runtime/components/react/dist/context.d.ts.map +0 -1
  187. package/lib/runtime/components/react/dist/event.config.d.ts.map +0 -1
  188. package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +0 -1
  189. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +0 -1
  190. package/lib/runtime/components/react/dist/mpx-button.d.ts.map +0 -1
  191. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +0 -1
  192. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +0 -1
  193. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +0 -1
  194. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +0 -1
  195. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +0 -1
  196. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +0 -1
  197. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +0 -1
  198. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +0 -1
  199. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +0 -1
  200. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +0 -1
  201. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +0 -1
  202. package/lib/runtime/components/react/dist/mpx-form.d.ts.map +0 -1
  203. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +0 -1
  204. package/lib/runtime/components/react/dist/mpx-image.d.ts.map +0 -1
  205. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +0 -1
  206. package/lib/runtime/components/react/dist/mpx-input.d.ts.map +0 -1
  207. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +0 -1
  208. package/lib/runtime/components/react/dist/mpx-label.d.ts.map +0 -1
  209. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +0 -1
  210. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +0 -1
  211. package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +0 -1
  212. package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +0 -1
  213. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +0 -1
  214. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +0 -1
  215. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +0 -1
  216. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +0 -1
  217. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +0 -1
  218. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +0 -1
  219. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +0 -1
  220. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +0 -1
  221. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +0 -1
  222. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +0 -1
  223. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +0 -1
  224. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +0 -1
  225. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +0 -1
  226. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +0 -1
  227. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +0 -1
  228. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +0 -1
  229. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +0 -1
  230. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +0 -1
  231. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +0 -1
  232. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +0 -1
  233. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +0 -1
  234. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +0 -1
  235. package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +0 -1
  236. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +0 -1
  237. package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +0 -1
  238. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +0 -1
  239. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +0 -1
  240. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +0 -1
  241. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +0 -1
  242. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +0 -1
  243. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +0 -1
  244. package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +0 -1
  245. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +0 -1
  246. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +0 -1
  247. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +0 -1
  248. package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +0 -1
  249. package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +0 -1
  250. package/lib/runtime/components/react/dist/mpx-text.d.ts.map +0 -1
  251. package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +0 -1
  252. package/lib/runtime/components/react/dist/mpx-video.d.ts.map +0 -1
  253. package/lib/runtime/components/react/dist/mpx-view.d.ts.map +0 -1
  254. package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +0 -1
  255. package/lib/runtime/components/react/dist/parser.d.ts.map +0 -1
  256. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +0 -33
  257. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +0 -1
  258. package/lib/runtime/components/react/dist/useAnimationHooks.js +0 -289
  259. package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +0 -1
  260. package/lib/runtime/components/react/dist/utils.d.ts.map +0 -1
  261. package/lib/runtime/components/react/useAnimationHooks.ts +0 -320
  262. package/lib/style-compiler/strip-conditional-loader.js +0 -289
@@ -1,320 +0,0 @@
1
- import { useEffect, useMemo, useRef } from 'react'
2
- import type { MutableRefObject } from 'react'
3
- import type { NativeSyntheticEvent, TransformsStyle } from 'react-native'
4
- import {
5
- Easing,
6
- useSharedValue,
7
- withTiming,
8
- useAnimatedStyle,
9
- withSequence,
10
- withDelay,
11
- makeMutable,
12
- cancelAnimation,
13
- runOnJS
14
- } from 'react-native-reanimated'
15
- import type { AnimationCallback, WithTimingConfig, SharedValue, AnimatableValue } from 'react-native-reanimated'
16
- import { error, hasOwn, collectDataset } from '@mpxjs/utils'
17
- import { useRunOnJSCallback } from './utils'
18
- import { ExtendedViewStyle } from './types/common'
19
- import type { _ViewProps } from './mpx-view'
20
-
21
- type AnimatedOption = {
22
- duration: number
23
- delay: number
24
- useNativeDriver: boolean
25
- timingFunction: 'linear' | 'ease' | 'ease-in' | 'ease-in-out'| 'ease-out'
26
- transformOrigin: string
27
- }
28
- type ExtendWithTimingConfig = WithTimingConfig & {
29
- delay: number
30
- }
31
- export type AnimationStepItem = {
32
- animatedOption: AnimatedOption
33
- rules: Map<string, number | string>
34
- transform: Map<string, number>
35
- }
36
- export type AnimationProp = {
37
- id: number,
38
- actions: AnimationStepItem[]
39
- }
40
-
41
- // 微信 timingFunction 和 RN Easing 对应关系
42
- const EasingKey = {
43
- linear: Easing.linear,
44
- ease: Easing.inOut(Easing.ease),
45
- 'ease-in': Easing.in(Easing.poly(3)),
46
- 'ease-in-out': Easing.inOut(Easing.poly(3)),
47
- 'ease-out': Easing.out(Easing.poly(3))
48
- // 'step-start': '',
49
- // 'step-end': ''
50
- }
51
- const TransformInitial: ExtendedViewStyle = {
52
- // matrix: 0,
53
- // matrix3d: 0,
54
- // rotate: '0deg',
55
- rotateX: '0deg',
56
- rotateY: '0deg',
57
- rotateZ: '0deg',
58
- // rotate3d:[0,0,0]
59
- // scale: 1,
60
- // scale3d: [1, 1, 1],
61
- scaleX: 1,
62
- scaleY: 1,
63
- // scaleZ: 1,
64
- // skew: 0,
65
- skewX: '0deg',
66
- skewY: '0deg',
67
- // translate: 0,
68
- // translate3d: 0,
69
- translateX: 0,
70
- translateY: 0
71
- // translateZ: 0,
72
- }
73
- // 动画默认初始值
74
- const InitialValue: ExtendedViewStyle = Object.assign({
75
- opacity: 1,
76
- backgroundColor: 'transparent',
77
- width: 0,
78
- height: 0,
79
- top: 0,
80
- right: 0,
81
- bottom: 0,
82
- left: 0,
83
- transformOrigin: ['50%', '50%', 0]
84
- }, TransformInitial)
85
- const TransformOrigin = 'transformOrigin'
86
- // transform
87
- const isTransform = (key: string) => Object.keys(TransformInitial).includes(key)
88
-
89
- // transform 数组转对象
90
- function getTransformObj (transforms: { [propName: string]: string | number }[]) {
91
- 'worklet'
92
- return transforms.reduce((transformObj, item) => {
93
- return Object.assign(transformObj, item)
94
- }, {} as { [propName: string]: string | number })
95
- }
96
-
97
- export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAnimation?: boolean, layoutRef: MutableRefObject<any>, transitionend?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void }) {
98
- const { style: originalStyle = {}, animation, enableAnimation, transitionend, layoutRef } = props
99
- const enableStyleAnimation = enableAnimation || !!animation
100
- const enableAnimationRef = useRef(enableStyleAnimation)
101
- if (enableAnimationRef.current !== enableStyleAnimation) {
102
- error('[Mpx runtime error]: animation use should be stable in the component lifecycle, or you can set [enable-animation] with true.')
103
- }
104
-
105
- if (!enableAnimationRef.current) return { enableStyleAnimation: false }
106
-
107
- // id 标识
108
- const id = animation?.id || -1
109
- // 有动画样式的 style key
110
- // eslint-disable-next-line react-hooks/rules-of-hooks
111
- const animatedStyleKeys = useSharedValue([] as (string|string[])[])
112
- // 记录动画key的style样式值 没有的话设置为false
113
- // eslint-disable-next-line react-hooks/rules-of-hooks
114
- const animatedKeys = useRef({} as {[propName: keyof ExtendedViewStyle]: boolean})
115
- // 记录上次style map
116
- // eslint-disable-next-line react-hooks/rules-of-hooks
117
- const lastStyleRef = useRef({} as {[propName: keyof ExtendedViewStyle]: number|string})
118
- // ** 全量 style prop sharedValue
119
- // 不能做增量的原因:
120
- // 1 尝试用 useRef,但 useAnimatedStyle 访问后的 ref 不能在增加新的值,被冻结
121
- // 2 尝试用 useSharedValue,因为实际触发的 style prop 需要是 sharedValue 才能驱动动画,若外层 shareValMap 也是 sharedValue,动画无法驱动。
122
- // eslint-disable-next-line react-hooks/rules-of-hooks
123
- const shareValMap = useMemo(() => {
124
- return Object.keys(InitialValue).reduce((valMap, key) => {
125
- const defaultVal = getInitialVal(key, isTransform(key))
126
- valMap[key] = makeMutable(defaultVal)
127
- return valMap
128
- }, {} as { [propName: keyof ExtendedViewStyle]: SharedValue<string|number> })
129
- }, [])
130
- // ** style更新同步
131
- // eslint-disable-next-line react-hooks/rules-of-hooks
132
- useEffect(() => {
133
- // style 更新后同步更新 lastStyleRef & shareValMap
134
- updateStyleVal()
135
- }, [originalStyle])
136
- // ** 获取动画样式prop & 驱动动画
137
- // eslint-disable-next-line react-hooks/rules-of-hooks
138
- useEffect(() => {
139
- if (id === -1) return
140
- // 更新动画样式 key map
141
- animatedKeys.current = getAnimatedStyleKeys()
142
- const keys = Object.keys(animatedKeys.current)
143
- animatedStyleKeys.value = formatAnimatedKeys([TransformOrigin, ...keys])
144
- // 驱动动画
145
- createAnimation(keys)
146
- }, [id])
147
- // ** 清空动画
148
- // eslint-disable-next-line react-hooks/rules-of-hooks
149
- useEffect(() => {
150
- return () => {
151
- Object.values(shareValMap).forEach((value) => {
152
- cancelAnimation(value)
153
- })
154
- }
155
- }, [])
156
- // 根据 animation action 创建&驱动动画
157
- function createAnimation (animatedKeys: string[] = []) {
158
- const actions = animation?.actions || []
159
- const sequence = {} as { [propName: keyof ExtendedViewStyle]: (string|number)[] }
160
- const lastValueMap = {} as { [propName: keyof ExtendedViewStyle]: string|number }
161
- actions.forEach(({ animatedOption, rules, transform }, index) => {
162
- const { delay, duration, timingFunction, transformOrigin } = animatedOption
163
- const easing = EasingKey[timingFunction] || Easing.inOut(Easing.quad)
164
- let needSetCallback = true
165
- const setTransformOrigin: AnimationCallback = (finished: boolean) => {
166
- 'worklet'
167
- // 动画结束后设置下一次transformOrigin
168
- if (finished) {
169
- if (index < actions.length - 1) {
170
- const transformOrigin = actions[index + 1].animatedOption?.transformOrigin
171
- transformOrigin && (shareValMap[TransformOrigin].value = transformOrigin)
172
- }
173
- }
174
- }
175
- if (index === 0) {
176
- // 设置当次中心
177
- shareValMap[TransformOrigin].value = transformOrigin
178
- }
179
- // 添加每个key的多次step动画
180
- animatedKeys.forEach(key => {
181
- const ruleV = isTransform(key) ? transform.get(key) : rules.get(key)
182
- // key不存在,第一轮取shareValMap[key]value,非第一轮取上一轮的
183
- const toVal = ruleV !== undefined
184
- ? ruleV
185
- : index > 0
186
- ? lastValueMap[key]
187
- : shareValMap[key].value
188
- const animation = getAnimation({ key, value: toVal! }, { delay, duration, easing }, needSetCallback ? setTransformOrigin : undefined)
189
- needSetCallback = false
190
- if (!sequence[key]) {
191
- sequence[key] = [animation]
192
- } else {
193
- sequence[key].push(animation)
194
- }
195
- // 更新一下 lastValueMap
196
- lastValueMap[key] = toVal!
197
- })
198
- // 赋值驱动动画
199
- animatedKeys.forEach((key) => {
200
- const animations = sequence[key]
201
- shareValMap[key].value = withSequence(...animations)
202
- })
203
- })
204
- }
205
- function withTimingCallback (finished?: boolean, current?: AnimatableValue, duration?: number) {
206
- if (!transitionend) return
207
- const target = {
208
- id: animation?.id || -1,
209
- dataset: collectDataset(props),
210
- offsetLeft: layoutRef?.current?.offsetLeft || 0,
211
- offsetTop: layoutRef?.current?.offsetTop || 0
212
- }
213
- transitionend({
214
- type: 'transitionend',
215
- // elapsedTime 对齐wx 单位s
216
- detail: { elapsedTime: duration ? duration / 1000 : 0, finished, current },
217
- target,
218
- currentTarget: target,
219
- timeStamp: Date.now()
220
- })
221
- }
222
- // eslint-disable-next-line react-hooks/rules-of-hooks
223
- const runOnJSCallbackRef = useRef({
224
- withTimingCallback
225
- })
226
- // eslint-disable-next-line react-hooks/rules-of-hooks
227
- const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef)
228
- // 创建单个animation
229
- function getAnimation ({ key, value }: { key: string, value: string|number }, { delay, duration, easing }: ExtendWithTimingConfig, callback?: AnimationCallback) {
230
- const animation = typeof callback === 'function'
231
- ? withTiming(value, { duration, easing }, (finished, current) => {
232
- callback(finished, current)
233
- if (transitionend && finished) {
234
- runOnJS(runOnJSCallback)('withTimingCallback', finished, current, duration)
235
- }
236
- })
237
- : withTiming(value, { duration, easing })
238
- return delay ? withDelay(delay, animation) : animation
239
- }
240
- // 获取样式初始值(prop style or 默认值)
241
- function getInitialVal (key: keyof ExtendedViewStyle, isTransform = false) {
242
- if (isTransform && Array.isArray(originalStyle.transform)) {
243
- let initialVal = InitialValue[key]
244
- // 仅支持 { transform: [{rotateX: '45deg'}, {rotateZ: '0.785398rad'}] } 格式的初始样式
245
- originalStyle.transform.forEach(item => {
246
- if (item[key] !== undefined) initialVal = item[key]
247
- })
248
- return initialVal
249
- }
250
- return originalStyle[key] === undefined ? InitialValue[key] : originalStyle[key]
251
- }
252
- // 循环 animation actions 获取所有有动画的 style prop name
253
- function getAnimatedStyleKeys () {
254
- return (animation?.actions || []).reduce((keyMap, action) => {
255
- const { rules, transform } = action
256
- const ruleArr = [...rules.keys(), ...transform.keys()]
257
- ruleArr.forEach(key => {
258
- if (!keyMap[key]) keyMap[key] = true
259
- })
260
- return keyMap
261
- }, animatedKeys.current)
262
- }
263
- // animated key transform 格式化
264
- function formatAnimatedKeys (keys: string[]) {
265
- const animatedKeys = [] as (string|string[])[]
266
- const transforms = [] as string[]
267
- keys.forEach(key => {
268
- if (isTransform(key)) {
269
- transforms.push(key)
270
- } else {
271
- animatedKeys.push(key)
272
- }
273
- })
274
- if (transforms.length) animatedKeys.push(transforms)
275
- return animatedKeys
276
- }
277
- // 设置 lastShareValRef & shareValMap
278
- function updateStyleVal () {
279
- Object.entries(originalStyle).forEach(([key, value]) => {
280
- if (key === 'transform') {
281
- Object.entries(getTransformObj(value)).forEach(([key, value]) => {
282
- if (value !== lastStyleRef.current[key]) {
283
- lastStyleRef.current[key] = value
284
- shareValMap[key].value = value
285
- }
286
- })
287
- } else if (hasOwn(shareValMap, key)) {
288
- if (value !== lastStyleRef.current[key]) {
289
- lastStyleRef.current[key] = value
290
- shareValMap[key].value = value
291
- }
292
- }
293
- })
294
- }
295
- // ** 生成动画样式
296
- // eslint-disable-next-line react-hooks/rules-of-hooks
297
- const animationStyle = useAnimatedStyle(() => {
298
- // console.info(`useAnimatedStyle styles=`, originalStyle)
299
- return animatedStyleKeys.value.reduce((styles, key) => {
300
- // console.info('getAnimationStyles', key, shareValMap[key].value)
301
- if (Array.isArray(key)) {
302
- const transformStyle = getTransformObj(originalStyle.transform || [])
303
- key.forEach((transformKey) => {
304
- transformStyle[transformKey] = shareValMap[transformKey].value
305
- })
306
- styles.transform = Object.entries(transformStyle).map(([key, value]) => {
307
- return { [key]: value }
308
- }) as Extract<'transform', TransformsStyle>
309
- } else {
310
- styles[key] = shareValMap[key].value
311
- }
312
- return styles
313
- }, {} as ExtendedViewStyle)
314
- })
315
-
316
- return {
317
- enableStyleAnimation: enableAnimationRef.current,
318
- animationStyle
319
- }
320
- }
@@ -1,289 +0,0 @@
1
- const fs = require('fs/promises')
2
- const parseRequest = require('../utils/parse-request')
3
- const atImport = require('postcss-import')
4
- const { default: postcss } = require('postcss')
5
-
6
- class Node {
7
- constructor(type, condition = null) {
8
- this.type = type // 'If', 'ElseIf', 'Else' 或 'Text'
9
- this.condition = condition // If 或 Elif 的条件
10
- this.children = []
11
- this.value = ''
12
- }
13
- }
14
-
15
- // 提取 css string 为 token
16
- function tokenize(cssString) {
17
- const regex = /\/\*\s*@mpx-(if|elif|else|endif)(?:\s*\((.*?)\))?\s*\*\//g
18
- const tokens = []
19
- let lastIndex = 0
20
- let match
21
-
22
- while ((match = regex.exec(cssString)) !== null) {
23
- // 如果 token 前有普通文本,生成文本 token
24
- if (match.index > lastIndex) {
25
- const text = cssString.substring(lastIndex, match.index)
26
- tokens.push({ type: 'text', content: text })
27
- }
28
- // match[1] 为关键字:if, elif, else, endif
29
- // match[2] 为条件(如果存在)
30
- tokens.push({
31
- type: match[1], // 'if'、'elif'、'else' 或 'endif'
32
- condition: match[2] ? match[2].trim() : null
33
- })
34
- lastIndex = regex.lastIndex
35
- }
36
- // 处理结尾剩余的文本
37
- if (lastIndex < cssString.length) {
38
- const text = cssString.substring(lastIndex)
39
- tokens.push({ type: 'text', content: text })
40
- }
41
- return tokens
42
- }
43
-
44
- // parse:将生成的 token 数组构造成嵌套的 AST
45
- function parse(cssString) {
46
- const tokens = tokenize(cssString)
47
- const ast = []
48
- const nodeStack = []
49
- let currentChildren = ast
50
- tokens.forEach((token) => {
51
- if (token.type === 'text') {
52
- const node = new Node('Text')
53
- node.value = token.content
54
- currentChildren.push(node)
55
- } else if (token.type === 'if') {
56
- const node = new Node('If', token.condition)
57
- currentChildren.push(node)
58
- nodeStack.push(currentChildren)
59
- currentChildren = node.children
60
- } else if (token.type === 'elif') {
61
- if (nodeStack.length === 0) {
62
- throw new Error('[Mpx style error]: elif without a preceding if')
63
- }
64
- currentChildren = nodeStack[nodeStack.length - 1]
65
- const node = new Node('ElseIf', token.condition)
66
- currentChildren.push(node)
67
- currentChildren = node.children
68
- } else if (token.type === 'else') {
69
- if (nodeStack.length === 0) {
70
- throw new Error('[Mpx style error]: else without a preceding if')
71
- }
72
- currentChildren = nodeStack[nodeStack.length - 1]
73
- const node = new Node('Else')
74
- currentChildren.push(node)
75
- currentChildren = node.children
76
- } else if (token.type === 'endif') {
77
- if (nodeStack.length > 0) {
78
- currentChildren = nodeStack.pop()
79
- }
80
- }
81
- })
82
- return ast
83
- }
84
-
85
- function evaluateCondition(condition, defs) {
86
- try {
87
- const keys = Object.keys(defs)
88
- const values = keys.map((key) => defs[key])
89
- /* eslint-disable no-new-func */
90
- const func = new Function(...keys, `return (${condition});`)
91
- return func(...values)
92
- } catch (e) {
93
- console.error(`[Mpx style error]:Error evaluating condition: ${condition}`, e)
94
- return false
95
- }
96
- }
97
-
98
- function traverseAndEvaluate(ast, defs) {
99
- let output = ''
100
- let batchedIf = false
101
- function traverse(nodes) {
102
- for (const node of nodes) {
103
- if (node.type === 'Text') {
104
- output += node.value
105
- } else if (node.type === 'If') {
106
- // 直接判断 If 节点
107
- batchedIf = false
108
- if (evaluateCondition(node.condition, defs)) {
109
- traverse(node.children)
110
- batchedIf = true
111
- }
112
- } else if (node.type === 'ElseIf' && !batchedIf) {
113
- if (evaluateCondition(node.condition, defs)) {
114
- traverse(node.children)
115
- batchedIf = true
116
- }
117
- } else if (node.type === 'Else' && !batchedIf) {
118
- traverse(node.children)
119
- }
120
- }
121
- }
122
- traverse(ast)
123
- return output
124
- }
125
-
126
- /**
127
- *
128
- * @param {string} content
129
- * @param {Record<string, any>} defs
130
- * @returns
131
- */
132
- function stripCondition(content, defs) {
133
- const ast = parse(content)
134
- const result = traverseAndEvaluate(ast, defs)
135
- return result
136
- }
137
-
138
- /**
139
- * @typedef {Object} StripByPostcssOption
140
- * @property {string} lang 样式语法格式
141
- * @property {string} resourcePath 文件路径
142
- * @property {string} css 源文件
143
- * @property {Record<string, any>} defs 条件定义
144
- * @property {import('webpack').LoaderContext<any>['resolve']} resolve webpack resolve 方法
145
- */
146
-
147
- /**
148
- * @typedef {Object} AtImportConfig
149
- * @property {string} from 当前文件路径
150
- * @property {(filename: string) => Promise<string> | string;} load 加载文件内容的函数
151
- * @property {(id: string, base: string) => Promise<string | null> | string | null;} resolve 解析文件路径的函数
152
- */
153
-
154
- /**
155
- *
156
- * @param {Function} callback
157
- * @param {string} name
158
- * @returns
159
- */
160
- const shouldInstallWarning = (callback, name) => {
161
- return () => {
162
- try {
163
- return callback()
164
- } catch (error) {
165
- throw new Error(
166
- `[mpx-strip-conditional-loader]: ${name} is not installed, please install it first.\norginal Error: ${
167
- error?.message ?? error.toString()
168
- }`,
169
- {
170
- cause: error
171
- }
172
- )
173
- }
174
- }
175
- }
176
- /**
177
- *
178
- * @typedef {import('postcss').ProcessOptions} ProcessOptions
179
- * @typedef {import('postcss').Root} Root
180
- *
181
- * @type {Record<string, ProcessOptions['syntax']>}
182
- */
183
- const styleSyntaxProcesserMap = {
184
- stylus: shouldInstallWarning(() => require('postcss-styl'), 'postcss-styl'),
185
- less: shouldInstallWarning(() => require('postcss-less'), 'postcss-less'),
186
- scss: shouldInstallWarning(() => require('postcss-scss'), 'postcss-scss')
187
- }
188
-
189
- /**
190
- * @param {StripByPostcssOption} options
191
- */
192
- async function stripByPostcss(options) {
193
- const syntax = styleSyntaxProcesserMap[options.lang]?.()
194
- const defs = options.defs ?? {}
195
-
196
- function stripContentCondition(content) {
197
- content = stripCondition(content, defs)
198
-
199
- if (options.lang === 'stylus') {
200
- content = content.replace(/\t/g, ' ')
201
- }
202
-
203
- return content
204
- }
205
-
206
- const afterConditionStrip = stripContentCondition(options.css, defs)
207
-
208
- /**
209
- * @type {import('postcss').AcceptedPlugin[]}
210
- */
211
- const plugins = [
212
- atImport({
213
- async load(filename) {
214
- let content = await fs.readFile(filename, 'utf-8')
215
- const processer = postcss(plugins)
216
-
217
- content = stripContentCondition(content, defs)
218
-
219
- const { css } = await processer.process(content, {
220
- syntax,
221
- from: filename,
222
- to: options.resourcePath
223
- })
224
- return css
225
- },
226
- resolve: (id, base) => {
227
- return new Promise((resolve, reject) => {
228
- options.resolve(base, id, (err, res) => {
229
- if (err) return reject(err)
230
- if (typeof res !== 'string') {
231
- return reject(
232
- new Error(
233
- `[mpx-strip-conditional-loader]: Cannot resolve ${id} from ${base}`
234
- )
235
- )
236
- }
237
- resolve(res)
238
- })
239
- })
240
- }
241
- }),
242
- {
243
- // less/scss syntax 在 postcss 重新生成 css 后,`//` 注释后面不会保留换行,会和后续的 css 语句和注释连在一起,导致后续语法错误
244
- postcssPlugin: 'mpx-strip-conditional-loader-append-command',
245
- CommentExit(comment) {
246
- comment.raws.right ??= ''
247
-
248
- if (comment.raws.right.endsWith('\n')) {
249
- return
250
- }
251
-
252
- comment.raws.right += '\n'
253
- }
254
- }
255
- ]
256
-
257
- const processer = postcss(plugins)
258
- return processer.process(afterConditionStrip, {
259
- from: options.resourcePath,
260
- syntax
261
- })
262
- }
263
-
264
- /**
265
- *
266
- * @this {import('webpack').LoaderContext<any>}
267
- * @param {string} css
268
- */
269
- module.exports = async function (css) {
270
- this.cacheable()
271
-
272
- const callback = this.async()
273
-
274
- const mpx = this.getMpx()
275
- const { resourcePath, queryObj } = parseRequest(this.resource)
276
-
277
- const result = await stripByPostcss({
278
- lang: queryObj.lang,
279
- resourcePath,
280
- css,
281
- defs: mpx.defs,
282
- resolve: this.resolve.bind(this)
283
- })
284
-
285
- callback(null, result.css, result.map)
286
- }
287
-
288
- module.exports.stripByPostcss = stripByPostcss
289
- module.exports.stripCondition = stripCondition