UNPKG

unocss-preset-useful

Version:
293 lines (292 loc) 8.86 kB
import * as _unocss_core0 from "@unocss/core"; import { CSSObject, StaticShortcut } from "@unocss/core"; import { UserConfig } from "unocss"; import { AttributifyOptions } from "@unocss/preset-attributify"; import { IconsOptions } from "@unocss/preset-icons"; import { RemToPxOptions } from "@unocss/preset-rem-to-px"; import { TagifyOptions } from "@unocss/preset-tagify"; import { TypographyOptions } from "@unocss/preset-typography"; import { WebFontsOptions } from "@unocss/preset-web-fonts"; import { PresetWind3Options, Theme } from "@unocss/preset-wind3"; import { PresetWind4Options, Theme as Theme$1 } from "@unocss/preset-wind4"; import { CompileClassOptions } from "@unocss/transformer-compile-class"; import { TransformerDirectivesOptions } from "@unocss/transformer-directives"; import { TransformerVariantGroupOptions } from "@unocss/transformer-variant-group"; import { ThemeAnimation } from "@unocss/preset-mini"; //#region src/types.d.ts type CustomStaticShortcut = [string | string[], StaticShortcut[1]] | [string | string[], StaticShortcut[1], StaticShortcut[2]]; type CustomStaticShortcuts = CustomStaticShortcut[]; type Objectiable<T> = Record<string, T>; type CSSKeyframesRule = Objectiable<CSSObject>; interface UsefulExtends extends Exclude<UsefulTheme, 'extend'> { keyframes?: Record<string, CSSKeyframesRule>; /** * Different from the original, you can use the following formats: * * ```ts * { name : 'name duration timing-function iteration-count' } * ``` */ animation?: Objectiable<string>; } interface UsefulTheme extends Omit<Theme, 'container' | 'containers'>, Theme$1 { extend?: UsefulExtends; } interface PreflightOptions { /** * Enable reset styles * * @default false */ reset?: boolean; } interface PostprocessOptions { /** * Make all unitilities important. * * @default false */ important?: boolean | ImportantOptions; /** * Extract rgba color in css variable, default key name is `--un-color` * * Only works when `wind3` is enabled * * @default false */ unColor?: boolean | string; } type FilterPattern = Array<string | RegExp> | string | RegExp | null; interface ImportantOptions { /** * Make all unitilities important. * */ includes?: FilterPattern; /** * Make all unitilities important. * */ excludes?: FilterPattern; } interface UsefulOptions { /** * Enable built-in postprocess * * @default false */ postprocess?: boolean | PostprocessOptions; /** * Enable preflights * * @default true */ preflights?: boolean | PreflightOptions; shortcuts?: boolean | { /** * Enable default shortcuts * * @default true */ default?: boolean; }; /** * Improve theme to be more useful, and align with Tailwind theme configuration * * - Add `animation` to theme, Expand theme animation name usage * * [ name, duration, timing-function, iteration-count ] * * @example * * ```ts * theme: { * extend: { * animation: { * shape: 'shape 5s linear infinite' * }, * // ... * } * } * ``` * You can choose to use special symbols as placeholders, to indicate whether to inject this property into the uno theme * * - `*` Abandon injection * - `+` Injection, but the value is empty * * @example * * ```ts * theme: { * extend: { * animation: { * foo: 'foo 1s * 3', * bar: 'bar 1s +', * }, * // ... * } * } * ``` * */ theme?: UsefulTheme; /** * Enable the default preset for preset-wind3 * Only works when `presets` is not specified * * @about [@unocss/preset-wind3](https://unocss.dev/presets/wind3) * @default false */ wind3?: boolean | PresetWind3Options; /** * Enable the default preset for preset-wind4 * Only works when `presets` is not specified * * After v1.0.0, wind4 is the default preset * * @about [@unocss/preset-wind4](https://unocss.dev/presets/wind4) * @default true */ wind4?: boolean | PresetWind4Options; /** * Enable attributify mode and the options of it * Only works when `presets` is not specified * * @about [@unocss/preset-attributify](https://unocss.dev/presets/attributify) * @default false */ attributify?: boolean | AttributifyOptions; /** * Enable icons preset and the options of it * Only works when `presets` is not specified * * @about [@unocss/preset-icons](https://unocss.dev/presets/icons) * @default false */ icons?: boolean | IconsOptions; /** * Enable webFonts preset and the options of it * Only works when `presets` is not specified * * **Note:** Default by [`fontsource`](https://fontsource.org/) provider * * @about [@unocss/preset-web-fonts](https://unocss.dev/presets/web-fonts) * @default false */ webFonts?: boolean | WebFontsOptions; /** * Enable typography preset and the options of it * Only works when `presets` is not specified * * @about [@unocss/preset-typography](https://unocss.dev/presets/typography) * @default false */ typography?: boolean | TypographyOptions; /** * Enable tagify preset and the options of it * Only works when `presets` is not specified * * @about [@unocss/preset-tagify](https://unocss.dev/presets/tagify) * @default false */ tagify?: boolean | TagifyOptions; /** * Enable remToPx preset and the options of it * Only works when `presets` is not specified * * @about [@unocss/preset-rem-to-px](https://unocss.dev/presets/rem-to-px) * @default false */ remToPx?: boolean | RemToPxOptions; /** * Enable magicss preset * * @about [unocss-preset-magicss](https://github.com/unpreset/unocss-preset-magicss) * @default false */ magicss?: boolean; /** * Enable directives transformer and the options of it * * @about [@unocss/transformer-directives](https://unocss.dev/transformers/directives) * @default true */ directives?: boolean | TransformerDirectivesOptions; /** * Enables the variant group feature of Windi CSS for UnoCSS. * * @about [@unocss/transformer-variant-group](https://unocss.dev/transformers/variant-group) * @default true */ variantGroup?: boolean | TransformerVariantGroupOptions; /** * Compile group of classes into one class * * @about [@unocss/transformer-class-group](https://unocss.dev/transformers/compile-class) * @default false */ compileClass?: boolean | CompileClassOptions; } type DeepPartial<T> = { [P in keyof T]?: DeepPartial<T[P]> }; //#endregion //#region src/utils.d.ts declare const animationRegExp: RegExp; /** * Normalize custom animate usage to UnoCSS animations theme. * * ⚠️ You must strictly follow the following format. ⚠️ * * [ name, duration, timing-function, iteration-count ] * * If you use * as placeholder, it will be ignored. * * [name, duration, *, iteration-count] * * If you use + as placeholder, it will be replaced with empty string. * * [name, duration, +, iteration-count] * * @example * * { animate: ['spin 1s linear infinite'] } * * Will be transformd: * * { * animate: ['spin 1s linear infinite'], * durations: { * spin: '1s', * }, * timingFns: { * spin: 'linear', * }, * counts: { * spin: 'infinite', * }, * } */ declare function resolveAnimation(extend_animation: Objectiable<string>): { animation: ThemeAnimation; shortcuts: CustomStaticShortcuts; }; /** * Deep merge two objects. * @param original Original object * @param patch Patch object * @returns Merged object */ declare function deepMerge<T>(original: T, patch: DeepPartial<T>): T; declare function isObject(val: unknown): val is Record<any, any>; declare function getKeyframes(css: string): Record<string, Record<string, CSSObject>>; declare function cssObj2StrSync(style: Record<string, CSSObject>): string; declare function stringifyObj(obj: CSSObject): string; declare function cssObj2StrAsync(style: Record<string, CSSObject>): Promise<string>; declare function toArray<T>(val: T | T[]): T[]; declare function camelToHyphen(str: string): string; //#endregion //#region src/index.d.ts declare const presetUseful: _unocss_core0.PresetFactoryAwaitable<UsefulTheme, UsefulOptions>; declare function defineConfig<T extends object = UsefulTheme>(config: UserConfig<T>): UserConfig<T>; declare function defineUsefulConfig<T extends object = UsefulTheme>(options?: UsefulOptions, config?: UserConfig<T>): UserConfig<T>; //#endregion export { UsefulOptions, UsefulTheme, animationRegExp, camelToHyphen, cssObj2StrAsync, cssObj2StrSync, deepMerge, presetUseful as default, presetUseful, defineConfig, defineUsefulConfig, getKeyframes, isObject, resolveAnimation, stringifyObj, toArray };