weapp-tailwindcss 4.3.3 → 4.4.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-2NRTWL47.js +43 -0
- package/dist/{chunk-3KXFKRIX.mjs → chunk-D25XJJMP.mjs} +593 -316
- package/dist/chunk-D2AKCBDU.mjs +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-3KMEJ2LM.js → chunk-GQAB52GE.js} +594 -317
- package/dist/chunk-H2Y5VNOJ.js +122 -0
- package/dist/chunk-H4JTYYOI.mjs +43 -0
- package/dist/{chunk-5BTC4YQI.mjs → chunk-IHKVNALD.mjs} +29 -38
- package/dist/{chunk-M7PVNKCH.mjs → chunk-L3HOZDIV.mjs} +45 -57
- package/dist/{chunk-GFQ2R7SX.mjs → chunk-NDHL3P32.mjs} +127 -129
- package/dist/{chunk-JDLLZFZX.js → chunk-QXCC745G.js} +46 -58
- package/dist/{chunk-O3G5TVND.js → chunk-RBRSMHFS.js} +1 -1
- package/dist/chunk-UW3WHSZ5.js +39 -0
- package/dist/{chunk-L7VNJFIK.js → chunk-VN2BU7ON.js} +129 -131
- 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.d.mts +1 -1
- package/dist/css-macro.d.ts +1 -1
- package/dist/css-macro.js +31 -19
- package/dist/css-macro.mjs +30 -18
- 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 +5 -6
- 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,17 +3,15 @@ import {
|
|
|
3
3
|
} from "./chunk-Q67IXIAH.mjs";
|
|
4
4
|
import {
|
|
5
5
|
getDefaultOptions
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-IHKVNALD.mjs";
|
|
7
7
|
import {
|
|
8
8
|
defuOverrideArray,
|
|
9
|
-
isMap
|
|
10
|
-
|
|
11
|
-
} from "./chunk-Y5AFAYKI.mjs";
|
|
9
|
+
isMap
|
|
10
|
+
} from "./chunk-ZNKIYZRQ.mjs";
|
|
12
11
|
|
|
13
12
|
// src/context/index.ts
|
|
14
|
-
import { logger, pc } from "@weapp-tailwindcss/logger";
|
|
13
|
+
import { logger as logger2, pc } from "@weapp-tailwindcss/logger";
|
|
15
14
|
import { useMangleStore } from "@weapp-tailwindcss/mangle";
|
|
16
|
-
import { createStyleHandler } from "@weapp-tailwindcss/postcss";
|
|
17
15
|
|
|
18
16
|
// src/cache/index.ts
|
|
19
17
|
import { LRUCache } from "lru-cache";
|
|
@@ -25,6 +23,9 @@ function md5Hash(data) {
|
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
// src/cache/index.ts
|
|
26
|
+
function isProcessResult(value) {
|
|
27
|
+
return typeof value === "object" && value !== null && "result" in value;
|
|
28
|
+
}
|
|
28
29
|
function createCache(options) {
|
|
29
30
|
const disabled = options === false;
|
|
30
31
|
const hashMap = /* @__PURE__ */ new Map();
|
|
@@ -34,7 +35,7 @@ function createCache(options) {
|
|
|
34
35
|
ttl: 0,
|
|
35
36
|
ttlAutopurge: false
|
|
36
37
|
});
|
|
37
|
-
|
|
38
|
+
const cache = {
|
|
38
39
|
hashMap,
|
|
39
40
|
instance,
|
|
40
41
|
hasHashKey(key) {
|
|
@@ -56,47 +57,60 @@ function createCache(options) {
|
|
|
56
57
|
return md5Hash(message);
|
|
57
58
|
},
|
|
58
59
|
calcHashValueChanged(key, hash) {
|
|
59
|
-
const hit =
|
|
60
|
+
const hit = hashMap.get(key);
|
|
60
61
|
if (hit) {
|
|
61
|
-
|
|
62
|
-
// new file should be changed
|
|
62
|
+
hashMap.set(key, {
|
|
63
63
|
changed: hash !== hit.hash,
|
|
64
|
-
// new hash
|
|
65
64
|
hash
|
|
66
65
|
});
|
|
67
66
|
} else {
|
|
68
|
-
|
|
69
|
-
// new file should be changed
|
|
67
|
+
hashMap.set(key, {
|
|
70
68
|
changed: true,
|
|
71
69
|
hash
|
|
72
70
|
});
|
|
73
71
|
}
|
|
74
|
-
return
|
|
72
|
+
return cache;
|
|
75
73
|
},
|
|
76
74
|
has(key) {
|
|
77
75
|
return instance.has(key);
|
|
78
76
|
},
|
|
79
|
-
async process(
|
|
77
|
+
async process({
|
|
78
|
+
key,
|
|
79
|
+
hashKey,
|
|
80
|
+
rawSource,
|
|
81
|
+
hash,
|
|
82
|
+
resolveCache,
|
|
83
|
+
transform,
|
|
84
|
+
onCacheHit
|
|
85
|
+
}) {
|
|
80
86
|
if (disabled) {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
87
|
+
const value2 = await transform();
|
|
88
|
+
return isProcessResult(value2) ? value2.result : value2;
|
|
89
|
+
}
|
|
90
|
+
const cacheHashKey = hashKey ?? key;
|
|
91
|
+
let hasChanged = true;
|
|
92
|
+
if (hash != null || rawSource != null) {
|
|
93
|
+
const nextHash = hash ?? cache.computeHash(rawSource);
|
|
94
|
+
cache.calcHashValueChanged(cacheHashKey, nextHash);
|
|
95
|
+
const entry = cache.getHashValue(cacheHashKey);
|
|
96
|
+
hasChanged = entry?.changed ?? true;
|
|
97
|
+
}
|
|
98
|
+
const readCache = resolveCache ?? (() => cache.get(key));
|
|
99
|
+
if (!hasChanged) {
|
|
100
|
+
const cached = readCache();
|
|
101
|
+
if (cached !== void 0) {
|
|
102
|
+
await onCacheHit?.(cached);
|
|
103
|
+
return cached;
|
|
96
104
|
}
|
|
97
105
|
}
|
|
106
|
+
const value = await transform();
|
|
107
|
+
const normalized = isProcessResult(value) ? value : { result: value };
|
|
108
|
+
const stored = normalized.cacheValue ?? normalized.result;
|
|
109
|
+
cache.set(key, stored);
|
|
110
|
+
return normalized.result;
|
|
98
111
|
}
|
|
99
112
|
};
|
|
113
|
+
return cache;
|
|
100
114
|
}
|
|
101
115
|
function initializeCache(cacheConfig) {
|
|
102
116
|
if (typeof cacheConfig === "boolean" || cacheConfig === void 0) {
|
|
@@ -105,6 +119,19 @@ function initializeCache(cacheConfig) {
|
|
|
105
119
|
return cacheConfig;
|
|
106
120
|
}
|
|
107
121
|
|
|
122
|
+
// src/context/custom-attributes.ts
|
|
123
|
+
function toCustomAttributesEntities(customAttributes) {
|
|
124
|
+
if (isMap(customAttributes)) {
|
|
125
|
+
return [
|
|
126
|
+
...customAttributes.entries()
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
return Object.entries(customAttributes);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/context/handlers.ts
|
|
133
|
+
import { createStyleHandler } from "@weapp-tailwindcss/postcss";
|
|
134
|
+
|
|
108
135
|
// src/js/babel.ts
|
|
109
136
|
import { jsStringEscape as jsStringEscape2 } from "@ast-core/escape";
|
|
110
137
|
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
@@ -118,101 +145,250 @@ function _interopDefaultCompat(e) {
|
|
|
118
145
|
}
|
|
119
146
|
var traverse = _interopDefaultCompat(_babelTraverse);
|
|
120
147
|
|
|
148
|
+
// src/utils/nameMatcher.ts
|
|
149
|
+
import { escapeStringRegexp } from "@weapp-core/regex";
|
|
150
|
+
function buildFuzzyMatcher(fuzzyStrings) {
|
|
151
|
+
if (fuzzyStrings.length === 0) {
|
|
152
|
+
return void 0;
|
|
153
|
+
}
|
|
154
|
+
if (fuzzyStrings.length === 1) {
|
|
155
|
+
const [needle] = fuzzyStrings;
|
|
156
|
+
return (value) => value.includes(needle);
|
|
157
|
+
}
|
|
158
|
+
const unique = [...new Set(fuzzyStrings)];
|
|
159
|
+
const pattern = new RegExp(unique.map(escapeStringRegexp).join("|"));
|
|
160
|
+
return (value) => pattern.test(value);
|
|
161
|
+
}
|
|
162
|
+
function normaliseRegex(regex) {
|
|
163
|
+
const { source, flags } = regex;
|
|
164
|
+
if (!flags.includes("g")) {
|
|
165
|
+
return regex;
|
|
166
|
+
}
|
|
167
|
+
return new RegExp(source, flags.replace(/g/g, ""));
|
|
168
|
+
}
|
|
169
|
+
function createNameMatcher(list, { exact = false } = {}) {
|
|
170
|
+
if (!list || list.length === 0) {
|
|
171
|
+
return () => false;
|
|
172
|
+
}
|
|
173
|
+
const exactStrings = exact ? /* @__PURE__ */ new Set() : void 0;
|
|
174
|
+
const fuzzyStrings = [];
|
|
175
|
+
const regexList = [];
|
|
176
|
+
for (const item of list) {
|
|
177
|
+
if (typeof item === "string") {
|
|
178
|
+
if (exact) {
|
|
179
|
+
exactStrings.add(item);
|
|
180
|
+
} else {
|
|
181
|
+
fuzzyStrings.push(item);
|
|
182
|
+
}
|
|
183
|
+
} else {
|
|
184
|
+
regexList.push(normaliseRegex(item));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const fuzzyMatcher = exact ? void 0 : buildFuzzyMatcher(fuzzyStrings);
|
|
188
|
+
const hasRegex = regexList.length > 0;
|
|
189
|
+
return (value) => {
|
|
190
|
+
if (exact && exactStrings?.has(value)) {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
if (fuzzyMatcher?.(value)) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
if (!hasRegex) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
return regexList.some((regex) => regex.test(value));
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
121
203
|
// src/js/handlers.ts
|
|
122
204
|
import { jsStringEscape } from "@ast-core/escape";
|
|
123
|
-
import { escapeStringRegexp } from "@weapp-core/regex";
|
|
205
|
+
import { escapeStringRegexp as escapeStringRegexp2 } from "@weapp-core/regex";
|
|
124
206
|
import { splitCode } from "@weapp-tailwindcss/shared/extractors";
|
|
125
207
|
|
|
126
208
|
// src/utils/decode.ts
|
|
209
|
+
var unicodeEscapeRE = /\\u([\dA-Fa-f]{4})/g;
|
|
210
|
+
var unicodeEscapeTestRE = /\\u[\dA-Fa-f]{4}/;
|
|
211
|
+
function decodeUnicode(value) {
|
|
212
|
+
if (!unicodeEscapeTestRE.test(value)) {
|
|
213
|
+
return value;
|
|
214
|
+
}
|
|
215
|
+
return value.replace(unicodeEscapeRE, (_match, hex) => {
|
|
216
|
+
const codePoint = Number.parseInt(hex, 16);
|
|
217
|
+
return Number.isNaN(codePoint) ? _match : String.fromCharCode(codePoint);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
127
220
|
function decodeUnicode2(input) {
|
|
221
|
+
if (!unicodeEscapeTestRE.test(input)) {
|
|
222
|
+
return input;
|
|
223
|
+
}
|
|
128
224
|
try {
|
|
129
225
|
return JSON.parse(`"${input}"`);
|
|
130
226
|
} catch (_error) {
|
|
131
|
-
return input;
|
|
227
|
+
return decodeUnicode(input);
|
|
132
228
|
}
|
|
133
229
|
}
|
|
134
230
|
|
|
135
231
|
// src/js/handlers.ts
|
|
232
|
+
var patternCache = /* @__PURE__ */ new Map();
|
|
233
|
+
var replacementCacheByEscapeMap = /* @__PURE__ */ new WeakMap();
|
|
234
|
+
var defaultReplacementCache = /* @__PURE__ */ new Map();
|
|
235
|
+
function getPattern(candidate) {
|
|
236
|
+
let cached = patternCache.get(candidate);
|
|
237
|
+
if (!cached) {
|
|
238
|
+
cached = new RegExp(escapeStringRegexp2(candidate));
|
|
239
|
+
patternCache.set(candidate, cached);
|
|
240
|
+
}
|
|
241
|
+
return cached;
|
|
242
|
+
}
|
|
243
|
+
function getReplacement(candidate, escapeMap) {
|
|
244
|
+
if (!escapeMap) {
|
|
245
|
+
let cached2 = defaultReplacementCache.get(candidate);
|
|
246
|
+
if (cached2 === void 0) {
|
|
247
|
+
cached2 = replaceWxml(candidate, { escapeMap });
|
|
248
|
+
defaultReplacementCache.set(candidate, cached2);
|
|
249
|
+
}
|
|
250
|
+
return cached2;
|
|
251
|
+
}
|
|
252
|
+
let store = replacementCacheByEscapeMap.get(escapeMap);
|
|
253
|
+
if (!store) {
|
|
254
|
+
store = /* @__PURE__ */ new Map();
|
|
255
|
+
replacementCacheByEscapeMap.set(escapeMap, store);
|
|
256
|
+
}
|
|
257
|
+
let cached = store.get(candidate);
|
|
258
|
+
if (cached === void 0) {
|
|
259
|
+
cached = replaceWxml(candidate, { escapeMap });
|
|
260
|
+
store.set(candidate, cached);
|
|
261
|
+
}
|
|
262
|
+
return cached;
|
|
263
|
+
}
|
|
264
|
+
function hasIgnoreComment(node) {
|
|
265
|
+
return Array.isArray(node.leadingComments) && node.leadingComments.some((comment) => comment.value.includes("weapp-tw") && comment.value.includes("ignore"));
|
|
266
|
+
}
|
|
267
|
+
function shouldTransformClassName(candidate, {
|
|
268
|
+
alwaysEscape,
|
|
269
|
+
classNameSet,
|
|
270
|
+
jsPreserveClass
|
|
271
|
+
}) {
|
|
272
|
+
if (alwaysEscape) {
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
275
|
+
if (!classNameSet) {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
if (!classNameSet.has(candidate)) {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
return !jsPreserveClass?.(candidate);
|
|
282
|
+
}
|
|
283
|
+
function extractLiteralValue(path2, { unescapeUnicode, arbitraryValues }) {
|
|
284
|
+
const allowDoubleQuotes = arbitraryValues?.allowDoubleQuotes;
|
|
285
|
+
let offset = 0;
|
|
286
|
+
let original;
|
|
287
|
+
if (path2.isStringLiteral()) {
|
|
288
|
+
offset = 1;
|
|
289
|
+
original = path2.node.value;
|
|
290
|
+
} else if (path2.isTemplateElement()) {
|
|
291
|
+
original = path2.node.value.raw;
|
|
292
|
+
} else {
|
|
293
|
+
original = "";
|
|
294
|
+
}
|
|
295
|
+
let literal = original;
|
|
296
|
+
if (unescapeUnicode && original.includes("\\u")) {
|
|
297
|
+
literal = decodeUnicode2(original);
|
|
298
|
+
}
|
|
299
|
+
return {
|
|
300
|
+
allowDoubleQuotes,
|
|
301
|
+
literal,
|
|
302
|
+
offset,
|
|
303
|
+
original
|
|
304
|
+
};
|
|
305
|
+
}
|
|
136
306
|
function replaceHandleValue(path2, options) {
|
|
137
307
|
const {
|
|
138
|
-
classNameSet,
|
|
139
308
|
escapeMap,
|
|
140
|
-
mangleContext
|
|
141
|
-
needEscaped = false
|
|
142
|
-
jsPreserveClass,
|
|
143
|
-
arbitraryValues,
|
|
144
|
-
alwaysEscape,
|
|
145
|
-
unescapeUnicode
|
|
309
|
+
mangleContext,
|
|
310
|
+
needEscaped = false
|
|
146
311
|
} = options;
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
let rawStr = str;
|
|
151
|
-
let needUpdate = false;
|
|
152
|
-
if (unescapeUnicode && rawStr.includes("\\u")) {
|
|
153
|
-
rawStr = decodeUnicode2(rawStr);
|
|
312
|
+
const { classNameSet, alwaysEscape } = options;
|
|
313
|
+
if (!alwaysEscape && (!classNameSet || classNameSet.size === 0)) {
|
|
314
|
+
return void 0;
|
|
154
315
|
}
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
316
|
+
const { literal, original, allowDoubleQuotes, offset } = extractLiteralValue(path2, options);
|
|
317
|
+
if (hasIgnoreComment(path2.node)) {
|
|
318
|
+
return void 0;
|
|
319
|
+
}
|
|
320
|
+
const candidates = splitCode(literal, allowDoubleQuotes);
|
|
321
|
+
if (candidates.length === 0) {
|
|
322
|
+
return void 0;
|
|
323
|
+
}
|
|
324
|
+
let transformed = literal;
|
|
325
|
+
let mutated = false;
|
|
326
|
+
let normalised = false;
|
|
327
|
+
for (const candidate of candidates) {
|
|
328
|
+
if (!shouldTransformClassName(candidate, options)) {
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (mangleContext && !normalised) {
|
|
332
|
+
const mangled = mangleContext.jsHandler(transformed);
|
|
333
|
+
if (mangled !== transformed) {
|
|
334
|
+
transformed = mangled;
|
|
335
|
+
mutated = true;
|
|
174
336
|
}
|
|
337
|
+
normalised = true;
|
|
175
338
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
value,
|
|
186
|
-
path: path2
|
|
187
|
-
};
|
|
339
|
+
if (!transformed.includes(candidate)) {
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
const pattern = getPattern(candidate);
|
|
343
|
+
const replacement = getReplacement(candidate, escapeMap);
|
|
344
|
+
const replaced = transformed.replace(pattern, replacement);
|
|
345
|
+
if (replaced !== transformed) {
|
|
346
|
+
transformed = replaced;
|
|
347
|
+
mutated = true;
|
|
188
348
|
}
|
|
189
349
|
}
|
|
350
|
+
const node = path2.node;
|
|
351
|
+
if (!mutated || typeof node.start !== "number" || typeof node.end !== "number") {
|
|
352
|
+
return void 0;
|
|
353
|
+
}
|
|
354
|
+
const start = node.start + offset;
|
|
355
|
+
const end = node.end - offset;
|
|
356
|
+
if (start >= end || transformed === original) {
|
|
357
|
+
return void 0;
|
|
358
|
+
}
|
|
359
|
+
const value = needEscaped ? jsStringEscape(transformed) : transformed;
|
|
360
|
+
return {
|
|
361
|
+
start,
|
|
362
|
+
end,
|
|
363
|
+
value,
|
|
364
|
+
path: path2
|
|
365
|
+
};
|
|
190
366
|
}
|
|
191
367
|
|
|
192
368
|
// src/js/JsTokenUpdater.ts
|
|
193
369
|
var JsTokenUpdater = class {
|
|
194
370
|
constructor({ value } = {}) {
|
|
195
|
-
this.
|
|
371
|
+
this.tokens = value ? [...value] : [];
|
|
196
372
|
}
|
|
197
373
|
addToken(token) {
|
|
198
374
|
if (token) {
|
|
199
|
-
this.
|
|
375
|
+
this.tokens.push(token);
|
|
200
376
|
}
|
|
201
377
|
}
|
|
202
378
|
push(...args) {
|
|
203
|
-
this.
|
|
379
|
+
this.tokens.push(...args);
|
|
204
380
|
return this;
|
|
205
381
|
}
|
|
206
382
|
map(callbackfn) {
|
|
207
|
-
this.
|
|
383
|
+
this.tokens = this.tokens.map(callbackfn);
|
|
208
384
|
return this;
|
|
209
385
|
}
|
|
210
386
|
filter(callbackfn) {
|
|
211
|
-
this.
|
|
387
|
+
this.tokens = this.tokens.filter(callbackfn);
|
|
212
388
|
return this;
|
|
213
389
|
}
|
|
214
390
|
updateMagicString(ms) {
|
|
215
|
-
for (const { start, end, value } of this.
|
|
391
|
+
for (const { start, end, value } of this.tokens) {
|
|
216
392
|
ms.update(start, end, value);
|
|
217
393
|
}
|
|
218
394
|
return ms;
|
|
@@ -220,13 +396,14 @@ var JsTokenUpdater = class {
|
|
|
220
396
|
};
|
|
221
397
|
|
|
222
398
|
// src/js/NodePathWalker.ts
|
|
223
|
-
var walkedBindingWeakMap = /* @__PURE__ */ new WeakMap();
|
|
224
399
|
var NodePathWalker = class {
|
|
225
400
|
constructor({ ignoreCallExpressionIdentifiers, callback } = {}) {
|
|
226
401
|
this.ignoreCallExpressionIdentifiers = ignoreCallExpressionIdentifiers ?? [];
|
|
227
402
|
this.callback = callback ?? (() => {
|
|
228
403
|
});
|
|
229
404
|
this.imports = /* @__PURE__ */ new Set();
|
|
405
|
+
this.visited = /* @__PURE__ */ new WeakSet();
|
|
406
|
+
this.isIgnoredCallIdentifier = createNameMatcher(this.ignoreCallExpressionIdentifiers, { exact: true });
|
|
230
407
|
}
|
|
231
408
|
walkVariableDeclarator(path2) {
|
|
232
409
|
const init = path2.get("init");
|
|
@@ -273,10 +450,10 @@ var NodePathWalker = class {
|
|
|
273
450
|
}
|
|
274
451
|
}
|
|
275
452
|
walkNode(arg) {
|
|
276
|
-
if (
|
|
453
|
+
if (this.visited.has(arg)) {
|
|
277
454
|
return;
|
|
278
455
|
}
|
|
279
|
-
|
|
456
|
+
this.visited.add(arg);
|
|
280
457
|
if (arg.isIdentifier()) {
|
|
281
458
|
const binding = arg.scope.getBinding(arg.node.name);
|
|
282
459
|
if (binding) {
|
|
@@ -336,14 +513,11 @@ var NodePathWalker = class {
|
|
|
336
513
|
}
|
|
337
514
|
}
|
|
338
515
|
/**
|
|
339
|
-
*
|
|
340
|
-
* @param path
|
|
516
|
+
* Walk the arguments of a desired call expression so their bindings can be analysed.
|
|
341
517
|
*/
|
|
342
518
|
walkCallExpression(path2) {
|
|
343
519
|
const calleePath = path2.get("callee");
|
|
344
|
-
if (calleePath.isIdentifier() &&
|
|
345
|
-
exact: true
|
|
346
|
-
})) {
|
|
520
|
+
if (calleePath.isIdentifier() && this.isIgnoredCallIdentifier(calleePath.node.name)) {
|
|
347
521
|
for (const arg of path2.get("arguments")) {
|
|
348
522
|
this.walkNode(arg);
|
|
349
523
|
}
|
|
@@ -431,19 +605,88 @@ function isEvalPath(p) {
|
|
|
431
605
|
}
|
|
432
606
|
return false;
|
|
433
607
|
}
|
|
434
|
-
|
|
608
|
+
function createEvalReplacementToken(path2, updated) {
|
|
609
|
+
const node = path2.node;
|
|
610
|
+
let offset = 0;
|
|
611
|
+
let original;
|
|
612
|
+
if (path2.isStringLiteral()) {
|
|
613
|
+
offset = 1;
|
|
614
|
+
original = path2.node.value;
|
|
615
|
+
} else if (path2.isTemplateElement()) {
|
|
616
|
+
original = path2.node.value.raw;
|
|
617
|
+
} else {
|
|
618
|
+
original = "";
|
|
619
|
+
}
|
|
620
|
+
if (typeof node.start !== "number" || typeof node.end !== "number") {
|
|
621
|
+
return void 0;
|
|
622
|
+
}
|
|
623
|
+
const start = node.start + offset;
|
|
624
|
+
const end = node.end - offset;
|
|
625
|
+
if (start >= end) {
|
|
626
|
+
return void 0;
|
|
627
|
+
}
|
|
628
|
+
if (original === updated) {
|
|
629
|
+
return void 0;
|
|
630
|
+
}
|
|
631
|
+
const value = path2.isStringLiteral() ? jsStringEscape2(updated) : updated;
|
|
632
|
+
return {
|
|
633
|
+
start,
|
|
634
|
+
end,
|
|
635
|
+
value,
|
|
636
|
+
path: path2
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
function handleEvalStringLiteral(path2, options, updater) {
|
|
640
|
+
const { code } = jsHandler(path2.node.value, {
|
|
641
|
+
...options,
|
|
642
|
+
needEscaped: false,
|
|
643
|
+
generateMap: false
|
|
644
|
+
});
|
|
645
|
+
if (!code) {
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
const token = createEvalReplacementToken(path2, code);
|
|
649
|
+
if (token) {
|
|
650
|
+
updater.addToken(token);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
function handleEvalTemplateElement(path2, options, updater) {
|
|
654
|
+
const { code } = jsHandler(path2.node.value.raw, {
|
|
655
|
+
...options,
|
|
656
|
+
generateMap: false
|
|
657
|
+
});
|
|
658
|
+
if (!code) {
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
const token = createEvalReplacementToken(path2, code);
|
|
662
|
+
if (token) {
|
|
663
|
+
updater.addToken(token);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
function walkEvalExpression(path2, options, updater) {
|
|
667
|
+
path2.traverse({
|
|
668
|
+
StringLiteral(innerPath) {
|
|
669
|
+
handleEvalStringLiteral(innerPath, options, updater);
|
|
670
|
+
},
|
|
671
|
+
TemplateElement(innerPath) {
|
|
672
|
+
handleEvalTemplateElement(innerPath, options, updater);
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
}
|
|
435
676
|
function analyzeSource(ast, options) {
|
|
436
677
|
const jsTokenUpdater = new JsTokenUpdater();
|
|
678
|
+
const ignoredPaths = /* @__PURE__ */ new WeakSet();
|
|
437
679
|
const walker = new NodePathWalker(
|
|
438
680
|
{
|
|
439
681
|
ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers,
|
|
440
682
|
callback(path2) {
|
|
441
683
|
if (path2.isStringLiteral() || path2.isTemplateElement()) {
|
|
442
|
-
|
|
684
|
+
ignoredPaths.add(path2);
|
|
443
685
|
}
|
|
444
686
|
}
|
|
445
687
|
}
|
|
446
688
|
);
|
|
689
|
+
const isIgnoredTaggedTemplate = createNameMatcher(options.ignoreTaggedTemplateExpressionIdentifiers, { exact: true });
|
|
447
690
|
const targetPaths = [];
|
|
448
691
|
const importDeclarations = /* @__PURE__ */ new Set();
|
|
449
692
|
const exportDeclarations = /* @__PURE__ */ new Set();
|
|
@@ -466,7 +709,7 @@ function analyzeSource(ast, options) {
|
|
|
466
709
|
}
|
|
467
710
|
if (ppp.isTaggedTemplateExpression()) {
|
|
468
711
|
const tagPath = ppp.get("tag");
|
|
469
|
-
if (tagPath.isIdentifier() &&
|
|
712
|
+
if (tagPath.isIdentifier() && isIgnoredTaggedTemplate(tagPath.node.name)) {
|
|
470
713
|
return;
|
|
471
714
|
}
|
|
472
715
|
}
|
|
@@ -477,59 +720,7 @@ function analyzeSource(ast, options) {
|
|
|
477
720
|
CallExpression: {
|
|
478
721
|
enter(p) {
|
|
479
722
|
if (isEvalPath(p)) {
|
|
480
|
-
p
|
|
481
|
-
StringLiteral: {
|
|
482
|
-
enter(path2) {
|
|
483
|
-
const { code } = jsHandler(path2.node.value, {
|
|
484
|
-
...options,
|
|
485
|
-
needEscaped: false,
|
|
486
|
-
generateMap: false
|
|
487
|
-
});
|
|
488
|
-
if (code) {
|
|
489
|
-
const node = path2.node;
|
|
490
|
-
if (typeof node.start === "number" && typeof node.end === "number") {
|
|
491
|
-
const start = node.start + 1;
|
|
492
|
-
const end = node.end - 1;
|
|
493
|
-
if (start < end && path2.node.value !== code) {
|
|
494
|
-
jsTokenUpdater.addToken(
|
|
495
|
-
{
|
|
496
|
-
start,
|
|
497
|
-
end,
|
|
498
|
-
value: jsStringEscape2(code),
|
|
499
|
-
path: path2
|
|
500
|
-
}
|
|
501
|
-
);
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
},
|
|
507
|
-
TemplateElement: {
|
|
508
|
-
enter(path2) {
|
|
509
|
-
const { code } = jsHandler(path2.node.value.raw, {
|
|
510
|
-
...options,
|
|
511
|
-
generateMap: false
|
|
512
|
-
});
|
|
513
|
-
if (code) {
|
|
514
|
-
const node = path2.node;
|
|
515
|
-
if (typeof node.start === "number" && typeof node.end === "number") {
|
|
516
|
-
const start = node.start;
|
|
517
|
-
const end = node.end;
|
|
518
|
-
if (start < end && path2.node.value.raw !== code) {
|
|
519
|
-
jsTokenUpdater.addToken(
|
|
520
|
-
{
|
|
521
|
-
start,
|
|
522
|
-
end,
|
|
523
|
-
value: code,
|
|
524
|
-
path: path2
|
|
525
|
-
}
|
|
526
|
-
);
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
});
|
|
723
|
+
walkEvalExpression(p, options, jsTokenUpdater);
|
|
533
724
|
return;
|
|
534
725
|
}
|
|
535
726
|
walker.walkCallExpression(p);
|
|
@@ -553,46 +744,30 @@ function analyzeSource(ast, options) {
|
|
|
553
744
|
ast,
|
|
554
745
|
targetPaths,
|
|
555
746
|
importDeclarations,
|
|
556
|
-
exportDeclarations
|
|
557
|
-
|
|
747
|
+
exportDeclarations,
|
|
748
|
+
ignoredPaths
|
|
558
749
|
};
|
|
559
750
|
}
|
|
560
751
|
function processUpdatedSource(rawSource, options, analysis) {
|
|
561
752
|
const ms = new MagicString(rawSource);
|
|
562
|
-
const { targetPaths, jsTokenUpdater } = analysis;
|
|
563
|
-
const
|
|
564
|
-
|
|
565
|
-
|
|
753
|
+
const { targetPaths, jsTokenUpdater, ignoredPaths } = analysis;
|
|
754
|
+
const replacementTokens = [];
|
|
755
|
+
for (const path2 of targetPaths) {
|
|
756
|
+
if (ignoredPaths.has(path2)) {
|
|
757
|
+
continue;
|
|
566
758
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
{
|
|
573
|
-
...options,
|
|
574
|
-
needEscaped: options.needEscaped ?? true
|
|
575
|
-
}
|
|
576
|
-
);
|
|
577
|
-
} else if (p.isTemplateElement()) {
|
|
578
|
-
return replaceHandleValue(
|
|
579
|
-
p,
|
|
580
|
-
{
|
|
581
|
-
...options,
|
|
582
|
-
needEscaped: false
|
|
583
|
-
}
|
|
584
|
-
);
|
|
759
|
+
const token = replaceHandleValue(
|
|
760
|
+
path2,
|
|
761
|
+
{
|
|
762
|
+
...options,
|
|
763
|
+
needEscaped: path2.isStringLiteral() ? options.needEscaped ?? true : false
|
|
585
764
|
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
jsTokenUpdater.push(
|
|
590
|
-
...tokens
|
|
591
|
-
).filter(
|
|
592
|
-
(x) => {
|
|
593
|
-
return !ignoreFlagMap.get(x.path);
|
|
765
|
+
);
|
|
766
|
+
if (token) {
|
|
767
|
+
replacementTokens.push(token);
|
|
594
768
|
}
|
|
595
|
-
|
|
769
|
+
}
|
|
770
|
+
jsTokenUpdater.push(...replacementTokens).filter((token) => !ignoredPaths.has(token.path)).updateMagicString(ms);
|
|
596
771
|
return ms;
|
|
597
772
|
}
|
|
598
773
|
function jsHandler(rawSource, options) {
|
|
@@ -629,69 +804,69 @@ function createJsHandler(options) {
|
|
|
629
804
|
uniAppX
|
|
630
805
|
} = options;
|
|
631
806
|
function handler(rawSource, classNameSet, options2) {
|
|
632
|
-
const
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
807
|
+
const overrideOptions = options2 ?? {};
|
|
808
|
+
const resolvedOptions = defuOverrideArray(
|
|
809
|
+
{
|
|
810
|
+
...overrideOptions,
|
|
811
|
+
classNameSet
|
|
812
|
+
},
|
|
813
|
+
{
|
|
814
|
+
classNameSet,
|
|
815
|
+
escapeMap,
|
|
816
|
+
arbitraryValues,
|
|
817
|
+
mangleContext,
|
|
818
|
+
jsPreserveClass,
|
|
819
|
+
generateMap,
|
|
820
|
+
babelParserOptions,
|
|
821
|
+
ignoreCallExpressionIdentifiers,
|
|
822
|
+
ignoreTaggedTemplateExpressionIdentifiers,
|
|
823
|
+
uniAppX
|
|
824
|
+
}
|
|
825
|
+
);
|
|
826
|
+
return jsHandler(rawSource, resolvedOptions);
|
|
645
827
|
}
|
|
646
828
|
return handler;
|
|
647
829
|
}
|
|
648
830
|
|
|
649
|
-
// src/tailwindcss/index.ts
|
|
650
|
-
import { getPackageInfoSync } from "local-pkg";
|
|
651
|
-
|
|
652
|
-
// src/tailwindcss/patcher.ts
|
|
653
|
-
import path from "path";
|
|
654
|
-
import process from "process";
|
|
655
|
-
import { defuOverrideArray as defuOverrideArray2 } from "@weapp-tailwindcss/shared";
|
|
656
|
-
import { TailwindcssPatcher } from "tailwindcss-patch";
|
|
657
|
-
function createTailwindcssPatcher(options) {
|
|
658
|
-
const { basedir, cacheDir, supportCustomLengthUnitsPatch, tailwindcss, tailwindcssPatcherOptions } = options || {};
|
|
659
|
-
const cache = {};
|
|
660
|
-
if (cacheDir) {
|
|
661
|
-
if (path.isAbsolute(cacheDir)) {
|
|
662
|
-
cache.dir = cacheDir;
|
|
663
|
-
} else if (basedir) {
|
|
664
|
-
cache.dir = path.resolve(basedir, cacheDir);
|
|
665
|
-
} else {
|
|
666
|
-
cache.dir = path.resolve(process.cwd(), cacheDir);
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
return new TailwindcssPatcher(defuOverrideArray2(
|
|
670
|
-
tailwindcssPatcherOptions,
|
|
671
|
-
{
|
|
672
|
-
cache,
|
|
673
|
-
patch: {
|
|
674
|
-
basedir,
|
|
675
|
-
applyPatches: {
|
|
676
|
-
exportContext: true,
|
|
677
|
-
extendLengthUnits: supportCustomLengthUnitsPatch
|
|
678
|
-
},
|
|
679
|
-
tailwindcss,
|
|
680
|
-
resolve: {
|
|
681
|
-
paths: [
|
|
682
|
-
import.meta.url
|
|
683
|
-
]
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
));
|
|
688
|
-
}
|
|
689
|
-
|
|
690
831
|
// src/wxml/utils.ts
|
|
691
832
|
import * as t from "@babel/types";
|
|
692
833
|
import { Parser } from "htmlparser2";
|
|
693
834
|
import MagicString2 from "magic-string";
|
|
694
835
|
|
|
836
|
+
// src/wxml/whitespace.ts
|
|
837
|
+
var WHITESPACE_CODES = /* @__PURE__ */ new Set([
|
|
838
|
+
9,
|
|
839
|
+
// \t
|
|
840
|
+
10,
|
|
841
|
+
// \n
|
|
842
|
+
11,
|
|
843
|
+
// \v
|
|
844
|
+
12,
|
|
845
|
+
// \f
|
|
846
|
+
13,
|
|
847
|
+
// \r
|
|
848
|
+
32,
|
|
849
|
+
// space
|
|
850
|
+
160,
|
|
851
|
+
// \u00A0
|
|
852
|
+
65279
|
|
853
|
+
// \uFEFF
|
|
854
|
+
]);
|
|
855
|
+
function isWhitespace(char) {
|
|
856
|
+
if (char.length === 0) {
|
|
857
|
+
return false;
|
|
858
|
+
}
|
|
859
|
+
return WHITESPACE_CODES.has(char.charCodeAt(0));
|
|
860
|
+
}
|
|
861
|
+
function isAllWhitespace(value) {
|
|
862
|
+
for (let i = 0; i < value.length; i++) {
|
|
863
|
+
if (!WHITESPACE_CODES.has(value.charCodeAt(i))) {
|
|
864
|
+
return false;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
return true;
|
|
868
|
+
}
|
|
869
|
+
|
|
695
870
|
// src/wxml/Tokenizer.ts
|
|
696
871
|
var Tokenizer = class {
|
|
697
872
|
constructor() {
|
|
@@ -700,7 +875,7 @@ var Tokenizer = class {
|
|
|
700
875
|
processChar(char, index) {
|
|
701
876
|
switch (this.state) {
|
|
702
877
|
case 0 /* START */:
|
|
703
|
-
if (
|
|
878
|
+
if (isWhitespace(char)) {
|
|
704
879
|
} else if (char === "{") {
|
|
705
880
|
this.state = 2 /* OPEN_BRACE */;
|
|
706
881
|
this.bufferStartIndex = index;
|
|
@@ -714,7 +889,7 @@ var Tokenizer = class {
|
|
|
714
889
|
}
|
|
715
890
|
break;
|
|
716
891
|
case 1 /* TEXT */:
|
|
717
|
-
if (
|
|
892
|
+
if (isWhitespace(char)) {
|
|
718
893
|
this.tokens.push({ start: this.bufferStartIndex, end: index, value: this.buffer, expressions: this.expressions });
|
|
719
894
|
this.buffer = "";
|
|
720
895
|
this.expressions = [];
|
|
@@ -756,7 +931,7 @@ var Tokenizer = class {
|
|
|
756
931
|
}
|
|
757
932
|
break;
|
|
758
933
|
case 4 /* BRACES_COMPLETE */:
|
|
759
|
-
if (
|
|
934
|
+
if (isWhitespace(char)) {
|
|
760
935
|
this.tokens.push({
|
|
761
936
|
start: this.bufferStartIndex,
|
|
762
937
|
end: index,
|
|
@@ -794,9 +969,9 @@ var Tokenizer = class {
|
|
|
794
969
|
expressions: this.expressions
|
|
795
970
|
});
|
|
796
971
|
}
|
|
797
|
-
const
|
|
972
|
+
const tokens = this.tokens;
|
|
798
973
|
this.reset();
|
|
799
|
-
return
|
|
974
|
+
return tokens;
|
|
800
975
|
}
|
|
801
976
|
reset() {
|
|
802
977
|
this.state = 0 /* START */;
|
|
@@ -807,9 +982,6 @@ var Tokenizer = class {
|
|
|
807
982
|
this.expressionStartIndex = 0;
|
|
808
983
|
this.expressions = [];
|
|
809
984
|
}
|
|
810
|
-
isWhitespace(char) {
|
|
811
|
-
return /\s/.test(char);
|
|
812
|
-
}
|
|
813
985
|
};
|
|
814
986
|
|
|
815
987
|
// src/wxml/utils.ts
|
|
@@ -858,7 +1030,7 @@ function handleEachClassFragment(ms, tokens, options = {}) {
|
|
|
858
1030
|
for (const token of tokens) {
|
|
859
1031
|
if (token.start > previousEnd) {
|
|
860
1032
|
const gap = ms.slice(previousEnd, token.start);
|
|
861
|
-
if (gap
|
|
1033
|
+
if (isAllWhitespace(gap)) {
|
|
862
1034
|
ms.update(previousEnd, token.start, replaceWxml(gap, {
|
|
863
1035
|
keepEOL: false,
|
|
864
1036
|
escapeMap: options.escapeMap,
|
|
@@ -906,7 +1078,7 @@ function handleEachClassFragment(ms, tokens, options = {}) {
|
|
|
906
1078
|
const lastToken = tokens[tokens.length - 1];
|
|
907
1079
|
if (lastToken.end < ms.original.length) {
|
|
908
1080
|
const gap = ms.slice(lastToken.end, ms.original.length);
|
|
909
|
-
if (gap
|
|
1081
|
+
if (isAllWhitespace(gap)) {
|
|
910
1082
|
ms.update(lastToken.end, ms.original.length, replaceWxml(gap, {
|
|
911
1083
|
keepEOL: false,
|
|
912
1084
|
escapeMap: options.escapeMap,
|
|
@@ -930,10 +1102,15 @@ function regTest(reg, str) {
|
|
|
930
1102
|
}
|
|
931
1103
|
function isPropsMatch(props, attr) {
|
|
932
1104
|
if (Array.isArray(props)) {
|
|
1105
|
+
let lowerAttr;
|
|
933
1106
|
for (const prop of props) {
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
1107
|
+
if (typeof prop === "string") {
|
|
1108
|
+
lowerAttr ?? (lowerAttr = attr.toLowerCase());
|
|
1109
|
+
if (prop.toLowerCase() === lowerAttr) {
|
|
1110
|
+
return true;
|
|
1111
|
+
}
|
|
1112
|
+
} else if (regTest(prop, attr)) {
|
|
1113
|
+
return true;
|
|
937
1114
|
}
|
|
938
1115
|
}
|
|
939
1116
|
return false;
|
|
@@ -951,6 +1128,23 @@ async function customTemplateHandler(rawSource, options) {
|
|
|
951
1128
|
runtimeSet,
|
|
952
1129
|
jsHandler: jsHandler2
|
|
953
1130
|
} = options ?? {};
|
|
1131
|
+
const wildcardAttributeRules = [];
|
|
1132
|
+
const tagAttributeRuleMap = /* @__PURE__ */ new Map();
|
|
1133
|
+
const regexpAttributeRules = [];
|
|
1134
|
+
for (const [selector, props] of customAttributesEntities) {
|
|
1135
|
+
if (selector === "*") {
|
|
1136
|
+
wildcardAttributeRules.push(props);
|
|
1137
|
+
} else if (typeof selector === "string") {
|
|
1138
|
+
const list = tagAttributeRuleMap.get(selector);
|
|
1139
|
+
if (list) {
|
|
1140
|
+
list.push(props);
|
|
1141
|
+
} else {
|
|
1142
|
+
tagAttributeRuleMap.set(selector, [props]);
|
|
1143
|
+
}
|
|
1144
|
+
} else {
|
|
1145
|
+
regexpAttributeRules.push([selector, props]);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
954
1148
|
const s = new MagicString2(rawSource);
|
|
955
1149
|
let tag = "";
|
|
956
1150
|
const wxsArray = [];
|
|
@@ -961,7 +1155,13 @@ async function customTemplateHandler(rawSource, options) {
|
|
|
961
1155
|
},
|
|
962
1156
|
onattribute(name, value, quote) {
|
|
963
1157
|
if (value) {
|
|
964
|
-
|
|
1158
|
+
const lowerName = name.toLowerCase();
|
|
1159
|
+
let updated = false;
|
|
1160
|
+
const update = () => {
|
|
1161
|
+
if (updated) {
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
updated = true;
|
|
965
1165
|
s.update(
|
|
966
1166
|
parser.startIndex + name.length + 2,
|
|
967
1167
|
// !important
|
|
@@ -975,21 +1175,34 @@ async function customTemplateHandler(rawSource, options) {
|
|
|
975
1175
|
})
|
|
976
1176
|
);
|
|
977
1177
|
};
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
update2();
|
|
1178
|
+
if (!disabledDefaultTemplateHandler && (lowerName === "class" || lowerName === "hover-class" || lowerName === "virtualhostclass")) {
|
|
1179
|
+
update();
|
|
981
1180
|
}
|
|
982
|
-
|
|
983
|
-
|
|
1181
|
+
if (!updated) {
|
|
1182
|
+
for (const props of wildcardAttributeRules) {
|
|
984
1183
|
if (isPropsMatch(props, name)) {
|
|
985
|
-
|
|
1184
|
+
update();
|
|
1185
|
+
break;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
if (!updated) {
|
|
1190
|
+
const tagRules = tagAttributeRuleMap.get(tag);
|
|
1191
|
+
if (tagRules) {
|
|
1192
|
+
for (const props of tagRules) {
|
|
1193
|
+
if (isPropsMatch(props, name)) {
|
|
1194
|
+
update();
|
|
1195
|
+
break;
|
|
1196
|
+
}
|
|
986
1197
|
}
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
if (!updated) {
|
|
1201
|
+
for (const [selector, props] of regexpAttributeRules) {
|
|
1202
|
+
if (regTest(selector, tag) && isPropsMatch(props, name)) {
|
|
1203
|
+
update();
|
|
1204
|
+
break;
|
|
990
1205
|
}
|
|
991
|
-
} else if (regTest(t2, tag) && isPropsMatch(props, name)) {
|
|
992
|
-
update2();
|
|
993
1206
|
}
|
|
994
1207
|
}
|
|
995
1208
|
}
|
|
@@ -1025,77 +1238,31 @@ function createTemplateHandler(options = {}) {
|
|
|
1025
1238
|
};
|
|
1026
1239
|
}
|
|
1027
1240
|
|
|
1028
|
-
// src/context/
|
|
1029
|
-
|
|
1030
|
-
error: 0,
|
|
1031
|
-
warn: 1,
|
|
1032
|
-
info: 3,
|
|
1033
|
-
silent: -999
|
|
1034
|
-
};
|
|
1035
|
-
function getCompilerContext(opts) {
|
|
1036
|
-
const ctx = defuOverrideArray(
|
|
1037
|
-
opts,
|
|
1038
|
-
getDefaultOptions(),
|
|
1039
|
-
{}
|
|
1040
|
-
);
|
|
1041
|
-
ctx.escapeMap = ctx.customReplaceDictionary;
|
|
1241
|
+
// src/context/handlers.ts
|
|
1242
|
+
function createHandlersFromContext(ctx, mangleContext, customAttributesEntities, cssCalcOptions) {
|
|
1042
1243
|
const {
|
|
1043
1244
|
cssPreflight,
|
|
1044
1245
|
customRuleCallback,
|
|
1045
1246
|
cssPreflightRange,
|
|
1046
|
-
|
|
1047
|
-
supportCustomLengthUnitsPatch,
|
|
1048
|
-
arbitraryValues,
|
|
1247
|
+
escapeMap,
|
|
1049
1248
|
cssChildCombinatorReplaceValue,
|
|
1050
|
-
inlineWxs,
|
|
1051
1249
|
injectAdditionalCssVarScope,
|
|
1052
|
-
jsPreserveClass,
|
|
1053
|
-
disabledDefaultTemplateHandler,
|
|
1054
1250
|
cssSelectorReplacement,
|
|
1055
1251
|
rem2rpx,
|
|
1056
|
-
cache,
|
|
1057
|
-
babelParserOptions,
|
|
1058
1252
|
postcssOptions,
|
|
1059
1253
|
cssRemoveProperty,
|
|
1060
1254
|
cssRemoveHoverPseudoClass,
|
|
1061
|
-
escapeMap,
|
|
1062
|
-
mangle,
|
|
1063
|
-
tailwindcssBasedir,
|
|
1064
|
-
appType,
|
|
1065
|
-
ignoreCallExpressionIdentifiers,
|
|
1066
|
-
ignoreTaggedTemplateExpressionIdentifiers,
|
|
1067
1255
|
cssPresetEnv,
|
|
1068
|
-
tailwindcss,
|
|
1069
|
-
tailwindcssPatcherOptions,
|
|
1070
1256
|
uniAppX,
|
|
1071
|
-
cssEntries,
|
|
1072
|
-
cssCalc,
|
|
1073
1257
|
px2rpx,
|
|
1074
|
-
|
|
1258
|
+
arbitraryValues,
|
|
1259
|
+
jsPreserveClass,
|
|
1260
|
+
babelParserOptions,
|
|
1261
|
+
ignoreCallExpressionIdentifiers,
|
|
1262
|
+
ignoreTaggedTemplateExpressionIdentifiers,
|
|
1263
|
+
inlineWxs,
|
|
1264
|
+
disabledDefaultTemplateHandler
|
|
1075
1265
|
} = ctx;
|
|
1076
|
-
logger.level = loggerLevelMap[logLevel] ?? loggerLevelMap.info;
|
|
1077
|
-
const twPatcher = createTailwindcssPatcher(
|
|
1078
|
-
{
|
|
1079
|
-
basedir: tailwindcssBasedir,
|
|
1080
|
-
cacheDir: appType === "mpx" ? "node_modules/tailwindcss-patch/.cache" : void 0,
|
|
1081
|
-
supportCustomLengthUnitsPatch: supportCustomLengthUnitsPatch ?? true,
|
|
1082
|
-
tailwindcss: defuOverrideArray(
|
|
1083
|
-
tailwindcss,
|
|
1084
|
-
{
|
|
1085
|
-
v4: {
|
|
1086
|
-
base: tailwindcssBasedir,
|
|
1087
|
-
cssEntries
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
),
|
|
1091
|
-
tailwindcssPatcherOptions
|
|
1092
|
-
}
|
|
1093
|
-
);
|
|
1094
|
-
logger.success(`\u5F53\u524D\u4F7F\u7528 ${pc.cyanBright("Tailwind CSS")} \u7248\u672C\u4E3A: ${pc.underline(pc.bold(pc.green(twPatcher.packageInfo.version)))}`);
|
|
1095
|
-
const cssCalcOptions = cssCalc ?? twPatcher.majorVersion === 4;
|
|
1096
|
-
const customAttributesEntities = isMap(customAttributes) ? [...customAttributes.entries()] : Object.entries(customAttributes);
|
|
1097
|
-
const { initMangle, mangleContext, setMangleRuntimeSet } = useMangleStore();
|
|
1098
|
-
initMangle(mangle);
|
|
1099
1266
|
const styleHandler = createStyleHandler({
|
|
1100
1267
|
cssPreflight,
|
|
1101
1268
|
customRuleCallback,
|
|
@@ -1133,11 +1300,121 @@ function getCompilerContext(opts) {
|
|
|
1133
1300
|
jsHandler: jsHandler2,
|
|
1134
1301
|
disabledDefaultTemplateHandler
|
|
1135
1302
|
});
|
|
1303
|
+
return {
|
|
1304
|
+
styleHandler,
|
|
1305
|
+
jsHandler: jsHandler2,
|
|
1306
|
+
templateHandler
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
// src/context/logger.ts
|
|
1311
|
+
import { logger } from "@weapp-tailwindcss/logger";
|
|
1312
|
+
var loggerLevelMap = {
|
|
1313
|
+
error: 0,
|
|
1314
|
+
warn: 1,
|
|
1315
|
+
info: 3,
|
|
1316
|
+
silent: -999
|
|
1317
|
+
};
|
|
1318
|
+
function applyLoggerLevel(logLevel) {
|
|
1319
|
+
logger.level = loggerLevelMap[logLevel ?? "info"] ?? loggerLevelMap.info;
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
// src/tailwindcss/index.ts
|
|
1323
|
+
import { getPackageInfoSync } from "local-pkg";
|
|
1324
|
+
|
|
1325
|
+
// src/tailwindcss/patcher.ts
|
|
1326
|
+
import path from "path";
|
|
1327
|
+
import process from "process";
|
|
1328
|
+
import { defuOverrideArray as defuOverrideArray2 } from "@weapp-tailwindcss/shared";
|
|
1329
|
+
import { TailwindcssPatcher } from "tailwindcss-patch";
|
|
1330
|
+
function createTailwindcssPatcher(options) {
|
|
1331
|
+
const { basedir, cacheDir, supportCustomLengthUnitsPatch, tailwindcss, tailwindcssPatcherOptions } = options || {};
|
|
1332
|
+
const cache = {};
|
|
1333
|
+
if (cacheDir) {
|
|
1334
|
+
if (path.isAbsolute(cacheDir)) {
|
|
1335
|
+
cache.dir = cacheDir;
|
|
1336
|
+
} else if (basedir) {
|
|
1337
|
+
cache.dir = path.resolve(basedir, cacheDir);
|
|
1338
|
+
} else {
|
|
1339
|
+
cache.dir = path.resolve(process.cwd(), cacheDir);
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
return new TailwindcssPatcher(defuOverrideArray2(
|
|
1343
|
+
tailwindcssPatcherOptions,
|
|
1344
|
+
{
|
|
1345
|
+
cache,
|
|
1346
|
+
patch: {
|
|
1347
|
+
basedir,
|
|
1348
|
+
applyPatches: {
|
|
1349
|
+
exportContext: true,
|
|
1350
|
+
extendLengthUnits: supportCustomLengthUnitsPatch
|
|
1351
|
+
},
|
|
1352
|
+
tailwindcss,
|
|
1353
|
+
resolve: {
|
|
1354
|
+
paths: [
|
|
1355
|
+
import.meta.url
|
|
1356
|
+
]
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
));
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
// src/context/tailwindcss.ts
|
|
1364
|
+
function createTailwindcssPatcherFromContext(ctx) {
|
|
1365
|
+
const {
|
|
1366
|
+
tailwindcssBasedir,
|
|
1367
|
+
supportCustomLengthUnitsPatch,
|
|
1368
|
+
tailwindcss,
|
|
1369
|
+
tailwindcssPatcherOptions,
|
|
1370
|
+
cssEntries,
|
|
1371
|
+
appType
|
|
1372
|
+
} = ctx;
|
|
1373
|
+
return createTailwindcssPatcher(
|
|
1374
|
+
{
|
|
1375
|
+
basedir: tailwindcssBasedir,
|
|
1376
|
+
cacheDir: appType === "mpx" ? "node_modules/tailwindcss-patch/.cache" : void 0,
|
|
1377
|
+
supportCustomLengthUnitsPatch: supportCustomLengthUnitsPatch ?? true,
|
|
1378
|
+
tailwindcss: defuOverrideArray(
|
|
1379
|
+
tailwindcss,
|
|
1380
|
+
{
|
|
1381
|
+
v4: {
|
|
1382
|
+
base: tailwindcssBasedir,
|
|
1383
|
+
cssEntries
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
),
|
|
1387
|
+
tailwindcssPatcherOptions
|
|
1388
|
+
}
|
|
1389
|
+
);
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
// src/context/index.ts
|
|
1393
|
+
function getCompilerContext(opts) {
|
|
1394
|
+
const ctx = defuOverrideArray(
|
|
1395
|
+
opts,
|
|
1396
|
+
getDefaultOptions(),
|
|
1397
|
+
{}
|
|
1398
|
+
);
|
|
1399
|
+
ctx.escapeMap = ctx.customReplaceDictionary;
|
|
1400
|
+
applyLoggerLevel(ctx.logLevel);
|
|
1401
|
+
const twPatcher = createTailwindcssPatcherFromContext(ctx);
|
|
1402
|
+
logger2.success(`\u5F53\u524D\u4F7F\u7528 ${pc.cyanBright("Tailwind CSS")} \u7248\u672C\u4E3A: ${pc.underline(pc.bold(pc.green(twPatcher.packageInfo.version)))}`);
|
|
1403
|
+
const cssCalcOptions = ctx.cssCalc ?? twPatcher.majorVersion === 4;
|
|
1404
|
+
const customAttributesEntities = toCustomAttributesEntities(ctx.customAttributes);
|
|
1405
|
+
const { initMangle, mangleContext, setMangleRuntimeSet } = useMangleStore();
|
|
1406
|
+
initMangle(ctx.mangle);
|
|
1407
|
+
const { styleHandler, jsHandler: jsHandler2, templateHandler } = createHandlersFromContext(
|
|
1408
|
+
ctx,
|
|
1409
|
+
mangleContext,
|
|
1410
|
+
customAttributesEntities,
|
|
1411
|
+
cssCalcOptions
|
|
1412
|
+
);
|
|
1136
1413
|
ctx.styleHandler = styleHandler;
|
|
1137
1414
|
ctx.jsHandler = jsHandler2;
|
|
1138
1415
|
ctx.templateHandler = templateHandler;
|
|
1139
1416
|
ctx.setMangleRuntimeSet = setMangleRuntimeSet;
|
|
1140
|
-
ctx.cache = initializeCache(cache);
|
|
1417
|
+
ctx.cache = initializeCache(ctx.cache);
|
|
1141
1418
|
ctx.twPatcher = twPatcher;
|
|
1142
1419
|
return ctx;
|
|
1143
1420
|
}
|