root.d.ts 2.2 KB

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