UNPKG

tailwindcss-patch

Version:

patch tailwindcss for exposing context and extract classes

156 lines (145 loc) 5.38 kB
import { PatchUserConfig } from '@tailwindcss-mangle/config'; export { TailwindcssUserConfig, defineConfig } from '@tailwindcss-mangle/config'; import { PackageJson } from 'pkg-types'; import { Node, Rule } from 'postcss'; import { Config } from 'tailwindcss'; import { GlobEntry } from '@tailwindcss/oxide'; import * as consola from 'consola'; type CacheStrategy = 'merge' | 'overwrite'; interface PackageInfo { name: string; version: string | undefined; rootPath: string; packageJsonPath: string; packageJson: PackageJson; } interface CacheOptions { dir?: string; cwd?: string; file?: string; strategy?: CacheStrategy; } interface InternalCacheOptions extends CacheOptions { enable?: boolean; } interface PatchOptions extends PatchUserConfig { overwrite?: boolean; paths?: string[]; basedir?: string; applyPatches?: { exportContext?: boolean; extendLengthUnits?: boolean | ILengthUnitsPatchOptions; }; filter?: (className: string) => boolean; } interface InternalPatchOptions extends PatchOptions { version?: string; } interface TailwindcssPatcherOptions { cache?: CacheOptions | boolean; patch?: PatchOptions; } type TailwindcssClassCache = Map<string, ({ layer: string; options: Record<string, any>; sort: Record<string, any>; } | Rule)[]>; interface TailwindcssRuntimeContext { applyClassCache: Map<any, any>; candidateRuleCache: Map<string, Set<[ { arbitrary: any; index: any; layer: string; options: any[]; parallelIndex: any; parentLayer: string; variants: any; }, Node ]>>; candidateRuleMap: Map<string | string, [object, Node][]>; changedContent: any[]; classCache: TailwindcssClassCache; disposables: any[]; getClassList: Function; getClassOrder: Function; getVariants: Function; markInvalidUtilityCandidate: Function; markInvalidUtilityNode: Function; notClassCache: Set<string>; offsets: { layerPositions: object; offsets: object; reservedVariantBits: any; variantOffsets: Map<string, any>; }; postCssNodeCache: Map<object, [Node]>; ruleCache: Set<[object, Node]>; stylesheetCache: Record<string, Set<any>>; tailwindConfig: Config; userConfigPath: string | null; variantMap: Map<string, [[object, Function]]>; variantOptions: Map<string, object>; } type DeepRequired<T> = { [K in keyof T]: Required<DeepRequired<T[K]>>; }; interface ILengthUnitsPatchOptions { units: string[]; lengthUnitsFilePath?: string; variableName?: string; overwrite?: boolean; destPath?: string; } declare function getCacheOptions(options?: CacheOptions | boolean): InternalCacheOptions; declare class CacheManager { options: Required<CacheOptions> & { filename: string; }; constructor(options?: CacheOptions); getOptions(options?: CacheOptions): Required<CacheOptions> & { filename: string; }; write(data: Set<string>): Promise<string | undefined>; read(): Promise<Set<string>>; } interface ExtractValidCandidatesOption { sources?: GlobEntry[]; base?: string; css?: string; } declare function extractValidCandidates(options?: ExtractValidCandidatesOption): Promise<string[]>; declare class TailwindcssPatcher { rawOptions: TailwindcssPatcherOptions; cacheOptions: InternalCacheOptions; patchOptions: InternalPatchOptions; patch: () => void; cacheManager: CacheManager; packageInfo: PackageInfo; majorVersion?: number; filter?: (className: string) => boolean; constructor(options?: TailwindcssPatcherOptions); setCache(set: Set<string>): Promise<string | undefined> | undefined; getCache(): Promise<Set<string>>; getContexts(): TailwindcssRuntimeContext[]; getClassCaches(): TailwindcssClassCache[]; getClassCacheSet(): Promise<Set<string>>; /** * @description 在多个 tailwindcss 上下文时,这个方法将被执行多次,所以策略上应该使用 append */ getClassSet(): Promise<Set<string>>; extract(): Promise<{ filename: string; classList: string[]; } | undefined>; extractValidCandidates: typeof extractValidCandidates; } declare function monkeyPatchForExposingContextV3(twDir: string, opt: InternalPatchOptions): Record<string, any> | undefined; declare function monkeyPatchForExposingContextV2(twDir: string, opt: InternalPatchOptions): Record<string, any>; declare function monkeyPatchForSupportingCustomUnit(rootDir: string, options?: Partial<ILengthUnitsPatchOptions>): { [x: string]: string; } | undefined; declare function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): Record<string, any> | undefined; declare const logger: consola.ConsolaInstance; export { CacheManager, type CacheOptions, type CacheStrategy, type DeepRequired, type ILengthUnitsPatchOptions, type InternalCacheOptions, type InternalPatchOptions, type PackageInfo, type PatchOptions, type TailwindcssClassCache, TailwindcssPatcher, type TailwindcssPatcherOptions, type TailwindcssRuntimeContext, getCacheOptions, internalPatch, logger, monkeyPatchForExposingContextV2, monkeyPatchForExposingContextV3, monkeyPatchForSupportingCustomUnit };