// @flow // (Only covers the API that Atlaspack uses) // Derived from the PostCSS docs available at // http://api.postcss.org/postcss.html. declare module 'postcss' { // eslint-disable-next-line import/no-extraneous-dependencies import type {SourceMapGenerator} from 'source-map'; declare type Callback = (T, number) => false | void; declare interface Input { file?: string; } declare interface Position { offset: number; column: number; line: number; } declare interface Source { input: Input; start?: Position; end?: Position; } declare interface Node { parent: Container; source: Source; +type: 'atrule' | 'comment' | 'decl' | 'root' | 'rule'; toJSON(): mixed; } declare interface Decl extends Container { type: 'decl'; prop: string; value: string; source: Source; } declare interface Rule extends Container { selector: string; type: 'rule'; remove(): void; } declare interface AtRule extends Container { name: string; params: string; type: 'atrule'; remove(): void; } declare interface Container extends Node { each(callback: Callback): false | void; nodes: Array; walk(callback: Callback): false | void; walkRules(callback: Callback): false | void; walkDecls(nameFilter: string | RegExp, callback: Callback): void; walkDecls(callback: Callback): void; walkAtRules(nameFilter: string | RegExp, callback: Callback): void; walkAtRules(callback: Callback): void; } declare interface Root extends Container {} declare class Processor { process( css: string | Result | Root, opts?: ProcessOptions, ): Promise; } declare type ProcessOptions = $Shape<{| from: string, to: string, map: MapOptions, parser: Parser, stringifier: Stringifier, syntax: {| parser: Parser, stringifier: Stringifier, |}, |}>; declare type MapOptions = {| inline?: boolean, prev?: string | any | false | function, sourcesContent?: boolean, annotation?: false | string, from?: string, |}; declare type Parser = ( css: string, optsopt: {|from?: string, map?: MapOptions|}, ) => Root; declare type Plugin = {| postcss(...args: Array): void, |}; declare type PluginFunction = (root: Root, result: Result) => void; declare type Result = { content: string, css: string, map: SourceMapGenerator, messages: Array, opts: ProcessOptions, processor: Processor, root: Root, toString(): string, ... }; declare type Message = {| type: string, plugin: string, file: string, |}; declare type Builder = ( part: string, node: Root, typeopt?: 'start' | 'end', ) => void; declare type Stringifier = (root: Root, builder: Builder) => void; declare module.exports: { (plugins?: Array | Processor): Processor, parse: Parser, stringify: Stringifier, root: ($Shape) => Root, atRule: ($Shape) => Container, comment: ($Shape) => Node, decl: ($Shape) => Node, rule: ($Shape) => Container, fromJSON: (mixed) => T, ... }; }