UNPKG

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