source: trip-planner-front/node_modules/postcss/lib/postcss.d.ts@ 59329aa

Last change on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

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