mirror of
https://github.com/Sevichecc/Urara-Blog.git
synced 2025-05-03 13:19:29 +08:00
772 lines
26 KiB
Text
772 lines
26 KiB
Text
import { LoadConfigResult } from 'unconfig';
|
|
import MagicString from 'magic-string';
|
|
|
|
declare type EventsMap = Record<string, any>;
|
|
interface DefaultEvents extends EventsMap {
|
|
[event: string]: (...args: any) => void;
|
|
}
|
|
interface Unsubscribe {
|
|
(): void;
|
|
}
|
|
declare class Emitter<Events extends EventsMap = DefaultEvents> {
|
|
/**
|
|
* Event names in keys and arrays with listeners in values.
|
|
*
|
|
* ```js
|
|
* emitter1.events = emitter2.events
|
|
* emitter2.events = { }
|
|
* ```
|
|
*/
|
|
events: Partial<{
|
|
[E in keyof Events]: Events[E][];
|
|
}>;
|
|
/**
|
|
* Add a listener for a given event.
|
|
*
|
|
* ```js
|
|
* const unbind = ee.on('tick', (tickType, tickDuration) => {
|
|
* count += 1
|
|
* })
|
|
*
|
|
* disable () {
|
|
* unbind()
|
|
* }
|
|
* ```
|
|
*
|
|
* @param event The event name.
|
|
* @param cb The listener function.
|
|
* @returns Unbind listener from event.
|
|
*/
|
|
on<K extends keyof Events>(this: this, event: K, cb: Events[K]): Unsubscribe;
|
|
/**
|
|
* Calls each of the listeners registered for a given event.
|
|
*
|
|
* ```js
|
|
* ee.emit('tick', tickType, tickDuration)
|
|
* ```
|
|
*
|
|
* @param event The event name.
|
|
* @param args The arguments for listeners.
|
|
*/
|
|
emit<K extends keyof Events>(this: this, event: K, ...args: Parameters<Events[K]>): void;
|
|
}
|
|
|
|
declare class UnoGenerator {
|
|
userConfig: UserConfig;
|
|
defaults: UserConfigDefaults;
|
|
version: string;
|
|
private _cache;
|
|
config: ResolvedConfig;
|
|
blocked: Set<string>;
|
|
parentOrders: Map<string, number>;
|
|
events: Emitter<{
|
|
config: (config: ResolvedConfig) => void;
|
|
}>;
|
|
constructor(userConfig?: UserConfig, defaults?: UserConfigDefaults);
|
|
setConfig(userConfig?: UserConfig, defaults?: UserConfigDefaults): void;
|
|
applyExtractors(code: string, id?: string, set?: Set<string>): Promise<Set<string>>;
|
|
makeContext(raw: string, applied: VariantMatchedResult): RuleContext<{}>;
|
|
parseToken(raw: string, alias?: string): Promise<StringifiedUtil[] | null | undefined>;
|
|
generate(input: string | Set<string> | string[], options?: GenerateOptions): Promise<GenerateResult>;
|
|
matchVariants(raw: string, current?: string): VariantMatchedResult;
|
|
private applyVariants;
|
|
constructCustomCSS(context: Readonly<RuleContext>, body: CSSObject | CSSEntries, overrideSelector?: string): string;
|
|
parseUtil(input: string | VariantMatchedResult, context: RuleContext, internal?: boolean): Promise<(ParsedUtil | RawUtil)[] | undefined>;
|
|
stringifyUtil(parsed?: ParsedUtil | RawUtil, context?: RuleContext): StringifiedUtil | undefined;
|
|
expandShortcut(input: string, context: RuleContext, depth?: number): [ShortcutValue[], RuleMeta | undefined] | undefined;
|
|
stringifyShortcuts(parent: VariantMatchedResult, context: RuleContext, expanded: ShortcutValue[], meta?: RuleMeta): Promise<StringifiedUtil[] | undefined>;
|
|
isBlocked(raw: string): boolean;
|
|
}
|
|
declare function createGenerator(config?: UserConfig, defaults?: UserConfigDefaults): UnoGenerator;
|
|
declare const regexScopePlaceholder: RegExp;
|
|
declare const hasScopePlaceholder: (css: string) => RegExpMatchArray | null;
|
|
declare function movePseudoElementsEnd(selector: string): string;
|
|
declare function toEscapedSelector(raw: string): string;
|
|
|
|
declare function escapeRegExp(string: string): string;
|
|
/**
|
|
* CSS Selector Escape
|
|
*/
|
|
declare function escapeSelector(str: string): string;
|
|
declare const e: typeof escapeSelector;
|
|
|
|
declare function normalizeCSSEntries(obj: string | CSSEntries | CSSObject): string | CSSEntries;
|
|
declare function normalizeCSSValues(obj: CSSValue | string | (CSSValue | string)[]): (string | CSSEntries)[];
|
|
declare function clearIdenticalEntries(entry: CSSEntries): CSSEntries;
|
|
declare function entriesToCss(arr?: CSSEntries): string;
|
|
declare function isObject(item: any): item is Record<string, any>;
|
|
declare function mergeDeep<T>(original: T, patch: DeepPartial<T>): T;
|
|
declare function clone<T>(val: T): T;
|
|
declare function isStaticRule(rule: Rule): rule is StaticRule;
|
|
declare function isStaticShortcut(sc: Shortcut): sc is StaticShortcut;
|
|
|
|
declare function toArray<T>(value?: T | T[]): T[];
|
|
declare function uniq<T>(value: T[]): T[];
|
|
declare function mergeSet<T>(target: Set<T>, append: Set<T>): Set<T>;
|
|
declare function isString(s: any): s is string;
|
|
|
|
declare const attributifyRE: RegExp;
|
|
declare const cssIdRE: RegExp;
|
|
declare const validateFilterRE: RegExp;
|
|
declare const CONTROL_SHORTCUT_NO_MERGE = "$$shortcut-no-merge";
|
|
declare function isAttributifySelector(selector: string): RegExpMatchArray | null;
|
|
declare function isValidSelector(selector?: string): selector is string;
|
|
declare function normalizeVariant(variant: Variant): VariantObject;
|
|
declare function isRawUtil(util: ParsedUtil | RawUtil | StringifiedUtil): util is RawUtil;
|
|
declare function notNull<T>(value: T | null | undefined): value is T;
|
|
declare function noop(): void;
|
|
|
|
declare class TwoKeyMap<K1, K2, V> {
|
|
_map: Map<K1, Map<K2, V>>;
|
|
get(key1: K1, key2: K2): V | undefined;
|
|
getFallback(key1: K1, key2: K2, fallback: V): V;
|
|
set(key1: K1, key2: K2, value: V): this;
|
|
has(key1: K1, key2: K2): boolean | undefined;
|
|
delete(key1: K1, key2: K2): boolean;
|
|
deleteTop(key1: K1): boolean;
|
|
map<T>(fn: (v: V, k1: K1, k2: K2) => T): T[];
|
|
}
|
|
declare class BetterMap<K, V> extends Map<K, V> {
|
|
map<R>(mapFn: (value: V, key: K) => R): R[];
|
|
}
|
|
|
|
declare function withLayer<T>(layer: string, rules: Rule<T>[]): Rule<T>[];
|
|
|
|
declare const regexClassGroup: RegExp;
|
|
declare function expandVariantGroup(str: string, seperators?: ('-' | ':')[]): string;
|
|
declare function expandVariantGroup(str: MagicString, seperators?: ('-' | ':')[]): MagicString;
|
|
|
|
declare function warnOnce(msg: string): void;
|
|
|
|
declare type ValueHandlerCallback = (str: string) => string | number | undefined;
|
|
declare type ValueHandler<K extends string> = {
|
|
[S in K]: ValueHandler<K>;
|
|
} & {
|
|
(str: string): string | undefined;
|
|
__options: {
|
|
sequence: K[];
|
|
};
|
|
};
|
|
declare function createValueHandler<K extends string>(handlers: Record<K, ValueHandlerCallback>): ValueHandler<K>;
|
|
|
|
declare type Awaitable<T> = T | Promise<T>;
|
|
declare type Arrayable<T> = T | T[];
|
|
declare type ArgumentType<T> = T extends ((...args: infer A) => any) ? A : never;
|
|
declare type Shift<T> = T extends [_: any, ...args: infer A] ? A : never;
|
|
declare type RestArgs<T> = Shift<ArgumentType<T>>;
|
|
declare type DeepPartial<T> = {
|
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
};
|
|
declare type FlatObjectTuple<T> = {
|
|
[K in keyof T]: T[K];
|
|
};
|
|
declare type PartialByKeys<T, K extends keyof T = keyof T> = FlatObjectTuple<Partial<Pick<T, Extract<keyof T, K>>> & Omit<T, K>>;
|
|
declare type RequiredByKey<T, K extends keyof T = keyof T> = FlatObjectTuple<Required<Pick<T, Extract<keyof T, K>>> & Omit<T, K>>;
|
|
declare type CSSObject = Record<string, string | number | undefined>;
|
|
declare type CSSEntries = [string, string | number | undefined][];
|
|
interface CSSColorValue {
|
|
type: string;
|
|
components: (string | number)[];
|
|
alpha: string | number | undefined;
|
|
}
|
|
declare type RGBAColorValue = [number, number, number, number] | [number, number, number];
|
|
interface ParsedColorValue {
|
|
/**
|
|
* Parsed color value.
|
|
*/
|
|
color?: string;
|
|
/**
|
|
* Parsed opacity value.
|
|
*/
|
|
opacity: string;
|
|
/**
|
|
* Color name.
|
|
*/
|
|
name: string;
|
|
/**
|
|
* Color scale, preferrably 000 - 999.
|
|
*/
|
|
no: string;
|
|
/**
|
|
* {@link CSSColorValue}
|
|
*/
|
|
cssColor: CSSColorValue | undefined;
|
|
/**
|
|
* Parsed alpha value from opacity
|
|
*/
|
|
alpha: string | number | undefined;
|
|
}
|
|
declare type PresetOptions = Record<string, any>;
|
|
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[];
|
|
/**
|
|
* The result of variant matching.
|
|
*/
|
|
variantMatch: VariantMatchedResult;
|
|
/**
|
|
* Constrcut a custom CSS rule.
|
|
* Variants and selector escaping will be handled automatically.
|
|
*/
|
|
constructCSS: (body: CSSEntries | CSSObject, overrideSelector?: string) => string;
|
|
/**
|
|
* Available only when `details` option is enabled.
|
|
*/
|
|
rules?: Rule[];
|
|
/**
|
|
* Available only when `details` option is enabled.
|
|
*/
|
|
shortcuts?: Shortcut[];
|
|
/**
|
|
* Available only when `details` option is enabled.
|
|
*/
|
|
variants?: Variant[];
|
|
}
|
|
interface VariantContext<Theme extends {} = {}> {
|
|
/**
|
|
* Unprocessed selector from user input.
|
|
*/
|
|
rawSelector: string;
|
|
/**
|
|
* UnoCSS generator instance
|
|
*/
|
|
generator: UnoGenerator;
|
|
/**
|
|
* The theme object
|
|
*/
|
|
theme: Theme;
|
|
}
|
|
interface ExtractorContext {
|
|
readonly original: string;
|
|
code: string;
|
|
id?: string;
|
|
}
|
|
interface PreflightContext<Theme extends {} = {}> {
|
|
/**
|
|
* UnoCSS generator instance
|
|
*/
|
|
generator: UnoGenerator;
|
|
/**
|
|
* The theme object
|
|
*/
|
|
theme: Theme;
|
|
}
|
|
interface Extractor {
|
|
name: string;
|
|
extract(ctx: ExtractorContext): Awaitable<Set<string> | undefined>;
|
|
order?: number;
|
|
}
|
|
interface RuleMeta {
|
|
/**
|
|
* The layer name of this rule.
|
|
* @default 'default'
|
|
*/
|
|
layer?: string;
|
|
/**
|
|
* Option to not merge this selector even if the body are the same.
|
|
* @default false
|
|
*/
|
|
noMerge?: boolean;
|
|
/**
|
|
* Fine tune sort
|
|
*/
|
|
sort?: number;
|
|
/**
|
|
* Templates to provide autocomplete suggestions
|
|
*/
|
|
autocomplete?: Arrayable<AutoCompleteTemplate>;
|
|
/**
|
|
* Matching prefix before this util
|
|
*/
|
|
prefix?: string;
|
|
/**
|
|
* Internal rules will only be matched for shortcuts but not the user code.
|
|
* @default false
|
|
*/
|
|
internal?: boolean;
|
|
}
|
|
declare type CSSValue = CSSObject | CSSEntries;
|
|
declare type CSSValues = CSSValue | CSSValue[];
|
|
declare type DynamicMatcher<Theme extends {} = {}> = ((match: RegExpMatchArray, context: Readonly<RuleContext<Theme>>) => Awaitable<CSSValue | string | (CSSValue | string)[] | undefined>);
|
|
declare type DynamicRule<Theme extends {} = {}> = [RegExp, DynamicMatcher<Theme>] | [RegExp, DynamicMatcher<Theme>, RuleMeta];
|
|
declare type StaticRule = [string, CSSObject | CSSEntries] | [string, CSSObject | CSSEntries, RuleMeta];
|
|
declare type Rule<Theme extends {} = {}> = DynamicRule<Theme> | StaticRule;
|
|
declare type DynamicShortcutMatcher<Theme extends {} = {}> = ((match: RegExpMatchArray, context: Readonly<RuleContext<Theme>>) => (string | ShortcutValue[] | undefined));
|
|
declare type StaticShortcut = [string, string | ShortcutValue[]] | [string, string | ShortcutValue[], RuleMeta];
|
|
declare type StaticShortcutMap = Record<string, string | ShortcutValue[]>;
|
|
declare type DynamicShortcut<Theme extends {} = {}> = [RegExp, DynamicShortcutMatcher<Theme>] | [RegExp, DynamicShortcutMatcher<Theme>, RuleMeta];
|
|
declare type UserShortcuts<Theme extends {} = {}> = StaticShortcutMap | (StaticShortcut | DynamicShortcut<Theme> | StaticShortcutMap)[];
|
|
declare type Shortcut<Theme extends {} = {}> = StaticShortcut | DynamicShortcut<Theme>;
|
|
declare type ShortcutValue = string | CSSValue;
|
|
declare type FilterPattern = ReadonlyArray<string | RegExp> | string | RegExp | null;
|
|
interface Preflight<Theme extends {} = {}> {
|
|
getCSS: (context: PreflightContext<Theme>) => Promise<string | undefined> | string | undefined;
|
|
layer?: string;
|
|
}
|
|
declare type BlocklistRule = string | RegExp;
|
|
interface VariantHandlerContext {
|
|
/**
|
|
* Rewrite the output selector. Often be used to append parents.
|
|
*/
|
|
prefix: string;
|
|
/**
|
|
* Rewrite the output selector. Often be used to append pesudo classes.
|
|
*/
|
|
selector: string;
|
|
/**
|
|
* Rewrite the output selector. Often be used to append pesudo elements.
|
|
*/
|
|
pseudo: string;
|
|
/**
|
|
* Rewrite the output css body. The input come in [key,value][] pairs.
|
|
*/
|
|
entries: CSSEntries;
|
|
/**
|
|
* Provide a parent selector(e.g. media query) to the output css.
|
|
*/
|
|
parent?: string;
|
|
/**
|
|
* Provide order to the `parent` parent selector within layer.
|
|
*/
|
|
parentOrder?: number;
|
|
/**
|
|
* Override layer to the output css.
|
|
*/
|
|
layer?: string;
|
|
/**
|
|
* Order in which the variant is sorted within single rule.
|
|
*/
|
|
sort?: number;
|
|
}
|
|
interface VariantHandler {
|
|
/**
|
|
* Callback to process the handler.
|
|
*/
|
|
handle?: (input: VariantHandlerContext, next: (input: VariantHandlerContext) => VariantHandlerContext) => VariantHandlerContext;
|
|
/**
|
|
* The result rewritten selector for the next round of matching
|
|
*/
|
|
matcher: string;
|
|
/**
|
|
* Order in which the variant is applied to selector.
|
|
*/
|
|
order?: number;
|
|
/**
|
|
* Rewrite the output selector. Often be used to append pesudo classes or parents.
|
|
*/
|
|
selector?: (input: string, body: CSSEntries) => string | undefined;
|
|
/**
|
|
* Rewrite the output css body. The input come in [key,value][] pairs.
|
|
*/
|
|
body?: (body: CSSEntries) => CSSEntries | undefined;
|
|
/**
|
|
* Provide a parent selector(e.g. media query) to the output css.
|
|
*/
|
|
parent?: string | [string, number] | undefined;
|
|
/**
|
|
* Order in which the variant is sorted within single rule.
|
|
*/
|
|
sort?: number;
|
|
/**
|
|
* Override layer to the output css.
|
|
*/
|
|
layer?: string | undefined;
|
|
}
|
|
declare type VariantFunction<Theme extends {} = {}> = (matcher: string, context: Readonly<VariantContext<Theme>>) => string | VariantHandler | undefined;
|
|
interface VariantObject<Theme extends {} = {}> {
|
|
/**
|
|
* The name of the variant.
|
|
*/
|
|
name?: string;
|
|
/**
|
|
* The entry function to match and rewrite the selector for futher processing.
|
|
*/
|
|
match: VariantFunction<Theme>;
|
|
/**
|
|
* Allows this variant to be used more than once in matching a single rule
|
|
*
|
|
* @default false
|
|
*/
|
|
multiPass?: boolean;
|
|
/**
|
|
* Custom function for auto complete
|
|
*/
|
|
autocomplete?: Arrayable<AutoCompleteFunction | AutoCompleteTemplate>;
|
|
}
|
|
declare type Variant<Theme extends {} = {}> = VariantFunction<Theme> | VariantObject<Theme>;
|
|
declare type Preprocessor = (matcher: string) => string | undefined;
|
|
declare type Postprocessor = (util: UtilObject) => void;
|
|
declare type ThemeExtender<T> = (theme: T) => void;
|
|
interface ConfigBase<Theme extends {} = {}> {
|
|
/**
|
|
* Rules to generate CSS utilities
|
|
*/
|
|
rules?: Rule<Theme>[];
|
|
/**
|
|
* Variants that preprocess the selectors,
|
|
* having the ability to rewrite the CSS object.
|
|
*/
|
|
variants?: Variant<Theme>[];
|
|
/**
|
|
* Similar to Windi CSS's shortcuts,
|
|
* allows you have create new utilities by combining existing ones.
|
|
*/
|
|
shortcuts?: UserShortcuts<Theme>;
|
|
/**
|
|
* Rules to exclude the selectors for your design system (to narrow down the possibilities).
|
|
* Combining `warnExcluded` options it can also helps you identify wrong usages.
|
|
*/
|
|
blocklist?: BlocklistRule[];
|
|
/**
|
|
* Utilities that always been included
|
|
*/
|
|
safelist?: string[];
|
|
/**
|
|
* Extractors to handle the source file and outputs possible classes/selectors
|
|
* Can be language-aware.
|
|
*/
|
|
extractors?: Extractor[];
|
|
/**
|
|
* Raw CSS injections.
|
|
*/
|
|
preflights?: Preflight<Theme>[];
|
|
/**
|
|
* Theme object for shared configuration between rules
|
|
*/
|
|
theme?: Theme;
|
|
/**
|
|
* Layer orders. Default to 0.
|
|
*/
|
|
layers?: Record<string, number>;
|
|
/**
|
|
* Custom function to sort layers.
|
|
*/
|
|
sortLayers?: (layers: string[]) => string[];
|
|
/**
|
|
* Preprocess the incoming utilities, return falsy value to exclude
|
|
*/
|
|
preprocess?: Arrayable<Preprocessor>;
|
|
/**
|
|
* Process the generate utils object
|
|
*/
|
|
postprocess?: Arrayable<Postprocessor>;
|
|
/**
|
|
* Custom functions to extend the theme object
|
|
*/
|
|
extendTheme?: Arrayable<ThemeExtender<Theme>>;
|
|
/**
|
|
* Additional options for auto complete
|
|
*/
|
|
autocomplete?: {
|
|
/**
|
|
* Custom functions / templates to provide autocomplete suggestions
|
|
*/
|
|
templates?: Arrayable<AutoCompleteFunction | AutoCompleteTemplate>;
|
|
/**
|
|
* Custom extractors to pickup possible classes and
|
|
* transform class-name style suggestions to the correct format
|
|
*/
|
|
extractors?: Arrayable<AutoCompleteExtractor>;
|
|
};
|
|
/**
|
|
* Expose internal details for debugging / inspecting
|
|
*
|
|
* Added `rules`, `shortcuts`, `variants` to the context and expose the context object in `StringifiedUtil`
|
|
*
|
|
* You don't usually need to set this.
|
|
*
|
|
* @default false
|
|
*/
|
|
details?: boolean;
|
|
}
|
|
declare type AutoCompleteTemplate = string;
|
|
declare type AutoCompleteFunction = (input: string) => Awaitable<string[]>;
|
|
interface AutoCompleteExtractorContext {
|
|
content: string;
|
|
cursor: number;
|
|
}
|
|
interface Replacement {
|
|
/**
|
|
* The range of the original text
|
|
*/
|
|
start: number;
|
|
end: number;
|
|
/**
|
|
* The text used to replace
|
|
*/
|
|
replacement: string;
|
|
}
|
|
interface SuggestResult {
|
|
/**
|
|
* The generated suggestions
|
|
*
|
|
* `[original, formatted]`
|
|
*/
|
|
suggestions: [string, string][];
|
|
/**
|
|
* The function to convert the selected suggestion back.
|
|
* Needs to pass in the original one.
|
|
*/
|
|
resolveReplacement: (suggestion: string) => Replacement;
|
|
}
|
|
interface AutoCompleteExtractorResult {
|
|
/**
|
|
* The extracted string
|
|
*/
|
|
extracted: string;
|
|
/**
|
|
* The function to convert the selected suggestion back
|
|
*/
|
|
resolveReplacement: (suggestion: string) => Replacement;
|
|
/**
|
|
* The function to format suggestions
|
|
*/
|
|
transformSuggestions?: (suggestions: string[]) => string[];
|
|
}
|
|
interface AutoCompleteExtractor {
|
|
name: string;
|
|
extract: (context: AutoCompleteExtractorContext) => Awaitable<AutoCompleteExtractorResult | null>;
|
|
order?: number;
|
|
}
|
|
interface Preset<Theme extends {} = {}> extends ConfigBase<Theme> {
|
|
name: string;
|
|
enforce?: 'pre' | 'post';
|
|
/**
|
|
* Preset options for other tools like IDE to consume
|
|
*/
|
|
options?: PresetOptions;
|
|
/**
|
|
* Apply prefix to all utilities and shortcuts
|
|
*/
|
|
prefix?: string;
|
|
/**
|
|
* Apply layer to all utilities and shortcuts
|
|
*/
|
|
layer?: string;
|
|
}
|
|
interface GeneratorOptions {
|
|
/**
|
|
* Merge utilities with the exact same body to save the file size
|
|
*
|
|
* @default true
|
|
*/
|
|
mergeSelectors?: boolean;
|
|
/**
|
|
* Emit warning when matched selectors are presented in blocklist
|
|
*
|
|
* @default true
|
|
*/
|
|
warn?: boolean;
|
|
}
|
|
interface UserOnlyOptions<Theme extends {} = {}> {
|
|
/**
|
|
* The theme object, will be merged with the theme provides by presets
|
|
*/
|
|
theme?: Theme;
|
|
/**
|
|
* Layout name of shortcuts
|
|
*
|
|
* @default 'shortcuts'
|
|
*/
|
|
shortcutsLayer?: string;
|
|
/**
|
|
* Presets
|
|
*/
|
|
presets?: (Preset<Theme> | Preset<Theme>[])[];
|
|
/**
|
|
* Environment mode
|
|
*
|
|
* @default 'build'
|
|
*/
|
|
envMode?: 'dev' | 'build';
|
|
}
|
|
interface UnocssPluginContext<Config extends UserConfig = UserConfig> {
|
|
ready: Promise<LoadConfigResult<Config>>;
|
|
uno: UnoGenerator;
|
|
/** All tokens scanned */
|
|
tokens: Set<string>;
|
|
/** Map for all module's raw content */
|
|
modules: BetterMap<string, string>;
|
|
/** Module IDs that been affected by UnoCSS */
|
|
affectedModules: Set<string>;
|
|
filter: (code: string, id: string) => boolean;
|
|
extract: (code: string, id?: string) => Promise<void>;
|
|
reloadConfig: () => Promise<LoadConfigResult<Config>>;
|
|
getConfig: () => Promise<Config>;
|
|
onReload: (fn: () => void) => void;
|
|
invalidate: () => void;
|
|
onInvalidate: (fn: () => void) => void;
|
|
root: string;
|
|
updateRoot: (root: string) => Promise<LoadConfigResult<Config>>;
|
|
}
|
|
interface SourceMap {
|
|
file?: string;
|
|
mappings?: string;
|
|
names?: string[];
|
|
sources?: string[];
|
|
sourcesContent?: string[];
|
|
version?: number;
|
|
}
|
|
interface TransformResult {
|
|
code: string;
|
|
map?: SourceMap | null;
|
|
etag?: string;
|
|
deps?: string[];
|
|
dynamicDeps?: string[];
|
|
}
|
|
declare type SourceCodeTransformerEnforce = 'pre' | 'post' | 'default';
|
|
interface SourceCodeTransformer {
|
|
name: string;
|
|
/**
|
|
* The order of transformer
|
|
*/
|
|
enforce?: SourceCodeTransformerEnforce;
|
|
/**
|
|
* Custom id filter, if not provided, the extraction filter will be applied
|
|
*/
|
|
idFilter?: (id: string) => boolean;
|
|
/**
|
|
* The transform function
|
|
*/
|
|
transform: (code: MagicString, id: string, ctx: UnocssPluginContext) => Awaitable<void>;
|
|
}
|
|
/**
|
|
* For other modules to aggregate the options
|
|
*/
|
|
interface PluginOptions {
|
|
/**
|
|
* Load from configs files
|
|
*
|
|
* set `false` to disable
|
|
*/
|
|
configFile?: string | false;
|
|
/**
|
|
* List of files that will also triggers config reloads
|
|
*/
|
|
configDeps?: string[];
|
|
/**
|
|
* Patterns that filter the files being extracted.
|
|
*/
|
|
include?: FilterPattern;
|
|
/**
|
|
* Patterns that filter the files NOT being extracted.
|
|
*/
|
|
exclude?: FilterPattern;
|
|
/**
|
|
* Custom transformers to the source code
|
|
*/
|
|
transformers?: SourceCodeTransformer[];
|
|
}
|
|
interface UserConfig<Theme extends {} = {}> extends ConfigBase<Theme>, UserOnlyOptions<Theme>, GeneratorOptions, PluginOptions {
|
|
}
|
|
interface UserConfigDefaults<Theme extends {} = {}> extends ConfigBase<Theme>, UserOnlyOptions<Theme> {
|
|
}
|
|
interface ResolvedConfig extends Omit<RequiredByKey<UserConfig, 'mergeSelectors' | 'theme' | 'rules' | 'variants' | 'layers' | 'extractors' | 'blocklist' | 'safelist' | 'preflights' | 'sortLayers'>, 'rules' | 'shortcuts' | 'autocomplete'> {
|
|
presets: Preset[];
|
|
shortcuts: Shortcut[];
|
|
variants: VariantObject[];
|
|
preprocess: Preprocessor[];
|
|
postprocess: Postprocessor[];
|
|
rulesSize: number;
|
|
rulesDynamic: (DynamicRule | undefined)[];
|
|
rulesStaticMap: Record<string, [number, CSSObject | CSSEntries, RuleMeta | undefined, Rule] | undefined>;
|
|
autocomplete: {
|
|
templates: (AutoCompleteFunction | AutoCompleteTemplate)[];
|
|
extractors: AutoCompleteExtractor[];
|
|
};
|
|
}
|
|
interface GenerateResult {
|
|
css: string;
|
|
layers: string[];
|
|
getLayer(name?: string): string | undefined;
|
|
getLayers(includes?: string[], excludes?: string[]): string;
|
|
matched: Set<string>;
|
|
}
|
|
declare type VariantMatchedResult = readonly [
|
|
raw: string,
|
|
current: string,
|
|
variantHandlers: VariantHandler[],
|
|
variants: Set<Variant>
|
|
];
|
|
declare type ParsedUtil = readonly [
|
|
index: number,
|
|
raw: string,
|
|
entries: CSSEntries,
|
|
meta: RuleMeta | undefined,
|
|
variantHandlers: VariantHandler[]
|
|
];
|
|
declare type RawUtil = readonly [
|
|
index: number,
|
|
rawCSS: string,
|
|
meta: RuleMeta | undefined
|
|
];
|
|
declare type StringifiedUtil = readonly [
|
|
index: number,
|
|
selector: string | undefined,
|
|
body: string,
|
|
parent: string | undefined,
|
|
meta: RuleMeta | undefined,
|
|
context: RuleContext | undefined
|
|
];
|
|
declare type PreparedRule = readonly [
|
|
selector: [string, number][],
|
|
body: string,
|
|
noMerge: boolean
|
|
];
|
|
interface UtilObject {
|
|
selector: string;
|
|
entries: CSSEntries;
|
|
parent: string | undefined;
|
|
layer: string | undefined;
|
|
sort: number | undefined;
|
|
}
|
|
interface GenerateOptions {
|
|
/**
|
|
* Filepath of the file being processed.
|
|
*/
|
|
id?: string;
|
|
/**
|
|
* Generate preflights (if defined)
|
|
*
|
|
* @default true
|
|
*/
|
|
preflights?: boolean;
|
|
/**
|
|
* Includes safelist
|
|
*/
|
|
safelist?: boolean;
|
|
/**
|
|
* Genreate minified CSS
|
|
* @default false
|
|
*/
|
|
minify?: boolean;
|
|
/**
|
|
* @expiremental
|
|
*/
|
|
scope?: string;
|
|
}
|
|
|
|
declare const extractorSplit: Extractor;
|
|
|
|
declare const extractorSvelte: Extractor;
|
|
|
|
export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValue, CSSValues, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, ParsedColorValue, ParsedUtil, PartialByKeys, PluginOptions, Postprocessor, Preflight, PreflightContext, PreparedRule, Preprocessor, Preset, PresetOptions, RGBAColorValue, RawUtil, Replacement, RequiredByKey, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, ShortcutValue, SourceCodeTransformer, SourceCodeTransformerEnforce, SourceMap, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, SuggestResult, ThemeExtender, TransformResult, TwoKeyMap, UnoGenerator, UnocssPluginContext, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, ValueHandler, ValueHandlerCallback, Variant, VariantContext, VariantFunction, VariantHandler, VariantHandlerContext, VariantMatchedResult, VariantObject, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, mergeDeep, mergeSet, movePseudoElementsEnd, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
|