@unocss/core
Advanced tools
Comparing version 0.4.11 to 0.4.12
@@ -13,2 +13,3 @@ declare class UnoGenerator { | ||
applyVariants(parsed: ParsedUtil, variantHandlers?: VariantHandler[], raw?: string): readonly [string, CSSEntries, string | undefined]; | ||
constructCustomCSS(context: Readonly<RuleContext>, body: CSSObject | CSSEntries, overrideSelector?: string): string; | ||
parseUtil(input: string | VariantMatchedResult): Promise<ParsedUtil | RawUtil | undefined>; | ||
@@ -33,7 +34,28 @@ stringifyUtil(parsed?: ParsedUtil | RawUtil): StringifiedUtil | undefined; | ||
interface RuleContext<Theme extends {} = {}> { | ||
/** | ||
* Unprocessed selector from user input. | ||
* Useful for generating CSS rule. | ||
*/ | ||
rawSelector: string; | ||
/** | ||
* Current selector for rule matching | ||
*/ | ||
currentSelector: string; | ||
/** | ||
* UnoCSS generator instance | ||
*/ | ||
generator: UnoGenerator; | ||
/** | ||
* The theme object | ||
*/ | ||
theme: Theme; | ||
/** | ||
* Matched variants handlers for this rule. | ||
*/ | ||
variantHandlers: VariantHandler[]; | ||
/** | ||
* Constrcut a custom CSS rule. | ||
* Variants and selector escaping will be handled automatically. | ||
*/ | ||
constructCSS: (body: CSSEntries | CSSObject, overrideSelector?: string) => string; | ||
} | ||
@@ -187,3 +209,3 @@ declare type Extractor = (code: string, id?: string) => Awaitable<Set<string> | undefined>; | ||
declare function hex2rgba(hex: string): [number, number, number, number] | [number, number, number] | undefined; | ||
declare function hex2rgba(hex?: string): [number, number, number, number] | [number, number, number] | undefined; | ||
@@ -190,0 +212,0 @@ declare const attributifyRE: RegExp; |
@@ -127,3 +127,3 @@ var __defProp = Object.defineProperty; | ||
var hexRE = /^#?([\da-f]+)$/i; | ||
function hex2rgba(hex) { | ||
function hex2rgba(hex = "") { | ||
const [, body] = hex.match(hexRE) || []; | ||
@@ -426,2 +426,10 @@ if (!body) | ||
} | ||
constructCustomCSS(context, body, overrideSelector) { | ||
body = normalizeEntries(body); | ||
const [selector, entries, mediaQuery] = this.applyVariants([0, overrideSelector || context.rawSelector, body, context.variantHandlers]); | ||
const cssBody = `${selector}{${entriesToCss(entries)}}`; | ||
if (mediaQuery) | ||
return `${mediaQuery}{${cssBody}}`; | ||
return cssBody; | ||
} | ||
async parseUtil(input) { | ||
@@ -438,3 +446,4 @@ const { theme, rulesStaticMap, rulesDynamic, rulesSize } = this.config; | ||
generator: this, | ||
variantHandlers | ||
variantHandlers, | ||
constructCSS: (...args) => this.constructCustomCSS(context, ...args) | ||
}; | ||
@@ -441,0 +450,0 @@ for (let i = rulesSize; i >= 0; i--) { |
{ | ||
"name": "@unocss/core", | ||
"version": "0.4.11", | ||
"description": "", | ||
"keywords": [], | ||
"homepage": "https://github.com/antfu/unocss#readme", | ||
"version": "0.4.12", | ||
"description": "The instant on-demand Atomic CSS engine.", | ||
"keywords": [ | ||
"unocss", | ||
"atomic-css", | ||
"atomic-css-engine", | ||
"css", | ||
"tailwind", | ||
"windicss" | ||
], | ||
"homepage": "https://github.com/antfu/unocss/tree/main/packages/core#readme", | ||
"bugs": { | ||
@@ -12,3 +19,4 @@ "url": "https://github.com/antfu/unocss/issues" | ||
"type": "git", | ||
"url": "git+https://github.com/antfu/unocss.git" | ||
"url": "git+https://github.com/antfu/unocss.git", | ||
"directory": "packages/core" | ||
}, | ||
@@ -15,0 +23,0 @@ "funding": "https://github.com/sponsors/antfu", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43986
1300