Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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 45KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283
  1. import * as mozilla from 'source-map';
  2. /**
  3. * @param plugins Can also be included with the Processor#use method.
  4. * @returns A processor that will apply plugins as CSS processors.
  5. */
  6. declare function postcss(plugins?: postcss.AcceptedPlugin[]): postcss.Processor;
  7. declare function postcss(...plugins: postcss.AcceptedPlugin[]): postcss.Processor;
  8. declare namespace postcss {
  9. type AcceptedPlugin = Plugin<any> | Transformer | {
  10. postcss: TransformCallback | Processor;
  11. } | Processor;
  12. /**
  13. * Creates a PostCSS plugin with a standard API.
  14. * @param name Plugin name. Same as in name property in package.json. It will
  15. * be saved in plugin.postcssPlugin property.
  16. * @param initializer Will receive plugin options and should return functions
  17. * to modify nodes in input CSS.
  18. */
  19. function plugin<T>(name: string, initializer: PluginInitializer<T>): Plugin<T>;
  20. interface Plugin<T> extends Transformer {
  21. (opts?: T): Transformer;
  22. postcss: Transformer;
  23. process: (css: string | {
  24. toString(): string;
  25. } | Result, processOpts?: ProcessOptions, pluginOpts?: T) => LazyResult;
  26. }
  27. interface Transformer extends TransformCallback {
  28. postcssPlugin?: string;
  29. postcssVersion?: string;
  30. }
  31. interface TransformCallback {
  32. /**
  33. * @returns A Promise that resolves when all work is complete. May return
  34. * synchronously, but that style of plugin is only meant for debugging and
  35. * development. In either case, the resolved or returned value is not used -
  36. * the "result" is the output.
  37. */
  38. (root: Root, result: Result): Promise<any> | any;
  39. }
  40. interface PluginInitializer<T> {
  41. (pluginOptions?: T): Transformer;
  42. }
  43. /**
  44. * Contains helpers for working with vendor prefixes.
  45. */
  46. export namespace vendor {
  47. /**
  48. * @returns The vendor prefix extracted from the input string.
  49. */
  50. function prefix(prop: string): string;
  51. /**
  52. * @returns The input string stripped of its vendor prefix.
  53. */
  54. function unprefixed(prop: string): string;
  55. }
  56. type ParserInput = string | { toString(): string };
  57. interface Parser {
  58. (css: ParserInput, opts?: Pick<ProcessOptions, 'map' | 'from'>): Root;
  59. }
  60. interface Builder {
  61. (part: string, node?: Node, type?: 'start' | 'end'): void;
  62. }
  63. interface Stringifier {
  64. (node: Node, builder: Builder): void;
  65. }
  66. /**
  67. * Default function to convert a node tree into a CSS string.
  68. */
  69. const stringify: Stringifier;
  70. /**
  71. * Parses source CSS.
  72. * @param css The CSS to parse.
  73. * @param options
  74. * @returns {} A new Root node, which contains the source CSS nodes.
  75. */
  76. const parse: Parser;
  77. /**
  78. * Contains helpers for safely splitting lists of CSS values, preserving
  79. * parentheses and quotes.
  80. */
  81. export namespace list {
  82. /**
  83. * Safely splits space-separated values (such as those for background,
  84. * border-radius and other shorthand properties).
  85. */
  86. function space(str: string): string[];
  87. /**
  88. * Safely splits comma-separated values (such as those for transition-* and
  89. * background properties).
  90. */
  91. function comma(str: string): string[];
  92. }
  93. /**
  94. * Creates a new Comment node.
  95. * @param defaults Properties for the new Comment node.
  96. * @returns The new node.
  97. */
  98. function comment(defaults?: CommentNewProps): Comment;
  99. /**
  100. * Creates a new AtRule node.
  101. * @param defaults Properties for the new AtRule node.
  102. * @returns The new node.
  103. */
  104. function atRule(defaults?: AtRuleNewProps): AtRule;
  105. /**
  106. * Creates a new Declaration node.
  107. * @param defaults Properties for the new Declaration node.
  108. * @returns The new node.
  109. */
  110. function decl(defaults?: DeclarationNewProps): Declaration;
  111. /**
  112. * Creates a new Rule node.
  113. * @param defaults Properties for the new Rule node.
  114. * @returns The new node.
  115. */
  116. function rule(defaults?: RuleNewProps): Rule;
  117. /**
  118. * Creates a new Root node.
  119. * @param defaults Properties for the new Root node.
  120. * @returns The new node.
  121. */
  122. function root(defaults?: object): Root;
  123. interface SourceMapOptions {
  124. /**
  125. * Indicates that the source map should be embedded in the output CSS as a
  126. * Base64-encoded comment. By default, it is true. But if all previous maps
  127. * are external, not inline, PostCSS will not embed the map even if you do
  128. * not set this option.
  129. *
  130. * If you have an inline source map, the result.map property will be empty,
  131. * as the source map will be contained within the text of result.css.
  132. */
  133. inline?: boolean;
  134. /**
  135. * Source map content from a previous processing step (e.g., Sass compilation).
  136. * PostCSS will try to read the previous source map automatically (based on comments
  137. * within the source CSS), but you can use this option to identify it manually.
  138. * If desired, you can omit the previous map with prev: false.
  139. */
  140. prev?: any;
  141. /**
  142. * Indicates that PostCSS should set the origin content (e.g., Sass source)
  143. * of the source map. By default, it is true. But if all previous maps do not
  144. * contain sources content, PostCSS will also leave it out even if you do not set
  145. * this option.
  146. */
  147. sourcesContent?: boolean;
  148. /**
  149. * Indicates that PostCSS should add annotation comments to the CSS. By default,
  150. * PostCSS will always add a comment with a path to the source map. PostCSS will
  151. * not add annotations to CSS files that do not contain any comments.
  152. *
  153. * By default, PostCSS presumes that you want to save the source map as
  154. * opts.to + '.map' and will use this path in the annotation comment. A different
  155. * path can be set by providing a string value for annotation.
  156. *
  157. * If you have set inline: true, annotation cannot be disabled.
  158. */
  159. annotation?: string | boolean;
  160. /**
  161. * Override "from" in map's sources.
  162. */
  163. from?: string;
  164. }
  165. /**
  166. * A Processor instance contains plugins to process CSS. Create one
  167. * Processor instance, initialize its plugins, and then use that instance
  168. * on numerous CSS files.
  169. */
  170. interface Processor {
  171. /**
  172. * Adds a plugin to be used as a CSS processor. Plugins can also be
  173. * added by passing them as arguments when creating a postcss instance.
  174. */
  175. use(plugin: AcceptedPlugin): Processor;
  176. /**
  177. * Parses source CSS. Because some plugins can be asynchronous it doesn't
  178. * make any transformations. Transformations will be applied in LazyResult's
  179. * methods.
  180. * @param css Input CSS or any object with toString() method, like a file
  181. * stream. If a Result instance is passed the processor will take the
  182. * existing Root parser from it.
  183. */
  184. process(css: ParserInput | Result | LazyResult | Root, options?: ProcessOptions): LazyResult;
  185. /**
  186. * Contains plugins added to this processor.
  187. */
  188. plugins: Plugin<any>[];
  189. /**
  190. * Contains the current version of PostCSS (e.g., "4.0.5").
  191. */
  192. version: string;
  193. }
  194. interface ProcessOptions {
  195. /**
  196. * The path of the CSS source file. You should always set "from", because it is
  197. * used in source map generation and syntax error messages.
  198. */
  199. from?: string;
  200. /**
  201. * The path where you'll put the output CSS file. You should always set "to"
  202. * to generate correct source maps.
  203. */
  204. to?: string;
  205. /**
  206. * Function to generate AST by string.
  207. */
  208. parser?: Parser;
  209. /**
  210. * Class to generate string by AST.
  211. */
  212. stringifier?: Stringifier;
  213. /**
  214. * Object with parse and stringify.
  215. */
  216. syntax?: Syntax;
  217. /**
  218. * Source map options
  219. */
  220. map?: SourceMapOptions | boolean;
  221. }
  222. interface Syntax {
  223. /**
  224. * Function to generate AST by string.
  225. */
  226. parse?: Parser;
  227. /**
  228. * Class to generate string by AST.
  229. */
  230. stringify?: Stringifier;
  231. }
  232. /**
  233. * A promise proxy for the result of PostCSS transformations.
  234. */
  235. interface LazyResult {
  236. /**
  237. * Processes input CSS through synchronous and asynchronous plugins.
  238. * @param onRejected Called if any plugin throws an error.
  239. */
  240. then: Promise<Result>["then"];
  241. /**
  242. * Processes input CSS through synchronous and asynchronous plugins.
  243. * @param onRejected Called if any plugin throws an error.
  244. */
  245. catch: Promise<Result>["catch"];
  246. /**
  247. * Alias for css property.
  248. */
  249. toString(): string;
  250. /**
  251. * Processes input CSS through synchronous plugins and converts Root to
  252. * CSS string. This property will only work with synchronous plugins. If
  253. * the processor contains any asynchronous plugins it will throw an error.
  254. * In this case, you should use LazyResult#then() instead.
  255. * @returns Result#css.
  256. */
  257. css: string;
  258. /**
  259. * Alias for css property to use when syntaxes generate non-CSS output.
  260. */
  261. content: string;
  262. /**
  263. * Processes input CSS through synchronous plugins. This property will
  264. * work only with synchronous plugins. If processor contains any
  265. * asynchronous plugins it will throw an error. You should use
  266. * LazyResult#then() instead.
  267. */
  268. map: ResultMap;
  269. /**
  270. * Processes input CSS through synchronous plugins. This property will work
  271. * only with synchronous plugins. If processor contains any asynchronous
  272. * plugins it will throw an error. You should use LazyResult#then() instead.
  273. */
  274. root: Root;
  275. /**
  276. * Processes input CSS through synchronous plugins and calls Result#warnings().
  277. * This property will only work with synchronous plugins. If the processor
  278. * contains any asynchronous plugins it will throw an error. In this case,
  279. * you should use LazyResult#then() instead.
  280. */
  281. warnings(): Warning[];
  282. /**
  283. * Processes input CSS through synchronous plugins. This property will work
  284. * only with synchronous plugins. If processor contains any asynchronous
  285. * plugins it will throw an error. You should use LazyResult#then() instead.
  286. */
  287. messages: ResultMessage[];
  288. /**
  289. * @returns A processor used for CSS transformations.
  290. */
  291. processor: Processor;
  292. /**
  293. * @returns Options from the Processor#process(css, opts) call that produced
  294. * this Result instance.
  295. */
  296. opts: ResultOptions;
  297. }
  298. /**
  299. * Provides the result of the PostCSS transformations.
  300. */
  301. interface Result {
  302. /**
  303. * Alias for css property.
  304. */
  305. toString(): string;
  306. /**
  307. * Creates an instance of Warning and adds it to messages.
  308. * @param message Used in the text property of the message object.
  309. * @param options Properties for Message object.
  310. */
  311. warn(message: string, options?: WarningOptions): void;
  312. /**
  313. * @returns Warnings from plugins, filtered from messages.
  314. */
  315. warnings(): Warning[];
  316. /**
  317. * A CSS string representing this Result's Root instance.
  318. */
  319. css: string;
  320. /**
  321. * Alias for css property to use with syntaxes that generate non-CSS output.
  322. */
  323. content: string;
  324. /**
  325. * An instance of the SourceMapGenerator class from the source-map library,
  326. * representing changes to the Result's Root instance.
  327. * This property will have a value only if the user does not want an inline
  328. * source map. By default, PostCSS generates inline source maps, written
  329. * directly into the processed CSS. The map property will be empty by default.
  330. * An external source map will be generated — and assigned to map — only if
  331. * the user has set the map.inline option to false, or if PostCSS was passed
  332. * an external input source map.
  333. */
  334. map: ResultMap;
  335. /**
  336. * Contains the Root node after all transformations.
  337. */
  338. root?: Root;
  339. /**
  340. * Contains messages from plugins (e.g., warnings or custom messages).
  341. * Add a warning using Result#warn() and get all warnings
  342. * using the Result#warnings() method.
  343. */
  344. messages: ResultMessage[];
  345. /**
  346. * The Processor instance used for this transformation.
  347. */
  348. processor?: Processor;
  349. /**
  350. * Options from the Processor#process(css, opts) or Root#toResult(opts) call
  351. * that produced this Result instance.
  352. */
  353. opts?: ResultOptions;
  354. }
  355. interface ResultOptions extends ProcessOptions {
  356. /**
  357. * The CSS node that was the source of the warning.
  358. */
  359. node?: postcss.Node;
  360. /**
  361. * Name of plugin that created this warning. Result#warn() will fill it
  362. * automatically with plugin.postcssPlugin value.
  363. */
  364. plugin?: string;
  365. }
  366. interface ResultMap {
  367. /**
  368. * Add a single mapping from original source line and column to the generated
  369. * source's line and column for this source map being created. The mapping
  370. * object should have the following properties:
  371. * @param mapping
  372. * @returns {}
  373. */
  374. addMapping(mapping: mozilla.Mapping): void;
  375. /**
  376. * Set the source content for an original source file.
  377. * @param sourceFile The URL of the original source file.
  378. * @param sourceContent The content of the source file.
  379. */
  380. setSourceContent(sourceFile: string, sourceContent: string): void;
  381. /**
  382. * Applies a SourceMap for a source file to the SourceMap. Each mapping to
  383. * the supplied source file is rewritten using the supplied SourceMap.
  384. * Note: The resolution for the resulting mappings is the minimum of this
  385. * map and the supplied map.
  386. * @param sourceMapConsumer The SourceMap to be applied.
  387. * @param sourceFile The filename of the source file. If omitted, sourceMapConsumer
  388. * file will be used, if it exists. Otherwise an error will be thrown.
  389. * @param sourceMapPath The dirname of the path to the SourceMap to be applied.
  390. * If relative, it is relative to the SourceMap. This parameter is needed when
  391. * the two SourceMaps aren't in the same directory, and the SourceMap to be
  392. * applied contains relative source paths. If so, those relative source paths
  393. * need to be rewritten relative to the SourceMap.
  394. * If omitted, it is assumed that both SourceMaps are in the same directory;
  395. * thus, not needing any rewriting (Supplying '.' has the same effect).
  396. */
  397. applySourceMap(
  398. sourceMapConsumer: mozilla.SourceMapConsumer,
  399. sourceFile?: string,
  400. sourceMapPath?: string
  401. ): void;
  402. /**
  403. * Renders the source map being generated to JSON.
  404. */
  405. toJSON: () => mozilla.RawSourceMap;
  406. /**
  407. * Renders the source map being generated to a string.
  408. */
  409. toString: () => string;
  410. }
  411. interface ResultMessage {
  412. type: string;
  413. plugin: string;
  414. [others: string]: any;
  415. }
  416. /**
  417. * Represents a plugin warning. It can be created using Result#warn().
  418. */
  419. interface Warning {
  420. /**
  421. * @returns Error position, message.
  422. */
  423. toString(): string;
  424. /**
  425. * Contains the warning message.
  426. */
  427. text: string;
  428. /**
  429. * Contains the name of the plugin that created this warning. When you
  430. * call Result#warn(), it will fill this property automatically.
  431. */
  432. plugin: string;
  433. /**
  434. * The CSS node that caused the warning.
  435. */
  436. node: Node;
  437. /**
  438. * The line in the input file with this warning's source.
  439. */
  440. line: number;
  441. /**
  442. * Column in the input file with this warning's source.
  443. */
  444. column: number;
  445. }
  446. interface WarningOptions extends ResultOptions {
  447. /**
  448. * A word inside a node's string that should be highlighted as source
  449. * of warning.
  450. */
  451. word?: string;
  452. /**
  453. * The index inside a node's string that should be highlighted as
  454. * source of warning.
  455. */
  456. index?: number;
  457. }
  458. /**
  459. * The CSS parser throws this error for broken CSS.
  460. */
  461. interface CssSyntaxError extends InputOrigin {
  462. name: string;
  463. /**
  464. * @returns Error position, message and source code of broken part.
  465. */
  466. toString(): string;
  467. /**
  468. * @param color Whether arrow should be colored red by terminal color codes.
  469. * By default, PostCSS will use process.stdout.isTTY and
  470. * process.env.NODE_DISABLE_COLORS.
  471. * @returns A few lines of CSS source that caused the error. If CSS has
  472. * input source map without sourceContent this method will return an empty
  473. * string.
  474. */
  475. showSourceCode(color?: boolean): string;
  476. /**
  477. * Contains full error text in the GNU error format.
  478. */
  479. message: string;
  480. /**
  481. * Contains only the error description.
  482. */
  483. reason: string;
  484. /**
  485. * Contains the PostCSS plugin name if the error didn't come from the
  486. * CSS parser.
  487. */
  488. plugin?: string;
  489. input?: InputOrigin;
  490. }
  491. interface InputOrigin {
  492. /**
  493. * If parser's from option is set, contains the absolute path to the
  494. * broken file. PostCSS will use the input source map to detect the
  495. * original error location. If you wrote a Sass file, then compiled it
  496. * to CSS and parsed it with PostCSS, PostCSS will show the original
  497. * position in the Sass file. If you need the position in the PostCSS
  498. * input (e.g., to debug the previous compiler), use error.input.file.
  499. */
  500. file?: string;
  501. /**
  502. * Contains the source line of the error. PostCSS will use the input
  503. * source map to detect the original error location. If you wrote a Sass
  504. * file, then compiled it to CSS and parsed it with PostCSS, PostCSS
  505. * will show the original position in the Sass file. If you need the
  506. * position in the PostCSS input (e.g., to debug the previous
  507. * compiler), use error.input.line.
  508. */
  509. line?: number;
  510. /**
  511. * Contains the source column of the error. PostCSS will use input
  512. * source map to detect the original error location. If you wrote a
  513. * Sass file, then compiled it to CSS and parsed it with PostCSS,
  514. * PostCSS will show the original position in the Sass file. If you
  515. * need the position in the PostCSS input (e.g., to debug the
  516. * previous compiler), use error.input.column.
  517. */
  518. column?: number;
  519. /**
  520. * Contains the source code of the broken file. PostCSS will use the
  521. * input source map to detect the original error location. If you wrote
  522. * a Sass file, then compiled it to CSS and parsed it with PostCSS,
  523. * PostCSS will show the original position in the Sass file. If you need
  524. * the position in the PostCSS input (e.g., to debug the previous
  525. * compiler), use error.input.source.
  526. */
  527. source?: string;
  528. }
  529. export class PreviousMap {
  530. private inline;
  531. annotation: string;
  532. root: string;
  533. private consumerCache;
  534. text: string;
  535. file: string;
  536. constructor(css: any, opts: any);
  537. consumer(): mozilla.SourceMapConsumer;
  538. withContent(): boolean;
  539. startWith(string: string, start: string): boolean;
  540. getAnnotationURL(sourceMapString: string): string;
  541. loadAnnotation(css: string): void;
  542. decodeInline(text: string): string;
  543. loadMap(
  544. file: any,
  545. prev: string | Function | mozilla.SourceMapConsumer | mozilla.SourceMapGenerator | mozilla.RawSourceMap
  546. ): string;
  547. isMap(map: any): boolean;
  548. }
  549. /**
  550. * Represents the source CSS.
  551. */
  552. interface Input {
  553. /**
  554. * The absolute path to the CSS source file defined with the "from" option.
  555. * Either this property or the "id" property are always defined.
  556. */
  557. file?: string;
  558. /**
  559. * The unique ID of the CSS source. Used if "from" option is not provided
  560. * (because PostCSS does not know the file path). Either this property
  561. * or the "file" property are always defined.
  562. */
  563. id?: string;
  564. /**
  565. * The CSS source identifier. Contains input.file if the user set the
  566. * "from" option, or input.id if they did not.
  567. */
  568. from: string;
  569. /**
  570. * Represents the input source map passed from a compilation step before
  571. * PostCSS (e.g., from the Sass compiler).
  572. */
  573. map: PreviousMap;
  574. /**
  575. * The flag to indicate whether or not the source code has Unicode BOM.
  576. */
  577. hasBOM: boolean;
  578. /**
  579. * Reads the input source map.
  580. * @returns A symbol position in the input source (e.g., in a Sass file
  581. * that was compiled to CSS before being passed to PostCSS):
  582. */
  583. origin(line: number, column: number): InputOrigin | false;
  584. }
  585. type ChildNode = AtRule | Rule | Declaration | Comment;
  586. type Node = Root | ChildNode;
  587. interface NodeBase {
  588. /**
  589. * Returns the input source of the node. The property is used in source
  590. * map generation. If you create a node manually
  591. * (e.g., with postcss.decl() ), that node will not have a source
  592. * property and will be absent from the source map. For this reason, the
  593. * plugin developer should consider cloning nodes to create new ones
  594. * (in which case the new node's source will reference the original,
  595. * cloned node) or setting the source property manually.
  596. */
  597. source?: NodeSource;
  598. /**
  599. * Contains information to generate byte-to-byte equal node string as it
  600. * was in origin input.
  601. */
  602. raws: NodeRaws;
  603. /**
  604. * @returns A CSS string representing the node.
  605. */
  606. toString(stringifier?: Stringifier | Syntax): string;
  607. /**
  608. * This method produces very useful error messages. If present, an input
  609. * source map will be used to get the original position of the source, even
  610. * from a previous compilation step (e.g., from Sass compilation).
  611. * @returns The original position of the node in the source, showing line
  612. * and column numbers and also a small excerpt to facilitate debugging.
  613. */
  614. error(
  615. /**
  616. * Error description.
  617. */
  618. message: string, options?: NodeErrorOptions): CssSyntaxError;
  619. /**
  620. * Creates an instance of Warning and adds it to messages. This method is
  621. * provided as a convenience wrapper for Result#warn.
  622. * Note that `opts.node` is automatically passed to Result#warn for you.
  623. * @param result The result that will receive the warning.
  624. * @param text Warning message. It will be used in the `text` property of
  625. * the message object.
  626. * @param opts Properties to assign to the message object.
  627. */
  628. warn(result: Result, text: string, opts?: WarningOptions): void;
  629. /**
  630. * @returns The next child of the node's parent; or, returns undefined if
  631. * the current node is the last child.
  632. */
  633. next(): ChildNode | undefined;
  634. /**
  635. * @returns The previous child of the node's parent; or, returns undefined
  636. * if the current node is the first child.
  637. */
  638. prev(): ChildNode | undefined;
  639. /**
  640. * Insert new node before current node to current node’s parent.
  641. *
  642. * Just an alias for `node.parent.insertBefore(node, newNode)`.
  643. *
  644. * @returns this node for method chaining.
  645. *
  646. * @example
  647. * decl.before('content: ""');
  648. */
  649. before(newNode: Node | object | string | Node[]): this;
  650. /**
  651. * Insert new node after current node to current node’s parent.
  652. *
  653. * Just an alias for `node.parent.insertAfter(node, newNode)`.
  654. *
  655. * @returns this node for method chaining.
  656. *
  657. * @example
  658. * decl.after('color: black');
  659. */
  660. after(newNode: Node | object | string | Node[]): this;
  661. /**
  662. * @returns The Root instance of the node's tree.
  663. */
  664. root(): Root;
  665. /**
  666. * Removes the node from its parent and cleans the parent property in the
  667. * node and its children.
  668. * @returns This node for chaining.
  669. */
  670. remove(): this;
  671. /**
  672. * Inserts node(s) before the current node and removes the current node.
  673. * @returns This node for chaining.
  674. */
  675. replaceWith(...nodes: (Node | object)[]): this;
  676. /**
  677. * @param overrides New properties to override in the clone.
  678. * @returns A clone of this node. The node and its (cloned) children will
  679. * have a clean parent and code style properties.
  680. */
  681. clone(overrides?: object): this;
  682. /**
  683. * Shortcut to clone the node and insert the resulting cloned node before
  684. * the current node.
  685. * @param overrides New Properties to override in the clone.
  686. * @returns The cloned node.
  687. */
  688. cloneBefore(overrides?: object): this;
  689. /**
  690. * Shortcut to clone the node and insert the resulting cloned node after
  691. * the current node.
  692. * @param overrides New Properties to override in the clone.
  693. * @returns The cloned node.
  694. */
  695. cloneAfter(overrides?: object): this;
  696. /**
  697. * @param prop Name or code style property.
  698. * @param defaultType Name of default value. It can be easily missed if the
  699. * value is the same as prop.
  700. * @returns A code style property value. If the node is missing the code
  701. * style property (because the node was manually built or cloned), PostCSS
  702. * will try to autodetect the code style property by looking at other nodes
  703. * in the tree.
  704. */
  705. raw(prop: string, defaultType?: string): string;
  706. }
  707. interface NodeNewProps {
  708. source?: NodeSource;
  709. raws?: NodeRaws;
  710. }
  711. interface NodeRaws {
  712. /**
  713. * The space symbols before the node. It also stores `*` and `_`
  714. * symbols before the declaration (IE hack).
  715. */
  716. before?: string;
  717. /**
  718. * The space symbols after the last child of the node to the end of
  719. * the node.
  720. */
  721. after?: string;
  722. /**
  723. * The symbols between the property and value for declarations,
  724. * selector and "{" for rules, last parameter and "{" for at-rules.
  725. */
  726. between?: string;
  727. /**
  728. * True if last child has (optional) semicolon.
  729. */
  730. semicolon?: boolean;
  731. /**
  732. * The space between the at-rule's name and parameters.
  733. */
  734. afterName?: string;
  735. /**
  736. * The space symbols between "/*" and comment's text.
  737. */
  738. left?: string;
  739. /**
  740. * The space symbols between comment's text and "*\/".
  741. */
  742. right?: string;
  743. /**
  744. * The content of important statement, if it is not just "!important".
  745. */
  746. important?: string;
  747. }
  748. interface NodeSource {
  749. input: Input;
  750. /**
  751. * The starting position of the node's source.
  752. */
  753. start?: {
  754. column: number;
  755. line: number;
  756. };
  757. /**
  758. * The ending position of the node's source.
  759. */
  760. end?: {
  761. column: number;
  762. line: number;
  763. };
  764. }
  765. interface NodeErrorOptions {
  766. /**
  767. * Plugin name that created this error. PostCSS will set it automatically.
  768. */
  769. plugin?: string;
  770. /**
  771. * A word inside a node's string, that should be highlighted as source
  772. * of error.
  773. */
  774. word?: string;
  775. /**
  776. * An index inside a node's string that should be highlighted as source
  777. * of error.
  778. */
  779. index?: number;
  780. }
  781. interface JsonNode {
  782. /**
  783. * Returns a string representing the node's type. Possible values are
  784. * root, atrule, rule, decl or comment.
  785. */
  786. type?: string;
  787. /**
  788. * Returns the node's parent node.
  789. */
  790. parent?: JsonContainer;
  791. /**
  792. * Returns the input source of the node. The property is used in source
  793. * map generation. If you create a node manually (e.g., with
  794. * postcss.decl() ), that node will not have a source property and
  795. * will be absent from the source map. For this reason, the plugin
  796. * developer should consider cloning nodes to create new ones (in which
  797. * case the new node's source will reference the original, cloned node)
  798. * or setting the source property manually.
  799. */
  800. source?: NodeSource;
  801. /**
  802. * Contains information to generate byte-to-byte equal node string as it
  803. * was in origin input.
  804. */
  805. raws?: NodeRaws;
  806. }
  807. type Container = Root | AtRule | Rule;
  808. /**
  809. * Containers can store any content. If you write a rule inside a rule,
  810. * PostCSS will parse it.
  811. */
  812. interface ContainerBase extends NodeBase {
  813. /**
  814. * Contains the container's children.
  815. */
  816. nodes?: ChildNode[];
  817. /**
  818. * @returns The container's first child.
  819. */
  820. first?: ChildNode;
  821. /**
  822. * @returns The container's last child.
  823. */
  824. last?: ChildNode;
  825. /**
  826. * @param overrides New properties to override in the clone.
  827. * @returns A clone of this node. The node and its (cloned) children will
  828. * have a clean parent and code style properties.
  829. */
  830. clone(overrides?: object): this;
  831. /**
  832. * @param child Child of the current container.
  833. * @returns The child's index within the container's "nodes" array.
  834. */
  835. index(child: ChildNode | number): number;
  836. /**
  837. * Determines whether all child nodes satisfy the specified test.
  838. * @param callback A function that accepts up to three arguments. The
  839. * every method calls the callback function for each node until the
  840. * callback returns false, or until the end of the array.
  841. * @returns True if the callback returns true for all of the container's
  842. * children.
  843. */
  844. every(callback: (node: ChildNode, index: number, nodes: ChildNode[]) => boolean): boolean;
  845. /**
  846. * Determines whether the specified callback returns true for any child node.
  847. * @param callback A function that accepts up to three arguments. The some
  848. * method calls the callback for each node until the callback returns true,
  849. * or until the end of the array.
  850. * @returns True if callback returns true for (at least) one of the
  851. * container's children.
  852. */
  853. some(callback: (node: ChildNode, index: number, nodes: ChildNode[]) => boolean): boolean;
  854. /**
  855. * Iterates through the container's immediate children, calling the
  856. * callback function for each child. If you need to recursively iterate
  857. * through all the container's descendant nodes, use container.walk().
  858. * Unlike the for {} -cycle or Array#forEach() this iterator is safe if
  859. * you are mutating the array of child nodes during iteration.
  860. * @param callback Iterator. Returning false will break iteration. Safe
  861. * if you are mutating the array of child nodes during iteration. PostCSS
  862. * will adjust the current index to match the mutations.
  863. * @returns False if the callback returns false during iteration.
  864. */
  865. each(callback: (node: ChildNode, index: number) => void): void;
  866. each(callback: (node: ChildNode, index: number) => boolean): boolean;
  867. /**
  868. * Traverses the container's descendant nodes, calling `callback` for each
  869. * node. Like container.each(), this method is safe to use if you are
  870. * mutating arrays during iteration. If you only need to iterate through
  871. * the container's immediate children, use container.each().
  872. * @param callback Iterator.
  873. */
  874. walk(callback: (node: ChildNode, index: number) => void): void;
  875. walk(callback: (node: ChildNode, index: number) => boolean): boolean;
  876. /**
  877. * Traverses the container's descendant nodes, calling `callback` for each
  878. * declaration. Like container.each(), this method is safe to use if you
  879. * are mutating arrays during iteration.
  880. * @param propFilter Filters declarations by property name. Only those
  881. * declarations whose property matches propFilter will be iterated over.
  882. * @param callback Called for each declaration node within the container.
  883. */
  884. walkDecls(propFilter: string | RegExp, callback: (decl: Declaration, index: number) => void): void;
  885. walkDecls(callback: (decl: Declaration, index: number) => void): void;
  886. walkDecls(propFilter: string | RegExp, callback: (decl: Declaration, index: number) => boolean): boolean;
  887. walkDecls(callback: (decl: Declaration, index: number) => boolean): boolean;
  888. /**
  889. * Traverses the container's descendant nodes, calling `callback` for each
  890. * at-rule. Like container.each(), this method is safe to use if you are
  891. * mutating arrays during iteration.
  892. * @param nameFilter Filters at-rules by name. If provided, iteration
  893. * will only happen over at-rules that have matching names.
  894. * @param callback Iterator called for each at-rule node within the
  895. * container.
  896. */
  897. walkAtRules(nameFilter: string | RegExp, callback: (atRule: AtRule, index: number) => void): void;
  898. walkAtRules(callback: (atRule: AtRule, index: number) => void): void;
  899. walkAtRules(nameFilter: string | RegExp, callback: (atRule: AtRule, index: number) => boolean): boolean;
  900. walkAtRules(callback: (atRule: AtRule, index: number) => boolean): boolean;
  901. /**
  902. * Traverses the container's descendant nodes, calling `callback` for each
  903. * rule. Like container.each(), this method is safe to use if you are
  904. * mutating arrays during iteration.
  905. * @param selectorFilter Filters rules by selector. If provided,
  906. * iteration will only happen over rules that have matching names.
  907. * @param callback Iterator called for each rule node within the
  908. * container.
  909. */
  910. walkRules(selectorFilter: string | RegExp, callback: (atRule: Rule, index: number) => void): void;
  911. walkRules(callback: (atRule: Rule, index: number) => void): void;
  912. walkRules(selectorFilter: string | RegExp, callback: (atRule: Rule, index: number) => boolean): boolean;
  913. walkRules(callback: (atRule: Rule, index: number) => boolean): boolean;
  914. /**
  915. * Traverses the container's descendant nodes, calling `callback` for each
  916. * comment. Like container.each(), this method is safe to use if you are
  917. * mutating arrays during iteration.
  918. * @param callback Iterator called for each comment node within the container.
  919. */
  920. walkComments(callback: (comment: Comment, indexed: number) => void): void;
  921. walkComments(callback: (comment: Comment, indexed: number) => boolean): boolean;
  922. /**
  923. * Passes all declaration values within the container that match pattern
  924. * through the callback, replacing those values with the returned result of
  925. * callback. This method is useful if you are using a custom unit or
  926. * function and need to iterate through all values.
  927. * @param pattern Pattern that we need to replace.
  928. * @param options Options to speed up the search.
  929. * @param callbackOrReplaceValue String to replace pattern or callback
  930. * that will return a new value. The callback will receive the same
  931. * arguments as those passed to a function parameter of String#replace.
  932. */
  933. replaceValues(pattern: string | RegExp, options: {
  934. /**
  935. * Property names. The method will only search for values that match
  936. * regexp within declarations of listed properties.
  937. */
  938. props?: string[];
  939. /**
  940. * Used to narrow down values and speed up the regexp search. Searching
  941. * every single value with a regexp can be slow. If you pass a fast
  942. * string, PostCSS will first check whether the value contains the fast
  943. * string; and only if it does will PostCSS check that value against
  944. * regexp. For example, instead of just checking for /\d+rem/ on all
  945. * values, set fast: 'rem' to first check whether a value has the rem
  946. * unit, and only if it does perform the regexp check.
  947. */
  948. fast?: string;
  949. }, callbackOrReplaceValue: string | {
  950. (substring: string, ...args: any[]): string;
  951. }): this;
  952. replaceValues(pattern: string | RegExp, callbackOrReplaceValue: string | {
  953. (substring: string, ...args: any[]): string;
  954. }): this;
  955. /**
  956. * Inserts new nodes to the beginning of the container.
  957. * Because each node class is identifiable by unique properties, use the
  958. * following shortcuts to create nodes in insert methods:
  959. * root.prepend({ name: '@charset', params: '"UTF-8"' }); // at-rule
  960. * root.prepend({ selector: 'a' }); // rule
  961. * rule.prepend({ prop: 'color', value: 'black' }); // declaration
  962. * rule.prepend({ text: 'Comment' }) // comment
  963. * A string containing the CSS of the new element can also be used. This
  964. * approach is slower than the above shortcuts.
  965. * root.prepend('a {}');
  966. * root.first.prepend('color: black; z-index: 1');
  967. * @param nodes New nodes.
  968. * @returns This container for chaining.
  969. */
  970. prepend(...nodes: (Node | object | string)[]): this;
  971. /**
  972. * Inserts new nodes to the end of the container.
  973. * Because each node class is identifiable by unique properties, use the
  974. * following shortcuts to create nodes in insert methods:
  975. * root.append({ name: '@charset', params: '"UTF-8"' }); // at-rule
  976. * root.append({ selector: 'a' }); // rule
  977. * rule.append({ prop: 'color', value: 'black' }); // declaration
  978. * rule.append({ text: 'Comment' }) // comment
  979. * A string containing the CSS of the new element can also be used. This
  980. * approach is slower than the above shortcuts.
  981. * root.append('a {}');
  982. * root.first.append('color: black; z-index: 1');
  983. * @param nodes New nodes.
  984. * @returns This container for chaining.
  985. */
  986. append(...nodes: (Node | object | string)[]): this;
  987. /**
  988. * Insert newNode before oldNode within the container.
  989. * @param oldNode Child or child's index.
  990. * @returns This container for chaining.
  991. */
  992. insertBefore(oldNode: ChildNode | number, newNode: ChildNode | object | string): this;
  993. /**
  994. * Insert newNode after oldNode within the container.
  995. * @param oldNode Child or child's index.
  996. * @returns This container for chaining.
  997. */
  998. insertAfter(oldNode: ChildNode | number, newNode: ChildNode | object | string): this;
  999. /**
  1000. * Removes the container from its parent and cleans the parent property in the
  1001. * container and its children.
  1002. * @returns This container for chaining.
  1003. */
  1004. remove(): this;
  1005. /**
  1006. * Removes child from the container and cleans the parent properties
  1007. * from the node and its children.
  1008. * @param child Child or child's index.
  1009. * @returns This container for chaining.
  1010. */
  1011. removeChild(child: ChildNode | number): this;
  1012. /**
  1013. * Removes all children from the container and cleans their parent
  1014. * properties.
  1015. * @returns This container for chaining.
  1016. */
  1017. removeAll(): this;
  1018. }
  1019. interface ContainerNewProps extends NodeNewProps {
  1020. /**
  1021. * Contains the container's children.
  1022. */
  1023. nodes?: ChildNode[];
  1024. raws?: ContainerRaws;
  1025. }
  1026. interface ContainerRaws extends NodeRaws {
  1027. indent?: string;
  1028. }
  1029. interface JsonContainer extends JsonNode {
  1030. /**
  1031. * Contains the container's children.
  1032. */
  1033. nodes?: ChildNode[];
  1034. /**
  1035. * @returns The container's first child.
  1036. */
  1037. first?: ChildNode;
  1038. /**
  1039. * @returns The container's last child.
  1040. */
  1041. last?: ChildNode;
  1042. }
  1043. /**
  1044. * Represents a CSS file and contains all its parsed nodes.
  1045. */
  1046. interface Root extends ContainerBase {
  1047. type: 'root';
  1048. /**
  1049. * Inherited from Container. Should always be undefined for a Root node.
  1050. */
  1051. parent: void;
  1052. /**
  1053. * @param overrides New properties to override in the clone.
  1054. * @returns A clone of this node. The node and its (cloned) children will
  1055. * have a clean parent and code style properties.
  1056. */
  1057. clone(overrides?: object): this;
  1058. /**
  1059. * @returns A Result instance representing the root's CSS.
  1060. */
  1061. toResult(options?: {
  1062. /**
  1063. * The path where you'll put the output CSS file. You should always
  1064. * set "to" to generate correct source maps.
  1065. */
  1066. to?: string;
  1067. map?: SourceMapOptions;
  1068. }): Result;
  1069. /**
  1070. * Removes child from the root node, and the parent properties of node and
  1071. * its children.
  1072. * @param child Child or child's index.
  1073. * @returns This root node for chaining.
  1074. */
  1075. removeChild(child: ChildNode | number): this;
  1076. }
  1077. interface RootNewProps extends ContainerNewProps {
  1078. }
  1079. interface JsonRoot extends JsonContainer {
  1080. }
  1081. /**
  1082. * Represents an at-rule. If it's followed in the CSS by a {} block, this
  1083. * node will have a nodes property representing its children.
  1084. */
  1085. interface AtRule extends ContainerBase {
  1086. type: 'atrule';
  1087. /**
  1088. * Returns the atrule's parent node.
  1089. */
  1090. parent: Container;
  1091. /**
  1092. * The identifier that immediately follows the @.
  1093. */
  1094. name: string;
  1095. /**
  1096. * These are the values that follow the at-rule's name, but precede any {}
  1097. * block. The spec refers to this area as the at-rule's "prelude".
  1098. */
  1099. params: string;
  1100. /**
  1101. * @param overrides New properties to override in the clone.
  1102. * @returns A clone of this node. The node and its (cloned) children will
  1103. * have a clean parent and code style properties.
  1104. */
  1105. clone(overrides?: object): this;
  1106. }
  1107. interface AtRuleNewProps extends ContainerNewProps {
  1108. /**
  1109. * The identifier that immediately follows the @.
  1110. */
  1111. name?: string;
  1112. /**
  1113. * These are the values that follow the at-rule's name, but precede any {}
  1114. * block. The spec refers to this area as the at-rule's "prelude".
  1115. */
  1116. params?: string | number;
  1117. raws?: AtRuleRaws;
  1118. }
  1119. interface AtRuleRaws extends NodeRaws {
  1120. params?: string;
  1121. }
  1122. interface JsonAtRule extends JsonContainer {
  1123. /**
  1124. * The identifier that immediately follows the @.
  1125. */
  1126. name?: string;
  1127. /**
  1128. * These are the values that follow the at-rule's name, but precede any {}
  1129. * block. The spec refers to this area as the at-rule's "prelude".
  1130. */
  1131. params?: string;
  1132. }
  1133. /**
  1134. * Represents a CSS rule: a selector followed by a declaration block.
  1135. */
  1136. interface Rule extends ContainerBase {
  1137. type: 'rule';
  1138. /**
  1139. * Returns the rule's parent node.
  1140. */
  1141. parent: Container;
  1142. /**
  1143. * The rule's full selector. If there are multiple comma-separated selectors,
  1144. * the entire group will be included.
  1145. */
  1146. selector: string;
  1147. /**
  1148. * An array containing the rule's individual selectors.
  1149. * Groups of selectors are split at commas.
  1150. */
  1151. selectors: string[];
  1152. /**
  1153. * @param overrides New properties to override in the clone.
  1154. * @returns A clone of this node. The node and its (cloned) children will
  1155. * have a clean parent and code style properties.
  1156. */
  1157. clone(overrides?: object): this;
  1158. }
  1159. interface RuleNewProps extends ContainerNewProps {
  1160. /**
  1161. * The rule's full selector. If there are multiple comma-separated selectors,
  1162. * the entire group will be included.
  1163. */
  1164. selector?: string;
  1165. /**
  1166. * An array containing the rule's individual selectors. Groups of selectors
  1167. * are split at commas.
  1168. */
  1169. selectors?: string[];
  1170. raws?: RuleRaws;
  1171. }
  1172. interface RuleRaws extends ContainerRaws {
  1173. /**
  1174. * The rule's full selector. If there are multiple comma-separated selectors,
  1175. * the entire group will be included.
  1176. */
  1177. selector?: string;
  1178. }
  1179. interface JsonRule extends JsonContainer {
  1180. /**
  1181. * The rule's full selector. If there are multiple comma-separated selectors,
  1182. * the entire group will be included.
  1183. */
  1184. selector?: string;
  1185. /**
  1186. * An array containing the rule's individual selectors.
  1187. * Groups of selectors are split at commas.
  1188. */
  1189. selectors?: string[];
  1190. }
  1191. /**
  1192. * Represents a CSS declaration.
  1193. */
  1194. interface Declaration extends NodeBase {
  1195. type: 'decl';
  1196. /**
  1197. * Returns the declaration's parent node.
  1198. */
  1199. parent: Container;
  1200. /**
  1201. * The declaration's property name.
  1202. */
  1203. prop: string;
  1204. /**
  1205. * The declaration's value. This value will be cleaned of comments. If the
  1206. * source value contained comments, those comments will be available in the
  1207. * _value.raws property. If you have not changed the value, the result of
  1208. * decl.toString() will include the original raws value (comments and all).
  1209. */
  1210. value: string;
  1211. /**
  1212. * True if the declaration has an !important annotation.
  1213. */
  1214. important: boolean;
  1215. /**
  1216. * @param overrides New properties to override in the clone.
  1217. * @returns A clone of this node. The node and its (cloned) children will
  1218. * have a clean parent and code style properties.
  1219. */
  1220. clone(overrides?: object): this;
  1221. }
  1222. interface DeclarationNewProps {
  1223. /**
  1224. * The declaration's property name.
  1225. */
  1226. prop?: string;
  1227. /**
  1228. * The declaration's value. This value will be cleaned of comments. If the
  1229. * source value contained comments, those comments will be available in the
  1230. * _value.raws property. If you have not changed the value, the result of
  1231. * decl.toString() will include the original raws value (comments and all).
  1232. */
  1233. value?: string;
  1234. raws?: DeclarationRaws;
  1235. }
  1236. interface DeclarationRaws extends NodeRaws {
  1237. /**
  1238. * The declaration's value. This value will be cleaned of comments.
  1239. * If the source value contained comments, those comments will be
  1240. * available in the _value.raws property. If you have not changed the value, the result of
  1241. * decl.toString() will include the original raws value (comments and all).
  1242. */
  1243. value?: string;
  1244. }
  1245. interface JsonDeclaration extends JsonNode {
  1246. /**
  1247. * True if the declaration has an !important annotation.
  1248. */
  1249. important?: boolean;
  1250. }
  1251. /**
  1252. * Represents a comment between declarations or statements (rule and at-rules).
  1253. * Comments inside selectors, at-rule parameters, or declaration values will
  1254. * be stored in the Node#raws properties.
  1255. */
  1256. interface Comment extends NodeBase {
  1257. type: 'comment';
  1258. /**
  1259. * Returns the comment's parent node.
  1260. */
  1261. parent: Container;
  1262. /**
  1263. * The comment's text.
  1264. */
  1265. text: string;
  1266. /**
  1267. * @param overrides New properties to override in the clone.
  1268. * @returns A clone of this node. The node and its (cloned) children will
  1269. * have a clean parent and code style properties.
  1270. */
  1271. clone(overrides?: object): this;
  1272. }
  1273. interface CommentNewProps {
  1274. /**
  1275. * The comment's text.
  1276. */
  1277. text?: string;
  1278. }
  1279. interface JsonComment extends JsonNode {
  1280. }
  1281. }
  1282. export = postcss;