weapp-tailwindcss 2.4.0 → 2.4.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.
- package/README.md +1 -1
- package/dist/cli.js +4 -4
- package/dist/cli.mjs +4 -4
- package/dist/extractors/split.d.ts +1 -1
- package/dist/gulp.js +6 -7
- package/dist/gulp.mjs +6 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/mangle/index.d.ts +8 -0
- package/dist/{options-5c083791.mjs → options-2a6f14b8.mjs} +254 -49
- package/dist/{options-450d76c2.js → options-3a20e9d4.js} +268 -62
- package/dist/options.d.ts +1 -3
- package/dist/postcss/shared.d.ts +2 -1
- package/dist/{postcss-e3fcf6f1.mjs → postcss-b4e0e1ac.mjs} +8 -4
- package/dist/{postcss-0c103b15.js → postcss-e0e5739b.js} +8 -4
- package/dist/postcss.js +2 -3
- package/dist/postcss.mjs +2 -3
- package/dist/replace.js +8 -12
- package/dist/replace.mjs +9 -13
- package/dist/shared-28d43730.js +148 -0
- package/dist/shared-31001503.mjs +140 -0
- package/dist/types.d.ts +24 -4
- package/dist/utils.d.ts +1 -0
- package/dist/vite.js +8 -9
- package/dist/vite.mjs +7 -8
- package/dist/webpack.js +8 -9
- package/dist/webpack.mjs +7 -8
- package/dist/wxml/shared.d.ts +2 -2
- package/dist/wxml/utils.d.ts +4 -4
- package/package.json +4 -2
- package/dist/mangle/store.d.ts +0 -15
- package/dist/shared-89ea7f77.mjs +0 -332
- package/dist/shared-9744fdd1.js +0 -353
package/README.md
CHANGED
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
|
|
85
85
|
<!-- ## [js文件内容中taiwlindcss类名的精确转化与忽略策略](https://weapp-tw.icebreaker.top/docs/options/comments) -->
|
|
86
86
|
|
|
87
|
-
## [配置项参考](https://weapp-tw.icebreaker.top/docs/
|
|
87
|
+
## [配置项参考](https://weapp-tw.icebreaker.top/docs/api/interfaces/UserDefinedOptions)
|
|
88
88
|
|
|
89
89
|
## [使用tailwindcss任意值(arbitrary values)](https://tailwindcss.com/docs/adding-custom-styles#using-arbitrary-values)
|
|
90
90
|
|
package/dist/cli.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var options = require('./options-
|
|
3
|
+
var options = require('./options-3a20e9d4.js');
|
|
4
4
|
require('micromatch');
|
|
5
5
|
require('@babel/types');
|
|
6
6
|
require('@babel/generator');
|
|
7
7
|
require('@babel/parser');
|
|
8
8
|
require('@babel/traverse');
|
|
9
9
|
require('./replace.js');
|
|
10
|
-
require('./shared-
|
|
11
|
-
require('tailwindcss-mangle-shared');
|
|
10
|
+
require('./shared-28d43730.js');
|
|
12
11
|
require('postcss');
|
|
13
|
-
require('./postcss-
|
|
12
|
+
require('./postcss-e0e5739b.js');
|
|
14
13
|
require('postcss-selector-parser');
|
|
15
14
|
require('@csstools/postcss-is-pseudo-class');
|
|
16
15
|
require('node:path');
|
|
17
16
|
require('node:fs');
|
|
18
17
|
require('semver');
|
|
19
18
|
require('tailwindcss-patch');
|
|
19
|
+
require('tailwindcss-mangle-shared');
|
|
20
20
|
|
|
21
21
|
const args = process.argv.slice(2);
|
|
22
22
|
if (args[0] === 'patch') {
|
package/dist/cli.mjs
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { g as getOptions, c as createPatch } from './options-
|
|
1
|
+
import { g as getOptions, c as createPatch } from './options-2a6f14b8.mjs';
|
|
2
2
|
import 'micromatch';
|
|
3
3
|
import '@babel/types';
|
|
4
4
|
import '@babel/generator';
|
|
5
5
|
import '@babel/parser';
|
|
6
6
|
import '@babel/traverse';
|
|
7
7
|
import './replace.mjs';
|
|
8
|
-
import './shared-
|
|
9
|
-
import 'tailwindcss-mangle-shared';
|
|
8
|
+
import './shared-31001503.mjs';
|
|
10
9
|
import 'postcss';
|
|
11
|
-
import './postcss-
|
|
10
|
+
import './postcss-b4e0e1ac.mjs';
|
|
12
11
|
import 'postcss-selector-parser';
|
|
13
12
|
import '@csstools/postcss-is-pseudo-class';
|
|
14
13
|
import 'node:path';
|
|
15
14
|
import 'node:fs';
|
|
16
15
|
import 'semver';
|
|
17
16
|
import 'tailwindcss-patch';
|
|
17
|
+
import 'tailwindcss-mangle-shared';
|
|
18
18
|
|
|
19
19
|
const args = process.argv.slice(2);
|
|
20
20
|
if (args[0] === 'patch') {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const validateFilterRE: RegExp;
|
|
2
2
|
export declare function isValidSelector(selector?: string): selector is string;
|
|
3
|
-
export declare const splitCode: (code: string) => string[];
|
|
3
|
+
export declare const splitCode: (code: string, allowDoubleQuotes?: boolean) => string[];
|
package/dist/gulp.js
CHANGED
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var stream = require('node:stream');
|
|
6
|
-
var options = require('./options-
|
|
7
|
-
var shared = require('./shared-9744fdd1.js');
|
|
6
|
+
var options = require('./options-3a20e9d4.js');
|
|
8
7
|
require('micromatch');
|
|
9
8
|
require('@babel/types');
|
|
10
9
|
require('@babel/generator');
|
|
11
10
|
require('@babel/parser');
|
|
12
11
|
require('@babel/traverse');
|
|
13
12
|
require('./replace.js');
|
|
13
|
+
require('./shared-28d43730.js');
|
|
14
14
|
require('postcss');
|
|
15
|
-
require('./postcss-
|
|
15
|
+
require('./postcss-e0e5739b.js');
|
|
16
16
|
require('postcss-selector-parser');
|
|
17
17
|
require('@csstools/postcss-is-pseudo-class');
|
|
18
18
|
require('node:path');
|
|
@@ -30,17 +30,16 @@ function createPlugins(options$1 = {}) {
|
|
|
30
30
|
if (options$1.customReplaceDictionary === undefined) {
|
|
31
31
|
options$1.customReplaceDictionary = 'simple';
|
|
32
32
|
}
|
|
33
|
-
const opts = options.getOptions(options$1
|
|
34
|
-
const { templeteHandler, styleHandler, patch, jsHandler,
|
|
33
|
+
const opts = options.getOptions(options$1);
|
|
34
|
+
const { templeteHandler, styleHandler, patch, jsHandler, setMangleRuntimeSet } = opts;
|
|
35
35
|
let set = new Set();
|
|
36
36
|
patch === null || patch === void 0 ? void 0 : patch();
|
|
37
|
-
shared.initStore(mangle);
|
|
38
37
|
const twPatcher = options.createTailwindcssPatcher();
|
|
39
38
|
function transformWxss() {
|
|
40
39
|
const transformStream = new Transform({ objectMode: true });
|
|
41
40
|
transformStream._transform = function (file, encoding, callback) {
|
|
42
41
|
set = twPatcher.getClassSet();
|
|
43
|
-
|
|
42
|
+
setMangleRuntimeSet(set);
|
|
44
43
|
const error = null;
|
|
45
44
|
if (file.contents) {
|
|
46
45
|
const code = styleHandler(file.contents.toString(), {
|
package/dist/gulp.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import stream from 'node:stream';
|
|
2
|
-
import { g as getOptions, a as createTailwindcssPatcher } from './options-
|
|
3
|
-
import { c as initStore, d as setRuntimeSet } from './shared-89ea7f77.mjs';
|
|
2
|
+
import { g as getOptions, a as createTailwindcssPatcher } from './options-2a6f14b8.mjs';
|
|
4
3
|
import 'micromatch';
|
|
5
4
|
import '@babel/types';
|
|
6
5
|
import '@babel/generator';
|
|
7
6
|
import '@babel/parser';
|
|
8
7
|
import '@babel/traverse';
|
|
9
8
|
import './replace.mjs';
|
|
9
|
+
import './shared-31001503.mjs';
|
|
10
10
|
import 'postcss';
|
|
11
|
-
import './postcss-
|
|
11
|
+
import './postcss-b4e0e1ac.mjs';
|
|
12
12
|
import 'postcss-selector-parser';
|
|
13
13
|
import '@csstools/postcss-is-pseudo-class';
|
|
14
14
|
import 'node:path';
|
|
@@ -22,17 +22,16 @@ function createPlugins(options = {}) {
|
|
|
22
22
|
if (options.customReplaceDictionary === undefined) {
|
|
23
23
|
options.customReplaceDictionary = 'simple';
|
|
24
24
|
}
|
|
25
|
-
const opts = getOptions(options
|
|
26
|
-
const { templeteHandler, styleHandler, patch, jsHandler,
|
|
25
|
+
const opts = getOptions(options);
|
|
26
|
+
const { templeteHandler, styleHandler, patch, jsHandler, setMangleRuntimeSet } = opts;
|
|
27
27
|
let set = new Set();
|
|
28
28
|
patch === null || patch === void 0 ? void 0 : patch();
|
|
29
|
-
initStore(mangle);
|
|
30
29
|
const twPatcher = createTailwindcssPatcher();
|
|
31
30
|
function transformWxss() {
|
|
32
31
|
const transformStream = new Transform({ objectMode: true });
|
|
33
32
|
transformStream._transform = function (file, encoding, callback) {
|
|
34
33
|
set = twPatcher.getClassSet();
|
|
35
|
-
|
|
34
|
+
setMangleRuntimeSet(set);
|
|
36
35
|
const error = null;
|
|
37
36
|
if (file.contents) {
|
|
38
37
|
const code = styleHandler(file.contents.toString(), {
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -5,23 +5,23 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var webpack = require('./webpack.js');
|
|
6
6
|
var vite = require('./vite.js');
|
|
7
7
|
var gulp = require('./gulp.js');
|
|
8
|
-
require('./options-
|
|
8
|
+
require('./options-3a20e9d4.js');
|
|
9
9
|
require('micromatch');
|
|
10
10
|
require('@babel/types');
|
|
11
11
|
require('@babel/generator');
|
|
12
12
|
require('@babel/parser');
|
|
13
13
|
require('@babel/traverse');
|
|
14
14
|
require('./replace.js');
|
|
15
|
-
require('./shared-
|
|
16
|
-
require('tailwindcss-mangle-shared');
|
|
15
|
+
require('./shared-28d43730.js');
|
|
17
16
|
require('postcss');
|
|
18
|
-
require('./postcss-
|
|
17
|
+
require('./postcss-e0e5739b.js');
|
|
19
18
|
require('postcss-selector-parser');
|
|
20
19
|
require('@csstools/postcss-is-pseudo-class');
|
|
21
20
|
require('node:path');
|
|
22
21
|
require('node:fs');
|
|
23
22
|
require('semver');
|
|
24
23
|
require('tailwindcss-patch');
|
|
24
|
+
require('tailwindcss-mangle-shared');
|
|
25
25
|
require('node:stream');
|
|
26
26
|
|
|
27
27
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
export { UnifiedWebpackPluginV5 } from './webpack.mjs';
|
|
2
2
|
export { UnifiedViteWeappTailwindcssPlugin } from './vite.mjs';
|
|
3
3
|
export { createPlugins } from './gulp.mjs';
|
|
4
|
-
import './options-
|
|
4
|
+
import './options-2a6f14b8.mjs';
|
|
5
5
|
import 'micromatch';
|
|
6
6
|
import '@babel/types';
|
|
7
7
|
import '@babel/generator';
|
|
8
8
|
import '@babel/parser';
|
|
9
9
|
import '@babel/traverse';
|
|
10
10
|
import './replace.mjs';
|
|
11
|
-
import './shared-
|
|
12
|
-
import 'tailwindcss-mangle-shared';
|
|
11
|
+
import './shared-31001503.mjs';
|
|
13
12
|
import 'postcss';
|
|
14
|
-
import './postcss-
|
|
13
|
+
import './postcss-b4e0e1ac.mjs';
|
|
15
14
|
import 'postcss-selector-parser';
|
|
16
15
|
import '@csstools/postcss-is-pseudo-class';
|
|
17
16
|
import 'node:path';
|
|
18
17
|
import 'node:fs';
|
|
19
18
|
import 'semver';
|
|
20
19
|
import 'tailwindcss-patch';
|
|
20
|
+
import 'tailwindcss-mangle-shared';
|
|
21
21
|
import 'node:stream';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { UserDefinedOptions, IMangleScopeContext } from "../types";
|
|
2
|
+
export declare const defaultMangleContext: IMangleScopeContext;
|
|
3
|
+
export declare function useMangleStore(): {
|
|
4
|
+
mangleContext: IMangleScopeContext;
|
|
5
|
+
resetMangle: () => IMangleScopeContext;
|
|
6
|
+
initMangle: (options: UserDefinedOptions['mangle']) => void;
|
|
7
|
+
setMangleRuntimeSet: (runtimeSet: Set<string>) => void;
|
|
8
|
+
};
|
|
@@ -4,14 +4,15 @@ 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 {
|
|
7
|
+
import { S as SimpleMappingChars2String, M as MappingChars2String } from './shared-31001503.mjs';
|
|
8
8
|
import postcss from 'postcss';
|
|
9
|
-
import { p as postcssWeappTailwindcss } from './postcss-
|
|
9
|
+
import { p as postcssWeappTailwindcss } from './postcss-b4e0e1ac.mjs';
|
|
10
10
|
import postcssIsPseudoClass from '@csstools/postcss-is-pseudo-class';
|
|
11
11
|
import path from 'node:path';
|
|
12
12
|
import fs from 'node:fs';
|
|
13
13
|
import { gte } from 'semver';
|
|
14
14
|
import { monkeyPatchForExposingContext, requireResolve, TailwindcssPatcher } from 'tailwindcss-patch';
|
|
15
|
+
import { ClassGenerator, defaultMangleClassFilter } from 'tailwindcss-mangle-shared';
|
|
15
16
|
|
|
16
17
|
function isObject(value) {
|
|
17
18
|
return value !== null && typeof value === "object";
|
|
@@ -55,12 +56,152 @@ function createDefu(merger) {
|
|
|
55
56
|
}
|
|
56
57
|
const defu = createDefu();
|
|
57
58
|
|
|
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 } = 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)) {
|
|
96
|
+
return 'js';
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return 'other';
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return groupedEntries;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function escapeStringRegexp(str) {
|
|
106
|
+
if (typeof str !== 'string') {
|
|
107
|
+
throw new TypeError('Expected a string');
|
|
108
|
+
}
|
|
109
|
+
return str.replaceAll(/[$()*+.?[\\\]^{|}]/g, '\\$&').replaceAll('-', '\\x2d');
|
|
110
|
+
}
|
|
111
|
+
const templateClassExactRegexp = /(?<=^|\s)(?:hover-)?class=(?:["']\W+\s*\w+\()?["']([^"]+)["']/gs;
|
|
112
|
+
const tagWithEitherClassAndHoverClassRegexp = /<[a-z][a-z-]*[a-z]*\s+[^>]*?(?:hover-)?clas{2}="[^"]*"[^>]*?\/?>/g;
|
|
113
|
+
function handleRegexp(reg) {
|
|
114
|
+
return `(?:${reg.source})`;
|
|
115
|
+
}
|
|
116
|
+
function getSourceString(input) {
|
|
117
|
+
let result;
|
|
118
|
+
if (typeof input === 'string') {
|
|
119
|
+
result = input;
|
|
120
|
+
}
|
|
121
|
+
else if (isRegexp(input)) {
|
|
122
|
+
result = input.source;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
result = input.toString();
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
function makePattern(arr) {
|
|
130
|
+
let pattern = '';
|
|
131
|
+
if (Array.isArray(arr)) {
|
|
132
|
+
pattern = arr
|
|
133
|
+
.reduce((acc, cur) => {
|
|
134
|
+
if (typeof cur === 'string') {
|
|
135
|
+
acc.push(cur);
|
|
136
|
+
}
|
|
137
|
+
else if (isRegexp(cur)) {
|
|
138
|
+
acc.push(handleRegexp(cur));
|
|
139
|
+
}
|
|
140
|
+
return acc;
|
|
141
|
+
}, [])
|
|
142
|
+
.join('|');
|
|
143
|
+
}
|
|
144
|
+
else if (typeof arr === 'string') {
|
|
145
|
+
pattern = arr;
|
|
146
|
+
}
|
|
147
|
+
else if (isRegexp(arr)) {
|
|
148
|
+
pattern = handleRegexp(arr);
|
|
149
|
+
}
|
|
150
|
+
return pattern;
|
|
151
|
+
}
|
|
152
|
+
function createTempleteHandlerMatchRegexp(tag, attrs, options = {}) {
|
|
153
|
+
const { exact = true } = options;
|
|
154
|
+
const prefix = exact ? '(?<=^|\\s)' : '';
|
|
155
|
+
const pattern = makePattern(attrs);
|
|
156
|
+
let tagPattern = getSourceString(tag);
|
|
157
|
+
if (tagPattern === '*') {
|
|
158
|
+
tagPattern = '[a-z][-a-z]*[a-z]*';
|
|
159
|
+
}
|
|
160
|
+
const source = `<(${tagPattern})\\s+[^>]*?(?:${prefix}(${pattern})="(?:[^"]*)")[^>]*?\\/?>`;
|
|
161
|
+
return new RegExp(source, 'g');
|
|
162
|
+
}
|
|
163
|
+
function createTemplateClassRegexp(attrs, options = {}) {
|
|
164
|
+
const { exact = true } = options;
|
|
165
|
+
const prefix = exact ? '(?<=^|\\s)' : '';
|
|
166
|
+
const pattern = makePattern(attrs);
|
|
167
|
+
const source = `(?:${prefix}${pattern})=(?:["']\\W+\\s*(?:\\w+)\\()?["']([^"]+)['"]`;
|
|
168
|
+
return new RegExp(source, 'gs');
|
|
169
|
+
}
|
|
170
|
+
function makeCustomAttributes(entries) {
|
|
171
|
+
if (Array.isArray(entries)) {
|
|
172
|
+
return entries.map(([k, v]) => {
|
|
173
|
+
return {
|
|
174
|
+
tagRegexp: createTempleteHandlerMatchRegexp(k, v),
|
|
175
|
+
attrRegexp: createTemplateClassRegexp(v),
|
|
176
|
+
tag: getSourceString(k),
|
|
177
|
+
attrs: v
|
|
178
|
+
};
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const variableRegExp = /{{(.*?)}}/gs;
|
|
183
|
+
function variableMatch(original) {
|
|
184
|
+
return variableRegExp.exec(original);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const validateFilterRE = /[\w%-?\u00A0-\uFFFF-]/;
|
|
188
|
+
function isValidSelector(selector = '') {
|
|
189
|
+
return validateFilterRE.test(selector);
|
|
190
|
+
}
|
|
191
|
+
const splitCode = (code, allowDoubleQuotes = false) => {
|
|
192
|
+
const splitter = allowDoubleQuotes ? /\s+/ : /\s+|"/;
|
|
193
|
+
return code.split(splitter).filter((element) => isValidSelector(element));
|
|
194
|
+
};
|
|
195
|
+
|
|
58
196
|
const isProd = () => process.env.NODE_ENV === 'production';
|
|
59
197
|
|
|
60
198
|
function handleValue(str, node, options) {
|
|
199
|
+
var _a;
|
|
61
200
|
const set = options.classNameSet;
|
|
62
201
|
const escapeMap = options.escapeMap;
|
|
63
|
-
const
|
|
202
|
+
const allowDoubleQuotes = (_a = options.arbitraryValues) === null || _a === void 0 ? void 0 : _a.allowDoubleQuotes;
|
|
203
|
+
const ctx = options.mangleContext;
|
|
204
|
+
const arr = splitCode(str, allowDoubleQuotes);
|
|
64
205
|
let rawStr = str;
|
|
65
206
|
for (const v of arr) {
|
|
66
207
|
if (set.has(v)) {
|
|
@@ -69,8 +210,9 @@ function handleValue(str, node, options) {
|
|
|
69
210
|
ignoreFlag = node.leadingComments.findIndex((x) => x.value.includes('weapp-tw') && x.value.includes('ignore')) > -1;
|
|
70
211
|
}
|
|
71
212
|
if (!ignoreFlag) {
|
|
72
|
-
|
|
73
|
-
|
|
213
|
+
if (ctx) {
|
|
214
|
+
rawStr = ctx.jsHandler(rawStr);
|
|
215
|
+
}
|
|
74
216
|
rawStr = rawStr.replaceAll(new RegExp(escapeStringRegexp(v), 'g'), replaceWxml(v, {
|
|
75
217
|
escapeMap
|
|
76
218
|
}));
|
|
@@ -116,11 +258,14 @@ function jsHandler(rawSource, options) {
|
|
|
116
258
|
});
|
|
117
259
|
}
|
|
118
260
|
function createjsHandler(options) {
|
|
261
|
+
const { mangleContext, arbitraryValues, minifiedJs, escapeMap } = options;
|
|
119
262
|
return (rawSource, set) => {
|
|
120
263
|
return jsHandler(rawSource, {
|
|
121
264
|
classNameSet: set,
|
|
122
|
-
minifiedJs
|
|
123
|
-
escapeMap
|
|
265
|
+
minifiedJs,
|
|
266
|
+
escapeMap,
|
|
267
|
+
arbitraryValues,
|
|
268
|
+
mangleContext
|
|
124
269
|
});
|
|
125
270
|
};
|
|
126
271
|
}
|
|
@@ -191,7 +336,10 @@ const defaultOptions = {
|
|
|
191
336
|
overwrite: true
|
|
192
337
|
}
|
|
193
338
|
},
|
|
194
|
-
appType: undefined
|
|
339
|
+
appType: undefined,
|
|
340
|
+
arbitraryValues: {
|
|
341
|
+
allowDoubleQuotes: false
|
|
342
|
+
}
|
|
195
343
|
};
|
|
196
344
|
|
|
197
345
|
function generateCode(match, options = {}) {
|
|
@@ -246,7 +394,8 @@ function templeteReplacer(original, options = {}) {
|
|
|
246
394
|
const before = original.slice(p, m.start);
|
|
247
395
|
resultArray.push(replaceWxml(before, {
|
|
248
396
|
keepEOL: true,
|
|
249
|
-
escapeMap: options.escapeMap
|
|
397
|
+
escapeMap: options.escapeMap,
|
|
398
|
+
mangleContext: options.mangleContext
|
|
250
399
|
}));
|
|
251
400
|
p = m.start;
|
|
252
401
|
if (m.raw.trim().length > 0) {
|
|
@@ -263,7 +412,8 @@ function templeteReplacer(original, options = {}) {
|
|
|
263
412
|
const after = original.slice(m.end);
|
|
264
413
|
resultArray.push(replaceWxml(after, {
|
|
265
414
|
keepEOL: true,
|
|
266
|
-
escapeMap: options.escapeMap
|
|
415
|
+
escapeMap: options.escapeMap,
|
|
416
|
+
mangleContext: options.mangleContext
|
|
267
417
|
}));
|
|
268
418
|
}
|
|
269
419
|
}
|
|
@@ -275,7 +425,8 @@ function templeteReplacer(original, options = {}) {
|
|
|
275
425
|
else {
|
|
276
426
|
return replaceWxml(original, {
|
|
277
427
|
keepEOL: false,
|
|
278
|
-
escapeMap: options.escapeMap
|
|
428
|
+
escapeMap: options.escapeMap,
|
|
429
|
+
mangleContext: options.mangleContext
|
|
279
430
|
});
|
|
280
431
|
}
|
|
281
432
|
}
|
|
@@ -453,6 +604,72 @@ function createTailwindcssPatcher() {
|
|
|
453
604
|
});
|
|
454
605
|
}
|
|
455
606
|
|
|
607
|
+
function getSelf(x) {
|
|
608
|
+
return x;
|
|
609
|
+
}
|
|
610
|
+
const defaultMangleContext = {
|
|
611
|
+
rawOptions: false,
|
|
612
|
+
runtimeSet: new Set(),
|
|
613
|
+
classGenerator: new ClassGenerator(),
|
|
614
|
+
filter: defaultMangleClassFilter,
|
|
615
|
+
cssHandler: getSelf,
|
|
616
|
+
jsHandler: getSelf,
|
|
617
|
+
wxmlHandler: getSelf
|
|
618
|
+
};
|
|
619
|
+
function useMangleStore() {
|
|
620
|
+
const ctx = Object.assign({}, defaultMangleContext);
|
|
621
|
+
function resetMangle() {
|
|
622
|
+
return Object.assign(ctx, defaultMangleContext);
|
|
623
|
+
}
|
|
624
|
+
function handleValue(rawSource) {
|
|
625
|
+
const arr = splitCode(rawSource);
|
|
626
|
+
for (const x of arr) {
|
|
627
|
+
if (ctx.runtimeSet.has(x)) {
|
|
628
|
+
rawSource = rawSource.replaceAll(new RegExp(escapeStringRegexp(x), 'g'), ctx.classGenerator.generateClassName(x).name);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return rawSource;
|
|
632
|
+
}
|
|
633
|
+
function initMangle(options) {
|
|
634
|
+
var _a;
|
|
635
|
+
ctx.rawOptions = options;
|
|
636
|
+
if (options) {
|
|
637
|
+
if (options === true) {
|
|
638
|
+
options = {
|
|
639
|
+
classGenerator: {},
|
|
640
|
+
mangleClassFilter: defaultMangleClassFilter
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
ctx.classGenerator = new ClassGenerator(options.classGenerator);
|
|
644
|
+
ctx.filter = (_a = options.mangleClassFilter) !== null && _a !== void 0 ? _a : defaultMangleClassFilter;
|
|
645
|
+
ctx.jsHandler = (rawSource) => {
|
|
646
|
+
return handleValue(rawSource);
|
|
647
|
+
};
|
|
648
|
+
ctx.cssHandler = (rawSource) => {
|
|
649
|
+
return handleValue(rawSource);
|
|
650
|
+
};
|
|
651
|
+
ctx.wxmlHandler = (rawSource) => {
|
|
652
|
+
return handleValue(rawSource);
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
function setMangleRuntimeSet(runtimeSet) {
|
|
657
|
+
const newSet = new Set();
|
|
658
|
+
for (const c of runtimeSet) {
|
|
659
|
+
if (ctx.filter(c)) {
|
|
660
|
+
newSet.add(c);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
ctx.runtimeSet = newSet;
|
|
664
|
+
}
|
|
665
|
+
return {
|
|
666
|
+
mangleContext: ctx,
|
|
667
|
+
resetMangle,
|
|
668
|
+
initMangle,
|
|
669
|
+
setMangleRuntimeSet
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
|
|
456
673
|
function createGlobMatcher(pattern) {
|
|
457
674
|
return function (file) {
|
|
458
675
|
return isMatch(file, pattern);
|
|
@@ -463,18 +680,7 @@ function normalizeMatcher(options, key) {
|
|
|
463
680
|
options[key] = createGlobMatcher(options[key]);
|
|
464
681
|
}
|
|
465
682
|
}
|
|
466
|
-
function getOptions(options = {}
|
|
467
|
-
const registerModules = modules.reduce((acc, cur) => {
|
|
468
|
-
if (acc[cur] !== undefined) {
|
|
469
|
-
acc[cur] = true;
|
|
470
|
-
}
|
|
471
|
-
return acc;
|
|
472
|
-
}, {
|
|
473
|
-
templete: false,
|
|
474
|
-
style: false,
|
|
475
|
-
patch: false,
|
|
476
|
-
js: false
|
|
477
|
-
});
|
|
683
|
+
function getOptions(options = {}) {
|
|
478
684
|
if (options.supportCustomLengthUnitsPatch === true) {
|
|
479
685
|
options.supportCustomLengthUnitsPatch = undefined;
|
|
480
686
|
}
|
|
@@ -491,36 +697,35 @@ function getOptions(options = {}, modules = ['style', 'templete', 'patch', 'js']
|
|
|
491
697
|
const result = defu(options, defaultOptions, {
|
|
492
698
|
minifiedJs: isProd()
|
|
493
699
|
});
|
|
494
|
-
const { cssPreflight, customRuleCallback, cssPreflightRange, replaceUniversalSelectorWith, customAttributes, customReplaceDictionary, supportCustomLengthUnitsPatch } = result;
|
|
700
|
+
const { cssPreflight, customRuleCallback, cssPreflightRange, replaceUniversalSelectorWith, customAttributes, customReplaceDictionary, supportCustomLengthUnitsPatch, arbitraryValues } = result;
|
|
495
701
|
result.escapeMap = customReplaceDictionary;
|
|
496
702
|
const cssInjectPreflight = createInjectPreflight(cssPreflight);
|
|
497
703
|
const customAttributesEntities = isMap(options.customAttributes) ? [...options.customAttributes.entries()] : Object.entries(customAttributes);
|
|
498
704
|
const { escapeMap, minifiedJs } = result;
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
}
|
|
705
|
+
const { initMangle, mangleContext, setMangleRuntimeSet } = useMangleStore();
|
|
706
|
+
initMangle(options.mangle);
|
|
707
|
+
result.templeteHandler = createTempleteHandler({
|
|
708
|
+
customAttributesEntities,
|
|
709
|
+
escapeMap,
|
|
710
|
+
mangleContext,
|
|
711
|
+
});
|
|
712
|
+
result.styleHandler = createStyleHandler({
|
|
713
|
+
cssInjectPreflight,
|
|
714
|
+
customRuleCallback,
|
|
715
|
+
cssPreflightRange,
|
|
716
|
+
replaceUniversalSelectorWith,
|
|
717
|
+
escapeMap,
|
|
718
|
+
mangleContext,
|
|
719
|
+
});
|
|
720
|
+
result.jsHandler = createjsHandler({
|
|
721
|
+
minifiedJs,
|
|
722
|
+
escapeMap,
|
|
723
|
+
mangleContext,
|
|
724
|
+
arbitraryValues
|
|
725
|
+
});
|
|
726
|
+
result.patch = createPatch(supportCustomLengthUnitsPatch);
|
|
727
|
+
result.setMangleRuntimeSet = setMangleRuntimeSet;
|
|
523
728
|
return result;
|
|
524
729
|
}
|
|
525
730
|
|
|
526
|
-
export { createTailwindcssPatcher as a, createPatch as c, getOptions as g };
|
|
731
|
+
export { createTailwindcssPatcher as a, getGroupedEntries as b, createPatch as c, getOptions as g };
|