@unocss/rule-utils 66.1.4 → 66.2.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/index.d.mts CHANGED
@@ -33,8 +33,12 @@ interface ParsedColorValue {
33
33
  alpha: string | number | undefined;
34
34
  }
35
35
  declare const cssColorFunctions: string[];
36
+ declare const rectangularColorSpace: string[];
37
+ declare const polarColorSpace: string[];
38
+ declare const hueInterpolationMethods: string[];
36
39
  declare const alphaPlaceholders: string[];
37
40
  declare const alphaPlaceholdersRE: RegExp;
41
+ declare function isInterpolatedMethod(type?: string): boolean;
38
42
  declare function hex2rgba(hex?: string): RGBAColorValue | undefined;
39
43
  declare function parseCssColor(str?: string): CSSColorValue | undefined;
40
44
  declare function colorOpacityToString(color: CSSColorValue): string | number;
@@ -62,11 +66,54 @@ declare function hasIconFn(str: string): boolean;
62
66
 
63
67
  declare function getBracket(str: string, open: string, close: string): string[] | undefined;
64
68
  declare function getStringComponent(str: string, open: string, close: string, separators: string | string[]): string[] | undefined;
65
- declare function getStringComponents(str: string, separators: string | string[], limit?: number): string[] | undefined;
69
+ declare function getStringComponents(str: string, separators: string | string[], limit?: number, open?: string, close?: string): string[] | undefined;
66
70
 
67
71
  declare function variantMatcher<T extends object = object>(name: string, handler: Arrayable<(input: VariantHandlerContext) => Record<string, any>>): VariantObject<T>;
68
72
  declare function variantParentMatcher<T extends object = object>(name: string, parent: string): VariantObject<T>;
69
73
  declare function variantGetBracket(prefix: string, matcher: string, separators: string[]): string[] | undefined;
70
74
  declare function variantGetParameter(prefix: Arrayable<string>, matcher: string, separators: string[]): string[] | undefined;
71
75
 
72
- export { type CSSColorValue, type ParsedColorValue, type RGBAColorValue, type ValueHandler, type ValueHandlerCallback, alphaPlaceholders, alphaPlaceholdersRE, calcMaxWidthBySize, colorOpacityToString, colorToString, createValueHandler, cssColorFunctions, getBracket, getStringComponent, getStringComponents, hasIconFn, hasThemeFn, hex2rgba, iconFnRE, parseCssColor, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
76
+ /**
77
+ * Note: the order of following pseudo classes will affect the order of generated css.
78
+ *
79
+ * Reference: https://github.com/tailwindlabs/tailwindcss/blob/main/src/corePlugins.js#L83
80
+ */
81
+ declare const PseudoClasses: Record<string, string>;
82
+ declare const PseudoClassesKeys: string[];
83
+ declare const PseudoClassesColon: Record<string, string>;
84
+ declare const PseudoClassesColonKeys: string[];
85
+ declare const PseudoClassFunctions: string[];
86
+ declare const PseudoClassesMulti: Record<string, string[]>;
87
+ declare const PseudoClassesStr: string;
88
+ declare const PseudoClassesColonStr: string;
89
+ declare const PseudoClassFunctionsStr: string;
90
+ declare const PseudoClassesMultiStr: string;
91
+ declare const excludedPseudo: string[];
92
+ declare const PseudoClassesAndElementsStr: string;
93
+ declare const PseudoClassesAndElementsColonStr: string;
94
+ interface PseudoVariantOptions {
95
+ /**
96
+ * Generate tagged pseudo selector as `[group=""]` instead of `.group`
97
+ *
98
+ * @default false
99
+ */
100
+ attributifyPseudo?: boolean;
101
+ /**
102
+ * Utils prefix
103
+ */
104
+ prefix?: string | string[];
105
+ }
106
+ interface PseudoVariantUtilities {
107
+ getBracket: typeof getBracket;
108
+ h: {
109
+ bracket: (s: string) => string | undefined;
110
+ };
111
+ variantGetBracket: typeof variantGetBracket;
112
+ }
113
+ declare function createTaggedPseudoClassMatcher<T extends object = object>(tag: string, parent: string, combinator: string, utils: PseudoVariantUtilities): VariantObject<T>;
114
+ declare function createPseudoClassesAndElements<T extends object = object>(utils: PseudoVariantUtilities): VariantObject<T>[];
115
+ declare function createPseudoClassFunctions<T extends object = object>(utils: PseudoVariantUtilities): VariantObject<T>;
116
+ declare function createTaggedPseudoClasses<T extends object = object>(options: PseudoVariantOptions, utils: PseudoVariantUtilities): VariantObject<T>[];
117
+ declare function createPartClasses<T extends object = object>(): VariantObject<T>;
118
+
119
+ export { type CSSColorValue, type ParsedColorValue, PseudoClassFunctions, PseudoClassFunctionsStr, PseudoClasses, PseudoClassesAndElementsColonStr, PseudoClassesAndElementsStr, PseudoClassesColon, PseudoClassesColonKeys, PseudoClassesColonStr, PseudoClassesKeys, PseudoClassesMulti, PseudoClassesMultiStr, PseudoClassesStr, type PseudoVariantOptions, type PseudoVariantUtilities, type RGBAColorValue, type ValueHandler, type ValueHandlerCallback, alphaPlaceholders, alphaPlaceholdersRE, calcMaxWidthBySize, colorOpacityToString, colorToString, createPartClasses, createPseudoClassFunctions, createPseudoClassesAndElements, createTaggedPseudoClassMatcher, createTaggedPseudoClasses, createValueHandler, cssColorFunctions, excludedPseudo, getBracket, getStringComponent, getStringComponents, hasIconFn, hasThemeFn, hex2rgba, hueInterpolationMethods, iconFnRE, isInterpolatedMethod, parseCssColor, polarColorSpace, rectangularColorSpace, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
package/dist/index.d.ts CHANGED
@@ -33,8 +33,12 @@ interface ParsedColorValue {
33
33
  alpha: string | number | undefined;
34
34
  }
35
35
  declare const cssColorFunctions: string[];
36
+ declare const rectangularColorSpace: string[];
37
+ declare const polarColorSpace: string[];
38
+ declare const hueInterpolationMethods: string[];
36
39
  declare const alphaPlaceholders: string[];
37
40
  declare const alphaPlaceholdersRE: RegExp;
41
+ declare function isInterpolatedMethod(type?: string): boolean;
38
42
  declare function hex2rgba(hex?: string): RGBAColorValue | undefined;
39
43
  declare function parseCssColor(str?: string): CSSColorValue | undefined;
40
44
  declare function colorOpacityToString(color: CSSColorValue): string | number;
@@ -62,11 +66,54 @@ declare function hasIconFn(str: string): boolean;
62
66
 
63
67
  declare function getBracket(str: string, open: string, close: string): string[] | undefined;
64
68
  declare function getStringComponent(str: string, open: string, close: string, separators: string | string[]): string[] | undefined;
65
- declare function getStringComponents(str: string, separators: string | string[], limit?: number): string[] | undefined;
69
+ declare function getStringComponents(str: string, separators: string | string[], limit?: number, open?: string, close?: string): string[] | undefined;
66
70
 
67
71
  declare function variantMatcher<T extends object = object>(name: string, handler: Arrayable<(input: VariantHandlerContext) => Record<string, any>>): VariantObject<T>;
68
72
  declare function variantParentMatcher<T extends object = object>(name: string, parent: string): VariantObject<T>;
69
73
  declare function variantGetBracket(prefix: string, matcher: string, separators: string[]): string[] | undefined;
70
74
  declare function variantGetParameter(prefix: Arrayable<string>, matcher: string, separators: string[]): string[] | undefined;
71
75
 
72
- export { type CSSColorValue, type ParsedColorValue, type RGBAColorValue, type ValueHandler, type ValueHandlerCallback, alphaPlaceholders, alphaPlaceholdersRE, calcMaxWidthBySize, colorOpacityToString, colorToString, createValueHandler, cssColorFunctions, getBracket, getStringComponent, getStringComponents, hasIconFn, hasThemeFn, hex2rgba, iconFnRE, parseCssColor, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
76
+ /**
77
+ * Note: the order of following pseudo classes will affect the order of generated css.
78
+ *
79
+ * Reference: https://github.com/tailwindlabs/tailwindcss/blob/main/src/corePlugins.js#L83
80
+ */
81
+ declare const PseudoClasses: Record<string, string>;
82
+ declare const PseudoClassesKeys: string[];
83
+ declare const PseudoClassesColon: Record<string, string>;
84
+ declare const PseudoClassesColonKeys: string[];
85
+ declare const PseudoClassFunctions: string[];
86
+ declare const PseudoClassesMulti: Record<string, string[]>;
87
+ declare const PseudoClassesStr: string;
88
+ declare const PseudoClassesColonStr: string;
89
+ declare const PseudoClassFunctionsStr: string;
90
+ declare const PseudoClassesMultiStr: string;
91
+ declare const excludedPseudo: string[];
92
+ declare const PseudoClassesAndElementsStr: string;
93
+ declare const PseudoClassesAndElementsColonStr: string;
94
+ interface PseudoVariantOptions {
95
+ /**
96
+ * Generate tagged pseudo selector as `[group=""]` instead of `.group`
97
+ *
98
+ * @default false
99
+ */
100
+ attributifyPseudo?: boolean;
101
+ /**
102
+ * Utils prefix
103
+ */
104
+ prefix?: string | string[];
105
+ }
106
+ interface PseudoVariantUtilities {
107
+ getBracket: typeof getBracket;
108
+ h: {
109
+ bracket: (s: string) => string | undefined;
110
+ };
111
+ variantGetBracket: typeof variantGetBracket;
112
+ }
113
+ declare function createTaggedPseudoClassMatcher<T extends object = object>(tag: string, parent: string, combinator: string, utils: PseudoVariantUtilities): VariantObject<T>;
114
+ declare function createPseudoClassesAndElements<T extends object = object>(utils: PseudoVariantUtilities): VariantObject<T>[];
115
+ declare function createPseudoClassFunctions<T extends object = object>(utils: PseudoVariantUtilities): VariantObject<T>;
116
+ declare function createTaggedPseudoClasses<T extends object = object>(options: PseudoVariantOptions, utils: PseudoVariantUtilities): VariantObject<T>[];
117
+ declare function createPartClasses<T extends object = object>(): VariantObject<T>;
118
+
119
+ export { type CSSColorValue, type ParsedColorValue, PseudoClassFunctions, PseudoClassFunctionsStr, PseudoClasses, PseudoClassesAndElementsColonStr, PseudoClassesAndElementsStr, PseudoClassesColon, PseudoClassesColonKeys, PseudoClassesColonStr, PseudoClassesKeys, PseudoClassesMulti, PseudoClassesMultiStr, PseudoClassesStr, type PseudoVariantOptions, type PseudoVariantUtilities, type RGBAColorValue, type ValueHandler, type ValueHandlerCallback, alphaPlaceholders, alphaPlaceholdersRE, calcMaxWidthBySize, colorOpacityToString, colorToString, createPartClasses, createPseudoClassFunctions, createPseudoClassesAndElements, createTaggedPseudoClassMatcher, createTaggedPseudoClasses, createValueHandler, cssColorFunctions, excludedPseudo, getBracket, getStringComponent, getStringComponents, hasIconFn, hasThemeFn, hex2rgba, hueInterpolationMethods, iconFnRE, isInterpolatedMethod, parseCssColor, polarColorSpace, rectangularColorSpace, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { isString, escapeRegExp, toArray } from '@unocss/core';
1
+ import { isString, escapeRegExp, escapeSelector, toArray } from '@unocss/core';
2
2
  import MagicString from 'magic-string';
3
3
 
4
4
  function getBracket(str, open, close) {
@@ -69,14 +69,14 @@ function getStringComponent(str, open, close, separators) {
69
69
  ""
70
70
  ];
71
71
  }
72
- function getStringComponents(str, separators, limit) {
72
+ function getStringComponents(str, separators, limit, open = "(", close = ")") {
73
73
  limit = limit ?? 10;
74
74
  const components = [];
75
75
  let i = 0;
76
76
  while (str !== "") {
77
77
  if (++i > limit)
78
78
  return;
79
- const componentPair = getStringComponent(str, "(", ")", separators);
79
+ const componentPair = getStringComponent(str, open, close, separators);
80
80
  if (!componentPair)
81
81
  return;
82
82
  const [component, rest] = componentPair;
@@ -88,8 +88,16 @@ function getStringComponents(str, separators, limit) {
88
88
  }
89
89
 
90
90
  const cssColorFunctions = ["hsl", "hsla", "hwb", "lab", "lch", "oklab", "oklch", "rgb", "rgba"];
91
+ const rectangularColorSpace = ["srgb", "srgb-linear", "display-p3", "a98-rgb", "prophoto-rgb", "rec2020", "lab", "oklab", "xyz", "xyz-d50", "xyz-d65"];
92
+ const polarColorSpace = ["hsl", "hwb", "lch", "oklch"];
93
+ const hueInterpolationMethods = ["shorter", "longer", "increasing", "decreasing"];
91
94
  const alphaPlaceholders = ["%alpha", "<alpha-value>"];
92
95
  const alphaPlaceholdersRE = new RegExp(alphaPlaceholders.map((v) => escapeRegExp(v)).join("|"), "g");
96
+ function isInterpolatedMethod(type) {
97
+ if (!type)
98
+ return false;
99
+ return rectangularColorSpace.some((space) => type.includes(space)) || polarColorSpace.some((space) => type.includes(space)) || hueInterpolationMethods.some((method) => type.includes(method));
100
+ }
93
101
  function hex2rgba(hex = "") {
94
102
  const color = parseHexColor(hex);
95
103
  if (color != null) {
@@ -158,21 +166,23 @@ function parseHexColor(str) {
158
166
  return;
159
167
  switch (body.length) {
160
168
  case 3:
161
- case 4:
169
+ case 4: {
162
170
  const digits = Array.from(body, (s) => Number.parseInt(s, 16)).map((n) => n << 4 | n);
163
171
  return {
164
172
  type: "rgb",
165
173
  components: digits.slice(0, 3),
166
174
  alpha: body.length === 3 ? void 0 : Math.round(digits[3] / 255 * 100) / 100
167
175
  };
176
+ }
168
177
  case 6:
169
- case 8:
178
+ case 8: {
170
179
  const value = Number.parseInt(body, 16);
171
180
  return {
172
181
  type: "rgb",
173
182
  components: body.length === 6 ? [value >> 16 & 255, value >> 8 & 255, value & 255] : [value >> 24 & 255, value >> 16 & 255, value >> 8 & 255],
174
183
  alpha: body.length === 6 ? void 0 : Math.round((value & 255) / 255 * 100) / 100
175
184
  };
185
+ }
176
186
  }
177
187
  }
178
188
  function cssColorKeyword(str) {
@@ -352,6 +362,313 @@ function hasIconFn(str) {
352
362
  return str.includes("icon(") && str.includes(")");
353
363
  }
354
364
 
365
+ const PseudoPlaceholder = "__pseudo_placeholder__";
366
+ const PseudoClasses = Object.fromEntries([
367
+ // pseudo elements part 1
368
+ ["first-letter", "::first-letter"],
369
+ ["first-line", "::first-line"],
370
+ // location
371
+ "any-link",
372
+ "link",
373
+ "visited",
374
+ "target",
375
+ ["open", "[open]"],
376
+ // forms
377
+ "default",
378
+ "checked",
379
+ "indeterminate",
380
+ "placeholder-shown",
381
+ "autofill",
382
+ "optional",
383
+ "required",
384
+ "valid",
385
+ "invalid",
386
+ "user-valid",
387
+ "user-invalid",
388
+ "in-range",
389
+ "out-of-range",
390
+ "read-only",
391
+ "read-write",
392
+ // content
393
+ "empty",
394
+ // interactions
395
+ "focus-within",
396
+ "hover",
397
+ "focus",
398
+ "focus-visible",
399
+ "active",
400
+ "enabled",
401
+ "disabled",
402
+ "popover-open",
403
+ // tree-structural
404
+ "root",
405
+ "empty",
406
+ ["even-of-type", ":nth-of-type(even)"],
407
+ ["even", ":nth-child(even)"],
408
+ ["odd-of-type", ":nth-of-type(odd)"],
409
+ ["odd", ":nth-child(odd)"],
410
+ ["nth", `:nth-child(${PseudoPlaceholder})`],
411
+ "first-of-type",
412
+ ["first", ":first-child"],
413
+ "last-of-type",
414
+ ["last", ":last-child"],
415
+ "only-child",
416
+ "only-of-type",
417
+ // pseudo elements part 2
418
+ ["backdrop-element", "::backdrop"],
419
+ ["placeholder", "::placeholder"],
420
+ ["before", "::before"],
421
+ ["after", "::after"],
422
+ ["file", "::file-selector-button"]
423
+ ].map((key) => Array.isArray(key) ? key : [key, `:${key}`]));
424
+ const PseudoClassesKeys = Object.keys(PseudoClasses);
425
+ const PseudoClassesColon = Object.fromEntries([
426
+ ["backdrop", "::backdrop"]
427
+ ].map((key) => Array.isArray(key) ? key : [key, `:${key}`]));
428
+ const PseudoClassesColonKeys = Object.keys(PseudoClassesColon);
429
+ const PseudoClassFunctions = [
430
+ "not",
431
+ "is",
432
+ "where",
433
+ "has"
434
+ ];
435
+ const PseudoClassesMulti = Object.fromEntries([
436
+ ["selection", ["::selection", " *::selection"]],
437
+ ["marker", ["::marker", " *::marker"]]
438
+ ]);
439
+ const PseudoClassesStr = Object.entries(PseudoClasses).filter(([, pseudo]) => !pseudo.startsWith("::")).map(([key]) => key).sort((a, b) => b.length - a.length).join("|");
440
+ const PseudoClassesColonStr = Object.entries(PseudoClassesColon).filter(([, pseudo]) => !pseudo.startsWith("::")).map(([key]) => key).sort((a, b) => b.length - a.length).join("|");
441
+ const PseudoClassFunctionsStr = PseudoClassFunctions.join("|");
442
+ const PseudoClassesMultiStr = Object.keys(PseudoClassesMulti).sort((a, b) => b.length - a.length).join("|");
443
+ const excludedPseudo = [
444
+ "::-webkit-resizer",
445
+ "::-webkit-scrollbar",
446
+ "::-webkit-scrollbar-button",
447
+ "::-webkit-scrollbar-corner",
448
+ "::-webkit-scrollbar-thumb",
449
+ "::-webkit-scrollbar-track",
450
+ "::-webkit-scrollbar-track-piece",
451
+ "::file-selector-button"
452
+ ];
453
+ const PseudoClassesAndElementsStr = Object.entries(PseudoClasses).map(([key]) => key).sort((a, b) => b.length - a.length).join("|");
454
+ const PseudoClassesAndElementsColonStr = Object.entries(PseudoClassesColon).map(([key]) => key).sort((a, b) => b.length - a.length).join("|");
455
+ function createTaggedPseudoClassMatcher(tag, parent, combinator, utils) {
456
+ const { h, variantGetBracket } = utils;
457
+ const rawRE = new RegExp(`^(${escapeRegExp(parent)}:)(\\S+)${escapeRegExp(combinator)}\\1`);
458
+ let splitRE;
459
+ let pseudoRE;
460
+ let pseudoColonRE;
461
+ let pseudoVarRE;
462
+ const matchBracket = (input) => {
463
+ const body = variantGetBracket(`${tag}-`, input, []);
464
+ if (!body)
465
+ return;
466
+ const [match, rest] = body;
467
+ const bracketValue = h.bracket(match);
468
+ if (bracketValue == null)
469
+ return;
470
+ const label = rest.split(splitRE, 1)?.[0] ?? "";
471
+ const prefix = `${parent}${escapeSelector(label)}`;
472
+ return [
473
+ label,
474
+ input.slice(input.length - (rest.length - label.length - 1)),
475
+ bracketValue.includes("&") ? bracketValue.replace(/&/g, prefix) : `${prefix}${bracketValue}`
476
+ ];
477
+ };
478
+ const matchPseudo = (input) => {
479
+ const match = input.match(pseudoRE) || input.match(pseudoColonRE);
480
+ if (!match)
481
+ return;
482
+ const [original, fn, pseudoKey] = match;
483
+ const label = match[3] ?? "";
484
+ let pseudo = PseudoClasses[pseudoKey] || PseudoClassesColon[pseudoKey] || `:${pseudoKey}`;
485
+ if (fn)
486
+ pseudo = `:${fn}(${pseudo})`;
487
+ return [
488
+ label,
489
+ input.slice(original.length),
490
+ `${parent}${escapeSelector(label)}${pseudo}`,
491
+ pseudoKey
492
+ ];
493
+ };
494
+ const matchPseudoVar = (input) => {
495
+ const match = input.match(pseudoVarRE);
496
+ if (!match)
497
+ return;
498
+ const [original, fn, pseudoValue] = match;
499
+ const label = match[3] ?? "";
500
+ const pseudo = `:${fn}(${pseudoValue})`;
501
+ return [
502
+ label,
503
+ input.slice(original.length),
504
+ `${parent}${escapeSelector(label)}${pseudo}`
505
+ ];
506
+ };
507
+ return {
508
+ name: `pseudo:${tag}`,
509
+ match(input, ctx) {
510
+ if (!(splitRE && pseudoRE && pseudoColonRE)) {
511
+ splitRE = new RegExp(`(?:${ctx.generator.config.separators.join("|")})`);
512
+ pseudoRE = new RegExp(`^${tag}-(?:(?:(${PseudoClassFunctionsStr})-)?(${PseudoClassesStr}))(?:(/[\\w-]+))?(?:${ctx.generator.config.separators.join("|")})`);
513
+ pseudoColonRE = new RegExp(`^${tag}-(?:(?:(${PseudoClassFunctionsStr})-)?(${PseudoClassesColonStr}))(?:(/[\\w-]+))?(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
514
+ pseudoVarRE = new RegExp(`^${tag}-(?:(${PseudoClassFunctionsStr})-)?\\[(.+)\\](?:(/[\\w-]+))?(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
515
+ }
516
+ if (!input.startsWith(tag))
517
+ return;
518
+ const result = matchBracket(input) || matchPseudo(input) || matchPseudoVar(input);
519
+ if (!result)
520
+ return;
521
+ const [_label, matcher, prefix, pseudoName = ""] = result;
522
+ return {
523
+ matcher,
524
+ handle: (input2, next) => next({
525
+ ...input2,
526
+ prefix: `${prefix}${combinator}${input2.prefix}`.replace(rawRE, "$1$2:"),
527
+ sort: PseudoClassesKeys.indexOf(pseudoName) ?? PseudoClassesColonKeys.indexOf(pseudoName)
528
+ })
529
+ };
530
+ },
531
+ multiPass: true
532
+ };
533
+ }
534
+ function createPseudoClassesAndElements(utils) {
535
+ const { h } = utils;
536
+ let PseudoClassesAndElementsRE;
537
+ let PseudoClassesAndElementsColonRE;
538
+ let PseudoClassesMultiRE;
539
+ return [
540
+ {
541
+ name: "pseudo",
542
+ match(input, ctx) {
543
+ if (!(PseudoClassesAndElementsRE && PseudoClassesAndElementsColonRE)) {
544
+ PseudoClassesAndElementsRE = new RegExp(`^(${PseudoClassesAndElementsStr})(?:-(\\d+|\\[\\w+\\]))?(?:${ctx.generator.config.separators.join("|")})`);
545
+ PseudoClassesAndElementsColonRE = new RegExp(`^(${PseudoClassesAndElementsColonStr})(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
546
+ }
547
+ const match = input.match(PseudoClassesAndElementsRE) || input.match(PseudoClassesAndElementsColonRE);
548
+ if (match) {
549
+ let pseudo = PseudoClasses[match[1]] || PseudoClassesColon[match[1]] || `:${match[1]}`;
550
+ if (match[2]) {
551
+ let anPlusB;
552
+ if (match[2].startsWith("[") && match[2].endsWith("]")) {
553
+ anPlusB = h.bracket(match[2]);
554
+ } else {
555
+ anPlusB = match[2];
556
+ }
557
+ if (anPlusB) {
558
+ pseudo = pseudo.replace(PseudoPlaceholder, anPlusB);
559
+ }
560
+ }
561
+ let index = PseudoClassesKeys.indexOf(match[1]);
562
+ if (index === -1)
563
+ index = PseudoClassesColonKeys.indexOf(match[1]);
564
+ if (index === -1)
565
+ index = void 0;
566
+ return {
567
+ matcher: input.slice(match[0].length),
568
+ handle: (input2, next) => {
569
+ const selectors = pseudo.includes("::") && !excludedPseudo.includes(pseudo) ? {
570
+ pseudo: `${input2.pseudo}${pseudo}`
571
+ } : {
572
+ selector: `${input2.selector}${pseudo}`
573
+ };
574
+ return next({
575
+ ...input2,
576
+ ...selectors,
577
+ sort: index,
578
+ noMerge: true
579
+ });
580
+ }
581
+ };
582
+ }
583
+ },
584
+ multiPass: true,
585
+ autocomplete: `(${PseudoClassesAndElementsStr}|${PseudoClassesAndElementsColonStr}):`
586
+ },
587
+ {
588
+ name: "pseudo:multi",
589
+ match(input, ctx) {
590
+ if (!PseudoClassesMultiRE) {
591
+ PseudoClassesMultiRE = new RegExp(`^(${PseudoClassesMultiStr})(?:${ctx.generator.config.separators.join("|")})`);
592
+ }
593
+ const match = input.match(PseudoClassesMultiRE);
594
+ if (match) {
595
+ const pseudos = PseudoClassesMulti[match[1]];
596
+ return pseudos.map((pseudo) => {
597
+ return {
598
+ matcher: input.slice(match[0].length),
599
+ handle: (input2, next) => next({
600
+ ...input2,
601
+ pseudo: `${input2.pseudo}${pseudo}`
602
+ })
603
+ };
604
+ });
605
+ }
606
+ },
607
+ multiPass: false,
608
+ autocomplete: `(${PseudoClassesMultiStr}):`
609
+ }
610
+ ];
611
+ }
612
+ function createPseudoClassFunctions(utils) {
613
+ const { getBracket, h } = utils;
614
+ let PseudoClassFunctionsRE;
615
+ let PseudoClassColonFunctionsRE;
616
+ let PseudoClassVarFunctionRE;
617
+ return {
618
+ match(input, ctx) {
619
+ if (!(PseudoClassFunctionsRE && PseudoClassColonFunctionsRE)) {
620
+ PseudoClassFunctionsRE = new RegExp(`^(${PseudoClassFunctionsStr})-(${PseudoClassesStr})(?:${ctx.generator.config.separators.join("|")})`);
621
+ PseudoClassColonFunctionsRE = new RegExp(`^(${PseudoClassFunctionsStr})-(${PseudoClassesColonStr})(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
622
+ PseudoClassVarFunctionRE = new RegExp(`^(${PseudoClassFunctionsStr})-(\\[.+\\])(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
623
+ }
624
+ const match = input.match(PseudoClassFunctionsRE) || input.match(PseudoClassColonFunctionsRE) || input.match(PseudoClassVarFunctionRE);
625
+ if (match) {
626
+ const fn = match[1];
627
+ const fnVal = getBracket(match[2], "[", "]");
628
+ const pseudo = fnVal ? h.bracket(match[2]) : PseudoClasses[match[2]] || PseudoClassesColon[match[2]] || `:${match[2]}`;
629
+ return {
630
+ matcher: input.slice(match[0].length),
631
+ selector: (s) => `${s}:${fn}(${pseudo})`
632
+ };
633
+ }
634
+ },
635
+ multiPass: true,
636
+ autocomplete: `(${PseudoClassFunctionsStr})-(${PseudoClassesStr}|${PseudoClassesColonStr}):`
637
+ };
638
+ }
639
+ function createTaggedPseudoClasses(options, utils) {
640
+ const attributify = !!options?.attributifyPseudo;
641
+ let firstPrefix = options?.prefix ?? "";
642
+ firstPrefix = (Array.isArray(firstPrefix) ? firstPrefix : [firstPrefix]).filter(Boolean)[0] ?? "";
643
+ const tagWithPrefix = (tag, combinator) => createTaggedPseudoClassMatcher(tag, attributify ? `[${firstPrefix}${tag}=""]` : `.${firstPrefix}${tag}`, combinator, utils);
644
+ return [
645
+ tagWithPrefix("group", " "),
646
+ tagWithPrefix("peer", "~"),
647
+ tagWithPrefix("parent", ">"),
648
+ tagWithPrefix("previous", "+"),
649
+ tagWithPrefix("group-aria", " "),
650
+ tagWithPrefix("peer-aria", "~"),
651
+ tagWithPrefix("parent-aria", ">"),
652
+ tagWithPrefix("previous-aria", "+")
653
+ ];
654
+ }
655
+ const PartClassesRE = /(part-\[(.+)\]:)(.+)/;
656
+ function createPartClasses() {
657
+ return {
658
+ match(input) {
659
+ const match = input.match(PartClassesRE);
660
+ if (match) {
661
+ const part = `part(${match[2]})`;
662
+ return {
663
+ matcher: input.slice(match[1].length),
664
+ selector: (s) => `${s}::${part}`
665
+ };
666
+ }
667
+ },
668
+ multiPass: true
669
+ };
670
+ }
671
+
355
672
  function variantMatcher(name, handler) {
356
673
  let re;
357
674
  return {
@@ -432,4 +749,4 @@ function variantGetParameter(prefix, matcher, separators) {
432
749
  }
433
750
  }
434
751
 
435
- export { alphaPlaceholders, alphaPlaceholdersRE, calcMaxWidthBySize, colorOpacityToString, colorToString, createValueHandler, cssColorFunctions, getBracket, getStringComponent, getStringComponents, hasIconFn, hasThemeFn, hex2rgba, iconFnRE, parseCssColor, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
752
+ export { PseudoClassFunctions, PseudoClassFunctionsStr, PseudoClasses, PseudoClassesAndElementsColonStr, PseudoClassesAndElementsStr, PseudoClassesColon, PseudoClassesColonKeys, PseudoClassesColonStr, PseudoClassesKeys, PseudoClassesMulti, PseudoClassesMultiStr, PseudoClassesStr, alphaPlaceholders, alphaPlaceholdersRE, calcMaxWidthBySize, colorOpacityToString, colorToString, createPartClasses, createPseudoClassFunctions, createPseudoClassesAndElements, createTaggedPseudoClassMatcher, createTaggedPseudoClasses, createValueHandler, cssColorFunctions, excludedPseudo, getBracket, getStringComponent, getStringComponents, hasIconFn, hasThemeFn, hex2rgba, hueInterpolationMethods, iconFnRE, isInterpolatedMethod, parseCssColor, polarColorSpace, rectangularColorSpace, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/rule-utils",
3
3
  "type": "module",
4
- "version": "66.1.4",
4
+ "version": "66.2.0",
5
5
  "description": "Utilities for UnoCSS",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "magic-string": "^0.30.17",
37
- "@unocss/core": "^66.1.4"
37
+ "@unocss/core": "^66.2.0"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "unbuild",