DisplayObject.d.ts 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. import type { mat3, vec2 } from 'gl-matrix';
  2. import { mat4, quat, vec3 } from 'gl-matrix';
  3. import type { PropertyParseOptions } from '../css';
  4. import type { DisplayObjectConfig, IAnimation, IChildNode } from '../dom';
  5. import { Element } from '../dom';
  6. import type { BaseStyleProps, ParsedBaseStyleProps } from '../types';
  7. export declare function isDisplayObject(value: any): value is DisplayObject;
  8. /**
  9. * prototype chains: DisplayObject -> Element -> Node -> EventTarget
  10. *
  11. * mixins: Animatable, Transformable, Visible
  12. * @see https://github.com/tannerntannern/ts-mixer/blob/master/README.md#mixing-generic-classes
  13. *
  14. * Provide abilities in scene graph, such as:
  15. * * transform `translate/rotate/scale`
  16. * * add/remove child
  17. * * visibility and z-index
  18. *
  19. * Those abilities are implemented with those components: `Transform/Sortable/Visible`.
  20. *
  21. * Emit following events:
  22. * * init
  23. * * destroy
  24. * * attributeChanged
  25. */
  26. export declare class DisplayObject<StyleProps extends BaseStyleProps = any, ParsedStyleProps extends ParsedBaseStyleProps = any> extends Element<StyleProps, ParsedStyleProps> {
  27. /**
  28. * contains style props in constructor's params, eg. fill, stroke...
  29. */
  30. config: DisplayObjectConfig<StyleProps>;
  31. isCustomElement: boolean;
  32. isMutationObserved: boolean;
  33. /**
  34. * push to active animations after calling `animate()`
  35. */
  36. private activeAnimations;
  37. /**
  38. * Use data-* attribute.
  39. * @see https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes
  40. * @example
  41. * group.dataset.prop1 = 1;
  42. * group.getAttribute('data-prop1'); // 1
  43. */
  44. dataset: any;
  45. constructor(config: DisplayObjectConfig<StyleProps>);
  46. destroy(): void;
  47. cloneNode(deep?: boolean, customCloneFunc?: (name: string, attribute: any) => any): this;
  48. private initAttributes;
  49. setAttribute<Key extends keyof StyleProps>(name: Key, value: StyleProps[Key], force?: boolean): void;
  50. /**
  51. * called when attributes get changed or initialized
  52. */
  53. internalSetAttribute<Key extends keyof StyleProps>(name: Key, value: StyleProps[Key], parseOptions?: Partial<PropertyParseOptions>): void;
  54. /**
  55. * returns different values than getBoundingClientRect(), as the latter returns value relative to the viewport
  56. * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGraphicsElement/getBBox
  57. *
  58. * FIXME: It is worth noting that getBBox responds to original untransformed values of a drawn object.
  59. * @see https://www.w3.org/Graphics/SVG/IG/resources/svgprimer.html#getBBox
  60. */
  61. getBBox(): DOMRect;
  62. setOrigin(position: vec3 | vec2 | number, y?: number, z?: number): this;
  63. getOrigin(): vec3;
  64. /**
  65. * set position in world space
  66. */
  67. setPosition(position: vec3 | vec2 | number, y?: number, z?: number): this;
  68. /**
  69. * set position in local space
  70. */
  71. setLocalPosition(position: vec3 | vec2 | number, y?: number, z?: number): this;
  72. /**
  73. * translate in world space
  74. */
  75. translate(position: vec3 | vec2 | number, y?: number, z?: number): this;
  76. /**
  77. * translate in local space
  78. */
  79. translateLocal(position: vec3 | vec2 | number, y?: number, z?: number): this;
  80. getPosition(): vec3;
  81. getLocalPosition(): vec3;
  82. /**
  83. * compatible with G 3.0
  84. *
  85. * scaling in local space
  86. * scale(10) = scale(10, 10, 10)
  87. *
  88. * we can't set scale in world space
  89. */
  90. scale(scaling: vec3 | vec2 | number, y?: number, z?: number): this;
  91. scaleLocal(scaling: vec3 | vec2 | number, y?: number, z?: number): this;
  92. /**
  93. * set scaling in local space
  94. */
  95. setLocalScale(scaling: vec3 | vec2 | number, y?: number, z?: number): this;
  96. /**
  97. * get scaling in local space
  98. */
  99. getLocalScale(): vec3;
  100. /**
  101. * get scaling in world space
  102. */
  103. getScale(): vec3;
  104. /**
  105. * only return degrees of Z axis in world space
  106. */
  107. getEulerAngles(): number;
  108. /**
  109. * only return degrees of Z axis in local space
  110. */
  111. getLocalEulerAngles(): number;
  112. /**
  113. * set euler angles(degrees) in world space
  114. */
  115. setEulerAngles(z: number): this;
  116. /**
  117. * set euler angles(degrees) in local space
  118. */
  119. setLocalEulerAngles(z: number): this;
  120. rotateLocal(x: number, y?: number, z?: number): this;
  121. rotate(x: number, y?: number, z?: number): this;
  122. setRotation(rotation: quat | number, y?: number, z?: number, w?: number): this;
  123. setLocalRotation(rotation: quat | number, y?: number, z?: number, w?: number): this;
  124. setLocalSkew(skew: vec2 | number, y?: number): this;
  125. getRotation(): quat;
  126. getLocalRotation(): quat;
  127. getLocalSkew(): vec2;
  128. getLocalTransform(): mat4;
  129. getWorldTransform(): mat4;
  130. setLocalTransform(transform: mat4): this;
  131. resetLocalTransform(): void;
  132. /**
  133. * returns an array of all Animation objects affecting this element
  134. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAnimations
  135. */
  136. getAnimations(): IAnimation[];
  137. /**
  138. * create an animation with WAAPI
  139. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/animate
  140. */
  141. animate(keyframes: Keyframe[] | PropertyIndexedKeyframes | null, options?: number | KeyframeAnimationOptions | undefined): IAnimation | null;
  142. /**
  143. * shortcut for Used value of `visibility`
  144. */
  145. isVisible(): boolean;
  146. get interactive(): boolean;
  147. set interactive(b: boolean);
  148. isInteractive(): boolean;
  149. isCulled(): boolean;
  150. /**
  151. * bring to front in current group
  152. */
  153. toFront(): this;
  154. /**
  155. * send to back in current group
  156. */
  157. toBack(): this;
  158. /**
  159. * compatible with G 3.0
  160. * @alias object.config
  161. * @deprecated
  162. */
  163. getConfig(): DisplayObjectConfig<StyleProps>;
  164. /**
  165. * @alias style
  166. * @example
  167. * circle.style.r = 10;
  168. * const r = circle.style;
  169. * @deprecated
  170. */
  171. attr(): StyleProps;
  172. attr(name: Partial<StyleProps>): DisplayObject<StyleProps>;
  173. attr<Key extends keyof StyleProps>(name: Key): StyleProps[Key];
  174. attr<Key extends keyof StyleProps>(name: Key, value: StyleProps[Key]): DisplayObject<StyleProps>;
  175. /**
  176. * return 3x3 matrix in world space
  177. * @deprecated
  178. */
  179. getMatrix(transformMat4?: mat4): mat3;
  180. /**
  181. * return 3x3 matrix in local space
  182. * @deprecated
  183. */
  184. getLocalMatrix(): mat3;
  185. /**
  186. * set 3x3 matrix in world space
  187. * @deprecated
  188. */
  189. setMatrix(mat: mat3): void;
  190. /**
  191. * set 3x3 matrix in local space
  192. * @deprecated
  193. */
  194. setLocalMatrix(mat: mat3): void;
  195. /**
  196. * Use `visibility: visible` instead.
  197. * @deprecated
  198. */
  199. show(): void;
  200. /**
  201. * Use `visibility: hidden` instead.
  202. * @deprecated
  203. */
  204. hide(): void;
  205. /**
  206. * Use `childElementCount` instead.
  207. * @deprecated
  208. */
  209. getCount(): number;
  210. /**
  211. * Use `parentElement` instead.
  212. * @deprecated
  213. */
  214. getParent(): DisplayObject | null;
  215. /**
  216. * Use `children` instead.
  217. * @deprecated
  218. */
  219. getChildren(): DisplayObject[];
  220. /**
  221. * Use `firstElementChild` instead.
  222. * @deprecated
  223. */
  224. getFirst(): DisplayObject | null;
  225. /**
  226. * Use `lastElementChild` instead.
  227. * @deprecated
  228. */
  229. getLast(): DisplayObject | null;
  230. /**
  231. * Use `this.children[index]` instead.
  232. * @deprecated
  233. */
  234. getChildByIndex(index: number): DisplayObject | null;
  235. /**
  236. * Use `appendChild` instead.
  237. * @deprecated
  238. */
  239. add<T extends IChildNode>(child: T, index?: number): T;
  240. /**
  241. * Use `this.style.clipPath` instead.
  242. * @deprecated
  243. */
  244. setClip(clipPath: DisplayObject | null): void;
  245. /**
  246. * Use `this.style.clipPath` instead.
  247. * @deprecated
  248. */
  249. getClip: () => any;
  250. /**
  251. * @deprecated
  252. */
  253. set<StyleProps extends BaseStyleProps, Key extends keyof DisplayObjectConfig<StyleProps>>(name: Key, value: DisplayObjectConfig<StyleProps>[Key]): void;
  254. /**
  255. * @deprecated
  256. */
  257. get<StyleProps extends BaseStyleProps>(name: keyof DisplayObjectConfig<StyleProps>): any;
  258. /**
  259. * Use `setPosition` instead.
  260. * @deprecated
  261. */
  262. moveTo(position: vec3 | vec2 | number, y?: number, z?: number): this;
  263. /**
  264. * Use `setPosition` instead.
  265. * @deprecated
  266. */
  267. move(position: vec3 | vec2 | number, y?: number, z?: number): this;
  268. /**
  269. * Use `this.style.zIndex` instead.
  270. * @deprecated
  271. */
  272. setZIndex(zIndex: number): this;
  273. }
  274. //# sourceMappingURL=DisplayObject.d.ts.map