UNPKG

transform-to-tailwindcss

Version:

🎨 Revolutionary CSS-to-TailwindCSS migration tool with surgical precision. Transform legacy stylesheets to utility-first classes instantly across Vue, React, Svelte, and Astro projects.

176 lines (167 loc) 4.95 kB
import { FilterPattern } from "@rollup/pluginutils"; import * as vite0 from "vite"; import * as vite1 from "vite"; import * as rollup2 from "rollup"; import * as rollup3 from "rollup"; import * as esbuild4 from "esbuild"; //#region src/type.d.ts type SuffixType = 'vue' | 'tsx' | 'html' | 'astro' | 'svelte'; interface Options { include?: FilterPattern; exclude?: FilterPattern; isRem?: boolean; debug?: boolean; collectClasses?: boolean; outputPath?: string; skipIfNoChanges?: boolean; } //#endregion //#region src/classCollector.d.ts /** * 类名收集器 - 用于收集所有转换生成的 Tailwind CSS 类名 */ declare class ClassCollector { private static instance; private collectedClasses; private outputPath; private isEnabled; private lastGeneratedClasses; private isGenerating; private buildEndCallCount; private skipIfNoChanges; private constructor(); static getInstance(): ClassCollector; /** * 验证输出路径是否为有效的.js、.ts、.cjs或.mjs文件 */ private validateOutputPath; /** * 启用类名收集功能 */ enable(outputPath?: string, skipIfNoChanges?: boolean): void; /** * 禁用类名收集功能 */ disable(): void; /** * 添加转换后的类名 */ addClasses(classes: string | string[], source?: string): void; /** * 从字符串中提取类名 */ private extractClasses; /** * 解析复杂的类名字符串,支持方括号内的复杂内容 */ private parseComplexClassString; /** * 验证是否是有效的 Tailwind CSS 类名 */ private isValidTailwindClass; /** * 获取所有收集的类名 */ getCollectedClasses(): string[]; /** * 清空收集的类名 */ clear(): void; /** * 检查类名是否发生变化 */ private hasClassesChanged; /** * 检查输出文件是否存在 */ private fileExists; /** * 生成safelist文件 */ generateSafelistFile(): Promise<void>; /** * 生成文件内容 */ private generateFileContent; /** * 添加构建完成的钩子 */ onBuildEnd(): void; /** * 重置构建状态 - 在新的构建开始时调用 */ resetBuildState(): void; } declare const classCollector: ClassCollector; //#endregion //#region src/transformAstro.d.ts interface Options$6 { filepath?: string; globalCss?: string; isRem?: boolean; debug?: boolean; collectClasses?: boolean; } declare function transformAstro(code: string, options: Options$6): Promise<string>; //#endregion //#region src/transformCode.d.ts interface Options$5 { filepath?: string; globalCss?: string; type?: SuffixType; isRem?: boolean; debug?: boolean; collectClasses?: boolean; } declare function transformCode(code: string, options?: Options$5): Promise<string>; //#endregion //#region src/transformHtml.d.ts interface Options$4 { isRem?: boolean; filepath?: string; globalCss?: string; debug?: boolean; collectClasses?: boolean; } declare function transformHtml(code: string, options?: Options$4): Promise<string>; //#endregion //#region src/transformJsx.d.ts interface Options$3 { filepath?: string; globalCss?: string; isRem?: boolean; debug?: boolean; collectClasses?: boolean; } declare function transformJsx(code: string, options?: Options$3): Promise<string>; //#endregion //#region src/transformSvelte.d.ts interface Options$2 { filepath?: string; globalCss?: string; isRem?: boolean; debug?: boolean; collectClasses?: boolean; } declare function transformSvelte(code: string, options?: Options$2): Promise<string>; //#endregion //#region src/transformVue.d.ts interface Options$1 { isJsx?: boolean; filepath?: string; globalCss?: string; isRem?: boolean; debug?: boolean; collectClasses?: boolean; } declare function transformVue(code: string, options?: Options$1): Promise<string>; //#endregion //#region src/unplugin.d.ts declare const viteTransformToTailwindcss: (options?: Options | undefined) => vite0.Plugin<any> | vite1.Plugin<any>[]; declare const rollupTransformToTailwindcss: (options?: Options | undefined) => rollup2.Plugin<any> | rollup3.Plugin<any>[]; declare const webpackTransformToTailwindcss: (options?: Options | undefined) => WebpackPluginInstance; declare const esbuildTransformToTailwindcss: (options?: Options | undefined) => esbuild4.Plugin; declare const rspackTransformToUnocss: (options?: Options | undefined) => RspackPluginInstance; declare const farmTransformToUnocss: (options?: Options | undefined) => JsPlugin; declare const rolldownTransformToUnocss: (options?: Options | undefined) => any; //#endregion export { Options, classCollector, esbuildTransformToTailwindcss, farmTransformToUnocss, rolldownTransformToUnocss, rollupTransformToTailwindcss, rspackTransformToUnocss, transformAstro, transformCode, transformHtml, transformJsx, transformSvelte, transformVue, viteTransformToTailwindcss, webpackTransformToTailwindcss };