@unocss/core 0.45.12 → 0.45.15
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 +49 -47
- package/dist/index.d.ts +13 -7
- package/dist/index.mjs +50 -47
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -45,10 +45,6 @@ function toArray(value = []) {
|
|
|
45
45
|
function uniq(value) {
|
|
46
46
|
return Array.from(new Set(value));
|
|
47
47
|
}
|
|
48
|
-
function mergeSet(target, append) {
|
|
49
|
-
append.forEach((i) => target.add(i));
|
|
50
|
-
return target;
|
|
51
|
-
}
|
|
52
48
|
function isString(s) {
|
|
53
49
|
return typeof s === "string";
|
|
54
50
|
}
|
|
@@ -138,7 +134,7 @@ function isStaticShortcut(sc) {
|
|
|
138
134
|
|
|
139
135
|
const attributifyRE = /^\[(.+?)~?="(.*)"\]$/;
|
|
140
136
|
const cssIdRE = /\.(css|postcss|sass|scss|less|stylus|styl)$/;
|
|
141
|
-
const validateFilterRE = /
|
|
137
|
+
const validateFilterRE = /[\w\u00A0-\uFFFF-_:%-?]/;
|
|
142
138
|
const CONTROL_SHORTCUT_NO_MERGE = "$$shortcut-no-merge";
|
|
143
139
|
function isAttributifySelector(selector) {
|
|
144
140
|
return selector.match(attributifyRE);
|
|
@@ -224,7 +220,7 @@ function withLayer(layer, rules) {
|
|
|
224
220
|
}
|
|
225
221
|
|
|
226
222
|
const regexClassGroup = /((?:[!\w+:_/-]|\[&?>?:?.*\])+?)([:-])\(((?:[~!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm;
|
|
227
|
-
function expandVariantGroup(str, seperators = ["-", ":"]) {
|
|
223
|
+
function expandVariantGroup(str, seperators = ["-", ":"], depth = 5) {
|
|
228
224
|
regexClassGroup.lastIndex = 0;
|
|
229
225
|
let hasChanged = false;
|
|
230
226
|
let content = str.toString();
|
|
@@ -239,11 +235,13 @@ function expandVariantGroup(str, seperators = ["-", ":"]) {
|
|
|
239
235
|
}
|
|
240
236
|
);
|
|
241
237
|
hasChanged = content !== before;
|
|
242
|
-
|
|
243
|
-
|
|
238
|
+
depth -= 1;
|
|
239
|
+
} while (hasChanged && depth);
|
|
240
|
+
if (typeof str === "string") {
|
|
244
241
|
return content;
|
|
245
|
-
else
|
|
246
|
-
return str.overwrite(0, str.length(), content);
|
|
242
|
+
} else {
|
|
243
|
+
return str.length() ? str.overwrite(0, str.length(), content) : str;
|
|
244
|
+
}
|
|
247
245
|
}
|
|
248
246
|
|
|
249
247
|
const warned = /* @__PURE__ */ new Set();
|
|
@@ -284,12 +282,12 @@ function createValueHandler(handlers) {
|
|
|
284
282
|
return handler;
|
|
285
283
|
}
|
|
286
284
|
|
|
287
|
-
const splitCode = (code) => code.split(/\\?[\s'"`;={}]+/g).filter(isValidSelector);
|
|
285
|
+
const splitCode = (code) => [...new Set(code.split(/\\?[\s'"`;={}]+/g))].filter(isValidSelector);
|
|
288
286
|
const extractorSplit = {
|
|
289
287
|
name: "split",
|
|
290
288
|
order: 0,
|
|
291
289
|
extract({ code }) {
|
|
292
|
-
return
|
|
290
|
+
return splitCode(code);
|
|
293
291
|
}
|
|
294
292
|
};
|
|
295
293
|
|
|
@@ -323,7 +321,7 @@ function createNanoEvents() {
|
|
|
323
321
|
const LAYER_DEFAULT = "default";
|
|
324
322
|
const LAYER_PREFLIGHTS = "preflights";
|
|
325
323
|
const LAYER_SHORTCUTS = "shortcuts";
|
|
326
|
-
const
|
|
324
|
+
const DEFAULT_LAYERS = {
|
|
327
325
|
[LAYER_PREFLIGHTS]: -100,
|
|
328
326
|
[LAYER_SHORTCUTS]: -10,
|
|
329
327
|
[LAYER_DEFAULT]: 0
|
|
@@ -362,7 +360,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
362
360
|
...rawPresets.filter((p) => !p.enforce),
|
|
363
361
|
...rawPresets.filter((p) => p.enforce === "post")
|
|
364
362
|
];
|
|
365
|
-
const layers = Object.assign(
|
|
363
|
+
const layers = Object.assign(DEFAULT_LAYERS, ...rawPresets.map((i) => i.layers), userConfig.layers);
|
|
366
364
|
function mergePresets(key) {
|
|
367
365
|
return uniq([
|
|
368
366
|
...sortedPresets.flatMap((p) => toArray(p[key] || [])),
|
|
@@ -376,13 +374,14 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
376
374
|
const rules = mergePresets("rules");
|
|
377
375
|
const rulesStaticMap = {};
|
|
378
376
|
const rulesSize = rules.length;
|
|
379
|
-
rules.
|
|
377
|
+
const rulesDynamic = rules.map((rule, i) => {
|
|
380
378
|
if (isStaticRule(rule)) {
|
|
381
379
|
const prefix = rule[2]?.prefix || "";
|
|
382
380
|
rulesStaticMap[prefix + rule[0]] = [i, rule[1], rule[2], rule];
|
|
383
|
-
|
|
381
|
+
return void 0;
|
|
384
382
|
}
|
|
385
|
-
|
|
383
|
+
return [i, ...rule];
|
|
384
|
+
}).filter(Boolean).reverse();
|
|
386
385
|
const theme = clone([
|
|
387
386
|
...sortedPresets.map((p) => p.theme || {}),
|
|
388
387
|
config.theme || {}
|
|
@@ -404,7 +403,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
404
403
|
layers,
|
|
405
404
|
theme,
|
|
406
405
|
rulesSize,
|
|
407
|
-
rulesDynamic
|
|
406
|
+
rulesDynamic,
|
|
408
407
|
rulesStaticMap,
|
|
409
408
|
preprocess: mergePresets("preprocess"),
|
|
410
409
|
postprocess: mergePresets("postprocess"),
|
|
@@ -417,7 +416,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
417
416
|
};
|
|
418
417
|
}
|
|
419
418
|
|
|
420
|
-
const version = "0.45.
|
|
419
|
+
const version = "0.45.15";
|
|
421
420
|
|
|
422
421
|
class UnoGenerator {
|
|
423
422
|
constructor(userConfig = {}, defaults = {}) {
|
|
@@ -453,7 +452,10 @@ class UnoGenerator {
|
|
|
453
452
|
};
|
|
454
453
|
for (const extractor of this.config.extractors) {
|
|
455
454
|
const result = await extractor.extract(context);
|
|
456
|
-
result
|
|
455
|
+
if (result) {
|
|
456
|
+
for (const token of result)
|
|
457
|
+
set.add(token);
|
|
458
|
+
}
|
|
457
459
|
}
|
|
458
460
|
return set;
|
|
459
461
|
}
|
|
@@ -581,12 +583,12 @@ class UnoGenerator {
|
|
|
581
583
|
return layerCache[layer];
|
|
582
584
|
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]) => {
|
|
583
585
|
const size = items.length;
|
|
584
|
-
const sorted = items.filter((i) => (i[4]?.layer || LAYER_DEFAULT) === layer).sort((a, b) => a[0] - b[0] || (a[4]?.sort || 0) - (b[4]?.sort || 0) || a[1]?.localeCompare(b[1] || "") || a[2]?.localeCompare(b[2] || "") || 0).map(([, selector, body, , meta]) => {
|
|
586
|
+
const sorted = items.filter((i) => (i[4]?.layer || LAYER_DEFAULT) === layer).sort((a, b) => a[0] - b[0] || (a[4]?.sort || 0) - (b[4]?.sort || 0) || a[1]?.localeCompare(b[1] || "") || a[2]?.localeCompare(b[2] || "") || 0).map(([, selector, body, , meta, , variantNoMerge]) => {
|
|
585
587
|
const scopedSelector = selector ? applyScope(selector, scope) : selector;
|
|
586
588
|
return [
|
|
587
589
|
[[scopedSelector ?? "", meta?.sort ?? 0]],
|
|
588
590
|
body,
|
|
589
|
-
!!meta?.noMerge
|
|
591
|
+
!!(variantNoMerge ?? meta?.noMerge)
|
|
590
592
|
];
|
|
591
593
|
});
|
|
592
594
|
if (!sorted.length)
|
|
@@ -699,7 +701,8 @@ class UnoGenerator {
|
|
|
699
701
|
entries: variantContextResult.entries,
|
|
700
702
|
parent,
|
|
701
703
|
layer: variantContextResult.layer,
|
|
702
|
-
sort: variantContextResult.sort
|
|
704
|
+
sort: variantContextResult.sort,
|
|
705
|
+
noMerge: variantContextResult.noMerge
|
|
703
706
|
};
|
|
704
707
|
for (const p of this.config.postprocess)
|
|
705
708
|
p(obj);
|
|
@@ -717,14 +720,13 @@ class UnoGenerator {
|
|
|
717
720
|
}
|
|
718
721
|
async parseUtil(input, context, internal = false) {
|
|
719
722
|
const [raw, processed, variantHandlers] = isString(input) ? this.matchVariants(input) : input;
|
|
720
|
-
|
|
723
|
+
if (this.config.details)
|
|
721
724
|
context.rules = context.rules ?? [];
|
|
722
|
-
context.rules.push(r);
|
|
723
|
-
} : noop;
|
|
724
725
|
const staticMatch = this.config.rulesStaticMap[processed];
|
|
725
726
|
if (staticMatch) {
|
|
726
727
|
if (staticMatch[1] && (internal || !staticMatch[2]?.internal)) {
|
|
727
|
-
|
|
728
|
+
if (this.config.details)
|
|
729
|
+
context.rules.push(staticMatch[3]);
|
|
728
730
|
const index = staticMatch[0];
|
|
729
731
|
const entry = normalizeCSSEntries(staticMatch[1]);
|
|
730
732
|
const meta = staticMatch[2];
|
|
@@ -735,24 +737,24 @@ class UnoGenerator {
|
|
|
735
737
|
}
|
|
736
738
|
}
|
|
737
739
|
context.variantHandlers = variantHandlers;
|
|
738
|
-
const { rulesDynamic
|
|
739
|
-
for (
|
|
740
|
-
|
|
741
|
-
if (!rule)
|
|
742
|
-
continue;
|
|
743
|
-
if (rule[2]?.internal && !internal)
|
|
740
|
+
const { rulesDynamic } = this.config;
|
|
741
|
+
for (const [i, matcher, handler, meta] of rulesDynamic) {
|
|
742
|
+
if (meta?.internal && !internal)
|
|
744
743
|
continue;
|
|
745
|
-
|
|
746
|
-
if (meta?.prefix
|
|
747
|
-
|
|
748
|
-
|
|
744
|
+
let unprefixed = processed;
|
|
745
|
+
if (meta?.prefix) {
|
|
746
|
+
if (!processed.startsWith(meta.prefix))
|
|
747
|
+
continue;
|
|
748
|
+
unprefixed = processed.slice(meta.prefix.length);
|
|
749
|
+
}
|
|
749
750
|
const match = unprefixed.match(matcher);
|
|
750
751
|
if (!match)
|
|
751
752
|
continue;
|
|
752
753
|
const result = await handler(match, context);
|
|
753
754
|
if (!result)
|
|
754
755
|
continue;
|
|
755
|
-
|
|
756
|
+
if (this.config.details)
|
|
757
|
+
context.rules.push([matcher, handler, meta]);
|
|
756
758
|
const entries = normalizeCSSValues(result).filter((i2) => i2.length);
|
|
757
759
|
if (entries.length) {
|
|
758
760
|
return entries.map((e2) => {
|
|
@@ -768,8 +770,8 @@ class UnoGenerator {
|
|
|
768
770
|
if (!parsed)
|
|
769
771
|
return;
|
|
770
772
|
if (isRawUtil(parsed))
|
|
771
|
-
return [parsed[0], void 0, parsed[1], void 0, parsed[2], this.config.details ? context : void 0];
|
|
772
|
-
const { selector, entries, parent, layer: variantLayer, sort: variantSort } = this.applyVariants(parsed);
|
|
773
|
+
return [parsed[0], void 0, parsed[1], void 0, parsed[2], this.config.details ? context : void 0, void 0];
|
|
774
|
+
const { selector, entries, parent, layer: variantLayer, sort: variantSort, noMerge } = this.applyVariants(parsed);
|
|
773
775
|
const body = entriesToCss(entries);
|
|
774
776
|
if (!body)
|
|
775
777
|
return;
|
|
@@ -779,7 +781,7 @@ class UnoGenerator {
|
|
|
779
781
|
layer: variantLayer ?? metaLayer,
|
|
780
782
|
sort: variantSort ?? metaSort
|
|
781
783
|
};
|
|
782
|
-
return [parsed[0], selector, body, parent, ruleMeta, this.config.details ? context : void 0];
|
|
784
|
+
return [parsed[0], selector, body, parent, ruleMeta, this.config.details ? context : void 0, noMerge];
|
|
783
785
|
}
|
|
784
786
|
expandShortcut(input, context, depth = 5) {
|
|
785
787
|
if (depth === 0)
|
|
@@ -839,12 +841,12 @@ class UnoGenerator {
|
|
|
839
841
|
const rawStringfieldUtil = [];
|
|
840
842
|
for (const item of parsed) {
|
|
841
843
|
if (isRawUtil(item)) {
|
|
842
|
-
rawStringfieldUtil.push([item[0], void 0, item[1], void 0, item[2], context]);
|
|
844
|
+
rawStringfieldUtil.push([item[0], void 0, item[1], void 0, item[2], context, void 0]);
|
|
843
845
|
continue;
|
|
844
846
|
}
|
|
845
|
-
const { selector, entries, parent: parent2, sort } = this.applyVariants(item, [...item[4], ...parentVariants], raw);
|
|
847
|
+
const { selector, entries, parent: parent2, sort, noMerge } = this.applyVariants(item, [...item[4], ...parentVariants], raw);
|
|
846
848
|
const mapItem = selectorMap.getFallback(selector, parent2, [[], item[0]]);
|
|
847
|
-
mapItem[0].push([entries, !!item[3]?.noMerge, sort ?? 0]);
|
|
849
|
+
mapItem[0].push([entries, !!(noMerge ?? item[3]?.noMerge), sort ?? 0]);
|
|
848
850
|
}
|
|
849
851
|
return rawStringfieldUtil.concat(selectorMap.map(([e2, index], selector, joinedParents) => {
|
|
850
852
|
const stringify = (flatten, noMerge, entrySortPair) => {
|
|
@@ -853,7 +855,7 @@ class UnoGenerator {
|
|
|
853
855
|
return (flatten ? [entriesList.flat(1)] : entriesList).map((entries) => {
|
|
854
856
|
const body = entriesToCss(entries);
|
|
855
857
|
if (body)
|
|
856
|
-
return [index, selector, body, joinedParents, { ...meta, noMerge, sort: maxSort }, context];
|
|
858
|
+
return [index, selector, body, joinedParents, { ...meta, noMerge, sort: maxSort }, context, void 0];
|
|
857
859
|
return void 0;
|
|
858
860
|
});
|
|
859
861
|
};
|
|
@@ -885,7 +887,8 @@ function applyScope(css, scope) {
|
|
|
885
887
|
function movePseudoElementsEnd(selector) {
|
|
886
888
|
const pseudoElements = selector.match(/::[\w-]+(\([\w-]+\))?/g);
|
|
887
889
|
if (pseudoElements) {
|
|
888
|
-
|
|
890
|
+
for (const e2 of pseudoElements)
|
|
891
|
+
selector = selector.replace(e2, "");
|
|
889
892
|
selector += pseudoElements.join("");
|
|
890
893
|
}
|
|
891
894
|
return selector;
|
|
@@ -926,7 +929,6 @@ exports.isStaticShortcut = isStaticShortcut;
|
|
|
926
929
|
exports.isString = isString;
|
|
927
930
|
exports.isValidSelector = isValidSelector;
|
|
928
931
|
exports.mergeDeep = mergeDeep;
|
|
929
|
-
exports.mergeSet = mergeSet;
|
|
930
932
|
exports.movePseudoElementsEnd = movePseudoElementsEnd;
|
|
931
933
|
exports.noop = noop;
|
|
932
934
|
exports.normalizeCSSEntries = normalizeCSSEntries;
|
package/dist/index.d.ts
CHANGED
|
@@ -102,7 +102,6 @@ declare function isStaticShortcut(sc: Shortcut): sc is StaticShortcut;
|
|
|
102
102
|
|
|
103
103
|
declare function toArray<T>(value?: T | T[]): T[];
|
|
104
104
|
declare function uniq<T>(value: T[]): T[];
|
|
105
|
-
declare function mergeSet<T>(target: Set<T>, append: Set<T>): Set<T>;
|
|
106
105
|
declare function isString(s: any): s is string;
|
|
107
106
|
|
|
108
107
|
declare const attributifyRE: RegExp;
|
|
@@ -133,8 +132,8 @@ declare class BetterMap<K, V> extends Map<K, V> {
|
|
|
133
132
|
declare function withLayer<T>(layer: string, rules: Rule<T>[]): Rule<T>[];
|
|
134
133
|
|
|
135
134
|
declare const regexClassGroup: RegExp;
|
|
136
|
-
declare function expandVariantGroup(str: string, seperators?:
|
|
137
|
-
declare function expandVariantGroup(str: MagicString, seperators?:
|
|
135
|
+
declare function expandVariantGroup(str: string, seperators?: string[], depth?: number): string;
|
|
136
|
+
declare function expandVariantGroup(str: MagicString, seperators?: string[], depth?: number): MagicString;
|
|
138
137
|
|
|
139
138
|
declare function warnOnce(msg: string): void;
|
|
140
139
|
|
|
@@ -272,7 +271,7 @@ interface PreflightContext<Theme extends {} = {}> {
|
|
|
272
271
|
}
|
|
273
272
|
interface Extractor {
|
|
274
273
|
name: string;
|
|
275
|
-
extract(ctx: ExtractorContext): Awaitable<Set<string> | undefined>;
|
|
274
|
+
extract(ctx: ExtractorContext): Awaitable<Set<string> | string[] | undefined>;
|
|
276
275
|
order?: number;
|
|
277
276
|
}
|
|
278
277
|
interface RuleMeta {
|
|
@@ -356,6 +355,11 @@ interface VariantHandlerContext {
|
|
|
356
355
|
* Order in which the variant is sorted within single rule.
|
|
357
356
|
*/
|
|
358
357
|
sort?: number;
|
|
358
|
+
/**
|
|
359
|
+
* Option to not merge the resulting entries even if the body are the same.
|
|
360
|
+
* @default false
|
|
361
|
+
*/
|
|
362
|
+
noMerge?: boolean;
|
|
359
363
|
}
|
|
360
364
|
interface VariantHandler {
|
|
361
365
|
/**
|
|
@@ -687,7 +691,7 @@ interface ResolvedConfig extends Omit<RequiredByKey<UserConfig, 'mergeSelectors'
|
|
|
687
691
|
preprocess: Preprocessor[];
|
|
688
692
|
postprocess: Postprocessor[];
|
|
689
693
|
rulesSize: number;
|
|
690
|
-
rulesDynamic:
|
|
694
|
+
rulesDynamic: [number, ...DynamicRule][];
|
|
691
695
|
rulesStaticMap: Record<string, [number, CSSObject | CSSEntries, RuleMeta | undefined, Rule] | undefined>;
|
|
692
696
|
autocomplete: {
|
|
693
697
|
templates: (AutoCompleteFunction | AutoCompleteTemplate)[];
|
|
@@ -725,7 +729,8 @@ declare type StringifiedUtil = readonly [
|
|
|
725
729
|
body: string,
|
|
726
730
|
parent: string | undefined,
|
|
727
731
|
meta: RuleMeta | undefined,
|
|
728
|
-
context: RuleContext | undefined
|
|
732
|
+
context: RuleContext | undefined,
|
|
733
|
+
noMerge: boolean | undefined
|
|
729
734
|
];
|
|
730
735
|
declare type PreparedRule = readonly [
|
|
731
736
|
selector: [string, number][],
|
|
@@ -738,6 +743,7 @@ interface UtilObject {
|
|
|
738
743
|
parent: string | undefined;
|
|
739
744
|
layer: string | undefined;
|
|
740
745
|
sort: number | undefined;
|
|
746
|
+
noMerge: boolean | undefined;
|
|
741
747
|
}
|
|
742
748
|
interface GenerateOptions {
|
|
743
749
|
/**
|
|
@@ -769,4 +775,4 @@ declare const extractorSplit: Extractor;
|
|
|
769
775
|
|
|
770
776
|
declare const extractorSvelte: Extractor;
|
|
771
777
|
|
|
772
|
-
export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValue, CSSValues, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, 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, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, mergeDeep,
|
|
778
|
+
export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValue, CSSValues, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, 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, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, mergeDeep, movePseudoElementsEnd, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
|
package/dist/index.mjs
CHANGED
|
@@ -41,10 +41,6 @@ function toArray(value = []) {
|
|
|
41
41
|
function uniq(value) {
|
|
42
42
|
return Array.from(new Set(value));
|
|
43
43
|
}
|
|
44
|
-
function mergeSet(target, append) {
|
|
45
|
-
append.forEach((i) => target.add(i));
|
|
46
|
-
return target;
|
|
47
|
-
}
|
|
48
44
|
function isString(s) {
|
|
49
45
|
return typeof s === "string";
|
|
50
46
|
}
|
|
@@ -134,7 +130,7 @@ function isStaticShortcut(sc) {
|
|
|
134
130
|
|
|
135
131
|
const attributifyRE = /^\[(.+?)~?="(.*)"\]$/;
|
|
136
132
|
const cssIdRE = /\.(css|postcss|sass|scss|less|stylus|styl)$/;
|
|
137
|
-
const validateFilterRE = /
|
|
133
|
+
const validateFilterRE = /[\w\u00A0-\uFFFF-_:%-?]/;
|
|
138
134
|
const CONTROL_SHORTCUT_NO_MERGE = "$$shortcut-no-merge";
|
|
139
135
|
function isAttributifySelector(selector) {
|
|
140
136
|
return selector.match(attributifyRE);
|
|
@@ -220,7 +216,7 @@ function withLayer(layer, rules) {
|
|
|
220
216
|
}
|
|
221
217
|
|
|
222
218
|
const regexClassGroup = /((?:[!\w+:_/-]|\[&?>?:?.*\])+?)([:-])\(((?:[~!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm;
|
|
223
|
-
function expandVariantGroup(str, seperators = ["-", ":"]) {
|
|
219
|
+
function expandVariantGroup(str, seperators = ["-", ":"], depth = 5) {
|
|
224
220
|
regexClassGroup.lastIndex = 0;
|
|
225
221
|
let hasChanged = false;
|
|
226
222
|
let content = str.toString();
|
|
@@ -235,11 +231,13 @@ function expandVariantGroup(str, seperators = ["-", ":"]) {
|
|
|
235
231
|
}
|
|
236
232
|
);
|
|
237
233
|
hasChanged = content !== before;
|
|
238
|
-
|
|
239
|
-
|
|
234
|
+
depth -= 1;
|
|
235
|
+
} while (hasChanged && depth);
|
|
236
|
+
if (typeof str === "string") {
|
|
240
237
|
return content;
|
|
241
|
-
else
|
|
242
|
-
return str.overwrite(0, str.length(), content);
|
|
238
|
+
} else {
|
|
239
|
+
return str.length() ? str.overwrite(0, str.length(), content) : str;
|
|
240
|
+
}
|
|
243
241
|
}
|
|
244
242
|
|
|
245
243
|
const warned = /* @__PURE__ */ new Set();
|
|
@@ -280,12 +278,12 @@ function createValueHandler(handlers) {
|
|
|
280
278
|
return handler;
|
|
281
279
|
}
|
|
282
280
|
|
|
283
|
-
const splitCode = (code) => code.split(/\\?[\s'"`;={}]+/g).filter(isValidSelector);
|
|
281
|
+
const splitCode = (code) => [...new Set(code.split(/\\?[\s'"`;={}]+/g))].filter(isValidSelector);
|
|
284
282
|
const extractorSplit = {
|
|
285
283
|
name: "split",
|
|
286
284
|
order: 0,
|
|
287
285
|
extract({ code }) {
|
|
288
|
-
return
|
|
286
|
+
return splitCode(code);
|
|
289
287
|
}
|
|
290
288
|
};
|
|
291
289
|
|
|
@@ -319,7 +317,7 @@ function createNanoEvents() {
|
|
|
319
317
|
const LAYER_DEFAULT = "default";
|
|
320
318
|
const LAYER_PREFLIGHTS = "preflights";
|
|
321
319
|
const LAYER_SHORTCUTS = "shortcuts";
|
|
322
|
-
const
|
|
320
|
+
const DEFAULT_LAYERS = {
|
|
323
321
|
[LAYER_PREFLIGHTS]: -100,
|
|
324
322
|
[LAYER_SHORTCUTS]: -10,
|
|
325
323
|
[LAYER_DEFAULT]: 0
|
|
@@ -358,7 +356,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
358
356
|
...rawPresets.filter((p) => !p.enforce),
|
|
359
357
|
...rawPresets.filter((p) => p.enforce === "post")
|
|
360
358
|
];
|
|
361
|
-
const layers = Object.assign(
|
|
359
|
+
const layers = Object.assign(DEFAULT_LAYERS, ...rawPresets.map((i) => i.layers), userConfig.layers);
|
|
362
360
|
function mergePresets(key) {
|
|
363
361
|
return uniq([
|
|
364
362
|
...sortedPresets.flatMap((p) => toArray(p[key] || [])),
|
|
@@ -372,13 +370,14 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
372
370
|
const rules = mergePresets("rules");
|
|
373
371
|
const rulesStaticMap = {};
|
|
374
372
|
const rulesSize = rules.length;
|
|
375
|
-
rules.
|
|
373
|
+
const rulesDynamic = rules.map((rule, i) => {
|
|
376
374
|
if (isStaticRule(rule)) {
|
|
377
375
|
const prefix = rule[2]?.prefix || "";
|
|
378
376
|
rulesStaticMap[prefix + rule[0]] = [i, rule[1], rule[2], rule];
|
|
379
|
-
|
|
377
|
+
return void 0;
|
|
380
378
|
}
|
|
381
|
-
|
|
379
|
+
return [i, ...rule];
|
|
380
|
+
}).filter(Boolean).reverse();
|
|
382
381
|
const theme = clone([
|
|
383
382
|
...sortedPresets.map((p) => p.theme || {}),
|
|
384
383
|
config.theme || {}
|
|
@@ -400,7 +399,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
400
399
|
layers,
|
|
401
400
|
theme,
|
|
402
401
|
rulesSize,
|
|
403
|
-
rulesDynamic
|
|
402
|
+
rulesDynamic,
|
|
404
403
|
rulesStaticMap,
|
|
405
404
|
preprocess: mergePresets("preprocess"),
|
|
406
405
|
postprocess: mergePresets("postprocess"),
|
|
@@ -413,7 +412,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
413
412
|
};
|
|
414
413
|
}
|
|
415
414
|
|
|
416
|
-
const version = "0.45.
|
|
415
|
+
const version = "0.45.15";
|
|
417
416
|
|
|
418
417
|
class UnoGenerator {
|
|
419
418
|
constructor(userConfig = {}, defaults = {}) {
|
|
@@ -449,7 +448,10 @@ class UnoGenerator {
|
|
|
449
448
|
};
|
|
450
449
|
for (const extractor of this.config.extractors) {
|
|
451
450
|
const result = await extractor.extract(context);
|
|
452
|
-
result
|
|
451
|
+
if (result) {
|
|
452
|
+
for (const token of result)
|
|
453
|
+
set.add(token);
|
|
454
|
+
}
|
|
453
455
|
}
|
|
454
456
|
return set;
|
|
455
457
|
}
|
|
@@ -577,12 +579,12 @@ class UnoGenerator {
|
|
|
577
579
|
return layerCache[layer];
|
|
578
580
|
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]) => {
|
|
579
581
|
const size = items.length;
|
|
580
|
-
const sorted = items.filter((i) => (i[4]?.layer || LAYER_DEFAULT) === layer).sort((a, b) => a[0] - b[0] || (a[4]?.sort || 0) - (b[4]?.sort || 0) || a[1]?.localeCompare(b[1] || "") || a[2]?.localeCompare(b[2] || "") || 0).map(([, selector, body, , meta]) => {
|
|
582
|
+
const sorted = items.filter((i) => (i[4]?.layer || LAYER_DEFAULT) === layer).sort((a, b) => a[0] - b[0] || (a[4]?.sort || 0) - (b[4]?.sort || 0) || a[1]?.localeCompare(b[1] || "") || a[2]?.localeCompare(b[2] || "") || 0).map(([, selector, body, , meta, , variantNoMerge]) => {
|
|
581
583
|
const scopedSelector = selector ? applyScope(selector, scope) : selector;
|
|
582
584
|
return [
|
|
583
585
|
[[scopedSelector ?? "", meta?.sort ?? 0]],
|
|
584
586
|
body,
|
|
585
|
-
!!meta?.noMerge
|
|
587
|
+
!!(variantNoMerge ?? meta?.noMerge)
|
|
586
588
|
];
|
|
587
589
|
});
|
|
588
590
|
if (!sorted.length)
|
|
@@ -695,7 +697,8 @@ class UnoGenerator {
|
|
|
695
697
|
entries: variantContextResult.entries,
|
|
696
698
|
parent,
|
|
697
699
|
layer: variantContextResult.layer,
|
|
698
|
-
sort: variantContextResult.sort
|
|
700
|
+
sort: variantContextResult.sort,
|
|
701
|
+
noMerge: variantContextResult.noMerge
|
|
699
702
|
};
|
|
700
703
|
for (const p of this.config.postprocess)
|
|
701
704
|
p(obj);
|
|
@@ -713,14 +716,13 @@ class UnoGenerator {
|
|
|
713
716
|
}
|
|
714
717
|
async parseUtil(input, context, internal = false) {
|
|
715
718
|
const [raw, processed, variantHandlers] = isString(input) ? this.matchVariants(input) : input;
|
|
716
|
-
|
|
719
|
+
if (this.config.details)
|
|
717
720
|
context.rules = context.rules ?? [];
|
|
718
|
-
context.rules.push(r);
|
|
719
|
-
} : noop;
|
|
720
721
|
const staticMatch = this.config.rulesStaticMap[processed];
|
|
721
722
|
if (staticMatch) {
|
|
722
723
|
if (staticMatch[1] && (internal || !staticMatch[2]?.internal)) {
|
|
723
|
-
|
|
724
|
+
if (this.config.details)
|
|
725
|
+
context.rules.push(staticMatch[3]);
|
|
724
726
|
const index = staticMatch[0];
|
|
725
727
|
const entry = normalizeCSSEntries(staticMatch[1]);
|
|
726
728
|
const meta = staticMatch[2];
|
|
@@ -731,24 +733,24 @@ class UnoGenerator {
|
|
|
731
733
|
}
|
|
732
734
|
}
|
|
733
735
|
context.variantHandlers = variantHandlers;
|
|
734
|
-
const { rulesDynamic
|
|
735
|
-
for (
|
|
736
|
-
|
|
737
|
-
if (!rule)
|
|
738
|
-
continue;
|
|
739
|
-
if (rule[2]?.internal && !internal)
|
|
736
|
+
const { rulesDynamic } = this.config;
|
|
737
|
+
for (const [i, matcher, handler, meta] of rulesDynamic) {
|
|
738
|
+
if (meta?.internal && !internal)
|
|
740
739
|
continue;
|
|
741
|
-
|
|
742
|
-
if (meta?.prefix
|
|
743
|
-
|
|
744
|
-
|
|
740
|
+
let unprefixed = processed;
|
|
741
|
+
if (meta?.prefix) {
|
|
742
|
+
if (!processed.startsWith(meta.prefix))
|
|
743
|
+
continue;
|
|
744
|
+
unprefixed = processed.slice(meta.prefix.length);
|
|
745
|
+
}
|
|
745
746
|
const match = unprefixed.match(matcher);
|
|
746
747
|
if (!match)
|
|
747
748
|
continue;
|
|
748
749
|
const result = await handler(match, context);
|
|
749
750
|
if (!result)
|
|
750
751
|
continue;
|
|
751
|
-
|
|
752
|
+
if (this.config.details)
|
|
753
|
+
context.rules.push([matcher, handler, meta]);
|
|
752
754
|
const entries = normalizeCSSValues(result).filter((i2) => i2.length);
|
|
753
755
|
if (entries.length) {
|
|
754
756
|
return entries.map((e2) => {
|
|
@@ -764,8 +766,8 @@ class UnoGenerator {
|
|
|
764
766
|
if (!parsed)
|
|
765
767
|
return;
|
|
766
768
|
if (isRawUtil(parsed))
|
|
767
|
-
return [parsed[0], void 0, parsed[1], void 0, parsed[2], this.config.details ? context : void 0];
|
|
768
|
-
const { selector, entries, parent, layer: variantLayer, sort: variantSort } = this.applyVariants(parsed);
|
|
769
|
+
return [parsed[0], void 0, parsed[1], void 0, parsed[2], this.config.details ? context : void 0, void 0];
|
|
770
|
+
const { selector, entries, parent, layer: variantLayer, sort: variantSort, noMerge } = this.applyVariants(parsed);
|
|
769
771
|
const body = entriesToCss(entries);
|
|
770
772
|
if (!body)
|
|
771
773
|
return;
|
|
@@ -775,7 +777,7 @@ class UnoGenerator {
|
|
|
775
777
|
layer: variantLayer ?? metaLayer,
|
|
776
778
|
sort: variantSort ?? metaSort
|
|
777
779
|
};
|
|
778
|
-
return [parsed[0], selector, body, parent, ruleMeta, this.config.details ? context : void 0];
|
|
780
|
+
return [parsed[0], selector, body, parent, ruleMeta, this.config.details ? context : void 0, noMerge];
|
|
779
781
|
}
|
|
780
782
|
expandShortcut(input, context, depth = 5) {
|
|
781
783
|
if (depth === 0)
|
|
@@ -835,12 +837,12 @@ class UnoGenerator {
|
|
|
835
837
|
const rawStringfieldUtil = [];
|
|
836
838
|
for (const item of parsed) {
|
|
837
839
|
if (isRawUtil(item)) {
|
|
838
|
-
rawStringfieldUtil.push([item[0], void 0, item[1], void 0, item[2], context]);
|
|
840
|
+
rawStringfieldUtil.push([item[0], void 0, item[1], void 0, item[2], context, void 0]);
|
|
839
841
|
continue;
|
|
840
842
|
}
|
|
841
|
-
const { selector, entries, parent: parent2, sort } = this.applyVariants(item, [...item[4], ...parentVariants], raw);
|
|
843
|
+
const { selector, entries, parent: parent2, sort, noMerge } = this.applyVariants(item, [...item[4], ...parentVariants], raw);
|
|
842
844
|
const mapItem = selectorMap.getFallback(selector, parent2, [[], item[0]]);
|
|
843
|
-
mapItem[0].push([entries, !!item[3]?.noMerge, sort ?? 0]);
|
|
845
|
+
mapItem[0].push([entries, !!(noMerge ?? item[3]?.noMerge), sort ?? 0]);
|
|
844
846
|
}
|
|
845
847
|
return rawStringfieldUtil.concat(selectorMap.map(([e2, index], selector, joinedParents) => {
|
|
846
848
|
const stringify = (flatten, noMerge, entrySortPair) => {
|
|
@@ -849,7 +851,7 @@ class UnoGenerator {
|
|
|
849
851
|
return (flatten ? [entriesList.flat(1)] : entriesList).map((entries) => {
|
|
850
852
|
const body = entriesToCss(entries);
|
|
851
853
|
if (body)
|
|
852
|
-
return [index, selector, body, joinedParents, { ...meta, noMerge, sort: maxSort }, context];
|
|
854
|
+
return [index, selector, body, joinedParents, { ...meta, noMerge, sort: maxSort }, context, void 0];
|
|
853
855
|
return void 0;
|
|
854
856
|
});
|
|
855
857
|
};
|
|
@@ -881,7 +883,8 @@ function applyScope(css, scope) {
|
|
|
881
883
|
function movePseudoElementsEnd(selector) {
|
|
882
884
|
const pseudoElements = selector.match(/::[\w-]+(\([\w-]+\))?/g);
|
|
883
885
|
if (pseudoElements) {
|
|
884
|
-
|
|
886
|
+
for (const e2 of pseudoElements)
|
|
887
|
+
selector = selector.replace(e2, "");
|
|
885
888
|
selector += pseudoElements.join("");
|
|
886
889
|
}
|
|
887
890
|
return selector;
|
|
@@ -896,4 +899,4 @@ function defaultVariantHandler(input, next) {
|
|
|
896
899
|
return next(input);
|
|
897
900
|
}
|
|
898
901
|
|
|
899
|
-
export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, mergeDeep,
|
|
902
|
+
export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, mergeDeep, movePseudoElementsEnd, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
|