weapp-tailwindcss 2.11.1 → 2.11.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +594 -0
  2. package/README_en.md +139 -0
  3. package/dist/cli.js +5 -5
  4. package/dist/cli.mjs +5 -5
  5. package/dist/core.js +5 -5
  6. package/dist/core.mjs +5 -5
  7. package/dist/css-macro/index.js +3 -3
  8. package/dist/css-macro/index.mjs +2 -2
  9. package/dist/css-macro/postcss.js +1 -1
  10. package/dist/css-macro/postcss.mjs +1 -1
  11. package/dist/defaults.js +1 -1
  12. package/dist/defaults.mjs +1 -1
  13. package/dist/{defu-NLkZUlr9.mjs → defu-D2_bzAv0.mjs} +19 -9
  14. package/dist/{defu-VMJMz2AB.js → defu-JkbfvVKI.js} +19 -9
  15. package/dist/gulp.js +8 -69
  16. package/dist/gulp.mjs +7 -68
  17. package/dist/index-C70Rgk3g.js +142 -0
  18. package/dist/{index-z25r_Htj.js → index-CKXO21Qe.js} +1 -1
  19. package/dist/index-D3TDwy2Y.mjs +140 -0
  20. package/dist/index-De0cmOEK.js +70 -0
  21. package/dist/index-QLyv-Fcp.mjs +64 -0
  22. package/dist/index.js +12 -12
  23. package/dist/index.mjs +9 -9
  24. package/dist/{options-M8pGfjj_.mjs → options-B5UOFsZN.mjs} +42 -49
  25. package/dist/{options-lXV72tWf.js → options-BAFFNEBI.js} +43 -50
  26. package/dist/{postcss-Et8j4ugT.js → plugin-Bxt3oO75.js} +2 -2
  27. package/dist/{postcss-W8i3cl5I.mjs → plugin-Du3zrk3S.mjs} +1 -1
  28. package/dist/postcss.js +5 -5
  29. package/dist/postcss.mjs +2 -2
  30. package/dist/replace.js +6 -6
  31. package/dist/replace.mjs +1 -1
  32. package/dist/types.d.ts +2 -1
  33. package/dist/v5-Crbh5I-S.js +187 -0
  34. package/dist/v5-V8LlDF1a.mjs +180 -0
  35. package/dist/vite.js +10 -141
  36. package/dist/vite.mjs +8 -143
  37. package/dist/weapp-tw-runtime-loader.js +1 -1
  38. package/dist/webpack.js +11 -185
  39. package/dist/webpack.mjs +10 -183
  40. package/package.json +97 -95
  41. /package/dist/{constants-ol1NPf7z.mjs → constants-CcqTvLgQ.mjs} +0 -0
  42. /package/dist/{constants-EVxkHOXL.js → constants-D-YMDg7M.js} +0 -0
  43. /package/dist/{defaults-dz6xGhOP.mjs → defaults-DMBtD8TO.mjs} +0 -0
  44. /package/dist/{defaults-0O-zKoXE.js → defaults-qX2VLo8u.js} +0 -0
  45. /package/dist/{index-06BoOZig.mjs → index-CLxBL7MC.mjs} +0 -0
  46. /package/dist/{shared-S0v7ZvWs.mjs → shared-D4ZM_mI-.mjs} +0 -0
  47. /package/dist/{shared-nXoJWFdz.js → shared-DtRIj-D_.js} +0 -0
@@ -7,12 +7,12 @@ import { jsStringEscape } from '@ast-core/escape';
7
7
  import generate from '@babel/generator';
8
8
  import { parse, parseExpression } from '@babel/parser';
9
9
  import traverse from '@babel/traverse';
10
- import { d as defu } from './defu-NLkZUlr9.mjs';
11
- import { n as noop, d as defaultOptions, i as isMap } from './defaults-dz6xGhOP.mjs';
10
+ import { d as defu } from './defu-D2_bzAv0.mjs';
11
+ import { n as noop, d as defaultOptions, i as isMap } from './defaults-DMBtD8TO.mjs';
12
12
  import * as t from '@babel/types';
13
13
  import { Parser } from 'htmlparser2';
14
14
  import postcss from 'postcss';
15
- import { p as postcssWeappTailwindcss } from './postcss-W8i3cl5I.mjs';
15
+ import { p as postcssWeappTailwindcss } from './plugin-Du3zrk3S.mjs';
16
16
  import postcssIsPseudoClass from '@csstools/postcss-is-pseudo-class';
17
17
  import path from 'node:path';
18
18
  import fs from 'node:fs';
@@ -64,16 +64,12 @@ const splitCode = (code, allowDoubleQuotes = false) => {
64
64
  };
65
65
 
66
66
  function regenerateHandleValue(str, node, options) {
67
- var _a;
68
- const set = options.classNameSet;
69
- const escapeMap = options.escapeMap;
70
- const allowDoubleQuotes = (_a = options.arbitraryValues) === null || _a === void 0 ? void 0 : _a.allowDoubleQuotes;
71
- const ctx = options.mangleContext;
72
- const jsPreserveClass = options.jsPreserveClass;
67
+ const { classNameSet: set, escapeMap, always, arbitraryValues, mangleContext: ctx, jsPreserveClass } = options;
68
+ const allowDoubleQuotes = arbitraryValues === null || arbitraryValues === void 0 ? void 0 : arbitraryValues.allowDoubleQuotes;
73
69
  const arr = splitCode(str, allowDoubleQuotes);
74
70
  let rawStr = str;
75
71
  for (const v of arr) {
76
- if (set.has(v) && !(jsPreserveClass === null || jsPreserveClass === void 0 ? void 0 : jsPreserveClass(v))) {
72
+ if (always || (set && set.has(v) && !(jsPreserveClass === null || jsPreserveClass === void 0 ? void 0 : jsPreserveClass(v)))) {
77
73
  let ignoreFlag = false;
78
74
  if (Array.isArray(node.leadingComments)) {
79
75
  ignoreFlag = node.leadingComments.findIndex((x) => x.value.includes('weapp-tw') && x.value.includes('ignore')) > -1;
@@ -82,7 +78,7 @@ function regenerateHandleValue(str, node, options) {
82
78
  if (ctx) {
83
79
  rawStr = ctx.jsHandler(rawStr);
84
80
  }
85
- rawStr = rawStr.replaceAll(new RegExp(escapeStringRegexp(v), 'g'), replaceWxml(v, {
81
+ rawStr = rawStr.replace(new RegExp(escapeStringRegexp(v)), replaceWxml(v, {
86
82
  escapeMap
87
83
  }));
88
84
  }
@@ -91,16 +87,12 @@ function regenerateHandleValue(str, node, options) {
91
87
  return rawStr;
92
88
  }
93
89
  function replaceHandleValue(str, node, options, ms, offset = 0, needEscaped = false) {
94
- var _a;
95
- const set = options.classNameSet;
96
- const escapeMap = options.escapeMap;
97
- const allowDoubleQuotes = (_a = options.arbitraryValues) === null || _a === void 0 ? void 0 : _a.allowDoubleQuotes;
98
- const ctx = options.mangleContext;
99
- const jsPreserveClass = options.jsPreserveClass;
90
+ const { classNameSet: set, escapeMap, always, arbitraryValues, mangleContext: ctx, jsPreserveClass } = options;
91
+ const allowDoubleQuotes = arbitraryValues === null || arbitraryValues === void 0 ? void 0 : arbitraryValues.allowDoubleQuotes;
100
92
  const arr = splitCode(str, allowDoubleQuotes);
101
93
  let rawStr = str;
102
94
  for (const v of arr) {
103
- if (set.has(v) && !(jsPreserveClass === null || jsPreserveClass === void 0 ? void 0 : jsPreserveClass(v))) {
95
+ if (always || (set && set.has(v) && !(jsPreserveClass === null || jsPreserveClass === void 0 ? void 0 : jsPreserveClass(v)))) {
104
96
  let ignoreFlag = false;
105
97
  if (Array.isArray(node.leadingComments)) {
106
98
  ignoreFlag = node.leadingComments.findIndex((x) => x.value.includes('weapp-tw') && x.value.includes('ignore')) > -1;
@@ -109,7 +101,7 @@ function replaceHandleValue(str, node, options, ms, offset = 0, needEscaped = fa
109
101
  if (ctx) {
110
102
  rawStr = ctx.jsHandler(rawStr);
111
103
  }
112
- rawStr = rawStr.replaceAll(new RegExp(escapeStringRegexp(v), 'g'), replaceWxml(v, {
104
+ rawStr = rawStr.replace(new RegExp(escapeStringRegexp(v)), replaceWxml(v, {
113
105
  escapeMap
114
106
  }));
115
107
  }
@@ -285,34 +277,35 @@ function createJsHandler(options) {
285
277
  };
286
278
  }
287
279
 
288
- function getQuotes(quote) {
289
- const quotes = quote === "'" ? 'double' : 'single';
290
- return quotes;
291
- }
292
280
  function generateCode(match, options = {}) {
293
- const ast = parseExpression(match);
294
- traverse(ast, {
295
- StringLiteral(path) {
296
- var _a;
297
- if (t.isMemberExpression(path.parent)) {
298
- return;
299
- }
300
- if (t.isBinaryExpression(path.parent) && t.isConditionalExpression((_a = path.parentPath) === null || _a === void 0 ? void 0 : _a.parent)) {
301
- return;
302
- }
303
- path.node.value = replaceWxml(path.node.value, options);
304
- },
305
- noScope: true
306
- });
307
- const { code } = generate(ast, {
308
- compact: true,
309
- minified: true,
310
- jsescOption: {
311
- quotes: getQuotes(options.quote),
312
- minimal: true
313
- }
314
- });
315
- return code;
281
+ try {
282
+ const ast = parseExpression(match);
283
+ const ms = new MagicString(match);
284
+ traverse(ast, {
285
+ StringLiteral(path) {
286
+ var _a;
287
+ if (t.isMemberExpression(path.parent)) {
288
+ return;
289
+ }
290
+ if (t.isBinaryExpression(path.parent) && t.isConditionalExpression((_a = path.parentPath) === null || _a === void 0 ? void 0 : _a.parent)) {
291
+ return;
292
+ }
293
+ const n = path.node;
294
+ replaceHandleValue(n.value, n, {
295
+ always: true,
296
+ classNameSet: options.runtimeSet,
297
+ mangleContext: options.mangleContext,
298
+ escapeMap: options.escapeMap,
299
+ needEscaped: true
300
+ }, ms, 1, true);
301
+ },
302
+ noScope: true
303
+ });
304
+ return ms.toString();
305
+ }
306
+ catch (_a) {
307
+ return match;
308
+ }
316
309
  }
317
310
  function extract(original, reg) {
318
311
  let match = reg.exec(original);
@@ -407,7 +400,7 @@ function customTemplateHandler(rawSource, options) {
407
400
  onattribute(name, value, quote) {
408
401
  if (value) {
409
402
  function update() {
410
- s.update(parser.startIndex + name.length + 2, parser.endIndex, templateReplacer(value, Object.assign(Object.assign({}, options), { quote })));
403
+ s.update(parser.startIndex + name.length + 2, parser.endIndex - 1, templateReplacer(value, Object.assign(Object.assign({}, options), { quote })));
411
404
  }
412
405
  if (!disabledDefaultTemplateHandler && (name === 'class' || name === 'hover-class' || name === 'virtualhostclass')) {
413
406
  update();
@@ -618,7 +611,7 @@ function useMangleStore() {
618
611
  const arr = splitCode(rawSource);
619
612
  for (const x of arr) {
620
613
  if (ctx.runtimeSet.has(x)) {
621
- rawSource = rawSource.replaceAll(new RegExp(escapeStringRegexp(x), 'g'), ctx.classGenerator.generateClassName(x).name);
614
+ rawSource = rawSource.replace(new RegExp(escapeStringRegexp(x)), ctx.classGenerator.generateClassName(x).name);
622
615
  }
623
616
  }
624
617
  return rawSource;
@@ -802,4 +795,4 @@ function getOptions(options = {}) {
802
795
  return result;
803
796
  }
804
797
 
805
- export { __awaiter as _, createTailwindcssPatcher as a, createPatch as c, getOptions as g };
798
+ export { __awaiter as _, createPatch as a, createTailwindcssPatcher as c, getOptions as g };
@@ -9,12 +9,12 @@ var escape = require('@ast-core/escape');
9
9
  var generate = require('@babel/generator');
10
10
  var parser = require('@babel/parser');
11
11
  var traverse = require('@babel/traverse');
12
- var defu = require('./defu-VMJMz2AB.js');
13
- var defaults = require('./defaults-0O-zKoXE.js');
12
+ var defu = require('./defu-JkbfvVKI.js');
13
+ var defaults = require('./defaults-qX2VLo8u.js');
14
14
  var t = require('@babel/types');
15
15
  var htmlparser2 = require('htmlparser2');
16
16
  var postcss = require('postcss');
17
- var postcss$1 = require('./postcss-Et8j4ugT.js');
17
+ var plugin = require('./plugin-Bxt3oO75.js');
18
18
  var postcssIsPseudoClass = require('@csstools/postcss-is-pseudo-class');
19
19
  var path = require('node:path');
20
20
  var fs = require('node:fs');
@@ -24,7 +24,7 @@ var shared = require('@tailwindcss-mangle/shared');
24
24
  var lruCache = require('lru-cache');
25
25
  var md5 = require('md5');
26
26
 
27
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
27
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
28
28
 
29
29
  function _interopNamespaceCompat(e) {
30
30
  if (e && typeof e === 'object' && 'default' in e) return e;
@@ -96,16 +96,12 @@ const splitCode = (code, allowDoubleQuotes = false) => {
96
96
  };
97
97
 
98
98
  function regenerateHandleValue(str, node, options) {
99
- var _a;
100
- const set = options.classNameSet;
101
- const escapeMap = options.escapeMap;
102
- const allowDoubleQuotes = (_a = options.arbitraryValues) === null || _a === void 0 ? void 0 : _a.allowDoubleQuotes;
103
- const ctx = options.mangleContext;
104
- const jsPreserveClass = options.jsPreserveClass;
99
+ const { classNameSet: set, escapeMap, always, arbitraryValues, mangleContext: ctx, jsPreserveClass } = options;
100
+ const allowDoubleQuotes = arbitraryValues === null || arbitraryValues === void 0 ? void 0 : arbitraryValues.allowDoubleQuotes;
105
101
  const arr = splitCode(str, allowDoubleQuotes);
106
102
  let rawStr = str;
107
103
  for (const v of arr) {
108
- if (set.has(v) && !(jsPreserveClass === null || jsPreserveClass === void 0 ? void 0 : jsPreserveClass(v))) {
104
+ if (always || (set && set.has(v) && !(jsPreserveClass === null || jsPreserveClass === void 0 ? void 0 : jsPreserveClass(v)))) {
109
105
  let ignoreFlag = false;
110
106
  if (Array.isArray(node.leadingComments)) {
111
107
  ignoreFlag = node.leadingComments.findIndex((x) => x.value.includes('weapp-tw') && x.value.includes('ignore')) > -1;
@@ -114,7 +110,7 @@ function regenerateHandleValue(str, node, options) {
114
110
  if (ctx) {
115
111
  rawStr = ctx.jsHandler(rawStr);
116
112
  }
117
- rawStr = rawStr.replaceAll(new RegExp(regex.escapeStringRegexp(v), 'g'), replace.replaceJs(v, {
113
+ rawStr = rawStr.replace(new RegExp(regex.escapeStringRegexp(v)), replace.replaceJs(v, {
118
114
  escapeMap
119
115
  }));
120
116
  }
@@ -123,16 +119,12 @@ function regenerateHandleValue(str, node, options) {
123
119
  return rawStr;
124
120
  }
125
121
  function replaceHandleValue(str, node, options, ms, offset = 0, needEscaped = false) {
126
- var _a;
127
- const set = options.classNameSet;
128
- const escapeMap = options.escapeMap;
129
- const allowDoubleQuotes = (_a = options.arbitraryValues) === null || _a === void 0 ? void 0 : _a.allowDoubleQuotes;
130
- const ctx = options.mangleContext;
131
- const jsPreserveClass = options.jsPreserveClass;
122
+ const { classNameSet: set, escapeMap, always, arbitraryValues, mangleContext: ctx, jsPreserveClass } = options;
123
+ const allowDoubleQuotes = arbitraryValues === null || arbitraryValues === void 0 ? void 0 : arbitraryValues.allowDoubleQuotes;
132
124
  const arr = splitCode(str, allowDoubleQuotes);
133
125
  let rawStr = str;
134
126
  for (const v of arr) {
135
- if (set.has(v) && !(jsPreserveClass === null || jsPreserveClass === void 0 ? void 0 : jsPreserveClass(v))) {
127
+ if (always || (set && set.has(v) && !(jsPreserveClass === null || jsPreserveClass === void 0 ? void 0 : jsPreserveClass(v)))) {
136
128
  let ignoreFlag = false;
137
129
  if (Array.isArray(node.leadingComments)) {
138
130
  ignoreFlag = node.leadingComments.findIndex((x) => x.value.includes('weapp-tw') && x.value.includes('ignore')) > -1;
@@ -141,7 +133,7 @@ function replaceHandleValue(str, node, options, ms, offset = 0, needEscaped = fa
141
133
  if (ctx) {
142
134
  rawStr = ctx.jsHandler(rawStr);
143
135
  }
144
- rawStr = rawStr.replaceAll(new RegExp(regex.escapeStringRegexp(v), 'g'), replace.replaceJs(v, {
136
+ rawStr = rawStr.replace(new RegExp(regex.escapeStringRegexp(v)), replace.replaceJs(v, {
145
137
  escapeMap
146
138
  }));
147
139
  }
@@ -317,34 +309,35 @@ function createJsHandler(options) {
317
309
  };
318
310
  }
319
311
 
320
- function getQuotes(quote) {
321
- const quotes = quote === "'" ? 'double' : 'single';
322
- return quotes;
323
- }
324
312
  function generateCode(match, options = {}) {
325
- const ast = parser.parseExpression(match);
326
- traverse__default["default"](ast, {
327
- StringLiteral(path) {
328
- var _a;
329
- if (t__namespace.isMemberExpression(path.parent)) {
330
- return;
331
- }
332
- if (t__namespace.isBinaryExpression(path.parent) && t__namespace.isConditionalExpression((_a = path.parentPath) === null || _a === void 0 ? void 0 : _a.parent)) {
333
- return;
334
- }
335
- path.node.value = replace.replaceJs(path.node.value, options);
336
- },
337
- noScope: true
338
- });
339
- const { code } = generate__default["default"](ast, {
340
- compact: true,
341
- minified: true,
342
- jsescOption: {
343
- quotes: getQuotes(options.quote),
344
- minimal: true
345
- }
346
- });
347
- return code;
313
+ try {
314
+ const ast = parser.parseExpression(match);
315
+ const ms = new MagicString__default["default"](match);
316
+ traverse__default["default"](ast, {
317
+ StringLiteral(path) {
318
+ var _a;
319
+ if (t__namespace.isMemberExpression(path.parent)) {
320
+ return;
321
+ }
322
+ if (t__namespace.isBinaryExpression(path.parent) && t__namespace.isConditionalExpression((_a = path.parentPath) === null || _a === void 0 ? void 0 : _a.parent)) {
323
+ return;
324
+ }
325
+ const n = path.node;
326
+ replaceHandleValue(n.value, n, {
327
+ always: true,
328
+ classNameSet: options.runtimeSet,
329
+ mangleContext: options.mangleContext,
330
+ escapeMap: options.escapeMap,
331
+ needEscaped: true
332
+ }, ms, 1, true);
333
+ },
334
+ noScope: true
335
+ });
336
+ return ms.toString();
337
+ }
338
+ catch (_a) {
339
+ return match;
340
+ }
348
341
  }
349
342
  function extract(original, reg) {
350
343
  let match = reg.exec(original);
@@ -439,7 +432,7 @@ function customTemplateHandler(rawSource, options) {
439
432
  onattribute(name, value, quote) {
440
433
  if (value) {
441
434
  function update() {
442
- s.update(parser.startIndex + name.length + 2, parser.endIndex, templateReplacer(value, Object.assign(Object.assign({}, options), { quote })));
435
+ s.update(parser.startIndex + name.length + 2, parser.endIndex - 1, templateReplacer(value, Object.assign(Object.assign({}, options), { quote })));
443
436
  }
444
437
  if (!disabledDefaultTemplateHandler && (name === 'class' || name === 'hover-class' || name === 'virtualhostclass')) {
445
438
  update();
@@ -483,7 +476,7 @@ function createTemplateHandler(options = {}) {
483
476
 
484
477
  function styleHandler(rawSource, options) {
485
478
  return __awaiter(this, void 0, void 0, function* () {
486
- return (yield postcss__default["default"]([postcssIsPseudoClass__default["default"](), postcss$1.postcssWeappTailwindcss(options)])
479
+ return (yield postcss__default["default"]([postcssIsPseudoClass__default["default"](), plugin.postcssWeappTailwindcss(options)])
487
480
  .process(rawSource)
488
481
  .async()).css;
489
482
  });
@@ -650,7 +643,7 @@ function useMangleStore() {
650
643
  const arr = splitCode(rawSource);
651
644
  for (const x of arr) {
652
645
  if (ctx.runtimeSet.has(x)) {
653
- rawSource = rawSource.replaceAll(new RegExp(regex.escapeStringRegexp(x), 'g'), ctx.classGenerator.generateClassName(x).name);
646
+ rawSource = rawSource.replace(new RegExp(regex.escapeStringRegexp(x)), ctx.classGenerator.generateClassName(x).name);
654
647
  }
655
648
  }
656
649
  return rawSource;
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  var selectorParser = require('postcss-selector-parser');
4
- var shared = require('./shared-nXoJWFdz.js');
4
+ var shared = require('./shared-DtRIj-D_.js');
5
5
  var postcss = require('postcss');
6
6
  require('@csstools/postcss-is-pseudo-class');
7
7
 
8
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
9
9
 
10
10
  var selectorParser__default = /*#__PURE__*/_interopDefaultCompat(selectorParser);
11
11
 
@@ -1,5 +1,5 @@
1
1
  import selectorParser from 'postcss-selector-parser';
2
- import { i as internalCssSelectorReplacer } from './shared-S0v7ZvWs.mjs';
2
+ import { i as internalCssSelectorReplacer } from './shared-D4ZM_mI-.mjs';
3
3
  import { Declaration, Rule } from 'postcss';
4
4
  import '@csstools/postcss-is-pseudo-class';
5
5
 
package/dist/postcss.js CHANGED
@@ -2,22 +2,22 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var postcss = require('./postcss-Et8j4ugT.js');
5
+ var plugin = require('./plugin-Bxt3oO75.js');
6
6
  var postcssIsPseudoClass = require('@csstools/postcss-is-pseudo-class');
7
7
  require('postcss-selector-parser');
8
- require('./shared-nXoJWFdz.js');
8
+ require('./shared-DtRIj-D_.js');
9
9
  require('@weapp-core/escape');
10
10
  require('@ast-core/escape');
11
11
  require('postcss');
12
12
 
13
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
14
14
 
15
15
  var postcssIsPseudoClass__default = /*#__PURE__*/_interopDefaultCompat(postcssIsPseudoClass);
16
16
 
17
17
 
18
18
 
19
- exports.postcssWeappTailwindcss = postcss.postcssWeappTailwindcss;
20
- Object.defineProperty(exports, 'postcssIsPseudoClass', {
19
+ exports.postcssWeappTailwindcss = plugin.postcssWeappTailwindcss;
20
+ Object.defineProperty(exports, "postcssIsPseudoClass", {
21
21
  enumerable: true,
22
22
  get: function () { return postcssIsPseudoClass__default["default"]; }
23
23
  });
package/dist/postcss.mjs CHANGED
@@ -1,7 +1,7 @@
1
- export { p as postcssWeappTailwindcss } from './postcss-W8i3cl5I.mjs';
1
+ export { p as postcssWeappTailwindcss } from './plugin-Du3zrk3S.mjs';
2
2
  export { default as postcssIsPseudoClass } from '@csstools/postcss-is-pseudo-class';
3
3
  import 'postcss-selector-parser';
4
- import './shared-S0v7ZvWs.mjs';
4
+ import './shared-D4ZM_mI-.mjs';
5
5
  import '@weapp-core/escape';
6
6
  import '@ast-core/escape';
7
7
  import 'postcss';
package/dist/replace.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var escape = require('@weapp-core/escape');
6
6
  require('@ast-core/escape');
7
- var shared = require('./shared-nXoJWFdz.js');
7
+ var shared = require('./shared-DtRIj-D_.js');
8
8
 
9
9
  function replaceWxml(original, options = {
10
10
  keepEOL: false,
@@ -25,23 +25,23 @@ function replaceWxml(original, options = {
25
25
  return res;
26
26
  }
27
27
 
28
- Object.defineProperty(exports, 'MappingChars2String', {
28
+ Object.defineProperty(exports, "MappingChars2String", {
29
29
  enumerable: true,
30
30
  get: function () { return escape.MappingChars2String; }
31
31
  });
32
- Object.defineProperty(exports, 'MappingChars2StringEntries', {
32
+ Object.defineProperty(exports, "MappingChars2StringEntries", {
33
33
  enumerable: true,
34
34
  get: function () { return escape.MappingChars2StringEntries; }
35
35
  });
36
- Object.defineProperty(exports, 'SYMBOL_TABLE', {
36
+ Object.defineProperty(exports, "SYMBOL_TABLE", {
37
37
  enumerable: true,
38
38
  get: function () { return escape.SYMBOL_TABLE; }
39
39
  });
40
- Object.defineProperty(exports, 'SimpleMappingChars2String', {
40
+ Object.defineProperty(exports, "SimpleMappingChars2String", {
41
41
  enumerable: true,
42
42
  get: function () { return escape.SimpleMappingChars2String; }
43
43
  });
44
- Object.defineProperty(exports, 'SimpleMappingChars2StringEntries', {
44
+ Object.defineProperty(exports, "SimpleMappingChars2StringEntries", {
45
45
  enumerable: true,
46
46
  get: function () { return escape.SimpleMappingChars2StringEntries; }
47
47
  });
package/dist/replace.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { escape, SimpleMappingChars2String } from '@weapp-core/escape';
2
2
  export { MappingChars2String, MappingChars2StringEntries, SYMBOL_TABLE, SimpleMappingChars2String, SimpleMappingChars2StringEntries } from '@weapp-core/escape';
3
3
  import '@ast-core/escape';
4
- export { i as replaceCss } from './shared-S0v7ZvWs.mjs';
4
+ export { i as replaceCss } from './shared-D4ZM_mI-.mjs';
5
5
 
6
6
  function replaceWxml(original, options = {
7
7
  keepEOL: false,
package/dist/types.d.ts CHANGED
@@ -37,7 +37,7 @@ export type ICustomAttributes = Record<string, ItemOrItemArray<string | RegExp>>
37
37
  export type ICustomAttributesEntities = [string | RegExp, ItemOrItemArray<string | RegExp>][];
38
38
  export type IJsHandlerOptions = {
39
39
  escapeMap?: Record<string, string>;
40
- classNameSet: Set<string>;
40
+ classNameSet?: Set<string>;
41
41
  minifiedJs?: boolean;
42
42
  arbitraryValues?: IArbitraryValues;
43
43
  mangleContext?: IMangleScopeContext;
@@ -45,6 +45,7 @@ export type IJsHandlerOptions = {
45
45
  strategy?: UserDefinedOptions['jsEscapeStrategy'];
46
46
  needEscaped?: boolean;
47
47
  generateMap?: boolean;
48
+ always?: boolean;
48
49
  };
49
50
  export interface RawSource {
50
51
  start: number;
@@ -0,0 +1,187 @@
1
+ 'use strict';
2
+
3
+ var options = require('./options-BAFFNEBI.js');
4
+ var path = require('node:path');
5
+ var fs = require('node:fs');
6
+ var plugin = require('./plugin-Bxt3oO75.js');
7
+ var defaults = require('./defaults-qX2VLo8u.js');
8
+ var index = require('./index-CKXO21Qe.js');
9
+
10
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
11
+
12
+ var path__default = /*#__PURE__*/_interopDefaultCompat(path);
13
+ var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
14
+
15
+ const debug = index.createDebug('processAssets: ');
16
+ class UnifiedWebpackPluginV5 {
17
+ constructor(options$1 = {}) {
18
+ if (options$1.customReplaceDictionary === undefined) {
19
+ options$1.customReplaceDictionary = 'simple';
20
+ }
21
+ this.options = options.getOptions(options$1);
22
+ this.appType = this.options.appType;
23
+ }
24
+ apply(compiler) {
25
+ const { mainCssChunkMatcher, disabled, onLoad, onUpdate, onEnd, onStart, styleHandler, patch, templateHandler, jsHandler, setMangleRuntimeSet, runtimeLoaderPath, cache, tailwindcssBasedir } = this.options;
26
+ if (disabled) {
27
+ return;
28
+ }
29
+ patch === null || patch === void 0 ? void 0 : patch();
30
+ const { Compilation, sources, NormalModule } = compiler.webpack;
31
+ const { ConcatSource, RawSource } = sources;
32
+ const twPatcher = options.createTailwindcssPatcher();
33
+ function getClassSet() {
34
+ return twPatcher.getClassSet({
35
+ basedir: tailwindcssBasedir
36
+ });
37
+ }
38
+ onLoad();
39
+ const loader = runtimeLoaderPath !== null && runtimeLoaderPath !== void 0 ? runtimeLoaderPath : path__default["default"].resolve(__dirname, './weapp-tw-runtime-loader.js');
40
+ const isExisted = fs__default["default"].existsSync(loader);
41
+ const WeappTwRuntimeAopLoader = {
42
+ loader,
43
+ options: {
44
+ getClassSet
45
+ },
46
+ ident: null,
47
+ type: null
48
+ };
49
+ compiler.hooks.compilation.tap(plugin.pluginName, (compilation) => {
50
+ NormalModule.getCompilationHooks(compilation).loader.tap(plugin.pluginName, (loaderContext, module) => {
51
+ if (isExisted) {
52
+ const idx = module.loaders.findIndex((x) => x.loader.includes('postcss-loader'));
53
+ if (idx > -1) {
54
+ module.loaders.unshift(WeappTwRuntimeAopLoader);
55
+ }
56
+ }
57
+ });
58
+ compilation.hooks.processAssets.tapPromise({
59
+ name: plugin.pluginName,
60
+ stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
61
+ }, (assets) => options.__awaiter(this, void 0, void 0, function* () {
62
+ onStart();
63
+ debug('start');
64
+ for (const chunk of compilation.chunks) {
65
+ if (chunk.id && chunk.hash) {
66
+ cache.calcHashValueChanged(chunk.id, chunk.hash);
67
+ }
68
+ }
69
+ const entries = Object.entries(assets);
70
+ const groupedEntries = defaults.getGroupedEntries(entries, this.options);
71
+ const runtimeSet = getClassSet();
72
+ setMangleRuntimeSet(runtimeSet);
73
+ debug('get runtimeSet, class count: %d', runtimeSet.size);
74
+ if (Array.isArray(groupedEntries.html)) {
75
+ let noCachedCount = 0;
76
+ for (let i = 0; i < groupedEntries.html.length; i++) {
77
+ const [file, originalSource] = groupedEntries.html[i];
78
+ const rawSource = originalSource.source().toString();
79
+ const hash = cache.computeHash(rawSource);
80
+ const cacheKey = file;
81
+ cache.calcHashValueChanged(cacheKey, hash);
82
+ yield cache.process(cacheKey, () => {
83
+ const source = cache.get(cacheKey);
84
+ if (source) {
85
+ compilation.updateAsset(file, source);
86
+ debug('html cache hit: %s', file);
87
+ }
88
+ else {
89
+ return false;
90
+ }
91
+ }, () => {
92
+ const wxml = templateHandler(rawSource, {
93
+ runtimeSet
94
+ });
95
+ const source = new ConcatSource(wxml);
96
+ compilation.updateAsset(file, source);
97
+ onUpdate(file, rawSource, wxml);
98
+ debug('html handle: %s', file);
99
+ noCachedCount++;
100
+ return {
101
+ key: cacheKey,
102
+ source
103
+ };
104
+ });
105
+ }
106
+ debug('html handle finish, total: %d, no-cached: %d', groupedEntries.html.length, noCachedCount);
107
+ }
108
+ if (Array.isArray(groupedEntries.js)) {
109
+ let noCachedCount = 0;
110
+ for (let i = 0; i < groupedEntries.js.length; i++) {
111
+ const [file, originalSource] = groupedEntries.js[i];
112
+ const cacheKey = defaults.removeExt(file);
113
+ yield cache.process(cacheKey, () => {
114
+ const source = cache.get(cacheKey);
115
+ if (source) {
116
+ compilation.updateAsset(file, source);
117
+ debug('js cache hit: %s', file);
118
+ }
119
+ else {
120
+ return false;
121
+ }
122
+ }, () => {
123
+ const rawSource = originalSource.source().toString();
124
+ const mapFilename = file + '.map';
125
+ const hasMap = Boolean(assets[mapFilename]);
126
+ const { code, map } = jsHandler(rawSource, runtimeSet, {
127
+ generateMap: hasMap
128
+ });
129
+ const source = new ConcatSource(code);
130
+ compilation.updateAsset(file, source);
131
+ onUpdate(file, rawSource, code);
132
+ debug('js handle: %s', file);
133
+ noCachedCount++;
134
+ if (hasMap && map) {
135
+ const source = new RawSource(map.toString());
136
+ compilation.updateAsset(mapFilename, source);
137
+ }
138
+ return {
139
+ key: cacheKey,
140
+ source
141
+ };
142
+ });
143
+ }
144
+ debug('js handle finish, total: %d, no-cached: %d', groupedEntries.js.length, noCachedCount);
145
+ }
146
+ if (Array.isArray(groupedEntries.css)) {
147
+ let noCachedCount = 0;
148
+ for (let i = 0; i < groupedEntries.css.length; i++) {
149
+ const [file, originalSource] = groupedEntries.css[i];
150
+ const rawSource = originalSource.source().toString();
151
+ const hash = cache.computeHash(rawSource);
152
+ const cacheKey = file;
153
+ cache.calcHashValueChanged(cacheKey, hash);
154
+ yield cache.process(cacheKey, () => {
155
+ const source = cache.get(cacheKey);
156
+ if (source) {
157
+ compilation.updateAsset(file, source);
158
+ debug('css cache hit: %s', file);
159
+ }
160
+ else {
161
+ return false;
162
+ }
163
+ }, () => options.__awaiter(this, void 0, void 0, function* () {
164
+ const css = yield styleHandler(rawSource, {
165
+ isMainChunk: mainCssChunkMatcher(file, this.appType)
166
+ });
167
+ const source = new ConcatSource(css);
168
+ compilation.updateAsset(file, source);
169
+ onUpdate(file, rawSource, css);
170
+ debug('css handle: %s', file);
171
+ noCachedCount++;
172
+ return {
173
+ key: cacheKey,
174
+ source
175
+ };
176
+ }));
177
+ }
178
+ debug('css handle finish, total: %d, no-cached: %d', groupedEntries.css.length, noCachedCount);
179
+ }
180
+ debug('end');
181
+ onEnd();
182
+ }));
183
+ });
184
+ }
185
+ }
186
+
187
+ exports.UnifiedWebpackPluginV5 = UnifiedWebpackPluginV5;