You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.5 KiB

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