oxlint-tailwindcss 0.5.0 → 0.6.1
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 +24 -5
- package/dist/index.cjs +233 -4
- package/dist/index.mjs +233 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -145,6 +145,20 @@ For slow environments (large monorepos, CI), you can increase the design system
|
|
|
145
145
|
}
|
|
146
146
|
```
|
|
147
147
|
|
|
148
|
+
### Root font size
|
|
149
|
+
|
|
150
|
+
The `enforce-canonical` rule converts px-based arbitrary values to named classes (e.g. `p-[2px]` → `p-0.5`). This conversion depends on the root font size:
|
|
151
|
+
|
|
152
|
+
```jsonc
|
|
153
|
+
{
|
|
154
|
+
"settings": {
|
|
155
|
+
"tailwindcss": {
|
|
156
|
+
"rootFontSize": 16, // pixels (default: 16)
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
148
162
|
### Debug logging
|
|
149
163
|
|
|
150
164
|
To see which design system is used for each file, enable debug mode:
|
|
@@ -447,15 +461,20 @@ Only flags when the exact same utility exists both as base and with a conditiona
|
|
|
447
461
|
|
|
448
462
|
#### `enforce-canonical`
|
|
449
463
|
|
|
450
|
-
|
|
464
|
+
Enforces canonical Tailwind CSS class names. Uses `canonicalizeCandidates()` from the Tailwind CSS engine dynamically — the same API that powers Tailwind CSS IntelliSense's `suggestCanonicalClasses`.
|
|
451
465
|
|
|
452
466
|
```tsx
|
|
453
467
|
// ❌ Bad → ✅ Fixed
|
|
454
|
-
"-m-0"
|
|
455
|
-
"-mt-0"
|
|
456
|
-
"
|
|
468
|
+
"-m-0" → "m-0"
|
|
469
|
+
"-mt-0" → "mt-0"
|
|
470
|
+
"p-[2px]" → "p-0.5"
|
|
471
|
+
"max-w-[400px]" → "max-w-100"
|
|
472
|
+
"text-[var(--color-text)]/90" → "text-(--color-text)/90"
|
|
473
|
+
"[--w-padding:theme(spacing.1)]" → "[--w-padding:--spacing(1)]"
|
|
457
474
|
```
|
|
458
475
|
|
|
476
|
+
The px→named conversion (e.g. `p-[2px]` → `p-0.5`) depends on `rootFontSize` (default: 16).
|
|
477
|
+
|
|
459
478
|
**Requires design system.** **Autofix:** Replaces with canonical form.
|
|
460
479
|
|
|
461
480
|
---
|
|
@@ -633,7 +652,7 @@ Does NOT convert complex expressions — only simple `var(--name)` wrappers:
|
|
|
633
652
|
|
|
634
653
|
Enforces a consistent order for variant prefixes.
|
|
635
654
|
|
|
636
|
-
Uses the design system's variant order when available, falls back to a sensible static default. Only checks classes with 2+ variants.
|
|
655
|
+
Uses the design system's variant order when available, falls back to a sensible static default. Only checks classes with 2+ variants. Pseudo-element variants (`before:`, `after:`, `placeholder:`, etc.) are always kept innermost (closest to the utility) regardless of the ordering source — placing them before element-selecting variants like `[&>svg]:` or `has-[.active]:` produces broken CSS in Tailwind v4.
|
|
637
656
|
|
|
638
657
|
**Options:**
|
|
639
658
|
|
package/dist/index.cjs
CHANGED
|
@@ -1338,6 +1338,17 @@ function commonPrefixLength(a, b) {
|
|
|
1338
1338
|
return i;
|
|
1339
1339
|
}
|
|
1340
1340
|
/**
|
|
1341
|
+
* Extracts `rootFontSize` from `context.settings.tailwindcss` (default: 16).
|
|
1342
|
+
*/
|
|
1343
|
+
function rootFontSizeFromSettings(settings) {
|
|
1344
|
+
const tw = settings?.tailwindcss;
|
|
1345
|
+
if (tw && typeof tw === "object" && "rootFontSize" in tw) {
|
|
1346
|
+
const v = tw.rootFontSize;
|
|
1347
|
+
if (typeof v === "number" && v > 0) return v;
|
|
1348
|
+
}
|
|
1349
|
+
return 16;
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
1341
1352
|
* Extracts `timeout` from `context.settings.tailwindcss`.
|
|
1342
1353
|
*/
|
|
1343
1354
|
function timeoutFromSettings(settings) {
|
|
@@ -1478,6 +1489,19 @@ function safeOptions(context) {
|
|
|
1478
1489
|
return;
|
|
1479
1490
|
}
|
|
1480
1491
|
}
|
|
1492
|
+
/**
|
|
1493
|
+
* Safely read context.settings.
|
|
1494
|
+
*
|
|
1495
|
+
* Like `safeOptions`, `context.settings` may not be accessible in `createOnce()`.
|
|
1496
|
+
* The try/catch handles that gracefully.
|
|
1497
|
+
*/
|
|
1498
|
+
function safeSettings(context) {
|
|
1499
|
+
try {
|
|
1500
|
+
return context.settings ?? void 0;
|
|
1501
|
+
} catch {
|
|
1502
|
+
return;
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1481
1505
|
//#endregion
|
|
1482
1506
|
//#region src/rules/no-deprecated-classes.ts
|
|
1483
1507
|
const DEPRECATED_MAP = {
|
|
@@ -1778,7 +1802,187 @@ const noConflictingClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1778
1802
|
}
|
|
1779
1803
|
});
|
|
1780
1804
|
//#endregion
|
|
1805
|
+
//#region src/design-system/canonicalize-service.ts
|
|
1806
|
+
/**
|
|
1807
|
+
* Persistent canonicalize service using worker_threads + SharedArrayBuffer.
|
|
1808
|
+
*
|
|
1809
|
+
* Calls `ds.canonicalizeCandidates(classes, { rem })` dynamically via a worker
|
|
1810
|
+
* thread. Same pattern as sort-service.ts — loads the DS once, then accepts
|
|
1811
|
+
* requests synchronously via Atomics.wait().
|
|
1812
|
+
*
|
|
1813
|
+
* This enables canonicalization of arbitrary user classes (e.g. `p-[2px]` → `p-0.5`)
|
|
1814
|
+
* which can't be precomputed because the input space is infinite.
|
|
1815
|
+
*/
|
|
1816
|
+
const BUFFER_SIZE$1 = 4 * 1024 * 1024;
|
|
1817
|
+
const HEADER_INTS$1 = 4;
|
|
1818
|
+
const DATA_OFFSET$1 = HEADER_INTS$1 * 4 + 4;
|
|
1819
|
+
const INIT_TIMEOUT$1 = 3e4;
|
|
1820
|
+
const REQUEST_TIMEOUT$1 = 1e4;
|
|
1821
|
+
const WORKER_SCRIPT$1 = `
|
|
1822
|
+
const { workerData } = require('worker_threads');
|
|
1823
|
+
|
|
1824
|
+
async function main() {
|
|
1825
|
+
const { sharedBuffer, cssPath } = workerData;
|
|
1826
|
+
const control = new Int32Array(sharedBuffer, 0, ${HEADER_INTS$1});
|
|
1827
|
+
const lengthView = new DataView(sharedBuffer, ${HEADER_INTS$1 * 4}, 4);
|
|
1828
|
+
const dataArea = new Uint8Array(sharedBuffer, ${DATA_OFFSET$1});
|
|
1829
|
+
|
|
1830
|
+
let ds;
|
|
1831
|
+
try {
|
|
1832
|
+
const { __unstable__loadDesignSystem } = require(workerData.tailwindNodePath);
|
|
1833
|
+
const { readFileSync } = require('fs');
|
|
1834
|
+
const { dirname } = require('path');
|
|
1835
|
+
const css = readFileSync(cssPath, 'utf-8');
|
|
1836
|
+
ds = await __unstable__loadDesignSystem(css, { base: dirname(cssPath) });
|
|
1837
|
+
} catch {
|
|
1838
|
+
Atomics.store(control, 2, -1);
|
|
1839
|
+
Atomics.notify(control, 2);
|
|
1840
|
+
return;
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
// Signal ready
|
|
1844
|
+
Atomics.store(control, 2, 1);
|
|
1845
|
+
Atomics.notify(control, 2);
|
|
1846
|
+
|
|
1847
|
+
// Request loop
|
|
1848
|
+
while (true) {
|
|
1849
|
+
Atomics.wait(control, 0, 0);
|
|
1850
|
+
|
|
1851
|
+
const len = lengthView.getUint32(0);
|
|
1852
|
+
const requestStr = Buffer.from(dataArea.slice(0, len)).toString('utf-8');
|
|
1853
|
+
Atomics.store(control, 0, 0);
|
|
1854
|
+
|
|
1855
|
+
let response;
|
|
1856
|
+
try {
|
|
1857
|
+
const { classes, rem } = JSON.parse(requestStr);
|
|
1858
|
+
const options = rem ? { rem } : undefined;
|
|
1859
|
+
const result = ds.canonicalizeCandidates(classes, options);
|
|
1860
|
+
response = Buffer.from(JSON.stringify(result), 'utf-8');
|
|
1861
|
+
} catch {
|
|
1862
|
+
response = Buffer.from('null', 'utf-8');
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1865
|
+
dataArea.set(response, 0);
|
|
1866
|
+
lengthView.setUint32(0, response.length);
|
|
1867
|
+
|
|
1868
|
+
Atomics.store(control, 1, 1);
|
|
1869
|
+
Atomics.notify(control, 1);
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
main();
|
|
1873
|
+
`;
|
|
1874
|
+
let worker$1 = null;
|
|
1875
|
+
let controlArray$1 = null;
|
|
1876
|
+
let lengthView$1 = null;
|
|
1877
|
+
let dataArea$1 = null;
|
|
1878
|
+
let initialized$1 = false;
|
|
1879
|
+
let available$1 = true;
|
|
1880
|
+
let currentCssPath$1 = null;
|
|
1881
|
+
function ensureService$1(cssPath) {
|
|
1882
|
+
if (initialized$1 && currentCssPath$1 === cssPath) return available$1;
|
|
1883
|
+
if (initialized$1) {
|
|
1884
|
+
cleanup$1();
|
|
1885
|
+
initialized$1 = false;
|
|
1886
|
+
available$1 = true;
|
|
1887
|
+
controlArray$1 = null;
|
|
1888
|
+
lengthView$1 = null;
|
|
1889
|
+
dataArea$1 = null;
|
|
1890
|
+
}
|
|
1891
|
+
initialized$1 = true;
|
|
1892
|
+
currentCssPath$1 = cssPath;
|
|
1893
|
+
try {
|
|
1894
|
+
const tailwindNodePath = require.resolve("@tailwindcss/node");
|
|
1895
|
+
const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE$1);
|
|
1896
|
+
controlArray$1 = new Int32Array(sharedBuffer, 0, HEADER_INTS$1);
|
|
1897
|
+
lengthView$1 = new DataView(sharedBuffer, HEADER_INTS$1 * 4, 4);
|
|
1898
|
+
dataArea$1 = new Uint8Array(sharedBuffer, DATA_OFFSET$1);
|
|
1899
|
+
worker$1 = new node_worker_threads.Worker(WORKER_SCRIPT$1, {
|
|
1900
|
+
eval: true,
|
|
1901
|
+
workerData: {
|
|
1902
|
+
sharedBuffer,
|
|
1903
|
+
cssPath,
|
|
1904
|
+
tailwindNodePath
|
|
1905
|
+
}
|
|
1906
|
+
});
|
|
1907
|
+
worker$1.unref();
|
|
1908
|
+
worker$1.on("error", () => {
|
|
1909
|
+
available$1 = false;
|
|
1910
|
+
worker$1 = null;
|
|
1911
|
+
});
|
|
1912
|
+
worker$1.on("exit", () => {
|
|
1913
|
+
worker$1 = null;
|
|
1914
|
+
});
|
|
1915
|
+
if (Atomics.wait(controlArray$1, 2, 0, INIT_TIMEOUT$1) === "timed-out" || controlArray$1[2] === -1) {
|
|
1916
|
+
available$1 = false;
|
|
1917
|
+
cleanup$1();
|
|
1918
|
+
return false;
|
|
1919
|
+
}
|
|
1920
|
+
process.on("exit", cleanup$1);
|
|
1921
|
+
return true;
|
|
1922
|
+
} catch {
|
|
1923
|
+
available$1 = false;
|
|
1924
|
+
cleanup$1();
|
|
1925
|
+
return false;
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
function cleanup$1() {
|
|
1929
|
+
if (worker$1) {
|
|
1930
|
+
try {
|
|
1931
|
+
worker$1.terminate();
|
|
1932
|
+
} catch {}
|
|
1933
|
+
worker$1 = null;
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
/**
|
|
1937
|
+
* Canonicalize classes using the Tailwind CSS design system via worker thread.
|
|
1938
|
+
* Returns the canonicalized class array, or null if the service is unavailable.
|
|
1939
|
+
*/
|
|
1940
|
+
function canonicalizeClassesSync(cssPath, classes, rem) {
|
|
1941
|
+
if (!ensureService$1(cssPath)) return null;
|
|
1942
|
+
if (!controlArray$1 || !dataArea$1 || !lengthView$1) return null;
|
|
1943
|
+
try {
|
|
1944
|
+
const request = Buffer.from(JSON.stringify({
|
|
1945
|
+
classes,
|
|
1946
|
+
rem
|
|
1947
|
+
}), "utf-8");
|
|
1948
|
+
if (request.length > BUFFER_SIZE$1 - DATA_OFFSET$1) return null;
|
|
1949
|
+
dataArea$1.set(request, 0);
|
|
1950
|
+
lengthView$1.setUint32(0, request.length);
|
|
1951
|
+
Atomics.store(controlArray$1, 0, 1);
|
|
1952
|
+
Atomics.notify(controlArray$1, 0);
|
|
1953
|
+
if (Atomics.wait(controlArray$1, 1, 0, REQUEST_TIMEOUT$1) === "timed-out") {
|
|
1954
|
+
available$1 = false;
|
|
1955
|
+
cleanup$1();
|
|
1956
|
+
return null;
|
|
1957
|
+
}
|
|
1958
|
+
const responseLen = lengthView$1.getUint32(0);
|
|
1959
|
+
const responseStr = Buffer.from(dataArea$1.slice(0, responseLen)).toString("utf-8");
|
|
1960
|
+
Atomics.store(controlArray$1, 1, 0);
|
|
1961
|
+
return JSON.parse(responseStr);
|
|
1962
|
+
} catch {
|
|
1963
|
+
available$1 = false;
|
|
1964
|
+
cleanup$1();
|
|
1965
|
+
return null;
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
//#endregion
|
|
1781
1969
|
//#region src/rules/enforce-canonical.ts
|
|
1970
|
+
/**
|
|
1971
|
+
* Preserve the user's ! position after canonicalization.
|
|
1972
|
+
* canonicalizeCandidates always normalizes ! to suffix, but
|
|
1973
|
+
* enforce-consistent-important-position handles that separately.
|
|
1974
|
+
*/
|
|
1975
|
+
function preserveImportantPosition(original, canonicalized) {
|
|
1976
|
+
const origHasPrefix = original.startsWith("!") || /^[a-z0-9[\]*@-]*:!/.test(original);
|
|
1977
|
+
const origHasSuffix = original.endsWith("!") && !origHasPrefix;
|
|
1978
|
+
if (!origHasPrefix && !origHasSuffix) return canonicalized.replace(/!/g, "");
|
|
1979
|
+
const bare = canonicalized.replace(/!/g, "");
|
|
1980
|
+
if (origHasPrefix) {
|
|
1981
|
+
const variantPrefix = bare.slice(0, bare.length - bare.replace(/^[a-z0-9[\]*@-]*:/g, "").length);
|
|
1982
|
+
return variantPrefix + "!" + bare.slice(variantPrefix.length);
|
|
1983
|
+
}
|
|
1984
|
+
return bare + "!";
|
|
1985
|
+
}
|
|
1782
1986
|
const enforceCanonical = (0, _oxlint_plugins.defineRule)({
|
|
1783
1987
|
meta: {
|
|
1784
1988
|
type: "suggestion",
|
|
@@ -1797,13 +2001,21 @@ const enforceCanonical = (0, _oxlint_plugins.defineRule)({
|
|
|
1797
2001
|
},
|
|
1798
2002
|
createOnce(context) {
|
|
1799
2003
|
const getDS = createLazyLoader(context);
|
|
2004
|
+
let _rem = null;
|
|
2005
|
+
function getRem() {
|
|
2006
|
+
if (_rem === null) _rem = rootFontSizeFromSettings(safeSettings(context));
|
|
2007
|
+
return _rem;
|
|
2008
|
+
}
|
|
1800
2009
|
function check(locations) {
|
|
1801
2010
|
const ds = getDS();
|
|
1802
2011
|
if (!ds) return;
|
|
1803
|
-
const { cache } = ds;
|
|
2012
|
+
const { cache, entryPoint } = ds;
|
|
1804
2013
|
for (const loc of locations) {
|
|
1805
2014
|
const classes = splitClasses(loc.value);
|
|
1806
|
-
const
|
|
2015
|
+
const dynamic = canonicalizeClassesSync(entryPoint, classes, getRem());
|
|
2016
|
+
let canonicals;
|
|
2017
|
+
if (dynamic) canonicals = classes.map((cls, i) => preserveImportantPosition(cls, dynamic[i]));
|
|
2018
|
+
else canonicals = classes.map((cls) => cache.canonicalize(cls));
|
|
1807
2019
|
let firstNonCanonical = true;
|
|
1808
2020
|
for (let i = 0; i < classes.length; i++) {
|
|
1809
2021
|
const cls = classes[i];
|
|
@@ -3113,6 +3325,18 @@ const noContradictingVariants = (0, _oxlint_plugins.defineRule)({
|
|
|
3113
3325
|
});
|
|
3114
3326
|
//#endregion
|
|
3115
3327
|
//#region src/rules/consistent-variant-order.ts
|
|
3328
|
+
const PSEUDO_ELEMENTS = new Set([
|
|
3329
|
+
"before",
|
|
3330
|
+
"after",
|
|
3331
|
+
"file",
|
|
3332
|
+
"placeholder",
|
|
3333
|
+
"selection",
|
|
3334
|
+
"marker",
|
|
3335
|
+
"backdrop",
|
|
3336
|
+
"first-line",
|
|
3337
|
+
"first-letter",
|
|
3338
|
+
"details-content"
|
|
3339
|
+
]);
|
|
3116
3340
|
const DEFAULT_VARIANT_ORDER = [
|
|
3117
3341
|
"*",
|
|
3118
3342
|
"**",
|
|
@@ -3258,9 +3482,14 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
3258
3482
|
const variants = extractVariants(cls);
|
|
3259
3483
|
if (variants.length < 2) return null;
|
|
3260
3484
|
const sorted = [...variants].sort((a, b) => getVariantPriority(a) - getVariantPriority(b));
|
|
3261
|
-
|
|
3485
|
+
const nonPseudo = [];
|
|
3486
|
+
const pseudo = [];
|
|
3487
|
+
for (const v of sorted) if (PSEUDO_ELEMENTS.has(v)) pseudo.push(v);
|
|
3488
|
+
else nonPseudo.push(v);
|
|
3489
|
+
const final = nonPseudo.length > 0 && pseudo.length > 0 ? [...nonPseudo, ...pseudo] : sorted;
|
|
3490
|
+
if (variants.every((v, i) => v === final[i])) return null;
|
|
3262
3491
|
const utility = extractUtility(cls);
|
|
3263
|
-
return
|
|
3492
|
+
return final.join(":") + ":" + utility;
|
|
3264
3493
|
}
|
|
3265
3494
|
function check(locations) {
|
|
3266
3495
|
for (const loc of locations) {
|
package/dist/index.mjs
CHANGED
|
@@ -1342,6 +1342,17 @@ function commonPrefixLength(a, b) {
|
|
|
1342
1342
|
return i;
|
|
1343
1343
|
}
|
|
1344
1344
|
/**
|
|
1345
|
+
* Extracts `rootFontSize` from `context.settings.tailwindcss` (default: 16).
|
|
1346
|
+
*/
|
|
1347
|
+
function rootFontSizeFromSettings(settings) {
|
|
1348
|
+
const tw = settings?.tailwindcss;
|
|
1349
|
+
if (tw && typeof tw === "object" && "rootFontSize" in tw) {
|
|
1350
|
+
const v = tw.rootFontSize;
|
|
1351
|
+
if (typeof v === "number" && v > 0) return v;
|
|
1352
|
+
}
|
|
1353
|
+
return 16;
|
|
1354
|
+
}
|
|
1355
|
+
/**
|
|
1345
1356
|
* Extracts `timeout` from `context.settings.tailwindcss`.
|
|
1346
1357
|
*/
|
|
1347
1358
|
function timeoutFromSettings(settings) {
|
|
@@ -1482,6 +1493,19 @@ function safeOptions(context) {
|
|
|
1482
1493
|
return;
|
|
1483
1494
|
}
|
|
1484
1495
|
}
|
|
1496
|
+
/**
|
|
1497
|
+
* Safely read context.settings.
|
|
1498
|
+
*
|
|
1499
|
+
* Like `safeOptions`, `context.settings` may not be accessible in `createOnce()`.
|
|
1500
|
+
* The try/catch handles that gracefully.
|
|
1501
|
+
*/
|
|
1502
|
+
function safeSettings(context) {
|
|
1503
|
+
try {
|
|
1504
|
+
return context.settings ?? void 0;
|
|
1505
|
+
} catch {
|
|
1506
|
+
return;
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1485
1509
|
//#endregion
|
|
1486
1510
|
//#region src/rules/no-deprecated-classes.ts
|
|
1487
1511
|
const DEPRECATED_MAP = {
|
|
@@ -1782,7 +1806,187 @@ const noConflictingClasses = defineRule({
|
|
|
1782
1806
|
}
|
|
1783
1807
|
});
|
|
1784
1808
|
//#endregion
|
|
1809
|
+
//#region src/design-system/canonicalize-service.ts
|
|
1810
|
+
/**
|
|
1811
|
+
* Persistent canonicalize service using worker_threads + SharedArrayBuffer.
|
|
1812
|
+
*
|
|
1813
|
+
* Calls `ds.canonicalizeCandidates(classes, { rem })` dynamically via a worker
|
|
1814
|
+
* thread. Same pattern as sort-service.ts — loads the DS once, then accepts
|
|
1815
|
+
* requests synchronously via Atomics.wait().
|
|
1816
|
+
*
|
|
1817
|
+
* This enables canonicalization of arbitrary user classes (e.g. `p-[2px]` → `p-0.5`)
|
|
1818
|
+
* which can't be precomputed because the input space is infinite.
|
|
1819
|
+
*/
|
|
1820
|
+
const BUFFER_SIZE$1 = 4 * 1024 * 1024;
|
|
1821
|
+
const HEADER_INTS$1 = 4;
|
|
1822
|
+
const DATA_OFFSET$1 = HEADER_INTS$1 * 4 + 4;
|
|
1823
|
+
const INIT_TIMEOUT$1 = 3e4;
|
|
1824
|
+
const REQUEST_TIMEOUT$1 = 1e4;
|
|
1825
|
+
const WORKER_SCRIPT$1 = `
|
|
1826
|
+
const { workerData } = require('worker_threads');
|
|
1827
|
+
|
|
1828
|
+
async function main() {
|
|
1829
|
+
const { sharedBuffer, cssPath } = workerData;
|
|
1830
|
+
const control = new Int32Array(sharedBuffer, 0, ${HEADER_INTS$1});
|
|
1831
|
+
const lengthView = new DataView(sharedBuffer, ${HEADER_INTS$1 * 4}, 4);
|
|
1832
|
+
const dataArea = new Uint8Array(sharedBuffer, ${DATA_OFFSET$1});
|
|
1833
|
+
|
|
1834
|
+
let ds;
|
|
1835
|
+
try {
|
|
1836
|
+
const { __unstable__loadDesignSystem } = require(workerData.tailwindNodePath);
|
|
1837
|
+
const { readFileSync } = require('fs');
|
|
1838
|
+
const { dirname } = require('path');
|
|
1839
|
+
const css = readFileSync(cssPath, 'utf-8');
|
|
1840
|
+
ds = await __unstable__loadDesignSystem(css, { base: dirname(cssPath) });
|
|
1841
|
+
} catch {
|
|
1842
|
+
Atomics.store(control, 2, -1);
|
|
1843
|
+
Atomics.notify(control, 2);
|
|
1844
|
+
return;
|
|
1845
|
+
}
|
|
1846
|
+
|
|
1847
|
+
// Signal ready
|
|
1848
|
+
Atomics.store(control, 2, 1);
|
|
1849
|
+
Atomics.notify(control, 2);
|
|
1850
|
+
|
|
1851
|
+
// Request loop
|
|
1852
|
+
while (true) {
|
|
1853
|
+
Atomics.wait(control, 0, 0);
|
|
1854
|
+
|
|
1855
|
+
const len = lengthView.getUint32(0);
|
|
1856
|
+
const requestStr = Buffer.from(dataArea.slice(0, len)).toString('utf-8');
|
|
1857
|
+
Atomics.store(control, 0, 0);
|
|
1858
|
+
|
|
1859
|
+
let response;
|
|
1860
|
+
try {
|
|
1861
|
+
const { classes, rem } = JSON.parse(requestStr);
|
|
1862
|
+
const options = rem ? { rem } : undefined;
|
|
1863
|
+
const result = ds.canonicalizeCandidates(classes, options);
|
|
1864
|
+
response = Buffer.from(JSON.stringify(result), 'utf-8');
|
|
1865
|
+
} catch {
|
|
1866
|
+
response = Buffer.from('null', 'utf-8');
|
|
1867
|
+
}
|
|
1868
|
+
|
|
1869
|
+
dataArea.set(response, 0);
|
|
1870
|
+
lengthView.setUint32(0, response.length);
|
|
1871
|
+
|
|
1872
|
+
Atomics.store(control, 1, 1);
|
|
1873
|
+
Atomics.notify(control, 1);
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
main();
|
|
1877
|
+
`;
|
|
1878
|
+
let worker$1 = null;
|
|
1879
|
+
let controlArray$1 = null;
|
|
1880
|
+
let lengthView$1 = null;
|
|
1881
|
+
let dataArea$1 = null;
|
|
1882
|
+
let initialized$1 = false;
|
|
1883
|
+
let available$1 = true;
|
|
1884
|
+
let currentCssPath$1 = null;
|
|
1885
|
+
function ensureService$1(cssPath) {
|
|
1886
|
+
if (initialized$1 && currentCssPath$1 === cssPath) return available$1;
|
|
1887
|
+
if (initialized$1) {
|
|
1888
|
+
cleanup$1();
|
|
1889
|
+
initialized$1 = false;
|
|
1890
|
+
available$1 = true;
|
|
1891
|
+
controlArray$1 = null;
|
|
1892
|
+
lengthView$1 = null;
|
|
1893
|
+
dataArea$1 = null;
|
|
1894
|
+
}
|
|
1895
|
+
initialized$1 = true;
|
|
1896
|
+
currentCssPath$1 = cssPath;
|
|
1897
|
+
try {
|
|
1898
|
+
const tailwindNodePath = __require.resolve("@tailwindcss/node");
|
|
1899
|
+
const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE$1);
|
|
1900
|
+
controlArray$1 = new Int32Array(sharedBuffer, 0, HEADER_INTS$1);
|
|
1901
|
+
lengthView$1 = new DataView(sharedBuffer, HEADER_INTS$1 * 4, 4);
|
|
1902
|
+
dataArea$1 = new Uint8Array(sharedBuffer, DATA_OFFSET$1);
|
|
1903
|
+
worker$1 = new Worker(WORKER_SCRIPT$1, {
|
|
1904
|
+
eval: true,
|
|
1905
|
+
workerData: {
|
|
1906
|
+
sharedBuffer,
|
|
1907
|
+
cssPath,
|
|
1908
|
+
tailwindNodePath
|
|
1909
|
+
}
|
|
1910
|
+
});
|
|
1911
|
+
worker$1.unref();
|
|
1912
|
+
worker$1.on("error", () => {
|
|
1913
|
+
available$1 = false;
|
|
1914
|
+
worker$1 = null;
|
|
1915
|
+
});
|
|
1916
|
+
worker$1.on("exit", () => {
|
|
1917
|
+
worker$1 = null;
|
|
1918
|
+
});
|
|
1919
|
+
if (Atomics.wait(controlArray$1, 2, 0, INIT_TIMEOUT$1) === "timed-out" || controlArray$1[2] === -1) {
|
|
1920
|
+
available$1 = false;
|
|
1921
|
+
cleanup$1();
|
|
1922
|
+
return false;
|
|
1923
|
+
}
|
|
1924
|
+
process.on("exit", cleanup$1);
|
|
1925
|
+
return true;
|
|
1926
|
+
} catch {
|
|
1927
|
+
available$1 = false;
|
|
1928
|
+
cleanup$1();
|
|
1929
|
+
return false;
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
function cleanup$1() {
|
|
1933
|
+
if (worker$1) {
|
|
1934
|
+
try {
|
|
1935
|
+
worker$1.terminate();
|
|
1936
|
+
} catch {}
|
|
1937
|
+
worker$1 = null;
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
/**
|
|
1941
|
+
* Canonicalize classes using the Tailwind CSS design system via worker thread.
|
|
1942
|
+
* Returns the canonicalized class array, or null if the service is unavailable.
|
|
1943
|
+
*/
|
|
1944
|
+
function canonicalizeClassesSync(cssPath, classes, rem) {
|
|
1945
|
+
if (!ensureService$1(cssPath)) return null;
|
|
1946
|
+
if (!controlArray$1 || !dataArea$1 || !lengthView$1) return null;
|
|
1947
|
+
try {
|
|
1948
|
+
const request = Buffer.from(JSON.stringify({
|
|
1949
|
+
classes,
|
|
1950
|
+
rem
|
|
1951
|
+
}), "utf-8");
|
|
1952
|
+
if (request.length > BUFFER_SIZE$1 - DATA_OFFSET$1) return null;
|
|
1953
|
+
dataArea$1.set(request, 0);
|
|
1954
|
+
lengthView$1.setUint32(0, request.length);
|
|
1955
|
+
Atomics.store(controlArray$1, 0, 1);
|
|
1956
|
+
Atomics.notify(controlArray$1, 0);
|
|
1957
|
+
if (Atomics.wait(controlArray$1, 1, 0, REQUEST_TIMEOUT$1) === "timed-out") {
|
|
1958
|
+
available$1 = false;
|
|
1959
|
+
cleanup$1();
|
|
1960
|
+
return null;
|
|
1961
|
+
}
|
|
1962
|
+
const responseLen = lengthView$1.getUint32(0);
|
|
1963
|
+
const responseStr = Buffer.from(dataArea$1.slice(0, responseLen)).toString("utf-8");
|
|
1964
|
+
Atomics.store(controlArray$1, 1, 0);
|
|
1965
|
+
return JSON.parse(responseStr);
|
|
1966
|
+
} catch {
|
|
1967
|
+
available$1 = false;
|
|
1968
|
+
cleanup$1();
|
|
1969
|
+
return null;
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
//#endregion
|
|
1785
1973
|
//#region src/rules/enforce-canonical.ts
|
|
1974
|
+
/**
|
|
1975
|
+
* Preserve the user's ! position after canonicalization.
|
|
1976
|
+
* canonicalizeCandidates always normalizes ! to suffix, but
|
|
1977
|
+
* enforce-consistent-important-position handles that separately.
|
|
1978
|
+
*/
|
|
1979
|
+
function preserveImportantPosition(original, canonicalized) {
|
|
1980
|
+
const origHasPrefix = original.startsWith("!") || /^[a-z0-9[\]*@-]*:!/.test(original);
|
|
1981
|
+
const origHasSuffix = original.endsWith("!") && !origHasPrefix;
|
|
1982
|
+
if (!origHasPrefix && !origHasSuffix) return canonicalized.replace(/!/g, "");
|
|
1983
|
+
const bare = canonicalized.replace(/!/g, "");
|
|
1984
|
+
if (origHasPrefix) {
|
|
1985
|
+
const variantPrefix = bare.slice(0, bare.length - bare.replace(/^[a-z0-9[\]*@-]*:/g, "").length);
|
|
1986
|
+
return variantPrefix + "!" + bare.slice(variantPrefix.length);
|
|
1987
|
+
}
|
|
1988
|
+
return bare + "!";
|
|
1989
|
+
}
|
|
1786
1990
|
const enforceCanonical = defineRule({
|
|
1787
1991
|
meta: {
|
|
1788
1992
|
type: "suggestion",
|
|
@@ -1801,13 +2005,21 @@ const enforceCanonical = defineRule({
|
|
|
1801
2005
|
},
|
|
1802
2006
|
createOnce(context) {
|
|
1803
2007
|
const getDS = createLazyLoader(context);
|
|
2008
|
+
let _rem = null;
|
|
2009
|
+
function getRem() {
|
|
2010
|
+
if (_rem === null) _rem = rootFontSizeFromSettings(safeSettings(context));
|
|
2011
|
+
return _rem;
|
|
2012
|
+
}
|
|
1804
2013
|
function check(locations) {
|
|
1805
2014
|
const ds = getDS();
|
|
1806
2015
|
if (!ds) return;
|
|
1807
|
-
const { cache } = ds;
|
|
2016
|
+
const { cache, entryPoint } = ds;
|
|
1808
2017
|
for (const loc of locations) {
|
|
1809
2018
|
const classes = splitClasses(loc.value);
|
|
1810
|
-
const
|
|
2019
|
+
const dynamic = canonicalizeClassesSync(entryPoint, classes, getRem());
|
|
2020
|
+
let canonicals;
|
|
2021
|
+
if (dynamic) canonicals = classes.map((cls, i) => preserveImportantPosition(cls, dynamic[i]));
|
|
2022
|
+
else canonicals = classes.map((cls) => cache.canonicalize(cls));
|
|
1811
2023
|
let firstNonCanonical = true;
|
|
1812
2024
|
for (let i = 0; i < classes.length; i++) {
|
|
1813
2025
|
const cls = classes[i];
|
|
@@ -3117,6 +3329,18 @@ const noContradictingVariants = defineRule({
|
|
|
3117
3329
|
});
|
|
3118
3330
|
//#endregion
|
|
3119
3331
|
//#region src/rules/consistent-variant-order.ts
|
|
3332
|
+
const PSEUDO_ELEMENTS = new Set([
|
|
3333
|
+
"before",
|
|
3334
|
+
"after",
|
|
3335
|
+
"file",
|
|
3336
|
+
"placeholder",
|
|
3337
|
+
"selection",
|
|
3338
|
+
"marker",
|
|
3339
|
+
"backdrop",
|
|
3340
|
+
"first-line",
|
|
3341
|
+
"first-letter",
|
|
3342
|
+
"details-content"
|
|
3343
|
+
]);
|
|
3120
3344
|
const DEFAULT_VARIANT_ORDER = [
|
|
3121
3345
|
"*",
|
|
3122
3346
|
"**",
|
|
@@ -3262,9 +3486,14 @@ const consistentVariantOrder = defineRule({
|
|
|
3262
3486
|
const variants = extractVariants(cls);
|
|
3263
3487
|
if (variants.length < 2) return null;
|
|
3264
3488
|
const sorted = [...variants].sort((a, b) => getVariantPriority(a) - getVariantPriority(b));
|
|
3265
|
-
|
|
3489
|
+
const nonPseudo = [];
|
|
3490
|
+
const pseudo = [];
|
|
3491
|
+
for (const v of sorted) if (PSEUDO_ELEMENTS.has(v)) pseudo.push(v);
|
|
3492
|
+
else nonPseudo.push(v);
|
|
3493
|
+
const final = nonPseudo.length > 0 && pseudo.length > 0 ? [...nonPseudo, ...pseudo] : sorted;
|
|
3494
|
+
if (variants.every((v, i) => v === final[i])) return null;
|
|
3266
3495
|
const utility = extractUtility(cls);
|
|
3267
|
-
return
|
|
3496
|
+
return final.join(":") + ":" + utility;
|
|
3268
3497
|
}
|
|
3269
3498
|
function check(locations) {
|
|
3270
3499
|
for (const loc of locations) {
|