版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

327 lines
12 KiB

  1. import { FullConfig, Extractor, ExtractorResultDetailed } from 'windicss/types/interfaces';
  2. import { generateCompletions } from 'windicss/utils';
  3. import Processor from 'windicss';
  4. import { WindiCssOptions, LoadConfigurationOptions } from '@windicss/config';
  5. export * from '@windicss/config';
  6. export { WindiCssOptions } from '@windicss/config';
  7. import * as magic_string from 'magic-string';
  8. export { Arrayable, partition, slash, toArray } from '@antfu/utils';
  9. declare const defaultAlias: Record<string, TagNames>;
  10. declare const preflightTags: string[];
  11. declare const htmlTags: readonly ["html", "body", "div", "a", "abbr", "address", "area", "article", "aside", "audio", "base", "basefont", "bdo", "blink", "blockquote", "br", "button", "canvas", "caption", "center", "col", "colgroup", "command", "comment", "datalist", "dd", "del", "details", "dir", "dl", "dt", "embed", "fieldset", "figure", "b", "big", "i", "small", "tt", "font", "footer", "form", "frame", "frameset", "head", "header", "hgroup", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "isindex", "iframe", "ilayer", "img", "input", "ins", "keygen", "keygen", "label", "layer", "legend", "li", "link", "map", "mark", "marquee", "menu", "meta", "meter", "multicol", "nav", "nobr", "noembed", "noframes", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "cite", "code", "dfn", "em", "kbd", "samp", "strong", "var", "plaintext", "pre", "progress", "q", "ruby", "script", "section", "select", "spacer", "span", "s", "strike", "style", "sub", "sup", "svg", "table", "tbody", "td", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "u", "ul", "video", "wbr", "wbr", "xmp"];
  12. type TagNames = (typeof htmlTags)[number];
  13. declare function defineConfig(config: FullConfig): FullConfig;
  14. interface TransformerOptions {
  15. include?: RegExp[];
  16. }
  17. type TransformerFunction = (code: string, id: string) => string | undefined | null;
  18. type Transformer<T extends TransformerOptions> = (options?: T) => TransformerFunction;
  19. declare function transformGroups(code: string, sourcemap?: boolean): {
  20. code: string;
  21. map: magic_string.SourceMap | undefined;
  22. } | null;
  23. declare function buildAliasTransformer(alias?: Record<string, string>): (code: string, sourcemap?: boolean) => {
  24. code: string;
  25. map: magic_string.SourceMap | undefined;
  26. } | null;
  27. interface UserOptions {
  28. /**
  29. * Options for windicss/tailwindcss.
  30. * Also accepts string as config file path.
  31. *
  32. * @default auto searching for `windi.config.ts` / `tailwind.config.js`
  33. */
  34. config?: WindiCssOptions | string;
  35. /**
  36. * A list of filename of paths to search of config files
  37. */
  38. configFiles?: string[];
  39. /**
  40. * Safe class names to be always included.
  41. *
  42. * @deprecated define this field in the windicss.config.ts instead
  43. */
  44. safelist?: string | (string | string[])[];
  45. /**
  46. * Class names to be always excluded.
  47. *
  48. * @deprecated define this field in the windicss.config.ts instead
  49. */
  50. blocklist?: string | (string | string[])[];
  51. /**
  52. * Enabled windicss preflight (a.k.a TailwindCSS style reset)
  53. *
  54. * @deprecated define this field in the windicss.config.ts instead
  55. * @default true
  56. */
  57. preflight?: boolean | {
  58. /**
  59. * Enable all the preflight regardless the template
  60. *
  61. * @deprecated define this field in the windicss.config.ts instead
  62. */
  63. enableAll?: boolean;
  64. /**
  65. * Enable all the preflight regardless the template
  66. *
  67. * @deprecated define this field in the windicss.config.ts instead
  68. */
  69. includeAll?: boolean;
  70. /**
  71. * Safelist to always included
  72. *
  73. * @deprecated define this field in the windicss.config.ts instead
  74. */
  75. safelist?: string | (string | string[])[];
  76. /**
  77. * Blocklist to always excluded
  78. *
  79. * @deprecated define this field in the windicss.config.ts instead
  80. */
  81. blocklist?: string | (string | string[])[];
  82. /**
  83. * Alias for resolving preflight
  84. */
  85. alias?: Record<string, TagNames>;
  86. /**
  87. * @default true
  88. * @deprecated define this field in the windicss.config.ts instead
  89. */
  90. includeBase?: boolean;
  91. /**
  92. * @default true
  93. * @deprecated define this field in the windicss.config.ts instead
  94. */
  95. includeGlobal?: boolean;
  96. /**
  97. * @default true
  98. * @deprecated define this field in the windicss.config.ts instead
  99. */
  100. includePlugin?: boolean;
  101. };
  102. /**
  103. * File paths will be resolved against this directory.
  104. *
  105. * @default process.cwd
  106. * @internal
  107. */
  108. root?: string;
  109. /**
  110. * Scan the files and extract the usage
  111. *
  112. * @default true
  113. */
  114. scan?: boolean | {
  115. /**
  116. * Auto scan on startup
  117. *
  118. * @default true
  119. */
  120. runOnStartup?: boolean;
  121. /**
  122. * Directories to search for classnames
  123. *
  124. * @default 'src'
  125. * @deprecated use `extract.include` in the windicss.config.ts instead
  126. */
  127. dirs?: string | string[];
  128. /**
  129. * File extension to search for classnames
  130. *
  131. * @default 'html', 'vue', 'md', 'mdx', 'pug', 'jsx', 'tsx', 'svelte', 'js', 'ts'
  132. * @deprecated use `extract.include` in the windicss.config.ts instead
  133. */
  134. fileExtensions?: string | string[];
  135. /**
  136. * Exclude globs
  137. *
  138. * @default []
  139. */
  140. exclude?: string | string[];
  141. /**
  142. * Include globs
  143. *
  144. * @default []
  145. */
  146. include?: string | string[];
  147. /**
  148. * Transformers to apply before doing extraction
  149. *
  150. * @default []
  151. */
  152. transformers?: TransformerFunction[];
  153. };
  154. /**
  155. * Transform CSS for `@apply` directive
  156. *
  157. * @default true
  158. */
  159. transformCSS?: boolean | 'pre' | 'post';
  160. /**
  161. * Transform groups like `hover:(bg-gray-100 font-medium)`
  162. *
  163. * @default true
  164. */
  165. transformGroups?: boolean;
  166. /**
  167. * Sort the genrate utilities
  168. *
  169. * @default true
  170. */
  171. sortUtilities?: boolean;
  172. /**
  173. * Callback before classes css generated
  174. */
  175. onBeforeGenerate?: (ctx: {
  176. classesPending: Set<string>;
  177. tagsPending: Set<string>;
  178. }) => void;
  179. /**
  180. * Callback when classes and/or tags are generated/changed
  181. */
  182. onGenerated?: (ctx: {
  183. classes: Set<string>;
  184. tags: Set<string>;
  185. }) => void;
  186. /**
  187. * Callback when the options are resolved. These are the plugin options and contain the windi config
  188. */
  189. onOptionsResolved?: (options: ResolvedOptions) => ResolvedOptions | void | Promise<ResolvedOptions | void>;
  190. /**
  191. * Callback when the windi config is resolved. Not to be confused with the options which are the top level way to
  192. * configure the util package
  193. */
  194. onConfigResolved?: (config: WindiCssOptions, configFilePath?: string) => WindiCssOptions | void | Promise<WindiCssOptions | void>;
  195. /**
  196. * Callback when the utils is initialized
  197. */
  198. onInitialized?: (utils: WindiPluginUtils) => void;
  199. }
  200. type WindiPluginUtilsOptions = Omit<LoadConfigurationOptions, 'config' | 'configFiles'> & {
  201. /**
  202. * Reuse existing plugin instance
  203. */
  204. utils?: WindiPluginUtils;
  205. };
  206. interface ResolvedOptions {
  207. config: WindiCssOptions;
  208. configFilePath: string | undefined;
  209. enableScan: boolean;
  210. enablePreflight: boolean;
  211. transformCSS: boolean | 'pre' | 'auto' | 'post';
  212. transformGroups: boolean;
  213. scanOptions: {
  214. fileExtensions: string[];
  215. dirs: string[];
  216. exclude: string[];
  217. include: string[];
  218. runOnStartup: boolean;
  219. transformers: TransformerFunction[];
  220. extractors: Extractor[];
  221. extraTransformTargets: {
  222. css: (string | ((path: string) => boolean))[];
  223. detect: (string | ((path: string) => boolean))[];
  224. };
  225. };
  226. preflightOptions: {
  227. includeBase: boolean;
  228. includeGlobal: boolean;
  229. includePlugin: boolean;
  230. includeAll: boolean;
  231. /**
  232. * @deprecated use includeAll
  233. */
  234. enableAll: boolean;
  235. safelist: Set<string>;
  236. blocklist: Set<string>;
  237. alias: Record<string, string>;
  238. };
  239. root: string;
  240. sortUtilities: boolean;
  241. safelist: Set<string>;
  242. blocklist: Set<string>;
  243. onBeforeGenerate: UserOptions['onBeforeGenerate'];
  244. onGenerated: UserOptions['onGenerated'];
  245. onConfigResolved: UserOptions['onConfigResolved'];
  246. onOptionsResolved: UserOptions['onOptionsResolved'];
  247. onInitialized: UserOptions['onInitialized'];
  248. }
  249. declare function DefaultExtractor(code: string, id?: string): ExtractorResultDetailed;
  250. declare function getDefaultExtractors(): Extractor[];
  251. declare function applyExtractors(code: string, id?: string, extractors?: Extractor[], defaultExtract?: typeof DefaultExtractor): Promise<ExtractorResultDetailed>;
  252. type CompletionsResult = ReturnType<typeof generateCompletions>;
  253. type LayerName = 'base' | 'utilities' | 'components';
  254. declare const SupportedLayers: readonly ["base", "utilities", "components"];
  255. interface LayerMeta {
  256. cssCache?: string;
  257. timestamp?: number;
  258. }
  259. interface TransformCssOptions {
  260. onLayerUpdated?: () => void;
  261. globaliseKeyframes?: boolean;
  262. }
  263. interface WindiPluginUtils {
  264. init(): Promise<Processor>;
  265. ensureInit(): Promise<Processor>;
  266. extractFile(code: string, id?: string, applyTransform?: boolean): Promise<boolean>;
  267. applyExtractors: typeof applyExtractors;
  268. generateCSS(layer?: LayerName): Promise<string>;
  269. getFiles(): Promise<string[]>;
  270. clearCache(clearAll?: boolean): void;
  271. transformCSS(css: string, id: string, transformOptions?: TransformCssOptions): string;
  272. transformGroups: typeof transformGroups;
  273. transformAlias: ReturnType<typeof buildAliasTransformer>;
  274. buildPendingStyles(): void;
  275. isDetectTarget(id: string): boolean;
  276. isScanTarget(id: string): boolean;
  277. isCssTransformTarget(id: string): boolean;
  278. isExcluded(id: string): boolean;
  279. scan(): Promise<void>;
  280. classesGenerated: Set<string>;
  281. classesPending: Set<string>;
  282. tagsGenerated: Set<string>;
  283. tagsPending: Set<string>;
  284. tagsAvailable: Set<string>;
  285. layersMeta: Record<LayerName, LayerMeta>;
  286. addClasses(classes: string[]): boolean;
  287. addTags(tags: string[]): boolean;
  288. getCompletions(): ReturnType<typeof generateCompletions>;
  289. lock(fn: () => Promise<void>): Promise<void>;
  290. waitLocks(): Promise<void>;
  291. initialized: boolean;
  292. options: ResolvedOptions;
  293. files: string[];
  294. globs: string[];
  295. processor: Processor;
  296. scanned: boolean;
  297. configFilePath: string | undefined;
  298. hasPending: boolean;
  299. }
  300. declare function createUtils(userOptions?: UserOptions | ResolvedOptions, utilsOptions?: WindiPluginUtilsOptions): WindiPluginUtils;
  301. declare function PugExtractor(code: string, id?: string): ExtractorResultDetailed;
  302. declare function SvelteExtractor(code: string, id?: string): ExtractorResultDetailed;
  303. type NestedArrayable<T> = T | (T | T[])[];
  304. declare function flattenArray<T>(v: NestedArrayable<T>): T[];
  305. declare function mergeArrays<T>(...args: (NestedArrayable<T> | undefined)[]): T[];
  306. declare function kebabCase(str: string): string;
  307. declare function include<T>(set: Set<T>, v: T[] | Set<T>): void;
  308. declare function exclude<T>(set: Set<T>, v: T[] | Set<T>): void;
  309. declare function escapeRegExp(str: string): string;
  310. declare function isResolvedOptions(options: UserOptions | ResolvedOptions): options is ResolvedOptions;
  311. declare function resolveOptions(options?: UserOptions | ResolvedOptions, utilsOptions?: WindiPluginUtilsOptions, loadConfigFile?: boolean): Promise<ResolvedOptions>;
  312. declare function mergeWindicssConfig(a: FullConfig, b: FullConfig): any;
  313. export { CompletionsResult, DefaultExtractor, LayerMeta, LayerName, NestedArrayable, PugExtractor, ResolvedOptions, SupportedLayers, SvelteExtractor, TagNames, TransformCssOptions, Transformer, TransformerFunction, TransformerOptions, UserOptions, WindiPluginUtils, WindiPluginUtilsOptions, applyExtractors, buildAliasTransformer, createUtils, defaultAlias, defineConfig, escapeRegExp, exclude, flattenArray, getDefaultExtractors, htmlTags, include, isResolvedOptions, kebabCase, mergeArrays, mergeWindicssConfig, preflightTags, resolveOptions, transformGroups };