@unocss/core 0.39.1 → 0.40.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 +37 -23
- package/dist/index.d.ts +43 -5
- package/dist/index.mjs +37 -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.40.0";
|
|
464
464
|
|
|
465
465
|
class UnoGenerator {
|
|
466
466
|
constructor(userConfig = {}, defaults = {}) {
|
|
@@ -679,9 +679,7 @@ class UnoGenerator {
|
|
|
679
679
|
if (typeof handler === "string")
|
|
680
680
|
handler = { matcher: handler };
|
|
681
681
|
processed = handler.matcher;
|
|
682
|
-
|
|
683
|
-
this.parentOrders.set(handler.parent[0], handler.parent[1]);
|
|
684
|
-
handlers.unshift(handler);
|
|
682
|
+
handlers.push(handler);
|
|
685
683
|
variants.add(v);
|
|
686
684
|
applied = true;
|
|
687
685
|
break;
|
|
@@ -694,25 +692,38 @@ class UnoGenerator {
|
|
|
694
692
|
return [raw, processed, handlers, variants];
|
|
695
693
|
}
|
|
696
694
|
applyVariants(parsed, variantHandlers = parsed[4], raw = parsed[1]) {
|
|
697
|
-
const
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
695
|
+
const handler = [...variantHandlers].sort((a, b) => (a.order || 0) - (b.order || 0)).reverse().reduce((previous, v) => (input) => {
|
|
696
|
+
const entries = v.body?.(input.entries) || input.entries;
|
|
697
|
+
const parents = Array.isArray(v.parent) ? v.parent : [v.parent, void 0];
|
|
698
|
+
return (v.handle ?? defaultVariantHandler)({
|
|
699
|
+
...input,
|
|
700
|
+
entries,
|
|
701
|
+
selector: v.selector?.(input.selector, entries) || input.selector,
|
|
702
|
+
parent: parents[0] || input.parent,
|
|
703
|
+
parentOrder: parents[1] || input.parentOrder,
|
|
704
|
+
layer: v.layer || input.layer,
|
|
705
|
+
sort: v.sort || input.sort
|
|
706
|
+
}, previous);
|
|
707
|
+
}, (input) => input);
|
|
708
|
+
const variantContextResult = handler({
|
|
709
|
+
prefix: "",
|
|
710
|
+
selector: toEscapedSelector(raw),
|
|
711
|
+
pseudo: "",
|
|
712
|
+
entries: parsed[2]
|
|
709
713
|
});
|
|
714
|
+
const { parent, parentOrder } = variantContextResult;
|
|
715
|
+
if (parent != null && parentOrder != null)
|
|
716
|
+
this.parentOrders.set(parent, parentOrder);
|
|
710
717
|
const obj = {
|
|
711
|
-
selector: movePseudoElementsEnd(
|
|
712
|
-
|
|
718
|
+
selector: movePseudoElementsEnd([
|
|
719
|
+
variantContextResult.prefix,
|
|
720
|
+
variantContextResult.selector,
|
|
721
|
+
variantContextResult.pseudo
|
|
722
|
+
].join("")),
|
|
723
|
+
entries: variantContextResult.entries,
|
|
713
724
|
parent,
|
|
714
|
-
layer,
|
|
715
|
-
sort
|
|
725
|
+
layer: variantContextResult.layer,
|
|
726
|
+
sort: variantContextResult.sort
|
|
716
727
|
};
|
|
717
728
|
for (const p of this.config.postprocess)
|
|
718
729
|
p(obj);
|
|
@@ -847,14 +858,14 @@ class UnoGenerator {
|
|
|
847
858
|
const mapItem = selectorMap.getFallback(selector, parent2, [[], item[0]]);
|
|
848
859
|
mapItem[0].push([entries, !!item[3]?.noMerge, sort ?? 0]);
|
|
849
860
|
}
|
|
850
|
-
return rawStringfieldUtil.concat(selectorMap.map(([e2, index], selector,
|
|
861
|
+
return rawStringfieldUtil.concat(selectorMap.map(([e2, index], selector, joinedParents) => {
|
|
851
862
|
const stringify = (flatten, noMerge, entrySortPair) => {
|
|
852
863
|
const maxSort = Math.max(...entrySortPair.map((e3) => e3[1]));
|
|
853
864
|
const entriesList = entrySortPair.map((e3) => e3[0]);
|
|
854
865
|
return (flatten ? [entriesList.flat(1)] : entriesList).map((entries) => {
|
|
855
866
|
const body = entriesToCss(entries);
|
|
856
867
|
if (body)
|
|
857
|
-
return [index, selector, body,
|
|
868
|
+
return [index, selector, body, joinedParents, { ...meta, noMerge, sort: maxSort }, context];
|
|
858
869
|
return void 0;
|
|
859
870
|
});
|
|
860
871
|
};
|
|
@@ -897,6 +908,9 @@ function toEscapedSelector(raw) {
|
|
|
897
908
|
return raw.replace(attributifyRe, (_, n, s, i) => `[${e(n)}${s}"${e(i)}"]`);
|
|
898
909
|
return `.${e(raw)}`;
|
|
899
910
|
}
|
|
911
|
+
function defaultVariantHandler(input, next) {
|
|
912
|
+
return next(input);
|
|
913
|
+
}
|
|
900
914
|
|
|
901
915
|
exports.BetterMap = BetterMap;
|
|
902
916
|
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.40.0";
|
|
460
460
|
|
|
461
461
|
class UnoGenerator {
|
|
462
462
|
constructor(userConfig = {}, defaults = {}) {
|
|
@@ -675,9 +675,7 @@ class UnoGenerator {
|
|
|
675
675
|
if (typeof handler === "string")
|
|
676
676
|
handler = { matcher: handler };
|
|
677
677
|
processed = handler.matcher;
|
|
678
|
-
|
|
679
|
-
this.parentOrders.set(handler.parent[0], handler.parent[1]);
|
|
680
|
-
handlers.unshift(handler);
|
|
678
|
+
handlers.push(handler);
|
|
681
679
|
variants.add(v);
|
|
682
680
|
applied = true;
|
|
683
681
|
break;
|
|
@@ -690,25 +688,38 @@ class UnoGenerator {
|
|
|
690
688
|
return [raw, processed, handlers, variants];
|
|
691
689
|
}
|
|
692
690
|
applyVariants(parsed, variantHandlers = parsed[4], raw = parsed[1]) {
|
|
693
|
-
const
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
691
|
+
const handler = [...variantHandlers].sort((a, b) => (a.order || 0) - (b.order || 0)).reverse().reduce((previous, v) => (input) => {
|
|
692
|
+
const entries = v.body?.(input.entries) || input.entries;
|
|
693
|
+
const parents = Array.isArray(v.parent) ? v.parent : [v.parent, void 0];
|
|
694
|
+
return (v.handle ?? defaultVariantHandler)({
|
|
695
|
+
...input,
|
|
696
|
+
entries,
|
|
697
|
+
selector: v.selector?.(input.selector, entries) || input.selector,
|
|
698
|
+
parent: parents[0] || input.parent,
|
|
699
|
+
parentOrder: parents[1] || input.parentOrder,
|
|
700
|
+
layer: v.layer || input.layer,
|
|
701
|
+
sort: v.sort || input.sort
|
|
702
|
+
}, previous);
|
|
703
|
+
}, (input) => input);
|
|
704
|
+
const variantContextResult = handler({
|
|
705
|
+
prefix: "",
|
|
706
|
+
selector: toEscapedSelector(raw),
|
|
707
|
+
pseudo: "",
|
|
708
|
+
entries: parsed[2]
|
|
705
709
|
});
|
|
710
|
+
const { parent, parentOrder } = variantContextResult;
|
|
711
|
+
if (parent != null && parentOrder != null)
|
|
712
|
+
this.parentOrders.set(parent, parentOrder);
|
|
706
713
|
const obj = {
|
|
707
|
-
selector: movePseudoElementsEnd(
|
|
708
|
-
|
|
714
|
+
selector: movePseudoElementsEnd([
|
|
715
|
+
variantContextResult.prefix,
|
|
716
|
+
variantContextResult.selector,
|
|
717
|
+
variantContextResult.pseudo
|
|
718
|
+
].join("")),
|
|
719
|
+
entries: variantContextResult.entries,
|
|
709
720
|
parent,
|
|
710
|
-
layer,
|
|
711
|
-
sort
|
|
721
|
+
layer: variantContextResult.layer,
|
|
722
|
+
sort: variantContextResult.sort
|
|
712
723
|
};
|
|
713
724
|
for (const p of this.config.postprocess)
|
|
714
725
|
p(obj);
|
|
@@ -843,14 +854,14 @@ class UnoGenerator {
|
|
|
843
854
|
const mapItem = selectorMap.getFallback(selector, parent2, [[], item[0]]);
|
|
844
855
|
mapItem[0].push([entries, !!item[3]?.noMerge, sort ?? 0]);
|
|
845
856
|
}
|
|
846
|
-
return rawStringfieldUtil.concat(selectorMap.map(([e2, index], selector,
|
|
857
|
+
return rawStringfieldUtil.concat(selectorMap.map(([e2, index], selector, joinedParents) => {
|
|
847
858
|
const stringify = (flatten, noMerge, entrySortPair) => {
|
|
848
859
|
const maxSort = Math.max(...entrySortPair.map((e3) => e3[1]));
|
|
849
860
|
const entriesList = entrySortPair.map((e3) => e3[0]);
|
|
850
861
|
return (flatten ? [entriesList.flat(1)] : entriesList).map((entries) => {
|
|
851
862
|
const body = entriesToCss(entries);
|
|
852
863
|
if (body)
|
|
853
|
-
return [index, selector, body,
|
|
864
|
+
return [index, selector, body, joinedParents, { ...meta, noMerge, sort: maxSort }, context];
|
|
854
865
|
return void 0;
|
|
855
866
|
});
|
|
856
867
|
};
|
|
@@ -893,5 +904,8 @@ function toEscapedSelector(raw) {
|
|
|
893
904
|
return raw.replace(attributifyRe, (_, n, s, i) => `[${e(n)}${s}"${e(i)}"]`);
|
|
894
905
|
return `.${e(raw)}`;
|
|
895
906
|
}
|
|
907
|
+
function defaultVariantHandler(input, next) {
|
|
908
|
+
return next(input);
|
|
909
|
+
}
|
|
896
910
|
|
|
897
911
|
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 };
|