@antv/g 1.0.0-alpha.20 → 1.0.0-alpha.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (293) hide show
  1. package/es/Canvas.d.ts +40 -18
  2. package/es/Canvas.js +121 -65
  3. package/es/DisplayObjectPool.d.ts +2 -1
  4. package/es/DisplayObjectPool.js +4 -0
  5. package/{lib → es/camera}/Camera.d.ts +6 -3
  6. package/es/{Camera.js → camera/Camera.js} +22 -16
  7. package/es/{Landmark.d.ts → camera/Landmark.d.ts} +2 -2
  8. package/es/{Landmark.js → camera/Landmark.js} +1 -1
  9. package/es/camera/index.d.ts +2 -0
  10. package/es/camera/index.js +2 -0
  11. package/es/components/Cullable.js +1 -1
  12. package/es/components/Geometry.d.ts +8 -1
  13. package/es/components/Renderable.d.ts +9 -8
  14. package/es/components/Renderable.js +2 -6
  15. package/es/components/Sortable.d.ts +6 -2
  16. package/es/display-objects/Circle.d.ts +2 -3
  17. package/es/display-objects/Circle.js +2 -5
  18. package/es/{CustomElement.d.ts → display-objects/CustomElement.d.ts} +1 -1
  19. package/es/{CustomElement.js → display-objects/CustomElement.js} +22 -12
  20. package/{lib → es/display-objects}/DisplayObject.d.ts +136 -141
  21. package/es/{DisplayObject.js → display-objects/DisplayObject.js} +408 -292
  22. package/es/display-objects/Ellipse.d.ts +2 -3
  23. package/es/display-objects/Ellipse.js +2 -5
  24. package/es/display-objects/Group.d.ts +2 -1
  25. package/es/display-objects/Group.js +13 -5
  26. package/es/display-objects/HTML.d.ts +2 -2
  27. package/es/display-objects/HTML.js +4 -7
  28. package/es/display-objects/Image.d.ts +2 -2
  29. package/es/display-objects/Image.js +2 -6
  30. package/es/display-objects/Line.d.ts +2 -2
  31. package/es/display-objects/Line.js +8 -8
  32. package/es/display-objects/Path.d.ts +3 -2
  33. package/es/display-objects/Path.js +8 -8
  34. package/es/display-objects/Polygon.d.ts +2 -2
  35. package/es/display-objects/Polygon.js +2 -6
  36. package/es/display-objects/Polyline.d.ts +2 -2
  37. package/es/display-objects/Polyline.js +8 -8
  38. package/es/display-objects/Rect.d.ts +2 -2
  39. package/es/display-objects/Rect.js +2 -6
  40. package/es/display-objects/Text.d.ts +2 -3
  41. package/es/display-objects/Text.js +8 -7
  42. package/es/display-objects/index.d.ts +2 -0
  43. package/es/display-objects/index.js +2 -0
  44. package/es/{Animation.d.ts → dom/Animation.d.ts} +3 -3
  45. package/es/{Animation.js → dom/Animation.js} +2 -3
  46. package/{lib → es/dom}/AnimationEffectTiming.d.ts +2 -0
  47. package/es/{AnimationEffectTiming.js → dom/AnimationEffectTiming.js} +3 -2
  48. package/es/{AnimationEvent.d.ts → dom/AnimationEvent.d.ts} +3 -2
  49. package/es/{AnimationEvent.js → dom/AnimationEvent.js} +1 -1
  50. package/es/{Timeline.d.ts → dom/AnimationTimeline.d.ts} +1 -1
  51. package/es/{Timeline.js → dom/AnimationTimeline.js} +1 -1
  52. package/es/dom/CustomElementRegistry.d.ts +15 -0
  53. package/es/dom/CustomElementRegistry.js +40 -0
  54. package/{lib → es/dom}/CustomEvent.d.ts +1 -1
  55. package/es/{CustomEvent.js → dom/CustomEvent.js} +1 -1
  56. package/es/dom/Document.d.ts +36 -17
  57. package/es/dom/Document.js +98 -14
  58. package/es/dom/Element.d.ts +71 -92
  59. package/es/dom/Element.js +179 -195
  60. package/es/dom/EventTarget.d.ts +11 -6
  61. package/es/dom/EventTarget.js +12 -4
  62. package/es/dom/FederatedEvent.d.ts +15 -7
  63. package/es/dom/FederatedEvent.js +33 -0
  64. package/es/dom/FederatedMouseEvent.d.ts +1 -1
  65. package/es/{KeyframeEffect.d.ts → dom/KeyframeEffect.d.ts} +16 -5
  66. package/es/{KeyframeEffect.js → dom/KeyframeEffect.js} +50 -4
  67. package/es/{KeyframeList.d.ts → dom/KeyframeList.d.ts} +1 -1
  68. package/es/{KeyframeList.js → dom/KeyframeList.js} +0 -0
  69. package/es/dom/Node.d.ts +38 -23
  70. package/es/dom/Node.js +37 -33
  71. package/es/dom/index.d.ts +15 -2
  72. package/es/dom/index.js +16 -3
  73. package/es/dom/interfaces.d.ts +301 -0
  74. package/es/dom/interfaces.js +1 -0
  75. package/es/global-module.d.ts +0 -2
  76. package/es/global-module.js +31 -29
  77. package/es/index.d.ts +7 -14
  78. package/es/index.js +8 -15
  79. package/es/plugins/CullingPlugin.d.ts +2 -2
  80. package/es/plugins/CullingPlugin.js +13 -16
  81. package/es/plugins/DirtyCheckPlugin.d.ts +1 -1
  82. package/es/plugins/DirtyCheckPlugin.js +8 -7
  83. package/es/plugins/EventPlugin.js +52 -31
  84. package/es/plugins/FrustumCullingStrategy.d.ts +1 -1
  85. package/es/plugins/FrustumCullingStrategy.js +5 -4
  86. package/es/plugins/PrepareRendererPlugin.d.ts +0 -1
  87. package/es/plugins/PrepareRendererPlugin.js +42 -38
  88. package/es/property-handlers/aabb.d.ts +2 -3
  89. package/es/property-handlers/aabb.js +29 -21
  90. package/es/property-handlers/anchor.d.ts +3 -0
  91. package/es/property-handlers/anchor.js +21 -0
  92. package/es/property-handlers/clipPath.d.ts +1 -1
  93. package/es/property-handlers/clipPath.js +3 -4
  94. package/es/property-handlers/color.d.ts +1 -1
  95. package/es/property-handlers/dimension.d.ts +1 -1
  96. package/es/property-handlers/dimension.js +6 -9
  97. package/es/property-handlers/filter.d.ts +1 -1
  98. package/es/property-handlers/index.d.ts +5 -4
  99. package/es/property-handlers/index.js +1 -0
  100. package/es/property-handlers/localPosition.d.ts +1 -1
  101. package/es/property-handlers/localPosition.js +1 -6
  102. package/es/property-handlers/offsetDistance.d.ts +1 -1
  103. package/es/property-handlers/offsetPath.d.ts +1 -1
  104. package/es/property-handlers/origin.d.ts +1 -1
  105. package/es/property-handlers/origin.js +9 -2
  106. package/es/property-handlers/path.d.ts +2 -2
  107. package/es/property-handlers/path.js +8 -4
  108. package/es/property-handlers/points.d.ts +1 -1
  109. package/es/property-handlers/transform.d.ts +1 -1
  110. package/es/property-handlers/zIndex.d.ts +1 -1
  111. package/es/services/ContextService.d.ts +3 -2
  112. package/es/services/EventService.d.ts +18 -13
  113. package/es/services/EventService.js +604 -384
  114. package/es/services/RenderingContext.d.ts +1 -1
  115. package/es/services/RenderingService.d.ts +23 -29
  116. package/es/services/RenderingService.js +63 -54
  117. package/es/services/SceneGraphSelector.d.ts +7 -7
  118. package/es/services/SceneGraphSelector.js +10 -6
  119. package/es/services/SceneGraphService.d.ts +73 -78
  120. package/es/services/SceneGraphService.js +165 -78
  121. package/es/services/aabb/PathUpdater.d.ts +1 -1
  122. package/es/services/aabb/RectUpdater.d.ts +2 -2
  123. package/es/services/aabb/interfaces.d.ts +1 -1
  124. package/es/shapes/Point.d.ts +4 -0
  125. package/es/shapes/Polygon.d.ts +9 -0
  126. package/es/shapes/Polygon.js +62 -0
  127. package/es/shapes/index.d.ts +1 -0
  128. package/es/shapes/index.js +2 -1
  129. package/es/types.d.ts +18 -6
  130. package/es/utils/animation.d.ts +1 -2
  131. package/es/utils/animation.js +5 -10
  132. package/es/utils/canvas.d.ts +1 -1
  133. package/es/utils/custom-easing.d.ts +3 -2
  134. package/es/utils/custom-easing.js +12 -6
  135. package/es/utils/event.js +1 -1
  136. package/es/utils/index.d.ts +1 -0
  137. package/es/utils/index.js +2 -1
  138. package/es/utils/interpolation.d.ts +3 -4
  139. package/es/utils/interpolation.js +0 -16
  140. package/es/utils/path.d.ts +2 -2
  141. package/lib/Canvas.d.ts +40 -18
  142. package/lib/Canvas.js +131 -74
  143. package/lib/DisplayObjectPool.d.ts +2 -1
  144. package/lib/DisplayObjectPool.js +4 -0
  145. package/{es → lib/camera}/Camera.d.ts +6 -3
  146. package/lib/{Camera.js → camera/Camera.js} +25 -20
  147. package/lib/{Landmark.d.ts → camera/Landmark.d.ts} +2 -2
  148. package/lib/{Landmark.js → camera/Landmark.js} +2 -3
  149. package/lib/camera/index.d.ts +2 -0
  150. package/lib/camera/index.js +31 -0
  151. package/lib/components/Cullable.js +1 -1
  152. package/lib/components/Geometry.d.ts +8 -1
  153. package/lib/components/Renderable.d.ts +9 -8
  154. package/lib/components/Renderable.js +2 -6
  155. package/lib/components/Sortable.d.ts +6 -2
  156. package/lib/display-objects/Circle.d.ts +2 -3
  157. package/lib/display-objects/Circle.js +3 -6
  158. package/lib/{CustomElement.d.ts → display-objects/CustomElement.d.ts} +1 -1
  159. package/lib/{CustomElement.js → display-objects/CustomElement.js} +22 -12
  160. package/{es → lib/display-objects}/DisplayObject.d.ts +136 -141
  161. package/lib/{DisplayObject.js → display-objects/DisplayObject.js} +418 -299
  162. package/lib/display-objects/Ellipse.d.ts +2 -3
  163. package/lib/display-objects/Ellipse.js +3 -6
  164. package/lib/display-objects/Group.d.ts +2 -1
  165. package/lib/display-objects/Group.js +12 -4
  166. package/lib/display-objects/HTML.d.ts +2 -2
  167. package/lib/display-objects/HTML.js +4 -7
  168. package/lib/display-objects/Image.d.ts +2 -2
  169. package/lib/display-objects/Image.js +2 -6
  170. package/lib/display-objects/Line.d.ts +2 -2
  171. package/lib/display-objects/Line.js +8 -8
  172. package/lib/display-objects/Path.d.ts +3 -2
  173. package/lib/display-objects/Path.js +8 -8
  174. package/lib/display-objects/Polygon.d.ts +2 -2
  175. package/lib/display-objects/Polygon.js +2 -6
  176. package/lib/display-objects/Polyline.d.ts +2 -2
  177. package/lib/display-objects/Polyline.js +8 -8
  178. package/lib/display-objects/Rect.d.ts +2 -2
  179. package/lib/display-objects/Rect.js +2 -6
  180. package/lib/display-objects/Text.d.ts +2 -3
  181. package/lib/display-objects/Text.js +9 -8
  182. package/lib/display-objects/index.d.ts +2 -0
  183. package/lib/display-objects/index.js +26 -0
  184. package/lib/{Animation.d.ts → dom/Animation.d.ts} +3 -3
  185. package/lib/{Animation.js → dom/Animation.js} +2 -3
  186. package/{es → lib/dom}/AnimationEffectTiming.d.ts +2 -0
  187. package/lib/{AnimationEffectTiming.js → dom/AnimationEffectTiming.js} +3 -3
  188. package/lib/{AnimationEvent.d.ts → dom/AnimationEvent.d.ts} +3 -2
  189. package/lib/{AnimationEvent.js → dom/AnimationEvent.js} +1 -1
  190. package/lib/{Timeline.d.ts → dom/AnimationTimeline.d.ts} +1 -1
  191. package/lib/{Timeline.js → dom/AnimationTimeline.js} +1 -1
  192. package/lib/dom/CustomElementRegistry.d.ts +15 -0
  193. package/lib/dom/CustomElementRegistry.js +48 -0
  194. package/{es → lib/dom}/CustomEvent.d.ts +1 -1
  195. package/lib/{CustomEvent.js → dom/CustomEvent.js} +1 -1
  196. package/lib/dom/Document.d.ts +36 -17
  197. package/lib/dom/Document.js +99 -15
  198. package/lib/dom/Element.d.ts +71 -92
  199. package/lib/dom/Element.js +180 -198
  200. package/lib/dom/EventTarget.d.ts +11 -6
  201. package/lib/dom/EventTarget.js +20 -10
  202. package/lib/dom/FederatedEvent.d.ts +15 -7
  203. package/lib/dom/FederatedEvent.js +33 -0
  204. package/lib/dom/FederatedMouseEvent.d.ts +1 -1
  205. package/lib/{KeyframeEffect.d.ts → dom/KeyframeEffect.d.ts} +16 -5
  206. package/lib/{KeyframeEffect.js → dom/KeyframeEffect.js} +50 -4
  207. package/lib/{KeyframeList.d.ts → dom/KeyframeList.d.ts} +1 -1
  208. package/lib/{KeyframeList.js → dom/KeyframeList.js} +0 -0
  209. package/lib/dom/Node.d.ts +38 -23
  210. package/lib/dom/Node.js +37 -33
  211. package/lib/dom/index.d.ts +15 -2
  212. package/lib/dom/index.js +177 -8
  213. package/lib/dom/interfaces.d.ts +301 -0
  214. package/lib/dom/interfaces.js +5 -0
  215. package/lib/global-module.d.ts +0 -2
  216. package/lib/global-module.js +30 -30
  217. package/lib/index.d.ts +7 -14
  218. package/lib/index.js +44 -135
  219. package/lib/plugins/CullingPlugin.d.ts +2 -2
  220. package/lib/plugins/CullingPlugin.js +14 -16
  221. package/lib/plugins/DirtyCheckPlugin.d.ts +1 -1
  222. package/lib/plugins/DirtyCheckPlugin.js +9 -7
  223. package/lib/plugins/EventPlugin.js +52 -30
  224. package/lib/plugins/FrustumCullingStrategy.d.ts +1 -1
  225. package/lib/plugins/FrustumCullingStrategy.js +5 -4
  226. package/lib/plugins/PrepareRendererPlugin.d.ts +0 -1
  227. package/lib/plugins/PrepareRendererPlugin.js +41 -37
  228. package/lib/property-handlers/aabb.d.ts +2 -3
  229. package/lib/property-handlers/aabb.js +28 -22
  230. package/lib/property-handlers/anchor.d.ts +3 -0
  231. package/lib/property-handlers/anchor.js +34 -0
  232. package/lib/property-handlers/clipPath.d.ts +1 -1
  233. package/lib/property-handlers/clipPath.js +3 -4
  234. package/lib/property-handlers/color.d.ts +1 -1
  235. package/lib/property-handlers/dimension.d.ts +1 -1
  236. package/lib/property-handlers/dimension.js +6 -9
  237. package/lib/property-handlers/filter.d.ts +1 -1
  238. package/lib/property-handlers/index.d.ts +5 -4
  239. package/lib/property-handlers/index.js +14 -0
  240. package/lib/property-handlers/localPosition.d.ts +1 -1
  241. package/lib/property-handlers/localPosition.js +1 -7
  242. package/lib/property-handlers/offsetDistance.d.ts +1 -1
  243. package/lib/property-handlers/offsetPath.d.ts +1 -1
  244. package/lib/property-handlers/origin.d.ts +1 -1
  245. package/lib/property-handlers/origin.js +10 -2
  246. package/lib/property-handlers/path.d.ts +2 -2
  247. package/lib/property-handlers/path.js +8 -4
  248. package/lib/property-handlers/points.d.ts +1 -1
  249. package/lib/property-handlers/transform.d.ts +1 -1
  250. package/lib/property-handlers/zIndex.d.ts +1 -1
  251. package/lib/services/ContextService.d.ts +3 -2
  252. package/lib/services/EventService.d.ts +18 -13
  253. package/lib/services/EventService.js +616 -385
  254. package/lib/services/RenderingContext.d.ts +1 -1
  255. package/lib/services/RenderingService.d.ts +23 -29
  256. package/lib/services/RenderingService.js +66 -56
  257. package/lib/services/SceneGraphSelector.d.ts +7 -7
  258. package/lib/services/SceneGraphSelector.js +10 -6
  259. package/lib/services/SceneGraphService.d.ts +73 -78
  260. package/lib/services/SceneGraphService.js +166 -79
  261. package/lib/services/aabb/PathUpdater.d.ts +1 -1
  262. package/lib/services/aabb/RectUpdater.d.ts +2 -2
  263. package/lib/services/aabb/interfaces.d.ts +1 -1
  264. package/lib/shapes/Point.d.ts +4 -0
  265. package/lib/shapes/Polygon.d.ts +9 -0
  266. package/lib/shapes/Polygon.js +69 -0
  267. package/lib/shapes/index.d.ts +1 -0
  268. package/lib/shapes/index.js +13 -0
  269. package/lib/types.d.ts +18 -6
  270. package/lib/utils/animation.d.ts +1 -2
  271. package/lib/utils/animation.js +8 -16
  272. package/lib/utils/canvas.d.ts +1 -1
  273. package/lib/utils/custom-easing.d.ts +3 -2
  274. package/lib/utils/custom-easing.js +16 -8
  275. package/lib/utils/event.js +1 -1
  276. package/lib/utils/index.d.ts +1 -0
  277. package/lib/utils/index.js +13 -0
  278. package/lib/utils/interpolation.d.ts +3 -4
  279. package/lib/utils/interpolation.js +0 -17
  280. package/lib/utils/path.d.ts +2 -2
  281. package/package.json +6 -6
  282. package/es/Batch.d.ts +0 -25
  283. package/es/Batch.js +0 -82
  284. package/es/shapes-type.d.ts +0 -175
  285. package/es/shapes-type.js +0 -18
  286. package/es/utils/matrix-decompose.d.ts +0 -3
  287. package/es/utils/matrix-decompose.js +0 -404
  288. package/lib/Batch.d.ts +0 -25
  289. package/lib/Batch.js +0 -91
  290. package/lib/shapes-type.d.ts +0 -175
  291. package/lib/shapes-type.js +0 -41
  292. package/lib/utils/matrix-decompose.d.ts +0 -3
  293. package/lib/utils/matrix-decompose.js +0 -414
@@ -1,16 +1,26 @@
1
1
  import { __assign, __extends, __read, __spreadArray } from "tslib";
2
- import { isObject, isNil } from '@antv/util';
3
- import { vec3, mat4, quat } from 'gl-matrix';
4
- import { Cullable, Renderable, Transform } from './components';
5
- import { createVec3, rad2deg, getEuler, fromRotationTranslationScale } from './utils/math';
6
- import { SHAPE } from './types';
7
- import { DisplayObjectPool } from './DisplayObjectPool';
8
- import { container } from './inversify.config';
9
- import { StylePropertyUpdaterFactory, StylePropertyParserFactory } from './property-handlers';
10
- import { DISPLAY_OBJECT_EVENT, Element } from './dom/Element';
2
+ import { isEqual, isNil, isObject } from '@antv/util';
3
+ import { mat4, quat, vec3 } from 'gl-matrix';
4
+ import { DisplayObjectPool } from '../DisplayObjectPool';
5
+ import { Element, ElementEvent, KeyframeEffect } from '../dom';
6
+ import { container, SHAPE } from '..';
7
+ import { createVec3, fromRotationTranslationScale, getEuler, rad2deg } from '../utils';
8
+ import { Cullable, Renderable } from '../components';
9
+ import { StylePropertyParserFactory, StylePropertyUpdaterFactory } from '../property-handlers';
10
+ import { dirtifyRenderable } from '../services';
11
+ var DEFAULT_STYLE_PROPS = {
12
+ anchor: [0, 0, 0],
13
+ origin: [0, 0, 0],
14
+ opacity: 1,
15
+ fillOpacity: 1,
16
+ strokeOpacity: 1
17
+ };
11
18
  /**
12
19
  * prototype chains: DisplayObject -> Element -> Node -> EventTarget
13
20
  *
21
+ * mixins: Animatable, Transformable, Visible
22
+ * @see https://github.com/tannerntannern/ts-mixer/blob/master/README.md#mixing-generic-classes
23
+ *
14
24
  * Provide abilities in scene graph, such as:
15
25
  * * transform `translate/rotate/scale`
16
26
  * * add/remove child
@@ -30,27 +40,18 @@ var DisplayObject = function (_super) {
30
40
  function DisplayObject(config) {
31
41
  var _a, _b, _c;
32
42
 
33
- var _this = _super.call(this) || this;
34
-
35
- _this.shadow = false;
36
- _this.displayObjectPool = container.get(DisplayObjectPool);
37
- _this.stylePropertyUpdaterFactory = container.get(StylePropertyUpdaterFactory);
38
- _this.stylePropertyParserFactory = container.get(StylePropertyParserFactory);
39
- /** scene graph operations */
40
-
41
- _this.scrollLeft = 0;
42
- _this.scrollTop = 0;
43
+ var _this = _super.call(this, config) || this;
43
44
  /**
44
- * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset
45
+ * push to active animations after calling `animate()`
45
46
  */
46
47
 
47
- _this.dataset = {}; // assign name, id to config
48
- // eg. group.get('name')
49
-
50
- _this.config = config; // insert this group into pool
51
48
 
52
- _this.displayObjectPool.add(_this.entity.getName(), _this); // compatible with G 3.0
49
+ _this.activeAnimations = [];
50
+ _this.stylePropertyUpdaterFactory = container.get(StylePropertyUpdaterFactory);
51
+ _this.stylePropertyParserFactory = container.get(StylePropertyParserFactory); // assign name, id to config
52
+ // eg. group.get('name')
53
53
 
54
+ _this.config = config; // compatible with G 3.0
54
55
 
55
56
  _this.config.interactive = (_a = _this.config.capture) !== null && _a !== void 0 ? _a : _this.config.interactive; // init scene graph node
56
57
 
@@ -58,14 +59,12 @@ var DisplayObject = function (_super) {
58
59
  _this.name = _this.config.name || '';
59
60
  _this.className = _this.config.className || '';
60
61
  _this.interactive = (_b = _this.config.interactive) !== null && _b !== void 0 ? _b : true;
61
- _this.nodeName = _this.config.type || SHAPE.Group;
62
- _this.attributes; // compatible with G 3.0
63
- // @ts-ignore
62
+ _this.nodeName = _this.config.type || SHAPE.Group; // compatible with G 3.0
64
63
 
65
- _this.config.style = __assign(__assign({
64
+ _this.config.style = __assign(__assign(__assign(__assign({}, DEFAULT_STYLE_PROPS), {
66
65
  zIndex: (_c = _this.config.zIndex) !== null && _c !== void 0 ? _c : 0,
67
66
  visibility: _this.config.visible === false ? 'hidden' : 'visible'
68
- }, _this.config.style), _this.config.attrs);
67
+ }), _this.config.style), _this.config.attrs);
69
68
  _this.style = new Proxy(_this.attributes, {
70
69
  get: function get(_, prop) {
71
70
  return _this.getAttribute(prop);
@@ -77,179 +76,170 @@ var DisplayObject = function (_super) {
77
76
  }
78
77
  });
79
78
 
80
- _this.initAttributes(_this.config.style);
79
+ _this.initAttributes(_this.config.style); // insert this group into pool
81
80
 
82
- _this.on(DISPLAY_OBJECT_EVENT.ChildInserted, function (child) {
83
- // when appending to document
84
- if (_this.ownerDocument && _this.ownerDocument.documentElement === _this && _this.ownerDocument.defaultView) {
85
- _this.ownerDocument.defaultView.decorate(child, _this.ownerDocument.defaultView.getRenderingService(), _this);
86
- }
87
- });
88
81
 
82
+ container.get(DisplayObjectPool).add(_this.entity.getName(), _this);
89
83
  return _this;
90
84
  }
91
- /**
92
- * compatible with G 3.0
93
- * @deprecated
94
- */
95
85
 
86
+ DisplayObject.prototype.destroy = function () {
87
+ _super.prototype.destroy.call(this); // remove from into pool
96
88
 
97
- DisplayObject.prototype.set = function (name, value) {
98
- this.config[name] = value;
99
- };
100
89
 
101
- DisplayObject.prototype.get = function (name) {
102
- return this.config[name];
103
- };
90
+ container.get(DisplayObjectPool).remove(this.entity.getName()); // stop all active animations
104
91
 
105
- DisplayObject.prototype.getConfig = function () {
106
- return this.config;
92
+ this.getAnimations().forEach(function (animation) {
93
+ animation.cancel();
94
+ });
107
95
  };
108
96
 
109
- DisplayObject.prototype.attr = function () {
110
- var _this = this;
111
-
112
- var args = [];
97
+ DisplayObject.prototype.cloneNode = function (deep) {
98
+ var cloned = new this.constructor({
99
+ // copy id & name
100
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/Node/cloneNode#notes
101
+ id: this.id,
102
+ name: this.name,
103
+ className: this.name,
104
+ interactive: this.interactive,
105
+ style: __assign({}, this.style)
106
+ });
113
107
 
114
- for (var _i = 0; _i < arguments.length; _i++) {
115
- args[_i] = arguments[_i];
108
+ if (deep) {
109
+ this.children.forEach(function (child) {
110
+ var clonedChild = child.cloneNode(deep);
111
+ cloned.appendChild(clonedChild);
112
+ });
116
113
  }
117
114
 
118
- var _a = __read(args, 2),
119
- name = _a[0],
120
- value = _a[1];
115
+ return cloned;
116
+ };
121
117
 
122
- if (!name) {
123
- return this.attributes;
124
- }
118
+ DisplayObject.prototype.initAttributes = function (attributes) {
119
+ var _this = this;
125
120
 
126
- if (isObject(name)) {
127
- Object.keys(name).forEach(function (key) {
128
- _this.setAttribute(key, name[key]);
129
- });
130
- return this;
121
+ if (attributes === void 0) {
122
+ attributes = {};
131
123
  }
132
124
 
133
- if (args.length === 2) {
134
- this.setAttribute(name, value);
135
- return this;
136
- }
125
+ var renderable = this.entity.getComponent(Renderable); // parse attributes first
137
126
 
138
- return this.attributes[name];
139
- };
140
- /**
141
- * @deprecated
142
- * compatible with G 3.0
143
- * @deprecated
144
- */
127
+ for (var attributeName in attributes) {
128
+ var value = attributes[attributeName];
129
+ this.attributes[attributeName] = value; // @ts-ignore
145
130
 
131
+ this.parseStyleProperty(attributeName, value);
132
+ }
146
133
 
147
- DisplayObject.prototype.getCount = function () {
148
- return this.childElementCount;
149
- };
150
- /**
151
- * @deprecated
152
- * compatible with G 3.0
153
- * @deprecated
154
- */
134
+ var priorities = {
135
+ x: 1000,
136
+ y: 1000
137
+ }; // update x, y at last
155
138
 
139
+ var sortedNames = Object.keys(attributes).sort(function (a, b) {
140
+ return (priorities[a] || 0) - (priorities[b] || 0);
141
+ });
142
+ sortedNames.forEach(function (attributeName) {
143
+ // @ts-ignore
144
+ _this.updateStyleProperty(attributeName, undefined, _this.parsedStyle[attributeName]);
145
+ }); // redraw at next frame
156
146
 
157
- DisplayObject.prototype.getParent = function () {
158
- return this.parentNode;
147
+ renderable.dirty = true;
159
148
  };
160
- /**
161
- * @deprecated
162
- * compatible with G 3.0
163
- * @deprecated
164
- */
165
149
 
150
+ DisplayObject.prototype.setAttribute = function (attributeName, value, force) {
151
+ if (force === void 0) {
152
+ force = false;
153
+ }
166
154
 
167
- DisplayObject.prototype.getChildren = function () {
168
- return this.children;
155
+ if (force || !isEqual(value, this.attributes[attributeName]) || attributeName === 'transformOrigin' || attributeName === 'visibility' // will affect children
156
+ ) {
157
+ if (attributeName === 'visibility') {
158
+ // set value cascade
159
+ this.forEach(function (object) {
160
+ object.changeAttribute(attributeName, value);
161
+ });
162
+ } else {
163
+ this.changeAttribute(attributeName, value);
164
+ }
165
+
166
+ _super.prototype.setAttribute.call(this, attributeName, value);
167
+ }
169
168
  };
170
169
  /**
171
- * @deprecated
172
- * compatible with G 3.0
173
- * @deprecated
170
+ * parse property, eg.
171
+ * * fill: 'red' => [1, 0, 0, 1]
172
+ * * translateX: '10px' => { unit: 'px', value: 10 }
174
173
  */
175
174
 
176
175
 
177
- DisplayObject.prototype.getFirst = function () {
178
- return this.firstChild;
176
+ DisplayObject.prototype.parseStyleProperty = function (name, value) {
177
+ var stylePropertyParser = this.stylePropertyParserFactory(name);
178
+
179
+ if (stylePropertyParser) {
180
+ // @ts-ignore
181
+ this.parsedStyle[name] = stylePropertyParser(value, this);
182
+ } else {
183
+ this.parsedStyle[name] = value;
184
+ }
179
185
  };
180
- /**
181
- * @deprecated
182
- * compatible with G 3.0
183
- * @deprecated
184
- * get last child group/shape
185
- */
186
186
 
187
+ DisplayObject.prototype.updateStyleProperty = function (name, oldParsedValue, newParsedValue) {
188
+ var _this = this; // update property, which may cause AABB re-calc
189
+ // @ts-ignore
187
190
 
188
- DisplayObject.prototype.getLast = function () {
189
- return this.lastChild;
190
- };
191
- /**
192
- * @deprecated
193
- * compatible with G 3.0
194
- * @deprecated
195
- * get child group/shape by index
196
- */
197
191
 
192
+ var stylePropertyUpdaters = this.stylePropertyUpdaterFactory(name);
198
193
 
199
- DisplayObject.prototype.getChildByIndex = function (index) {
200
- return this.children[index] || null;
194
+ if (stylePropertyUpdaters) {
195
+ stylePropertyUpdaters.forEach(function (updater) {
196
+ // @ts-ignore
197
+ updater(oldParsedValue, newParsedValue, _this, _this.sceneGraphService);
198
+ });
199
+ }
201
200
  };
202
201
  /**
203
- * compatible with G 3.0
204
- * @deprecated
202
+ * called when attributes get changed or initialized
205
203
  */
206
204
 
207
205
 
208
- DisplayObject.prototype.add = function (child, index) {
209
- this.appendChild(child, index);
210
- };
211
- /** transform operations */
212
-
206
+ DisplayObject.prototype.changeAttribute = function (name, value) {
207
+ var _this = this;
213
208
 
214
- DisplayObject.prototype.setOrigin = function (position, y, z) {
215
- if (y === void 0) {
216
- y = 0;
217
- }
209
+ var entity = this.getEntity();
210
+ var renderable = entity.getComponent(Renderable);
211
+ var oldValue = this.attributes[name]; // @ts-ignore
218
212
 
219
- if (z === void 0) {
220
- z = 0;
221
- }
213
+ var oldParsedValue = this.parsedStyle[name]; // update value
222
214
 
223
- this.sceneGraphService.setOrigin(this, createVec3(position, y, z));
224
- return this;
225
- };
215
+ this.attributes[name] = value; // @ts-ignore
226
216
 
227
- DisplayObject.prototype.getOrigin = function () {
228
- return this.sceneGraphService.getOrigin(this);
229
- };
230
- /**
231
- * alias setPosition
232
- */
217
+ this.parseStyleProperty(name, value); // @ts-ignore
233
218
 
219
+ this.updateStyleProperty(name, oldParsedValue, this.parsedStyle[name]); // inform clip path targets
234
220
 
235
- DisplayObject.prototype.moveTo = function (position, y, z) {
236
- if (y === void 0) {
237
- y = 0;
238
- }
221
+ if (this.attributes.clipPathTargets && this.attributes.clipPathTargets.length) {
222
+ this.attributes.clipPathTargets.forEach(function (target) {
223
+ dirtifyRenderable(target);
224
+ target.emit(ElementEvent.ATTRIBUTE_CHANGED, {
225
+ attributeName: 'clipPath',
226
+ oldValue: _this,
227
+ newValue: _this
228
+ });
229
+ });
230
+ } // redraw at next frame
239
231
 
240
- if (z === void 0) {
241
- z = 0;
242
- }
243
232
 
244
- this.setPosition(position, y, z);
245
- return this;
246
- };
247
- /**
248
- * alias setPosition
249
- */
233
+ renderable.dirty = true;
234
+ this.emit(ElementEvent.ATTRIBUTE_CHANGED, {
235
+ attributeName: name,
236
+ oldValue: oldValue,
237
+ newValue: value
238
+ });
239
+ }; // #region transformable
250
240
 
251
241
 
252
- DisplayObject.prototype.move = function (position, y, z) {
242
+ DisplayObject.prototype.setOrigin = function (position, y, z) {
253
243
  if (y === void 0) {
254
244
  y = 0;
255
245
  }
@@ -258,12 +248,15 @@ var DisplayObject = function (_super) {
258
248
  z = 0;
259
249
  }
260
250
 
261
- this.setPosition(position, y, z);
251
+ this.sceneGraphService.setOrigin(this, createVec3(position, y, z));
252
+ this.attributes.origin = this.getOrigin();
262
253
  return this;
263
254
  };
255
+
256
+ DisplayObject.prototype.getOrigin = function () {
257
+ return this.sceneGraphService.getOrigin(this);
258
+ };
264
259
  /**
265
- * compatible with G 3.0
266
- *
267
260
  * set position in world space
268
261
  */
269
262
 
@@ -404,9 +397,8 @@ var DisplayObject = function (_super) {
404
397
 
405
398
 
406
399
  DisplayObject.prototype.getEulerAngles = function () {
407
- var transform = this.entity.getComponent(Transform); // eslint-disable-next-line @typescript-eslint/no-unused-vars
408
-
409
- var _a = __read(getEuler(vec3.create(), this.sceneGraphService.getWorldTransform(this, transform)), 3),
400
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
401
+ var _a = __read(getEuler(vec3.create(), this.sceneGraphService.getWorldTransform(this)), 3),
410
402
  ex = _a[0],
411
403
  ey = _a[1],
412
404
  ez = _a[2];
@@ -481,80 +473,83 @@ var DisplayObject = function (_super) {
481
473
  DisplayObject.prototype.getWorldTransform = function () {
482
474
  return this.sceneGraphService.getWorldTransform(this);
483
475
  };
476
+
477
+ DisplayObject.prototype.resetLocalTransform = function () {
478
+ this.sceneGraphService.resetLocalTransform(this);
479
+ };
484
480
  /**
485
- * return 3x3 matrix in world space
486
- * @deprecated
481
+ * sync style.x/y when local position changed
482
+ *
483
+ * Mixins may not declare private/protected properties
484
+ * however, you can use ES2020 private fields
487
485
  */
488
486
 
489
487
 
490
- DisplayObject.prototype.getMatrix = function () {
491
- var transform = this.getWorldTransform();
492
-
493
- var _a = __read(mat4.getTranslation(vec3.create(), transform), 2),
494
- tx = _a[0],
495
- ty = _a[1];
496
-
497
- var _b = __read(mat4.getScaling(vec3.create(), transform), 2),
498
- sx = _b[0],
499
- sy = _b[1];
500
-
501
- var rotation = mat4.getRotation(quat.create(), transform);
488
+ DisplayObject.prototype.syncLocalPosition = function () {
489
+ var localPosition = this.getLocalPosition();
490
+ this.attributes.x = localPosition[0];
491
+ this.attributes.y = localPosition[1];
492
+ }; // #endregion transformable
493
+ // #region animatable
502
494
 
503
- var _c = __read(getEuler(vec3.create(), rotation), 3),
504
- eux = _c[0],
505
- euy = _c[1],
506
- euz = _c[2]; // gimbal lock at 90 degrees
495
+ /**
496
+ * returns an array of all Animation objects affecting this element
497
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAnimations
498
+ */
507
499
 
508
500
 
509
- return fromRotationTranslationScale(eux || euz, tx, ty, sx, sy);
501
+ DisplayObject.prototype.getAnimations = function () {
502
+ return this.activeAnimations;
510
503
  };
511
504
  /**
512
- * set 3x3 matrix in world space
513
- * @deprecated
505
+ * create an animation with WAAPI
506
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/animate
514
507
  */
515
508
 
516
509
 
517
- DisplayObject.prototype.setMatrix = function (mat) {
518
- var row0x = mat[0];
519
- var row0y = mat[3];
520
- var row1x = mat[1];
521
- var row1y = mat[4]; // decompose 3x3 matrix
522
- // @see https://www.w3.org/TR/css-transforms-1/#decomposing-a-2d-matrix
510
+ DisplayObject.prototype.animate = function (keyframes, options) {
511
+ var _a, _b;
523
512
 
524
- var scalingX = Math.sqrt(row0x * row0x + row0y * row0y);
525
- var scalingY = Math.sqrt(row1x * row1x + row1y * row1y); // If determinant is negative, one axis was flipped.
513
+ var timeline = (_a = this.ownerDocument) === null || _a === void 0 ? void 0 : _a.timeline; // accounte for clip path, use target's timeline
526
514
 
527
- var determinant = row0x * row1y - row0y * row1x;
515
+ if (this.attributes.clipPathTargets && this.attributes.clipPathTargets.length) {
516
+ var target = this.attributes.clipPathTargets[0];
517
+ timeline = (_b = target.ownerDocument) === null || _b === void 0 ? void 0 : _b.timeline;
518
+ } // clear old parsed transform
528
519
 
529
- if (determinant < 0) {
530
- // Flip axis with minimum unit vector dot product.
531
- if (row0x < row1y) {
532
- scalingX = -scalingX;
533
- } else {
534
- scalingY = -scalingY;
535
- }
536
- } // Renormalize matrix to remove scale.
537
520
 
521
+ this.parsedStyle.transform = undefined;
538
522
 
539
- if (scalingX) {
540
- row0x *= 1 / scalingX;
541
- row0y *= 1 / scalingX;
523
+ if (timeline) {
524
+ return timeline.play(new KeyframeEffect(this, keyframes, options));
542
525
  }
543
526
 
544
- if (scalingY) {
545
- row1x *= 1 / scalingY;
546
- row1y *= 1 / scalingY;
547
- } // Compute rotation and renormalize matrix.
548
-
527
+ return null;
528
+ }; // #endregion animatable
529
+ // #region visible
549
530
 
550
- var angle = Math.atan2(row0y, row0x);
551
- this.setEulerAngles(angle).setPosition(mat[6], mat[7]).setLocalScale(scalingX, scalingY);
531
+ /**
532
+ * show group, which will also change visibility of its children in sceneGraphNode
533
+ *
534
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/visibility
535
+ */
536
+
537
+
538
+ DisplayObject.prototype.show = function () {
539
+ this.style.visibility = 'visible';
552
540
  };
553
- /* z-index & visibility */
541
+ /**
542
+ * hide group, which will also change visibility of its children in sceneGraphNode
543
+ */
554
544
 
555
545
 
556
- DisplayObject.prototype.setZIndex = function (zIndex) {
557
- this.style.zIndex = zIndex;
546
+ DisplayObject.prototype.hide = function () {
547
+ this.style.visibility = 'hidden';
548
+ };
549
+
550
+ DisplayObject.prototype.isVisible = function () {
551
+ var cullable = this.entity.getComponent(Cullable);
552
+ return this.style.visibility === 'visible' && (!cullable || cullable && !cullable.isCulled());
558
553
  };
559
554
  /**
560
555
  * bring to front in current group
@@ -563,11 +558,12 @@ var DisplayObject = function (_super) {
563
558
 
564
559
  DisplayObject.prototype.toFront = function () {
565
560
  if (this.parentNode) {
566
- var zIndex = Math.max.apply(Math, __spreadArray([], __read(this.parentNode.children.map(function (child) {
561
+ this.style.zIndex = Math.max.apply(Math, __spreadArray([], __read(this.parentNode.children.map(function (child) {
567
562
  return Number(child.style.zIndex);
568
563
  })))) + 1;
569
- this.setZIndex(zIndex);
570
564
  }
565
+
566
+ return this;
571
567
  };
572
568
  /**
573
569
  * send to back in current group
@@ -576,34 +572,85 @@ var DisplayObject = function (_super) {
576
572
 
577
573
  DisplayObject.prototype.toBack = function () {
578
574
  if (this.parentNode) {
579
- var zIndex = Math.min.apply(Math, __spreadArray([], __read(this.parentNode.children.map(function (child) {
575
+ this.style.zIndex = Math.min.apply(Math, __spreadArray([], __read(this.parentNode.children.map(function (child) {
580
576
  return Number(child.style.zIndex);
581
577
  })))) - 1;
582
- this.setZIndex(zIndex);
583
578
  }
579
+
580
+ return this;
581
+ }; // #endregion visible
582
+ // #region deprecated
583
+
584
+ /**
585
+ * @deprecated
586
+ * compatible with G 3.0
587
+ * @deprecated
588
+ */
589
+
590
+
591
+ DisplayObject.prototype.getCount = function () {
592
+ return this.childElementCount;
584
593
  };
585
594
  /**
586
- * show group, which will also change visibility of its children in sceneGraphNode
587
- *
588
- * @see https://developer.mozilla.org/en-US/docs/Web/CSS/visibility
595
+ * @deprecated
596
+ * compatible with G 3.0
597
+ * @deprecated
589
598
  */
590
599
 
591
600
 
592
- DisplayObject.prototype.show = function () {
593
- this.style.visibility = 'visible';
601
+ DisplayObject.prototype.getParent = function () {
602
+ return this.parentElement;
594
603
  };
595
604
  /**
596
- * hide group, which will also change visibility of its children in sceneGraphNode
605
+ * @deprecated
606
+ * compatible with G 3.0
607
+ * @deprecated
597
608
  */
598
609
 
599
610
 
600
- DisplayObject.prototype.hide = function () {
601
- this.style.visibility = 'hidden';
611
+ DisplayObject.prototype.getChildren = function () {
612
+ return this.children;
602
613
  };
614
+ /**
615
+ * @deprecated
616
+ * compatible with G 3.0
617
+ * @deprecated
618
+ */
603
619
 
604
- DisplayObject.prototype.isVisible = function () {
605
- var cullable = this.getEntity().getComponent(Cullable);
606
- return this.style.visibility === 'visible' && (!cullable || cullable && !cullable.isCulled());
620
+
621
+ DisplayObject.prototype.getFirst = function () {
622
+ return this.firstElementChild;
623
+ };
624
+ /**
625
+ * @deprecated
626
+ * compatible with G 3.0
627
+ * @deprecated
628
+ * get last child group/shape
629
+ */
630
+
631
+
632
+ DisplayObject.prototype.getLast = function () {
633
+ return this.lastElementChild;
634
+ };
635
+ /**
636
+ * @deprecated
637
+ * compatible with G 3.0
638
+ * @deprecated
639
+ * get child group/shape by index
640
+ */
641
+
642
+
643
+ DisplayObject.prototype.getChildByIndex = function (index) {
644
+ return this.children[index] || null;
645
+ };
646
+ /**
647
+ * compatible with G 3.0
648
+ * @deprecated
649
+ */
650
+
651
+
652
+ DisplayObject.prototype.add = function (child, index) {
653
+ return this.appendChild(child, index);
607
654
  };
608
655
  /**
609
656
  * @alias style.clipPath
@@ -621,113 +668,182 @@ var DisplayObject = function (_super) {
621
668
 
622
669
 
623
670
  DisplayObject.prototype.getClip = function () {
624
- return this.style.clipPath;
671
+ return this.style.clipPath || null;
625
672
  };
626
673
  /**
627
- * parse property, eg.
628
- * * fill: 'red' => [1, 0, 0, 1]
629
- * * translateX: '10px' => { unit: 'px', value: 10 }
674
+ * compatible with G 3.0
675
+ * @deprecated
630
676
  */
631
677
 
632
678
 
633
- DisplayObject.prototype.parseStyleProperty = function (name, value) {
634
- var stylePropertyParser = this.stylePropertyParserFactory(name);
679
+ DisplayObject.prototype.set = function (name, value) {
680
+ this.config[name] = value;
681
+ };
682
+ /**
683
+ * compatible with G 3.0
684
+ * @deprecated
685
+ */
635
686
 
636
- if (stylePropertyParser) {
637
- this.parsedStyle[name] = stylePropertyParser(value, this);
638
- } else {
639
- this.parsedStyle[name] = value;
640
- }
687
+
688
+ DisplayObject.prototype.get = function (name) {
689
+ return this.config[name];
641
690
  };
691
+ /**
692
+ * compatible with G 3.0
693
+ * @alias object.config
694
+ * @deprecated
695
+ */
642
696
 
643
- DisplayObject.prototype.updateStyleProperty = function (name, oldParsedValue, newParsedValue) {
644
- var _this = this; // update property, which may cause AABB re-calc
645
- // @ts-ignore
646
697
 
698
+ DisplayObject.prototype.getConfig = function () {
699
+ return this.config;
700
+ };
647
701
 
648
- var stylePropertyUpdaters = this.stylePropertyUpdaterFactory(name);
702
+ DisplayObject.prototype.attr = function () {
703
+ var _this = this;
649
704
 
650
- if (stylePropertyUpdaters) {
651
- stylePropertyUpdaters.forEach(function (updater) {
652
- updater(oldParsedValue, newParsedValue, _this, _this.sceneGraphService);
705
+ var args = [];
706
+
707
+ for (var _i = 0; _i < arguments.length; _i++) {
708
+ args[_i] = arguments[_i];
709
+ }
710
+
711
+ var _a = __read(args, 2),
712
+ name = _a[0],
713
+ value = _a[1];
714
+
715
+ if (!name) {
716
+ return this.attributes;
717
+ }
718
+
719
+ if (isObject(name)) {
720
+ Object.keys(name).forEach(function (key) {
721
+ _this.setAttribute(key, name[key]);
653
722
  });
723
+ return this;
724
+ }
725
+
726
+ if (args.length === 2) {
727
+ this.setAttribute(name, value);
728
+ return this;
654
729
  }
730
+
731
+ return this.attributes[name];
655
732
  };
656
733
  /**
657
- * called when attributes get changed or initialized
734
+ * @alias setPosition
735
+ * @deprecated
658
736
  */
659
737
 
660
738
 
661
- DisplayObject.prototype.changeAttribute = function (name, value) {
662
- var _this = this;
739
+ DisplayObject.prototype.moveTo = function (position, y, z) {
740
+ if (y === void 0) {
741
+ y = 0;
742
+ }
663
743
 
664
- var entity = this.getEntity();
665
- var renderable = entity.getComponent(Renderable);
666
- var oldValue = this.attributes[name]; // @ts-ignore
744
+ if (z === void 0) {
745
+ z = 0;
746
+ }
667
747
 
668
- var oldParsedValue = this.parsedStyle[name]; // update value
748
+ this.setPosition(position, y, z);
749
+ return this;
750
+ };
751
+ /**
752
+ * @alias setPosition
753
+ * @deprecated
754
+ */
669
755
 
670
- this.attributes[name] = value; // @ts-ignore
671
756
 
672
- this.parseStyleProperty(name, value); // @ts-ignore
757
+ DisplayObject.prototype.move = function (position, y, z) {
758
+ if (y === void 0) {
759
+ y = 0;
760
+ }
673
761
 
674
- this.updateStyleProperty(name, oldParsedValue, this.parsedStyle[name]); // inform clip path targets
762
+ if (z === void 0) {
763
+ z = 0;
764
+ }
675
765
 
676
- if (this.attributes.clipPathTargets && this.attributes.clipPathTargets.length) {
677
- this.attributes.clipPathTargets.forEach(function (target) {
678
- var targetRenderable = target.getEntity().getComponent(Renderable);
679
- targetRenderable.dirty = true;
680
- targetRenderable.aabbDirty = true;
681
- target.emitter.emit(DISPLAY_OBJECT_EVENT.AttributeChanged, 'clipPath', _this, _this, target);
682
- });
683
- } // redraw at next frame
766
+ this.setPosition(position, y, z);
767
+ return this;
768
+ };
769
+ /**
770
+ * @alias style.zIndex
771
+ * @deprecated
772
+ */
684
773
 
685
774
 
686
- renderable.dirty = true;
687
- this.emitter.emit(DISPLAY_OBJECT_EVENT.AttributeChanged, name, oldValue, value, this);
775
+ DisplayObject.prototype.setZIndex = function (zIndex) {
776
+ this.style.zIndex = zIndex;
777
+ return this;
688
778
  };
779
+ /**
780
+ * return 3x3 matrix in world space
781
+ * @deprecated
782
+ */
689
783
 
690
- DisplayObject.prototype.initAttributes = function (attributes) {
691
- var _this = this;
692
784
 
693
- if (attributes === void 0) {
694
- attributes = {};
695
- }
785
+ DisplayObject.prototype.getMatrix = function () {
786
+ var transform = this.getWorldTransform();
696
787
 
697
- var entity = this.getEntity();
698
- var renderable = entity.getComponent(Renderable); // parse attributes first
788
+ var _a = __read(mat4.getTranslation(vec3.create(), transform), 2),
789
+ tx = _a[0],
790
+ ty = _a[1];
699
791
 
700
- for (var attributeName in attributes) {
701
- var value = attributes[attributeName];
702
- this.attributes[attributeName] = value; // @ts-ignore
792
+ var _b = __read(mat4.getScaling(vec3.create(), transform), 2),
793
+ sx = _b[0],
794
+ sy = _b[1];
703
795
 
704
- this.parseStyleProperty(attributeName, value);
705
- }
796
+ var rotation = mat4.getRotation(quat.create(), transform);
706
797
 
707
- var priorities = {
708
- x: 1000,
709
- y: 1000
710
- }; // update x, y at last
798
+ var _c = __read(getEuler(vec3.create(), rotation), 3),
799
+ eux = _c[0],
800
+ euy = _c[1],
801
+ euz = _c[2]; // gimbal lock at 90 degrees
711
802
 
712
- var sortedNames = Object.keys(attributes).sort(function (a, b) {
713
- return (priorities[a] || 0) - (priorities[b] || 0);
714
- });
715
- sortedNames.forEach(function (attributeName) {
716
- // @ts-ignore
717
- _this.updateStyleProperty(attributeName, undefined, _this.parsedStyle[attributeName]);
718
- }); // redraw at next frame
719
803
 
720
- renderable.dirty = true;
804
+ return fromRotationTranslationScale(eux || euz, tx, ty, sx, sy);
721
805
  };
722
806
  /**
723
- * sync style.x/y when local position changed
807
+ * set 3x3 matrix in world space
808
+ * @deprecated
724
809
  */
725
810
 
726
811
 
727
- DisplayObject.prototype.syncLocalPosition = function () {
728
- var localPosition = this.getLocalPosition();
729
- this.attributes.x = localPosition[0];
730
- this.attributes.y = localPosition[1];
812
+ DisplayObject.prototype.setMatrix = function (mat) {
813
+ var row0x = mat[0];
814
+ var row0y = mat[3];
815
+ var row1x = mat[1];
816
+ var row1y = mat[4]; // decompose 3x3 matrix
817
+ // @see https://www.w3.org/TR/css-transforms-1/#decomposing-a-2d-matrix
818
+
819
+ var scalingX = Math.sqrt(row0x * row0x + row0y * row0y);
820
+ var scalingY = Math.sqrt(row1x * row1x + row1y * row1y); // If determinant is negative, one axis was flipped.
821
+
822
+ var determinant = row0x * row1y - row0y * row1x;
823
+
824
+ if (determinant < 0) {
825
+ // Flip axis with minimum unit vector dot product.
826
+ if (row0x < row1y) {
827
+ scalingX = -scalingX;
828
+ } else {
829
+ scalingY = -scalingY;
830
+ }
831
+ } // Renormalize matrix to remove scale.
832
+
833
+
834
+ if (scalingX) {
835
+ row0x *= 1 / scalingX;
836
+ row0y *= 1 / scalingX;
837
+ }
838
+
839
+ if (scalingY) {
840
+ row1x *= 1 / scalingY;
841
+ row1y *= 1 / scalingY;
842
+ } // Compute rotation and renormalize matrix.
843
+
844
+
845
+ var angle = Math.atan2(row0y, row0x);
846
+ this.setEulerAngles(angle).setPosition(mat[6], mat[7]).setLocalScale(scalingX, scalingY);
731
847
  };
732
848
 
733
849
  return DisplayObject;