at-rule.d.ts 2.8 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 after the last child of the node to the end of the node.
  6. */
  7. after?: string
  8. /**
  9. * The space between the at-rule name and its parameters.
  10. */
  11. afterName?: string
  12. /**
  13. * The space symbols before the node. It also stores `*`
  14. * and `_` symbols before the declaration (IE hack).
  15. */
  16. before?: string
  17. /**
  18. * The symbols between the last parameter and `{` for rules.
  19. */
  20. between?: string
  21. /**
  22. * The rule’s selector with comments.
  23. */
  24. params?: {
  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 AtRuleProps extends ContainerProps {
  34. /** Name of the at-rule. */
  35. name: string
  36. /** Parameters following the name of the at-rule. */
  37. params?: number | string
  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. /**
  71. * The at-rule’s name immediately follows the `@`.
  72. *
  73. * ```js
  74. * const root = postcss.parse('@media print {}')
  75. * media.name //=> 'media'
  76. * const media = root.first
  77. * ```
  78. */
  79. name: string
  80. /**
  81. * The at-rule’s parameters, the values that follow the at-rule’s name
  82. * but precede any `{}` block.
  83. *
  84. * ```js
  85. * const root = postcss.parse('@media print, screen {}')
  86. * const media = root.first
  87. * media.params //=> 'print, screen'
  88. * ```
  89. */
  90. params: string
  91. parent: Container | undefined
  92. raws: AtRule.AtRuleRaws
  93. type: 'atrule'
  94. constructor(defaults?: AtRule.AtRuleProps)
  95. assign(overrides: AtRule.AtRuleProps | object): this
  96. clone(overrides?: Partial<AtRule.AtRuleProps>): AtRule
  97. cloneAfter(overrides?: Partial<AtRule.AtRuleProps>): AtRule
  98. cloneBefore(overrides?: Partial<AtRule.AtRuleProps>): AtRule
  99. }
  100. declare class AtRule extends AtRule_ {}
  101. export = AtRule