weapp-tailwindcss 2.3.3
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/LICENSE +21 -0
- package/README.md +674 -0
- package/bin/weapp-tailwindcss.js +7 -0
- package/dist/babel/index.d.ts +4 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +26 -0
- package/dist/cli.mjs +24 -0
- package/dist/constants.d.ts +6 -0
- package/dist/defaults.d.ts +2 -0
- package/dist/dic.d.ts +44 -0
- package/dist/env.d.ts +2 -0
- package/dist/escape.d.ts +3 -0
- package/dist/extractors/split.d.ts +3 -0
- package/dist/gulp/index.d.ts +8 -0
- package/dist/gulp.d.ts +1 -0
- package/dist/gulp.js +86 -0
- package/dist/gulp.mjs +78 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +31 -0
- package/dist/index.mjs +21 -0
- package/dist/js/index.d.ts +5 -0
- package/dist/mangle/store.d.ts +15 -0
- package/dist/options-3a695e84.js +574 -0
- package/dist/options-ed6f4a3a.mjs +542 -0
- package/dist/options.d.ts +4 -0
- package/dist/postcss/index.d.ts +3 -0
- package/dist/postcss/mp.d.ts +4 -0
- package/dist/postcss/plugin.d.ts +6 -0
- package/dist/postcss/preflight.d.ts +3 -0
- package/dist/postcss/selectorParser.d.ts +3 -0
- package/dist/postcss/shared.d.ts +1 -0
- package/dist/postcss-1f9a5153.mjs +105 -0
- package/dist/postcss-dc9eeafc.js +114 -0
- package/dist/postcss.d.ts +1 -0
- package/dist/postcss.js +22 -0
- package/dist/postcss.mjs +6 -0
- package/dist/reg.d.ts +26 -0
- package/dist/replace.d.ts +4 -0
- package/dist/replace.js +36 -0
- package/dist/replace.mjs +27 -0
- package/dist/shared-c2953d9d.js +354 -0
- package/dist/shared-eae1dc7a.mjs +333 -0
- package/dist/tailwindcss/patcher.d.ts +8 -0
- package/dist/tailwindcss/supportCustomUnit.d.ts +6 -0
- package/dist/types.d.ts +118 -0
- package/dist/utils.d.ts +9 -0
- package/dist/vite/index.d.ts +3 -0
- package/dist/vite.d.ts +1 -0
- package/dist/vite.js +82 -0
- package/dist/vite.mjs +78 -0
- package/dist/webpack/BaseUnifiedPlugin/v5.d.ts +9 -0
- package/dist/webpack/index.d.ts +1 -0
- package/dist/webpack.d.ts +1 -0
- package/dist/webpack.js +101 -0
- package/dist/webpack.mjs +97 -0
- package/dist/wxml/index.d.ts +3 -0
- package/dist/wxml/shared.d.ts +2 -0
- package/dist/wxml/utils.d.ts +7 -0
- package/package.json +224 -0
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var shared = require('./shared-c2953d9d.js');
|
|
4
|
+
var micromatch = require('micromatch');
|
|
5
|
+
var generate = require('@babel/generator');
|
|
6
|
+
var parser = require('@babel/parser');
|
|
7
|
+
var traverse = require('@babel/traverse');
|
|
8
|
+
var replace = require('./replace.js');
|
|
9
|
+
var t = require('@babel/types');
|
|
10
|
+
var postcss = require('postcss');
|
|
11
|
+
var postcss$1 = require('./postcss-dc9eeafc.js');
|
|
12
|
+
var postcssIsPseudoClass = require('@csstools/postcss-is-pseudo-class');
|
|
13
|
+
var path = require('path');
|
|
14
|
+
var fs = require('fs');
|
|
15
|
+
var semver = require('semver');
|
|
16
|
+
var tailwindcssPatch = require('tailwindcss-patch');
|
|
17
|
+
|
|
18
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
19
|
+
|
|
20
|
+
function _interopNamespaceCompat(e) {
|
|
21
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
22
|
+
var n = Object.create(null);
|
|
23
|
+
if (e) {
|
|
24
|
+
Object.keys(e).forEach(function (k) {
|
|
25
|
+
if (k !== 'default') {
|
|
26
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
27
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () { return e[k]; }
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
n["default"] = e;
|
|
35
|
+
return Object.freeze(n);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var generate__default = /*#__PURE__*/_interopDefaultCompat(generate);
|
|
39
|
+
var traverse__default = /*#__PURE__*/_interopDefaultCompat(traverse);
|
|
40
|
+
var t__namespace = /*#__PURE__*/_interopNamespaceCompat(t);
|
|
41
|
+
var postcss__default = /*#__PURE__*/_interopDefaultCompat(postcss);
|
|
42
|
+
var postcssIsPseudoClass__default = /*#__PURE__*/_interopDefaultCompat(postcssIsPseudoClass);
|
|
43
|
+
var path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
44
|
+
var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
45
|
+
|
|
46
|
+
function isObject(value) {
|
|
47
|
+
return value !== null && typeof value === "object";
|
|
48
|
+
}
|
|
49
|
+
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
50
|
+
if (!isObject(defaults)) {
|
|
51
|
+
return _defu(baseObject, {}, namespace, merger);
|
|
52
|
+
}
|
|
53
|
+
const object = Object.assign({}, defaults);
|
|
54
|
+
for (const key in baseObject) {
|
|
55
|
+
if (key === "__proto__" || key === "constructor") {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const value = baseObject[key];
|
|
59
|
+
if (value === null || value === void 0) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (merger && merger(object, key, value, namespace)) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
66
|
+
object[key] = [...value, ...object[key]];
|
|
67
|
+
} else if (isObject(value) && isObject(object[key])) {
|
|
68
|
+
object[key] = _defu(
|
|
69
|
+
value,
|
|
70
|
+
object[key],
|
|
71
|
+
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
72
|
+
merger
|
|
73
|
+
);
|
|
74
|
+
} else {
|
|
75
|
+
object[key] = value;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return object;
|
|
79
|
+
}
|
|
80
|
+
function createDefu(merger) {
|
|
81
|
+
return (...arguments_) => (
|
|
82
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
83
|
+
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
const defu = createDefu();
|
|
87
|
+
|
|
88
|
+
function generateCode(match, options = {}) {
|
|
89
|
+
const ast = parser.parseExpression(match);
|
|
90
|
+
traverse__default["default"](ast, {
|
|
91
|
+
StringLiteral(path) {
|
|
92
|
+
var _a;
|
|
93
|
+
if (t__namespace.isMemberExpression(path.parent)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (t__namespace.isBinaryExpression(path.parent)) {
|
|
97
|
+
if (t__namespace.isConditionalExpression((_a = path.parentPath) === null || _a === void 0 ? void 0 : _a.parent)) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
path.node.value = replace.replaceJs(path.node.value, options);
|
|
102
|
+
},
|
|
103
|
+
noScope: true
|
|
104
|
+
});
|
|
105
|
+
const { code } = generate__default["default"](ast, {
|
|
106
|
+
compact: true,
|
|
107
|
+
minified: true,
|
|
108
|
+
jsescOption: {
|
|
109
|
+
quotes: 'single',
|
|
110
|
+
minimal: true
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
return code;
|
|
114
|
+
}
|
|
115
|
+
function extractSource(original) {
|
|
116
|
+
let match = shared.variableMatch(original);
|
|
117
|
+
const sources = [];
|
|
118
|
+
while (match !== null) {
|
|
119
|
+
const start = match.index;
|
|
120
|
+
const end = shared.variableRegExp.lastIndex;
|
|
121
|
+
sources.push({
|
|
122
|
+
start,
|
|
123
|
+
end,
|
|
124
|
+
raw: match[1],
|
|
125
|
+
prevConcatenated: !/\s/.test(original[start - 1]),
|
|
126
|
+
nextConcatenated: !/\s/.test(original[end])
|
|
127
|
+
});
|
|
128
|
+
match = shared.variableMatch(original);
|
|
129
|
+
}
|
|
130
|
+
return sources;
|
|
131
|
+
}
|
|
132
|
+
function templeteReplacer(original, options = {}) {
|
|
133
|
+
const sources = extractSource(original);
|
|
134
|
+
if (sources.length) {
|
|
135
|
+
const resultArray = [];
|
|
136
|
+
let p = 0;
|
|
137
|
+
for (let i = 0; i < sources.length; i++) {
|
|
138
|
+
const m = sources[i];
|
|
139
|
+
const before = original.slice(p, m.start);
|
|
140
|
+
resultArray.push(replace.replaceJs(before, {
|
|
141
|
+
keepEOL: true,
|
|
142
|
+
escapeMap: options.escapeMap
|
|
143
|
+
}));
|
|
144
|
+
p = m.start;
|
|
145
|
+
if (m.raw.trim().length) {
|
|
146
|
+
const code = generateCode(m.raw, options);
|
|
147
|
+
const source = `{{${code}}}`;
|
|
148
|
+
m.source = source;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
m.source = '';
|
|
152
|
+
}
|
|
153
|
+
resultArray.push(m.source);
|
|
154
|
+
p = m.end;
|
|
155
|
+
if (i === sources.length - 1) {
|
|
156
|
+
const after = original.slice(m.end);
|
|
157
|
+
resultArray.push(replace.replaceJs(after, {
|
|
158
|
+
keepEOL: true,
|
|
159
|
+
escapeMap: options.escapeMap
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return resultArray
|
|
164
|
+
.filter((x) => x)
|
|
165
|
+
.join('')
|
|
166
|
+
.trim();
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
return replace.replaceJs(original, {
|
|
170
|
+
keepEOL: false,
|
|
171
|
+
escapeMap: options.escapeMap
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function templeteHandler(rawSource, options = {}) {
|
|
176
|
+
return rawSource.replace(shared.tagWithEitherClassAndHoverClassRegexp, (m0) => {
|
|
177
|
+
return m0.replace(shared.templateClassExactRegexp, (m1, className) => {
|
|
178
|
+
return m1.replace(className, templeteReplacer(className, options));
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
function customTempleteHandler(rawSource, options = {}) {
|
|
183
|
+
let source = templeteHandler(rawSource, options);
|
|
184
|
+
const regexps = shared.makeCustomAttributes(options.customAttributesEntities);
|
|
185
|
+
if (regexps) {
|
|
186
|
+
if (Array.isArray(regexps)) {
|
|
187
|
+
for (let i = 0; i < regexps.length; i++) {
|
|
188
|
+
const regexp = regexps[i];
|
|
189
|
+
source = source.replace(regexp.tagRegexp, (m0) => {
|
|
190
|
+
return m0.replace(regexp.attrRegexp, (m1, className) => {
|
|
191
|
+
return m1.replace(className, templeteReplacer(className, options));
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return source;
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
return source;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function createTempleteHandler(options = {}) {
|
|
203
|
+
return (rawSource, opt = {}) => {
|
|
204
|
+
return customTempleteHandler(rawSource, defu(opt, options));
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function styleHandler(rawSource, options) {
|
|
209
|
+
return postcss__default["default"]([postcss$1.postcssWeappTailwindcss(options), postcssIsPseudoClass__default["default"]()]).process(rawSource).css;
|
|
210
|
+
}
|
|
211
|
+
function createStyleHandler(options) {
|
|
212
|
+
return (rawSource, opt) => {
|
|
213
|
+
return styleHandler(rawSource, defu(opt, options));
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const createInjectPreflight = (options) => {
|
|
218
|
+
const result = [];
|
|
219
|
+
if (options && typeof options === 'object') {
|
|
220
|
+
const entries = Object.entries(options);
|
|
221
|
+
for (let i = 0; i < entries.length; i++) {
|
|
222
|
+
const [prop, value] = entries[i];
|
|
223
|
+
if (value !== false) {
|
|
224
|
+
result.push({
|
|
225
|
+
prop,
|
|
226
|
+
value: value.toString()
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return () => {
|
|
232
|
+
return result;
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
function findAstNode(content, options) {
|
|
237
|
+
const DOPTS = options.dangerousOptions;
|
|
238
|
+
const ast = parser.parse(content);
|
|
239
|
+
let arrayRef;
|
|
240
|
+
let changed = false;
|
|
241
|
+
traverse__default["default"](ast, {
|
|
242
|
+
Identifier(path) {
|
|
243
|
+
if (path.node.name === DOPTS.variableName) {
|
|
244
|
+
if (t__namespace.isVariableDeclarator(path.parent)) {
|
|
245
|
+
if (t__namespace.isArrayExpression(path.parent.init)) {
|
|
246
|
+
arrayRef = path.parent.init;
|
|
247
|
+
const set = new Set(path.parent.init.elements.map((x) => x.value));
|
|
248
|
+
for (let i = 0; i < options.units.length; i++) {
|
|
249
|
+
const unit = options.units[i];
|
|
250
|
+
if (!set.has(unit)) {
|
|
251
|
+
path.parent.init.elements = path.parent.init.elements.map((x) => {
|
|
252
|
+
if (t__namespace.isStringLiteral(x)) {
|
|
253
|
+
return {
|
|
254
|
+
type: x === null || x === void 0 ? void 0 : x.type,
|
|
255
|
+
value: x === null || x === void 0 ? void 0 : x.value
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
return x;
|
|
259
|
+
});
|
|
260
|
+
path.parent.init.elements.push({
|
|
261
|
+
type: 'StringLiteral',
|
|
262
|
+
value: unit
|
|
263
|
+
});
|
|
264
|
+
changed = true;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
return {
|
|
273
|
+
arrayRef,
|
|
274
|
+
changed
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function getInstalledPkgJsonPath(options) {
|
|
279
|
+
const dangerousOptions = options.dangerousOptions;
|
|
280
|
+
try {
|
|
281
|
+
const tmpJsonPath = tailwindcssPatch.requireResolve(`${dangerousOptions.packageName}/package.json`, {
|
|
282
|
+
paths: options.paths,
|
|
283
|
+
basedir: options.basedir
|
|
284
|
+
});
|
|
285
|
+
return tmpJsonPath;
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
if (error.code === 'MODULE_NOT_FOUND') {
|
|
289
|
+
console.warn('没有找到`tailwindcss`包,请确认是否安装。想要禁用打上rpx支持patch或者非`tailwindcss`框架,你可以设置 `supportCustomLengthUnitsPatch` 为 false');
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function createPatch(options) {
|
|
294
|
+
if (options === false) {
|
|
295
|
+
return shared.noop;
|
|
296
|
+
}
|
|
297
|
+
return () => {
|
|
298
|
+
try {
|
|
299
|
+
return internalPatch(getInstalledPkgJsonPath(options), options);
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
console.warn(`patch tailwindcss failed:` + error.message);
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
function monkeyPatchForSupportingCustomUnit(rootDir, options) {
|
|
307
|
+
var _a;
|
|
308
|
+
const { dangerousOptions } = options;
|
|
309
|
+
const DOPTS = dangerousOptions;
|
|
310
|
+
const dataTypesFilePath = path__default["default"].resolve(rootDir, DOPTS.lengthUnitsFilePath);
|
|
311
|
+
const dataTypesFileContent = fs__default["default"].readFileSync(dataTypesFilePath, {
|
|
312
|
+
encoding: 'utf-8'
|
|
313
|
+
});
|
|
314
|
+
const { arrayRef, changed } = findAstNode(dataTypesFileContent, options);
|
|
315
|
+
if (arrayRef && changed) {
|
|
316
|
+
const { code } = generate__default["default"](arrayRef, {
|
|
317
|
+
jsescOption: {
|
|
318
|
+
quotes: 'single'
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
if (arrayRef.start && arrayRef.end) {
|
|
322
|
+
const prev = dataTypesFileContent.slice(0, arrayRef.start);
|
|
323
|
+
const next = dataTypesFileContent.slice(arrayRef.end);
|
|
324
|
+
const newCode = prev + code + next;
|
|
325
|
+
if (DOPTS.overwrite) {
|
|
326
|
+
fs__default["default"].writeFileSync((_a = DOPTS.destPath) !== null && _a !== void 0 ? _a : dataTypesFilePath, newCode, {
|
|
327
|
+
encoding: 'utf-8'
|
|
328
|
+
});
|
|
329
|
+
console.log('patch tailwindcss for custom length unit successfully!');
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return code;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
function internalPatch(pkgJsonPath, options, overwrite = true) {
|
|
336
|
+
if (pkgJsonPath) {
|
|
337
|
+
const pkgJson = require(pkgJsonPath);
|
|
338
|
+
const dangerousOptions = options.dangerousOptions;
|
|
339
|
+
if (semver.gte(pkgJson.version, dangerousOptions.gteVersion)) {
|
|
340
|
+
const rootDir = path__default["default"].dirname(pkgJsonPath);
|
|
341
|
+
const dataTypes = monkeyPatchForSupportingCustomUnit(rootDir, options);
|
|
342
|
+
const result = tailwindcssPatch.monkeyPatchForExposingContext(rootDir, {
|
|
343
|
+
overwrite
|
|
344
|
+
});
|
|
345
|
+
return Object.assign(Object.assign({}, result), { dataTypes });
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
function createTailwindcssPatcher() {
|
|
350
|
+
return new tailwindcssPatch.TailwindcssPatcher({
|
|
351
|
+
cache: true
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const isProd = () => process.env.NODE_ENV === 'production';
|
|
356
|
+
|
|
357
|
+
function handleValue(str, node, options) {
|
|
358
|
+
const set = options.classNameSet;
|
|
359
|
+
const escapeMap = options.escapeMap;
|
|
360
|
+
const arr = shared.splitCode(str);
|
|
361
|
+
let rawStr = str;
|
|
362
|
+
for (let i = 0; i < arr.length; i++) {
|
|
363
|
+
const v = arr[i];
|
|
364
|
+
if (set.has(v)) {
|
|
365
|
+
let ignoreFlag = false;
|
|
366
|
+
if (Array.isArray(node.leadingComments)) {
|
|
367
|
+
ignoreFlag = node.leadingComments.findIndex((x) => x.value.includes('weapp-tw') && x.value.includes('ignore')) > -1;
|
|
368
|
+
}
|
|
369
|
+
if (!ignoreFlag) {
|
|
370
|
+
const { jsHandler } = shared.useStore();
|
|
371
|
+
rawStr = jsHandler(rawStr);
|
|
372
|
+
rawStr = rawStr.replace(new RegExp(shared.escapeStringRegexp(v), 'g'), replace.replaceJs(v, {
|
|
373
|
+
escapeMap
|
|
374
|
+
}));
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return rawStr;
|
|
379
|
+
}
|
|
380
|
+
function jsHandler(rawSource, options) {
|
|
381
|
+
var _a;
|
|
382
|
+
const ast = parser.parse(rawSource, {
|
|
383
|
+
sourceType: 'unambiguous'
|
|
384
|
+
});
|
|
385
|
+
const topt = {
|
|
386
|
+
StringLiteral: {
|
|
387
|
+
enter(p) {
|
|
388
|
+
const n = p.node;
|
|
389
|
+
n.value = handleValue(n.value, n, options);
|
|
390
|
+
}
|
|
391
|
+
},
|
|
392
|
+
TemplateElement: {
|
|
393
|
+
enter(p) {
|
|
394
|
+
const n = p.node;
|
|
395
|
+
n.value.raw = handleValue(n.value.raw, n, options);
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
CallExpression: {
|
|
399
|
+
enter(p) {
|
|
400
|
+
const n = p.node;
|
|
401
|
+
if (t__namespace.isIdentifier(n.callee) && n.callee.name === 'eval') {
|
|
402
|
+
if (t__namespace.isStringLiteral(n.arguments[0])) {
|
|
403
|
+
const res = jsHandler(n.arguments[0].value, options);
|
|
404
|
+
if (res.code) {
|
|
405
|
+
n.arguments[0].value = res.code;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
noScope: true
|
|
412
|
+
};
|
|
413
|
+
traverse__default["default"](ast, topt);
|
|
414
|
+
return generate__default["default"](ast, {
|
|
415
|
+
minified: (_a = options.minifiedJs) !== null && _a !== void 0 ? _a : isProd()
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
function createjsHandler(options) {
|
|
419
|
+
return (rawSource, set) => {
|
|
420
|
+
return jsHandler(rawSource, {
|
|
421
|
+
classNameSet: set,
|
|
422
|
+
minifiedJs: options.minifiedJs,
|
|
423
|
+
escapeMap: options.escapeMap
|
|
424
|
+
});
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const defaultOptions = {
|
|
429
|
+
cssMatcher: (file) => /.+\.(?:wx|ac|jx|tt|q|c)ss$/.test(file),
|
|
430
|
+
htmlMatcher: (file) => /.+\.(?:(?:(?:wx|ax|jx|ks|tt|q)ml)|swan)$/.test(file),
|
|
431
|
+
jsMatcher: (file) => {
|
|
432
|
+
if (file.includes('node_modules')) {
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
return /.+\.[cm]?[jt]sx?$/.test(file);
|
|
436
|
+
},
|
|
437
|
+
mainCssChunkMatcher: (file, appType) => {
|
|
438
|
+
switch (appType) {
|
|
439
|
+
case 'uni-app': {
|
|
440
|
+
return /^common\/main/.test(file);
|
|
441
|
+
}
|
|
442
|
+
case 'uni-app-vite': {
|
|
443
|
+
return /^app/.test(file) || /^common\/main/.test(file);
|
|
444
|
+
}
|
|
445
|
+
case 'mpx': {
|
|
446
|
+
return /^app/.test(file);
|
|
447
|
+
}
|
|
448
|
+
case 'taro': {
|
|
449
|
+
return /^app/.test(file);
|
|
450
|
+
}
|
|
451
|
+
case 'remax': {
|
|
452
|
+
return /^app/.test(file);
|
|
453
|
+
}
|
|
454
|
+
case 'rax': {
|
|
455
|
+
return /^bundle/.test(file);
|
|
456
|
+
}
|
|
457
|
+
case 'native': {
|
|
458
|
+
return /^app/.test(file);
|
|
459
|
+
}
|
|
460
|
+
case 'kbone': {
|
|
461
|
+
return /^(?:common\/)?miniprogram-app/.test(file);
|
|
462
|
+
}
|
|
463
|
+
default: {
|
|
464
|
+
return true;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
},
|
|
468
|
+
cssPreflight: {
|
|
469
|
+
'box-sizing': 'border-box',
|
|
470
|
+
'border-width': '0',
|
|
471
|
+
'border-style': 'solid',
|
|
472
|
+
'border-color': 'currentColor'
|
|
473
|
+
},
|
|
474
|
+
cssPreflightRange: 'view',
|
|
475
|
+
replaceUniversalSelectorWith: 'view',
|
|
476
|
+
disabled: false,
|
|
477
|
+
customRuleCallback: shared.noop,
|
|
478
|
+
onLoad: shared.noop,
|
|
479
|
+
onStart: shared.noop,
|
|
480
|
+
onEnd: shared.noop,
|
|
481
|
+
onUpdate: shared.noop,
|
|
482
|
+
customAttributes: {},
|
|
483
|
+
customReplaceDictionary: shared.SimpleMappingChars2String,
|
|
484
|
+
supportCustomLengthUnitsPatch: {
|
|
485
|
+
units: ['rpx'],
|
|
486
|
+
dangerousOptions: {
|
|
487
|
+
gteVersion: '3.0.0',
|
|
488
|
+
lengthUnitsFilePath: 'lib/util/dataTypes.js',
|
|
489
|
+
packageName: 'tailwindcss',
|
|
490
|
+
variableName: 'lengthUnits',
|
|
491
|
+
overwrite: true
|
|
492
|
+
}
|
|
493
|
+
},
|
|
494
|
+
appType: undefined
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
function createGlobMatcher(pattern) {
|
|
498
|
+
return function (file) {
|
|
499
|
+
return micromatch.isMatch(file, pattern);
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
function normalizeMatcher(options, key) {
|
|
503
|
+
if (typeof options[key] === 'string' || Array.isArray(options[key])) {
|
|
504
|
+
options[key] = createGlobMatcher(options[key]);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
function getOptions(options = {}, modules = ['style', 'templete', 'patch', 'js']) {
|
|
508
|
+
const registerModules = modules.reduce((acc, cur) => {
|
|
509
|
+
if (acc[cur] !== undefined) {
|
|
510
|
+
acc[cur] = true;
|
|
511
|
+
}
|
|
512
|
+
return acc;
|
|
513
|
+
}, {
|
|
514
|
+
templete: false,
|
|
515
|
+
style: false,
|
|
516
|
+
patch: false,
|
|
517
|
+
js: false
|
|
518
|
+
});
|
|
519
|
+
if (options.supportCustomLengthUnitsPatch === true) {
|
|
520
|
+
options.supportCustomLengthUnitsPatch = undefined;
|
|
521
|
+
}
|
|
522
|
+
if (options.customReplaceDictionary === 'simple') {
|
|
523
|
+
options.customReplaceDictionary = shared.SimpleMappingChars2String;
|
|
524
|
+
}
|
|
525
|
+
else if (options.customReplaceDictionary === 'complex') {
|
|
526
|
+
options.customReplaceDictionary = shared.MappingChars2String;
|
|
527
|
+
}
|
|
528
|
+
normalizeMatcher(options, 'cssMatcher');
|
|
529
|
+
normalizeMatcher(options, 'htmlMatcher');
|
|
530
|
+
normalizeMatcher(options, 'jsMatcher');
|
|
531
|
+
normalizeMatcher(options, 'mainCssChunkMatcher');
|
|
532
|
+
const result = defu(options, defaultOptions, {
|
|
533
|
+
minifiedJs: isProd()
|
|
534
|
+
});
|
|
535
|
+
const { cssPreflight, customRuleCallback, cssPreflightRange, replaceUniversalSelectorWith, customAttributes, customReplaceDictionary, supportCustomLengthUnitsPatch } = result;
|
|
536
|
+
result.escapeMap = customReplaceDictionary;
|
|
537
|
+
const cssInjectPreflight = createInjectPreflight(cssPreflight);
|
|
538
|
+
let customAttributesEntities;
|
|
539
|
+
if (shared.isMap(options.customAttributes)) {
|
|
540
|
+
customAttributesEntities = Array.from(options.customAttributes.entries());
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
customAttributesEntities = Object.entries(customAttributes);
|
|
544
|
+
}
|
|
545
|
+
if (registerModules.templete) {
|
|
546
|
+
result.templeteHandler = createTempleteHandler({
|
|
547
|
+
customAttributesEntities,
|
|
548
|
+
escapeMap: result.escapeMap
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
if (registerModules.style) {
|
|
552
|
+
result.styleHandler = createStyleHandler({
|
|
553
|
+
cssInjectPreflight,
|
|
554
|
+
customRuleCallback,
|
|
555
|
+
cssPreflightRange,
|
|
556
|
+
replaceUniversalSelectorWith,
|
|
557
|
+
escapeMap: result.escapeMap
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
if (registerModules.js) {
|
|
561
|
+
result.jsHandler = createjsHandler({
|
|
562
|
+
minifiedJs: result.minifiedJs,
|
|
563
|
+
escapeMap: result.escapeMap
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
if (registerModules.patch) {
|
|
567
|
+
result.patch = createPatch(supportCustomLengthUnitsPatch);
|
|
568
|
+
}
|
|
569
|
+
return result;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
exports.createPatch = createPatch;
|
|
573
|
+
exports.createTailwindcssPatcher = createTailwindcssPatcher;
|
|
574
|
+
exports.getOptions = getOptions;
|