@mpxjs/webpack-plugin 2.10.17-beta.2 → 2.10.17-beta.4
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/config.js +60 -0
- package/lib/file-loader.js +4 -1
- package/lib/global.d.ts +16 -0
- package/lib/index.js +22 -2
- package/lib/json-compiler/index.js +13 -4
- package/lib/platform/json/wx/index.js +6 -0
- package/lib/platform/style/wx/index.js +57 -33
- package/lib/platform/template/wx/component-config/ad.js +5 -0
- package/lib/platform/template/wx/component-config/button.js +9 -2
- package/lib/platform/template/wx/component-config/camera.js +25 -3
- package/lib/platform/template/wx/component-config/canvas.js +8 -1
- package/lib/platform/template/wx/component-config/cover-image.js +7 -2
- package/lib/platform/template/wx/component-config/cover-view.js +3 -1
- package/lib/platform/template/wx/component-config/form.js +27 -2
- package/lib/platform/template/wx/component-config/image.js +5 -0
- package/lib/platform/template/wx/component-config/input.js +10 -0
- package/lib/platform/template/wx/component-config/label.js +10 -2
- package/lib/platform/template/wx/component-config/map.js +11 -0
- package/lib/platform/template/wx/component-config/movable-area.js +4 -1
- package/lib/platform/template/wx/component-config/movable-view.js +17 -2
- package/lib/platform/template/wx/component-config/navigator.js +26 -0
- package/lib/platform/template/wx/component-config/picker-view.js +12 -0
- package/lib/platform/template/wx/component-config/picker.js +3 -1
- package/lib/platform/template/wx/component-config/progress.js +11 -1
- package/lib/platform/template/wx/component-config/rich-text.js +5 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +12 -1
- package/lib/platform/template/wx/component-config/slider.js +8 -0
- package/lib/platform/template/wx/component-config/swiper-item.js +5 -2
- package/lib/platform/template/wx/component-config/swiper.js +10 -0
- package/lib/platform/template/wx/component-config/text.js +5 -0
- package/lib/platform/template/wx/component-config/textarea.js +19 -2
- package/lib/platform/template/wx/component-config/unsupported.js +10 -1
- package/lib/platform/template/wx/component-config/video.js +10 -0
- package/lib/platform/template/wx/index.js +21 -1
- package/lib/react/LoadAsyncChunkModule.js +1 -1
- package/lib/react/processStyles.js +21 -9
- package/lib/react/style-helper.js +76 -13
- package/lib/resolver/AddModePlugin.js +23 -8
- package/lib/runtime/components/react/animationHooks/index.ts +75 -0
- package/lib/runtime/components/react/animationHooks/useAnimationAPIHooks.ts +198 -0
- package/lib/runtime/components/react/animationHooks/useTransitionHooks.ts +297 -0
- package/lib/runtime/components/react/animationHooks/utils.ts +196 -0
- package/lib/runtime/components/react/context.ts +7 -1
- package/lib/runtime/components/react/dist/animationHooks/index.d.ts +16 -0
- package/lib/runtime/components/react/dist/animationHooks/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/animationHooks/index.js +67 -0
- package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts +4 -0
- package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.js +182 -0
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts +4 -0
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.js +274 -0
- package/lib/runtime/components/react/dist/animationHooks/utils.d.ts +110 -0
- package/lib/runtime/components/react/dist/animationHooks/utils.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/animationHooks/utils.js +150 -0
- package/lib/runtime/components/react/dist/context.d.ts +6 -1
- package/lib/runtime/components/react/dist/context.d.ts.map +1 -1
- package/lib/runtime/components/react/dist/mpx-camera.d.ts +32 -0
- package/lib/runtime/components/react/dist/mpx-camera.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-camera.jsx +236 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts +2 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts.map +1 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +21 -10
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +1 -1
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +3 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts +10 -0
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +1 -1
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +28 -16
- package/lib/runtime/components/react/dist/mpx-view.d.ts +3 -2
- package/lib/runtime/components/react/dist/mpx-view.d.ts.map +1 -1
- package/lib/runtime/components/react/dist/mpx-view.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
- package/lib/runtime/components/react/dist/utils.d.ts +1 -0
- package/lib/runtime/components/react/dist/utils.d.ts.map +1 -1
- package/lib/runtime/components/react/dist/utils.jsx +34 -13
- package/lib/runtime/components/react/mpx-camera.tsx +327 -0
- package/lib/runtime/components/react/mpx-input.tsx +26 -10
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +3 -0
- package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +2 -2
- package/lib/runtime/components/react/mpx-swiper.tsx +43 -15
- package/lib/runtime/components/react/mpx-view.tsx +4 -5
- package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
- package/lib/runtime/components/react/types/global.d.ts +1 -0
- package/lib/runtime/components/react/utils.tsx +34 -16
- package/lib/runtime/optionProcessor.js +5 -0
- package/lib/runtime/optionProcessorReact.js +7 -0
- package/lib/runtime/stringify.wxs +2 -2
- package/lib/style-compiler/strip-conditional-loader/rebaseUrl.js +225 -0
- package/lib/style-compiler/strip-conditional-loader.js +55 -180
- package/lib/template-compiler/compiler.js +1 -3
- package/lib/utils/dom-tag-config.js +1 -1
- package/lib/utils/string.js +25 -1
- package/package.json +2 -1
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +0 -33
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/useAnimationHooks.js +0 -289
- package/lib/runtime/components/react/useAnimationHooks.ts +0 -320
|
@@ -13,23 +13,23 @@ import Portal from './mpx-portal';
|
|
|
13
13
|
const styles = {
|
|
14
14
|
pagination_x: {
|
|
15
15
|
position: 'absolute',
|
|
16
|
-
bottom:
|
|
16
|
+
bottom: 0,
|
|
17
17
|
left: 0,
|
|
18
18
|
right: 0,
|
|
19
19
|
flexDirection: 'row',
|
|
20
20
|
flex: 1,
|
|
21
21
|
justifyContent: 'center',
|
|
22
|
-
alignItems: '
|
|
22
|
+
alignItems: 'flex-end'
|
|
23
23
|
},
|
|
24
24
|
pagination_y: {
|
|
25
25
|
position: 'absolute',
|
|
26
|
-
right:
|
|
26
|
+
right: 0,
|
|
27
27
|
top: 0,
|
|
28
28
|
bottom: 0,
|
|
29
29
|
flexDirection: 'column',
|
|
30
30
|
flex: 1,
|
|
31
31
|
justifyContent: 'center',
|
|
32
|
-
alignItems: '
|
|
32
|
+
alignItems: 'flex-end'
|
|
33
33
|
},
|
|
34
34
|
pagerWrapperx: {
|
|
35
35
|
position: 'absolute',
|
|
@@ -49,16 +49,6 @@ const styles = {
|
|
|
49
49
|
justifyContent: 'flex-start'
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
|
-
const dotCommonStyle = {
|
|
53
|
-
width: 8,
|
|
54
|
-
height: 8,
|
|
55
|
-
borderRadius: 4,
|
|
56
|
-
marginLeft: 3,
|
|
57
|
-
marginRight: 3,
|
|
58
|
-
marginTop: 3,
|
|
59
|
-
marginBottom: 3,
|
|
60
|
-
zIndex: 98
|
|
61
|
-
};
|
|
62
52
|
const activeDotStyle = {
|
|
63
53
|
zIndex: 99
|
|
64
54
|
};
|
|
@@ -71,7 +61,17 @@ const easeMap = {
|
|
|
71
61
|
easeInOutCubic: Easing.inOut(Easing.cubic)
|
|
72
62
|
};
|
|
73
63
|
const SwiperWrapper = forwardRef((props, ref) => {
|
|
74
|
-
const { 'indicator-dots': showPagination, 'indicator-color': dotColor = 'rgba(0, 0, 0, .3)', 'indicator-active-color': activeDotColor = '#000000', 'enable-var': enableVar = false, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'external-var-context': externalVarContext, 'simultaneous-handlers': originSimultaneousHandlers = [], 'wait-for': waitFor = [], style = {}, autoplay = false, circular = false, disableGesture = false, current: propCurrent = 0, bindchange } = props;
|
|
64
|
+
const { 'indicator-dots': showPagination, 'indicator-color': dotColor = 'rgba(0, 0, 0, .3)', 'indicator-width': dotWidth = 8, 'indicator-height': dotHeight = 8, 'indicator-radius': dotRadius = 4, 'indicator-spacing': dotSpacing = 4, 'indicator-margin': paginationMargin = 10, 'indicator-active-color': activeDotColor = '#000000', 'enable-var': enableVar = false, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'external-var-context': externalVarContext, 'simultaneous-handlers': originSimultaneousHandlers = [], 'wait-for': waitFor = [], style = {}, autoplay = false, circular = false, disableGesture = false, current: propCurrent = 0, bindchange } = props;
|
|
65
|
+
const dotCommonStyle = {
|
|
66
|
+
width: dotWidth,
|
|
67
|
+
height: dotHeight,
|
|
68
|
+
borderRadius: dotRadius,
|
|
69
|
+
marginLeft: dotSpacing,
|
|
70
|
+
marginRight: dotSpacing,
|
|
71
|
+
marginTop: dotSpacing,
|
|
72
|
+
marginBottom: dotSpacing,
|
|
73
|
+
zIndex: 98
|
|
74
|
+
};
|
|
75
75
|
const easeingFunc = props['easing-function'] || 'default';
|
|
76
76
|
const easeDuration = props.duration || 500;
|
|
77
77
|
const horizontal = props.vertical !== undefined ? !props.vertical : true;
|
|
@@ -152,6 +152,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
152
152
|
'style',
|
|
153
153
|
'indicator-dots',
|
|
154
154
|
'indicator-color',
|
|
155
|
+
'indicator-width',
|
|
155
156
|
'indicator-active-color',
|
|
156
157
|
'previous-margin',
|
|
157
158
|
'vertical',
|
|
@@ -193,7 +194,17 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
193
194
|
for (let i = 0; i < children.length; i++) {
|
|
194
195
|
dots.push(<View style={[dotCommonStyle, { backgroundColor: unActionColor }]} key={i}></View>);
|
|
195
196
|
}
|
|
196
|
-
|
|
197
|
+
let paginationStyle = styles['pagination_' + dir];
|
|
198
|
+
if (paginationMargin) {
|
|
199
|
+
paginationStyle = {
|
|
200
|
+
...paginationStyle,
|
|
201
|
+
marginBottom: paginationMargin,
|
|
202
|
+
marginLeft: paginationMargin,
|
|
203
|
+
marginRight: paginationMargin,
|
|
204
|
+
marginTop: paginationMargin
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
return (<View pointerEvents="none" style={paginationStyle} key="pagination">
|
|
197
208
|
<View style={[styles['pagerWrapper' + dir]]}>
|
|
198
209
|
<Animated.View style={[
|
|
199
210
|
dotCommonStyle,
|
|
@@ -770,6 +781,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
770
781
|
style: [normalStyle, layoutStyle, styles.swiper]
|
|
771
782
|
}, layoutProps, innerProps);
|
|
772
783
|
const animateComponent = createElement(Animated.View, {
|
|
784
|
+
key: 'swiperContainer',
|
|
773
785
|
style: [{ flexDirection: dir === 'x' ? 'row' : 'column', width: '100%', height: '100%' }, animatedStyles]
|
|
774
786
|
}, wrapChildren({
|
|
775
787
|
children: arrPages
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { View, NativeSyntheticEvent, ViewProps } from 'react-native';
|
|
8
8
|
import { ReactNode } from 'react';
|
|
9
|
-
import
|
|
9
|
+
import { AnimationType } from './animationHooks/index';
|
|
10
|
+
import type { AnimationProp } from './animationHooks/utils';
|
|
10
11
|
import { ExtendedViewStyle } from './types/common';
|
|
11
12
|
import { HandlerRef } from './useNodesRef';
|
|
12
13
|
export interface _ViewProps extends ViewProps {
|
|
@@ -23,7 +24,7 @@ export interface _ViewProps extends ViewProps {
|
|
|
23
24
|
'parent-font-size'?: number;
|
|
24
25
|
'parent-width'?: number;
|
|
25
26
|
'parent-height'?: number;
|
|
26
|
-
'enable-animation'?: boolean;
|
|
27
|
+
'enable-animation'?: boolean | AnimationType;
|
|
27
28
|
bindtouchstart?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void;
|
|
28
29
|
bindtouchmove?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void;
|
|
29
30
|
bindtouchend?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mpx-view.d.ts","sourceRoot":"","sources":["../mpx-view.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,IAAI,EAAa,oBAAoB,EAAE,SAAS,EAAoD,MAAM,cAAc,CAAA;AACjI,OAAO,EAA2C,SAAS,EAAsB,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"mpx-view.d.ts","sourceRoot":"","sources":["../mpx-view.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,IAAI,EAAa,oBAAoB,EAAE,SAAS,EAAoD,MAAM,cAAc,CAAA;AACjI,OAAO,EAA2C,SAAS,EAAsB,MAAM,OAAO,CAAA;AAG9F,OAA0B,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAoB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAOvD,MAAM,WAAW,UAAW,SAAQ,SAAS;IAC3C,KAAK,CAAC,EAAE,iBAAiB,CAAA;IACzB,SAAS,CAAC,EAAE,aAAa,CAAA;IACzB,QAAQ,CAAC,EAAE,SAAS,GAAG,SAAS,EAAE,CAAA;IAClC,aAAa,CAAC,EAAE,iBAAiB,CAAA;IACjC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,sBAAsB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5C,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,kBAAkB,CAAC,EAAE,OAAO,GAAG,aAAa,CAAA;IAC5C,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,CAAC,UAAU,CAAC,GAAG,OAAO,KAAK,IAAI,CAAA;IAC5E,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,CAAC,UAAU,CAAC,GAAG,OAAO,KAAK,IAAI,CAAA;IAC3E,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,CAAC,UAAU,CAAC,GAAG,OAAO,KAAK,IAAI,CAAA;IAC1E,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,CAAC,UAAU,CAAC,GAAG,OAAO,KAAK,IAAI,CAAA;IAC/E,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,CAAC,UAAU,CAAC,GAAG,OAAO,KAAK,IAAI,CAAA;CACjF;AAsoBD,QAAA,MAAM,KAAK,qHAgIT,CAAA;AAIF,eAAe,KAAK,CAAA"}
|
|
@@ -8,7 +8,7 @@ import { View, StyleSheet, Image } from 'react-native';
|
|
|
8
8
|
import { useRef, useState, useEffect, forwardRef, createElement } from 'react';
|
|
9
9
|
import useInnerProps from './getInnerListeners';
|
|
10
10
|
import Animated from 'react-native-reanimated';
|
|
11
|
-
import useAnimationHooks from './
|
|
11
|
+
import useAnimationHooks from './animationHooks/index';
|
|
12
12
|
import useNodesRef from './useNodesRef';
|
|
13
13
|
import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout, renderImage, pickStyle, extendObject, useHover } from './utils';
|
|
14
14
|
import { error, isFunction } from '@mpxjs/utils';
|
|
@@ -203,7 +203,7 @@ function backgroundSize(imageProps, preImageInfo, imageSize, layoutInfo) {
|
|
|
203
203
|
else { // 数值类型 ImageStyle
|
|
204
204
|
// 数值类型设置为 stretch
|
|
205
205
|
imageProps.resizeMode = 'stretch';
|
|
206
|
-
if (type === 'linear' && (!layoutWidth || !layoutHeight)) {
|
|
206
|
+
if (type === 'linear' && (!layoutWidth || !layoutHeight) && (isPercent(width) || isPercent(height))) {
|
|
207
207
|
// ios 上 linear 组件只要重新触发渲染,在渲染过程中外层容器 width 或者 height 被设置为 0,通过设置 % 的方式会渲染不出来,即使后面再更新为正常宽高也渲染不出来
|
|
208
208
|
// 所以 hack 手动先将 linear 宽高也设置为 0,后面再更新为正确的数值或 %。
|
|
209
209
|
dimensions = {
|
|
@@ -184,7 +184,7 @@ const _WebView = forwardRef((props, ref) => {
|
|
|
184
184
|
}
|
|
185
185
|
break;
|
|
186
186
|
case 'postMessage':
|
|
187
|
-
bindmessage && bindmessage(getCustomEvent('
|
|
187
|
+
bindmessage && bindmessage(getCustomEvent('message', {}, {
|
|
188
188
|
detail: {
|
|
189
189
|
data: params[0]?.data
|
|
190
190
|
}
|
|
@@ -32,6 +32,7 @@ export declare function splitStyle<T extends Record<string, any>>(styleObj: T):
|
|
|
32
32
|
backgroundStyle?: Partial<T>;
|
|
33
33
|
innerStyle?: Partial<T>;
|
|
34
34
|
};
|
|
35
|
+
export declare function parseValues(str: string, char?: string): string[];
|
|
35
36
|
interface TransformStyleConfig {
|
|
36
37
|
enableVar?: boolean;
|
|
37
38
|
externalVarContext?: Record<string, any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../utils.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA2C,SAAS,EAAE,YAAY,EAAwC,QAAQ,EAAE,cAAc,EAAyC,gBAAgB,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useState, Children, cloneElement, createElement } from 'react';
|
|
2
2
|
import { Image } from 'react-native';
|
|
3
|
-
import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn } from '@mpxjs/utils';
|
|
3
|
+
import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn, isEmptyObject } from '@mpxjs/utils';
|
|
4
4
|
import { VarContext, ScrollViewContext, RouteContext } from './context';
|
|
5
5
|
import { ExpressionParser, parseFunc, ReplaceSource } from './parser';
|
|
6
6
|
import { initialWindowMetrics } from 'react-native-safe-area-context';
|
|
@@ -193,7 +193,7 @@ function transformVar(styleObj, varKeyPaths, varContext, visitOther) {
|
|
|
193
193
|
const resolved = resolveVar(value, varContext);
|
|
194
194
|
if (resolved === undefined) {
|
|
195
195
|
delete target[key];
|
|
196
|
-
error(`Can not resolve css var at ${varKeyPath.join('.')}:${value}.`)
|
|
196
|
+
// error(`Can not resolve css var at ${varKeyPath.join('.')}:${value}.`)
|
|
197
197
|
return;
|
|
198
198
|
}
|
|
199
199
|
target[key] = resolved;
|
|
@@ -241,6 +241,10 @@ function transformStringify(styleObj) {
|
|
|
241
241
|
if (isNumber(styleObj.fontWeight)) {
|
|
242
242
|
styleObj.fontWeight = '' + styleObj.fontWeight;
|
|
243
243
|
}
|
|
244
|
+
// transformOrigin 20px 需要转换为 transformOrigin '20'
|
|
245
|
+
if (isNumber(styleObj.transformOrigin)) {
|
|
246
|
+
styleObj.transformOrigin = '' + styleObj.transformOrigin;
|
|
247
|
+
}
|
|
244
248
|
}
|
|
245
249
|
function transformPosition(styleObj, meta) {
|
|
246
250
|
if (styleObj.position === 'fixed') {
|
|
@@ -249,7 +253,7 @@ function transformPosition(styleObj, meta) {
|
|
|
249
253
|
}
|
|
250
254
|
}
|
|
251
255
|
// 多value解析
|
|
252
|
-
function parseValues(str, char = ' ') {
|
|
256
|
+
export function parseValues(str, char = ' ') {
|
|
253
257
|
let stack = 0;
|
|
254
258
|
let temp = '';
|
|
255
259
|
const result = [];
|
|
@@ -261,11 +265,11 @@ function parseValues(str, char = ' ') {
|
|
|
261
265
|
stack--;
|
|
262
266
|
}
|
|
263
267
|
// 非括号内 或者 非分隔字符且非空
|
|
264
|
-
if (stack !== 0 ||
|
|
268
|
+
if (stack !== 0 || str[i] !== char) {
|
|
265
269
|
temp += str[i];
|
|
266
270
|
}
|
|
267
271
|
if ((stack === 0 && str[i] === char) || i === str.length - 1) {
|
|
268
|
-
result.push(temp);
|
|
272
|
+
result.push(temp.trim());
|
|
269
273
|
temp = '';
|
|
270
274
|
}
|
|
271
275
|
}
|
|
@@ -274,6 +278,8 @@ function parseValues(str, char = ' ') {
|
|
|
274
278
|
// parse string transform, eg: transform: 'rotateX(45deg) rotateZ(0.785398rad)'
|
|
275
279
|
function parseTransform(transformStr) {
|
|
276
280
|
const values = parseValues(transformStr);
|
|
281
|
+
// Todo transform 排序不一致时,transform动画会闪烁,故这里同样的排序输出 transform
|
|
282
|
+
values.sort();
|
|
277
283
|
const transform = [];
|
|
278
284
|
values.forEach(item => {
|
|
279
285
|
const match = item.match(/([/\w]+)\((.+)\)/);
|
|
@@ -337,6 +343,14 @@ function transformBoxShadow(styleObj) {
|
|
|
337
343
|
return `${res}${idx === 0 ? '' : ' '}${global.__formatValue(i)}`;
|
|
338
344
|
}, '');
|
|
339
345
|
}
|
|
346
|
+
function transformZIndex(styleObj) {
|
|
347
|
+
if (!styleObj.zIndex || typeof styleObj.zIndex === 'number')
|
|
348
|
+
return;
|
|
349
|
+
if (styleObj.zIndex === 'auto') {
|
|
350
|
+
error('Property [z-index] does not supported [auto], please check again!');
|
|
351
|
+
styleObj.zIndex = 0;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
340
354
|
export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight }) {
|
|
341
355
|
const varStyle = {};
|
|
342
356
|
const unoVarStyle = {};
|
|
@@ -386,17 +400,19 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
386
400
|
envKeyPaths.push(keyPath.slice());
|
|
387
401
|
}
|
|
388
402
|
}
|
|
389
|
-
function calcVisitor({ value, keyPath }) {
|
|
403
|
+
function calcVisitor({ key, value, keyPath }) {
|
|
390
404
|
if (calcUseRegExp.test(value)) {
|
|
405
|
+
// calc translate & border-radius 的百分比计算
|
|
406
|
+
if (hasOwn(selfPercentRule, key) && /%/.test(value)) {
|
|
407
|
+
hasSelfPercent = true;
|
|
408
|
+
percentKeyPaths.push(keyPath.slice());
|
|
409
|
+
}
|
|
391
410
|
calcKeyPaths.push(keyPath.slice());
|
|
392
411
|
}
|
|
393
412
|
}
|
|
394
413
|
function percentVisitor({ key, value, keyPath }) {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
percentKeyPaths.push(keyPath.slice());
|
|
398
|
-
}
|
|
399
|
-
else if ((key === 'fontSize' || key === 'lineHeight') && PERCENT_REGEX.test(value)) {
|
|
414
|
+
// fixme 去掉 translate & border-radius 的百分比计算
|
|
415
|
+
if ((key === 'fontSize' || key === 'lineHeight') && PERCENT_REGEX.test(value)) {
|
|
400
416
|
percentKeyPaths.push(keyPath.slice());
|
|
401
417
|
}
|
|
402
418
|
}
|
|
@@ -405,6 +421,8 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
405
421
|
[envVisitor, percentVisitor, calcVisitor].forEach(visitor => visitor({ target, key, value, keyPath }));
|
|
406
422
|
}
|
|
407
423
|
}
|
|
424
|
+
// transform 字符串格式转化数组格式(先转数组再处理css var)
|
|
425
|
+
transformTransform(styleObj);
|
|
408
426
|
// traverse var & generate normalStyle
|
|
409
427
|
traverseStyle(styleObj, [varVisitor]);
|
|
410
428
|
hasVarDec = hasVarDec || !!externalVarContext;
|
|
@@ -467,8 +485,11 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
467
485
|
transformStringify(normalStyle);
|
|
468
486
|
// transform rpx to px
|
|
469
487
|
transformBoxShadow(normalStyle);
|
|
470
|
-
// transform
|
|
471
|
-
|
|
488
|
+
// transform z-index auto to 0
|
|
489
|
+
transformZIndex(normalStyle);
|
|
490
|
+
if (Array.isArray(normalStyle.transform)) {
|
|
491
|
+
normalStyle.transform = normalStyle.transform.filter(item => !isEmptyObject(item));
|
|
492
|
+
}
|
|
472
493
|
return {
|
|
473
494
|
hasVarDec,
|
|
474
495
|
varContextRef,
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import React, { createElement, forwardRef, useRef, useCallback, useContext, useState, useEffect } from 'react'
|
|
2
|
+
import { useTransformStyle, useLayout, extendObject } from './utils'
|
|
3
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
4
|
+
import { noop } from '@mpxjs/utils'
|
|
5
|
+
import { RouteContext } from './context'
|
|
6
|
+
|
|
7
|
+
const qualityValue = {
|
|
8
|
+
high: 90,
|
|
9
|
+
normal: 75,
|
|
10
|
+
low: 50,
|
|
11
|
+
original: 100
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface CameraProps {
|
|
15
|
+
mode?: 'normal' | 'scanCode'
|
|
16
|
+
resolution?: 'low' | 'medium' | 'high'
|
|
17
|
+
devicePosition?: 'front' | 'back'
|
|
18
|
+
flash?: 'auto' | 'on' | 'off'
|
|
19
|
+
frameSize?: 'small' | 'medium' | 'large'
|
|
20
|
+
style?: Record<string, any>
|
|
21
|
+
bindstop?: () => void
|
|
22
|
+
binderror?: (error: { message: string }) => void
|
|
23
|
+
bindinitdone?: (result: { type: string, data: string }) => void
|
|
24
|
+
bindscancode?: (result: { type: string, data: string }) => void
|
|
25
|
+
'parent-font-size'?: number
|
|
26
|
+
'parent-width'?: number
|
|
27
|
+
'parent-height'?: number
|
|
28
|
+
'enable-var'?: boolean
|
|
29
|
+
'external-var-context'?: any
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface TakePhotoOptions {
|
|
33
|
+
quality?: 'high' | 'normal' | 'low' | 'original'
|
|
34
|
+
success?: (result: { errMsg: string, tempImagePath: string }) => void
|
|
35
|
+
fail?: (result: { errMsg: string }) => void
|
|
36
|
+
complete?: (result: { errMsg: string, tempImagePath?: string }) => void
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface RecordOptions {
|
|
40
|
+
timeout?: number
|
|
41
|
+
success?: (result: { errMsg: string }) => void
|
|
42
|
+
fail?: (result: { errMsg: string, error?: any }) => void
|
|
43
|
+
complete?: (result: { errMsg: string }) => void
|
|
44
|
+
timeoutCallback?: (result: { errMsg: string, error?: any }) => void
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface StopRecordOptions {
|
|
48
|
+
success?: (result: { errMsg: string, tempVideoPath: string, duration: number }) => void
|
|
49
|
+
fail?: (result: { errMsg: string }) => void
|
|
50
|
+
complete?: (result: { errMsg: string, tempVideoPath?: string, duration?: number }) => void
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface CameraRef {
|
|
54
|
+
setZoom: (zoom: number) => void
|
|
55
|
+
takePhoto: (options?: TakePhotoOptions) => void
|
|
56
|
+
startRecord: (options?: RecordOptions) => void
|
|
57
|
+
stopRecord: (options?: StopRecordOptions) => void
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
type HandlerRef<T, P> = {
|
|
61
|
+
current: T | null
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let RecordRes: any = null
|
|
65
|
+
|
|
66
|
+
const _camera = forwardRef<HandlerRef<any, CameraProps>, CameraProps>((props: CameraProps, ref): JSX.Element | null => {
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
68
|
+
const { Camera, useCameraDevice, useCodeScanner, useCameraFormat } = require('react-native-vision-camera')
|
|
69
|
+
const cameraRef = useRef<any>(null)
|
|
70
|
+
const {
|
|
71
|
+
mode = 'normal',
|
|
72
|
+
resolution = 'medium',
|
|
73
|
+
devicePosition = 'back',
|
|
74
|
+
flash = 'auto',
|
|
75
|
+
frameSize = 'medium',
|
|
76
|
+
bindinitdone,
|
|
77
|
+
bindstop,
|
|
78
|
+
bindscancode,
|
|
79
|
+
'parent-font-size': parentFontSize,
|
|
80
|
+
'parent-width': parentWidth,
|
|
81
|
+
'parent-height': parentHeight,
|
|
82
|
+
'enable-var': enableVar,
|
|
83
|
+
'external-var-context': externalVarContext,
|
|
84
|
+
style = {}
|
|
85
|
+
} = props
|
|
86
|
+
const styleObj = extendObject(
|
|
87
|
+
{},
|
|
88
|
+
style
|
|
89
|
+
)
|
|
90
|
+
const {
|
|
91
|
+
normalStyle,
|
|
92
|
+
hasSelfPercent,
|
|
93
|
+
setWidth,
|
|
94
|
+
setHeight
|
|
95
|
+
} = useTransformStyle(styleObj, {
|
|
96
|
+
enableVar,
|
|
97
|
+
externalVarContext,
|
|
98
|
+
parentFontSize,
|
|
99
|
+
parentWidth,
|
|
100
|
+
parentHeight
|
|
101
|
+
})
|
|
102
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: cameraRef })
|
|
103
|
+
const isPhoto = mode === 'normal'
|
|
104
|
+
const device = useCameraDevice(devicePosition || 'back')
|
|
105
|
+
const { navigation } = useContext(RouteContext) || {}
|
|
106
|
+
const [zoomValue, setZoomValue] = useState<number>(1)
|
|
107
|
+
const [hasPermission, setHasPermission] = useState<boolean | null>(null)
|
|
108
|
+
const hasCamera = useRef(false)
|
|
109
|
+
|
|
110
|
+
// 先定义常量,避免在条件判断后使用
|
|
111
|
+
const maxZoom = device?.maxZoom || 1
|
|
112
|
+
const RESOLUTION_MAPPING: Record<string, { width: number, height: number }> = {
|
|
113
|
+
low: { width: 640, height: 480 },
|
|
114
|
+
medium: { width: 1280, height: 720 },
|
|
115
|
+
high: { width: 1920, height: 1080 }
|
|
116
|
+
}
|
|
117
|
+
const FRAME_SIZE_MAPPING: Record<string, { width: number, height: number }> = {
|
|
118
|
+
small: { width: 480, height: 360 },
|
|
119
|
+
medium: { width: 720, height: 540 },
|
|
120
|
+
large: { width: 1080, height: 810 }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const format = useCameraFormat(device, [
|
|
124
|
+
{
|
|
125
|
+
photoResolution: RESOLUTION_MAPPING[resolution],
|
|
126
|
+
videoResolution: FRAME_SIZE_MAPPING[frameSize] || RESOLUTION_MAPPING[resolution]
|
|
127
|
+
}
|
|
128
|
+
])
|
|
129
|
+
|
|
130
|
+
const codeScanner = useCodeScanner({
|
|
131
|
+
codeTypes: ['qr', 'ean-13'],
|
|
132
|
+
onCodeScanned: (codes: any[]) => {
|
|
133
|
+
const result = codes.map(code => code.value).join(',')
|
|
134
|
+
bindscancode && bindscancode(getCustomEvent('scancode', {}, {
|
|
135
|
+
detail: {
|
|
136
|
+
result: codes.map(code => code.value).join(',')
|
|
137
|
+
}
|
|
138
|
+
}))
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
const onInitialized = useCallback(() => {
|
|
143
|
+
bindinitdone && bindinitdone(getCustomEvent('initdone', {}, {
|
|
144
|
+
detail: {
|
|
145
|
+
maxZoom
|
|
146
|
+
}
|
|
147
|
+
}))
|
|
148
|
+
}, [bindinitdone, maxZoom])
|
|
149
|
+
|
|
150
|
+
const onStopped = useCallback(() => {
|
|
151
|
+
bindstop && bindstop()
|
|
152
|
+
}, [bindstop])
|
|
153
|
+
|
|
154
|
+
const camera: CameraRef = {
|
|
155
|
+
setZoom: (zoom: number) => {
|
|
156
|
+
setZoomValue(zoom)
|
|
157
|
+
},
|
|
158
|
+
takePhoto: (options: TakePhotoOptions = {}) => {
|
|
159
|
+
const { success = noop, fail = noop, complete = noop } = options
|
|
160
|
+
cameraRef.current?.takePhoto?.({
|
|
161
|
+
flash,
|
|
162
|
+
quality: qualityValue[options.quality || 'normal'] as number
|
|
163
|
+
} as any).then((res: { path: any }) => {
|
|
164
|
+
const result = {
|
|
165
|
+
errMsg: 'takePhoto:ok',
|
|
166
|
+
tempImagePath: res.path
|
|
167
|
+
}
|
|
168
|
+
success(result)
|
|
169
|
+
complete(result)
|
|
170
|
+
}).catch(() => {
|
|
171
|
+
const result = {
|
|
172
|
+
errMsg: 'takePhoto:fail'
|
|
173
|
+
}
|
|
174
|
+
fail(result)
|
|
175
|
+
complete(result)
|
|
176
|
+
})
|
|
177
|
+
},
|
|
178
|
+
startRecord: (options: RecordOptions = {}) => {
|
|
179
|
+
let { timeout = 30, success = noop, fail = noop, complete = noop, timeoutCallback = noop } = options
|
|
180
|
+
timeout = timeout > 300 ? 300 : timeout
|
|
181
|
+
let recordTimer: NodeJS.Timeout | null = null
|
|
182
|
+
let isTimeout = false
|
|
183
|
+
try {
|
|
184
|
+
const result = {
|
|
185
|
+
errMsg: 'startRecord:ok'
|
|
186
|
+
}
|
|
187
|
+
success(result)
|
|
188
|
+
complete(result)
|
|
189
|
+
|
|
190
|
+
cameraRef.current?.startRecording?.({
|
|
191
|
+
flash,
|
|
192
|
+
onRecordingError: (error: any) => {
|
|
193
|
+
if (recordTimer) clearTimeout(recordTimer)
|
|
194
|
+
const errorResult = {
|
|
195
|
+
errMsg: 'startRecord:fail during recording',
|
|
196
|
+
error: error
|
|
197
|
+
}
|
|
198
|
+
timeoutCallback(errorResult)
|
|
199
|
+
},
|
|
200
|
+
onRecordingFinished: (video: any) => {
|
|
201
|
+
RecordRes = video
|
|
202
|
+
if (recordTimer) clearTimeout(recordTimer)
|
|
203
|
+
}
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
recordTimer = setTimeout(() => { // 超时自动停止
|
|
207
|
+
isTimeout = true
|
|
208
|
+
cameraRef.current?.stopRecording().catch(() => {
|
|
209
|
+
// 忽略停止录制时的错误
|
|
210
|
+
})
|
|
211
|
+
}, timeout * 1000)
|
|
212
|
+
} catch (error: any) {
|
|
213
|
+
if (recordTimer) clearTimeout(recordTimer)
|
|
214
|
+
const result = {
|
|
215
|
+
errMsg: 'startRecord:fail ' + (error.message || 'unknown error')
|
|
216
|
+
}
|
|
217
|
+
fail(result)
|
|
218
|
+
complete(result)
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
stopRecord: (options: StopRecordOptions = {}) => {
|
|
222
|
+
const { success = noop, fail = noop, complete = noop } = options
|
|
223
|
+
try {
|
|
224
|
+
cameraRef.current?.stopRecording().then(() => {
|
|
225
|
+
setTimeout(() => {
|
|
226
|
+
if (RecordRes) {
|
|
227
|
+
const result = {
|
|
228
|
+
errMsg: 'stopRecord:ok',
|
|
229
|
+
tempVideoPath: RecordRes?.path,
|
|
230
|
+
duration: RecordRes.duration * 1000 // 转成ms
|
|
231
|
+
}
|
|
232
|
+
RecordRes = null
|
|
233
|
+
success(result)
|
|
234
|
+
complete(result)
|
|
235
|
+
}
|
|
236
|
+
}, 200) // 延时200ms,确保录制结果已准备好
|
|
237
|
+
}).catch((e: any) => {
|
|
238
|
+
const result = {
|
|
239
|
+
errMsg: 'stopRecord:fail ' + (e.message || 'promise rejected')
|
|
240
|
+
}
|
|
241
|
+
fail(result)
|
|
242
|
+
complete(result)
|
|
243
|
+
})
|
|
244
|
+
} catch (error: any) {
|
|
245
|
+
const result = {
|
|
246
|
+
errMsg: 'stopRecord:fail ' + (error.message || 'unknown error')
|
|
247
|
+
}
|
|
248
|
+
fail(result)
|
|
249
|
+
complete(result)
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
useEffect(() => {
|
|
255
|
+
if (navigation) {
|
|
256
|
+
if (navigation && !navigation.camera) {
|
|
257
|
+
navigation.camera = camera
|
|
258
|
+
} else {
|
|
259
|
+
hasCamera.current = true
|
|
260
|
+
navigation.camera.multi = true
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const checkCameraPermission = async () => {
|
|
264
|
+
try {
|
|
265
|
+
const cameraPermission = global?.__mpx?.config?.rnConfig?.cameraPermission
|
|
266
|
+
if (typeof cameraPermission === 'function') {
|
|
267
|
+
const permissionResult = await cameraPermission()
|
|
268
|
+
setHasPermission(permissionResult === true)
|
|
269
|
+
} else {
|
|
270
|
+
setHasPermission(true)
|
|
271
|
+
}
|
|
272
|
+
} catch (error) {
|
|
273
|
+
setHasPermission(false)
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
checkCameraPermission()
|
|
277
|
+
return () => {
|
|
278
|
+
if (navigation && navigation.camera) {
|
|
279
|
+
navigation.camera = null
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}, [])
|
|
283
|
+
|
|
284
|
+
const innerProps = useInnerProps(
|
|
285
|
+
extendObject(
|
|
286
|
+
{},
|
|
287
|
+
props,
|
|
288
|
+
layoutProps,
|
|
289
|
+
{
|
|
290
|
+
ref: cameraRef,
|
|
291
|
+
style: extendObject({}, normalStyle, layoutStyle),
|
|
292
|
+
isActive: true,
|
|
293
|
+
photo: true,
|
|
294
|
+
video: true,
|
|
295
|
+
onInitialized,
|
|
296
|
+
onStopped,
|
|
297
|
+
device,
|
|
298
|
+
format,
|
|
299
|
+
codeScanner: !isPhoto ? codeScanner : undefined,
|
|
300
|
+
zoom: zoomValue
|
|
301
|
+
}
|
|
302
|
+
),
|
|
303
|
+
[
|
|
304
|
+
'mode',
|
|
305
|
+
'resolution',
|
|
306
|
+
'frame-size',
|
|
307
|
+
'bindinitdone',
|
|
308
|
+
'bindstop',
|
|
309
|
+
'flash',
|
|
310
|
+
'bindscancode',
|
|
311
|
+
'binderror'
|
|
312
|
+
],
|
|
313
|
+
{
|
|
314
|
+
layoutRef
|
|
315
|
+
}
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
if (!hasPermission || hasCamera.current || !device) {
|
|
319
|
+
return null
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return createElement(Camera, innerProps)
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
_camera.displayName = 'MpxCamera'
|
|
326
|
+
|
|
327
|
+
export default _camera
|