UNPKG

1.52 kBTypeScriptView Raw
1import Container, { ContainerProps } from './container.js'
2import { ProcessOptions } from './postcss.js'
3import Result from './result.js'
4import Root, { RootProps } from './root.js'
5
6export interface DocumentProps extends ContainerProps {
7 nodes?: Root[]
8
9 /**
10 * Information to generate byte-to-byte equal node string as it was
11 * in the origin input.
12 *
13 * Every parser saves its own properties.
14 */
15 raws?: Record<string, any>
16}
17
18type ChildNode = Root
19type ChildProps = RootProps
20
21/**
22 * Represents a file and contains all its parsed nodes.
23 *
24 * **Experimental:** some aspects of this node could change within minor
25 * or patch version releases.
26 *
27 * ```js
28 * const document = htmlParser(
29 * '<html><style>a{color:black}</style><style>b{z-index:2}</style>'
30 * )
31 * document.type //=> 'document'
32 * document.nodes.length //=> 2
33 * ```
34 */
35export default class Document extends Container<Root> {
36 type: 'document'
37 parent: undefined
38
39 constructor(defaults?: DocumentProps)
40
41 /**
42 * Returns a `Result` instance representing the document’s CSS roots.
43 *
44 * ```js
45 * const root1 = postcss.parse(css1, { from: 'a.css' })
46 * const root2 = postcss.parse(css2, { from: 'b.css' })
47 * const document = postcss.document()
48 * document.append(root1)
49 * document.append(root2)
50 * const result = document.toResult({ to: 'all.css', map: true })
51 * ```
52 *
53 * @param opts Options.
54 * @return Result with current document’s CSS.
55 */
56 toResult(options?: ProcessOptions): Result
57}