rule.d.ts 2.9 KB

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