版博士V2.0程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Element.d.ts 15 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. import Node from '../node/Node';
  2. import DOMRect from './DOMRect';
  3. import IDOMTokenList from '../../dom-token-list/IDOMTokenList';
  4. import IElement from './IElement';
  5. import IShadowRoot from '../shadow-root/IShadowRoot';
  6. import INode from '../node/INode';
  7. import IHTMLCollection from './IHTMLCollection';
  8. import INodeList from '../node/INodeList';
  9. import { TInsertAdjacentPositions } from './IElement';
  10. import IDOMRectList from './IDOMRectList';
  11. import IAttr from '../attr/IAttr';
  12. import INamedNodeMap from '../../named-node-map/INamedNodeMap';
  13. import Event from '../../event/Event';
  14. /**
  15. * Element.
  16. */
  17. export default class Element extends Node implements IElement {
  18. static _observedAttributes: string[];
  19. static observedAttributes: string[];
  20. tagName: string;
  21. nodeType: import("../node/NodeTypeEnum").default;
  22. shadowRoot: IShadowRoot;
  23. prefix: string;
  24. scrollTop: number;
  25. scrollLeft: number;
  26. children: IHTMLCollection<IElement>;
  27. readonly namespaceURI: string;
  28. oncancel: (event: Event) => void | null;
  29. onerror: (event: Event) => void | null;
  30. onscroll: (event: Event) => void | null;
  31. onselect: (event: Event) => void | null;
  32. onwheel: (event: Event) => void | null;
  33. oncopy: (event: Event) => void | null;
  34. oncut: (event: Event) => void | null;
  35. onpaste: (event: Event) => void | null;
  36. oncompositionend: (event: Event) => void | null;
  37. oncompositionstart: (event: Event) => void | null;
  38. oncompositionupdate: (event: Event) => void | null;
  39. onblur: (event: Event) => void | null;
  40. onfocus: (event: Event) => void | null;
  41. onfocusin: (event: Event) => void | null;
  42. onfocusout: (event: Event) => void | null;
  43. onfullscreenchange: (event: Event) => void | null;
  44. onfullscreenerror: (event: Event) => void | null;
  45. onkeydown: (event: Event) => void | null;
  46. onkeyup: (event: Event) => void | null;
  47. onauxclick: (event: Event) => void | null;
  48. onclick: (event: Event) => void | null;
  49. oncontextmenu: (event: Event) => void | null;
  50. ondblclick: (event: Event) => void | null;
  51. onmousedown: (event: Event) => void | null;
  52. onmouseenter: (event: Event) => void | null;
  53. onmouseleave: (event: Event) => void | null;
  54. onmousemove: (event: Event) => void | null;
  55. onmouseout: (event: Event) => void | null;
  56. onmouseover: (event: Event) => void | null;
  57. onmouseup: (event: Event) => void | null;
  58. ontouchcancel: (event: Event) => void | null;
  59. ontouchend: (event: Event) => void | null;
  60. ontouchmove: (event: Event) => void | null;
  61. ontouchstart: (event: Event) => void | null;
  62. _shadowRoot: IShadowRoot;
  63. _attributes: {
  64. [k: string]: IAttr;
  65. };
  66. private _classList;
  67. _isValue?: string;
  68. /**
  69. * Returns class list.
  70. *
  71. * @returns Class list.
  72. */
  73. get classList(): IDOMTokenList;
  74. /**
  75. * Returns ID.
  76. *
  77. * @returns ID.
  78. */
  79. get id(): string;
  80. /**
  81. * Sets ID.
  82. *
  83. * @param id ID.
  84. */
  85. set id(id: string);
  86. /**
  87. * Returns class name.
  88. *
  89. * @returns Class name.
  90. */
  91. get className(): string;
  92. /**
  93. * Sets class name.
  94. *
  95. * @param className Class name.
  96. */
  97. set className(className: string);
  98. /**
  99. * Node name.
  100. *
  101. * @returns Node name.
  102. */
  103. get nodeName(): string;
  104. /**
  105. * Local name.
  106. *
  107. * @returns Local name.
  108. */
  109. get localName(): string;
  110. /**
  111. * Previous element sibling.
  112. *
  113. * @returns Element.
  114. */
  115. get previousElementSibling(): IElement;
  116. /**
  117. * Next element sibling.
  118. *
  119. * @returns Element.
  120. */
  121. get nextElementSibling(): IElement;
  122. /**
  123. * Get text value of children.
  124. *
  125. * @returns Text content.
  126. */
  127. get textContent(): string;
  128. /**
  129. * Sets text content.
  130. *
  131. * @param textContent Text content.
  132. */
  133. set textContent(textContent: string);
  134. /**
  135. * Returns inner HTML.
  136. *
  137. * @returns HTML.
  138. */
  139. get innerHTML(): string;
  140. /**
  141. * Sets inner HTML.
  142. *
  143. * @param html HTML.
  144. */
  145. set innerHTML(html: string);
  146. /**
  147. * Returns outer HTML.
  148. *
  149. * @returns HTML.
  150. */
  151. get outerHTML(): string;
  152. /**
  153. * Returns outer HTML.
  154. *
  155. * @param html HTML.
  156. */
  157. set outerHTML(html: string);
  158. /**
  159. * Returns attributes.
  160. *
  161. * @returns Attributes.
  162. */
  163. get attributes(): INamedNodeMap;
  164. /**
  165. * First element child.
  166. *
  167. * @returns Element.
  168. */
  169. get firstElementChild(): IElement;
  170. /**
  171. * Last element child.
  172. *
  173. * @returns Element.
  174. */
  175. get lastElementChild(): IElement;
  176. /**
  177. * Last element child.
  178. *
  179. * @returns Element.
  180. */
  181. get childElementCount(): number;
  182. /**
  183. * Returns slot.
  184. *
  185. * @returns Slot.
  186. */
  187. get slot(): string;
  188. /**
  189. * Returns slot.
  190. *
  191. * @param slot Slot.
  192. */
  193. set slot(title: string);
  194. /**
  195. * Attribute changed callback.
  196. *
  197. * @param name Name.
  198. * @param oldValue Old value.
  199. * @param newValue New value.
  200. */
  201. attributeChangedCallback?(name: string, oldValue: string, newValue: string): void;
  202. /**
  203. * Returns inner HTML and optionally the content of shadow roots.
  204. *
  205. * This is a feature implemented in Chromium, but not supported by Mozilla yet.
  206. *
  207. * @see https://web.dev/declarative-shadow-dom/
  208. * @see https://chromestatus.com/feature/5191745052606464
  209. * @param [options] Options.
  210. * @param [options.includeShadowRoots] Set to "true" to include shadow roots.
  211. * @returns HTML.
  212. */
  213. getInnerHTML(options?: {
  214. includeShadowRoots?: boolean;
  215. }): string;
  216. /**
  217. * Clones a node.
  218. *
  219. * @override
  220. * @param [deep=false] "true" to clone deep.
  221. * @returns Cloned node.
  222. */
  223. cloneNode(deep?: boolean): IElement;
  224. /**
  225. * @override
  226. */
  227. appendChild(node: INode): INode;
  228. /**
  229. * @override
  230. */
  231. removeChild(node: INode): INode;
  232. /**
  233. * Removes the node from its parent.
  234. */
  235. remove(): void;
  236. /**
  237. * @override
  238. */
  239. insertBefore(newNode: INode, referenceNode: INode | null): INode;
  240. /**
  241. * The Node.replaceWith() method replaces this Node in the children list of its parent with a set of Node or DOMString objects.
  242. *
  243. * @param nodes List of Node or DOMString.
  244. */
  245. replaceWith(...nodes: (INode | string)[]): void;
  246. /**
  247. * Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, just before this ChildNode. DOMString objects are inserted as equivalent Text nodes.
  248. *
  249. * @param nodes List of Node or DOMString.
  250. */
  251. before(...nodes: (string | INode)[]): void;
  252. /**
  253. * Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, just after this ChildNode. DOMString objects are inserted as equivalent Text nodes.
  254. *
  255. * @param nodes List of Node or DOMString.
  256. */
  257. after(...nodes: (string | INode)[]): void;
  258. /**
  259. * Inserts a set of Node objects or DOMString objects after the last child of the ParentNode. DOMString objects are inserted as equivalent Text nodes.
  260. *
  261. * @param nodes List of Node or DOMString.
  262. */
  263. append(...nodes: (string | INode)[]): void;
  264. /**
  265. * Inserts a set of Node objects or DOMString objects before the first child of the ParentNode. DOMString objects are inserted as equivalent Text nodes.
  266. *
  267. * @param nodes List of Node or DOMString.
  268. */
  269. prepend(...nodes: (string | INode)[]): void;
  270. /**
  271. * Replaces the existing children of a node with a specified new set of children.
  272. *
  273. * @param nodes List of Node or DOMString.
  274. */
  275. replaceChildren(...nodes: (string | INode)[]): void;
  276. /**
  277. * Inserts a node to the given position.
  278. *
  279. * @param position Position to insert element.
  280. * @param element Node to insert.
  281. * @returns Inserted node or null if couldn't insert.
  282. */
  283. insertAdjacentElement(position: TInsertAdjacentPositions, element: INode): INode | null;
  284. /**
  285. * Inserts an HTML string to the given position.
  286. *
  287. * @param position Position to insert text.
  288. * @param text HTML string to insert.
  289. */
  290. insertAdjacentHTML(position: TInsertAdjacentPositions, text: string): void;
  291. /**
  292. * Inserts text to the given position.
  293. *
  294. * @param position Position to insert text.
  295. * @param text String to insert.
  296. */
  297. insertAdjacentText(position: TInsertAdjacentPositions, text: string): void;
  298. /**
  299. * Sets an attribute.
  300. *
  301. * @param name Name.
  302. * @param value Value.
  303. */
  304. setAttribute(name: string, value: string): void;
  305. /**
  306. * Sets a namespace attribute.
  307. *
  308. * @param namespaceURI Namespace URI.
  309. * @param name Name.
  310. * @param value Value.
  311. */
  312. setAttributeNS(namespaceURI: string, name: string, value: string): void;
  313. /**
  314. * Returns attribute names.
  315. *
  316. * @returns Attribute names.
  317. */
  318. getAttributeNames(): string[];
  319. /**
  320. * Returns attribute value.
  321. *
  322. * @param name Name.
  323. */
  324. getAttribute(name: string): string;
  325. /**
  326. * Toggle an attribute.
  327. * Returns `true` if attribute name is eventually present, and `false` otherwise.
  328. *
  329. * @param name A DOMString specifying the name of the attribute to be toggled.
  330. * @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.
  331. */
  332. toggleAttribute(name: string, force?: boolean): boolean;
  333. /**
  334. * Returns namespace attribute value.
  335. *
  336. * @param namespace Namespace URI.
  337. * @param localName Local name.
  338. */
  339. getAttributeNS(namespace: string, localName: string): string;
  340. /**
  341. * Returns a boolean value indicating whether the specified element has the attribute or not.
  342. *
  343. * @param name Attribute name.
  344. * @returns True if attribute exists, false otherwise.
  345. */
  346. hasAttribute(name: string): boolean;
  347. /**
  348. * Returns a boolean value indicating whether the specified element has the namespace attribute or not.
  349. *
  350. * @param namespace Namespace URI.
  351. * @param localName Local name.
  352. * @returns True if attribute exists, false otherwise.
  353. */
  354. hasAttributeNS(namespace: string, localName: string): boolean;
  355. /**
  356. * Returns "true" if the element has attributes.
  357. *
  358. * @returns "true" if the element has attributes.
  359. */
  360. hasAttributes(): boolean;
  361. /**
  362. * Removes an attribute.
  363. *
  364. * @param name Name.
  365. */
  366. removeAttribute(name: string): void;
  367. /**
  368. * Removes a namespace attribute.
  369. *
  370. * @param namespace Namespace URI.
  371. * @param localName Local name.
  372. */
  373. removeAttributeNS(namespace: string, localName: string): void;
  374. /**
  375. * Attaches a shadow root.
  376. *
  377. * @param _shadowRootInit Shadow root init.
  378. * @param shadowRootInit
  379. * @param shadowRootInit.mode
  380. * @returns Shadow root.
  381. */
  382. attachShadow(shadowRootInit: {
  383. mode: string;
  384. }): IShadowRoot;
  385. /**
  386. * Converts to string.
  387. *
  388. * @returns String.
  389. */
  390. toString(): string;
  391. /**
  392. * Returns the size of an element and its position relative to the viewport.
  393. *
  394. * @returns DOM rect.
  395. */
  396. getBoundingClientRect(): DOMRect;
  397. /**
  398. * Returns a collection of DOMRect objects that indicate the bounding rectangles for each CSS border box in a client.
  399. *
  400. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getClientRects
  401. * @returns DOM rect list.
  402. */
  403. getClientRects(): IDOMRectList<DOMRect>;
  404. /**
  405. * The matches() method checks to see if the Element would be selected by the provided selectorString.
  406. *
  407. * @param selector Selector.
  408. * @returns "true" if matching.
  409. */
  410. matches(selector: string): boolean;
  411. /**
  412. * Traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string.
  413. *
  414. * @param selector Selector.
  415. * @returns Closest matching element.
  416. */
  417. closest(selector: string): IElement;
  418. /**
  419. * Query CSS selector to find matching nodes.
  420. *
  421. * @param selector CSS selector.
  422. * @returns Matching elements.
  423. */
  424. querySelectorAll(selector: string): INodeList<IElement>;
  425. /**
  426. * Query CSS Selector to find matching node.
  427. *
  428. * @param selector CSS selector.
  429. * @returns Matching element.
  430. */
  431. querySelector(selector: string): IElement;
  432. /**
  433. * Returns an elements by class name.
  434. *
  435. * @param className Tag name.
  436. * @returns Matching element.
  437. */
  438. getElementsByClassName(className: string): IHTMLCollection<IElement>;
  439. /**
  440. * Returns an elements by tag name.
  441. *
  442. * @param tagName Tag name.
  443. * @returns Matching element.
  444. */
  445. getElementsByTagName(tagName: string): IHTMLCollection<IElement>;
  446. /**
  447. * Returns an elements by tag name and namespace.
  448. *
  449. * @param namespaceURI Namespace URI.
  450. * @param tagName Tag name.
  451. * @returns Matching element.
  452. */
  453. getElementsByTagNameNS(namespaceURI: string, tagName: string): IHTMLCollection<IElement>;
  454. /**
  455. * The setAttributeNode() method adds a new Attr node to the specified element.
  456. *
  457. * @param attribute Attribute.
  458. * @returns Replaced attribute.
  459. */
  460. setAttributeNode(attribute: IAttr): IAttr;
  461. /**
  462. * The setAttributeNodeNS() method adds a new Attr node to the specified element.
  463. *
  464. * @param attribute Attribute.
  465. * @returns Replaced attribute.
  466. */
  467. setAttributeNodeNS(attribute: IAttr): IAttr;
  468. /**
  469. * Returns an Attr node.
  470. *
  471. * @param name Name.
  472. * @returns Replaced attribute.
  473. */
  474. getAttributeNode(name: string): IAttr;
  475. /**
  476. * Returns a namespaced Attr node.
  477. *
  478. * @param namespace Namespace.
  479. * @param name Name.
  480. * @returns Replaced attribute.
  481. */
  482. getAttributeNodeNS(namespace: string, name: string): IAttr;
  483. /**
  484. * Removes an Attr node.
  485. *
  486. * @param attribute Attribute.
  487. * @returns Removed attribute.
  488. */
  489. removeAttributeNode(attribute: IAttr): IAttr;
  490. /**
  491. * Removes an Attr node.
  492. *
  493. * @param attribute Attribute.
  494. * @returns Removed attribute.
  495. */
  496. removeAttributeNodeNS(attribute: IAttr): IAttr;
  497. /**
  498. * Scrolls to a particular set of coordinates.
  499. *
  500. * @param x X position or options object.
  501. * @param y Y position.
  502. */
  503. scroll(x: {
  504. top?: number;
  505. left?: number;
  506. behavior?: string;
  507. } | number, y?: number): void;
  508. /**
  509. * Scrolls to a particular set of coordinates.
  510. *
  511. * @param x X position or options object.
  512. * @param y Y position.
  513. */
  514. scrollTo(x: {
  515. top?: number;
  516. left?: number;
  517. behavior?: string;
  518. } | number, y?: number): void;
  519. /**
  520. * Returns attribute name.
  521. *
  522. * @param name Name.
  523. * @returns Attribute name based on namespace.
  524. */
  525. protected _getAttributeName(name: any): string;
  526. }