UNPKG

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