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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. import AtRule from './at-rule.js'
  2. import Comment from './comment.js'
  3. import Declaration from './declaration.js'
  4. import Node, { ChildNode, ChildProps, NodeProps } from './node.js'
  5. import Rule from './rule.js'
  6. declare namespace Container {
  7. export class ContainerWithChildren<
  8. Child extends Node = ChildNode
  9. > extends Container_<Child> {
  10. nodes: Child[]
  11. }
  12. export interface ValueOptions {
  13. /**
  14. * String that’s used to narrow down values and speed up the regexp search.
  15. */
  16. fast?: string
  17. /**
  18. * An array of property names.
  19. */
  20. props?: string[]
  21. }
  22. export interface ContainerProps extends NodeProps {
  23. nodes?: (Node | ChildProps)[]
  24. }
  25. // eslint-disable-next-line @typescript-eslint/no-use-before-define
  26. export { Container_ as default }
  27. }
  28. /**
  29. * The `Root`, `AtRule`, and `Rule` container nodes
  30. * inherit some common methods to help work with their children.
  31. *
  32. * Note that all containers can store any content. If you write a rule inside
  33. * a rule, PostCSS will parse it.
  34. */
  35. declare abstract class Container_<Child extends Node = ChildNode> extends Node {
  36. /**
  37. * An array containing the container’s children.
  38. *
  39. * ```js
  40. * const root = postcss.parse('a { color: black }')
  41. * root.nodes.length //=> 1
  42. * root.nodes[0].selector //=> 'a'
  43. * root.nodes[0].nodes[0].prop //=> 'color'
  44. * ```
  45. */
  46. nodes: Child[] | undefined
  47. /**
  48. * Inserts new nodes to the end of the container.
  49. *
  50. * ```js
  51. * const decl1 = new Declaration({ prop: 'color', value: 'black' })
  52. * const decl2 = new Declaration({ prop: 'background-color', value: 'white' })
  53. * rule.append(decl1, decl2)
  54. *
  55. * root.append({ name: 'charset', params: '"UTF-8"' }) // at-rule
  56. * root.append({ selector: 'a' }) // rule
  57. * rule.append({ prop: 'color', value: 'black' }) // declaration
  58. * rule.append({ text: 'Comment' }) // comment
  59. *
  60. * root.append('a {}')
  61. * root.first.append('color: black; z-index: 1')
  62. * ```
  63. *
  64. * @param nodes New nodes.
  65. * @return This node for methods chain.
  66. */
  67. append(
  68. ...nodes: (
  69. | ChildProps
  70. | ChildProps[]
  71. | Node
  72. | Node[]
  73. | string
  74. | string[]
  75. | undefined
  76. )[]
  77. ): this
  78. assign(overrides: Container.ContainerProps | object): this
  79. clone(overrides?: Partial<Container.ContainerProps>): this
  80. cloneAfter(overrides?: Partial<Container.ContainerProps>): this
  81. cloneBefore(overrides?: Partial<Container.ContainerProps>): this
  82. /**
  83. * Iterates through the container’s immediate children,
  84. * calling `callback` for each child.
  85. *
  86. * Returning `false` in the callback will break iteration.
  87. *
  88. * This method only iterates through the container’s immediate children.
  89. * If you need to recursively iterate through all the container’s descendant
  90. * nodes, use `Container#walk`.
  91. *
  92. * Unlike the for `{}`-cycle or `Array#forEach` this iterator is safe
  93. * if you are mutating the array of child nodes during iteration.
  94. * PostCSS will adjust the current index to match the mutations.
  95. *
  96. * ```js
  97. * const root = postcss.parse('a { color: black; z-index: 1 }')
  98. * const rule = root.first
  99. *
  100. * for (const decl of rule.nodes) {
  101. * decl.cloneBefore({ prop: '-webkit-' + decl.prop })
  102. * // Cycle will be infinite, because cloneBefore moves the current node
  103. * // to the next index
  104. * }
  105. *
  106. * rule.each(decl => {
  107. * decl.cloneBefore({ prop: '-webkit-' + decl.prop })
  108. * // Will be executed only for color and z-index
  109. * })
  110. * ```
  111. *
  112. * @param callback Iterator receives each node and index.
  113. * @return Returns `false` if iteration was broke.
  114. */
  115. each(
  116. callback: (node: Child, index: number) => false | void
  117. ): false | undefined
  118. /**
  119. * Returns `true` if callback returns `true`
  120. * for all of the container’s children.
  121. *
  122. * ```js
  123. * const noPrefixes = rule.every(i => i.prop[0] !== '-')
  124. * ```
  125. *
  126. * @param condition Iterator returns true or false.
  127. * @return Is every child pass condition.
  128. */
  129. every(
  130. condition: (node: Child, index: number, nodes: Child[]) => boolean
  131. ): boolean
  132. /**
  133. * Returns a `child`’s index within the `Container#nodes` array.
  134. *
  135. * ```js
  136. * rule.index( rule.nodes[2] ) //=> 2
  137. * ```
  138. *
  139. * @param child Child of the current container.
  140. * @return Child index.
  141. */
  142. index(child: Child | number): number
  143. /**
  144. * Insert new node after old node within the container.
  145. *
  146. * @param oldNode Child or child’s index.
  147. * @param newNode New node.
  148. * @return This node for methods chain.
  149. */
  150. insertAfter(
  151. oldNode: Child | number,
  152. newNode:
  153. | Node
  154. | Node[]
  155. | ChildProps
  156. | ChildProps[]
  157. | string
  158. | string[]
  159. | undefined
  160. ): this
  161. /**
  162. * Insert new node before old node within the container.
  163. *
  164. * ```js
  165. * rule.insertBefore(decl, decl.clone({ prop: '-webkit-' + decl.prop }))
  166. * ```
  167. *
  168. * @param oldNode Child or child’s index.
  169. * @param newNode New node.
  170. * @return This node for methods chain.
  171. */
  172. insertBefore(
  173. oldNode: Child | number,
  174. newNode:
  175. | Node
  176. | Node[]
  177. | ChildProps
  178. | ChildProps[]
  179. | string
  180. | string[]
  181. | undefined
  182. ): this
  183. /**
  184. * Traverses the container’s descendant nodes, calling callback
  185. * for each comment node.
  186. *
  187. * Like `Container#each`, this method is safe
  188. * to use if you are mutating arrays during iteration.
  189. *
  190. * ```js
  191. * root.walkComments(comment => {
  192. * comment.remove()
  193. * })
  194. * ```
  195. *
  196. * @param callback Iterator receives each node and index.
  197. * @return Returns `false` if iteration was broke.
  198. */
  199. /**
  200. * Inserts new nodes to the start of the container.
  201. *
  202. * ```js
  203. * const decl1 = new Declaration({ prop: 'color', value: 'black' })
  204. * const decl2 = new Declaration({ prop: 'background-color', value: 'white' })
  205. * rule.prepend(decl1, decl2)
  206. *
  207. * root.append({ name: 'charset', params: '"UTF-8"' }) // at-rule
  208. * root.append({ selector: 'a' }) // rule
  209. * rule.append({ prop: 'color', value: 'black' }) // declaration
  210. * rule.append({ text: 'Comment' }) // comment
  211. *
  212. * root.append('a {}')
  213. * root.first.append('color: black; z-index: 1')
  214. * ```
  215. *
  216. * @param nodes New nodes.
  217. * @return This node for methods chain.
  218. */
  219. prepend(
  220. ...nodes: (
  221. | ChildProps
  222. | ChildProps[]
  223. | Node
  224. | Node[]
  225. | string
  226. | string[]
  227. | undefined
  228. )[]
  229. ): this
  230. /**
  231. * Add child to the end of the node.
  232. *
  233. * ```js
  234. * rule.push(new Declaration({ prop: 'color', value: 'black' }))
  235. * ```
  236. *
  237. * @param child New node.
  238. * @return This node for methods chain.
  239. */
  240. push(child: Child): this
  241. /**
  242. * Removes all children from the container
  243. * and cleans their parent properties.
  244. *
  245. * ```js
  246. * rule.removeAll()
  247. * rule.nodes.length //=> 0
  248. * ```
  249. *
  250. * @return This node for methods chain.
  251. */
  252. removeAll(): this
  253. /**
  254. * Removes node from the container and cleans the parent properties
  255. * from the node and its children.
  256. *
  257. * ```js
  258. * rule.nodes.length //=> 5
  259. * rule.removeChild(decl)
  260. * rule.nodes.length //=> 4
  261. * decl.parent //=> undefined
  262. * ```
  263. *
  264. * @param child Child or child’s index.
  265. * @return This node for methods chain.
  266. */
  267. removeChild(child: Child | number): this
  268. replaceValues(
  269. pattern: RegExp | string,
  270. replaced: { (substring: string, ...args: any[]): string } | string
  271. ): this
  272. /**
  273. * Passes all declaration values within the container that match pattern
  274. * through callback, replacing those values with the returned result
  275. * of callback.
  276. *
  277. * This method is useful if you are using a custom unit or function
  278. * and need to iterate through all values.
  279. *
  280. * ```js
  281. * root.replaceValues(/\d+rem/, { fast: 'rem' }, string => {
  282. * return 15 * parseInt(string) + 'px'
  283. * })
  284. * ```
  285. *
  286. * @param pattern Replace pattern.
  287. * @param {object} opts Options to speed up the search.
  288. * @param callback String to replace pattern or callback
  289. * that returns a new value. The callback
  290. * will receive the same arguments
  291. * as those passed to a function parameter
  292. * of `String#replace`.
  293. * @return This node for methods chain.
  294. */
  295. replaceValues(
  296. pattern: RegExp | string,
  297. options: Container.ValueOptions,
  298. replaced: { (substring: string, ...args: any[]): string } | string
  299. ): this
  300. /**
  301. * Returns `true` if callback returns `true` for (at least) one
  302. * of the container’s children.
  303. *
  304. * ```js
  305. * const hasPrefix = rule.some(i => i.prop[0] === '-')
  306. * ```
  307. *
  308. * @param condition Iterator returns true or false.
  309. * @return Is some child pass condition.
  310. */
  311. some(
  312. condition: (node: Child, index: number, nodes: Child[]) => boolean
  313. ): boolean
  314. /**
  315. * Traverses the container’s descendant nodes, calling callback
  316. * for each node.
  317. *
  318. * Like container.each(), this method is safe to use
  319. * if you are mutating arrays during iteration.
  320. *
  321. * If you only need to iterate through the container’s immediate children,
  322. * use `Container#each`.
  323. *
  324. * ```js
  325. * root.walk(node => {
  326. * // Traverses all descendant nodes.
  327. * })
  328. * ```
  329. *
  330. * @param callback Iterator receives each node and index.
  331. * @return Returns `false` if iteration was broke.
  332. */
  333. walk(
  334. callback: (node: ChildNode, index: number) => false | void
  335. ): false | undefined
  336. /**
  337. * Traverses the container’s descendant nodes, calling callback
  338. * for each at-rule node.
  339. *
  340. * If you pass a filter, iteration will only happen over at-rules
  341. * that have matching names.
  342. *
  343. * Like `Container#each`, this method is safe
  344. * to use if you are mutating arrays during iteration.
  345. *
  346. * ```js
  347. * root.walkAtRules(rule => {
  348. * if (isOld(rule.name)) rule.remove()
  349. * })
  350. *
  351. * let first = false
  352. * root.walkAtRules('charset', rule => {
  353. * if (!first) {
  354. * first = true
  355. * } else {
  356. * rule.remove()
  357. * }
  358. * })
  359. * ```
  360. *
  361. * @param name String or regular expression to filter at-rules by name.
  362. * @param callback Iterator receives each node and index.
  363. * @return Returns `false` if iteration was broke.
  364. */
  365. walkAtRules(
  366. nameFilter: RegExp | string,
  367. callback: (atRule: AtRule, index: number) => false | void
  368. ): false | undefined
  369. walkAtRules(
  370. callback: (atRule: AtRule, index: number) => false | void
  371. ): false | undefined
  372. walkComments(
  373. callback: (comment: Comment, indexed: number) => false | void
  374. ): false | undefined
  375. walkComments(
  376. callback: (comment: Comment, indexed: number) => false | void
  377. ): false | undefined
  378. /**
  379. * Traverses the container’s descendant nodes, calling callback
  380. * for each declaration node.
  381. *
  382. * If you pass a filter, iteration will only happen over declarations
  383. * with matching properties.
  384. *
  385. * ```js
  386. * root.walkDecls(decl => {
  387. * checkPropertySupport(decl.prop)
  388. * })
  389. *
  390. * root.walkDecls('border-radius', decl => {
  391. * decl.remove()
  392. * })
  393. *
  394. * root.walkDecls(/^background/, decl => {
  395. * decl.value = takeFirstColorFromGradient(decl.value)
  396. * })
  397. * ```
  398. *
  399. * Like `Container#each`, this method is safe
  400. * to use if you are mutating arrays during iteration.
  401. *
  402. * @param prop String or regular expression to filter declarations
  403. * by property name.
  404. * @param callback Iterator receives each node and index.
  405. * @return Returns `false` if iteration was broke.
  406. */
  407. walkDecls(
  408. propFilter: RegExp | string,
  409. callback: (decl: Declaration, index: number) => false | void
  410. ): false | undefined
  411. walkDecls(
  412. callback: (decl: Declaration, index: number) => false | void
  413. ): false | undefined
  414. /**
  415. * Traverses the container’s descendant nodes, calling callback
  416. * for each rule node.
  417. *
  418. * If you pass a filter, iteration will only happen over rules
  419. * with matching selectors.
  420. *
  421. * Like `Container#each`, this method is safe
  422. * to use if you are mutating arrays during iteration.
  423. *
  424. * ```js
  425. * const selectors = []
  426. * root.walkRules(rule => {
  427. * selectors.push(rule.selector)
  428. * })
  429. * console.log(`Your CSS uses ${ selectors.length } selectors`)
  430. * ```
  431. *
  432. * @param selector String or regular expression to filter rules by selector.
  433. * @param callback Iterator receives each node and index.
  434. * @return Returns `false` if iteration was broke.
  435. */
  436. walkRules(
  437. selectorFilter: RegExp | string,
  438. callback: (rule: Rule, index: number) => false | void
  439. ): false | undefined
  440. walkRules(
  441. callback: (rule: Rule, index: number) => false | void
  442. ): false | undefined
  443. /**
  444. * The container’s first child.
  445. *
  446. * ```js
  447. * rule.first === rules.nodes[0]
  448. * ```
  449. */
  450. get first(): Child | undefined
  451. /**
  452. * The container’s last child.
  453. *
  454. * ```js
  455. * rule.last === rule.nodes[rule.nodes.length - 1]
  456. * ```
  457. */
  458. get last(): Child | undefined
  459. }
  460. declare class Container<
  461. Child extends Node = ChildNode
  462. > extends Container_<Child> {}
  463. export = Container