@unocss/core 0.54.0 → 0.54.2
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 +44 -11
- package/dist/index.d.ts +7 -1
- package/dist/index.mjs +44 -7
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const MagicString = require('magic-string');
|
|
6
|
-
|
|
7
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
8
|
-
|
|
9
|
-
const MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
|
|
10
|
-
|
|
11
5
|
function escapeRegExp(string) {
|
|
12
6
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
13
7
|
}
|
|
@@ -277,9 +271,26 @@ function parseVariantGroup(str, separators = ["-", ":"], depth = 5) {
|
|
|
277
271
|
);
|
|
278
272
|
depth -= 1;
|
|
279
273
|
} while (hasChanged && depth);
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
expanded
|
|
274
|
+
let expanded;
|
|
275
|
+
if (typeof str === "string") {
|
|
276
|
+
expanded = "";
|
|
277
|
+
let prevOffset = 0;
|
|
278
|
+
for (const [offset, group] of groupsByOffset) {
|
|
279
|
+
expanded += str.slice(prevOffset, offset);
|
|
280
|
+
expanded += group.items.map((item) => item.className).join(" ");
|
|
281
|
+
prevOffset = offset + group.length;
|
|
282
|
+
}
|
|
283
|
+
expanded += str.slice(prevOffset);
|
|
284
|
+
} else {
|
|
285
|
+
expanded = str;
|
|
286
|
+
for (const [offset, group] of groupsByOffset) {
|
|
287
|
+
expanded.overwrite(
|
|
288
|
+
offset,
|
|
289
|
+
offset + group.length,
|
|
290
|
+
group.items.map((item) => item.className).join(" ")
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
283
294
|
return {
|
|
284
295
|
prefixes: Array.from(prefixes),
|
|
285
296
|
hasChanged,
|
|
@@ -386,7 +397,9 @@ function createNanoEvents() {
|
|
|
386
397
|
const LAYER_DEFAULT = "default";
|
|
387
398
|
const LAYER_PREFLIGHTS = "preflights";
|
|
388
399
|
const LAYER_SHORTCUTS = "shortcuts";
|
|
400
|
+
const LAYER_IMPORTS = "imports";
|
|
389
401
|
const DEFAULT_LAYERS = {
|
|
402
|
+
[LAYER_IMPORTS]: -200,
|
|
390
403
|
[LAYER_PREFLIGHTS]: -100,
|
|
391
404
|
[LAYER_SHORTCUTS]: -10,
|
|
392
405
|
[LAYER_DEFAULT]: 0
|
|
@@ -475,7 +488,8 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
475
488
|
theme = extendTheme(theme) || theme;
|
|
476
489
|
const autocomplete = {
|
|
477
490
|
templates: uniq(sources.flatMap((p) => toArray(p.autocomplete?.templates))),
|
|
478
|
-
extractors: sources.flatMap((p) => toArray(p.autocomplete?.extractors)).sort((a, b) => (a.order || 0) - (b.order || 0))
|
|
491
|
+
extractors: sources.flatMap((p) => toArray(p.autocomplete?.extractors)).sort((a, b) => (a.order || 0) - (b.order || 0)),
|
|
492
|
+
shorthands: mergeAutocompleteShorthands(sources.map((p) => p.autocomplete?.shorthands || {}))
|
|
479
493
|
};
|
|
480
494
|
let separators = getMerged("separators");
|
|
481
495
|
if (!separators.length)
|
|
@@ -533,8 +547,27 @@ function mergeConfigs(configs) {
|
|
|
533
547
|
function mergeThemes(themes) {
|
|
534
548
|
return themes.map((theme) => theme ? clone(theme) : {}).reduce((a, b) => mergeDeep(a, b), {});
|
|
535
549
|
}
|
|
550
|
+
function mergeAutocompleteShorthands(shorthands) {
|
|
551
|
+
return shorthands.reduce(
|
|
552
|
+
(a, b) => {
|
|
553
|
+
const rs = {};
|
|
554
|
+
for (const key in b) {
|
|
555
|
+
const value = b[key];
|
|
556
|
+
if (Array.isArray(value))
|
|
557
|
+
rs[key] = `(${value.join("|")})`;
|
|
558
|
+
else
|
|
559
|
+
rs[key] = value;
|
|
560
|
+
}
|
|
561
|
+
return {
|
|
562
|
+
...a,
|
|
563
|
+
...rs
|
|
564
|
+
};
|
|
565
|
+
},
|
|
566
|
+
{}
|
|
567
|
+
);
|
|
568
|
+
}
|
|
536
569
|
|
|
537
|
-
const version = "0.54.
|
|
570
|
+
const version = "0.54.2";
|
|
538
571
|
|
|
539
572
|
class UnoGenerator {
|
|
540
573
|
constructor(userConfig = {}, defaults = {}) {
|
package/dist/index.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ declare class UnoGenerator<Theme extends object = object> {
|
|
|
66
66
|
setConfig(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): void;
|
|
67
67
|
applyExtractors(code: string, id?: string, extracted?: Set<string>): Promise<Set<string>>;
|
|
68
68
|
makeContext(raw: string, applied: VariantMatchedResult<Theme>): RuleContext<Theme>;
|
|
69
|
-
parseToken(raw: string, alias?: string): Promise<StringifiedUtil<Theme>[] |
|
|
69
|
+
parseToken(raw: string, alias?: string): Promise<StringifiedUtil<Theme>[] | undefined | null>;
|
|
70
70
|
generate(input: string | Set<string> | string[], options?: GenerateOptions): Promise<GenerateResult>;
|
|
71
71
|
matchVariants(raw: string, current?: string): Promise<VariantMatchedResult<Theme>>;
|
|
72
72
|
private applyVariants;
|
|
@@ -551,6 +551,11 @@ interface ConfigBase<Theme extends object = object> {
|
|
|
551
551
|
* transform class-name style suggestions to the correct format
|
|
552
552
|
*/
|
|
553
553
|
extractors?: Arrayable<AutoCompleteExtractor>;
|
|
554
|
+
/**
|
|
555
|
+
* Custom shorthands to provide autocomplete suggestions.
|
|
556
|
+
* if values is an array, it will be joined with `|` and wrapped with `()`
|
|
557
|
+
*/
|
|
558
|
+
shorthands?: Record<string, string | string[]>;
|
|
554
559
|
};
|
|
555
560
|
/**
|
|
556
561
|
* Hook to modify the resolved config.
|
|
@@ -851,6 +856,7 @@ interface ResolvedConfig<Theme extends object = object> extends Omit<RequiredByK
|
|
|
851
856
|
autocomplete: {
|
|
852
857
|
templates: (AutoCompleteFunction | AutoCompleteTemplate)[];
|
|
853
858
|
extractors: AutoCompleteExtractor[];
|
|
859
|
+
shorthands: Record<string, string>;
|
|
854
860
|
};
|
|
855
861
|
separators: string[];
|
|
856
862
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import MagicString from 'magic-string';
|
|
2
|
-
|
|
3
1
|
function escapeRegExp(string) {
|
|
4
2
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
5
3
|
}
|
|
@@ -269,9 +267,26 @@ function parseVariantGroup(str, separators = ["-", ":"], depth = 5) {
|
|
|
269
267
|
);
|
|
270
268
|
depth -= 1;
|
|
271
269
|
} while (hasChanged && depth);
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
expanded
|
|
270
|
+
let expanded;
|
|
271
|
+
if (typeof str === "string") {
|
|
272
|
+
expanded = "";
|
|
273
|
+
let prevOffset = 0;
|
|
274
|
+
for (const [offset, group] of groupsByOffset) {
|
|
275
|
+
expanded += str.slice(prevOffset, offset);
|
|
276
|
+
expanded += group.items.map((item) => item.className).join(" ");
|
|
277
|
+
prevOffset = offset + group.length;
|
|
278
|
+
}
|
|
279
|
+
expanded += str.slice(prevOffset);
|
|
280
|
+
} else {
|
|
281
|
+
expanded = str;
|
|
282
|
+
for (const [offset, group] of groupsByOffset) {
|
|
283
|
+
expanded.overwrite(
|
|
284
|
+
offset,
|
|
285
|
+
offset + group.length,
|
|
286
|
+
group.items.map((item) => item.className).join(" ")
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
275
290
|
return {
|
|
276
291
|
prefixes: Array.from(prefixes),
|
|
277
292
|
hasChanged,
|
|
@@ -378,7 +393,9 @@ function createNanoEvents() {
|
|
|
378
393
|
const LAYER_DEFAULT = "default";
|
|
379
394
|
const LAYER_PREFLIGHTS = "preflights";
|
|
380
395
|
const LAYER_SHORTCUTS = "shortcuts";
|
|
396
|
+
const LAYER_IMPORTS = "imports";
|
|
381
397
|
const DEFAULT_LAYERS = {
|
|
398
|
+
[LAYER_IMPORTS]: -200,
|
|
382
399
|
[LAYER_PREFLIGHTS]: -100,
|
|
383
400
|
[LAYER_SHORTCUTS]: -10,
|
|
384
401
|
[LAYER_DEFAULT]: 0
|
|
@@ -467,7 +484,8 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
467
484
|
theme = extendTheme(theme) || theme;
|
|
468
485
|
const autocomplete = {
|
|
469
486
|
templates: uniq(sources.flatMap((p) => toArray(p.autocomplete?.templates))),
|
|
470
|
-
extractors: sources.flatMap((p) => toArray(p.autocomplete?.extractors)).sort((a, b) => (a.order || 0) - (b.order || 0))
|
|
487
|
+
extractors: sources.flatMap((p) => toArray(p.autocomplete?.extractors)).sort((a, b) => (a.order || 0) - (b.order || 0)),
|
|
488
|
+
shorthands: mergeAutocompleteShorthands(sources.map((p) => p.autocomplete?.shorthands || {}))
|
|
471
489
|
};
|
|
472
490
|
let separators = getMerged("separators");
|
|
473
491
|
if (!separators.length)
|
|
@@ -525,8 +543,27 @@ function mergeConfigs(configs) {
|
|
|
525
543
|
function mergeThemes(themes) {
|
|
526
544
|
return themes.map((theme) => theme ? clone(theme) : {}).reduce((a, b) => mergeDeep(a, b), {});
|
|
527
545
|
}
|
|
546
|
+
function mergeAutocompleteShorthands(shorthands) {
|
|
547
|
+
return shorthands.reduce(
|
|
548
|
+
(a, b) => {
|
|
549
|
+
const rs = {};
|
|
550
|
+
for (const key in b) {
|
|
551
|
+
const value = b[key];
|
|
552
|
+
if (Array.isArray(value))
|
|
553
|
+
rs[key] = `(${value.join("|")})`;
|
|
554
|
+
else
|
|
555
|
+
rs[key] = value;
|
|
556
|
+
}
|
|
557
|
+
return {
|
|
558
|
+
...a,
|
|
559
|
+
...rs
|
|
560
|
+
};
|
|
561
|
+
},
|
|
562
|
+
{}
|
|
563
|
+
);
|
|
564
|
+
}
|
|
528
565
|
|
|
529
|
-
const version = "0.54.
|
|
566
|
+
const version = "0.54.2";
|
|
530
567
|
|
|
531
568
|
class UnoGenerator {
|
|
532
569
|
constructor(userConfig = {}, defaults = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/core",
|
|
3
|
-
"version": "0.54.
|
|
3
|
+
"version": "0.54.2",
|
|
4
4
|
"description": "The instant on-demand Atomic CSS engine.",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"magic-string": "^0.30.
|
|
41
|
-
"unconfig": "^0.3.
|
|
40
|
+
"magic-string": "^0.30.2",
|
|
41
|
+
"unconfig": "^0.3.10"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "unbuild",
|