at-rule.d.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import Container, { ContainerProps } from './container.js'
  2. declare namespace AtRule {
  3. export interface AtRuleRaws extends Record<string, unknown> {
  4. /**
  5. * The space symbols before the node. It also stores `*`
  6. * and `_` symbols before the declaration (IE hack).
  7. */
  8. before?: string
  9. /**
  10. * The space symbols after the last child of the node to the end of the node.
  11. */
  12. after?: string
  13. /**
  14. * The space between the at-rule name and its parameters.
  15. */
  16. afterName?: string
  17. /**
  18. * The symbols between the last parameter and `{` for rules.
  19. */
  20. between?: string
  21. /**
  22. * Contains `true` if the last child has an (optional) semicolon.
  23. */
  24. semicolon?: boolean
  25. /**
  26. * The rule’s selector with comments.
  27. */
  28. params?: {
  29. value: string
  30. raw: string
  31. }
  32. }
  33. export interface AtRuleProps extends ContainerProps {
  34. /** Name of the at-rule. */
  35. name: string
  36. /** Parameters following the name of the at-rule. */
  37. params?: string | number
  38. /** Information used to generate byte-to-byte equal node string as it was in the origin input. */
  39. raws?: AtRuleRaws
  40. }
  41. // eslint-disable-next-line @typescript-eslint/no-use-before-define
  42. export { AtRule_ as default }
  43. }
  44. /**
  45. * Represents an at-rule.
  46. *
  47. * ```js
  48. * Once (root, { AtRule }) {
  49. * let media = new AtRule({ name: 'media', params: 'print' })
  50. * media.append(…)
  51. * root.append(media)
  52. * }
  53. * ```
  54. *
  55. * If it’s followed in the CSS by a `{}` block, this node will have
  56. * a nodes property representing its children.
  57. *
  58. * ```js
  59. * const root = postcss.parse('@charset "UTF-8"; @media print {}')
  60. *
  61. * const charset = root.first
  62. * charset.type //=> 'atrule'
  63. * charset.nodes //=> undefined
  64. *
  65. * const media = root.last
  66. * media.nodes //=> []
  67. * ```
  68. */
  69. declare class AtRule_ extends Container {
  70. type: 'atrule'
  71. parent: Container | undefined
  72. raws: AtRule.AtRuleRaws
  73. /**
  74. * The at-rule’s name immediately follows the `@`.
  75. *
  76. * ```js
  77. * const root = postcss.parse('@media print {}')
  78. * media.name //=> 'media'
  79. * const media = root.first
  80. * ```
  81. */
  82. name: string
  83. /**
  84. * The at-rule’s parameters, the values that follow the at-rule’s name
  85. * but precede any `{}` block.
  86. *
  87. * ```js
  88. * const root = postcss.parse('@media print, screen {}')
  89. * const media = root.first
  90. * media.params //=> 'print, screen'
  91. * ```
  92. */
  93. params: string
  94. constructor(defaults?: AtRule.AtRuleProps)
  95. assign(overrides: object | AtRule.AtRuleProps): this
  96. clone(overrides?: Partial<AtRule.AtRuleProps>): this
  97. cloneBefore(overrides?: Partial<AtRule.AtRuleProps>): this
  98. cloneAfter(overrides?: Partial<AtRule.AtRuleProps>): this
  99. }
  100. declare class AtRule extends AtRule_ {}
  101. export = AtRule