import type { TailwindV4SourcePattern as SourceEntry, TailwindV4CssSource } from '@tailwindcss-mangle/engine/v4' import type { PackageResolvingOptions } from 'local-pkg' import type { ILengthUnitsPatchOptions } from '../types' export type CacheStrategy = 'merge' | 'overwrite' export type CacheDriver = 'file' | 'memory' | 'noop' /** * Configures how the Tailwind class cache is stored and where it lives on disk. */ export interface CacheOptions { /** Whether caching is enabled. */ enabled?: boolean /** Working directory used when resolving cache paths. */ cwd?: string /** Directory where cache files are written. */ dir?: string /** * Cache filename. Defaults to `class-cache.json` inside the derived cache folder * when omitted. */ file?: string /** Strategy used when merging new class lists with an existing cache. */ strategy?: CacheStrategy /** Backend used to persist the cache (`file`, `memory`, or `noop`). Defaults to `file`. */ driver?: CacheDriver } /** * Preferred options for extraction output behavior. */ export interface ExtractOptions { /** Whether to produce an output file. */ write?: boolean /** Optional absolute or relative path to the output file. */ file?: string /** Output format, defaults to JSON when omitted. */ format?: 'json' | 'lines' /** Pretty-print spacing (truthy value enables indentation). */ pretty?: number | boolean /** Whether to strip the universal selector (`*`) from the final list. */ removeUniversalSelector?: boolean } /** * Options controlling how Tailwind contexts are exposed during runtime patching. */ export interface ExposeContextOptions { /** Name of the property used to reference an exposed context. */ refProperty?: string } /** * Extends the built-in length-unit patch with custom defaults. */ export interface ExtendLengthUnitsOptions extends Partial { /** Enables or disables the length-unit patch. */ enabled?: boolean } /** * Preferred options for runtime patch behavior. */ export interface ApplyOptions { /** Whether patched files can be overwritten on disk. */ overwrite?: boolean /** Whether to expose runtime Tailwind contexts (or configure how they are exposed). */ exposeContext?: boolean | ExposeContextOptions /** Extends the length-unit patch or disables it entirely. */ extendLengthUnits?: false | ExtendLengthUnitsOptions } interface TailwindRuntimeOptionsBase { /** Path to a Tailwind config file when auto-detection is insufficient. */ config?: string /** Custom working directory used when resolving config-relative paths. */ cwd?: string /** Optional PostCSS plugin name to use instead of the default. */ postcssPlugin?: string } /** * Configuration specific to Tailwind CSS v2 patching flows. */ export interface TailwindV2Options extends TailwindRuntimeOptionsBase {} /** * Configuration specific to Tailwind CSS v3 patching flows. */ export interface TailwindV3Options extends TailwindRuntimeOptionsBase {} /** * Additional configuration specific to Tailwind CSS v4 extraction. */ export interface TailwindV4Options { /** Base directory used when resolving v4 content sources and configs. */ base?: string /** Raw CSS passed directly to the v4 design system. */ css?: string /** 构建器在 CSS 落盘前捕获的内存 CSS 入口。 */ cssSources?: TailwindV4CssSource[] /** Set of CSS entry files that should be scanned for `@config` directives. */ cssEntries?: string[] /** Overrides the content sources scanned by the oxide scanner. */ sources?: SourceEntry[] /** Enables UnoCSS-style bare arbitrary values such as `p-10%` and `p-2.5px`. */ bareArbitraryValues?: boolean | { /** Unit allow-list used when detecting bare arbitrary values. */ units?: string[] } | undefined } /** * High-level Tailwind patch configuration shared across versions. */ export interface TailwindCssOptions extends TailwindRuntimeOptionsBase { /** Explicit Tailwind CSS major version used by the current project. When omitted, the installed package version is inferred. */ version?: 2 | 3 | 4 /** Tailwind package name if the project uses a fork. */ packageName?: string /** Package resolution options forwarded to `local-pkg`. */ resolve?: PackageResolvingOptions /** Overrides applied when patching Tailwind CSS v2. */ v2?: TailwindV2Options /** Overrides applied when patching Tailwind CSS v3. */ v3?: TailwindV3Options /** Options specific to Tailwind CSS v4 patching. */ v4?: TailwindV4Options } /** * Root configuration consumed by the Tailwind CSS patch runner. */ export interface TailwindCssPatchOptions { /** * Base directory used when resolving Tailwind resources. * Defaults to `process.cwd()`. */ projectRoot?: string /** Preferred Tailwind runtime configuration. */ tailwindcss?: TailwindCssOptions /** Preferred patch toggles. */ apply?: ApplyOptions /** Preferred extraction output settings. */ extract?: ExtractOptions /** Optional function that filters final class names. */ filter?: (className: string) => boolean /** Cache configuration or boolean to enable/disable quickly. */ cache?: boolean | CacheOptions } /** * Stable shape for output configuration after normalization. */ export interface NormalizedOutputOptions { enabled: boolean file?: string format: 'json' | 'lines' pretty: number | false removeUniversalSelector: boolean } /** * Stable cache configuration used internally after defaults are applied. */ export interface NormalizedCacheOptions { enabled: boolean cwd: string dir: string file: string path: string strategy: CacheStrategy driver: CacheDriver } /** Tracks whether runtime contexts should be exposed and via which property. */ export interface NormalizedExposeContextOptions { enabled: boolean refProperty: string } /** Normalized representation of the extend-length-units feature flag. */ export interface NormalizedExtendLengthUnitsOptions extends ILengthUnitsPatchOptions { enabled: boolean } /** Normalized Tailwind v4 configuration consumed by runtime helpers. */ export interface NormalizedTailwindV4Options { base: string configuredBase?: string css?: string cssSources: TailwindV4CssSource[] cssEntries: string[] sources: SourceEntry[] hasUserDefinedSources: boolean bareArbitraryValues: false | { units?: string[] } | undefined } /** * Tailwind configuration ready for consumption by the runtime after normalization. */ export interface NormalizedTailwindConfigOptions extends TailwindRuntimeOptionsBase { packageName: string versionHint?: 2 | 3 | 4 resolve?: PackageResolvingOptions v2?: TailwindV2Options v3?: TailwindV3Options v4?: NormalizedTailwindV4Options } /** Grouped normalized feature flags. */ export interface NormalizedFeatureOptions { exposeContext: NormalizedExposeContextOptions extendLengthUnits: NormalizedExtendLengthUnitsOptions | null } /** Final normalized shape consumed throughout the patch runtime. */ export interface NormalizedTailwindCssPatchOptions { projectRoot: string overwrite: boolean tailwind: NormalizedTailwindConfigOptions features: NormalizedFeatureOptions output: NormalizedOutputOptions cache: NormalizedCacheOptions filter: (className: string) => boolean }