@unocss/core 0.17.3 → 0.20.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 -19
- package/dist/index.d.ts +48 -10
- package/dist/index.mjs +40 -19
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -337,6 +337,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
337
337
|
...sortedPresets.map((p) => p.theme || {}),
|
|
338
338
|
config.theme || {}
|
|
339
339
|
].reduce((a, p) => mergeDeep(a, p), {});
|
|
340
|
+
const options = Object.assign({}, ...config.presets?.map((p) => Array.isArray(p) ? p : [p]).flat(1).map((p) => p.options ?? {}) || []);
|
|
340
341
|
return {
|
|
341
342
|
mergeSelectors: true,
|
|
342
343
|
warn: true,
|
|
@@ -352,14 +353,17 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
352
353
|
rulesSize,
|
|
353
354
|
rulesDynamic: rules,
|
|
354
355
|
rulesStaticMap,
|
|
356
|
+
preprocess: mergePresets("preprocess"),
|
|
357
|
+
postprocess: mergePresets("postprocess"),
|
|
355
358
|
preflights: mergePresets("preflights"),
|
|
356
359
|
variants: mergePresets("variants").map(normalizeVariant),
|
|
357
360
|
shortcuts: resolveShortcuts(mergePresets("shortcuts")),
|
|
358
|
-
extractors
|
|
361
|
+
extractors,
|
|
362
|
+
options
|
|
359
363
|
};
|
|
360
364
|
}
|
|
361
365
|
|
|
362
|
-
const version = "0.
|
|
366
|
+
const version = "0.20.0";
|
|
363
367
|
|
|
364
368
|
class UnoGenerator {
|
|
365
369
|
constructor(userConfig = {}, defaults = {}) {
|
|
@@ -388,7 +392,8 @@ class UnoGenerator {
|
|
|
388
392
|
return code;
|
|
389
393
|
},
|
|
390
394
|
code,
|
|
391
|
-
id
|
|
395
|
+
id,
|
|
396
|
+
options: this.config.options
|
|
392
397
|
};
|
|
393
398
|
for (const extractor of this.config.extractors) {
|
|
394
399
|
const result = await extractor.extract(context);
|
|
@@ -436,8 +441,8 @@ class UnoGenerator {
|
|
|
436
441
|
return;
|
|
437
442
|
}
|
|
438
443
|
let current = raw;
|
|
439
|
-
|
|
440
|
-
current =
|
|
444
|
+
for (const p of this.config.preprocess)
|
|
445
|
+
current = p(raw);
|
|
441
446
|
if (this.isBlocked(current))
|
|
442
447
|
return block(current);
|
|
443
448
|
const applied = this.matchVariants(raw, current);
|
|
@@ -449,7 +454,8 @@ class UnoGenerator {
|
|
|
449
454
|
theme: this.config.theme,
|
|
450
455
|
generator: this,
|
|
451
456
|
variantHandlers: applied[2],
|
|
452
|
-
constructCSS: (...args) => this.constructCustomCSS(context, ...args)
|
|
457
|
+
constructCSS: (...args) => this.constructCustomCSS(context, ...args),
|
|
458
|
+
options: this.config.options
|
|
453
459
|
};
|
|
454
460
|
const expanded = this.expandShortcut(applied[1], context);
|
|
455
461
|
if (expanded) {
|
|
@@ -474,7 +480,13 @@ class UnoGenerator {
|
|
|
474
480
|
const getLayer = (layer) => {
|
|
475
481
|
if (layerCache[layer])
|
|
476
482
|
return layerCache[layer];
|
|
477
|
-
let css = Array.from(sheet).sort((a, b) =>
|
|
483
|
+
let css = Array.from(sheet).sort((a, b) => {
|
|
484
|
+
const parentOrderA = this.parentOrders.get(a[0]);
|
|
485
|
+
const parentOrderB = this.parentOrders.get(b[0]);
|
|
486
|
+
if (parentOrderA !== void 0 && parentOrderB !== void 0)
|
|
487
|
+
return parentOrderA - parentOrderB;
|
|
488
|
+
return a[0]?.localeCompare(b[0] || "");
|
|
489
|
+
}).map(([parent, items]) => {
|
|
478
490
|
const size = items.length;
|
|
479
491
|
const sorted = items.filter((i) => (i[4]?.layer || "default") === layer).sort((a, b) => a[0] - b[0] || a[1]?.localeCompare(b[1] || "") || 0).map((a) => [a[1] ? applyScope(a[1], scope) : a[1], a[2]]);
|
|
480
492
|
if (!sorted.length)
|
|
@@ -519,12 +531,18 @@ class UnoGenerator {
|
|
|
519
531
|
const handlers = [];
|
|
520
532
|
let processed = current || raw;
|
|
521
533
|
let applied = false;
|
|
534
|
+
const context = {
|
|
535
|
+
rawSelector: raw,
|
|
536
|
+
theme: this.config.theme,
|
|
537
|
+
generator: this,
|
|
538
|
+
options: this.config.options
|
|
539
|
+
};
|
|
522
540
|
while (true) {
|
|
523
541
|
applied = false;
|
|
524
542
|
for (const v of this.config.variants) {
|
|
525
543
|
if (!v.multiPass && usedVariants.has(v))
|
|
526
544
|
continue;
|
|
527
|
-
let handler = v.match(processed,
|
|
545
|
+
let handler = v.match(processed, context);
|
|
528
546
|
if (!handler)
|
|
529
547
|
continue;
|
|
530
548
|
if (typeof handler === "string")
|
|
@@ -548,18 +566,21 @@ class UnoGenerator {
|
|
|
548
566
|
}
|
|
549
567
|
applyVariants(parsed, variantHandlers = parsed[4], raw = parsed[1]) {
|
|
550
568
|
const entries = variantHandlers.reduce((p, v) => v.body?.(p) || p, parsed[2]);
|
|
551
|
-
|
|
552
|
-
variantHandlers.reduce((p, v) => v.selector?.(p, entries) || p, toEscapedSelector(raw)),
|
|
569
|
+
const obj = {
|
|
570
|
+
selector: variantHandlers.reduce((p, v) => v.selector?.(p, entries) || p, toEscapedSelector(raw)),
|
|
553
571
|
entries,
|
|
554
|
-
variantHandlers.reduce((p, v) => Array.isArray(v.parent) ? v.parent[0] : v.parent || p, void 0)
|
|
555
|
-
|
|
572
|
+
parent: variantHandlers.reduce((p, v) => Array.isArray(v.parent) ? v.parent[0] : v.parent || p, void 0)
|
|
573
|
+
};
|
|
574
|
+
for (const p of this.config.postprocess)
|
|
575
|
+
p(obj);
|
|
576
|
+
return obj;
|
|
556
577
|
}
|
|
557
578
|
constructCustomCSS(context, body, overrideSelector) {
|
|
558
579
|
body = normalizeCSSEntries(body);
|
|
559
|
-
const
|
|
580
|
+
const { selector, entries, parent } = this.applyVariants([0, overrideSelector || context.rawSelector, body, void 0, context.variantHandlers]);
|
|
560
581
|
const cssBody = `${selector}{${entriesToCss(entries)}}`;
|
|
561
|
-
if (
|
|
562
|
-
return `${
|
|
582
|
+
if (parent)
|
|
583
|
+
return `${parent}{${cssBody}}`;
|
|
563
584
|
return cssBody;
|
|
564
585
|
}
|
|
565
586
|
async parseUtil(input, context, internal = false) {
|
|
@@ -596,11 +617,11 @@ class UnoGenerator {
|
|
|
596
617
|
return;
|
|
597
618
|
if (isRawUtil(parsed))
|
|
598
619
|
return [parsed[0], void 0, parsed[1], void 0, parsed[2]];
|
|
599
|
-
const
|
|
620
|
+
const { selector, entries, parent } = this.applyVariants(parsed);
|
|
600
621
|
const body = entriesToCss(entries);
|
|
601
622
|
if (!body)
|
|
602
623
|
return;
|
|
603
|
-
return [parsed[0], selector, body,
|
|
624
|
+
return [parsed[0], selector, body, parent, parsed[3]];
|
|
604
625
|
}
|
|
605
626
|
expandShortcut(processed, context, depth = 3) {
|
|
606
627
|
if (depth === 0)
|
|
@@ -645,8 +666,8 @@ class UnoGenerator {
|
|
|
645
666
|
for (const item of parsed) {
|
|
646
667
|
if (isRawUtil(item))
|
|
647
668
|
continue;
|
|
648
|
-
const
|
|
649
|
-
const mapItem = selectorMap.getFallback(selector,
|
|
669
|
+
const { selector, entries, parent: parent2 } = this.applyVariants(item, [...item[4], ...parentVariants], raw);
|
|
670
|
+
const mapItem = selectorMap.getFallback(selector, parent2, [[], item[0]]);
|
|
650
671
|
mapItem[0].push(...entries);
|
|
651
672
|
if (item[0] > mapItem[1])
|
|
652
673
|
mapItem[1] = item[0];
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ declare class UnoGenerator {
|
|
|
11
11
|
applyExtractors(code: string, id?: string, set?: Set<string>): Promise<Set<string>>;
|
|
12
12
|
generate(input: string | Set<string>, { id, scope, preflights, safelist, minify, }?: GenerateOptions): Promise<GenerateResult>;
|
|
13
13
|
matchVariants(raw: string, current?: string): VariantMatchedResult;
|
|
14
|
-
applyVariants(parsed: ParsedUtil, variantHandlers?: VariantHandler[], raw?: string):
|
|
14
|
+
applyVariants(parsed: ParsedUtil, variantHandlers?: VariantHandler[], raw?: string): UtilObject;
|
|
15
15
|
constructCustomCSS(context: Readonly<RuleContext>, body: CSSObject | CSSEntries, overrideSelector?: string): string;
|
|
16
16
|
parseUtil(input: string | VariantMatchedResult, context: RuleContext, internal?: boolean): Promise<ParsedUtil[] | RawUtil[] | undefined>;
|
|
17
17
|
stringifyUtil(parsed?: ParsedUtil | RawUtil): StringifiedUtil | undefined;
|
|
@@ -59,6 +59,7 @@ declare type ParsedColorValue = {
|
|
|
59
59
|
*/
|
|
60
60
|
rgba?: RGBAColorValue;
|
|
61
61
|
};
|
|
62
|
+
declare type PresetOptions = Record<string, any>;
|
|
62
63
|
interface RuleContext<Theme extends {} = {}> {
|
|
63
64
|
/**
|
|
64
65
|
* Unprocessed selector from user input.
|
|
@@ -86,11 +87,34 @@ interface RuleContext<Theme extends {} = {}> {
|
|
|
86
87
|
* Variants and selector escaping will be handled automatically.
|
|
87
88
|
*/
|
|
88
89
|
constructCSS: (body: CSSEntries | CSSObject, overrideSelector?: string) => string;
|
|
90
|
+
/**
|
|
91
|
+
* User-provided options from preset.
|
|
92
|
+
*/
|
|
93
|
+
readonly options: PresetOptions;
|
|
94
|
+
}
|
|
95
|
+
interface VariantContext<Theme extends {} = {}> {
|
|
96
|
+
/**
|
|
97
|
+
* Unprocessed selector from user input.
|
|
98
|
+
*/
|
|
99
|
+
rawSelector: string;
|
|
100
|
+
/**
|
|
101
|
+
* UnoCSS generator instance
|
|
102
|
+
*/
|
|
103
|
+
generator: UnoGenerator;
|
|
104
|
+
/**
|
|
105
|
+
* The theme object
|
|
106
|
+
*/
|
|
107
|
+
theme: Theme;
|
|
108
|
+
/**
|
|
109
|
+
* User-provided options from preset.
|
|
110
|
+
*/
|
|
111
|
+
readonly options: PresetOptions;
|
|
89
112
|
}
|
|
90
113
|
interface ExtractorContext {
|
|
91
114
|
readonly original: string;
|
|
92
115
|
code: string;
|
|
93
116
|
id?: string;
|
|
117
|
+
readonly options: PresetOptions;
|
|
94
118
|
}
|
|
95
119
|
interface Extractor {
|
|
96
120
|
name: string;
|
|
@@ -110,11 +134,11 @@ interface RuleMeta {
|
|
|
110
134
|
internal?: boolean;
|
|
111
135
|
}
|
|
112
136
|
declare type CSSValues = CSSObject | CSSEntries | (CSSObject | CSSEntries)[];
|
|
113
|
-
declare type DynamicMatcher<Theme extends {} = {}> = ((match:
|
|
137
|
+
declare type DynamicMatcher<Theme extends {} = {}> = ((match: RegExpMatchArray, context: Readonly<RuleContext<Theme>>) => Awaitable<CSSValues | string | undefined>);
|
|
114
138
|
declare type DynamicRule<Theme extends {} = {}> = [RegExp, DynamicMatcher<Theme>] | [RegExp, DynamicMatcher<Theme>, RuleMeta];
|
|
115
139
|
declare type StaticRule = [string, CSSObject | CSSEntries] | [string, CSSObject | CSSEntries, RuleMeta];
|
|
116
140
|
declare type Rule<Theme extends {} = {}> = DynamicRule<Theme> | StaticRule;
|
|
117
|
-
declare type DynamicShortcutMatcher<Theme extends {} = {}> = ((match:
|
|
141
|
+
declare type DynamicShortcutMatcher<Theme extends {} = {}> = ((match: RegExpMatchArray, context: Readonly<RuleContext<Theme>>) => (string | string[] | undefined));
|
|
118
142
|
declare type StaticShortcut = [string, string | string[]] | [string, string | string[], RuleMeta];
|
|
119
143
|
declare type StaticShortcutMap = Record<string, string | string[]>;
|
|
120
144
|
declare type DynamicShortcut<Theme extends {} = {}> = [RegExp, DynamicShortcutMatcher<Theme>] | [RegExp, DynamicShortcutMatcher<Theme>, RuleMeta];
|
|
@@ -144,7 +168,7 @@ interface VariantHandler {
|
|
|
144
168
|
*/
|
|
145
169
|
parent?: string | [string, number] | undefined;
|
|
146
170
|
}
|
|
147
|
-
declare type VariantFunction<Theme extends {} = {}> = (matcher: string,
|
|
171
|
+
declare type VariantFunction<Theme extends {} = {}> = (matcher: string, context: Readonly<VariantContext<Theme>>) => string | VariantHandler | undefined;
|
|
148
172
|
declare type VariantObject<Theme extends {} = {}> = {
|
|
149
173
|
/**
|
|
150
174
|
* The entry function to match and rewrite the selector for futher processing.
|
|
@@ -158,6 +182,8 @@ declare type VariantObject<Theme extends {} = {}> = {
|
|
|
158
182
|
multiPass?: boolean;
|
|
159
183
|
};
|
|
160
184
|
declare type Variant<Theme extends {} = {}> = VariantFunction<Theme> | VariantObject<Theme>;
|
|
185
|
+
declare type Preprocessor = (matcher: string) => string | undefined;
|
|
186
|
+
declare type Postprocessor = (util: UtilObject) => void;
|
|
161
187
|
interface ConfigBase<Theme extends {} = {}> {
|
|
162
188
|
/**
|
|
163
189
|
* Rules to generate CSS utilities
|
|
@@ -203,6 +229,14 @@ interface ConfigBase<Theme extends {} = {}> {
|
|
|
203
229
|
* Custom function to sort layers.
|
|
204
230
|
*/
|
|
205
231
|
sortLayers?: (layers: string[]) => string[];
|
|
232
|
+
/**
|
|
233
|
+
* Preprocess the incoming utilities, return falsy value to exclude
|
|
234
|
+
*/
|
|
235
|
+
preprocess?: Preprocessor | Preprocessor[];
|
|
236
|
+
/**
|
|
237
|
+
* Process the generate utils object
|
|
238
|
+
*/
|
|
239
|
+
postprocess?: Postprocessor | Postprocessor[];
|
|
206
240
|
}
|
|
207
241
|
interface Preset<Theme extends {} = {}> extends ConfigBase<Theme> {
|
|
208
242
|
name: string;
|
|
@@ -210,7 +244,7 @@ interface Preset<Theme extends {} = {}> extends ConfigBase<Theme> {
|
|
|
210
244
|
/**
|
|
211
245
|
* Preset options for other tools like IDE to consume
|
|
212
246
|
*/
|
|
213
|
-
options?:
|
|
247
|
+
options?: PresetOptions;
|
|
214
248
|
}
|
|
215
249
|
interface GeneratorOptions {
|
|
216
250
|
/**
|
|
@@ -231,10 +265,6 @@ interface UserOnlyOptions<Theme extends {} = {}> {
|
|
|
231
265
|
* The theme object, will be merged with the theme provides by presets
|
|
232
266
|
*/
|
|
233
267
|
theme?: Theme;
|
|
234
|
-
/**
|
|
235
|
-
* Preprocess the incoming utilities, return falsy value to exclude
|
|
236
|
-
*/
|
|
237
|
-
preprocess?: (matcher: string) => string | undefined;
|
|
238
268
|
/**
|
|
239
269
|
* Layout name of shortcuts
|
|
240
270
|
*
|
|
@@ -282,9 +312,12 @@ interface UserConfigDefaults<Theme extends {} = {}> extends ConfigBase<Theme>, U
|
|
|
282
312
|
interface ResolvedConfig extends Omit<RequiredByKey<UserConfig, 'mergeSelectors' | 'theme' | 'rules' | 'variants' | 'layers' | 'extractors' | 'blocklist' | 'safelist' | 'preflights' | 'sortLayers'>, 'rules' | 'shortcuts'> {
|
|
283
313
|
shortcuts: Shortcut[];
|
|
284
314
|
variants: VariantObject[];
|
|
315
|
+
preprocess: Preprocessor[];
|
|
316
|
+
postprocess: Postprocessor[];
|
|
285
317
|
rulesSize: number;
|
|
286
318
|
rulesDynamic: (DynamicRule | undefined)[];
|
|
287
319
|
rulesStaticMap: Record<string, [number, CSSObject | CSSEntries, RuleMeta | undefined] | undefined>;
|
|
320
|
+
options: PresetOptions;
|
|
288
321
|
}
|
|
289
322
|
interface GenerateResult {
|
|
290
323
|
css: string;
|
|
@@ -317,6 +350,11 @@ declare type StringifiedUtil = readonly [
|
|
|
317
350
|
parent: string | undefined,
|
|
318
351
|
meta: RuleMeta | undefined
|
|
319
352
|
];
|
|
353
|
+
interface UtilObject {
|
|
354
|
+
selector: string;
|
|
355
|
+
entries: CSSEntries;
|
|
356
|
+
parent: string | undefined;
|
|
357
|
+
}
|
|
320
358
|
interface GenerateOptions {
|
|
321
359
|
/**
|
|
322
360
|
* Filepath of the file being processed.
|
|
@@ -409,4 +447,4 @@ declare const extractorSplit: Extractor;
|
|
|
409
447
|
|
|
410
448
|
declare const extractorSvelte: Extractor;
|
|
411
449
|
|
|
412
|
-
export { ArgumentType, Awaitable, BetterMap, BlocklistRule, CSSEntries, CSSObject, CSSValues, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, ParsedColorValue, ParsedUtil, PartialByKeys, PluginOptions, Preflight, Preset, RGBAColorValue, RawUtil, RequiredByKey, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, TwoKeyMap, UnoGenerator, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, ValueHandler, ValueHandlerCallback, Variant, VariantFunction, VariantHandler, VariantMatchedResult, VariantObject, attributifyRE, clearIdenticalEntries, createGenerator, createValueHandler, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, hex2rgba, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, toArray, uniq, validateFilterRE, warnOnce, withLayer };
|
|
450
|
+
export { ArgumentType, Awaitable, BetterMap, BlocklistRule, CSSEntries, CSSObject, CSSValues, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, ParsedColorValue, ParsedUtil, PartialByKeys, PluginOptions, Postprocessor, Preflight, Preprocessor, Preset, PresetOptions, RGBAColorValue, RawUtil, RequiredByKey, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, TwoKeyMap, UnoGenerator, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, ValueHandler, ValueHandlerCallback, Variant, VariantContext, VariantFunction, VariantHandler, VariantMatchedResult, VariantObject, attributifyRE, clearIdenticalEntries, createGenerator, createValueHandler, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, hex2rgba, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, toArray, uniq, validateFilterRE, warnOnce, withLayer };
|
package/dist/index.mjs
CHANGED
|
@@ -333,6 +333,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
333
333
|
...sortedPresets.map((p) => p.theme || {}),
|
|
334
334
|
config.theme || {}
|
|
335
335
|
].reduce((a, p) => mergeDeep(a, p), {});
|
|
336
|
+
const options = Object.assign({}, ...config.presets?.map((p) => Array.isArray(p) ? p : [p]).flat(1).map((p) => p.options ?? {}) || []);
|
|
336
337
|
return {
|
|
337
338
|
mergeSelectors: true,
|
|
338
339
|
warn: true,
|
|
@@ -348,14 +349,17 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
348
349
|
rulesSize,
|
|
349
350
|
rulesDynamic: rules,
|
|
350
351
|
rulesStaticMap,
|
|
352
|
+
preprocess: mergePresets("preprocess"),
|
|
353
|
+
postprocess: mergePresets("postprocess"),
|
|
351
354
|
preflights: mergePresets("preflights"),
|
|
352
355
|
variants: mergePresets("variants").map(normalizeVariant),
|
|
353
356
|
shortcuts: resolveShortcuts(mergePresets("shortcuts")),
|
|
354
|
-
extractors
|
|
357
|
+
extractors,
|
|
358
|
+
options
|
|
355
359
|
};
|
|
356
360
|
}
|
|
357
361
|
|
|
358
|
-
const version = "0.
|
|
362
|
+
const version = "0.20.0";
|
|
359
363
|
|
|
360
364
|
class UnoGenerator {
|
|
361
365
|
constructor(userConfig = {}, defaults = {}) {
|
|
@@ -384,7 +388,8 @@ class UnoGenerator {
|
|
|
384
388
|
return code;
|
|
385
389
|
},
|
|
386
390
|
code,
|
|
387
|
-
id
|
|
391
|
+
id,
|
|
392
|
+
options: this.config.options
|
|
388
393
|
};
|
|
389
394
|
for (const extractor of this.config.extractors) {
|
|
390
395
|
const result = await extractor.extract(context);
|
|
@@ -432,8 +437,8 @@ class UnoGenerator {
|
|
|
432
437
|
return;
|
|
433
438
|
}
|
|
434
439
|
let current = raw;
|
|
435
|
-
|
|
436
|
-
current =
|
|
440
|
+
for (const p of this.config.preprocess)
|
|
441
|
+
current = p(raw);
|
|
437
442
|
if (this.isBlocked(current))
|
|
438
443
|
return block(current);
|
|
439
444
|
const applied = this.matchVariants(raw, current);
|
|
@@ -445,7 +450,8 @@ class UnoGenerator {
|
|
|
445
450
|
theme: this.config.theme,
|
|
446
451
|
generator: this,
|
|
447
452
|
variantHandlers: applied[2],
|
|
448
|
-
constructCSS: (...args) => this.constructCustomCSS(context, ...args)
|
|
453
|
+
constructCSS: (...args) => this.constructCustomCSS(context, ...args),
|
|
454
|
+
options: this.config.options
|
|
449
455
|
};
|
|
450
456
|
const expanded = this.expandShortcut(applied[1], context);
|
|
451
457
|
if (expanded) {
|
|
@@ -470,7 +476,13 @@ class UnoGenerator {
|
|
|
470
476
|
const getLayer = (layer) => {
|
|
471
477
|
if (layerCache[layer])
|
|
472
478
|
return layerCache[layer];
|
|
473
|
-
let css = Array.from(sheet).sort((a, b) =>
|
|
479
|
+
let css = Array.from(sheet).sort((a, b) => {
|
|
480
|
+
const parentOrderA = this.parentOrders.get(a[0]);
|
|
481
|
+
const parentOrderB = this.parentOrders.get(b[0]);
|
|
482
|
+
if (parentOrderA !== void 0 && parentOrderB !== void 0)
|
|
483
|
+
return parentOrderA - parentOrderB;
|
|
484
|
+
return a[0]?.localeCompare(b[0] || "");
|
|
485
|
+
}).map(([parent, items]) => {
|
|
474
486
|
const size = items.length;
|
|
475
487
|
const sorted = items.filter((i) => (i[4]?.layer || "default") === layer).sort((a, b) => a[0] - b[0] || a[1]?.localeCompare(b[1] || "") || 0).map((a) => [a[1] ? applyScope(a[1], scope) : a[1], a[2]]);
|
|
476
488
|
if (!sorted.length)
|
|
@@ -515,12 +527,18 @@ class UnoGenerator {
|
|
|
515
527
|
const handlers = [];
|
|
516
528
|
let processed = current || raw;
|
|
517
529
|
let applied = false;
|
|
530
|
+
const context = {
|
|
531
|
+
rawSelector: raw,
|
|
532
|
+
theme: this.config.theme,
|
|
533
|
+
generator: this,
|
|
534
|
+
options: this.config.options
|
|
535
|
+
};
|
|
518
536
|
while (true) {
|
|
519
537
|
applied = false;
|
|
520
538
|
for (const v of this.config.variants) {
|
|
521
539
|
if (!v.multiPass && usedVariants.has(v))
|
|
522
540
|
continue;
|
|
523
|
-
let handler = v.match(processed,
|
|
541
|
+
let handler = v.match(processed, context);
|
|
524
542
|
if (!handler)
|
|
525
543
|
continue;
|
|
526
544
|
if (typeof handler === "string")
|
|
@@ -544,18 +562,21 @@ class UnoGenerator {
|
|
|
544
562
|
}
|
|
545
563
|
applyVariants(parsed, variantHandlers = parsed[4], raw = parsed[1]) {
|
|
546
564
|
const entries = variantHandlers.reduce((p, v) => v.body?.(p) || p, parsed[2]);
|
|
547
|
-
|
|
548
|
-
variantHandlers.reduce((p, v) => v.selector?.(p, entries) || p, toEscapedSelector(raw)),
|
|
565
|
+
const obj = {
|
|
566
|
+
selector: variantHandlers.reduce((p, v) => v.selector?.(p, entries) || p, toEscapedSelector(raw)),
|
|
549
567
|
entries,
|
|
550
|
-
variantHandlers.reduce((p, v) => Array.isArray(v.parent) ? v.parent[0] : v.parent || p, void 0)
|
|
551
|
-
|
|
568
|
+
parent: variantHandlers.reduce((p, v) => Array.isArray(v.parent) ? v.parent[0] : v.parent || p, void 0)
|
|
569
|
+
};
|
|
570
|
+
for (const p of this.config.postprocess)
|
|
571
|
+
p(obj);
|
|
572
|
+
return obj;
|
|
552
573
|
}
|
|
553
574
|
constructCustomCSS(context, body, overrideSelector) {
|
|
554
575
|
body = normalizeCSSEntries(body);
|
|
555
|
-
const
|
|
576
|
+
const { selector, entries, parent } = this.applyVariants([0, overrideSelector || context.rawSelector, body, void 0, context.variantHandlers]);
|
|
556
577
|
const cssBody = `${selector}{${entriesToCss(entries)}}`;
|
|
557
|
-
if (
|
|
558
|
-
return `${
|
|
578
|
+
if (parent)
|
|
579
|
+
return `${parent}{${cssBody}}`;
|
|
559
580
|
return cssBody;
|
|
560
581
|
}
|
|
561
582
|
async parseUtil(input, context, internal = false) {
|
|
@@ -592,11 +613,11 @@ class UnoGenerator {
|
|
|
592
613
|
return;
|
|
593
614
|
if (isRawUtil(parsed))
|
|
594
615
|
return [parsed[0], void 0, parsed[1], void 0, parsed[2]];
|
|
595
|
-
const
|
|
616
|
+
const { selector, entries, parent } = this.applyVariants(parsed);
|
|
596
617
|
const body = entriesToCss(entries);
|
|
597
618
|
if (!body)
|
|
598
619
|
return;
|
|
599
|
-
return [parsed[0], selector, body,
|
|
620
|
+
return [parsed[0], selector, body, parent, parsed[3]];
|
|
600
621
|
}
|
|
601
622
|
expandShortcut(processed, context, depth = 3) {
|
|
602
623
|
if (depth === 0)
|
|
@@ -641,8 +662,8 @@ class UnoGenerator {
|
|
|
641
662
|
for (const item of parsed) {
|
|
642
663
|
if (isRawUtil(item))
|
|
643
664
|
continue;
|
|
644
|
-
const
|
|
645
|
-
const mapItem = selectorMap.getFallback(selector,
|
|
665
|
+
const { selector, entries, parent: parent2 } = this.applyVariants(item, [...item[4], ...parentVariants], raw);
|
|
666
|
+
const mapItem = selectorMap.getFallback(selector, parent2, [[], item[0]]);
|
|
646
667
|
mapItem[0].push(...entries);
|
|
647
668
|
if (item[0] > mapItem[1])
|
|
648
669
|
mapItem[1] = item[0];
|