lib.d.mts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. import { S as SourceLocation, U as UserConfig, P as Plugin } from './types-CJYAW1ql.mjs';
  2. import { V as Variant, C as Candidate } from './resolve-config-QUZ9b-Gn.mjs';
  3. import './colors.mjs';
  4. declare const enum ThemeOptions {
  5. NONE = 0,
  6. INLINE = 1,
  7. REFERENCE = 2,
  8. DEFAULT = 4,
  9. STATIC = 8,
  10. USED = 16
  11. }
  12. declare class Theme {
  13. #private;
  14. private values;
  15. private keyframes;
  16. prefix: string | null;
  17. constructor(values?: Map<string, {
  18. value: string;
  19. options: ThemeOptions;
  20. src: Declaration["src"];
  21. }>, keyframes?: Set<AtRule>);
  22. get size(): number;
  23. add(key: string, value: string, options?: ThemeOptions, src?: Declaration['src']): void;
  24. keysInNamespaces(themeKeys: Iterable<ThemeKey>): string[];
  25. get(themeKeys: ThemeKey[]): string | null;
  26. hasDefault(key: string): boolean;
  27. getOptions(key: string): ThemeOptions;
  28. entries(): IterableIterator<[string, {
  29. value: string;
  30. options: ThemeOptions;
  31. src: Declaration["src"];
  32. }]> | [string, {
  33. value: string;
  34. options: ThemeOptions;
  35. src: Declaration["src"];
  36. }][];
  37. prefixKey(key: string): string;
  38. clearNamespace(namespace: string, clearOptions: ThemeOptions): void;
  39. markUsedVariable(themeKey: string): boolean;
  40. resolve(candidateValue: string | null, themeKeys: ThemeKey[], options?: ThemeOptions): string | null;
  41. resolveValue(candidateValue: string | null, themeKeys: ThemeKey[]): string | null;
  42. resolveWith(candidateValue: string, themeKeys: ThemeKey[], nestedKeys?: `--${string}`[]): [string, Record<string, string>] | null;
  43. namespace(namespace: string): Map<string | null, string>;
  44. addKeyframes(value: AtRule): void;
  45. getKeyframes(): AtRule[];
  46. }
  47. type ThemeKey = `--${string}`;
  48. type VariantFn<T extends Variant['kind']> = (rule: Rule, variant: Extract<Variant, {
  49. kind: T;
  50. }>) => null | void;
  51. type CompareFn = (a: Variant, z: Variant) => number;
  52. declare const enum Compounds {
  53. Never = 0,
  54. AtRules = 1,
  55. StyleRules = 2
  56. }
  57. declare class Variants {
  58. compareFns: Map<number, CompareFn>;
  59. variants: Map<string, {
  60. kind: Variant["kind"];
  61. order: number;
  62. applyFn: VariantFn<any>;
  63. compoundsWith: Compounds;
  64. compounds: Compounds;
  65. }>;
  66. private completions;
  67. /**
  68. * Registering a group of variants should result in the same sort number for
  69. * all the variants. This is to ensure that the variants are applied in the
  70. * correct order.
  71. */
  72. private groupOrder;
  73. /**
  74. * Keep track of the last sort order instead of using the size of the map to
  75. * avoid unnecessarily skipping order numbers.
  76. */
  77. private lastOrder;
  78. static(name: string, applyFn: VariantFn<'static'>, { compounds, order }?: {
  79. compounds?: Compounds;
  80. order?: number;
  81. }): void;
  82. fromAst(name: string, ast: AstNode[], designSystem: DesignSystem): void;
  83. functional(name: string, applyFn: VariantFn<'functional'>, { compounds, order }?: {
  84. compounds?: Compounds;
  85. order?: number;
  86. }): void;
  87. compound(name: string, compoundsWith: Compounds, applyFn: VariantFn<'compound'>, { compounds, order }?: {
  88. compounds?: Compounds;
  89. order?: number;
  90. }): void;
  91. group(fn: () => void, compareFn?: CompareFn): void;
  92. has(name: string): boolean;
  93. get(name: string): {
  94. kind: Variant["kind"];
  95. order: number;
  96. applyFn: VariantFn<any>;
  97. compoundsWith: Compounds;
  98. compounds: Compounds;
  99. } | undefined;
  100. kind(name: string): "static" | "arbitrary" | "functional" | "compound";
  101. compoundsWith(parent: string, child: string | Variant): boolean;
  102. suggest(name: string, suggestions: () => string[]): void;
  103. getCompletions(name: string): string[];
  104. compare(a: Variant | null, z: Variant | null): number;
  105. keys(): IterableIterator<string>;
  106. entries(): IterableIterator<[string, {
  107. kind: Variant["kind"];
  108. order: number;
  109. applyFn: VariantFn<any>;
  110. compoundsWith: Compounds;
  111. compounds: Compounds;
  112. }]>;
  113. private set;
  114. private nextOrder;
  115. }
  116. declare function compileAstNodes(candidate: Candidate, designSystem: DesignSystem, flags: CompileAstFlags): {
  117. node: AstNode;
  118. propertySort: {
  119. order: number[];
  120. count: number;
  121. };
  122. }[];
  123. interface CanonicalizeOptions {
  124. /**
  125. * The root font size in pixels. If provided, `rem` values will be normalized
  126. * to `px` values.
  127. *
  128. * E.g.: `mt-[16px]` with `rem: 16` will become `mt-4` (assuming `--spacing: 0.25rem`).
  129. */
  130. rem?: number;
  131. /**
  132. * Whether to collapse multiple utilities into a single utility if possible.
  133. *
  134. * E.g.: `mt-2 mr-2 mb-2 ml-2` → `m-2`
  135. */
  136. collapse?: boolean;
  137. /**
  138. * Whether to convert between logical and physical properties when collapsing
  139. * utilities.
  140. *
  141. * E.g.: `mr-2 ml-2` → `mx-2`
  142. */
  143. logicalToPhysical?: boolean;
  144. }
  145. interface ClassMetadata {
  146. modifiers: string[];
  147. }
  148. type ClassEntry = [string, ClassMetadata];
  149. interface SelectorOptions {
  150. modifier?: string;
  151. value?: string;
  152. }
  153. interface VariantEntry {
  154. name: string;
  155. isArbitrary: boolean;
  156. values: string[];
  157. hasDash: boolean;
  158. selectors: (options: SelectorOptions) => string[];
  159. }
  160. type CompileFn<T extends Candidate['kind']> = (value: Extract<Candidate, {
  161. kind: T;
  162. }>) => AstNode[] | undefined | null;
  163. interface SuggestionGroup {
  164. supportsNegative?: boolean;
  165. values: (string | null)[];
  166. modifiers: string[];
  167. }
  168. type UtilityOptions = {
  169. types: string[];
  170. };
  171. type Utility = {
  172. kind: 'static' | 'functional';
  173. compileFn: CompileFn<any>;
  174. options?: UtilityOptions;
  175. };
  176. declare class Utilities {
  177. private utilities;
  178. private completions;
  179. static(name: string, compileFn: CompileFn<'static'>): void;
  180. functional(name: string, compileFn: CompileFn<'functional'>, options?: UtilityOptions): void;
  181. has(name: string, kind: 'static' | 'functional'): boolean;
  182. get(name: string): Utility[];
  183. getCompletions(name: string): SuggestionGroup[];
  184. suggest(name: string, groups: () => SuggestionGroup[]): void;
  185. keys(kind: 'static' | 'functional'): string[];
  186. }
  187. declare const enum CompileAstFlags {
  188. None = 0,
  189. RespectImportant = 1
  190. }
  191. type DesignSystem = {
  192. theme: Theme;
  193. utilities: Utilities;
  194. variants: Variants;
  195. invalidCandidates: Set<string>;
  196. important: boolean;
  197. getClassOrder(classes: string[]): [string, bigint | null][];
  198. getClassList(): ClassEntry[];
  199. getVariants(): VariantEntry[];
  200. parseCandidate(candidate: string): Readonly<Candidate>[];
  201. parseVariant(variant: string): Readonly<Variant> | null;
  202. compileAstNodes(candidate: Candidate, flags?: CompileAstFlags): ReturnType<typeof compileAstNodes>;
  203. printCandidate(candidate: Candidate): string;
  204. printVariant(variant: Variant): string;
  205. getVariantOrder(): Map<Variant, number>;
  206. resolveThemeValue(path: string, forceInline?: boolean): string | undefined;
  207. trackUsedVariables(raw: string): void;
  208. canonicalizeCandidates(candidates: string[], options?: CanonicalizeOptions): string[];
  209. candidatesToCss(classes: string[]): (string | null)[];
  210. candidatesToAst(classes: string[]): AstNode[][];
  211. storage: Record<symbol, unknown>;
  212. };
  213. type StyleRule = {
  214. kind: 'rule';
  215. selector: string;
  216. nodes: AstNode[];
  217. src?: SourceLocation;
  218. dst?: SourceLocation;
  219. };
  220. type AtRule = {
  221. kind: 'at-rule';
  222. name: string;
  223. params: string;
  224. nodes: AstNode[];
  225. src?: SourceLocation;
  226. dst?: SourceLocation;
  227. };
  228. type Declaration = {
  229. kind: 'declaration';
  230. property: string;
  231. value: string | undefined;
  232. important: boolean;
  233. src?: SourceLocation;
  234. dst?: SourceLocation;
  235. };
  236. type Comment = {
  237. kind: 'comment';
  238. value: string;
  239. src?: SourceLocation;
  240. dst?: SourceLocation;
  241. };
  242. type Context = {
  243. kind: 'context';
  244. context: Record<string, string | boolean>;
  245. nodes: AstNode[];
  246. src?: undefined;
  247. dst?: undefined;
  248. };
  249. type AtRoot = {
  250. kind: 'at-root';
  251. nodes: AstNode[];
  252. src?: undefined;
  253. dst?: undefined;
  254. };
  255. type Rule = StyleRule | AtRule;
  256. type AstNode = StyleRule | AtRule | Declaration | Comment | Context | AtRoot;
  257. /**
  258. * Line offset tables are the key to generating our source maps. They allow us
  259. * to store indexes with our AST nodes and later convert them into positions as
  260. * when given the source that the indexes refer to.
  261. */
  262. /**
  263. * A position in source code
  264. *
  265. * https://tc39.es/ecma426/#sec-position-record-type
  266. */
  267. interface Position {
  268. /** The line number, one-based */
  269. line: number;
  270. /** The column/character number, one-based */
  271. column: number;
  272. }
  273. interface OriginalPosition extends Position {
  274. source: DecodedSource;
  275. }
  276. /**
  277. * A "decoded" sourcemap
  278. *
  279. * @see https://tc39.es/ecma426/#decoded-source-map-record
  280. */
  281. interface DecodedSourceMap {
  282. file: string | null;
  283. sources: DecodedSource[];
  284. mappings: DecodedMapping[];
  285. }
  286. /**
  287. * A "decoded" source
  288. *
  289. * @see https://tc39.es/ecma426/#decoded-source-record
  290. */
  291. interface DecodedSource {
  292. url: string | null;
  293. content: string | null;
  294. ignore: boolean;
  295. }
  296. /**
  297. * A "decoded" mapping
  298. *
  299. * @see https://tc39.es/ecma426/#decoded-mapping-record
  300. */
  301. interface DecodedMapping {
  302. originalPosition: OriginalPosition | null;
  303. generatedPosition: Position;
  304. name: string | null;
  305. }
  306. type Config = UserConfig;
  307. declare const enum Polyfills {
  308. None = 0,
  309. AtProperty = 1,
  310. ColorMix = 2,
  311. All = 3
  312. }
  313. type CompileOptions = {
  314. base?: string;
  315. from?: string;
  316. polyfills?: Polyfills;
  317. loadModule?: (id: string, base: string, resourceHint: 'plugin' | 'config') => Promise<{
  318. path: string;
  319. base: string;
  320. module: Plugin | Config;
  321. }>;
  322. loadStylesheet?: (id: string, base: string) => Promise<{
  323. path: string;
  324. base: string;
  325. content: string;
  326. }>;
  327. };
  328. type Root = null | 'none' | {
  329. base: string;
  330. pattern: string;
  331. };
  332. declare const enum Features {
  333. None = 0,
  334. AtApply = 1,
  335. AtImport = 2,
  336. JsPluginCompat = 4,
  337. ThemeFunction = 8,
  338. Utilities = 16,
  339. Variants = 32,
  340. AtTheme = 64
  341. }
  342. declare function compileAst(input: AstNode[], opts?: CompileOptions): Promise<{
  343. sources: {
  344. base: string;
  345. pattern: string;
  346. negated: boolean;
  347. }[];
  348. root: Root;
  349. features: Features;
  350. build(candidates: string[]): AstNode[];
  351. }>;
  352. declare function compile(css: string, opts?: CompileOptions): Promise<{
  353. sources: {
  354. base: string;
  355. pattern: string;
  356. negated: boolean;
  357. }[];
  358. root: Root;
  359. features: Features;
  360. build(candidates: string[]): string;
  361. buildSourceMap(): DecodedSourceMap;
  362. }>;
  363. declare function __unstable__loadDesignSystem(css: string, opts?: CompileOptions): Promise<DesignSystem>;
  364. declare function postcssPluginWarning(): void;
  365. export { type Config, type DecodedSourceMap, Features, Polyfills, __unstable__loadDesignSystem, compile, compileAst, postcssPluginWarning as default };