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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. import AtRule = require('./at-rule.js')
  2. import { AtRuleProps } from './at-rule.js'
  3. import Comment, { CommentProps } from './comment.js'
  4. import Container from './container.js'
  5. import CssSyntaxError from './css-syntax-error.js'
  6. import Declaration, { DeclarationProps } from './declaration.js'
  7. import Document from './document.js'
  8. import Input from './input.js'
  9. import { Stringifier, Syntax } from './postcss.js'
  10. import Result from './result.js'
  11. import Root from './root.js'
  12. import Rule, { RuleProps } from './rule.js'
  13. import Warning, { WarningOptions } from './warning.js'
  14. declare namespace Node {
  15. export type ChildNode = AtRule.default | Comment | Declaration | Rule
  16. export type AnyNode =
  17. | AtRule.default
  18. | Comment
  19. | Declaration
  20. | Document
  21. | Root
  22. | Rule
  23. export type ChildProps =
  24. | AtRuleProps
  25. | CommentProps
  26. | DeclarationProps
  27. | RuleProps
  28. export interface Position {
  29. /**
  30. * Source line in file. In contrast to `offset` it starts from 1.
  31. */
  32. column: number
  33. /**
  34. * Source column in file.
  35. */
  36. line: number
  37. /**
  38. * Source offset in file. It starts from 0.
  39. */
  40. offset: number
  41. }
  42. export interface Range {
  43. /**
  44. * End position, exclusive.
  45. */
  46. end: Position
  47. /**
  48. * Start position, inclusive.
  49. */
  50. start: Position
  51. }
  52. /**
  53. * Source represents an interface for the {@link Node.source} property.
  54. */
  55. export interface Source {
  56. /**
  57. * The inclusive ending position for the source
  58. * code of a node.
  59. */
  60. end?: Position
  61. /**
  62. * The source file from where a node has originated.
  63. */
  64. input: Input
  65. /**
  66. * The inclusive starting position for the source
  67. * code of a node.
  68. */
  69. start?: Position
  70. }
  71. /**
  72. * Interface represents an interface for an object received
  73. * as parameter by Node class constructor.
  74. */
  75. export interface NodeProps {
  76. source?: Source
  77. }
  78. export interface NodeErrorOptions {
  79. /**
  80. * An ending index inside a node's string that should be highlighted as
  81. * source of error.
  82. */
  83. endIndex?: number
  84. /**
  85. * An index inside a node's string that should be highlighted as source
  86. * of error.
  87. */
  88. index?: number
  89. /**
  90. * Plugin name that created this error. PostCSS will set it automatically.
  91. */
  92. plugin?: string
  93. /**
  94. * A word inside a node's string, that should be highlighted as source
  95. * of error.
  96. */
  97. word?: string
  98. }
  99. // eslint-disable-next-line @typescript-eslint/no-shadow
  100. class Node extends Node_ {}
  101. export { Node as default }
  102. }
  103. /**
  104. * It represents an abstract class that handles common
  105. * methods for other CSS abstract syntax tree nodes.
  106. *
  107. * Any node that represents CSS selector or value should
  108. * not extend the `Node` class.
  109. */
  110. declare abstract class Node_ {
  111. /**
  112. * It represents parent of the current node.
  113. *
  114. * ```js
  115. * root.nodes[0].parent === root //=> true
  116. * ```
  117. */
  118. parent: Container | Document | undefined
  119. /**
  120. * It represents unnecessary whitespace and characters present
  121. * in the css source code.
  122. *
  123. * Information to generate byte-to-byte equal node string as it was
  124. * in the origin input.
  125. *
  126. * The properties of the raws object are decided by parser,
  127. * the default parser uses the following properties:
  128. *
  129. * * `before`: the space symbols before the node. It also stores `*`
  130. * and `_` symbols before the declaration (IE hack).
  131. * * `after`: the space symbols after the last child of the node
  132. * to the end of the node.
  133. * * `between`: the symbols between the property and value
  134. * for declarations, selector and `{` for rules, or last parameter
  135. * and `{` for at-rules.
  136. * * `semicolon`: contains true if the last child has
  137. * an (optional) semicolon.
  138. * * `afterName`: the space between the at-rule name and its parameters.
  139. * * `left`: the space symbols between `/*` and the comment’s text.
  140. * * `right`: the space symbols between the comment’s text
  141. * and <code>*&#47;</code>.
  142. * - `important`: the content of the important statement,
  143. * if it is not just `!important`.
  144. *
  145. * PostCSS filters out the comments inside selectors, declaration values
  146. * and at-rule parameters but it stores the origin content in raws.
  147. *
  148. * ```js
  149. * const root = postcss.parse('a {\n color:black\n}')
  150. * root.first.first.raws //=> { before: '\n ', between: ':' }
  151. * ```
  152. */
  153. raws: any
  154. /**
  155. * It represents information related to origin of a node and is required
  156. * for generating source maps.
  157. *
  158. * The nodes that are created manually using the public APIs
  159. * provided by PostCSS will have `source` undefined and
  160. * will be absent in the source map.
  161. *
  162. * For this reason, the plugin developer should consider
  163. * duplicating nodes as the duplicate node will have the
  164. * same source as the original node by default or assign
  165. * source to a node created manually.
  166. *
  167. * ```js
  168. * decl.source.input.from //=> '/home/ai/source.css'
  169. * decl.source.start //=> { line: 10, column: 2 }
  170. * decl.source.end //=> { line: 10, column: 12 }
  171. * ```
  172. *
  173. * ```js
  174. * // Incorrect method, source not specified!
  175. * const prefixed = postcss.decl({
  176. * prop: '-moz-' + decl.prop,
  177. * value: decl.value
  178. * })
  179. *
  180. * // Correct method, source is inherited when duplicating.
  181. * const prefixed = decl.clone({
  182. * prop: '-moz-' + decl.prop
  183. * })
  184. * ```
  185. *
  186. * ```js
  187. * if (atrule.name === 'add-link') {
  188. * const rule = postcss.rule({
  189. * selector: 'a',
  190. * source: atrule.source
  191. * })
  192. *
  193. * atrule.parent.insertBefore(atrule, rule)
  194. * }
  195. * ```
  196. */
  197. source?: Node.Source
  198. /**
  199. * It represents type of a node in
  200. * an abstract syntax tree.
  201. *
  202. * A type of node helps in identification of a node
  203. * and perform operation based on it's type.
  204. *
  205. * ```js
  206. * const declaration = new Declaration({
  207. * prop: 'color',
  208. * value: 'black'
  209. * })
  210. *
  211. * declaration.type //=> 'decl'
  212. * ```
  213. */
  214. type: string
  215. constructor(defaults?: object)
  216. /**
  217. * Insert new node after current node to current node’s parent.
  218. *
  219. * Just alias for `node.parent.insertAfter(node, add)`.
  220. *
  221. * ```js
  222. * decl.after('color: black')
  223. * ```
  224. *
  225. * @param newNode New node.
  226. * @return This node for methods chain.
  227. */
  228. after(newNode: Node | Node.ChildProps | Node[] | string | undefined): this
  229. /**
  230. * It assigns properties to an existing node instance.
  231. *
  232. * ```js
  233. * decl.assign({ prop: 'word-wrap', value: 'break-word' })
  234. * ```
  235. *
  236. * @param overrides New properties to override the node.
  237. *
  238. * @return `this` for method chaining.
  239. */
  240. assign(overrides: object): this
  241. /**
  242. * Insert new node before current node to current node’s parent.
  243. *
  244. * Just alias for `node.parent.insertBefore(node, add)`.
  245. *
  246. * ```js
  247. * decl.before('content: ""')
  248. * ```
  249. *
  250. * @param newNode New node.
  251. * @return This node for methods chain.
  252. */
  253. before(newNode: Node | Node.ChildProps | Node[] | string | undefined): this
  254. /**
  255. * Clear the code style properties for the node and its children.
  256. *
  257. * ```js
  258. * node.raws.before //=> ' '
  259. * node.cleanRaws()
  260. * node.raws.before //=> undefined
  261. * ```
  262. *
  263. * @param keepBetween Keep the `raws.between` symbols.
  264. */
  265. cleanRaws(keepBetween?: boolean): void
  266. /**
  267. * It creates clone of an existing node, which includes all the properties
  268. * and their values, that includes `raws` but not `type`.
  269. *
  270. * ```js
  271. * decl.raws.before //=> "\n "
  272. * const cloned = decl.clone({ prop: '-moz-' + decl.prop })
  273. * cloned.raws.before //=> "\n "
  274. * cloned.toString() //=> -moz-transform: scale(0)
  275. * ```
  276. *
  277. * @param overrides New properties to override in the clone.
  278. *
  279. * @return Duplicate of the node instance.
  280. */
  281. clone(overrides?: object): this
  282. /**
  283. * Shortcut to clone the node and insert the resulting cloned node
  284. * after the current node.
  285. *
  286. * @param overrides New properties to override in the clone.
  287. * @return New node.
  288. */
  289. cloneAfter(overrides?: object): this
  290. /**
  291. * Shortcut to clone the node and insert the resulting cloned node
  292. * before the current node.
  293. *
  294. * ```js
  295. * decl.cloneBefore({ prop: '-moz-' + decl.prop })
  296. * ```
  297. *
  298. * @param overrides Mew properties to override in the clone.
  299. *
  300. * @return New node
  301. */
  302. cloneBefore(overrides?: object): this
  303. /**
  304. * It creates an instance of the class `CssSyntaxError` and parameters passed
  305. * to this method are assigned to the error instance.
  306. *
  307. * The error instance will have description for the
  308. * error, original position of the node in the
  309. * source, showing line and column number.
  310. *
  311. * If any previous map is present, it would be used
  312. * to get original position of the source.
  313. *
  314. * The Previous Map here is referred to the source map
  315. * generated by previous compilation, example: Less,
  316. * Stylus and Sass.
  317. *
  318. * This method returns the error instance instead of
  319. * throwing it.
  320. *
  321. * ```js
  322. * if (!variables[name]) {
  323. * throw decl.error(`Unknown variable ${name}`, { word: name })
  324. * // CssSyntaxError: postcss-vars:a.sass:4:3: Unknown variable $black
  325. * // color: $black
  326. * // a
  327. * // ^
  328. * // background: white
  329. * }
  330. * ```
  331. *
  332. * @param message Description for the error instance.
  333. * @param options Options for the error instance.
  334. *
  335. * @return Error instance is returned.
  336. */
  337. error(message: string, options?: Node.NodeErrorOptions): CssSyntaxError
  338. /**
  339. * Returns the next child of the node’s parent.
  340. * Returns `undefined` if the current node is the last child.
  341. *
  342. * ```js
  343. * if (comment.text === 'delete next') {
  344. * const next = comment.next()
  345. * if (next) {
  346. * next.remove()
  347. * }
  348. * }
  349. * ```
  350. *
  351. * @return Next node.
  352. */
  353. next(): Node.ChildNode | undefined
  354. /**
  355. * Get the position for a word or an index inside the node.
  356. *
  357. * @param opts Options.
  358. * @return Position.
  359. */
  360. positionBy(opts?: Pick<WarningOptions, 'index' | 'word'>): Node.Position
  361. /**
  362. * Convert string index to line/column.
  363. *
  364. * @param index The symbol number in the node’s string.
  365. * @return Symbol position in file.
  366. */
  367. positionInside(index: number): Node.Position
  368. /**
  369. * Returns the previous child of the node’s parent.
  370. * Returns `undefined` if the current node is the first child.
  371. *
  372. * ```js
  373. * const annotation = decl.prev()
  374. * if (annotation.type === 'comment') {
  375. * readAnnotation(annotation.text)
  376. * }
  377. * ```
  378. *
  379. * @return Previous node.
  380. */
  381. prev(): Node.ChildNode | undefined
  382. /**
  383. * Get the range for a word or start and end index inside the node.
  384. * The start index is inclusive; the end index is exclusive.
  385. *
  386. * @param opts Options.
  387. * @return Range.
  388. */
  389. rangeBy(
  390. opts?: Pick<WarningOptions, 'endIndex' | 'index' | 'word'>
  391. ): Node.Range
  392. /**
  393. * Returns a `raws` value. If the node is missing
  394. * the code style property (because the node was manually built or cloned),
  395. * PostCSS will try to autodetect the code style property by looking
  396. * at other nodes in the tree.
  397. *
  398. * ```js
  399. * const root = postcss.parse('a { background: white }')
  400. * root.nodes[0].append({ prop: 'color', value: 'black' })
  401. * root.nodes[0].nodes[1].raws.before //=> undefined
  402. * root.nodes[0].nodes[1].raw('before') //=> ' '
  403. * ```
  404. *
  405. * @param prop Name of code style property.
  406. * @param defaultType Name of default value, it can be missed
  407. * if the value is the same as prop.
  408. * @return {string} Code style value.
  409. */
  410. raw(prop: string, defaultType?: string): string
  411. /**
  412. * It removes the node from its parent and deletes its parent property.
  413. *
  414. * ```js
  415. * if (decl.prop.match(/^-webkit-/)) {
  416. * decl.remove()
  417. * }
  418. * ```
  419. *
  420. * @return `this` for method chaining.
  421. */
  422. remove(): this
  423. /**
  424. * Inserts node(s) before the current node and removes the current node.
  425. *
  426. * ```js
  427. * AtRule: {
  428. * mixin: atrule => {
  429. * atrule.replaceWith(mixinRules[atrule.params])
  430. * }
  431. * }
  432. * ```
  433. *
  434. * @param nodes Mode(s) to replace current one.
  435. * @return Current node to methods chain.
  436. */
  437. replaceWith(
  438. ...nodes: (
  439. | Node
  440. | Node[]
  441. | Node.ChildProps
  442. | Node.ChildProps[]
  443. )[]
  444. ): this
  445. /**
  446. * Finds the Root instance of the node’s tree.
  447. *
  448. * ```js
  449. * root.nodes[0].nodes[0].root() === root
  450. * ```
  451. *
  452. * @return Root parent.
  453. */
  454. root(): Root
  455. /**
  456. * Fix circular links on `JSON.stringify()`.
  457. *
  458. * @return Cleaned object.
  459. */
  460. toJSON(): object
  461. /**
  462. * It compiles the node to browser readable cascading style sheets string
  463. * depending on it's type.
  464. *
  465. * ```js
  466. * new Rule({ selector: 'a' }).toString() //=> "a {}"
  467. * ```
  468. *
  469. * @param stringifier A syntax to use in string generation.
  470. * @return CSS string of this node.
  471. */
  472. toString(stringifier?: Stringifier | Syntax): string
  473. /**
  474. * It is a wrapper for {@link Result#warn}, providing convenient
  475. * way of generating warnings.
  476. *
  477. * ```js
  478. * Declaration: {
  479. * bad: (decl, { result }) => {
  480. * decl.warn(result, 'Deprecated property: bad')
  481. * }
  482. * }
  483. * ```
  484. *
  485. * @param result The `Result` instance that will receive the warning.
  486. * @param message Description for the warning.
  487. * @param options Options for the warning.
  488. *
  489. * @return `Warning` instance is returned
  490. */
  491. warn(result: Result, message: string, options?: WarningOptions): Warning
  492. }
  493. declare class Node extends Node_ {}
  494. export = Node