Element.d.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. import type { Cullable, Geometry, RBushNode, Renderable, Sortable, Transform } from '../components';
  2. import type { AABB, Rectangle } from '../shapes';
  3. import type { BaseStyleProps, ParsedBaseStyleProps } from '../types';
  4. import type { ICSSStyleDeclaration, IElement, IEventTarget, INode } from './interfaces';
  5. import { Node } from './Node';
  6. export declare function resetEntityCounter(): void;
  7. /**
  8. * Has following capabilities:
  9. * * Node insert/remove, eg. appendChild, removeChild, remove...
  10. * * Query eg. querySelector getElementById...
  11. * * Animation
  12. */
  13. export declare class Element<StyleProps extends BaseStyleProps = any, ParsedStyleProps extends ParsedBaseStyleProps = any> extends Node implements IElement<StyleProps, ParsedStyleProps> {
  14. static isElement(target: IEventTarget | INode | IElement): target is IElement;
  15. /**
  16. * Unique id.
  17. */
  18. entity: number;
  19. renderable: Renderable;
  20. cullable: Cullable;
  21. transformable: Transform;
  22. sortable: Sortable;
  23. geometry: Geometry;
  24. rBushNode: RBushNode;
  25. /**
  26. * used with `getElementById()`
  27. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/id
  28. */
  29. id: string;
  30. /**
  31. * used in `getElementsByClassName`
  32. * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName
  33. */
  34. get className(): string;
  35. set className(className: string);
  36. /**
  37. * used in `getElementsByName`
  38. * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByName
  39. */
  40. name: string;
  41. /**
  42. * https://developer.mozilla.org/zh-CN/docs/Web/API/Element/namespaceURI
  43. */
  44. namespaceURI: string;
  45. /**
  46. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/classList
  47. */
  48. get classList(): string[];
  49. scrollLeft: number;
  50. scrollTop: number;
  51. /**
  52. * We don't support border now
  53. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/clientTop
  54. */
  55. clientTop: number;
  56. clientLeft: number;
  57. get tagName(): string;
  58. get children(): IElement[];
  59. get childElementCount(): number;
  60. get firstElementChild(): IElement | null;
  61. get lastElementChild(): IElement | null;
  62. get parentElement(): IElement | null;
  63. get nextSibling(): IElement | null;
  64. get previousSibling(): IElement | null;
  65. cloneNode(deep?: boolean): this;
  66. appendChild<T extends INode>(child: T, index?: number): T;
  67. insertBefore<T extends INode>(newChild: T, refChild: INode | null): T;
  68. replaceChild<T extends INode>(newChild: INode, oldChild: T): T;
  69. removeChild<T extends INode>(child: T): T;
  70. /**
  71. * Remove all children which can be appended to its original parent later again.
  72. */
  73. removeChildren(): void;
  74. /**
  75. * Recursively destroy all children which can not be appended to its original parent later again.
  76. */
  77. destroyChildren(): void;
  78. /**
  79. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/matches
  80. */
  81. matches(selector: string): boolean;
  82. getElementById<E extends IElement = IElement>(id: string): E | null;
  83. getElementsByName<E extends IElement = IElement>(name: string): E[];
  84. getElementsByClassName<E extends IElement = IElement>(className: string): E[];
  85. getElementsByTagName<E extends IElement = IElement>(tagName: string): E[];
  86. querySelector<E extends IElement = IElement>(selectors: string): E | null;
  87. querySelectorAll<E extends IElement = IElement>(selectors: string): E[];
  88. /**
  89. * should traverses the element and its parents (heading toward the document root)
  90. * until it finds a node that matches the specified CSS selector.
  91. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/closest
  92. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#polyfill
  93. */
  94. closest<E extends IElement = IElement>(selectors: string): E | null;
  95. /**
  96. * search in scene group, but should not include itself
  97. */
  98. find<E extends IElement = IElement>(filter: (node: E) => boolean): E | null;
  99. findAll<E extends IElement = IElement>(filter: (node: E) => boolean): E[];
  100. /**
  101. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/after
  102. */
  103. after(...nodes: INode[]): void;
  104. /**
  105. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/before
  106. */
  107. before(...nodes: INode[]): void;
  108. /**
  109. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/replaceWith
  110. */
  111. replaceWith(...nodes: INode[]): void;
  112. /**
  113. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/append
  114. */
  115. append(...nodes: INode[]): void;
  116. /**
  117. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/prepend
  118. */
  119. prepend(...nodes: INode[]): void;
  120. /**
  121. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/replaceChildren
  122. */
  123. replaceChildren(...nodes: INode[]): void;
  124. /**
  125. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/remove
  126. */
  127. remove(): this;
  128. /**
  129. * is destroyed or not
  130. */
  131. destroyed: boolean;
  132. destroy(): void;
  133. getGeometryBounds(): AABB;
  134. getRenderBounds(): AABB;
  135. /**
  136. * get bounds in world space, account for children
  137. */
  138. getBounds(): AABB;
  139. /**
  140. * get bounds in local space, account for children
  141. */
  142. getLocalBounds(): AABB;
  143. /**
  144. * account for context's bounds in client space,
  145. * but not accounting for children
  146. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect
  147. */
  148. getBoundingClientRect(): Rectangle;
  149. /**
  150. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/getClientRects
  151. */
  152. getClientRects(): Rectangle[];
  153. /**
  154. * compatible with `style`
  155. * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style
  156. */
  157. style: StyleProps & ICSSStyleDeclaration<StyleProps>;
  158. computedStyle: any;
  159. /**
  160. * Renderers will use these used values.
  161. */
  162. parsedStyle: ParsedStyleProps;
  163. /**
  164. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/computedStyleMap
  165. * eg. circle.computedStyleMap().get('fill');
  166. */
  167. computedStyleMap(): Map<string, unknown>;
  168. /**
  169. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/attributes
  170. */
  171. readonly attributes: StyleProps;
  172. /**
  173. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttributeNames
  174. */
  175. getAttributeNames(): string[];
  176. /**
  177. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute
  178. */
  179. getAttribute(name: keyof StyleProps): StyleProps[keyof StyleProps];
  180. /**
  181. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttribute
  182. */
  183. hasAttribute(qualifiedName: string): boolean;
  184. /**
  185. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttributes
  186. */
  187. hasAttributes(): boolean;
  188. /**
  189. * should use removeAttribute() instead of setting the attribute value to null either directly or using setAttribute(). Many attributes will not behave as expected if you set them to null.
  190. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute
  191. */
  192. removeAttribute(attributeName: keyof StyleProps): void;
  193. /**
  194. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute
  195. */
  196. setAttribute<Key extends keyof StyleProps>(attributeName: Key, value: StyleProps[Key], force?: boolean): void;
  197. getAttributeNS(namespace: string, localName: string): string;
  198. getAttributeNode(qualifiedName: string): Attr;
  199. getAttributeNodeNS(namespace: string, localName: string): Attr;
  200. hasAttributeNS(namespace: string, localName: string): boolean;
  201. removeAttributeNS(namespace: string, localName: string): void;
  202. removeAttributeNode(attr: Attr): Attr;
  203. setAttributeNS(namespace: string, qualifiedName: string, value: string): void;
  204. setAttributeNode(attr: Attr): Attr;
  205. setAttributeNodeNS(attr: Attr): Attr;
  206. toggleAttribute(qualifiedName: string, force?: boolean): boolean;
  207. }
  208. //# sourceMappingURL=Element.d.ts.map