unocss-preset-useful
Version:
My useful preset about unocss usage.
294 lines (288 loc) • 9.09 kB
text/typescript
import * as _unocss_core from '@unocss/core';
import { StaticShortcut, CSSObject, UserConfig } from '@unocss/core';
import { AttributifyOptions } from '@unocss/preset-attributify';
import { IconsOptions } from '@unocss/preset-icons';
import { Theme, ThemeAnimation } from '@unocss/preset-mini';
import { RemToPxOptions } from '@unocss/preset-rem-to-px';
import { TagifyOptions } from '@unocss/preset-tagify';
import { TypographyOptions } from '@unocss/preset-typography';
import { PresetUnoOptions } from '@unocss/preset-uno';
import { WebFontsOptions } from '@unocss/preset-web-fonts';
import { CompileClassOptions } from '@unocss/transformer-compile-class';
import { TransformerDirectivesOptions } from '@unocss/transformer-directives';
import { TransformerVariantGroupOptions } from '@unocss/transformer-variant-group';
import { PresetScrollbarDefaultOption } from 'unocss-preset-scrollbar';
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 Theme {
extend?: UsefulExtends;
}
interface PreflightOptions {
/**
* Enable reset styles
*
* @default true
*/
reset?: boolean;
}
type FilterPattern = Array<string | RegExp> | string | RegExp | null;
interface ImportantOptions {
/**
* Make all unitilities important.
*
*/
includes?: FilterPattern;
/**
* Make all unitilities important.
*
*/
excludes?: FilterPattern;
}
interface UsefulOptions {
/**
* Make all unitilities important.
*
* @default false
*/
important?: boolean | ImportantOptions;
/**
* Enable default shortcuts
*
* @default true
*/
enableDefaultShortcuts?: boolean;
/**
* Enable magic animations
*
* @default false
* @deprecated Use `magicss` option instead
*/
enableMagicAnimations?: boolean;
/**
* Enable reset styles
*
* @default true
*
* @deprecated Use `preflights.reset` instead
*/
enableResetStyles?: boolean;
/**
* Enable preflights
*
* @default true
*/
preflights?: boolean | PreflightOptions;
/**
* Extract rgba color in css variable
*
* @default false
*/
unColor?: boolean | string;
/**
* 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
* Only works when `presets` is not specified
*
* @about [@unocss/preset-uno](https://unocss.dev/presets/uno)
* @default true
*/
uno?: boolean | PresetUnoOptions;
/**
* 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 scrollbar preset and the options of it
* Only works when `presets` is not specified
*
* @about [unocss-preset-scrollbar](https://github.com/action-hong/unocss-preset-scrollbar)
* @default false
*/
scrollbar?: boolean | PresetScrollbarDefaultOption;
/**
* 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]>;
};
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;
declare const presetUseful: _unocss_core.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>;
export { type UsefulOptions, type UsefulTheme, animationRegExp, camelToHyphen, cssObj2StrAsync, cssObj2StrSync, deepMerge, presetUseful as default, defineConfig, defineUsefulConfig, getKeyframes, isObject, presetUseful, resolveAnimation, stringifyObj, toArray };