@unocss/core 0.22.6 → 0.24.1
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/README.md +1 -1
- package/dist/index.cjs +62 -71
- package/dist/index.d.ts +26 -8
- package/dist/index.mjs +63 -71
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @unocss/core
|
|
2
2
|
|
|
3
|
-
The core engine of [UnoCSS](https://github.com/
|
|
3
|
+
The core engine of [UnoCSS](https://github.com/unocss/unocss) without any presets. It can be used as the engine of your own atomic CSS framework.
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
package/dist/index.cjs
CHANGED
|
@@ -137,28 +137,6 @@ function mergeSet(target, append) {
|
|
|
137
137
|
return target;
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
const hexRE = /^#?([\da-f]+)$/i;
|
|
141
|
-
function hex2rgba(hex = "") {
|
|
142
|
-
const [, body] = hex.match(hexRE) || [];
|
|
143
|
-
if (!body)
|
|
144
|
-
return;
|
|
145
|
-
switch (body.length) {
|
|
146
|
-
case 3:
|
|
147
|
-
case 4:
|
|
148
|
-
const digits = Array.from(body, (s) => Number.parseInt(s, 16)).map((n) => n << 4 | n);
|
|
149
|
-
if (body.length === 3)
|
|
150
|
-
return digits;
|
|
151
|
-
digits[3] = Math.round(digits[3] / 255 * 100) / 100;
|
|
152
|
-
return digits;
|
|
153
|
-
case 6:
|
|
154
|
-
case 8:
|
|
155
|
-
const value = Number.parseInt(body, 16);
|
|
156
|
-
if (body.length === 6)
|
|
157
|
-
return [value >> 16 & 255, value >> 8 & 255, value & 255];
|
|
158
|
-
return [value >> 24 & 255, value >> 16 & 255, value >> 8 & 255, Math.round((value & 255) / 255 * 100) / 100];
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
140
|
const attributifyRE = /^\[(.+?)~?="(.*)"\]$/;
|
|
163
141
|
const validateFilterRE = /(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-?]/;
|
|
164
142
|
const CONTROL_SHORTCUT_NO_MERGE = "$$shortcut-no-merge";
|
|
@@ -388,7 +366,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
388
366
|
};
|
|
389
367
|
}
|
|
390
368
|
|
|
391
|
-
const version = "0.
|
|
369
|
+
const version = "0.24.1";
|
|
392
370
|
|
|
393
371
|
class UnoGenerator {
|
|
394
372
|
constructor(userConfig = {}, defaults = {}) {
|
|
@@ -425,6 +403,49 @@ class UnoGenerator {
|
|
|
425
403
|
}
|
|
426
404
|
return set;
|
|
427
405
|
}
|
|
406
|
+
async parseToken(raw) {
|
|
407
|
+
if (this.blocked.has(raw))
|
|
408
|
+
return;
|
|
409
|
+
if (this._cache.has(raw))
|
|
410
|
+
return this._cache.get(raw);
|
|
411
|
+
let current = raw;
|
|
412
|
+
for (const p of this.config.preprocess)
|
|
413
|
+
current = p(raw);
|
|
414
|
+
if (this.isBlocked(current)) {
|
|
415
|
+
this.blocked.add(raw);
|
|
416
|
+
this._cache.set(raw, null);
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
const applied = this.matchVariants(raw, current);
|
|
420
|
+
if (!applied || this.isBlocked(applied[1])) {
|
|
421
|
+
this.blocked.add(raw);
|
|
422
|
+
this._cache.set(raw, null);
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
const context = {
|
|
426
|
+
rawSelector: raw,
|
|
427
|
+
currentSelector: applied[1],
|
|
428
|
+
theme: this.config.theme,
|
|
429
|
+
generator: this,
|
|
430
|
+
variantHandlers: applied[2],
|
|
431
|
+
constructCSS: (...args) => this.constructCustomCSS(context, ...args)
|
|
432
|
+
};
|
|
433
|
+
const expanded = this.expandShortcut(applied[1], context);
|
|
434
|
+
if (expanded) {
|
|
435
|
+
const utils = await this.stringifyShortcuts(applied, context, expanded[0], expanded[1]);
|
|
436
|
+
if (utils?.length) {
|
|
437
|
+
this._cache.set(raw, utils);
|
|
438
|
+
return utils;
|
|
439
|
+
}
|
|
440
|
+
} else {
|
|
441
|
+
const utils = (await this.parseUtil(applied, context))?.map((i) => this.stringifyUtil(i)).filter(notNull);
|
|
442
|
+
if (utils?.length) {
|
|
443
|
+
this._cache.set(raw, utils);
|
|
444
|
+
return utils;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
this._cache.set(raw, null);
|
|
448
|
+
}
|
|
428
449
|
async generate(input, {
|
|
429
450
|
id,
|
|
430
451
|
scope,
|
|
@@ -439,8 +460,12 @@ class UnoGenerator {
|
|
|
439
460
|
const layerSet = /* @__PURE__ */ new Set(["default"]);
|
|
440
461
|
const matched = /* @__PURE__ */ new Set();
|
|
441
462
|
const sheet = /* @__PURE__ */ new Map();
|
|
442
|
-
|
|
443
|
-
|
|
463
|
+
await Promise.all(Array.from(tokens).map(async (raw) => {
|
|
464
|
+
if (matched.has(raw))
|
|
465
|
+
return;
|
|
466
|
+
const payload = await this.parseToken(raw);
|
|
467
|
+
if (payload == null)
|
|
468
|
+
return;
|
|
444
469
|
matched.add(raw);
|
|
445
470
|
for (const item of payload) {
|
|
446
471
|
const parent = item[3] || "";
|
|
@@ -450,47 +475,6 @@ class UnoGenerator {
|
|
|
450
475
|
if (item[4]?.layer)
|
|
451
476
|
layerSet.add(item[4].layer);
|
|
452
477
|
}
|
|
453
|
-
};
|
|
454
|
-
const block = (raw) => {
|
|
455
|
-
this.blocked.add(raw);
|
|
456
|
-
this._cache.set(raw, null);
|
|
457
|
-
};
|
|
458
|
-
await Promise.all(Array.from(tokens).map(async (raw) => {
|
|
459
|
-
if (matched.has(raw) || this.blocked.has(raw))
|
|
460
|
-
return;
|
|
461
|
-
if (this._cache.has(raw)) {
|
|
462
|
-
const r = this._cache.get(raw);
|
|
463
|
-
if (r)
|
|
464
|
-
hit(raw, r);
|
|
465
|
-
return;
|
|
466
|
-
}
|
|
467
|
-
let current = raw;
|
|
468
|
-
for (const p of this.config.preprocess)
|
|
469
|
-
current = p(raw);
|
|
470
|
-
if (this.isBlocked(current))
|
|
471
|
-
return block(current);
|
|
472
|
-
const applied = this.matchVariants(raw, current);
|
|
473
|
-
if (!applied || this.isBlocked(applied[1]))
|
|
474
|
-
return block(raw);
|
|
475
|
-
const context = {
|
|
476
|
-
rawSelector: raw,
|
|
477
|
-
currentSelector: applied[1],
|
|
478
|
-
theme: this.config.theme,
|
|
479
|
-
generator: this,
|
|
480
|
-
variantHandlers: applied[2],
|
|
481
|
-
constructCSS: (...args) => this.constructCustomCSS(context, ...args)
|
|
482
|
-
};
|
|
483
|
-
const expanded = this.expandShortcut(applied[1], context);
|
|
484
|
-
if (expanded) {
|
|
485
|
-
const utils = await this.stringifyShortcuts(applied, context, expanded[0], expanded[1]);
|
|
486
|
-
if (utils?.length)
|
|
487
|
-
return hit(raw, utils);
|
|
488
|
-
} else {
|
|
489
|
-
const utils = (await this.parseUtil(applied, context))?.map((i) => this.stringifyUtil(i)).filter(notNull);
|
|
490
|
-
if (utils?.length)
|
|
491
|
-
return hit(raw, utils);
|
|
492
|
-
}
|
|
493
|
-
this._cache.set(raw, null);
|
|
494
478
|
}));
|
|
495
479
|
if (preflights) {
|
|
496
480
|
this.config.preflights.forEach((i) => {
|
|
@@ -513,7 +497,7 @@ class UnoGenerator {
|
|
|
513
497
|
return layerCache[layer];
|
|
514
498
|
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]) => {
|
|
515
499
|
const size = items.length;
|
|
516
|
-
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], !!a[4]?.noMerge]).map((a) => [a[0] == null ? a[0] : [a[0]], a[1], a[2]]);
|
|
500
|
+
const sorted = items.filter((i) => (i[4]?.layer || "default") === layer).sort((a, b) => a[0] - b[0] || (a[4]?.sort || 0) - (b[4]?.sort || 0) || a[1]?.localeCompare(b[1] || "") || 0).map((a) => [a[1] ? applyScope(a[1], scope) : a[1], a[2], !!a[4]?.noMerge]).map((a) => [a[0] == null ? a[0] : [a[0]], a[1], a[2]]);
|
|
517
501
|
if (!sorted.length)
|
|
518
502
|
return void 0;
|
|
519
503
|
const rules = sorted.reverse().map(([selector, body, noMerge], idx) => {
|
|
@@ -591,7 +575,9 @@ class UnoGenerator {
|
|
|
591
575
|
const obj = {
|
|
592
576
|
selector: handlers.reduce((p, v) => v.selector?.(p, entries) || p, toEscapedSelector(raw)),
|
|
593
577
|
entries,
|
|
594
|
-
parent: handlers.reduce((p, v) => Array.isArray(v.parent) ? v.parent[0] : v.parent || p, void 0)
|
|
578
|
+
parent: handlers.reduce((p, v) => Array.isArray(v.parent) ? v.parent[0] : v.parent || p, void 0),
|
|
579
|
+
layer: handlers.reduce((p, v) => v.layer || p, void 0),
|
|
580
|
+
sort: handlers.reduce((p, v) => v.sort || p, void 0)
|
|
595
581
|
};
|
|
596
582
|
for (const p of this.config.postprocess)
|
|
597
583
|
p(obj);
|
|
@@ -639,11 +625,17 @@ class UnoGenerator {
|
|
|
639
625
|
return;
|
|
640
626
|
if (isRawUtil(parsed))
|
|
641
627
|
return [parsed[0], void 0, parsed[1], void 0, parsed[2]];
|
|
642
|
-
const { selector, entries, parent } = this.applyVariants(parsed);
|
|
628
|
+
const { selector, entries, parent, layer: variantLayer, sort: variantSort } = this.applyVariants(parsed);
|
|
643
629
|
const body = entriesToCss(entries);
|
|
644
630
|
if (!body)
|
|
645
631
|
return;
|
|
646
|
-
|
|
632
|
+
const { layer: metaLayer, sort: metaSort, ...meta } = parsed[3] ?? {};
|
|
633
|
+
const ruleMeta = {
|
|
634
|
+
...meta,
|
|
635
|
+
layer: variantLayer ?? metaLayer,
|
|
636
|
+
sort: variantSort ?? metaSort
|
|
637
|
+
};
|
|
638
|
+
return [parsed[0], selector, body, parent, ruleMeta];
|
|
647
639
|
}
|
|
648
640
|
expandShortcut(processed, context, depth = 3) {
|
|
649
641
|
if (depth === 0)
|
|
@@ -749,7 +741,6 @@ exports.expandVariantGroup = expandVariantGroup;
|
|
|
749
741
|
exports.extractorSplit = extractorSplit;
|
|
750
742
|
exports.extractorSvelte = extractorSvelte;
|
|
751
743
|
exports.hasScopePlaceholder = hasScopePlaceholder;
|
|
752
|
-
exports.hex2rgba = hex2rgba;
|
|
753
744
|
exports.isAttributifySelector = isAttributifySelector;
|
|
754
745
|
exports.isObject = isObject;
|
|
755
746
|
exports.isRawUtil = isRawUtil;
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ declare class UnoGenerator {
|
|
|
9
9
|
constructor(userConfig?: UserConfig, defaults?: UserConfigDefaults);
|
|
10
10
|
setConfig(userConfig?: UserConfig, defaults?: UserConfigDefaults): void;
|
|
11
11
|
applyExtractors(code: string, id?: string, set?: Set<string>): Promise<Set<string>>;
|
|
12
|
+
parseToken(raw: string): Promise<StringifiedUtil[] | null | undefined>;
|
|
12
13
|
generate(input: string | Set<string>, { id, scope, preflights, safelist, minify, }?: GenerateOptions): Promise<GenerateResult>;
|
|
13
14
|
matchVariants(raw: string, current?: string): VariantMatchedResult;
|
|
14
15
|
applyVariants(parsed: ParsedUtil, variantHandlers?: VariantHandler[], raw?: string): UtilObject;
|
|
@@ -37,6 +38,11 @@ declare type PartialByKeys<T, K extends keyof T = keyof T> = FlatObjectTuple<Par
|
|
|
37
38
|
declare type RequiredByKey<T, K extends keyof T = keyof T> = FlatObjectTuple<Required<Pick<T, Extract<keyof T, K>>> & Omit<T, K>>;
|
|
38
39
|
declare type CSSObject = Record<string, string | number | undefined>;
|
|
39
40
|
declare type CSSEntries = [string, string | number | undefined][];
|
|
41
|
+
interface CSSColorValue {
|
|
42
|
+
type: string;
|
|
43
|
+
components: (string | number)[];
|
|
44
|
+
alpha: string | number | undefined;
|
|
45
|
+
}
|
|
40
46
|
declare type RGBAColorValue = [number, number, number, number] | [number, number, number];
|
|
41
47
|
interface ParsedColorValue {
|
|
42
48
|
/**
|
|
@@ -56,13 +62,13 @@ interface ParsedColorValue {
|
|
|
56
62
|
*/
|
|
57
63
|
no: string;
|
|
58
64
|
/**
|
|
59
|
-
* {@link
|
|
65
|
+
* {@link CSSColorValue}
|
|
60
66
|
*/
|
|
61
|
-
|
|
67
|
+
cssColor: CSSColorValue | undefined;
|
|
62
68
|
/**
|
|
63
|
-
* Parsed
|
|
69
|
+
* Parsed alpha value from opacity
|
|
64
70
|
*/
|
|
65
|
-
alpha
|
|
71
|
+
alpha: string | number | undefined;
|
|
66
72
|
}
|
|
67
73
|
declare type PresetOptions = Record<string, any>;
|
|
68
74
|
interface RuleContext<Theme extends {} = {}> {
|
|
@@ -128,6 +134,10 @@ interface RuleMeta {
|
|
|
128
134
|
* @default false
|
|
129
135
|
*/
|
|
130
136
|
noMerge?: boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Fine tune sort
|
|
139
|
+
*/
|
|
140
|
+
sort?: number;
|
|
131
141
|
/**
|
|
132
142
|
* Internal rules will only be matched for shortcuts but not the user code.
|
|
133
143
|
* @default false
|
|
@@ -169,9 +179,17 @@ interface VariantHandler {
|
|
|
169
179
|
*/
|
|
170
180
|
parent?: string | [string, number] | undefined;
|
|
171
181
|
/**
|
|
172
|
-
*
|
|
182
|
+
* Order in which the variant is applied to selector.
|
|
173
183
|
*/
|
|
174
184
|
order?: number;
|
|
185
|
+
/**
|
|
186
|
+
* Order in which the variant is sorted within single rule.
|
|
187
|
+
*/
|
|
188
|
+
sort?: number;
|
|
189
|
+
/**
|
|
190
|
+
* Override layer to the output css.
|
|
191
|
+
*/
|
|
192
|
+
layer?: string | undefined;
|
|
175
193
|
}
|
|
176
194
|
declare type VariantFunction<Theme extends {} = {}> = (matcher: string, context: Readonly<VariantContext<Theme>>) => string | VariantHandler | undefined;
|
|
177
195
|
interface VariantObject<Theme extends {} = {}> {
|
|
@@ -363,6 +381,8 @@ interface UtilObject {
|
|
|
363
381
|
selector: string;
|
|
364
382
|
entries: CSSEntries;
|
|
365
383
|
parent: string | undefined;
|
|
384
|
+
layer: string | undefined;
|
|
385
|
+
sort: number | undefined;
|
|
366
386
|
}
|
|
367
387
|
interface GenerateOptions {
|
|
368
388
|
/**
|
|
@@ -411,8 +431,6 @@ declare function toArray<T>(value?: T | T[]): T[];
|
|
|
411
431
|
declare function uniq<T>(value: T[]): T[];
|
|
412
432
|
declare function mergeSet<T>(target: Set<T>, append: Set<T>): Set<T>;
|
|
413
433
|
|
|
414
|
-
declare function hex2rgba(hex?: string): RGBAColorValue | undefined;
|
|
415
|
-
|
|
416
434
|
declare const attributifyRE: RegExp;
|
|
417
435
|
declare const validateFilterRE: RegExp;
|
|
418
436
|
declare const CONTROL_SHORTCUT_NO_MERGE = "$$shortcut-no-merge";
|
|
@@ -458,4 +476,4 @@ declare const extractorSplit: Extractor;
|
|
|
458
476
|
|
|
459
477
|
declare const extractorSvelte: Extractor;
|
|
460
478
|
|
|
461
|
-
export { ArgumentType, Arrayable, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, 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, ThemeExtender, TwoKeyMap, UnoGenerator, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, ValueHandler, ValueHandlerCallback, Variant, VariantContext, VariantFunction, VariantHandler, VariantMatchedResult, VariantObject, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder,
|
|
479
|
+
export { ArgumentType, Arrayable, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, 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, ThemeExtender, TwoKeyMap, UnoGenerator, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, ValueHandler, ValueHandlerCallback, Variant, VariantContext, VariantFunction, VariantHandler, VariantMatchedResult, VariantObject, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, toArray, uniq, validateFilterRE, warnOnce, withLayer };
|
package/dist/index.mjs
CHANGED
|
@@ -133,28 +133,6 @@ function mergeSet(target, append) {
|
|
|
133
133
|
return target;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
const hexRE = /^#?([\da-f]+)$/i;
|
|
137
|
-
function hex2rgba(hex = "") {
|
|
138
|
-
const [, body] = hex.match(hexRE) || [];
|
|
139
|
-
if (!body)
|
|
140
|
-
return;
|
|
141
|
-
switch (body.length) {
|
|
142
|
-
case 3:
|
|
143
|
-
case 4:
|
|
144
|
-
const digits = Array.from(body, (s) => Number.parseInt(s, 16)).map((n) => n << 4 | n);
|
|
145
|
-
if (body.length === 3)
|
|
146
|
-
return digits;
|
|
147
|
-
digits[3] = Math.round(digits[3] / 255 * 100) / 100;
|
|
148
|
-
return digits;
|
|
149
|
-
case 6:
|
|
150
|
-
case 8:
|
|
151
|
-
const value = Number.parseInt(body, 16);
|
|
152
|
-
if (body.length === 6)
|
|
153
|
-
return [value >> 16 & 255, value >> 8 & 255, value & 255];
|
|
154
|
-
return [value >> 24 & 255, value >> 16 & 255, value >> 8 & 255, Math.round((value & 255) / 255 * 100) / 100];
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
136
|
const attributifyRE = /^\[(.+?)~?="(.*)"\]$/;
|
|
159
137
|
const validateFilterRE = /(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-?]/;
|
|
160
138
|
const CONTROL_SHORTCUT_NO_MERGE = "$$shortcut-no-merge";
|
|
@@ -384,7 +362,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
384
362
|
};
|
|
385
363
|
}
|
|
386
364
|
|
|
387
|
-
const version = "0.
|
|
365
|
+
const version = "0.24.1";
|
|
388
366
|
|
|
389
367
|
class UnoGenerator {
|
|
390
368
|
constructor(userConfig = {}, defaults = {}) {
|
|
@@ -421,6 +399,49 @@ class UnoGenerator {
|
|
|
421
399
|
}
|
|
422
400
|
return set;
|
|
423
401
|
}
|
|
402
|
+
async parseToken(raw) {
|
|
403
|
+
if (this.blocked.has(raw))
|
|
404
|
+
return;
|
|
405
|
+
if (this._cache.has(raw))
|
|
406
|
+
return this._cache.get(raw);
|
|
407
|
+
let current = raw;
|
|
408
|
+
for (const p of this.config.preprocess)
|
|
409
|
+
current = p(raw);
|
|
410
|
+
if (this.isBlocked(current)) {
|
|
411
|
+
this.blocked.add(raw);
|
|
412
|
+
this._cache.set(raw, null);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
const applied = this.matchVariants(raw, current);
|
|
416
|
+
if (!applied || this.isBlocked(applied[1])) {
|
|
417
|
+
this.blocked.add(raw);
|
|
418
|
+
this._cache.set(raw, null);
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
const context = {
|
|
422
|
+
rawSelector: raw,
|
|
423
|
+
currentSelector: applied[1],
|
|
424
|
+
theme: this.config.theme,
|
|
425
|
+
generator: this,
|
|
426
|
+
variantHandlers: applied[2],
|
|
427
|
+
constructCSS: (...args) => this.constructCustomCSS(context, ...args)
|
|
428
|
+
};
|
|
429
|
+
const expanded = this.expandShortcut(applied[1], context);
|
|
430
|
+
if (expanded) {
|
|
431
|
+
const utils = await this.stringifyShortcuts(applied, context, expanded[0], expanded[1]);
|
|
432
|
+
if (utils?.length) {
|
|
433
|
+
this._cache.set(raw, utils);
|
|
434
|
+
return utils;
|
|
435
|
+
}
|
|
436
|
+
} else {
|
|
437
|
+
const utils = (await this.parseUtil(applied, context))?.map((i) => this.stringifyUtil(i)).filter(notNull);
|
|
438
|
+
if (utils?.length) {
|
|
439
|
+
this._cache.set(raw, utils);
|
|
440
|
+
return utils;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
this._cache.set(raw, null);
|
|
444
|
+
}
|
|
424
445
|
async generate(input, {
|
|
425
446
|
id,
|
|
426
447
|
scope,
|
|
@@ -435,8 +456,12 @@ class UnoGenerator {
|
|
|
435
456
|
const layerSet = /* @__PURE__ */ new Set(["default"]);
|
|
436
457
|
const matched = /* @__PURE__ */ new Set();
|
|
437
458
|
const sheet = /* @__PURE__ */ new Map();
|
|
438
|
-
|
|
439
|
-
|
|
459
|
+
await Promise.all(Array.from(tokens).map(async (raw) => {
|
|
460
|
+
if (matched.has(raw))
|
|
461
|
+
return;
|
|
462
|
+
const payload = await this.parseToken(raw);
|
|
463
|
+
if (payload == null)
|
|
464
|
+
return;
|
|
440
465
|
matched.add(raw);
|
|
441
466
|
for (const item of payload) {
|
|
442
467
|
const parent = item[3] || "";
|
|
@@ -446,47 +471,6 @@ class UnoGenerator {
|
|
|
446
471
|
if (item[4]?.layer)
|
|
447
472
|
layerSet.add(item[4].layer);
|
|
448
473
|
}
|
|
449
|
-
};
|
|
450
|
-
const block = (raw) => {
|
|
451
|
-
this.blocked.add(raw);
|
|
452
|
-
this._cache.set(raw, null);
|
|
453
|
-
};
|
|
454
|
-
await Promise.all(Array.from(tokens).map(async (raw) => {
|
|
455
|
-
if (matched.has(raw) || this.blocked.has(raw))
|
|
456
|
-
return;
|
|
457
|
-
if (this._cache.has(raw)) {
|
|
458
|
-
const r = this._cache.get(raw);
|
|
459
|
-
if (r)
|
|
460
|
-
hit(raw, r);
|
|
461
|
-
return;
|
|
462
|
-
}
|
|
463
|
-
let current = raw;
|
|
464
|
-
for (const p of this.config.preprocess)
|
|
465
|
-
current = p(raw);
|
|
466
|
-
if (this.isBlocked(current))
|
|
467
|
-
return block(current);
|
|
468
|
-
const applied = this.matchVariants(raw, current);
|
|
469
|
-
if (!applied || this.isBlocked(applied[1]))
|
|
470
|
-
return block(raw);
|
|
471
|
-
const context = {
|
|
472
|
-
rawSelector: raw,
|
|
473
|
-
currentSelector: applied[1],
|
|
474
|
-
theme: this.config.theme,
|
|
475
|
-
generator: this,
|
|
476
|
-
variantHandlers: applied[2],
|
|
477
|
-
constructCSS: (...args) => this.constructCustomCSS(context, ...args)
|
|
478
|
-
};
|
|
479
|
-
const expanded = this.expandShortcut(applied[1], context);
|
|
480
|
-
if (expanded) {
|
|
481
|
-
const utils = await this.stringifyShortcuts(applied, context, expanded[0], expanded[1]);
|
|
482
|
-
if (utils?.length)
|
|
483
|
-
return hit(raw, utils);
|
|
484
|
-
} else {
|
|
485
|
-
const utils = (await this.parseUtil(applied, context))?.map((i) => this.stringifyUtil(i)).filter(notNull);
|
|
486
|
-
if (utils?.length)
|
|
487
|
-
return hit(raw, utils);
|
|
488
|
-
}
|
|
489
|
-
this._cache.set(raw, null);
|
|
490
474
|
}));
|
|
491
475
|
if (preflights) {
|
|
492
476
|
this.config.preflights.forEach((i) => {
|
|
@@ -509,7 +493,7 @@ class UnoGenerator {
|
|
|
509
493
|
return layerCache[layer];
|
|
510
494
|
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]) => {
|
|
511
495
|
const size = items.length;
|
|
512
|
-
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], !!a[4]?.noMerge]).map((a) => [a[0] == null ? a[0] : [a[0]], a[1], a[2]]);
|
|
496
|
+
const sorted = items.filter((i) => (i[4]?.layer || "default") === layer).sort((a, b) => a[0] - b[0] || (a[4]?.sort || 0) - (b[4]?.sort || 0) || a[1]?.localeCompare(b[1] || "") || 0).map((a) => [a[1] ? applyScope(a[1], scope) : a[1], a[2], !!a[4]?.noMerge]).map((a) => [a[0] == null ? a[0] : [a[0]], a[1], a[2]]);
|
|
513
497
|
if (!sorted.length)
|
|
514
498
|
return void 0;
|
|
515
499
|
const rules = sorted.reverse().map(([selector, body, noMerge], idx) => {
|
|
@@ -587,7 +571,9 @@ class UnoGenerator {
|
|
|
587
571
|
const obj = {
|
|
588
572
|
selector: handlers.reduce((p, v) => v.selector?.(p, entries) || p, toEscapedSelector(raw)),
|
|
589
573
|
entries,
|
|
590
|
-
parent: handlers.reduce((p, v) => Array.isArray(v.parent) ? v.parent[0] : v.parent || p, void 0)
|
|
574
|
+
parent: handlers.reduce((p, v) => Array.isArray(v.parent) ? v.parent[0] : v.parent || p, void 0),
|
|
575
|
+
layer: handlers.reduce((p, v) => v.layer || p, void 0),
|
|
576
|
+
sort: handlers.reduce((p, v) => v.sort || p, void 0)
|
|
591
577
|
};
|
|
592
578
|
for (const p of this.config.postprocess)
|
|
593
579
|
p(obj);
|
|
@@ -635,11 +621,17 @@ class UnoGenerator {
|
|
|
635
621
|
return;
|
|
636
622
|
if (isRawUtil(parsed))
|
|
637
623
|
return [parsed[0], void 0, parsed[1], void 0, parsed[2]];
|
|
638
|
-
const { selector, entries, parent } = this.applyVariants(parsed);
|
|
624
|
+
const { selector, entries, parent, layer: variantLayer, sort: variantSort } = this.applyVariants(parsed);
|
|
639
625
|
const body = entriesToCss(entries);
|
|
640
626
|
if (!body)
|
|
641
627
|
return;
|
|
642
|
-
|
|
628
|
+
const { layer: metaLayer, sort: metaSort, ...meta } = parsed[3] ?? {};
|
|
629
|
+
const ruleMeta = {
|
|
630
|
+
...meta,
|
|
631
|
+
layer: variantLayer ?? metaLayer,
|
|
632
|
+
sort: variantSort ?? metaSort
|
|
633
|
+
};
|
|
634
|
+
return [parsed[0], selector, body, parent, ruleMeta];
|
|
643
635
|
}
|
|
644
636
|
expandShortcut(processed, context, depth = 3) {
|
|
645
637
|
if (depth === 0)
|
|
@@ -728,4 +720,4 @@ function toEscapedSelector(raw) {
|
|
|
728
720
|
return `.${e(raw)}`;
|
|
729
721
|
}
|
|
730
722
|
|
|
731
|
-
export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder,
|
|
723
|
+
export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, toArray, uniq, validateFilterRE, warnOnce, withLayer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.1",
|
|
4
4
|
"description": "The instant on-demand Atomic CSS engine.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unocss",
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
"tailwind",
|
|
11
11
|
"windicss"
|
|
12
12
|
],
|
|
13
|
-
"homepage": "https://github.com/
|
|
13
|
+
"homepage": "https://github.com/unocss/unocss/tree/main/packages/core#readme",
|
|
14
14
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/
|
|
15
|
+
"url": "https://github.com/unocss/unocss/issues"
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "git+https://github.com/
|
|
19
|
+
"url": "git+https://github.com/unocss/unocss.git",
|
|
20
20
|
"directory": "packages/core"
|
|
21
21
|
},
|
|
22
22
|
"funding": "https://github.com/sponsors/antfu",
|