@unocss/core
Advanced tools
Comparing version 0.2.2 to 0.3.0
@@ -0,1 +1,22 @@ | ||
declare class UnoGenerator { | ||
userConfig: UserConfig; | ||
defaults: UserConfigDefaults; | ||
private _cache; | ||
config: ResolvedConfig; | ||
excluded: Set<string>; | ||
constructor(userConfig?: UserConfig, defaults?: UserConfigDefaults); | ||
setConfig(userConfig?: UserConfig, defaults?: UserConfigDefaults): void; | ||
applyExtractors(code: string, id?: string, set?: Set<string>): Promise<Set<string>>; | ||
generate(input: string | Set<string>, id?: string, scope?: string): Promise<GenerateResult>; | ||
matchVariants(raw: string): VariantMatchedResult; | ||
applyVariants(parsed: ParsedUtil, variantHandlers?: VariantHandler[], raw?: string): readonly [string, CSSEntries, string | undefined]; | ||
parseUtil(input: string | VariantMatchedResult): Promise<ParsedUtil | RawUtil | undefined>; | ||
stringifyUtil(parsed?: ParsedUtil | RawUtil): StringifiedUtil | undefined; | ||
expandShortcut(processed: string): string[] | undefined; | ||
stringifyShortcuts(parent: VariantMatchedResult, expanded: string[]): Promise<StringifiedUtil[]>; | ||
isExcluded(raw: string): boolean; | ||
} | ||
declare function createGenerator(config?: UserConfig, defaults?: UserConfigDefaults): UnoGenerator; | ||
declare const hasScopePlaceholder: (css: string) => RegExpMatchArray | null; | ||
declare type Awaitable<T> = T | Promise<T>; | ||
@@ -10,4 +31,11 @@ declare type ArgumentType<T> = T extends ((...args: infer A) => any) ? A : never; | ||
declare type CSSEntries = [string, string | number | undefined][]; | ||
interface RuleContext<Theme extends {} = {}> { | ||
rawSelector: string; | ||
currentSelector: string; | ||
generator: UnoGenerator; | ||
theme: Theme; | ||
variantHandlers: VariantHandler[]; | ||
} | ||
declare type Extractor = (code: string, id?: string) => Awaitable<Set<string> | undefined>; | ||
declare type DynamicRule<Theme extends {} = {}> = [RegExp, ((match: string[], theme: Theme) => Awaitable<CSSObject | CSSEntries | undefined>)]; | ||
declare type DynamicRule<Theme extends {} = {}> = [RegExp, ((match: string[], context: Readonly<RuleContext<Theme>>) => Awaitable<CSSObject | CSSEntries | string | undefined>)]; | ||
declare type StaticRule = [string, CSSObject | CSSEntries]; | ||
@@ -130,6 +158,10 @@ declare type Rule<Theme extends {} = {}> = DynamicRule<Theme> | StaticRule; | ||
]; | ||
declare type RawUtil = readonly [ | ||
number, | ||
string | ||
]; | ||
declare type StringifiedUtil = readonly [ | ||
number, | ||
string | undefined, | ||
string, | ||
string, | ||
string | undefined | ||
@@ -163,2 +195,3 @@ ]; | ||
declare function normalizeVariant(variant: Variant): VariantObject; | ||
declare function isRawUtil(util: ParsedUtil | RawUtil | StringifiedUtil): util is RawUtil; | ||
@@ -181,23 +214,2 @@ declare class TwoKeyMap<K1, K2, V> { | ||
declare class UnoGenerator { | ||
userConfig: UserConfig; | ||
defaults: UserConfigDefaults; | ||
private _cache; | ||
config: ResolvedConfig; | ||
excluded: Set<string>; | ||
constructor(userConfig?: UserConfig, defaults?: UserConfigDefaults); | ||
setConfig(userConfig?: UserConfig, defaults?: UserConfigDefaults): void; | ||
applyExtractors(code: string, id?: string, set?: Set<string>): Promise<Set<string>>; | ||
generate(input: string | Set<string>, id?: string, scope?: string): Promise<GenerateResult>; | ||
matchVariants(raw: string): VariantMatchedResult; | ||
applyVariants(parsed: ParsedUtil, variantHandlers?: VariantHandler[], raw?: string): readonly [string, CSSEntries, string | undefined]; | ||
parseUtil(input: string | VariantMatchedResult): Promise<ParsedUtil | undefined>; | ||
stringifyUtil(parsed?: ParsedUtil): StringifiedUtil | undefined; | ||
expandShortcut(processed: string): string[] | undefined; | ||
stringifyShortcuts(parent: VariantMatchedResult, expanded: string[]): Promise<StringifiedUtil[]>; | ||
isExcluded(raw: string): boolean; | ||
} | ||
declare function createGenerator(config?: UserConfig, defaults?: UserConfigDefaults): UnoGenerator; | ||
declare const hasScopePlaceholder: (css: string) => RegExpMatchArray | null; | ||
export { ArgumentType, Awaitable, BetterMap, CSSEntries, CSSObject, ConfigBase, DeepPartial, DynamicRule, DynamicShortcut, ExcludeRule, Extractor, GenerateResult, GeneratorOptions, ParsedUtil, Preset, ResolvedConfig, RestArgs, Rule, Shift, Shortcut, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, TwoKeyMap, UnoGenerator, UserConfig, UserConfigDefaults, UserShortcuts, Variant, VariantFunction, VariantHandler, VariantMatchedResult, VariantObject, attributifyRE, createGenerator, defineConfig, e, entriesToCss, escapeRegExp, escapeSelector, extractorSplit, hasScopePlaceholder, hex2rgba, isAttributifySelector, isObject, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, normalizeVariant, toArray, uniq, validateFilterRE }; | ||
export { ArgumentType, Awaitable, BetterMap, CSSEntries, CSSObject, ConfigBase, DeepPartial, DynamicRule, DynamicShortcut, ExcludeRule, Extractor, GenerateResult, GeneratorOptions, ParsedUtil, Preset, RawUtil, ResolvedConfig, RestArgs, Rule, RuleContext, Shift, Shortcut, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, TwoKeyMap, UnoGenerator, UserConfig, UserConfigDefaults, UserShortcuts, Variant, VariantFunction, VariantHandler, VariantMatchedResult, VariantObject, attributifyRE, createGenerator, defineConfig, e, entriesToCss, escapeRegExp, escapeSelector, extractorSplit, hasScopePlaceholder, hex2rgba, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, normalizeVariant, toArray, uniq, validateFilterRE }; |
@@ -26,2 +26,3 @@ var __defProp = Object.defineProperty; | ||
isObject: () => isObject, | ||
isRawUtil: () => isRawUtil, | ||
isStaticRule: () => isStaticRule, | ||
@@ -166,2 +167,5 @@ isStaticShortcut: () => isStaticShortcut, | ||
} | ||
function isRawUtil(util) { | ||
return util.length === 2; | ||
} | ||
@@ -358,8 +362,11 @@ // src/utils/map.ts | ||
const size = items.length; | ||
const sorted = items.sort((a, b) => a[0] - b[0] || a[1].localeCompare(b[1])).map((a) => [applyScope(a[1], scope), a[2]]); | ||
const sorted = items.sort((a, b) => { | ||
var _a; | ||
return a[0] - b[0] || ((_a = a[1]) == null ? void 0 : _a.localeCompare(b[1] || "")) || 0; | ||
}).map((a) => [a[1] ? applyScope(a[1], scope) : a[1], a[2]]); | ||
const rules = sorted.map(([selector, body], idx) => { | ||
if (this.config.mergeSelectors) { | ||
if (selector && this.config.mergeSelectors) { | ||
for (let i = size - 1; i > idx; i--) { | ||
const current = sorted[i]; | ||
if (current[1] === body) { | ||
if (current[0] && current[1] === body) { | ||
current[0] = `${selector},${current[0]}`; | ||
@@ -370,3 +377,3 @@ return null; | ||
} | ||
return `${selector}{${body}}`; | ||
return selector ? `${selector}{${body}}` : body; | ||
}).filter(Boolean).join("\n"); | ||
@@ -428,6 +435,13 @@ return query ? `${query}{ | ||
const { theme, rulesStaticMap, rulesDynamic, rulesSize } = this.config; | ||
const [raw, processed, variants] = typeof input === "string" ? this.matchVariants(input) : input; | ||
const [raw, processed, variantHandlers] = typeof input === "string" ? this.matchVariants(input) : input; | ||
const staticMatch = rulesStaticMap[processed]; | ||
if (staticMatch == null ? void 0 : staticMatch[1]) | ||
return [staticMatch[0], raw, normalizeEntries(staticMatch[1]), variants]; | ||
return [staticMatch[0], raw, normalizeEntries(staticMatch[1]), variantHandlers]; | ||
const context = { | ||
rawSelector: raw, | ||
currentSelector: processed, | ||
theme, | ||
generator: this, | ||
variantHandlers | ||
}; | ||
for (let i = rulesSize; i >= 0; i--) { | ||
@@ -441,5 +455,7 @@ const rule = rulesDynamic[i]; | ||
continue; | ||
const obj = await handler(match, theme); | ||
if (obj) | ||
return [i, raw, normalizeEntries(obj), variants]; | ||
const result = await handler(match, context); | ||
if (typeof result === "string") | ||
return [i, result]; | ||
if (result) | ||
return [i, raw, normalizeEntries(result), variantHandlers]; | ||
} | ||
@@ -450,2 +466,4 @@ } | ||
return; | ||
if (isRawUtil(parsed)) | ||
return [parsed[0], void 0, parsed[1], void 0]; | ||
const [selector, entries, mediaQuery] = this.applyVariants(parsed); | ||
@@ -536,2 +554,3 @@ const body = entriesToCss(entries); | ||
isObject, | ||
isRawUtil, | ||
isStaticRule, | ||
@@ -538,0 +557,0 @@ isStaticShortcut, |
{ | ||
"name": "@unocss/core", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
# @unocss/core | ||
The core engine of [UnoCSS](https://github.com/antfu/unocss) without any presets. Can be used as the engine of your own atomic-css framework. | ||
The core engine of [UnoCSS](https://github.com/antfu/unocss) without any presets. It can be used as the engine of your own atomic CSS framework. | ||
@@ -5,0 +5,0 @@ ## Usage |
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
42015
1260