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. export { AtRule_ as default }
  45. }
  46. /**
  47. * Represents an at-rule.
  48. *
  49. * ```js
  50. * Once (root, { AtRule }) {
  51. * let media = new AtRule({ name: 'media', params: 'print' })
  52. * media.append(…)
  53. * root.append(media)
  54. * }
  55. * ```
  56. *
  57. * If it’s followed in the CSS by a `{}` block, this node will have
  58. * a nodes property representing its children.
  59. *
  60. * ```js
  61. * const root = postcss.parse('@charset "UTF-8"; @media print {}')
  62. *
  63. * const charset = root.first
  64. * charset.type //=> 'atrule'
  65. * charset.nodes //=> undefined
  66. *
  67. * const media = root.last
  68. * media.nodes //=> []
  69. * ```
  70. */
  71. declare class AtRule_ extends Container {
  72. /**
  73. * An array containing the layer’s children.
  74. *
  75. * ```js
  76. * const root = postcss.parse('@layer example { a { color: black } }')
  77. * const layer = root.first
  78. * layer.nodes.length //=> 1
  79. * layer.nodes[0].selector //=> 'a'
  80. * ```
  81. *
  82. * Can be `undefinded` if the at-rule has no body.
  83. *
  84. * ```js
  85. * const root = postcss.parse('@layer a, b, c;')
  86. * const layer = root.first
  87. * layer.nodes //=> undefined
  88. * ```
  89. */
  90. nodes: Container['nodes'] | undefined
  91. parent: ContainerWithChildren | undefined
  92. raws: AtRule.AtRuleRaws
  93. type: 'atrule'
  94. /**
  95. * The at-rule’s name immediately follows the `@`.
  96. *
  97. * ```js
  98. * const root = postcss.parse('@media print {}')
  99. * const media = root.first
  100. * media.name //=> 'media'
  101. * ```
  102. */
  103. get name(): string
  104. set name(value: string)
  105. /**
  106. * The at-rule’s parameters, the values that follow the at-rule’s name
  107. * but precede any `{}` block.
  108. *
  109. * ```js
  110. * const root = postcss.parse('@media print, screen {}')
  111. * const media = root.first
  112. * media.params //=> 'print, screen'
  113. * ```
  114. */
  115. get params(): string
  116. set params(value: string)
  117. constructor(defaults?: AtRule.AtRuleProps)
  118. assign(overrides: AtRule.AtRuleProps | object): this
  119. clone(overrides?: Partial<AtRule.AtRuleProps>): this
  120. cloneAfter(overrides?: Partial<AtRule.AtRuleProps>): this
  121. cloneBefore(overrides?: Partial<AtRule.AtRuleProps>): this
  122. }
  123. declare class AtRule extends AtRule_ {}
  124. export = AtRule