weapp-tailwindcss 2.8.0 → 2.8.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.
@@ -2,15 +2,16 @@ import { isMatch } from 'micromatch';
2
2
  import MagicString from 'magic-string';
3
3
  import { replaceJs as replaceWxml } from './replace.mjs';
4
4
  import { escapeStringRegexp, variableRegExp } from '@weapp-core/regex';
5
- import { jsStringEscape, SimpleMappingChars2String, MappingChars2String } from '@weapp-core/escape';
5
+ import { SimpleMappingChars2String, MappingChars2String } from '@weapp-core/escape';
6
+ import { jsStringEscape } from '@ast-core/escape';
6
7
  import generate from '@babel/generator';
7
8
  import { parse, parseExpression } from '@babel/parser';
8
9
  import traverse from '@babel/traverse';
9
- import { n as noop, d as defaultOptions, i as isMap } from './defaults-72ea9566.mjs';
10
+ import { n as noop, d as defaultOptions, i as isMap } from './defaults-dc8a0e3d.mjs';
10
11
  import * as t from '@babel/types';
11
12
  import { Parser } from 'htmlparser2';
12
13
  import postcss from 'postcss';
13
- import { p as postcssWeappTailwindcss } from './postcss-a551ddc0.mjs';
14
+ import { p as postcssWeappTailwindcss } from './postcss-55ed4d42.mjs';
14
15
  import postcssIsPseudoClass from '@csstools/postcss-is-pseudo-class';
15
16
  import path from 'node:path';
16
17
  import fs from 'node:fs';
@@ -82,8 +83,9 @@ function replaceHandleValue(str, node, options, ms, offset = 0, needEscaped = fa
82
83
  if (typeof node.start === 'number' && typeof node.end === 'number') {
83
84
  const start = node.start + offset;
84
85
  const end = node.end - offset;
85
- if (start < end) {
86
- ms.update(start, end, needEscaped ? jsStringEscape(rawStr) : rawStr);
86
+ if (start < end && str !== rawStr) {
87
+ const content = needEscaped ? jsStringEscape(rawStr) : rawStr;
88
+ ms.update(start, end, content);
87
89
  }
88
90
  }
89
91
  return rawStr;
@@ -91,6 +93,55 @@ function replaceHandleValue(str, node, options, ms, offset = 0, needEscaped = fa
91
93
 
92
94
  const isProd = () => process.env.NODE_ENV === 'production';
93
95
 
96
+ function isObject(value) {
97
+ return value !== null && typeof value === "object";
98
+ }
99
+ function _defu(baseObject, defaults, namespace = ".", merger) {
100
+ if (!isObject(defaults)) {
101
+ return _defu(baseObject, {}, namespace, merger);
102
+ }
103
+ const object = Object.assign({}, defaults);
104
+ for (const key in baseObject) {
105
+ if (key === "__proto__" || key === "constructor") {
106
+ continue;
107
+ }
108
+ const value = baseObject[key];
109
+ if (value === null || value === void 0) {
110
+ continue;
111
+ }
112
+ if (merger && merger(object, key, value, namespace)) {
113
+ continue;
114
+ }
115
+ if (Array.isArray(value) && Array.isArray(object[key])) {
116
+ object[key] = [...value, ...object[key]];
117
+ } else if (isObject(value) && isObject(object[key])) {
118
+ object[key] = _defu(
119
+ value,
120
+ object[key],
121
+ (namespace ? `${namespace}.` : "") + key.toString(),
122
+ merger
123
+ );
124
+ } else {
125
+ object[key] = value;
126
+ }
127
+ }
128
+ return object;
129
+ }
130
+ function createDefu(merger) {
131
+ return (...arguments_) => (
132
+ // eslint-disable-next-line unicorn/no-array-reduce
133
+ arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
134
+ );
135
+ }
136
+ const defu = createDefu();
137
+
138
+ function isEvalPath(p) {
139
+ if (p.isCallExpression()) {
140
+ const calleePath = p.get('callee');
141
+ return calleePath.isIdentifier() && calleePath.node.name === 'eval';
142
+ }
143
+ return false;
144
+ }
94
145
  function jsHandler(rawSource, options) {
95
146
  var _a;
96
147
  const ast = parse(rawSource, {
@@ -101,26 +152,56 @@ function jsHandler(rawSource, options) {
101
152
  const ropt = {
102
153
  StringLiteral: {
103
154
  enter(p) {
155
+ var _a;
156
+ if (isEvalPath(p.parentPath)) {
157
+ return;
158
+ }
104
159
  const n = p.node;
105
- replaceHandleValue(n.value, n, options, ms, 1, true);
160
+ replaceHandleValue(n.value, n, options, ms, 1, (_a = options.needEscaped) !== null && _a !== void 0 ? _a : true);
106
161
  }
107
162
  },
108
163
  TemplateElement: {
109
164
  enter(p) {
165
+ if (p.parentPath.isTemplateLiteral() && isEvalPath(p.parentPath.parentPath)) {
166
+ return;
167
+ }
110
168
  const n = p.node;
111
169
  replaceHandleValue(n.value.raw, n, options, ms, 0, false);
112
170
  }
113
171
  },
114
172
  CallExpression: {
115
173
  enter(p) {
116
- const calleePath = p.get('callee');
117
- if (calleePath.isIdentifier() && calleePath.node.name === 'eval') {
174
+ if (isEvalPath(p)) {
118
175
  p.traverse({
119
176
  StringLiteral: {
120
177
  enter(s) {
121
- const res = jsHandler(s.node.value, options);
178
+ const res = jsHandler(s.node.value, Object.assign(Object.assign({}, options), { needEscaped: false, generateMap: false }));
122
179
  if (res.code) {
123
- s.node.value = res.code;
180
+ const node = s.node;
181
+ if (typeof node.start === 'number' && typeof node.end === 'number') {
182
+ const start = node.start + 1;
183
+ const end = node.end - 1;
184
+ if (start < end && s.node.value !== res.code) {
185
+ ms.update(start, end, jsStringEscape(res.code));
186
+ node.value = res.code;
187
+ }
188
+ }
189
+ }
190
+ }
191
+ },
192
+ TemplateElement: {
193
+ enter(s) {
194
+ const res = jsHandler(s.node.value.raw, Object.assign(Object.assign({}, options), { generateMap: false }));
195
+ if (res.code) {
196
+ const node = s.node;
197
+ if (typeof node.start === 'number' && typeof node.end === 'number') {
198
+ const start = node.start;
199
+ const end = node.end;
200
+ if (start < end && s.node.value.raw !== res.code) {
201
+ ms.update(start, end, res.code);
202
+ s.node.value.raw = res.code;
203
+ }
204
+ }
124
205
  }
125
206
  }
126
207
  }
@@ -130,28 +211,34 @@ function jsHandler(rawSource, options) {
130
211
  }
131
212
  };
132
213
  traverse(ast, ropt);
133
- return {
214
+ const result = {
134
215
  code: ms.toString()
135
216
  };
217
+ return result;
136
218
  }
137
219
  else {
138
220
  const gopt = {
139
221
  StringLiteral: {
140
222
  enter(p) {
223
+ if (isEvalPath(p.parentPath)) {
224
+ return;
225
+ }
141
226
  const n = p.node;
142
227
  n.value = regenerateHandleValue(n.value, n, options);
143
228
  }
144
229
  },
145
230
  TemplateElement: {
146
231
  enter(p) {
232
+ if (p.parentPath.isTemplateLiteral() && isEvalPath(p.parentPath.parentPath)) {
233
+ return;
234
+ }
147
235
  const n = p.node;
148
236
  n.value.raw = regenerateHandleValue(n.value.raw, n, options);
149
237
  }
150
238
  },
151
239
  CallExpression: {
152
240
  enter(p) {
153
- const calleePath = p.get('callee');
154
- if (calleePath.isIdentifier() && calleePath.node.name === 'eval') {
241
+ if (isEvalPath(p)) {
155
242
  p.traverse({
156
243
  StringLiteral: {
157
244
  enter(s) {
@@ -160,6 +247,14 @@ function jsHandler(rawSource, options) {
160
247
  s.node.value = res.code;
161
248
  }
162
249
  }
250
+ },
251
+ TemplateElement: {
252
+ enter(s) {
253
+ const res = jsHandler(s.node.value.raw, options);
254
+ if (res.code) {
255
+ s.node.value.raw = res.code;
256
+ }
257
+ }
163
258
  }
164
259
  });
165
260
  }
@@ -172,63 +267,23 @@ function jsHandler(rawSource, options) {
172
267
  });
173
268
  }
174
269
  }
175
- function createjsHandler(options) {
176
- const { mangleContext, arbitraryValues, minifiedJs, escapeMap, jsPreserveClass, strategy } = options;
177
- return (rawSource, set) => {
178
- return jsHandler(rawSource, {
270
+ function createJsHandler(options) {
271
+ const { mangleContext, arbitraryValues, minifiedJs, escapeMap, jsPreserveClass, strategy, generateMap } = options;
272
+ return (rawSource, set, options) => {
273
+ const opts = defu(options, {
179
274
  classNameSet: set,
180
275
  minifiedJs,
181
276
  escapeMap,
182
277
  arbitraryValues,
183
278
  mangleContext,
184
279
  jsPreserveClass,
185
- strategy
280
+ strategy,
281
+ generateMap
186
282
  });
283
+ return jsHandler(rawSource, opts);
187
284
  };
188
285
  }
189
286
 
190
- function isObject(value) {
191
- return value !== null && typeof value === "object";
192
- }
193
- function _defu(baseObject, defaults, namespace = ".", merger) {
194
- if (!isObject(defaults)) {
195
- return _defu(baseObject, {}, namespace, merger);
196
- }
197
- const object = Object.assign({}, defaults);
198
- for (const key in baseObject) {
199
- if (key === "__proto__" || key === "constructor") {
200
- continue;
201
- }
202
- const value = baseObject[key];
203
- if (value === null || value === void 0) {
204
- continue;
205
- }
206
- if (merger && merger(object, key, value, namespace)) {
207
- continue;
208
- }
209
- if (Array.isArray(value) && Array.isArray(object[key])) {
210
- object[key] = [...value, ...object[key]];
211
- } else if (isObject(value) && isObject(object[key])) {
212
- object[key] = _defu(
213
- value,
214
- object[key],
215
- (namespace ? `${namespace}.` : "") + key.toString(),
216
- merger
217
- );
218
- } else {
219
- object[key] = value;
220
- }
221
- }
222
- return object;
223
- }
224
- function createDefu(merger) {
225
- return (...arguments_) => (
226
- // eslint-disable-next-line unicorn/no-array-reduce
227
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
228
- );
229
- }
230
- const defu = createDefu();
231
-
232
287
  function generateCode(match, options = {}) {
233
288
  const ast = parseExpression(match);
234
289
  traverse(ast, {
@@ -394,7 +449,7 @@ function createTemplateHandler(options = {}) {
394
449
  }
395
450
 
396
451
  function styleHandler(rawSource, options) {
397
- return postcss([postcssWeappTailwindcss(options), postcssIsPseudoClass()]).process(rawSource).css;
452
+ return postcss([postcssIsPseudoClass(), postcssWeappTailwindcss(options)]).process(rawSource).css;
398
453
  }
399
454
  function createStyleHandler(options) {
400
455
  return (rawSource, opt) => {
@@ -631,7 +686,7 @@ function getOptions(options = {}) {
631
686
  const result = defu(options, defaultOptions, {
632
687
  minifiedJs: isProd()
633
688
  });
634
- const { cssPreflight, customRuleCallback, cssPreflightRange, replaceUniversalSelectorWith, customAttributes, customReplaceDictionary, supportCustomLengthUnitsPatch, arbitraryValues, cssChildCombinatorReplaceValue, inlineWxs, injectAdditionalCssVarScope, jsPreserveClass, disabledDefaultTemplateHandler, jsEscapeStrategy } = result;
689
+ const { cssPreflight, customRuleCallback, cssPreflightRange, replaceUniversalSelectorWith, customAttributes, customReplaceDictionary, supportCustomLengthUnitsPatch, arbitraryValues, cssChildCombinatorReplaceValue, inlineWxs, injectAdditionalCssVarScope, jsPreserveClass, disabledDefaultTemplateHandler, jsEscapeStrategy, cssSelectorReplacement } = result;
635
690
  result.escapeMap = customReplaceDictionary;
636
691
  const cssInjectPreflight = createInjectPreflight(cssPreflight);
637
692
  const customAttributesEntities = isMap(options.customAttributes)
@@ -648,16 +703,18 @@ function getOptions(options = {}) {
648
703
  escapeMap,
649
704
  mangleContext,
650
705
  cssChildCombinatorReplaceValue,
651
- injectAdditionalCssVarScope
706
+ injectAdditionalCssVarScope,
707
+ cssSelectorReplacement
652
708
  });
653
709
  result.styleHandler = styleHandler;
654
- const jsHandler = createjsHandler({
710
+ const jsHandler = createJsHandler({
655
711
  minifiedJs,
656
712
  escapeMap,
657
713
  mangleContext,
658
714
  arbitraryValues,
659
715
  jsPreserveClass,
660
- strategy: jsEscapeStrategy
716
+ strategy: jsEscapeStrategy,
717
+ generateMap: true
661
718
  });
662
719
  result.jsHandler = jsHandler;
663
720
  const templateHandler = createTemplateHandler({
@@ -1,20 +1,28 @@
1
1
  import selectorParser from 'postcss-selector-parser';
2
- import { i as internalCssSelectorReplacer } from './shared-fd149084.mjs';
2
+ import { i as internalCssSelectorReplacer } from './shared-283aac78.mjs';
3
3
  import { Declaration, Rule } from 'postcss';
4
4
  import '@csstools/postcss-is-pseudo-class';
5
5
 
6
6
  const createTransform = (rule, options) => {
7
- const { replaceUniversalSelectorWith, escapeMap, mangleContext } = options;
7
+ const { replaceUniversalSelectorWith, escapeMap, mangleContext, cssSelectorReplacement } = options;
8
8
  const replaceFlag = replaceUniversalSelectorWith !== false;
9
9
  const transform = (selectors) => {
10
10
  selectors.walk((selector) => {
11
- if (selector.type === 'universal' && replaceFlag) {
12
- selector.value = replaceUniversalSelectorWith;
11
+ if (selector.type === 'universal') {
12
+ if (replaceFlag) {
13
+ selector.value = replaceUniversalSelectorWith;
14
+ }
15
+ else if (cssSelectorReplacement && cssSelectorReplacement.universal) {
16
+ selector.value = cssSelectorReplacement.universal;
17
+ }
13
18
  }
14
19
  if (selector.type === 'selector') {
15
20
  const node = selector.nodes.find((x) => x.type === 'pseudo' && x.value === ':hover');
16
21
  node && selector.remove();
17
22
  }
23
+ if (selector.type === 'pseudo' && selector.value === ':root' && cssSelectorReplacement && cssSelectorReplacement.root) {
24
+ selector.value = cssSelectorReplacement.root;
25
+ }
18
26
  if (selector.type === 'class') {
19
27
  selector.value = internalCssSelectorReplacer(selector.value, {
20
28
  escapeMap,
@@ -295,8 +303,11 @@ function remakeCssVarSelector(selectors, cssPreflightRange) {
295
303
  function remakeCombinatorSelector(selector, cssChildCombinatorReplaceValue) {
296
304
  let childCombinatorReplaceValue = 'view + view';
297
305
  if (Array.isArray(cssChildCombinatorReplaceValue)) {
298
- const part = cssChildCombinatorReplaceValue.join(',');
299
- childCombinatorReplaceValue = [part, ' + ', part].join('');
306
+ childCombinatorReplaceValue = cssChildCombinatorReplaceValue
307
+ .map((x) => {
308
+ return x + ' + ' + x;
309
+ })
310
+ .join(',');
300
311
  }
301
312
  else if (typeof cssChildCombinatorReplaceValue === 'string') {
302
313
  childCombinatorReplaceValue = cssChildCombinatorReplaceValue;
@@ -343,6 +354,12 @@ const postcssWeappTailwindcss = (options = {
343
354
  isMainChunk && commonChunkPreflight(rule, options);
344
355
  isCustomRuleCallbackFn && customRuleCallback(rule, options);
345
356
  });
357
+ },
358
+ AtRule(atRule) {
359
+ if (atRule.name === 'media' && /\(hover:\s*hover\)/.test(atRule.params)) {
360
+ atRule.before(atRule.nodes);
361
+ atRule.remove();
362
+ }
346
363
  }
347
364
  };
348
365
  };
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var selectorParser = require('postcss-selector-parser');
4
- var shared = require('./shared-df9de23f.js');
4
+ var shared = require('./shared-8b9be5f0.js');
5
5
  var postcss = require('postcss');
6
6
  require('@csstools/postcss-is-pseudo-class');
7
7
 
@@ -10,17 +10,25 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
10
10
  var selectorParser__default = /*#__PURE__*/_interopDefaultCompat(selectorParser);
11
11
 
12
12
  const createTransform = (rule, options) => {
13
- const { replaceUniversalSelectorWith, escapeMap, mangleContext } = options;
13
+ const { replaceUniversalSelectorWith, escapeMap, mangleContext, cssSelectorReplacement } = options;
14
14
  const replaceFlag = replaceUniversalSelectorWith !== false;
15
15
  const transform = (selectors) => {
16
16
  selectors.walk((selector) => {
17
- if (selector.type === 'universal' && replaceFlag) {
18
- selector.value = replaceUniversalSelectorWith;
17
+ if (selector.type === 'universal') {
18
+ if (replaceFlag) {
19
+ selector.value = replaceUniversalSelectorWith;
20
+ }
21
+ else if (cssSelectorReplacement && cssSelectorReplacement.universal) {
22
+ selector.value = cssSelectorReplacement.universal;
23
+ }
19
24
  }
20
25
  if (selector.type === 'selector') {
21
26
  const node = selector.nodes.find((x) => x.type === 'pseudo' && x.value === ':hover');
22
27
  node && selector.remove();
23
28
  }
29
+ if (selector.type === 'pseudo' && selector.value === ':root' && cssSelectorReplacement && cssSelectorReplacement.root) {
30
+ selector.value = cssSelectorReplacement.root;
31
+ }
24
32
  if (selector.type === 'class') {
25
33
  selector.value = shared.internalCssSelectorReplacer(selector.value, {
26
34
  escapeMap,
@@ -301,8 +309,11 @@ function remakeCssVarSelector(selectors, cssPreflightRange) {
301
309
  function remakeCombinatorSelector(selector, cssChildCombinatorReplaceValue) {
302
310
  let childCombinatorReplaceValue = 'view + view';
303
311
  if (Array.isArray(cssChildCombinatorReplaceValue)) {
304
- const part = cssChildCombinatorReplaceValue.join(',');
305
- childCombinatorReplaceValue = [part, ' + ', part].join('');
312
+ childCombinatorReplaceValue = cssChildCombinatorReplaceValue
313
+ .map((x) => {
314
+ return x + ' + ' + x;
315
+ })
316
+ .join(',');
306
317
  }
307
318
  else if (typeof cssChildCombinatorReplaceValue === 'string') {
308
319
  childCombinatorReplaceValue = cssChildCombinatorReplaceValue;
@@ -349,6 +360,12 @@ const postcssWeappTailwindcss = (options = {
349
360
  isMainChunk && commonChunkPreflight(rule, options);
350
361
  isCustomRuleCallbackFn && customRuleCallback(rule, options);
351
362
  });
363
+ },
364
+ AtRule(atRule) {
365
+ if (atRule.name === 'media' && /\(hover:\s*hover\)/.test(atRule.params)) {
366
+ atRule.before(atRule.nodes);
367
+ atRule.remove();
368
+ }
352
369
  }
353
370
  };
354
371
  };
package/dist/postcss.js CHANGED
@@ -2,11 +2,12 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var postcss = require('./postcss-4e99a8e8.js');
5
+ var postcss = require('./postcss-8d7f67b4.js');
6
6
  var postcssIsPseudoClass = require('@csstools/postcss-is-pseudo-class');
7
7
  require('postcss-selector-parser');
8
- require('./shared-df9de23f.js');
8
+ require('./shared-8b9be5f0.js');
9
9
  require('@weapp-core/escape');
10
+ require('@ast-core/escape');
10
11
  require('postcss');
11
12
 
12
13
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
package/dist/postcss.mjs CHANGED
@@ -1,6 +1,7 @@
1
- export { p as postcssWeappTailwindcss } from './postcss-a551ddc0.mjs';
1
+ export { p as postcssWeappTailwindcss } from './postcss-55ed4d42.mjs';
2
2
  export { default as postcssIsPseudoClass } from '@csstools/postcss-is-pseudo-class';
3
3
  import 'postcss-selector-parser';
4
- import './shared-fd149084.mjs';
4
+ import './shared-283aac78.mjs';
5
5
  import '@weapp-core/escape';
6
+ import '@ast-core/escape';
6
7
  import 'postcss';
package/dist/replace.js CHANGED
@@ -3,7 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var escape = require('@weapp-core/escape');
6
- var shared = require('./shared-df9de23f.js');
6
+ require('@ast-core/escape');
7
+ var shared = require('./shared-8b9be5f0.js');
7
8
 
8
9
  function replaceWxml(original, options = {
9
10
  keepEOL: false,
package/dist/replace.mjs CHANGED
@@ -1,6 +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
- export { i as replaceCss } from './shared-fd149084.mjs';
3
+ import '@ast-core/escape';
4
+ export { i as replaceCss } from './shared-283aac78.mjs';
4
5
 
5
6
  function replaceWxml(original, options = {
6
7
  keepEOL: false,
@@ -1,4 +1,5 @@
1
1
  import { escape, SimpleMappingChars2String } from '@weapp-core/escape';
2
+ import '@ast-core/escape';
2
3
 
3
4
  function internalCssSelectorReplacer(selectors, options = {
4
5
  escapeMap: SimpleMappingChars2String
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var escape = require('@weapp-core/escape');
4
+ require('@ast-core/escape');
4
5
 
5
6
  function internalCssSelectorReplacer(selectors, options = {
6
7
  escapeMap: escape.SimpleMappingChars2String
package/dist/types.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import type { Rule } from 'postcss';
2
2
  import type { IClassGeneratorOptions, ClassGenerator } from '@tailwindcss-mangle/shared';
3
+ import type { SourceMap } from 'magic-string';
4
+ import type { GeneratorResult } from '@babel/generator';
3
5
  import type { InjectPreflight } from './postcss/preflight';
4
6
  export type ItemOrItemArray<T> = T | T[];
5
7
  export type AppType = 'uni-app' | 'uni-app-vite' | 'taro' | 'remax' | 'rax' | 'native' | 'kbone' | 'mpx';
@@ -14,12 +16,8 @@ export type CssPreflightOptions = {
14
16
  export type RequiredStyleHandlerOptions = {
15
17
  isMainChunk: boolean;
16
18
  cssInjectPreflight?: InjectPreflight;
17
- cssPreflightRange?: 'view' | 'all';
18
- cssChildCombinatorReplaceValue?: string | string[];
19
- replaceUniversalSelectorWith?: string | false;
20
19
  escapeMap?: Record<string, string>;
21
- injectAdditionalCssVarScope?: boolean;
22
- };
20
+ } & Pick<UserDefinedOptions, 'cssPreflightRange' | 'cssChildCombinatorReplaceValue' | 'replaceUniversalSelectorWith' | 'injectAdditionalCssVarScope' | 'cssSelectorReplacement'>;
23
21
  export type CustomRuleCallback = (node: Rule, options: Readonly<RequiredStyleHandlerOptions>) => void;
24
22
  export interface InternalCssSelectorReplacerOptions {
25
23
  mangleContext?: IMangleScopeContext;
@@ -29,6 +27,11 @@ export type IStyleHandlerOptions = {
29
27
  customRuleCallback?: CustomRuleCallback;
30
28
  mangleContext?: IMangleScopeContext;
31
29
  } & RequiredStyleHandlerOptions;
30
+ export type JsHandlerReplaceResult = {
31
+ code: string;
32
+ map?: SourceMap;
33
+ };
34
+ export type JsHandlerResult = JsHandlerReplaceResult | GeneratorResult;
32
35
  export type ICustomAttributes = Record<string, ItemOrItemArray<string | RegExp>> | Map<string | RegExp, ItemOrItemArray<string | RegExp>>;
33
36
  export type ICustomAttributesEntities = [string | RegExp, ItemOrItemArray<string | RegExp>][];
34
37
  export type IJsHandlerOptions = {
@@ -39,6 +42,8 @@ export type IJsHandlerOptions = {
39
42
  mangleContext?: IMangleScopeContext;
40
43
  jsPreserveClass?: (keyword: string) => boolean | undefined;
41
44
  strategy?: UserDefinedOptions['jsEscapeStrategy'];
45
+ needEscaped?: boolean;
46
+ generateMap?: boolean;
42
47
  };
43
48
  export interface RawSource {
44
49
  start: number;
@@ -95,7 +100,13 @@ export interface UserDefinedOptions {
95
100
  jsPreserveClass?: (keyword: string) => boolean | undefined;
96
101
  disabledDefaultTemplateHandler?: boolean;
97
102
  jsEscapeStrategy?: 'regenerate' | 'replace';
103
+ runtimeLoaderPath?: string;
104
+ cssSelectorReplacement?: {
105
+ root?: string | false;
106
+ universal?: string | false;
107
+ };
98
108
  }
109
+ export type JsHandler = (rawSource: string, set: Set<string>, options?: CreateJsHandlerOptions) => JsHandlerResult;
99
110
  export interface IMangleScopeContext {
100
111
  rawOptions: UserDefinedOptions['mangle'];
101
112
  runtimeSet: Set<string>;
@@ -114,9 +125,7 @@ export interface ITemplateHandlerOptions extends ICommonReplaceOptions {
114
125
  escapeMap?: Record<string, string>;
115
126
  mangleContext?: IMangleScopeContext;
116
127
  inlineWxs?: boolean;
117
- jsHandler?: (rawSource: string, set: Set<string>) => {
118
- code: string;
119
- };
128
+ jsHandler?: JsHandler;
120
129
  runtimeSet?: Set<string>;
121
130
  disabledDefaultTemplateHandler?: boolean;
122
131
  }
@@ -127,9 +136,7 @@ export type InternalUserDefinedOptions = Required<Omit<UserDefinedOptions, GlobO
127
136
  supportCustomLengthUnitsPatch: ILengthUnitsPatchOptions | false;
128
137
  templateHandler: (rawSource: string, options?: ITemplateHandlerOptions) => string;
129
138
  styleHandler: (rawSource: string, options: IStyleHandlerOptions) => string;
130
- jsHandler: (rawSource: string, set: Set<string>) => {
131
- code: string;
132
- };
139
+ jsHandler: JsHandler;
133
140
  escapeMap: Record<string, string>;
134
141
  patch: () => void;
135
142
  customReplaceDictionary: Record<string, string>;
@@ -146,3 +153,4 @@ export interface InternalPatchResult {
146
153
  processTailwindFeatures?: string;
147
154
  plugin?: string;
148
155
  }
156
+ export type CreateJsHandlerOptions = Omit<IJsHandlerOptions, 'classNameSet'>;
package/dist/vite.js CHANGED
@@ -2,14 +2,15 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var options = require('./options-7b804be0.js');
6
- var postcss = require('./postcss-4e99a8e8.js');
7
- var defaults = require('./defaults-c6437917.js');
5
+ var options = require('./options-50d69eba.js');
6
+ var postcss = require('./postcss-8d7f67b4.js');
7
+ var defaults = require('./defaults-263271f9.js');
8
8
  require('micromatch');
9
9
  require('magic-string');
10
10
  require('./replace.js');
11
11
  require('@weapp-core/escape');
12
- require('./shared-df9de23f.js');
12
+ require('@ast-core/escape');
13
+ require('./shared-8b9be5f0.js');
13
14
  require('@weapp-core/regex');
14
15
  require('@babel/generator');
15
16
  require('@babel/parser');
@@ -71,9 +72,16 @@ function UnifiedViteWeappTailwindcssPlugin(options$1 = {}) {
71
72
  for (let i = 0; i < groupedEntries.js.length; i++) {
72
73
  const [file, originalSource] = groupedEntries.js[i];
73
74
  const rawSource = originalSource.code;
74
- const { code } = jsHandler(rawSource, runtimeSet);
75
+ const mapFilename = file + '.map';
76
+ const hasMap = Boolean(bundle[mapFilename]);
77
+ const { code, map } = jsHandler(rawSource, runtimeSet, {
78
+ generateMap: hasMap
79
+ });
75
80
  originalSource.code = code;
76
81
  onUpdate(file, rawSource, code);
82
+ if (hasMap && map) {
83
+ bundle[mapFilename].source = map.toString();
84
+ }
77
85
  }
78
86
  }
79
87
  onEnd();
package/dist/vite.mjs CHANGED
@@ -1,11 +1,12 @@
1
- import { g as getOptions, a as createTailwindcssPatcher } from './options-70759e98.mjs';
2
- import { v as vitePluginName } from './postcss-a551ddc0.mjs';
3
- import { g as getGroupedEntries } from './defaults-72ea9566.mjs';
1
+ import { g as getOptions, a as createTailwindcssPatcher } from './options-8a945166.mjs';
2
+ import { v as vitePluginName } from './postcss-55ed4d42.mjs';
3
+ import { g as getGroupedEntries } from './defaults-dc8a0e3d.mjs';
4
4
  import 'micromatch';
5
5
  import 'magic-string';
6
6
  import './replace.mjs';
7
7
  import '@weapp-core/escape';
8
- import './shared-fd149084.mjs';
8
+ import '@ast-core/escape';
9
+ import './shared-283aac78.mjs';
9
10
  import '@weapp-core/regex';
10
11
  import '@babel/generator';
11
12
  import '@babel/parser';
@@ -67,9 +68,16 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
67
68
  for (let i = 0; i < groupedEntries.js.length; i++) {
68
69
  const [file, originalSource] = groupedEntries.js[i];
69
70
  const rawSource = originalSource.code;
70
- const { code } = jsHandler(rawSource, runtimeSet);
71
+ const mapFilename = file + '.map';
72
+ const hasMap = Boolean(bundle[mapFilename]);
73
+ const { code, map } = jsHandler(rawSource, runtimeSet, {
74
+ generateMap: hasMap
75
+ });
71
76
  originalSource.code = code;
72
77
  onUpdate(file, rawSource, code);
78
+ if (hasMap && map) {
79
+ bundle[mapFilename].source = map.toString();
80
+ }
73
81
  }
74
82
  }
75
83
  onEnd();