@mpxjs/webpack-plugin 2.10.17-beta.2 → 2.10.17-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/config.js +60 -0
- package/lib/file-loader.js +4 -1
- package/lib/global.d.ts +16 -0
- package/lib/index.js +22 -2
- package/lib/json-compiler/index.js +13 -4
- package/lib/platform/json/wx/index.js +6 -0
- package/lib/platform/style/wx/index.js +57 -33
- package/lib/platform/template/wx/component-config/ad.js +5 -0
- package/lib/platform/template/wx/component-config/button.js +9 -2
- package/lib/platform/template/wx/component-config/camera.js +25 -3
- package/lib/platform/template/wx/component-config/canvas.js +8 -1
- package/lib/platform/template/wx/component-config/cover-image.js +7 -2
- package/lib/platform/template/wx/component-config/cover-view.js +3 -1
- package/lib/platform/template/wx/component-config/form.js +27 -2
- package/lib/platform/template/wx/component-config/image.js +5 -0
- package/lib/platform/template/wx/component-config/input.js +10 -0
- package/lib/platform/template/wx/component-config/label.js +10 -2
- package/lib/platform/template/wx/component-config/map.js +11 -0
- package/lib/platform/template/wx/component-config/movable-area.js +4 -1
- package/lib/platform/template/wx/component-config/movable-view.js +17 -2
- package/lib/platform/template/wx/component-config/navigator.js +26 -0
- package/lib/platform/template/wx/component-config/picker-view.js +12 -0
- package/lib/platform/template/wx/component-config/picker.js +3 -1
- package/lib/platform/template/wx/component-config/progress.js +11 -1
- package/lib/platform/template/wx/component-config/rich-text.js +5 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +12 -1
- package/lib/platform/template/wx/component-config/slider.js +8 -0
- package/lib/platform/template/wx/component-config/swiper-item.js +5 -2
- package/lib/platform/template/wx/component-config/swiper.js +10 -0
- package/lib/platform/template/wx/component-config/text.js +5 -0
- package/lib/platform/template/wx/component-config/textarea.js +19 -2
- package/lib/platform/template/wx/component-config/unsupported.js +10 -1
- package/lib/platform/template/wx/component-config/video.js +10 -0
- package/lib/platform/template/wx/index.js +21 -1
- package/lib/react/LoadAsyncChunkModule.js +1 -1
- package/lib/react/processStyles.js +21 -9
- package/lib/react/style-helper.js +76 -13
- package/lib/resolver/AddModePlugin.js +23 -8
- package/lib/runtime/components/react/animationHooks/index.ts +75 -0
- package/lib/runtime/components/react/animationHooks/useAnimationAPIHooks.ts +198 -0
- package/lib/runtime/components/react/animationHooks/useTransitionHooks.ts +297 -0
- package/lib/runtime/components/react/animationHooks/utils.ts +196 -0
- package/lib/runtime/components/react/context.ts +7 -1
- package/lib/runtime/components/react/dist/animationHooks/index.d.ts +16 -0
- package/lib/runtime/components/react/dist/animationHooks/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/animationHooks/index.js +67 -0
- package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts +4 -0
- package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.js +182 -0
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts +4 -0
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.js +274 -0
- package/lib/runtime/components/react/dist/animationHooks/utils.d.ts +110 -0
- package/lib/runtime/components/react/dist/animationHooks/utils.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/animationHooks/utils.js +150 -0
- package/lib/runtime/components/react/dist/context.d.ts +6 -1
- package/lib/runtime/components/react/dist/context.d.ts.map +1 -1
- package/lib/runtime/components/react/dist/mpx-camera.d.ts +32 -0
- package/lib/runtime/components/react/dist/mpx-camera.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-camera.jsx +236 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts +2 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts.map +1 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +21 -10
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +1 -1
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +3 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts +10 -0
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +1 -1
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +28 -16
- package/lib/runtime/components/react/dist/mpx-view.d.ts +3 -2
- package/lib/runtime/components/react/dist/mpx-view.d.ts.map +1 -1
- package/lib/runtime/components/react/dist/mpx-view.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
- package/lib/runtime/components/react/dist/utils.d.ts +1 -0
- package/lib/runtime/components/react/dist/utils.d.ts.map +1 -1
- package/lib/runtime/components/react/dist/utils.jsx +34 -13
- package/lib/runtime/components/react/mpx-camera.tsx +327 -0
- package/lib/runtime/components/react/mpx-input.tsx +26 -10
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +3 -0
- package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +2 -2
- package/lib/runtime/components/react/mpx-swiper.tsx +43 -15
- package/lib/runtime/components/react/mpx-view.tsx +4 -5
- package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
- package/lib/runtime/components/react/types/global.d.ts +1 -0
- package/lib/runtime/components/react/utils.tsx +34 -16
- package/lib/runtime/optionProcessor.js +5 -0
- package/lib/runtime/optionProcessorReact.js +7 -0
- package/lib/runtime/stringify.wxs +2 -2
- package/lib/style-compiler/strip-conditional-loader/rebaseUrl.js +225 -0
- package/lib/style-compiler/strip-conditional-loader.js +55 -180
- package/lib/template-compiler/compiler.js +1 -3
- package/lib/utils/dom-tag-config.js +1 -1
- package/lib/utils/string.js +25 -1
- package/package.json +2 -1
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +0 -33
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/useAnimationHooks.js +0 -289
- package/lib/runtime/components/react/useAnimationHooks.ts +0 -320
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
const path = require('node:path')
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {(id: string, importer?: string, aliasOnly?: boolean) => Promise<string | undefined>} ResolveIdFn
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {(unquotedUrl: string, rawUrl: string) => Promise<string | false> | string | false} CssUrlReplacer
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// https://drafts.csswg.org/css-syntax-3/#identifier-code-point
|
|
10
|
+
const cssUrlRE = /(?<!@import\s+)(?<=^|[^\w\-\u0080-\uffff])url\((\s*('[^']+'|"[^"]+")\s*|(?:\\.|[^'")\\])+)\)/
|
|
11
|
+
const cssDataUriRE = /(?<=^|[^\w\-\u0080-\uffff])data-uri\((\s*('[^']+'|"[^"]+")\s*|[^'")]+)\)/
|
|
12
|
+
const importCssRE = /@import\s+(?:url\()?('[^']+\.css'|"[^"]+\.css"|[^'"\s)]+\.css)/
|
|
13
|
+
const nonEscapedDoubleQuoteRe = /(?<!\\)"/g
|
|
14
|
+
const externalRE = /^([a-z]+:)?\/\//
|
|
15
|
+
const isExternalUrl = url => externalRE.test(url)
|
|
16
|
+
|
|
17
|
+
const dataUrlRE = /^\s*data:/i
|
|
18
|
+
const isDataUrl = url => dataUrlRE.test(url)
|
|
19
|
+
const functionCallRE = /^[A-Z_][.\w-]*\(/i
|
|
20
|
+
|
|
21
|
+
function skipUrlReplacer(unquotedUrl) {
|
|
22
|
+
return isExternalUrl(unquotedUrl) || isDataUrl(unquotedUrl) || unquotedUrl[0] === '#' || unquotedUrl[0] === '@' || functionCallRE.test(unquotedUrl)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @param {string} rawUrl
|
|
28
|
+
* @param {string} matched
|
|
29
|
+
* @param {CssUrlReplacer} replacer
|
|
30
|
+
* @param {string} funcName
|
|
31
|
+
* @returns {Promise<string>}
|
|
32
|
+
*/
|
|
33
|
+
async function doUrlReplace(rawUrl, matched, replacer, funcName = 'url') {
|
|
34
|
+
let wrap = ''
|
|
35
|
+
const first = rawUrl[0]
|
|
36
|
+
let unquotedUrl = rawUrl
|
|
37
|
+
if (first === '"' || first === "'") {
|
|
38
|
+
wrap = first
|
|
39
|
+
unquotedUrl = rawUrl.slice(1, -1)
|
|
40
|
+
}
|
|
41
|
+
if (skipUrlReplacer(unquotedUrl)) {
|
|
42
|
+
return matched
|
|
43
|
+
}
|
|
44
|
+
// Remove escape sequences to get the actual file name before resolving.
|
|
45
|
+
unquotedUrl = unquotedUrl.replace(/\\(\W)/g, '$1')
|
|
46
|
+
|
|
47
|
+
let newUrl = await replacer(unquotedUrl, rawUrl)
|
|
48
|
+
if (newUrl === false) {
|
|
49
|
+
return matched
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// The new url might need wrapping even if the original did not have it, e.g.
|
|
53
|
+
// if a space was added during replacement or the URL contains ")"
|
|
54
|
+
if (wrap === '' && (newUrl !== encodeURI(newUrl) || newUrl.includes(')'))) {
|
|
55
|
+
wrap = '"'
|
|
56
|
+
}
|
|
57
|
+
// If wrapping in single quotes and newUrl also contains single quotes, switch to double quotes.
|
|
58
|
+
// Give preference to double quotes since SVG inlining converts double quotes to single quotes.
|
|
59
|
+
if (wrap === "'" && newUrl.includes("'")) {
|
|
60
|
+
wrap = '"'
|
|
61
|
+
}
|
|
62
|
+
// Escape double quotes if they exist (they also tend to be rarer than single quotes)
|
|
63
|
+
if (wrap === '"' && newUrl.includes('"')) {
|
|
64
|
+
newUrl = newUrl.replace(nonEscapedDoubleQuoteRe, '\\"')
|
|
65
|
+
}
|
|
66
|
+
return `${funcName}(${wrap}${newUrl}${wrap})`
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
* @param {string} rawUrl
|
|
72
|
+
* @param {string} matched
|
|
73
|
+
* @param {CssUrlReplacer} replacer
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
76
|
+
async function doImportCSSReplace(rawUrl, matched, replacer) {
|
|
77
|
+
let wrap = ''
|
|
78
|
+
const first = rawUrl[0]
|
|
79
|
+
let unquotedUrl = rawUrl
|
|
80
|
+
if (first === '"' || first === "'") {
|
|
81
|
+
wrap = first
|
|
82
|
+
unquotedUrl = rawUrl.slice(1, -1)
|
|
83
|
+
}
|
|
84
|
+
if (skipUrlReplacer(unquotedUrl)) {
|
|
85
|
+
return matched
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const newUrl = await replacer(unquotedUrl, rawUrl)
|
|
89
|
+
if (newUrl === false) {
|
|
90
|
+
return matched
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const prefix = matched.includes('url(') ? 'url(' : ''
|
|
94
|
+
return `@import ${prefix}${wrap}${newUrl}${wrap}`
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* @param {string} input
|
|
100
|
+
* @param {RegExp} re
|
|
101
|
+
* @param {(match: RegExpMatchArray) => string | Promise<string>} replacer
|
|
102
|
+
* @returns {Promise<string>}
|
|
103
|
+
*/
|
|
104
|
+
async function asyncReplace(input, re, replacer) {
|
|
105
|
+
let match = null
|
|
106
|
+
let remaining = input
|
|
107
|
+
let rewritten = ''
|
|
108
|
+
while ((match = re.exec(remaining))) {
|
|
109
|
+
rewritten += remaining.slice(0, match.index)
|
|
110
|
+
rewritten += await replacer(match)
|
|
111
|
+
remaining = remaining.slice(match.index + match[0].length)
|
|
112
|
+
}
|
|
113
|
+
rewritten += remaining
|
|
114
|
+
return rewritten
|
|
115
|
+
}
|
|
116
|
+
module.exports.asyncReplace = asyncReplace
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
*
|
|
120
|
+
* @param {string} css
|
|
121
|
+
* @param {CssUrlReplacer} replacer
|
|
122
|
+
* @returns
|
|
123
|
+
*/
|
|
124
|
+
function rewriteCssUrls(css, replacer) {
|
|
125
|
+
return asyncReplace(css, cssUrlRE, async match => {
|
|
126
|
+
const [matched, rawUrl] = match
|
|
127
|
+
return await doUrlReplace(rawUrl.trim(), matched, replacer)
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
*
|
|
133
|
+
* @param {string} css
|
|
134
|
+
* @param {CssUrlReplacer} replacer
|
|
135
|
+
* @returns
|
|
136
|
+
*/
|
|
137
|
+
function rewriteCssDataUris(css, replacer) {
|
|
138
|
+
return asyncReplace(css, cssDataUriRE, async match => {
|
|
139
|
+
const [matched, rawUrl] = match
|
|
140
|
+
return await doUrlReplace(rawUrl.trim(), matched, replacer, 'data-uri')
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
*
|
|
145
|
+
* @param {string} css
|
|
146
|
+
* @param {CssUrlReplacer} replacer
|
|
147
|
+
* @returns
|
|
148
|
+
*/
|
|
149
|
+
function rewriteImportCss(css, replacer) {
|
|
150
|
+
return asyncReplace(css, importCssRE, async match => {
|
|
151
|
+
const [matched, rawUrl] = match
|
|
152
|
+
return await doImportCSSReplace(rawUrl, matched, replacer)
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const windowsSlashRE = /\\/g
|
|
157
|
+
function slash(p) {
|
|
158
|
+
return p.replace(windowsSlashRE, '/')
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const isWindows = typeof process !== 'undefined' && process.platform === 'win32'
|
|
162
|
+
/**
|
|
163
|
+
*
|
|
164
|
+
* @param {string} id
|
|
165
|
+
* @returns {string}
|
|
166
|
+
*/
|
|
167
|
+
function normalizePath(id) {
|
|
168
|
+
return path.posix.normalize(isWindows ? slash(id) : id)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
*
|
|
173
|
+
* @param {string} file
|
|
174
|
+
* @param {string} rootFile
|
|
175
|
+
* @param {string} content
|
|
176
|
+
* @param {ResolveIdFn} resolver
|
|
177
|
+
* @param {(unquotedUrl: string, rawUrl: string) => boolean} [ignoreUrl]
|
|
178
|
+
* @returns {Promise<{ file: string, contents?: string }>}
|
|
179
|
+
*/
|
|
180
|
+
async function rebaseUrls(file, rootFile, content, resolver, ignoreUrl) {
|
|
181
|
+
// file = path.resolve(file) // ensure os-specific flashes
|
|
182
|
+
// in the same dir, no need to rebase
|
|
183
|
+
const fileDir = path.dirname(file)
|
|
184
|
+
const rootDir = path.dirname(rootFile)
|
|
185
|
+
|
|
186
|
+
// no url()
|
|
187
|
+
const hasUrls = cssUrlRE.test(content)
|
|
188
|
+
// data-uri() calls
|
|
189
|
+
const hasDataUris = cssDataUriRE.test(content)
|
|
190
|
+
// no @import xxx.css
|
|
191
|
+
const hasImportCss = importCssRE.test(content)
|
|
192
|
+
|
|
193
|
+
if (!hasUrls && !hasDataUris && !hasImportCss) {
|
|
194
|
+
return { file }
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
let rebased
|
|
198
|
+
const rebaseFn = async (unquotedUrl, rawUrl) => {
|
|
199
|
+
if (ignoreUrl?.(unquotedUrl, rawUrl)) return false
|
|
200
|
+
if (unquotedUrl[0] === '/') return unquotedUrl
|
|
201
|
+
const absolute = (await resolver(unquotedUrl, file)) || path.resolve(fileDir, unquotedUrl)
|
|
202
|
+
const relative = path.relative(rootDir, absolute)
|
|
203
|
+
return normalizePath(relative)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// fix css imports in less such as `@import "foo.css"`
|
|
207
|
+
if (hasImportCss) {
|
|
208
|
+
rebased = await rewriteImportCss(content, rebaseFn)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (hasUrls) {
|
|
212
|
+
rebased = await rewriteCssUrls(rebased || content, rebaseFn)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (hasDataUris) {
|
|
216
|
+
rebased = await rewriteCssDataUris(rebased || content, rebaseFn)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return {
|
|
220
|
+
file,
|
|
221
|
+
contents: rebased
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
module.exports.rebaseUrls = rebaseUrls
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
const fs = require('fs
|
|
2
|
-
const parseRequest = require('../utils/parse-request')
|
|
3
|
-
const path = require('path')
|
|
4
|
-
const loaderUtils = require('loader-utils')
|
|
1
|
+
const fs = require('fs')
|
|
5
2
|
|
|
6
3
|
class Node {
|
|
7
4
|
constructor(type, condition = null) {
|
|
@@ -131,189 +128,74 @@ function traverseAndEvaluate(ast, defs) {
|
|
|
131
128
|
*/
|
|
132
129
|
function stripCondition(content, defs) {
|
|
133
130
|
const ast = parse(content)
|
|
134
|
-
|
|
135
|
-
return result
|
|
131
|
+
return traverseAndEvaluate(ast, defs)
|
|
136
132
|
}
|
|
137
133
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
* @property {string} css 源文件
|
|
143
|
-
* @property {Record<string, any>} defs 条件定义
|
|
144
|
-
* @property {import('webpack').LoaderContext<any>['resolve']} resolve webpack resolve 方法
|
|
145
|
-
*/
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* @typedef {Object} AtImportConfig
|
|
149
|
-
* @property {string} from 当前文件路径
|
|
150
|
-
* @property {(filename: string) => Promise<string> | string;} load 加载文件内容的函数
|
|
151
|
-
* @property {(id: string, base: string) => Promise<string | null> | string | null;} resolve 解析文件路径的函数
|
|
152
|
-
*/
|
|
153
|
-
|
|
154
|
-
async function atImport(options) {
|
|
155
|
-
let { css, load, resolve, from } = options
|
|
156
|
-
const fromParent = path.dirname(from)
|
|
157
|
-
const e1 = /\/\*[\s\S]*?\*\//g
|
|
158
|
-
// 匹配 // 单行注释,可能匹配到静态资源中的 http:// 的 //,不过影响不大, @import 不太可能出现在静态资源链接中
|
|
159
|
-
const e2 = /\/\/.*/g
|
|
160
|
-
// 使用正则匹配匹配出 多行注释和单行注释
|
|
161
|
-
const comments = []
|
|
162
|
-
let comment
|
|
163
|
-
while ((comment = e1.exec(css))) {
|
|
164
|
-
const [content] = comment
|
|
165
|
-
comments.push({
|
|
166
|
-
start: comment.index,
|
|
167
|
-
end: comment.index + content.length,
|
|
168
|
-
content: content
|
|
169
|
-
})
|
|
170
|
-
}
|
|
134
|
+
let proxyReadFileSync
|
|
135
|
+
let proxyReadFile
|
|
136
|
+
const rawReadFileSync = fs.readFileSync
|
|
137
|
+
const rawReadFile = fs.readFile
|
|
171
138
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
start: comment.index,
|
|
176
|
-
end: comment.index + content.length,
|
|
177
|
-
content: content
|
|
178
|
-
})
|
|
139
|
+
function rewriteFSForCss() {
|
|
140
|
+
proxyReadFileSync = function (path, options) {
|
|
141
|
+
return rawReadFileSync.call(fs, path, options)
|
|
179
142
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
comments.sort((a, b) => (a.start > b.start ? 1 : -1))
|
|
183
|
-
|
|
184
|
-
function isInComments(index) {
|
|
185
|
-
let left = 0
|
|
186
|
-
let right = comments.length - 1
|
|
187
|
-
|
|
188
|
-
while (left <= right) {
|
|
189
|
-
const mid = Math.floor((left + right) / 2)
|
|
190
|
-
const comment = comments[mid]
|
|
191
|
-
|
|
192
|
-
if (index >= comment.start && index <= comment.end) {
|
|
193
|
-
return true
|
|
194
|
-
} else if (index < comment.start) {
|
|
195
|
-
right = mid - 1
|
|
196
|
-
} else {
|
|
197
|
-
left = mid + 1
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return false
|
|
143
|
+
proxyReadFile = function (path, options, callback) {
|
|
144
|
+
return rawReadFile.call(fs, path, options, callback)
|
|
202
145
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
// 注意清理分号,否则留个分号会报错
|
|
206
|
-
const importRegex = /@import\s+(url\(['"]([^'"]+)['"]\)|['"]([^'"]+)['"])(\s*;)?/g
|
|
207
|
-
let importList = []
|
|
208
|
-
let importMatch
|
|
209
|
-
while ((importMatch = importRegex.exec(css))) {
|
|
210
|
-
const fullMatch = importMatch[0]
|
|
211
|
-
const importSyntax = fullMatch.trim()
|
|
212
|
-
importSyntax.startsWith('@import')
|
|
213
|
-
const importValue = importSyntax.slice(7).trim()
|
|
214
|
-
// 匹配 @import 后字符串格式
|
|
215
|
-
const importUrlRegex = /url\s*\(['"]([^'"]+)['"]\)/g
|
|
216
|
-
const importStrRegexp = /^(['"])([^'"]+)\1/
|
|
217
|
-
|
|
218
|
-
let urlMatch = null
|
|
219
|
-
if (importValue.startsWith('url')) {
|
|
220
|
-
urlMatch = importUrlRegex.exec(importValue)?.[1]
|
|
221
|
-
} else {
|
|
222
|
-
urlMatch = importStrRegexp.exec(importValue)?.[2]
|
|
223
|
-
}
|
|
224
|
-
if (!urlMatch) {
|
|
225
|
-
continue
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
importList.push({
|
|
229
|
-
start: importMatch.index,
|
|
230
|
-
end: importMatch.index + fullMatch.length,
|
|
231
|
-
content: fullMatch,
|
|
232
|
-
url: urlMatch
|
|
233
|
-
})
|
|
146
|
+
fs.readFileSync = function (path, options) {
|
|
147
|
+
return proxyReadFileSync(path, options)
|
|
234
148
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
importList = importList.filter(imp => !isInComments(imp.start))
|
|
238
|
-
|
|
239
|
-
// 逆序替换 import,避免修改内容导致的索引偏移问题
|
|
240
|
-
importList.sort((a, b) => (a.start > b.start ? -1 : 1))
|
|
241
|
-
|
|
242
|
-
for (const imp of importList) {
|
|
243
|
-
const importPath = imp.url
|
|
244
|
-
if (!importPath) continue
|
|
245
|
-
// 非法路径直接报错
|
|
246
|
-
const resolvedUrl = await resolve(importPath, fromParent)
|
|
247
|
-
const content = (await load(resolvedUrl)) ?? ''
|
|
248
|
-
css = css.slice(0, imp.start) + '\n' + content + '\n' + css.slice(imp.end)
|
|
149
|
+
fs.readFile = function (path, options, callback) {
|
|
150
|
+
return proxyReadFile(path, options, callback)
|
|
249
151
|
}
|
|
250
|
-
|
|
251
|
-
return css
|
|
252
152
|
}
|
|
253
|
-
/**
|
|
254
|
-
* @param {StripByPostcssOption} options
|
|
255
|
-
*/
|
|
256
|
-
async function stripByPostcss(options) {
|
|
257
|
-
const defs = options.defs ?? {}
|
|
258
|
-
|
|
259
|
-
function stripContentCondition(content) {
|
|
260
|
-
content = stripCondition(content, defs)
|
|
261
153
|
|
|
262
|
-
|
|
263
|
-
|
|
154
|
+
function startFSStripForCss(defs) {
|
|
155
|
+
function shouldStrip(path) {
|
|
156
|
+
return typeof path === 'string' && /\.(styl|scss|sass|less|css)$/.test(path)
|
|
157
|
+
}
|
|
158
|
+
proxyReadFileSync = function (path, options) {
|
|
159
|
+
const content = rawReadFileSync.call(fs, path, options)
|
|
160
|
+
if (shouldStrip(path)) {
|
|
161
|
+
try {
|
|
162
|
+
if (typeof content === 'string') {
|
|
163
|
+
return stripCondition(content, defs)
|
|
164
|
+
}
|
|
165
|
+
} catch (e) {
|
|
166
|
+
return content
|
|
167
|
+
}
|
|
264
168
|
}
|
|
265
|
-
|
|
266
169
|
return content
|
|
267
170
|
}
|
|
268
171
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
async load(filename) {
|
|
276
|
-
let content = await fs.readFile(filename, 'utf-8')
|
|
277
|
-
|
|
278
|
-
content = stripContentCondition(content, defs)
|
|
172
|
+
proxyReadFile = function (path, options, callback) {
|
|
173
|
+
let cb = callback
|
|
174
|
+
if (typeof options === 'function') {
|
|
175
|
+
cb = options
|
|
176
|
+
options = null
|
|
177
|
+
}
|
|
279
178
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
return new Promise((resolve, reject) => {
|
|
288
|
-
// 处理 ~ 开头的路径
|
|
289
|
-
options.resolve(base, id.startsWith('~') && !id.startsWith('~/') ? loaderUtils.urlToRequest(id) : id, (err, res) => {
|
|
290
|
-
if (err) return reject(err)
|
|
291
|
-
if (typeof res !== 'string') {
|
|
292
|
-
return reject(new Error(`[mpx-strip-conditional-loader]: Cannot resolve ${id} from ${base}`))
|
|
179
|
+
const wrappedCallback = (err, data) => {
|
|
180
|
+
if (err) return cb(err)
|
|
181
|
+
if (shouldStrip(path)) {
|
|
182
|
+
try {
|
|
183
|
+
if (typeof data === 'string') {
|
|
184
|
+
const result = stripCondition(data, defs)
|
|
185
|
+
return cb(null, result)
|
|
293
186
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
187
|
+
} catch (e) {
|
|
188
|
+
return cb(null, data)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
cb(null, data)
|
|
297
192
|
}
|
|
193
|
+
if (options) {
|
|
194
|
+
return rawReadFile.call(fs, path, options, wrappedCallback)
|
|
195
|
+
}
|
|
196
|
+
return rawReadFile.call(fs, path, wrappedCallback)
|
|
298
197
|
}
|
|
299
|
-
|
|
300
|
-
return {
|
|
301
|
-
css: await atImport({
|
|
302
|
-
...atImportOptions,
|
|
303
|
-
from: options.resourcePath,
|
|
304
|
-
css: afterConditionStrip
|
|
305
|
-
})
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
const createResolver = (contetx, extensions) =>
|
|
310
|
-
contetx.getResolve({ mainFiles: ['index'], extensions: [...extensions, '.css'], preferRelative: true })
|
|
311
|
-
const resolver = {
|
|
312
|
-
stylus: contetx => createResolver(contetx, ['.styl']),
|
|
313
|
-
scss: contetx => createResolver(contetx, ['.scss']),
|
|
314
|
-
less: contetx => createResolver(contetx, ['.styl'])
|
|
315
198
|
}
|
|
316
|
-
|
|
317
199
|
/**
|
|
318
200
|
*
|
|
319
201
|
* @this {import('webpack').LoaderContext<any>}
|
|
@@ -325,18 +207,11 @@ module.exports = async function (css) {
|
|
|
325
207
|
const callback = this.async()
|
|
326
208
|
|
|
327
209
|
const mpx = this.getMpx()
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
const result = await stripByPostcss({
|
|
331
|
-
lang: queryObj.lang,
|
|
332
|
-
resourcePath,
|
|
333
|
-
css,
|
|
334
|
-
defs: mpx.defs,
|
|
335
|
-
resolve: resolver[queryObj.lang] ? resolver[queryObj.lang](this) : this.resolve.bind(this)
|
|
336
|
-
})
|
|
210
|
+
const result = stripCondition(css, mpx.defs)
|
|
337
211
|
|
|
338
|
-
callback(null, result
|
|
212
|
+
callback(null, result)
|
|
339
213
|
}
|
|
340
214
|
|
|
341
|
-
module.exports.stripByPostcss = stripByPostcss
|
|
342
215
|
module.exports.stripCondition = stripCondition
|
|
216
|
+
module.exports.rewriteFSForCss = rewriteFSForCss
|
|
217
|
+
module.exports.startFSStripForCss = startFSStripForCss
|
|
@@ -764,8 +764,6 @@ function parse (template, options) {
|
|
|
764
764
|
|
|
765
765
|
const children = currentParent.children
|
|
766
766
|
|
|
767
|
-
// const isTextLikeParent = currentParent.tag === 'text' || currentParent.tag === 'mpx-text' || currentParent.tag === 'Text' || currentParent.tag === 'mpx-simple-text'
|
|
768
|
-
|
|
769
767
|
if (currentParent.tag !== 'text') {
|
|
770
768
|
text = text.trim()
|
|
771
769
|
} else {
|
|
@@ -2719,7 +2717,7 @@ function postProcessTemplate (el) {
|
|
|
2719
2717
|
}
|
|
2720
2718
|
}
|
|
2721
2719
|
|
|
2722
|
-
const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd,tenon,ios,android,harmony,noMode')
|
|
2720
|
+
const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd,tenon,ios,android,harmony,ks,noMode')
|
|
2723
2721
|
|
|
2724
2722
|
function isValidModeP (i) {
|
|
2725
2723
|
return isValidMode(i[0] === '_' ? i.slice(1) : i)
|
|
@@ -91,7 +91,7 @@ const isBuildInReactTag = makeMap(
|
|
|
91
91
|
'mpx-movable-area,mpx-label,mpx-input,' +
|
|
92
92
|
'mpx-image,mpx-form,mpx-checkbox,mpx-checkbox-group,mpx-button,' +
|
|
93
93
|
'mpx-rich-text,mpx-picker-view-column,mpx-picker-view,mpx-picker,' +
|
|
94
|
-
'mpx-icon,mpx-canvas'
|
|
94
|
+
'mpx-icon,mpx-canvas,mpx-camera'
|
|
95
95
|
)
|
|
96
96
|
|
|
97
97
|
const isSpace = makeMap('ensp,emsp,nbsp')
|
package/lib/utils/string.js
CHANGED
|
@@ -28,9 +28,33 @@ function trimBlankRow (str) {
|
|
|
28
28
|
return str.replace(/^\s*[\r\n]/gm, '')
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
// 多value解析
|
|
32
|
+
function parseValues (str, char = ' ') {
|
|
33
|
+
let stack = 0
|
|
34
|
+
let temp = ''
|
|
35
|
+
const result = []
|
|
36
|
+
for (let i = 0; i < str.length; i++) {
|
|
37
|
+
if (str[i] === '(') {
|
|
38
|
+
stack++
|
|
39
|
+
} else if (str[i] === ')') {
|
|
40
|
+
stack--
|
|
41
|
+
}
|
|
42
|
+
// 非括号内 或者 非分隔字符且非空
|
|
43
|
+
if (stack !== 0 || str[i] !== char) {
|
|
44
|
+
temp += str[i]
|
|
45
|
+
}
|
|
46
|
+
if ((stack === 0 && str[i] === char) || i === str.length - 1) {
|
|
47
|
+
result.push(temp.trim())
|
|
48
|
+
temp = ''
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return result
|
|
52
|
+
}
|
|
53
|
+
|
|
31
54
|
module.exports = {
|
|
32
55
|
isCapital,
|
|
33
56
|
isMustache,
|
|
34
57
|
capitalToHyphen,
|
|
35
|
-
trimBlankRow
|
|
58
|
+
trimBlankRow,
|
|
59
|
+
parseValues
|
|
36
60
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.10.17-beta.
|
|
3
|
+
"version": "2.10.17-beta.4",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -97,6 +97,7 @@
|
|
|
97
97
|
"react-native-safe-area-context": "^4.12.0",
|
|
98
98
|
"react-native-svg": "^15.8.0",
|
|
99
99
|
"react-native-video": "^6.9.0",
|
|
100
|
+
"react-native-vision-camera": "^4.7.2",
|
|
100
101
|
"react-native-webview": "^13.12.2",
|
|
101
102
|
"rimraf": "^6.0.1"
|
|
102
103
|
},
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { MutableRefObject } from 'react';
|
|
2
|
-
import type { NativeSyntheticEvent } from 'react-native';
|
|
3
|
-
import { ExtendedViewStyle } from './types/common';
|
|
4
|
-
import type { _ViewProps } from './mpx-view';
|
|
5
|
-
type AnimatedOption = {
|
|
6
|
-
duration: number;
|
|
7
|
-
delay: number;
|
|
8
|
-
useNativeDriver: boolean;
|
|
9
|
-
timingFunction: 'linear' | 'ease' | 'ease-in' | 'ease-in-out' | 'ease-out';
|
|
10
|
-
transformOrigin: string;
|
|
11
|
-
};
|
|
12
|
-
export type AnimationStepItem = {
|
|
13
|
-
animatedOption: AnimatedOption;
|
|
14
|
-
rules: Map<string, number | string>;
|
|
15
|
-
transform: Map<string, number>;
|
|
16
|
-
};
|
|
17
|
-
export type AnimationProp = {
|
|
18
|
-
id: number;
|
|
19
|
-
actions: AnimationStepItem[];
|
|
20
|
-
};
|
|
21
|
-
export default function useAnimationHooks<T, P>(props: _ViewProps & {
|
|
22
|
-
enableAnimation?: boolean;
|
|
23
|
-
layoutRef: MutableRefObject<any>;
|
|
24
|
-
transitionend?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void;
|
|
25
|
-
}): {
|
|
26
|
-
enableStyleAnimation: boolean;
|
|
27
|
-
animationStyle?: undefined;
|
|
28
|
-
} | {
|
|
29
|
-
enableStyleAnimation: true;
|
|
30
|
-
animationStyle: ExtendedViewStyle;
|
|
31
|
-
};
|
|
32
|
-
export {};
|
|
33
|
-
//# sourceMappingURL=useAnimationHooks.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useAnimationHooks.d.ts","sourceRoot":"","sources":["../useAnimationHooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAA;AAC7C,OAAO,KAAK,EAAE,oBAAoB,EAAmB,MAAM,cAAc,CAAA;AAezE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,KAAK,cAAc,GAAG;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,eAAe,EAAE,OAAO,CAAA;IACxB,cAAc,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,aAAa,GAAE,UAAU,CAAA;IACzE,eAAe,EAAE,MAAM,CAAA;CACxB,CAAA;AAID,MAAM,MAAM,iBAAiB,GAAG;IAC9B,cAAc,EAAE,cAAc,CAAA;IAC9B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;IACnC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B,CAAA;AACD,MAAM,MAAM,aAAa,GAAG;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,iBAAiB,EAAE,CAAA;CAC7B,CAAA;AA0DD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAAG,KAAK,EAAE,UAAU,GAAG;IAAE,eAAe,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAAC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,CAAC,UAAU,CAAC,GAAG,OAAO,KAAK,IAAI,CAAA;CAAE;;;;;;EA+NhN"}
|