1 | import AtRule = require('./at-rule.js')
|
2 |
|
3 | import { AtRuleProps } from './at-rule.js'
|
4 | import Comment, { CommentProps } from './comment.js'
|
5 | import Container from './container.js'
|
6 | import CssSyntaxError from './css-syntax-error.js'
|
7 | import Declaration, { DeclarationProps } from './declaration.js'
|
8 | import Document from './document.js'
|
9 | import Input from './input.js'
|
10 | import { Stringifier, Syntax } from './postcss.js'
|
11 | import Result from './result.js'
|
12 | import Root from './root.js'
|
13 | import Rule, { RuleProps } from './rule.js'
|
14 | import Warning, { WarningOptions } from './warning.js'
|
15 |
|
16 | declare namespace Node {
|
17 | export type ChildNode = AtRule.default | Comment | Declaration | Rule
|
18 |
|
19 | export type AnyNode =
|
20 | | AtRule.default
|
21 | | Comment
|
22 | | Declaration
|
23 | | Document
|
24 | | Root
|
25 | | Rule
|
26 |
|
27 | export type ChildProps =
|
28 | | AtRuleProps
|
29 | | CommentProps
|
30 | | DeclarationProps
|
31 | | RuleProps
|
32 |
|
33 | export interface Position {
|
34 | |
35 |
|
36 |
|
37 | column: number
|
38 |
|
39 | |
40 |
|
41 |
|
42 | line: number
|
43 |
|
44 | |
45 |
|
46 |
|
47 | offset: number
|
48 | }
|
49 |
|
50 | export interface Range {
|
51 | |
52 |
|
53 |
|
54 | end: Position
|
55 |
|
56 | |
57 |
|
58 |
|
59 | start: Position
|
60 | }
|
61 |
|
62 | |
63 |
|
64 |
|
65 | export interface Source {
|
66 | |
67 |
|
68 |
|
69 |
|
70 | end?: Position
|
71 |
|
72 | |
73 |
|
74 |
|
75 | input: Input
|
76 |
|
77 | |
78 |
|
79 |
|
80 |
|
81 | start?: Position
|
82 | }
|
83 |
|
84 | |
85 |
|
86 |
|
87 |
|
88 | export interface NodeProps {
|
89 | source?: Source
|
90 | }
|
91 |
|
92 | export interface NodeErrorOptions {
|
93 | |
94 |
|
95 |
|
96 |
|
97 | endIndex?: number
|
98 | |
99 |
|
100 |
|
101 |
|
102 | index?: number
|
103 | |
104 |
|
105 |
|
106 | plugin?: string
|
107 | |
108 |
|
109 |
|
110 |
|
111 | word?: string
|
112 | }
|
113 |
|
114 |
|
115 | class Node extends Node_ {}
|
116 | export { Node as default }
|
117 | }
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 | declare abstract class Node_ {
|
127 | |
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 | parent: Container | Document | undefined
|
135 |
|
136 | |
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 | raws: any
|
171 |
|
172 | |
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 | source?: Node.Source
|
216 |
|
217 | |
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 | type: string
|
234 |
|
235 | constructor(defaults?: object)
|
236 |
|
237 | /**
|
238 | * Insert new node after current node to current node’s parent.
|
239 | *
|
240 | * Just alias for `node.parent.insertAfter(node, add)`.
|
241 | *
|
242 | * ```js
|
243 | * decl.after('color: black')
|
244 | * ```
|
245 | *
|
246 | * @param newNode New node.
|
247 | * @return This node for methods chain.
|
248 | */
|
249 | after(newNode: Node | Node.ChildProps | Node[] | string): this
|
250 |
|
251 | /**
|
252 | * It assigns properties to an existing node instance.
|
253 | *
|
254 | * ```js
|
255 | * decl.assign({ prop: 'word-wrap', value: 'break-word' })
|
256 | * ```
|
257 | *
|
258 | * @param overrides New properties to override the node.
|
259 | *
|
260 | * @return `this` for method chaining.
|
261 | */
|
262 | assign(overrides: object): this
|
263 |
|
264 | /**
|
265 | * Insert new node before current node to current node’s parent.
|
266 | *
|
267 | * Just alias for `node.parent.insertBefore(node, add)`.
|
268 | *
|
269 | * ```js
|
270 | * decl.before('content: ""')
|
271 | * ```
|
272 | *
|
273 | * @param newNode New node.
|
274 | * @return This node for methods chain.
|
275 | */
|
276 | before(newNode: Node | Node.ChildProps | Node[] | string): this
|
277 |
|
278 | /**
|
279 | * Clear the code style properties for the node and its children.
|
280 | *
|
281 | * ```js
|
282 | * node.raws.before //=> ' '
|
283 | * node.cleanRaws()
|
284 | * node.raws.before //=> undefined
|
285 | * ```
|
286 | *
|
287 | * @param keepBetween Keep the `raws.between` symbols.
|
288 | */
|
289 | cleanRaws(keepBetween?: boolean): void
|
290 |
|
291 | /**
|
292 | * It creates clone of an existing node, which includes all the properties
|
293 | * and their values, that includes `raws` but not `type`.
|
294 | *
|
295 | * ```js
|
296 | * decl.raws.before //=> "\n "
|
297 | * const cloned = decl.clone({ prop: '-moz-' + decl.prop })
|
298 | * cloned.raws.before //=> "\n "
|
299 | * cloned.toString() //=> -moz-transform: scale(0)
|
300 | * ```
|
301 | *
|
302 | * @param overrides New properties to override in the clone.
|
303 | *
|
304 | * @return Duplicate of the node instance.
|
305 | */
|
306 | clone(overrides?: object): Node
|
307 |
|
308 | /**
|
309 | * Shortcut to clone the node and insert the resulting cloned node
|
310 | * after the current node.
|
311 | *
|
312 | * @param overrides New properties to override in the clone.
|
313 | * @return New node.
|
314 | */
|
315 | cloneAfter(overrides?: object): Node
|
316 |
|
317 | /**
|
318 | * Shortcut to clone the node and insert the resulting cloned node
|
319 | * before the current node.
|
320 | *
|
321 | * ```js
|
322 | * decl.cloneBefore({ prop: '-moz-' + decl.prop })
|
323 | * ```
|
324 | *
|
325 | * @param overrides Mew properties to override in the clone.
|
326 | *
|
327 | * @return New node
|
328 | */
|
329 | cloneBefore(overrides?: object): Node
|
330 |
|
331 | /**
|
332 | * It creates an instance of the class `CssSyntaxError` and parameters passed
|
333 | * to this method are assigned to the error instance.
|
334 | *
|
335 | * The error instance will have description for the
|
336 | * error, original position of the node in the
|
337 | * source, showing line and column number.
|
338 | *
|
339 | * If any previous map is present, it would be used
|
340 | * to get original position of the source.
|
341 | *
|
342 | * The Previous Map here is referred to the source map
|
343 | * generated by previous compilation, example: Less,
|
344 | * Stylus and Sass.
|
345 | *
|
346 | * This method returns the error instance instead of
|
347 | * throwing it.
|
348 | *
|
349 | * ```js
|
350 | * if (!variables[name]) {
|
351 | * throw decl.error(`Unknown variable ${name}`, { word: name })
|
352 | *
|
353 | *
|
354 | *
|
355 | *
|
356 | *
|
357 | * }
|
358 | * ```
|
359 | *
|
360 | * @param message Description for the error instance.
|
361 | * @param options Options for the error instance.
|
362 | *
|
363 | * @return Error instance is returned.
|
364 | */
|
365 | error(message: string, options?: Node.NodeErrorOptions): CssSyntaxError
|
366 |
|
367 | /**
|
368 | * Returns the next child of the node’s parent.
|
369 | * Returns `undefined` if the current node is the last child.
|
370 | *
|
371 | * ```js
|
372 | * if (comment.text === 'delete next') {
|
373 | * const next = comment.next()
|
374 | * if (next) {
|
375 | * next.remove()
|
376 | * }
|
377 | * }
|
378 | * ```
|
379 | *
|
380 | * @return Next node.
|
381 | */
|
382 | next(): Node.ChildNode | undefined
|
383 |
|
384 | /**
|
385 | * Get the position for a word or an index inside the node.
|
386 | *
|
387 | * @param opts Options.
|
388 | * @return Position.
|
389 | */
|
390 | positionBy(opts?: Pick<WarningOptions, 'index' | 'word'>): Node.Position
|
391 |
|
392 | /**
|
393 | * Convert string index to line/column.
|
394 | *
|
395 | * @param index The symbol number in the node’s string.
|
396 | * @return Symbol position in file.
|
397 | */
|
398 | positionInside(index: number): Node.Position
|
399 |
|
400 | /**
|
401 | * Returns the previous child of the node’s parent.
|
402 | * Returns `undefined` if the current node is the first child.
|
403 | *
|
404 | * ```js
|
405 | * const annotation = decl.prev()
|
406 | * if (annotation.type === 'comment') {
|
407 | * readAnnotation(annotation.text)
|
408 | * }
|
409 | * ```
|
410 | *
|
411 | * @return Previous node.
|
412 | */
|
413 | prev(): Node.ChildNode | undefined
|
414 |
|
415 | /**
|
416 | * Get the range for a word or start and end index inside the node.
|
417 | * The start index is inclusive; the end index is exclusive.
|
418 | *
|
419 | * @param opts Options.
|
420 | * @return Range.
|
421 | */
|
422 | rangeBy(
|
423 | opts?: Pick<WarningOptions, 'endIndex' | 'index' | 'word'>
|
424 | ): Node.Range
|
425 |
|
426 | /**
|
427 | * Returns a `raws` value. If the node is missing
|
428 | * the code style property (because the node was manually built or cloned),
|
429 | * PostCSS will try to autodetect the code style property by looking
|
430 | * at other nodes in the tree.
|
431 | *
|
432 | * ```js
|
433 | * const root = postcss.parse('a { background: white }')
|
434 | * root.nodes[0].append({ prop: 'color', value: 'black' })
|
435 | * root.nodes[0].nodes[1].raws.before
|
436 | * root.nodes[0].nodes[1].raw('before')
|
437 | * ```
|
438 | *
|
439 | * @param prop Name of code style property.
|
440 | * @param defaultType Name of default value, it can be missed
|
441 | * if the value is the same as prop.
|
442 | * @return {string} Code style value.
|
443 | */
|
444 | raw(prop: string, defaultType?: string): string
|
445 |
|
446 | /**
|
447 | * It removes the node from its parent and deletes its parent property.
|
448 | *
|
449 | * ```js
|
450 | * if (decl.prop.match(/^-webkit-/)) {
|
451 | * decl.remove()
|
452 | * }
|
453 | * ```
|
454 | *
|
455 | * @return `this` for method chaining.
|
456 | */
|
457 | remove(): this
|
458 |
|
459 | /**
|
460 | * Inserts node(s) before the current node and removes the current node.
|
461 | *
|
462 | * ```js
|
463 | * AtRule: {
|
464 | * mixin: atrule => {
|
465 | * atrule.replaceWith(mixinRules[atrule.params])
|
466 | * }
|
467 | * }
|
468 | * ```
|
469 | *
|
470 | * @param nodes Mode(s) to replace current one.
|
471 | * @return Current node to methods chain.
|
472 | */
|
473 | replaceWith(
|
474 | ...nodes: (
|
475 | | Node.ChildNode
|
476 | | Node.ChildNode[]
|
477 | | Node.ChildProps
|
478 | | Node.ChildProps[]
|
479 | )[]
|
480 | ): this
|
481 |
|
482 | /**
|
483 | * Finds the Root instance of the node’s tree.
|
484 | *
|
485 | * ```js
|
486 | * root.nodes[0].nodes[0].root() === root
|
487 | * ```
|
488 | *
|
489 | * @return Root parent.
|
490 | */
|
491 | root(): Root
|
492 |
|
493 | /**
|
494 | * Fix circular links on `JSON.stringify()`.
|
495 | *
|
496 | * @return Cleaned object.
|
497 | */
|
498 | toJSON(): object
|
499 |
|
500 | /**
|
501 | * It compiles the node to browser readable cascading style sheets string
|
502 | * depending on it's type.
|
503 | *
|
504 | * ```js
|
505 | * new Rule({ selector: 'a' }).toString()
|
506 | * ```
|
507 | *
|
508 | * @param stringifier A syntax to use in string generation.
|
509 | * @return CSS string of this node.
|
510 | */
|
511 | toString(stringifier?: Stringifier | Syntax): string
|
512 |
|
513 | /**
|
514 | * It is a wrapper for {@link Result#warn}, providing convenient
|
515 | * way of generating warnings.
|
516 | *
|
517 | * ```js
|
518 | * Declaration: {
|
519 | * bad: (decl, { result }) => {
|
520 | * decl.warn(result, 'Deprecated property: bad')
|
521 | * }
|
522 | * }
|
523 | * ```
|
524 | *
|
525 | * @param result The `Result` instance that will receive the warning.
|
526 | * @param message Description for the warning.
|
527 | * @param options Options for the warning.
|
528 | *
|
529 | * @return `Warning` instance is returned
|
530 | */
|
531 | warn(result: Result, message: string, options?: WarningOptions): Warning
|
532 | }
|
533 |
|
534 | declare class Node extends Node_ { }
|
535 |
|
536 | export = Node
|
537 |
|
\ | No newline at end of file |