weapp-tailwindcss 3.4.0-alpha.0 → 3.4.0-alpha.2

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.
Files changed (124) hide show
  1. package/dist/babel/index.d.ts +16 -0
  2. package/dist/bundlers/gulp/index.d.ts +8 -0
  3. package/dist/bundlers/vite/index.d.ts +3 -0
  4. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +8 -0
  5. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +8 -0
  6. package/dist/bundlers/webpack/index.d.ts +1 -0
  7. package/dist/{weapp-tw-runtime-loader.d.ts → bundlers/webpack/loaders/weapp-tw-runtime-loader.d.ts} +2 -4
  8. package/dist/cache/index.d.ts +32 -0
  9. package/dist/cli.d.ts +1 -2
  10. package/dist/cli.js +51 -1760
  11. package/dist/cli.mjs +45 -34
  12. package/dist/constants-CFM1J-h1.js +42 -0
  13. package/dist/constants-Dy2Dd3Fz.mjs +36 -0
  14. package/dist/constants.d.ts +7 -0
  15. package/dist/core.d.ts +2 -16
  16. package/dist/core.js +60 -1775
  17. package/dist/core.mjs +60 -46
  18. package/dist/css-macro/constants.d.ts +14 -0
  19. package/dist/css-macro/index.d.ts +4 -7
  20. package/dist/css-macro/index.js +30 -140
  21. package/dist/css-macro/index.mjs +28 -35
  22. package/dist/css-macro/postcss.d.ts +3 -5
  23. package/dist/css-macro/postcss.js +46 -99
  24. package/dist/css-macro/postcss.mjs +45 -54
  25. package/dist/debug/index.d.ts +2 -0
  26. package/dist/defaults-DW-EahCC.js +145 -0
  27. package/dist/defaults-w3rlKQwe.mjs +139 -0
  28. package/dist/defaults.d.ts +2 -16
  29. package/dist/defaults.js +7 -208
  30. package/dist/defaults.mjs +4 -9
  31. package/dist/defu-Cdz2PomB.js +60 -0
  32. package/dist/defu-n46TJT6t.mjs +57 -0
  33. package/dist/env.d.ts +2 -0
  34. package/dist/escape.d.ts +4 -0
  35. package/dist/extractors/split.d.ts +3 -0
  36. package/dist/gulp.d.ts +1 -26
  37. package/dist/gulp.js +38 -1898
  38. package/dist/gulp.mjs +30 -15
  39. package/dist/index-B2TNoaOv.mjs +134 -0
  40. package/dist/index-B5NiRecR.js +130 -0
  41. package/dist/index-BEIjgKpF.mjs +11 -0
  42. package/dist/index-BPzIdybK.mjs +513 -0
  43. package/dist/index-DeW_zXzo.mjs +124 -0
  44. package/dist/index-DmzxhHCX.js +136 -0
  45. package/dist/index-DwZHOkK3.js +526 -0
  46. package/dist/index-HC-Qkn0i.js +17 -0
  47. package/dist/index.d.ts +4 -17
  48. package/dist/index.js +43 -2291
  49. package/dist/index.mjs +33 -23
  50. package/dist/js/handlers.d.ts +13 -0
  51. package/dist/js/index.d.ts +7 -0
  52. package/dist/mangle/index.d.ts +8 -0
  53. package/dist/options-7EjuAISl.mjs +869 -0
  54. package/dist/options-C-rvBixk.js +901 -0
  55. package/dist/options.d.ts +2 -0
  56. package/dist/postcss/cssVars.d.ts +5 -0
  57. package/dist/postcss/index.d.ts +3 -0
  58. package/dist/postcss/mp.d.ts +8 -0
  59. package/dist/postcss/plugins/ctx.d.ts +6 -0
  60. package/dist/postcss/plugins/index.d.ts +7 -0
  61. package/dist/postcss/plugins/post.d.ts +5 -0
  62. package/dist/postcss/plugins/pre.d.ts +5 -0
  63. package/dist/postcss/preflight.d.ts +3 -0
  64. package/dist/postcss/selectorParser.d.ts +6 -0
  65. package/dist/postcss/shared.d.ts +3 -0
  66. package/dist/postcss/symbols.d.ts +1 -0
  67. package/dist/postcss.d.ts +1 -23
  68. package/dist/postcss.js +22 -598
  69. package/dist/postcss.mjs +8 -17
  70. package/dist/reg.d.ts +1 -0
  71. package/dist/replace.d.ts +3 -19
  72. package/dist/replace.js +42 -93
  73. package/dist/replace.mjs +26 -30
  74. package/dist/shared-DbJl6i6a.mjs +25 -0
  75. package/dist/shared-hzYeE1wX.js +28 -0
  76. package/dist/tailwindcss/patcher.d.ts +3 -0
  77. package/dist/types.d.ts +165 -0
  78. package/dist/utils.d.ts +18 -0
  79. package/dist/v5-BD9-sqra.mjs +174 -0
  80. package/dist/v5-Ch6783yy.js +181 -0
  81. package/dist/vite.d.ts +1 -22
  82. package/dist/vite.js +36 -1947
  83. package/dist/vite.mjs +28 -15
  84. package/dist/weapp-tw-runtime-loader.js +14 -41
  85. package/dist/weapp-tw-runtime-loader.mjs +8 -12
  86. package/dist/webpack.d.ts +1 -26
  87. package/dist/webpack.js +37 -1994
  88. package/dist/webpack.mjs +29 -15
  89. package/dist/webpack4.d.ts +1 -27
  90. package/dist/webpack4.js +190 -1979
  91. package/dist/webpack4.mjs +188 -211
  92. package/dist/wxml/Tokenizer.d.ts +31 -0
  93. package/dist/wxml/index.d.ts +2 -0
  94. package/dist/wxml/shared.d.ts +2 -0
  95. package/dist/wxml/utils.d.ts +13 -0
  96. package/package.json +3 -3
  97. package/dist/chunk-257YPDSI.mjs +0 -173
  98. package/dist/chunk-75EWCRQW.mjs +0 -13
  99. package/dist/chunk-AB467PG7.mjs +0 -43
  100. package/dist/chunk-E7XGHGC7.mjs +0 -62
  101. package/dist/chunk-GUE4UCRJ.mjs +0 -126
  102. package/dist/chunk-IOYI6MSW.mjs +0 -533
  103. package/dist/chunk-LDWI65M5.mjs +0 -152
  104. package/dist/chunk-NVFWRLOI.mjs +0 -27
  105. package/dist/chunk-ORMKM6ZA.mjs +0 -30
  106. package/dist/chunk-PC4B5JJB.mjs +0 -953
  107. package/dist/chunk-SRLZU2YE.mjs +0 -95
  108. package/dist/chunk-VECXHWWG.mjs +0 -31
  109. package/dist/chunk-VN37QGSM.mjs +0 -216
  110. package/dist/cli.d.mts +0 -2
  111. package/dist/core.d.mts +0 -22
  112. package/dist/css-macro/index.d.mts +0 -18
  113. package/dist/css-macro/postcss.d.mts +0 -7
  114. package/dist/defaults.d.mts +0 -16
  115. package/dist/gulp.d.mts +0 -26
  116. package/dist/index.d.mts +0 -17
  117. package/dist/postcss.d.mts +0 -23
  118. package/dist/replace.d.mts +0 -19
  119. package/dist/types-DSNuiOhH.d.mts +0 -519
  120. package/dist/types-DSNuiOhH.d.ts +0 -519
  121. package/dist/vite.d.mts +0 -22
  122. package/dist/weapp-tw-runtime-loader.d.mts +0 -7
  123. package/dist/webpack.d.mts +0 -26
  124. package/dist/webpack4.d.mts +0 -27
package/dist/cli.js CHANGED
@@ -1,1765 +1,56 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
- var __getProtoOf = Object.getPrototypeOf;
10
- var __hasOwnProp = Object.prototype.hasOwnProperty;
11
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {}))
15
- if (__hasOwnProp.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- if (__getOwnPropSymbols)
18
- for (var prop of __getOwnPropSymbols(b)) {
19
- if (__propIsEnum.call(b, prop))
20
- __defNormalProp(a, prop, b[prop]);
21
- }
22
- return a;
23
- };
24
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
- var __export = (target, all) => {
26
- for (var name in all)
27
- __defProp(target, name, { get: all[name], enumerable: true });
28
- };
29
- var __copyProps = (to, from, except, desc) => {
30
- if (from && typeof from === "object" || typeof from === "function") {
31
- for (let key of __getOwnPropNames(from))
32
- if (!__hasOwnProp.call(to, key) && key !== except)
33
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
- }
35
- return to;
36
- };
37
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
38
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
39
- // If the importer is in node compatibility mode or this is not an ESM
40
- // file that has been converted to a CommonJS file using a Babel-
41
- // compatible transform (i.e. "__esModule" has not been set), then set
42
- // "default" to the CommonJS "module.exports" for node compatibility.
43
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
44
- mod
45
- ));
46
- var __async = (__this, __arguments, generator) => {
47
- return new Promise((resolve, reject) => {
48
- var fulfilled = (value) => {
49
- try {
50
- step(generator.next(value));
51
- } catch (e) {
52
- reject(e);
53
- }
54
- };
55
- var rejected = (value) => {
56
- try {
57
- step(generator.throw(value));
58
- } catch (e) {
59
- reject(e);
60
- }
61
- };
62
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
63
- step((generator = generator.apply(__this, __arguments)).next());
64
- });
65
- };
66
-
67
- // src/cli.ts
68
- var import_node_process2 = __toESM(require("process"));
69
- var import_semver = __toESM(require("semver"));
70
-
71
- // src/js/index.ts
72
- var import_magic_string = __toESM(require("magic-string"));
73
-
74
- // src/escape.ts
75
- var escape_exports = {};
76
- __export(escape_exports, {
77
- decodeUnicode: () => decodeUnicode,
78
- decodeUnicode2: () => decodeUnicode2,
79
- jsStringEscape: () => import_escape.jsStringEscape
80
- });
81
- __reExport(escape_exports, require("@weapp-core/escape"));
82
- var import_escape = require("@ast-core/escape");
83
- function decodeUnicode(s) {
84
- return unescape(s.replaceAll(/\\(u[\dA-Fa-f]{4})/g, "%$1"));
85
- }
86
- function decodeUnicode2(input) {
87
- try {
88
- return JSON.parse(`"${input}"`);
89
- } catch (_error) {
90
- return input;
91
- }
92
- }
93
-
94
- // src/wxml/shared.ts
95
- function replaceWxml(original, options = {
96
- keepEOL: false,
97
- escapeMap: escape_exports.SimpleMappingChars2String
98
- }) {
99
- const { keepEOL, escapeMap, mangleContext, ignoreHead } = options;
100
- let res = original;
101
- if (!keepEOL) {
102
- res = res.replaceAll(/[\n\r]+/g, "");
103
- }
104
- if (mangleContext) {
105
- res = mangleContext.wxmlHandler(res);
106
- }
107
- res = (0, escape_exports.escape)(res, {
108
- map: escapeMap,
109
- ignoreHead
110
- });
111
- return res;
112
- }
113
-
114
- // src/reg.ts
115
- var reg_exports = {};
116
- __reExport(reg_exports, require("@weapp-core/regex"));
117
-
118
- // src/extractors/split.ts
119
- var validateFilterRE = /[\w\u00A0-\uFFFF%-?]/;
120
- function isValidSelector(selector = "") {
121
- return validateFilterRE.test(selector);
122
- }
123
- function splitCode(code, allowDoubleQuotes = false) {
124
- const splitter = allowDoubleQuotes ? /\s+/ : /\s+|"/;
125
- return code.split(splitter).filter((element) => isValidSelector(element));
126
- }
127
-
128
- // src/js/handlers.ts
129
- function replaceHandleValue(str, node, options, ms, offset = 0) {
130
- const {
131
- classNameSet: set,
132
- escapeMap,
133
- mangleContext: ctx,
134
- needEscaped = false,
135
- jsPreserveClass,
136
- arbitraryValues,
137
- always,
138
- unescapeUnicode
139
- } = options;
140
- const allowDoubleQuotes = arbitraryValues == null ? void 0 : arbitraryValues.allowDoubleQuotes;
141
- let rawStr = str;
142
- let needUpdate = false;
143
- if (unescapeUnicode && rawStr.includes("\\u")) {
144
- rawStr = decodeUnicode2(rawStr);
145
- }
146
- const arr = splitCode(rawStr, allowDoubleQuotes);
147
- for (const v of arr) {
148
- if (always || set && set.has(v) && !(jsPreserveClass == null ? void 0 : jsPreserveClass(v))) {
149
- let ignoreFlag = false;
150
- if (Array.isArray(node.leadingComments)) {
151
- ignoreFlag = node.leadingComments.findIndex((x) => x.value.includes("weapp-tw") && x.value.includes("ignore")) > -1;
152
- }
153
- if (!ignoreFlag) {
154
- if (ctx) {
155
- rawStr = ctx.jsHandler(rawStr);
156
- }
157
- rawStr = rawStr.replace(
158
- new RegExp((0, reg_exports.escapeStringRegexp)(v)),
159
- replaceWxml(v, {
160
- escapeMap
161
- })
162
- );
163
- needUpdate = true;
164
- }
165
- }
166
- }
167
- if (needUpdate && typeof node.start === "number" && typeof node.end === "number") {
168
- const start = node.start + offset;
169
- const end = node.end - offset;
170
- if (start < end && str !== rawStr) {
171
- const content = needEscaped ? (0, import_escape.jsStringEscape)(rawStr) : rawStr;
172
- ms.update(start, end, content);
173
- }
174
- }
175
- return rawStr;
176
- }
177
-
178
- // src/babel/index.ts
179
- var import_generator = __toESM(require("@babel/generator"));
180
- var import_traverse = __toESM(require("@babel/traverse"));
181
- var import_parser = require("@babel/parser");
182
- function _interopDefaultCompat(e) {
183
- return e && typeof e === "object" && "default" in e ? e.default : e;
184
- }
185
- var generate = _interopDefaultCompat(import_generator.default);
186
- var traverse = _interopDefaultCompat(import_traverse.default);
187
-
188
- // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
189
- function isPlainObject(value) {
190
- if (value === null || typeof value !== "object") {
191
- return false;
192
- }
193
- const prototype = Object.getPrototypeOf(value);
194
- if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
195
- return false;
196
- }
197
- if (Symbol.iterator in value) {
198
- return false;
199
- }
200
- if (Symbol.toStringTag in value) {
201
- return Object.prototype.toString.call(value) === "[object Module]";
202
- }
203
- return true;
204
- }
205
- function _defu(baseObject, defaults, namespace = ".", merger) {
206
- if (!isPlainObject(defaults)) {
207
- return _defu(baseObject, {}, namespace, merger);
208
- }
209
- const object = Object.assign({}, defaults);
210
- for (const key in baseObject) {
211
- if (key === "__proto__" || key === "constructor") {
212
- continue;
213
- }
214
- const value = baseObject[key];
215
- if (value === null || value === void 0) {
216
- continue;
217
- }
218
- if (merger && merger(object, key, value, namespace)) {
219
- continue;
220
- }
221
- if (Array.isArray(value) && Array.isArray(object[key])) {
222
- object[key] = [...value, ...object[key]];
223
- } else if (isPlainObject(value) && isPlainObject(object[key])) {
224
- object[key] = _defu(
225
- value,
226
- object[key],
227
- (namespace ? `${namespace}.` : "") + key.toString(),
228
- merger
229
- );
230
- } else {
231
- object[key] = value;
232
- }
233
- }
234
- return object;
235
- }
236
- function createDefu(merger) {
237
- return (...arguments_) => (
238
- // eslint-disable-next-line unicorn/no-array-reduce
239
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
240
- );
241
- }
242
- var defu = createDefu();
243
- var defuFn = createDefu((object, key, currentValue) => {
244
- if (object[key] !== void 0 && typeof currentValue === "function") {
245
- object[key] = currentValue(object[key]);
246
- return true;
247
- }
248
- });
249
- var defuArrayFn = createDefu((object, key, currentValue) => {
250
- if (Array.isArray(object[key]) && typeof currentValue === "function") {
251
- object[key] = currentValue(object[key]);
252
- return true;
253
- }
254
- });
255
-
256
- // src/utils.ts
257
- function isMap(value) {
258
- return Object.prototype.toString.call(value) === "[object Map]";
259
- }
260
- function noop() {
261
- }
262
- var defuOverrideArray = createDefu((obj, key, value) => {
263
- if (Array.isArray(obj[key]) && Array.isArray(value)) {
264
- obj[key] = value;
265
- return true;
266
- }
267
- });
268
-
269
- // src/js/index.ts
270
- function isEvalPath(p) {
271
- if (p.isCallExpression()) {
272
- const calleePath = p.get("callee");
273
- return calleePath.isIdentifier() && calleePath.node.name === "eval";
274
- }
275
- return false;
276
- }
277
- function getAstGrep() {
278
- return __async(this, null, function* () {
279
- try {
280
- const { js } = yield import("@ast-grep/napi");
281
- return js;
282
- } catch (error) {
283
- console.warn("\u8BF7\u5148\u5B89\u88C5 `@ast-grep/napi` , \u5B89\u88C5\u5B8C\u6210\u540E\u518D\u5C1D\u8BD5\u8FD0\u884C\uFF01");
284
- throw error;
285
- }
286
- });
287
- }
288
- function astGrepUpdateString(ast, options, ms) {
289
- return __async(this, null, function* () {
290
- const js = yield getAstGrep();
291
- const nodes = ast.findAll(js.kind("string"));
292
- for (const node of nodes) {
293
- const range = node.range();
294
- const text = node.text();
295
- replaceHandleValue(
296
- text.slice(1, -1),
297
- {
298
- end: range.end.index - 1,
299
- start: range.start.index + 1
300
- },
301
- __spreadProps(__spreadValues({}, options), {
302
- unescapeUnicode: true
303
- }),
304
- ms,
305
- 0
306
- );
307
- }
308
- const templateNodes = ast.findAll(js.kind("template_string"));
309
- for (const node of templateNodes) {
310
- const fragments = node.findAll(js.kind("string_fragment"));
311
- for (const fragment of fragments) {
312
- const range = fragment.range();
313
- const text = fragment.text();
314
- replaceHandleValue(
315
- text,
316
- {
317
- end: range.end.index,
318
- start: range.start.index
319
- },
320
- __spreadProps(__spreadValues({}, options), {
321
- unescapeUnicode: true
322
- }),
323
- ms,
324
- 0
325
- );
326
- }
327
- }
328
- });
329
- }
330
- function jsHandler(rawSource, options) {
331
- const ms = new import_magic_string.default(rawSource);
332
- let ast;
333
- try {
334
- ast = (0, import_parser.parse)(rawSource, options.babelParserOptions);
335
- } catch (error) {
336
- return {
337
- code: rawSource,
338
- error
339
- };
340
- }
341
- const traverseOptions = {
342
- StringLiteral: {
343
- enter(p) {
344
- var _a;
345
- if (isEvalPath(p.parentPath)) {
346
- return;
347
- }
348
- const n = p.node;
349
- replaceHandleValue(
350
- n.value,
351
- n,
352
- __spreadProps(__spreadValues({}, options), {
353
- needEscaped: (_a = options.needEscaped) != null ? _a : true
354
- }),
355
- ms,
356
- 1
357
- );
358
- }
359
- // exit(p) {}
360
- },
361
- TemplateElement: {
362
- enter(p) {
363
- if (p.parentPath.isTemplateLiteral() && isEvalPath(p.parentPath.parentPath)) {
364
- return;
365
- }
366
- const n = p.node;
367
- replaceHandleValue(
368
- n.value.raw,
369
- n,
370
- __spreadProps(__spreadValues({}, options), {
371
- needEscaped: false
372
- }),
373
- ms,
374
- 0
375
- );
376
- }
377
- },
378
- CallExpression: {
379
- enter(p) {
380
- if (isEvalPath(p)) {
381
- p.traverse({
382
- StringLiteral: {
383
- enter(s) {
384
- const res = jsHandler(s.node.value, __spreadProps(__spreadValues({}, options), {
385
- needEscaped: false,
386
- generateMap: false
387
- }));
388
- if (res.code) {
389
- const node = s.node;
390
- if (typeof node.start === "number" && typeof node.end === "number") {
391
- const start = node.start + 1;
392
- const end = node.end - 1;
393
- if (start < end && s.node.value !== res.code) {
394
- ms.update(start, end, (0, import_escape.jsStringEscape)(res.code));
395
- node.value = res.code;
396
- }
397
- }
398
- }
399
- }
400
- },
401
- TemplateElement: {
402
- enter(s) {
403
- const res = jsHandler(s.node.value.raw, __spreadProps(__spreadValues({}, options), {
404
- generateMap: false
405
- }));
406
- if (res.code) {
407
- const node = s.node;
408
- if (typeof node.start === "number" && typeof node.end === "number") {
409
- const start = node.start;
410
- const end = node.end;
411
- if (start < end && s.node.value.raw !== res.code) {
412
- ms.update(start, end, res.code);
413
- s.node.value.raw = res.code;
414
- }
415
- }
416
- }
417
- }
418
- }
419
- });
420
- }
421
- }
422
- }
423
- };
424
- traverse(ast, traverseOptions);
425
- return {
426
- code: ms.toString()
427
- };
428
- }
429
- function jsHandlerAsync(rawSource, options) {
430
- return __async(this, null, function* () {
431
- const ms = new import_magic_string.default(rawSource);
432
- const js = yield getAstGrep();
433
- let ast;
1
+ 'use strict';
2
+
3
+ var process = require('node:process');
4
+ var semver = require('semver');
5
+ var options = require('./options-C-rvBixk.js');
6
+ var index = require('./index-DwZHOkK3.js');
7
+ require('magic-string');
8
+ require('./replace.js');
9
+ require('@weapp-core/escape');
10
+ require('@ast-core/escape');
11
+ require('./shared-hzYeE1wX.js');
12
+ require('@weapp-core/regex');
13
+ require('@babel/generator');
14
+ require('@babel/traverse');
15
+ require('@babel/parser');
16
+ require('./defaults-DW-EahCC.js');
17
+ require('./defu-Cdz2PomB.js');
18
+ require('@babel/types');
19
+ require('htmlparser2');
20
+ require('postcss');
21
+ require('node:path');
22
+ require('tailwindcss-patch');
23
+ require('@tailwindcss-mangle/shared');
24
+ require('lru-cache');
25
+ require('md5');
26
+ require('@csstools/postcss-is-pseudo-class');
27
+ require('postcss-rem-to-responsive-pixel');
28
+ require('postcss-selector-parser');
29
+
30
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
31
+
32
+ var process__default = /*#__PURE__*/_interopDefaultCompat(process);
33
+ var semver__default = /*#__PURE__*/_interopDefaultCompat(semver);
34
+
35
+ process__default["default"].title = 'node (weapp-tailwindcss)';
36
+ const args = process__default["default"].argv.slice(2);
37
+ if (semver__default["default"].lt(process__default["default"].versions.node, index.WEAPP_TW_REQUIRED_NODE_VERSION)) {
38
+ console.error(`You are using Node.js ${process__default["default"].versions.node}. For weapp-tailwindcss, Node.js version >= v${index.WEAPP_TW_REQUIRED_NODE_VERSION} is required.`);
39
+ process__default["default"].exit(1);
40
+ }
41
+ const command = args[0];
42
+ if (command === 'patch') {
43
+ const options$1 = options.getOptions();
44
+ options$1.patch();
45
+ }
46
+ else {
434
47
  try {
435
- const root = yield js.parseAsync(rawSource);
436
- ast = root.root();
437
- } catch (e) {
438
- return {
439
- code: rawSource
440
- };
441
- }
442
- yield astGrepUpdateString(ast, options, ms);
443
- return {
444
- code: ms.toString()
445
- };
446
- });
447
- }
448
- function createJsHandler(options) {
449
- const { mangleContext, arbitraryValues, escapeMap, jsPreserveClass, generateMap, jsAstTool, babelParserOptions } = options;
450
- function _jsHandler(rawSource, set, options2) {
451
- const opts = defuOverrideArray(options2, {
452
- classNameSet: set,
453
- escapeMap,
454
- arbitraryValues,
455
- mangleContext,
456
- jsPreserveClass,
457
- generateMap,
458
- jsAstTool,
459
- babelParserOptions
460
- });
461
- if (opts.jsAstTool === "ast-grep") {
462
- return jsHandlerAsync(rawSource, opts);
463
- }
464
- return jsHandler(rawSource, opts);
465
- }
466
- function sync(rawSource, set, options2) {
467
- const opts = defuOverrideArray(options2, {
468
- classNameSet: set,
469
- escapeMap,
470
- arbitraryValues,
471
- mangleContext,
472
- jsPreserveClass,
473
- generateMap,
474
- jsAstTool,
475
- babelParserOptions
476
- });
477
- return jsHandler(rawSource, opts);
478
- }
479
- _jsHandler.sync = sync;
480
- return _jsHandler;
481
- }
482
-
483
- // src/defaults.ts
484
- var defaultOptions = {
485
- cssMatcher: (file) => /.+\.(?:wx|ac|jx|tt|q|c|ty)ss$/.test(file),
486
- htmlMatcher: (file) => /.+\.(?:(?:wx|ax|jx|ks|tt|q|ty)ml|swan)$/.test(file),
487
- jsMatcher: (file) => {
488
- if (file.includes("node_modules")) {
489
- return false;
490
- }
491
- return /.+\.[cm]?js?$/.test(file);
492
- },
493
- mainCssChunkMatcher: (file, appType) => {
494
- switch (appType) {
495
- case "uni-app": {
496
- return /^common\/main/.test(file);
497
- }
498
- case "uni-app-vite": {
499
- return file.startsWith("app") || /^common\/main/.test(file);
500
- }
501
- case "mpx": {
502
- return file.startsWith("app");
503
- }
504
- case "taro": {
505
- return file.startsWith("app");
506
- }
507
- case "remax": {
508
- return file.startsWith("app");
509
- }
510
- case "rax": {
511
- return file.startsWith("bundle");
512
- }
513
- case "native": {
514
- return file.startsWith("app");
515
- }
516
- case "kbone": {
517
- return /^(?:common\/)?miniprogram-app/.test(file);
518
- }
519
- default: {
520
- return true;
521
- }
522
- }
523
- },
524
- wxsMatcher: () => {
525
- return false;
526
- },
527
- // https://tailwindcss.com/docs/preflight#border-styles-are-reset-globally
528
- cssPreflight: {
529
- "box-sizing": "border-box",
530
- "border-width": "0",
531
- "border-style": "solid",
532
- "border-color": "currentColor"
533
- },
534
- disabled: false,
535
- customRuleCallback: noop,
536
- onLoad: noop,
537
- onStart: noop,
538
- onEnd: noop,
539
- onUpdate: noop,
540
- customAttributes: {},
541
- customReplaceDictionary: escape_exports.SimpleMappingChars2String,
542
- appType: void 0,
543
- arbitraryValues: {
544
- allowDoubleQuotes: false
545
- },
546
- cssChildCombinatorReplaceValue: ["view"],
547
- inlineWxs: false,
548
- injectAdditionalCssVarScope: false,
549
- jsPreserveClass: (keyword) => {
550
- if (keyword === "*") {
551
- return true;
552
- }
553
- return false;
554
- },
555
- disabledDefaultTemplateHandler: false,
556
- cssSelectorReplacement: {
557
- root: "page",
558
- universal: ["view", "text"]
559
- },
560
- babelParserOptions: {
561
- sourceType: "unambiguous"
562
- },
563
- postcssOptions: {},
564
- cssRemoveHoverPseudoClass: true
565
- // jsAstTool: 'ast-grep'
566
- };
567
-
568
- // src/wxml/utils.ts
569
- var t = __toESM(require("@babel/types"));
570
- var import_htmlparser2 = require("htmlparser2");
571
- var import_magic_string2 = __toESM(require("magic-string"));
572
-
573
- // src/wxml/Tokenizer.ts
574
- var Tokenizer = class {
575
- constructor() {
576
- this.reset();
577
- }
578
- processChar(char, index) {
579
- switch (this.state) {
580
- case 0 /* START */:
581
- if (char === " ") {
582
- } else if (char === "{") {
583
- this.state = 2 /* OPEN_BRACE */;
584
- this.bufferStartIndex = index;
585
- this.buffer += char;
586
- this.expressionBuffer = char;
587
- this.expressionStartIndex = index;
588
- } else {
589
- this.state = 1 /* TEXT */;
590
- this.bufferStartIndex = index;
591
- this.buffer += char;
592
- }
593
- break;
594
- case 1 /* TEXT */:
595
- if (char === " ") {
596
- this.tokens.push({ start: this.bufferStartIndex, end: index, value: this.buffer, expressions: this.expressions });
597
- this.buffer = "";
598
- this.expressions = [];
599
- this.state = 0 /* START */;
600
- } else if (char === "{") {
601
- this.buffer += char;
602
- this.expressionBuffer = char;
603
- this.expressionStartIndex = index;
604
- this.state = 2 /* OPEN_BRACE */;
605
- } else {
606
- this.buffer += char;
607
- }
608
- break;
609
- case 2 /* OPEN_BRACE */:
610
- if (char === "}") {
611
- this.buffer += char;
612
- this.expressionBuffer += char;
613
- this.state = 3 /* POTENTIAL_CLOSE */;
614
- } else {
615
- this.buffer += char;
616
- this.expressionBuffer += char;
617
- }
618
- break;
619
- case 3 /* POTENTIAL_CLOSE */:
620
- if (char === "}") {
621
- this.buffer += char;
622
- this.expressionBuffer += char;
623
- this.expressions.push({
624
- start: this.expressionStartIndex,
625
- end: index + 1,
626
- value: this.expressionBuffer
627
- });
628
- this.expressionBuffer = "";
629
- this.state = 4 /* BRACES_COMPLETE */;
630
- } else {
631
- this.buffer += char;
632
- this.expressionBuffer += char;
633
- this.state = 2 /* OPEN_BRACE */;
634
- }
635
- break;
636
- case 4 /* BRACES_COMPLETE */:
637
- if (char === " ") {
638
- this.tokens.push({
639
- start: this.bufferStartIndex,
640
- end: index,
641
- value: this.buffer,
642
- expressions: this.expressions
643
- });
644
- this.buffer = "";
645
- this.expressions = [];
646
- this.state = 0 /* START */;
647
- } else if (char === "{") {
648
- this.expressionStartIndex = index;
649
- this.expressionBuffer = char;
650
- this.buffer += char;
651
- this.state = 2 /* OPEN_BRACE */;
652
- } else {
653
- this.buffer += char;
654
- this.state = 1 /* TEXT */;
655
- }
656
- break;
657
- default:
658
- throw new Error("Unexpected state");
659
- }
660
- }
661
- run(input) {
662
- for (let i = 0; i < input.length; i++) {
663
- const char = input[i];
664
- this.processChar(char, i);
665
- }
666
- if (this.buffer.length > 0) {
667
- this.tokens.push({
668
- start: this.bufferStartIndex,
669
- end: input.length,
670
- value: this.buffer,
671
- expressions: this.expressions
672
- });
673
- }
674
- return this.tokens;
675
- }
676
- reset() {
677
- this.state = 0 /* START */;
678
- this.buffer = "";
679
- this.tokens = [];
680
- this.bufferStartIndex = 0;
681
- this.expressionBuffer = "";
682
- this.expressionStartIndex = 0;
683
- this.expressions = [];
684
- }
685
- };
686
-
687
- // src/wxml/utils.ts
688
- function generateCode(match, options = {}) {
689
- try {
690
- const { jsHandler: jsHandler2, runtimeSet } = options;
691
- if (jsHandler2 && jsHandler2.sync && runtimeSet) {
692
- const { code } = jsHandler2.sync(match, runtimeSet);
693
- return code;
694
- } else {
695
- const ms = new import_magic_string2.default(match);
696
- const ast = (0, import_parser.parseExpression)(match);
697
- traverse(ast, {
698
- StringLiteral(path2) {
699
- var _a, _b;
700
- if (t.isMemberExpression(path2.parent)) {
701
- return;
702
- }
703
- if (t.isBinaryExpression(path2.parent) && (t.isConditionalExpression((_a = path2.parentPath) == null ? void 0 : _a.parent) || t.isLogicalExpression((_b = path2.parentPath) == null ? void 0 : _b.parent))) {
704
- return;
705
- }
706
- const n = path2.node;
707
- replaceHandleValue(
708
- n.value,
709
- n,
710
- {
711
- mangleContext: options.mangleContext,
712
- escapeMap: options.escapeMap,
713
- classNameSet: options.runtimeSet,
714
- needEscaped: true,
715
- always: true
716
- },
717
- ms,
718
- 1
719
- );
720
- },
721
- noScope: true
722
- });
723
- return ms.toString();
724
- }
725
- } catch (e) {
726
- return match;
727
- }
728
- }
729
- function extract(original, reg) {
730
- let match = reg.exec(original);
731
- const sources = [];
732
- while (match !== null) {
733
- const start = match.index;
734
- const end = reg.lastIndex;
735
- sources.push({
736
- start,
737
- end,
738
- raw: match[1]
739
- });
740
- match = reg.exec(original);
741
- }
742
- return sources;
743
- }
744
- function extractSource(original) {
745
- return extract(original, reg_exports.variableRegExp);
746
- }
747
- function handleEachClassFragment(original, options = {}) {
748
- const sources = extractSource(original);
749
- if (sources.length > 0) {
750
- const resultArray = [];
751
- let p = 0;
752
- for (let i = 0; i < sources.length; i++) {
753
- const m = sources[i];
754
- const before = original.slice(p, m.start);
755
- resultArray.push(
756
- replaceWxml(before, {
757
- keepEOL: true,
758
- escapeMap: options.escapeMap,
759
- mangleContext: options.mangleContext,
760
- // 首的str才会被转译
761
- // example: 2xl:xx 2x{{y}}
762
- ignoreHead: p > 0
763
- })
764
- );
765
- p = m.start;
766
- if (m.raw.trim().length > 0) {
767
- const code = generateCode(m.raw, options);
768
- const source = `{{${code}}}`;
769
- m.source = source;
770
- } else {
771
- m.source = "";
772
- }
773
- resultArray.push(m.source);
774
- p = m.end;
775
- if (i === sources.length - 1) {
776
- const after = original.slice(m.end);
777
- resultArray.push(
778
- replaceWxml(after, {
779
- keepEOL: true,
780
- escapeMap: options.escapeMap,
781
- mangleContext: options.mangleContext,
782
- ignoreHead: true
783
- })
784
- );
785
- }
786
- }
787
- return resultArray.filter(Boolean).join("").trim();
788
- } else {
789
- return replaceWxml(original, {
790
- keepEOL: false,
791
- escapeMap: options.escapeMap,
792
- mangleContext: options.mangleContext,
793
- ignoreHead: false
794
- });
795
- }
796
- }
797
- function templateReplacer(original, options = {}) {
798
- const ms = new import_magic_string2.default(original);
799
- const tokenizer = new Tokenizer();
800
- const tokens = tokenizer.run(ms.original);
801
- for (const token of tokens) {
802
- const target = handleEachClassFragment(token.value, options);
803
- ms.update(token.start, token.end, target);
804
- }
805
- return ms.toString();
806
- }
807
- function regTest(reg, str) {
808
- reg.lastIndex = 0;
809
- return reg.test(str);
810
- }
811
- function isPropsMatch(props, attr) {
812
- if (Array.isArray(props)) {
813
- for (const prop of props) {
814
- const res = typeof prop === "string" ? prop.toLowerCase() === attr.toLowerCase() : regTest(prop, attr);
815
- if (res) {
816
- return res;
817
- }
818
- }
819
- return false;
820
- } else if (typeof props === "string") {
821
- return props === attr;
822
- } else {
823
- return regTest(props, attr);
824
- }
825
- }
826
- function customTemplateHandler(rawSource, options) {
827
- return __async(this, null, function* () {
828
- const {
829
- customAttributesEntities = [],
830
- disabledDefaultTemplateHandler,
831
- inlineWxs,
832
- runtimeSet,
833
- jsHandler: jsHandler2
834
- } = options != null ? options : {};
835
- const s = new import_magic_string2.default(rawSource);
836
- let tag = "";
837
- const wxsArray = [];
838
- const parser = new import_htmlparser2.Parser(
839
- {
840
- onopentagname(name) {
841
- tag = name;
842
- },
843
- onattribute(name, value, quote) {
844
- if (value) {
845
- let update2 = function() {
846
- s.update(
847
- parser.startIndex + name.length + 2,
848
- // !important
849
- // htmlparser2 9.0.0: parser.endIndex
850
- // htmlparser2 9.1.0: parser.endIndex - 1
851
- // https://github.com/sonofmagic/weapp-tailwindcss/issues/269
852
- parser.endIndex - 1,
853
- templateReplacer(value, __spreadProps(__spreadValues({}, options), {
854
- quote
855
- }))
856
- );
857
- };
858
- var update = update2;
859
- if (!disabledDefaultTemplateHandler && (name === "class" || name === "hover-class" || name === "virtualHostClass" || name === "virtualhostclass")) {
860
- update2();
861
- }
862
- for (const [t2, props] of customAttributesEntities) {
863
- if (t2 === "*") {
864
- if (isPropsMatch(props, name)) {
865
- update2();
866
- }
867
- } else if (typeof t2 === "string") {
868
- if (t2 === tag && isPropsMatch(props, name)) {
869
- update2();
870
- }
871
- } else if (regTest(t2, tag) && isPropsMatch(props, name)) {
872
- update2();
873
- }
874
- }
875
- }
876
- },
877
- ontext(data) {
878
- if (inlineWxs && tag === "wxs") {
879
- wxsArray.push({
880
- data,
881
- endIndex: parser.endIndex + 1,
882
- startIndex: parser.startIndex
883
- });
884
- }
885
- },
886
- onclosetag() {
887
- tag = "";
888
- }
889
- },
890
- {
891
- xmlMode: true
892
- }
893
- );
894
- parser.write(s.original);
895
- parser.end();
896
- for (const { data, endIndex, startIndex } of wxsArray) {
897
- const { code } = yield jsHandler2(data, runtimeSet);
898
- s.update(startIndex, endIndex, code);
899
- }
900
- return s.toString();
901
- });
902
- }
903
- function createTemplateHandler(options = {}) {
904
- return (rawSource, opt = {}) => {
905
- return customTemplateHandler(rawSource, defuOverrideArray(opt, options));
906
- };
907
- }
908
-
909
- // src/postcss/index.ts
910
- var import_postcss2 = __toESM(require("postcss"));
911
-
912
- // src/postcss/plugins/index.ts
913
- var import_postcss_is_pseudo_class = __toESM(require("@csstools/postcss-is-pseudo-class"));
914
- var import_postcss_rem_to_responsive_pixel = __toESM(require("postcss-rem-to-responsive-pixel"));
915
-
916
- // src/postcss/selectorParser.ts
917
- var import_postcss_selector_parser = __toESM(require("postcss-selector-parser"));
918
-
919
- // src/postcss/shared.ts
920
- function internalCssSelectorReplacer(selectors, options = {
921
- escapeMap: escape_exports.SimpleMappingChars2String
922
- }) {
923
- const { mangleContext, escapeMap } = options;
924
- if (mangleContext) {
925
- selectors = mangleContext.cssHandler(selectors);
926
- }
927
- return (0, escape_exports.escape)(selectors, {
928
- map: escapeMap
929
- });
930
- }
931
- function composeIsPseudo(strs) {
932
- if (typeof strs === "string") {
933
- return strs;
934
- }
935
- if (strs.length > 1) {
936
- return `:is(${strs.join(",")})`;
937
- }
938
- return strs.join("");
939
- }
940
-
941
- // src/postcss/selectorParser.ts
942
- function createRuleTransform(rule, options) {
943
- const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass } = options;
944
- const transform = (selectors) => {
945
- selectors.walk((selector) => {
946
- if (selector.type === "universal" && cssSelectorReplacement && cssSelectorReplacement.universal) {
947
- selector.value = composeIsPseudo(cssSelectorReplacement.universal);
948
- }
949
- if (cssRemoveHoverPseudoClass && selector.type === "selector") {
950
- const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
951
- node && selector.remove();
952
- }
953
- if (selector.type === "pseudo" && selector.value === ":root" && cssSelectorReplacement && cssSelectorReplacement.root) {
954
- selector.value = composeIsPseudo(cssSelectorReplacement.root);
955
- }
956
- if (selector.type === "class") {
957
- selector.value = internalCssSelectorReplacer(selector.value, {
958
- escapeMap,
959
- mangleContext
960
- });
961
- }
962
- });
963
- if (selectors.length === 0) {
964
- rule.remove();
965
- }
966
- };
967
- return transform;
968
- }
969
- function getRuleTransformer(rule, options) {
970
- return (0, import_postcss_selector_parser.default)(createRuleTransform(rule, options));
971
- }
972
- function ruleTransformSync(rule, options) {
973
- const transformer = getRuleTransformer(rule, options);
974
- return transformer.transformSync(rule, {
975
- lossless: false,
976
- updateSelector: true
977
- });
978
- }
979
- function isOnlyBeforeAndAfterPseudoElement(node) {
980
- let b = false;
981
- let a = false;
982
- (0, import_postcss_selector_parser.default)((selectors) => {
983
- selectors.walkPseudos((s) => {
984
- var _a;
985
- if (((_a = s.parent) == null ? void 0 : _a.length) === 1) {
986
- if (/^:?:before$/.test(s.value)) {
987
- b = true;
988
- }
989
- if (/^:?:after$/.test(s.value)) {
990
- a = true;
991
- }
992
- }
993
- });
994
- }).astSync(node);
995
- return b && a;
996
- }
997
- var fallbackRemove = (0, import_postcss_selector_parser.default)((selectors) => {
998
- selectors.walk((selector) => {
999
- var _a, _b;
1000
- if (selector.type === "universal") {
1001
- (_a = selector.parent) == null ? void 0 : _a.remove();
1002
- }
1003
- if (selector.type === "pseudo" && selector.value === ":is") {
1004
- (_b = selector.parent) == null ? void 0 : _b.remove();
1005
- }
1006
- });
1007
- });
1008
-
1009
- // src/postcss/mp.ts
1010
- var import_postcss = require("postcss");
1011
-
1012
- // src/postcss/cssVars.ts
1013
- var cssVars_default = [
1014
- {
1015
- prop: "--tw-border-spacing-x",
1016
- value: "0"
1017
- },
1018
- {
1019
- prop: "--tw-border-spacing-y",
1020
- value: "0"
1021
- },
1022
- {
1023
- prop: "--tw-translate-x",
1024
- value: "0"
1025
- },
1026
- {
1027
- prop: "--tw-translate-y",
1028
- value: "0"
1029
- },
1030
- {
1031
- prop: "--tw-rotate",
1032
- value: "0"
1033
- },
1034
- {
1035
- prop: "--tw-skew-x",
1036
- value: "0"
1037
- },
1038
- {
1039
- prop: "--tw-skew-y",
1040
- value: "0"
1041
- },
1042
- {
1043
- prop: "--tw-scale-x",
1044
- value: "1"
1045
- },
1046
- {
1047
- prop: "--tw-scale-y",
1048
- value: "1"
1049
- },
1050
- {
1051
- prop: "--tw-pan-x",
1052
- value: " "
1053
- },
1054
- {
1055
- prop: "--tw-pan-y",
1056
- value: " "
1057
- },
1058
- {
1059
- prop: "--tw-pinch-zoom",
1060
- value: " "
1061
- },
1062
- {
1063
- prop: "--tw-scroll-snap-strictness",
1064
- value: "proximity"
1065
- },
1066
- {
1067
- prop: "--tw-gradient-from-position",
1068
- value: " "
1069
- },
1070
- {
1071
- prop: "--tw-gradient-via-position",
1072
- value: " "
1073
- },
1074
- {
1075
- prop: "--tw-gradient-to-position",
1076
- value: " "
1077
- },
1078
- {
1079
- prop: "--tw-ordinal",
1080
- value: " "
1081
- },
1082
- {
1083
- prop: "--tw-slashed-zero",
1084
- value: " "
1085
- },
1086
- {
1087
- prop: "--tw-numeric-figure",
1088
- value: " "
1089
- },
1090
- {
1091
- prop: "--tw-numeric-spacing",
1092
- value: " "
1093
- },
1094
- {
1095
- prop: "--tw-numeric-fraction",
1096
- value: " "
1097
- },
1098
- {
1099
- prop: "--tw-ring-inset",
1100
- value: " "
1101
- },
1102
- {
1103
- prop: "--tw-ring-offset-width",
1104
- value: "0px"
1105
- },
1106
- {
1107
- prop: "--tw-ring-offset-color",
1108
- value: "#fff"
1109
- },
1110
- {
1111
- prop: "--tw-ring-color",
1112
- value: "rgb(59 130 246 / 0.5)"
1113
- },
1114
- {
1115
- prop: "--tw-ring-offset-shadow",
1116
- value: "0 0 #0000"
1117
- },
1118
- {
1119
- prop: "--tw-ring-shadow",
1120
- value: "0 0 #0000"
1121
- },
1122
- {
1123
- prop: "--tw-shadow",
1124
- value: "0 0 #0000"
1125
- },
1126
- {
1127
- prop: "--tw-shadow-colored",
1128
- value: "0 0 #0000"
1129
- },
1130
- {
1131
- prop: "--tw-blur",
1132
- value: " "
1133
- },
1134
- {
1135
- prop: "--tw-brightness",
1136
- value: " "
1137
- },
1138
- {
1139
- prop: "--tw-contrast",
1140
- value: " "
1141
- },
1142
- {
1143
- prop: "--tw-grayscale",
1144
- value: " "
1145
- },
1146
- {
1147
- prop: "--tw-hue-rotate",
1148
- value: " "
1149
- },
1150
- {
1151
- prop: "--tw-invert",
1152
- value: " "
1153
- },
1154
- {
1155
- prop: "--tw-saturate",
1156
- value: " "
1157
- },
1158
- {
1159
- prop: "--tw-sepia",
1160
- value: " "
1161
- },
1162
- {
1163
- prop: "--tw-drop-shadow",
1164
- value: " "
1165
- },
1166
- {
1167
- prop: "--tw-backdrop-blur",
1168
- value: " "
1169
- },
1170
- {
1171
- prop: "--tw-backdrop-brightness",
1172
- value: " "
1173
- },
1174
- {
1175
- prop: "--tw-backdrop-contrast",
1176
- value: " "
1177
- },
1178
- {
1179
- prop: "--tw-backdrop-grayscale",
1180
- value: " "
1181
- },
1182
- {
1183
- prop: "--tw-backdrop-hue-rotate",
1184
- value: " "
1185
- },
1186
- {
1187
- prop: "--tw-backdrop-invert",
1188
- value: " "
1189
- },
1190
- {
1191
- prop: "--tw-backdrop-opacity",
1192
- value: " "
1193
- },
1194
- {
1195
- prop: "--tw-backdrop-saturate",
1196
- value: " "
1197
- },
1198
- {
1199
- prop: "--tw-backdrop-sepia",
1200
- value: " "
1201
- },
1202
- {
1203
- prop: "--tw-contain-size",
1204
- value: " "
1205
- },
1206
- {
1207
- prop: "--tw-contain-layout",
1208
- value: " "
1209
- },
1210
- {
1211
- prop: "--tw-contain-paint",
1212
- value: " "
1213
- },
1214
- {
1215
- prop: "--tw-contain-style",
1216
- value: " "
1217
- }
1218
- ];
1219
-
1220
- // src/postcss/mp.ts
1221
- var initialNodes = cssVars_default.map((x) => {
1222
- return new import_postcss.Declaration({
1223
- prop: x.prop,
1224
- value: x.value
1225
- });
1226
- });
1227
- var PATTERNS = [
1228
- /:not\(template\)\s*[~+]\s*:not\(template\)/.source,
1229
- /:not\(\[hidden\]\)\s*[~+]\s*:not\(\[hidden\]\)/.source
1230
- ].join("|");
1231
- var BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, "g");
1232
- function testIfVariablesScope(node, count = 2) {
1233
- if (isOnlyBeforeAndAfterPseudoElement(node)) {
1234
- const nodes = node.nodes;
1235
- let c = 0;
1236
- for (const tryTestDecl of nodes) {
1237
- if (tryTestDecl && tryTestDecl.type === "decl" && tryTestDecl.prop.startsWith("--tw-")) {
1238
- c++;
1239
- }
1240
- if (c >= count) {
1241
- return true;
1242
- }
1243
- }
1244
- return false;
1245
- }
1246
- return false;
1247
- }
1248
- function testIfTwBackdrop(node, count = 2) {
1249
- if (node.type === "rule" && node.selector === "::backdrop") {
1250
- const nodes = node.nodes;
1251
- let c = 0;
1252
- for (const tryTestDecl of nodes) {
1253
- if (tryTestDecl && tryTestDecl.type === "decl" && tryTestDecl.prop.startsWith("--tw-")) {
1254
- c++;
1255
- }
1256
- if (c >= count) {
1257
- return true;
1258
- }
1259
- }
1260
- return false;
1261
- }
1262
- return false;
1263
- }
1264
- function makePseudoVarRule() {
1265
- const pseudoVarRule = new import_postcss.Rule({
1266
- // selectors: ['::before', '::after'],
1267
- selector: "::before,::after"
1268
- });
1269
- pseudoVarRule.append(
1270
- new import_postcss.Declaration({
1271
- prop: "--tw-content",
1272
- value: '""'
1273
- })
1274
- );
1275
- return pseudoVarRule;
1276
- }
1277
- function remakeCssVarSelector(selectors, options) {
1278
- const { cssPreflightRange, cssSelectorReplacement } = options;
1279
- if (cssPreflightRange === "all" && !selectors.includes(":not(not)")) {
1280
- selectors.push(":not(not)");
1281
- }
1282
- if (cssSelectorReplacement) {
1283
- if (Array.isArray(cssSelectorReplacement.universal)) {
1284
- if (!cssSelectorReplacement.universal.every((x) => {
1285
- return selectors.includes(x);
1286
- }) && !selectors.includes("*")) {
1287
- selectors.unshift("*");
1288
- }
1289
- } else if (typeof cssSelectorReplacement.universal === "string" && !selectors.includes(cssSelectorReplacement.universal) && !selectors.includes("*")) {
1290
- selectors.unshift("*");
1291
- }
1292
- }
1293
- return selectors;
1294
- }
1295
- function remakeCombinatorSelector(selector, cssChildCombinatorReplaceValue) {
1296
- let childCombinatorReplaceValue = "view + view";
1297
- if (Array.isArray(cssChildCombinatorReplaceValue) && cssChildCombinatorReplaceValue.length > 0) {
1298
- const x = composeIsPseudo(cssChildCombinatorReplaceValue);
1299
- childCombinatorReplaceValue = `${x} + ${x}`;
1300
- } else if (typeof cssChildCombinatorReplaceValue === "string") {
1301
- childCombinatorReplaceValue = cssChildCombinatorReplaceValue;
1302
- }
1303
- return selector.replaceAll(BROAD_MATCH_GLOBAL_REGEXP, childCombinatorReplaceValue);
1304
- }
1305
- function commonChunkPreflight(node, options) {
1306
- const { ctx, cssChildCombinatorReplaceValue, cssInjectPreflight, injectAdditionalCssVarScope } = options;
1307
- node.selector = remakeCombinatorSelector(node.selector, cssChildCombinatorReplaceValue);
1308
- if (testIfVariablesScope(node)) {
1309
- ctx == null ? void 0 : ctx.markVariablesScope(node);
1310
- node.selectors = remakeCssVarSelector(node.selectors, options);
1311
- node.before(makePseudoVarRule());
1312
- if (typeof cssInjectPreflight === "function") {
1313
- node.append(...cssInjectPreflight());
1314
- }
1315
- }
1316
- if (injectAdditionalCssVarScope && testIfTwBackdrop(node)) {
1317
- const syntheticRule = new import_postcss.Rule({
1318
- selectors: ["*", "::after", "::before"],
1319
- nodes: initialNodes
1320
- });
1321
- syntheticRule.selectors = remakeCssVarSelector(syntheticRule.selectors, options);
1322
- node.before(syntheticRule);
1323
- node.before(makePseudoVarRule());
1324
- if (typeof cssInjectPreflight === "function") {
1325
- syntheticRule.append(...cssInjectPreflight());
1326
- }
1327
- }
1328
- }
1329
-
1330
- // src/constants.ts
1331
- var postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
1332
- var WEAPP_TW_REQUIRED_NODE_VERSION = "16.6.0";
1333
-
1334
- // src/postcss/plugins/pre.ts
1335
- function isAtMediaHover(atRule) {
1336
- return /media\(\s*hover\s*:\s*hover\s*\)/.test(atRule.name) || atRule.name === "media" && /\(\s*hover\s*:\s*hover\s*\)/.test(atRule.params);
1337
- }
1338
- var postcssWeappTailwindcssPrePlugin = (options = {
1339
- isMainChunk: true
1340
- }) => {
1341
- const { isMainChunk } = options;
1342
- const p = {
1343
- postcssPlugin,
1344
- Rule(rule) {
1345
- ruleTransformSync(rule, options);
1346
- },
1347
- AtRule(atRule) {
1348
- if (isAtMediaHover(atRule)) {
1349
- if (atRule.nodes) {
1350
- atRule.replaceWith(atRule.nodes);
1351
- } else {
1352
- atRule.remove();
1353
- }
1354
- }
1355
- }
1356
- };
1357
- if (isMainChunk) {
1358
- p.Once = (root) => {
1359
- root.walkRules((rule) => {
1360
- commonChunkPreflight(rule, options);
1361
- });
1362
- };
1363
- }
1364
- return p;
1365
- };
1366
- postcssWeappTailwindcssPrePlugin.postcss = true;
1367
-
1368
- // src/postcss/plugins/post.ts
1369
- var postcssWeappTailwindcssPostPlugin = (options = {
1370
- isMainChunk: true
1371
- }) => {
1372
- const { customRuleCallback, isMainChunk, ctx } = options;
1373
- const p = {
1374
- postcssPlugin
1375
- };
1376
- if (isMainChunk) {
1377
- p.OnceExit = (root) => {
1378
- root.walkRules((rule) => {
1379
- if (ctx) {
1380
- if (ctx.isVariablesScope(rule)) {
1381
- fallbackRemove.transformSync(rule, {
1382
- updateSelector: true,
1383
- lossless: false
1384
- });
1385
- }
1386
- } else if (testIfVariablesScope(rule)) {
1387
- fallbackRemove.transformSync(rule, {
1388
- updateSelector: true,
1389
- lossless: false
1390
- });
1391
- }
1392
- });
1393
- };
1394
- }
1395
- if (typeof customRuleCallback === "function") {
1396
- p.Rule = (rule) => {
1397
- customRuleCallback(rule, options);
1398
- };
1399
- }
1400
- return p;
1401
- };
1402
- postcssWeappTailwindcssPostPlugin.postcss = true;
1403
-
1404
- // src/postcss/symbols.ts
1405
- var VariablesScopeSymbol = Symbol("VariablesScope");
1406
-
1407
- // src/postcss/plugins/ctx.ts
1408
- function createContext() {
1409
- const variablesScopeWeakMap = /* @__PURE__ */ new WeakMap();
1410
- function isVariablesScope(rule) {
1411
- return variablesScopeWeakMap.get(rule) === VariablesScopeSymbol;
1412
- }
1413
- function markVariablesScope(rule) {
1414
- variablesScopeWeakMap.set(rule, VariablesScopeSymbol);
1415
- }
1416
- return {
1417
- variablesScopeWeakMap,
1418
- isVariablesScope,
1419
- markVariablesScope
1420
- };
1421
- }
1422
-
1423
- // src/postcss/plugins/index.ts
1424
- var import_postcss_is_pseudo_class2 = __toESM(require("@csstools/postcss-is-pseudo-class"));
1425
- var import_postcss_rem_to_responsive_pixel2 = __toESM(require("postcss-rem-to-responsive-pixel"));
1426
- function getPlugins(options) {
1427
- var _a, _b;
1428
- const ctx = createContext();
1429
- options.ctx = ctx;
1430
- const plugins = [
1431
- ...(_b = (_a = options.postcssOptions) == null ? void 0 : _a.plugins) != null ? _b : [],
1432
- postcssWeappTailwindcssPrePlugin(options),
1433
- (0, import_postcss_is_pseudo_class.default)({
1434
- specificityMatchingName: "weapp-tw-ig"
1435
- })
1436
- ];
1437
- if (options.rem2rpx) {
1438
- plugins.push(
1439
- (0, import_postcss_rem_to_responsive_pixel.default)(
1440
- typeof options.rem2rpx === "object" ? options.rem2rpx : {
1441
- rootValue: 32,
1442
- propList: ["*"],
1443
- transformUnit: "rpx"
1444
- }
1445
- )
1446
- );
1447
- }
1448
- plugins.push(postcssWeappTailwindcssPostPlugin(options));
1449
- return plugins;
1450
- }
1451
-
1452
- // src/postcss/index.ts
1453
- function styleHandler(rawSource, options) {
1454
- return __async(this, null, function* () {
1455
- var _a, _b;
1456
- return (yield (0, import_postcss2.default)(getPlugins(options)).process(
1457
- rawSource,
1458
- (_b = (_a = options.postcssOptions) == null ? void 0 : _a.options) != null ? _b : {
1459
- from: void 0
1460
- }
1461
- ).async()).css;
1462
- });
1463
- }
1464
- function createStyleHandler(options) {
1465
- return (rawSource, opt) => {
1466
- return styleHandler(
1467
- rawSource,
1468
- defuOverrideArray(opt, options)
1469
- );
1470
- };
1471
- }
1472
-
1473
- // src/postcss/preflight.ts
1474
- function createInjectPreflight(options) {
1475
- const result = [];
1476
- if (options && typeof options === "object") {
1477
- const entries = Object.entries(options);
1478
- for (const [prop, value] of entries) {
1479
- if (value !== false) {
1480
- result.push({
1481
- prop,
1482
- value: value.toString()
48
+ import('@weapp-tailwindcss/cli').then(({ createCli }) => {
49
+ createCli().parse();
1483
50
  });
1484
- }
1485
- }
1486
- }
1487
- return () => {
1488
- return result;
1489
- };
1490
- }
1491
-
1492
- // src/tailwindcss/patcher.ts
1493
- var import_node_path = __toESM(require("path"));
1494
- var import_node_process = __toESM(require("process"));
1495
- var import_tailwindcss_patch = require("tailwindcss-patch");
1496
- function createTailwindcssPatcher(basedir, cacheDir, supportCustomLengthUnitsPatch) {
1497
- const cache = {};
1498
- if (cacheDir) {
1499
- if (import_node_path.default.isAbsolute(cacheDir)) {
1500
- cache.dir = cacheDir;
1501
- } else if (basedir) {
1502
- cache.dir = import_node_path.default.resolve(basedir, cacheDir);
1503
- } else {
1504
- cache.dir = import_node_path.default.resolve(import_node_process.default.cwd(), cacheDir);
1505
51
  }
1506
- }
1507
- return new import_tailwindcss_patch.TailwindcssPatcher({
1508
- cache,
1509
- patch: {
1510
- basedir,
1511
- applyPatches: {
1512
- exportContext: true,
1513
- extendLengthUnits: supportCustomLengthUnitsPatch
1514
- }
52
+ catch (error) {
53
+ console.warn('请先安装 `@weapp-tailwindcss/cli` , 安装完成后再尝试运行!');
54
+ throw error;
1515
55
  }
1516
- });
1517
- }
1518
-
1519
- // src/mangle/index.ts
1520
- var import_shared5 = require("@tailwindcss-mangle/shared");
1521
- function getSelf(x) {
1522
- return x;
1523
- }
1524
- var defaultMangleContext = {
1525
- rawOptions: false,
1526
- runtimeSet: /* @__PURE__ */ new Set(),
1527
- classGenerator: new import_shared5.ClassGenerator(),
1528
- filter: import_shared5.defaultMangleClassFilter,
1529
- cssHandler: getSelf,
1530
- jsHandler: getSelf,
1531
- wxmlHandler: getSelf
1532
- };
1533
- function useMangleStore() {
1534
- const ctx = Object.assign({}, defaultMangleContext);
1535
- function resetMangle() {
1536
- return Object.assign(ctx, defaultMangleContext);
1537
- }
1538
- function handleValue(rawSource) {
1539
- const arr = splitCode(rawSource);
1540
- for (const x of arr) {
1541
- if (ctx.runtimeSet.has(x)) {
1542
- rawSource = rawSource.replace(new RegExp((0, reg_exports.escapeStringRegexp)(x)), ctx.classGenerator.generateClassName(x).name);
1543
- }
1544
- }
1545
- return rawSource;
1546
- }
1547
- function initMangle(options) {
1548
- var _a;
1549
- ctx.rawOptions = options;
1550
- if (options) {
1551
- if (options === true) {
1552
- options = {
1553
- classGenerator: {},
1554
- mangleClassFilter: import_shared5.defaultMangleClassFilter
1555
- };
1556
- }
1557
- ctx.classGenerator = new import_shared5.ClassGenerator(options.classGenerator);
1558
- ctx.filter = (_a = options.mangleClassFilter) != null ? _a : import_shared5.defaultMangleClassFilter;
1559
- ctx.jsHandler = (rawSource) => {
1560
- return handleValue(rawSource);
1561
- };
1562
- ctx.cssHandler = (rawSource) => {
1563
- return handleValue(rawSource);
1564
- };
1565
- ctx.wxmlHandler = (rawSource) => {
1566
- return handleValue(rawSource);
1567
- };
1568
- }
1569
- }
1570
- function setMangleRuntimeSet(runtimeSet) {
1571
- const newSet = /* @__PURE__ */ new Set();
1572
- for (const c of runtimeSet) {
1573
- if (ctx.filter(c)) {
1574
- newSet.add(c);
1575
- }
1576
- }
1577
- ctx.runtimeSet = newSet;
1578
- }
1579
- return {
1580
- mangleContext: ctx,
1581
- resetMangle,
1582
- initMangle,
1583
- setMangleRuntimeSet
1584
- };
1585
- }
1586
-
1587
- // src/cache/index.ts
1588
- var import_lru_cache = require("lru-cache");
1589
- var import_md5 = __toESM(require("md5"));
1590
- function createCache(options) {
1591
- const disabled = options === false;
1592
- const hashMap = /* @__PURE__ */ new Map();
1593
- const instance = new import_lru_cache.LRUCache({
1594
- // 可能会添加和删除一些页面和组件, 先设定 1024 吧
1595
- max: 1024,
1596
- ttl: 0,
1597
- ttlAutopurge: false
1598
- });
1599
- return {
1600
- hashMap,
1601
- instance,
1602
- hasHashKey(key) {
1603
- return hashMap.has(key);
1604
- },
1605
- getHashValue(key) {
1606
- return hashMap.get(key);
1607
- },
1608
- setHashValue(key, value) {
1609
- return hashMap.set(key, value);
1610
- },
1611
- get(key) {
1612
- return instance.get(key);
1613
- },
1614
- set(key, value) {
1615
- return instance.set(key, value);
1616
- },
1617
- computeHash(message) {
1618
- return (0, import_md5.default)(message);
1619
- },
1620
- calcHashValueChanged(key, hash) {
1621
- const hit = this.getHashValue(key);
1622
- if (hit) {
1623
- this.setHashValue(key, {
1624
- // new file should be changed
1625
- changed: hash !== hit.hash,
1626
- // new hash
1627
- hash
1628
- });
1629
- } else {
1630
- this.setHashValue(key, {
1631
- // new file should be changed
1632
- changed: true,
1633
- hash
1634
- });
1635
- }
1636
- return this;
1637
- },
1638
- has(key) {
1639
- return instance.has(key);
1640
- },
1641
- process(key, callback, fallback) {
1642
- return __async(this, null, function* () {
1643
- if (disabled) {
1644
- const res = yield fallback();
1645
- if (res) {
1646
- this.set(res.key, res.source);
1647
- }
1648
- } else {
1649
- const hit = this.getHashValue(key);
1650
- if (hit && !hit.changed) {
1651
- const returnFlag = yield callback();
1652
- if (returnFlag !== false) {
1653
- return;
1654
- }
1655
- }
1656
- const res = yield fallback();
1657
- if (res) {
1658
- this.set(res.key, res.source);
1659
- }
1660
- }
1661
- });
1662
- }
1663
- };
1664
- }
1665
-
1666
- // src/options.ts
1667
- function getOptions(opts) {
1668
- const result = defuOverrideArray(
1669
- opts,
1670
- defaultOptions,
1671
- {}
1672
- );
1673
- result.escapeMap = result.customReplaceDictionary;
1674
- const {
1675
- cssPreflight,
1676
- customRuleCallback,
1677
- cssPreflightRange,
1678
- customAttributes,
1679
- supportCustomLengthUnitsPatch,
1680
- arbitraryValues,
1681
- cssChildCombinatorReplaceValue,
1682
- inlineWxs,
1683
- injectAdditionalCssVarScope,
1684
- jsPreserveClass,
1685
- disabledDefaultTemplateHandler,
1686
- cssSelectorReplacement,
1687
- rem2rpx,
1688
- cache,
1689
- jsAstTool,
1690
- babelParserOptions,
1691
- postcssOptions,
1692
- cssRemoveHoverPseudoClass,
1693
- escapeMap,
1694
- mangle,
1695
- tailwindcssBasedir,
1696
- appType
1697
- } = result;
1698
- const cssInjectPreflight = createInjectPreflight(cssPreflight);
1699
- const customAttributesEntities = isMap(customAttributes) ? [...customAttributes.entries()] : Object.entries(customAttributes);
1700
- const { initMangle, mangleContext, setMangleRuntimeSet } = useMangleStore();
1701
- initMangle(mangle);
1702
- const styleHandler2 = createStyleHandler({
1703
- cssInjectPreflight,
1704
- customRuleCallback,
1705
- cssPreflightRange,
1706
- escapeMap,
1707
- mangleContext,
1708
- cssChildCombinatorReplaceValue,
1709
- injectAdditionalCssVarScope,
1710
- cssSelectorReplacement,
1711
- rem2rpx,
1712
- postcssOptions,
1713
- cssRemoveHoverPseudoClass
1714
- });
1715
- const jsHandler2 = createJsHandler({
1716
- escapeMap,
1717
- mangleContext,
1718
- arbitraryValues,
1719
- jsPreserveClass,
1720
- generateMap: true,
1721
- jsAstTool,
1722
- babelParserOptions
1723
- });
1724
- const templateHandler = createTemplateHandler({
1725
- customAttributesEntities,
1726
- escapeMap,
1727
- mangleContext,
1728
- inlineWxs,
1729
- jsHandler: jsHandler2,
1730
- disabledDefaultTemplateHandler
1731
- });
1732
- result.styleHandler = styleHandler2;
1733
- result.jsHandler = jsHandler2;
1734
- result.templateHandler = templateHandler;
1735
- const twPatcher = createTailwindcssPatcher(tailwindcssBasedir, appType === "mpx" ? "node_modules/tailwindcss-patch/.cache" : void 0, supportCustomLengthUnitsPatch);
1736
- result.patch = twPatcher.patch;
1737
- result.setMangleRuntimeSet = setMangleRuntimeSet;
1738
- result.cache = cache === void 0 || typeof cache === "boolean" ? createCache(cache) : cache;
1739
- result.twPatcher = twPatcher;
1740
- return result;
1741
- }
1742
-
1743
- // src/cli.ts
1744
- import_node_process2.default.title = "node (weapp-tailwindcss)";
1745
- var args = import_node_process2.default.argv.slice(2);
1746
- if (import_semver.default.lt(import_node_process2.default.versions.node, WEAPP_TW_REQUIRED_NODE_VERSION)) {
1747
- console.error(
1748
- `You are using Node.js ${import_node_process2.default.versions.node}. For weapp-tailwindcss, Node.js version >= v${WEAPP_TW_REQUIRED_NODE_VERSION} is required.`
1749
- );
1750
- import_node_process2.default.exit(1);
1751
- }
1752
- var command = args[0];
1753
- if (command === "patch") {
1754
- const options = getOptions();
1755
- options.patch();
1756
- } else {
1757
- try {
1758
- import("@weapp-tailwindcss/cli").then(({ createCli }) => {
1759
- createCli().parse();
1760
- });
1761
- } catch (error) {
1762
- console.warn("\u8BF7\u5148\u5B89\u88C5 `@weapp-tailwindcss/cli` , \u5B89\u88C5\u5B8C\u6210\u540E\u518D\u5C1D\u8BD5\u8FD0\u884C\uFF01");
1763
- throw error;
1764
- }
1765
56
  }