1 | import { SourceMapGenerator, RawSourceMap } from 'source-map'
|
2 |
|
3 | import Node, {
|
4 | Position,
|
5 | Source,
|
6 | ChildNode,
|
7 | NodeProps,
|
8 | ChildProps,
|
9 | AnyNode
|
10 | } from './node.js'
|
11 | import Declaration, { DeclarationProps } from './declaration.js'
|
12 | import Root, { RootProps } from './root.js'
|
13 | import Comment, { CommentProps } from './comment.js'
|
14 | import AtRule, { AtRuleProps } from './at-rule.js'
|
15 | import Result, { Message } from './result.js'
|
16 | import Rule, { RuleProps } from './rule.js'
|
17 | import Container, { ContainerProps } from './container.js'
|
18 | import Warning, { WarningOptions } from './warning.js'
|
19 | import Input, { FilePosition } from './input.js'
|
20 | import CssSyntaxError from './css-syntax-error.js'
|
21 | import list, { List } from './list.js'
|
22 | import Processor from './processor.js'
|
23 |
|
24 | export {
|
25 | WarningOptions,
|
26 | FilePosition,
|
27 | Position,
|
28 | Source,
|
29 | ChildNode,
|
30 | AnyNode,
|
31 | Message,
|
32 | NodeProps,
|
33 | DeclarationProps,
|
34 | ContainerProps,
|
35 | CommentProps,
|
36 | RuleProps,
|
37 | ChildProps,
|
38 | AtRuleProps,
|
39 | RootProps,
|
40 | Warning,
|
41 | CssSyntaxError,
|
42 | Node,
|
43 | Container,
|
44 | list,
|
45 | Declaration,
|
46 | Comment,
|
47 | AtRule,
|
48 | Rule,
|
49 | Root,
|
50 | Result,
|
51 | Input
|
52 | }
|
53 |
|
54 | export type SourceMap = SourceMapGenerator & {
|
55 | toJSON(): RawSourceMap
|
56 | }
|
57 |
|
58 | export type Helpers = { result: Result; postcss: Postcss } & Postcss
|
59 |
|
60 | type RootProcessor = (root: Root, helper: Helpers) => Promise<void> | void
|
61 | type DeclarationProcessor = (
|
62 | decl: Declaration,
|
63 | helper: Helpers
|
64 | ) => Promise<void> | void
|
65 | type RuleProcessor = (rule: Rule, helper: Helpers) => Promise<void> | void
|
66 | type AtRuleProcessor = (atRule: AtRule, helper: Helpers) => Promise<void> | void
|
67 | type CommentProcessor = (
|
68 | comment: Comment,
|
69 | helper: Helpers
|
70 | ) => Promise<void> | void
|
71 |
|
72 | interface Processors {
|
73 | |
74 |
|
75 |
|
76 | Once?: RootProcessor
|
77 |
|
78 | |
79 |
|
80 |
|
81 | OnceExit?: RootProcessor
|
82 |
|
83 | |
84 |
|
85 |
|
86 |
|
87 |
|
88 | Root?: RootProcessor
|
89 |
|
90 | |
91 |
|
92 |
|
93 |
|
94 |
|
95 | RootExit?: RootProcessor
|
96 |
|
97 | |
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 | Declaration?: DeclarationProcessor | { [prop: string]: DeclarationProcessor }
|
104 |
|
105 | |
106 |
|
107 |
|
108 |
|
109 |
|
110 | DeclarationExit?:
|
111 | | DeclarationProcessor
|
112 | | { [prop: string]: DeclarationProcessor }
|
113 |
|
114 | |
115 |
|
116 |
|
117 |
|
118 |
|
119 | Rule?: RuleProcessor
|
120 |
|
121 | |
122 |
|
123 |
|
124 |
|
125 |
|
126 | RuleExit?: RuleProcessor
|
127 |
|
128 | |
129 |
|
130 |
|
131 |
|
132 |
|
133 | AtRule?: AtRuleProcessor | { [name: string]: AtRuleProcessor }
|
134 |
|
135 | |
136 |
|
137 |
|
138 |
|
139 |
|
140 | AtRuleExit?: AtRuleProcessor | { [name: string]: AtRuleProcessor }
|
141 |
|
142 | |
143 |
|
144 |
|
145 |
|
146 |
|
147 | Comment?: CommentProcessor
|
148 |
|
149 | |
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 | CommentExit?: CommentProcessor
|
156 |
|
157 | |
158 |
|
159 |
|
160 |
|
161 |
|
162 | Exit?: RootProcessor
|
163 | }
|
164 |
|
165 | export interface Plugin extends Processors {
|
166 | postcssPlugin: string
|
167 | prepare?: (result: Result) => Processors
|
168 | }
|
169 |
|
170 | export interface PluginCreator<PluginOptions> {
|
171 | (opts?: PluginOptions): Plugin
|
172 | postcss: true
|
173 | }
|
174 |
|
175 | export interface Transformer extends TransformCallback {
|
176 | postcssPlugin: string
|
177 | postcssVersion: string
|
178 | }
|
179 |
|
180 | export interface TransformCallback {
|
181 | (root: Root, result: Result): Promise<void> | void
|
182 | }
|
183 |
|
184 | export interface OldPlugin<T> extends Transformer {
|
185 | (opts?: T): Transformer
|
186 | postcss: Transformer
|
187 | }
|
188 |
|
189 | export type AcceptedPlugin =
|
190 | | Plugin
|
191 | | PluginCreator<any>
|
192 | | OldPlugin<any>
|
193 | | TransformCallback
|
194 | | {
|
195 | postcss: TransformCallback | Processor
|
196 | }
|
197 | | Processor
|
198 |
|
199 | export interface Parser {
|
200 | (
|
201 | css: string | { toString(): string },
|
202 | opts?: Pick<ProcessOptions, 'map' | 'from'>
|
203 | ): Root
|
204 | }
|
205 |
|
206 | export interface Builder {
|
207 | (part: string, node?: AnyNode, type?: 'start' | 'end'): void
|
208 | }
|
209 |
|
210 | export interface Stringifier {
|
211 | (node: AnyNode, builder: Builder): void
|
212 | }
|
213 |
|
214 | export interface Syntax {
|
215 | |
216 |
|
217 |
|
218 | parse?: Parser
|
219 |
|
220 | |
221 |
|
222 |
|
223 | stringify?: Stringifier
|
224 | }
|
225 |
|
226 | export interface SourceMapOptions {
|
227 | |
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 | inline?: boolean
|
237 |
|
238 | |
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 | prev?: string | boolean | object | ((file: string) => string)
|
248 |
|
249 | /**
|
250 | * Indicates that PostCSS should set the origin content (e.g., Sass source)
|
251 | * of the source map. By default, it is true. But if all previous maps do not
|
252 | * contain sources content, PostCSS will also leave it out even if you
|
253 | * do not set this option.
|
254 | */
|
255 | sourcesContent?: boolean
|
256 |
|
257 | /**
|
258 | * Indicates that PostCSS should add annotation comments to the CSS.
|
259 | * By default, PostCSS will always add a comment with a path
|
260 | * to the source map. PostCSS will not add annotations to CSS files
|
261 | * that do not contain any comments.
|
262 | *
|
263 | * By default, PostCSS presumes that you want to save the source map as
|
264 | * `opts.to + '.map'` and will use this path in the annotation comment.
|
265 | * A different path can be set by providing a string value for annotation.
|
266 | *
|
267 | * If you have set `inline: true`, annotation cannot be disabled.
|
268 | */
|
269 | annotation?: string | boolean | ((file: string, root: Root) => string)
|
270 |
|
271 | /**
|
272 | * Override `from` in map’s sources.
|
273 | */
|
274 | from?: string
|
275 |
|
276 | /**
|
277 | * Use absolute path in generated source map.
|
278 | */
|
279 | absolute?: boolean
|
280 | }
|
281 |
|
282 | export interface ProcessOptions {
|
283 | /**
|
284 | * The path of the CSS source file. You should always set `from`,
|
285 | * because it is used in source map generation and syntax error messages.
|
286 | */
|
287 | from?: string
|
288 |
|
289 | /**
|
290 | * The path where you'll put the output CSS file. You should always set `to`
|
291 | * to generate correct source maps.
|
292 | */
|
293 | to?: string
|
294 |
|
295 | /**
|
296 | * Function to generate AST by string.
|
297 | */
|
298 | parser?: Syntax | Parser
|
299 |
|
300 | /**
|
301 | * Class to generate string by AST.
|
302 | */
|
303 | stringifier?: Syntax | Stringifier
|
304 |
|
305 | /**
|
306 | * Object with parse and stringify.
|
307 | */
|
308 | syntax?: Syntax
|
309 |
|
310 | /**
|
311 | * Source map options
|
312 | */
|
313 | map?: SourceMapOptions | boolean
|
314 | }
|
315 |
|
316 | export interface Postcss {
|
317 | /**
|
318 | * Create a new `Processor` instance that will apply `plugins`
|
319 | * as CSS processors.
|
320 | *
|
321 | * ```js
|
322 | * let postcss = require('postcss')
|
323 | *
|
324 | * postcss(plugins).process(css, { from, to }).then(result => {
|
325 | * console.log(result.css)
|
326 | * })
|
327 | * ```
|
328 | *
|
329 | * @param plugins PostCSS plugins.
|
330 | * @return Processor to process multiple CSS.
|
331 | */
|
332 | (plugins?: AcceptedPlugin[]): Processor
|
333 | (...plugins: AcceptedPlugin[]): Processor
|
334 |
|
335 | /**
|
336 | * Default function to convert a node tree into a CSS string.
|
337 | */
|
338 | stringify: Stringifier
|
339 |
|
340 | /**
|
341 | * Parses source css and returns a new `Root` node,
|
342 | * which contains the source CSS nodes.
|
343 | *
|
344 | * ```js
|
345 | * // Simple CSS concatenation with source map support
|
346 | * const root1 = postcss.parse(css1, { from: file1 })
|
347 | * const root2 = postcss.parse(css2, { from: file2 })
|
348 | * root1.append(root2).toResult().css
|
349 | * ```
|
350 | */
|
351 | parse: Parser
|
352 |
|
353 | /**
|
354 | * Contains the `list` module.
|
355 | */
|
356 | list: List
|
357 |
|
358 | /**
|
359 | * Creates a new `Comment` node.
|
360 | *
|
361 | * @param defaults Properties for the new node.
|
362 | * @return New comment node
|
363 | */
|
364 | comment(defaults?: CommentProps): Comment
|
365 |
|
366 | /**
|
367 | * Creates a new `AtRule` node.
|
368 | *
|
369 | * @param defaults Properties for the new node.
|
370 | * @return New at-rule node.
|
371 | */
|
372 | atRule(defaults?: AtRuleProps): AtRule
|
373 |
|
374 | /**
|
375 | * Creates a new `Declaration` node.
|
376 | *
|
377 | * @param defaults Properties for the new node.
|
378 | * @return New declaration node.
|
379 | */
|
380 | decl(defaults?: DeclarationProps): Declaration
|
381 |
|
382 | /**
|
383 | * Creates a new `Rule` node.
|
384 | *
|
385 | * @param default Properties for the new node.
|
386 | * @return New rule node.
|
387 | */
|
388 | rule(defaults?: RuleProps): Rule
|
389 |
|
390 | /**
|
391 | * Creates a new `Root` node.
|
392 | *
|
393 | * @param defaults Properties for the new node.
|
394 | * @return New root node.
|
395 | */
|
396 | root(defaults?: RootProps): Root
|
397 |
|
398 | CssSyntaxError: typeof CssSyntaxError
|
399 | Declaration: typeof Declaration
|
400 | Container: typeof Container
|
401 | Comment: typeof Comment
|
402 | Warning: typeof Warning
|
403 | AtRule: typeof AtRule
|
404 | Result: typeof Result
|
405 | Input: typeof Input
|
406 | Rule: typeof Rule
|
407 | Root: typeof Root
|
408 | Node: typeof Node
|
409 | }
|
410 |
|
411 | export const stringify: Stringifier
|
412 | export const parse: Parser
|
413 |
|
414 | export const comment: Postcss['comment']
|
415 | export const atRule: Postcss['atRule']
|
416 | export const decl: Postcss['decl']
|
417 | export const rule: Postcss['rule']
|
418 | export const root: Postcss['root']
|
419 |
|
420 | declare const postcss: Postcss
|
421 |
|
422 | export default postcss
|
423 |
|
\ | No newline at end of file |