@mpxjs/webpack-plugin 2.10.20 → 2.10.21
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.
- package/lib/index.js +13 -1
- package/lib/parser.js +1 -1
- package/lib/platform/style/wx/index.js +78 -30
- package/lib/platform/template/wx/component-config/block.js +2 -1
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/react/processTemplate.js +23 -10
- package/lib/react/style-helper.js +1 -1
- package/lib/react/template-loader.js +15 -2
- package/lib/runtime/components/react/context.ts +8 -1
- package/lib/runtime/components/react/dist/context.d.ts +6 -1
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +1 -0
- package/lib/runtime/components/react/dist/mpx-button.d.ts +1 -1
- package/lib/runtime/components/react/dist/mpx-button.jsx +6 -5
- package/lib/runtime/components/react/dist/mpx-camera.jsx +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +4 -1
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +6 -4
- package/lib/runtime/components/react/dist/mpx-form.jsx +3 -3
- package/lib/runtime/components/react/dist/mpx-icon/index.jsx +5 -1
- package/lib/runtime/components/react/dist/mpx-image.d.ts +3 -2
- package/lib/runtime/components/react/dist/mpx-image.jsx +46 -12
- package/lib/runtime/components/react/dist/mpx-inline-text.jsx +10 -6
- package/lib/runtime/components/react/dist/mpx-input.jsx +17 -4
- package/lib/runtime/components/react/dist/mpx-label.jsx +6 -4
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +19 -4
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +12 -2
- package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +7 -4
- package/lib/runtime/components/react/dist/mpx-portal/index.jsx +5 -1
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +4 -1
- package/lib/runtime/components/react/dist/mpx-radio.jsx +5 -4
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +3 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +13 -4
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +52 -6
- package/lib/runtime/components/react/dist/mpx-simple-view.jsx +36 -6
- package/lib/runtime/components/react/dist/mpx-slider.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +8 -4
- package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +6 -4
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +7 -4
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +15 -4
- package/lib/runtime/components/react/dist/mpx-switch.jsx +4 -1
- package/lib/runtime/components/react/dist/mpx-text.jsx +57 -12
- package/lib/runtime/components/react/dist/mpx-video.d.ts +2 -1
- package/lib/runtime/components/react/dist/mpx-video.jsx +10 -4
- package/lib/runtime/components/react/dist/mpx-view.jsx +42 -7
- package/lib/runtime/components/react/dist/utils.d.ts +21 -11
- package/lib/runtime/components/react/dist/utils.jsx +102 -33
- package/lib/runtime/components/react/getInnerListeners.ts +1 -0
- package/lib/runtime/components/react/mpx-button.tsx +6 -5
- package/lib/runtime/components/react/mpx-camera.tsx +1 -0
- package/lib/runtime/components/react/mpx-canvas/index.tsx +4 -1
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +2 -1
- package/lib/runtime/components/react/mpx-checkbox.tsx +6 -4
- package/lib/runtime/components/react/mpx-form.tsx +3 -3
- package/lib/runtime/components/react/mpx-icon/index.tsx +5 -1
- package/lib/runtime/components/react/mpx-image.tsx +58 -19
- package/lib/runtime/components/react/mpx-inline-text.tsx +12 -7
- package/lib/runtime/components/react/mpx-input.tsx +17 -4
- package/lib/runtime/components/react/mpx-label.tsx +6 -4
- package/lib/runtime/components/react/mpx-movable-view.tsx +20 -4
- package/lib/runtime/components/react/mpx-picker/index.tsx +12 -2
- package/lib/runtime/components/react/mpx-picker-view/index.tsx +8 -4
- package/lib/runtime/components/react/mpx-portal/index.tsx +5 -1
- package/lib/runtime/components/react/mpx-radio-group.tsx +4 -1
- package/lib/runtime/components/react/mpx-radio.tsx +5 -4
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +3 -1
- package/lib/runtime/components/react/mpx-scroll-view.tsx +13 -4
- package/lib/runtime/components/react/mpx-simple-text.tsx +55 -8
- package/lib/runtime/components/react/mpx-simple-view.tsx +30 -6
- package/lib/runtime/components/react/mpx-slider.tsx +2 -1
- package/lib/runtime/components/react/mpx-sticky-header.tsx +8 -4
- package/lib/runtime/components/react/mpx-sticky-section.tsx +6 -4
- package/lib/runtime/components/react/mpx-swiper-item.tsx +7 -4
- package/lib/runtime/components/react/mpx-swiper.tsx +16 -4
- package/lib/runtime/components/react/mpx-switch.tsx +4 -1
- package/lib/runtime/components/react/mpx-text.tsx +55 -15
- package/lib/runtime/components/react/mpx-video.tsx +11 -5
- package/lib/runtime/components/react/mpx-view.tsx +35 -7
- package/lib/runtime/components/react/types/global.d.ts +4 -0
- package/lib/runtime/components/react/utils.tsx +123 -43
- package/lib/runtime/optionProcessorReact.js +5 -0
- package/lib/script-setup-compiler/index.js +1 -1
- package/lib/style-compiler/plugins/trans-special.js +1 -1
- package/lib/template-compiler/compiler.js +37 -14
- package/lib/utils/gen-component-tag.js +1 -5
- package/lib/utils/normalize-perf-options.js +47 -0
- package/lib/web/index.js +1 -0
- package/lib/web/processMainScript.js +3 -7
- package/lib/web/processScript.js +3 -6
- package/lib/web/processStyles.js +12 -3
- package/lib/wxml/loader.js +1 -1
- package/package.json +5 -4
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
* ✔ decode
|
|
6
6
|
*/
|
|
7
7
|
import { Text, TextStyle, TextProps } from 'react-native'
|
|
8
|
-
import { useRef, forwardRef, ReactNode, JSX, createElement, Children } from 'react'
|
|
8
|
+
import { useRef, forwardRef, ReactNode, JSX, createElement, Children, useContext } from 'react'
|
|
9
9
|
import Portal from './mpx-portal'
|
|
10
10
|
import useInnerProps from './getInnerListeners'
|
|
11
11
|
import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
|
|
12
|
-
import { useTransformStyle, wrapChildren, extendObject } from './utils'
|
|
12
|
+
import { useTransformStyle, wrapChildren, extendObject, getDefaultAllowFontScaling, useTextPassThroughValue, isStringChildren, splitStyle } from './utils'
|
|
13
|
+
import { TextPassThroughContext } from './context'
|
|
14
|
+
import * as perf from '@mpxjs/perf'
|
|
13
15
|
|
|
14
16
|
const decodeMap = {
|
|
15
17
|
'<': '<',
|
|
@@ -51,9 +53,17 @@ interface _TextProps extends TextProps {
|
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref): JSX.Element => {
|
|
56
|
+
let stopTotal: (() => void) | undefined
|
|
57
|
+
if (__mpx_perf_framework__) stopTotal = perf.scope('text:render:total')
|
|
58
|
+
|
|
59
|
+
// ───── props 阶段 ─────
|
|
60
|
+
let stopProps: (() => void) | undefined
|
|
61
|
+
if (__mpx_perf_framework__) stopProps = perf.scope('text:render:props')
|
|
62
|
+
const inheritedText = useContext(TextPassThroughContext)
|
|
63
|
+
const mergedProps = extendObject({}, inheritedText?.pendingTextProps, props)
|
|
54
64
|
const {
|
|
55
|
-
style = {},
|
|
56
|
-
allowFontScaling
|
|
65
|
+
style: currentStyle = {},
|
|
66
|
+
allowFontScaling,
|
|
57
67
|
selectable,
|
|
58
68
|
'enable-var': enableVar,
|
|
59
69
|
'external-var-context': externalVarContext,
|
|
@@ -62,35 +72,60 @@ const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref):
|
|
|
62
72
|
'parent-width': parentWidth,
|
|
63
73
|
'parent-height': parentHeight,
|
|
64
74
|
decode
|
|
65
|
-
} =
|
|
75
|
+
} = mergedProps
|
|
76
|
+
if (__mpx_perf_framework__) stopProps!()
|
|
66
77
|
|
|
78
|
+
// ───── style 阶段 ─────
|
|
79
|
+
let stopStyle: (() => void) | undefined
|
|
80
|
+
if (__mpx_perf_framework__) stopStyle = perf.scope('text:render:style')
|
|
67
81
|
const {
|
|
68
82
|
normalStyle,
|
|
69
83
|
hasVarDec,
|
|
70
84
|
varContextRef,
|
|
71
85
|
hasPositionFixed
|
|
72
|
-
} = useTransformStyle(
|
|
86
|
+
} = useTransformStyle(currentStyle, {
|
|
73
87
|
enableVar,
|
|
74
88
|
externalVarContext,
|
|
75
89
|
parentFontSize,
|
|
76
90
|
parentWidth,
|
|
77
91
|
parentHeight
|
|
78
92
|
})
|
|
93
|
+
const finalStyle = extendObject({}, inheritedText?.textStyle, normalStyle)
|
|
79
94
|
|
|
80
95
|
const nodeRef = useRef(null)
|
|
81
|
-
useNodesRef<Text, _TextProps>(
|
|
82
|
-
style:
|
|
96
|
+
useNodesRef<Text, _TextProps>(mergedProps, ref, nodeRef, {
|
|
97
|
+
style: finalStyle
|
|
83
98
|
})
|
|
84
99
|
|
|
100
|
+
const children = decode ? getDecodedChildren(mergedProps.children) : mergedProps.children
|
|
101
|
+
const isStringOnly = isStringChildren(children)
|
|
102
|
+
let childTextStyle: TextStyle | undefined
|
|
103
|
+
if (!isStringOnly) {
|
|
104
|
+
const { textStyle = {} } = splitStyle(finalStyle)
|
|
105
|
+
childTextStyle = Object.keys(textStyle).length ? textStyle : undefined
|
|
106
|
+
}
|
|
107
|
+
const textPassThrough = useTextPassThroughValue(
|
|
108
|
+
childTextStyle,
|
|
109
|
+
undefined,
|
|
110
|
+
{
|
|
111
|
+
inheritTextProps: false,
|
|
112
|
+
disabled: isStringOnly
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
if (__mpx_perf_framework__) stopStyle!()
|
|
116
|
+
|
|
117
|
+
// ───── innerProps 阶段 ─────
|
|
118
|
+
let stopInnerProps: (() => void) | undefined
|
|
119
|
+
if (__mpx_perf_framework__) stopInnerProps = perf.scope('text:render:innerProps')
|
|
85
120
|
const innerProps = useInnerProps(
|
|
86
121
|
extendObject(
|
|
87
122
|
{},
|
|
88
|
-
|
|
123
|
+
mergedProps,
|
|
89
124
|
{
|
|
90
125
|
ref: nodeRef,
|
|
91
|
-
style:
|
|
126
|
+
style: finalStyle,
|
|
92
127
|
selectable: !!selectable || !!userSelect,
|
|
93
|
-
allowFontScaling
|
|
128
|
+
allowFontScaling: allowFontScaling ?? getDefaultAllowFontScaling()
|
|
94
129
|
}
|
|
95
130
|
),
|
|
96
131
|
[
|
|
@@ -98,23 +133,28 @@ const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref):
|
|
|
98
133
|
'decode'
|
|
99
134
|
]
|
|
100
135
|
)
|
|
136
|
+
if (__mpx_perf_framework__) stopInnerProps!()
|
|
101
137
|
|
|
102
|
-
|
|
103
|
-
|
|
138
|
+
// ───── createElement 阶段 ─────
|
|
139
|
+
let stopCreate: (() => void) | undefined
|
|
140
|
+
if (__mpx_perf_framework__) stopCreate = perf.scope('text:render:createElement')
|
|
104
141
|
let finalComponent:JSX.Element = createElement(Text, innerProps, wrapChildren(
|
|
105
|
-
extendObject({},
|
|
142
|
+
extendObject({}, mergedProps, {
|
|
106
143
|
children
|
|
107
144
|
}),
|
|
108
145
|
{
|
|
109
146
|
hasVarDec,
|
|
110
|
-
varContext: varContextRef.current
|
|
147
|
+
varContext: varContextRef.current,
|
|
148
|
+
textPassThrough
|
|
111
149
|
}
|
|
112
150
|
))
|
|
113
151
|
|
|
114
152
|
if (hasPositionFixed) {
|
|
115
153
|
finalComponent = createElement(Portal, null, finalComponent)
|
|
116
154
|
}
|
|
155
|
+
if (__mpx_perf_framework__) stopCreate!()
|
|
117
156
|
|
|
157
|
+
if (__mpx_perf_framework__) stopTotal!()
|
|
118
158
|
return finalComponent
|
|
119
159
|
})
|
|
120
160
|
|
|
@@ -77,7 +77,7 @@ import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
|
77
77
|
import Portal from './mpx-portal'
|
|
78
78
|
|
|
79
79
|
interface VideoProps {
|
|
80
|
-
src: string
|
|
80
|
+
src: string | ReactVideoSourceProperties | number
|
|
81
81
|
autoplay?: boolean
|
|
82
82
|
loop?: boolean
|
|
83
83
|
muted?: boolean
|
|
@@ -321,10 +321,8 @@ const MpxVideo = forwardRef<HandlerRef<View, VideoProps>, VideoProps>((videoProp
|
|
|
321
321
|
videoRef.current && videoRef.current.setFullScreen(true)
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
-
const source:
|
|
325
|
-
|
|
326
|
-
}
|
|
327
|
-
if (isDrm) {
|
|
324
|
+
const source = typeof src === 'string' ? { uri: src } : (typeof src === 'number' ? src : extendObject({}, src))
|
|
325
|
+
if (isDrm && source && typeof source !== 'number') {
|
|
328
326
|
source.drm = {
|
|
329
327
|
type: DRMType.FAIRPLAY,
|
|
330
328
|
certificateUrl: __mpx_mode__ !== 'ios' ? provisionUrl : certificateUrl,
|
|
@@ -369,6 +367,14 @@ const MpxVideo = forwardRef<HandlerRef<View, VideoProps>, VideoProps>((videoProp
|
|
|
369
367
|
'src',
|
|
370
368
|
'autoplay',
|
|
371
369
|
'loop',
|
|
370
|
+
'initial-time',
|
|
371
|
+
'object-fit',
|
|
372
|
+
'is-drm',
|
|
373
|
+
'provision-url',
|
|
374
|
+
'certificate-url',
|
|
375
|
+
'license-url',
|
|
376
|
+
'preferred-peak-bit-rate',
|
|
377
|
+
'enable-auto-rotation',
|
|
372
378
|
'bindplay',
|
|
373
379
|
'bindpause',
|
|
374
380
|
'bindended',
|
|
@@ -12,8 +12,9 @@ import useAnimationHooks, { AnimationType } from './animationHooks/index'
|
|
|
12
12
|
import type { AnimationProp } from './animationHooks/utils'
|
|
13
13
|
import { ExtendedViewStyle } from './types/common'
|
|
14
14
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
15
|
-
import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout, renderImage, pickStyle, extendObject, useHover } from './utils'
|
|
15
|
+
import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout, renderImage, pickStyle, extendObject, useHover, useTextPassThroughValue } from './utils'
|
|
16
16
|
import { error, isFunction } from '@mpxjs/utils'
|
|
17
|
+
import * as perf from '@mpxjs/perf'
|
|
17
18
|
import LinearGradient from 'react-native-linear-gradient'
|
|
18
19
|
import { GestureDetector, PanGesture } from 'react-native-gesture-handler'
|
|
19
20
|
import Portal from './mpx-portal'
|
|
@@ -681,16 +682,16 @@ interface WrapChildrenConfig {
|
|
|
681
682
|
backgroundStyle?: ExtendedViewStyle
|
|
682
683
|
varContext?: Record<string, any>
|
|
683
684
|
textProps?: Record<string, any>
|
|
685
|
+
textPassThrough?: ReturnType<typeof useTextPassThroughValue>
|
|
684
686
|
innerStyle?: Record<string, any>
|
|
685
687
|
enableFastImage?: boolean
|
|
686
688
|
}
|
|
687
689
|
|
|
688
|
-
function wrapWithChildren (props: _ViewProps, { hasVarDec, enableBackground,
|
|
690
|
+
function wrapWithChildren (props: _ViewProps, { hasVarDec, enableBackground, backgroundStyle, varContext, textPassThrough, innerStyle, enableFastImage }: WrapChildrenConfig) {
|
|
689
691
|
const children = wrapChildren(props, {
|
|
690
692
|
hasVarDec,
|
|
691
693
|
varContext,
|
|
692
|
-
|
|
693
|
-
textProps
|
|
694
|
+
textPassThrough
|
|
694
695
|
})
|
|
695
696
|
|
|
696
697
|
return [
|
|
@@ -701,6 +702,13 @@ function wrapWithChildren (props: _ViewProps, { hasVarDec, enableBackground, tex
|
|
|
701
702
|
}
|
|
702
703
|
|
|
703
704
|
const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, ref): JSX.Element => {
|
|
705
|
+
// 性能探针 - total
|
|
706
|
+
let stopTotal: (() => void) | undefined
|
|
707
|
+
if (__mpx_perf_framework__) stopTotal = perf.scope('view:render:total')
|
|
708
|
+
|
|
709
|
+
// ───── props 阶段 ─────
|
|
710
|
+
let stopProps: (() => void) | undefined
|
|
711
|
+
if (__mpx_perf_framework__) stopProps = perf.scope('view:render:props')
|
|
704
712
|
const { textProps, innerProps: props = {} } = splitProps(viewProps)
|
|
705
713
|
let {
|
|
706
714
|
style = {},
|
|
@@ -734,7 +742,11 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
734
742
|
const { isHover, gesture } = useHover({ enableHover, hoverStartTime, hoverStayTime })
|
|
735
743
|
|
|
736
744
|
const styleObj: ExtendedViewStyle = extendObject({}, defaultStyle, style, isHover ? hoverStyle as ExtendedViewStyle : {})
|
|
745
|
+
if (__mpx_perf_framework__) stopProps!()
|
|
737
746
|
|
|
747
|
+
// ───── style 阶段 ─────
|
|
748
|
+
let stopStyle: (() => void) | undefined
|
|
749
|
+
if (__mpx_perf_framework__) stopStyle = perf.scope('view:render:style')
|
|
738
750
|
const {
|
|
739
751
|
normalStyle,
|
|
740
752
|
hasSelfPercent,
|
|
@@ -752,6 +764,7 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
752
764
|
})
|
|
753
765
|
|
|
754
766
|
const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle)
|
|
767
|
+
const textPassThrough = useTextPassThroughValue(textStyle, textProps)
|
|
755
768
|
|
|
756
769
|
enableBackground = enableBackground || !!backgroundStyle
|
|
757
770
|
const enableBackgroundRef = useRef(enableBackground)
|
|
@@ -783,7 +796,11 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
783
796
|
style: viewStyle,
|
|
784
797
|
transitionend
|
|
785
798
|
})
|
|
799
|
+
if (__mpx_perf_framework__) stopStyle!()
|
|
786
800
|
|
|
801
|
+
// ───── innerProps 阶段 ─────
|
|
802
|
+
let stopInnerProps: (() => void) | undefined
|
|
803
|
+
if (__mpx_perf_framework__) stopInnerProps = perf.scope('view:render:innerProps')
|
|
787
804
|
const innerProps = useInnerProps(
|
|
788
805
|
extendObject(
|
|
789
806
|
{},
|
|
@@ -795,23 +812,31 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
795
812
|
}
|
|
796
813
|
),
|
|
797
814
|
[
|
|
815
|
+
'animation',
|
|
798
816
|
'hover-start-time',
|
|
799
817
|
'hover-stay-time',
|
|
800
818
|
'hover-style',
|
|
801
|
-
'hover-class'
|
|
819
|
+
'hover-class',
|
|
820
|
+
'enable-fast-image',
|
|
821
|
+
'enable-animation',
|
|
822
|
+
'bindtransitionend',
|
|
823
|
+
'catchtransitionend'
|
|
802
824
|
],
|
|
803
825
|
{
|
|
804
826
|
layoutRef
|
|
805
827
|
}
|
|
806
828
|
)
|
|
829
|
+
if (__mpx_perf_framework__) stopInnerProps!()
|
|
807
830
|
|
|
831
|
+
// ───── createElement 阶段 ─────
|
|
832
|
+
let stopCreate: (() => void) | undefined
|
|
833
|
+
if (__mpx_perf_framework__) stopCreate = perf.scope('view:render:createElement')
|
|
808
834
|
const childNode = wrapWithChildren(props, {
|
|
809
835
|
hasVarDec,
|
|
810
836
|
enableBackground: enableBackgroundRef.current,
|
|
811
|
-
textStyle,
|
|
812
837
|
backgroundStyle,
|
|
813
838
|
varContext: varContextRef.current,
|
|
814
|
-
|
|
839
|
+
textPassThrough,
|
|
815
840
|
innerStyle,
|
|
816
841
|
enableFastImage
|
|
817
842
|
})
|
|
@@ -827,6 +852,9 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
827
852
|
if (hasPositionFixed) {
|
|
828
853
|
finalComponent = createElement(Portal, null, finalComponent)
|
|
829
854
|
}
|
|
855
|
+
if (__mpx_perf_framework__) stopCreate!()
|
|
856
|
+
|
|
857
|
+
if (__mpx_perf_framework__) stopTotal!()
|
|
830
858
|
return finalComponent
|
|
831
859
|
})
|
|
832
860
|
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
declare let __mpx_mode__: 'wx' | 'ali' | 'swan' | 'qq' | 'tt' | 'web' | 'dd' | 'qa' | 'jd' | 'android' | 'ios' | 'harmony'
|
|
2
|
+
// 性能探针开关(DefinePlugin 注入)。详见 packages/webpack-plugin/lib/utils/normalize-perf-options.js
|
|
3
|
+
declare const __mpx_perf__: boolean
|
|
4
|
+
declare const __mpx_perf_framework__: boolean
|
|
5
|
+
declare const __mpx_perf_user__: boolean
|
|
2
6
|
declare module '@mpxjs/utils' {
|
|
3
7
|
export function isEmptyObject (obj: Object): boolean
|
|
4
8
|
export function isFunction (fn: unknown): boolean
|
|
@@ -1,23 +1,39 @@
|
|
|
1
|
-
import { useEffect, useCallback, useMemo, useRef, ReactNode, ReactElement, isValidElement, useContext, useState, Dispatch, SetStateAction,
|
|
1
|
+
import { useEffect, useCallback, useMemo, useRef, ReactNode, ReactElement, isValidElement, useContext, useState, Dispatch, SetStateAction, createElement, MutableRefObject } from 'react'
|
|
2
2
|
import { LayoutChangeEvent, TextStyle, ImageProps, Image } from 'react-native'
|
|
3
3
|
import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn } from '@mpxjs/utils'
|
|
4
|
-
import { VarContext, ScrollViewContext, RouteContext } from './context'
|
|
4
|
+
import { VarContext, ScrollViewContext, RouteContext, TextPassThroughContext, TextPassThroughContextValue } from './context'
|
|
5
5
|
import { ExpressionParser, parseFunc, ReplaceSource } from './parser'
|
|
6
6
|
import { initialWindowMetrics } from 'react-native-safe-area-context'
|
|
7
|
-
import type { FastImageProps } from '@d11/react-native-fast-image'
|
|
8
7
|
import type { AnyFunc, ExtendedFunctionComponent } from './types/common'
|
|
9
8
|
import { Gesture } from 'react-native-gesture-handler'
|
|
10
9
|
|
|
11
|
-
export const
|
|
10
|
+
export const TEXT_STYLE_MAP: Record<string, boolean> = {
|
|
11
|
+
color: true,
|
|
12
|
+
letterSpacing: true,
|
|
13
|
+
lineHeight: true,
|
|
14
|
+
includeFontPadding: true,
|
|
15
|
+
writingDirection: true
|
|
16
|
+
}
|
|
12
17
|
export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/
|
|
13
18
|
export const URL_REGEX = /^\s*url\(["']?(.*?)["']?\)\s*$/
|
|
14
|
-
export const SVG_REGEXP =
|
|
15
|
-
export const
|
|
16
|
-
|
|
19
|
+
export const SVG_REGEXP = /\.svg(?:[?#].*)?$/i
|
|
20
|
+
export const BACKGROUND_STYLE_MAP: Record<string, boolean> = {
|
|
21
|
+
backgroundImage: true,
|
|
22
|
+
backgroundSize: true,
|
|
23
|
+
backgroundRepeat: true,
|
|
24
|
+
backgroundPosition: true
|
|
25
|
+
}
|
|
26
|
+
export const TEXT_PROPS_MAP: Record<string, boolean> = {
|
|
27
|
+
ellipsizeMode: true,
|
|
28
|
+
numberOfLines: true
|
|
29
|
+
}
|
|
17
30
|
export const DEFAULT_FONT_SIZE = 16
|
|
18
31
|
export const HIDDEN_STYLE = {
|
|
19
32
|
opacity: 0
|
|
20
33
|
}
|
|
34
|
+
export const DEFAULT_BOX_SIZING_STYLE = {
|
|
35
|
+
boxSizing: 'content-box'
|
|
36
|
+
}
|
|
21
37
|
|
|
22
38
|
declare const __mpx_mode__: 'ios' | 'android' | 'harmony'
|
|
23
39
|
|
|
@@ -30,9 +46,19 @@ const varUseRegExp = /var\(/
|
|
|
30
46
|
const unoVarDecRegExp = /^--un-/
|
|
31
47
|
const unoVarUseRegExp = /var\(--un-/
|
|
32
48
|
const calcUseRegExp = /calc\(/
|
|
33
|
-
const calcPercentExp = /^calc\(.*-?\d+(\.\d+)?%.*\)$/
|
|
34
49
|
const envUseRegExp = /env\(/
|
|
35
|
-
const
|
|
50
|
+
const boxSizingAffectingStyleMap: Record<string, boolean> = {
|
|
51
|
+
padding: true,
|
|
52
|
+
paddingTop: true,
|
|
53
|
+
paddingRight: true,
|
|
54
|
+
paddingBottom: true,
|
|
55
|
+
paddingLeft: true,
|
|
56
|
+
borderWidth: true,
|
|
57
|
+
borderTopWidth: true,
|
|
58
|
+
borderRightWidth: true,
|
|
59
|
+
borderBottomWidth: true,
|
|
60
|
+
borderLeftWidth: true
|
|
61
|
+
}
|
|
36
62
|
|
|
37
63
|
const safeAreaInsetMap: Record<string, 'top' | 'right' | 'bottom' | 'left'> = {
|
|
38
64
|
'safe-area-inset-top': 'top',
|
|
@@ -43,6 +69,25 @@ const safeAreaInsetMap: Record<string, 'top' | 'right' | 'bottom' | 'left'> = {
|
|
|
43
69
|
|
|
44
70
|
export const extendObject = Object.assign
|
|
45
71
|
|
|
72
|
+
export function getDefaultAllowFontScaling (): boolean {
|
|
73
|
+
return global.__mpx?.config?.rnConfig?.allowFontScaling ?? false
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function transformBoxSizing (style: Record<string, any> = {}, hasBoxSizingAffectingStyle = false) {
|
|
77
|
+
if (hasBoxSizingAffectingStyle && style.boxSizing === undefined) {
|
|
78
|
+
style.boxSizing = global.__mpx?.config?.rnConfig?.defaultBoxSizing ?? DEFAULT_BOX_SIZING_STYLE.boxSizing
|
|
79
|
+
}
|
|
80
|
+
return style
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function isBoxSizingAffectingStyle (key: string) {
|
|
84
|
+
return hasOwn(boxSizingAffectingStyleMap, key)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function isTextStyle (key: string) {
|
|
88
|
+
return hasOwn(TEXT_STYLE_MAP, key) || key.startsWith('font') || key.startsWith('text')
|
|
89
|
+
}
|
|
90
|
+
|
|
46
91
|
function getSafeAreaInset (name: string, navigation: Record<string, any> | undefined) {
|
|
47
92
|
const insets = extendObject({}, initialWindowMetrics?.insets, navigation?.insets)
|
|
48
93
|
return insets[safeAreaInsetMap[name]]
|
|
@@ -107,12 +152,14 @@ export function isText (ele: ReactNode): ele is ReactElement {
|
|
|
107
152
|
return false
|
|
108
153
|
}
|
|
109
154
|
|
|
110
|
-
export function
|
|
111
|
-
|
|
112
|
-
|
|
155
|
+
export function isStringChildren (children: ReactNode) {
|
|
156
|
+
if (typeof children === 'string') return true
|
|
157
|
+
if (!Array.isArray(children)) return false
|
|
158
|
+
return children.every((child) => typeof child === 'string')
|
|
113
159
|
}
|
|
114
160
|
|
|
115
161
|
type GroupData<T> = Record<string, Partial<T>>
|
|
162
|
+
|
|
116
163
|
export function groupBy<T extends Record<string, any>> (
|
|
117
164
|
obj: T,
|
|
118
165
|
callback: (key: string, val: T[keyof T]) => string,
|
|
@@ -126,24 +173,21 @@ export function groupBy<T extends Record<string, any>> (
|
|
|
126
173
|
return group
|
|
127
174
|
}
|
|
128
175
|
|
|
129
|
-
export function splitStyle<T extends Record<string, any>> (styleObj: T): {
|
|
176
|
+
export function splitStyle<T extends Record<string, any>> (styleObj: T, sideEffect?: (key: string, val: T[keyof T]) => void): {
|
|
130
177
|
textStyle?: Partial<T>
|
|
131
178
|
backgroundStyle?: Partial<T>
|
|
132
179
|
innerStyle?: Partial<T>
|
|
133
180
|
} {
|
|
134
|
-
return groupBy(styleObj, (key) => {
|
|
135
|
-
|
|
181
|
+
return groupBy(styleObj, (key, val) => {
|
|
182
|
+
sideEffect && sideEffect(key, val)
|
|
183
|
+
if (isTextStyle(key)) {
|
|
136
184
|
return 'textStyle'
|
|
137
|
-
} else if (
|
|
185
|
+
} else if (hasOwn(BACKGROUND_STYLE_MAP, key)) {
|
|
138
186
|
return 'backgroundStyle'
|
|
139
187
|
} else {
|
|
140
188
|
return 'innerStyle'
|
|
141
189
|
}
|
|
142
|
-
})
|
|
143
|
-
textStyle: Partial<T>
|
|
144
|
-
backgroundStyle: Partial<T>
|
|
145
|
-
innerStyle: Partial<T>
|
|
146
|
-
}
|
|
190
|
+
})
|
|
147
191
|
}
|
|
148
192
|
const radiusPercentRule: Record<string, 'height' | 'width'> = {
|
|
149
193
|
borderTopLeftRadius: 'width',
|
|
@@ -416,6 +460,7 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
416
460
|
let hasVarDec = false
|
|
417
461
|
let hasVarUse = false
|
|
418
462
|
let hasSelfPercent = false
|
|
463
|
+
let hasBoxSizingAffectingStyle = false
|
|
419
464
|
const varKeyPaths: Array<Array<string>> = []
|
|
420
465
|
const unoVarKeyPaths: Array<Array<string>> = []
|
|
421
466
|
const percentKeyPaths: Array<Array<string>> = []
|
|
@@ -451,19 +496,20 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
451
496
|
}
|
|
452
497
|
}
|
|
453
498
|
|
|
499
|
+
function boxSizingVisitor ({ key, keyPath }: VisitorArg) {
|
|
500
|
+
if (keyPath.length === 1 && !hasBoxSizingAffectingStyle && isBoxSizingAffectingStyle(key)) {
|
|
501
|
+
hasBoxSizingAffectingStyle = true
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
454
505
|
function envVisitor ({ value, keyPath }: VisitorArg) {
|
|
455
506
|
if (envUseRegExp.test(value)) {
|
|
456
507
|
envKeyPaths.push(keyPath.slice())
|
|
457
508
|
}
|
|
458
509
|
}
|
|
459
510
|
|
|
460
|
-
function calcVisitor ({
|
|
511
|
+
function calcVisitor ({ value, keyPath }: VisitorArg) {
|
|
461
512
|
if (calcUseRegExp.test(value)) {
|
|
462
|
-
// calc translate & border-radius 的百分比计算
|
|
463
|
-
if (hasOwn(selfPercentRule, key) && calcPercentExp.test(value)) {
|
|
464
|
-
hasSelfPercent = true
|
|
465
|
-
percentKeyPaths.push(keyPath.slice())
|
|
466
|
-
}
|
|
467
513
|
calcKeyPaths.push(keyPath.slice())
|
|
468
514
|
}
|
|
469
515
|
}
|
|
@@ -480,13 +526,13 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
480
526
|
}
|
|
481
527
|
|
|
482
528
|
function visitOther ({ target, key, value, keyPath }: VisitorArg) {
|
|
483
|
-
if (
|
|
529
|
+
if (typeof value === 'string' && (value.includes('%') || value.includes('calc(') || value.includes('env('))) {
|
|
484
530
|
[envVisitor, percentVisitor, calcVisitor].forEach(visitor => visitor({ target, key, value, keyPath }))
|
|
485
531
|
}
|
|
486
532
|
}
|
|
487
533
|
|
|
488
534
|
// traverse var & generate normalStyle
|
|
489
|
-
traverseStyle(styleObj, [varVisitor])
|
|
535
|
+
traverseStyle(styleObj, [varVisitor, boxSizingVisitor])
|
|
490
536
|
hasVarDec = hasVarDec || !!externalVarContext
|
|
491
537
|
enableVar = enableVar || hasVarDec || hasVarUse
|
|
492
538
|
const enableVarRef = useRef(enableVar)
|
|
@@ -531,6 +577,9 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
531
577
|
// apply calc
|
|
532
578
|
transformCalc(normalStyle, calcKeyPaths, (value: string, key: string) => {
|
|
533
579
|
if (PERCENT_REGEX.test(value)) {
|
|
580
|
+
if (hasOwn(selfPercentRule, key)) {
|
|
581
|
+
hasSelfPercent = true
|
|
582
|
+
}
|
|
534
583
|
const resolved = resolvePercent(value, key, percentConfig)
|
|
535
584
|
return typeof resolved === 'number' ? resolved : 0
|
|
536
585
|
} else {
|
|
@@ -552,6 +601,7 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
552
601
|
transformBoxShadow(normalStyle)
|
|
553
602
|
// transform 字符串格式转化数组格式(先转数组再处理css var)
|
|
554
603
|
transformTransform(normalStyle)
|
|
604
|
+
transformBoxSizing(normalStyle, hasBoxSizingAffectingStyle)
|
|
555
605
|
|
|
556
606
|
return {
|
|
557
607
|
hasVarDec,
|
|
@@ -614,7 +664,7 @@ export function splitProps<T extends Record<string, any>> (props: T): {
|
|
|
614
664
|
innerProps?: Partial<T>
|
|
615
665
|
} {
|
|
616
666
|
return groupBy(props, (key) => {
|
|
617
|
-
if (
|
|
667
|
+
if (hasOwn(TEXT_PROPS_MAP, key)) {
|
|
618
668
|
return 'textProps'
|
|
619
669
|
} else {
|
|
620
670
|
return 'innerProps'
|
|
@@ -668,20 +718,50 @@ export const useLayout = ({ props, hasSelfPercent, setWidth, setHeight, onLayout
|
|
|
668
718
|
export interface WrapChildrenConfig {
|
|
669
719
|
hasVarDec: boolean
|
|
670
720
|
varContext?: Record<string, any>
|
|
671
|
-
|
|
672
|
-
textProps?: Record<string, any>
|
|
721
|
+
textPassThrough?: TextPassThroughContextValue | null
|
|
673
722
|
}
|
|
674
723
|
|
|
675
|
-
export
|
|
724
|
+
export interface TextPassThroughValueOptions {
|
|
725
|
+
inheritTextProps?: boolean
|
|
726
|
+
disabled?: boolean
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
export function useTextPassThroughValue (
|
|
730
|
+
textStyle?: TextStyle,
|
|
731
|
+
textProps?: Record<string, any>,
|
|
732
|
+
{ inheritTextProps = true, disabled = false }: TextPassThroughValueOptions = {}
|
|
733
|
+
) {
|
|
734
|
+
const parent = useContext(TextPassThroughContext)
|
|
735
|
+
const valueRef = useRef<TextPassThroughContextValue | null>(null)
|
|
736
|
+
|
|
737
|
+
if (disabled) return null
|
|
738
|
+
|
|
739
|
+
if (!textStyle && !textProps && (inheritTextProps || !parent?.pendingTextProps)) return null
|
|
740
|
+
|
|
741
|
+
const nextTextStyle = textStyle
|
|
742
|
+
? extendObject({}, parent?.textStyle, textStyle)
|
|
743
|
+
: parent?.textStyle
|
|
744
|
+
const nextTextProps = inheritTextProps
|
|
745
|
+
? textProps
|
|
746
|
+
? extendObject({}, parent?.pendingTextProps, textProps)
|
|
747
|
+
: parent?.pendingTextProps
|
|
748
|
+
: textProps
|
|
749
|
+
const nextValue = {
|
|
750
|
+
textStyle: nextTextStyle,
|
|
751
|
+
pendingTextProps: nextTextProps
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
if (diffAndCloneA(valueRef.current, nextValue).diff) {
|
|
755
|
+
valueRef.current = nextValue
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
return valueRef.current
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
export function wrapChildren (props: Record<string, any> = {}, { hasVarDec, varContext, textPassThrough }: WrapChildrenConfig) {
|
|
676
762
|
let { children } = props
|
|
677
|
-
if (
|
|
678
|
-
children =
|
|
679
|
-
if (isText(child)) {
|
|
680
|
-
const style = extendObject({}, textStyle, child.props.style)
|
|
681
|
-
return cloneElement(child, extendObject({}, textProps, { style }))
|
|
682
|
-
}
|
|
683
|
-
return child
|
|
684
|
-
})
|
|
763
|
+
if (textPassThrough) {
|
|
764
|
+
children = <TextPassThroughContext.Provider value={textPassThrough} key='textPassThroughWrap'>{children}</TextPassThroughContext.Provider>
|
|
685
765
|
}
|
|
686
766
|
if (hasVarDec && varContext) {
|
|
687
767
|
children = <VarContext.Provider value={varContext} key='varContextWrap'>{children}</VarContext.Provider>
|
|
@@ -755,10 +835,10 @@ export function getCurrentPage (pageId: number | null | undefined) {
|
|
|
755
835
|
}
|
|
756
836
|
|
|
757
837
|
export function renderImage (
|
|
758
|
-
imageProps: ImageProps
|
|
838
|
+
imageProps: ImageProps,
|
|
759
839
|
enableFastImage = true
|
|
760
840
|
) {
|
|
761
|
-
let Component
|
|
841
|
+
let Component = Image
|
|
762
842
|
if (enableFastImage) {
|
|
763
843
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
764
844
|
const fastImageModule = require('@d11/react-native-fast-image')
|
|
@@ -14,6 +14,11 @@ export function getComponent (component, extendOptions) {
|
|
|
14
14
|
// eslint-disable-next-line
|
|
15
15
|
if (extendOptions && !component.__mpxExtended) {
|
|
16
16
|
extend(component, extendOptions, { __mpxExtended: true })
|
|
17
|
+
const render = (component.type && component.type.render) || component.render
|
|
18
|
+
const displayName = extendOptions.displayName || component.displayName
|
|
19
|
+
if (render && displayName && !render.displayName) {
|
|
20
|
+
render.displayName = displayName
|
|
21
|
+
}
|
|
17
22
|
}
|
|
18
23
|
return component
|
|
19
24
|
}
|
|
@@ -3,7 +3,7 @@ const MagicString = require('magic-string')
|
|
|
3
3
|
const { SourceMapConsumer, SourceMapGenerator } = require('source-map')
|
|
4
4
|
const traverse = require('@babel/traverse').default
|
|
5
5
|
const t = require('@babel/types')
|
|
6
|
-
const formatCodeFrame = require('@babel/code-frame')
|
|
6
|
+
const { default: formatCodeFrame } = require('@babel/code-frame')
|
|
7
7
|
const parseRequest = require('../utils/parse-request')
|
|
8
8
|
|
|
9
9
|
// Special compiler macros
|
|
@@ -18,7 +18,7 @@ module.exports = ({ id, transPage = false }) => {
|
|
|
18
18
|
}))
|
|
19
19
|
selector.insertAfter(n, compoundSelectors)
|
|
20
20
|
}
|
|
21
|
-
if (transPage &&
|
|
21
|
+
if (transPage && n.type === 'tag' && n.value === 'page') {
|
|
22
22
|
const compoundSelectors = n.nodes || []
|
|
23
23
|
n.replaceWith(selectorParser.className({
|
|
24
24
|
value: MPX_TAG_PAGE_SELECTOR
|