DOMAdaptor.d.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { OptionList } from '../util/Options.js';
  2. export declare type AttributeData = {
  3. name: string;
  4. value: string;
  5. };
  6. export declare type PageBBox = {
  7. left: number;
  8. right: number;
  9. top: number;
  10. bottom: number;
  11. };
  12. export interface DOMAdaptor<N, T, D> {
  13. document: D;
  14. parse(text: string, format?: string): D;
  15. node(kind: string, def?: OptionList, children?: (N | T)[], ns?: string): N;
  16. text(text: string): T;
  17. head(doc: D): N;
  18. body(doc: D): N;
  19. root(doc: D): N;
  20. doctype(doc: D): string;
  21. tags(node: N, name: string, ns?: string): N[];
  22. getElements(nodes: (string | N | N[])[], document: D): N[];
  23. contains(container: N, node: N | T): boolean;
  24. parent(node: N | T): N;
  25. append(node: N, child: N | T): N | T;
  26. insert(nchild: N | T, ochild: N | T): void;
  27. remove(child: N | T): N | T;
  28. replace(nnode: N | T, onode: N | T): N | T;
  29. clone(node: N): N;
  30. split(node: T, n: number): T;
  31. next(node: N | T): N | T;
  32. previous(node: N | T): N | T;
  33. firstChild(node: N): N | T;
  34. lastChild(node: N): N | T;
  35. childNodes(node: N): (N | T)[];
  36. childNode(node: N, i: number): N | T;
  37. kind(node: N | T): string;
  38. value(node: N | T): string;
  39. textContent(node: N): string;
  40. innerHTML(node: N): string;
  41. outerHTML(node: N): string;
  42. serializeXML(node: N): string;
  43. setAttribute(node: N, name: string, value: string | number, ns?: string): void;
  44. setAttributes(node: N, def: OptionList): void;
  45. getAttribute(node: N, name: string): string;
  46. removeAttribute(node: N, name: string): void;
  47. hasAttribute(node: N, name: string): boolean;
  48. allAttributes(node: N): AttributeData[];
  49. addClass(node: N, name: string): void;
  50. removeClass(node: N, name: string): void;
  51. hasClass(node: N, name: string): boolean;
  52. allClasses(node: N): string[];
  53. setStyle(node: N, name: string, value: string): void;
  54. getStyle(node: N, name: string): string;
  55. allStyles(node: N): string;
  56. insertRules(node: N, rules: string[]): void;
  57. fontSize(node: N): number;
  58. fontFamily(node: N): string;
  59. nodeSize(node: N, em?: number, local?: boolean): [number, number];
  60. nodeBBox(node: N): PageBBox;
  61. }
  62. export declare abstract class AbstractDOMAdaptor<N, T, D> implements DOMAdaptor<N, T, D> {
  63. document: D;
  64. constructor(document?: D);
  65. abstract parse(text: string, format?: string): D;
  66. node(kind: string, def?: OptionList, children?: (N | T)[], ns?: string): N;
  67. protected abstract create(kind: string, ns?: string): N;
  68. abstract text(text: string): T;
  69. setAttributes(node: N, def: OptionList): void;
  70. abstract head(doc: D): N;
  71. abstract body(doc: D): N;
  72. abstract root(doc: D): N;
  73. abstract doctype(doc: D): string;
  74. abstract tags(node: N, name: string, ns?: string): N[];
  75. abstract getElements(nodes: (string | N | N[])[], document: D): N[];
  76. abstract contains(container: N, node: N | T): boolean;
  77. abstract parent(node: N | T): N;
  78. abstract append(node: N, child: N | T): N | T;
  79. abstract insert(nchild: N | T, ochild: N | T): void;
  80. abstract remove(child: N | T): N | T;
  81. replace(nnode: N | T, onode: N | T): N | T;
  82. abstract clone(node: N): N;
  83. abstract split(node: T, n: number): T;
  84. abstract next(node: N | T): N | T;
  85. abstract previous(node: N | T): N | T;
  86. abstract firstChild(node: N): N | T;
  87. abstract lastChild(node: N): N | T;
  88. abstract childNodes(node: N): (N | T)[];
  89. childNode(node: N, i: number): N | T;
  90. abstract kind(node: N | T): string;
  91. abstract value(node: N | T): string;
  92. abstract textContent(node: N): string;
  93. abstract innerHTML(node: N): string;
  94. abstract outerHTML(node: N): string;
  95. abstract serializeXML(node: N): string;
  96. abstract setAttribute(node: N, name: string, value: string, ns?: string): void;
  97. abstract getAttribute(node: N, name: string): string;
  98. abstract removeAttribute(node: N, name: string): void;
  99. abstract hasAttribute(node: N, name: string): boolean;
  100. abstract allAttributes(node: N): AttributeData[];
  101. abstract addClass(node: N, name: string): void;
  102. abstract removeClass(node: N, name: string): void;
  103. abstract hasClass(node: N, name: string): boolean;
  104. allClasses(node: N): string[];
  105. abstract setStyle(node: N, name: string, value: string): void;
  106. abstract getStyle(node: N, name: string): string;
  107. abstract allStyles(node: N): string;
  108. abstract insertRules(node: N, rules: string[]): void;
  109. abstract fontSize(node: N): number;
  110. abstract fontFamily(node: N): string;
  111. abstract nodeSize(node: N, em?: number, local?: boolean): [number, number];
  112. abstract nodeBBox(node: N): PageBBox;
  113. }