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.

190 lines
4.9 KiB

  1. import Document from './document.js'
  2. import { SourceMap } from './postcss.js'
  3. import Processor from './processor.js'
  4. import Result, { Message, ResultOptions } from './result.js'
  5. import Root from './root.js'
  6. import Warning from './warning.js'
  7. declare namespace LazyResult {
  8. // eslint-disable-next-line @typescript-eslint/no-use-before-define
  9. export { LazyResult_ as default }
  10. }
  11. /**
  12. * A Promise proxy for the result of PostCSS transformations.
  13. *
  14. * A `LazyResult` instance is returned by `Processor#process`.
  15. *
  16. * ```js
  17. * const lazy = postcss([autoprefixer]).process(css)
  18. * ```
  19. */
  20. declare class LazyResult_<RootNode = Document | Root>
  21. implements PromiseLike<Result<RootNode>>
  22. {
  23. /**
  24. * Processes input CSS through synchronous and asynchronous plugins
  25. * and calls onRejected for each error thrown in any plugin.
  26. *
  27. * It implements standard Promise API.
  28. *
  29. * ```js
  30. * postcss([autoprefixer]).process(css).then(result => {
  31. * console.log(result.css)
  32. * }).catch(error => {
  33. * console.error(error)
  34. * })
  35. * ```
  36. */
  37. catch: Promise<Result<RootNode>>['catch']
  38. /**
  39. * Processes input CSS through synchronous and asynchronous plugins
  40. * and calls onFinally on any error or when all plugins will finish work.
  41. *
  42. * It implements standard Promise API.
  43. *
  44. * ```js
  45. * postcss([autoprefixer]).process(css).finally(() => {
  46. * console.log('processing ended')
  47. * })
  48. * ```
  49. */
  50. finally: Promise<Result<RootNode>>['finally']
  51. /**
  52. * Processes input CSS through synchronous and asynchronous plugins
  53. * and calls `onFulfilled` with a Result instance. If a plugin throws
  54. * an error, the `onRejected` callback will be executed.
  55. *
  56. * It implements standard Promise API.
  57. *
  58. * ```js
  59. * postcss([autoprefixer]).process(css, { from: cssPath }).then(result => {
  60. * console.log(result.css)
  61. * })
  62. * ```
  63. */
  64. then: Promise<Result<RootNode>>['then']
  65. /**
  66. * An alias for the `css` property. Use it with syntaxes
  67. * that generate non-CSS output.
  68. *
  69. * This property will only work with synchronous plugins.
  70. * If the processor contains any asynchronous plugins
  71. * it will throw an error.
  72. *
  73. * PostCSS runners should always use `LazyResult#then`.
  74. */
  75. get content(): string
  76. /**
  77. * Processes input CSS through synchronous plugins, converts `Root`
  78. * to a CSS string and returns `Result#css`.
  79. *
  80. * This property will only work with synchronous plugins.
  81. * If the processor contains any asynchronous plugins
  82. * it will throw an error.
  83. *
  84. * PostCSS runners should always use `LazyResult#then`.
  85. */
  86. get css(): string
  87. /**
  88. * Processes input CSS through synchronous plugins
  89. * and returns `Result#map`.
  90. *
  91. * This property will only work with synchronous plugins.
  92. * If the processor contains any asynchronous plugins
  93. * it will throw an error.
  94. *
  95. * PostCSS runners should always use `LazyResult#then`.
  96. */
  97. get map(): SourceMap
  98. /**
  99. * Processes input CSS through synchronous plugins
  100. * and returns `Result#messages`.
  101. *
  102. * This property will only work with synchronous plugins. If the processor
  103. * contains any asynchronous plugins it will throw an error.
  104. *
  105. * PostCSS runners should always use `LazyResult#then`.
  106. */
  107. get messages(): Message[]
  108. /**
  109. * Options from the `Processor#process` call.
  110. */
  111. get opts(): ResultOptions
  112. /**
  113. * Returns a `Processor` instance, which will be used
  114. * for CSS transformations.
  115. */
  116. get processor(): Processor
  117. /**
  118. * Processes input CSS through synchronous plugins
  119. * and returns `Result#root`.
  120. *
  121. * This property will only work with synchronous plugins. If the processor
  122. * contains any asynchronous plugins it will throw an error.
  123. *
  124. * PostCSS runners should always use `LazyResult#then`.
  125. */
  126. get root(): RootNode
  127. /**
  128. * Returns the default string description of an object.
  129. * Required to implement the Promise interface.
  130. */
  131. get [Symbol.toStringTag](): string
  132. /**
  133. * @param processor Processor used for this transformation.
  134. * @param css CSS to parse and transform.
  135. * @param opts Options from the `Processor#process` or `Root#toResult`.
  136. */
  137. constructor(processor: Processor, css: string, opts: ResultOptions)
  138. /**
  139. * Run plugin in async way and return `Result`.
  140. *
  141. * @return Result with output content.
  142. */
  143. async(): Promise<Result<RootNode>>
  144. /**
  145. * Run plugin in sync way and return `Result`.
  146. *
  147. * @return Result with output content.
  148. */
  149. sync(): Result<RootNode>
  150. /**
  151. * Alias for the `LazyResult#css` property.
  152. *
  153. * ```js
  154. * lazy + '' === lazy.css
  155. * ```
  156. *
  157. * @return Output CSS.
  158. */
  159. toString(): string
  160. /**
  161. * Processes input CSS through synchronous plugins
  162. * and calls `Result#warnings`.
  163. *
  164. * @return Warnings from plugins.
  165. */
  166. warnings(): Warning[]
  167. }
  168. declare class LazyResult<
  169. RootNode = Document | Root
  170. > extends LazyResult_<RootNode> {}
  171. export = LazyResult