@mpxjs/webpack-plugin 2.10.19 → 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.
Files changed (137) hide show
  1. package/lib/dependencies/ResolveDependency.js +2 -2
  2. package/lib/index.js +38 -7
  3. package/lib/json-compiler/helper.js +11 -10
  4. package/lib/json-compiler/index.js +7 -4
  5. package/lib/json-compiler/plugin.js +4 -4
  6. package/lib/loader.js +4 -4
  7. package/lib/native-loader.js +4 -4
  8. package/lib/parser.js +1 -1
  9. package/lib/platform/create-diagnostic.js +168 -0
  10. package/lib/platform/index.js +16 -3
  11. package/lib/platform/json/wx/index.js +66 -17
  12. package/lib/platform/run-rules.js +9 -5
  13. package/lib/platform/style/wx/index.js +82 -33
  14. package/lib/platform/template/normalize-component-rules.js +7 -9
  15. package/lib/platform/template/wx/component-config/block.js +2 -1
  16. package/lib/platform/template/wx/component-config/custom-built-in-component.js +34 -0
  17. package/lib/platform/template/wx/component-config/index.js +18 -3
  18. package/lib/platform/template/wx/component-config/input.js +1 -7
  19. package/lib/platform/template/wx/component-config/movable-view.js +1 -7
  20. package/lib/platform/template/wx/component-config/text.js +1 -1
  21. package/lib/platform/template/wx/component-config/textarea.js +1 -25
  22. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  23. package/lib/platform/template/wx/index.js +48 -34
  24. package/lib/react/processJSON.js +7 -4
  25. package/lib/react/processStyles.js +22 -8
  26. package/lib/react/processTemplate.js +98 -41
  27. package/lib/react/style-helper.js +121 -86
  28. package/lib/react/template-loader.js +161 -0
  29. package/lib/runtime/components/react/context.ts +8 -1
  30. package/lib/runtime/components/react/dist/context.d.ts +6 -1
  31. package/lib/runtime/components/react/dist/context.js +1 -0
  32. package/lib/runtime/components/react/dist/getInnerListeners.js +1 -0
  33. package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +1 -1
  34. package/lib/runtime/components/react/dist/mpx-button.d.ts +1 -1
  35. package/lib/runtime/components/react/dist/mpx-button.jsx +6 -5
  36. package/lib/runtime/components/react/dist/mpx-camera.jsx +1 -0
  37. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +4 -1
  38. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +2 -1
  39. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +6 -4
  40. package/lib/runtime/components/react/dist/mpx-form.jsx +3 -3
  41. package/lib/runtime/components/react/dist/mpx-icon/index.jsx +5 -1
  42. package/lib/runtime/components/react/dist/mpx-image.d.ts +3 -3
  43. package/lib/runtime/components/react/dist/mpx-image.jsx +45 -12
  44. package/lib/runtime/components/react/dist/mpx-inline-text.jsx +10 -6
  45. package/lib/runtime/components/react/dist/mpx-input.jsx +17 -4
  46. package/lib/runtime/components/react/dist/mpx-label.jsx +6 -4
  47. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +19 -4
  48. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +12 -2
  49. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +1 -1
  50. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +7 -4
  51. package/lib/runtime/components/react/dist/mpx-portal/index.jsx +5 -1
  52. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +4 -1
  53. package/lib/runtime/components/react/dist/mpx-radio.jsx +5 -4
  54. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +3 -1
  55. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +13 -4
  56. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +52 -6
  57. package/lib/runtime/components/react/dist/mpx-simple-view.jsx +36 -6
  58. package/lib/runtime/components/react/dist/mpx-slider.jsx +2 -1
  59. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +8 -4
  60. package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +6 -4
  61. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +7 -4
  62. package/lib/runtime/components/react/dist/mpx-swiper.jsx +15 -4
  63. package/lib/runtime/components/react/dist/mpx-switch.jsx +4 -1
  64. package/lib/runtime/components/react/dist/mpx-text.jsx +57 -12
  65. package/lib/runtime/components/react/dist/mpx-video.d.ts +2 -1
  66. package/lib/runtime/components/react/dist/mpx-video.jsx +10 -4
  67. package/lib/runtime/components/react/dist/mpx-view.jsx +42 -7
  68. package/lib/runtime/components/react/dist/utils.d.ts +21 -11
  69. package/lib/runtime/components/react/dist/utils.jsx +105 -35
  70. package/lib/runtime/components/react/getInnerListeners.ts +1 -0
  71. package/lib/runtime/components/react/mpx-async-suspense.tsx +2 -1
  72. package/lib/runtime/components/react/mpx-button.tsx +6 -5
  73. package/lib/runtime/components/react/mpx-camera.tsx +1 -0
  74. package/lib/runtime/components/react/mpx-canvas/index.tsx +4 -1
  75. package/lib/runtime/components/react/mpx-checkbox-group.tsx +2 -1
  76. package/lib/runtime/components/react/mpx-checkbox.tsx +6 -4
  77. package/lib/runtime/components/react/mpx-form.tsx +3 -3
  78. package/lib/runtime/components/react/mpx-icon/index.tsx +5 -1
  79. package/lib/runtime/components/react/mpx-image.tsx +57 -20
  80. package/lib/runtime/components/react/mpx-inline-text.tsx +12 -7
  81. package/lib/runtime/components/react/mpx-input.tsx +17 -4
  82. package/lib/runtime/components/react/mpx-label.tsx +6 -4
  83. package/lib/runtime/components/react/mpx-movable-view.tsx +20 -4
  84. package/lib/runtime/components/react/mpx-picker/index.tsx +12 -2
  85. package/lib/runtime/components/react/mpx-picker/type.ts +1 -1
  86. package/lib/runtime/components/react/mpx-picker-view/index.tsx +8 -4
  87. package/lib/runtime/components/react/mpx-portal/index.tsx +5 -1
  88. package/lib/runtime/components/react/mpx-radio-group.tsx +4 -1
  89. package/lib/runtime/components/react/mpx-radio.tsx +5 -4
  90. package/lib/runtime/components/react/mpx-rich-text/index.tsx +3 -1
  91. package/lib/runtime/components/react/mpx-scroll-view.tsx +13 -4
  92. package/lib/runtime/components/react/mpx-simple-text.tsx +55 -8
  93. package/lib/runtime/components/react/mpx-simple-view.tsx +30 -6
  94. package/lib/runtime/components/react/mpx-slider.tsx +2 -1
  95. package/lib/runtime/components/react/mpx-sticky-header.tsx +8 -4
  96. package/lib/runtime/components/react/mpx-sticky-section.tsx +6 -4
  97. package/lib/runtime/components/react/mpx-swiper-item.tsx +7 -4
  98. package/lib/runtime/components/react/mpx-swiper.tsx +16 -4
  99. package/lib/runtime/components/react/mpx-switch.tsx +4 -1
  100. package/lib/runtime/components/react/mpx-text.tsx +55 -15
  101. package/lib/runtime/components/react/mpx-video.tsx +11 -5
  102. package/lib/runtime/components/react/mpx-view.tsx +35 -7
  103. package/lib/runtime/components/react/types/global.d.ts +4 -0
  104. package/lib/runtime/components/react/utils.tsx +126 -45
  105. package/lib/runtime/components/wx/default-component.mpx +9 -0
  106. package/lib/runtime/components/wx/default-page.mpx +3 -11
  107. package/lib/runtime/optionProcessor.d.ts +2 -0
  108. package/lib/runtime/optionProcessor.js +77 -1
  109. package/lib/runtime/optionProcessorReact.js +5 -0
  110. package/lib/script-setup-compiler/index.js +1 -1
  111. package/lib/style-compiler/index.js +2 -0
  112. package/lib/style-compiler/plugins/remove-strip-conditional-comments.js +14 -0
  113. package/lib/style-compiler/plugins/trans-special.js +1 -1
  114. package/lib/style-compiler/strip-conditional.js +40 -26
  115. package/lib/template-compiler/compiler.js +306 -125
  116. package/lib/template-compiler/gen-node-react.js +35 -7
  117. package/lib/template-compiler/index.js +9 -7
  118. package/lib/utils/const.js +4 -1
  119. package/lib/utils/gen-component-tag.js +1 -5
  120. package/lib/utils/normalize-perf-options.js +47 -0
  121. package/lib/utils/partial-compile-rules.js +27 -0
  122. package/lib/utils/pre-process-json.js +3 -0
  123. package/lib/utils/source-location.js +96 -0
  124. package/lib/web/compile-wx-template-fragment.js +68 -0
  125. package/lib/web/index.js +3 -0
  126. package/lib/web/processJSON.js +7 -4
  127. package/lib/web/processMainScript.js +3 -7
  128. package/lib/web/processScript.js +43 -8
  129. package/lib/web/processStyles.js +12 -3
  130. package/lib/web/processTemplate.js +61 -19
  131. package/lib/web/template-loader.js +123 -0
  132. package/lib/web/template-shared.js +48 -0
  133. package/lib/wxml/loader.js +4 -3
  134. package/lib/wxss/loader.js +1 -1
  135. package/lib/wxss/utils.js +6 -4
  136. package/package.json +12 -4
  137. package/lib/platform/template/wx/component-config/component.js +0 -41
@@ -1,20 +1,37 @@
1
- import { useEffect, useCallback, useMemo, useRef, isValidElement, useContext, useState, Children, cloneElement, createElement } from 'react';
1
+ import { useEffect, useCallback, useMemo, useRef, isValidElement, useContext, useState, createElement } from 'react';
2
2
  import { 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 } from './context';
5
5
  import { ExpressionParser, parseFunc, ReplaceSource } from './parser';
6
6
  import { initialWindowMetrics } from 'react-native-safe-area-context';
7
7
  import { Gesture } from 'react-native-gesture-handler';
8
- export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/;
8
+ export const TEXT_STYLE_MAP = {
9
+ color: true,
10
+ letterSpacing: true,
11
+ lineHeight: true,
12
+ includeFontPadding: true,
13
+ writingDirection: true
14
+ };
9
15
  export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/;
10
16
  export const URL_REGEX = /^\s*url\(["']?(.*?)["']?\)\s*$/;
11
- export const SVG_REGEXP = /https?:\/\/.*\.(?:svg)/i;
12
- export const BACKGROUND_REGEX = /^background(Image|Size|Repeat|Position)$/;
13
- export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines|allowFontScaling/;
17
+ export const SVG_REGEXP = /\.svg(?:[?#].*)?$/i;
18
+ export const BACKGROUND_STYLE_MAP = {
19
+ backgroundImage: true,
20
+ backgroundSize: true,
21
+ backgroundRepeat: true,
22
+ backgroundPosition: true
23
+ };
24
+ export const TEXT_PROPS_MAP = {
25
+ ellipsizeMode: true,
26
+ numberOfLines: true
27
+ };
14
28
  export const DEFAULT_FONT_SIZE = 16;
15
29
  export const HIDDEN_STYLE = {
16
30
  opacity: 0
17
31
  };
32
+ export const DEFAULT_BOX_SIZING_STYLE = {
33
+ boxSizing: 'content-box'
34
+ };
18
35
  export const isIOS = __mpx_mode__ === 'ios';
19
36
  export const isAndroid = __mpx_mode__ === 'android';
20
37
  export const isHarmony = __mpx_mode__ === 'harmony';
@@ -23,9 +40,19 @@ const varUseRegExp = /var\(/;
23
40
  const unoVarDecRegExp = /^--un-/;
24
41
  const unoVarUseRegExp = /var\(--un-/;
25
42
  const calcUseRegExp = /calc\(/;
26
- const calcPercentExp = /^calc\(.*-?\d+(\.\d+)?%.*\)$/;
27
43
  const envUseRegExp = /env\(/;
28
- const filterRegExp = /(calc|env|%)/;
44
+ const boxSizingAffectingStyleMap = {
45
+ padding: true,
46
+ paddingTop: true,
47
+ paddingRight: true,
48
+ paddingBottom: true,
49
+ paddingLeft: true,
50
+ borderWidth: true,
51
+ borderTopWidth: true,
52
+ borderRightWidth: true,
53
+ borderBottomWidth: true,
54
+ borderLeftWidth: true
55
+ };
29
56
  const safeAreaInsetMap = {
30
57
  'safe-area-inset-top': 'top',
31
58
  'safe-area-inset-right': 'right',
@@ -33,6 +60,21 @@ const safeAreaInsetMap = {
33
60
  'safe-area-inset-left': 'left'
34
61
  };
35
62
  export const extendObject = Object.assign;
63
+ export function getDefaultAllowFontScaling() {
64
+ return global.__mpx?.config?.rnConfig?.allowFontScaling ?? false;
65
+ }
66
+ export function transformBoxSizing(style = {}, hasBoxSizingAffectingStyle = false) {
67
+ if (hasBoxSizingAffectingStyle && style.boxSizing === undefined) {
68
+ style.boxSizing = global.__mpx?.config?.rnConfig?.defaultBoxSizing ?? DEFAULT_BOX_SIZING_STYLE.boxSizing;
69
+ }
70
+ return style;
71
+ }
72
+ export function isBoxSizingAffectingStyle(key) {
73
+ return hasOwn(boxSizingAffectingStyleMap, key);
74
+ }
75
+ function isTextStyle(key) {
76
+ return hasOwn(TEXT_STYLE_MAP, key) || key.startsWith('font') || key.startsWith('text');
77
+ }
36
78
  function getSafeAreaInset(name, navigation) {
37
79
  const insets = extendObject({}, initialWindowMetrics?.insets, navigation?.insets);
38
80
  return insets[safeAreaInsetMap[name]];
@@ -86,9 +128,12 @@ export function isText(ele) {
86
128
  }
87
129
  return false;
88
130
  }
89
- export function every(children, callback) {
90
- const childrenArray = Array.isArray(children) ? children : [children];
91
- return childrenArray.every((child) => callback(child));
131
+ export function isStringChildren(children) {
132
+ if (typeof children === 'string')
133
+ return true;
134
+ if (!Array.isArray(children))
135
+ return false;
136
+ return children.every((child) => typeof child === 'string');
92
137
  }
93
138
  export function groupBy(obj, callback, group = {}) {
94
139
  Object.entries(obj).forEach(([key, val]) => {
@@ -98,12 +143,13 @@ export function groupBy(obj, callback, group = {}) {
98
143
  });
99
144
  return group;
100
145
  }
101
- export function splitStyle(styleObj) {
102
- return groupBy(styleObj, (key) => {
103
- if (TEXT_STYLE_REGEX.test(key)) {
146
+ export function splitStyle(styleObj, sideEffect) {
147
+ return groupBy(styleObj, (key, val) => {
148
+ sideEffect && sideEffect(key, val);
149
+ if (isTextStyle(key)) {
104
150
  return 'textStyle';
105
151
  }
106
- else if (BACKGROUND_REGEX.test(key)) {
152
+ else if (hasOwn(BACKGROUND_STYLE_MAP, key)) {
107
153
  return 'backgroundStyle';
108
154
  }
109
155
  else {
@@ -284,8 +330,9 @@ export function parseValues(str, char = ' ') {
284
330
  // parse string transform, eg: transform: 'rotateX(45deg) rotateZ(0.785398rad)'
285
331
  function parseTransform(transformStr) {
286
332
  const values = parseValues(transformStr);
287
- // Todo transform 排序不一致时,transform动画会闪烁,故这里同样的排序输出 transform
288
- values.sort();
333
+ // Todo 2 RN下顺序不一致转换结果不一致,故这里不处理,动画前后transform 排序不一致的问题,由业务调整写法
334
+ // Todo 1 transform 排序不一致时,transform动画会闪烁,故这里同样的排序输出 transform
335
+ // values.sort()
289
336
  const transform = [];
290
337
  values.forEach(item => {
291
338
  const match = item.match(/([/\w]+)\((.+)\)/);
@@ -356,6 +403,7 @@ export function useTransformStyle(styleObj = {}, { enableVar, transformRadiusPer
356
403
  let hasVarDec = false;
357
404
  let hasVarUse = false;
358
405
  let hasSelfPercent = false;
406
+ let hasBoxSizingAffectingStyle = false;
359
407
  const varKeyPaths = [];
360
408
  const unoVarKeyPaths = [];
361
409
  const percentKeyPaths = [];
@@ -393,18 +441,18 @@ export function useTransformStyle(styleObj = {}, { enableVar, transformRadiusPer
393
441
  }
394
442
  }
395
443
  }
444
+ function boxSizingVisitor({ key, keyPath }) {
445
+ if (keyPath.length === 1 && !hasBoxSizingAffectingStyle && isBoxSizingAffectingStyle(key)) {
446
+ hasBoxSizingAffectingStyle = true;
447
+ }
448
+ }
396
449
  function envVisitor({ value, keyPath }) {
397
450
  if (envUseRegExp.test(value)) {
398
451
  envKeyPaths.push(keyPath.slice());
399
452
  }
400
453
  }
401
- function calcVisitor({ key, value, keyPath }) {
454
+ function calcVisitor({ value, keyPath }) {
402
455
  if (calcUseRegExp.test(value)) {
403
- // calc translate & border-radius 的百分比计算
404
- if (hasOwn(selfPercentRule, key) && calcPercentExp.test(value)) {
405
- hasSelfPercent = true;
406
- percentKeyPaths.push(keyPath.slice());
407
- }
408
456
  calcKeyPaths.push(keyPath.slice());
409
457
  }
410
458
  }
@@ -420,12 +468,12 @@ export function useTransformStyle(styleObj = {}, { enableVar, transformRadiusPer
420
468
  }
421
469
  }
422
470
  function visitOther({ target, key, value, keyPath }) {
423
- if (filterRegExp.test(value)) {
471
+ if (typeof value === 'string' && (value.includes('%') || value.includes('calc(') || value.includes('env('))) {
424
472
  [envVisitor, percentVisitor, calcVisitor].forEach(visitor => visitor({ target, key, value, keyPath }));
425
473
  }
426
474
  }
427
475
  // traverse var & generate normalStyle
428
- traverseStyle(styleObj, [varVisitor]);
476
+ traverseStyle(styleObj, [varVisitor, boxSizingVisitor]);
429
477
  hasVarDec = hasVarDec || !!externalVarContext;
430
478
  enableVar = enableVar || hasVarDec || hasVarUse;
431
479
  const enableVarRef = useRef(enableVar);
@@ -466,6 +514,9 @@ export function useTransformStyle(styleObj = {}, { enableVar, transformRadiusPer
466
514
  // apply calc
467
515
  transformCalc(normalStyle, calcKeyPaths, (value, key) => {
468
516
  if (PERCENT_REGEX.test(value)) {
517
+ if (hasOwn(selfPercentRule, key)) {
518
+ hasSelfPercent = true;
519
+ }
469
520
  const resolved = resolvePercent(value, key, percentConfig);
470
521
  return typeof resolved === 'number' ? resolved : 0;
471
522
  }
@@ -488,6 +539,7 @@ export function useTransformStyle(styleObj = {}, { enableVar, transformRadiusPer
488
539
  transformBoxShadow(normalStyle);
489
540
  // transform 字符串格式转化数组格式(先转数组再处理css var)
490
541
  transformTransform(normalStyle);
542
+ transformBoxSizing(normalStyle, hasBoxSizingAffectingStyle);
491
543
  return {
492
544
  hasVarDec,
493
545
  varContextRef,
@@ -538,7 +590,7 @@ export function setStyle(styleObj, keyPath, setter) {
538
590
  }
539
591
  export function splitProps(props) {
540
592
  return groupBy(props, (key) => {
541
- if (TEXT_PROPS_REGEX.test(key)) {
593
+ if (hasOwn(TEXT_PROPS_MAP, key)) {
542
594
  return 'textProps';
543
595
  }
544
596
  else {
@@ -577,16 +629,34 @@ export const useLayout = ({ props, hasSelfPercent, setWidth, setHeight, onLayout
577
629
  layoutProps
578
630
  };
579
631
  };
580
- export function wrapChildren(props = {}, { hasVarDec, varContext, textStyle, textProps }) {
632
+ export function useTextPassThroughValue(textStyle, textProps, { inheritTextProps = true, disabled = false } = {}) {
633
+ const parent = useContext(TextPassThroughContext);
634
+ const valueRef = useRef(null);
635
+ if (disabled)
636
+ return null;
637
+ if (!textStyle && !textProps && (inheritTextProps || !parent?.pendingTextProps))
638
+ return null;
639
+ const nextTextStyle = textStyle
640
+ ? extendObject({}, parent?.textStyle, textStyle)
641
+ : parent?.textStyle;
642
+ const nextTextProps = inheritTextProps
643
+ ? textProps
644
+ ? extendObject({}, parent?.pendingTextProps, textProps)
645
+ : parent?.pendingTextProps
646
+ : textProps;
647
+ const nextValue = {
648
+ textStyle: nextTextStyle,
649
+ pendingTextProps: nextTextProps
650
+ };
651
+ if (diffAndCloneA(valueRef.current, nextValue).diff) {
652
+ valueRef.current = nextValue;
653
+ }
654
+ return valueRef.current;
655
+ }
656
+ export function wrapChildren(props = {}, { hasVarDec, varContext, textPassThrough }) {
581
657
  let { children } = props;
582
- if (textStyle || textProps) {
583
- children = Children.map(children, (child) => {
584
- if (isText(child)) {
585
- const style = extendObject({}, textStyle, child.props.style);
586
- return cloneElement(child, extendObject({}, textProps, { style }));
587
- }
588
- return child;
589
- });
658
+ if (textPassThrough) {
659
+ children = <TextPassThroughContext.Provider value={textPassThrough} key='textPassThroughWrap'>{children}</TextPassThroughContext.Provider>;
590
660
  }
591
661
  if (hasVarDec && varContext) {
592
662
  children = <VarContext.Provider value={varContext} key='varContextWrap'>{children}</VarContext.Provider>;
@@ -325,6 +325,7 @@ const useInnerProps = (
325
325
  'parent-font-size',
326
326
  'parent-width',
327
327
  'parent-height',
328
+ 'enable-text-pass-through',
328
329
  ...userRemoveProps,
329
330
  ...rawEventKeys
330
331
  ]
@@ -56,6 +56,7 @@ const styles = StyleSheet.create({
56
56
 
57
57
  interface DefaultFallbackProps {
58
58
  onReload: () => void
59
+ bindreload: () => void
59
60
  }
60
61
 
61
62
  const DefaultFallback = ({ onReload }: DefaultFallbackProps) => {
@@ -171,7 +172,7 @@ const AsyncSuspense: React.FC<AsyncSuspenseProps> = ({
171
172
  } else if (status === 'error') {
172
173
  if (type === 'page') {
173
174
  const fallback = getFallback ? getFallback() : DefaultFallback
174
- return createElement(fallback as ComponentType<DefaultFallbackProps>, { onReload: reloadPage })
175
+ return createElement(fallback as ComponentType<DefaultFallbackProps>, { onReload: reloadPage, bindreload: reloadPage })
175
176
  } else {
176
177
  return getFallback ? createElement(getFallback(), innerProps) : null
177
178
  }
@@ -19,7 +19,7 @@
19
19
  * ✘ app-parameter
20
20
  * ✘ show-message-card
21
21
  * ✘ phone-number-no-quota-toast
22
- * bindgetuserinfo
22
+ * bindgetuserinfo
23
23
  * ✘ bindcontact
24
24
  * ✘ createliveactivity
25
25
  * ✘ bindgetphonenumber
@@ -47,7 +47,7 @@ import {
47
47
  } from 'react-native'
48
48
  import { warn } from '@mpxjs/utils'
49
49
  import { GestureDetector, PanGesture } from 'react-native-gesture-handler'
50
- import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useHover } from './utils'
50
+ import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useHover, useTextPassThroughValue } from './utils'
51
51
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
52
52
  import useNodesRef, { HandlerRef } from './useNodesRef'
53
53
  import { RouteContext, FormContext } from './context'
@@ -308,6 +308,7 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
308
308
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
309
309
 
310
310
  const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle)
311
+ const textPassThrough = useTextPassThroughValue(textStyle, textProps)
311
312
 
312
313
  if (backgroundStyle) {
313
314
  warn('Button does not support background image-related styles!')
@@ -395,7 +396,8 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
395
396
  'hover-start-time',
396
397
  'hover-stay-time',
397
398
  'open-type',
398
- 'form-type'
399
+ 'form-type',
400
+ 'bindgetuserinfo'
399
401
  ],
400
402
  {
401
403
  layoutRef,
@@ -409,8 +411,7 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
409
411
  {
410
412
  hasVarDec,
411
413
  varContext: varContextRef.current,
412
- textStyle,
413
- textProps
414
+ textPassThrough
414
415
  }
415
416
  )
416
417
  )
@@ -328,6 +328,7 @@ const _camera = forwardRef<HandlerRef<any, CameraProps>, CameraProps>((props: Ca
328
328
  'mode',
329
329
  'resolution',
330
330
  'frame-size',
331
+ 'device-position',
331
332
  'bindinitdone',
332
333
  'bindstop',
333
334
  'flash',
@@ -103,7 +103,10 @@ const _Canvas = forwardRef<HandlerRef<CanvasProps & View, CanvasProps>, CanvasPr
103
103
  style: extendObject({}, normalStyle, layoutStyle, { opacity: isLoaded ? 1 : 0 })
104
104
  }
105
105
  ),
106
- [],
106
+ [
107
+ 'originWhitelist',
108
+ 'binderror'
109
+ ],
107
110
  {
108
111
  layoutRef
109
112
  }
@@ -128,7 +128,8 @@ const CheckboxGroup = forwardRef<
128
128
  }
129
129
  ),
130
130
  [
131
- 'name'
131
+ 'name',
132
+ 'bindchange'
132
133
  ],
133
134
  {
134
135
  layoutRef
@@ -26,7 +26,7 @@ import { warn } from '@mpxjs/utils'
26
26
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
27
27
  import useNodesRef, { HandlerRef } from './useNodesRef'
28
28
  import Icon from './mpx-icon'
29
- import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject } from './utils'
29
+ import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useTextPassThroughValue } from './utils'
30
30
  import { CheckboxGroupContext, LabelContext } from './context'
31
31
  import Portal from './mpx-portal'
32
32
 
@@ -148,6 +148,7 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
148
148
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
149
149
 
150
150
  const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle)
151
+ const textPassThrough = useTextPassThroughValue(textStyle, textProps)
151
152
 
152
153
  if (backgroundStyle) {
153
154
  warn('Checkbox does not support background image-related styles!')
@@ -178,7 +179,9 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
178
179
  [
179
180
  'value',
180
181
  'disabled',
181
- 'checked'
182
+ 'checked',
183
+ 'color',
184
+ '_onChange'
182
185
  ],
183
186
  {
184
187
  layoutRef
@@ -224,8 +227,7 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
224
227
  {
225
228
  hasVarDec,
226
229
  varContext: varContextRef.current,
227
- textStyle,
228
- textProps
230
+ textPassThrough
229
231
  }
230
232
  )
231
233
  )
@@ -9,7 +9,7 @@ import { JSX, useRef, forwardRef, ReactNode, useMemo, createElement } from 'reac
9
9
  import useNodesRef, { HandlerRef } from './useNodesRef'
10
10
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
11
11
  import { FormContext } from './context'
12
- import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren, extendObject } from './utils'
12
+ import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren, extendObject, useTextPassThroughValue } from './utils'
13
13
  interface FormProps {
14
14
  style?: Record<string, any>
15
15
  children?: ReactNode
@@ -48,6 +48,7 @@ const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: For
48
48
  } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
49
49
 
50
50
  const { textStyle, innerStyle = {} } = splitStyle(normalStyle)
51
+ const textPassThrough = useTextPassThroughValue(textStyle, textProps)
51
52
 
52
53
  const formRef = useRef(null)
53
54
  useNodesRef(props, ref, formRef, {
@@ -117,8 +118,7 @@ const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: For
117
118
  {
118
119
  hasVarDec,
119
120
  varContext: varContextRef.current,
120
- textStyle,
121
- textProps
121
+ textPassThrough
122
122
  }
123
123
  )
124
124
  ))
@@ -99,7 +99,11 @@ const Icon = forwardRef<HandlerRef<Text, IconProps>, IconProps>(
99
99
  style: extendObject({}, normalStyle, layoutStyle, { tintColor: color })
100
100
  }
101
101
  ),
102
- [],
102
+ [
103
+ 'type',
104
+ 'size',
105
+ 'color'
106
+ ],
103
107
  {
104
108
  layoutRef
105
109
  }
@@ -20,10 +20,11 @@ import {
20
20
  ImageErrorEventData,
21
21
  LayoutChangeEvent,
22
22
  DimensionValue,
23
- ImageLoadEventData
23
+ ImageLoadEventData,
24
+ ImageSourcePropType
24
25
  } from 'react-native'
25
26
  import { noop } from '@mpxjs/utils'
26
- import { SvgCssUri } from 'react-native-svg/css'
27
+ import { LocalSvg, SvgCssUri } from 'react-native-svg/css'
27
28
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
28
29
  import useNodesRef, { HandlerRef } from './useNodesRef'
29
30
  import { SVG_REGEXP, useLayout, useTransformStyle, renderImage, extendObject, isAndroid } from './utils'
@@ -46,9 +47,8 @@ export type Mode =
46
47
  | 'bottom right'
47
48
 
48
49
  export interface ImageProps {
49
- src?: string
50
+ src?: string | ImageSourcePropType
50
51
  mode?: Mode
51
- svg?: boolean
52
52
  style?: ImageStyle & Record<string, any>
53
53
  'enable-offset'?: boolean
54
54
  'enable-var'?: boolean
@@ -57,6 +57,7 @@ export interface ImageProps {
57
57
  'parent-width'?: number
58
58
  'parent-height'?: number
59
59
  'enable-fast-image'?: boolean
60
+ 'is-svg'?: boolean
60
61
  bindload?: (evt: NativeSyntheticEvent<ImageLoadEventData> | unknown) => void
61
62
  binderror?: (evt: NativeSyntheticEvent<ImageErrorEventData> | unknown) => void
62
63
  }
@@ -71,7 +72,6 @@ interface ImageState {
71
72
 
72
73
  const DEFAULT_IMAGE_WIDTH = 320
73
74
  const DEFAULT_IMAGE_HEIGHT = 240
74
-
75
75
  const cropMode: Mode[] = [
76
76
  'top',
77
77
  'bottom',
@@ -99,6 +99,32 @@ const relativeCenteredSize = (viewSize: number, imageSize: number) => {
99
99
  return (viewSize - imageSize) / 2
100
100
  }
101
101
 
102
+ function normalizeImageSource (src: string | ImageSourcePropType): ImageSourcePropType {
103
+ return typeof src === 'string' ? { uri: src } : src
104
+ }
105
+
106
+ function getImageUri (src: string | ImageSourcePropType) {
107
+ return typeof src === 'string' ? src : RNImage.resolveAssetSource(src)?.uri || ''
108
+ }
109
+
110
+ function isSvgSource (src: string | ImageSourcePropType) {
111
+ const uri = getImageUri(src)
112
+ return SVG_REGEXP.test(uri)
113
+ }
114
+
115
+ function getImageSize (src: string | ImageSourcePropType, success: (width: number, height: number) => void, fail: () => void = noop) {
116
+ if (typeof src === 'string') {
117
+ RNImage.getSize(src, success, fail)
118
+ return
119
+ }
120
+ const source = RNImage.resolveAssetSource(src)
121
+ if (source && source.width && source.height) {
122
+ success(source.width, source.height)
123
+ } else {
124
+ fail()
125
+ }
126
+ }
127
+
102
128
  // 获取能完全显示图片的缩放比例:长宽方向的缩放比例最小值即为能完全展示的比例
103
129
  function getFitScale (width1: number, height1: number, width2: number, height2: number) {
104
130
  return Math.min(width2 / width1, height2 / height1)
@@ -137,6 +163,7 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
137
163
  'enable-fast-image': enableFastImage,
138
164
  'parent-width': parentWidth,
139
165
  'parent-height': parentHeight,
166
+ 'is-svg': isSvgProp,
140
167
  bindload,
141
168
  binderror
142
169
  } = props
@@ -158,7 +185,7 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
158
185
  defaultStyle
159
186
  })
160
187
 
161
- const isSvg = SVG_REGEXP.test(src)
188
+ const isSvg = isSvgProp || isSvgSource(src)
162
189
  const isWidthFixMode = mode === 'widthFix'
163
190
  const isHeightFixMode = mode === 'heightFix'
164
191
  const isCropMode = cropMode.includes(mode)
@@ -380,7 +407,7 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
380
407
 
381
408
  const onImageLoad = (evt: NativeSyntheticEvent<ImageLoadEventData>) => {
382
409
  evt.persist()
383
- RNImage.getSize(src, (width: number, height: number) => {
410
+ const triggerLoad = (width: number, height: number) => {
384
411
  bindload!(
385
412
  getCustomEvent(
386
413
  'load',
@@ -392,7 +419,13 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
392
419
  props
393
420
  )
394
421
  )
395
- })
422
+ }
423
+ const { source } = evt.nativeEvent
424
+ if (source && source.width && source.height) {
425
+ triggerLoad(source.width, source.height)
426
+ return
427
+ }
428
+ getImageSize(src, triggerLoad)
396
429
  }
397
430
 
398
431
  const onImageError = (evt: NativeSyntheticEvent<ImageErrorEventData>) => {
@@ -411,7 +444,7 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
411
444
 
412
445
  useEffect(() => {
413
446
  if (!isSvg && isLayoutMode) {
414
- RNImage.getSize(
447
+ getImageSize(
415
448
  src,
416
449
  (width: number, height: number) => {
417
450
  state.current.imageWidth = width
@@ -457,7 +490,10 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
457
490
  [
458
491
  'src',
459
492
  'mode',
460
- 'svg'
493
+ 'is-svg',
494
+ 'enable-fast-image',
495
+ 'bindload',
496
+ 'binderror'
461
497
  ],
462
498
  {
463
499
  layoutRef
@@ -465,18 +501,19 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
465
501
  )
466
502
 
467
503
  function renderSvgImage () {
504
+ const svgProps = {
505
+ onLayout: onSvgLoad,
506
+ style: extendObject(
507
+ { transformOrigin: 'left top' },
508
+ modeStyle
509
+ )
510
+ }
468
511
  return createElement(
469
512
  View,
470
513
  innerProps,
471
- createElement(SvgCssUri, {
472
- uri: src,
473
- onLayout: onSvgLoad,
474
- onError: binderror && onSvgError,
475
- style: extendObject(
476
- { transformOrigin: 'left top' },
477
- modeStyle
478
- )
479
- })
514
+ typeof src === 'string'
515
+ ? createElement(SvgCssUri, extendObject({ uri: src, onError: binderror && onSvgError }, svgProps))
516
+ : createElement(LocalSvg, extendObject({ asset: src }, svgProps))
480
517
  )
481
518
  }
482
519
 
@@ -484,7 +521,7 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
484
521
  return renderImage(
485
522
  extendObject(
486
523
  {
487
- source: { uri: src },
524
+ source: normalizeImageSource(src),
488
525
  resizeMode: resizeMode,
489
526
  onLoad: bindload && onImageLoad,
490
527
  onError: binderror && onImageError,
@@ -1,16 +1,21 @@
1
1
  import { Text, TextProps } from 'react-native'
2
- import { JSX, createElement } from 'react'
2
+ import { JSX, createElement, useContext } from 'react'
3
3
 
4
- import { extendObject } from './utils'
4
+ import { extendObject, getDefaultAllowFontScaling } from './utils'
5
+ import { TextPassThroughContext } from './context'
5
6
 
6
7
  const InlineText = (props: TextProps): JSX.Element => {
8
+ const inheritedText = useContext(TextPassThroughContext)
9
+ const style = extendObject({}, inheritedText?.textStyle, props.style)
10
+ const mergedProps = extendObject({}, inheritedText?.pendingTextProps, props, { style })
7
11
  const {
8
- allowFontScaling = false
9
- } = props
12
+ allowFontScaling,
13
+ children
14
+ } = mergedProps
10
15
 
11
- return createElement(Text, extendObject({}, props, {
12
- allowFontScaling
13
- }))
16
+ return createElement(Text, extendObject({}, mergedProps, {
17
+ allowFontScaling: allowFontScaling ?? getDefaultAllowFontScaling()
18
+ }), children)
14
19
  }
15
20
 
16
21
  InlineText.displayName = 'MpxInlineText'