document.d.ts 1.9 KB

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