index.d.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { ChildNode, Element, DataNode, Document, ParentNode } from "./node.js";
  2. export * from "./node.js";
  3. export interface DomHandlerOptions {
  4. /**
  5. * Add a `startIndex` property to nodes.
  6. * When the parser is used in a non-streaming fashion, `startIndex` is an integer
  7. * indicating the position of the start of the node in the document.
  8. *
  9. * @default false
  10. */
  11. withStartIndices?: boolean;
  12. /**
  13. * Add an `endIndex` property to nodes.
  14. * When the parser is used in a non-streaming fashion, `endIndex` is an integer
  15. * indicating the position of the end of the node in the document.
  16. *
  17. * @default false
  18. */
  19. withEndIndices?: boolean;
  20. /**
  21. * Treat the markup as XML.
  22. *
  23. * @default false
  24. */
  25. xmlMode?: boolean;
  26. }
  27. interface ParserInterface {
  28. startIndex: number | null;
  29. endIndex: number | null;
  30. }
  31. declare type Callback = (error: Error | null, dom: ChildNode[]) => void;
  32. declare type ElementCallback = (element: Element) => void;
  33. export declare class DomHandler {
  34. /** The elements of the DOM */
  35. dom: ChildNode[];
  36. /** The root element for the DOM */
  37. root: Document;
  38. /** Called once parsing has completed. */
  39. private readonly callback;
  40. /** Settings for the handler. */
  41. private readonly options;
  42. /** Callback whenever a tag is closed. */
  43. private readonly elementCB;
  44. /** Indicated whether parsing has been completed. */
  45. private done;
  46. /** Stack of open tags. */
  47. protected tagStack: ParentNode[];
  48. /** A data node that is still being written to. */
  49. protected lastNode: DataNode | null;
  50. /** Reference to the parser instance. Used for location information. */
  51. private parser;
  52. /**
  53. * @param callback Called once parsing has completed.
  54. * @param options Settings for the handler.
  55. * @param elementCB Callback whenever a tag is closed.
  56. */
  57. constructor(callback?: Callback | null, options?: DomHandlerOptions | null, elementCB?: ElementCallback);
  58. onparserinit(parser: ParserInterface): void;
  59. onreset(): void;
  60. onend(): void;
  61. onerror(error: Error): void;
  62. onclosetag(): void;
  63. onopentag(name: string, attribs: {
  64. [key: string]: string;
  65. }): void;
  66. ontext(data: string): void;
  67. oncomment(data: string): void;
  68. oncommentend(): void;
  69. oncdatastart(): void;
  70. oncdataend(): void;
  71. onprocessinginstruction(name: string, data: string): void;
  72. protected handleCallback(error: Error | null): void;
  73. protected addNode(node: ChildNode): void;
  74. }
  75. export default DomHandler;
  76. //# sourceMappingURL=index.d.ts.map