Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

postcss.d.ts 11KB

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