@unocss/core 0.65.0-beta.1 → 0.65.0-beta.3
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 +12 -4
- package/dist/index.d.ts +12 -4
- package/dist/index.mjs +44 -28
- 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
|
}>;
|
|
@@ -302,7 +303,7 @@ interface ExtractorContext {
|
|
|
302
303
|
extracted: Set<string> | CountableSet<string>;
|
|
303
304
|
envMode?: 'dev' | 'build';
|
|
304
305
|
}
|
|
305
|
-
interface
|
|
306
|
+
interface BaseContext<Theme extends object = object> {
|
|
306
307
|
/**
|
|
307
308
|
* UnoCSS generator instance
|
|
308
309
|
*/
|
|
@@ -312,7 +313,9 @@ interface PreflightContext<Theme extends object = object> {
|
|
|
312
313
|
*/
|
|
313
314
|
theme: Theme;
|
|
314
315
|
}
|
|
315
|
-
interface
|
|
316
|
+
interface PreflightContext<Theme extends object = object> extends BaseContext<Theme> {
|
|
317
|
+
}
|
|
318
|
+
interface SafeListContext<Theme extends object = object> extends BaseContext<Theme> {
|
|
316
319
|
}
|
|
317
320
|
interface Extractor {
|
|
318
321
|
name: string;
|
|
@@ -359,6 +362,10 @@ interface RuleMeta {
|
|
|
359
362
|
* @private
|
|
360
363
|
*/
|
|
361
364
|
__hash?: string;
|
|
365
|
+
/**
|
|
366
|
+
* Custom metadata
|
|
367
|
+
*/
|
|
368
|
+
custom?: Record<string, any>;
|
|
362
369
|
}
|
|
363
370
|
type CSSValue = CSSObject | CSSEntries;
|
|
364
371
|
type CSSValues = CSSValue | CSSValue[];
|
|
@@ -923,8 +930,9 @@ interface ResolvedConfig<Theme extends object = object> extends Omit<RequiredByK
|
|
|
923
930
|
preprocess: Preprocessor[];
|
|
924
931
|
postprocess: Postprocessor[];
|
|
925
932
|
rulesSize: number;
|
|
926
|
-
|
|
927
|
-
|
|
933
|
+
rules: readonly Rule<Theme>[];
|
|
934
|
+
rulesDynamic: readonly DynamicRule<Theme>[];
|
|
935
|
+
rulesStaticMap: Record<string, StaticRule | undefined>;
|
|
928
936
|
autocomplete: {
|
|
929
937
|
templates: (AutoCompleteFunction | AutoCompleteTemplate)[];
|
|
930
938
|
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
|
}>;
|
|
@@ -302,7 +303,7 @@ interface ExtractorContext {
|
|
|
302
303
|
extracted: Set<string> | CountableSet<string>;
|
|
303
304
|
envMode?: 'dev' | 'build';
|
|
304
305
|
}
|
|
305
|
-
interface
|
|
306
|
+
interface BaseContext<Theme extends object = object> {
|
|
306
307
|
/**
|
|
307
308
|
* UnoCSS generator instance
|
|
308
309
|
*/
|
|
@@ -312,7 +313,9 @@ interface PreflightContext<Theme extends object = object> {
|
|
|
312
313
|
*/
|
|
313
314
|
theme: Theme;
|
|
314
315
|
}
|
|
315
|
-
interface
|
|
316
|
+
interface PreflightContext<Theme extends object = object> extends BaseContext<Theme> {
|
|
317
|
+
}
|
|
318
|
+
interface SafeListContext<Theme extends object = object> extends BaseContext<Theme> {
|
|
316
319
|
}
|
|
317
320
|
interface Extractor {
|
|
318
321
|
name: string;
|
|
@@ -359,6 +362,10 @@ interface RuleMeta {
|
|
|
359
362
|
* @private
|
|
360
363
|
*/
|
|
361
364
|
__hash?: string;
|
|
365
|
+
/**
|
|
366
|
+
* Custom metadata
|
|
367
|
+
*/
|
|
368
|
+
custom?: Record<string, any>;
|
|
362
369
|
}
|
|
363
370
|
type CSSValue = CSSObject | CSSEntries;
|
|
364
371
|
type CSSValues = CSSValue | CSSValue[];
|
|
@@ -923,8 +930,9 @@ interface ResolvedConfig<Theme extends object = object> extends Omit<RequiredByK
|
|
|
923
930
|
preprocess: Preprocessor[];
|
|
924
931
|
postprocess: Postprocessor[];
|
|
925
932
|
rulesSize: number;
|
|
926
|
-
|
|
927
|
-
|
|
933
|
+
rules: readonly Rule<Theme>[];
|
|
934
|
+
rulesDynamic: readonly DynamicRule<Theme>[];
|
|
935
|
+
rulesStaticMap: Record<string, StaticRule | undefined>;
|
|
928
936
|
autocomplete: {
|
|
929
937
|
templates: (AutoCompleteFunction | AutoCompleteTemplate)[];
|
|
930
938
|
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-beta.
|
|
656
|
+
const version = "0.65.0-beta.3";
|
|
657
657
|
|
|
658
658
|
function createNanoEvents() {
|
|
659
659
|
return {
|
|
@@ -690,6 +690,7 @@ class UnoGeneratorInternal {
|
|
|
690
690
|
__publicField(this, "config");
|
|
691
691
|
__publicField(this, "blocked", /* @__PURE__ */ new Set());
|
|
692
692
|
__publicField(this, "parentOrders", /* @__PURE__ */ new Map());
|
|
693
|
+
__publicField(this, "activatedRules", /* @__PURE__ */ new Set());
|
|
693
694
|
__publicField(this, "events", createNanoEvents());
|
|
694
695
|
}
|
|
695
696
|
static async create(userConfig = {}, defaults = {}) {
|
|
@@ -706,6 +707,7 @@ class UnoGeneratorInternal {
|
|
|
706
707
|
this.userConfig = userConfig;
|
|
707
708
|
this.blocked.clear();
|
|
708
709
|
this.parentOrders.clear();
|
|
710
|
+
this.activatedRules.clear();
|
|
709
711
|
this._cache.clear();
|
|
710
712
|
this.config = await resolveConfig(userConfig, this.defaults);
|
|
711
713
|
this.events.emit("config", this.config);
|
|
@@ -789,7 +791,6 @@ class UnoGeneratorInternal {
|
|
|
789
791
|
minify = false,
|
|
790
792
|
extendedInfo = false
|
|
791
793
|
} = options;
|
|
792
|
-
const outputCssLayers = this.config.outputToCssLayers;
|
|
793
794
|
const tokens = isString(input) ? await this.applyExtractors(
|
|
794
795
|
input,
|
|
795
796
|
id,
|
|
@@ -861,6 +862,14 @@ class UnoGeneratorInternal {
|
|
|
861
862
|
})();
|
|
862
863
|
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
864
|
const layerCache = {};
|
|
865
|
+
const outputCssLayers = this.config.outputToCssLayers;
|
|
866
|
+
const getLayerAlias = (layer) => {
|
|
867
|
+
let alias = layer;
|
|
868
|
+
if (typeof outputCssLayers === "object") {
|
|
869
|
+
alias = outputCssLayers.cssLayerName?.(layer);
|
|
870
|
+
}
|
|
871
|
+
return alias === null ? null : alias ?? layer;
|
|
872
|
+
};
|
|
864
873
|
const getLayer = (layer = LAYER_DEFAULT) => {
|
|
865
874
|
if (layerCache[layer])
|
|
866
875
|
return layerCache[layer];
|
|
@@ -900,19 +909,22 @@ class UnoGeneratorInternal {
|
|
|
900
909
|
if (preflights) {
|
|
901
910
|
css = [preflightsMap[layer], css].filter(Boolean).join(nl);
|
|
902
911
|
}
|
|
912
|
+
let alias;
|
|
903
913
|
if (outputCssLayers && css) {
|
|
904
|
-
|
|
905
|
-
if (
|
|
906
|
-
|
|
907
|
-
cssLayer = layer;
|
|
908
|
-
css = `@layer ${cssLayer}{${nl}${css}${nl}}`;
|
|
914
|
+
alias = getLayerAlias(layer);
|
|
915
|
+
if (alias !== null) {
|
|
916
|
+
css = `@layer ${alias}{${nl}${css}${nl}}`;
|
|
909
917
|
}
|
|
910
918
|
}
|
|
911
|
-
const layerMark = minify ? "" : `/* layer: ${layer} */${nl}`;
|
|
919
|
+
const layerMark = minify ? "" : `/* layer: ${layer}${alias && alias !== layer ? `, alias: ${alias}` : ""} */${nl}`;
|
|
912
920
|
return layerCache[layer] = css ? layerMark + css : "";
|
|
913
921
|
};
|
|
914
922
|
const getLayers = (includes = layers, excludes) => {
|
|
915
|
-
|
|
923
|
+
const layers2 = includes.filter((i) => !excludes?.includes(i));
|
|
924
|
+
return [
|
|
925
|
+
outputCssLayers && layers2.length > 0 ? `@layer ${layers2.map(getLayerAlias).filter(notNull).join(", ")};` : void 0,
|
|
926
|
+
...layers2.map((i) => getLayer(i) || "")
|
|
927
|
+
].filter(Boolean).join(nl);
|
|
916
928
|
};
|
|
917
929
|
const setLayer = async (layer, callback) => {
|
|
918
930
|
const content = await callback(getLayer(layer));
|
|
@@ -1051,9 +1063,10 @@ class UnoGeneratorInternal {
|
|
|
1051
1063
|
const staticMatch = this.config.rulesStaticMap[processed];
|
|
1052
1064
|
if (staticMatch) {
|
|
1053
1065
|
if (staticMatch[1] && (internal || !staticMatch[2]?.internal)) {
|
|
1066
|
+
context.generator.activatedRules.add(staticMatch);
|
|
1054
1067
|
if (this.config.details)
|
|
1055
|
-
context.rules.push(staticMatch
|
|
1056
|
-
const index = staticMatch
|
|
1068
|
+
context.rules.push(staticMatch);
|
|
1069
|
+
const index = this.config.rules.indexOf(staticMatch);
|
|
1057
1070
|
const entry = normalizeCSSEntries(staticMatch[1]);
|
|
1058
1071
|
const meta = staticMatch[2];
|
|
1059
1072
|
if (isString(entry))
|
|
@@ -1064,7 +1077,8 @@ class UnoGeneratorInternal {
|
|
|
1064
1077
|
}
|
|
1065
1078
|
context.variantHandlers = variantHandlers;
|
|
1066
1079
|
const { rulesDynamic } = this.config;
|
|
1067
|
-
for (const
|
|
1080
|
+
for (const rule of rulesDynamic) {
|
|
1081
|
+
const [matcher, handler, meta] = rule;
|
|
1068
1082
|
if (meta?.internal && !internal)
|
|
1069
1083
|
continue;
|
|
1070
1084
|
let unprefixed = processed;
|
|
@@ -1072,10 +1086,10 @@ class UnoGeneratorInternal {
|
|
|
1072
1086
|
const prefixes = toArray(meta.prefix);
|
|
1073
1087
|
if (shortcutPrefix) {
|
|
1074
1088
|
const shortcutPrefixes = toArray(shortcutPrefix);
|
|
1075
|
-
if (!prefixes.some((
|
|
1089
|
+
if (!prefixes.some((i) => shortcutPrefixes.includes(i)))
|
|
1076
1090
|
continue;
|
|
1077
1091
|
} else {
|
|
1078
|
-
const prefix = prefixes.find((
|
|
1092
|
+
const prefix = prefixes.find((i) => processed.startsWith(i));
|
|
1079
1093
|
if (prefix == null)
|
|
1080
1094
|
continue;
|
|
1081
1095
|
unprefixed = processed.slice(prefix.length);
|
|
@@ -1087,8 +1101,9 @@ class UnoGeneratorInternal {
|
|
|
1087
1101
|
let result = await handler(match, context);
|
|
1088
1102
|
if (!result)
|
|
1089
1103
|
continue;
|
|
1104
|
+
context.generator.activatedRules.add(rule);
|
|
1090
1105
|
if (this.config.details)
|
|
1091
|
-
context.rules.push(
|
|
1106
|
+
context.rules.push(rule);
|
|
1092
1107
|
if (typeof result !== "string") {
|
|
1093
1108
|
if (Symbol.asyncIterator in result) {
|
|
1094
1109
|
const entries2 = [];
|
|
@@ -1101,11 +1116,12 @@ class UnoGeneratorInternal {
|
|
|
1101
1116
|
result = Array.from(result).filter(notNull);
|
|
1102
1117
|
}
|
|
1103
1118
|
}
|
|
1104
|
-
const entries = normalizeCSSValues(result).filter((
|
|
1119
|
+
const entries = normalizeCSSValues(result).filter((i) => i.length);
|
|
1105
1120
|
if (entries.length) {
|
|
1121
|
+
const index = this.config.rules.indexOf(rule);
|
|
1106
1122
|
return entries.map((css) => {
|
|
1107
1123
|
if (isString(css))
|
|
1108
|
-
return [
|
|
1124
|
+
return [index, css, meta];
|
|
1109
1125
|
let variants = variantHandlers;
|
|
1110
1126
|
for (const entry of css) {
|
|
1111
1127
|
if (entry[0] === symbols.variants) {
|
|
@@ -1130,7 +1146,7 @@ class UnoGeneratorInternal {
|
|
|
1130
1146
|
];
|
|
1131
1147
|
}
|
|
1132
1148
|
}
|
|
1133
|
-
return [
|
|
1149
|
+
return [index, raw, css, meta, variants];
|
|
1134
1150
|
});
|
|
1135
1151
|
}
|
|
1136
1152
|
}
|
package/package.json
CHANGED