@herb-tools/tailwind-class-sorter 0.8.10 → 0.9.0
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/tailwind-class-sorter.cjs +53 -46
- package/dist/tailwind-class-sorter.cjs.map +1 -1
- package/dist/tailwind-class-sorter.esm.js +53 -46
- package/dist/tailwind-class-sorter.esm.js.map +1 -1
- package/package.json +5 -5
- package/src/config.ts +27 -27
- package/src/expiring-map.ts +3 -3
- package/src/resolve.ts +2 -2
- package/src/sorting.ts +11 -10
|
@@ -6526,7 +6526,15 @@ function requireMapGenerator () {
|
|
|
6526
6526
|
}
|
|
6527
6527
|
}
|
|
6528
6528
|
} else if (this.css) {
|
|
6529
|
-
|
|
6529
|
+
let startIndex;
|
|
6530
|
+
while ((startIndex = this.css.lastIndexOf('/*#')) !== -1) {
|
|
6531
|
+
let endIndex = this.css.indexOf('*/', startIndex + 3);
|
|
6532
|
+
if (endIndex === -1) break
|
|
6533
|
+
while (startIndex > 0 && this.css[startIndex - 1] === '\n') {
|
|
6534
|
+
startIndex--;
|
|
6535
|
+
}
|
|
6536
|
+
this.css = this.css.slice(0, startIndex) + this.css.slice(endIndex + 2);
|
|
6537
|
+
}
|
|
6530
6538
|
}
|
|
6531
6539
|
}
|
|
6532
6540
|
|
|
@@ -7003,7 +7011,7 @@ function requireParser () {
|
|
|
7003
7011
|
node.source.end.offset++;
|
|
7004
7012
|
|
|
7005
7013
|
let text = token[1].slice(2, -2);
|
|
7006
|
-
if (
|
|
7014
|
+
if (!text.trim()) {
|
|
7007
7015
|
node.text = '';
|
|
7008
7016
|
node.raws.left = text;
|
|
7009
7017
|
node.raws.right = '';
|
|
@@ -8236,10 +8244,9 @@ function requireNoWorkResult () {
|
|
|
8236
8244
|
this._css = css;
|
|
8237
8245
|
this._opts = opts;
|
|
8238
8246
|
this._map = undefined;
|
|
8239
|
-
let root;
|
|
8240
8247
|
|
|
8241
8248
|
let str = stringify;
|
|
8242
|
-
this.result = new Result(this._processor,
|
|
8249
|
+
this.result = new Result(this._processor, undefined, this._opts);
|
|
8243
8250
|
this.result.css = css;
|
|
8244
8251
|
|
|
8245
8252
|
let self = this;
|
|
@@ -8249,7 +8256,7 @@ function requireNoWorkResult () {
|
|
|
8249
8256
|
}
|
|
8250
8257
|
});
|
|
8251
8258
|
|
|
8252
|
-
let map = new MapGenerator(str,
|
|
8259
|
+
let map = new MapGenerator(str, undefined, this._opts, css);
|
|
8253
8260
|
if (map.isMap()) {
|
|
8254
8261
|
let [generatedCSS, generatedMap] = map.generate();
|
|
8255
8262
|
if (generatedCSS) {
|
|
@@ -8324,7 +8331,7 @@ function requireProcessor () {
|
|
|
8324
8331
|
|
|
8325
8332
|
class Processor {
|
|
8326
8333
|
constructor(plugins = []) {
|
|
8327
|
-
this.version = '8.5.
|
|
8334
|
+
this.version = '8.5.8';
|
|
8328
8335
|
this.plugins = this.normalize(plugins);
|
|
8329
8336
|
}
|
|
8330
8337
|
|
|
@@ -12195,10 +12202,10 @@ var postcssImportExports = requirePostcssImport();
|
|
|
12195
12202
|
var postcssImport = /*@__PURE__*/getDefaultExportFromCjs(postcssImportExports);
|
|
12196
12203
|
|
|
12197
12204
|
function expiringMap(duration) {
|
|
12198
|
-
|
|
12205
|
+
const map = new Map();
|
|
12199
12206
|
return {
|
|
12200
12207
|
get(key) {
|
|
12201
|
-
|
|
12208
|
+
const result = map.get(key);
|
|
12202
12209
|
if (!result)
|
|
12203
12210
|
return undefined;
|
|
12204
12211
|
if (result.expiration <= new Date()) {
|
|
@@ -12208,7 +12215,7 @@ function expiringMap(duration) {
|
|
|
12208
12215
|
return result.value;
|
|
12209
12216
|
},
|
|
12210
12217
|
set(key, value) {
|
|
12211
|
-
|
|
12218
|
+
const expiration = new Date();
|
|
12212
12219
|
expiration.setMilliseconds(expiration.getMilliseconds() + duration);
|
|
12213
12220
|
map.set(key, {
|
|
12214
12221
|
value,
|
|
@@ -21346,18 +21353,18 @@ function resolveCssFrom(base, id) {
|
|
|
21346
21353
|
}
|
|
21347
21354
|
|
|
21348
21355
|
// @ts-check
|
|
21349
|
-
|
|
21350
|
-
|
|
21351
|
-
|
|
21356
|
+
const sourceToPathMap = new Map();
|
|
21357
|
+
const sourceToEntryMap = new Map();
|
|
21358
|
+
const pathToContextMap = expiringMap(10_000);
|
|
21352
21359
|
async function getTailwindConfig(options = {}) {
|
|
21353
|
-
|
|
21354
|
-
|
|
21360
|
+
const pkgName = 'tailwindcss';
|
|
21361
|
+
const key = [
|
|
21355
21362
|
options.baseDir ?? process.cwd(),
|
|
21356
21363
|
options.tailwindStylesheet ?? '',
|
|
21357
21364
|
options.tailwindConfig ?? '',
|
|
21358
21365
|
pkgName,
|
|
21359
21366
|
].join(':');
|
|
21360
|
-
|
|
21367
|
+
const baseDir = getBaseDir(options);
|
|
21361
21368
|
// Map the source file to it's associated Tailwind config file
|
|
21362
21369
|
let configPath = sourceToPathMap.get(key);
|
|
21363
21370
|
if (configPath === undefined) {
|
|
@@ -21370,13 +21377,13 @@ async function getTailwindConfig(options = {}) {
|
|
|
21370
21377
|
sourceToEntryMap.set(key, entryPoint);
|
|
21371
21378
|
}
|
|
21372
21379
|
// Now see if we've loaded the Tailwind config file before (and it's still valid)
|
|
21373
|
-
|
|
21374
|
-
|
|
21380
|
+
const contextKey = `${pkgName}:${configPath}:${entryPoint}`;
|
|
21381
|
+
const existing = pathToContextMap.get(contextKey);
|
|
21375
21382
|
if (existing) {
|
|
21376
21383
|
return existing;
|
|
21377
21384
|
}
|
|
21378
21385
|
// By this point we know we need to load the Tailwind config file
|
|
21379
|
-
|
|
21386
|
+
const result = await loadTailwindConfig(baseDir, pkgName, configPath, entryPoint);
|
|
21380
21387
|
pathToContextMap.set(contextKey, result);
|
|
21381
21388
|
return result;
|
|
21382
21389
|
}
|
|
@@ -21393,7 +21400,7 @@ async function loadTailwindConfig(baseDir, pkgName, tailwindConfigPath, entryPoi
|
|
|
21393
21400
|
let loadConfig;
|
|
21394
21401
|
let tailwindConfig = { content: [] };
|
|
21395
21402
|
try {
|
|
21396
|
-
|
|
21403
|
+
const pkgPath = resolveJsFrom(baseDir, pkgName);
|
|
21397
21404
|
let pkgJsonPath;
|
|
21398
21405
|
try {
|
|
21399
21406
|
const Module = require('module');
|
|
@@ -21418,14 +21425,14 @@ async function loadTailwindConfig(baseDir, pkgName, tailwindConfigPath, entryPoi
|
|
|
21418
21425
|
throw new Error('Could not find Tailwind CSS package.json');
|
|
21419
21426
|
}
|
|
21420
21427
|
}
|
|
21421
|
-
|
|
21428
|
+
const pkgDir = path__namespace.dirname(pkgJsonPath);
|
|
21422
21429
|
try {
|
|
21423
|
-
|
|
21430
|
+
const v4 = await loadV4(baseDir, pkgDir, pkgName, entryPoint);
|
|
21424
21431
|
if (v4) {
|
|
21425
21432
|
return v4;
|
|
21426
21433
|
}
|
|
21427
21434
|
}
|
|
21428
|
-
catch (
|
|
21435
|
+
catch (_error) {
|
|
21429
21436
|
// V4 loading failed, will try v3 below
|
|
21430
21437
|
}
|
|
21431
21438
|
resolveConfig = require(path__namespace.join(pkgDir, 'resolveConfig'));
|
|
@@ -21434,7 +21441,7 @@ async function loadTailwindConfig(baseDir, pkgName, tailwindConfigPath, entryPoi
|
|
|
21434
21441
|
// Prior to `tailwindcss@3.3.0` this won't exist so we load it last
|
|
21435
21442
|
loadConfig = require(path__namespace.join(pkgDir, 'loadConfig'));
|
|
21436
21443
|
}
|
|
21437
|
-
catch (
|
|
21444
|
+
catch (_error) {
|
|
21438
21445
|
// Tailwind isn't installed or loading failed, will use defaults
|
|
21439
21446
|
}
|
|
21440
21447
|
if (tailwindConfigPath) {
|
|
@@ -21454,7 +21461,7 @@ async function loadTailwindConfig(baseDir, pkgName, tailwindConfigPath, entryPoi
|
|
|
21454
21461
|
};
|
|
21455
21462
|
}
|
|
21456
21463
|
tailwindConfig.content = ['no-op'];
|
|
21457
|
-
|
|
21464
|
+
const context = createContext(resolveConfig(tailwindConfig));
|
|
21458
21465
|
return {
|
|
21459
21466
|
context,
|
|
21460
21467
|
generateRules,
|
|
@@ -21466,11 +21473,11 @@ async function loadTailwindConfig(baseDir, pkgName, tailwindConfigPath, entryPoi
|
|
|
21466
21473
|
* everything from working so we'll let the error handler decide how to proceed.
|
|
21467
21474
|
*/
|
|
21468
21475
|
function createLoader({ legacy, jiti, filepath, onError, }) {
|
|
21469
|
-
|
|
21476
|
+
const cacheKey = `${+Date.now()}`;
|
|
21470
21477
|
async function loadFile(id, base, resourceType) {
|
|
21471
21478
|
try {
|
|
21472
|
-
|
|
21473
|
-
|
|
21479
|
+
const resolved = resolveJsFrom(base, id);
|
|
21480
|
+
const url = require$$3$1.pathToFileURL(resolved);
|
|
21474
21481
|
url.searchParams.append('t', cacheKey);
|
|
21475
21482
|
return await jiti.import(url.href, { default: true });
|
|
21476
21483
|
}
|
|
@@ -21479,7 +21486,7 @@ function createLoader({ legacy, jiti, filepath, onError, }) {
|
|
|
21479
21486
|
}
|
|
21480
21487
|
}
|
|
21481
21488
|
if (legacy) {
|
|
21482
|
-
|
|
21489
|
+
const baseDir = path__namespace.dirname(filepath);
|
|
21483
21490
|
return (id) => loadFile(id, baseDir, 'module');
|
|
21484
21491
|
}
|
|
21485
21492
|
return async (id, base, resourceType) => {
|
|
@@ -21491,8 +21498,8 @@ function createLoader({ legacy, jiti, filepath, onError, }) {
|
|
|
21491
21498
|
}
|
|
21492
21499
|
async function loadV4(baseDir, pkgDir, pkgName, entryPoint) {
|
|
21493
21500
|
// Import Tailwind — if this is v4 it'll have APIs we can use directly
|
|
21494
|
-
|
|
21495
|
-
|
|
21501
|
+
const pkgPath = resolveJsFrom(baseDir, pkgName);
|
|
21502
|
+
const tw = await import(require$$3$1.pathToFileURL(pkgPath).toString());
|
|
21496
21503
|
// This is not Tailwind v4
|
|
21497
21504
|
if (!tw.__unstable__loadDesignSystem) {
|
|
21498
21505
|
return null;
|
|
@@ -21500,11 +21507,11 @@ async function loadV4(baseDir, pkgDir, pkgName, entryPoint) {
|
|
|
21500
21507
|
// If the user doesn't define an entrypoint then we use the default theme
|
|
21501
21508
|
entryPoint = entryPoint ?? `${pkgDir}/theme.css`;
|
|
21502
21509
|
// Create a Jiti instance that can be used to load plugins and config files
|
|
21503
|
-
|
|
21510
|
+
const jiti = createJiti((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('tailwind-class-sorter.cjs', document.baseURI).href)), {
|
|
21504
21511
|
moduleCache: false,
|
|
21505
21512
|
fsCache: false,
|
|
21506
21513
|
});
|
|
21507
|
-
|
|
21514
|
+
const importBasePath = path__namespace.dirname(entryPoint);
|
|
21508
21515
|
// Resolve imports in the entrypoint to a flat CSS tree
|
|
21509
21516
|
let css = await fs__namespace.readFile(entryPoint, 'utf-8');
|
|
21510
21517
|
// Determine if the v4 API supports resolving `@import`
|
|
@@ -21522,13 +21529,13 @@ async function loadV4(baseDir, pkgDir, pkgName, entryPoint) {
|
|
|
21522
21529
|
}
|
|
21523
21530
|
catch { }
|
|
21524
21531
|
if (!supportsImports) {
|
|
21525
|
-
|
|
21526
|
-
|
|
21532
|
+
const resolveImports = postcss([postcssImport()]);
|
|
21533
|
+
const result = await resolveImports.process(css, { from: entryPoint });
|
|
21527
21534
|
css = result.css;
|
|
21528
21535
|
}
|
|
21529
21536
|
// Load the design system and set up a compatible context object that is
|
|
21530
21537
|
// usable by the rest of the plugin
|
|
21531
|
-
|
|
21538
|
+
const design = await tw.__unstable__loadDesignSystem(css, {
|
|
21532
21539
|
base: importBasePath,
|
|
21533
21540
|
// v4.0.0-alpha.25+
|
|
21534
21541
|
loadModule: createLoader({
|
|
@@ -21546,7 +21553,7 @@ async function loadV4(baseDir, pkgDir, pkgName, entryPoint) {
|
|
|
21546
21553
|
},
|
|
21547
21554
|
}),
|
|
21548
21555
|
loadStylesheet: async (id, base) => {
|
|
21549
|
-
|
|
21556
|
+
const resolved = resolveCssFrom(base, id);
|
|
21550
21557
|
return {
|
|
21551
21558
|
base: path__namespace.dirname(resolved),
|
|
21552
21559
|
content: await fs__namespace.readFile(resolved, 'utf-8'),
|
|
@@ -21649,7 +21656,7 @@ function bigSign(bigIntValue) {
|
|
|
21649
21656
|
return Number(bigIntValue > 0n) - Number(bigIntValue < 0n);
|
|
21650
21657
|
}
|
|
21651
21658
|
function prefixCandidate(context, selector) {
|
|
21652
|
-
|
|
21659
|
+
const prefix = context.tailwindConfig.prefix;
|
|
21653
21660
|
return typeof prefix === 'function' ? prefix(selector) : prefix + selector;
|
|
21654
21661
|
}
|
|
21655
21662
|
// Polyfill for older Tailwind CSS versions
|
|
@@ -21661,12 +21668,12 @@ function getClassOrderPolyfill(classes, { env }) {
|
|
|
21661
21668
|
// that don't exist on their own. This will result in them "not existing" and
|
|
21662
21669
|
// sorting could be weird since you still require them in order to make the
|
|
21663
21670
|
// host utitlies work properly. (Thanks Biology)
|
|
21664
|
-
|
|
21671
|
+
const parasiteUtilities = new Set([
|
|
21665
21672
|
prefixCandidate(env.context, 'group'),
|
|
21666
21673
|
prefixCandidate(env.context, 'peer'),
|
|
21667
21674
|
]);
|
|
21668
|
-
|
|
21669
|
-
for (
|
|
21675
|
+
const classNamesWithOrder = [];
|
|
21676
|
+
for (const className of classes) {
|
|
21670
21677
|
let order = env
|
|
21671
21678
|
.generateRules(new Set([className]), env.context)
|
|
21672
21679
|
.sort(([a], [z]) => bigSign(z - a))[0]?.[0] ?? null;
|
|
@@ -21684,7 +21691,7 @@ function reorderClasses(classList, { env }) {
|
|
|
21684
21691
|
if (!env.context) {
|
|
21685
21692
|
return classList.map(name => [name, null]);
|
|
21686
21693
|
}
|
|
21687
|
-
|
|
21694
|
+
const orderedClasses = env.context.getClassOrder
|
|
21688
21695
|
? env.context.getClassOrder(classList)
|
|
21689
21696
|
: getClassOrderPolyfill(classList, { env });
|
|
21690
21697
|
return orderedClasses.sort(([nameA, a], [nameZ, z]) => {
|
|
@@ -21720,8 +21727,8 @@ function sortClasses(classStr, { env, ignoreFirst = false, ignoreLast = false, r
|
|
|
21720
21727
|
return ' ';
|
|
21721
21728
|
}
|
|
21722
21729
|
let result = '';
|
|
21723
|
-
|
|
21724
|
-
|
|
21730
|
+
const parts = classStr.split(/([\t\r\f\n ]+)/);
|
|
21731
|
+
const classes = parts.filter((_, i) => i % 2 === 0);
|
|
21725
21732
|
let whitespace = parts.filter((_, i) => i % 2 !== 0);
|
|
21726
21733
|
if (classes[classes.length - 1] === '') {
|
|
21727
21734
|
classes.pop();
|
|
@@ -21737,7 +21744,7 @@ function sortClasses(classStr, { env, ignoreFirst = false, ignoreLast = false, r
|
|
|
21737
21744
|
if (ignoreLast) {
|
|
21738
21745
|
suffix = `${whitespace.pop() ?? ''}${classes.pop() ?? ''}`;
|
|
21739
21746
|
}
|
|
21740
|
-
|
|
21747
|
+
const { classList, removedIndices } = sortClassList(classes, {
|
|
21741
21748
|
env,
|
|
21742
21749
|
removeDuplicates,
|
|
21743
21750
|
});
|
|
@@ -21762,9 +21769,9 @@ function sortClassList(classList, { env, removeDuplicates, }) {
|
|
|
21762
21769
|
if (env.options.tailwindPreserveDuplicates) {
|
|
21763
21770
|
removeDuplicates = false;
|
|
21764
21771
|
}
|
|
21765
|
-
|
|
21772
|
+
const removedIndices = new Set();
|
|
21766
21773
|
if (removeDuplicates) {
|
|
21767
|
-
|
|
21774
|
+
const seenClasses = new Set();
|
|
21768
21775
|
orderedClasses = orderedClasses.filter(([cls, order], index) => {
|
|
21769
21776
|
if (seenClasses.has(cls)) {
|
|
21770
21777
|
removedIndices.add(index);
|