@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
|
@@ -6504,7 +6504,15 @@ function requireMapGenerator () {
|
|
|
6504
6504
|
}
|
|
6505
6505
|
}
|
|
6506
6506
|
} else if (this.css) {
|
|
6507
|
-
|
|
6507
|
+
let startIndex;
|
|
6508
|
+
while ((startIndex = this.css.lastIndexOf('/*#')) !== -1) {
|
|
6509
|
+
let endIndex = this.css.indexOf('*/', startIndex + 3);
|
|
6510
|
+
if (endIndex === -1) break
|
|
6511
|
+
while (startIndex > 0 && this.css[startIndex - 1] === '\n') {
|
|
6512
|
+
startIndex--;
|
|
6513
|
+
}
|
|
6514
|
+
this.css = this.css.slice(0, startIndex) + this.css.slice(endIndex + 2);
|
|
6515
|
+
}
|
|
6508
6516
|
}
|
|
6509
6517
|
}
|
|
6510
6518
|
|
|
@@ -6981,7 +6989,7 @@ function requireParser () {
|
|
|
6981
6989
|
node.source.end.offset++;
|
|
6982
6990
|
|
|
6983
6991
|
let text = token[1].slice(2, -2);
|
|
6984
|
-
if (
|
|
6992
|
+
if (!text.trim()) {
|
|
6985
6993
|
node.text = '';
|
|
6986
6994
|
node.raws.left = text;
|
|
6987
6995
|
node.raws.right = '';
|
|
@@ -8214,10 +8222,9 @@ function requireNoWorkResult () {
|
|
|
8214
8222
|
this._css = css;
|
|
8215
8223
|
this._opts = opts;
|
|
8216
8224
|
this._map = undefined;
|
|
8217
|
-
let root;
|
|
8218
8225
|
|
|
8219
8226
|
let str = stringify;
|
|
8220
|
-
this.result = new Result(this._processor,
|
|
8227
|
+
this.result = new Result(this._processor, undefined, this._opts);
|
|
8221
8228
|
this.result.css = css;
|
|
8222
8229
|
|
|
8223
8230
|
let self = this;
|
|
@@ -8227,7 +8234,7 @@ function requireNoWorkResult () {
|
|
|
8227
8234
|
}
|
|
8228
8235
|
});
|
|
8229
8236
|
|
|
8230
|
-
let map = new MapGenerator(str,
|
|
8237
|
+
let map = new MapGenerator(str, undefined, this._opts, css);
|
|
8231
8238
|
if (map.isMap()) {
|
|
8232
8239
|
let [generatedCSS, generatedMap] = map.generate();
|
|
8233
8240
|
if (generatedCSS) {
|
|
@@ -8302,7 +8309,7 @@ function requireProcessor () {
|
|
|
8302
8309
|
|
|
8303
8310
|
class Processor {
|
|
8304
8311
|
constructor(plugins = []) {
|
|
8305
|
-
this.version = '8.5.
|
|
8312
|
+
this.version = '8.5.8';
|
|
8306
8313
|
this.plugins = this.normalize(plugins);
|
|
8307
8314
|
}
|
|
8308
8315
|
|
|
@@ -12173,10 +12180,10 @@ var postcssImportExports = requirePostcssImport();
|
|
|
12173
12180
|
var postcssImport = /*@__PURE__*/getDefaultExportFromCjs(postcssImportExports);
|
|
12174
12181
|
|
|
12175
12182
|
function expiringMap(duration) {
|
|
12176
|
-
|
|
12183
|
+
const map = new Map();
|
|
12177
12184
|
return {
|
|
12178
12185
|
get(key) {
|
|
12179
|
-
|
|
12186
|
+
const result = map.get(key);
|
|
12180
12187
|
if (!result)
|
|
12181
12188
|
return undefined;
|
|
12182
12189
|
if (result.expiration <= new Date()) {
|
|
@@ -12186,7 +12193,7 @@ function expiringMap(duration) {
|
|
|
12186
12193
|
return result.value;
|
|
12187
12194
|
},
|
|
12188
12195
|
set(key, value) {
|
|
12189
|
-
|
|
12196
|
+
const expiration = new Date();
|
|
12190
12197
|
expiration.setMilliseconds(expiration.getMilliseconds() + duration);
|
|
12191
12198
|
map.set(key, {
|
|
12192
12199
|
value,
|
|
@@ -21324,18 +21331,18 @@ function resolveCssFrom(base, id) {
|
|
|
21324
21331
|
}
|
|
21325
21332
|
|
|
21326
21333
|
// @ts-check
|
|
21327
|
-
|
|
21328
|
-
|
|
21329
|
-
|
|
21334
|
+
const sourceToPathMap = new Map();
|
|
21335
|
+
const sourceToEntryMap = new Map();
|
|
21336
|
+
const pathToContextMap = expiringMap(10_000);
|
|
21330
21337
|
async function getTailwindConfig(options = {}) {
|
|
21331
|
-
|
|
21332
|
-
|
|
21338
|
+
const pkgName = 'tailwindcss';
|
|
21339
|
+
const key = [
|
|
21333
21340
|
options.baseDir ?? process.cwd(),
|
|
21334
21341
|
options.tailwindStylesheet ?? '',
|
|
21335
21342
|
options.tailwindConfig ?? '',
|
|
21336
21343
|
pkgName,
|
|
21337
21344
|
].join(':');
|
|
21338
|
-
|
|
21345
|
+
const baseDir = getBaseDir(options);
|
|
21339
21346
|
// Map the source file to it's associated Tailwind config file
|
|
21340
21347
|
let configPath = sourceToPathMap.get(key);
|
|
21341
21348
|
if (configPath === undefined) {
|
|
@@ -21348,13 +21355,13 @@ async function getTailwindConfig(options = {}) {
|
|
|
21348
21355
|
sourceToEntryMap.set(key, entryPoint);
|
|
21349
21356
|
}
|
|
21350
21357
|
// Now see if we've loaded the Tailwind config file before (and it's still valid)
|
|
21351
|
-
|
|
21352
|
-
|
|
21358
|
+
const contextKey = `${pkgName}:${configPath}:${entryPoint}`;
|
|
21359
|
+
const existing = pathToContextMap.get(contextKey);
|
|
21353
21360
|
if (existing) {
|
|
21354
21361
|
return existing;
|
|
21355
21362
|
}
|
|
21356
21363
|
// By this point we know we need to load the Tailwind config file
|
|
21357
|
-
|
|
21364
|
+
const result = await loadTailwindConfig(baseDir, pkgName, configPath, entryPoint);
|
|
21358
21365
|
pathToContextMap.set(contextKey, result);
|
|
21359
21366
|
return result;
|
|
21360
21367
|
}
|
|
@@ -21371,7 +21378,7 @@ async function loadTailwindConfig(baseDir, pkgName, tailwindConfigPath, entryPoi
|
|
|
21371
21378
|
let loadConfig;
|
|
21372
21379
|
let tailwindConfig = { content: [] };
|
|
21373
21380
|
try {
|
|
21374
|
-
|
|
21381
|
+
const pkgPath = resolveJsFrom(baseDir, pkgName);
|
|
21375
21382
|
let pkgJsonPath;
|
|
21376
21383
|
try {
|
|
21377
21384
|
const Module = require('module');
|
|
@@ -21396,14 +21403,14 @@ async function loadTailwindConfig(baseDir, pkgName, tailwindConfigPath, entryPoi
|
|
|
21396
21403
|
throw new Error('Could not find Tailwind CSS package.json');
|
|
21397
21404
|
}
|
|
21398
21405
|
}
|
|
21399
|
-
|
|
21406
|
+
const pkgDir = path$3.dirname(pkgJsonPath);
|
|
21400
21407
|
try {
|
|
21401
|
-
|
|
21408
|
+
const v4 = await loadV4(baseDir, pkgDir, pkgName, entryPoint);
|
|
21402
21409
|
if (v4) {
|
|
21403
21410
|
return v4;
|
|
21404
21411
|
}
|
|
21405
21412
|
}
|
|
21406
|
-
catch (
|
|
21413
|
+
catch (_error) {
|
|
21407
21414
|
// V4 loading failed, will try v3 below
|
|
21408
21415
|
}
|
|
21409
21416
|
resolveConfig = require(path$3.join(pkgDir, 'resolveConfig'));
|
|
@@ -21412,7 +21419,7 @@ async function loadTailwindConfig(baseDir, pkgName, tailwindConfigPath, entryPoi
|
|
|
21412
21419
|
// Prior to `tailwindcss@3.3.0` this won't exist so we load it last
|
|
21413
21420
|
loadConfig = require(path$3.join(pkgDir, 'loadConfig'));
|
|
21414
21421
|
}
|
|
21415
|
-
catch (
|
|
21422
|
+
catch (_error) {
|
|
21416
21423
|
// Tailwind isn't installed or loading failed, will use defaults
|
|
21417
21424
|
}
|
|
21418
21425
|
if (tailwindConfigPath) {
|
|
@@ -21432,7 +21439,7 @@ async function loadTailwindConfig(baseDir, pkgName, tailwindConfigPath, entryPoi
|
|
|
21432
21439
|
};
|
|
21433
21440
|
}
|
|
21434
21441
|
tailwindConfig.content = ['no-op'];
|
|
21435
|
-
|
|
21442
|
+
const context = createContext(resolveConfig(tailwindConfig));
|
|
21436
21443
|
return {
|
|
21437
21444
|
context,
|
|
21438
21445
|
generateRules,
|
|
@@ -21444,11 +21451,11 @@ async function loadTailwindConfig(baseDir, pkgName, tailwindConfigPath, entryPoi
|
|
|
21444
21451
|
* everything from working so we'll let the error handler decide how to proceed.
|
|
21445
21452
|
*/
|
|
21446
21453
|
function createLoader({ legacy, jiti, filepath, onError, }) {
|
|
21447
|
-
|
|
21454
|
+
const cacheKey = `${+Date.now()}`;
|
|
21448
21455
|
async function loadFile(id, base, resourceType) {
|
|
21449
21456
|
try {
|
|
21450
|
-
|
|
21451
|
-
|
|
21457
|
+
const resolved = resolveJsFrom(base, id);
|
|
21458
|
+
const url = pathToFileURL(resolved);
|
|
21452
21459
|
url.searchParams.append('t', cacheKey);
|
|
21453
21460
|
return await jiti.import(url.href, { default: true });
|
|
21454
21461
|
}
|
|
@@ -21457,7 +21464,7 @@ function createLoader({ legacy, jiti, filepath, onError, }) {
|
|
|
21457
21464
|
}
|
|
21458
21465
|
}
|
|
21459
21466
|
if (legacy) {
|
|
21460
|
-
|
|
21467
|
+
const baseDir = path$3.dirname(filepath);
|
|
21461
21468
|
return (id) => loadFile(id, baseDir, 'module');
|
|
21462
21469
|
}
|
|
21463
21470
|
return async (id, base, resourceType) => {
|
|
@@ -21469,8 +21476,8 @@ function createLoader({ legacy, jiti, filepath, onError, }) {
|
|
|
21469
21476
|
}
|
|
21470
21477
|
async function loadV4(baseDir, pkgDir, pkgName, entryPoint) {
|
|
21471
21478
|
// Import Tailwind — if this is v4 it'll have APIs we can use directly
|
|
21472
|
-
|
|
21473
|
-
|
|
21479
|
+
const pkgPath = resolveJsFrom(baseDir, pkgName);
|
|
21480
|
+
const tw = await import(pathToFileURL(pkgPath).toString());
|
|
21474
21481
|
// This is not Tailwind v4
|
|
21475
21482
|
if (!tw.__unstable__loadDesignSystem) {
|
|
21476
21483
|
return null;
|
|
@@ -21478,11 +21485,11 @@ async function loadV4(baseDir, pkgDir, pkgName, entryPoint) {
|
|
|
21478
21485
|
// If the user doesn't define an entrypoint then we use the default theme
|
|
21479
21486
|
entryPoint = entryPoint ?? `${pkgDir}/theme.css`;
|
|
21480
21487
|
// Create a Jiti instance that can be used to load plugins and config files
|
|
21481
|
-
|
|
21488
|
+
const jiti = createJiti(import.meta.url, {
|
|
21482
21489
|
moduleCache: false,
|
|
21483
21490
|
fsCache: false,
|
|
21484
21491
|
});
|
|
21485
|
-
|
|
21492
|
+
const importBasePath = path$3.dirname(entryPoint);
|
|
21486
21493
|
// Resolve imports in the entrypoint to a flat CSS tree
|
|
21487
21494
|
let css = await fs$2.readFile(entryPoint, 'utf-8');
|
|
21488
21495
|
// Determine if the v4 API supports resolving `@import`
|
|
@@ -21500,13 +21507,13 @@ async function loadV4(baseDir, pkgDir, pkgName, entryPoint) {
|
|
|
21500
21507
|
}
|
|
21501
21508
|
catch { }
|
|
21502
21509
|
if (!supportsImports) {
|
|
21503
|
-
|
|
21504
|
-
|
|
21510
|
+
const resolveImports = postcss([postcssImport()]);
|
|
21511
|
+
const result = await resolveImports.process(css, { from: entryPoint });
|
|
21505
21512
|
css = result.css;
|
|
21506
21513
|
}
|
|
21507
21514
|
// Load the design system and set up a compatible context object that is
|
|
21508
21515
|
// usable by the rest of the plugin
|
|
21509
|
-
|
|
21516
|
+
const design = await tw.__unstable__loadDesignSystem(css, {
|
|
21510
21517
|
base: importBasePath,
|
|
21511
21518
|
// v4.0.0-alpha.25+
|
|
21512
21519
|
loadModule: createLoader({
|
|
@@ -21524,7 +21531,7 @@ async function loadV4(baseDir, pkgDir, pkgName, entryPoint) {
|
|
|
21524
21531
|
},
|
|
21525
21532
|
}),
|
|
21526
21533
|
loadStylesheet: async (id, base) => {
|
|
21527
|
-
|
|
21534
|
+
const resolved = resolveCssFrom(base, id);
|
|
21528
21535
|
return {
|
|
21529
21536
|
base: path$3.dirname(resolved),
|
|
21530
21537
|
content: await fs$2.readFile(resolved, 'utf-8'),
|
|
@@ -21627,7 +21634,7 @@ function bigSign(bigIntValue) {
|
|
|
21627
21634
|
return Number(bigIntValue > 0n) - Number(bigIntValue < 0n);
|
|
21628
21635
|
}
|
|
21629
21636
|
function prefixCandidate(context, selector) {
|
|
21630
|
-
|
|
21637
|
+
const prefix = context.tailwindConfig.prefix;
|
|
21631
21638
|
return typeof prefix === 'function' ? prefix(selector) : prefix + selector;
|
|
21632
21639
|
}
|
|
21633
21640
|
// Polyfill for older Tailwind CSS versions
|
|
@@ -21639,12 +21646,12 @@ function getClassOrderPolyfill(classes, { env }) {
|
|
|
21639
21646
|
// that don't exist on their own. This will result in them "not existing" and
|
|
21640
21647
|
// sorting could be weird since you still require them in order to make the
|
|
21641
21648
|
// host utitlies work properly. (Thanks Biology)
|
|
21642
|
-
|
|
21649
|
+
const parasiteUtilities = new Set([
|
|
21643
21650
|
prefixCandidate(env.context, 'group'),
|
|
21644
21651
|
prefixCandidate(env.context, 'peer'),
|
|
21645
21652
|
]);
|
|
21646
|
-
|
|
21647
|
-
for (
|
|
21653
|
+
const classNamesWithOrder = [];
|
|
21654
|
+
for (const className of classes) {
|
|
21648
21655
|
let order = env
|
|
21649
21656
|
.generateRules(new Set([className]), env.context)
|
|
21650
21657
|
.sort(([a], [z]) => bigSign(z - a))[0]?.[0] ?? null;
|
|
@@ -21662,7 +21669,7 @@ function reorderClasses(classList, { env }) {
|
|
|
21662
21669
|
if (!env.context) {
|
|
21663
21670
|
return classList.map(name => [name, null]);
|
|
21664
21671
|
}
|
|
21665
|
-
|
|
21672
|
+
const orderedClasses = env.context.getClassOrder
|
|
21666
21673
|
? env.context.getClassOrder(classList)
|
|
21667
21674
|
: getClassOrderPolyfill(classList, { env });
|
|
21668
21675
|
return orderedClasses.sort(([nameA, a], [nameZ, z]) => {
|
|
@@ -21698,8 +21705,8 @@ function sortClasses(classStr, { env, ignoreFirst = false, ignoreLast = false, r
|
|
|
21698
21705
|
return ' ';
|
|
21699
21706
|
}
|
|
21700
21707
|
let result = '';
|
|
21701
|
-
|
|
21702
|
-
|
|
21708
|
+
const parts = classStr.split(/([\t\r\f\n ]+)/);
|
|
21709
|
+
const classes = parts.filter((_, i) => i % 2 === 0);
|
|
21703
21710
|
let whitespace = parts.filter((_, i) => i % 2 !== 0);
|
|
21704
21711
|
if (classes[classes.length - 1] === '') {
|
|
21705
21712
|
classes.pop();
|
|
@@ -21715,7 +21722,7 @@ function sortClasses(classStr, { env, ignoreFirst = false, ignoreLast = false, r
|
|
|
21715
21722
|
if (ignoreLast) {
|
|
21716
21723
|
suffix = `${whitespace.pop() ?? ''}${classes.pop() ?? ''}`;
|
|
21717
21724
|
}
|
|
21718
|
-
|
|
21725
|
+
const { classList, removedIndices } = sortClassList(classes, {
|
|
21719
21726
|
env,
|
|
21720
21727
|
removeDuplicates,
|
|
21721
21728
|
});
|
|
@@ -21740,9 +21747,9 @@ function sortClassList(classList, { env, removeDuplicates, }) {
|
|
|
21740
21747
|
if (env.options.tailwindPreserveDuplicates) {
|
|
21741
21748
|
removeDuplicates = false;
|
|
21742
21749
|
}
|
|
21743
|
-
|
|
21750
|
+
const removedIndices = new Set();
|
|
21744
21751
|
if (removeDuplicates) {
|
|
21745
|
-
|
|
21752
|
+
const seenClasses = new Set();
|
|
21746
21753
|
orderedClasses = orderedClasses.filter(([cls, order], index) => {
|
|
21747
21754
|
if (seenClasses.has(cls)) {
|
|
21748
21755
|
removedIndices.add(index);
|