@unocss/core 0.4.11 → 0.4.12
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 +23 -1
- package/dist/index.js +11 -2
- package/dist/index.mjs +11 -2
- package/package.json +13 -5
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ declare class UnoGenerator {
|
|
|
10
10
|
generate(input: string | Set<string>, id?: string, scope?: string): Promise<GenerateResult>;
|
|
11
11
|
matchVariants(raw: string): VariantMatchedResult;
|
|
12
12
|
applyVariants(parsed: ParsedUtil, variantHandlers?: VariantHandler[], raw?: string): readonly [string, CSSEntries, string | undefined];
|
|
13
|
+
constructCustomCSS(context: Readonly<RuleContext>, body: CSSObject | CSSEntries, overrideSelector?: string): string;
|
|
13
14
|
parseUtil(input: string | VariantMatchedResult): Promise<ParsedUtil | RawUtil | undefined>;
|
|
14
15
|
stringifyUtil(parsed?: ParsedUtil | RawUtil): StringifiedUtil | undefined;
|
|
15
16
|
expandShortcut(processed: string, depth?: number): string[] | undefined;
|
|
@@ -29,11 +30,32 @@ declare type DeepPartial<T> = {
|
|
|
29
30
|
declare type CSSObject = Record<string, string | number | undefined>;
|
|
30
31
|
declare type CSSEntries = [string, string | number | undefined][];
|
|
31
32
|
interface RuleContext<Theme extends {} = {}> {
|
|
33
|
+
/**
|
|
34
|
+
* Unprocessed selector from user input.
|
|
35
|
+
* Useful for generating CSS rule.
|
|
36
|
+
*/
|
|
32
37
|
rawSelector: string;
|
|
38
|
+
/**
|
|
39
|
+
* Current selector for rule matching
|
|
40
|
+
*/
|
|
33
41
|
currentSelector: string;
|
|
42
|
+
/**
|
|
43
|
+
* UnoCSS generator instance
|
|
44
|
+
*/
|
|
34
45
|
generator: UnoGenerator;
|
|
46
|
+
/**
|
|
47
|
+
* The theme object
|
|
48
|
+
*/
|
|
35
49
|
theme: Theme;
|
|
50
|
+
/**
|
|
51
|
+
* Matched variants handlers for this rule.
|
|
52
|
+
*/
|
|
36
53
|
variantHandlers: VariantHandler[];
|
|
54
|
+
/**
|
|
55
|
+
* Constrcut a custom CSS rule.
|
|
56
|
+
* Variants and selector escaping will be handled automatically.
|
|
57
|
+
*/
|
|
58
|
+
constructCSS: (body: CSSEntries | CSSObject, overrideSelector?: string) => string;
|
|
37
59
|
}
|
|
38
60
|
declare type Extractor = (code: string, id?: string) => Awaitable<Set<string> | undefined>;
|
|
39
61
|
declare type DynamicRule<Theme extends {} = {}> = [RegExp, ((match: string[], context: Readonly<RuleContext<Theme>>) => Awaitable<CSSObject | CSSEntries | string | undefined>)];
|
|
@@ -182,7 +204,7 @@ declare function toArray<T>(value?: T | T[]): T[];
|
|
|
182
204
|
declare function uniq<T>(value: T[]): T[];
|
|
183
205
|
declare function mergeSet<T>(target: Set<T>, append: Set<T>): Set<T>;
|
|
184
206
|
|
|
185
|
-
declare function hex2rgba(hex
|
|
207
|
+
declare function hex2rgba(hex?: string): [number, number, number, number] | [number, number, number] | undefined;
|
|
186
208
|
|
|
187
209
|
declare const attributifyRE: RegExp;
|
|
188
210
|
declare const validateFilterRE: RegExp;
|
package/dist/index.js
CHANGED
|
@@ -124,7 +124,7 @@ function mergeSet(target, append) {
|
|
|
124
124
|
|
|
125
125
|
// src/utils/colors.ts
|
|
126
126
|
var hexRE = /^#?([\da-f]+)$/i;
|
|
127
|
-
function hex2rgba(hex) {
|
|
127
|
+
function hex2rgba(hex = "") {
|
|
128
128
|
const [, body] = hex.match(hexRE) || [];
|
|
129
129
|
if (!body)
|
|
130
130
|
return;
|
|
@@ -422,6 +422,14 @@ ${rules}
|
|
|
422
422
|
mediaQuery
|
|
423
423
|
];
|
|
424
424
|
}
|
|
425
|
+
constructCustomCSS(context, body, overrideSelector) {
|
|
426
|
+
body = normalizeEntries(body);
|
|
427
|
+
const [selector, entries, mediaQuery] = this.applyVariants([0, overrideSelector || context.rawSelector, body, context.variantHandlers]);
|
|
428
|
+
const cssBody = `${selector}{${entriesToCss(entries)}}`;
|
|
429
|
+
if (mediaQuery)
|
|
430
|
+
return `${mediaQuery}{${cssBody}}`;
|
|
431
|
+
return cssBody;
|
|
432
|
+
}
|
|
425
433
|
async parseUtil(input) {
|
|
426
434
|
const { theme, rulesStaticMap, rulesDynamic, rulesSize } = this.config;
|
|
427
435
|
const [raw, processed, variantHandlers] = typeof input === "string" ? this.matchVariants(input) : input;
|
|
@@ -433,7 +441,8 @@ ${rules}
|
|
|
433
441
|
currentSelector: processed,
|
|
434
442
|
theme,
|
|
435
443
|
generator: this,
|
|
436
|
-
variantHandlers
|
|
444
|
+
variantHandlers,
|
|
445
|
+
constructCSS: (...args) => this.constructCustomCSS(context, ...args)
|
|
437
446
|
};
|
|
438
447
|
for (let i = rulesSize; i >= 0; i--) {
|
|
439
448
|
const rule = rulesDynamic[i];
|
package/dist/index.mjs
CHANGED
|
@@ -88,7 +88,7 @@ function mergeSet(target, append) {
|
|
|
88
88
|
|
|
89
89
|
// src/utils/colors.ts
|
|
90
90
|
var hexRE = /^#?([\da-f]+)$/i;
|
|
91
|
-
function hex2rgba(hex) {
|
|
91
|
+
function hex2rgba(hex = "") {
|
|
92
92
|
const [, body] = hex.match(hexRE) || [];
|
|
93
93
|
if (!body)
|
|
94
94
|
return;
|
|
@@ -386,6 +386,14 @@ ${rules}
|
|
|
386
386
|
mediaQuery
|
|
387
387
|
];
|
|
388
388
|
}
|
|
389
|
+
constructCustomCSS(context, body, overrideSelector) {
|
|
390
|
+
body = normalizeEntries(body);
|
|
391
|
+
const [selector, entries, mediaQuery] = this.applyVariants([0, overrideSelector || context.rawSelector, body, context.variantHandlers]);
|
|
392
|
+
const cssBody = `${selector}{${entriesToCss(entries)}}`;
|
|
393
|
+
if (mediaQuery)
|
|
394
|
+
return `${mediaQuery}{${cssBody}}`;
|
|
395
|
+
return cssBody;
|
|
396
|
+
}
|
|
389
397
|
async parseUtil(input) {
|
|
390
398
|
const { theme, rulesStaticMap, rulesDynamic, rulesSize } = this.config;
|
|
391
399
|
const [raw, processed, variantHandlers] = typeof input === "string" ? this.matchVariants(input) : input;
|
|
@@ -397,7 +405,8 @@ ${rules}
|
|
|
397
405
|
currentSelector: processed,
|
|
398
406
|
theme,
|
|
399
407
|
generator: this,
|
|
400
|
-
variantHandlers
|
|
408
|
+
variantHandlers,
|
|
409
|
+
constructCSS: (...args) => this.constructCustomCSS(context, ...args)
|
|
401
410
|
};
|
|
402
411
|
for (let i = rulesSize; i >= 0; i--) {
|
|
403
412
|
const rule = rulesDynamic[i];
|
package/package.json
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/core",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"description": "",
|
|
5
|
-
"keywords": [
|
|
6
|
-
|
|
3
|
+
"version": "0.4.12",
|
|
4
|
+
"description": "The instant on-demand Atomic CSS engine.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"unocss",
|
|
7
|
+
"atomic-css",
|
|
8
|
+
"atomic-css-engine",
|
|
9
|
+
"css",
|
|
10
|
+
"tailwind",
|
|
11
|
+
"windicss"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/antfu/unocss/tree/main/packages/core#readme",
|
|
7
14
|
"bugs": {
|
|
8
15
|
"url": "https://github.com/antfu/unocss/issues"
|
|
9
16
|
},
|
|
10
17
|
"repository": {
|
|
11
18
|
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/antfu/unocss.git"
|
|
19
|
+
"url": "git+https://github.com/antfu/unocss.git",
|
|
20
|
+
"directory": "packages/core"
|
|
13
21
|
},
|
|
14
22
|
"funding": "https://github.com/sponsors/antfu",
|
|
15
23
|
"license": "MIT",
|