@mpxjs/webpack-plugin 2.10.16-beta.6 → 2.10.16-perf.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/config.js +0 -60
- package/lib/dependencies/AppEntryDependency.js +2 -2
- package/lib/dependencies/ResolveDependency.js +1 -1
- package/lib/file-loader.js +3 -13
- package/lib/helpers.js +0 -2
- package/lib/index.js +15 -40
- package/lib/json-compiler/helper.js +2 -72
- package/lib/json-compiler/index.js +56 -16
- package/lib/json-compiler/plugin.js +2 -2
- package/lib/loader.js +4 -10
- package/lib/native-loader.js +3 -6
- package/lib/platform/json/wx/index.js +29 -30
- package/lib/platform/style/wx/index.js +1 -8
- package/lib/platform/template/wx/component-config/ad.js +0 -5
- package/lib/platform/template/wx/component-config/button.js +5 -21
- package/lib/platform/template/wx/component-config/camera.js +3 -25
- package/lib/platform/template/wx/component-config/canvas.js +1 -8
- package/lib/platform/template/wx/component-config/component.js +33 -31
- package/lib/platform/template/wx/component-config/cover-image.js +2 -7
- package/lib/platform/template/wx/component-config/cover-view.js +1 -3
- package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
- package/lib/platform/template/wx/component-config/form.js +2 -27
- package/lib/platform/template/wx/component-config/image.js +0 -5
- package/lib/platform/template/wx/component-config/input.js +0 -10
- package/lib/platform/template/wx/component-config/label.js +2 -10
- package/lib/platform/template/wx/component-config/map.js +0 -11
- package/lib/platform/template/wx/component-config/movable-area.js +1 -4
- package/lib/platform/template/wx/component-config/movable-view.js +2 -17
- package/lib/platform/template/wx/component-config/navigator.js +0 -26
- package/lib/platform/template/wx/component-config/picker-view.js +0 -12
- package/lib/platform/template/wx/component-config/picker.js +1 -3
- package/lib/platform/template/wx/component-config/progress.js +1 -11
- package/lib/platform/template/wx/component-config/rich-text.js +0 -5
- package/lib/platform/template/wx/component-config/scroll-view.js +1 -12
- package/lib/platform/template/wx/component-config/slider.js +0 -8
- package/lib/platform/template/wx/component-config/swiper-item.js +2 -5
- package/lib/platform/template/wx/component-config/swiper.js +0 -10
- package/lib/platform/template/wx/component-config/text.js +0 -5
- package/lib/platform/template/wx/component-config/textarea.js +2 -19
- package/lib/platform/template/wx/component-config/unsupported.js +1 -10
- package/lib/platform/template/wx/component-config/video.js +0 -10
- package/lib/platform/template/wx/index.js +1 -21
- package/lib/react/index.js +0 -2
- package/lib/react/processJSON.js +71 -39
- package/lib/react/processStyles.js +2 -3
- package/lib/react/processTemplate.js +6 -8
- package/lib/react/script-helper.js +16 -6
- package/lib/react/style-helper.js +2 -10
- package/lib/runtime/components/react/context.ts +6 -12
- package/lib/runtime/components/react/dist/context.js +0 -1
- package/lib/runtime/components/react/dist/mpx-image.jsx +62 -100
- package/lib/runtime/components/react/dist/mpx-input.jsx +9 -35
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +50 -58
- package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +3 -4
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +18 -12
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +11 -8
- package/lib/runtime/components/react/dist/mpx-portal/index.jsx +1 -5
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +14 -6
- package/lib/runtime/components/react/dist/mpx-text.jsx +5 -33
- package/lib/runtime/components/react/dist/mpx-view.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
- package/lib/runtime/components/react/dist/utils.jsx +6 -16
- package/lib/runtime/components/react/mpx-image.tsx +82 -123
- package/lib/runtime/components/react/mpx-input.tsx +16 -41
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +49 -66
- package/lib/runtime/components/react/mpx-picker-view/index.tsx +2 -5
- package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +21 -26
- package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +12 -8
- package/lib/runtime/components/react/mpx-portal/index.tsx +2 -8
- package/lib/runtime/components/react/mpx-scroll-view.tsx +17 -6
- package/lib/runtime/components/react/mpx-text.tsx +5 -38
- package/lib/runtime/components/react/mpx-view.tsx +1 -1
- package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
- package/lib/runtime/components/react/types/common.d.ts +0 -19
- package/lib/runtime/components/react/utils.tsx +6 -15
- package/lib/runtime/stringify.wxs +2 -2
- package/lib/script-setup-compiler/index.js +2 -2
- package/lib/style-compiler/index.js +2 -3
- package/lib/style-compiler/load-postcss-config.js +1 -1
- package/lib/style-compiler/plugins/trans-special.js +2 -10
- package/lib/style-compiler/strip-conditional-loader.js +15 -178
- package/lib/template-compiler/bind-this.js +2 -2
- package/lib/template-compiler/compiler.js +72 -270
- package/lib/template-compiler/gen-node-react.js +6 -18
- package/lib/template-compiler/index.js +10 -12
- package/lib/template-compiler/parse-exps.js +1 -1
- package/lib/utils/const.js +1 -2
- package/lib/utils/dom-tag-config.js +6 -6
- package/lib/utils/env.js +1 -6
- package/lib/utils/pre-process-json.js +0 -5
- package/lib/web/index.js +0 -2
- package/lib/web/processJSON.js +16 -44
- package/lib/web/processScript.js +1 -1
- package/lib/web/processTemplate.js +4 -6
- package/lib/web/script-helper.js +9 -19
- package/lib/wxs/pre-loader.js +1 -1
- package/lib/wxss/loader.js +9 -1
- package/package.json +2 -13
- package/lib/dependencies/RecordModuleIdMapDependency.js +0 -49
- package/lib/runtime/components/react/dist/context.d.ts +0 -75
- package/lib/runtime/components/react/dist/context.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/event.config.d.ts +0 -8
- package/lib/runtime/components/react/dist/event.config.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts +0 -8
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +0 -13
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-button.d.ts +0 -69
- package/lib/runtime/components/react/dist/mpx-button.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-camera.d.ts +0 -28
- package/lib/runtime/components/react/dist/mpx-camera.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-camera.jsx +0 -102
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +0 -24
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +0 -8
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +0 -7
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +0 -21
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +0 -9
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +0 -11
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +0 -3
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +0 -33
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +0 -53
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +0 -21
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +0 -33
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-form.d.ts +0 -28
- package/lib/runtime/components/react/dist/mpx-form.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +0 -19
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -22
- package/lib/runtime/components/react/dist/mpx-image.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +0 -8
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-input.d.ts +0 -50
- package/lib/runtime/components/react/dist/mpx-input.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +0 -13
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-label.d.ts +0 -21
- package/lib/runtime/components/react/dist/mpx-label.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +0 -21
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +0 -66
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-nav.d.ts +0 -9
- package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-nav.jsx +0 -132
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts +0 -10
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +0 -7
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +0 -8
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +0 -7
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +0 -7
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +0 -7
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +0 -3
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +0 -7
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +0 -7
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +0 -107
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +0 -33
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +0 -9
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +0 -24
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +0 -15
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +0 -14
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.jsx +0 -20
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +0 -17
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +0 -13
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +0 -12
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +0 -23
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +0 -17
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +0 -16
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +0 -30
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +0 -10
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-progress.d.ts +0 -24
- package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +0 -21
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-radio.d.ts +0 -27
- package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +0 -2
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +0 -25
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +0 -15
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +0 -55
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +0 -8
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +0 -8
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-slider.d.ts +0 -31
- package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +0 -18
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +0 -16
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +0 -19
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts +0 -53
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-switch.d.ts +0 -27
- package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-text.d.ts +0 -23
- package/lib/runtime/components/react/dist/mpx-text.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts +0 -8
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-video.d.ts +0 -102
- package/lib/runtime/components/react/dist/mpx-video.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-view.d.ts +0 -35
- package/lib/runtime/components/react/dist/mpx-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts +0 -23
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/parser.d.ts +0 -40
- package/lib/runtime/components/react/dist/parser.d.ts.map +0 -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/useNodesRef.d.ts +0 -12
- package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/utils.d.ts +0 -123
- package/lib/runtime/components/react/dist/utils.d.ts.map +0 -1
- package/lib/runtime/components/react/mpx-camera.tsx +0 -167
- package/lib/runtime/components/react/mpx-nav.tsx +0 -155
- package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +0 -55
- package/lib/utils/get-build-tag-component.js +0 -35
package/lib/react/processJSON.js
CHANGED
|
@@ -12,8 +12,11 @@ const { transSubpackage } = require('../utils/trans-async-sub-rules')
|
|
|
12
12
|
const createJSONHelper = require('../json-compiler/helper')
|
|
13
13
|
const getRulesRunner = require('../platform/index')
|
|
14
14
|
const { RESOLVE_IGNORED_ERR } = require('../utils/const')
|
|
15
|
+
const normalize = require('../utils/normalize')
|
|
15
16
|
const RecordResourceMapDependency = require('../dependencies/RecordResourceMapDependency')
|
|
16
17
|
const RecordPageConfigsMapDependency = require('../dependencies/RecordPageConfigsMapDependency')
|
|
18
|
+
const mpxViewPath = normalize.lib('runtime/components/react/dist/mpx-view.jsx')
|
|
19
|
+
const mpxTextPath = normalize.lib('runtime/components/react/dist/mpx-text.jsx')
|
|
17
20
|
|
|
18
21
|
module.exports = function (jsonContent, {
|
|
19
22
|
loaderContext,
|
|
@@ -39,38 +42,23 @@ module.exports = function (jsonContent, {
|
|
|
39
42
|
|
|
40
43
|
const emitWarning = (msg) => {
|
|
41
44
|
loaderContext.emitWarning(
|
|
42
|
-
new Error('[
|
|
45
|
+
new Error('[json processor][' + loaderContext.resource + ']: ' + msg)
|
|
43
46
|
)
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
const emitError = (msg) => {
|
|
47
50
|
loaderContext.emitError(
|
|
48
|
-
new Error('[
|
|
51
|
+
new Error('[json compiler][' + loaderContext.resource + ']: ' + msg)
|
|
49
52
|
)
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
|
|
53
56
|
|
|
54
|
-
function fillInComponentsMap (name, entry, tarRoot) {
|
|
55
|
-
const { resource, outputPath } = entry
|
|
56
|
-
const { resourcePath } = parseRequest(resource)
|
|
57
|
-
componentsMap[resourcePath] = outputPath
|
|
58
|
-
loaderContext._module && loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'component', outputPath))
|
|
59
|
-
localComponentsMap[name] = {
|
|
60
|
-
resource: addQuery(resource, {
|
|
61
|
-
isComponent: true,
|
|
62
|
-
outputPath
|
|
63
|
-
}),
|
|
64
|
-
async: tarRoot
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
57
|
const {
|
|
69
58
|
isUrlRequest,
|
|
70
59
|
urlToRequest,
|
|
71
60
|
processPage,
|
|
72
|
-
processComponent
|
|
73
|
-
processPlaceholder
|
|
61
|
+
processComponent
|
|
74
62
|
} = createJSONHelper({
|
|
75
63
|
loaderContext,
|
|
76
64
|
emitWarning,
|
|
@@ -149,6 +137,45 @@ module.exports = function (jsonContent, {
|
|
|
149
137
|
isShow: true
|
|
150
138
|
}
|
|
151
139
|
|
|
140
|
+
const fillInComponentPlaceholder = (name, placeholder, placeholderEntry) => {
|
|
141
|
+
const componentPlaceholder = jsonObj.componentPlaceholder || {}
|
|
142
|
+
if (componentPlaceholder[name]) return
|
|
143
|
+
componentPlaceholder[name] = placeholder
|
|
144
|
+
jsonObj.componentPlaceholder = componentPlaceholder
|
|
145
|
+
if (placeholderEntry && !jsonObj.usingComponents[placeholder]) jsonObj.usingComponents[placeholder] = placeholderEntry
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const fillInComponentsMap = (name, entry, tarRoot) => {
|
|
149
|
+
const { resource, outputPath } = entry
|
|
150
|
+
const { resourcePath } = parseRequest(resource)
|
|
151
|
+
tarRoot = transSubpackage(mpx.transSubpackageRules, tarRoot)
|
|
152
|
+
componentsMap[resourcePath] = outputPath
|
|
153
|
+
loaderContext._module && loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'component', outputPath))
|
|
154
|
+
localComponentsMap[name] = {
|
|
155
|
+
resource: addQuery(resource, {
|
|
156
|
+
isComponent: true,
|
|
157
|
+
outputPath
|
|
158
|
+
}),
|
|
159
|
+
async: tarRoot
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const normalizePlaceholder = (placeholder) => {
|
|
164
|
+
if (typeof placeholder === 'string') {
|
|
165
|
+
const placeholderMap = mode === 'ali'
|
|
166
|
+
? {
|
|
167
|
+
view: { name: 'mpx-view', resource: mpxViewPath },
|
|
168
|
+
text: { name: 'mpx-text', resource: mpxTextPath }
|
|
169
|
+
}
|
|
170
|
+
: {}
|
|
171
|
+
placeholder = placeholderMap[placeholder] || { name: placeholder }
|
|
172
|
+
}
|
|
173
|
+
if (!placeholder.name) {
|
|
174
|
+
emitError('The asyncSubpackageRules configuration format of @mpxjs/webpack-plugin a is incorrect')
|
|
175
|
+
}
|
|
176
|
+
return placeholder
|
|
177
|
+
}
|
|
178
|
+
|
|
152
179
|
const processTabBar = (tabBar, callback) => {
|
|
153
180
|
if (tabBar) {
|
|
154
181
|
tabBar = Object.assign({}, defaultTabbar, tabBar)
|
|
@@ -318,34 +345,38 @@ module.exports = function (jsonContent, {
|
|
|
318
345
|
|
|
319
346
|
const processComponents = (components, context, callback) => {
|
|
320
347
|
if (components) {
|
|
321
|
-
const asyncComponents = []
|
|
322
|
-
const resolveResourcePathMap = new Map()
|
|
323
348
|
async.eachOf(components, (component, name, callback) => {
|
|
324
|
-
processComponent(component, context, {}, (err, entry = {}, { tarRoot, placeholder
|
|
349
|
+
processComponent(component, context, {}, (err, entry = {}, { tarRoot, placeholder } = {}) => {
|
|
325
350
|
if (err) return callback(err === RESOLVE_IGNORED_ERR ? null : err)
|
|
351
|
+
fillInComponentsMap(name, entry, tarRoot)
|
|
326
352
|
const { relativePath } = entry
|
|
327
353
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
resolveResourcePathMap.set(name, resourcePath)
|
|
331
|
-
if (tarRoot) asyncComponents.push({ name, tarRoot, placeholder, relativePath })
|
|
332
|
-
|
|
333
|
-
fillInComponentsMap(name, entry, tarRoot)
|
|
334
|
-
callback()
|
|
335
|
-
})
|
|
336
|
-
}, (err) => {
|
|
337
|
-
if (err) return callback(err)
|
|
338
|
-
async.each(asyncComponents, ({ name, tarRoot, placeholder, relativePath }, callback) => {
|
|
339
|
-
processPlaceholder({ jsonObj, context, name, tarRoot, placeholder, relativePath, resolveResourcePathMap }, (err, placeholder) => {
|
|
340
|
-
if (err) return callback(err)
|
|
354
|
+
if (tarRoot) {
|
|
341
355
|
if (placeholder) {
|
|
342
|
-
|
|
343
|
-
|
|
356
|
+
placeholder = normalizePlaceholder(placeholder)
|
|
357
|
+
if (placeholder.resource) {
|
|
358
|
+
processComponent(placeholder.resource, projectRoot, { relativePath }, (err, entry) => {
|
|
359
|
+
if (err) return callback(err)
|
|
360
|
+
fillInComponentPlaceholder(name, placeholder.name, entry)
|
|
361
|
+
fillInComponentsMap(placeholder.name, entry, '')
|
|
362
|
+
callback()
|
|
363
|
+
})
|
|
364
|
+
} else {
|
|
365
|
+
fillInComponentPlaceholder(name, placeholder.name)
|
|
366
|
+
callback()
|
|
367
|
+
}
|
|
368
|
+
} else {
|
|
369
|
+
if (!jsonObj.componentPlaceholder || !jsonObj.componentPlaceholder[name]) {
|
|
370
|
+
const errMsg = `componentPlaceholder of "${name}" doesn't exist! \n\r`
|
|
371
|
+
emitError(errMsg)
|
|
372
|
+
}
|
|
373
|
+
callback()
|
|
344
374
|
}
|
|
375
|
+
} else {
|
|
345
376
|
callback()
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
})
|
|
377
|
+
}
|
|
378
|
+
})
|
|
379
|
+
}, callback)
|
|
349
380
|
} else {
|
|
350
381
|
callback()
|
|
351
382
|
}
|
|
@@ -363,6 +394,7 @@ module.exports = function (jsonContent, {
|
|
|
363
394
|
callback()
|
|
364
395
|
}
|
|
365
396
|
}
|
|
397
|
+
|
|
366
398
|
async.parallel([
|
|
367
399
|
(callback) => {
|
|
368
400
|
// 添加首页标识
|
|
@@ -15,12 +15,12 @@ module.exports = function (styles, {
|
|
|
15
15
|
if (styles.length) {
|
|
16
16
|
const warn = (msg) => {
|
|
17
17
|
loaderContext.emitWarning(
|
|
18
|
-
new Error('[
|
|
18
|
+
new Error('[style compiler][' + loaderContext.resource + ']: ' + msg)
|
|
19
19
|
)
|
|
20
20
|
}
|
|
21
21
|
const error = (msg) => {
|
|
22
22
|
loaderContext.emitError(
|
|
23
|
-
new Error('[
|
|
23
|
+
new Error('[style compiler][' + loaderContext.resource + ']: ' + msg)
|
|
24
24
|
)
|
|
25
25
|
}
|
|
26
26
|
const { mode, srcMode } = loaderContext.getMpx()
|
|
@@ -52,7 +52,6 @@ module.exports = function (styles, {
|
|
|
52
52
|
filename: loaderContext.resourcePath,
|
|
53
53
|
mode,
|
|
54
54
|
srcMode,
|
|
55
|
-
ctorType,
|
|
56
55
|
warn,
|
|
57
56
|
error
|
|
58
57
|
})
|
|
@@ -17,7 +17,6 @@ module.exports = function (template, {
|
|
|
17
17
|
moduleId,
|
|
18
18
|
ctorType,
|
|
19
19
|
usingComponentsInfo,
|
|
20
|
-
originalUsingComponents,
|
|
21
20
|
componentGenerics
|
|
22
21
|
}, callback) {
|
|
23
22
|
const mpx = loaderContext.getMpx()
|
|
@@ -47,29 +46,28 @@ module.exports = function (template, {
|
|
|
47
46
|
if (template) {
|
|
48
47
|
// 由于远端src template资源引用的相对路径可能发生变化,暂时不支持。
|
|
49
48
|
if (template.src) {
|
|
50
|
-
return callback(new Error('[
|
|
49
|
+
return callback(new Error('[mpx loader][' + loaderContext.resource + ']: ' + 'template content must be inline in .mpx files!'))
|
|
51
50
|
}
|
|
52
51
|
if (template.lang) {
|
|
53
|
-
return callback(new Error('[
|
|
52
|
+
return callback(new Error('[mpx loader][' + loaderContext.resource + ']: ' + 'template lang is not supported in trans react native mode temporarily, we will support it in the future!'))
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
if (template.content) {
|
|
57
56
|
const templateSrcMode = template.mode || srcMode
|
|
58
57
|
const warn = (msg) => {
|
|
59
58
|
loaderContext.emitWarning(
|
|
60
|
-
new Error('[
|
|
59
|
+
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
61
60
|
)
|
|
62
61
|
}
|
|
63
62
|
const error = (msg) => {
|
|
64
63
|
loaderContext.emitError(
|
|
65
|
-
new Error('[
|
|
64
|
+
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
66
65
|
)
|
|
67
66
|
}
|
|
68
67
|
const { root, meta } = templateCompiler.parse(template.content, {
|
|
69
68
|
warn,
|
|
70
69
|
error,
|
|
71
70
|
usingComponentsInfo, // processTemplate中无其他地方使用,直接透传 string 类型
|
|
72
|
-
originalUsingComponents,
|
|
73
71
|
hasComment,
|
|
74
72
|
isNative,
|
|
75
73
|
ctorType,
|
|
@@ -115,7 +113,7 @@ module.exports = function (template, {
|
|
|
115
113
|
output += `var ${module} = require(${loaderUtils.stringifyRequest(this, src)});\n`
|
|
116
114
|
}
|
|
117
115
|
|
|
118
|
-
const rawCode = genNode(root
|
|
116
|
+
const rawCode = genNode(root)
|
|
119
117
|
if (rawCode) {
|
|
120
118
|
try {
|
|
121
119
|
const ignoreMap = Object.assign({
|
|
@@ -132,7 +130,7 @@ module.exports = function (template, {
|
|
|
132
130
|
return ${bindResult.code}
|
|
133
131
|
};\n`
|
|
134
132
|
} catch (e) {
|
|
135
|
-
error(`
|
|
133
|
+
error(`Invalid render function generated by the template, please check!
|
|
136
134
|
Error code:
|
|
137
135
|
${rawCode}
|
|
138
136
|
Error Detail:
|
|
@@ -4,11 +4,16 @@ const parseRequest = require('../utils/parse-request')
|
|
|
4
4
|
const shallowStringify = require('../utils/shallow-stringify')
|
|
5
5
|
const normalize = require('../utils/normalize')
|
|
6
6
|
const addQuery = require('../utils/add-query')
|
|
7
|
+
const { isBuildInReactTag } = require('../utils/dom-tag-config')
|
|
7
8
|
|
|
8
9
|
function stringifyRequest (loaderContext, request) {
|
|
9
10
|
return loaderUtils.stringifyRequest(loaderContext, request)
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
function getBuiltInComponentRequest (component) {
|
|
14
|
+
return JSON.stringify(addQuery(`@mpxjs/webpack-plugin/lib/runtime/components/react/dist/${component}`, { isComponent: true }))
|
|
15
|
+
}
|
|
16
|
+
|
|
12
17
|
function getAsyncChunkName (chunkName) {
|
|
13
18
|
if (chunkName && typeof chunkName !== 'boolean') {
|
|
14
19
|
return `/* webpackChunkName: "${chunkName}/index" */`
|
|
@@ -21,8 +26,8 @@ function getAsyncSuspense (type, moduleId, componentRequest, componentName, chun
|
|
|
21
26
|
type: ${JSON.stringify(type)},
|
|
22
27
|
moduleId: ${JSON.stringify(moduleId)},
|
|
23
28
|
chunkName: ${JSON.stringify(chunkName)},
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
getFallback: ${getFallback},
|
|
30
|
+
getLoading: ${getLoading},
|
|
26
31
|
getChildren () {
|
|
27
32
|
return import(${getAsyncChunkName(chunkName)}${componentRequest}).then(function (res) {
|
|
28
33
|
return getComponent(res, {displayName: ${JSON.stringify(componentName)}})
|
|
@@ -90,17 +95,22 @@ function buildComponentsMap ({ localComponentsMap, builtInComponentsMap, loaderC
|
|
|
90
95
|
if (placeholder) {
|
|
91
96
|
if (localComponentsMap[placeholder]) {
|
|
92
97
|
const placeholderCfg = localComponentsMap[placeholder]
|
|
98
|
+
const placeholderRequest = stringifyRequest(loaderContext, placeholderCfg.resource)
|
|
93
99
|
if (placeholderCfg.async) {
|
|
94
100
|
loaderContext.emitWarning(
|
|
95
101
|
new Error(`[json processor][${loaderContext.resource}]: componentPlaceholder ${placeholder} should not be a async component, please check!`)
|
|
96
102
|
)
|
|
97
103
|
}
|
|
98
|
-
const placeholderRequest = stringifyRequest(loaderContext, placeholderCfg.resource)
|
|
99
104
|
getFallback = getComponentGetter(getComponent(placeholderRequest, placeholder))
|
|
100
105
|
} else {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
106
|
+
const tag = `mpx-${placeholder}`
|
|
107
|
+
if (isBuildInReactTag(tag)) {
|
|
108
|
+
getFallback = getComponentGetter(getBuiltInComponent(getBuiltInComponentRequest(tag)))
|
|
109
|
+
} else {
|
|
110
|
+
loaderContext.emitError(
|
|
111
|
+
new Error(`[json processor][${loaderContext.resource}]: componentPlaceholder ${placeholder} is not built-in component, please check!`)
|
|
112
|
+
)
|
|
113
|
+
}
|
|
104
114
|
}
|
|
105
115
|
} else {
|
|
106
116
|
loaderContext.emitError(
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const postcss = require('postcss')
|
|
2
2
|
const selectorParser = require('postcss-selector-parser')
|
|
3
|
-
const { MPX_TAG_PAGE_SELECTOR } = require('../utils/const')
|
|
4
3
|
const getRulesRunner = require('../platform/index')
|
|
5
4
|
const dash2hump = require('../utils/hump-dash').dash2hump
|
|
6
5
|
const unitRegExp = /^\s*(-?\d+(?:\.\d+)?)(rpx|vw|vh)\s*$/
|
|
@@ -8,8 +7,8 @@ const numberRegExp = /^\s*(-?\d+(\.\d+)?)(px)?\s*$/
|
|
|
8
7
|
const hairlineRegExp = /^\s*hairlineWidth\s*$/
|
|
9
8
|
const varRegExp = /^--/
|
|
10
9
|
const cssPrefixExp = /^-(webkit|moz|ms|o)-/
|
|
11
|
-
function getClassMap ({ content, filename, mode, srcMode,
|
|
12
|
-
const classMap =
|
|
10
|
+
function getClassMap ({ content, filename, mode, srcMode, warn, error }) {
|
|
11
|
+
const classMap = {}
|
|
13
12
|
|
|
14
13
|
const root = postcss.parse(content, {
|
|
15
14
|
from: filename
|
|
@@ -37,13 +36,6 @@ function getClassMap ({ content, filename, mode, srcMode, ctorType, warn, error
|
|
|
37
36
|
error
|
|
38
37
|
})
|
|
39
38
|
|
|
40
|
-
// 目前所有 AtRule 只支持 @media,其他全部给出错误提示
|
|
41
|
-
root.walkAtRules(rule => {
|
|
42
|
-
if (rule.name !== 'media') {
|
|
43
|
-
warn(`Only @media rule is supported in react native mode temporarily, but got @${rule.name}`)
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
|
|
47
39
|
root.walkRules(rule => {
|
|
48
40
|
const classMapValue = {}
|
|
49
41
|
rule.walkDecls(({ prop, value }) => {
|
|
@@ -6,13 +6,9 @@ export type LabelContextValue = MutableRefObject<{
|
|
|
6
6
|
triggerChange: (evt: NativeSyntheticEvent<TouchEvent>) => void
|
|
7
7
|
}>
|
|
8
8
|
|
|
9
|
-
export type KeyboardAvoidContextValue = MutableRefObject<
|
|
10
|
-
cursorSpacing: number
|
|
11
|
-
|
|
12
|
-
adjustPosition: boolean
|
|
13
|
-
keyboardHeight?: number
|
|
14
|
-
onKeyboardShow?: () => void
|
|
15
|
-
} | null>
|
|
9
|
+
export type KeyboardAvoidContextValue = MutableRefObject<
|
|
10
|
+
{ cursorSpacing: number, ref: MutableRefObject<any> } | null
|
|
11
|
+
>
|
|
16
12
|
|
|
17
13
|
export interface GroupValue {
|
|
18
14
|
[key: string]: { checked: boolean; setValue: Dispatch<SetStateAction<boolean>> }
|
|
@@ -41,13 +37,13 @@ export interface IntersectionObserver {
|
|
|
41
37
|
}
|
|
42
38
|
|
|
43
39
|
export interface PortalContextValue {
|
|
44
|
-
mount: (children: React.ReactNode, key?: number | null, id?: number
|
|
40
|
+
mount: (children: React.ReactNode, key?: number | null, id?: number| null) => number| undefined
|
|
45
41
|
update: (key: number, children: React.ReactNode) => void
|
|
46
42
|
unmount: (key: number) => void
|
|
47
43
|
}
|
|
48
44
|
|
|
49
45
|
export interface ScrollViewContextValue {
|
|
50
|
-
gestureRef: React.RefObject<any> | null
|
|
46
|
+
gestureRef: React.RefObject<any> | null,
|
|
51
47
|
scrollOffset: Animated.Value
|
|
52
48
|
}
|
|
53
49
|
|
|
@@ -57,7 +53,7 @@ export interface RouteContextValue {
|
|
|
57
53
|
}
|
|
58
54
|
|
|
59
55
|
export interface StickyContextValue {
|
|
60
|
-
registerStickyHeader: Function
|
|
56
|
+
registerStickyHeader: Function,
|
|
61
57
|
unregisterStickyHeader: Function
|
|
62
58
|
}
|
|
63
59
|
|
|
@@ -88,5 +84,3 @@ export const ScrollViewContext = createContext<ScrollViewContextValue>({ gesture
|
|
|
88
84
|
export const PortalContext = createContext<PortalContextValue>(null as any)
|
|
89
85
|
|
|
90
86
|
export const StickyContext = createContext<StickyContextValue>({ registerStickyHeader: noop, unregisterStickyHeader: noop })
|
|
91
|
-
|
|
92
|
-
export const ProviderContext = createContext(null)
|
|
@@ -15,4 +15,3 @@ export const KeyboardAvoidContext = createContext(null);
|
|
|
15
15
|
export const ScrollViewContext = createContext({ gestureRef: null, scrollOffset: new Animated.Value(0) });
|
|
16
16
|
export const PortalContext = createContext(null);
|
|
17
17
|
export const StickyContext = createContext({ registerStickyHeader: noop, unregisterStickyHeader: noop });
|
|
18
|
-
export const ProviderContext = createContext(null);
|
|
@@ -40,16 +40,7 @@ const ModeMap = new Map([
|
|
|
40
40
|
...cropMode.map(mode => [mode, 'stretch'])
|
|
41
41
|
]);
|
|
42
42
|
const isNumber = (value) => typeof value === 'number';
|
|
43
|
-
const relativeCenteredSize = (viewSize, imageSize) =>
|
|
44
|
-
return (viewSize - imageSize) / 2;
|
|
45
|
-
};
|
|
46
|
-
// 获取能完全显示图片的缩放比例:长宽方向的缩放比例最小值即为能完全展示的比例
|
|
47
|
-
function getFitScale(width1, height1, width2, height2) {
|
|
48
|
-
return Math.min(width2 / width1, height2 / height1);
|
|
49
|
-
}
|
|
50
|
-
function getFillScale(width1, height1, width2, height2) {
|
|
51
|
-
return Math.max(width2 / width1, height2 / height1);
|
|
52
|
-
}
|
|
43
|
+
const relativeCenteredSize = (viewSize, imageSize) => (viewSize - imageSize) / 2;
|
|
53
44
|
function noMeetCalcRule(isSvg, mode, viewWidth, viewHeight, ratio) {
|
|
54
45
|
const isMeetSize = viewWidth && viewHeight && ratio;
|
|
55
46
|
if (isSvg && !isMeetSize)
|
|
@@ -58,16 +49,6 @@ function noMeetCalcRule(isSvg, mode, viewWidth, viewHeight, ratio) {
|
|
|
58
49
|
return true;
|
|
59
50
|
return false;
|
|
60
51
|
}
|
|
61
|
-
const getFixedWidth = (viewWidth, viewHeight, ratio) => {
|
|
62
|
-
if (!ratio)
|
|
63
|
-
return viewWidth;
|
|
64
|
-
const fixed = viewHeight / ratio;
|
|
65
|
-
return !fixed ? viewWidth : fixed;
|
|
66
|
-
};
|
|
67
|
-
const getFixedHeight = (viewWidth, viewHeight, ratio) => {
|
|
68
|
-
const fixed = viewWidth * ratio;
|
|
69
|
-
return !fixed ? viewHeight : fixed;
|
|
70
|
-
};
|
|
71
52
|
const Image = forwardRef((props, ref) => {
|
|
72
53
|
const { src = '', mode = 'scaleToFill', style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'enable-fast-image': enableFastImage, 'parent-width': parentWidth, 'parent-height': parentHeight, bindload, binderror } = props;
|
|
73
54
|
const defaultStyle = {
|
|
@@ -75,6 +56,7 @@ const Image = forwardRef((props, ref) => {
|
|
|
75
56
|
height: DEFAULT_IMAGE_HEIGHT
|
|
76
57
|
};
|
|
77
58
|
const styleObj = extendObject({}, defaultStyle, style, { overflow: 'hidden' });
|
|
59
|
+
const state = useRef({});
|
|
78
60
|
const nodeRef = useRef(null);
|
|
79
61
|
useNodesRef(props, ref, nodeRef, {
|
|
80
62
|
defaultStyle
|
|
@@ -88,19 +70,13 @@ const Image = forwardRef((props, ref) => {
|
|
|
88
70
|
const onLayout = ({ nativeEvent: { layout: { width, height } } }) => {
|
|
89
71
|
state.current.viewWidth = width;
|
|
90
72
|
state.current.viewHeight = height;
|
|
91
|
-
// 实际渲染尺寸可能会指定的值不一致,误差低于 0.5 则认为没有变化
|
|
92
|
-
if (Math.abs(viewHeight - height) < 0.5 && Math.abs(viewWidth - width) < 0.5) {
|
|
93
|
-
if (state.current.imageWidth && state.current.imageHeight && state.current.ratio) {
|
|
94
|
-
if (!loaded)
|
|
95
|
-
setLoaded(true);
|
|
96
|
-
}
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
73
|
if (state.current.imageWidth && state.current.imageHeight && state.current.ratio) {
|
|
74
|
+
setViewWidth(width);
|
|
75
|
+
setViewHeight(height);
|
|
100
76
|
setRatio(state.current.ratio);
|
|
101
77
|
setImageWidth(state.current.imageWidth);
|
|
102
78
|
setImageHeight(state.current.imageHeight);
|
|
103
|
-
|
|
79
|
+
state.current = {};
|
|
104
80
|
setLoaded(true);
|
|
105
81
|
}
|
|
106
82
|
};
|
|
@@ -120,56 +96,43 @@ const Image = forwardRef((props, ref) => {
|
|
|
120
96
|
const [imageHeight, setImageHeight] = useState(0);
|
|
121
97
|
const [ratio, setRatio] = useState(0);
|
|
122
98
|
const [loaded, setLoaded] = useState(!isLayoutMode);
|
|
123
|
-
const
|
|
124
|
-
viewWidth
|
|
125
|
-
viewHeight
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
setViewHeight(fixedHeight);
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
case 'heightFix': {
|
|
137
|
-
setViewHeight(viewHeight);
|
|
138
|
-
const fixedWidth = getFixedWidth(viewWidth, viewHeight, ratio);
|
|
139
|
-
setViewWidth(fixedWidth);
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
default:
|
|
143
|
-
setViewHeight(viewHeight);
|
|
144
|
-
setViewWidth(viewWidth);
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
99
|
+
const fixedHeight = useMemo(() => {
|
|
100
|
+
const fixed = viewWidth * ratio;
|
|
101
|
+
return !fixed ? viewHeight : fixed;
|
|
102
|
+
}, [ratio, viewWidth, viewHeight]);
|
|
103
|
+
const fixedWidth = useMemo(() => {
|
|
104
|
+
if (!ratio)
|
|
105
|
+
return viewWidth;
|
|
106
|
+
const fixed = viewHeight / ratio;
|
|
107
|
+
return !fixed ? viewWidth : fixed;
|
|
108
|
+
}, [ratio, viewWidth, viewHeight]);
|
|
148
109
|
const modeStyle = useMemo(() => {
|
|
149
110
|
if (noMeetCalcRule(isSvg, mode, viewWidth, viewHeight, ratio))
|
|
150
111
|
return {};
|
|
151
112
|
switch (mode) {
|
|
152
|
-
case 'scaleToFill':
|
|
113
|
+
case 'scaleToFill':
|
|
153
114
|
case 'aspectFit':
|
|
154
115
|
if (isSvg) {
|
|
155
|
-
const scale =
|
|
116
|
+
const scale = ratio <= 1
|
|
117
|
+
? imageWidth >= viewWidth ? viewWidth / imageWidth : imageWidth / viewWidth
|
|
118
|
+
: imageHeight >= viewHeight ? viewHeight / imageHeight : imageHeight / viewHeight;
|
|
156
119
|
return {
|
|
157
120
|
transform: [
|
|
158
|
-
{
|
|
159
|
-
{ translateX:
|
|
160
|
-
{ scale }
|
|
121
|
+
{ scale },
|
|
122
|
+
ratio <= 1 ? { translateY: -(imageHeight * scale - viewHeight) / 2 / scale } : { translateX: -(imageWidth * scale - viewWidth) / 2 / scale }
|
|
161
123
|
]
|
|
162
124
|
};
|
|
163
125
|
}
|
|
164
126
|
return {};
|
|
165
127
|
case 'aspectFill':
|
|
166
128
|
if (isSvg) {
|
|
167
|
-
const scale =
|
|
129
|
+
const scale = ratio >= 1
|
|
130
|
+
? imageWidth >= viewWidth ? viewWidth / imageWidth : imageWidth / viewWidth
|
|
131
|
+
: imageHeight >= viewHeight ? viewHeight / imageHeight : imageHeight / viewHeight;
|
|
168
132
|
return {
|
|
169
133
|
transform: [
|
|
170
|
-
{
|
|
171
|
-
{ translateX:
|
|
172
|
-
{ scale }
|
|
134
|
+
{ scale },
|
|
135
|
+
ratio >= 1 ? { translateY: -(imageHeight * scale - viewHeight) / 2 / scale } : { translateX: -(imageWidth * scale - viewWidth) / 2 / scale }
|
|
173
136
|
]
|
|
174
137
|
};
|
|
175
138
|
}
|
|
@@ -177,7 +140,9 @@ const Image = forwardRef((props, ref) => {
|
|
|
177
140
|
case 'widthFix':
|
|
178
141
|
case 'heightFix':
|
|
179
142
|
if (isSvg) {
|
|
180
|
-
const scale =
|
|
143
|
+
const scale = ratio >= 1
|
|
144
|
+
? imageWidth >= fixedWidth ? fixedWidth / imageWidth : imageWidth / fixedWidth
|
|
145
|
+
: imageHeight >= fixedHeight ? fixedHeight / imageHeight : imageHeight / fixedHeight;
|
|
181
146
|
return {
|
|
182
147
|
transform: [{ scale }]
|
|
183
148
|
};
|
|
@@ -240,23 +205,12 @@ const Image = forwardRef((props, ref) => {
|
|
|
240
205
|
default:
|
|
241
206
|
return {};
|
|
242
207
|
}
|
|
243
|
-
}, [isSvg, mode, viewWidth, viewHeight, imageWidth, imageHeight, ratio]);
|
|
208
|
+
}, [isSvg, mode, viewWidth, viewHeight, imageWidth, imageHeight, ratio, fixedWidth, fixedHeight]);
|
|
244
209
|
const onSvgLoad = (evt) => {
|
|
245
210
|
const { width, height } = evt.nativeEvent.layout;
|
|
246
|
-
|
|
211
|
+
setRatio(!width ? 0 : height / width);
|
|
212
|
+
setImageWidth(width);
|
|
247
213
|
setImageHeight(height);
|
|
248
|
-
state.current.ratio = !width ? 0 : height / width;
|
|
249
|
-
if (isWidthFixMode
|
|
250
|
-
? state.current.viewWidth
|
|
251
|
-
: isHeightFixMode
|
|
252
|
-
? state.current.viewHeight
|
|
253
|
-
: state.current.viewWidth && state.current.viewHeight) {
|
|
254
|
-
setRatio(state.current.ratio);
|
|
255
|
-
setImageWidth(width);
|
|
256
|
-
setImageHeight(height);
|
|
257
|
-
setViewSize(state.current.viewWidth, state.current.viewHeight, state.current.ratio);
|
|
258
|
-
setLoaded(true);
|
|
259
|
-
}
|
|
260
214
|
bindload && bindload(getCustomEvent('load', evt, {
|
|
261
215
|
detail: { width, height },
|
|
262
216
|
layoutRef
|
|
@@ -294,10 +248,12 @@ const Image = forwardRef((props, ref) => {
|
|
|
294
248
|
: isHeightFixMode
|
|
295
249
|
? state.current.viewHeight
|
|
296
250
|
: state.current.viewWidth && state.current.viewHeight) {
|
|
297
|
-
|
|
251
|
+
state.current.viewWidth && setViewWidth(state.current.viewWidth);
|
|
252
|
+
state.current.viewHeight && setViewHeight(state.current.viewHeight);
|
|
253
|
+
setRatio(!width ? 0 : height / width);
|
|
298
254
|
setImageWidth(width);
|
|
299
255
|
setImageHeight(height);
|
|
300
|
-
|
|
256
|
+
state.current = {};
|
|
301
257
|
setLoaded(true);
|
|
302
258
|
}
|
|
303
259
|
}, () => {
|
|
@@ -307,7 +263,7 @@ const Image = forwardRef((props, ref) => {
|
|
|
307
263
|
}, [src, isSvg, isLayoutMode]);
|
|
308
264
|
const innerProps = useInnerProps(extendObject({}, props, layoutProps, {
|
|
309
265
|
ref: nodeRef,
|
|
310
|
-
style: extendObject({}, normalStyle, layoutStyle, isHeightFixMode ? { width:
|
|
266
|
+
style: extendObject({}, normalStyle, layoutStyle, isHeightFixMode ? { width: fixedWidth } : {}, isWidthFixMode ? { height: fixedHeight } : {})
|
|
311
267
|
}), [
|
|
312
268
|
'src',
|
|
313
269
|
'mode',
|
|
@@ -315,25 +271,31 @@ const Image = forwardRef((props, ref) => {
|
|
|
315
271
|
], {
|
|
316
272
|
layoutRef
|
|
317
273
|
});
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
274
|
+
function renderSvgImage() {
|
|
275
|
+
return createElement(View, innerProps, createElement(SvgCssUri, {
|
|
276
|
+
uri: src,
|
|
277
|
+
onLayout: onSvgLoad,
|
|
278
|
+
onError: binderror && onSvgError,
|
|
279
|
+
style: extendObject({ transformOrigin: 'left top' }, modeStyle)
|
|
280
|
+
}));
|
|
281
|
+
}
|
|
282
|
+
function renderBaseImage() {
|
|
283
|
+
return renderImage(extendObject({
|
|
284
|
+
source: { uri: src },
|
|
285
|
+
resizeMode: resizeMode,
|
|
286
|
+
onLoad: bindload && onImageLoad,
|
|
287
|
+
onError: binderror && onImageError,
|
|
288
|
+
style: extendObject({
|
|
289
|
+
transformOrigin: 'left top',
|
|
290
|
+
width: isCropMode ? imageWidth : '100%',
|
|
291
|
+
height: isCropMode ? imageHeight : '100%'
|
|
292
|
+
}, isCropMode ? modeStyle : {})
|
|
293
|
+
}, isLayoutMode ? {} : innerProps), enableFastImage);
|
|
294
|
+
}
|
|
295
|
+
function renderLayoutImage() {
|
|
296
|
+
return createElement(View, innerProps, loaded && renderBaseImage());
|
|
297
|
+
}
|
|
298
|
+
const finalComponent = isSvg ? renderSvgImage() : isLayoutMode ? renderLayoutImage() : renderBaseImage();
|
|
337
299
|
if (hasPositionFixed) {
|
|
338
300
|
return createElement(Portal, null, finalComponent);
|
|
339
301
|
}
|