版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

295 lines
9.5 KiB

  1. import IShadowRoot from '../shadow-root/IShadowRoot';
  2. import IAttr from '../attr/IAttr';
  3. import INamedNodeMap from '../../named-node-map/INamedNodeMap';
  4. import DOMRect from './DOMRect';
  5. import IDOMTokenList from '../../dom-token-list/IDOMTokenList';
  6. import INode from './../node/INode';
  7. import IChildNode from '../child-node/IChildNode';
  8. import IParentNode from '../parent-node/IParentNode';
  9. import INonDocumentTypeChildNode from '../child-node/INonDocumentTypeChildNode';
  10. import IDOMRectList from './IDOMRectList';
  11. import Event from '../../event/Event';
  12. export declare type TInsertAdjacentPositions = 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend';
  13. /**
  14. * Element.
  15. */
  16. export default interface IElement extends IChildNode, INonDocumentTypeChildNode, IParentNode {
  17. readonly tagName: string;
  18. readonly shadowRoot: IShadowRoot;
  19. readonly classList: IDOMTokenList;
  20. readonly namespaceURI: string;
  21. prefix: string | null;
  22. scrollTop: number;
  23. scrollLeft: number;
  24. id: string;
  25. className: string;
  26. innerHTML: string;
  27. outerHTML: string;
  28. slot: string;
  29. readonly nodeName: string;
  30. readonly localName: string;
  31. readonly attributes: INamedNodeMap;
  32. oncancel: (event: Event) => void | null;
  33. onerror: (event: Event) => void | null;
  34. onscroll: (event: Event) => void | null;
  35. onselect: (event: Event) => void | null;
  36. onwheel: (event: Event) => void | null;
  37. oncopy: (event: Event) => void | null;
  38. oncut: (event: Event) => void | null;
  39. onpaste: (event: Event) => void | null;
  40. oncompositionend: (event: Event) => void | null;
  41. oncompositionstart: (event: Event) => void | null;
  42. oncompositionupdate: (event: Event) => void | null;
  43. onblur: (event: Event) => void | null;
  44. onfocus: (event: Event) => void | null;
  45. onfocusin: (event: Event) => void | null;
  46. onfocusout: (event: Event) => void | null;
  47. onfullscreenchange: (event: Event) => void | null;
  48. onfullscreenerror: (event: Event) => void | null;
  49. onkeydown: (event: Event) => void | null;
  50. onkeyup: (event: Event) => void | null;
  51. onauxclick: (event: Event) => void | null;
  52. onclick: (event: Event) => void | null;
  53. oncontextmenu: (event: Event) => void | null;
  54. ondblclick: (event: Event) => void | null;
  55. onmousedown: (event: Event) => void | null;
  56. onmouseenter: (event: Event) => void | null;
  57. onmouseleave: (event: Event) => void | null;
  58. onmousemove: (event: Event) => void | null;
  59. onmouseout: (event: Event) => void | null;
  60. onmouseover: (event: Event) => void | null;
  61. onmouseup: (event: Event) => void | null;
  62. ontouchcancel: (event: Event) => void | null;
  63. ontouchend: (event: Event) => void | null;
  64. ontouchmove: (event: Event) => void | null;
  65. ontouchstart: (event: Event) => void | null;
  66. /**
  67. * Attribute changed callback.
  68. *
  69. * @param name Name.
  70. * @param oldValue Old value.
  71. * @param newValue New value.
  72. */
  73. attributeChangedCallback?(name: string, oldValue: string, newValue: string): void;
  74. /**
  75. * Returns inner HTML and optionally the content of shadow roots.
  76. *
  77. * This is a feature implemented in Chromium, but not supported by Mozilla yet.
  78. *
  79. * @see https://web.dev/declarative-shadow-dom/
  80. * @see https://chromestatus.com/feature/5191745052606464
  81. * @param [options] Options.
  82. * @param [options.includeShadowRoots] Set to "true" to include shadow roots.
  83. * @returns HTML.
  84. */
  85. getInnerHTML(options?: {
  86. includeShadowRoots?: boolean;
  87. }): string;
  88. /**
  89. * Sets an attribute.
  90. *
  91. * @param name Name.
  92. * @param value Value.
  93. */
  94. setAttribute(name: string, value: string): void;
  95. /**
  96. * Sets a namespace attribute.
  97. *
  98. * @param namespaceURI Namespace URI.
  99. * @param name Name.
  100. * @param value Value.
  101. */
  102. setAttributeNS(namespaceURI: string, name: string, value: string): void;
  103. /**
  104. * Returns attribute names.
  105. *
  106. * @returns Attribute names.
  107. */
  108. getAttributeNames(): string[];
  109. /**
  110. * Returns attribute value.
  111. *
  112. * @param name Name.
  113. */
  114. getAttribute(name: string): string;
  115. /**
  116. * Returns namespace attribute value.
  117. *
  118. * @param namespace Namespace URI.
  119. * @param localName Local name.
  120. */
  121. getAttributeNS(namespace: string, localName: string): string;
  122. /**
  123. * Returns a boolean value indicating whether the specified element has the attribute or not.
  124. *
  125. * @param name Attribute name.
  126. * @returns True if attribute exists, false otherwise.
  127. */
  128. hasAttribute(name: string): boolean;
  129. /**
  130. * Returns a boolean value indicating whether the specified element has the namespace attribute or not.
  131. *
  132. * @param namespace Namespace URI.
  133. * @param localName Local name.
  134. * @returns True if attribute exists, false otherwise.
  135. */
  136. hasAttributeNS(namespace: string, localName: string): boolean;
  137. /**
  138. * Returns "true" if the element has attributes.
  139. *
  140. * @returns "true" if the element has attributes.
  141. */
  142. hasAttributes(): boolean;
  143. /**
  144. * Removes an attribute.
  145. *
  146. * @param name Name.
  147. */
  148. removeAttribute(name: string): void;
  149. /**
  150. * Removes a namespace attribute.
  151. *
  152. * @param namespace Namespace URI.
  153. * @param localName Local name.
  154. */
  155. removeAttributeNS(namespace: string, localName: string): void;
  156. /**
  157. * Toggle an attribute.
  158. *
  159. * @param name A DOMString specifying the name of the attribute to be toggled.
  160. * @param force A boolean value to determine whether the attribute should be added or removed, no matter whether the attribute is present or not at the moment.
  161. */
  162. toggleAttribute(name: string, force?: boolean): boolean;
  163. /**
  164. * Attaches a shadow root.
  165. *
  166. * @param _shadowRootInit Shadow root init.
  167. * @returns Shadow root.
  168. */
  169. attachShadow(_shadowRootInit: {
  170. mode: string;
  171. }): IShadowRoot;
  172. /**
  173. * Scrolls to a particular set of coordinates.
  174. *
  175. * @param x X position or options object.
  176. * @param y Y position.
  177. */
  178. scroll(x: {
  179. top?: number;
  180. left?: number;
  181. behavior?: string;
  182. } | number, y: number): void;
  183. /**
  184. * Scrolls to a particular set of coordinates.
  185. *
  186. * @param x X position or options object.
  187. * @param y Y position.
  188. */
  189. scrollTo(x: {
  190. top?: number;
  191. left?: number;
  192. behavior?: string;
  193. } | number, y: number): void;
  194. /**
  195. * Returns the size of an element and its position relative to the viewport.
  196. *
  197. * @returns DOM rect.
  198. */
  199. getBoundingClientRect(): DOMRect;
  200. /**
  201. * Returns a collection of DOMRect objects that indicate the bounding rectangles for each CSS border box in a client.
  202. *
  203. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getClientRects
  204. * @returns DOM rect list.
  205. */
  206. getClientRects(): IDOMRectList<DOMRect>;
  207. /**
  208. * The matches() method checks to see if the Element would be selected by the provided selectorString.
  209. *
  210. * @param selector Selector.
  211. * @returns "true" if matching.
  212. */
  213. matches(selector: string): boolean;
  214. /**
  215. * Traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string.
  216. *
  217. * @param selector Selector.
  218. * @returns Closest matching element.
  219. */
  220. closest(selector: string): IElement;
  221. /**
  222. * The setAttributeNode() method adds a new Attr node to the specified element.
  223. *
  224. * @param attribute Attribute.
  225. * @returns Replaced attribute.
  226. */
  227. setAttributeNode(attribute: IAttr): IAttr;
  228. /**
  229. * The setAttributeNodeNS() method adds a new Attr node to the specified element.
  230. *
  231. * @param attribute Attribute.
  232. * @returns Replaced attribute.
  233. */
  234. setAttributeNodeNS(attribute: IAttr): IAttr;
  235. /**
  236. * Returns an Attr node.
  237. *
  238. * @param name Name.
  239. * @returns Replaced attribute.
  240. */
  241. getAttributeNode(name: string): IAttr;
  242. /**
  243. * Returns a namespaced Attr node.
  244. *
  245. * @param namespace Namespace.
  246. * @param nodeName Node name.
  247. * @returns Replaced attribute.
  248. */
  249. getAttributeNodeNS(namespace: string, nodeName: string): IAttr;
  250. /**
  251. * Removes an Attr node.
  252. *
  253. * @param attribute Attribute.
  254. * @returns Removed attribute.
  255. */
  256. removeAttributeNode(attribute: IAttr): IAttr;
  257. /**
  258. * Removes an Attr node.
  259. *
  260. * @param attribute Attribute.
  261. * @returns Removed attribute.
  262. */
  263. removeAttributeNodeNS(attribute: IAttr): IAttr;
  264. /**
  265. * Clones a node.
  266. *
  267. * @override
  268. * @param [deep=false] "true" to clone deep.
  269. * @returns Cloned node.
  270. */
  271. cloneNode(deep: boolean): IElement;
  272. /**
  273. * Inserts a node to the given position.
  274. *
  275. * @param position Position to insert element.
  276. * @param element Node to insert.
  277. * @returns Inserted node or null if couldn't insert.
  278. */
  279. insertAdjacentElement(position: TInsertAdjacentPositions, node: INode): INode | null;
  280. /**
  281. * Inserts an HTML string to the given position.
  282. *
  283. * @param position Position to insert text.
  284. * @param text HTML string to insert.
  285. */
  286. insertAdjacentHTML(position: TInsertAdjacentPositions, text: string): void;
  287. /**
  288. * Inserts text to the given position.
  289. *
  290. * @param position Position to insert text.
  291. * @param text String to insert.
  292. */
  293. insertAdjacentText(position: TInsertAdjacentPositions, text: string): void;
  294. }