@unocss/core 0.20.0 → 0.21.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 +11 -22
- package/dist/index.d.ts +9 -11
- package/dist/index.mjs +11 -22
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -249,7 +249,6 @@ function createValueHandler(handlers) {
|
|
|
249
249
|
if (res != null)
|
|
250
250
|
return res;
|
|
251
251
|
}
|
|
252
|
-
return void 0;
|
|
253
252
|
};
|
|
254
253
|
function addProcessor(that, name) {
|
|
255
254
|
if (!that.__options) {
|
|
@@ -337,7 +336,6 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
337
336
|
...sortedPresets.map((p) => p.theme || {}),
|
|
338
337
|
config.theme || {}
|
|
339
338
|
].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 ?? {}) || []);
|
|
341
339
|
return {
|
|
342
340
|
mergeSelectors: true,
|
|
343
341
|
warn: true,
|
|
@@ -358,12 +356,11 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
358
356
|
preflights: mergePresets("preflights"),
|
|
359
357
|
variants: mergePresets("variants").map(normalizeVariant),
|
|
360
358
|
shortcuts: resolveShortcuts(mergePresets("shortcuts")),
|
|
361
|
-
extractors
|
|
362
|
-
options
|
|
359
|
+
extractors
|
|
363
360
|
};
|
|
364
361
|
}
|
|
365
362
|
|
|
366
|
-
const version = "0.
|
|
363
|
+
const version = "0.21.0";
|
|
367
364
|
|
|
368
365
|
class UnoGenerator {
|
|
369
366
|
constructor(userConfig = {}, defaults = {}) {
|
|
@@ -392,8 +389,7 @@ class UnoGenerator {
|
|
|
392
389
|
return code;
|
|
393
390
|
},
|
|
394
391
|
code,
|
|
395
|
-
id
|
|
396
|
-
options: this.config.options
|
|
392
|
+
id
|
|
397
393
|
};
|
|
398
394
|
for (const extractor of this.config.extractors) {
|
|
399
395
|
const result = await extractor.extract(context);
|
|
@@ -454,8 +450,7 @@ class UnoGenerator {
|
|
|
454
450
|
theme: this.config.theme,
|
|
455
451
|
generator: this,
|
|
456
452
|
variantHandlers: applied[2],
|
|
457
|
-
constructCSS: (...args) => this.constructCustomCSS(context, ...args)
|
|
458
|
-
options: this.config.options
|
|
453
|
+
constructCSS: (...args) => this.constructCustomCSS(context, ...args)
|
|
459
454
|
};
|
|
460
455
|
const expanded = this.expandShortcut(applied[1], context);
|
|
461
456
|
if (expanded) {
|
|
@@ -480,13 +475,7 @@ class UnoGenerator {
|
|
|
480
475
|
const getLayer = (layer) => {
|
|
481
476
|
if (layerCache[layer])
|
|
482
477
|
return layerCache[layer];
|
|
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
|
+
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]) => {
|
|
490
479
|
const size = items.length;
|
|
491
480
|
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]]);
|
|
492
481
|
if (!sorted.length)
|
|
@@ -496,7 +485,7 @@ class UnoGenerator {
|
|
|
496
485
|
for (let i = idx + 1; i < size; i++) {
|
|
497
486
|
const current = sorted[i];
|
|
498
487
|
if (current && current[0] && current[1] === body) {
|
|
499
|
-
current[0] = `${current[0]},${selector}`;
|
|
488
|
+
current[0] = `${current[0]},${nl}${selector}`;
|
|
500
489
|
return null;
|
|
501
490
|
}
|
|
502
491
|
}
|
|
@@ -534,8 +523,7 @@ class UnoGenerator {
|
|
|
534
523
|
const context = {
|
|
535
524
|
rawSelector: raw,
|
|
536
525
|
theme: this.config.theme,
|
|
537
|
-
generator: this
|
|
538
|
-
options: this.config.options
|
|
526
|
+
generator: this
|
|
539
527
|
};
|
|
540
528
|
while (true) {
|
|
541
529
|
applied = false;
|
|
@@ -565,11 +553,12 @@ class UnoGenerator {
|
|
|
565
553
|
return [raw, processed, handlers];
|
|
566
554
|
}
|
|
567
555
|
applyVariants(parsed, variantHandlers = parsed[4], raw = parsed[1]) {
|
|
568
|
-
const
|
|
556
|
+
const handlers = [...variantHandlers].sort((a, b) => (a.order || 0) - (b.order || 0));
|
|
557
|
+
const entries = handlers.reduce((p, v) => v.body?.(p) || p, parsed[2]);
|
|
569
558
|
const obj = {
|
|
570
|
-
selector:
|
|
559
|
+
selector: handlers.reduce((p, v) => v.selector?.(p, entries) || p, toEscapedSelector(raw)),
|
|
571
560
|
entries,
|
|
572
|
-
parent:
|
|
561
|
+
parent: handlers.reduce((p, v) => Array.isArray(v.parent) ? v.parent[0] : v.parent || p, void 0)
|
|
573
562
|
};
|
|
574
563
|
for (const p of this.config.postprocess)
|
|
575
564
|
p(obj);
|
package/dist/index.d.ts
CHANGED
|
@@ -51,13 +51,17 @@ declare type ParsedColorValue = {
|
|
|
51
51
|
*/
|
|
52
52
|
name: string;
|
|
53
53
|
/**
|
|
54
|
-
* Color scale
|
|
54
|
+
* Color scale, preferrably 000 - 999.
|
|
55
55
|
*/
|
|
56
56
|
no: string;
|
|
57
57
|
/**
|
|
58
58
|
* {@link RGBAColorValue}
|
|
59
59
|
*/
|
|
60
60
|
rgba?: RGBAColorValue;
|
|
61
|
+
/**
|
|
62
|
+
* Parsed rgba's alpha value.
|
|
63
|
+
*/
|
|
64
|
+
alpha?: number | string;
|
|
61
65
|
};
|
|
62
66
|
declare type PresetOptions = Record<string, any>;
|
|
63
67
|
interface RuleContext<Theme extends {} = {}> {
|
|
@@ -87,10 +91,6 @@ interface RuleContext<Theme extends {} = {}> {
|
|
|
87
91
|
* Variants and selector escaping will be handled automatically.
|
|
88
92
|
*/
|
|
89
93
|
constructCSS: (body: CSSEntries | CSSObject, overrideSelector?: string) => string;
|
|
90
|
-
/**
|
|
91
|
-
* User-provided options from preset.
|
|
92
|
-
*/
|
|
93
|
-
readonly options: PresetOptions;
|
|
94
94
|
}
|
|
95
95
|
interface VariantContext<Theme extends {} = {}> {
|
|
96
96
|
/**
|
|
@@ -105,16 +105,11 @@ interface VariantContext<Theme extends {} = {}> {
|
|
|
105
105
|
* The theme object
|
|
106
106
|
*/
|
|
107
107
|
theme: Theme;
|
|
108
|
-
/**
|
|
109
|
-
* User-provided options from preset.
|
|
110
|
-
*/
|
|
111
|
-
readonly options: PresetOptions;
|
|
112
108
|
}
|
|
113
109
|
interface ExtractorContext {
|
|
114
110
|
readonly original: string;
|
|
115
111
|
code: string;
|
|
116
112
|
id?: string;
|
|
117
|
-
readonly options: PresetOptions;
|
|
118
113
|
}
|
|
119
114
|
interface Extractor {
|
|
120
115
|
name: string;
|
|
@@ -167,6 +162,10 @@ interface VariantHandler {
|
|
|
167
162
|
* Provide a parent selector(e.g. media query) to the output css.
|
|
168
163
|
*/
|
|
169
164
|
parent?: string | [string, number] | undefined;
|
|
165
|
+
/**
|
|
166
|
+
* Variant ordering.
|
|
167
|
+
*/
|
|
168
|
+
order?: number;
|
|
170
169
|
}
|
|
171
170
|
declare type VariantFunction<Theme extends {} = {}> = (matcher: string, context: Readonly<VariantContext<Theme>>) => string | VariantHandler | undefined;
|
|
172
171
|
declare type VariantObject<Theme extends {} = {}> = {
|
|
@@ -317,7 +316,6 @@ interface ResolvedConfig extends Omit<RequiredByKey<UserConfig, 'mergeSelectors'
|
|
|
317
316
|
rulesSize: number;
|
|
318
317
|
rulesDynamic: (DynamicRule | undefined)[];
|
|
319
318
|
rulesStaticMap: Record<string, [number, CSSObject | CSSEntries, RuleMeta | undefined] | undefined>;
|
|
320
|
-
options: PresetOptions;
|
|
321
319
|
}
|
|
322
320
|
interface GenerateResult {
|
|
323
321
|
css: string;
|
package/dist/index.mjs
CHANGED
|
@@ -245,7 +245,6 @@ function createValueHandler(handlers) {
|
|
|
245
245
|
if (res != null)
|
|
246
246
|
return res;
|
|
247
247
|
}
|
|
248
|
-
return void 0;
|
|
249
248
|
};
|
|
250
249
|
function addProcessor(that, name) {
|
|
251
250
|
if (!that.__options) {
|
|
@@ -333,7 +332,6 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
333
332
|
...sortedPresets.map((p) => p.theme || {}),
|
|
334
333
|
config.theme || {}
|
|
335
334
|
].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 ?? {}) || []);
|
|
337
335
|
return {
|
|
338
336
|
mergeSelectors: true,
|
|
339
337
|
warn: true,
|
|
@@ -354,12 +352,11 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
354
352
|
preflights: mergePresets("preflights"),
|
|
355
353
|
variants: mergePresets("variants").map(normalizeVariant),
|
|
356
354
|
shortcuts: resolveShortcuts(mergePresets("shortcuts")),
|
|
357
|
-
extractors
|
|
358
|
-
options
|
|
355
|
+
extractors
|
|
359
356
|
};
|
|
360
357
|
}
|
|
361
358
|
|
|
362
|
-
const version = "0.
|
|
359
|
+
const version = "0.21.0";
|
|
363
360
|
|
|
364
361
|
class UnoGenerator {
|
|
365
362
|
constructor(userConfig = {}, defaults = {}) {
|
|
@@ -388,8 +385,7 @@ class UnoGenerator {
|
|
|
388
385
|
return code;
|
|
389
386
|
},
|
|
390
387
|
code,
|
|
391
|
-
id
|
|
392
|
-
options: this.config.options
|
|
388
|
+
id
|
|
393
389
|
};
|
|
394
390
|
for (const extractor of this.config.extractors) {
|
|
395
391
|
const result = await extractor.extract(context);
|
|
@@ -450,8 +446,7 @@ class UnoGenerator {
|
|
|
450
446
|
theme: this.config.theme,
|
|
451
447
|
generator: this,
|
|
452
448
|
variantHandlers: applied[2],
|
|
453
|
-
constructCSS: (...args) => this.constructCustomCSS(context, ...args)
|
|
454
|
-
options: this.config.options
|
|
449
|
+
constructCSS: (...args) => this.constructCustomCSS(context, ...args)
|
|
455
450
|
};
|
|
456
451
|
const expanded = this.expandShortcut(applied[1], context);
|
|
457
452
|
if (expanded) {
|
|
@@ -476,13 +471,7 @@ class UnoGenerator {
|
|
|
476
471
|
const getLayer = (layer) => {
|
|
477
472
|
if (layerCache[layer])
|
|
478
473
|
return layerCache[layer];
|
|
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
|
+
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]) => {
|
|
486
475
|
const size = items.length;
|
|
487
476
|
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]]);
|
|
488
477
|
if (!sorted.length)
|
|
@@ -492,7 +481,7 @@ class UnoGenerator {
|
|
|
492
481
|
for (let i = idx + 1; i < size; i++) {
|
|
493
482
|
const current = sorted[i];
|
|
494
483
|
if (current && current[0] && current[1] === body) {
|
|
495
|
-
current[0] = `${current[0]},${selector}`;
|
|
484
|
+
current[0] = `${current[0]},${nl}${selector}`;
|
|
496
485
|
return null;
|
|
497
486
|
}
|
|
498
487
|
}
|
|
@@ -530,8 +519,7 @@ class UnoGenerator {
|
|
|
530
519
|
const context = {
|
|
531
520
|
rawSelector: raw,
|
|
532
521
|
theme: this.config.theme,
|
|
533
|
-
generator: this
|
|
534
|
-
options: this.config.options
|
|
522
|
+
generator: this
|
|
535
523
|
};
|
|
536
524
|
while (true) {
|
|
537
525
|
applied = false;
|
|
@@ -561,11 +549,12 @@ class UnoGenerator {
|
|
|
561
549
|
return [raw, processed, handlers];
|
|
562
550
|
}
|
|
563
551
|
applyVariants(parsed, variantHandlers = parsed[4], raw = parsed[1]) {
|
|
564
|
-
const
|
|
552
|
+
const handlers = [...variantHandlers].sort((a, b) => (a.order || 0) - (b.order || 0));
|
|
553
|
+
const entries = handlers.reduce((p, v) => v.body?.(p) || p, parsed[2]);
|
|
565
554
|
const obj = {
|
|
566
|
-
selector:
|
|
555
|
+
selector: handlers.reduce((p, v) => v.selector?.(p, entries) || p, toEscapedSelector(raw)),
|
|
567
556
|
entries,
|
|
568
|
-
parent:
|
|
557
|
+
parent: handlers.reduce((p, v) => Array.isArray(v.parent) ? v.parent[0] : v.parent || p, void 0)
|
|
569
558
|
};
|
|
570
559
|
for (const p of this.config.postprocess)
|
|
571
560
|
p(obj);
|