HTMLAdaptor.d.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import { OptionList } from '../util/Options.js';
  2. import { AttributeData, AbstractDOMAdaptor, DOMAdaptor } from '../core/DOMAdaptor.js';
  3. export interface MinDocument<N, T> {
  4. documentElement: N;
  5. head: N;
  6. body: N;
  7. title: string;
  8. doctype: {
  9. name: string;
  10. };
  11. createElement(kind: string): N;
  12. createElementNS(ns: string, kind: string): N;
  13. createTextNode(text: string): T;
  14. querySelectorAll(selector: string): ArrayLike<N>;
  15. }
  16. export interface MinHTMLElement<N, T> {
  17. nodeType: number;
  18. nodeName: string;
  19. nodeValue: string;
  20. textContent: string;
  21. innerHTML: string;
  22. outerHTML: string;
  23. parentNode: N | Node;
  24. nextSibling: N | T | Node;
  25. previousSibling: N | T | Node;
  26. offsetWidth: number;
  27. offsetHeight: number;
  28. attributes: AttributeData[] | NamedNodeMap;
  29. className: string;
  30. classList: DOMTokenList;
  31. style: OptionList;
  32. sheet?: {
  33. insertRule: (rule: string, index?: number) => void;
  34. };
  35. childNodes: (N | T)[] | NodeList;
  36. firstChild: N | T | Node;
  37. lastChild: N | T | Node;
  38. getElementsByTagName(name: string): N[] | HTMLCollectionOf<Element>;
  39. getElementsByTagNameNS(ns: string, name: string): N[] | HTMLCollectionOf<Element>;
  40. contains(child: N | T): boolean;
  41. appendChild(child: N | T): N | T | Node;
  42. removeChild(child: N | T): N | T | Node;
  43. replaceChild(nnode: N | T, onode: N | T): N | T | Node;
  44. insertBefore(nchild: N | T, ochild: N | T): void;
  45. cloneNode(deep: boolean): N | Node;
  46. setAttribute(name: string, value: string): void;
  47. setAttributeNS(ns: string, name: string, value: string): void;
  48. getAttribute(name: string): string;
  49. removeAttribute(name: string): void;
  50. hasAttribute(name: string): boolean;
  51. getBoundingClientRect(): Object;
  52. getBBox?(): {
  53. x: number;
  54. y: number;
  55. width: number;
  56. height: number;
  57. };
  58. }
  59. export interface MinText<N, T> {
  60. nodeType: number;
  61. nodeName: string;
  62. nodeValue: string;
  63. parentNode: N | Node;
  64. nextSibling: N | T | Node;
  65. previousSibling: N | T | Node;
  66. splitText(n: number): T;
  67. }
  68. export interface MinDOMParser<D> {
  69. parseFromString(text: string, format?: string): D;
  70. }
  71. export interface MinXMLSerializer<N> {
  72. serializeToString(node: N): string;
  73. }
  74. export interface MinWindow<N, D> {
  75. document: D;
  76. DOMParser: {
  77. new (): MinDOMParser<D>;
  78. };
  79. XMLSerializer: {
  80. new (): MinXMLSerializer<N>;
  81. };
  82. NodeList: any;
  83. HTMLCollection: any;
  84. HTMLElement: any;
  85. DocumentFragment: any;
  86. Document: any;
  87. getComputedStyle(node: N): any;
  88. }
  89. export interface MinHTMLAdaptor<N, T, D> extends DOMAdaptor<N, T, D> {
  90. window: MinWindow<N, D>;
  91. }
  92. export declare class HTMLAdaptor<N extends MinHTMLElement<N, T>, T extends MinText<N, T>, D extends MinDocument<N, T>> extends AbstractDOMAdaptor<N, T, D> implements MinHTMLAdaptor<N, T, D> {
  93. window: MinWindow<N, D>;
  94. parser: MinDOMParser<D>;
  95. constructor(window: MinWindow<N, D>);
  96. parse(text: string, format?: string): D;
  97. protected create(kind: string, ns?: string): N;
  98. text(text: string): T;
  99. head(doc: D): N;
  100. body(doc: D): N;
  101. root(doc: D): N;
  102. doctype(doc: D): string;
  103. tags(node: N, name: string, ns?: string): N[];
  104. getElements(nodes: (string | N | N[])[], _document: D): N[];
  105. contains(container: N, node: N | T): boolean;
  106. parent(node: N | T): N;
  107. append(node: N, child: N | T): N | T;
  108. insert(nchild: N | T, ochild: N | T): void;
  109. remove(child: N | T): N | T;
  110. replace(nnode: N | T, onode: N | T): N | T;
  111. clone(node: N): N;
  112. split(node: T, n: number): T;
  113. next(node: N | T): N | T;
  114. previous(node: N | T): N | T;
  115. firstChild(node: N): N | T;
  116. lastChild(node: N): N | T;
  117. childNodes(node: N): (N | T)[];
  118. childNode(node: N, i: number): N | T;
  119. kind(node: N | T): string;
  120. value(node: N | T): string;
  121. textContent(node: N): string;
  122. innerHTML(node: N): string;
  123. outerHTML(node: N): string;
  124. serializeXML(node: N): string;
  125. setAttribute(node: N, name: string, value: string, ns?: string): void;
  126. getAttribute(node: N, name: string): string;
  127. removeAttribute(node: N, name: string): void;
  128. hasAttribute(node: N, name: string): boolean;
  129. allAttributes(node: N): AttributeData[];
  130. addClass(node: N, name: string): void;
  131. removeClass(node: N, name: string): void;
  132. hasClass(node: N, name: string): boolean;
  133. setStyle(node: N, name: string, value: string): void;
  134. getStyle(node: N, name: string): any;
  135. allStyles(node: N): any;
  136. insertRules(node: N, rules: string[]): void;
  137. fontSize(node: N): number;
  138. fontFamily(node: N): any;
  139. nodeSize(node: N, em?: number, local?: boolean): [number, number];
  140. nodeBBox(node: N): {
  141. left: number;
  142. right: number;
  143. top: number;
  144. bottom: number;
  145. };
  146. }