root.d.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. nodes: NonNullable<Container['nodes']>
  51. parent: Document | undefined
  52. raws: Root.RootRaws
  53. type: 'root'
  54. constructor(defaults?: Root.RootProps)
  55. assign(overrides: object | Root.RootProps): this
  56. clone(overrides?: Partial<Root.RootProps>): this
  57. cloneAfter(overrides?: Partial<Root.RootProps>): this
  58. cloneBefore(overrides?: Partial<Root.RootProps>): this
  59. /**
  60. * Returns a `Result` instance representing the root’s CSS.
  61. *
  62. * ```js
  63. * const root1 = postcss.parse(css1, { from: 'a.css' })
  64. * const root2 = postcss.parse(css2, { from: 'b.css' })
  65. * root1.append(root2)
  66. * const result = root1.toResult({ to: 'all.css', map: true })
  67. * ```
  68. *
  69. * @param options Options.
  70. * @return Result with current root’s CSS.
  71. */
  72. toResult(options?: ProcessOptions): Result
  73. }
  74. declare class Root extends Root_ {}
  75. export = Root