rule.d.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import Container, { ContainerProps } from './container.js'
  2. declare namespace Rule {
  3. export interface RuleRaws extends Record<string, unknown> {
  4. /**
  5. * The space symbols before the node. It also stores `*`
  6. * and `_` symbols before the declaration (IE hack).
  7. */
  8. before?: string
  9. /**
  10. * The space symbols after the last child of the node to the end of the node.
  11. */
  12. after?: string
  13. /**
  14. * The symbols between the selector and `{` for rules.
  15. */
  16. between?: string
  17. /**
  18. * Contains `true` if the last child has an (optional) semicolon.
  19. */
  20. semicolon?: boolean
  21. /**
  22. * Contains `true` if there is semicolon after rule.
  23. */
  24. ownSemicolon?: string
  25. /**
  26. * The rule’s selector with comments.
  27. */
  28. selector?: {
  29. value: string
  30. raw: string
  31. }
  32. }
  33. export interface RuleProps extends ContainerProps {
  34. /** Selector or selectors of the rule. */
  35. selector?: string
  36. /** Selectors of the rule represented as an array of strings. */
  37. selectors?: string[]
  38. /** Information used to generate byte-to-byte equal node string as it was in the origin input. */
  39. raws?: RuleRaws
  40. }
  41. // eslint-disable-next-line @typescript-eslint/no-use-before-define
  42. export { Rule_ as default }
  43. }
  44. /**
  45. * Represents a CSS rule: a selector followed by a declaration block.
  46. *
  47. * ```js
  48. * Once (root, { Rule }) {
  49. * let a = new Rule({ selector: 'a' })
  50. * a.append(…)
  51. * root.append(a)
  52. * }
  53. * ```
  54. *
  55. * ```js
  56. * const root = postcss.parse('a{}')
  57. * const rule = root.first
  58. * rule.type //=> 'rule'
  59. * rule.toString() //=> 'a{}'
  60. * ```
  61. */
  62. declare class Rule_ extends Container {
  63. type: 'rule'
  64. parent: Container | undefined
  65. raws: Rule.RuleRaws
  66. /**
  67. * The rule’s full selector represented as a string.
  68. *
  69. * ```js
  70. * const root = postcss.parse('a, b { }')
  71. * const rule = root.first
  72. * rule.selector //=> 'a, b'
  73. * ```
  74. */
  75. selector: string
  76. /**
  77. * An array containing the rule’s individual selectors.
  78. * Groups of selectors are split at commas.
  79. *
  80. * ```js
  81. * const root = postcss.parse('a, b { }')
  82. * const rule = root.first
  83. *
  84. * rule.selector //=> 'a, b'
  85. * rule.selectors //=> ['a', 'b']
  86. *
  87. * rule.selectors = ['a', 'strong']
  88. * rule.selector //=> 'a, strong'
  89. * ```
  90. */
  91. selectors: string[]
  92. constructor(defaults?: Rule.RuleProps)
  93. assign(overrides: object | Rule.RuleProps): this
  94. clone(overrides?: Partial<Rule.RuleProps>): this
  95. cloneBefore(overrides?: Partial<Rule.RuleProps>): this
  96. cloneAfter(overrides?: Partial<Rule.RuleProps>): this
  97. }
  98. declare class Rule extends Rule_ {}
  99. export = Rule