tailwindcss-patch 8.7.2 → 8.7.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.
- package/dist/{chunk-PL4WB2UD.mjs → chunk-3T6WSV7F.mjs} +1460 -1316
- package/dist/chunk-7JAOSSRO.js +7 -0
- package/dist/{chunk-7WRLTAPZ.js → chunk-EFYAZO6C.js} +1492 -1352
- package/dist/chunk-JHEI2MLC.mjs +10 -0
- package/dist/cli.js +5 -4
- package/dist/cli.mjs +2 -1
- package/dist/dist-EMUBVNNO.mjs +269 -0
- package/dist/dist-NW65QXLC.js +269 -0
- package/dist/index.d.mts +61 -44
- package/dist/index.d.ts +61 -44
- package/dist/index.js +3 -2
- package/dist/index.mjs +2 -1
- package/package.json +2 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/esm_shims.js
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
var getFilename = () => fileURLToPath(import.meta.url);
|
|
5
|
+
var getDirname = () => path.dirname(getFilename());
|
|
6
|
+
var __dirname = /* @__PURE__ */ getDirname();
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
__dirname
|
|
10
|
+
};
|
package/dist/cli.js
CHANGED
|
@@ -2,22 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkEFYAZO6Cjs = require('./chunk-EFYAZO6C.js');
|
|
6
|
+
require('./chunk-7JAOSSRO.js');
|
|
6
7
|
|
|
7
8
|
// src/cli.ts
|
|
8
9
|
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
9
10
|
async function main() {
|
|
10
|
-
const cli =
|
|
11
|
+
const cli = _chunkEFYAZO6Cjs.createTailwindcssPatchCli.call(void 0, );
|
|
11
12
|
cli.help();
|
|
12
13
|
cli.parse(_process2.default.argv, { run: false });
|
|
13
14
|
await cli.runMatchedCommand();
|
|
14
15
|
}
|
|
15
16
|
main().catch((error) => {
|
|
16
|
-
if (error instanceof
|
|
17
|
+
if (error instanceof _chunkEFYAZO6Cjs.ValidateCommandError) {
|
|
17
18
|
_process2.default.exitCode = error.exitCode;
|
|
18
19
|
return;
|
|
19
20
|
}
|
|
20
21
|
const message = error instanceof Error ? error.message : String(error);
|
|
21
|
-
|
|
22
|
+
_chunkEFYAZO6Cjs.logger_default.error(message);
|
|
22
23
|
_process2.default.exitCode = 1;
|
|
23
24
|
});
|
package/dist/cli.mjs
CHANGED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import "./chunk-JHEI2MLC.mjs";
|
|
2
|
+
|
|
3
|
+
// ../shared/dist/index.js
|
|
4
|
+
import process from "process";
|
|
5
|
+
function isPlainObject(value) {
|
|
6
|
+
if (value === null || typeof value !== "object") {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const prototype = Object.getPrototypeOf(value);
|
|
10
|
+
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
if (Symbol.iterator in value) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (Symbol.toStringTag in value) {
|
|
17
|
+
return Object.prototype.toString.call(value) === "[object Module]";
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
22
|
+
if (!isPlainObject(defaults)) {
|
|
23
|
+
return _defu(baseObject, {}, namespace, merger);
|
|
24
|
+
}
|
|
25
|
+
const object = Object.assign({}, defaults);
|
|
26
|
+
for (const key in baseObject) {
|
|
27
|
+
if (key === "__proto__" || key === "constructor") {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const value = baseObject[key];
|
|
31
|
+
if (value === null || value === void 0) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (merger && merger(object, key, value, namespace)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
38
|
+
object[key] = [...value, ...object[key]];
|
|
39
|
+
} else if (isPlainObject(value) && isPlainObject(object[key])) {
|
|
40
|
+
object[key] = _defu(
|
|
41
|
+
value,
|
|
42
|
+
object[key],
|
|
43
|
+
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
44
|
+
merger
|
|
45
|
+
);
|
|
46
|
+
} else {
|
|
47
|
+
object[key] = value;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return object;
|
|
51
|
+
}
|
|
52
|
+
function createDefu(merger) {
|
|
53
|
+
return (...arguments_) => (
|
|
54
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
55
|
+
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
var defu = createDefu();
|
|
59
|
+
var defuFn = createDefu((object, key, currentValue) => {
|
|
60
|
+
if (object[key] !== void 0 && typeof currentValue === "function") {
|
|
61
|
+
object[key] = currentValue(object[key]);
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
var defuArrayFn = createDefu((object, key, currentValue) => {
|
|
66
|
+
if (Array.isArray(object[key]) && typeof currentValue === "function") {
|
|
67
|
+
object[key] = currentValue(object[key]);
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
var defuOverrideArray = createDefu((obj, key, value) => {
|
|
72
|
+
if (Array.isArray(obj[key]) && Array.isArray(value)) {
|
|
73
|
+
obj[key] = value;
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
var preserveClassNames = [
|
|
78
|
+
// https://tailwindcss.com/docs/transition-timing-function start
|
|
79
|
+
// https://github.com/sonofmagic/tailwindcss-mangle/issues/21
|
|
80
|
+
"ease-out",
|
|
81
|
+
"ease-linear",
|
|
82
|
+
"ease-in",
|
|
83
|
+
"ease-in-out"
|
|
84
|
+
// https://tailwindcss.com/docs/transition-timing-function end
|
|
85
|
+
];
|
|
86
|
+
var preserveClassNamesMap = preserveClassNames.reduce((acc, cur) => {
|
|
87
|
+
acc[cur] = true;
|
|
88
|
+
return acc;
|
|
89
|
+
}, {});
|
|
90
|
+
function defaultMangleClassFilter(className) {
|
|
91
|
+
if (preserveClassNamesMap[className]) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
return /[:-]/.test(className);
|
|
95
|
+
}
|
|
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
|
+
bucket.push(item);
|
|
109
|
+
} else {
|
|
110
|
+
result[bucketCategory] = [item];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
var acceptChars = [..."abcdefghijklmnopqrstuvwxyz"];
|
|
116
|
+
function stripEscapeSequence(words) {
|
|
117
|
+
return words.replaceAll("\\", "");
|
|
118
|
+
}
|
|
119
|
+
function isRegexp(value) {
|
|
120
|
+
return Object.prototype.toString.call(value) === "[object RegExp]";
|
|
121
|
+
}
|
|
122
|
+
function isMap(value) {
|
|
123
|
+
return Object.prototype.toString.call(value) === "[object Map]";
|
|
124
|
+
}
|
|
125
|
+
function regExpTest(arr = [], str) {
|
|
126
|
+
if (Array.isArray(arr)) {
|
|
127
|
+
for (const item of arr) {
|
|
128
|
+
if (typeof item === "string") {
|
|
129
|
+
if (item === str) {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
} else if (isRegexp(item)) {
|
|
133
|
+
item.lastIndex = 0;
|
|
134
|
+
if (item.test(str)) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
throw new TypeError("paramater 'arr' should be a Array of Regexp | String !");
|
|
142
|
+
}
|
|
143
|
+
var ClassGenerator = class {
|
|
144
|
+
newClassMap;
|
|
145
|
+
newClassSize;
|
|
146
|
+
context;
|
|
147
|
+
opts;
|
|
148
|
+
classPrefix;
|
|
149
|
+
constructor(opts = {}) {
|
|
150
|
+
this.newClassMap = {};
|
|
151
|
+
this.newClassSize = 0;
|
|
152
|
+
this.context = {};
|
|
153
|
+
this.opts = opts;
|
|
154
|
+
this.classPrefix = opts.classPrefix ?? "tw-";
|
|
155
|
+
}
|
|
156
|
+
defaultClassGenerate() {
|
|
157
|
+
const chars = [];
|
|
158
|
+
let rest = (this.newClassSize - this.newClassSize % acceptChars.length) / acceptChars.length;
|
|
159
|
+
if (rest > 0) {
|
|
160
|
+
while (true) {
|
|
161
|
+
rest -= 1;
|
|
162
|
+
const m = rest % acceptChars.length;
|
|
163
|
+
const c = acceptChars[m];
|
|
164
|
+
chars.push(c);
|
|
165
|
+
rest -= m;
|
|
166
|
+
if (rest === 0) {
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
rest /= acceptChars.length;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const prefixIndex = this.newClassSize % acceptChars.length;
|
|
173
|
+
const newClassName = `${this.classPrefix}${acceptChars[prefixIndex]}${chars.join("")}`;
|
|
174
|
+
return newClassName;
|
|
175
|
+
}
|
|
176
|
+
ignoreClassName(className) {
|
|
177
|
+
return regExpTest(this.opts.ignoreClass, className);
|
|
178
|
+
}
|
|
179
|
+
includeFilePath(filePath) {
|
|
180
|
+
const { include } = this.opts;
|
|
181
|
+
return Array.isArray(include) ? regExpTest(include, filePath) : true;
|
|
182
|
+
}
|
|
183
|
+
excludeFilePath(filePath) {
|
|
184
|
+
const { exclude } = this.opts;
|
|
185
|
+
return Array.isArray(exclude) ? regExpTest(exclude, filePath) : false;
|
|
186
|
+
}
|
|
187
|
+
isFileIncluded(filePath) {
|
|
188
|
+
return this.includeFilePath(filePath) && !this.excludeFilePath(filePath);
|
|
189
|
+
}
|
|
190
|
+
transformCssClass(className) {
|
|
191
|
+
const key = stripEscapeSequence(className);
|
|
192
|
+
const cn = this.newClassMap[key];
|
|
193
|
+
if (cn) {
|
|
194
|
+
return cn.name;
|
|
195
|
+
}
|
|
196
|
+
return className;
|
|
197
|
+
}
|
|
198
|
+
generateClassName(original) {
|
|
199
|
+
const opts = this.opts;
|
|
200
|
+
original = stripEscapeSequence(original);
|
|
201
|
+
const cn = this.newClassMap[original];
|
|
202
|
+
if (cn) {
|
|
203
|
+
return cn;
|
|
204
|
+
}
|
|
205
|
+
let newClassName;
|
|
206
|
+
if (opts.customGenerate && typeof opts.customGenerate === "function") {
|
|
207
|
+
newClassName = opts.customGenerate(original, opts, this.context);
|
|
208
|
+
}
|
|
209
|
+
if (!newClassName) {
|
|
210
|
+
newClassName = this.defaultClassGenerate();
|
|
211
|
+
}
|
|
212
|
+
if (opts.reserveClassName && regExpTest(opts.reserveClassName, newClassName)) {
|
|
213
|
+
if (opts.log) {
|
|
214
|
+
process.stdout.write(`The class name has been reserved. ${newClassName}
|
|
215
|
+
`);
|
|
216
|
+
}
|
|
217
|
+
this.newClassSize++;
|
|
218
|
+
return this.generateClassName(original);
|
|
219
|
+
}
|
|
220
|
+
if (opts.log) {
|
|
221
|
+
process.stdout.write(`Minify class name from ${original} to ${newClassName}
|
|
222
|
+
`);
|
|
223
|
+
}
|
|
224
|
+
const newClass = {
|
|
225
|
+
name: newClassName,
|
|
226
|
+
usedBy: /* @__PURE__ */ new Set()
|
|
227
|
+
};
|
|
228
|
+
this.newClassMap[original] = newClass;
|
|
229
|
+
this.newClassSize++;
|
|
230
|
+
return newClass;
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
function escapeStringRegexp(str) {
|
|
234
|
+
if (typeof str !== "string") {
|
|
235
|
+
throw new TypeError("Expected a string");
|
|
236
|
+
}
|
|
237
|
+
return str.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&").replaceAll("-", "\\x2d");
|
|
238
|
+
}
|
|
239
|
+
function makeRegex(str, options = {
|
|
240
|
+
exact: true
|
|
241
|
+
}) {
|
|
242
|
+
return new RegExp(`(?<=^|[\\s"])${escapeStringRegexp(str)}${options.exact ? '(?=$|[\\s"])' : ""}`, "g");
|
|
243
|
+
}
|
|
244
|
+
var validateFilterRE = /[\w\u00A0-\uFFFF%-?]/;
|
|
245
|
+
function isValidSelector(selector = "") {
|
|
246
|
+
return validateFilterRE.test(selector);
|
|
247
|
+
}
|
|
248
|
+
function splitCode(code, options = { splitQuote: true }) {
|
|
249
|
+
const regex = options.splitQuote ? /[\s"]+/ : /\s+/;
|
|
250
|
+
return code.split(regex).filter((x) => isValidSelector(x));
|
|
251
|
+
}
|
|
252
|
+
export {
|
|
253
|
+
ClassGenerator,
|
|
254
|
+
acceptChars,
|
|
255
|
+
defaultMangleClassFilter,
|
|
256
|
+
defu,
|
|
257
|
+
defuOverrideArray,
|
|
258
|
+
escapeStringRegexp,
|
|
259
|
+
groupBy,
|
|
260
|
+
isMap,
|
|
261
|
+
isRegexp,
|
|
262
|
+
isValidSelector,
|
|
263
|
+
makeRegex,
|
|
264
|
+
preserveClassNames,
|
|
265
|
+
regExpTest,
|
|
266
|
+
splitCode,
|
|
267
|
+
stripEscapeSequence,
|
|
268
|
+
validateFilterRE
|
|
269
|
+
};
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }require('./chunk-7JAOSSRO.js');
|
|
2
|
+
|
|
3
|
+
// ../shared/dist/index.js
|
|
4
|
+
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
5
|
+
function isPlainObject(value) {
|
|
6
|
+
if (value === null || typeof value !== "object") {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const prototype = Object.getPrototypeOf(value);
|
|
10
|
+
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
if (Symbol.iterator in value) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (Symbol.toStringTag in value) {
|
|
17
|
+
return Object.prototype.toString.call(value) === "[object Module]";
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
22
|
+
if (!isPlainObject(defaults)) {
|
|
23
|
+
return _defu(baseObject, {}, namespace, merger);
|
|
24
|
+
}
|
|
25
|
+
const object = Object.assign({}, defaults);
|
|
26
|
+
for (const key in baseObject) {
|
|
27
|
+
if (key === "__proto__" || key === "constructor") {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const value = baseObject[key];
|
|
31
|
+
if (value === null || value === void 0) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (merger && merger(object, key, value, namespace)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
38
|
+
object[key] = [...value, ...object[key]];
|
|
39
|
+
} else if (isPlainObject(value) && isPlainObject(object[key])) {
|
|
40
|
+
object[key] = _defu(
|
|
41
|
+
value,
|
|
42
|
+
object[key],
|
|
43
|
+
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
44
|
+
merger
|
|
45
|
+
);
|
|
46
|
+
} else {
|
|
47
|
+
object[key] = value;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return object;
|
|
51
|
+
}
|
|
52
|
+
function createDefu(merger) {
|
|
53
|
+
return (...arguments_) => (
|
|
54
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
55
|
+
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
var defu = createDefu();
|
|
59
|
+
var defuFn = createDefu((object, key, currentValue) => {
|
|
60
|
+
if (object[key] !== void 0 && typeof currentValue === "function") {
|
|
61
|
+
object[key] = currentValue(object[key]);
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
var defuArrayFn = createDefu((object, key, currentValue) => {
|
|
66
|
+
if (Array.isArray(object[key]) && typeof currentValue === "function") {
|
|
67
|
+
object[key] = currentValue(object[key]);
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
var defuOverrideArray = createDefu((obj, key, value) => {
|
|
72
|
+
if (Array.isArray(obj[key]) && Array.isArray(value)) {
|
|
73
|
+
obj[key] = value;
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
var preserveClassNames = [
|
|
78
|
+
// https://tailwindcss.com/docs/transition-timing-function start
|
|
79
|
+
// https://github.com/sonofmagic/tailwindcss-mangle/issues/21
|
|
80
|
+
"ease-out",
|
|
81
|
+
"ease-linear",
|
|
82
|
+
"ease-in",
|
|
83
|
+
"ease-in-out"
|
|
84
|
+
// https://tailwindcss.com/docs/transition-timing-function end
|
|
85
|
+
];
|
|
86
|
+
var preserveClassNamesMap = preserveClassNames.reduce((acc, cur) => {
|
|
87
|
+
acc[cur] = true;
|
|
88
|
+
return acc;
|
|
89
|
+
}, {});
|
|
90
|
+
function defaultMangleClassFilter(className) {
|
|
91
|
+
if (preserveClassNamesMap[className]) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
return /[:-]/.test(className);
|
|
95
|
+
}
|
|
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
|
+
bucket.push(item);
|
|
109
|
+
} else {
|
|
110
|
+
result[bucketCategory] = [item];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
var acceptChars = [..."abcdefghijklmnopqrstuvwxyz"];
|
|
116
|
+
function stripEscapeSequence(words) {
|
|
117
|
+
return words.replaceAll("\\", "");
|
|
118
|
+
}
|
|
119
|
+
function isRegexp(value) {
|
|
120
|
+
return Object.prototype.toString.call(value) === "[object RegExp]";
|
|
121
|
+
}
|
|
122
|
+
function isMap(value) {
|
|
123
|
+
return Object.prototype.toString.call(value) === "[object Map]";
|
|
124
|
+
}
|
|
125
|
+
function regExpTest(arr = [], str) {
|
|
126
|
+
if (Array.isArray(arr)) {
|
|
127
|
+
for (const item of arr) {
|
|
128
|
+
if (typeof item === "string") {
|
|
129
|
+
if (item === str) {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
} else if (isRegexp(item)) {
|
|
133
|
+
item.lastIndex = 0;
|
|
134
|
+
if (item.test(str)) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
throw new TypeError("paramater 'arr' should be a Array of Regexp | String !");
|
|
142
|
+
}
|
|
143
|
+
var ClassGenerator = class {
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
constructor(opts = {}) {
|
|
150
|
+
this.newClassMap = {};
|
|
151
|
+
this.newClassSize = 0;
|
|
152
|
+
this.context = {};
|
|
153
|
+
this.opts = opts;
|
|
154
|
+
this.classPrefix = _nullishCoalesce(opts.classPrefix, () => ( "tw-"));
|
|
155
|
+
}
|
|
156
|
+
defaultClassGenerate() {
|
|
157
|
+
const chars = [];
|
|
158
|
+
let rest = (this.newClassSize - this.newClassSize % acceptChars.length) / acceptChars.length;
|
|
159
|
+
if (rest > 0) {
|
|
160
|
+
while (true) {
|
|
161
|
+
rest -= 1;
|
|
162
|
+
const m = rest % acceptChars.length;
|
|
163
|
+
const c = acceptChars[m];
|
|
164
|
+
chars.push(c);
|
|
165
|
+
rest -= m;
|
|
166
|
+
if (rest === 0) {
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
rest /= acceptChars.length;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const prefixIndex = this.newClassSize % acceptChars.length;
|
|
173
|
+
const newClassName = `${this.classPrefix}${acceptChars[prefixIndex]}${chars.join("")}`;
|
|
174
|
+
return newClassName;
|
|
175
|
+
}
|
|
176
|
+
ignoreClassName(className) {
|
|
177
|
+
return regExpTest(this.opts.ignoreClass, className);
|
|
178
|
+
}
|
|
179
|
+
includeFilePath(filePath) {
|
|
180
|
+
const { include } = this.opts;
|
|
181
|
+
return Array.isArray(include) ? regExpTest(include, filePath) : true;
|
|
182
|
+
}
|
|
183
|
+
excludeFilePath(filePath) {
|
|
184
|
+
const { exclude } = this.opts;
|
|
185
|
+
return Array.isArray(exclude) ? regExpTest(exclude, filePath) : false;
|
|
186
|
+
}
|
|
187
|
+
isFileIncluded(filePath) {
|
|
188
|
+
return this.includeFilePath(filePath) && !this.excludeFilePath(filePath);
|
|
189
|
+
}
|
|
190
|
+
transformCssClass(className) {
|
|
191
|
+
const key = stripEscapeSequence(className);
|
|
192
|
+
const cn = this.newClassMap[key];
|
|
193
|
+
if (cn) {
|
|
194
|
+
return cn.name;
|
|
195
|
+
}
|
|
196
|
+
return className;
|
|
197
|
+
}
|
|
198
|
+
generateClassName(original) {
|
|
199
|
+
const opts = this.opts;
|
|
200
|
+
original = stripEscapeSequence(original);
|
|
201
|
+
const cn = this.newClassMap[original];
|
|
202
|
+
if (cn) {
|
|
203
|
+
return cn;
|
|
204
|
+
}
|
|
205
|
+
let newClassName;
|
|
206
|
+
if (opts.customGenerate && typeof opts.customGenerate === "function") {
|
|
207
|
+
newClassName = opts.customGenerate(original, opts, this.context);
|
|
208
|
+
}
|
|
209
|
+
if (!newClassName) {
|
|
210
|
+
newClassName = this.defaultClassGenerate();
|
|
211
|
+
}
|
|
212
|
+
if (opts.reserveClassName && regExpTest(opts.reserveClassName, newClassName)) {
|
|
213
|
+
if (opts.log) {
|
|
214
|
+
_process2.default.stdout.write(`The class name has been reserved. ${newClassName}
|
|
215
|
+
`);
|
|
216
|
+
}
|
|
217
|
+
this.newClassSize++;
|
|
218
|
+
return this.generateClassName(original);
|
|
219
|
+
}
|
|
220
|
+
if (opts.log) {
|
|
221
|
+
_process2.default.stdout.write(`Minify class name from ${original} to ${newClassName}
|
|
222
|
+
`);
|
|
223
|
+
}
|
|
224
|
+
const newClass = {
|
|
225
|
+
name: newClassName,
|
|
226
|
+
usedBy: /* @__PURE__ */ new Set()
|
|
227
|
+
};
|
|
228
|
+
this.newClassMap[original] = newClass;
|
|
229
|
+
this.newClassSize++;
|
|
230
|
+
return newClass;
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
function escapeStringRegexp(str) {
|
|
234
|
+
if (typeof str !== "string") {
|
|
235
|
+
throw new TypeError("Expected a string");
|
|
236
|
+
}
|
|
237
|
+
return str.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&").replaceAll("-", "\\x2d");
|
|
238
|
+
}
|
|
239
|
+
function makeRegex(str, options = {
|
|
240
|
+
exact: true
|
|
241
|
+
}) {
|
|
242
|
+
return new RegExp(`(?<=^|[\\s"])${escapeStringRegexp(str)}${options.exact ? '(?=$|[\\s"])' : ""}`, "g");
|
|
243
|
+
}
|
|
244
|
+
var validateFilterRE = /[\w\u00A0-\uFFFF%-?]/;
|
|
245
|
+
function isValidSelector(selector = "") {
|
|
246
|
+
return validateFilterRE.test(selector);
|
|
247
|
+
}
|
|
248
|
+
function splitCode(code, options = { splitQuote: true }) {
|
|
249
|
+
const regex = options.splitQuote ? /[\s"]+/ : /\s+/;
|
|
250
|
+
return code.split(regex).filter((x) => isValidSelector(x));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
exports.ClassGenerator = ClassGenerator; exports.acceptChars = acceptChars; exports.defaultMangleClassFilter = defaultMangleClassFilter; exports.defu = defu; exports.defuOverrideArray = defuOverrideArray; exports.escapeStringRegexp = escapeStringRegexp; exports.groupBy = groupBy; exports.isMap = isMap; exports.isRegexp = isRegexp; exports.isValidSelector = isValidSelector; exports.makeRegex = makeRegex; exports.preserveClassNames = preserveClassNames; exports.regExpTest = regExpTest; exports.splitCode = splitCode; exports.stripEscapeSequence = stripEscapeSequence; exports.validateFilterRE = validateFilterRE;
|