document.d.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. parent: undefined
  35. type: 'document'
  36. constructor(defaults?: Document.DocumentProps)
  37. assign(overrides: Document.DocumentProps | object): this
  38. clone(overrides?: Partial<Document.DocumentProps>): Document
  39. cloneAfter(overrides?: Partial<Document.DocumentProps>): Document
  40. cloneBefore(overrides?: Partial<Document.DocumentProps>): Document
  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. }
  58. declare class Document extends Document_ {}
  59. export = Document