oxlint-tailwindcss 1.12.0 → 1.13.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/README.md +27 -7
- package/dist/index.cjs +59 -14
- package/dist/index.mjs +59 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,7 +35,8 @@ Read the story behind this plugin:
|
|
|
35
35
|
- **Variable detection** — Lints variables matching `/^classNames?$/`, `/^classes$/`, `/^styles?$/`
|
|
36
36
|
(e.g. `className`, `classNames`, `classes`, `styles`) automatically.
|
|
37
37
|
- **Customizable** — Extend class detection with custom attributes, attribute patterns (regex, for
|
|
38
|
-
`*ClassName` props), callees,
|
|
38
|
+
`*ClassName` props), callees, callee extractors (route a wrapper through the `tv`/`cva`/`classed`
|
|
39
|
+
extractor), tags, and variable patterns.
|
|
39
40
|
- **Component class support** — Recognizes `@layer components { .btn {} }` in your CSS.
|
|
40
41
|
|
|
41
42
|
Full documentation: **https://oxlint-tailwindcss.pages.dev** (English) ·
|
|
@@ -179,8 +180,11 @@ the run fails fast, and the state self-heals once the machine recovers.
|
|
|
179
180
|
|
|
180
181
|
### Root font size
|
|
181
182
|
|
|
182
|
-
|
|
183
|
-
`p-
|
|
183
|
+
Comparing a px value against a rem-based scale depends on the root font size. `prefer-scale-token`
|
|
184
|
+
uses it to suggest `p-[10px]` → `p-2.5`, and `enforce-canonical` passes it to Tailwind's
|
|
185
|
+
canonicalizer. `enforce-canonical` only autofixes rewrites that emit identical CSS, so a px value is
|
|
186
|
+
never rewritten to a token that resolves through `var(--spacing)`. Change it only if your project
|
|
187
|
+
sets a root size other than 16 on `<html>`:
|
|
184
188
|
|
|
185
189
|
```jsonc
|
|
186
190
|
{
|
|
@@ -250,6 +254,8 @@ entries are appended to the built-in defaults:
|
|
|
250
254
|
"attributePatterns": ["ClassName$"],
|
|
251
255
|
// Additional function names to scan
|
|
252
256
|
"callees": ["myHelper"],
|
|
257
|
+
// Route a custom wrapper through a structured extractor (tv/cva/classed/flat)
|
|
258
|
+
"calleeExtractors": { "defineStyles": "tv" },
|
|
253
259
|
// Additional tagged template tags to scan
|
|
254
260
|
"tags": ["css"],
|
|
255
261
|
// Additional regex patterns for variable names (as strings)
|
|
@@ -266,6 +272,13 @@ entries are appended to the built-in defaults:
|
|
|
266
272
|
This applies to all 24 rules at once. For example, adding `"classNames"` to `attributes` makes every
|
|
267
273
|
rule lint `<Input classNames={{ root: "..." }} />`.
|
|
268
274
|
|
|
275
|
+
> **`calleeExtractors`** — `cva`, `tv`, and `classed` are extracted with logic that understands
|
|
276
|
+
> their config shape (`base`, `slots`, `variants`, …). If a shared package re-exports one under
|
|
277
|
+
> another name (e.g. `defineStyles = createTV(config)`), map it —
|
|
278
|
+
> `"calleeExtractors": { "defineStyles": "tv" }` — so the wrapper gets the same deep extraction
|
|
279
|
+
> without renaming imports. Mapped names are auto-registered as callees; values are one of `tv`,
|
|
280
|
+
> `cva`, `classed`, or `flat` (the reserved names can't be remapped).
|
|
281
|
+
|
|
269
282
|
> **`attributePatterns` vs `variablePatterns`** — both match by regex, but on different things.
|
|
270
283
|
> `attributePatterns` matches **JSX attribute names** (`contentContainerClassName`,
|
|
271
284
|
> `tintColorClassName`, …); `variablePatterns` matches **variable declaration names only**
|
|
@@ -569,8 +582,14 @@ syntax normalization), so `--fix` never changes how your design renders.
|
|
|
569
582
|
"-mt-0" → "mt-0"
|
|
570
583
|
"flex-grow-[2]" → "grow-2"
|
|
571
584
|
"text-[var(--color-text)]/90" → "text-(--color-text)/90"
|
|
585
|
+
"dark:bg-white/[.08]" → "dark:bg-white/8"
|
|
586
|
+
"data-[open]:flex" → "data-open:flex"
|
|
587
|
+
"min-[40rem]:flex" → "sm:flex"
|
|
572
588
|
```
|
|
573
589
|
|
|
590
|
+
Variants and the `!` position are preserved. A variant rewrite that would change the selector
|
|
591
|
+
(`has-[:checked]:` → `has-checked:`, `[&>*]:` → `*:`) is left as written.
|
|
592
|
+
|
|
574
593
|
It does **not** rewrite an arbitrary length into a spacing-scale step (`pl-[15px]` → `pl-3.75`),
|
|
575
594
|
even though IntelliSense suggests it: `pl-3.75` compiles to `calc(var(--spacing) * 3.75)`, which is
|
|
576
595
|
not byte-identical to `15px`, so the two can diverge under a `:root` override or a different root
|
|
@@ -1020,10 +1039,11 @@ The class parser correctly handles:
|
|
|
1020
1039
|
- **`enforce-canonical`**: Named classes are canonicalized via the precomputed map (covers
|
|
1021
1040
|
everything in `getClassList()` plus a curated list of legacy v3 spellings like `break-words`,
|
|
1022
1041
|
`flex-grow`, `start-N`, `bg-gradient-to-*`, `bg-left-top` → `bg-top-left`). Arbitrary/CSS-var
|
|
1023
|
-
forms (`bg-(--c)`, `text-[var(--x)]`)
|
|
1024
|
-
is byte-identical; a value-changing form
|
|
1025
|
-
Some valid v4 classes that don't appear
|
|
1026
|
-
`border-1` is valid as a dynamic numeric
|
|
1042
|
+
forms (`bg-(--c)`, `text-[var(--x)]`) and arbitrary variants (`data-[open]:`, `min-[40rem]:`) are
|
|
1043
|
+
canonicalized dynamically via the worker when the result is byte-identical; a value-changing form
|
|
1044
|
+
like `p-[2px]` → `p-0.5` is left to `prefer-scale-token`. Some valid v4 classes that don't appear
|
|
1045
|
+
in `getClassList()` and have no canonical rewrite (e.g. `border-1` is valid as a dynamic numeric
|
|
1046
|
+
value but isn't enumerated) are left untouched.
|
|
1027
1047
|
- **`no-conflicting-classes`**: compares the emitted declarations (property, value, the custom
|
|
1028
1048
|
properties each value reads, and which box it applies to), so compositions are derived rather than
|
|
1029
1049
|
enumerated. Two exceptions cannot be derived and stay declared in the source: `prose` variants and
|
package/dist/index.cjs
CHANGED
|
@@ -113,6 +113,13 @@ function preserveSpaces(loc, fixed) {
|
|
|
113
113
|
if (loc.preserveTrailingSpace && !fixed.endsWith(" ")) fixed = `${fixed} `;
|
|
114
114
|
return fixed;
|
|
115
115
|
}
|
|
116
|
+
/** The structured extractor kinds `calleeExtractors` accepts (#155). */
|
|
117
|
+
const CALLEE_EXTRACTOR_KINDS = /* @__PURE__ */ new Set([
|
|
118
|
+
"tv",
|
|
119
|
+
"cva",
|
|
120
|
+
"classed",
|
|
121
|
+
"flat"
|
|
122
|
+
]);
|
|
116
123
|
const DEFAULT_EXTRACTOR_CONFIG = {
|
|
117
124
|
attributes: ["className", "class"],
|
|
118
125
|
attributePatterns: [],
|
|
@@ -137,7 +144,8 @@ const DEFAULT_EXTRACTOR_CONFIG = {
|
|
|
137
144
|
/^classNames?$/,
|
|
138
145
|
/^classes$/,
|
|
139
146
|
/^styles?$/
|
|
140
|
-
]
|
|
147
|
+
],
|
|
148
|
+
calleeExtractors: /* @__PURE__ */ new Map()
|
|
141
149
|
};
|
|
142
150
|
const configCache = /* @__PURE__ */ new WeakMap();
|
|
143
151
|
function mergeUnique(defaults, extras, exclusions) {
|
|
@@ -152,6 +160,25 @@ function mergeUnique(defaults, extras, exclusions) {
|
|
|
152
160
|
return [...set];
|
|
153
161
|
}
|
|
154
162
|
/**
|
|
163
|
+
* Builds the validated `calleeExtractors` map from raw settings (#155).
|
|
164
|
+
* Mirrors the graceful degradation of `compileRegexList`: a malformed shape or
|
|
165
|
+
* an unrecognized kind is skipped rather than thrown, so a typo in the config
|
|
166
|
+
* can never crash the lint from inside a visitor. Names present in
|
|
167
|
+
* `excluded` (from `exclude.callees`) are dropped so exclusion still wins over
|
|
168
|
+
* a callee that would otherwise be auto-registered.
|
|
169
|
+
*/
|
|
170
|
+
function compileCalleeExtractors(raw, excluded) {
|
|
171
|
+
const map = /* @__PURE__ */ new Map();
|
|
172
|
+
if (!raw || typeof raw !== "object") return map;
|
|
173
|
+
for (const [name, kind] of Object.entries(raw)) {
|
|
174
|
+
if (!name || typeof kind !== "string") continue;
|
|
175
|
+
if (!CALLEE_EXTRACTOR_KINDS.has(kind)) continue;
|
|
176
|
+
if (excluded.has(name)) continue;
|
|
177
|
+
map.set(name, kind);
|
|
178
|
+
}
|
|
179
|
+
return map;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
155
182
|
* Returns the extractor config for this rule context, merging defaults with
|
|
156
183
|
* user settings from `settings.tailwindcss`. The result is cached per
|
|
157
184
|
* context (WeakMap-keyed) so settings are read once per rule lifetime.
|
|
@@ -177,12 +204,15 @@ function getExtractorConfig(context) {
|
|
|
177
204
|
const exclude = tw.exclude;
|
|
178
205
|
const excludedPatternSources = new Set(exclude?.variablePatterns ?? []);
|
|
179
206
|
const filteredPatterns = excludedPatternSources.size > 0 ? DEFAULT_EXTRACTOR_CONFIG.variablePatterns.filter((re) => !excludedPatternSources.has(re.source)) : DEFAULT_EXTRACTOR_CONFIG.variablePatterns;
|
|
207
|
+
const excludedCallees = new Set(exclude?.callees ?? []);
|
|
208
|
+
const calleeExtractors = compileCalleeExtractors(tw.calleeExtractors, excludedCallees);
|
|
180
209
|
const resolved = {
|
|
181
210
|
attributes: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.attributes, tw.attributes, exclude?.attributes),
|
|
182
211
|
attributePatterns: compileRegexList(tw.attributePatterns),
|
|
183
|
-
callees: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.callees, tw.callees, exclude?.callees),
|
|
212
|
+
callees: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.callees, [...tw.callees ?? [], ...calleeExtractors.keys()], exclude?.callees),
|
|
184
213
|
tags: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.tags, tw.tags, exclude?.tags),
|
|
185
|
-
variablePatterns: [...filteredPatterns, ...compileRegexList(tw.variablePatterns)]
|
|
214
|
+
variablePatterns: [...filteredPatterns, ...compileRegexList(tw.variablePatterns)],
|
|
215
|
+
calleeExtractors
|
|
186
216
|
};
|
|
187
217
|
configCache.set(context, resolved);
|
|
188
218
|
return resolved;
|
|
@@ -262,9 +292,10 @@ function extractFromJSXAttribute(node, config = DEFAULT_EXTRACTOR_CONFIG) {
|
|
|
262
292
|
function extractFromCallExpression(node, config = DEFAULT_EXTRACTOR_CONFIG) {
|
|
263
293
|
const calleeName = getCalleeName(node.callee);
|
|
264
294
|
if (!calleeName || !config.callees.includes(calleeName)) return [];
|
|
265
|
-
|
|
266
|
-
if (
|
|
267
|
-
if (
|
|
295
|
+
const structured = calleeName === "cva" || calleeName === "tv" || calleeName === "classed" ? calleeName : config.calleeExtractors.get(calleeName);
|
|
296
|
+
if (structured === "cva") return withOrigin(extractFromCvaCall(node), "callee");
|
|
297
|
+
if (structured === "tv") return withOrigin(extractFromTvCall(node), "callee");
|
|
298
|
+
if (structured === "classed") return withOrigin(extractFromClassedCall(node), "callee");
|
|
268
299
|
const results = [];
|
|
269
300
|
for (const arg of node.arguments) extractFromExpression(arg, results);
|
|
270
301
|
return withOrigin(results, "callee");
|
|
@@ -830,14 +861,28 @@ function hasArbitraryValue(cls) {
|
|
|
830
861
|
* Unlike `hasArbitraryValue`, this also catches `(--var)` shorthand — both
|
|
831
862
|
* forms are what require the async Tailwind DS to canonicalize, because
|
|
832
863
|
* their value space is unbounded. Simple named classes (`flex`, `px-4`,
|
|
833
|
-
*
|
|
834
|
-
* the
|
|
864
|
+
* `hover:flex`) can be canonicalized from the precomputed cache without
|
|
865
|
+
* touching the worker. See `variantHasArbitraryValue` for the variant side.
|
|
835
866
|
*/
|
|
836
867
|
function utilityHasDynamicValue(cls) {
|
|
837
868
|
const utility = extractUtility(cls);
|
|
838
869
|
return utility.includes("[") || utility.includes("(");
|
|
839
870
|
}
|
|
840
871
|
/**
|
|
872
|
+
* Checks if a class's VARIANT part carries an arbitrary value — an arbitrary
|
|
873
|
+
* variant (`[&>svg]:`) or a bracketed/parenthesized argument (`data-[open]:`,
|
|
874
|
+
* `min-[40rem]:`, `supports-(--x):`).
|
|
875
|
+
*
|
|
876
|
+
* The precompute only knows utilities, so the cache canonicalizes the utility
|
|
877
|
+
* and passes the variant through untouched; Tailwind also canonicalizes
|
|
878
|
+
* variants (`data-[open]:` → `data-open:`, `min-[40rem]:` → `sm:`), which only
|
|
879
|
+
* the design system can answer. Bracket-aware via `splitUtilityAndVariant`.
|
|
880
|
+
*/
|
|
881
|
+
function variantHasArbitraryValue(cls) {
|
|
882
|
+
const { variant } = splitUtilityAndVariant(cls);
|
|
883
|
+
return variant.includes("[") || variant.includes("(");
|
|
884
|
+
}
|
|
885
|
+
/**
|
|
841
886
|
* A utility the precompute cannot have enumerated, because the VALUE comes from
|
|
842
887
|
* the user rather than from the design system's class list: arbitrary brackets,
|
|
843
888
|
* the `(--var)` shorthand, a `/` modifier, or an off-scale number.
|
|
@@ -4984,15 +5029,15 @@ const noDeprecatedClasses = defineRule({
|
|
|
4984
5029
|
const WORKER_SCRIPT$1 = makeWorkerScript(`(ds, request) => {
|
|
4985
5030
|
const { classes, rem } = request;
|
|
4986
5031
|
const options = rem ? { rem } : undefined;
|
|
5032
|
+
const OWN_CLASS = /("(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*')|(^|[{};])(\\s*)\\.(?:\\\\[0-9a-fA-F]{1,6}\\s?|\\\\[^0-9a-fA-F\\s]|[\\w-])+/g;
|
|
4987
5033
|
const declsOf = (cls) => {
|
|
4988
5034
|
let out;
|
|
4989
5035
|
try { out = ds.candidatesToCss([cls]); } catch (e) { return null; }
|
|
4990
5036
|
if (!out || !out[0]) return null;
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
return css.slice(open + 1, close).replace(/\\s+/g, ' ').trim();
|
|
5037
|
+
return out[0]
|
|
5038
|
+
.replace(OWN_CLASS, (m, str, start, ws) => (str !== undefined ? str : start + ws + '.__c'))
|
|
5039
|
+
.replace(/\\s+/g, ' ')
|
|
5040
|
+
.trim();
|
|
4996
5041
|
};
|
|
4997
5042
|
return classes.map((cls) => {
|
|
4998
5043
|
// A malformed/mid-typing arbitrary value (e.g. \`px-[calc(var(--a)+)]\`) can
|
|
@@ -5295,7 +5340,7 @@ const enforceCanonical = defineRule({
|
|
|
5295
5340
|
canonicals[i] = classes[i];
|
|
5296
5341
|
continue;
|
|
5297
5342
|
}
|
|
5298
|
-
if (utilityHasDynamicValue(classes[i])) {
|
|
5343
|
+
if (utilityHasDynamicValue(classes[i]) || variantHasArbitraryValue(classes[i])) {
|
|
5299
5344
|
arbitraryIdx.push(i);
|
|
5300
5345
|
arbitrary.push(classes[i]);
|
|
5301
5346
|
} else canonicals[i] = cache.canonicalize(classes[i]);
|
package/dist/index.mjs
CHANGED
|
@@ -117,6 +117,13 @@ function preserveSpaces(loc, fixed) {
|
|
|
117
117
|
if (loc.preserveTrailingSpace && !fixed.endsWith(" ")) fixed = `${fixed} `;
|
|
118
118
|
return fixed;
|
|
119
119
|
}
|
|
120
|
+
/** The structured extractor kinds `calleeExtractors` accepts (#155). */
|
|
121
|
+
const CALLEE_EXTRACTOR_KINDS = /* @__PURE__ */ new Set([
|
|
122
|
+
"tv",
|
|
123
|
+
"cva",
|
|
124
|
+
"classed",
|
|
125
|
+
"flat"
|
|
126
|
+
]);
|
|
120
127
|
const DEFAULT_EXTRACTOR_CONFIG = {
|
|
121
128
|
attributes: ["className", "class"],
|
|
122
129
|
attributePatterns: [],
|
|
@@ -141,7 +148,8 @@ const DEFAULT_EXTRACTOR_CONFIG = {
|
|
|
141
148
|
/^classNames?$/,
|
|
142
149
|
/^classes$/,
|
|
143
150
|
/^styles?$/
|
|
144
|
-
]
|
|
151
|
+
],
|
|
152
|
+
calleeExtractors: /* @__PURE__ */ new Map()
|
|
145
153
|
};
|
|
146
154
|
const configCache = /* @__PURE__ */ new WeakMap();
|
|
147
155
|
function mergeUnique(defaults, extras, exclusions) {
|
|
@@ -156,6 +164,25 @@ function mergeUnique(defaults, extras, exclusions) {
|
|
|
156
164
|
return [...set];
|
|
157
165
|
}
|
|
158
166
|
/**
|
|
167
|
+
* Builds the validated `calleeExtractors` map from raw settings (#155).
|
|
168
|
+
* Mirrors the graceful degradation of `compileRegexList`: a malformed shape or
|
|
169
|
+
* an unrecognized kind is skipped rather than thrown, so a typo in the config
|
|
170
|
+
* can never crash the lint from inside a visitor. Names present in
|
|
171
|
+
* `excluded` (from `exclude.callees`) are dropped so exclusion still wins over
|
|
172
|
+
* a callee that would otherwise be auto-registered.
|
|
173
|
+
*/
|
|
174
|
+
function compileCalleeExtractors(raw, excluded) {
|
|
175
|
+
const map = /* @__PURE__ */ new Map();
|
|
176
|
+
if (!raw || typeof raw !== "object") return map;
|
|
177
|
+
for (const [name, kind] of Object.entries(raw)) {
|
|
178
|
+
if (!name || typeof kind !== "string") continue;
|
|
179
|
+
if (!CALLEE_EXTRACTOR_KINDS.has(kind)) continue;
|
|
180
|
+
if (excluded.has(name)) continue;
|
|
181
|
+
map.set(name, kind);
|
|
182
|
+
}
|
|
183
|
+
return map;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
159
186
|
* Returns the extractor config for this rule context, merging defaults with
|
|
160
187
|
* user settings from `settings.tailwindcss`. The result is cached per
|
|
161
188
|
* context (WeakMap-keyed) so settings are read once per rule lifetime.
|
|
@@ -181,12 +208,15 @@ function getExtractorConfig(context) {
|
|
|
181
208
|
const exclude = tw.exclude;
|
|
182
209
|
const excludedPatternSources = new Set(exclude?.variablePatterns ?? []);
|
|
183
210
|
const filteredPatterns = excludedPatternSources.size > 0 ? DEFAULT_EXTRACTOR_CONFIG.variablePatterns.filter((re) => !excludedPatternSources.has(re.source)) : DEFAULT_EXTRACTOR_CONFIG.variablePatterns;
|
|
211
|
+
const excludedCallees = new Set(exclude?.callees ?? []);
|
|
212
|
+
const calleeExtractors = compileCalleeExtractors(tw.calleeExtractors, excludedCallees);
|
|
184
213
|
const resolved = {
|
|
185
214
|
attributes: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.attributes, tw.attributes, exclude?.attributes),
|
|
186
215
|
attributePatterns: compileRegexList(tw.attributePatterns),
|
|
187
|
-
callees: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.callees, tw.callees, exclude?.callees),
|
|
216
|
+
callees: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.callees, [...tw.callees ?? [], ...calleeExtractors.keys()], exclude?.callees),
|
|
188
217
|
tags: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.tags, tw.tags, exclude?.tags),
|
|
189
|
-
variablePatterns: [...filteredPatterns, ...compileRegexList(tw.variablePatterns)]
|
|
218
|
+
variablePatterns: [...filteredPatterns, ...compileRegexList(tw.variablePatterns)],
|
|
219
|
+
calleeExtractors
|
|
190
220
|
};
|
|
191
221
|
configCache.set(context, resolved);
|
|
192
222
|
return resolved;
|
|
@@ -266,9 +296,10 @@ function extractFromJSXAttribute(node, config = DEFAULT_EXTRACTOR_CONFIG) {
|
|
|
266
296
|
function extractFromCallExpression(node, config = DEFAULT_EXTRACTOR_CONFIG) {
|
|
267
297
|
const calleeName = getCalleeName(node.callee);
|
|
268
298
|
if (!calleeName || !config.callees.includes(calleeName)) return [];
|
|
269
|
-
|
|
270
|
-
if (
|
|
271
|
-
if (
|
|
299
|
+
const structured = calleeName === "cva" || calleeName === "tv" || calleeName === "classed" ? calleeName : config.calleeExtractors.get(calleeName);
|
|
300
|
+
if (structured === "cva") return withOrigin(extractFromCvaCall(node), "callee");
|
|
301
|
+
if (structured === "tv") return withOrigin(extractFromTvCall(node), "callee");
|
|
302
|
+
if (structured === "classed") return withOrigin(extractFromClassedCall(node), "callee");
|
|
272
303
|
const results = [];
|
|
273
304
|
for (const arg of node.arguments) extractFromExpression(arg, results);
|
|
274
305
|
return withOrigin(results, "callee");
|
|
@@ -834,14 +865,28 @@ function hasArbitraryValue(cls) {
|
|
|
834
865
|
* Unlike `hasArbitraryValue`, this also catches `(--var)` shorthand — both
|
|
835
866
|
* forms are what require the async Tailwind DS to canonicalize, because
|
|
836
867
|
* their value space is unbounded. Simple named classes (`flex`, `px-4`,
|
|
837
|
-
*
|
|
838
|
-
* the
|
|
868
|
+
* `hover:flex`) can be canonicalized from the precomputed cache without
|
|
869
|
+
* touching the worker. See `variantHasArbitraryValue` for the variant side.
|
|
839
870
|
*/
|
|
840
871
|
function utilityHasDynamicValue(cls) {
|
|
841
872
|
const utility = extractUtility(cls);
|
|
842
873
|
return utility.includes("[") || utility.includes("(");
|
|
843
874
|
}
|
|
844
875
|
/**
|
|
876
|
+
* Checks if a class's VARIANT part carries an arbitrary value — an arbitrary
|
|
877
|
+
* variant (`[&>svg]:`) or a bracketed/parenthesized argument (`data-[open]:`,
|
|
878
|
+
* `min-[40rem]:`, `supports-(--x):`).
|
|
879
|
+
*
|
|
880
|
+
* The precompute only knows utilities, so the cache canonicalizes the utility
|
|
881
|
+
* and passes the variant through untouched; Tailwind also canonicalizes
|
|
882
|
+
* variants (`data-[open]:` → `data-open:`, `min-[40rem]:` → `sm:`), which only
|
|
883
|
+
* the design system can answer. Bracket-aware via `splitUtilityAndVariant`.
|
|
884
|
+
*/
|
|
885
|
+
function variantHasArbitraryValue(cls) {
|
|
886
|
+
const { variant } = splitUtilityAndVariant(cls);
|
|
887
|
+
return variant.includes("[") || variant.includes("(");
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
845
890
|
* A utility the precompute cannot have enumerated, because the VALUE comes from
|
|
846
891
|
* the user rather than from the design system's class list: arbitrary brackets,
|
|
847
892
|
* the `(--var)` shorthand, a `/` modifier, or an off-scale number.
|
|
@@ -4988,15 +5033,15 @@ const noDeprecatedClasses = defineRule({
|
|
|
4988
5033
|
const WORKER_SCRIPT$1 = makeWorkerScript(`(ds, request) => {
|
|
4989
5034
|
const { classes, rem } = request;
|
|
4990
5035
|
const options = rem ? { rem } : undefined;
|
|
5036
|
+
const OWN_CLASS = /("(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*')|(^|[{};])(\\s*)\\.(?:\\\\[0-9a-fA-F]{1,6}\\s?|\\\\[^0-9a-fA-F\\s]|[\\w-])+/g;
|
|
4991
5037
|
const declsOf = (cls) => {
|
|
4992
5038
|
let out;
|
|
4993
5039
|
try { out = ds.candidatesToCss([cls]); } catch (e) { return null; }
|
|
4994
5040
|
if (!out || !out[0]) return null;
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
return css.slice(open + 1, close).replace(/\\s+/g, ' ').trim();
|
|
5041
|
+
return out[0]
|
|
5042
|
+
.replace(OWN_CLASS, (m, str, start, ws) => (str !== undefined ? str : start + ws + '.__c'))
|
|
5043
|
+
.replace(/\\s+/g, ' ')
|
|
5044
|
+
.trim();
|
|
5000
5045
|
};
|
|
5001
5046
|
return classes.map((cls) => {
|
|
5002
5047
|
// A malformed/mid-typing arbitrary value (e.g. \`px-[calc(var(--a)+)]\`) can
|
|
@@ -5299,7 +5344,7 @@ const enforceCanonical = defineRule({
|
|
|
5299
5344
|
canonicals[i] = classes[i];
|
|
5300
5345
|
continue;
|
|
5301
5346
|
}
|
|
5302
|
-
if (utilityHasDynamicValue(classes[i])) {
|
|
5347
|
+
if (utilityHasDynamicValue(classes[i]) || variantHasArbitraryValue(classes[i])) {
|
|
5303
5348
|
arbitraryIdx.push(i);
|
|
5304
5349
|
arbitrary.push(classes[i]);
|
|
5305
5350
|
} else canonicals[i] = cache.canonicalize(classes[i]);
|