declaration.d.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import Container 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. value: string
  23. raw: string
  24. }
  25. }
  26. export interface DeclarationProps {
  27. /** Name of the declaration. */
  28. prop: string
  29. /** Value of the declaration. */
  30. value: string
  31. /** Whether the declaration has an `!important` annotation. */
  32. important?: boolean
  33. /** Information used to generate byte-to-byte equal node string as it was in the origin input. */
  34. raws?: DeclarationRaws
  35. }
  36. // eslint-disable-next-line @typescript-eslint/no-use-before-define
  37. export { Declaration_ as default }
  38. }
  39. /**
  40. * Represents a CSS declaration.
  41. *
  42. * ```js
  43. * Once (root, { Declaration }) {
  44. * let 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. * decl.type //=> 'decl'
  53. * decl.toString() //=> ' color: black'
  54. * ```
  55. */
  56. declare class Declaration_ extends Node {
  57. type: 'decl'
  58. parent: Container | undefined
  59. raws: Declaration.DeclarationRaws
  60. /**
  61. * The declaration's property name.
  62. *
  63. * ```js
  64. * const root = postcss.parse('a { color: black }')
  65. * const decl = root.first.first
  66. * decl.prop //=> 'color'
  67. * ```
  68. */
  69. prop: string
  70. /**
  71. * The declaration’s value.
  72. *
  73. * This value will be cleaned of comments. If the source value contained
  74. * comments, those comments will be available in the `raws` property.
  75. * If you have not changed the value, the result of `decl.toString()`
  76. * will include the original raws value (comments and all).
  77. *
  78. * ```js
  79. * const root = postcss.parse('a { color: black }')
  80. * const decl = root.first.first
  81. * decl.value //=> 'black'
  82. * ```
  83. */
  84. value: string
  85. /**
  86. * `true` if the declaration has an `!important` annotation.
  87. *
  88. * ```js
  89. * const root = postcss.parse('a { color: black !important; color: red }')
  90. * root.first.first.important //=> true
  91. * root.first.last.important //=> undefined
  92. * ```
  93. */
  94. important: boolean
  95. /**
  96. * `true` if declaration is declaration of CSS Custom Property
  97. * or Sass variable.
  98. *
  99. * ```js
  100. * const root = postcss.parse(':root { --one: 1 }')
  101. * let one = root.first.first
  102. * one.variable //=> true
  103. * ```
  104. *
  105. * ```js
  106. * const root = postcss.parse('$one: 1')
  107. * let one = root.first
  108. * one.variable //=> true
  109. * ```
  110. */
  111. variable: boolean
  112. constructor(defaults?: Declaration.DeclarationProps)
  113. assign(overrides: object | Declaration.DeclarationProps): this
  114. clone(overrides?: Partial<Declaration.DeclarationProps>): this
  115. cloneBefore(overrides?: Partial<Declaration.DeclarationProps>): this
  116. cloneAfter(overrides?: Partial<Declaration.DeclarationProps>): this
  117. }
  118. declare class Declaration extends Declaration_ {}
  119. export = Declaration