UNPKG

@unocss/preset-web-fonts

Version:

Web Fonts support for Uno CSS

91 lines (88 loc) 2.43 kB
import { Awaitable, Arrayable } from '@unocss/core'; type WebFontsProviders = 'google' | 'bunny' | 'fontshare' | 'fontsource' | 'none' | Provider; interface WebFontMeta { name: string; weights?: (string | number)[]; italic?: boolean; variable?: Record<string, Partial<Axes>>; /** * Override the provider * @default <matches root config> */ provider?: WebFontsProviders; } interface WebFontProcessor { getCSS?: (fonts: ResolvedWebFontMeta[], providers: Provider[], getCSSDefault: (fonts: ResolvedWebFontMeta[], providers: Provider[]) => Awaitable<string>) => Awaitable<string | undefined>; transformCSS?: (css: string) => Promise<string | undefined>; } interface ResolvedWebFontMeta extends Omit<WebFontMeta, 'provider'> { provider: Provider; } interface WebFontsOptions { /** * Provider service of the web fonts * @default 'google' */ provider?: WebFontsProviders; /** * The fonts */ fonts?: Record<string, WebFontMeta | string | (WebFontMeta | string)[]>; /** * Extend fonts to the theme object * @default true */ extendTheme?: boolean; /** * Key for the theme object * * @default 'fontFamily' */ themeKey?: string; /** * Inline CSS @import() * * @default true */ inlineImports?: boolean; /** * Custom fetch function * * @default undefined */ customFetch?: (url: string) => Promise<any>; /** * Custom processor for the font CSS */ processors?: Arrayable<WebFontProcessor>; /** * Timeouts for fetching web fonts */ timeouts?: false | { /** * Timeout for printing warning message * * @default 500 */ warning?: number; /** * Timeout for failing the fetch * * @default 2000 */ failure?: number; }; } interface Provider { name: WebFontsProviders; getPreflight?: (fonts: WebFontMeta[]) => Awaitable<string | undefined>; getImportUrl?: (fonts: WebFontMeta[]) => string | undefined; getFontName?: (font: WebFontMeta) => string; } interface Axes { default: string; min: string; max: string; step: string; } export type { Axes as A, Provider as P, ResolvedWebFontMeta as R, WebFontMeta as W, WebFontsProviders as a, WebFontsOptions as b, WebFontProcessor as c };