@unocss/core 0.65.0-beta.2 → 0.65.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +18 -4
- package/dist/index.d.ts +18 -4
- package/dist/index.mjs +52 -29
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -141,6 +141,7 @@ declare class UnoGeneratorInternal<Theme extends object = object> {
|
|
|
141
141
|
config: ResolvedConfig<Theme>;
|
|
142
142
|
blocked: Set<string>;
|
|
143
143
|
parentOrders: Map<string, number>;
|
|
144
|
+
activatedRules: Set<Rule<Theme>>;
|
|
144
145
|
events: Emitter<{
|
|
145
146
|
config: (config: ResolvedConfig<Theme>) => void;
|
|
146
147
|
}>;
|
|
@@ -248,6 +249,7 @@ declare const SymbolVariants: unique symbol;
|
|
|
248
249
|
declare const SymbolParent: unique symbol;
|
|
249
250
|
declare const SymbolSelector: unique symbol;
|
|
250
251
|
declare const SymbolLayer: unique symbol;
|
|
252
|
+
declare const SymbolSort: unique symbol;
|
|
251
253
|
interface ControlSymbols {
|
|
252
254
|
/**
|
|
253
255
|
* Prevent merging in shortcuts
|
|
@@ -269,6 +271,10 @@ interface ControlSymbols {
|
|
|
269
271
|
* Layer modifier
|
|
270
272
|
*/
|
|
271
273
|
layer: typeof SymbolLayer;
|
|
274
|
+
/**
|
|
275
|
+
* Sort modifier
|
|
276
|
+
*/
|
|
277
|
+
sort: typeof SymbolSort;
|
|
272
278
|
}
|
|
273
279
|
interface ControlSymbolsValue {
|
|
274
280
|
[SymbolShortcutsNoMerge]: true;
|
|
@@ -276,6 +282,7 @@ interface ControlSymbolsValue {
|
|
|
276
282
|
[SymbolParent]: string;
|
|
277
283
|
[SymbolSelector]: (selector: string) => string;
|
|
278
284
|
[SymbolLayer]: string;
|
|
285
|
+
[SymbolSort]: number;
|
|
279
286
|
}
|
|
280
287
|
type ObjectToEntry<T> = {
|
|
281
288
|
[K in keyof T]: [K, T[K]];
|
|
@@ -302,7 +309,7 @@ interface ExtractorContext {
|
|
|
302
309
|
extracted: Set<string> | CountableSet<string>;
|
|
303
310
|
envMode?: 'dev' | 'build';
|
|
304
311
|
}
|
|
305
|
-
interface
|
|
312
|
+
interface BaseContext<Theme extends object = object> {
|
|
306
313
|
/**
|
|
307
314
|
* UnoCSS generator instance
|
|
308
315
|
*/
|
|
@@ -312,7 +319,9 @@ interface PreflightContext<Theme extends object = object> {
|
|
|
312
319
|
*/
|
|
313
320
|
theme: Theme;
|
|
314
321
|
}
|
|
315
|
-
interface
|
|
322
|
+
interface PreflightContext<Theme extends object = object> extends BaseContext<Theme> {
|
|
323
|
+
}
|
|
324
|
+
interface SafeListContext<Theme extends object = object> extends BaseContext<Theme> {
|
|
316
325
|
}
|
|
317
326
|
interface Extractor {
|
|
318
327
|
name: string;
|
|
@@ -359,6 +368,10 @@ interface RuleMeta {
|
|
|
359
368
|
* @private
|
|
360
369
|
*/
|
|
361
370
|
__hash?: string;
|
|
371
|
+
/**
|
|
372
|
+
* Custom metadata
|
|
373
|
+
*/
|
|
374
|
+
custom?: Record<string, any>;
|
|
362
375
|
}
|
|
363
376
|
type CSSValue = CSSObject | CSSEntries;
|
|
364
377
|
type CSSValues = CSSValue | CSSValue[];
|
|
@@ -923,8 +936,9 @@ interface ResolvedConfig<Theme extends object = object> extends Omit<RequiredByK
|
|
|
923
936
|
preprocess: Preprocessor[];
|
|
924
937
|
postprocess: Postprocessor[];
|
|
925
938
|
rulesSize: number;
|
|
926
|
-
|
|
927
|
-
|
|
939
|
+
rules: readonly Rule<Theme>[];
|
|
940
|
+
rulesDynamic: readonly DynamicRule<Theme>[];
|
|
941
|
+
rulesStaticMap: Record<string, StaticRule | undefined>;
|
|
928
942
|
autocomplete: {
|
|
929
943
|
templates: (AutoCompleteFunction | AutoCompleteTemplate)[];
|
|
930
944
|
extractors: AutoCompleteExtractor[];
|
package/dist/index.d.ts
CHANGED
|
@@ -141,6 +141,7 @@ declare class UnoGeneratorInternal<Theme extends object = object> {
|
|
|
141
141
|
config: ResolvedConfig<Theme>;
|
|
142
142
|
blocked: Set<string>;
|
|
143
143
|
parentOrders: Map<string, number>;
|
|
144
|
+
activatedRules: Set<Rule<Theme>>;
|
|
144
145
|
events: Emitter<{
|
|
145
146
|
config: (config: ResolvedConfig<Theme>) => void;
|
|
146
147
|
}>;
|
|
@@ -248,6 +249,7 @@ declare const SymbolVariants: unique symbol;
|
|
|
248
249
|
declare const SymbolParent: unique symbol;
|
|
249
250
|
declare const SymbolSelector: unique symbol;
|
|
250
251
|
declare const SymbolLayer: unique symbol;
|
|
252
|
+
declare const SymbolSort: unique symbol;
|
|
251
253
|
interface ControlSymbols {
|
|
252
254
|
/**
|
|
253
255
|
* Prevent merging in shortcuts
|
|
@@ -269,6 +271,10 @@ interface ControlSymbols {
|
|
|
269
271
|
* Layer modifier
|
|
270
272
|
*/
|
|
271
273
|
layer: typeof SymbolLayer;
|
|
274
|
+
/**
|
|
275
|
+
* Sort modifier
|
|
276
|
+
*/
|
|
277
|
+
sort: typeof SymbolSort;
|
|
272
278
|
}
|
|
273
279
|
interface ControlSymbolsValue {
|
|
274
280
|
[SymbolShortcutsNoMerge]: true;
|
|
@@ -276,6 +282,7 @@ interface ControlSymbolsValue {
|
|
|
276
282
|
[SymbolParent]: string;
|
|
277
283
|
[SymbolSelector]: (selector: string) => string;
|
|
278
284
|
[SymbolLayer]: string;
|
|
285
|
+
[SymbolSort]: number;
|
|
279
286
|
}
|
|
280
287
|
type ObjectToEntry<T> = {
|
|
281
288
|
[K in keyof T]: [K, T[K]];
|
|
@@ -302,7 +309,7 @@ interface ExtractorContext {
|
|
|
302
309
|
extracted: Set<string> | CountableSet<string>;
|
|
303
310
|
envMode?: 'dev' | 'build';
|
|
304
311
|
}
|
|
305
|
-
interface
|
|
312
|
+
interface BaseContext<Theme extends object = object> {
|
|
306
313
|
/**
|
|
307
314
|
* UnoCSS generator instance
|
|
308
315
|
*/
|
|
@@ -312,7 +319,9 @@ interface PreflightContext<Theme extends object = object> {
|
|
|
312
319
|
*/
|
|
313
320
|
theme: Theme;
|
|
314
321
|
}
|
|
315
|
-
interface
|
|
322
|
+
interface PreflightContext<Theme extends object = object> extends BaseContext<Theme> {
|
|
323
|
+
}
|
|
324
|
+
interface SafeListContext<Theme extends object = object> extends BaseContext<Theme> {
|
|
316
325
|
}
|
|
317
326
|
interface Extractor {
|
|
318
327
|
name: string;
|
|
@@ -359,6 +368,10 @@ interface RuleMeta {
|
|
|
359
368
|
* @private
|
|
360
369
|
*/
|
|
361
370
|
__hash?: string;
|
|
371
|
+
/**
|
|
372
|
+
* Custom metadata
|
|
373
|
+
*/
|
|
374
|
+
custom?: Record<string, any>;
|
|
362
375
|
}
|
|
363
376
|
type CSSValue = CSSObject | CSSEntries;
|
|
364
377
|
type CSSValues = CSSValue | CSSValue[];
|
|
@@ -923,8 +936,9 @@ interface ResolvedConfig<Theme extends object = object> extends Omit<RequiredByK
|
|
|
923
936
|
preprocess: Preprocessor[];
|
|
924
937
|
postprocess: Postprocessor[];
|
|
925
938
|
rulesSize: number;
|
|
926
|
-
|
|
927
|
-
|
|
939
|
+
rules: readonly Rule<Theme>[];
|
|
940
|
+
rulesDynamic: readonly DynamicRule<Theme>[];
|
|
941
|
+
rulesStaticMap: Record<string, StaticRule | undefined>;
|
|
928
942
|
autocomplete: {
|
|
929
943
|
templates: (AutoCompleteFunction | AutoCompleteTemplate)[];
|
|
930
944
|
extractors: AutoCompleteExtractor[];
|
package/dist/index.mjs
CHANGED
|
@@ -554,16 +554,15 @@ async function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
554
554
|
const rules = getMerged("rules");
|
|
555
555
|
const rulesStaticMap = {};
|
|
556
556
|
const rulesSize = rules.length;
|
|
557
|
-
const rulesDynamic = rules.
|
|
558
|
-
if (isStaticRule(rule))
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
}).filter(Boolean).reverse();
|
|
557
|
+
const rulesDynamic = rules.filter((rule) => {
|
|
558
|
+
if (!isStaticRule(rule))
|
|
559
|
+
return true;
|
|
560
|
+
const prefixes = toArray(rule[2]?.prefix || "");
|
|
561
|
+
prefixes.forEach((prefix) => {
|
|
562
|
+
rulesStaticMap[prefix + rule[0]] = rule;
|
|
563
|
+
});
|
|
564
|
+
return false;
|
|
565
|
+
}).reverse();
|
|
567
566
|
let theme = mergeThemes(sources.map((p) => p.theme));
|
|
568
567
|
const extendThemes = getMerged("extendTheme");
|
|
569
568
|
for (const extendTheme of extendThemes)
|
|
@@ -589,6 +588,7 @@ async function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
589
588
|
shortcutsLayer: config.shortcutsLayer || "shortcuts",
|
|
590
589
|
layers,
|
|
591
590
|
theme,
|
|
591
|
+
rules,
|
|
592
592
|
rulesSize,
|
|
593
593
|
rulesDynamic,
|
|
594
594
|
rulesStaticMap,
|
|
@@ -653,7 +653,7 @@ function definePreset(preset) {
|
|
|
653
653
|
return preset;
|
|
654
654
|
}
|
|
655
655
|
|
|
656
|
-
const version = "0.65.0
|
|
656
|
+
const version = "0.65.0";
|
|
657
657
|
|
|
658
658
|
function createNanoEvents() {
|
|
659
659
|
return {
|
|
@@ -679,7 +679,8 @@ const symbols = {
|
|
|
679
679
|
variants: "$$symbol-variants",
|
|
680
680
|
parent: "$$symbol-parent",
|
|
681
681
|
selector: "$$symbol-selector",
|
|
682
|
-
layer: "$$symbol-layer"
|
|
682
|
+
layer: "$$symbol-layer",
|
|
683
|
+
sort: "$$symbol-sort"
|
|
683
684
|
};
|
|
684
685
|
class UnoGeneratorInternal {
|
|
685
686
|
constructor(userConfig = {}, defaults = {}) {
|
|
@@ -690,6 +691,7 @@ class UnoGeneratorInternal {
|
|
|
690
691
|
__publicField(this, "config");
|
|
691
692
|
__publicField(this, "blocked", /* @__PURE__ */ new Set());
|
|
692
693
|
__publicField(this, "parentOrders", /* @__PURE__ */ new Map());
|
|
694
|
+
__publicField(this, "activatedRules", /* @__PURE__ */ new Set());
|
|
693
695
|
__publicField(this, "events", createNanoEvents());
|
|
694
696
|
}
|
|
695
697
|
static async create(userConfig = {}, defaults = {}) {
|
|
@@ -706,6 +708,7 @@ class UnoGeneratorInternal {
|
|
|
706
708
|
this.userConfig = userConfig;
|
|
707
709
|
this.blocked.clear();
|
|
708
710
|
this.parentOrders.clear();
|
|
711
|
+
this.activatedRules.clear();
|
|
709
712
|
this._cache.clear();
|
|
710
713
|
this.config = await resolveConfig(userConfig, this.defaults);
|
|
711
714
|
this.events.emit("config", this.config);
|
|
@@ -789,7 +792,6 @@ class UnoGeneratorInternal {
|
|
|
789
792
|
minify = false,
|
|
790
793
|
extendedInfo = false
|
|
791
794
|
} = options;
|
|
792
|
-
const outputCssLayers = this.config.outputToCssLayers;
|
|
793
795
|
const tokens = isString(input) ? await this.applyExtractors(
|
|
794
796
|
input,
|
|
795
797
|
id,
|
|
@@ -861,6 +863,14 @@ class UnoGeneratorInternal {
|
|
|
861
863
|
})();
|
|
862
864
|
const layers = this.config.sortLayers(Array.from(layerSet).sort((a, b) => (this.config.layers[a] ?? 0) - (this.config.layers[b] ?? 0) || a.localeCompare(b)));
|
|
863
865
|
const layerCache = {};
|
|
866
|
+
const outputCssLayers = this.config.outputToCssLayers;
|
|
867
|
+
const getLayerAlias = (layer) => {
|
|
868
|
+
let alias = layer;
|
|
869
|
+
if (typeof outputCssLayers === "object") {
|
|
870
|
+
alias = outputCssLayers.cssLayerName?.(layer);
|
|
871
|
+
}
|
|
872
|
+
return alias === null ? null : alias ?? layer;
|
|
873
|
+
};
|
|
864
874
|
const getLayer = (layer = LAYER_DEFAULT) => {
|
|
865
875
|
if (layerCache[layer])
|
|
866
876
|
return layerCache[layer];
|
|
@@ -900,19 +910,22 @@ class UnoGeneratorInternal {
|
|
|
900
910
|
if (preflights) {
|
|
901
911
|
css = [preflightsMap[layer], css].filter(Boolean).join(nl);
|
|
902
912
|
}
|
|
913
|
+
let alias;
|
|
903
914
|
if (outputCssLayers && css) {
|
|
904
|
-
|
|
905
|
-
if (
|
|
906
|
-
|
|
907
|
-
cssLayer = layer;
|
|
908
|
-
css = `@layer ${cssLayer}{${nl}${css}${nl}}`;
|
|
915
|
+
alias = getLayerAlias(layer);
|
|
916
|
+
if (alias !== null) {
|
|
917
|
+
css = `@layer ${alias}{${nl}${css}${nl}}`;
|
|
909
918
|
}
|
|
910
919
|
}
|
|
911
|
-
const layerMark = minify ? "" : `/* layer: ${layer} */${nl}`;
|
|
920
|
+
const layerMark = minify ? "" : `/* layer: ${layer}${alias && alias !== layer ? `, alias: ${alias}` : ""} */${nl}`;
|
|
912
921
|
return layerCache[layer] = css ? layerMark + css : "";
|
|
913
922
|
};
|
|
914
923
|
const getLayers = (includes = layers, excludes) => {
|
|
915
|
-
|
|
924
|
+
const layers2 = includes.filter((i) => !excludes?.includes(i));
|
|
925
|
+
return [
|
|
926
|
+
outputCssLayers && layers2.length > 0 ? `@layer ${layers2.map(getLayerAlias).filter(notNull).join(", ")};` : void 0,
|
|
927
|
+
...layers2.map((i) => getLayer(i) || "")
|
|
928
|
+
].filter(Boolean).join(nl);
|
|
916
929
|
};
|
|
917
930
|
const setLayer = async (layer, callback) => {
|
|
918
931
|
const content = await callback(getLayer(layer));
|
|
@@ -1051,9 +1064,10 @@ class UnoGeneratorInternal {
|
|
|
1051
1064
|
const staticMatch = this.config.rulesStaticMap[processed];
|
|
1052
1065
|
if (staticMatch) {
|
|
1053
1066
|
if (staticMatch[1] && (internal || !staticMatch[2]?.internal)) {
|
|
1067
|
+
context.generator.activatedRules.add(staticMatch);
|
|
1054
1068
|
if (this.config.details)
|
|
1055
|
-
context.rules.push(staticMatch
|
|
1056
|
-
const index = staticMatch
|
|
1069
|
+
context.rules.push(staticMatch);
|
|
1070
|
+
const index = this.config.rules.indexOf(staticMatch);
|
|
1057
1071
|
const entry = normalizeCSSEntries(staticMatch[1]);
|
|
1058
1072
|
const meta = staticMatch[2];
|
|
1059
1073
|
if (isString(entry))
|
|
@@ -1064,7 +1078,8 @@ class UnoGeneratorInternal {
|
|
|
1064
1078
|
}
|
|
1065
1079
|
context.variantHandlers = variantHandlers;
|
|
1066
1080
|
const { rulesDynamic } = this.config;
|
|
1067
|
-
for (const
|
|
1081
|
+
for (const rule of rulesDynamic) {
|
|
1082
|
+
const [matcher, handler, meta] = rule;
|
|
1068
1083
|
if (meta?.internal && !internal)
|
|
1069
1084
|
continue;
|
|
1070
1085
|
let unprefixed = processed;
|
|
@@ -1072,10 +1087,10 @@ class UnoGeneratorInternal {
|
|
|
1072
1087
|
const prefixes = toArray(meta.prefix);
|
|
1073
1088
|
if (shortcutPrefix) {
|
|
1074
1089
|
const shortcutPrefixes = toArray(shortcutPrefix);
|
|
1075
|
-
if (!prefixes.some((
|
|
1090
|
+
if (!prefixes.some((i) => shortcutPrefixes.includes(i)))
|
|
1076
1091
|
continue;
|
|
1077
1092
|
} else {
|
|
1078
|
-
const prefix = prefixes.find((
|
|
1093
|
+
const prefix = prefixes.find((i) => processed.startsWith(i));
|
|
1079
1094
|
if (prefix == null)
|
|
1080
1095
|
continue;
|
|
1081
1096
|
unprefixed = processed.slice(prefix.length);
|
|
@@ -1087,8 +1102,9 @@ class UnoGeneratorInternal {
|
|
|
1087
1102
|
let result = await handler(match, context);
|
|
1088
1103
|
if (!result)
|
|
1089
1104
|
continue;
|
|
1105
|
+
context.generator.activatedRules.add(rule);
|
|
1090
1106
|
if (this.config.details)
|
|
1091
|
-
context.rules.push(
|
|
1107
|
+
context.rules.push(rule);
|
|
1092
1108
|
if (typeof result !== "string") {
|
|
1093
1109
|
if (Symbol.asyncIterator in result) {
|
|
1094
1110
|
const entries2 = [];
|
|
@@ -1101,12 +1117,14 @@ class UnoGeneratorInternal {
|
|
|
1101
1117
|
result = Array.from(result).filter(notNull);
|
|
1102
1118
|
}
|
|
1103
1119
|
}
|
|
1104
|
-
const entries = normalizeCSSValues(result).filter((
|
|
1120
|
+
const entries = normalizeCSSValues(result).filter((i) => i.length);
|
|
1105
1121
|
if (entries.length) {
|
|
1122
|
+
const index = this.config.rules.indexOf(rule);
|
|
1106
1123
|
return entries.map((css) => {
|
|
1107
1124
|
if (isString(css))
|
|
1108
|
-
return [
|
|
1125
|
+
return [index, css, meta];
|
|
1109
1126
|
let variants = variantHandlers;
|
|
1127
|
+
let entryMeta = meta;
|
|
1110
1128
|
for (const entry of css) {
|
|
1111
1129
|
if (entry[0] === symbols.variants) {
|
|
1112
1130
|
variants = [
|
|
@@ -1128,9 +1146,14 @@ class UnoGeneratorInternal {
|
|
|
1128
1146
|
{ layer: entry[1] },
|
|
1129
1147
|
...variants
|
|
1130
1148
|
];
|
|
1149
|
+
} else if (entry[0] === symbols.sort) {
|
|
1150
|
+
entryMeta = {
|
|
1151
|
+
...entryMeta,
|
|
1152
|
+
sort: entry[1]
|
|
1153
|
+
};
|
|
1131
1154
|
}
|
|
1132
1155
|
}
|
|
1133
|
-
return [
|
|
1156
|
+
return [index, raw, css, entryMeta, variants];
|
|
1134
1157
|
});
|
|
1135
1158
|
}
|
|
1136
1159
|
}
|