rule.d.ts 2.8 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 the text of the semicolon after this 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. export { Rule_ as default }
  52. }
  53. /**
  54. * Represents a CSS rule: a selector followed by a declaration block.
  55. *
  56. * ```js
  57. * Once (root, { Rule }) {
  58. * let a = new Rule({ selector: 'a' })
  59. * a.append(…)
  60. * root.append(a)
  61. * }
  62. * ```
  63. *
  64. * ```js
  65. * const root = postcss.parse('a{}')
  66. * const rule = root.first
  67. * rule.type //=> 'rule'
  68. * rule.toString() //=> 'a{}'
  69. * ```
  70. */
  71. declare class Rule_ extends Container {
  72. nodes: NonNullable<Container['nodes']>
  73. parent: ContainerWithChildren | undefined
  74. raws: Rule.RuleRaws
  75. type: 'rule'
  76. /**
  77. * The rule’s full selector represented as a string.
  78. *
  79. * ```js
  80. * const root = postcss.parse('a, b { }')
  81. * const rule = root.first
  82. * rule.selector //=> 'a, b'
  83. * ```
  84. */
  85. get selector(): string
  86. set selector(value: string)
  87. /**
  88. * An array containing the rule’s individual selectors.
  89. * Groups of selectors are split at commas.
  90. *
  91. * ```js
  92. * const root = postcss.parse('a, b { }')
  93. * const rule = root.first
  94. *
  95. * rule.selector //=> 'a, b'
  96. * rule.selectors //=> ['a', 'b']
  97. *
  98. * rule.selectors = ['a', 'strong']
  99. * rule.selector //=> 'a, strong'
  100. * ```
  101. */
  102. get selectors(): string[]
  103. set selectors(values: string[])
  104. constructor(defaults?: Rule.RuleProps)
  105. assign(overrides: object | Rule.RuleProps): this
  106. clone(overrides?: Partial<Rule.RuleProps>): this
  107. cloneAfter(overrides?: Partial<Rule.RuleProps>): this
  108. cloneBefore(overrides?: Partial<Rule.RuleProps>): this
  109. }
  110. declare class Rule extends Rule_ {}
  111. export = Rule