UNPKG

@unocss/svelte-scoped

Version:

Use UnoCSS in a modular fashion with styles being stored only in the Svelte component they are used in: Vite plugin for apps, Svelte preprocessor for component libraries

63 lines (62 loc) 2.72 kB
import { UnocssPluginContext } from "@unocss/core"; import { PreprocessorGroup } from "svelte/types/compiler/preprocess"; //#region src/types.d.ts interface TransformClassesOptions { /** * Prefix for compiled class names. Distinct between `@unocss/svelte-scoped/vite` and `@unocss/svelte-scoped/preprocessor` to avoid bugs when using a component library built with `@unocss/svelte-scoped/preprocessor` in a project using `@unocss/svelte-scoped/vite`. * @default 'uno-' // `@unocss/svelte-scoped/vite` * @default 'usp-' // `@unocss/svelte-scoped/preprocessor` */ classPrefix?: string; /** * Add hash and combine recognized tokens (optimal for production); set false in dev mode for easy dev tools toggling to allow for design adjustments in the browser * @default true */ combine?: boolean; /** * Used to generate hash for compiled class names */ hashFn?: (str: string) => string; /** * Hash safelist classes (including shortcuts in the safelist) instead of passing them through as-is. * When false (default), safelist classes are left unhashed so they match the globally generated safelist CSS. * Set to true to restore the legacy behavior where shortcut classes in the safelist were still hashed. * @default false */ hashSafelistClasses?: boolean; } interface TransformApplyOptions { /** * Transform CSS custom properties (recommended for CSS syntax compatibility) or @apply directives. * * Pass `false` to disable. * * @default ['--at-apply', '@apply'] */ applyVariables?: string | string[] | false; } interface TransformDirectivesOptions { /** * Transform the `theme()` directive (recommended for CSS syntax compatibility). * * Disable for TailwindCss compatibility. * * Pass `false` to disable. * * @default true */ transformThemeDirective?: boolean; } //#endregion //#region src/_preprocess/types.d.ts interface UnocssSveltePreprocessOptions extends TransformClassesOptions, TransformApplyOptions, TransformDirectivesOptions { /** * UnoCSS config or path to config file. If not provided, will load unocss.config.ts/js. It's recommended to use the separate config file if you are having trouble with the UnoCSS extension in VSCode. */ configOrPath?: UserConfig | string; } //#endregion //#region src/_preprocess/index.d.ts declare function UnocssSveltePreprocess(options?: UnocssSveltePreprocessOptions, unoContextFromVite?: Pick<UnocssPluginContext, 'ready' | 'uno'>, isViteBuild?: () => boolean): PreprocessorGroup; //#endregion export { TransformDirectivesOptions as a, TransformClassesOptions as i, UnocssSveltePreprocessOptions as n, TransformApplyOptions as r, UnocssSveltePreprocess as t };