@mpxjs/webpack-plugin 2.10.6-beta.7 → 2.10.7-beta.1

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.
@@ -57,7 +57,7 @@ const normalizeStyle = (style = {}) => {
57
57
  const isPercent = (val) => typeof val === 'string' && PERCENT_REGEX.test(val);
58
58
  const isBackgroundSizeKeyword = (val) => typeof val === 'string' && /^cover|contain$/.test(val);
59
59
  const isNeedLayout = (preImageInfo) => {
60
- const { sizeList, backgroundPosition, linearInfo } = preImageInfo;
60
+ const { sizeList, backgroundPosition, linearInfo, type } = preImageInfo;
61
61
  const [width, height] = sizeList;
62
62
  const bp = backgroundPosition;
63
63
  // 含有百分号,center 需计算布局
@@ -66,7 +66,8 @@ const isNeedLayout = (preImageInfo) => {
66
66
  (isPercent(width) && height === 'auto') ||
67
67
  isPercent(bp[1]) ||
68
68
  isPercent(bp[3]) ||
69
- isDiagonalAngle(linearInfo);
69
+ isDiagonalAngle(linearInfo) ||
70
+ (type === 'linear' && (isPercent(height) || isPercent(width)));
70
71
  };
71
72
  const checkNeedLayout = (preImageInfo) => {
72
73
  const { sizeList } = preImageInfo;
@@ -155,7 +156,7 @@ function backgroundPosition(imageProps, preImageInfo, imageSize, layoutInfo) {
155
156
  }
156
157
  // background-size 转换
157
158
  function backgroundSize(imageProps, preImageInfo, imageSize, layoutInfo) {
158
- const sizeList = preImageInfo.sizeList;
159
+ const { sizeList, type } = preImageInfo;
159
160
  if (!sizeList)
160
161
  return;
161
162
  const { width: layoutWidth, height: layoutHeight } = layoutInfo || {};
@@ -202,10 +203,23 @@ function backgroundSize(imageProps, preImageInfo, imageSize, layoutInfo) {
202
203
  else { // 数值类型 ImageStyle
203
204
  // 数值类型设置为 stretch
204
205
  imageProps.resizeMode = 'stretch';
205
- dimensions = {
206
- width: isPercent(width) ? width : +width,
207
- height: isPercent(height) ? height : +height
208
- };
206
+ if (type === 'linear') {
207
+ const dimensionWidth = calcPercent(width, layoutWidth) || 0;
208
+ const dimensionHeight = calcPercent(height, layoutHeight) || 0;
209
+ // ios 上 linear 组件只要重新触发渲染,在渲染过程中 width 或者 height 被设置为 0,即使后面再更新为正常宽高,也会渲染不出来
210
+ if (dimensionWidth && dimensionHeight) {
211
+ dimensions = {
212
+ width: dimensionWidth,
213
+ height: dimensionHeight
214
+ };
215
+ }
216
+ }
217
+ else {
218
+ dimensions = {
219
+ width: isPercent(width) ? width : +width,
220
+ height: isPercent(height) ? height : +height
221
+ };
222
+ }
209
223
  }
210
224
  }
211
225
  // 样式合并
@@ -319,6 +319,13 @@ function transformTransform(style) {
319
319
  return;
320
320
  style.transform = parseTransform(style.transform);
321
321
  }
322
+ function transformBoxShadow(styleObj) {
323
+ if (!styleObj.boxShadow)
324
+ return;
325
+ styleObj.boxShadow = parseValues(styleObj.boxShadow).reduce((res, i, idx) => {
326
+ return `${res}${idx === 0 ? '' : ' '}${global.__formatValue(i)}`;
327
+ }, '');
328
+ }
322
329
  export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight }) {
323
330
  const varStyle = {};
324
331
  const unoVarStyle = {};
@@ -447,6 +454,8 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
447
454
  transformPosition(normalStyle, positionMeta);
448
455
  // transform number enum stringify
449
456
  transformStringify(normalStyle);
457
+ // transform rpx to px
458
+ transformBoxShadow(normalStyle);
450
459
  // transform 字符串格式转化数组格式
451
460
  transformTransform(normalStyle);
452
461
  return {
@@ -44,6 +44,7 @@ interface MovableViewProps {
44
44
  disabled?: boolean
45
45
  animation?: boolean
46
46
  id?: string
47
+ changeThrottleTime?:number
47
48
  bindchange?: (event: unknown) => void
48
49
  bindtouchstart?: (event: GestureTouchEvent) => void
49
50
  catchtouchstart?: (event: GestureTouchEvent) => void
@@ -105,6 +106,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
105
106
  'simultaneous-handlers': originSimultaneousHandlers = [],
106
107
  'wait-for': waitFor = [],
107
108
  style = {},
109
+ changeThrottleTime = 60,
108
110
  bindtouchstart,
109
111
  catchtouchstart,
110
112
  bindhtouchmove,
@@ -150,6 +152,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
150
152
  const isFirstTouch = useSharedValue(true)
151
153
  const touchEvent = useSharedValue<string>('')
152
154
  const initialViewPosition = useSharedValue({ x: x || 0, y: y || 0 })
155
+ const lastChangeTime = useSharedValue(0)
153
156
 
154
157
  const MovableAreaLayout = useContext(MovableAreaContext)
155
158
 
@@ -197,6 +200,16 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
197
200
  )
198
201
  }, [])
199
202
 
203
+ // 节流版本的 change 事件触发
204
+ const handleTriggerChangeThrottled = useCallback(({ x, y, type }: { x: number; y: number; type?: string }) => {
205
+ 'worklet'
206
+ const now = Date.now()
207
+ if (now - lastChangeTime.value >= changeThrottleTime) {
208
+ lastChangeTime.value = now
209
+ runOnJS(handleTriggerChange)({ x, y, type })
210
+ }
211
+ }, [changeThrottleTime])
212
+
200
213
  useEffect(() => {
201
214
  runOnUI(() => {
202
215
  if (offsetX.value !== x || offsetY.value !== y) {
@@ -460,7 +473,8 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
460
473
  }
461
474
  }
462
475
  if (bindchange) {
463
- runOnJS(handleTriggerChange)({
476
+ // 使用节流版本减少 runOnJS 调用
477
+ handleTriggerChangeThrottled({
464
478
  x: offsetX.value,
465
479
  y: offsetY.value
466
480
  })
@@ -116,6 +116,9 @@ const _RichText = forwardRef<HandlerRef<View, _RichTextProps>, _RichTextProps>((
116
116
  source: { html: generateHTML(html) },
117
117
  onMessage: (event: WebViewMessageEvent) => {
118
118
  setWebViewHeight(+event.nativeEvent.data)
119
+ },
120
+ style: {
121
+ backgroundColor: 'transparent'
119
122
  }
120
123
  })
121
124
  )
@@ -143,7 +143,7 @@ const isPercent = (val: string | number | undefined): val is string => typeof va
143
143
  const isBackgroundSizeKeyword = (val: string | number): boolean => typeof val === 'string' && /^cover|contain$/.test(val)
144
144
 
145
145
  const isNeedLayout = (preImageInfo: PreImageInfo): boolean => {
146
- const { sizeList, backgroundPosition, linearInfo } = preImageInfo
146
+ const { sizeList, backgroundPosition, linearInfo, type } = preImageInfo
147
147
  const [width, height] = sizeList
148
148
  const bp = backgroundPosition
149
149
 
@@ -153,7 +153,8 @@ const isNeedLayout = (preImageInfo: PreImageInfo): boolean => {
153
153
  (isPercent(width) && height === 'auto') ||
154
154
  isPercent(bp[1]) ||
155
155
  isPercent(bp[3]) ||
156
- isDiagonalAngle(linearInfo)
156
+ isDiagonalAngle(linearInfo) ||
157
+ (type === 'linear' && (isPercent(height) || isPercent(width)))
157
158
  }
158
159
 
159
160
  const checkNeedLayout = (preImageInfo: PreImageInfo) => {
@@ -246,7 +247,7 @@ function backgroundPosition (imageProps: ImageProps, preImageInfo: PreImageInfo,
246
247
 
247
248
  // background-size 转换
248
249
  function backgroundSize (imageProps: ImageProps, preImageInfo: PreImageInfo, imageSize: Size, layoutInfo: Size) {
249
- const sizeList = preImageInfo.sizeList
250
+ const { sizeList, type } = preImageInfo
250
251
  if (!sizeList) return
251
252
  const { width: layoutWidth, height: layoutHeight } = layoutInfo || {}
252
253
  const { width: imageSizeWidth, height: imageSizeHeight } = imageSize || {}
@@ -286,10 +287,22 @@ function backgroundSize (imageProps: ImageProps, preImageInfo: PreImageInfo, ima
286
287
  } else { // 数值类型 ImageStyle
287
288
  // 数值类型设置为 stretch
288
289
  imageProps.resizeMode = 'stretch'
289
- dimensions = {
290
- width: isPercent(width) ? width : +width,
291
- height: isPercent(height) ? height : +height
292
- } as { width: NumberVal, height: NumberVal }
290
+ if (type === 'linear') {
291
+ const dimensionWidth = calcPercent(width as NumberVal, layoutWidth) || 0
292
+ const dimensionHeight = calcPercent(height as NumberVal, layoutHeight) || 0
293
+ // ios linear 组件只要重新触发渲染,在渲染过程中 width 或者 height 被设置为 0,即使后面再更新为正常宽高,也会渲染不出来
294
+ if (dimensionWidth && dimensionHeight) {
295
+ dimensions = {
296
+ width: dimensionWidth,
297
+ height: dimensionHeight
298
+ } as { width: NumberVal, height: NumberVal }
299
+ }
300
+ } else {
301
+ dimensions = {
302
+ width: isPercent(width) ? width : +width,
303
+ height: isPercent(height) ? height : +height
304
+ } as { width: NumberVal, height: NumberVal }
305
+ }
293
306
  }
294
307
  }
295
308
 
@@ -365,6 +365,14 @@ function transformTransform (style: Record<string, any>) {
365
365
  if (!style.transform || Array.isArray(style.transform)) return
366
366
  style.transform = parseTransform(style.transform)
367
367
  }
368
+
369
+ function transformBoxShadow (styleObj: Record<string, any>) {
370
+ if (!styleObj.boxShadow) return
371
+ styleObj.boxShadow = parseValues(styleObj.boxShadow).reduce((res, i, idx) => {
372
+ return `${res}${idx === 0 ? '' : ' '}${global.__formatValue(i)}`
373
+ }, '')
374
+ }
375
+
368
376
  interface TransformStyleConfig {
369
377
  enableVar?: boolean
370
378
  externalVarContext?: Record<string, any>
@@ -506,6 +514,8 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
506
514
  transformPosition(normalStyle, positionMeta)
507
515
  // transform number enum stringify
508
516
  transformStringify(normalStyle)
517
+ // transform rpx to px
518
+ transformBoxShadow(normalStyle)
509
519
 
510
520
  // transform 字符串格式转化数组格式
511
521
  transformTransform(normalStyle)
@@ -181,7 +181,6 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
181
181
  global.__mpxRouter.lastStack = null
182
182
  global.__mpxRouter.needCache = null
183
183
  global.__mpxRouter.needRemove = []
184
- global.__mpxRouter.eventChannelMap = {}
185
184
  global.__mpxRouter.currentActionType = null
186
185
  // 处理reLaunch中传递的url并非首页时的replace逻辑
187
186
  global.__mpxRouter.beforeEach(function (to, from, next) {
@@ -241,7 +240,6 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
241
240
  case 'to':
242
241
  stack.push(insertItem)
243
242
  global.__mpxRouter.needCache = insertItem
244
- if (action.eventChannel) global.__mpxRouter.eventChannelMap[to.path.slice(1)] = action.eventChannel
245
243
  break
246
244
  case 'back':
247
245
  global.__mpxRouter.needRemove = stack.splice(stack.length - action.delta, action.delta)
@@ -1,4 +1,3 @@
1
- import { ReactNode, ComponentType } from 'react'
2
1
  declare global {
3
2
  namespace NodeJS {
4
3
  interface Global {
@@ -8,20 +7,3 @@ declare global {
8
7
  }
9
8
 
10
9
  export function getComponent (...args: any): object
11
-
12
- interface AsyncModule {
13
- __esModule: boolean
14
- default: ReactNode
15
- }
16
-
17
- interface AsyncSuspenseProps {
18
- type: 'component' | 'page'
19
- chunkName: string
20
- moduleId: string
21
- innerProps: any
22
- loading: ComponentType<unknown>
23
- fallback: ComponentType<unknown>
24
- getChildren: () => Promise<AsyncModule>
25
- }
26
-
27
- export function getAsyncSuspense(props: AsyncSuspenseProps): ReactNode
@@ -1,30 +1,6 @@
1
- import AsyncSuspense from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/AsyncSuspense'
2
- import { memo, forwardRef, createElement } from 'react'
3
- import { extend } from './utils'
4
-
5
1
  export function getComponent (component, extendOptions) {
6
2
  component = component.__esModule ? component.default : component
7
3
  // eslint-disable-next-line
8
4
  if (extendOptions) Object.assign(component, extendOptions)
9
5
  return component
10
6
  }
11
-
12
- export function getAsyncSuspense (commonProps) {
13
- if (commonProps.type === 'component') {
14
- return memo(forwardRef(function (props, ref) {
15
- return createElement(AsyncSuspense,
16
- extend(commonProps, {
17
- innerProps: Object.assign({}, props, { ref })
18
- })
19
- )
20
- }))
21
- } else {
22
- return function (props) {
23
- return createElement(AsyncSuspense,
24
- extend(commonProps, {
25
- innerProps: props
26
- })
27
- )
28
- }
29
- }
30
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.6-beta.7",
3
+ "version": "2.10.7-beta.1",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -28,7 +28,7 @@
28
28
  "@better-scroll/wheel": "^2.5.1",
29
29
  "@better-scroll/zoom": "^2.5.1",
30
30
  "@mpxjs/template-engine": "^2.8.7",
31
- "@mpxjs/utils": "^2.10.6 | ^2.10.6-beta.1",
31
+ "@mpxjs/utils": "^2.10.7 | ^2.10.7-beta.1",
32
32
  "acorn": "^8.11.3",
33
33
  "acorn-walk": "^7.2.0",
34
34
  "async": "^2.6.0",
@@ -83,7 +83,7 @@
83
83
  },
84
84
  "devDependencies": {
85
85
  "@d11/react-native-fast-image": "^8.6.12",
86
- "@mpxjs/api-proxy": "^2.10.6 | ^2.10.6-beta.1",
86
+ "@mpxjs/api-proxy": "^2.10.7 | ^2.10.7-beta.1",
87
87
  "@types/babel-traverse": "^6.25.4",
88
88
  "@types/babel-types": "^7.0.4",
89
89
  "@types/react": "^18.2.79",
@@ -1,58 +0,0 @@
1
- const path = require('path')
2
- const NullDependency = require('webpack/lib/dependencies/NullDependency')
3
- const makeSerializable = require('webpack/lib/util/makeSerializable')
4
-
5
- class RecordFileUrlDependency extends NullDependency {
6
- constructor (range, url) {
7
- super()
8
- this.range = range
9
- this.url = url
10
- }
11
-
12
- get type () {
13
- return 'mpx record file url'
14
- }
15
-
16
- mpxAction (module, compilation, callback) {
17
- return callback()
18
- }
19
-
20
- updateHash (hash, context) {
21
- hash.update('' + (+new Date()) + Math.random())
22
- super.updateHash(hash, context)
23
- }
24
-
25
- serialize (context) {
26
- const { write } = context
27
- write(this.url)
28
- super.serialize(context)
29
- }
30
-
31
- deserialize (context) {
32
- const { read } = context
33
- this.url = read()
34
- super.deserialize(context)
35
- }
36
- }
37
-
38
- RecordFileUrlDependency.Template = class RecordFileUrlDependencyTemplate {
39
- apply (dependency, source, { module, chunkGraph, runtimeTemplate }) {
40
- const { range } = dependency
41
- const compliation = runtimeTemplate.compilation
42
- const publicPath = compliation.outputOptions.publicPath
43
- const chunks = chunkGraph.getModuleChunks(module)
44
- const chunk = chunks[0]
45
- const chunkPath = path.dirname(publicPath + chunk.name)
46
- const imgPath = publicPath + dependency.url
47
- let relativePath = path.relative(chunkPath, imgPath)
48
- if (!relativePath.startsWith('.')) {
49
- relativePath = './' + relativePath
50
- }
51
-
52
- source.replace(range[0], range[1] - 1, JSON.stringify(relativePath))
53
- }
54
- }
55
-
56
- makeSerializable(RecordFileUrlDependency, '@mpxjs/webpack-plugin/lib/dependencies/RecordFileUrlDependency')
57
-
58
- module.exports = RecordFileUrlDependency
@@ -1,34 +0,0 @@
1
- const { matchCondition } = require('./match-condition')
2
-
3
- function transAsyncSubNameRules (asyncSubpackageNameRules, tarRoot) {
4
- // 如果没有tarRoot,则无需进行tarRoot的修改,因此
5
- if (tarRoot && Array.isArray(asyncSubpackageNameRules) && asyncSubpackageNameRules.length >= 1) {
6
- for (const item of asyncSubpackageNameRules) {
7
- if (item?.from) {
8
- const fromPaths = Array.isArray(item.from) ? item.from : [item.from];
9
- if (fromPaths.includes(tarRoot)) {
10
- tarRoot = item.to
11
- break
12
- }
13
- }
14
- }
15
- }
16
- return tarRoot
17
- }
18
-
19
- function transAsyncSubRules (resourcePath, asyncSubpackageRules, tarRoot) {
20
- if (!tarRoot && Array.isArray(asyncSubpackageRules) && asyncSubpackageRules.length >= 1) {
21
- for (const item of asyncSubpackageRules) {
22
- if (matchCondition(resourcePath, item)) {
23
- tarRoot = item.root
24
- break
25
- }
26
- }
27
- }
28
- return tarRoot
29
- }
30
-
31
- module.exports = {
32
- transAsyncSubNameRules,
33
- transAsyncSubRules
34
- }