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.

126 lines
2.9 KiB

  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 rules 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. /**
  78. * The rules full selector represented as a string.
  79. *
  80. * ```js
  81. * const root = postcss.parse('a, b { }')
  82. * const rule = root.first
  83. * rule.selector //=> 'a, b'
  84. * ```
  85. */
  86. get selector(): string
  87. set selector(value: string)
  88. /**
  89. * An array containing the rules individual selectors.
  90. * Groups of selectors are split at commas.
  91. *
  92. * ```js
  93. * const root = postcss.parse('a, b { }')
  94. * const rule = root.first
  95. *
  96. * rule.selector //=> 'a, b'
  97. * rule.selectors //=> ['a', 'b']
  98. *
  99. * rule.selectors = ['a', 'strong']
  100. * rule.selector //=> 'a, strong'
  101. * ```
  102. */
  103. get selectors(): string[]
  104. set selectors(values: string[])
  105. constructor(defaults?: Rule.RuleProps)
  106. assign(overrides: object | Rule.RuleProps): this
  107. clone(overrides?: Partial<Rule.RuleProps>): this
  108. cloneAfter(overrides?: Partial<Rule.RuleProps>): this
  109. cloneBefore(overrides?: Partial<Rule.RuleProps>): this
  110. }
  111. declare class Rule extends Rule_ {}
  112. export = Rule