weapp-tailwindcss 2.11.2 → 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 (45) hide show
  1. package/dist/cli.js +5 -5
  2. package/dist/cli.mjs +5 -5
  3. package/dist/core.js +5 -5
  4. package/dist/core.mjs +5 -5
  5. package/dist/css-macro/index.js +3 -3
  6. package/dist/css-macro/index.mjs +2 -2
  7. package/dist/css-macro/postcss.js +1 -1
  8. package/dist/css-macro/postcss.mjs +1 -1
  9. package/dist/defaults.js +1 -1
  10. package/dist/defaults.mjs +1 -1
  11. package/dist/{defu-NLkZUlr9.mjs → defu-D2_bzAv0.mjs} +19 -9
  12. package/dist/{defu-VMJMz2AB.js → defu-JkbfvVKI.js} +19 -9
  13. package/dist/gulp.js +8 -69
  14. package/dist/gulp.mjs +7 -68
  15. package/dist/index-C70Rgk3g.js +142 -0
  16. package/dist/{index-z25r_Htj.js → index-CKXO21Qe.js} +1 -1
  17. package/dist/index-D3TDwy2Y.mjs +140 -0
  18. package/dist/index-De0cmOEK.js +70 -0
  19. package/dist/index-QLyv-Fcp.mjs +64 -0
  20. package/dist/index.js +12 -12
  21. package/dist/index.mjs +9 -9
  22. package/dist/{options-QwNnkDpt.mjs → options-B5UOFsZN.mjs} +24 -36
  23. package/dist/{options-GnoWW1lR.js → options-BAFFNEBI.js} +25 -37
  24. package/dist/{postcss-Et8j4ugT.js → plugin-Bxt3oO75.js} +2 -2
  25. package/dist/{postcss-W8i3cl5I.mjs → plugin-Du3zrk3S.mjs} +1 -1
  26. package/dist/postcss.js +5 -5
  27. package/dist/postcss.mjs +2 -2
  28. package/dist/replace.js +6 -6
  29. package/dist/replace.mjs +1 -1
  30. package/dist/types.d.ts +2 -1
  31. package/dist/v5-Crbh5I-S.js +187 -0
  32. package/dist/v5-V8LlDF1a.mjs +180 -0
  33. package/dist/vite.js +10 -141
  34. package/dist/vite.mjs +8 -143
  35. package/dist/weapp-tw-runtime-loader.js +1 -1
  36. package/dist/webpack.js +11 -185
  37. package/dist/webpack.mjs +10 -183
  38. package/package.json +53 -52
  39. /package/dist/{constants-ol1NPf7z.mjs → constants-CcqTvLgQ.mjs} +0 -0
  40. /package/dist/{constants-EVxkHOXL.js → constants-D-YMDg7M.js} +0 -0
  41. /package/dist/{defaults-dz6xGhOP.mjs → defaults-DMBtD8TO.mjs} +0 -0
  42. /package/dist/{defaults-0O-zKoXE.js → defaults-qX2VLo8u.js} +0 -0
  43. /package/dist/{index-06BoOZig.mjs → index-CLxBL7MC.mjs} +0 -0
  44. /package/dist/{shared-S0v7ZvWs.mjs → shared-D4ZM_mI-.mjs} +0 -0
  45. /package/dist/{shared-nXoJWFdz.js → shared-DtRIj-D_.js} +0 -0
@@ -0,0 +1,140 @@
1
+ import { g as getOptions, c as createTailwindcssPatcher, _ as __awaiter } from './options-B5UOFsZN.mjs';
2
+ import { v as vitePluginName } from './plugin-Du3zrk3S.mjs';
3
+ import { g as getGroupedEntries } from './defaults-DMBtD8TO.mjs';
4
+ import { c as createDebug } from './index-CLxBL7MC.mjs';
5
+
6
+ const debug = createDebug('generateBundle: ');
7
+ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
8
+ if (options.customReplaceDictionary === undefined) {
9
+ options.customReplaceDictionary = 'simple';
10
+ }
11
+ const opts = getOptions(options);
12
+ const { disabled, onEnd, onLoad, onStart, onUpdate, templateHandler, styleHandler, patch, jsHandler, mainCssChunkMatcher, appType, setMangleRuntimeSet, cache, tailwindcssBasedir } = opts;
13
+ if (disabled) {
14
+ return;
15
+ }
16
+ patch === null || patch === void 0 ? void 0 : patch();
17
+ const twPatcher = createTailwindcssPatcher();
18
+ onLoad();
19
+ return {
20
+ name: vitePluginName,
21
+ enforce: 'post',
22
+ generateBundle(opt, bundle) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ debug('start');
25
+ onStart();
26
+ const entries = Object.entries(bundle);
27
+ const groupedEntries = getGroupedEntries(entries, opts);
28
+ const runtimeSet = twPatcher.getClassSet({
29
+ basedir: tailwindcssBasedir
30
+ });
31
+ setMangleRuntimeSet(runtimeSet);
32
+ debug('get runtimeSet, class count: %d', runtimeSet.size);
33
+ if (Array.isArray(groupedEntries.html)) {
34
+ let noCachedCount = 0;
35
+ for (let i = 0; i < groupedEntries.html.length; i++) {
36
+ const [file, originalSource] = groupedEntries.html[i];
37
+ const oldVal = originalSource.source.toString();
38
+ const hash = cache.computeHash(oldVal);
39
+ cache.calcHashValueChanged(file, hash);
40
+ yield cache.process(file, () => {
41
+ const source = cache.get(file);
42
+ if (source) {
43
+ originalSource.source = source;
44
+ debug('html cache hit: %s', file);
45
+ }
46
+ else {
47
+ return false;
48
+ }
49
+ }, () => {
50
+ originalSource.source = templateHandler(oldVal, {
51
+ runtimeSet
52
+ });
53
+ onUpdate(file, oldVal, originalSource.source);
54
+ debug('html handle: %s', file);
55
+ noCachedCount++;
56
+ return {
57
+ key: file,
58
+ source: originalSource.source
59
+ };
60
+ });
61
+ }
62
+ debug('html handle finish, total: %d, no-cached: %d', groupedEntries.html.length, noCachedCount);
63
+ }
64
+ if (Array.isArray(groupedEntries.js)) {
65
+ let noCachedCount = 0;
66
+ for (let i = 0; i < groupedEntries.js.length; i++) {
67
+ const [file, originalSource] = groupedEntries.js[i];
68
+ const rawSource = originalSource.code;
69
+ const hash = cache.computeHash(rawSource);
70
+ cache.calcHashValueChanged(file, hash);
71
+ yield cache.process(file, () => {
72
+ const source = cache.get(file);
73
+ if (source) {
74
+ originalSource.code = source;
75
+ debug('js cache hit: %s', file);
76
+ }
77
+ else {
78
+ return false;
79
+ }
80
+ }, () => {
81
+ const mapFilename = file + '.map';
82
+ const hasMap = Boolean(bundle[mapFilename]);
83
+ const { code, map } = jsHandler(rawSource, runtimeSet, {
84
+ generateMap: hasMap
85
+ });
86
+ originalSource.code = code;
87
+ onUpdate(file, rawSource, code);
88
+ debug('js handle: %s', file);
89
+ noCachedCount++;
90
+ if (hasMap && map) {
91
+ bundle[mapFilename].source = map.toString();
92
+ }
93
+ return {
94
+ key: file,
95
+ source: code
96
+ };
97
+ });
98
+ }
99
+ debug('js handle finish, total: %d, no-cached: %d', groupedEntries.js.length, noCachedCount);
100
+ }
101
+ if (Array.isArray(groupedEntries.css)) {
102
+ let noCachedCount = 0;
103
+ for (let i = 0; i < groupedEntries.css.length; i++) {
104
+ const [file, originalSource] = groupedEntries.css[i];
105
+ const rawSource = originalSource.source.toString();
106
+ const hash = cache.computeHash(rawSource);
107
+ cache.calcHashValueChanged(file, hash);
108
+ yield cache.process(file, () => {
109
+ const source = cache.get(file);
110
+ if (source) {
111
+ originalSource.source = source;
112
+ debug('css cache hit: %s', file);
113
+ }
114
+ else {
115
+ return false;
116
+ }
117
+ }, () => __awaiter(this, void 0, void 0, function* () {
118
+ const css = yield styleHandler(rawSource, {
119
+ isMainChunk: mainCssChunkMatcher(originalSource.fileName, appType)
120
+ });
121
+ originalSource.source = css;
122
+ onUpdate(file, rawSource, css);
123
+ debug('css handle: %s', file);
124
+ noCachedCount++;
125
+ return {
126
+ key: file,
127
+ source: css
128
+ };
129
+ }));
130
+ }
131
+ debug('css handle finish, total: %d, no-cached: %d', groupedEntries.css.length, noCachedCount);
132
+ }
133
+ onEnd();
134
+ debug('end');
135
+ });
136
+ }
137
+ };
138
+ }
139
+
140
+ export { UnifiedViteWeappTailwindcssPlugin as U };
@@ -0,0 +1,70 @@
1
+ 'use strict';
2
+
3
+ var options = require('./options-BAFFNEBI.js');
4
+ var stream = require('node:stream');
5
+
6
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
7
+
8
+ var stream__default = /*#__PURE__*/_interopDefaultCompat(stream);
9
+
10
+ const Transform = stream__default["default"].Transform;
11
+ function createPlugins(options$1 = {}) {
12
+ const opts = options.getOptions(options$1);
13
+ const { templateHandler, styleHandler, patch, jsHandler, setMangleRuntimeSet, tailwindcssBasedir } = opts;
14
+ let runtimeSet = new Set();
15
+ patch === null || patch === void 0 ? void 0 : patch();
16
+ const twPatcher = options.createTailwindcssPatcher();
17
+ function transformWxss() {
18
+ const transformStream = new Transform({ objectMode: true });
19
+ transformStream._transform = function (file, encoding, callback) {
20
+ return options.__awaiter(this, void 0, void 0, function* () {
21
+ runtimeSet = twPatcher.getClassSet({
22
+ basedir: tailwindcssBasedir
23
+ });
24
+ setMangleRuntimeSet(runtimeSet);
25
+ const error = null;
26
+ if (file.contents) {
27
+ const code = yield styleHandler(file.contents.toString(), {
28
+ isMainChunk: true
29
+ });
30
+ file.contents = Buffer.from(code);
31
+ }
32
+ callback(error, file);
33
+ });
34
+ };
35
+ return transformStream;
36
+ }
37
+ function transformJs() {
38
+ const transformStream = new Transform({ objectMode: true });
39
+ transformStream._transform = function (file, encoding, callback) {
40
+ const error = null;
41
+ if (file.contents) {
42
+ const { code } = jsHandler(file.contents.toString(), runtimeSet);
43
+ file.contents = Buffer.from(code);
44
+ }
45
+ callback(error, file);
46
+ };
47
+ return transformStream;
48
+ }
49
+ function transformWxml() {
50
+ const transformStream = new Transform({ objectMode: true });
51
+ transformStream._transform = function (file, encoding, callback) {
52
+ const error = null;
53
+ if (file.contents) {
54
+ const code = templateHandler(file.contents.toString(), {
55
+ runtimeSet
56
+ });
57
+ file.contents = Buffer.from(code);
58
+ }
59
+ callback(error, file);
60
+ };
61
+ return transformStream;
62
+ }
63
+ return {
64
+ transformWxss,
65
+ transformWxml,
66
+ transformJs
67
+ };
68
+ }
69
+
70
+ exports.createPlugins = createPlugins;
@@ -0,0 +1,64 @@
1
+ import { g as getOptions, c as createTailwindcssPatcher, _ as __awaiter } from './options-B5UOFsZN.mjs';
2
+ import stream from 'node:stream';
3
+
4
+ const Transform = stream.Transform;
5
+ function createPlugins(options = {}) {
6
+ const opts = getOptions(options);
7
+ const { templateHandler, styleHandler, patch, jsHandler, setMangleRuntimeSet, tailwindcssBasedir } = opts;
8
+ let runtimeSet = new Set();
9
+ patch === null || patch === void 0 ? void 0 : patch();
10
+ const twPatcher = createTailwindcssPatcher();
11
+ function transformWxss() {
12
+ const transformStream = new Transform({ objectMode: true });
13
+ transformStream._transform = function (file, encoding, callback) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ runtimeSet = twPatcher.getClassSet({
16
+ basedir: tailwindcssBasedir
17
+ });
18
+ setMangleRuntimeSet(runtimeSet);
19
+ const error = null;
20
+ if (file.contents) {
21
+ const code = yield styleHandler(file.contents.toString(), {
22
+ isMainChunk: true
23
+ });
24
+ file.contents = Buffer.from(code);
25
+ }
26
+ callback(error, file);
27
+ });
28
+ };
29
+ return transformStream;
30
+ }
31
+ function transformJs() {
32
+ const transformStream = new Transform({ objectMode: true });
33
+ transformStream._transform = function (file, encoding, callback) {
34
+ const error = null;
35
+ if (file.contents) {
36
+ const { code } = jsHandler(file.contents.toString(), runtimeSet);
37
+ file.contents = Buffer.from(code);
38
+ }
39
+ callback(error, file);
40
+ };
41
+ return transformStream;
42
+ }
43
+ function transformWxml() {
44
+ const transformStream = new Transform({ objectMode: true });
45
+ transformStream._transform = function (file, encoding, callback) {
46
+ const error = null;
47
+ if (file.contents) {
48
+ const code = templateHandler(file.contents.toString(), {
49
+ runtimeSet
50
+ });
51
+ file.contents = Buffer.from(code);
52
+ }
53
+ callback(error, file);
54
+ };
55
+ return transformStream;
56
+ }
57
+ return {
58
+ transformWxss,
59
+ transformWxml,
60
+ transformJs
61
+ };
62
+ }
63
+
64
+ export { createPlugins as c };
package/dist/index.js CHANGED
@@ -2,26 +2,26 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var webpack = require('./webpack.js');
6
- var vite = require('./vite.js');
7
- var gulp = require('./gulp.js');
8
- require('./options-GnoWW1lR.js');
5
+ var v5 = require('./v5-Crbh5I-S.js');
6
+ var index = require('./index-C70Rgk3g.js');
7
+ var index$1 = require('./index-De0cmOEK.js');
8
+ require('./options-BAFFNEBI.js');
9
9
  require('micromatch');
10
10
  require('magic-string');
11
11
  require('./replace.js');
12
12
  require('@weapp-core/escape');
13
13
  require('@ast-core/escape');
14
- require('./shared-nXoJWFdz.js');
14
+ require('./shared-DtRIj-D_.js');
15
15
  require('@weapp-core/regex');
16
16
  require('@babel/generator');
17
17
  require('@babel/parser');
18
18
  require('@babel/traverse');
19
- require('./defu-VMJMz2AB.js');
20
- require('./defaults-0O-zKoXE.js');
19
+ require('./defu-JkbfvVKI.js');
20
+ require('./defaults-qX2VLo8u.js');
21
21
  require('@babel/types');
22
22
  require('htmlparser2');
23
23
  require('postcss');
24
- require('./postcss-Et8j4ugT.js');
24
+ require('./plugin-Bxt3oO75.js');
25
25
  require('postcss-selector-parser');
26
26
  require('@csstools/postcss-is-pseudo-class');
27
27
  require('node:path');
@@ -31,12 +31,12 @@ require('tailwindcss-patch');
31
31
  require('@tailwindcss-mangle/shared');
32
32
  require('lru-cache');
33
33
  require('md5');
34
- require('./index-z25r_Htj.js');
34
+ require('./index-CKXO21Qe.js');
35
35
  require('debug');
36
36
  require('node:stream');
37
37
 
38
38
 
39
39
 
40
- exports.UnifiedWebpackPluginV5 = webpack.UnifiedWebpackPluginV5;
41
- exports.UnifiedViteWeappTailwindcssPlugin = vite.UnifiedViteWeappTailwindcssPlugin;
42
- exports.createPlugins = gulp.createPlugins;
40
+ exports.UnifiedWebpackPluginV5 = v5.UnifiedWebpackPluginV5;
41
+ exports.UnifiedViteWeappTailwindcssPlugin = index.UnifiedViteWeappTailwindcssPlugin;
42
+ exports.createPlugins = index$1.createPlugins;
package/dist/index.mjs CHANGED
@@ -1,23 +1,23 @@
1
- export { UnifiedWebpackPluginV5 } from './webpack.mjs';
2
- export { UnifiedViteWeappTailwindcssPlugin } from './vite.mjs';
3
- export { createPlugins } from './gulp.mjs';
4
- import './options-QwNnkDpt.mjs';
1
+ export { U as UnifiedWebpackPluginV5 } from './v5-V8LlDF1a.mjs';
2
+ export { U as UnifiedViteWeappTailwindcssPlugin } from './index-D3TDwy2Y.mjs';
3
+ export { c as createPlugins } from './index-QLyv-Fcp.mjs';
4
+ import './options-B5UOFsZN.mjs';
5
5
  import 'micromatch';
6
6
  import 'magic-string';
7
7
  import './replace.mjs';
8
8
  import '@weapp-core/escape';
9
9
  import '@ast-core/escape';
10
- import './shared-S0v7ZvWs.mjs';
10
+ import './shared-D4ZM_mI-.mjs';
11
11
  import '@weapp-core/regex';
12
12
  import '@babel/generator';
13
13
  import '@babel/parser';
14
14
  import '@babel/traverse';
15
- import './defu-NLkZUlr9.mjs';
16
- import './defaults-dz6xGhOP.mjs';
15
+ import './defu-D2_bzAv0.mjs';
16
+ import './defaults-DMBtD8TO.mjs';
17
17
  import '@babel/types';
18
18
  import 'htmlparser2';
19
19
  import 'postcss';
20
- import './postcss-W8i3cl5I.mjs';
20
+ import './plugin-Du3zrk3S.mjs';
21
21
  import 'postcss-selector-parser';
22
22
  import '@csstools/postcss-is-pseudo-class';
23
23
  import 'node:path';
@@ -27,6 +27,6 @@ import 'tailwindcss-patch';
27
27
  import '@tailwindcss-mangle/shared';
28
28
  import 'lru-cache';
29
29
  import 'md5';
30
- import './index-06BoOZig.mjs';
30
+ import './index-CLxBL7MC.mjs';
31
31
  import 'debug';
32
32
  import 'node:stream';
@@ -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,13 +277,10 @@ 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
281
  try {
294
282
  const ast = parseExpression(match);
283
+ const ms = new MagicString(match);
295
284
  traverse(ast, {
296
285
  StringLiteral(path) {
297
286
  var _a;
@@ -301,19 +290,18 @@ function generateCode(match, options = {}) {
301
290
  if (t.isBinaryExpression(path.parent) && t.isConditionalExpression((_a = path.parentPath) === null || _a === void 0 ? void 0 : _a.parent)) {
302
291
  return;
303
292
  }
304
- path.node.value = replaceWxml(path.node.value, options);
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);
305
301
  },
306
302
  noScope: true
307
303
  });
308
- const { code } = generate(ast, {
309
- compact: true,
310
- minified: true,
311
- jsescOption: {
312
- quotes: getQuotes(options.quote),
313
- minimal: true
314
- }
315
- });
316
- return code;
304
+ return ms.toString();
317
305
  }
318
306
  catch (_a) {
319
307
  return match;
@@ -412,7 +400,7 @@ function customTemplateHandler(rawSource, options) {
412
400
  onattribute(name, value, quote) {
413
401
  if (value) {
414
402
  function update() {
415
- 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 })));
416
404
  }
417
405
  if (!disabledDefaultTemplateHandler && (name === 'class' || name === 'hover-class' || name === 'virtualhostclass')) {
418
406
  update();
@@ -623,7 +611,7 @@ function useMangleStore() {
623
611
  const arr = splitCode(rawSource);
624
612
  for (const x of arr) {
625
613
  if (ctx.runtimeSet.has(x)) {
626
- 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);
627
615
  }
628
616
  }
629
617
  return rawSource;
@@ -807,4 +795,4 @@ function getOptions(options = {}) {
807
795
  return result;
808
796
  }
809
797
 
810
- 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,13 +309,10 @@ 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
313
  try {
326
314
  const ast = parser.parseExpression(match);
315
+ const ms = new MagicString__default["default"](match);
327
316
  traverse__default["default"](ast, {
328
317
  StringLiteral(path) {
329
318
  var _a;
@@ -333,19 +322,18 @@ function generateCode(match, options = {}) {
333
322
  if (t__namespace.isBinaryExpression(path.parent) && t__namespace.isConditionalExpression((_a = path.parentPath) === null || _a === void 0 ? void 0 : _a.parent)) {
334
323
  return;
335
324
  }
336
- path.node.value = replace.replaceJs(path.node.value, options);
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);
337
333
  },
338
334
  noScope: true
339
335
  });
340
- const { code } = generate__default["default"](ast, {
341
- compact: true,
342
- minified: true,
343
- jsescOption: {
344
- quotes: getQuotes(options.quote),
345
- minimal: true
346
- }
347
- });
348
- return code;
336
+ return ms.toString();
349
337
  }
350
338
  catch (_a) {
351
339
  return match;
@@ -444,7 +432,7 @@ function customTemplateHandler(rawSource, options) {
444
432
  onattribute(name, value, quote) {
445
433
  if (value) {
446
434
  function update() {
447
- 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 })));
448
436
  }
449
437
  if (!disabledDefaultTemplateHandler && (name === 'class' || name === 'hover-class' || name === 'virtualhostclass')) {
450
438
  update();
@@ -488,7 +476,7 @@ function createTemplateHandler(options = {}) {
488
476
 
489
477
  function styleHandler(rawSource, options) {
490
478
  return __awaiter(this, void 0, void 0, function* () {
491
- return (yield postcss__default["default"]([postcssIsPseudoClass__default["default"](), postcss$1.postcssWeappTailwindcss(options)])
479
+ return (yield postcss__default["default"]([postcssIsPseudoClass__default["default"](), plugin.postcssWeappTailwindcss(options)])
492
480
  .process(rawSource)
493
481
  .async()).css;
494
482
  });
@@ -655,7 +643,7 @@ function useMangleStore() {
655
643
  const arr = splitCode(rawSource);
656
644
  for (const x of arr) {
657
645
  if (ctx.runtimeSet.has(x)) {
658
- 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);
659
647
  }
660
648
  }
661
649
  return rawSource;