@unocss/core 0.49.7 → 0.50.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.cjs +23 -25
- package/dist/index.d.ts +9 -5
- package/dist/index.mjs +23 -25
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -327,6 +327,7 @@ function createValueHandler(handlers) {
|
|
|
327
327
|
}
|
|
328
328
|
|
|
329
329
|
const defaultSplitRE = /\\?[\s'"`;{}]+/g;
|
|
330
|
+
const quotedArbitraryValuesRE = /(?:[\w&:[\]-]|\[\S+=\S+\])+\[\\?['"]?\S+?['"]\]\]?[\w:-]*/g;
|
|
330
331
|
const arbitraryPropertyRE = /\[(\\\W|[\w-])+:['"]?\S+?['"]?\]/g;
|
|
331
332
|
const arbitraryPropertyCandidateRE = new RegExp(`^${arbitraryPropertyRE.source}$`);
|
|
332
333
|
const splitCode = (code) => {
|
|
@@ -336,6 +337,8 @@ const splitCode = (code) => {
|
|
|
336
337
|
continue;
|
|
337
338
|
result.add(match[0]);
|
|
338
339
|
}
|
|
340
|
+
for (const match of code.matchAll(quotedArbitraryValuesRE))
|
|
341
|
+
result.add(match[0]);
|
|
339
342
|
code.split(defaultSplitRE).forEach((match) => {
|
|
340
343
|
isValidSelector(match) && !arbitraryPropertyCandidateRE.test(match) && result.add(match);
|
|
341
344
|
});
|
|
@@ -419,7 +422,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
419
422
|
...rawPresets.filter((p) => !p.enforce),
|
|
420
423
|
...rawPresets.filter((p) => p.enforce === "post")
|
|
421
424
|
];
|
|
422
|
-
const layers = Object.assign(DEFAULT_LAYERS, ...rawPresets.map((i) => i.layers),
|
|
425
|
+
const layers = Object.assign({}, DEFAULT_LAYERS, ...rawPresets.map((i) => i.layers), config.layers);
|
|
423
426
|
function mergePresets(key) {
|
|
424
427
|
return uniq([
|
|
425
428
|
...sortedPresets.flatMap((p) => toArray(p[key] || [])),
|
|
@@ -473,7 +476,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
473
476
|
postprocess: mergePresets("postprocess"),
|
|
474
477
|
preflights: mergePresets("preflights"),
|
|
475
478
|
autocomplete,
|
|
476
|
-
variants: mergePresets("variants").map(normalizeVariant),
|
|
479
|
+
variants: mergePresets("variants").map(normalizeVariant).sort((a, b) => (a.order || 0) - (b.order || 0)),
|
|
477
480
|
shortcuts: resolveShortcuts(mergePresets("shortcuts")).reverse(),
|
|
478
481
|
extractors,
|
|
479
482
|
safelist: mergePresets("safelist"),
|
|
@@ -481,7 +484,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
481
484
|
};
|
|
482
485
|
}
|
|
483
486
|
|
|
484
|
-
const version = "0.
|
|
487
|
+
const version = "0.50.0";
|
|
485
488
|
|
|
486
489
|
class UnoGenerator {
|
|
487
490
|
constructor(userConfig = {}, defaults = {}) {
|
|
@@ -550,7 +553,7 @@ class UnoGenerator {
|
|
|
550
553
|
this._cache.set(cacheKey, null);
|
|
551
554
|
return;
|
|
552
555
|
}
|
|
553
|
-
const applied = this.matchVariants(raw, current);
|
|
556
|
+
const applied = await this.matchVariants(raw, current);
|
|
554
557
|
if (!applied || this.isBlocked(applied[1])) {
|
|
555
558
|
this.blocked.add(raw);
|
|
556
559
|
this._cache.set(cacheKey, null);
|
|
@@ -559,7 +562,7 @@ class UnoGenerator {
|
|
|
559
562
|
const context = this.makeContext(raw, [alias || applied[0], applied[1], applied[2], applied[3]]);
|
|
560
563
|
if (this.config.details)
|
|
561
564
|
context.variants = [...applied[3]];
|
|
562
|
-
const expanded = this.expandShortcut(context.currentSelector, context);
|
|
565
|
+
const expanded = await this.expandShortcut(context.currentSelector, context);
|
|
563
566
|
const utils = expanded ? await this.stringifyShortcuts(context.variantMatch, context, expanded[0], expanded[1]) : (await this.parseUtil(context.variantMatch, context))?.map((i) => this.stringifyUtil(i, context)).filter(notNull);
|
|
564
567
|
if (utils?.length) {
|
|
565
568
|
this._cache.set(cacheKey, utils);
|
|
@@ -634,7 +637,9 @@ class UnoGenerator {
|
|
|
634
637
|
return layerCache[layer];
|
|
635
638
|
let css = Array.from(sheet).sort((a, b) => (this.parentOrders.get(a[0]) ?? 0) - (this.parentOrders.get(b[0]) ?? 0) || a[0]?.localeCompare(b[0] || "") || 0).map(([parent, items]) => {
|
|
636
639
|
const size = items.length;
|
|
637
|
-
const sorted = items.filter((i) => (i[4]?.layer || LAYER_DEFAULT) === layer).sort(
|
|
640
|
+
const sorted = items.filter((i) => (i[4]?.layer || LAYER_DEFAULT) === layer).sort(
|
|
641
|
+
(a, b) => a[0] - b[0] || (a[4]?.sort || 0) - (b[4]?.sort || 0) || a[5]?.currentSelector?.localeCompare(b[5]?.currentSelector ?? "") || a[1]?.localeCompare(b[1] || "") || a[2]?.localeCompare(b[2] || "") || 0
|
|
642
|
+
).map(([, selector, body, , meta, , variantNoMerge]) => {
|
|
638
643
|
const scopedSelector = selector ? applyScope(selector, scope) : selector;
|
|
639
644
|
return [
|
|
640
645
|
[[scopedSelector ?? "", meta?.sort ?? 0]],
|
|
@@ -684,7 +689,7 @@ class UnoGenerator {
|
|
|
684
689
|
getLayer
|
|
685
690
|
};
|
|
686
691
|
}
|
|
687
|
-
matchVariants(raw, current) {
|
|
692
|
+
async matchVariants(raw, current) {
|
|
688
693
|
const variants = /* @__PURE__ */ new Set();
|
|
689
694
|
const handlers = [];
|
|
690
695
|
let processed = current || raw;
|
|
@@ -699,7 +704,7 @@ class UnoGenerator {
|
|
|
699
704
|
for (const v of this.config.variants) {
|
|
700
705
|
if (!v.multiPass && variants.has(v))
|
|
701
706
|
continue;
|
|
702
|
-
let handler = v.match(processed, context);
|
|
707
|
+
let handler = await v.match(processed, context);
|
|
703
708
|
if (!handler)
|
|
704
709
|
continue;
|
|
705
710
|
if (isString(handler))
|
|
@@ -744,11 +749,11 @@ class UnoGenerator {
|
|
|
744
749
|
if (parent != null && parentOrder != null)
|
|
745
750
|
this.parentOrders.set(parent, parentOrder);
|
|
746
751
|
const obj = {
|
|
747
|
-
selector:
|
|
752
|
+
selector: [
|
|
748
753
|
variantContextResult.prefix,
|
|
749
754
|
variantContextResult.selector,
|
|
750
755
|
variantContextResult.pseudo
|
|
751
|
-
].join("")
|
|
756
|
+
].join(""),
|
|
752
757
|
entries: variantContextResult.entries,
|
|
753
758
|
parent,
|
|
754
759
|
layer: variantContextResult.layer,
|
|
@@ -770,7 +775,7 @@ class UnoGenerator {
|
|
|
770
775
|
return cssBody;
|
|
771
776
|
}
|
|
772
777
|
async parseUtil(input, context, internal = false, shortcutPrefix) {
|
|
773
|
-
const [raw, processed, variantHandlers] = isString(input) ? this.matchVariants(input) : input;
|
|
778
|
+
const [raw, processed, variantHandlers] = isString(input) ? await this.matchVariants(input) : input;
|
|
774
779
|
if (this.config.details)
|
|
775
780
|
context.rules = context.rules ?? [];
|
|
776
781
|
const staticMatch = this.config.rulesStaticMap[processed];
|
|
@@ -842,7 +847,7 @@ class UnoGenerator {
|
|
|
842
847
|
};
|
|
843
848
|
return [parsed[0], selector, body, parent, ruleMeta, this.config.details ? context : void 0, noMerge];
|
|
844
849
|
}
|
|
845
|
-
expandShortcut(input, context, depth = 5) {
|
|
850
|
+
async expandShortcut(input, context, depth = 5) {
|
|
846
851
|
if (depth === 0)
|
|
847
852
|
return;
|
|
848
853
|
const recordShortcut = this.config.details ? (s) => {
|
|
@@ -881,9 +886,9 @@ class UnoGenerator {
|
|
|
881
886
|
if (isString(result))
|
|
882
887
|
result = expandVariantGroup(result.trim()).split(/\s+/g);
|
|
883
888
|
if (!result) {
|
|
884
|
-
const [raw, inputWithoutVariant] = isString(input) ? this.matchVariants(input) : input;
|
|
889
|
+
const [raw, inputWithoutVariant] = isString(input) ? await this.matchVariants(input) : input;
|
|
885
890
|
if (raw !== inputWithoutVariant) {
|
|
886
|
-
const expanded = this.expandShortcut(inputWithoutVariant, context, depth - 1);
|
|
891
|
+
const expanded = await this.expandShortcut(inputWithoutVariant, context, depth - 1);
|
|
887
892
|
if (expanded)
|
|
888
893
|
result = expanded[0].map((item) => isString(item) ? raw.replace(inputWithoutVariant, item) : item);
|
|
889
894
|
}
|
|
@@ -891,7 +896,9 @@ class UnoGenerator {
|
|
|
891
896
|
if (!result)
|
|
892
897
|
return;
|
|
893
898
|
return [
|
|
894
|
-
|
|
899
|
+
(await Promise.all(result.map(
|
|
900
|
+
async (r) => (isString(r) ? (await this.expandShortcut(r, context, depth - 1))?.[0] : void 0) || [r]
|
|
901
|
+
))).flat(1).filter(Boolean),
|
|
895
902
|
meta
|
|
896
903
|
];
|
|
897
904
|
}
|
|
@@ -950,15 +957,6 @@ function applyScope(css, scope) {
|
|
|
950
957
|
else
|
|
951
958
|
return scope ? `${scope} ${css}` : css;
|
|
952
959
|
}
|
|
953
|
-
function movePseudoElementsEnd(selector) {
|
|
954
|
-
const pseudoElements = selector.match(/::[\w-]+(\([\w-]+\))?/g);
|
|
955
|
-
if (pseudoElements) {
|
|
956
|
-
for (const e2 of pseudoElements)
|
|
957
|
-
selector = selector.replace(e2, "");
|
|
958
|
-
selector += pseudoElements.join("");
|
|
959
|
-
}
|
|
960
|
-
return selector;
|
|
961
|
-
}
|
|
962
960
|
const attributifyRe = /^\[(.+?)(~?=)"(.*)"\]$/;
|
|
963
961
|
function toEscapedSelector(raw) {
|
|
964
962
|
if (attributifyRe.test(raw))
|
|
@@ -998,13 +996,13 @@ exports.isString = isString;
|
|
|
998
996
|
exports.isValidSelector = isValidSelector;
|
|
999
997
|
exports.makeRegexClassGroup = makeRegexClassGroup;
|
|
1000
998
|
exports.mergeDeep = mergeDeep;
|
|
1001
|
-
exports.movePseudoElementsEnd = movePseudoElementsEnd;
|
|
1002
999
|
exports.noop = noop;
|
|
1003
1000
|
exports.normalizeCSSEntries = normalizeCSSEntries;
|
|
1004
1001
|
exports.normalizeCSSValues = normalizeCSSValues;
|
|
1005
1002
|
exports.normalizeVariant = normalizeVariant;
|
|
1006
1003
|
exports.notNull = notNull;
|
|
1007
1004
|
exports.parseVariantGroup = parseVariantGroup;
|
|
1005
|
+
exports.quotedArbitraryValuesRE = quotedArbitraryValuesRE;
|
|
1008
1006
|
exports.regexScopePlaceholder = regexScopePlaceholder;
|
|
1009
1007
|
exports.toArray = toArray;
|
|
1010
1008
|
exports.toEscapedSelector = toEscapedSelector;
|
package/dist/index.d.ts
CHANGED
|
@@ -68,19 +68,18 @@ declare class UnoGenerator<Theme extends {} = {}> {
|
|
|
68
68
|
makeContext(raw: string, applied: VariantMatchedResult<Theme>): RuleContext<Theme>;
|
|
69
69
|
parseToken(raw: string, alias?: string): Promise<StringifiedUtil<Theme>[] | null | undefined>;
|
|
70
70
|
generate(input: string | Set<string> | string[], options?: GenerateOptions): Promise<GenerateResult>;
|
|
71
|
-
matchVariants(raw: string, current?: string): VariantMatchedResult<Theme
|
|
71
|
+
matchVariants(raw: string, current?: string): Promise<VariantMatchedResult<Theme>>;
|
|
72
72
|
private applyVariants;
|
|
73
73
|
constructCustomCSS(context: Readonly<RuleContext<Theme>>, body: CSSObject | CSSEntries, overrideSelector?: string): string;
|
|
74
74
|
parseUtil(input: string | VariantMatchedResult<Theme>, context: RuleContext<Theme>, internal?: boolean, shortcutPrefix?: string | string[] | undefined): Promise<(ParsedUtil | RawUtil)[] | undefined>;
|
|
75
75
|
stringifyUtil(parsed?: ParsedUtil | RawUtil, context?: RuleContext<Theme>): StringifiedUtil<Theme> | undefined;
|
|
76
|
-
expandShortcut(input: string, context: RuleContext<Theme>, depth?: number): [ShortcutValue[], RuleMeta | undefined] | undefined
|
|
76
|
+
expandShortcut(input: string, context: RuleContext<Theme>, depth?: number): Promise<[ShortcutValue[], RuleMeta | undefined] | undefined>;
|
|
77
77
|
stringifyShortcuts(parent: VariantMatchedResult<Theme>, context: RuleContext<Theme>, expanded: ShortcutValue[], meta?: RuleMeta): Promise<StringifiedUtil<Theme>[] | undefined>;
|
|
78
78
|
isBlocked(raw: string): boolean;
|
|
79
79
|
}
|
|
80
80
|
declare function createGenerator<Theme extends {} = {}>(config?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): UnoGenerator<Theme>;
|
|
81
81
|
declare const regexScopePlaceholder: RegExp;
|
|
82
82
|
declare const hasScopePlaceholder: (css: string) => RegExpMatchArray | null;
|
|
83
|
-
declare function movePseudoElementsEnd(selector: string): string;
|
|
84
83
|
declare function toEscapedSelector(raw: string): string;
|
|
85
84
|
|
|
86
85
|
declare function escapeRegExp(string: string): string;
|
|
@@ -401,7 +400,7 @@ interface VariantHandler {
|
|
|
401
400
|
*/
|
|
402
401
|
layer?: string | undefined;
|
|
403
402
|
}
|
|
404
|
-
type VariantFunction<Theme extends {} = {}> = (matcher: string, context: Readonly<VariantContext<Theme>>) => string | VariantHandler | undefined
|
|
403
|
+
type VariantFunction<Theme extends {} = {}> = (matcher: string, context: Readonly<VariantContext<Theme>>) => Awaitable<string | VariantHandler | undefined>;
|
|
405
404
|
interface VariantObject<Theme extends {} = {}> {
|
|
406
405
|
/**
|
|
407
406
|
* The name of the variant.
|
|
@@ -411,6 +410,10 @@ interface VariantObject<Theme extends {} = {}> {
|
|
|
411
410
|
* The entry function to match and rewrite the selector for further processing.
|
|
412
411
|
*/
|
|
413
412
|
match: VariantFunction<Theme>;
|
|
413
|
+
/**
|
|
414
|
+
* Sort for when the match is applied.
|
|
415
|
+
*/
|
|
416
|
+
order?: number;
|
|
414
417
|
/**
|
|
415
418
|
* Allows this variant to be used more than once in matching a single rule
|
|
416
419
|
*
|
|
@@ -822,9 +825,10 @@ interface GenerateOptions {
|
|
|
822
825
|
scope?: string;
|
|
823
826
|
}
|
|
824
827
|
|
|
828
|
+
declare const quotedArbitraryValuesRE: RegExp;
|
|
825
829
|
declare const arbitraryPropertyRE: RegExp;
|
|
826
830
|
declare const extractorSplit: Extractor;
|
|
827
831
|
|
|
828
832
|
declare const extractorSvelte: Extractor;
|
|
829
833
|
|
|
830
|
-
export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValue, CSSValues, CliEntryItem, CliOptions, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, ExtraContentOptions, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, ParsedColorValue, ParsedUtil, PartialByKeys, PluginOptions, Postprocessor, Preflight, PreflightContext, PreparedRule, Preprocessor, Preset, PresetOptions, RGBAColorValue, RawUtil, Replacement, RequiredByKey, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, ShortcutValue, SourceCodeTransformer, SourceCodeTransformerEnforce, SourceMap, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, SuggestResult, ThemeExtender, TransformResult, TwoKeyMap, UnoGenerator, UnocssPluginContext, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, ValueHandler, ValueHandlerCallback, Variant, VariantContext, VariantFunction, VariantHandler, VariantHandlerContext, VariantMatchedResult, VariantObject, arbitraryPropertyRE, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, makeRegexClassGroup, mergeDeep,
|
|
834
|
+
export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValue, CSSValues, CliEntryItem, CliOptions, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, ExtraContentOptions, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, ParsedColorValue, ParsedUtil, PartialByKeys, PluginOptions, Postprocessor, Preflight, PreflightContext, PreparedRule, Preprocessor, Preset, PresetOptions, RGBAColorValue, RawUtil, Replacement, RequiredByKey, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, ShortcutValue, SourceCodeTransformer, SourceCodeTransformerEnforce, SourceMap, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, SuggestResult, ThemeExtender, TransformResult, TwoKeyMap, UnoGenerator, UnocssPluginContext, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, ValueHandler, ValueHandlerCallback, Variant, VariantContext, VariantFunction, VariantHandler, VariantHandlerContext, VariantMatchedResult, VariantObject, arbitraryPropertyRE, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, makeRegexClassGroup, mergeDeep, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, parseVariantGroup, quotedArbitraryValuesRE, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
|
package/dist/index.mjs
CHANGED
|
@@ -323,6 +323,7 @@ function createValueHandler(handlers) {
|
|
|
323
323
|
}
|
|
324
324
|
|
|
325
325
|
const defaultSplitRE = /\\?[\s'"`;{}]+/g;
|
|
326
|
+
const quotedArbitraryValuesRE = /(?:[\w&:[\]-]|\[\S+=\S+\])+\[\\?['"]?\S+?['"]\]\]?[\w:-]*/g;
|
|
326
327
|
const arbitraryPropertyRE = /\[(\\\W|[\w-])+:['"]?\S+?['"]?\]/g;
|
|
327
328
|
const arbitraryPropertyCandidateRE = new RegExp(`^${arbitraryPropertyRE.source}$`);
|
|
328
329
|
const splitCode = (code) => {
|
|
@@ -332,6 +333,8 @@ const splitCode = (code) => {
|
|
|
332
333
|
continue;
|
|
333
334
|
result.add(match[0]);
|
|
334
335
|
}
|
|
336
|
+
for (const match of code.matchAll(quotedArbitraryValuesRE))
|
|
337
|
+
result.add(match[0]);
|
|
335
338
|
code.split(defaultSplitRE).forEach((match) => {
|
|
336
339
|
isValidSelector(match) && !arbitraryPropertyCandidateRE.test(match) && result.add(match);
|
|
337
340
|
});
|
|
@@ -415,7 +418,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
415
418
|
...rawPresets.filter((p) => !p.enforce),
|
|
416
419
|
...rawPresets.filter((p) => p.enforce === "post")
|
|
417
420
|
];
|
|
418
|
-
const layers = Object.assign(DEFAULT_LAYERS, ...rawPresets.map((i) => i.layers),
|
|
421
|
+
const layers = Object.assign({}, DEFAULT_LAYERS, ...rawPresets.map((i) => i.layers), config.layers);
|
|
419
422
|
function mergePresets(key) {
|
|
420
423
|
return uniq([
|
|
421
424
|
...sortedPresets.flatMap((p) => toArray(p[key] || [])),
|
|
@@ -469,7 +472,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
469
472
|
postprocess: mergePresets("postprocess"),
|
|
470
473
|
preflights: mergePresets("preflights"),
|
|
471
474
|
autocomplete,
|
|
472
|
-
variants: mergePresets("variants").map(normalizeVariant),
|
|
475
|
+
variants: mergePresets("variants").map(normalizeVariant).sort((a, b) => (a.order || 0) - (b.order || 0)),
|
|
473
476
|
shortcuts: resolveShortcuts(mergePresets("shortcuts")).reverse(),
|
|
474
477
|
extractors,
|
|
475
478
|
safelist: mergePresets("safelist"),
|
|
@@ -477,7 +480,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
477
480
|
};
|
|
478
481
|
}
|
|
479
482
|
|
|
480
|
-
const version = "0.
|
|
483
|
+
const version = "0.50.0";
|
|
481
484
|
|
|
482
485
|
class UnoGenerator {
|
|
483
486
|
constructor(userConfig = {}, defaults = {}) {
|
|
@@ -546,7 +549,7 @@ class UnoGenerator {
|
|
|
546
549
|
this._cache.set(cacheKey, null);
|
|
547
550
|
return;
|
|
548
551
|
}
|
|
549
|
-
const applied = this.matchVariants(raw, current);
|
|
552
|
+
const applied = await this.matchVariants(raw, current);
|
|
550
553
|
if (!applied || this.isBlocked(applied[1])) {
|
|
551
554
|
this.blocked.add(raw);
|
|
552
555
|
this._cache.set(cacheKey, null);
|
|
@@ -555,7 +558,7 @@ class UnoGenerator {
|
|
|
555
558
|
const context = this.makeContext(raw, [alias || applied[0], applied[1], applied[2], applied[3]]);
|
|
556
559
|
if (this.config.details)
|
|
557
560
|
context.variants = [...applied[3]];
|
|
558
|
-
const expanded = this.expandShortcut(context.currentSelector, context);
|
|
561
|
+
const expanded = await this.expandShortcut(context.currentSelector, context);
|
|
559
562
|
const utils = expanded ? await this.stringifyShortcuts(context.variantMatch, context, expanded[0], expanded[1]) : (await this.parseUtil(context.variantMatch, context))?.map((i) => this.stringifyUtil(i, context)).filter(notNull);
|
|
560
563
|
if (utils?.length) {
|
|
561
564
|
this._cache.set(cacheKey, utils);
|
|
@@ -630,7 +633,9 @@ class UnoGenerator {
|
|
|
630
633
|
return layerCache[layer];
|
|
631
634
|
let css = Array.from(sheet).sort((a, b) => (this.parentOrders.get(a[0]) ?? 0) - (this.parentOrders.get(b[0]) ?? 0) || a[0]?.localeCompare(b[0] || "") || 0).map(([parent, items]) => {
|
|
632
635
|
const size = items.length;
|
|
633
|
-
const sorted = items.filter((i) => (i[4]?.layer || LAYER_DEFAULT) === layer).sort(
|
|
636
|
+
const sorted = items.filter((i) => (i[4]?.layer || LAYER_DEFAULT) === layer).sort(
|
|
637
|
+
(a, b) => a[0] - b[0] || (a[4]?.sort || 0) - (b[4]?.sort || 0) || a[5]?.currentSelector?.localeCompare(b[5]?.currentSelector ?? "") || a[1]?.localeCompare(b[1] || "") || a[2]?.localeCompare(b[2] || "") || 0
|
|
638
|
+
).map(([, selector, body, , meta, , variantNoMerge]) => {
|
|
634
639
|
const scopedSelector = selector ? applyScope(selector, scope) : selector;
|
|
635
640
|
return [
|
|
636
641
|
[[scopedSelector ?? "", meta?.sort ?? 0]],
|
|
@@ -680,7 +685,7 @@ class UnoGenerator {
|
|
|
680
685
|
getLayer
|
|
681
686
|
};
|
|
682
687
|
}
|
|
683
|
-
matchVariants(raw, current) {
|
|
688
|
+
async matchVariants(raw, current) {
|
|
684
689
|
const variants = /* @__PURE__ */ new Set();
|
|
685
690
|
const handlers = [];
|
|
686
691
|
let processed = current || raw;
|
|
@@ -695,7 +700,7 @@ class UnoGenerator {
|
|
|
695
700
|
for (const v of this.config.variants) {
|
|
696
701
|
if (!v.multiPass && variants.has(v))
|
|
697
702
|
continue;
|
|
698
|
-
let handler = v.match(processed, context);
|
|
703
|
+
let handler = await v.match(processed, context);
|
|
699
704
|
if (!handler)
|
|
700
705
|
continue;
|
|
701
706
|
if (isString(handler))
|
|
@@ -740,11 +745,11 @@ class UnoGenerator {
|
|
|
740
745
|
if (parent != null && parentOrder != null)
|
|
741
746
|
this.parentOrders.set(parent, parentOrder);
|
|
742
747
|
const obj = {
|
|
743
|
-
selector:
|
|
748
|
+
selector: [
|
|
744
749
|
variantContextResult.prefix,
|
|
745
750
|
variantContextResult.selector,
|
|
746
751
|
variantContextResult.pseudo
|
|
747
|
-
].join("")
|
|
752
|
+
].join(""),
|
|
748
753
|
entries: variantContextResult.entries,
|
|
749
754
|
parent,
|
|
750
755
|
layer: variantContextResult.layer,
|
|
@@ -766,7 +771,7 @@ class UnoGenerator {
|
|
|
766
771
|
return cssBody;
|
|
767
772
|
}
|
|
768
773
|
async parseUtil(input, context, internal = false, shortcutPrefix) {
|
|
769
|
-
const [raw, processed, variantHandlers] = isString(input) ? this.matchVariants(input) : input;
|
|
774
|
+
const [raw, processed, variantHandlers] = isString(input) ? await this.matchVariants(input) : input;
|
|
770
775
|
if (this.config.details)
|
|
771
776
|
context.rules = context.rules ?? [];
|
|
772
777
|
const staticMatch = this.config.rulesStaticMap[processed];
|
|
@@ -838,7 +843,7 @@ class UnoGenerator {
|
|
|
838
843
|
};
|
|
839
844
|
return [parsed[0], selector, body, parent, ruleMeta, this.config.details ? context : void 0, noMerge];
|
|
840
845
|
}
|
|
841
|
-
expandShortcut(input, context, depth = 5) {
|
|
846
|
+
async expandShortcut(input, context, depth = 5) {
|
|
842
847
|
if (depth === 0)
|
|
843
848
|
return;
|
|
844
849
|
const recordShortcut = this.config.details ? (s) => {
|
|
@@ -877,9 +882,9 @@ class UnoGenerator {
|
|
|
877
882
|
if (isString(result))
|
|
878
883
|
result = expandVariantGroup(result.trim()).split(/\s+/g);
|
|
879
884
|
if (!result) {
|
|
880
|
-
const [raw, inputWithoutVariant] = isString(input) ? this.matchVariants(input) : input;
|
|
885
|
+
const [raw, inputWithoutVariant] = isString(input) ? await this.matchVariants(input) : input;
|
|
881
886
|
if (raw !== inputWithoutVariant) {
|
|
882
|
-
const expanded = this.expandShortcut(inputWithoutVariant, context, depth - 1);
|
|
887
|
+
const expanded = await this.expandShortcut(inputWithoutVariant, context, depth - 1);
|
|
883
888
|
if (expanded)
|
|
884
889
|
result = expanded[0].map((item) => isString(item) ? raw.replace(inputWithoutVariant, item) : item);
|
|
885
890
|
}
|
|
@@ -887,7 +892,9 @@ class UnoGenerator {
|
|
|
887
892
|
if (!result)
|
|
888
893
|
return;
|
|
889
894
|
return [
|
|
890
|
-
|
|
895
|
+
(await Promise.all(result.map(
|
|
896
|
+
async (r) => (isString(r) ? (await this.expandShortcut(r, context, depth - 1))?.[0] : void 0) || [r]
|
|
897
|
+
))).flat(1).filter(Boolean),
|
|
891
898
|
meta
|
|
892
899
|
];
|
|
893
900
|
}
|
|
@@ -946,15 +953,6 @@ function applyScope(css, scope) {
|
|
|
946
953
|
else
|
|
947
954
|
return scope ? `${scope} ${css}` : css;
|
|
948
955
|
}
|
|
949
|
-
function movePseudoElementsEnd(selector) {
|
|
950
|
-
const pseudoElements = selector.match(/::[\w-]+(\([\w-]+\))?/g);
|
|
951
|
-
if (pseudoElements) {
|
|
952
|
-
for (const e2 of pseudoElements)
|
|
953
|
-
selector = selector.replace(e2, "");
|
|
954
|
-
selector += pseudoElements.join("");
|
|
955
|
-
}
|
|
956
|
-
return selector;
|
|
957
|
-
}
|
|
958
956
|
const attributifyRe = /^\[(.+?)(~?=)"(.*)"\]$/;
|
|
959
957
|
function toEscapedSelector(raw) {
|
|
960
958
|
if (attributifyRe.test(raw))
|
|
@@ -965,4 +963,4 @@ function defaultVariantHandler(input, next) {
|
|
|
965
963
|
return next(input);
|
|
966
964
|
}
|
|
967
965
|
|
|
968
|
-
export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, arbitraryPropertyRE, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, makeRegexClassGroup, mergeDeep,
|
|
966
|
+
export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, arbitraryPropertyRE, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, makeRegexClassGroup, mergeDeep, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, parseVariantGroup, quotedArbitraryValuesRE, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.0",
|
|
4
4
|
"description": "The instant on-demand Atomic CSS engine.",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"magic-string": "^0.
|
|
40
|
+
"magic-string": "^0.29.0",
|
|
41
41
|
"unconfig": "^0.3.7"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|