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