@mpxjs/webpack-plugin 2.10.4 → 2.10.5
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/platform/style/wx/index.js +22 -21
- package/lib/react/processScript.js +9 -1
- package/lib/react/script-helper.js +5 -1
- package/lib/runtime/components/react/dist/event.config.js +0 -2
- package/lib/runtime/components/react/dist/getInnerListeners.js +127 -153
- package/lib/runtime/components/react/dist/mpx-button.jsx +2 -3
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +3 -4
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +2 -3
- package/lib/runtime/components/react/dist/mpx-form.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-icon/index.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-image.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-input.jsx +17 -11
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +22 -29
- package/lib/runtime/components/react/dist/mpx-label.jsx +2 -3
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +11 -3
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +2 -3
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +4 -4
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-radio.jsx +2 -3
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +3 -2
- package/lib/runtime/components/react/dist/mpx-simple-view.jsx +3 -3
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -5
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +9 -9
- package/lib/runtime/components/react/dist/mpx-switch.jsx +3 -5
- package/lib/runtime/components/react/dist/mpx-text.jsx +4 -7
- package/lib/runtime/components/react/dist/mpx-video.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-view.jsx +13 -6
- package/lib/runtime/components/react/dist/useAnimationHooks.js +27 -4
- package/lib/runtime/components/react/dist/utils.jsx +85 -95
- package/lib/runtime/components/react/event.config.ts +1 -8
- package/lib/runtime/components/react/getInnerListeners.ts +146 -192
- package/lib/runtime/components/react/mpx-button.tsx +4 -5
- package/lib/runtime/components/react/mpx-canvas/index.tsx +23 -15
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +4 -3
- package/lib/runtime/components/react/mpx-checkbox.tsx +8 -9
- package/lib/runtime/components/react/mpx-form.tsx +25 -19
- package/lib/runtime/components/react/mpx-icon/index.tsx +4 -3
- package/lib/runtime/components/react/mpx-image.tsx +4 -3
- package/lib/runtime/components/react/mpx-input.tsx +22 -15
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +30 -41
- package/lib/runtime/components/react/mpx-label.tsx +4 -5
- package/lib/runtime/components/react/mpx-movable-area.tsx +22 -13
- package/lib/runtime/components/react/mpx-movable-view.tsx +47 -40
- package/lib/runtime/components/react/mpx-navigator.tsx +4 -6
- package/lib/runtime/components/react/mpx-picker/index.tsx +7 -4
- package/lib/runtime/components/react/mpx-picker-view/index.tsx +17 -14
- package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +4 -4
- package/lib/runtime/components/react/mpx-radio-group.tsx +4 -3
- package/lib/runtime/components/react/mpx-radio.tsx +8 -9
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +15 -6
- package/lib/runtime/components/react/mpx-scroll-view.tsx +96 -90
- package/lib/runtime/components/react/mpx-simple-text.tsx +10 -3
- package/lib/runtime/components/react/mpx-simple-view.tsx +10 -4
- package/lib/runtime/components/react/mpx-swiper-item.tsx +31 -24
- package/lib/runtime/components/react/mpx-swiper.tsx +67 -61
- package/lib/runtime/components/react/mpx-switch.tsx +19 -14
- package/lib/runtime/components/react/mpx-text.tsx +16 -13
- package/lib/runtime/components/react/mpx-video.tsx +34 -33
- package/lib/runtime/components/react/mpx-view.tsx +30 -14
- package/lib/runtime/components/react/types/getInnerListeners.d.ts +65 -35
- package/lib/runtime/components/react/useAnimationHooks.ts +30 -9
- package/lib/runtime/components/react/utils.tsx +91 -98
- package/lib/template-compiler/compiler.js +1 -1
- package/package.json +3 -3
|
@@ -76,36 +76,36 @@ import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
|
76
76
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
77
77
|
|
|
78
78
|
interface VideoProps {
|
|
79
|
-
src: string
|
|
80
|
-
autoplay?: boolean
|
|
81
|
-
loop?: boolean
|
|
82
|
-
muted?: boolean
|
|
83
|
-
controls?: boolean
|
|
84
|
-
poster?: string
|
|
85
|
-
style?: ViewStyle
|
|
86
|
-
'initial-time'?: number
|
|
87
|
-
'object-fit'?: null | 'contain' | 'fill' | 'cover'
|
|
88
|
-
'is-drm'?: boolean
|
|
89
|
-
'provision-url'?: string
|
|
90
|
-
'certificate-url'?: string
|
|
91
|
-
'license-url'?: string
|
|
92
|
-
'preferred-peak-bit-rate'?: number
|
|
93
|
-
'enable-auto-rotation'?: number
|
|
94
|
-
'enable-var'?: boolean
|
|
95
|
-
'external-var-context'?: Record<string, any
|
|
96
|
-
'parent-font-size'?: number
|
|
97
|
-
'parent-width'?: number
|
|
98
|
-
'parent-height'?: number
|
|
99
|
-
bindplay?: (event: Record<string, any>) => void
|
|
100
|
-
bindpause?: (event: Record<string, any>) => void
|
|
101
|
-
bindended?: (event: Record<string, any>) => void
|
|
102
|
-
bindtimeupdate?: (event: Record<string, any>) => void
|
|
103
|
-
bindfullscreenchange?: (event: Record<string, any>) => void
|
|
104
|
-
bindwaiting?: (event: Record<string, any>) => void
|
|
105
|
-
binderror?: (event: Record<string, any>) => void
|
|
106
|
-
bindloadedmetadata?: (event: Record<string, any>) => void
|
|
107
|
-
bindcontrolstoggle?: (event: Record<string, any>) => void
|
|
108
|
-
bindseekcomplete?: (event: Record<string, any>) => void
|
|
79
|
+
src: string
|
|
80
|
+
autoplay?: boolean
|
|
81
|
+
loop?: boolean
|
|
82
|
+
muted?: boolean
|
|
83
|
+
controls?: boolean
|
|
84
|
+
poster?: string
|
|
85
|
+
style?: ViewStyle
|
|
86
|
+
'initial-time'?: number
|
|
87
|
+
'object-fit'?: null | 'contain' | 'fill' | 'cover'
|
|
88
|
+
'is-drm'?: boolean
|
|
89
|
+
'provision-url'?: string
|
|
90
|
+
'certificate-url'?: string
|
|
91
|
+
'license-url'?: string
|
|
92
|
+
'preferred-peak-bit-rate'?: number
|
|
93
|
+
'enable-auto-rotation'?: number
|
|
94
|
+
'enable-var'?: boolean
|
|
95
|
+
'external-var-context'?: Record<string, any>
|
|
96
|
+
'parent-font-size'?: number
|
|
97
|
+
'parent-width'?: number
|
|
98
|
+
'parent-height'?: number
|
|
99
|
+
bindplay?: (event: Record<string, any>) => void
|
|
100
|
+
bindpause?: (event: Record<string, any>) => void
|
|
101
|
+
bindended?: (event: Record<string, any>) => void
|
|
102
|
+
bindtimeupdate?: (event: Record<string, any>) => void
|
|
103
|
+
bindfullscreenchange?: (event: Record<string, any>) => void
|
|
104
|
+
bindwaiting?: (event: Record<string, any>) => void
|
|
105
|
+
binderror?: (event: Record<string, any>) => void
|
|
106
|
+
bindloadedmetadata?: (event: Record<string, any>) => void
|
|
107
|
+
bindcontrolstoggle?: (event: Record<string, any>) => void
|
|
108
|
+
bindseekcomplete?: (event: Record<string, any>) => void
|
|
109
109
|
}
|
|
110
110
|
interface VideoInfoData {
|
|
111
111
|
naturalSize: {
|
|
@@ -332,8 +332,10 @@ const MpxVideo = forwardRef<HandlerRef<View, VideoProps>, VideoProps>((videoProp
|
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
const innerProps = useInnerProps(
|
|
335
|
-
props,
|
|
336
335
|
extendObject(
|
|
336
|
+
{},
|
|
337
|
+
props,
|
|
338
|
+
layoutProps,
|
|
337
339
|
{
|
|
338
340
|
style: styles.video,
|
|
339
341
|
ref: videoRef,
|
|
@@ -360,8 +362,7 @@ const MpxVideo = forwardRef<HandlerRef<View, VideoProps>, VideoProps>((videoProp
|
|
|
360
362
|
onControlsVisibilityChange:
|
|
361
363
|
bindcontrolstoggle && handleAndroidControlsVisibilityChange,
|
|
362
364
|
onLoad: handleVideoLoad
|
|
363
|
-
}
|
|
364
|
-
layoutProps
|
|
365
|
+
}
|
|
365
366
|
),
|
|
366
367
|
[
|
|
367
368
|
'src',
|
|
@@ -13,7 +13,7 @@ import type { AnimationProp } from './useAnimationHooks'
|
|
|
13
13
|
import { ExtendedViewStyle } from './types/common'
|
|
14
14
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
15
15
|
import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout, renderImage, pickStyle, extendObject, useHover } from './utils'
|
|
16
|
-
import { error } from '@mpxjs/utils'
|
|
16
|
+
import { error, isFunction } from '@mpxjs/utils'
|
|
17
17
|
import LinearGradient from 'react-native-linear-gradient'
|
|
18
18
|
import { GestureDetector, PanGesture } from 'react-native-gesture-handler'
|
|
19
19
|
import Portal from './mpx-portal'
|
|
@@ -36,6 +36,8 @@ export interface _ViewProps extends ViewProps {
|
|
|
36
36
|
bindtouchstart?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
37
37
|
bindtouchmove?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
38
38
|
bindtouchend?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
39
|
+
bindtransitionend?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
40
|
+
catchtransitionend?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
type Handler = (...args: any[]) => void
|
|
@@ -683,7 +685,9 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
683
685
|
'parent-font-size': parentFontSize,
|
|
684
686
|
'parent-width': parentWidth,
|
|
685
687
|
'parent-height': parentHeight,
|
|
686
|
-
animation
|
|
688
|
+
animation,
|
|
689
|
+
catchtransitionend,
|
|
690
|
+
bindtransitionend
|
|
687
691
|
} = props
|
|
688
692
|
|
|
689
693
|
// 默认样式
|
|
@@ -737,28 +741,40 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
737
741
|
} = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
738
742
|
|
|
739
743
|
const viewStyle = extendObject({}, innerStyle, layoutStyle)
|
|
740
|
-
|
|
744
|
+
const transitionend = isFunction(catchtransitionend)
|
|
745
|
+
? catchtransitionend
|
|
746
|
+
: isFunction(bindtransitionend)
|
|
747
|
+
? bindtransitionend
|
|
748
|
+
: undefined
|
|
741
749
|
const { enableStyleAnimation, animationStyle } = useAnimationHooks({
|
|
742
|
-
|
|
750
|
+
layoutRef,
|
|
743
751
|
animation,
|
|
744
|
-
|
|
752
|
+
enableAnimation,
|
|
753
|
+
style: viewStyle,
|
|
754
|
+
transitionend
|
|
745
755
|
})
|
|
746
756
|
|
|
747
757
|
const innerProps = useInnerProps(
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
758
|
+
extendObject(
|
|
759
|
+
{},
|
|
760
|
+
props,
|
|
761
|
+
layoutProps,
|
|
762
|
+
{
|
|
763
|
+
ref: nodeRef,
|
|
764
|
+
style: enableStyleAnimation ? [viewStyle, animationStyle] : viewStyle
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
),
|
|
768
|
+
[
|
|
755
769
|
'hover-start-time',
|
|
756
770
|
'hover-stay-time',
|
|
757
771
|
'hover-style',
|
|
758
772
|
'hover-class'
|
|
759
|
-
],
|
|
773
|
+
],
|
|
774
|
+
{
|
|
760
775
|
layoutRef
|
|
761
|
-
}
|
|
776
|
+
}
|
|
777
|
+
)
|
|
762
778
|
|
|
763
779
|
const childNode = wrapWithChildren(props, {
|
|
764
780
|
hasVarDec,
|
|
@@ -1,58 +1,85 @@
|
|
|
1
|
-
import { MutableRefObject } from 'react'
|
|
1
|
+
import { RefObject, MutableRefObject } from 'react'
|
|
2
2
|
import { NativeSyntheticEvent } from 'react-native'
|
|
3
3
|
|
|
4
|
-
type LayoutRef = MutableRefObject<
|
|
4
|
+
type LayoutRef = MutableRefObject<{
|
|
5
|
+
x?: number
|
|
6
|
+
y?: number
|
|
7
|
+
width?: number
|
|
8
|
+
height?: number
|
|
9
|
+
offsetLeft?: number
|
|
10
|
+
offsetTop?: number
|
|
11
|
+
} | null>
|
|
5
12
|
|
|
6
|
-
type
|
|
13
|
+
type InnerRef = MutableRefObject<{
|
|
14
|
+
startTimer: {
|
|
15
|
+
bubble: ReturnType<typeof setTimeout> | null
|
|
16
|
+
capture: ReturnType<typeof setTimeout> | null
|
|
17
|
+
}
|
|
18
|
+
mpxPressInfo: {
|
|
19
|
+
detail: {
|
|
20
|
+
x: number
|
|
21
|
+
y: number
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}>
|
|
25
|
+
|
|
26
|
+
type PropsRef = MutableRefObject<Props>
|
|
27
|
+
|
|
28
|
+
type EventType = 'bubble' | 'capture'
|
|
7
29
|
|
|
8
30
|
type Props = Record<string, any>
|
|
9
31
|
|
|
10
|
-
type AdditionalProps = Record<string, any
|
|
32
|
+
type AdditionalProps = Record<string, any>
|
|
11
33
|
|
|
12
|
-
type RemoveProps = string[]
|
|
34
|
+
type RemoveProps = string[]
|
|
13
35
|
|
|
14
36
|
type NativeTouchEvent = NativeSyntheticEvent<NativeEvent>
|
|
15
37
|
|
|
16
38
|
type Navigation = Record<string, any> | undefined
|
|
17
39
|
|
|
40
|
+
interface EventConfigDetail {
|
|
41
|
+
bubble: string[],
|
|
42
|
+
capture: string[],
|
|
43
|
+
hasCatch: boolean
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type EventConfig = {
|
|
47
|
+
innerRef: InnerRef
|
|
48
|
+
propsRef: PropsRef
|
|
49
|
+
disableTap: boolean
|
|
50
|
+
layoutRef: LayoutRef
|
|
51
|
+
navigation: Navigation
|
|
52
|
+
[index: string]: EventConfigDetail
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface RawConfig {
|
|
56
|
+
layoutRef?: LayoutRef
|
|
57
|
+
disableTap?: boolean
|
|
58
|
+
[index: string]: any
|
|
59
|
+
}
|
|
60
|
+
|
|
18
61
|
interface NativeEvent {
|
|
19
|
-
timestamp: number
|
|
20
|
-
pageX: number
|
|
21
|
-
pageY: number
|
|
62
|
+
timestamp: number
|
|
63
|
+
pageX: number
|
|
64
|
+
pageY: number
|
|
22
65
|
touches: TouchPoint[]
|
|
23
66
|
changedTouches: TouchPoint[]
|
|
24
67
|
}
|
|
25
68
|
|
|
26
69
|
interface TouchPoint {
|
|
27
|
-
identifier: number
|
|
28
|
-
pageX: number
|
|
29
|
-
pageY: number
|
|
30
|
-
clientX: number
|
|
31
|
-
clientY: number
|
|
32
|
-
locationX?: number
|
|
33
|
-
locationY?: number
|
|
70
|
+
identifier: number
|
|
71
|
+
pageX: number
|
|
72
|
+
pageY: number
|
|
73
|
+
clientX: number
|
|
74
|
+
clientY: number
|
|
75
|
+
locationX?: number
|
|
76
|
+
locationY?: number
|
|
34
77
|
}
|
|
35
78
|
|
|
36
|
-
interface InnerRef {
|
|
37
|
-
startTimer: {
|
|
38
|
-
bubble: null | ReturnType<typeof setTimeout>;
|
|
39
|
-
capture: null | ReturnType<typeof setTimeout>;
|
|
40
|
-
};
|
|
41
|
-
mpxPressInfo: {
|
|
42
|
-
detail: {
|
|
43
|
-
x: number;
|
|
44
|
-
y: number;
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
interface UseInnerPropsConfig {
|
|
49
|
-
layoutRef?: LayoutRef;
|
|
50
|
-
disableTouch?: boolean;
|
|
51
|
-
disableTap?: boolean
|
|
52
|
-
}
|
|
53
79
|
interface DataSetType {
|
|
54
|
-
[key: string]: string
|
|
80
|
+
[key: string]: string
|
|
55
81
|
}
|
|
82
|
+
|
|
56
83
|
interface ExtendedNativeTouchEvent extends NativeTouchEvent {
|
|
57
84
|
_stoppedEventTypes?: Set<string>
|
|
58
85
|
}
|
|
@@ -65,8 +92,11 @@ export {
|
|
|
65
92
|
UseInnerPropsConfig,
|
|
66
93
|
InnerRef,
|
|
67
94
|
LayoutRef,
|
|
68
|
-
|
|
95
|
+
PropsRef,
|
|
69
96
|
DataSetType,
|
|
70
97
|
Navigation,
|
|
71
|
-
ExtendedNativeTouchEvent
|
|
98
|
+
ExtendedNativeTouchEvent,
|
|
99
|
+
EventConfig,
|
|
100
|
+
RawConfig,
|
|
101
|
+
EventType
|
|
72
102
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef } from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import type { MutableRefObject } from 'react'
|
|
3
|
+
import type { NativeSyntheticEvent, TransformsStyle } from 'react-native'
|
|
3
4
|
import {
|
|
4
5
|
Easing,
|
|
5
6
|
useSharedValue,
|
|
@@ -9,11 +10,10 @@ import {
|
|
|
9
10
|
withDelay,
|
|
10
11
|
makeMutable,
|
|
11
12
|
cancelAnimation,
|
|
12
|
-
|
|
13
|
-
WithTimingConfig,
|
|
14
|
-
AnimationCallback
|
|
13
|
+
runOnJS
|
|
15
14
|
} from 'react-native-reanimated'
|
|
16
|
-
import {
|
|
15
|
+
import type { AnimationCallback, WithTimingConfig, SharedValue, AnimatableValue } from 'react-native-reanimated'
|
|
16
|
+
import { error, hasOwn, collectDataset } from '@mpxjs/utils'
|
|
17
17
|
import { ExtendedViewStyle } from './types/common'
|
|
18
18
|
import type { _ViewProps } from './mpx-view'
|
|
19
19
|
|
|
@@ -175,9 +175,8 @@ function getTransformObj (transforms: { [propName: string]: string | number }[])
|
|
|
175
175
|
}, {} as { [propName: string]: string | number })
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAnimation?: boolean }) {
|
|
179
|
-
const { style = {}, animation, enableAnimation } = props
|
|
180
|
-
|
|
178
|
+
export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAnimation?: boolean, layoutRef: MutableRefObject<any>, transitionend?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void }) {
|
|
179
|
+
const { style = {}, animation, enableAnimation, transitionend, layoutRef } = props
|
|
181
180
|
const enableStyleAnimation = enableAnimation || !!animation
|
|
182
181
|
const enableAnimationRef = useRef(enableStyleAnimation)
|
|
183
182
|
if (enableAnimationRef.current !== enableStyleAnimation) {
|
|
@@ -285,10 +284,32 @@ export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAni
|
|
|
285
284
|
})
|
|
286
285
|
})
|
|
287
286
|
}
|
|
287
|
+
function withTimingCallback (finished?: boolean, current?: AnimatableValue, duration?: number) {
|
|
288
|
+
if (!transitionend) return
|
|
289
|
+
const target = {
|
|
290
|
+
id: animation?.id || -1,
|
|
291
|
+
dataset: collectDataset(props),
|
|
292
|
+
offsetLeft: layoutRef?.current?.offsetLeft || 0,
|
|
293
|
+
offsetTop: layoutRef?.current?.offsetTop || 0
|
|
294
|
+
}
|
|
295
|
+
transitionend({
|
|
296
|
+
type: 'transitionend',
|
|
297
|
+
// elapsedTime 对齐wx 单位s
|
|
298
|
+
detail: { elapsedTime: duration ? duration / 1000 : 0, finished, current },
|
|
299
|
+
target,
|
|
300
|
+
currentTarget: target,
|
|
301
|
+
timeStamp: Date.now()
|
|
302
|
+
})
|
|
303
|
+
}
|
|
288
304
|
// 创建单个animation
|
|
289
305
|
function getAnimation ({ key, value }: { key: string, value: string|number }, { delay, duration, easing }: ExtendWithTimingConfig, callback?: AnimationCallback) {
|
|
290
306
|
const animation = typeof callback === 'function'
|
|
291
|
-
? withTiming(value, { duration, easing },
|
|
307
|
+
? withTiming(value, { duration, easing }, (finished, current) => {
|
|
308
|
+
callback(finished, current)
|
|
309
|
+
if (transitionend && finished) {
|
|
310
|
+
runOnJS(withTimingCallback)(finished, current, duration)
|
|
311
|
+
}
|
|
312
|
+
})
|
|
292
313
|
: withTiming(value, { duration, easing })
|
|
293
314
|
return delay ? withDelay(delay, animation) : animation
|
|
294
315
|
}
|
|
@@ -32,6 +32,7 @@ const unoVarDecRegExp = /^--un-/
|
|
|
32
32
|
const unoVarUseRegExp = /var\(--un-/
|
|
33
33
|
const calcUseRegExp = /calc\(/
|
|
34
34
|
const envUseRegExp = /env\(/
|
|
35
|
+
const filterRegExp = /(calc|env|%)/
|
|
35
36
|
|
|
36
37
|
const safeAreaInsetMap: Record<string, 'top' | 'right' | 'bottom' | 'left'> = {
|
|
37
38
|
'safe-area-inset-top': 'top',
|
|
@@ -168,6 +169,10 @@ interface PercentConfig {
|
|
|
168
169
|
parentHeight?: number
|
|
169
170
|
}
|
|
170
171
|
|
|
172
|
+
interface PositionMeta {
|
|
173
|
+
hasPositionFixed: boolean
|
|
174
|
+
}
|
|
175
|
+
|
|
171
176
|
function resolvePercent (value: string | number | undefined, key: string, percentConfig: PercentConfig): string | number | undefined {
|
|
172
177
|
if (!(typeof value === 'string' && PERCENT_REGEX.test(value))) return value
|
|
173
178
|
let base
|
|
@@ -222,10 +227,11 @@ function resolveVar (input: string, varContext: Record<string, any>) {
|
|
|
222
227
|
return global.__formatValue(replaced.source())
|
|
223
228
|
}
|
|
224
229
|
|
|
225
|
-
function transformVar (styleObj: Record<string, any>, varKeyPaths: Array<Array<string>>, varContext: Record<string, any
|
|
230
|
+
function transformVar (styleObj: Record<string, any>, varKeyPaths: Array<Array<string>>, varContext: Record<string, any>, visitOther: (arg: VisitorArg) => void) {
|
|
226
231
|
varKeyPaths.forEach((varKeyPath) => {
|
|
227
232
|
setStyle(styleObj, varKeyPath, ({ target, key, value }) => {
|
|
228
233
|
target[key] = resolveVar(value, varContext)
|
|
234
|
+
visitOther({ target, key, value: target[key], keyPath: varKeyPath })
|
|
229
235
|
})
|
|
230
236
|
})
|
|
231
237
|
}
|
|
@@ -267,13 +273,17 @@ function transformCalc (styleObj: Record<string, any>, calcKeyPaths: Array<Array
|
|
|
267
273
|
})
|
|
268
274
|
}
|
|
269
275
|
|
|
270
|
-
const stringifyProps = ['fontWeight']
|
|
271
276
|
function transformStringify (styleObj: Record<string, any>) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
+
if (isNumber(styleObj.fontWeight)) {
|
|
278
|
+
styleObj.fontWeight = '' + styleObj.fontWeight
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function transformPosition (styleObj: Record<string, any>, meta: PositionMeta) {
|
|
283
|
+
if (styleObj.position === 'fixed') {
|
|
284
|
+
styleObj.position = 'absolute'
|
|
285
|
+
meta.hasPositionFixed = true
|
|
286
|
+
}
|
|
277
287
|
}
|
|
278
288
|
|
|
279
289
|
interface TransformStyleConfig {
|
|
@@ -288,17 +298,19 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
288
298
|
const varStyle: Record<string, any> = {}
|
|
289
299
|
const unoVarStyle: Record<string, any> = {}
|
|
290
300
|
const normalStyle: Record<string, any> = {}
|
|
291
|
-
const normalStyleRef = useRef<Record<string, any>>({})
|
|
292
|
-
const normalStyleChangedRef = useRef(false)
|
|
293
301
|
let hasVarDec = false
|
|
294
302
|
let hasVarUse = false
|
|
303
|
+
let hasSelfPercent = false
|
|
295
304
|
const varKeyPaths: Array<Array<string>> = []
|
|
296
305
|
const unoVarKeyPaths: Array<Array<string>> = []
|
|
306
|
+
const percentKeyPaths: Array<Array<string>> = []
|
|
307
|
+
const calcKeyPaths: Array<Array<string>> = []
|
|
308
|
+
const envKeyPaths: Array<Array<string>> = []
|
|
297
309
|
const [width, setWidth] = useState(0)
|
|
298
310
|
const [height, setHeight] = useState(0)
|
|
299
311
|
const navigation = useNavigation()
|
|
300
312
|
|
|
301
|
-
function varVisitor ({ key, value, keyPath }: VisitorArg) {
|
|
313
|
+
function varVisitor ({ target, key, value, keyPath }: VisitorArg) {
|
|
302
314
|
if (keyPath.length === 1) {
|
|
303
315
|
if (unoVarDecRegExp.test(key)) {
|
|
304
316
|
unoVarStyle[key] = value
|
|
@@ -318,10 +330,39 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
318
330
|
} else if (varUseRegExp.test(value)) {
|
|
319
331
|
hasVarUse = true
|
|
320
332
|
varKeyPaths.push(keyPath.slice())
|
|
333
|
+
} else {
|
|
334
|
+
visitOther({ target, key, value, keyPath })
|
|
321
335
|
}
|
|
322
336
|
}
|
|
323
337
|
}
|
|
324
338
|
|
|
339
|
+
function envVisitor ({ value, keyPath }: VisitorArg) {
|
|
340
|
+
if (envUseRegExp.test(value)) {
|
|
341
|
+
envKeyPaths.push(keyPath.slice())
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function calcVisitor ({ value, keyPath }: VisitorArg) {
|
|
346
|
+
if (calcUseRegExp.test(value)) {
|
|
347
|
+
calcKeyPaths.push(keyPath.slice())
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function percentVisitor ({ key, value, keyPath }: VisitorArg) {
|
|
352
|
+
if (hasOwn(selfPercentRule, key) && PERCENT_REGEX.test(value)) {
|
|
353
|
+
hasSelfPercent = true
|
|
354
|
+
percentKeyPaths.push(keyPath.slice())
|
|
355
|
+
} else if ((key === 'fontSize' || key === 'lineHeight') && PERCENT_REGEX.test(value)) {
|
|
356
|
+
percentKeyPaths.push(keyPath.slice())
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function visitOther ({ target, key, value, keyPath }: VisitorArg) {
|
|
361
|
+
if (filterRegExp.test(value)) {
|
|
362
|
+
[envVisitor, percentVisitor, calcVisitor].forEach(visitor => visitor({ target, key, value, keyPath }))
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
325
366
|
// traverse var & generate normalStyle
|
|
326
367
|
traverseStyle(styleObj, [varVisitor])
|
|
327
368
|
|
|
@@ -341,104 +382,61 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
341
382
|
if (diffAndCloneA(varContextRef.current, newVarContext).diff) {
|
|
342
383
|
varContextRef.current = newVarContext
|
|
343
384
|
}
|
|
344
|
-
transformVar(normalStyle, varKeyPaths, varContextRef.current)
|
|
385
|
+
transformVar(normalStyle, varKeyPaths, varContextRef.current, visitOther)
|
|
345
386
|
}
|
|
346
387
|
|
|
347
388
|
// apply unocss var
|
|
348
389
|
if (unoVarKeyPaths.length) {
|
|
349
|
-
transformVar(normalStyle, unoVarKeyPaths, unoVarStyle)
|
|
390
|
+
transformVar(normalStyle, unoVarKeyPaths, unoVarStyle, visitOther)
|
|
350
391
|
}
|
|
351
392
|
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
393
|
+
const percentConfig = {
|
|
394
|
+
width,
|
|
395
|
+
height,
|
|
396
|
+
fontSize: normalStyle.fontSize,
|
|
397
|
+
parentWidth,
|
|
398
|
+
parentHeight,
|
|
399
|
+
parentFontSize
|
|
356
400
|
}
|
|
357
401
|
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
const percentKeyPaths: Array<Array<string>> = []
|
|
362
|
-
const calcKeyPaths: Array<Array<string>> = []
|
|
363
|
-
const envKeyPaths: Array<Array<string>> = []
|
|
364
|
-
// transform can be memoized
|
|
365
|
-
function envVisitor ({ value, keyPath }: VisitorArg) {
|
|
366
|
-
if (envUseRegExp.test(value)) {
|
|
367
|
-
envKeyPaths.push(keyPath.slice())
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
function calcVisitor ({ value, keyPath }: VisitorArg) {
|
|
372
|
-
if (calcUseRegExp.test(value)) {
|
|
373
|
-
calcKeyPaths.push(keyPath.slice())
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
function percentVisitor ({ key, value, keyPath }: VisitorArg) {
|
|
378
|
-
if (hasOwn(selfPercentRule, key) && PERCENT_REGEX.test(value)) {
|
|
379
|
-
hasSelfPercent = true
|
|
380
|
-
percentKeyPaths.push(keyPath.slice())
|
|
381
|
-
} else if ((key === 'fontSize' || key === 'lineHeight') && PERCENT_REGEX.test(value)) {
|
|
382
|
-
percentKeyPaths.push(keyPath.slice())
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
function transformPosition (styleObj: Record<string, any>) {
|
|
387
|
-
if (styleObj.position === 'fixed') {
|
|
388
|
-
hasPositionFixed = true
|
|
389
|
-
styleObj.position = 'absolute'
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
// traverse env & calc & percent
|
|
394
|
-
traverseStyle(normalStyle, [envVisitor, percentVisitor, calcVisitor])
|
|
395
|
-
|
|
396
|
-
const percentConfig = {
|
|
397
|
-
width,
|
|
398
|
-
height,
|
|
399
|
-
fontSize: normalStyle.fontSize,
|
|
400
|
-
parentWidth,
|
|
401
|
-
parentHeight,
|
|
402
|
-
parentFontSize
|
|
403
|
-
}
|
|
402
|
+
const positionMeta = {
|
|
403
|
+
hasPositionFixed: false
|
|
404
|
+
}
|
|
404
405
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
406
|
+
// apply env
|
|
407
|
+
transformEnv(normalStyle, envKeyPaths, navigation)
|
|
408
|
+
// apply percent
|
|
409
|
+
transformPercent(normalStyle, percentKeyPaths, percentConfig)
|
|
410
|
+
// apply calc
|
|
411
|
+
transformCalc(normalStyle, calcKeyPaths, (value: string, key: string) => {
|
|
412
|
+
if (PERCENT_REGEX.test(value)) {
|
|
413
|
+
const resolved = resolvePercent(value, key, percentConfig)
|
|
414
|
+
return typeof resolved === 'number' ? resolved : 0
|
|
415
|
+
} else {
|
|
416
|
+
const formatted = global.__formatValue(value)
|
|
417
|
+
if (typeof formatted === 'number') {
|
|
418
|
+
return formatted
|
|
414
419
|
} else {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
return formatted
|
|
418
|
-
} else {
|
|
419
|
-
warn('calc() only support number, px, rpx, % temporarily.')
|
|
420
|
-
return 0
|
|
421
|
-
}
|
|
420
|
+
warn('calc() only support number, px, rpx, % temporarily.')
|
|
421
|
+
return 0
|
|
422
422
|
}
|
|
423
|
-
})
|
|
424
|
-
// apply position
|
|
425
|
-
transformPosition(normalStyle)
|
|
426
|
-
// transform number enum stringify
|
|
427
|
-
transformStringify(normalStyle)
|
|
428
|
-
|
|
429
|
-
return {
|
|
430
|
-
normalStyle,
|
|
431
|
-
hasSelfPercent,
|
|
432
|
-
hasPositionFixed
|
|
433
423
|
}
|
|
434
|
-
}
|
|
424
|
+
})
|
|
425
|
+
|
|
426
|
+
// apply position
|
|
427
|
+
transformPosition(normalStyle, positionMeta)
|
|
428
|
+
// transform number enum stringify
|
|
429
|
+
transformStringify(normalStyle)
|
|
435
430
|
|
|
436
|
-
return
|
|
431
|
+
return {
|
|
437
432
|
hasVarDec,
|
|
438
433
|
varContextRef,
|
|
439
434
|
setWidth,
|
|
440
|
-
setHeight
|
|
441
|
-
|
|
435
|
+
setHeight,
|
|
436
|
+
normalStyle,
|
|
437
|
+
hasSelfPercent,
|
|
438
|
+
hasPositionFixed: positionMeta.hasPositionFixed
|
|
439
|
+
}
|
|
442
440
|
}
|
|
443
441
|
|
|
444
442
|
export interface VisitorArg {
|
|
@@ -455,12 +453,7 @@ export function traverseStyle (styleObj: Record<string, any>, visitors: Array<(a
|
|
|
455
453
|
target.forEach((value, index) => {
|
|
456
454
|
const key = String(index)
|
|
457
455
|
keyPath.push(key)
|
|
458
|
-
visitors.forEach(visitor => visitor({
|
|
459
|
-
target,
|
|
460
|
-
key,
|
|
461
|
-
value,
|
|
462
|
-
keyPath
|
|
463
|
-
}))
|
|
456
|
+
visitors.forEach(visitor => visitor({ target, key, value, keyPath }))
|
|
464
457
|
traverse(value)
|
|
465
458
|
keyPath.pop()
|
|
466
459
|
})
|
|
@@ -2725,8 +2725,8 @@ function processElement (el, root, options, meta) {
|
|
|
2725
2725
|
processIf(el)
|
|
2726
2726
|
processFor(el)
|
|
2727
2727
|
processRefReact(el, meta)
|
|
2728
|
+
processStyleReact(el, options)
|
|
2728
2729
|
if (!pass) {
|
|
2729
|
-
processStyleReact(el, options)
|
|
2730
2730
|
processEventReact(el, options)
|
|
2731
2731
|
processComponentGenerics(el, meta)
|
|
2732
2732
|
processComponentIs(el, options)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.5",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -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.
|
|
86
|
+
"@mpxjs/api-proxy": "^2.10.5",
|
|
87
87
|
"@types/babel-traverse": "^6.25.4",
|
|
88
88
|
"@types/babel-types": "^7.0.4",
|
|
89
89
|
"@types/react": "^18.2.79",
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
"engines": {
|
|
101
101
|
"node": ">=14.14.0"
|
|
102
102
|
},
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "80a4120733a1ee64e394ae58240497ea6721f435"
|
|
104
104
|
}
|