weapp-tailwindcss 4.3.3 → 4.4.0-alpha.0
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/dist/chunk-2NRTWL47.js +43 -0
- package/dist/{chunk-GFQ2R7SX.mjs → chunk-3MSGCIVH.mjs} +127 -129
- package/dist/{chunk-3KMEJ2LM.js → chunk-AEJDBNAX.js} +540 -315
- package/dist/{chunk-M7PVNKCH.mjs → chunk-AXYGCCZW.mjs} +45 -57
- package/dist/chunk-E2LRXNZ3.js +122 -0
- package/dist/{chunk-L36QGA7Y.mjs → chunk-FBGUUXQV.mjs} +1 -1
- package/dist/{chunk-A75TB5TE.js → chunk-FOSGDQZ7.js} +34 -43
- package/dist/chunk-H4JTYYOI.mjs +43 -0
- package/dist/{chunk-5BTC4YQI.mjs → chunk-IHKVNALD.mjs} +29 -38
- package/dist/chunk-KAKRCCPX.mjs +122 -0
- package/dist/{chunk-L7VNJFIK.js → chunk-NZ7VALIM.js} +129 -131
- package/dist/{chunk-JDLLZFZX.js → chunk-PPTSD6TQ.js} +46 -58
- package/dist/{chunk-O3G5TVND.js → chunk-RBRSMHFS.js} +1 -1
- package/dist/chunk-UW3WHSZ5.js +39 -0
- package/dist/{chunk-3KXFKRIX.mjs → chunk-WCIVXE2D.mjs} +539 -314
- package/dist/chunk-ZNKIYZRQ.mjs +39 -0
- package/dist/cli.js +5 -8
- package/dist/cli.mjs +4 -7
- package/dist/core.js +5 -5
- package/dist/core.mjs +4 -4
- package/dist/css-macro/postcss.js +1 -1
- package/dist/css-macro/postcss.mjs +1 -1
- package/dist/css-macro.js +3 -3
- package/dist/css-macro.mjs +2 -2
- package/dist/defaults.js +4 -4
- package/dist/defaults.mjs +3 -3
- package/dist/escape.js +1 -1
- package/dist/escape.mjs +1 -1
- package/dist/gulp.js +7 -7
- package/dist/gulp.mjs +6 -6
- package/dist/index.js +9 -9
- package/dist/index.mjs +8 -8
- package/dist/postcss-html-transform.js +1 -1
- package/dist/postcss-html-transform.mjs +1 -1
- package/dist/presets.js +3 -3
- package/dist/presets.mjs +2 -2
- package/dist/types.d.mts +247 -246
- package/dist/types.d.ts +247 -246
- package/dist/types.js +1 -1
- package/dist/types.mjs +1 -1
- package/dist/vite.js +7 -7
- package/dist/vite.mjs +6 -6
- package/dist/webpack.js +7 -7
- package/dist/webpack.mjs +6 -6
- package/dist/webpack4.js +48 -63
- package/dist/webpack4.mjs +46 -61
- package/package.json +4 -5
- package/dist/chunk-3AUX4FGE.mjs +0 -13
- package/dist/chunk-GEUHO2UC.mjs +0 -141
- package/dist/chunk-LSSLYD6B.js +0 -13
- package/dist/chunk-QXQOYYCR.js +0 -26
- package/dist/chunk-TI4R65TB.js +0 -141
- package/dist/chunk-Y5AFAYKI.mjs +0 -26
|
@@ -3,20 +3,18 @@
|
|
|
3
3
|
var _chunkPLMJW644js = require('./chunk-PLMJW644.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkFOSGDQZ7js = require('./chunk-FOSGDQZ7.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
+
var _chunkUW3WHSZ5js = require('./chunk-UW3WHSZ5.js');
|
|
10
11
|
|
|
11
|
-
var _chunkQXQOYYCRjs = require('./chunk-QXQOYYCR.js');
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
var _chunkO3G5TVNDjs = require('./chunk-O3G5TVND.js');
|
|
13
|
+
var _chunkRBRSMHFSjs = require('./chunk-RBRSMHFS.js');
|
|
15
14
|
|
|
16
15
|
// src/context/index.ts
|
|
17
16
|
var _logger = require('@weapp-tailwindcss/logger');
|
|
18
17
|
var _mangle = require('@weapp-tailwindcss/mangle');
|
|
19
|
-
var _postcss = require('@weapp-tailwindcss/postcss');
|
|
20
18
|
|
|
21
19
|
// src/cache/index.ts
|
|
22
20
|
var _lrucache = require('lru-cache');
|
|
@@ -28,6 +26,9 @@ function md5Hash(data) {
|
|
|
28
26
|
}
|
|
29
27
|
|
|
30
28
|
// src/cache/index.ts
|
|
29
|
+
function isProcessResult(value) {
|
|
30
|
+
return typeof value === "object" && value !== null && "result" in value;
|
|
31
|
+
}
|
|
31
32
|
function createCache(options) {
|
|
32
33
|
const disabled = options === false;
|
|
33
34
|
const hashMap = /* @__PURE__ */ new Map();
|
|
@@ -37,7 +38,7 @@ function createCache(options) {
|
|
|
37
38
|
ttl: 0,
|
|
38
39
|
ttlAutopurge: false
|
|
39
40
|
});
|
|
40
|
-
|
|
41
|
+
const cache = {
|
|
41
42
|
hashMap,
|
|
42
43
|
instance,
|
|
43
44
|
hasHashKey(key) {
|
|
@@ -59,47 +60,60 @@ function createCache(options) {
|
|
|
59
60
|
return md5Hash(message);
|
|
60
61
|
},
|
|
61
62
|
calcHashValueChanged(key, hash) {
|
|
62
|
-
const hit =
|
|
63
|
+
const hit = hashMap.get(key);
|
|
63
64
|
if (hit) {
|
|
64
|
-
|
|
65
|
-
// new file should be changed
|
|
65
|
+
hashMap.set(key, {
|
|
66
66
|
changed: hash !== hit.hash,
|
|
67
|
-
// new hash
|
|
68
67
|
hash
|
|
69
68
|
});
|
|
70
69
|
} else {
|
|
71
|
-
|
|
72
|
-
// new file should be changed
|
|
70
|
+
hashMap.set(key, {
|
|
73
71
|
changed: true,
|
|
74
72
|
hash
|
|
75
73
|
});
|
|
76
74
|
}
|
|
77
|
-
return
|
|
75
|
+
return cache;
|
|
78
76
|
},
|
|
79
77
|
has(key) {
|
|
80
78
|
return instance.has(key);
|
|
81
79
|
},
|
|
82
|
-
async process(
|
|
80
|
+
async process({
|
|
81
|
+
key,
|
|
82
|
+
hashKey,
|
|
83
|
+
rawSource,
|
|
84
|
+
hash,
|
|
85
|
+
resolveCache,
|
|
86
|
+
transform,
|
|
87
|
+
onCacheHit
|
|
88
|
+
}) {
|
|
83
89
|
if (disabled) {
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
const value2 = await transform();
|
|
91
|
+
return isProcessResult(value2) ? value2.result : value2;
|
|
92
|
+
}
|
|
93
|
+
const cacheHashKey = _nullishCoalesce(hashKey, () => ( key));
|
|
94
|
+
let hasChanged = true;
|
|
95
|
+
if (hash != null || rawSource != null) {
|
|
96
|
+
const nextHash = _nullishCoalesce(hash, () => ( cache.computeHash(rawSource)));
|
|
97
|
+
cache.calcHashValueChanged(cacheHashKey, nextHash);
|
|
98
|
+
const entry = cache.getHashValue(cacheHashKey);
|
|
99
|
+
hasChanged = _nullishCoalesce(_optionalChain([entry, 'optionalAccess', _2 => _2.changed]), () => ( true));
|
|
100
|
+
}
|
|
101
|
+
const readCache = _nullishCoalesce(resolveCache, () => ( (() => cache.get(key))));
|
|
102
|
+
if (!hasChanged) {
|
|
103
|
+
const cached = readCache();
|
|
104
|
+
if (cached !== void 0) {
|
|
105
|
+
await _optionalChain([onCacheHit, 'optionalCall', _3 => _3(cached)]);
|
|
106
|
+
return cached;
|
|
99
107
|
}
|
|
100
108
|
}
|
|
109
|
+
const value = await transform();
|
|
110
|
+
const normalized = isProcessResult(value) ? value : { result: value };
|
|
111
|
+
const stored = _nullishCoalesce(normalized.cacheValue, () => ( normalized.result));
|
|
112
|
+
cache.set(key, stored);
|
|
113
|
+
return normalized.result;
|
|
101
114
|
}
|
|
102
115
|
};
|
|
116
|
+
return cache;
|
|
103
117
|
}
|
|
104
118
|
function initializeCache(cacheConfig) {
|
|
105
119
|
if (typeof cacheConfig === "boolean" || cacheConfig === void 0) {
|
|
@@ -108,6 +122,19 @@ function initializeCache(cacheConfig) {
|
|
|
108
122
|
return cacheConfig;
|
|
109
123
|
}
|
|
110
124
|
|
|
125
|
+
// src/context/custom-attributes.ts
|
|
126
|
+
function toCustomAttributesEntities(customAttributes) {
|
|
127
|
+
if (_chunkUW3WHSZ5js.isMap.call(void 0, customAttributes)) {
|
|
128
|
+
return [
|
|
129
|
+
...customAttributes.entries()
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
return Object.entries(customAttributes);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// src/context/handlers.ts
|
|
136
|
+
var _postcss = require('@weapp-tailwindcss/postcss');
|
|
137
|
+
|
|
111
138
|
// src/js/babel.ts
|
|
112
139
|
var _escape = require('@ast-core/escape');
|
|
113
140
|
|
|
@@ -121,101 +148,198 @@ function _interopDefaultCompat(e) {
|
|
|
121
148
|
}
|
|
122
149
|
var traverse = _interopDefaultCompat(_traverse2.default);
|
|
123
150
|
|
|
151
|
+
// src/utils/nameMatcher.ts
|
|
152
|
+
function createNameMatcher(list, { exact = false } = {}) {
|
|
153
|
+
if (!list || list.length === 0) {
|
|
154
|
+
return () => false;
|
|
155
|
+
}
|
|
156
|
+
const exactStrings = /* @__PURE__ */ new Set();
|
|
157
|
+
const fuzzyStrings = [];
|
|
158
|
+
const regexList = [];
|
|
159
|
+
for (const item of list) {
|
|
160
|
+
if (typeof item === "string") {
|
|
161
|
+
if (exact) {
|
|
162
|
+
exactStrings.add(item);
|
|
163
|
+
} else {
|
|
164
|
+
fuzzyStrings.push(item);
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
regexList.push(item);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return (value) => {
|
|
171
|
+
if (exact && exactStrings.has(value)) {
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
if (!exact) {
|
|
175
|
+
for (const candidate of fuzzyStrings) {
|
|
176
|
+
if (value.includes(candidate)) {
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
for (const regex of regexList) {
|
|
182
|
+
regex.lastIndex = 0;
|
|
183
|
+
if (regex.test(value)) {
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return false;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
124
191
|
// src/js/handlers.ts
|
|
125
192
|
|
|
126
193
|
var _regex = require('@weapp-core/regex');
|
|
127
194
|
var _extractors = require('@weapp-tailwindcss/shared/extractors');
|
|
128
195
|
|
|
129
196
|
// src/utils/decode.ts
|
|
197
|
+
var unicodeEscapeRE = /\\u([\dA-Fa-f]{4})/g;
|
|
198
|
+
function decodeUnicode(value) {
|
|
199
|
+
return value.replace(unicodeEscapeRE, (_match, hex) => {
|
|
200
|
+
const codePoint = Number.parseInt(hex, 16);
|
|
201
|
+
return Number.isNaN(codePoint) ? _match : String.fromCharCode(codePoint);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
130
204
|
function decodeUnicode2(input) {
|
|
131
205
|
try {
|
|
132
206
|
return JSON.parse(`"${input}"`);
|
|
133
207
|
} catch (_error) {
|
|
134
|
-
return input;
|
|
208
|
+
return decodeUnicode(input);
|
|
135
209
|
}
|
|
136
210
|
}
|
|
137
211
|
|
|
138
212
|
// src/js/handlers.ts
|
|
213
|
+
function hasIgnoreComment(node) {
|
|
214
|
+
return Array.isArray(node.leadingComments) && node.leadingComments.some((comment) => comment.value.includes("weapp-tw") && comment.value.includes("ignore"));
|
|
215
|
+
}
|
|
216
|
+
function shouldTransformClassName(candidate, {
|
|
217
|
+
alwaysEscape,
|
|
218
|
+
classNameSet,
|
|
219
|
+
jsPreserveClass
|
|
220
|
+
}) {
|
|
221
|
+
if (alwaysEscape) {
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
if (!classNameSet) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
if (!classNameSet.has(candidate)) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
return !_optionalChain([jsPreserveClass, 'optionalCall', _4 => _4(candidate)]);
|
|
231
|
+
}
|
|
232
|
+
function extractLiteralValue(path2, { unescapeUnicode, arbitraryValues }) {
|
|
233
|
+
const allowDoubleQuotes = _optionalChain([arbitraryValues, 'optionalAccess', _5 => _5.allowDoubleQuotes]);
|
|
234
|
+
let offset = 0;
|
|
235
|
+
let original;
|
|
236
|
+
if (path2.isStringLiteral()) {
|
|
237
|
+
offset = 1;
|
|
238
|
+
original = path2.node.value;
|
|
239
|
+
} else if (path2.isTemplateElement()) {
|
|
240
|
+
original = path2.node.value.raw;
|
|
241
|
+
} else {
|
|
242
|
+
original = "";
|
|
243
|
+
}
|
|
244
|
+
let literal = original;
|
|
245
|
+
if (unescapeUnicode && original.includes("\\u")) {
|
|
246
|
+
literal = decodeUnicode2(original);
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
allowDoubleQuotes,
|
|
250
|
+
literal,
|
|
251
|
+
offset,
|
|
252
|
+
original
|
|
253
|
+
};
|
|
254
|
+
}
|
|
139
255
|
function replaceHandleValue(path2, options) {
|
|
140
256
|
const {
|
|
141
|
-
classNameSet,
|
|
142
257
|
escapeMap,
|
|
143
|
-
mangleContext
|
|
144
|
-
needEscaped = false
|
|
145
|
-
jsPreserveClass,
|
|
146
|
-
arbitraryValues,
|
|
147
|
-
alwaysEscape,
|
|
148
|
-
unescapeUnicode
|
|
258
|
+
mangleContext,
|
|
259
|
+
needEscaped = false
|
|
149
260
|
} = options;
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
let rawStr = str;
|
|
154
|
-
let needUpdate = false;
|
|
155
|
-
if (unescapeUnicode && rawStr.includes("\\u")) {
|
|
156
|
-
rawStr = decodeUnicode2(rawStr);
|
|
261
|
+
const { literal, original, allowDoubleQuotes, offset } = extractLiteralValue(path2, options);
|
|
262
|
+
if (hasIgnoreComment(path2.node)) {
|
|
263
|
+
return void 0;
|
|
157
264
|
}
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
})
|
|
175
|
-
);
|
|
176
|
-
needUpdate = true;
|
|
265
|
+
const candidates = _extractors.splitCode.call(void 0, literal, allowDoubleQuotes);
|
|
266
|
+
if (candidates.length === 0) {
|
|
267
|
+
return void 0;
|
|
268
|
+
}
|
|
269
|
+
let transformed = literal;
|
|
270
|
+
let mutated = false;
|
|
271
|
+
const replacementCache = /* @__PURE__ */ new Map();
|
|
272
|
+
for (const candidate of candidates) {
|
|
273
|
+
if (!shouldTransformClassName(candidate, options)) {
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
if (mangleContext) {
|
|
277
|
+
const mangled = mangleContext.jsHandler(transformed);
|
|
278
|
+
if (mangled !== transformed) {
|
|
279
|
+
transformed = mangled;
|
|
280
|
+
mutated = true;
|
|
177
281
|
}
|
|
178
282
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
end,
|
|
188
|
-
value,
|
|
189
|
-
path: path2
|
|
283
|
+
if (!transformed.includes(candidate)) {
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
let cached = replacementCache.get(candidate);
|
|
287
|
+
if (!cached) {
|
|
288
|
+
cached = {
|
|
289
|
+
pattern: new RegExp(_regex.escapeStringRegexp.call(void 0, candidate)),
|
|
290
|
+
replacement: _chunkPLMJW644js.replaceWxml.call(void 0, candidate, { escapeMap })
|
|
190
291
|
};
|
|
292
|
+
replacementCache.set(candidate, cached);
|
|
191
293
|
}
|
|
294
|
+
const { pattern, replacement } = cached;
|
|
295
|
+
const replaced = transformed.replace(pattern, replacement);
|
|
296
|
+
if (replaced !== transformed) {
|
|
297
|
+
transformed = replaced;
|
|
298
|
+
mutated = true;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
const node = path2.node;
|
|
302
|
+
if (!mutated || typeof node.start !== "number" || typeof node.end !== "number") {
|
|
303
|
+
return void 0;
|
|
192
304
|
}
|
|
305
|
+
const start = node.start + offset;
|
|
306
|
+
const end = node.end - offset;
|
|
307
|
+
if (start >= end || transformed === original) {
|
|
308
|
+
return void 0;
|
|
309
|
+
}
|
|
310
|
+
const value = needEscaped ? _escape.jsStringEscape.call(void 0, transformed) : transformed;
|
|
311
|
+
return {
|
|
312
|
+
start,
|
|
313
|
+
end,
|
|
314
|
+
value,
|
|
315
|
+
path: path2
|
|
316
|
+
};
|
|
193
317
|
}
|
|
194
318
|
|
|
195
319
|
// src/js/JsTokenUpdater.ts
|
|
196
320
|
var JsTokenUpdater = class {
|
|
197
321
|
constructor({ value } = {}) {
|
|
198
|
-
this.
|
|
322
|
+
this.tokens = value ? [...value] : [];
|
|
199
323
|
}
|
|
200
324
|
addToken(token) {
|
|
201
325
|
if (token) {
|
|
202
|
-
this.
|
|
326
|
+
this.tokens.push(token);
|
|
203
327
|
}
|
|
204
328
|
}
|
|
205
329
|
push(...args) {
|
|
206
|
-
this.
|
|
330
|
+
this.tokens.push(...args);
|
|
207
331
|
return this;
|
|
208
332
|
}
|
|
209
333
|
map(callbackfn) {
|
|
210
|
-
this.
|
|
334
|
+
this.tokens = this.tokens.map(callbackfn);
|
|
211
335
|
return this;
|
|
212
336
|
}
|
|
213
337
|
filter(callbackfn) {
|
|
214
|
-
this.
|
|
338
|
+
this.tokens = this.tokens.filter(callbackfn);
|
|
215
339
|
return this;
|
|
216
340
|
}
|
|
217
341
|
updateMagicString(ms) {
|
|
218
|
-
for (const { start, end, value } of this.
|
|
342
|
+
for (const { start, end, value } of this.tokens) {
|
|
219
343
|
ms.update(start, end, value);
|
|
220
344
|
}
|
|
221
345
|
return ms;
|
|
@@ -223,13 +347,14 @@ var JsTokenUpdater = class {
|
|
|
223
347
|
};
|
|
224
348
|
|
|
225
349
|
// src/js/NodePathWalker.ts
|
|
226
|
-
var walkedBindingWeakMap = /* @__PURE__ */ new WeakMap();
|
|
227
350
|
var NodePathWalker = class {
|
|
228
351
|
constructor({ ignoreCallExpressionIdentifiers, callback } = {}) {
|
|
229
352
|
this.ignoreCallExpressionIdentifiers = _nullishCoalesce(ignoreCallExpressionIdentifiers, () => ( []));
|
|
230
353
|
this.callback = _nullishCoalesce(callback, () => ( (() => {
|
|
231
354
|
})));
|
|
232
355
|
this.imports = /* @__PURE__ */ new Set();
|
|
356
|
+
this.visited = /* @__PURE__ */ new WeakSet();
|
|
357
|
+
this.isIgnoredCallIdentifier = createNameMatcher(this.ignoreCallExpressionIdentifiers, { exact: true });
|
|
233
358
|
}
|
|
234
359
|
walkVariableDeclarator(path2) {
|
|
235
360
|
const init = path2.get("init");
|
|
@@ -276,10 +401,10 @@ var NodePathWalker = class {
|
|
|
276
401
|
}
|
|
277
402
|
}
|
|
278
403
|
walkNode(arg) {
|
|
279
|
-
if (
|
|
404
|
+
if (this.visited.has(arg)) {
|
|
280
405
|
return;
|
|
281
406
|
}
|
|
282
|
-
|
|
407
|
+
this.visited.add(arg);
|
|
283
408
|
if (arg.isIdentifier()) {
|
|
284
409
|
const binding = arg.scope.getBinding(arg.node.name);
|
|
285
410
|
if (binding) {
|
|
@@ -339,14 +464,11 @@ var NodePathWalker = class {
|
|
|
339
464
|
}
|
|
340
465
|
}
|
|
341
466
|
/**
|
|
342
|
-
*
|
|
343
|
-
* @param path
|
|
467
|
+
* Walk the arguments of a desired call expression so their bindings can be analysed.
|
|
344
468
|
*/
|
|
345
469
|
walkCallExpression(path2) {
|
|
346
470
|
const calleePath = path2.get("callee");
|
|
347
|
-
if (calleePath.isIdentifier() &&
|
|
348
|
-
exact: true
|
|
349
|
-
})) {
|
|
471
|
+
if (calleePath.isIdentifier() && this.isIgnoredCallIdentifier(calleePath.node.name)) {
|
|
350
472
|
for (const arg of path2.get("arguments")) {
|
|
351
473
|
this.walkNode(arg);
|
|
352
474
|
}
|
|
@@ -434,19 +556,88 @@ function isEvalPath(p) {
|
|
|
434
556
|
}
|
|
435
557
|
return false;
|
|
436
558
|
}
|
|
437
|
-
|
|
559
|
+
function createEvalReplacementToken(path2, updated) {
|
|
560
|
+
const node = path2.node;
|
|
561
|
+
let offset = 0;
|
|
562
|
+
let original;
|
|
563
|
+
if (path2.isStringLiteral()) {
|
|
564
|
+
offset = 1;
|
|
565
|
+
original = path2.node.value;
|
|
566
|
+
} else if (path2.isTemplateElement()) {
|
|
567
|
+
original = path2.node.value.raw;
|
|
568
|
+
} else {
|
|
569
|
+
original = "";
|
|
570
|
+
}
|
|
571
|
+
if (typeof node.start !== "number" || typeof node.end !== "number") {
|
|
572
|
+
return void 0;
|
|
573
|
+
}
|
|
574
|
+
const start = node.start + offset;
|
|
575
|
+
const end = node.end - offset;
|
|
576
|
+
if (start >= end) {
|
|
577
|
+
return void 0;
|
|
578
|
+
}
|
|
579
|
+
if (original === updated) {
|
|
580
|
+
return void 0;
|
|
581
|
+
}
|
|
582
|
+
const value = path2.isStringLiteral() ? _escape.jsStringEscape.call(void 0, updated) : updated;
|
|
583
|
+
return {
|
|
584
|
+
start,
|
|
585
|
+
end,
|
|
586
|
+
value,
|
|
587
|
+
path: path2
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
function handleEvalStringLiteral(path2, options, updater) {
|
|
591
|
+
const { code } = jsHandler(path2.node.value, {
|
|
592
|
+
...options,
|
|
593
|
+
needEscaped: false,
|
|
594
|
+
generateMap: false
|
|
595
|
+
});
|
|
596
|
+
if (!code) {
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
const token = createEvalReplacementToken(path2, code);
|
|
600
|
+
if (token) {
|
|
601
|
+
updater.addToken(token);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
function handleEvalTemplateElement(path2, options, updater) {
|
|
605
|
+
const { code } = jsHandler(path2.node.value.raw, {
|
|
606
|
+
...options,
|
|
607
|
+
generateMap: false
|
|
608
|
+
});
|
|
609
|
+
if (!code) {
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
const token = createEvalReplacementToken(path2, code);
|
|
613
|
+
if (token) {
|
|
614
|
+
updater.addToken(token);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
function walkEvalExpression(path2, options, updater) {
|
|
618
|
+
path2.traverse({
|
|
619
|
+
StringLiteral(innerPath) {
|
|
620
|
+
handleEvalStringLiteral(innerPath, options, updater);
|
|
621
|
+
},
|
|
622
|
+
TemplateElement(innerPath) {
|
|
623
|
+
handleEvalTemplateElement(innerPath, options, updater);
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
}
|
|
438
627
|
function analyzeSource(ast, options) {
|
|
439
628
|
const jsTokenUpdater = new JsTokenUpdater();
|
|
629
|
+
const ignoredPaths = /* @__PURE__ */ new WeakSet();
|
|
440
630
|
const walker = new NodePathWalker(
|
|
441
631
|
{
|
|
442
632
|
ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers,
|
|
443
633
|
callback(path2) {
|
|
444
634
|
if (path2.isStringLiteral() || path2.isTemplateElement()) {
|
|
445
|
-
|
|
635
|
+
ignoredPaths.add(path2);
|
|
446
636
|
}
|
|
447
637
|
}
|
|
448
638
|
}
|
|
449
639
|
);
|
|
640
|
+
const isIgnoredTaggedTemplate = createNameMatcher(options.ignoreTaggedTemplateExpressionIdentifiers, { exact: true });
|
|
450
641
|
const targetPaths = [];
|
|
451
642
|
const importDeclarations = /* @__PURE__ */ new Set();
|
|
452
643
|
const exportDeclarations = /* @__PURE__ */ new Set();
|
|
@@ -469,7 +660,7 @@ function analyzeSource(ast, options) {
|
|
|
469
660
|
}
|
|
470
661
|
if (ppp.isTaggedTemplateExpression()) {
|
|
471
662
|
const tagPath = ppp.get("tag");
|
|
472
|
-
if (tagPath.isIdentifier() &&
|
|
663
|
+
if (tagPath.isIdentifier() && isIgnoredTaggedTemplate(tagPath.node.name)) {
|
|
473
664
|
return;
|
|
474
665
|
}
|
|
475
666
|
}
|
|
@@ -480,59 +671,7 @@ function analyzeSource(ast, options) {
|
|
|
480
671
|
CallExpression: {
|
|
481
672
|
enter(p) {
|
|
482
673
|
if (isEvalPath(p)) {
|
|
483
|
-
p
|
|
484
|
-
StringLiteral: {
|
|
485
|
-
enter(path2) {
|
|
486
|
-
const { code } = jsHandler(path2.node.value, {
|
|
487
|
-
...options,
|
|
488
|
-
needEscaped: false,
|
|
489
|
-
generateMap: false
|
|
490
|
-
});
|
|
491
|
-
if (code) {
|
|
492
|
-
const node = path2.node;
|
|
493
|
-
if (typeof node.start === "number" && typeof node.end === "number") {
|
|
494
|
-
const start = node.start + 1;
|
|
495
|
-
const end = node.end - 1;
|
|
496
|
-
if (start < end && path2.node.value !== code) {
|
|
497
|
-
jsTokenUpdater.addToken(
|
|
498
|
-
{
|
|
499
|
-
start,
|
|
500
|
-
end,
|
|
501
|
-
value: _escape.jsStringEscape.call(void 0, code),
|
|
502
|
-
path: path2
|
|
503
|
-
}
|
|
504
|
-
);
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
},
|
|
510
|
-
TemplateElement: {
|
|
511
|
-
enter(path2) {
|
|
512
|
-
const { code } = jsHandler(path2.node.value.raw, {
|
|
513
|
-
...options,
|
|
514
|
-
generateMap: false
|
|
515
|
-
});
|
|
516
|
-
if (code) {
|
|
517
|
-
const node = path2.node;
|
|
518
|
-
if (typeof node.start === "number" && typeof node.end === "number") {
|
|
519
|
-
const start = node.start;
|
|
520
|
-
const end = node.end;
|
|
521
|
-
if (start < end && path2.node.value.raw !== code) {
|
|
522
|
-
jsTokenUpdater.addToken(
|
|
523
|
-
{
|
|
524
|
-
start,
|
|
525
|
-
end,
|
|
526
|
-
value: code,
|
|
527
|
-
path: path2
|
|
528
|
-
}
|
|
529
|
-
);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
});
|
|
674
|
+
walkEvalExpression(p, options, jsTokenUpdater);
|
|
536
675
|
return;
|
|
537
676
|
}
|
|
538
677
|
walker.walkCallExpression(p);
|
|
@@ -556,46 +695,30 @@ function analyzeSource(ast, options) {
|
|
|
556
695
|
ast,
|
|
557
696
|
targetPaths,
|
|
558
697
|
importDeclarations,
|
|
559
|
-
exportDeclarations
|
|
560
|
-
|
|
698
|
+
exportDeclarations,
|
|
699
|
+
ignoredPaths
|
|
561
700
|
};
|
|
562
701
|
}
|
|
563
702
|
function processUpdatedSource(rawSource, options, analysis) {
|
|
564
703
|
const ms = new (0, _magicstring2.default)(rawSource);
|
|
565
|
-
const { targetPaths, jsTokenUpdater } = analysis;
|
|
566
|
-
const
|
|
567
|
-
|
|
568
|
-
|
|
704
|
+
const { targetPaths, jsTokenUpdater, ignoredPaths } = analysis;
|
|
705
|
+
const replacementTokens = [];
|
|
706
|
+
for (const path2 of targetPaths) {
|
|
707
|
+
if (ignoredPaths.has(path2)) {
|
|
708
|
+
continue;
|
|
569
709
|
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
{
|
|
576
|
-
...options,
|
|
577
|
-
needEscaped: _nullishCoalesce(options.needEscaped, () => ( true))
|
|
578
|
-
}
|
|
579
|
-
);
|
|
580
|
-
} else if (p.isTemplateElement()) {
|
|
581
|
-
return replaceHandleValue(
|
|
582
|
-
p,
|
|
583
|
-
{
|
|
584
|
-
...options,
|
|
585
|
-
needEscaped: false
|
|
586
|
-
}
|
|
587
|
-
);
|
|
710
|
+
const token = replaceHandleValue(
|
|
711
|
+
path2,
|
|
712
|
+
{
|
|
713
|
+
...options,
|
|
714
|
+
needEscaped: path2.isStringLiteral() ? _nullishCoalesce(options.needEscaped, () => ( true)) : false
|
|
588
715
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
jsTokenUpdater.push(
|
|
593
|
-
...tokens
|
|
594
|
-
).filter(
|
|
595
|
-
(x) => {
|
|
596
|
-
return !ignoreFlagMap.get(x.path);
|
|
716
|
+
);
|
|
717
|
+
if (token) {
|
|
718
|
+
replacementTokens.push(token);
|
|
597
719
|
}
|
|
598
|
-
|
|
720
|
+
}
|
|
721
|
+
jsTokenUpdater.push(...replacementTokens).filter((token) => !ignoredPaths.has(token.path)).updateMagicString(ms);
|
|
599
722
|
return ms;
|
|
600
723
|
}
|
|
601
724
|
function jsHandler(rawSource, options) {
|
|
@@ -632,69 +755,69 @@ function createJsHandler(options) {
|
|
|
632
755
|
uniAppX
|
|
633
756
|
} = options;
|
|
634
757
|
function handler(rawSource, classNameSet, options2) {
|
|
635
|
-
const
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
758
|
+
const overrideOptions = _nullishCoalesce(options2, () => ( {}));
|
|
759
|
+
const resolvedOptions = _chunkUW3WHSZ5js.defuOverrideArray.call(void 0,
|
|
760
|
+
{
|
|
761
|
+
...overrideOptions,
|
|
762
|
+
classNameSet
|
|
763
|
+
},
|
|
764
|
+
{
|
|
765
|
+
classNameSet,
|
|
766
|
+
escapeMap,
|
|
767
|
+
arbitraryValues,
|
|
768
|
+
mangleContext,
|
|
769
|
+
jsPreserveClass,
|
|
770
|
+
generateMap,
|
|
771
|
+
babelParserOptions,
|
|
772
|
+
ignoreCallExpressionIdentifiers,
|
|
773
|
+
ignoreTaggedTemplateExpressionIdentifiers,
|
|
774
|
+
uniAppX
|
|
775
|
+
}
|
|
776
|
+
);
|
|
777
|
+
return jsHandler(rawSource, resolvedOptions);
|
|
648
778
|
}
|
|
649
779
|
return handler;
|
|
650
780
|
}
|
|
651
781
|
|
|
652
|
-
// src/tailwindcss/index.ts
|
|
653
|
-
var _localpkg = require('local-pkg');
|
|
654
|
-
|
|
655
|
-
// src/tailwindcss/patcher.ts
|
|
656
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
657
|
-
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
658
|
-
var _shared = require('@weapp-tailwindcss/shared');
|
|
659
|
-
var _tailwindcsspatch = require('tailwindcss-patch');
|
|
660
|
-
function createTailwindcssPatcher(options) {
|
|
661
|
-
const { basedir, cacheDir, supportCustomLengthUnitsPatch, tailwindcss, tailwindcssPatcherOptions } = options || {};
|
|
662
|
-
const cache = {};
|
|
663
|
-
if (cacheDir) {
|
|
664
|
-
if (_path2.default.isAbsolute(cacheDir)) {
|
|
665
|
-
cache.dir = cacheDir;
|
|
666
|
-
} else if (basedir) {
|
|
667
|
-
cache.dir = _path2.default.resolve(basedir, cacheDir);
|
|
668
|
-
} else {
|
|
669
|
-
cache.dir = _path2.default.resolve(_process2.default.cwd(), cacheDir);
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
return new (0, _tailwindcsspatch.TailwindcssPatcher)(_shared.defuOverrideArray.call(void 0,
|
|
673
|
-
tailwindcssPatcherOptions,
|
|
674
|
-
{
|
|
675
|
-
cache,
|
|
676
|
-
patch: {
|
|
677
|
-
basedir,
|
|
678
|
-
applyPatches: {
|
|
679
|
-
exportContext: true,
|
|
680
|
-
extendLengthUnits: supportCustomLengthUnitsPatch
|
|
681
|
-
},
|
|
682
|
-
tailwindcss,
|
|
683
|
-
resolve: {
|
|
684
|
-
paths: [
|
|
685
|
-
_chunkO3G5TVNDjs.importMetaUrl
|
|
686
|
-
]
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
));
|
|
691
|
-
}
|
|
692
|
-
|
|
693
782
|
// src/wxml/utils.ts
|
|
694
783
|
var _types = require('@babel/types'); var t = _interopRequireWildcard(_types);
|
|
695
784
|
var _htmlparser2 = require('htmlparser2');
|
|
696
785
|
|
|
697
786
|
|
|
787
|
+
// src/wxml/whitespace.ts
|
|
788
|
+
var WHITESPACE_CODES = /* @__PURE__ */ new Set([
|
|
789
|
+
9,
|
|
790
|
+
// \t
|
|
791
|
+
10,
|
|
792
|
+
// \n
|
|
793
|
+
11,
|
|
794
|
+
// \v
|
|
795
|
+
12,
|
|
796
|
+
// \f
|
|
797
|
+
13,
|
|
798
|
+
// \r
|
|
799
|
+
32,
|
|
800
|
+
// space
|
|
801
|
+
160,
|
|
802
|
+
// \u00A0
|
|
803
|
+
65279
|
|
804
|
+
// \uFEFF
|
|
805
|
+
]);
|
|
806
|
+
function isWhitespace(char) {
|
|
807
|
+
if (char.length === 0) {
|
|
808
|
+
return false;
|
|
809
|
+
}
|
|
810
|
+
return WHITESPACE_CODES.has(char.charCodeAt(0));
|
|
811
|
+
}
|
|
812
|
+
function isAllWhitespace(value) {
|
|
813
|
+
for (let i = 0; i < value.length; i++) {
|
|
814
|
+
if (!WHITESPACE_CODES.has(value.charCodeAt(i))) {
|
|
815
|
+
return false;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
return true;
|
|
819
|
+
}
|
|
820
|
+
|
|
698
821
|
// src/wxml/Tokenizer.ts
|
|
699
822
|
var Tokenizer = class {
|
|
700
823
|
constructor() {
|
|
@@ -703,7 +826,7 @@ var Tokenizer = class {
|
|
|
703
826
|
processChar(char, index) {
|
|
704
827
|
switch (this.state) {
|
|
705
828
|
case 0 /* START */:
|
|
706
|
-
if (
|
|
829
|
+
if (isWhitespace(char)) {
|
|
707
830
|
} else if (char === "{") {
|
|
708
831
|
this.state = 2 /* OPEN_BRACE */;
|
|
709
832
|
this.bufferStartIndex = index;
|
|
@@ -717,7 +840,7 @@ var Tokenizer = class {
|
|
|
717
840
|
}
|
|
718
841
|
break;
|
|
719
842
|
case 1 /* TEXT */:
|
|
720
|
-
if (
|
|
843
|
+
if (isWhitespace(char)) {
|
|
721
844
|
this.tokens.push({ start: this.bufferStartIndex, end: index, value: this.buffer, expressions: this.expressions });
|
|
722
845
|
this.buffer = "";
|
|
723
846
|
this.expressions = [];
|
|
@@ -759,7 +882,7 @@ var Tokenizer = class {
|
|
|
759
882
|
}
|
|
760
883
|
break;
|
|
761
884
|
case 4 /* BRACES_COMPLETE */:
|
|
762
|
-
if (
|
|
885
|
+
if (isWhitespace(char)) {
|
|
763
886
|
this.tokens.push({
|
|
764
887
|
start: this.bufferStartIndex,
|
|
765
888
|
end: index,
|
|
@@ -797,9 +920,9 @@ var Tokenizer = class {
|
|
|
797
920
|
expressions: this.expressions
|
|
798
921
|
});
|
|
799
922
|
}
|
|
800
|
-
const
|
|
923
|
+
const tokens = this.tokens;
|
|
801
924
|
this.reset();
|
|
802
|
-
return
|
|
925
|
+
return tokens;
|
|
803
926
|
}
|
|
804
927
|
reset() {
|
|
805
928
|
this.state = 0 /* START */;
|
|
@@ -810,9 +933,6 @@ var Tokenizer = class {
|
|
|
810
933
|
this.expressionStartIndex = 0;
|
|
811
934
|
this.expressions = [];
|
|
812
935
|
}
|
|
813
|
-
isWhitespace(char) {
|
|
814
|
-
return /\s/.test(char);
|
|
815
|
-
}
|
|
816
936
|
};
|
|
817
937
|
|
|
818
938
|
// src/wxml/utils.ts
|
|
@@ -831,7 +951,7 @@ function generateCode(match, options = {}) {
|
|
|
831
951
|
if (t.isMemberExpression(path2.parent)) {
|
|
832
952
|
return;
|
|
833
953
|
}
|
|
834
|
-
if (t.isBinaryExpression(path2.parent) && (t.isConditionalExpression(_optionalChain([path2, 'access',
|
|
954
|
+
if (t.isBinaryExpression(path2.parent) && (t.isConditionalExpression(_optionalChain([path2, 'access', _6 => _6.parentPath, 'optionalAccess', _7 => _7.parent])) || t.isLogicalExpression(_optionalChain([path2, 'access', _8 => _8.parentPath, 'optionalAccess', _9 => _9.parent])))) {
|
|
835
955
|
return;
|
|
836
956
|
}
|
|
837
957
|
jsTokenUpdater.addToken(
|
|
@@ -861,7 +981,7 @@ function handleEachClassFragment(ms, tokens, options = {}) {
|
|
|
861
981
|
for (const token of tokens) {
|
|
862
982
|
if (token.start > previousEnd) {
|
|
863
983
|
const gap = ms.slice(previousEnd, token.start);
|
|
864
|
-
if (gap
|
|
984
|
+
if (isAllWhitespace(gap)) {
|
|
865
985
|
ms.update(previousEnd, token.start, _chunkPLMJW644js.replaceWxml.call(void 0, gap, {
|
|
866
986
|
keepEOL: false,
|
|
867
987
|
escapeMap: options.escapeMap,
|
|
@@ -909,7 +1029,7 @@ function handleEachClassFragment(ms, tokens, options = {}) {
|
|
|
909
1029
|
const lastToken = tokens[tokens.length - 1];
|
|
910
1030
|
if (lastToken.end < ms.original.length) {
|
|
911
1031
|
const gap = ms.slice(lastToken.end, ms.original.length);
|
|
912
|
-
if (gap
|
|
1032
|
+
if (isAllWhitespace(gap)) {
|
|
913
1033
|
ms.update(lastToken.end, ms.original.length, _chunkPLMJW644js.replaceWxml.call(void 0, gap, {
|
|
914
1034
|
keepEOL: false,
|
|
915
1035
|
escapeMap: options.escapeMap,
|
|
@@ -933,10 +1053,15 @@ function regTest(reg, str) {
|
|
|
933
1053
|
}
|
|
934
1054
|
function isPropsMatch(props, attr) {
|
|
935
1055
|
if (Array.isArray(props)) {
|
|
1056
|
+
let lowerAttr;
|
|
936
1057
|
for (const prop of props) {
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
1058
|
+
if (typeof prop === "string") {
|
|
1059
|
+
_nullishCoalesce(lowerAttr, () => ( (lowerAttr = attr.toLowerCase())));
|
|
1060
|
+
if (prop.toLowerCase() === lowerAttr) {
|
|
1061
|
+
return true;
|
|
1062
|
+
}
|
|
1063
|
+
} else if (regTest(prop, attr)) {
|
|
1064
|
+
return true;
|
|
940
1065
|
}
|
|
941
1066
|
}
|
|
942
1067
|
return false;
|
|
@@ -954,6 +1079,23 @@ async function customTemplateHandler(rawSource, options) {
|
|
|
954
1079
|
runtimeSet,
|
|
955
1080
|
jsHandler: jsHandler2
|
|
956
1081
|
} = _nullishCoalesce(options, () => ( {}));
|
|
1082
|
+
const wildcardAttributeRules = [];
|
|
1083
|
+
const tagAttributeRuleMap = /* @__PURE__ */ new Map();
|
|
1084
|
+
const regexpAttributeRules = [];
|
|
1085
|
+
for (const [selector, props] of customAttributesEntities) {
|
|
1086
|
+
if (selector === "*") {
|
|
1087
|
+
wildcardAttributeRules.push(props);
|
|
1088
|
+
} else if (typeof selector === "string") {
|
|
1089
|
+
const list = tagAttributeRuleMap.get(selector);
|
|
1090
|
+
if (list) {
|
|
1091
|
+
list.push(props);
|
|
1092
|
+
} else {
|
|
1093
|
+
tagAttributeRuleMap.set(selector, [props]);
|
|
1094
|
+
}
|
|
1095
|
+
} else {
|
|
1096
|
+
regexpAttributeRules.push([selector, props]);
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
957
1099
|
const s = new (0, _magicstring2.default)(rawSource);
|
|
958
1100
|
let tag = "";
|
|
959
1101
|
const wxsArray = [];
|
|
@@ -964,7 +1106,13 @@ async function customTemplateHandler(rawSource, options) {
|
|
|
964
1106
|
},
|
|
965
1107
|
onattribute(name, value, quote) {
|
|
966
1108
|
if (value) {
|
|
967
|
-
|
|
1109
|
+
const lowerName = name.toLowerCase();
|
|
1110
|
+
let updated = false;
|
|
1111
|
+
const update = () => {
|
|
1112
|
+
if (updated) {
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
updated = true;
|
|
968
1116
|
s.update(
|
|
969
1117
|
parser.startIndex + name.length + 2,
|
|
970
1118
|
// !important
|
|
@@ -978,21 +1126,34 @@ async function customTemplateHandler(rawSource, options) {
|
|
|
978
1126
|
})
|
|
979
1127
|
);
|
|
980
1128
|
};
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
update2();
|
|
1129
|
+
if (!disabledDefaultTemplateHandler && (lowerName === "class" || lowerName === "hover-class" || lowerName === "virtualhostclass")) {
|
|
1130
|
+
update();
|
|
984
1131
|
}
|
|
985
|
-
|
|
986
|
-
|
|
1132
|
+
if (!updated) {
|
|
1133
|
+
for (const props of wildcardAttributeRules) {
|
|
987
1134
|
if (isPropsMatch(props, name)) {
|
|
988
|
-
|
|
1135
|
+
update();
|
|
1136
|
+
break;
|
|
989
1137
|
}
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
if (!updated) {
|
|
1141
|
+
const tagRules = tagAttributeRuleMap.get(tag);
|
|
1142
|
+
if (tagRules) {
|
|
1143
|
+
for (const props of tagRules) {
|
|
1144
|
+
if (isPropsMatch(props, name)) {
|
|
1145
|
+
update();
|
|
1146
|
+
break;
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
if (!updated) {
|
|
1152
|
+
for (const [selector, props] of regexpAttributeRules) {
|
|
1153
|
+
if (regTest(selector, tag) && isPropsMatch(props, name)) {
|
|
1154
|
+
update();
|
|
1155
|
+
break;
|
|
993
1156
|
}
|
|
994
|
-
} else if (regTest(t2, tag) && isPropsMatch(props, name)) {
|
|
995
|
-
update2();
|
|
996
1157
|
}
|
|
997
1158
|
}
|
|
998
1159
|
}
|
|
@@ -1024,81 +1185,35 @@ async function customTemplateHandler(rawSource, options) {
|
|
|
1024
1185
|
}
|
|
1025
1186
|
function createTemplateHandler(options = {}) {
|
|
1026
1187
|
return (rawSource, opt = {}) => {
|
|
1027
|
-
return customTemplateHandler(rawSource,
|
|
1188
|
+
return customTemplateHandler(rawSource, _chunkUW3WHSZ5js.defuOverrideArray.call(void 0, opt, options));
|
|
1028
1189
|
};
|
|
1029
1190
|
}
|
|
1030
1191
|
|
|
1031
|
-
// src/context/
|
|
1032
|
-
|
|
1033
|
-
error: 0,
|
|
1034
|
-
warn: 1,
|
|
1035
|
-
info: 3,
|
|
1036
|
-
silent: -999
|
|
1037
|
-
};
|
|
1038
|
-
function getCompilerContext(opts) {
|
|
1039
|
-
const ctx = _chunkQXQOYYCRjs.defuOverrideArray.call(void 0,
|
|
1040
|
-
opts,
|
|
1041
|
-
_chunkA75TB5TEjs.getDefaultOptions.call(void 0, ),
|
|
1042
|
-
{}
|
|
1043
|
-
);
|
|
1044
|
-
ctx.escapeMap = ctx.customReplaceDictionary;
|
|
1192
|
+
// src/context/handlers.ts
|
|
1193
|
+
function createHandlersFromContext(ctx, mangleContext, customAttributesEntities, cssCalcOptions) {
|
|
1045
1194
|
const {
|
|
1046
1195
|
cssPreflight,
|
|
1047
1196
|
customRuleCallback,
|
|
1048
1197
|
cssPreflightRange,
|
|
1049
|
-
|
|
1050
|
-
supportCustomLengthUnitsPatch,
|
|
1051
|
-
arbitraryValues,
|
|
1198
|
+
escapeMap,
|
|
1052
1199
|
cssChildCombinatorReplaceValue,
|
|
1053
|
-
inlineWxs,
|
|
1054
1200
|
injectAdditionalCssVarScope,
|
|
1055
|
-
jsPreserveClass,
|
|
1056
|
-
disabledDefaultTemplateHandler,
|
|
1057
1201
|
cssSelectorReplacement,
|
|
1058
1202
|
rem2rpx,
|
|
1059
|
-
cache,
|
|
1060
|
-
babelParserOptions,
|
|
1061
1203
|
postcssOptions,
|
|
1062
1204
|
cssRemoveProperty,
|
|
1063
1205
|
cssRemoveHoverPseudoClass,
|
|
1064
|
-
escapeMap,
|
|
1065
|
-
mangle,
|
|
1066
|
-
tailwindcssBasedir,
|
|
1067
|
-
appType,
|
|
1068
|
-
ignoreCallExpressionIdentifiers,
|
|
1069
|
-
ignoreTaggedTemplateExpressionIdentifiers,
|
|
1070
1206
|
cssPresetEnv,
|
|
1071
|
-
tailwindcss,
|
|
1072
|
-
tailwindcssPatcherOptions,
|
|
1073
1207
|
uniAppX,
|
|
1074
|
-
cssEntries,
|
|
1075
|
-
cssCalc,
|
|
1076
1208
|
px2rpx,
|
|
1077
|
-
|
|
1209
|
+
arbitraryValues,
|
|
1210
|
+
jsPreserveClass,
|
|
1211
|
+
babelParserOptions,
|
|
1212
|
+
ignoreCallExpressionIdentifiers,
|
|
1213
|
+
ignoreTaggedTemplateExpressionIdentifiers,
|
|
1214
|
+
inlineWxs,
|
|
1215
|
+
disabledDefaultTemplateHandler
|
|
1078
1216
|
} = ctx;
|
|
1079
|
-
_logger.logger.level = _nullishCoalesce(loggerLevelMap[logLevel], () => ( loggerLevelMap.info));
|
|
1080
|
-
const twPatcher = createTailwindcssPatcher(
|
|
1081
|
-
{
|
|
1082
|
-
basedir: tailwindcssBasedir,
|
|
1083
|
-
cacheDir: appType === "mpx" ? "node_modules/tailwindcss-patch/.cache" : void 0,
|
|
1084
|
-
supportCustomLengthUnitsPatch: _nullishCoalesce(supportCustomLengthUnitsPatch, () => ( true)),
|
|
1085
|
-
tailwindcss: _chunkQXQOYYCRjs.defuOverrideArray.call(void 0,
|
|
1086
|
-
tailwindcss,
|
|
1087
|
-
{
|
|
1088
|
-
v4: {
|
|
1089
|
-
base: tailwindcssBasedir,
|
|
1090
|
-
cssEntries
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
),
|
|
1094
|
-
tailwindcssPatcherOptions
|
|
1095
|
-
}
|
|
1096
|
-
);
|
|
1097
|
-
_logger.logger.success(`\u5F53\u524D\u4F7F\u7528 ${_logger.pc.cyanBright("Tailwind CSS")} \u7248\u672C\u4E3A: ${_logger.pc.underline(_logger.pc.bold(_logger.pc.green(twPatcher.packageInfo.version)))}`);
|
|
1098
|
-
const cssCalcOptions = _nullishCoalesce(cssCalc, () => ( twPatcher.majorVersion === 4));
|
|
1099
|
-
const customAttributesEntities = _chunkQXQOYYCRjs.isMap.call(void 0, customAttributes) ? [...customAttributes.entries()] : Object.entries(customAttributes);
|
|
1100
|
-
const { initMangle, mangleContext, setMangleRuntimeSet } = _mangle.useMangleStore.call(void 0, );
|
|
1101
|
-
initMangle(mangle);
|
|
1102
1217
|
const styleHandler = _postcss.createStyleHandler.call(void 0, {
|
|
1103
1218
|
cssPreflight,
|
|
1104
1219
|
customRuleCallback,
|
|
@@ -1136,11 +1251,121 @@ function getCompilerContext(opts) {
|
|
|
1136
1251
|
jsHandler: jsHandler2,
|
|
1137
1252
|
disabledDefaultTemplateHandler
|
|
1138
1253
|
});
|
|
1254
|
+
return {
|
|
1255
|
+
styleHandler,
|
|
1256
|
+
jsHandler: jsHandler2,
|
|
1257
|
+
templateHandler
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
// src/context/logger.ts
|
|
1262
|
+
|
|
1263
|
+
var loggerLevelMap = {
|
|
1264
|
+
error: 0,
|
|
1265
|
+
warn: 1,
|
|
1266
|
+
info: 3,
|
|
1267
|
+
silent: -999
|
|
1268
|
+
};
|
|
1269
|
+
function applyLoggerLevel(logLevel) {
|
|
1270
|
+
_logger.logger.level = _nullishCoalesce(loggerLevelMap[_nullishCoalesce(logLevel, () => ( "info"))], () => ( loggerLevelMap.info));
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
// src/tailwindcss/index.ts
|
|
1274
|
+
var _localpkg = require('local-pkg');
|
|
1275
|
+
|
|
1276
|
+
// src/tailwindcss/patcher.ts
|
|
1277
|
+
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
1278
|
+
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
1279
|
+
var _shared = require('@weapp-tailwindcss/shared');
|
|
1280
|
+
var _tailwindcsspatch = require('tailwindcss-patch');
|
|
1281
|
+
function createTailwindcssPatcher(options) {
|
|
1282
|
+
const { basedir, cacheDir, supportCustomLengthUnitsPatch, tailwindcss, tailwindcssPatcherOptions } = options || {};
|
|
1283
|
+
const cache = {};
|
|
1284
|
+
if (cacheDir) {
|
|
1285
|
+
if (_path2.default.isAbsolute(cacheDir)) {
|
|
1286
|
+
cache.dir = cacheDir;
|
|
1287
|
+
} else if (basedir) {
|
|
1288
|
+
cache.dir = _path2.default.resolve(basedir, cacheDir);
|
|
1289
|
+
} else {
|
|
1290
|
+
cache.dir = _path2.default.resolve(_process2.default.cwd(), cacheDir);
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
return new (0, _tailwindcsspatch.TailwindcssPatcher)(_shared.defuOverrideArray.call(void 0,
|
|
1294
|
+
tailwindcssPatcherOptions,
|
|
1295
|
+
{
|
|
1296
|
+
cache,
|
|
1297
|
+
patch: {
|
|
1298
|
+
basedir,
|
|
1299
|
+
applyPatches: {
|
|
1300
|
+
exportContext: true,
|
|
1301
|
+
extendLengthUnits: supportCustomLengthUnitsPatch
|
|
1302
|
+
},
|
|
1303
|
+
tailwindcss,
|
|
1304
|
+
resolve: {
|
|
1305
|
+
paths: [
|
|
1306
|
+
_chunkRBRSMHFSjs.importMetaUrl
|
|
1307
|
+
]
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
));
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
// src/context/tailwindcss.ts
|
|
1315
|
+
function createTailwindcssPatcherFromContext(ctx) {
|
|
1316
|
+
const {
|
|
1317
|
+
tailwindcssBasedir,
|
|
1318
|
+
supportCustomLengthUnitsPatch,
|
|
1319
|
+
tailwindcss,
|
|
1320
|
+
tailwindcssPatcherOptions,
|
|
1321
|
+
cssEntries,
|
|
1322
|
+
appType
|
|
1323
|
+
} = ctx;
|
|
1324
|
+
return createTailwindcssPatcher(
|
|
1325
|
+
{
|
|
1326
|
+
basedir: tailwindcssBasedir,
|
|
1327
|
+
cacheDir: appType === "mpx" ? "node_modules/tailwindcss-patch/.cache" : void 0,
|
|
1328
|
+
supportCustomLengthUnitsPatch: _nullishCoalesce(supportCustomLengthUnitsPatch, () => ( true)),
|
|
1329
|
+
tailwindcss: _chunkUW3WHSZ5js.defuOverrideArray.call(void 0,
|
|
1330
|
+
tailwindcss,
|
|
1331
|
+
{
|
|
1332
|
+
v4: {
|
|
1333
|
+
base: tailwindcssBasedir,
|
|
1334
|
+
cssEntries
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
),
|
|
1338
|
+
tailwindcssPatcherOptions
|
|
1339
|
+
}
|
|
1340
|
+
);
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
// src/context/index.ts
|
|
1344
|
+
function getCompilerContext(opts) {
|
|
1345
|
+
const ctx = _chunkUW3WHSZ5js.defuOverrideArray.call(void 0,
|
|
1346
|
+
opts,
|
|
1347
|
+
_chunkFOSGDQZ7js.getDefaultOptions.call(void 0, ),
|
|
1348
|
+
{}
|
|
1349
|
+
);
|
|
1350
|
+
ctx.escapeMap = ctx.customReplaceDictionary;
|
|
1351
|
+
applyLoggerLevel(ctx.logLevel);
|
|
1352
|
+
const twPatcher = createTailwindcssPatcherFromContext(ctx);
|
|
1353
|
+
_logger.logger.success(`\u5F53\u524D\u4F7F\u7528 ${_logger.pc.cyanBright("Tailwind CSS")} \u7248\u672C\u4E3A: ${_logger.pc.underline(_logger.pc.bold(_logger.pc.green(twPatcher.packageInfo.version)))}`);
|
|
1354
|
+
const cssCalcOptions = _nullishCoalesce(ctx.cssCalc, () => ( twPatcher.majorVersion === 4));
|
|
1355
|
+
const customAttributesEntities = toCustomAttributesEntities(ctx.customAttributes);
|
|
1356
|
+
const { initMangle, mangleContext, setMangleRuntimeSet } = _mangle.useMangleStore.call(void 0, );
|
|
1357
|
+
initMangle(ctx.mangle);
|
|
1358
|
+
const { styleHandler, jsHandler: jsHandler2, templateHandler } = createHandlersFromContext(
|
|
1359
|
+
ctx,
|
|
1360
|
+
mangleContext,
|
|
1361
|
+
customAttributesEntities,
|
|
1362
|
+
cssCalcOptions
|
|
1363
|
+
);
|
|
1139
1364
|
ctx.styleHandler = styleHandler;
|
|
1140
1365
|
ctx.jsHandler = jsHandler2;
|
|
1141
1366
|
ctx.templateHandler = templateHandler;
|
|
1142
1367
|
ctx.setMangleRuntimeSet = setMangleRuntimeSet;
|
|
1143
|
-
ctx.cache = initializeCache(cache);
|
|
1368
|
+
ctx.cache = initializeCache(ctx.cache);
|
|
1144
1369
|
ctx.twPatcher = twPatcher;
|
|
1145
1370
|
return ctx;
|
|
1146
1371
|
}
|