@unocss/core 0.11.3 → 0.12.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.ts +17 -7
- package/dist/index.js +31 -21
- package/dist/index.mjs +31 -21
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
declare class UnoGenerator {
|
|
2
2
|
userConfig: UserConfig;
|
|
3
3
|
defaults: UserConfigDefaults;
|
|
4
|
+
version: string;
|
|
4
5
|
private _cache;
|
|
5
6
|
config: ResolvedConfig;
|
|
6
7
|
blocked: Set<string>;
|
|
@@ -12,10 +13,10 @@ declare class UnoGenerator {
|
|
|
12
13
|
matchVariants(raw: string, current?: string): VariantMatchedResult;
|
|
13
14
|
applyVariants(parsed: ParsedUtil, variantHandlers?: VariantHandler[], raw?: string): readonly [string, CSSEntries, string | undefined];
|
|
14
15
|
constructCustomCSS(context: Readonly<RuleContext>, body: CSSObject | CSSEntries, overrideSelector?: string): string;
|
|
15
|
-
parseUtil(input: string | VariantMatchedResult): Promise<ParsedUtil | RawUtil | undefined>;
|
|
16
|
+
parseUtil(input: string | VariantMatchedResult, context: RuleContext, internal?: boolean): Promise<ParsedUtil | RawUtil | undefined>;
|
|
16
17
|
stringifyUtil(parsed?: ParsedUtil | RawUtil): StringifiedUtil | undefined;
|
|
17
|
-
expandShortcut(processed: string, depth?: number): [string[], RuleMeta | undefined] | undefined;
|
|
18
|
-
stringifyShortcuts(parent: VariantMatchedResult, expanded: string[], meta?: RuleMeta): Promise<StringifiedUtil[] | undefined>;
|
|
18
|
+
expandShortcut(processed: string, context: RuleContext, depth?: number): [string[], RuleMeta | undefined] | undefined;
|
|
19
|
+
stringifyShortcuts(parent: VariantMatchedResult, context: RuleContext, expanded: string[], meta?: RuleMeta): Promise<StringifiedUtil[] | undefined>;
|
|
19
20
|
isBlocked(raw: string): boolean;
|
|
20
21
|
}
|
|
21
22
|
declare function createGenerator(config?: UserConfig, defaults?: UserConfigDefaults): UnoGenerator;
|
|
@@ -73,18 +74,27 @@ interface Extractor {
|
|
|
73
74
|
order?: number;
|
|
74
75
|
}
|
|
75
76
|
interface RuleMeta {
|
|
77
|
+
/**
|
|
78
|
+
* The layer name of this rule.
|
|
79
|
+
* @default 'default'
|
|
80
|
+
*/
|
|
76
81
|
layer?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Internal rules will only be matched for shortcuts but not the user code.
|
|
84
|
+
* @default false
|
|
85
|
+
*/
|
|
86
|
+
internal?: boolean;
|
|
77
87
|
}
|
|
78
88
|
declare type DynamicMatcher<Theme extends {} = {}> = ((match: string[], context: Readonly<RuleContext<Theme>>) => Awaitable<CSSObject | CSSEntries | string | undefined>);
|
|
79
89
|
declare type DynamicRule<Theme extends {} = {}> = [RegExp, DynamicMatcher<Theme>] | [RegExp, DynamicMatcher<Theme>, RuleMeta];
|
|
80
90
|
declare type StaticRule = [string, CSSObject | CSSEntries] | [string, CSSObject | CSSEntries, RuleMeta];
|
|
81
91
|
declare type Rule<Theme extends {} = {}> = DynamicRule<Theme> | StaticRule;
|
|
82
|
-
declare type DynamicShortcutMatcher = ((match: string[]) => (string | string[] | undefined));
|
|
83
|
-
declare type DynamicShortcut = [RegExp, DynamicShortcutMatcher] | [RegExp, DynamicShortcutMatcher, RuleMeta];
|
|
92
|
+
declare type DynamicShortcutMatcher<Theme extends {} = {}> = ((match: string[], context: Readonly<RuleContext<Theme>>) => (string | string[] | undefined));
|
|
84
93
|
declare type StaticShortcut = [string, string | string[]] | [string, string | string[], RuleMeta];
|
|
85
94
|
declare type StaticShortcutMap = Record<string, string | string[]>;
|
|
86
|
-
declare type
|
|
87
|
-
declare type
|
|
95
|
+
declare type DynamicShortcut<Theme extends {} = {}> = [RegExp, DynamicShortcutMatcher<Theme>] | [RegExp, DynamicShortcutMatcher<Theme>, RuleMeta];
|
|
96
|
+
declare type UserShortcuts<Theme extends {} = {}> = StaticShortcutMap | (StaticShortcut | DynamicShortcut<Theme> | StaticShortcutMap)[];
|
|
97
|
+
declare type Shortcut<Theme extends {} = {}> = StaticShortcut | DynamicShortcut<Theme>;
|
|
88
98
|
interface Preflight {
|
|
89
99
|
getCSS: () => string | undefined;
|
|
90
100
|
layer?: string;
|
package/dist/index.js
CHANGED
|
@@ -304,11 +304,15 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
304
304
|
};
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
+
// package.json
|
|
308
|
+
var version = "0.12.0";
|
|
309
|
+
|
|
307
310
|
// src/generator/index.ts
|
|
308
311
|
var UnoGenerator = class {
|
|
309
312
|
constructor(userConfig = {}, defaults = {}) {
|
|
310
313
|
this.userConfig = userConfig;
|
|
311
314
|
this.defaults = defaults;
|
|
315
|
+
this.version = version;
|
|
312
316
|
this._cache = new Map();
|
|
313
317
|
this.blocked = new Set();
|
|
314
318
|
this.parentOrders = new Map();
|
|
@@ -387,13 +391,21 @@ var UnoGenerator = class {
|
|
|
387
391
|
const applied = this.matchVariants(raw, current);
|
|
388
392
|
if (!applied || this.isBlocked(applied[1]))
|
|
389
393
|
return block(raw);
|
|
390
|
-
const
|
|
394
|
+
const context = {
|
|
395
|
+
rawSelector: raw,
|
|
396
|
+
currentSelector: applied[1],
|
|
397
|
+
theme: this.config.theme,
|
|
398
|
+
generator: this,
|
|
399
|
+
variantHandlers: applied[2],
|
|
400
|
+
constructCSS: (...args) => this.constructCustomCSS(context, ...args)
|
|
401
|
+
};
|
|
402
|
+
const expanded = this.expandShortcut(applied[1], context);
|
|
391
403
|
if (expanded) {
|
|
392
|
-
const utils = await this.stringifyShortcuts(applied, expanded[0], expanded[1]);
|
|
404
|
+
const utils = await this.stringifyShortcuts(applied, context, expanded[0], expanded[1]);
|
|
393
405
|
if (utils == null ? void 0 : utils.length)
|
|
394
406
|
return hit(raw, utils);
|
|
395
407
|
} else {
|
|
396
|
-
const util = this.stringifyUtil(await this.parseUtil(applied));
|
|
408
|
+
const util = this.stringifyUtil(await this.parseUtil(applied, context));
|
|
397
409
|
if (util)
|
|
398
410
|
return hit(raw, [util]);
|
|
399
411
|
}
|
|
@@ -512,24 +524,22 @@ var UnoGenerator = class {
|
|
|
512
524
|
return `${mediaQuery}{${cssBody}}`;
|
|
513
525
|
return cssBody;
|
|
514
526
|
}
|
|
515
|
-
async parseUtil(input) {
|
|
516
|
-
|
|
527
|
+
async parseUtil(input, context, internal = false) {
|
|
528
|
+
var _a, _b;
|
|
517
529
|
const [raw, processed, variantHandlers] = typeof input === "string" ? this.matchVariants(input) : input;
|
|
518
|
-
const staticMatch = rulesStaticMap[processed];
|
|
519
|
-
if (staticMatch
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
generator: this,
|
|
526
|
-
variantHandlers,
|
|
527
|
-
constructCSS: (...args) => this.constructCustomCSS(context, ...args)
|
|
528
|
-
};
|
|
530
|
+
const staticMatch = this.config.rulesStaticMap[processed];
|
|
531
|
+
if (staticMatch) {
|
|
532
|
+
if (staticMatch[1] && (internal || !((_a = staticMatch[2]) == null ? void 0 : _a.internal)))
|
|
533
|
+
return [staticMatch[0], raw, normalizeEntries(staticMatch[1]), staticMatch[2], variantHandlers];
|
|
534
|
+
}
|
|
535
|
+
context.variantHandlers = variantHandlers;
|
|
536
|
+
const { rulesDynamic, rulesSize } = this.config;
|
|
529
537
|
for (let i = rulesSize; i >= 0; i--) {
|
|
530
538
|
const rule = rulesDynamic[i];
|
|
531
539
|
if (!rule)
|
|
532
540
|
continue;
|
|
541
|
+
if (((_b = rule[2]) == null ? void 0 : _b.internal) && !internal)
|
|
542
|
+
continue;
|
|
533
543
|
const [matcher, handler, meta] = rule;
|
|
534
544
|
const match = processed.match(matcher);
|
|
535
545
|
if (!match)
|
|
@@ -555,7 +565,7 @@ var UnoGenerator = class {
|
|
|
555
565
|
return;
|
|
556
566
|
return [parsed[0], selector, body, mediaQuery, parsed[3]];
|
|
557
567
|
}
|
|
558
|
-
expandShortcut(processed, depth = 3) {
|
|
568
|
+
expandShortcut(processed, context, depth = 3) {
|
|
559
569
|
if (depth === 0)
|
|
560
570
|
return;
|
|
561
571
|
let meta;
|
|
@@ -570,7 +580,7 @@ var UnoGenerator = class {
|
|
|
570
580
|
} else {
|
|
571
581
|
const match = processed.match(s[0]);
|
|
572
582
|
if (match)
|
|
573
|
-
result = s[1](match);
|
|
583
|
+
result = s[1](match, context);
|
|
574
584
|
if (result) {
|
|
575
585
|
meta = meta || s[2];
|
|
576
586
|
break;
|
|
@@ -584,14 +594,14 @@ var UnoGenerator = class {
|
|
|
584
594
|
return [
|
|
585
595
|
result.flatMap((r) => {
|
|
586
596
|
var _a;
|
|
587
|
-
return ((_a = this.expandShortcut(r, depth - 1)) == null ? void 0 : _a[0]) || [r];
|
|
597
|
+
return ((_a = this.expandShortcut(r, context, depth - 1)) == null ? void 0 : _a[0]) || [r];
|
|
588
598
|
}),
|
|
589
599
|
meta
|
|
590
600
|
];
|
|
591
601
|
}
|
|
592
|
-
async stringifyShortcuts(parent, expanded, meta = { layer: this.config.shortcutsLayer }) {
|
|
602
|
+
async stringifyShortcuts(parent, context, expanded, meta = { layer: this.config.shortcutsLayer }) {
|
|
593
603
|
const selectorMap = new TwoKeyMap();
|
|
594
|
-
const parsed = (await Promise.all(uniq(expanded).map((i) => this.parseUtil(i)))).filter(Boolean).sort((a, b) => a[0] - b[0]);
|
|
604
|
+
const parsed = (await Promise.all(uniq(expanded).map((i) => this.parseUtil(i, context, true)))).filter(Boolean).sort((a, b) => a[0] - b[0]);
|
|
595
605
|
const [raw, , parentVariants] = parent;
|
|
596
606
|
for (const item of parsed) {
|
|
597
607
|
if (isRawUtil(item))
|
package/dist/index.mjs
CHANGED
|
@@ -267,11 +267,15 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
267
267
|
};
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
+
// package.json
|
|
271
|
+
var version = "0.12.0";
|
|
272
|
+
|
|
270
273
|
// src/generator/index.ts
|
|
271
274
|
var UnoGenerator = class {
|
|
272
275
|
constructor(userConfig = {}, defaults = {}) {
|
|
273
276
|
this.userConfig = userConfig;
|
|
274
277
|
this.defaults = defaults;
|
|
278
|
+
this.version = version;
|
|
275
279
|
this._cache = new Map();
|
|
276
280
|
this.blocked = new Set();
|
|
277
281
|
this.parentOrders = new Map();
|
|
@@ -350,13 +354,21 @@ var UnoGenerator = class {
|
|
|
350
354
|
const applied = this.matchVariants(raw, current);
|
|
351
355
|
if (!applied || this.isBlocked(applied[1]))
|
|
352
356
|
return block(raw);
|
|
353
|
-
const
|
|
357
|
+
const context = {
|
|
358
|
+
rawSelector: raw,
|
|
359
|
+
currentSelector: applied[1],
|
|
360
|
+
theme: this.config.theme,
|
|
361
|
+
generator: this,
|
|
362
|
+
variantHandlers: applied[2],
|
|
363
|
+
constructCSS: (...args) => this.constructCustomCSS(context, ...args)
|
|
364
|
+
};
|
|
365
|
+
const expanded = this.expandShortcut(applied[1], context);
|
|
354
366
|
if (expanded) {
|
|
355
|
-
const utils = await this.stringifyShortcuts(applied, expanded[0], expanded[1]);
|
|
367
|
+
const utils = await this.stringifyShortcuts(applied, context, expanded[0], expanded[1]);
|
|
356
368
|
if (utils == null ? void 0 : utils.length)
|
|
357
369
|
return hit(raw, utils);
|
|
358
370
|
} else {
|
|
359
|
-
const util = this.stringifyUtil(await this.parseUtil(applied));
|
|
371
|
+
const util = this.stringifyUtil(await this.parseUtil(applied, context));
|
|
360
372
|
if (util)
|
|
361
373
|
return hit(raw, [util]);
|
|
362
374
|
}
|
|
@@ -475,24 +487,22 @@ var UnoGenerator = class {
|
|
|
475
487
|
return `${mediaQuery}{${cssBody}}`;
|
|
476
488
|
return cssBody;
|
|
477
489
|
}
|
|
478
|
-
async parseUtil(input) {
|
|
479
|
-
|
|
490
|
+
async parseUtil(input, context, internal = false) {
|
|
491
|
+
var _a, _b;
|
|
480
492
|
const [raw, processed, variantHandlers] = typeof input === "string" ? this.matchVariants(input) : input;
|
|
481
|
-
const staticMatch = rulesStaticMap[processed];
|
|
482
|
-
if (staticMatch
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
generator: this,
|
|
489
|
-
variantHandlers,
|
|
490
|
-
constructCSS: (...args) => this.constructCustomCSS(context, ...args)
|
|
491
|
-
};
|
|
493
|
+
const staticMatch = this.config.rulesStaticMap[processed];
|
|
494
|
+
if (staticMatch) {
|
|
495
|
+
if (staticMatch[1] && (internal || !((_a = staticMatch[2]) == null ? void 0 : _a.internal)))
|
|
496
|
+
return [staticMatch[0], raw, normalizeEntries(staticMatch[1]), staticMatch[2], variantHandlers];
|
|
497
|
+
}
|
|
498
|
+
context.variantHandlers = variantHandlers;
|
|
499
|
+
const { rulesDynamic, rulesSize } = this.config;
|
|
492
500
|
for (let i = rulesSize; i >= 0; i--) {
|
|
493
501
|
const rule = rulesDynamic[i];
|
|
494
502
|
if (!rule)
|
|
495
503
|
continue;
|
|
504
|
+
if (((_b = rule[2]) == null ? void 0 : _b.internal) && !internal)
|
|
505
|
+
continue;
|
|
496
506
|
const [matcher, handler, meta] = rule;
|
|
497
507
|
const match = processed.match(matcher);
|
|
498
508
|
if (!match)
|
|
@@ -518,7 +528,7 @@ var UnoGenerator = class {
|
|
|
518
528
|
return;
|
|
519
529
|
return [parsed[0], selector, body, mediaQuery, parsed[3]];
|
|
520
530
|
}
|
|
521
|
-
expandShortcut(processed, depth = 3) {
|
|
531
|
+
expandShortcut(processed, context, depth = 3) {
|
|
522
532
|
if (depth === 0)
|
|
523
533
|
return;
|
|
524
534
|
let meta;
|
|
@@ -533,7 +543,7 @@ var UnoGenerator = class {
|
|
|
533
543
|
} else {
|
|
534
544
|
const match = processed.match(s[0]);
|
|
535
545
|
if (match)
|
|
536
|
-
result = s[1](match);
|
|
546
|
+
result = s[1](match, context);
|
|
537
547
|
if (result) {
|
|
538
548
|
meta = meta || s[2];
|
|
539
549
|
break;
|
|
@@ -547,14 +557,14 @@ var UnoGenerator = class {
|
|
|
547
557
|
return [
|
|
548
558
|
result.flatMap((r) => {
|
|
549
559
|
var _a;
|
|
550
|
-
return ((_a = this.expandShortcut(r, depth - 1)) == null ? void 0 : _a[0]) || [r];
|
|
560
|
+
return ((_a = this.expandShortcut(r, context, depth - 1)) == null ? void 0 : _a[0]) || [r];
|
|
551
561
|
}),
|
|
552
562
|
meta
|
|
553
563
|
];
|
|
554
564
|
}
|
|
555
|
-
async stringifyShortcuts(parent, expanded, meta = { layer: this.config.shortcutsLayer }) {
|
|
565
|
+
async stringifyShortcuts(parent, context, expanded, meta = { layer: this.config.shortcutsLayer }) {
|
|
556
566
|
const selectorMap = new TwoKeyMap();
|
|
557
|
-
const parsed = (await Promise.all(uniq(expanded).map((i) => this.parseUtil(i)))).filter(Boolean).sort((a, b) => a[0] - b[0]);
|
|
567
|
+
const parsed = (await Promise.all(uniq(expanded).map((i) => this.parseUtil(i, context, true)))).filter(Boolean).sort((a, b) => a[0] - b[0]);
|
|
558
568
|
const [raw, , parentVariants] = parent;
|
|
559
569
|
for (const item of parsed) {
|
|
560
570
|
if (isRawUtil(item))
|