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