@unocss/core 0.39.2 → 0.41.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 +40 -23
- package/dist/index.d.ts +43 -5
- package/dist/index.mjs +40 -23
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -350,7 +350,7 @@ function extractQuoted(str, options = {}) {
|
|
|
350
350
|
return result;
|
|
351
351
|
}
|
|
352
352
|
|
|
353
|
-
const splitCode = (code) => code.split(/[\s'"
|
|
353
|
+
const splitCode = (code) => code.split(/[\s'"`;=]+/g).filter(isValidSelector);
|
|
354
354
|
const extractorSplit = {
|
|
355
355
|
name: "split",
|
|
356
356
|
order: 0,
|
|
@@ -460,7 +460,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
460
460
|
};
|
|
461
461
|
}
|
|
462
462
|
|
|
463
|
-
const version = "0.
|
|
463
|
+
const version = "0.41.0";
|
|
464
464
|
|
|
465
465
|
class UnoGenerator {
|
|
466
466
|
constructor(userConfig = {}, defaults = {}) {
|
|
@@ -638,7 +638,10 @@ class UnoGenerator {
|
|
|
638
638
|
const selectors = selectorSortPair ? [...new Set(selectorSortPair.sort((a, b) => a[1] - b[1] || a[0]?.localeCompare(b[0] || "") || 0).map((pair) => pair[0]).filter(Boolean))] : [];
|
|
639
639
|
return selectors.length ? `${selectors.join(`,${nl}`)}{${body}}` : body;
|
|
640
640
|
}).filter(Boolean).reverse().join(nl);
|
|
641
|
-
|
|
641
|
+
if (!parent)
|
|
642
|
+
return rules;
|
|
643
|
+
const parents = parent.split(" $$ ");
|
|
644
|
+
return `${parents.join("{")}{${nl}${rules}${nl}}${parents.map((_) => "").join("}")}`;
|
|
642
645
|
}).filter(Boolean).join(nl);
|
|
643
646
|
if (preflights) {
|
|
644
647
|
css = [preflightsMap[layer], css].filter(Boolean).join(nl);
|
|
@@ -679,8 +682,6 @@ class UnoGenerator {
|
|
|
679
682
|
if (typeof handler === "string")
|
|
680
683
|
handler = { matcher: handler };
|
|
681
684
|
processed = handler.matcher;
|
|
682
|
-
if (Array.isArray(handler.parent))
|
|
683
|
-
this.parentOrders.set(handler.parent[0], handler.parent[1]);
|
|
684
685
|
handlers.unshift(handler);
|
|
685
686
|
variants.add(v);
|
|
686
687
|
applied = true;
|
|
@@ -694,25 +695,38 @@ class UnoGenerator {
|
|
|
694
695
|
return [raw, processed, handlers, variants];
|
|
695
696
|
}
|
|
696
697
|
applyVariants(parsed, variantHandlers = parsed[4], raw = parsed[1]) {
|
|
697
|
-
const
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
698
|
+
const handler = [...variantHandlers].sort((a, b) => (a.order || 0) - (b.order || 0)).reverse().reduce((previous, v) => (input) => {
|
|
699
|
+
const entries = v.body?.(input.entries) || input.entries;
|
|
700
|
+
const parents = Array.isArray(v.parent) ? v.parent : [v.parent, void 0];
|
|
701
|
+
return (v.handle ?? defaultVariantHandler)({
|
|
702
|
+
...input,
|
|
703
|
+
entries,
|
|
704
|
+
selector: v.selector?.(input.selector, entries) || input.selector,
|
|
705
|
+
parent: parents[0] || input.parent,
|
|
706
|
+
parentOrder: parents[1] || input.parentOrder,
|
|
707
|
+
layer: v.layer || input.layer,
|
|
708
|
+
sort: v.sort || input.sort
|
|
709
|
+
}, previous);
|
|
710
|
+
}, (input) => input);
|
|
711
|
+
const variantContextResult = handler({
|
|
712
|
+
prefix: "",
|
|
713
|
+
selector: toEscapedSelector(raw),
|
|
714
|
+
pseudo: "",
|
|
715
|
+
entries: parsed[2]
|
|
709
716
|
});
|
|
717
|
+
const { parent, parentOrder } = variantContextResult;
|
|
718
|
+
if (parent != null && parentOrder != null)
|
|
719
|
+
this.parentOrders.set(parent, parentOrder);
|
|
710
720
|
const obj = {
|
|
711
|
-
selector: movePseudoElementsEnd(
|
|
712
|
-
|
|
721
|
+
selector: movePseudoElementsEnd([
|
|
722
|
+
variantContextResult.prefix,
|
|
723
|
+
variantContextResult.selector,
|
|
724
|
+
variantContextResult.pseudo
|
|
725
|
+
].join("")),
|
|
726
|
+
entries: variantContextResult.entries,
|
|
713
727
|
parent,
|
|
714
|
-
layer,
|
|
715
|
-
sort
|
|
728
|
+
layer: variantContextResult.layer,
|
|
729
|
+
sort: variantContextResult.sort
|
|
716
730
|
};
|
|
717
731
|
for (const p of this.config.postprocess)
|
|
718
732
|
p(obj);
|
|
@@ -847,14 +861,14 @@ class UnoGenerator {
|
|
|
847
861
|
const mapItem = selectorMap.getFallback(selector, parent2, [[], item[0]]);
|
|
848
862
|
mapItem[0].push([entries, !!item[3]?.noMerge, sort ?? 0]);
|
|
849
863
|
}
|
|
850
|
-
return rawStringfieldUtil.concat(selectorMap.map(([e2, index], selector,
|
|
864
|
+
return rawStringfieldUtil.concat(selectorMap.map(([e2, index], selector, joinedParents) => {
|
|
851
865
|
const stringify = (flatten, noMerge, entrySortPair) => {
|
|
852
866
|
const maxSort = Math.max(...entrySortPair.map((e3) => e3[1]));
|
|
853
867
|
const entriesList = entrySortPair.map((e3) => e3[0]);
|
|
854
868
|
return (flatten ? [entriesList.flat(1)] : entriesList).map((entries) => {
|
|
855
869
|
const body = entriesToCss(entries);
|
|
856
870
|
if (body)
|
|
857
|
-
return [index, selector, body,
|
|
871
|
+
return [index, selector, body, joinedParents, { ...meta, noMerge, sort: maxSort }, context];
|
|
858
872
|
return void 0;
|
|
859
873
|
});
|
|
860
874
|
};
|
|
@@ -897,6 +911,9 @@ function toEscapedSelector(raw) {
|
|
|
897
911
|
return raw.replace(attributifyRe, (_, n, s, i) => `[${e(n)}${s}"${e(i)}"]`);
|
|
898
912
|
return `.${e(raw)}`;
|
|
899
913
|
}
|
|
914
|
+
function defaultVariantHandler(input, next) {
|
|
915
|
+
return next(input);
|
|
916
|
+
}
|
|
900
917
|
|
|
901
918
|
exports.BetterMap = BetterMap;
|
|
902
919
|
exports.CONTROL_SHORTCUT_NO_MERGE = CONTROL_SHORTCUT_NO_MERGE;
|
package/dist/index.d.ts
CHANGED
|
@@ -333,11 +333,53 @@ interface Preflight<Theme extends {} = {}> {
|
|
|
333
333
|
layer?: string;
|
|
334
334
|
}
|
|
335
335
|
declare type BlocklistRule = string | RegExp;
|
|
336
|
+
interface VariantHandlerContext {
|
|
337
|
+
/**
|
|
338
|
+
* Rewrite the output selector. Often be used to append parents.
|
|
339
|
+
*/
|
|
340
|
+
prefix: string;
|
|
341
|
+
/**
|
|
342
|
+
* Rewrite the output selector. Often be used to append pesudo classes.
|
|
343
|
+
*/
|
|
344
|
+
selector: string;
|
|
345
|
+
/**
|
|
346
|
+
* Rewrite the output selector. Often be used to append pesudo elements.
|
|
347
|
+
*/
|
|
348
|
+
pseudo: string;
|
|
349
|
+
/**
|
|
350
|
+
* Rewrite the output css body. The input come in [key,value][] pairs.
|
|
351
|
+
*/
|
|
352
|
+
entries: CSSEntries;
|
|
353
|
+
/**
|
|
354
|
+
* Provide a parent selector(e.g. media query) to the output css.
|
|
355
|
+
*/
|
|
356
|
+
parent?: string;
|
|
357
|
+
/**
|
|
358
|
+
* Provide order to the `parent` parent selector within layer.
|
|
359
|
+
*/
|
|
360
|
+
parentOrder?: number;
|
|
361
|
+
/**
|
|
362
|
+
* Override layer to the output css.
|
|
363
|
+
*/
|
|
364
|
+
layer?: string;
|
|
365
|
+
/**
|
|
366
|
+
* Order in which the variant is sorted within single rule.
|
|
367
|
+
*/
|
|
368
|
+
sort?: number;
|
|
369
|
+
}
|
|
336
370
|
interface VariantHandler {
|
|
371
|
+
/**
|
|
372
|
+
* Callback to process the handler.
|
|
373
|
+
*/
|
|
374
|
+
handle?: (input: VariantHandlerContext, next: (input: VariantHandlerContext) => VariantHandlerContext) => VariantHandlerContext;
|
|
337
375
|
/**
|
|
338
376
|
* The result rewritten selector for the next round of matching
|
|
339
377
|
*/
|
|
340
378
|
matcher: string;
|
|
379
|
+
/**
|
|
380
|
+
* Order in which the variant is applied to selector.
|
|
381
|
+
*/
|
|
382
|
+
order?: number;
|
|
341
383
|
/**
|
|
342
384
|
* Rewrite the output selector. Often be used to append pesudo classes or parents.
|
|
343
385
|
*/
|
|
@@ -350,10 +392,6 @@ interface VariantHandler {
|
|
|
350
392
|
* Provide a parent selector(e.g. media query) to the output css.
|
|
351
393
|
*/
|
|
352
394
|
parent?: string | [string, number] | undefined;
|
|
353
|
-
/**
|
|
354
|
-
* Order in which the variant is applied to selector.
|
|
355
|
-
*/
|
|
356
|
-
order?: number;
|
|
357
395
|
/**
|
|
358
396
|
* Order in which the variant is sorted within single rule.
|
|
359
397
|
*/
|
|
@@ -732,4 +770,4 @@ declare const extractorSplit: Extractor;
|
|
|
732
770
|
|
|
733
771
|
declare const extractorSvelte: Extractor;
|
|
734
772
|
|
|
735
|
-
export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValue, CSSValues, ConfigBase, DeepPartial, DetailString, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, ExtractStringOptions, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, ParsedColorValue, ParsedUtil, PartialByKeys, PluginOptions, Postprocessor, Preflight, PreflightContext, PreparedRule, Preprocessor, Preset, PresetOptions, RGBAColorValue, Range, RawUtil, Replacement, RequiredByKey, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, SourceCodeTransformer, SourceMap, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, SuggestResult, ThemeExtender, TransformResult, TwoKeyMap, UnoGenerator, UnocssPluginContext, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, ValueHandler, ValueHandlerCallback, Variant, VariantContext, VariantFunction, VariantHandler, VariantMatchedResult, VariantObject, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractQuoted, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, matchingPair, mergeDeep, mergeSet, movePseudoElementsEnd, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
|
|
773
|
+
export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValue, CSSValues, ConfigBase, DeepPartial, DetailString, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, ExtractStringOptions, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, ParsedColorValue, ParsedUtil, PartialByKeys, PluginOptions, Postprocessor, Preflight, PreflightContext, PreparedRule, Preprocessor, Preset, PresetOptions, RGBAColorValue, Range, RawUtil, Replacement, RequiredByKey, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, SourceCodeTransformer, 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, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractQuoted, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, matchingPair, mergeDeep, mergeSet, movePseudoElementsEnd, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
|
package/dist/index.mjs
CHANGED
|
@@ -346,7 +346,7 @@ function extractQuoted(str, options = {}) {
|
|
|
346
346
|
return result;
|
|
347
347
|
}
|
|
348
348
|
|
|
349
|
-
const splitCode = (code) => code.split(/[\s'"
|
|
349
|
+
const splitCode = (code) => code.split(/[\s'"`;=]+/g).filter(isValidSelector);
|
|
350
350
|
const extractorSplit = {
|
|
351
351
|
name: "split",
|
|
352
352
|
order: 0,
|
|
@@ -456,7 +456,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
456
456
|
};
|
|
457
457
|
}
|
|
458
458
|
|
|
459
|
-
const version = "0.
|
|
459
|
+
const version = "0.41.0";
|
|
460
460
|
|
|
461
461
|
class UnoGenerator {
|
|
462
462
|
constructor(userConfig = {}, defaults = {}) {
|
|
@@ -634,7 +634,10 @@ class UnoGenerator {
|
|
|
634
634
|
const selectors = selectorSortPair ? [...new Set(selectorSortPair.sort((a, b) => a[1] - b[1] || a[0]?.localeCompare(b[0] || "") || 0).map((pair) => pair[0]).filter(Boolean))] : [];
|
|
635
635
|
return selectors.length ? `${selectors.join(`,${nl}`)}{${body}}` : body;
|
|
636
636
|
}).filter(Boolean).reverse().join(nl);
|
|
637
|
-
|
|
637
|
+
if (!parent)
|
|
638
|
+
return rules;
|
|
639
|
+
const parents = parent.split(" $$ ");
|
|
640
|
+
return `${parents.join("{")}{${nl}${rules}${nl}}${parents.map((_) => "").join("}")}`;
|
|
638
641
|
}).filter(Boolean).join(nl);
|
|
639
642
|
if (preflights) {
|
|
640
643
|
css = [preflightsMap[layer], css].filter(Boolean).join(nl);
|
|
@@ -675,8 +678,6 @@ class UnoGenerator {
|
|
|
675
678
|
if (typeof handler === "string")
|
|
676
679
|
handler = { matcher: handler };
|
|
677
680
|
processed = handler.matcher;
|
|
678
|
-
if (Array.isArray(handler.parent))
|
|
679
|
-
this.parentOrders.set(handler.parent[0], handler.parent[1]);
|
|
680
681
|
handlers.unshift(handler);
|
|
681
682
|
variants.add(v);
|
|
682
683
|
applied = true;
|
|
@@ -690,25 +691,38 @@ class UnoGenerator {
|
|
|
690
691
|
return [raw, processed, handlers, variants];
|
|
691
692
|
}
|
|
692
693
|
applyVariants(parsed, variantHandlers = parsed[4], raw = parsed[1]) {
|
|
693
|
-
const
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
694
|
+
const handler = [...variantHandlers].sort((a, b) => (a.order || 0) - (b.order || 0)).reverse().reduce((previous, v) => (input) => {
|
|
695
|
+
const entries = v.body?.(input.entries) || input.entries;
|
|
696
|
+
const parents = Array.isArray(v.parent) ? v.parent : [v.parent, void 0];
|
|
697
|
+
return (v.handle ?? defaultVariantHandler)({
|
|
698
|
+
...input,
|
|
699
|
+
entries,
|
|
700
|
+
selector: v.selector?.(input.selector, entries) || input.selector,
|
|
701
|
+
parent: parents[0] || input.parent,
|
|
702
|
+
parentOrder: parents[1] || input.parentOrder,
|
|
703
|
+
layer: v.layer || input.layer,
|
|
704
|
+
sort: v.sort || input.sort
|
|
705
|
+
}, previous);
|
|
706
|
+
}, (input) => input);
|
|
707
|
+
const variantContextResult = handler({
|
|
708
|
+
prefix: "",
|
|
709
|
+
selector: toEscapedSelector(raw),
|
|
710
|
+
pseudo: "",
|
|
711
|
+
entries: parsed[2]
|
|
705
712
|
});
|
|
713
|
+
const { parent, parentOrder } = variantContextResult;
|
|
714
|
+
if (parent != null && parentOrder != null)
|
|
715
|
+
this.parentOrders.set(parent, parentOrder);
|
|
706
716
|
const obj = {
|
|
707
|
-
selector: movePseudoElementsEnd(
|
|
708
|
-
|
|
717
|
+
selector: movePseudoElementsEnd([
|
|
718
|
+
variantContextResult.prefix,
|
|
719
|
+
variantContextResult.selector,
|
|
720
|
+
variantContextResult.pseudo
|
|
721
|
+
].join("")),
|
|
722
|
+
entries: variantContextResult.entries,
|
|
709
723
|
parent,
|
|
710
|
-
layer,
|
|
711
|
-
sort
|
|
724
|
+
layer: variantContextResult.layer,
|
|
725
|
+
sort: variantContextResult.sort
|
|
712
726
|
};
|
|
713
727
|
for (const p of this.config.postprocess)
|
|
714
728
|
p(obj);
|
|
@@ -843,14 +857,14 @@ class UnoGenerator {
|
|
|
843
857
|
const mapItem = selectorMap.getFallback(selector, parent2, [[], item[0]]);
|
|
844
858
|
mapItem[0].push([entries, !!item[3]?.noMerge, sort ?? 0]);
|
|
845
859
|
}
|
|
846
|
-
return rawStringfieldUtil.concat(selectorMap.map(([e2, index], selector,
|
|
860
|
+
return rawStringfieldUtil.concat(selectorMap.map(([e2, index], selector, joinedParents) => {
|
|
847
861
|
const stringify = (flatten, noMerge, entrySortPair) => {
|
|
848
862
|
const maxSort = Math.max(...entrySortPair.map((e3) => e3[1]));
|
|
849
863
|
const entriesList = entrySortPair.map((e3) => e3[0]);
|
|
850
864
|
return (flatten ? [entriesList.flat(1)] : entriesList).map((entries) => {
|
|
851
865
|
const body = entriesToCss(entries);
|
|
852
866
|
if (body)
|
|
853
|
-
return [index, selector, body,
|
|
867
|
+
return [index, selector, body, joinedParents, { ...meta, noMerge, sort: maxSort }, context];
|
|
854
868
|
return void 0;
|
|
855
869
|
});
|
|
856
870
|
};
|
|
@@ -893,5 +907,8 @@ function toEscapedSelector(raw) {
|
|
|
893
907
|
return raw.replace(attributifyRe, (_, n, s, i) => `[${e(n)}${s}"${e(i)}"]`);
|
|
894
908
|
return `.${e(raw)}`;
|
|
895
909
|
}
|
|
910
|
+
function defaultVariantHandler(input, next) {
|
|
911
|
+
return next(input);
|
|
912
|
+
}
|
|
896
913
|
|
|
897
914
|
export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractQuoted, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, matchingPair, mergeDeep, mergeSet, movePseudoElementsEnd, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
|