plugin.d.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import { N as NamedUtilityValue, P as PluginUtils } from './resolve-config-B4yBzhca.js';
  2. import './colors-C__qRT83.js';
  3. /**
  4. * The source code for one or more nodes in the AST
  5. *
  6. * This generally corresponds to a stylesheet
  7. */
  8. interface Source {
  9. /**
  10. * The path to the file that contains the referenced source code
  11. *
  12. * If this references the *output* source code, this is `null`.
  13. */
  14. file: string | null;
  15. /**
  16. * The referenced source code
  17. */
  18. code: string;
  19. }
  20. /**
  21. * The file and offsets within it that this node covers
  22. *
  23. * This can represent either:
  24. * - A location in the original CSS which caused this node to be created
  25. * - A location in the output CSS where this node resides
  26. */
  27. type SourceLocation = [source: Source, start: number, end: number];
  28. type Config = UserConfig;
  29. type PluginFn = (api: PluginAPI) => void;
  30. type PluginWithConfig = {
  31. handler: PluginFn;
  32. config?: UserConfig;
  33. /** @internal */
  34. reference?: boolean;
  35. src?: SourceLocation | undefined;
  36. };
  37. type PluginWithOptions<T> = {
  38. (options?: T): PluginWithConfig;
  39. __isOptionsFunction: true;
  40. };
  41. type Plugin = PluginFn | PluginWithConfig | PluginWithOptions<any>;
  42. type PluginAPI = {
  43. addBase(base: CssInJs): void;
  44. addVariant(name: string, variant: string | string[] | CssInJs): void;
  45. matchVariant<T = string>(name: string, cb: (value: T | string, extra: {
  46. modifier: string | null;
  47. }) => string | string[], options?: {
  48. values?: Record<string, T>;
  49. sort?(a: {
  50. value: T | string;
  51. modifier: string | null;
  52. }, b: {
  53. value: T | string;
  54. modifier: string | null;
  55. }): number;
  56. }): void;
  57. addUtilities(utilities: Record<string, CssInJs | CssInJs[]> | Record<string, CssInJs | CssInJs[]>[], options?: {}): void;
  58. matchUtilities(utilities: Record<string, (value: string, extra: {
  59. modifier: string | null;
  60. }) => CssInJs | CssInJs[]>, options?: Partial<{
  61. type: string | string[];
  62. supportsNegativeValues: boolean;
  63. values: Record<string, string> & {
  64. __BARE_VALUE__?: (value: NamedUtilityValue) => string | undefined;
  65. };
  66. modifiers: 'any' | Record<string, string>;
  67. }>): void;
  68. addComponents(utilities: Record<string, CssInJs> | Record<string, CssInJs>[], options?: {}): void;
  69. matchComponents(utilities: Record<string, (value: string, extra: {
  70. modifier: string | null;
  71. }) => CssInJs>, options?: Partial<{
  72. type: string | string[];
  73. supportsNegativeValues: boolean;
  74. values: Record<string, string> & {
  75. __BARE_VALUE__?: (value: NamedUtilityValue) => string | undefined;
  76. };
  77. modifiers: 'any' | Record<string, string>;
  78. }>): void;
  79. theme(path: string, defaultValue?: any): any;
  80. config(path?: string, defaultValue?: any): any;
  81. prefix(className: string): string;
  82. };
  83. type CssInJs = {
  84. [key: string]: string | string[] | CssInJs | CssInJs[];
  85. };
  86. type ResolvableTo<T> = T | ((utils: PluginUtils) => T);
  87. type ThemeValue = ResolvableTo<Record<string, unknown>> | null | undefined;
  88. type ThemeConfig = Record<string, ThemeValue> & {
  89. extend?: Record<string, ThemeValue>;
  90. };
  91. type ContentFile = string | {
  92. raw: string;
  93. extension?: string;
  94. };
  95. type DarkModeStrategy = false | 'media' | 'class' | ['class', string] | 'selector' | ['selector', string] | ['variant', string | string[]];
  96. interface UserConfig {
  97. presets?: UserConfig[];
  98. theme?: ThemeConfig;
  99. plugins?: Plugin[];
  100. }
  101. interface UserConfig {
  102. content?: ContentFile[] | {
  103. relative?: boolean;
  104. files: ContentFile[];
  105. };
  106. }
  107. interface UserConfig {
  108. darkMode?: DarkModeStrategy;
  109. }
  110. interface UserConfig {
  111. prefix?: string;
  112. }
  113. interface UserConfig {
  114. blocklist?: string[];
  115. }
  116. interface UserConfig {
  117. important?: boolean | string;
  118. }
  119. interface UserConfig {
  120. future?: 'all' | Record<string, boolean>;
  121. }
  122. interface UserConfig {
  123. experimental?: 'all' | Record<string, boolean>;
  124. }
  125. declare function createPlugin(handler: PluginFn, config?: Partial<Config>): PluginWithConfig;
  126. declare namespace createPlugin {
  127. var withOptions: <T>(pluginFunction: (options?: T) => PluginFn, configFunction?: (options?: T) => Partial<Config>) => PluginWithOptions<T>;
  128. }
  129. export { createPlugin as default };