unplugin-tailwindcss-mangle 0.0.0 → 0.0.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/dist/index.mjs ADDED
@@ -0,0 +1,488 @@
1
+ import { createUnplugin } from 'unplugin';
2
+ import { getClassCacheSet } from 'tailwindcss-patch';
3
+ import { html, defaultTreeAdapter, parse, serialize } from 'parse5';
4
+ import _generate from '@babel/generator';
5
+ import { parse as parse$1 } from '@babel/parser';
6
+ import _traverse from '@babel/traverse';
7
+ import postcss from 'postcss';
8
+ import parser from 'postcss-selector-parser';
9
+
10
+ const pluginName = 'unplugin-tailwindcss-mangle';
11
+
12
+ function groupBy(arr, cb) {
13
+ if (!Array.isArray(arr)) {
14
+ throw new Error('expected an array for first argument');
15
+ }
16
+ if (typeof cb !== 'function') {
17
+ throw new Error('expected a function for second argument');
18
+ }
19
+ const result = {};
20
+ for (let i = 0; i < arr.length; i++) {
21
+ const item = arr[i];
22
+ const bucketCategory = cb(item);
23
+ const bucket = result[bucketCategory];
24
+ if (!Array.isArray(bucket)) {
25
+ result[bucketCategory] = [item];
26
+ }
27
+ else {
28
+ result[bucketCategory].push(item);
29
+ }
30
+ }
31
+ return result;
32
+ }
33
+ function getGroupedEntries(entries, options = {
34
+ cssMatcher(file) {
35
+ return /\.css$/.test(file);
36
+ },
37
+ htmlMatcher(file) {
38
+ return /\.html?$/.test(file);
39
+ },
40
+ jsMatcher(file) {
41
+ return /\.js$/.test(file);
42
+ }
43
+ }) {
44
+ const { cssMatcher, htmlMatcher, jsMatcher } = options;
45
+ const groupedEntries = groupBy(entries, ([file]) => {
46
+ if (cssMatcher(file)) {
47
+ return 'css';
48
+ }
49
+ else if (htmlMatcher(file)) {
50
+ return 'html';
51
+ }
52
+ else if (jsMatcher(file)) {
53
+ return 'js';
54
+ }
55
+ else {
56
+ return 'other';
57
+ }
58
+ });
59
+ return groupedEntries;
60
+ }
61
+ const acceptChars = 'abcdefghijklmnopqrstuvwxyz'.split('');
62
+ function stripEscapeSequence(words) {
63
+ return words.replace(/\\/g, '');
64
+ }
65
+ function isRegexp(value) {
66
+ return Object.prototype.toString.call(value) === '[object RegExp]';
67
+ }
68
+ function regExpTest(arr = [], str) {
69
+ if (Array.isArray(arr)) {
70
+ for (let i = 0; i < arr.length; i++) {
71
+ const item = arr[i];
72
+ if (typeof item === 'string') {
73
+ if (item === str) {
74
+ return true;
75
+ }
76
+ }
77
+ else if (isRegexp(item)) {
78
+ item.lastIndex = 0;
79
+ if (item.test(str)) {
80
+ return true;
81
+ }
82
+ }
83
+ }
84
+ return false;
85
+ }
86
+ throw new TypeError("paramater 'arr' should be a Array of Regexp | String !");
87
+ }
88
+ function escapeStringRegexp(str) {
89
+ if (typeof str !== 'string') {
90
+ throw new TypeError('Expected a string');
91
+ }
92
+ return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
93
+ }
94
+
95
+ class ClassGenerator {
96
+ constructor(opts = {}) {
97
+ var _a;
98
+ this.newClassMap = {};
99
+ this.newClassSize = 0;
100
+ this.context = {};
101
+ this.opts = opts;
102
+ this.classPrefix = (_a = opts.classPrefix) !== null && _a !== void 0 ? _a : 'tw-';
103
+ }
104
+ defaultClassGenerator() {
105
+ const chars = [];
106
+ let rest = (this.newClassSize - (this.newClassSize % acceptChars.length)) / acceptChars.length;
107
+ if (rest > 0) {
108
+ while (true) {
109
+ rest -= 1;
110
+ const m = rest % acceptChars.length;
111
+ const c = acceptChars[m];
112
+ chars.push(c);
113
+ rest -= m;
114
+ if (rest === 0) {
115
+ break;
116
+ }
117
+ rest /= acceptChars.length;
118
+ }
119
+ }
120
+ const prefixIndex = this.newClassSize % acceptChars.length;
121
+ const newClassName = `${this.classPrefix}${acceptChars[prefixIndex]}${chars.join('')}`;
122
+ return newClassName;
123
+ }
124
+ ignoreClassName(className) {
125
+ return regExpTest(this.opts.ignoreClass, className);
126
+ }
127
+ includeFilePath(filePath) {
128
+ const { include } = this.opts;
129
+ if (Array.isArray(include)) {
130
+ return regExpTest(include, filePath);
131
+ }
132
+ else {
133
+ return true;
134
+ }
135
+ }
136
+ excludeFilePath(filePath) {
137
+ const { exclude } = this.opts;
138
+ if (Array.isArray(exclude)) {
139
+ return regExpTest(exclude, filePath);
140
+ }
141
+ else {
142
+ return false;
143
+ }
144
+ }
145
+ isFileIncluded(filePath) {
146
+ return this.includeFilePath(filePath) && !this.excludeFilePath(filePath);
147
+ }
148
+ transformCssClass(className) {
149
+ const key = stripEscapeSequence(className);
150
+ const cn = this.newClassMap[key];
151
+ if (cn)
152
+ return cn.name;
153
+ return className;
154
+ }
155
+ generateClassName(original) {
156
+ const opts = this.opts;
157
+ original = stripEscapeSequence(original);
158
+ const cn = this.newClassMap[original];
159
+ if (cn)
160
+ return cn;
161
+ let newClassName;
162
+ if (opts.classGenerator) {
163
+ newClassName = opts.classGenerator(original, opts, this.context);
164
+ }
165
+ if (!newClassName) {
166
+ newClassName = this.defaultClassGenerator();
167
+ }
168
+ if (opts.reserveClassName && regExpTest(opts.reserveClassName, newClassName)) {
169
+ if (opts.log) {
170
+ console.log(`The class name has been reserved. ${newClassName}`);
171
+ }
172
+ this.newClassSize++;
173
+ return this.generateClassName(original);
174
+ }
175
+ if (opts.log) {
176
+ console.log(`Minify class name from ${original} to ${newClassName}`);
177
+ }
178
+ const newClass = {
179
+ name: newClassName,
180
+ usedBy: []
181
+ };
182
+ this.newClassMap[original] = newClass;
183
+ this.newClassSize++;
184
+ return newClass;
185
+ }
186
+ }
187
+
188
+ ({
189
+ HTML: html.NS.HTML,
190
+ XML: html.NS.XML,
191
+ MATHML: html.NS.MATHML,
192
+ SVG: html.NS.SVG,
193
+ XLINK: html.NS.XLINK,
194
+ XMLNS: html.NS.XMLNS
195
+ });
196
+
197
+ /**
198
+ * Determines if a given node is a document or not
199
+ * @param {Node} node Node to test
200
+ * @return {boolean}
201
+ */
202
+ function isDocument(node) {
203
+ return node.nodeName === '#document';
204
+ }
205
+ /**
206
+ * Determines if a given node is a document fragment or not
207
+ * @param {Node} node Node to test
208
+ * @return {boolean}
209
+ */
210
+ function isDocumentFragment(node) {
211
+ return node.nodeName === '#document-fragment';
212
+ }
213
+ /**
214
+ * Determines if a given node is a template node or not
215
+ * @param {Node} node Node to test
216
+ * @return {boolean}
217
+ */
218
+ function isTemplateNode(node) {
219
+ return node.nodeName === 'template';
220
+ }
221
+ const isElementNode = defaultTreeAdapter.isElementNode;
222
+ const isCommentNode = defaultTreeAdapter.isCommentNode;
223
+ const isDocumentTypeNode = defaultTreeAdapter.isDocumentTypeNode;
224
+ const isTextNode = defaultTreeAdapter.isTextNode;
225
+ /**
226
+ * Determines if a given node is a parent or not
227
+ * @param {Node} node Node to test
228
+ * @return {boolean}
229
+ */
230
+ function isParentNode(node) {
231
+ return (isDocument(node) ||
232
+ isDocumentFragment(node) ||
233
+ isElementNode(node) ||
234
+ isTemplateNode(node));
235
+ }
236
+
237
+ defaultTreeAdapter.appendChild;
238
+
239
+ /**
240
+ * Traverses the tree of a given node
241
+ * @param {Node} node Node to traverse
242
+ * @param {Visitor} visitor Visitor to apply
243
+ * @param {ParentNode=} parent Parent node of the current node
244
+ * @return {void}
245
+ */
246
+ function traverse$1(node, visitor, parent) {
247
+ const shouldVisitChildren = typeof visitor['pre:node'] !== 'function' ||
248
+ visitor['pre:node'](node, parent) !== false;
249
+ if (shouldVisitChildren && isParentNode(node)) {
250
+ for (const child of node.childNodes) {
251
+ traverse$1(child, visitor, node);
252
+ }
253
+ }
254
+ if (typeof visitor.node === 'function') {
255
+ visitor.node(node, parent);
256
+ }
257
+ if (typeof visitor.document === 'function' && isDocument(node)) {
258
+ visitor.document(node);
259
+ }
260
+ if (typeof visitor.documentFragment === 'function' &&
261
+ isDocumentFragment(node)) {
262
+ visitor.documentFragment(node, parent);
263
+ }
264
+ if (typeof visitor.element === 'function' && isElementNode(node)) {
265
+ visitor.element(node, parent);
266
+ }
267
+ if (typeof visitor.template === 'function' && isTemplateNode(node)) {
268
+ visitor.template(node, parent);
269
+ }
270
+ if (typeof visitor.comment === 'function' && isCommentNode(node)) {
271
+ visitor.comment(node, parent);
272
+ }
273
+ if (typeof visitor.text === 'function' && isTextNode(node)) {
274
+ visitor.text(node, parent);
275
+ }
276
+ if (typeof visitor.documentType === 'function' && isDocumentTypeNode(node)) {
277
+ visitor.documentType(node, parent);
278
+ }
279
+ }
280
+
281
+ function htmlHandler(rawSource, options) {
282
+ const { runtimeSet, classGenerator } = options;
283
+ const fragment = parse(rawSource);
284
+ traverse$1(fragment, {
285
+ element(node, parent) {
286
+ const attr = node.attrs.find((x) => x.name === 'class');
287
+ if (attr) {
288
+ const arr = attr.value.split(/\s/).filter((x) => x);
289
+ attr.value = arr
290
+ .map((x) => {
291
+ if (runtimeSet.has(x)) {
292
+ return classGenerator.generateClassName(x).name;
293
+ }
294
+ return x;
295
+ })
296
+ .join(' ');
297
+ }
298
+ }
299
+ });
300
+ return serialize(fragment);
301
+ }
302
+
303
+ const validateFilterRE = /[\w\u00A0-\uFFFF-_:%-?]/;
304
+ function isValidSelector(selector = '') {
305
+ return validateFilterRE.test(selector);
306
+ }
307
+ const splitCode = (code) => code.split(/[\s"]+/).filter(isValidSelector);
308
+
309
+ function getDefaultExportFromNamespaceIfPresent(n) {
310
+ return n && Object.prototype.hasOwnProperty.call(n, 'default') ? n.default : n;
311
+ }
312
+ const generate = getDefaultExportFromNamespaceIfPresent(_generate);
313
+ const traverse = getDefaultExportFromNamespaceIfPresent(_traverse);
314
+ function jsHandler(rawSource, options) {
315
+ const ast = parse$1(rawSource);
316
+ const set = options.runtimeSet;
317
+ const clsGen = options.classGenerator;
318
+ const topt = {
319
+ StringLiteral: {
320
+ enter(p) {
321
+ const n = p.node;
322
+ const arr = splitCode(n.value);
323
+ let rawStr = n.value;
324
+ for (let i = 0; i < arr.length; i++) {
325
+ const v = arr[i];
326
+ if (set.has(v)) {
327
+ let ignoreFlag = false;
328
+ if (Array.isArray(n.leadingComments)) {
329
+ ignoreFlag = n.leadingComments.findIndex((x) => x.value.includes('tw-mangle') && x.value.includes('ignore')) > -1;
330
+ }
331
+ if (!ignoreFlag) {
332
+ rawStr = rawStr.replace(new RegExp(escapeStringRegexp(v), 'g'), clsGen.generateClassName(v).name);
333
+ }
334
+ }
335
+ }
336
+ n.value = rawStr;
337
+ }
338
+ },
339
+ noScope: true
340
+ };
341
+ traverse(ast, topt);
342
+ return generate(ast);
343
+ }
344
+
345
+ const postcssPlugin = 'postcss-mangle-tailwindcss-plugin';
346
+ const postcssMangleTailwindcssPlugin = (options) => {
347
+ let newClassMap = {};
348
+ if (options) {
349
+ if (options.newClassMap) {
350
+ newClassMap = options.newClassMap;
351
+ }
352
+ }
353
+ return {
354
+ postcssPlugin,
355
+ Rule(rule, helper) {
356
+ rule.selector = parser((selectors) => {
357
+ selectors.walk((s) => {
358
+ if (s.value) {
359
+ const hit = newClassMap[s.value];
360
+ if (hit) {
361
+ s.value = hit.name;
362
+ }
363
+ }
364
+ });
365
+ }).processSync(rule.selector);
366
+ }
367
+ };
368
+ };
369
+ postcssMangleTailwindcssPlugin.postcss = true;
370
+
371
+ function cssHandler(rawSource, options) {
372
+ return postcss([
373
+ postcssMangleTailwindcssPlugin({
374
+ newClassMap: options.classGenerator.newClassMap
375
+ })
376
+ ]).process(rawSource).css;
377
+ }
378
+
379
+ const unplugin = createUnplugin((options = {}, meta) => {
380
+ const isMangleClass = (className) => {
381
+ return /[-:]/.test(className);
382
+ };
383
+ let classSet;
384
+ const classGenerator = new ClassGenerator();
385
+ function getCachedClassSet() {
386
+ const set = getClassCacheSet();
387
+ set.forEach((c) => {
388
+ if (!isMangleClass(c)) {
389
+ set.delete(c);
390
+ }
391
+ });
392
+ classSet = set;
393
+ return classSet;
394
+ }
395
+ return {
396
+ name: pluginName,
397
+ enforce: 'post',
398
+ vite: {
399
+ generateBundle: {
400
+ handler(options, bundle, isWrite) {
401
+ const runtimeSet = getCachedClassSet();
402
+ if (!runtimeSet.size) {
403
+ return;
404
+ }
405
+ const groupedEntries = getGroupedEntries(Object.entries(bundle));
406
+ if (Array.isArray(groupedEntries.html) && groupedEntries.html.length) {
407
+ for (let i = 0; i < groupedEntries.html.length; i++) {
408
+ const [, asset] = groupedEntries.html[i];
409
+ asset.source = htmlHandler(asset.source.toString(), {
410
+ classGenerator,
411
+ runtimeSet
412
+ });
413
+ }
414
+ }
415
+ if (Array.isArray(groupedEntries.js) && groupedEntries.js.length) {
416
+ for (let i = 0; i < groupedEntries.js.length; i++) {
417
+ const [, chunk] = groupedEntries.js[i];
418
+ chunk.code = jsHandler(chunk.code, {
419
+ runtimeSet,
420
+ classGenerator
421
+ }).code;
422
+ }
423
+ }
424
+ if (Array.isArray(groupedEntries.css) && groupedEntries.css.length) {
425
+ for (let i = 0; i < groupedEntries.css.length; i++) {
426
+ const [, css] = groupedEntries.css[i];
427
+ css.source = cssHandler(css.source.toString(), {
428
+ classGenerator,
429
+ runtimeSet
430
+ });
431
+ }
432
+ }
433
+ }
434
+ }
435
+ },
436
+ webpack(compiler) {
437
+ const Compilation = compiler.webpack.Compilation;
438
+ const { ConcatSource } = compiler.webpack.sources;
439
+ compiler.hooks.compilation.tap(pluginName, (compilation) => {
440
+ compilation.hooks.processAssets.tap({
441
+ name: pluginName,
442
+ stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
443
+ }, (assets) => {
444
+ const runtimeSet = getCachedClassSet();
445
+ if (!runtimeSet.size) {
446
+ return;
447
+ }
448
+ const groupedEntries = getGroupedEntries(Object.entries(assets));
449
+ if (Array.isArray(groupedEntries.html) && groupedEntries.html.length) {
450
+ for (let i = 0; i < groupedEntries.html.length; i++) {
451
+ const [file, asset] = groupedEntries.html[i];
452
+ const html = htmlHandler(asset.source().toString(), {
453
+ classGenerator,
454
+ runtimeSet
455
+ });
456
+ const source = new ConcatSource(html);
457
+ compilation.updateAsset(file, source);
458
+ }
459
+ }
460
+ if (Array.isArray(groupedEntries.js) && groupedEntries.js.length) {
461
+ for (let i = 0; i < groupedEntries.js.length; i++) {
462
+ const [file, chunk] = groupedEntries.js[i];
463
+ const code = jsHandler(chunk.source().toString(), {
464
+ runtimeSet,
465
+ classGenerator
466
+ }).code;
467
+ const source = new ConcatSource(code);
468
+ compilation.updateAsset(file, source);
469
+ }
470
+ }
471
+ if (Array.isArray(groupedEntries.css) && groupedEntries.css.length) {
472
+ for (let i = 0; i < groupedEntries.css.length; i++) {
473
+ const [file, css] = groupedEntries.css[i];
474
+ const newCss = cssHandler(css.source().toString(), {
475
+ classGenerator,
476
+ runtimeSet
477
+ });
478
+ const source = new ConcatSource(newCss);
479
+ compilation.updateAsset(file, source);
480
+ }
481
+ }
482
+ });
483
+ });
484
+ }
485
+ };
486
+ });
487
+
488
+ export { unplugin as default };
@@ -0,0 +1,2 @@
1
+ import type { IHandlerOptions } from '../types';
2
+ export declare function jsHandler(rawSource: string, options: IHandlerOptions): import("@babel/generator").GeneratorResult;
@@ -0,0 +1,3 @@
1
+ export declare const validateFilterRE: RegExp;
2
+ export declare function isValidSelector(selector?: string): selector is string;
3
+ export declare const splitCode: (code: string) => string[];
package/dist/nuxt.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import type { Options } from './types';
2
+ export default function (options: Options | undefined, nuxt: any): void;
package/dist/nuxt.js ADDED
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ var index = require('./index.js');
4
+ require('unplugin');
5
+ require('tailwindcss-patch');
6
+ require('parse5');
7
+ require('@babel/generator');
8
+ require('@babel/parser');
9
+ require('@babel/traverse');
10
+ require('postcss');
11
+ require('postcss-selector-parser');
12
+
13
+ /******************************************************************************
14
+ Copyright (c) Microsoft Corporation.
15
+
16
+ Permission to use, copy, modify, and/or distribute this software for any
17
+ purpose with or without fee is hereby granted.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
20
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
21
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
22
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
24
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
25
+ PERFORMANCE OF THIS SOFTWARE.
26
+ ***************************************************************************** */
27
+
28
+ function __awaiter(thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ }
37
+
38
+ function nuxt (options = {}, nuxt) {
39
+ nuxt.hook('webpack:config', (config) => __awaiter(this, void 0, void 0, function* () {
40
+ config.plugins = config.plugins || [];
41
+ config.plugins.unshift(index.webpack(options));
42
+ }));
43
+ nuxt.hook('vite:extendConfig', (config) => __awaiter(this, void 0, void 0, function* () {
44
+ config.plugins = config.plugins || [];
45
+ config.plugins.push(index.vite(options));
46
+ }));
47
+ }
48
+
49
+ module.exports = nuxt;
package/dist/nuxt.mjs ADDED
@@ -0,0 +1,47 @@
1
+ import unplugin from './index.mjs';
2
+ import 'unplugin';
3
+ import 'tailwindcss-patch';
4
+ import 'parse5';
5
+ import '@babel/generator';
6
+ import '@babel/parser';
7
+ import '@babel/traverse';
8
+ import 'postcss';
9
+ import 'postcss-selector-parser';
10
+
11
+ /******************************************************************************
12
+ Copyright (c) Microsoft Corporation.
13
+
14
+ Permission to use, copy, modify, and/or distribute this software for any
15
+ purpose with or without fee is hereby granted.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
18
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
19
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
20
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
21
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
22
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23
+ PERFORMANCE OF THIS SOFTWARE.
24
+ ***************************************************************************** */
25
+
26
+ function __awaiter(thisArg, _arguments, P, generator) {
27
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
+ return new (P || (P = Promise))(function (resolve, reject) {
29
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
33
+ });
34
+ }
35
+
36
+ function nuxt (options = {}, nuxt) {
37
+ nuxt.hook('webpack:config', (config) => __awaiter(this, void 0, void 0, function* () {
38
+ config.plugins = config.plugins || [];
39
+ config.plugins.unshift(unplugin.webpack(options));
40
+ }));
41
+ nuxt.hook('vite:extendConfig', (config) => __awaiter(this, void 0, void 0, function* () {
42
+ config.plugins = config.plugins || [];
43
+ config.plugins.push(unplugin.vite(options));
44
+ }));
45
+ }
46
+
47
+ export { nuxt as default };
@@ -0,0 +1,2 @@
1
+ declare const _default: (options?: import("./types").Options | undefined) => import("rollup").Plugin | import("rollup").Plugin[];
2
+ export default _default;
package/dist/rollup.js ADDED
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ var index = require('./index.js');
4
+ require('unplugin');
5
+ require('tailwindcss-patch');
6
+ require('parse5');
7
+ require('@babel/generator');
8
+ require('@babel/parser');
9
+ require('@babel/traverse');
10
+ require('postcss');
11
+ require('postcss-selector-parser');
12
+
13
+ var rollup = index.rollup;
14
+
15
+ module.exports = rollup;
@@ -0,0 +1,13 @@
1
+ import unplugin from './index.mjs';
2
+ import 'unplugin';
3
+ import 'tailwindcss-patch';
4
+ import 'parse5';
5
+ import '@babel/generator';
6
+ import '@babel/parser';
7
+ import '@babel/traverse';
8
+ import 'postcss';
9
+ import 'postcss-selector-parser';
10
+
11
+ var rollup = unplugin.rollup;
12
+
13
+ export { rollup as default };
@@ -0,0 +1,26 @@
1
+ import type ClassGenerator from './classGenerator';
2
+ export interface Options {
3
+ }
4
+ export interface IMangleContextClass {
5
+ name: string;
6
+ usedBy: any[];
7
+ }
8
+ export interface IMangleOptions {
9
+ reserveClassName?: (string | RegExp)[];
10
+ classGenerator?: (original: string, opts: IMangleOptions, context: Record<string, any>) => string | undefined;
11
+ log?: boolean;
12
+ exclude?: (string | RegExp)[];
13
+ include?: (string | RegExp)[];
14
+ ignoreClass?: (string | RegExp)[];
15
+ classPrefix?: string;
16
+ }
17
+ export interface IClassGenerator {
18
+ newClassMap: Record<string, IMangleContextClass>;
19
+ newClassSize: number;
20
+ context: Record<string, any>;
21
+ }
22
+ export type { TraverseOptions } from '@babel/traverse';
23
+ export interface IHandlerOptions {
24
+ runtimeSet: Set<string>;
25
+ classGenerator: ClassGenerator;
26
+ }
@@ -0,0 +1,14 @@
1
+ import type { IMangleOptions, IClassGenerator } from './types';
2
+ export declare function groupBy<T>(arr: T[], cb: (arg: T) => string): Record<string, T[]>;
3
+ export declare function getGroupedEntries<T>(entries: [string, T][], options?: {
4
+ cssMatcher(file: string): boolean;
5
+ htmlMatcher(file: string): boolean;
6
+ jsMatcher(file: string): boolean;
7
+ }): Record<"css" | "html" | "js" | "other", [string, T][]>;
8
+ export declare const acceptChars: string[];
9
+ export declare function stripEscapeSequence(words: string): string;
10
+ export declare const validate: (opts: IMangleOptions, classGenerator: IClassGenerator) => void;
11
+ export declare function isRegexp(value: unknown): boolean;
12
+ export declare function isMap(value: unknown): boolean;
13
+ export declare function regExpTest(arr: (string | RegExp)[] | undefined, str: string): boolean;
14
+ export declare function escapeStringRegexp(str: string): string;
package/dist/vite.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare const _default: (options?: import("./types").Options | undefined) => import("vite").Plugin | import("vite").Plugin[];
2
+ export default _default;