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.

151 lines
3.8 KiB

  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. // eslint-disable-next-line @typescript-eslint/no-use-before-define
  37. export { Declaration_ as default }
  38. }
  39. /**
  40. * It represents a class that handles
  41. * [CSS declarations](https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax#css_declarations)
  42. *
  43. * ```js
  44. * Once (root, { Declaration }) {
  45. * const color = new Declaration({ prop: 'color', value: 'black' })
  46. * root.append(color)
  47. * }
  48. * ```
  49. *
  50. * ```js
  51. * const root = postcss.parse('a { color: black }')
  52. * const decl = root.first?.first
  53. *
  54. * decl.type //=> 'decl'
  55. * decl.toString() //=> ' color: black'
  56. * ```
  57. */
  58. declare class Declaration_ extends Node {
  59. parent: ContainerWithChildren | undefined
  60. raws: Declaration.DeclarationRaws
  61. type: 'decl'
  62. /**
  63. * It represents a specificity of the declaration.
  64. *
  65. * If true, the CSS declaration will have an
  66. * [important](https://developer.mozilla.org/en-US/docs/Web/CSS/important)
  67. * specifier.
  68. *
  69. * ```js
  70. * const root = postcss.parse('a { color: black !important; color: red }')
  71. *
  72. * root.first.first.important //=> true
  73. * root.first.last.important //=> undefined
  74. * ```
  75. */
  76. get important(): boolean
  77. set important(value: boolean)
  78. /**
  79. * The property name for a CSS declaration.
  80. *
  81. * ```js
  82. * const root = postcss.parse('a { color: black }')
  83. * const decl = root.first.first
  84. *
  85. * decl.prop //=> 'color'
  86. * ```
  87. */
  88. get prop(): string
  89. set prop(value: string)
  90. /**
  91. * The property value for a CSS declaration.
  92. *
  93. * Any CSS comments inside the value string will be filtered out.
  94. * CSS comments present in the source value will be available in
  95. * the `raws` property.
  96. *
  97. * Assigning new `value` would ignore the comments in `raws`
  98. * property while compiling node to string.
  99. *
  100. * ```js
  101. * const root = postcss.parse('a { color: black }')
  102. * const decl = root.first.first
  103. *
  104. * decl.value //=> 'black'
  105. * ```
  106. */
  107. get value(): string
  108. set value(value: string)
  109. /**
  110. * It represents a getter that returns `true` if a declaration starts with
  111. * `--` or `$`, which are used to declare variables in CSS and SASS/SCSS.
  112. *
  113. * ```js
  114. * const root = postcss.parse(':root { --one: 1 }')
  115. * const one = root.first.first
  116. *
  117. * one.variable //=> true
  118. * ```
  119. *
  120. * ```js
  121. * const root = postcss.parse('$one: 1')
  122. * const one = root.first
  123. *
  124. * one.variable //=> true
  125. * ```
  126. */
  127. get variable(): boolean
  128. constructor(defaults?: Declaration.DeclarationProps)
  129. assign(overrides: Declaration.DeclarationProps | object): this
  130. clone(overrides?: Partial<Declaration.DeclarationProps>): this
  131. cloneAfter(overrides?: Partial<Declaration.DeclarationProps>): this
  132. cloneBefore(overrides?: Partial<Declaration.DeclarationProps>): this
  133. }
  134. declare class Declaration extends Declaration_ {}
  135. export = Declaration