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.

106 lines
2.4 KiB

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