at-rule.d.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import Container, {
  2. ContainerProps,
  3. ContainerWithChildren
  4. } from './container.js'
  5. declare namespace AtRule {
  6. export interface AtRuleRaws 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 between the at-rule name and its parameters.
  13. */
  14. afterName?: string
  15. /**
  16. * The space symbols before the node. It also stores `*`
  17. * and `_` symbols before the declaration (IE hack).
  18. */
  19. before?: string
  20. /**
  21. * The symbols between the last parameter and `{` for rules.
  22. */
  23. between?: string
  24. /**
  25. * The rule’s selector with comments.
  26. */
  27. params?: {
  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 interface AtRuleProps extends ContainerProps {
  37. /** Name of the at-rule. */
  38. name: string
  39. /** Parameters following the name of the at-rule. */
  40. params?: number | string
  41. /** Information used to generate byte-to-byte equal node string as it was in the origin input. */
  42. raws?: AtRuleRaws
  43. }
  44. // eslint-disable-next-line @typescript-eslint/no-use-before-define
  45. export { AtRule_ as default }
  46. }
  47. /**
  48. * Represents an at-rule.
  49. *
  50. * ```js
  51. * Once (root, { AtRule }) {
  52. * let media = new AtRule({ name: 'media', params: 'print' })
  53. * media.append(…)
  54. * root.append(media)
  55. * }
  56. * ```
  57. *
  58. * If it’s followed in the CSS by a `{}` block, this node will have
  59. * a nodes property representing its children.
  60. *
  61. * ```js
  62. * const root = postcss.parse('@charset "UTF-8"; @media print {}')
  63. *
  64. * const charset = root.first
  65. * charset.type //=> 'atrule'
  66. * charset.nodes //=> undefined
  67. *
  68. * const media = root.last
  69. * media.nodes //=> []
  70. * ```
  71. */
  72. declare class AtRule_ extends Container {
  73. /**
  74. * An array containing the layer’s children.
  75. *
  76. * ```js
  77. * const root = postcss.parse('@layer example { a { color: black } }')
  78. * const layer = root.first
  79. * layer.nodes.length //=> 1
  80. * layer.nodes[0].selector //=> 'a'
  81. * ```
  82. *
  83. * Can be `undefinded` if the at-rule has no body.
  84. *
  85. * ```js
  86. * const root = postcss.parse('@layer a, b, c;')
  87. * const layer = root.first
  88. * layer.nodes //=> undefined
  89. * ```
  90. */
  91. nodes: Container['nodes']
  92. parent: ContainerWithChildren | undefined
  93. raws: AtRule.AtRuleRaws
  94. type: 'atrule'
  95. constructor(defaults?: AtRule.AtRuleProps)
  96. assign(overrides: AtRule.AtRuleProps | object): this
  97. clone(overrides?: Partial<AtRule.AtRuleProps>): this
  98. cloneAfter(overrides?: Partial<AtRule.AtRuleProps>): this
  99. cloneBefore(overrides?: Partial<AtRule.AtRuleProps>): this
  100. /**
  101. * The at-rule’s name immediately follows the `@`.
  102. *
  103. * ```js
  104. * const root = postcss.parse('@media print {}')
  105. * const media = root.first
  106. * media.name //=> 'media'
  107. * ```
  108. */
  109. get name(): string
  110. set name(value: string)
  111. /**
  112. * The at-rule’s parameters, the values that follow the at-rule’s name
  113. * but precede any `{}` block.
  114. *
  115. * ```js
  116. * const root = postcss.parse('@media print, screen {}')
  117. * const media = root.first
  118. * media.params //=> 'print, screen'
  119. * ```
  120. */
  121. get params(): string
  122. set params(value: string)
  123. }
  124. declare class AtRule extends AtRule_ {}
  125. export = AtRule