declaration.d.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { ContainerWithChildren } from './container.js'
  2. import Node from './node.js'
  3. declare namespace Declaration {
  4. export interface DeclarationRaws extends Record<string, unknown> {
  5. /**
  6. * The space symbols before the node. It also stores `*`
  7. * and `_` symbols before the declaration (IE hack).
  8. */
  9. before?: string
  10. /**
  11. * The symbols between the property and value for declarations.
  12. */
  13. between?: string
  14. /**
  15. * The content of the important statement, if it is not just `!important`.
  16. */
  17. important?: string
  18. /**
  19. * Declaration value with comments.
  20. */
  21. value?: {
  22. raw: string
  23. value: string
  24. }
  25. }
  26. export interface DeclarationProps {
  27. /** Whether the declaration has an `!important` annotation. */
  28. important?: boolean
  29. /** Name of the declaration. */
  30. prop: string
  31. /** Information used to generate byte-to-byte equal node string as it was in the origin input. */
  32. raws?: DeclarationRaws
  33. /** Value of the declaration. */
  34. value: string
  35. }
  36. export { Declaration_ as default }
  37. }
  38. /**
  39. * It represents a class that handles
  40. * [CSS declarations](https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax#css_declarations)
  41. *
  42. * ```js
  43. * Once (root, { Declaration }) {
  44. * const color = new Declaration({ prop: 'color', value: 'black' })
  45. * root.append(color)
  46. * }
  47. * ```
  48. *
  49. * ```js
  50. * const root = postcss.parse('a { color: black }')
  51. * const decl = root.first?.first
  52. *
  53. * decl.type //=> 'decl'
  54. * decl.toString() //=> ' color: black'
  55. * ```
  56. */
  57. declare class Declaration_ extends Node {
  58. parent: ContainerWithChildren | undefined
  59. raws: Declaration.DeclarationRaws
  60. type: 'decl'
  61. /**
  62. * It represents a specificity of the declaration.
  63. *
  64. * If true, the CSS declaration will have an
  65. * [important](https://developer.mozilla.org/en-US/docs/Web/CSS/important)
  66. * specifier.
  67. *
  68. * ```js
  69. * const root = postcss.parse('a { color: black !important; color: red }')
  70. *
  71. * root.first.first.important //=> true
  72. * root.first.last.important //=> undefined
  73. * ```
  74. */
  75. get important(): boolean
  76. set important(value: boolean)
  77. /**
  78. * The property name for a CSS declaration.
  79. *
  80. * ```js
  81. * const root = postcss.parse('a { color: black }')
  82. * const decl = root.first.first
  83. *
  84. * decl.prop //=> 'color'
  85. * ```
  86. */
  87. get prop(): string
  88. set prop(value: string)
  89. /**
  90. * The property value for a CSS declaration.
  91. *
  92. * Any CSS comments inside the value string will be filtered out.
  93. * CSS comments present in the source value will be available in
  94. * the `raws` property.
  95. *
  96. * Assigning new `value` would ignore the comments in `raws`
  97. * property while compiling node to string.
  98. *
  99. * ```js
  100. * const root = postcss.parse('a { color: black }')
  101. * const decl = root.first.first
  102. *
  103. * decl.value //=> 'black'
  104. * ```
  105. */
  106. get value(): string
  107. set value(value: string)
  108. /**
  109. * It represents a getter that returns `true` if a declaration starts with
  110. * `--` or `$`, which are used to declare variables in CSS and SASS/SCSS.
  111. *
  112. * ```js
  113. * const root = postcss.parse(':root { --one: 1 }')
  114. * const one = root.first.first
  115. *
  116. * one.variable //=> true
  117. * ```
  118. *
  119. * ```js
  120. * const root = postcss.parse('$one: 1')
  121. * const one = root.first
  122. *
  123. * one.variable //=> true
  124. * ```
  125. */
  126. get variable(): boolean
  127. constructor(defaults?: Declaration.DeclarationProps)
  128. assign(overrides: Declaration.DeclarationProps | object): this
  129. clone(overrides?: Partial<Declaration.DeclarationProps>): this
  130. cloneAfter(overrides?: Partial<Declaration.DeclarationProps>): this
  131. cloneBefore(overrides?: Partial<Declaration.DeclarationProps>): this
  132. }
  133. declare class Declaration extends Declaration_ {}
  134. export = Declaration