UNPKG

1.86 kBTypeScriptView Raw
1import Container, { ContainerProps } from './container.js'
2import Document from './document.js'
3import { ProcessOptions } from './postcss.js'
4import Result from './result.js'
5
6interface RootRaws extends Record<string, any> {
7 /**
8 * The space symbols after the last child to the end of file.
9 */
10 after?: string
11
12 /**
13 * Non-CSS code before `Root`, when `Root` is inside `Document`.
14 *
15 * **Experimental:** some aspects of this node could change within minor
16 * or patch version releases.
17 */
18 codeBefore?: string
19
20 /**
21 * Non-CSS code after `Root`, when `Root` is inside `Document`.
22 *
23 * **Experimental:** some aspects of this node could change within minor
24 * or patch version releases.
25 */
26 codeAfter?: string
27
28 /**
29 * Is the last child has an (optional) semicolon.
30 */
31 semicolon?: boolean
32}
33
34export interface RootProps extends ContainerProps {
35 /**
36 * Information used to generate byte-to-byte equal node string
37 * as it was in the origin input.
38 * */
39 raws?: RootRaws
40}
41
42/**
43 * Represents a CSS file and contains all its parsed nodes.
44 *
45 * ```js
46 * const root = postcss.parse('a{color:black} b{z-index:2}')
47 * root.type //=> 'root'
48 * root.nodes.length //=> 2
49 * ```
50 */
51export default class Root extends Container {
52 type: 'root'
53 parent: Document | undefined
54 raws: RootRaws
55
56 /**
57 * Returns a `Result` instance representing the root’s CSS.
58 *
59 * ```js
60 * const root1 = postcss.parse(css1, { from: 'a.css' })
61 * const root2 = postcss.parse(css2, { from: 'b.css' })
62 * root1.append(root2)
63 * const result = root1.toResult({ to: 'all.css', map: true })
64 * ```
65 *
66 * @param opts Options.
67 * @return Result with current root’s CSS.
68 */
69 toResult(options?: ProcessOptions): Result
70
71 constructor(defaults?: RootProps)
72 assign(overrides: object | RootProps): this
73}