root.d.ts 1.8 KB

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