index.d.mts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import { AstNode as AstNode$1 } from './ast';
  2. import { Candidate, Variant } from './candidate';
  3. import { compileAstNodes } from './compile';
  4. import { ClassEntry, VariantEntry, CanonicalizeOptions } from './intellisense';
  5. import { Theme } from './theme';
  6. import { Utilities } from './utilities';
  7. import { Variants } from './variants';
  8. import * as tailwindcss from 'tailwindcss';
  9. import { Polyfills, Features } from 'tailwindcss';
  10. export { Features, Polyfills } from 'tailwindcss';
  11. declare const DEBUG: boolean;
  12. declare const env_DEBUG: typeof DEBUG;
  13. declare namespace env {
  14. export { env_DEBUG as DEBUG };
  15. }
  16. declare const enum CompileAstFlags {
  17. None = 0,
  18. RespectImportant = 1
  19. }
  20. type DesignSystem = {
  21. theme: Theme;
  22. utilities: Utilities;
  23. variants: Variants;
  24. invalidCandidates: Set<string>;
  25. important: boolean;
  26. getClassOrder(classes: string[]): [string, bigint | null][];
  27. getClassList(): ClassEntry[];
  28. getVariants(): VariantEntry[];
  29. parseCandidate(candidate: string): Readonly<Candidate>[];
  30. parseVariant(variant: string): Readonly<Variant> | null;
  31. compileAstNodes(candidate: Candidate, flags?: CompileAstFlags): ReturnType<typeof compileAstNodes>;
  32. printCandidate(candidate: Candidate): string;
  33. printVariant(variant: Variant): string;
  34. getVariantOrder(): Map<Variant, number>;
  35. resolveThemeValue(path: string, forceInline?: boolean): string | undefined;
  36. trackUsedVariables(raw: string): void;
  37. canonicalizeCandidates(candidates: string[], options?: CanonicalizeOptions): string[];
  38. candidatesToCss(classes: string[]): (string | null)[];
  39. candidatesToAst(classes: string[]): AstNode$1[][];
  40. storage: Record<symbol, unknown>;
  41. };
  42. /**
  43. * The source code for one or more nodes in the AST
  44. *
  45. * This generally corresponds to a stylesheet
  46. */
  47. interface Source {
  48. /**
  49. * The path to the file that contains the referenced source code
  50. *
  51. * If this references the *output* source code, this is `null`.
  52. */
  53. file: string | null;
  54. /**
  55. * The referenced source code
  56. */
  57. code: string;
  58. }
  59. /**
  60. * The file and offsets within it that this node covers
  61. *
  62. * This can represent either:
  63. * - A location in the original CSS which caused this node to be created
  64. * - A location in the output CSS where this node resides
  65. */
  66. type SourceLocation = [source: Source, start: number, end: number];
  67. /**
  68. * Line offset tables are the key to generating our source maps. They allow us
  69. * to store indexes with our AST nodes and later convert them into positions as
  70. * when given the source that the indexes refer to.
  71. */
  72. /**
  73. * A position in source code
  74. *
  75. * https://tc39.es/ecma426/#sec-position-record-type
  76. */
  77. interface Position {
  78. /** The line number, one-based */
  79. line: number;
  80. /** The column/character number, one-based */
  81. column: number;
  82. }
  83. interface OriginalPosition extends Position {
  84. source: DecodedSource;
  85. }
  86. /**
  87. * A "decoded" sourcemap
  88. *
  89. * @see https://tc39.es/ecma426/#decoded-source-map-record
  90. */
  91. interface DecodedSourceMap {
  92. file: string | null;
  93. sources: DecodedSource[];
  94. mappings: DecodedMapping[];
  95. }
  96. /**
  97. * A "decoded" source
  98. *
  99. * @see https://tc39.es/ecma426/#decoded-source-record
  100. */
  101. interface DecodedSource {
  102. url: string | null;
  103. content: string | null;
  104. ignore: boolean;
  105. }
  106. /**
  107. * A "decoded" mapping
  108. *
  109. * @see https://tc39.es/ecma426/#decoded-mapping-record
  110. */
  111. interface DecodedMapping {
  112. originalPosition: OriginalPosition | null;
  113. generatedPosition: Position;
  114. name: string | null;
  115. }
  116. type StyleRule = {
  117. kind: 'rule';
  118. selector: string;
  119. nodes: AstNode[];
  120. src?: SourceLocation;
  121. dst?: SourceLocation;
  122. };
  123. type AtRule = {
  124. kind: 'at-rule';
  125. name: string;
  126. params: string;
  127. nodes: AstNode[];
  128. src?: SourceLocation;
  129. dst?: SourceLocation;
  130. };
  131. type Declaration = {
  132. kind: 'declaration';
  133. property: string;
  134. value: string | undefined;
  135. important: boolean;
  136. src?: SourceLocation;
  137. dst?: SourceLocation;
  138. };
  139. type Comment = {
  140. kind: 'comment';
  141. value: string;
  142. src?: SourceLocation;
  143. dst?: SourceLocation;
  144. };
  145. type Context = {
  146. kind: 'context';
  147. context: Record<string, string | boolean>;
  148. nodes: AstNode[];
  149. src?: undefined;
  150. dst?: undefined;
  151. };
  152. type AtRoot = {
  153. kind: 'at-root';
  154. nodes: AstNode[];
  155. src?: undefined;
  156. dst?: undefined;
  157. };
  158. type AstNode = StyleRule | AtRule | Declaration | Comment | Context | AtRoot;
  159. type Resolver = (id: string, base: string) => Promise<string | false | undefined>;
  160. interface CompileOptions {
  161. base: string;
  162. from?: string;
  163. onDependency: (path: string) => void;
  164. shouldRewriteUrls?: boolean;
  165. polyfills?: Polyfills;
  166. customCssResolver?: Resolver;
  167. customJsResolver?: Resolver;
  168. }
  169. declare function compileAst(ast: AstNode[], options: CompileOptions): Promise<{
  170. sources: {
  171. base: string;
  172. pattern: string;
  173. negated: boolean;
  174. }[];
  175. root: "none" | {
  176. base: string;
  177. pattern: string;
  178. } | null;
  179. features: Features;
  180. build(candidates: string[]): AstNode[];
  181. }>;
  182. declare function compile(css: string, options: CompileOptions): Promise<{
  183. sources: {
  184. base: string;
  185. pattern: string;
  186. negated: boolean;
  187. }[];
  188. root: "none" | {
  189. base: string;
  190. pattern: string;
  191. } | null;
  192. features: Features;
  193. build(candidates: string[]): string;
  194. buildSourceMap(): tailwindcss.DecodedSourceMap;
  195. }>;
  196. declare function __unstable__loadDesignSystem(css: string, { base }: {
  197. base: string;
  198. }): Promise<DesignSystem>;
  199. declare function loadModule(id: string, base: string, onDependency: (path: string) => void, customJsResolver?: Resolver): Promise<{
  200. path: string;
  201. base: string;
  202. module: any;
  203. }>;
  204. declare class Instrumentation implements Disposable {
  205. #private;
  206. private defaultFlush;
  207. constructor(defaultFlush?: (message: string) => undefined);
  208. hit(label: string): void;
  209. start(label: string): void;
  210. end(label: string): void;
  211. reset(): void;
  212. report(flush?: (message: string) => undefined): void;
  213. [Symbol.dispose](): void;
  214. }
  215. declare function normalizePath(originalPath: string): string;
  216. interface OptimizeOptions {
  217. /**
  218. * The file being transformed
  219. */
  220. file?: string;
  221. /**
  222. * Enabled minified output
  223. */
  224. minify?: boolean;
  225. /**
  226. * The output source map before optimization
  227. *
  228. * If omitted a resulting source map will not be available
  229. */
  230. map?: string;
  231. }
  232. interface TransformResult {
  233. code: string;
  234. map: string | undefined;
  235. }
  236. declare function optimize(input: string, { file, minify, map }?: OptimizeOptions): TransformResult;
  237. interface SourceMap {
  238. readonly raw: string;
  239. readonly inline: string;
  240. comment(url: string): string;
  241. }
  242. declare function toSourceMap(map: DecodedSourceMap | string): SourceMap;
  243. export { type CompileOptions, type DecodedSource, type DecodedSourceMap, Instrumentation, type OptimizeOptions, type Resolver, type SourceMap, type TransformResult, __unstable__loadDesignSystem, compile, compileAst, env, loadModule, normalizePath, optimize, toSourceMap };