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 after the last child of the node to the end of the node.
  6. */
  7. after?: string
  8. /**
  9. * The space symbols before the node. It also stores `*`
  10. * and `_` symbols before the declaration (IE hack).
  11. */
  12. before?: string
  13. /**
  14. * The symbols between the selector and `{` for rules.
  15. */
  16. between?: string
  17. /**
  18. * Contains `true` if there is semicolon after rule.
  19. */
  20. ownSemicolon?: string
  21. /**
  22. * The rule’s selector with comments.
  23. */
  24. selector?: {
  25. raw: string
  26. value: string
  27. }
  28. /**
  29. * Contains `true` if the last child has an (optional) semicolon.
  30. */
  31. semicolon?: boolean
  32. }
  33. export interface RuleProps extends ContainerProps {
  34. /** Information used to generate byte-to-byte equal node string as it was in the origin input. */
  35. raws?: RuleRaws
  36. /** Selector or selectors of the rule. */
  37. selector?: string
  38. /** Selectors of the rule represented as an array of strings. */
  39. selectors?: string[]
  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. parent: Container | undefined
  64. raws: Rule.RuleRaws
  65. /**
  66. * The rule’s full selector represented as a string.
  67. *
  68. * ```js
  69. * const root = postcss.parse('a, b { }')
  70. * const rule = root.first
  71. * rule.selector //=> 'a, b'
  72. * ```
  73. */
  74. selector: string
  75. /**
  76. * An array containing the rule’s individual selectors.
  77. * Groups of selectors are split at commas.
  78. *
  79. * ```js
  80. * const root = postcss.parse('a, b { }')
  81. * const rule = root.first
  82. *
  83. * rule.selector //=> 'a, b'
  84. * rule.selectors //=> ['a', 'b']
  85. *
  86. * rule.selectors = ['a', 'strong']
  87. * rule.selector //=> 'a, strong'
  88. * ```
  89. */
  90. selectors: string[]
  91. type: 'rule'
  92. constructor(defaults?: Rule.RuleProps)
  93. assign(overrides: object | Rule.RuleProps): this
  94. clone(overrides?: Partial<Rule.RuleProps>): Rule
  95. cloneAfter(overrides?: Partial<Rule.RuleProps>): Rule
  96. cloneBefore(overrides?: Partial<Rule.RuleProps>): Rule
  97. }
  98. declare class Rule extends Rule_ {}
  99. export = Rule