weapp-tailwindcss 2.6.0 → 2.6.1

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.
@@ -6,10 +6,11 @@ var generate = require('@babel/generator');
6
6
  var parser = require('@babel/parser');
7
7
  var traverse = require('@babel/traverse');
8
8
  var replace = require('./replace.js');
9
- var shared = require('./shared-ae7dd073.js');
9
+ var defaults = require('./defaults-0d9846f4.js');
10
10
  var postcss = require('postcss');
11
- var postcss$1 = require('./postcss-b53e9504.js');
11
+ var postcss$1 = require('./postcss-cf8b998a.js');
12
12
  var postcssIsPseudoClass = require('@csstools/postcss-is-pseudo-class');
13
+ var dic = require('./dic-05980807.js');
13
14
  var path = require('node:path');
14
15
  var fs = require('node:fs');
15
16
  var semver = require('semver');
@@ -86,52 +87,6 @@ function createDefu(merger) {
86
87
  }
87
88
  const defu = createDefu();
88
89
 
89
- function isRegexp(value) {
90
- return Object.prototype.toString.call(value) === '[object RegExp]';
91
- }
92
- function isMap(value) {
93
- return Object.prototype.toString.call(value) === '[object Map]';
94
- }
95
- const noop = () => { };
96
- function groupBy(arr, cb) {
97
- if (!Array.isArray(arr)) {
98
- throw new TypeError('expected an array for first argument');
99
- }
100
- if (typeof cb !== 'function') {
101
- throw new TypeError('expected a function for second argument');
102
- }
103
- const result = {};
104
- for (const item of arr) {
105
- const bucketCategory = cb(item);
106
- const bucket = result[bucketCategory];
107
- if (Array.isArray(bucket)) {
108
- result[bucketCategory].push(item);
109
- }
110
- else {
111
- result[bucketCategory] = [item];
112
- }
113
- }
114
- return result;
115
- }
116
- function getGroupedEntries(entries, options) {
117
- const { cssMatcher, htmlMatcher, jsMatcher, wxsMatcher } = options;
118
- const groupedEntries = groupBy(entries, ([file]) => {
119
- if (cssMatcher(file)) {
120
- return 'css';
121
- }
122
- else if (htmlMatcher(file)) {
123
- return 'html';
124
- }
125
- else if (jsMatcher(file) || wxsMatcher(file)) {
126
- return 'js';
127
- }
128
- else {
129
- return 'other';
130
- }
131
- });
132
- return groupedEntries;
133
- }
134
-
135
90
  function escapeStringRegexp(str) {
136
91
  if (typeof str !== 'string') {
137
92
  throw new TypeError('Expected a string');
@@ -148,7 +103,7 @@ function getSourceString(input) {
148
103
  if (typeof input === 'string') {
149
104
  result = input;
150
105
  }
151
- else if (isRegexp(input)) {
106
+ else if (defaults.isRegexp(input)) {
152
107
  result = input.source;
153
108
  }
154
109
  else {
@@ -164,7 +119,7 @@ function makePattern(arr) {
164
119
  if (typeof cur === 'string') {
165
120
  acc.push(cur);
166
121
  }
167
- else if (isRegexp(cur)) {
122
+ else if (defaults.isRegexp(cur)) {
168
123
  acc.push(handleRegexp(cur));
169
124
  }
170
125
  return acc;
@@ -174,7 +129,7 @@ function makePattern(arr) {
174
129
  else if (typeof arr === 'string') {
175
130
  pattern = arr;
176
131
  }
177
- else if (isRegexp(arr)) {
132
+ else if (defaults.isRegexp(arr)) {
178
133
  pattern = handleRegexp(arr);
179
134
  }
180
135
  return pattern;
@@ -229,10 +184,11 @@ function handleValue(str, node, options) {
229
184
  const escapeMap = options.escapeMap;
230
185
  const allowDoubleQuotes = (_a = options.arbitraryValues) === null || _a === void 0 ? void 0 : _a.allowDoubleQuotes;
231
186
  const ctx = options.mangleContext;
187
+ const jsPreserveClass = options.jsPreserveClass;
232
188
  const arr = splitCode(str, allowDoubleQuotes);
233
189
  let rawStr = str;
234
190
  for (const v of arr) {
235
- if (set.has(v)) {
191
+ if (set.has(v) && !(jsPreserveClass === null || jsPreserveClass === void 0 ? void 0 : jsPreserveClass(v))) {
236
192
  let ignoreFlag = false;
237
193
  if (Array.isArray(node.leadingComments)) {
238
194
  ignoreFlag = node.leadingComments.findIndex((x) => x.value.includes('weapp-tw') && x.value.includes('ignore')) > -1;
@@ -286,96 +242,19 @@ function jsHandler(rawSource, options) {
286
242
  });
287
243
  }
288
244
  function createjsHandler(options) {
289
- const { mangleContext, arbitraryValues, minifiedJs, escapeMap } = options;
245
+ const { mangleContext, arbitraryValues, minifiedJs, escapeMap, jsPreserveClass } = options;
290
246
  return (rawSource, set) => {
291
247
  return jsHandler(rawSource, {
292
248
  classNameSet: set,
293
249
  minifiedJs,
294
250
  escapeMap,
295
251
  arbitraryValues,
296
- mangleContext
252
+ mangleContext,
253
+ jsPreserveClass
297
254
  });
298
255
  };
299
256
  }
300
257
 
301
- const defaultOptions = {
302
- cssMatcher: (file) => /.+\.(?:wx|ac|jx|tt|q|c)ss$/.test(file),
303
- htmlMatcher: (file) => /.+\.(?:(?:(?:wx|ax|jx|ks|tt|q)ml)|swan)$/.test(file),
304
- jsMatcher: (file) => {
305
- if (file.includes('node_modules')) {
306
- return false;
307
- }
308
- return /.+\.[cm]?js?$/.test(file);
309
- },
310
- mainCssChunkMatcher: (file, appType) => {
311
- switch (appType) {
312
- case 'uni-app': {
313
- return /^common\/main/.test(file);
314
- }
315
- case 'uni-app-vite': {
316
- return file.startsWith('app') || /^common\/main/.test(file);
317
- }
318
- case 'mpx': {
319
- return file.startsWith('app');
320
- }
321
- case 'taro': {
322
- return file.startsWith('app');
323
- }
324
- case 'remax': {
325
- return file.startsWith('app');
326
- }
327
- case 'rax': {
328
- return file.startsWith('bundle');
329
- }
330
- case 'native': {
331
- return file.startsWith('app');
332
- }
333
- case 'kbone': {
334
- return /^(?:common\/)?miniprogram-app/.test(file);
335
- }
336
- default: {
337
- return true;
338
- }
339
- }
340
- },
341
- wxsMatcher: (file) => {
342
- return false;
343
- },
344
- cssPreflight: {
345
- 'box-sizing': 'border-box',
346
- 'border-width': '0',
347
- 'border-style': 'solid',
348
- 'border-color': 'currentColor'
349
- },
350
- cssPreflightRange: 'view',
351
- replaceUniversalSelectorWith: 'view',
352
- disabled: false,
353
- customRuleCallback: noop,
354
- onLoad: noop,
355
- onStart: noop,
356
- onEnd: noop,
357
- onUpdate: noop,
358
- customAttributes: {},
359
- customReplaceDictionary: shared.SimpleMappingChars2String,
360
- supportCustomLengthUnitsPatch: {
361
- units: ['rpx'],
362
- dangerousOptions: {
363
- gteVersion: '3.0.0',
364
- lengthUnitsFilePath: 'lib/util/dataTypes.js',
365
- packageName: 'tailwindcss',
366
- variableName: 'lengthUnits',
367
- overwrite: true
368
- }
369
- },
370
- appType: undefined,
371
- arbitraryValues: {
372
- allowDoubleQuotes: false
373
- },
374
- cssChildCombinatorReplaceValue: 'view + view',
375
- inlineWxs: false,
376
- injectAdditionalCssVarScope: false
377
- };
378
-
379
258
  function generateCode(match, options = {}) {
380
259
  const ast = parser.parseExpression(match);
381
260
  traverse__default["default"](ast, {
@@ -579,7 +458,7 @@ function getInstalledPkgJsonPath(options) {
579
458
  }
580
459
  function createPatch(options) {
581
460
  if (options === false) {
582
- return noop;
461
+ return defaults.noop;
583
462
  }
584
463
  return () => {
585
464
  try {
@@ -720,23 +599,23 @@ function getOptions(options = {}) {
720
599
  options.supportCustomLengthUnitsPatch = undefined;
721
600
  }
722
601
  if (options.customReplaceDictionary === 'simple') {
723
- options.customReplaceDictionary = shared.SimpleMappingChars2String;
602
+ options.customReplaceDictionary = dic.SimpleMappingChars2String;
724
603
  }
725
604
  else if (options.customReplaceDictionary === 'complex') {
726
- options.customReplaceDictionary = shared.MappingChars2String;
605
+ options.customReplaceDictionary = dic.MappingChars2String;
727
606
  }
728
607
  normalizeMatcher(options, 'cssMatcher');
729
608
  normalizeMatcher(options, 'htmlMatcher');
730
609
  normalizeMatcher(options, 'jsMatcher');
731
610
  normalizeMatcher(options, 'wxsMatcher');
732
611
  normalizeMatcher(options, 'mainCssChunkMatcher');
733
- const result = defu(options, defaultOptions, {
612
+ const result = defu(options, defaults.defaultOptions, {
734
613
  minifiedJs: isProd()
735
614
  });
736
- const { cssPreflight, customRuleCallback, cssPreflightRange, replaceUniversalSelectorWith, customAttributes, customReplaceDictionary, supportCustomLengthUnitsPatch, arbitraryValues, cssChildCombinatorReplaceValue, inlineWxs, injectAdditionalCssVarScope } = result;
615
+ const { cssPreflight, customRuleCallback, cssPreflightRange, replaceUniversalSelectorWith, customAttributes, customReplaceDictionary, supportCustomLengthUnitsPatch, arbitraryValues, cssChildCombinatorReplaceValue, inlineWxs, injectAdditionalCssVarScope, jsPreserveClass } = result;
737
616
  result.escapeMap = customReplaceDictionary;
738
617
  const cssInjectPreflight = createInjectPreflight(cssPreflight);
739
- const customAttributesEntities = isMap(options.customAttributes)
618
+ const customAttributesEntities = defaults.isMap(options.customAttributes)
740
619
  ? [...options.customAttributes.entries()]
741
620
  : Object.entries(customAttributes);
742
621
  const { escapeMap, minifiedJs } = result;
@@ -757,7 +636,8 @@ function getOptions(options = {}) {
757
636
  minifiedJs,
758
637
  escapeMap,
759
638
  mangleContext,
760
- arbitraryValues
639
+ arbitraryValues,
640
+ jsPreserveClass
761
641
  });
762
642
  result.jsHandler = jsHandler;
763
643
  const templeteHandler = createTempleteHandler({
@@ -775,5 +655,4 @@ function getOptions(options = {}) {
775
655
 
776
656
  exports.createPatch = createPatch;
777
657
  exports.createTailwindcssPatcher = createTailwindcssPatcher;
778
- exports.getGroupedEntries = getGroupedEntries;
779
658
  exports.getOptions = getOptions;
@@ -4,10 +4,11 @@ import generate from '@babel/generator';
4
4
  import { parse, parseExpression } from '@babel/parser';
5
5
  import traverse from '@babel/traverse';
6
6
  import { replaceJs as replaceWxml } from './replace.mjs';
7
- import { S as SimpleMappingChars2String, M as MappingChars2String } from './shared-7c88fb94.mjs';
7
+ import { i as isRegexp, n as noop, d as defaultOptions, a as isMap } from './defaults-c7f00aae.mjs';
8
8
  import postcss from 'postcss';
9
- import { p as postcssWeappTailwindcss } from './postcss-760298ba.mjs';
9
+ import { p as postcssWeappTailwindcss } from './postcss-53e2ad95.mjs';
10
10
  import postcssIsPseudoClass from '@csstools/postcss-is-pseudo-class';
11
+ import { S as SimpleMappingChars2String, M as MappingChars2String } from './dic-3790a3a4.mjs';
11
12
  import path from 'node:path';
12
13
  import fs from 'node:fs';
13
14
  import { gte } from 'semver';
@@ -56,52 +57,6 @@ function createDefu(merger) {
56
57
  }
57
58
  const defu = createDefu();
58
59
 
59
- function isRegexp(value) {
60
- return Object.prototype.toString.call(value) === '[object RegExp]';
61
- }
62
- function isMap(value) {
63
- return Object.prototype.toString.call(value) === '[object Map]';
64
- }
65
- const noop = () => { };
66
- function groupBy(arr, cb) {
67
- if (!Array.isArray(arr)) {
68
- throw new TypeError('expected an array for first argument');
69
- }
70
- if (typeof cb !== 'function') {
71
- throw new TypeError('expected a function for second argument');
72
- }
73
- const result = {};
74
- for (const item of arr) {
75
- const bucketCategory = cb(item);
76
- const bucket = result[bucketCategory];
77
- if (Array.isArray(bucket)) {
78
- result[bucketCategory].push(item);
79
- }
80
- else {
81
- result[bucketCategory] = [item];
82
- }
83
- }
84
- return result;
85
- }
86
- function getGroupedEntries(entries, options) {
87
- const { cssMatcher, htmlMatcher, jsMatcher, wxsMatcher } = options;
88
- const groupedEntries = groupBy(entries, ([file]) => {
89
- if (cssMatcher(file)) {
90
- return 'css';
91
- }
92
- else if (htmlMatcher(file)) {
93
- return 'html';
94
- }
95
- else if (jsMatcher(file) || wxsMatcher(file)) {
96
- return 'js';
97
- }
98
- else {
99
- return 'other';
100
- }
101
- });
102
- return groupedEntries;
103
- }
104
-
105
60
  function escapeStringRegexp(str) {
106
61
  if (typeof str !== 'string') {
107
62
  throw new TypeError('Expected a string');
@@ -199,10 +154,11 @@ function handleValue(str, node, options) {
199
154
  const escapeMap = options.escapeMap;
200
155
  const allowDoubleQuotes = (_a = options.arbitraryValues) === null || _a === void 0 ? void 0 : _a.allowDoubleQuotes;
201
156
  const ctx = options.mangleContext;
157
+ const jsPreserveClass = options.jsPreserveClass;
202
158
  const arr = splitCode(str, allowDoubleQuotes);
203
159
  let rawStr = str;
204
160
  for (const v of arr) {
205
- if (set.has(v)) {
161
+ if (set.has(v) && !(jsPreserveClass === null || jsPreserveClass === void 0 ? void 0 : jsPreserveClass(v))) {
206
162
  let ignoreFlag = false;
207
163
  if (Array.isArray(node.leadingComments)) {
208
164
  ignoreFlag = node.leadingComments.findIndex((x) => x.value.includes('weapp-tw') && x.value.includes('ignore')) > -1;
@@ -256,96 +212,19 @@ function jsHandler(rawSource, options) {
256
212
  });
257
213
  }
258
214
  function createjsHandler(options) {
259
- const { mangleContext, arbitraryValues, minifiedJs, escapeMap } = options;
215
+ const { mangleContext, arbitraryValues, minifiedJs, escapeMap, jsPreserveClass } = options;
260
216
  return (rawSource, set) => {
261
217
  return jsHandler(rawSource, {
262
218
  classNameSet: set,
263
219
  minifiedJs,
264
220
  escapeMap,
265
221
  arbitraryValues,
266
- mangleContext
222
+ mangleContext,
223
+ jsPreserveClass
267
224
  });
268
225
  };
269
226
  }
270
227
 
271
- const defaultOptions = {
272
- cssMatcher: (file) => /.+\.(?:wx|ac|jx|tt|q|c)ss$/.test(file),
273
- htmlMatcher: (file) => /.+\.(?:(?:(?:wx|ax|jx|ks|tt|q)ml)|swan)$/.test(file),
274
- jsMatcher: (file) => {
275
- if (file.includes('node_modules')) {
276
- return false;
277
- }
278
- return /.+\.[cm]?js?$/.test(file);
279
- },
280
- mainCssChunkMatcher: (file, appType) => {
281
- switch (appType) {
282
- case 'uni-app': {
283
- return /^common\/main/.test(file);
284
- }
285
- case 'uni-app-vite': {
286
- return file.startsWith('app') || /^common\/main/.test(file);
287
- }
288
- case 'mpx': {
289
- return file.startsWith('app');
290
- }
291
- case 'taro': {
292
- return file.startsWith('app');
293
- }
294
- case 'remax': {
295
- return file.startsWith('app');
296
- }
297
- case 'rax': {
298
- return file.startsWith('bundle');
299
- }
300
- case 'native': {
301
- return file.startsWith('app');
302
- }
303
- case 'kbone': {
304
- return /^(?:common\/)?miniprogram-app/.test(file);
305
- }
306
- default: {
307
- return true;
308
- }
309
- }
310
- },
311
- wxsMatcher: (file) => {
312
- return false;
313
- },
314
- cssPreflight: {
315
- 'box-sizing': 'border-box',
316
- 'border-width': '0',
317
- 'border-style': 'solid',
318
- 'border-color': 'currentColor'
319
- },
320
- cssPreflightRange: 'view',
321
- replaceUniversalSelectorWith: 'view',
322
- disabled: false,
323
- customRuleCallback: noop,
324
- onLoad: noop,
325
- onStart: noop,
326
- onEnd: noop,
327
- onUpdate: noop,
328
- customAttributes: {},
329
- customReplaceDictionary: SimpleMappingChars2String,
330
- supportCustomLengthUnitsPatch: {
331
- units: ['rpx'],
332
- dangerousOptions: {
333
- gteVersion: '3.0.0',
334
- lengthUnitsFilePath: 'lib/util/dataTypes.js',
335
- packageName: 'tailwindcss',
336
- variableName: 'lengthUnits',
337
- overwrite: true
338
- }
339
- },
340
- appType: undefined,
341
- arbitraryValues: {
342
- allowDoubleQuotes: false
343
- },
344
- cssChildCombinatorReplaceValue: 'view + view',
345
- inlineWxs: false,
346
- injectAdditionalCssVarScope: false
347
- };
348
-
349
228
  function generateCode(match, options = {}) {
350
229
  const ast = parseExpression(match);
351
230
  traverse(ast, {
@@ -703,7 +582,7 @@ function getOptions(options = {}) {
703
582
  const result = defu(options, defaultOptions, {
704
583
  minifiedJs: isProd()
705
584
  });
706
- const { cssPreflight, customRuleCallback, cssPreflightRange, replaceUniversalSelectorWith, customAttributes, customReplaceDictionary, supportCustomLengthUnitsPatch, arbitraryValues, cssChildCombinatorReplaceValue, inlineWxs, injectAdditionalCssVarScope } = result;
585
+ const { cssPreflight, customRuleCallback, cssPreflightRange, replaceUniversalSelectorWith, customAttributes, customReplaceDictionary, supportCustomLengthUnitsPatch, arbitraryValues, cssChildCombinatorReplaceValue, inlineWxs, injectAdditionalCssVarScope, jsPreserveClass } = result;
707
586
  result.escapeMap = customReplaceDictionary;
708
587
  const cssInjectPreflight = createInjectPreflight(cssPreflight);
709
588
  const customAttributesEntities = isMap(options.customAttributes)
@@ -727,7 +606,8 @@ function getOptions(options = {}) {
727
606
  minifiedJs,
728
607
  escapeMap,
729
608
  mangleContext,
730
- arbitraryValues
609
+ arbitraryValues,
610
+ jsPreserveClass
731
611
  });
732
612
  result.jsHandler = jsHandler;
733
613
  const templeteHandler = createTempleteHandler({
@@ -743,4 +623,4 @@ function getOptions(options = {}) {
743
623
  return result;
744
624
  }
745
625
 
746
- export { createTailwindcssPatcher as a, getGroupedEntries as b, createPatch as c, getOptions as g };
626
+ export { createTailwindcssPatcher as a, createPatch as c, getOptions as g };
@@ -1,5 +1,5 @@
1
1
  import selectorParser from 'postcss-selector-parser';
2
- import { i as internalCssSelectorReplacer } from './shared-7c88fb94.mjs';
2
+ import { i as internalCssSelectorReplacer } from './shared-686bfc32.mjs';
3
3
  import { Declaration, Rule } from 'postcss';
4
4
  import '@csstools/postcss-is-pseudo-class';
5
5
 
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var selectorParser = require('postcss-selector-parser');
4
- var shared = require('./shared-ae7dd073.js');
4
+ var shared = require('./shared-4eed0e5c.js');
5
5
  var postcss = require('postcss');
6
6
  require('@csstools/postcss-is-pseudo-class');
7
7
 
package/dist/postcss.js CHANGED
@@ -2,10 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var postcss = require('./postcss-b53e9504.js');
5
+ var postcss = require('./postcss-cf8b998a.js');
6
6
  var postcssIsPseudoClass = require('@csstools/postcss-is-pseudo-class');
7
7
  require('postcss-selector-parser');
8
- require('./shared-ae7dd073.js');
8
+ require('./shared-4eed0e5c.js');
9
+ require('./dic-05980807.js');
9
10
  require('postcss');
10
11
 
11
12
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
package/dist/postcss.mjs CHANGED
@@ -1,5 +1,6 @@
1
- export { p as postcssWeappTailwindcss } from './postcss-760298ba.mjs';
1
+ export { p as postcssWeappTailwindcss } from './postcss-53e2ad95.mjs';
2
2
  export { default as postcssIsPseudoClass } from '@csstools/postcss-is-pseudo-class';
3
3
  import 'postcss-selector-parser';
4
- import './shared-7c88fb94.mjs';
4
+ import './shared-686bfc32.mjs';
5
+ import './dic-3790a3a4.mjs';
5
6
  import 'postcss';
package/dist/replace.js CHANGED
@@ -2,11 +2,12 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var shared = require('./shared-ae7dd073.js');
5
+ var dic = require('./dic-05980807.js');
6
+ var shared = require('./shared-4eed0e5c.js');
6
7
 
7
8
  function replaceWxml(original, options = {
8
9
  keepEOL: false,
9
- escapeMap: shared.SimpleMappingChars2String
10
+ escapeMap: dic.SimpleMappingChars2String
10
11
  }) {
11
12
  const { keepEOL, escapeMap, mangleContext } = options;
12
13
  let res = original;
@@ -23,10 +24,10 @@ function replaceWxml(original, options = {
23
24
  return res;
24
25
  }
25
26
 
26
- exports.MappingChars2String = shared.MappingChars2String;
27
- exports.MappingChars2StringEntries = shared.MappingChars2StringEntries;
28
- exports.SYMBOL_TABLE = shared.SYMBOL_TABLE;
29
- exports.SimpleMappingChars2String = shared.SimpleMappingChars2String;
30
- exports.SimpleMappingChars2StringEntries = shared.SimpleMappingChars2StringEntries;
27
+ exports.MappingChars2String = dic.MappingChars2String;
28
+ exports.MappingChars2StringEntries = dic.MappingChars2StringEntries;
29
+ exports.SYMBOL_TABLE = dic.SYMBOL_TABLE;
30
+ exports.SimpleMappingChars2String = dic.SimpleMappingChars2String;
31
+ exports.SimpleMappingChars2StringEntries = dic.SimpleMappingChars2StringEntries;
31
32
  exports.replaceCss = shared.internalCssSelectorReplacer;
32
33
  exports.replaceJs = replaceWxml;
package/dist/replace.mjs CHANGED
@@ -1,5 +1,7 @@
1
- import { e as escape, S as SimpleMappingChars2String } from './shared-7c88fb94.mjs';
2
- export { M as MappingChars2String, b as MappingChars2StringEntries, a as SYMBOL_TABLE, c as SimpleMappingChars2StringEntries, i as replaceCss } from './shared-7c88fb94.mjs';
1
+ import { S as SimpleMappingChars2String } from './dic-3790a3a4.mjs';
2
+ export { M as MappingChars2String, b as MappingChars2StringEntries, a as SYMBOL_TABLE, c as SimpleMappingChars2StringEntries } from './dic-3790a3a4.mjs';
3
+ import { e as escape } from './shared-686bfc32.mjs';
4
+ export { i as replaceCss } from './shared-686bfc32.mjs';
3
5
 
4
6
  function replaceWxml(original, options = {
5
7
  keepEOL: false,
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ var dic = require('./dic-05980807.js');
4
+
5
+ const MAX_ASCII_CHAR_CODE = 127;
6
+ function isAsciiNumber(code) {
7
+ return code >= 48 && code <= 57;
8
+ }
9
+ function escape(selectors, options = {
10
+ map: dic.SimpleMappingChars2String
11
+ }) {
12
+ const { map = dic.SimpleMappingChars2String } = options;
13
+ const sb = [...selectors];
14
+ for (let i = 0; i < sb.length; i++) {
15
+ const char = sb[i];
16
+ const code = char.codePointAt(0);
17
+ const isCodeExisted = code !== undefined;
18
+ const hit = map[char];
19
+ if (isCodeExisted) {
20
+ if (code > MAX_ASCII_CHAR_CODE) {
21
+ sb[i] = 'u' + Number(code).toString(16);
22
+ }
23
+ else if (hit) {
24
+ sb[i] = hit;
25
+ }
26
+ else if (i === 0) {
27
+ if (isAsciiNumber(code)) {
28
+ sb[i] = '_' + char;
29
+ }
30
+ else if (char === '-') {
31
+ const nextChar = sb[i + 1];
32
+ if (nextChar) {
33
+ const nextCharCode = nextChar.codePointAt(0);
34
+ if (nextCharCode && isAsciiNumber(nextCharCode)) {
35
+ sb[i] = '_' + char;
36
+ }
37
+ }
38
+ else if (nextChar === undefined) {
39
+ sb[i] = '_' + char;
40
+ }
41
+ }
42
+ }
43
+ }
44
+ }
45
+ const res = sb.join('');
46
+ return res;
47
+ }
48
+
49
+ function internalCssSelectorReplacer(selectors, options = {
50
+ escapeMap: dic.SimpleMappingChars2String
51
+ }) {
52
+ const { mangleContext, escapeMap } = options;
53
+ if (mangleContext) {
54
+ selectors = mangleContext.cssHandler(selectors);
55
+ }
56
+ return escape(selectors, {
57
+ map: escapeMap
58
+ });
59
+ }
60
+
61
+ exports.escape = escape;
62
+ exports.internalCssSelectorReplacer = internalCssSelectorReplacer;
@@ -0,0 +1,59 @@
1
+ import { S as SimpleMappingChars2String } from './dic-3790a3a4.mjs';
2
+
3
+ const MAX_ASCII_CHAR_CODE = 127;
4
+ function isAsciiNumber(code) {
5
+ return code >= 48 && code <= 57;
6
+ }
7
+ function escape(selectors, options = {
8
+ map: SimpleMappingChars2String
9
+ }) {
10
+ const { map = SimpleMappingChars2String } = options;
11
+ const sb = [...selectors];
12
+ for (let i = 0; i < sb.length; i++) {
13
+ const char = sb[i];
14
+ const code = char.codePointAt(0);
15
+ const isCodeExisted = code !== undefined;
16
+ const hit = map[char];
17
+ if (isCodeExisted) {
18
+ if (code > MAX_ASCII_CHAR_CODE) {
19
+ sb[i] = 'u' + Number(code).toString(16);
20
+ }
21
+ else if (hit) {
22
+ sb[i] = hit;
23
+ }
24
+ else if (i === 0) {
25
+ if (isAsciiNumber(code)) {
26
+ sb[i] = '_' + char;
27
+ }
28
+ else if (char === '-') {
29
+ const nextChar = sb[i + 1];
30
+ if (nextChar) {
31
+ const nextCharCode = nextChar.codePointAt(0);
32
+ if (nextCharCode && isAsciiNumber(nextCharCode)) {
33
+ sb[i] = '_' + char;
34
+ }
35
+ }
36
+ else if (nextChar === undefined) {
37
+ sb[i] = '_' + char;
38
+ }
39
+ }
40
+ }
41
+ }
42
+ }
43
+ const res = sb.join('');
44
+ return res;
45
+ }
46
+
47
+ function internalCssSelectorReplacer(selectors, options = {
48
+ escapeMap: SimpleMappingChars2String
49
+ }) {
50
+ const { mangleContext, escapeMap } = options;
51
+ if (mangleContext) {
52
+ selectors = mangleContext.cssHandler(selectors);
53
+ }
54
+ return escape(selectors, {
55
+ map: escapeMap
56
+ });
57
+ }
58
+
59
+ export { escape as e, internalCssSelectorReplacer as i };
package/dist/types.d.ts CHANGED
@@ -38,6 +38,7 @@ export type IJsHandlerOptions = {
38
38
  minifiedJs?: boolean;
39
39
  arbitraryValues?: IArbitraryValues;
40
40
  mangleContext?: IMangleScopeContext;
41
+ jsPreserveClass?: (keyword: string) => boolean | undefined;
41
42
  };
42
43
  export interface RawSource {
43
44
  start: number;
@@ -91,6 +92,7 @@ export interface UserDefinedOptions {
91
92
  wxsMatcher?: ((name: string) => boolean) | string | string[];
92
93
  inlineWxs?: boolean;
93
94
  injectAdditionalCssVarScope?: boolean;
95
+ jsPreserveClass?: (keyword: string) => boolean | undefined;
94
96
  }
95
97
  export interface IMangleScopeContext {
96
98
  rawOptions: UserDefinedOptions['mangle'];