@mpxjs/webpack-plugin 2.10.17 → 2.10.18-beta.2
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 +231 -0
- package/lib/index.js +70 -73
- package/lib/init.js +3 -0
- package/lib/json-compiler/index.js +13 -4
- package/lib/loader.js +4 -0
- package/lib/platform/json/wx/index.js +6 -0
- package/lib/platform/style/wx/index.js +102 -72
- package/lib/platform/template/wx/component-config/ad.js +5 -0
- package/lib/platform/template/wx/component-config/button.js +10 -3
- 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/script-helper.js +2 -2
- package/lib/react/style-helper.js +76 -13
- package/lib/resolver/AddModePlugin.js +17 -7
- package/lib/resolver/ExtendComponentsPlugin.js +60 -0
- package/lib/runtime/components/ali/mpx-section-list.mpx +566 -0
- package/lib/runtime/components/ali/mpx-sticky-header.mpx +212 -0
- package/lib/runtime/components/ali/mpx-sticky-section.mpx +17 -0
- package/lib/runtime/components/react/animationHooks/index.ts +75 -0
- package/lib/runtime/components/react/animationHooks/useAnimationAPIHooks.ts +197 -0
- package/lib/runtime/components/react/animationHooks/useTransitionHooks.ts +301 -0
- package/lib/runtime/components/react/animationHooks/utils.ts +197 -0
- package/lib/runtime/components/react/context.ts +12 -3
- package/lib/runtime/components/react/dist/animationHooks/index.d.ts +15 -0
- package/lib/runtime/components/react/dist/animationHooks/index.js +67 -0
- package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts +3 -0
- package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.js +181 -0
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts +3 -0
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.js +279 -0
- package/lib/runtime/components/react/dist/animationHooks/utils.d.ts +109 -0
- package/lib/runtime/components/react/dist/animationHooks/utils.js +151 -0
- package/lib/runtime/components/react/dist/context.d.ts +10 -3
- package/lib/runtime/components/react/dist/context.js +1 -2
- package/lib/runtime/components/react/dist/event.config.d.ts +0 -1
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +3 -1
- package/lib/runtime/components/react/dist/mpx-button.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-camera.d.ts +31 -0
- package/lib/runtime/components/react/dist/mpx-camera.jsx +236 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-form.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-image.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-input.d.ts +2 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +66 -50
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +35 -6
- package/lib/runtime/components/react/dist/mpx-label.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-nav.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-progress.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-radio.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +84 -78
- package/lib/runtime/components/react/dist/mpx-section-list.d.ts +48 -0
- package/lib/runtime/components/react/dist/mpx-section-list.jsx +292 -0
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-slider.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +20 -20
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts +11 -1
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +136 -83
- package/lib/runtime/components/react/dist/mpx-switch.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-text.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -0
- package/lib/runtime/components/react/dist/mpx-video.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-view.d.ts +3 -3
- package/lib/runtime/components/react/dist/mpx-view.jsx +22 -8
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
- package/lib/runtime/components/react/dist/parser.d.ts +0 -1
- package/lib/runtime/components/react/dist/useNodesRef.d.ts +0 -1
- package/lib/runtime/components/react/dist/utils.d.ts +10 -9
- package/lib/runtime/components/react/dist/utils.jsx +47 -24
- package/lib/runtime/components/react/mpx-async-suspense.tsx +3 -1
- package/lib/runtime/components/react/mpx-camera.tsx +327 -0
- package/lib/runtime/components/react/mpx-image.tsx +2 -2
- package/lib/runtime/components/react/mpx-input.tsx +77 -54
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +35 -6
- package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +2 -2
- package/lib/runtime/components/react/mpx-scroll-view.tsx +110 -114
- package/lib/runtime/components/react/mpx-section-list.tsx +439 -0
- package/lib/runtime/components/react/mpx-sticky-header.tsx +24 -24
- package/lib/runtime/components/react/mpx-swiper.tsx +156 -81
- package/lib/runtime/components/react/mpx-textarea.tsx +1 -0
- package/lib/runtime/components/react/mpx-view.tsx +27 -12
- package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
- package/lib/runtime/components/react/tsconfig.json +26 -0
- package/lib/runtime/components/react/types/global.d.ts +1 -0
- package/lib/runtime/components/react/utils.tsx +51 -27
- package/lib/runtime/components/web/mpx-scroll-view.vue +5 -2
- package/lib/runtime/components/web/mpx-section-list.vue +551 -0
- package/lib/runtime/components/wx/mpx-section-list-default/list-footer.mpx +26 -0
- package/lib/runtime/components/wx/mpx-section-list-default/list-header.mpx +26 -0
- package/lib/runtime/components/wx/mpx-section-list-default/list-item.mpx +26 -0
- package/lib/runtime/components/wx/mpx-section-list-default/section-header.mpx +26 -0
- package/lib/runtime/components/wx/mpx-section-list.mpx +209 -0
- package/lib/runtime/components/wx/mpx-sticky-header.mpx +40 -0
- package/lib/runtime/components/wx/mpx-sticky-section.mpx +31 -0
- package/lib/runtime/optionProcessor.js +5 -0
- package/lib/runtime/optionProcessorReact.js +7 -0
- package/lib/runtime/stringify.wxs +2 -2
- package/lib/script-setup-compiler/index.js +1 -2
- package/lib/style-compiler/strip-conditional.js +244 -0
- package/lib/template-compiler/compiler.js +9 -8
- package/lib/utils/const.js +29 -0
- package/lib/utils/dom-tag-config.js +1 -1
- package/lib/utils/string.js +25 -1
- package/lib/wxss/loader.js +4 -1
- package/lib/wxss/utils.js +7 -2
- package/package.json +7 -14
- package/LICENSE +0 -433
- package/lib/runtime/components/react/dist/context.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/event.config.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-button.d.ts.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-form.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-image.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +0 -1
- 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.map +0 -1
- package/lib/runtime/components/react/dist/mpx-label.d.ts.map +0 -1
- 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.map +0 -1
- package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +0 -1
- 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.map +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-text.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-video.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +0 -1
- 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/useAnimationHooks.js +0 -289
- package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/utils.d.ts.map +0 -1
- package/lib/runtime/components/react/useAnimationHooks.ts +0 -320
- package/lib/style-compiler/strip-conditional-loader.js +0 -289
|
@@ -3,31 +3,70 @@ const selectorParser = require('postcss-selector-parser')
|
|
|
3
3
|
const { MPX_TAG_PAGE_SELECTOR } = require('../utils/const')
|
|
4
4
|
const getRulesRunner = require('../platform/index')
|
|
5
5
|
const dash2hump = require('../utils/hump-dash').dash2hump
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const parseValues = require('../utils/string').parseValues
|
|
7
|
+
const unitRegExp = /^\s*(-?\d+(?:\.\d+)?)(rpx|vw|vh|px)?\s*$/
|
|
8
8
|
const hairlineRegExp = /^\s*hairlineWidth\s*$/
|
|
9
9
|
const varRegExp = /^--/
|
|
10
10
|
const cssPrefixExp = /^-(webkit|moz|ms|o)-/
|
|
11
|
-
function getClassMap ({ content, filename, mode, srcMode, ctorType, warn, error }) {
|
|
12
|
-
const classMap = ctorType === 'page'
|
|
11
|
+
function getClassMap ({ content, filename, mode, srcMode, ctorType, formatValueName, warn, error }) {
|
|
12
|
+
const classMap = ctorType === 'page'
|
|
13
|
+
? { [MPX_TAG_PAGE_SELECTOR]: { flex: 1, height: "'100%'" } }
|
|
14
|
+
: {}
|
|
13
15
|
|
|
14
16
|
const root = postcss.parse(content, {
|
|
15
17
|
from: filename
|
|
16
18
|
})
|
|
17
19
|
|
|
18
20
|
function formatValue (value) {
|
|
19
|
-
let matched
|
|
20
21
|
let needStringify = true
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const matched = unitRegExp.exec(value)
|
|
23
|
+
if (matched) {
|
|
24
|
+
if (!matched[2] || matched[2] === 'px') {
|
|
25
|
+
value = matched[1]
|
|
26
|
+
needStringify = false
|
|
27
|
+
} else {
|
|
28
|
+
value = `${formatValueName}(${+matched[1]}, '${matched[2]}')`
|
|
29
|
+
needStringify = false
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (hairlineRegExp.test(value)) {
|
|
33
|
+
value = `${formatValueName}(${JSON.stringify(value)}, 'hairlineWidth')`
|
|
26
34
|
needStringify = false
|
|
27
35
|
}
|
|
28
36
|
return needStringify ? JSON.stringify(value) : value
|
|
29
37
|
}
|
|
30
38
|
|
|
39
|
+
function getMediaOptions (params) {
|
|
40
|
+
return parseValues(params).reduce((option, item) => {
|
|
41
|
+
if (['all', 'print'].includes(item)) {
|
|
42
|
+
if (item === 'media') {
|
|
43
|
+
option.type = item
|
|
44
|
+
} else {
|
|
45
|
+
error('not supported ', item)
|
|
46
|
+
return option
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (['not', 'only', 'or', ','].includes(item)) {
|
|
50
|
+
if (item === 'and') {
|
|
51
|
+
option.logical_operators = item
|
|
52
|
+
} else {
|
|
53
|
+
error('not supported ', item)
|
|
54
|
+
return option
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const bracketsExp = /\((.+?)\)/
|
|
58
|
+
if (bracketsExp.test(item)) {
|
|
59
|
+
const range = parseValues((item.match(bracketsExp)?.[1] || ''), ':')
|
|
60
|
+
if (range.length < 2) {
|
|
61
|
+
return option
|
|
62
|
+
} else {
|
|
63
|
+
option[dash2hump(range[0])] = +formatValue(range[1])
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return option
|
|
67
|
+
}, {})
|
|
68
|
+
}
|
|
69
|
+
|
|
31
70
|
const rulesRunner = getRulesRunner({
|
|
32
71
|
mode,
|
|
33
72
|
srcMode,
|
|
@@ -41,13 +80,15 @@ function getClassMap ({ content, filename, mode, srcMode, ctorType, warn, error
|
|
|
41
80
|
root.walkAtRules(rule => {
|
|
42
81
|
if (rule.name !== 'media') {
|
|
43
82
|
warn(`Only @media rule is supported in react native mode temporarily, but got @${rule.name}`)
|
|
83
|
+
// 删除不支持的 AtRule,防止其影响后续解析
|
|
84
|
+
rule.remove()
|
|
44
85
|
}
|
|
45
86
|
})
|
|
46
87
|
|
|
47
88
|
root.walkRules(rule => {
|
|
48
89
|
const classMapValue = {}
|
|
49
90
|
rule.walkDecls(({ prop, value }) => {
|
|
50
|
-
if (cssPrefixExp.test(prop) || cssPrefixExp.test(value)) return
|
|
91
|
+
if (value === 'undefined' || cssPrefixExp.test(prop) || cssPrefixExp.test(value)) return
|
|
51
92
|
let newData = rulesRunner({ prop, value, selector: rule.selector })
|
|
52
93
|
if (!newData) return
|
|
53
94
|
if (!Array.isArray(newData)) {
|
|
@@ -79,7 +120,8 @@ function getClassMap ({ content, filename, mode, srcMode, ctorType, warn, error
|
|
|
79
120
|
})
|
|
80
121
|
|
|
81
122
|
const classMapKeys = []
|
|
82
|
-
|
|
123
|
+
const options = getMediaOptions(rule.parent.params || '')
|
|
124
|
+
const isMedia = options.maxWidth || options.minWidth
|
|
83
125
|
selectorParser(selectors => {
|
|
84
126
|
selectors.each(selector => {
|
|
85
127
|
if (selector.nodes.length === 1 && selector.nodes[0].type === 'class') {
|
|
@@ -93,7 +135,28 @@ function getClassMap ({ content, filename, mode, srcMode, ctorType, warn, error
|
|
|
93
135
|
if (classMapKeys.length) {
|
|
94
136
|
classMapKeys.forEach((key) => {
|
|
95
137
|
if (Object.keys(classMapValue).length) {
|
|
96
|
-
|
|
138
|
+
let _default = classMap[key]?._default
|
|
139
|
+
let _media = classMap[key]?._media
|
|
140
|
+
if (isMedia) {
|
|
141
|
+
// 当前是媒体查询
|
|
142
|
+
_default = _default || {}
|
|
143
|
+
_media = _media || []
|
|
144
|
+
_media.push({
|
|
145
|
+
options,
|
|
146
|
+
value: classMapValue
|
|
147
|
+
})
|
|
148
|
+
classMap[key] = {
|
|
149
|
+
_media,
|
|
150
|
+
_default
|
|
151
|
+
}
|
|
152
|
+
} else if (_default) {
|
|
153
|
+
// 已有媒体查询数据,此次非媒体查询
|
|
154
|
+
Object.assign(_default, classMapValue)
|
|
155
|
+
} else {
|
|
156
|
+
// 无媒体查询
|
|
157
|
+
const val = classMap[key] || {}
|
|
158
|
+
classMap[key] = Object.assign(val, classMapValue)
|
|
159
|
+
}
|
|
97
160
|
}
|
|
98
161
|
})
|
|
99
162
|
}
|
|
@@ -39,21 +39,31 @@ module.exports = class AddModePlugin {
|
|
|
39
39
|
|
|
40
40
|
const queryObj = parseQuery(request.query || '?')
|
|
41
41
|
const queryInfix = queryObj.infix
|
|
42
|
-
if (!implicitMode) queryObj.mode = mode
|
|
43
|
-
queryObj.infix = `${queryInfix || ''}.${mode}`
|
|
44
42
|
|
|
45
43
|
// 如果已经确认是mode后缀的文件,添加query与mode后直接返回
|
|
46
44
|
if (modePattern.test(path.basename(resourcePath))) {
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
// 已经被resolved到对应mode的文件,避免重复添加mode
|
|
46
|
+
const isResolved = (implicitMode || queryObj.mode === mode) && modePattern.test(queryObj.infix)
|
|
47
|
+
if (!isResolved) {
|
|
48
|
+
queryObj.infix = `${queryInfix || ''}.${mode}`
|
|
49
|
+
if (!implicitMode) queryObj.mode = mode
|
|
50
|
+
request.query = stringifyQuery(queryObj)
|
|
51
|
+
request.mode = obj.mode
|
|
52
|
+
}
|
|
49
53
|
return callback()
|
|
50
54
|
} else if (defaultMode && defaultModePattern.test(path.basename(resourcePath))) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
const isResolved = (implicitMode || queryObj.mode === mode) && defaultModePattern.test(queryObj.infix)
|
|
56
|
+
if (!isResolved) {
|
|
57
|
+
queryObj.infix = `${queryInfix || ''}.${defaultMode}`
|
|
58
|
+
if (!implicitMode) queryObj.mode = mode
|
|
59
|
+
request.query = stringifyQuery(queryObj)
|
|
60
|
+
request.mode = obj.mode
|
|
61
|
+
}
|
|
54
62
|
return callback()
|
|
55
63
|
}
|
|
56
64
|
|
|
65
|
+
if (!implicitMode) queryObj.mode = mode
|
|
66
|
+
queryObj.infix = `${queryInfix || ''}.${mode}`
|
|
57
67
|
obj.query = stringifyQuery(queryObj)
|
|
58
68
|
obj.path = addInfix(resourcePath, mode, extname)
|
|
59
69
|
obj.relativePath = request.relativePath && addInfix(request.relativePath, mode, extname)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const { EXTEND_COMPONENT_CONFIG } = require('../utils/const')
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 扩展组件路径解析插件
|
|
5
|
+
* 将 @mpxjs/webpack-plugin/lib/runtime/components/extends/[component-name] 格式的路径
|
|
6
|
+
* 解析为对应平台的实际组件路径
|
|
7
|
+
*/
|
|
8
|
+
module.exports = class ExtendComponentsPlugin {
|
|
9
|
+
constructor (source, mode, target) {
|
|
10
|
+
this.source = source
|
|
11
|
+
this.target = target
|
|
12
|
+
this.mode = mode
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
apply (resolver) {
|
|
16
|
+
const target = resolver.ensureHook(this.target)
|
|
17
|
+
const mode = this.mode
|
|
18
|
+
|
|
19
|
+
resolver.getHook(this.source).tapAsync('ExtendComponentsPlugin', (request, resolveContext, callback) => {
|
|
20
|
+
const requestPath = request.request
|
|
21
|
+
if (!requestPath || !requestPath.startsWith('@mpxjs/webpack-plugin/lib/runtime/components/extends/')) {
|
|
22
|
+
return callback()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 匹配 @mpxjs/webpack-plugin/lib/runtime/components/extends/[component-name]
|
|
26
|
+
const extendsMatch = requestPath.match(/^@mpxjs\/webpack-plugin\/lib\/runtime\/components\/extends\/(.+)$/)
|
|
27
|
+
|
|
28
|
+
if (!extendsMatch) {
|
|
29
|
+
return callback()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const componentName = extendsMatch[1]
|
|
33
|
+
|
|
34
|
+
// 检查组件是否在配置中
|
|
35
|
+
if (!EXTEND_COMPONENT_CONFIG[componentName]) {
|
|
36
|
+
return callback(new Error(`Extended component "${componentName}" was not found. Available extended components: ${Object.keys(EXTEND_COMPONENT_CONFIG).join(', ')}`))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 获取当前模式下的组件路径
|
|
40
|
+
const componentConfig = EXTEND_COMPONENT_CONFIG[componentName]
|
|
41
|
+
const newRequest = componentConfig[mode]
|
|
42
|
+
|
|
43
|
+
if (!newRequest) {
|
|
44
|
+
return callback(new Error(`Extended component "${componentName}" cannot be used on the ${mode} platform. Supported platforms include: ${Object.keys(componentConfig).join(', ')}`))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const obj = Object.assign({}, request, {
|
|
48
|
+
request: newRequest
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
resolver.doResolve(
|
|
52
|
+
target,
|
|
53
|
+
obj,
|
|
54
|
+
`resolve extend component: ${componentName} to ${newRequest}`,
|
|
55
|
+
resolveContext,
|
|
56
|
+
callback
|
|
57
|
+
)
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
}
|