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