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.

104 lines
2.3 KiB

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