@antv/g 5.0.22 → 5.0.23-alpha.4

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 (156) hide show
  1. package/dist/index.umd.min.js +3 -3
  2. package/es/AbstractRenderer.js +5 -0
  3. package/es/camera/Camera.js +2 -2
  4. package/es/css/cssom/CSSKeywordValue.d.ts +1 -1
  5. package/es/css/cssom/CSSNumericSumValue.d.ts +1 -1
  6. package/es/css/cssom/CSSNumericValue.d.ts +139 -4
  7. package/es/css/cssom/CSSNumericValue.js +1164 -5
  8. package/es/css/cssom/CSSTransformValue.d.ts +1 -1
  9. package/es/css/cssom/index.d.ts +0 -10
  10. package/es/css/cssom/index.js +1 -11
  11. package/es/css/parser/color.js +1 -1
  12. package/es/css/parser/dimension.js +1 -2
  13. package/es/css/parser/numeric.js +1 -1
  14. package/es/css/parser/path.d.ts +2 -2
  15. package/es/css/parser/path.js +1 -1
  16. package/es/css/parser/points.js +1 -1
  17. package/es/css/parser/transform-origin.js +1 -1
  18. package/es/css/properties/CSSPropertyPath.d.ts +14 -2
  19. package/es/css/properties/CSSPropertyTextTransform.d.ts +2 -2
  20. package/es/css/properties/CSSPropertyTransform.js +1 -2
  21. package/es/display-objects/DisplayObject.js +4 -5
  22. package/es/display-objects/Path.d.ts +15 -15
  23. package/es/display-objects/Path.js +1 -1
  24. package/es/display-objects/Polygon.d.ts +8 -1
  25. package/es/display-objects/Polyline.d.ts +7 -5
  26. package/es/dom/Document.js +2 -2
  27. package/es/dom/Element.js +1 -2
  28. package/es/dom/EventTarget.js +1 -1
  29. package/es/dom/FederatedTouchEvent.d.ts +5 -3
  30. package/es/plugins/CullingPlugin.d.ts +0 -1
  31. package/es/plugins/CullingPlugin.js +3 -8
  32. package/es/plugins/DirtyCheckPlugin.d.ts +1 -1
  33. package/es/plugins/DirtyCheckPlugin.js +9 -8
  34. package/es/plugins/EventPlugin.d.ts +1 -1
  35. package/es/plugins/EventPlugin.js +163 -148
  36. package/es/plugins/PrepareRendererPlugin.d.ts +0 -1
  37. package/es/plugins/PrepareRendererPlugin.js +15 -16
  38. package/es/services/EventService.d.ts +8 -0
  39. package/es/services/EventService.js +274 -20
  40. package/es/services/RenderingService.d.ts +17 -16
  41. package/es/services/RenderingService.js +18 -17
  42. package/es/services/SceneGraphService.js +1 -1
  43. package/es/services/aabb/PathUpdater.d.ts +3 -3
  44. package/es/services/aabb/PolylineUpdater.d.ts +3 -3
  45. package/es/services/aabb/RectUpdater.js +1 -1
  46. package/es/types.d.ts +5 -3
  47. package/es/utils/assert.d.ts +6 -0
  48. package/es/utils/assert.js +18 -0
  49. package/es/utils/event.d.ts +18 -16
  50. package/es/utils/hooks.d.ts +280 -0
  51. package/es/utils/hooks.js +753 -0
  52. package/es/utils/index.d.ts +1 -0
  53. package/es/utils/index.js +2 -1
  54. package/es/utils/math.d.ts +1 -0
  55. package/es/utils/math.js +13 -2
  56. package/es/utils/string.d.ts +1 -0
  57. package/es/utils/string.js +8 -0
  58. package/es/utils/text.js +2 -1
  59. package/lib/AbstractRenderer.js +5 -0
  60. package/lib/camera/Camera.js +4 -4
  61. package/lib/css/cssom/CSSKeywordValue.d.ts +1 -1
  62. package/lib/css/cssom/CSSNumericSumValue.d.ts +1 -1
  63. package/lib/css/cssom/CSSNumericValue.d.ts +139 -4
  64. package/lib/css/cssom/CSSNumericValue.js +1222 -52
  65. package/lib/css/cssom/CSSTransformValue.d.ts +1 -1
  66. package/lib/css/cssom/index.d.ts +0 -10
  67. package/lib/css/cssom/index.js +0 -130
  68. package/lib/css/parser/color.js +5 -5
  69. package/lib/css/parser/dimension.js +1 -3
  70. package/lib/css/parser/numeric.js +3 -3
  71. package/lib/css/parser/path.d.ts +2 -2
  72. package/lib/css/parser/path.js +4 -4
  73. package/lib/css/parser/points.js +2 -2
  74. package/lib/css/parser/transform-origin.js +2 -2
  75. package/lib/css/properties/CSSPropertyPath.d.ts +14 -2
  76. package/lib/css/properties/CSSPropertyTextTransform.d.ts +2 -2
  77. package/lib/css/properties/CSSPropertyTransform.js +0 -2
  78. package/lib/display-objects/DisplayObject.js +7 -9
  79. package/lib/display-objects/Path.d.ts +15 -15
  80. package/lib/display-objects/Path.js +3 -3
  81. package/lib/display-objects/Polygon.d.ts +8 -1
  82. package/lib/display-objects/Polyline.d.ts +7 -5
  83. package/lib/dom/Document.js +2 -2
  84. package/lib/dom/Element.js +1 -3
  85. package/lib/dom/EventTarget.js +9 -9
  86. package/lib/dom/FederatedTouchEvent.d.ts +5 -3
  87. package/lib/plugins/CullingPlugin.d.ts +0 -1
  88. package/lib/plugins/CullingPlugin.js +3 -7
  89. package/lib/plugins/DirtyCheckPlugin.d.ts +1 -1
  90. package/lib/plugins/DirtyCheckPlugin.js +10 -8
  91. package/lib/plugins/EventPlugin.d.ts +1 -1
  92. package/lib/plugins/EventPlugin.js +172 -156
  93. package/lib/plugins/PrepareRendererPlugin.d.ts +0 -1
  94. package/lib/plugins/PrepareRendererPlugin.js +14 -14
  95. package/lib/services/EventService.d.ts +8 -0
  96. package/lib/services/EventService.js +274 -19
  97. package/lib/services/RenderingService.d.ts +17 -16
  98. package/lib/services/RenderingService.js +19 -18
  99. package/lib/services/SceneGraphService.js +3 -3
  100. package/lib/services/aabb/PathUpdater.d.ts +3 -3
  101. package/lib/services/aabb/PolylineUpdater.d.ts +3 -3
  102. package/lib/services/aabb/RectUpdater.js +3 -3
  103. package/lib/types.d.ts +5 -3
  104. package/lib/utils/assert.d.ts +6 -0
  105. package/lib/utils/assert.js +30 -0
  106. package/lib/utils/event.d.ts +18 -16
  107. package/lib/utils/hooks.d.ts +280 -0
  108. package/lib/utils/hooks.js +759 -0
  109. package/lib/utils/index.d.ts +1 -0
  110. package/lib/utils/index.js +13 -0
  111. package/lib/utils/math.d.ts +1 -0
  112. package/lib/utils/math.js +17 -4
  113. package/lib/utils/string.d.ts +1 -0
  114. package/lib/utils/string.js +11 -0
  115. package/lib/utils/text.js +5 -3
  116. package/package.json +4 -7
  117. package/es/css/cssom/CSSMathInvert.d.ts +0 -14
  118. package/es/css/cssom/CSSMathInvert.js +0 -84
  119. package/es/css/cssom/CSSMathMax.d.ts +0 -17
  120. package/es/css/cssom/CSSMathMax.js +0 -118
  121. package/es/css/cssom/CSSMathMin.d.ts +0 -17
  122. package/es/css/cssom/CSSMathMin.js +0 -119
  123. package/es/css/cssom/CSSMathNegate.d.ts +0 -14
  124. package/es/css/cssom/CSSMathNegate.js +0 -80
  125. package/es/css/cssom/CSSMathProduct.d.ts +0 -16
  126. package/es/css/cssom/CSSMathProduct.js +0 -109
  127. package/es/css/cssom/CSSMathSum.d.ts +0 -17
  128. package/es/css/cssom/CSSMathSum.js +0 -117
  129. package/es/css/cssom/CSSMathValue.d.ts +0 -11
  130. package/es/css/cssom/CSSMathValue.js +0 -27
  131. package/es/css/cssom/CSSMathVariadic.d.ts +0 -9
  132. package/es/css/cssom/CSSMathVariadic.js +0 -44
  133. package/es/css/cssom/CSSNumericValueType.d.ts +0 -33
  134. package/es/css/cssom/CSSNumericValueType.js +0 -259
  135. package/es/css/cssom/CSSUnitValue.d.ts +0 -33
  136. package/es/css/cssom/CSSUnitValue.js +0 -252
  137. package/lib/css/cssom/CSSMathInvert.d.ts +0 -14
  138. package/lib/css/cssom/CSSMathInvert.js +0 -94
  139. package/lib/css/cssom/CSSMathMax.d.ts +0 -17
  140. package/lib/css/cssom/CSSMathMax.js +0 -128
  141. package/lib/css/cssom/CSSMathMin.d.ts +0 -17
  142. package/lib/css/cssom/CSSMathMin.js +0 -128
  143. package/lib/css/cssom/CSSMathNegate.d.ts +0 -14
  144. package/lib/css/cssom/CSSMathNegate.js +0 -89
  145. package/lib/css/cssom/CSSMathProduct.d.ts +0 -16
  146. package/lib/css/cssom/CSSMathProduct.js +0 -119
  147. package/lib/css/cssom/CSSMathSum.d.ts +0 -17
  148. package/lib/css/cssom/CSSMathSum.js +0 -129
  149. package/lib/css/cssom/CSSMathValue.d.ts +0 -11
  150. package/lib/css/cssom/CSSMathValue.js +0 -35
  151. package/lib/css/cssom/CSSMathVariadic.d.ts +0 -9
  152. package/lib/css/cssom/CSSMathVariadic.js +0 -55
  153. package/lib/css/cssom/CSSNumericValueType.d.ts +0 -33
  154. package/lib/css/cssom/CSSNumericValueType.js +0 -272
  155. package/lib/css/cssom/CSSUnitValue.d.ts +0 -33
  156. package/lib/css/cssom/CSSUnitValue.js +0 -267
@@ -11,7 +11,6 @@ export interface CullingStrategyContribution {
11
11
  * 2. other custom culling strategies, eg. frustum culling
12
12
  */
13
13
  export declare class CullingPlugin implements RenderingPlugin {
14
- static tag: string;
15
14
  private strategyProvider;
16
15
  apply(renderingService: RenderingService): void;
17
16
  }
@@ -26,11 +26,9 @@ var CullingPlugin =
26
26
  function () {
27
27
  function CullingPlugin() {}
28
28
 
29
- CullingPlugin_1 = CullingPlugin;
30
-
31
29
  CullingPlugin.prototype.apply = function (renderingService) {
32
30
  var strategies = this.strategyProvider.getContributions();
33
- renderingService.hooks.cull.tap(CullingPlugin_1.tag, function (object) {
31
+ renderingService.hooks.cull.tap(function (object) {
34
32
  if (object) {
35
33
  var cullable = object.cullable;
36
34
 
@@ -52,15 +50,13 @@ function () {
52
50
 
53
51
  return object;
54
52
  });
55
- renderingService.hooks.afterRender.tap(CullingPlugin_1.tag, function (object) {
53
+ renderingService.hooks.afterRender.tap(function (object) {
56
54
  object.cullable.visibilityPlaneMask = -1;
57
55
  });
58
56
  };
59
57
 
60
- var CullingPlugin_1;
61
- CullingPlugin.tag = 'CullingPlugin';
62
58
  (0, _tslib.__decorate)([(0, _manaSyringe.contrib)(CullingStrategyContribution), (0, _tslib.__metadata)("design:type", Object)], CullingPlugin.prototype, "strategyProvider", void 0);
63
- CullingPlugin = CullingPlugin_1 = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
59
+ CullingPlugin = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
64
60
  contrib: _RenderingService.RenderingPluginContribution
65
61
  })], CullingPlugin);
66
62
  return CullingPlugin;
@@ -3,7 +3,7 @@ import type { RenderingService, RenderingPlugin } from '../services/RenderingSer
3
3
  * Filter dirty renderables and calculate the "dirty rectangle" which will be clear when frame began
4
4
  */
5
5
  export declare class DirtyCheckPlugin implements RenderingPlugin {
6
- static tag: string;
6
+ private canvasConfig;
7
7
  private renderingContext;
8
8
  apply(renderingService: RenderingService): void;
9
9
  }
@@ -9,6 +9,8 @@ var _tslib = require("tslib");
9
9
 
10
10
  var _manaSyringe = require("mana-syringe");
11
11
 
12
+ var _types = require("../types");
13
+
12
14
  var _RenderingService = require("../services/RenderingService");
13
15
 
14
16
  var _RenderingContext = require("../services/RenderingContext");
@@ -21,18 +23,19 @@ var DirtyCheckPlugin =
21
23
  function () {
22
24
  function DirtyCheckPlugin() {}
23
25
 
24
- DirtyCheckPlugin_1 = DirtyCheckPlugin;
25
-
26
26
  DirtyCheckPlugin.prototype.apply = function (renderingService) {
27
27
  var _this = this;
28
28
 
29
- renderingService.hooks.dirtycheck.tap(DirtyCheckPlugin_1.tag, function (object) {
29
+ renderingService.hooks.dirtycheck.tap(function (object) {
30
30
  if (object) {
31
- // const { enableDirtyRectangleRendering } = this.canvasConfig.renderer.getConfig();
31
+ var enableDirtyCheck = _this.canvasConfig.renderer.getConfig().enableDirtyCheck;
32
+
32
33
  var renderable = object.renderable;
33
34
 
34
- var isDirty = renderable.dirty || _this.renderingContext.renderReasons.has(_RenderingContext.RenderReason.CAMERA_CHANGED); // if (isDirty || !enableDirtyRectangleRendering) {
35
+ var isCameraDirty = _this.renderingContext.renderReasons.has(_RenderingContext.RenderReason.CAMERA_CHANGED);
35
36
 
37
+ var isRenderingContextDirty = _this.renderingContext.dirty;
38
+ var isDirty = renderable.dirty || isCameraDirty || (enableDirtyCheck ? false : isRenderingContextDirty);
36
39
 
37
40
  if (isDirty) {
38
41
  return object;
@@ -45,10 +48,9 @@ function () {
45
48
  });
46
49
  };
47
50
 
48
- var DirtyCheckPlugin_1;
49
- DirtyCheckPlugin.tag = 'DirtyCheckPlugin';
51
+ (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_types.CanvasConfig), (0, _tslib.__metadata)("design:type", Object)], DirtyCheckPlugin.prototype, "canvasConfig", void 0);
50
52
  (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_RenderingContext.RenderingContext), (0, _tslib.__metadata)("design:type", Object)], DirtyCheckPlugin.prototype, "renderingContext", void 0);
51
- DirtyCheckPlugin = DirtyCheckPlugin_1 = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
53
+ DirtyCheckPlugin = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
52
54
  contrib: _RenderingService.RenderingPluginContribution
53
55
  })], DirtyCheckPlugin);
54
56
  return DirtyCheckPlugin;
@@ -7,7 +7,6 @@ import { RenderingService } from '../services';
7
7
  * also provide some extra events such as `drag`
8
8
  */
9
9
  export declare class EventPlugin implements RenderingPlugin {
10
- static tag: string;
11
10
  private canvasConfig;
12
11
  private contextService;
13
12
  private renderingService;
@@ -18,6 +17,7 @@ export declare class EventPlugin implements RenderingPlugin {
18
17
  private rootWheelEvent;
19
18
  apply(renderingService: RenderingService): void;
20
19
  private onPointerMove;
20
+ private formatTouch;
21
21
  private bootstrapEvent;
22
22
  private normalizeWheelEvent;
23
23
  /**
@@ -9,8 +9,6 @@ var _tslib = require("tslib");
9
9
 
10
10
  var _manaSyringe = require("mana-syringe");
11
11
 
12
- var _lodashEs = require("lodash-es");
13
-
14
12
  var _FederatedPointerEvent = require("../dom/FederatedPointerEvent");
15
13
 
16
14
  var _FederatedWheelEvent = require("../dom/FederatedWheelEvent");
@@ -23,6 +21,8 @@ var _types = require("../types");
23
21
 
24
22
  var _event = require("../utils/event");
25
23
 
24
+ var _utils = require("../utils");
25
+
26
26
  /**
27
27
  * support mouse & touch events
28
28
  * @see https://github.com/pixijs/pixi.js/blob/dev/packages/interaction/README.md
@@ -40,41 +40,21 @@ function () {
40
40
  this.rootWheelEvent = new _FederatedWheelEvent.FederatedWheelEvent(null);
41
41
 
42
42
  this.onPointerMove = function (nativeEvent) {
43
- var e_1, _a;
44
-
45
- var _b, _c;
43
+ var _a, _b;
46
44
 
47
- var canvas = (_c = (_b = _this.renderingContext.root) === null || _b === void 0 ? void 0 : _b.ownerDocument) === null || _c === void 0 ? void 0 : _c.defaultView;
45
+ var canvas = (_b = (_a = _this.renderingContext.root) === null || _a === void 0 ? void 0 : _a.ownerDocument) === null || _b === void 0 ? void 0 : _b.defaultView;
48
46
  if (canvas.supportTouchEvent && nativeEvent.pointerType === 'touch') return;
49
47
 
50
- var normalizedEvents = _this.normalizeToPointerEvent(nativeEvent, canvas);
48
+ var normalizedEvent = _this.normalizeToPointerEvent(nativeEvent, canvas);
51
49
 
52
- try {
53
- for (var normalizedEvents_1 = (0, _tslib.__values)(normalizedEvents), normalizedEvents_1_1 = normalizedEvents_1.next(); !normalizedEvents_1_1.done; normalizedEvents_1_1 = normalizedEvents_1.next()) {
54
- var normalizedEvent = normalizedEvents_1_1.value;
50
+ var event = _this.bootstrapEvent(_this.rootPointerEvent, normalizedEvent, canvas);
55
51
 
56
- var event_1 = _this.bootstrapEvent(_this.rootPointerEvent, normalizedEvent, canvas);
57
-
58
- _this.eventService.mapEvent(event_1);
59
- }
60
- } catch (e_1_1) {
61
- e_1 = {
62
- error: e_1_1
63
- };
64
- } finally {
65
- try {
66
- if (normalizedEvents_1_1 && !normalizedEvents_1_1.done && (_a = normalizedEvents_1.return)) _a.call(normalizedEvents_1);
67
- } finally {
68
- if (e_1) throw e_1.error;
69
- }
70
- }
52
+ _this.eventService.mapEvent(event);
71
53
 
72
54
  _this.setCursor(_this.eventService.cursor);
73
55
  };
74
56
  }
75
57
 
76
- EventPlugin_1 = EventPlugin;
77
-
78
58
  EventPlugin.prototype.apply = function (renderingService) {
79
59
  var _this = this;
80
60
 
@@ -87,7 +67,7 @@ function () {
87
67
  case 0:
88
68
  return [4
89
69
  /*yield*/
90
- , this.renderingService.hooks.pick.promise({
70
+ , this.renderingService.hooks.pick.callPromise({
91
71
  position: position,
92
72
  picked: [],
93
73
  topmost: true // we only concern the topmost element
@@ -103,21 +83,19 @@ function () {
103
83
  });
104
84
  });
105
85
  });
106
- renderingService.hooks.pointerWheel.tap(EventPlugin_1.tag, function (nativeEvent) {
86
+ renderingService.hooks.pointerWheel.tap(function (nativeEvent) {
107
87
  var wheelEvent = _this.normalizeWheelEvent(nativeEvent);
108
88
 
109
89
  _this.eventService.mapEvent(wheelEvent);
110
90
  });
111
- renderingService.hooks.pointerDown.tap(EventPlugin_1.tag, function (nativeEvent) {
112
- var e_2, _a;
113
-
91
+ renderingService.hooks.pointerDown.tap(function (nativeEvent) {
114
92
  if (canvas.supportTouchEvent && nativeEvent.pointerType === 'touch') {
115
93
  return;
116
94
  }
117
95
 
118
- var events = _this.normalizeToPointerEvent(nativeEvent, canvas);
96
+ var normalizedEvent = _this.normalizeToPointerEvent(nativeEvent, canvas);
119
97
 
120
- if (_this.autoPreventDefault && events[0].isNormalized) {
98
+ if (_this.autoPreventDefault && normalizedEvent.isNormalized) {
121
99
  var cancelable = nativeEvent.cancelable || !('cancelable' in nativeEvent);
122
100
 
123
101
  if (cancelable) {
@@ -125,31 +103,13 @@ function () {
125
103
  }
126
104
  }
127
105
 
128
- try {
129
- for (var events_1 = (0, _tslib.__values)(events), events_1_1 = events_1.next(); !events_1_1.done; events_1_1 = events_1.next()) {
130
- var event_2 = events_1_1.value;
106
+ var federatedEvent = _this.bootstrapEvent(_this.rootPointerEvent, normalizedEvent, canvas);
131
107
 
132
- var federatedEvent = _this.bootstrapEvent(_this.rootPointerEvent, event_2, canvas);
133
-
134
- _this.eventService.mapEvent(federatedEvent);
135
- }
136
- } catch (e_2_1) {
137
- e_2 = {
138
- error: e_2_1
139
- };
140
- } finally {
141
- try {
142
- if (events_1_1 && !events_1_1.done && (_a = events_1.return)) _a.call(events_1);
143
- } finally {
144
- if (e_2) throw e_2.error;
145
- }
146
- }
108
+ _this.eventService.mapEvent(federatedEvent);
147
109
 
148
110
  _this.setCursor(_this.eventService.cursor);
149
111
  });
150
- renderingService.hooks.pointerUp.tap(EventPlugin_1.tag, function (nativeEvent) {
151
- var e_3, _a;
152
-
112
+ renderingService.hooks.pointerUp.tap(function (nativeEvent) {
153
113
  if (canvas.supportTouchEvent && nativeEvent.pointerType === 'touch') return; // account for element in SVG
154
114
 
155
115
  var $element = _this.contextService.getDomElement();
@@ -158,83 +118,167 @@ function () {
158
118
  $element.contains && // @ts-ignore
159
119
  !$element.contains(nativeEvent.target) ? 'outside' : '';
160
120
 
161
- var normalizedEvents = _this.normalizeToPointerEvent(nativeEvent, canvas);
121
+ var normalizedEvent = _this.normalizeToPointerEvent(nativeEvent, canvas);
162
122
 
163
- try {
164
- for (var normalizedEvents_2 = (0, _tslib.__values)(normalizedEvents), normalizedEvents_2_1 = normalizedEvents_2.next(); !normalizedEvents_2_1.done; normalizedEvents_2_1 = normalizedEvents_2.next()) {
165
- var normalizedEvent = normalizedEvents_2_1.value;
123
+ var event = _this.bootstrapEvent(_this.rootPointerEvent, normalizedEvent, canvas);
166
124
 
167
- var event_3 = _this.bootstrapEvent(_this.rootPointerEvent, normalizedEvent, canvas);
125
+ event.type += outside;
168
126
 
169
- event_3.type += outside;
127
+ _this.eventService.mapEvent(event);
170
128
 
171
- _this.eventService.mapEvent(event_3);
172
- }
173
- } catch (e_3_1) {
174
- e_3 = {
175
- error: e_3_1
176
- };
177
- } finally {
178
- try {
179
- if (normalizedEvents_2_1 && !normalizedEvents_2_1.done && (_a = normalizedEvents_2.return)) _a.call(normalizedEvents_2);
180
- } finally {
181
- if (e_3) throw e_3.error;
129
+ _this.setCursor(_this.eventService.cursor);
130
+ });
131
+ renderingService.hooks.pointerMove.tap(this.onPointerMove);
132
+ renderingService.hooks.pointerOver.tap(this.onPointerMove);
133
+ renderingService.hooks.pointerOut.tap(this.onPointerMove);
134
+ renderingService.hooks.pointerCancel.tap(function (nativeEvent) {
135
+ if (canvas.supportTouchEvent && nativeEvent.pointerType === 'touch') {
136
+ return;
137
+ }
138
+
139
+ var normalizedEvent = _this.normalizeToPointerEvent(nativeEvent, canvas);
140
+
141
+ if (_this.autoPreventDefault && normalizedEvent.isNormalized) {
142
+ var cancelable = nativeEvent.cancelable || !('cancelable' in nativeEvent);
143
+
144
+ if (cancelable) {
145
+ nativeEvent.preventDefault();
182
146
  }
183
147
  }
184
148
 
149
+ var federatedEvent = _this.bootstrapEvent(_this.rootPointerEvent, normalizedEvent, canvas);
150
+
151
+ _this.eventService.mapEvent(federatedEvent);
152
+
185
153
  _this.setCursor(_this.eventService.cursor);
186
154
  });
187
- renderingService.hooks.pointerMove.tap(EventPlugin_1.tag, this.onPointerMove);
188
- renderingService.hooks.pointerOver.tap(EventPlugin_1.tag, this.onPointerMove);
189
- renderingService.hooks.pointerOut.tap(EventPlugin_1.tag, this.onPointerMove);
190
155
  };
191
156
 
192
- EventPlugin.prototype.bootstrapEvent = function (event, nativeEvent, view) {
193
- event.view = view;
194
- event.originalEvent = null;
195
- event.nativeEvent = nativeEvent;
196
- event.pointerId = nativeEvent.pointerId;
197
- event.width = nativeEvent.width;
198
- event.height = nativeEvent.height;
199
- event.isPrimary = nativeEvent.isPrimary;
200
- event.pointerType = nativeEvent.pointerType;
201
- event.pressure = nativeEvent.pressure;
202
- event.tangentialPressure = nativeEvent.tangentialPressure;
203
- event.tiltX = nativeEvent.tiltX;
204
- event.tiltY = nativeEvent.tiltY;
205
- event.twist = nativeEvent.twist;
206
- this.transferMouseData(event, nativeEvent);
157
+ EventPlugin.prototype.formatTouch = function (touch) {
158
+ var formattedTouch = {
159
+ nativeTouch: touch,
160
+ clientX: touch.clientX,
161
+ clientY: touch.clientY,
162
+ screenX: touch.screenX,
163
+ screenY: touch.screenY,
164
+ viewportX: 0,
165
+ viewportY: 0,
166
+ canvasX: 0,
167
+ canvasY: 0,
168
+ x: 0,
169
+ y: 0,
170
+ target: undefined,
171
+ force: touch.force,
172
+ identifier: touch.identifier,
173
+ pageX: touch.pageX,
174
+ pageY: touch.pageY,
175
+ radiusX: touch.radiusX,
176
+ radiusY: touch.radiusY,
177
+ rotationAngle: touch.rotationAngle
178
+ };
207
179
 
208
- var _a = this.eventService.client2Viewport(new _shapes.Point(nativeEvent.clientX, nativeEvent.clientY)),
180
+ var _a = this.eventService.client2Viewport(new _shapes.Point(touch.clientX, touch.clientY)),
209
181
  x = _a.x,
210
182
  y = _a.y;
211
183
 
212
- event.viewport.x = x;
213
- event.viewport.y = y;
184
+ formattedTouch.viewportX = x;
185
+ formattedTouch.viewportY = y;
214
186
 
215
- var _b = this.eventService.viewport2Canvas(event.viewport),
187
+ var _b = this.eventService.viewport2Canvas({
188
+ x: x,
189
+ y: y
190
+ }),
216
191
  canvasX = _b.x,
217
192
  canvasY = _b.y;
218
193
 
219
- event.canvas.x = canvasX;
220
- event.canvas.y = canvasY;
221
- event.global.copyFrom(event.canvas);
222
- event.offset.copyFrom(event.canvas);
223
- event.isTrusted = nativeEvent.isTrusted;
194
+ formattedTouch.canvasX = canvasX;
195
+ formattedTouch.canvasY = canvasY;
196
+ formattedTouch.x = canvasX;
197
+ formattedTouch.y = canvasY;
198
+ return formattedTouch;
199
+ };
224
200
 
225
- if (event.type === 'pointerleave') {
226
- event.type = 'pointerout';
227
- }
201
+ EventPlugin.prototype.bootstrapEvent = function (e, nativeEvent, view) {
202
+ e.pointerType = nativeEvent.pointerType;
203
+
204
+ if (e.pointerType !== 'touch') {
205
+ var event_1 = e;
206
+ event_1.view = view;
207
+ event_1.originalEvent = null;
208
+ event_1.nativeEvent = nativeEvent;
209
+ event_1.pointerId = nativeEvent.pointerId;
210
+ event_1.width = nativeEvent.width;
211
+ event_1.height = nativeEvent.height;
212
+ event_1.isPrimary = nativeEvent.isPrimary;
213
+ event_1.pressure = nativeEvent.pressure;
214
+ event_1.tangentialPressure = nativeEvent.tangentialPressure;
215
+ event_1.tiltX = nativeEvent.tiltX;
216
+ event_1.tiltY = nativeEvent.tiltY;
217
+ event_1.twist = nativeEvent.twist;
218
+ this.transferMouseData(event_1, nativeEvent);
219
+
220
+ var _a = this.eventService.client2Viewport(new _shapes.Point(nativeEvent.clientX, nativeEvent.clientY)),
221
+ x = _a.x,
222
+ y = _a.y;
223
+
224
+ event_1.viewport.x = x;
225
+ event_1.viewport.y = y;
226
+
227
+ var _b = this.eventService.viewport2Canvas(event_1.viewport),
228
+ canvasX = _b.x,
229
+ canvasY = _b.y;
230
+
231
+ event_1.canvas.x = canvasX;
232
+ event_1.canvas.y = canvasY;
233
+ event_1.global.copyFrom(event_1.canvas);
234
+ event_1.offset.copyFrom(event_1.canvas);
235
+ event_1.isTrusted = nativeEvent.isTrusted;
236
+
237
+ if (event_1.type === 'pointerleave') {
238
+ event_1.type = 'pointerout';
239
+ }
228
240
 
229
- if (event.type.startsWith('mouse')) {
230
- event.type = event.type.replace('mouse', 'pointer');
231
- }
241
+ if (event_1.type.startsWith('mouse')) {
242
+ event_1.type = event_1.type.replace('mouse', 'pointer');
243
+ } // if (event.type.startsWith('touch')) {
244
+ // event.type = TOUCH_TO_POINTER[event.type] || event.type;
245
+ // }
246
+
247
+ } else {
248
+ var event_2 = e; // handle TouchEvent
249
+
250
+ var ne = nativeEvent;
251
+ var changedTouches = [];
252
+ var touches = [];
253
+
254
+ if (ne.changedTouches) {
255
+ for (var i = 0; i < ne.changedTouches.length; i++) {
256
+ changedTouches.push(this.formatTouch(ne.changedTouches[i]));
257
+ }
258
+ }
232
259
 
233
- if (event.type.startsWith('touch')) {
234
- event.type = _event.TOUCH_TO_POINTER[event.type] || event.type;
260
+ if (ne.touches) {
261
+ for (var i = 0; i < ne.touches.length; i++) {
262
+ touches.push(this.formatTouch(ne.touches[i]));
263
+ }
264
+ }
265
+
266
+ event_2.nativeEvent = nativeEvent;
267
+ event_2.isTrusted = nativeEvent.isTrusted;
268
+ event_2.timeStamp = performance.now();
269
+ event_2.type = nativeEvent.type; // @see https://w3c.github.io/touch-events/#touchevent-interface
270
+
271
+ event_2.altKey = nativeEvent.altKey;
272
+ event_2.metaKey = nativeEvent.metaKey;
273
+ event_2.shiftKey = nativeEvent.shiftKey;
274
+ event_2.ctrlKey = nativeEvent.ctrlKey; // copy raw touches
275
+
276
+ event_2.changedTouches = changedTouches;
277
+ event_2.touches = touches;
278
+ event_2.targetTouches = [];
235
279
  }
236
280
 
237
- return event;
281
+ return e;
238
282
  };
239
283
 
240
284
  EventPlugin.prototype.normalizeWheelEvent = function (nativeEvent) {
@@ -274,12 +318,13 @@ function () {
274
318
  event.timeStamp = performance.now();
275
319
  event.type = nativeEvent.type;
276
320
  event.altKey = nativeEvent.altKey;
321
+ event.metaKey = nativeEvent.metaKey;
322
+ event.shiftKey = nativeEvent.shiftKey;
323
+ event.ctrlKey = nativeEvent.ctrlKey;
277
324
  event.button = nativeEvent.button;
278
325
  event.buttons = nativeEvent.buttons;
279
326
  event.client.x = nativeEvent.clientX;
280
327
  event.client.y = nativeEvent.clientY;
281
- event.ctrlKey = nativeEvent.ctrlKey;
282
- event.metaKey = nativeEvent.metaKey;
283
328
  event.movement.x = nativeEvent.movementX;
284
329
  event.movement.y = nativeEvent.movementY;
285
330
  event.page.x = nativeEvent.pageX;
@@ -294,66 +339,37 @@ function () {
294
339
  };
295
340
 
296
341
  EventPlugin.prototype.normalizeToPointerEvent = function (event, canvas) {
297
- var normalizedEvents = [];
298
-
299
342
  if (canvas.isTouchEvent(event)) {
300
- for (var i = 0; i < event.changedTouches.length; i++) {
301
- var touch = event.changedTouches[i]; // use changedTouches instead of touches since touchend has no touches
302
- // @see https://stackoverflow.com/a/10079076
303
-
304
- if ((0, _lodashEs.isUndefined)(touch.button)) touch.button = event.touches.length ? 1 : 0;
305
- if ((0, _lodashEs.isUndefined)(touch.buttons)) touch.buttons = event.touches.length ? 1 : 0;
343
+ // @ts-ignore
344
+ event.isNormalized = true; // @ts-ignore
306
345
 
307
- if ((0, _lodashEs.isUndefined)(touch.isPrimary)) {
308
- touch.isPrimary = event.touches.length === 1 && event.type === 'touchstart';
309
- }
310
-
311
- if ((0, _lodashEs.isUndefined)(touch.width)) touch.width = touch.radiusX || 1;
312
- if ((0, _lodashEs.isUndefined)(touch.height)) touch.height = touch.radiusY || 1;
313
- if ((0, _lodashEs.isUndefined)(touch.tiltX)) touch.tiltX = 0;
314
- if ((0, _lodashEs.isUndefined)(touch.tiltY)) touch.tiltY = 0;
315
- if ((0, _lodashEs.isUndefined)(touch.pointerType)) touch.pointerType = 'touch'; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Touch/identifier
316
-
317
- if ((0, _lodashEs.isUndefined)(touch.pointerId)) touch.pointerId = touch.identifier || 0;
318
- if ((0, _lodashEs.isUndefined)(touch.pressure)) touch.pressure = touch.force || 0.5;
319
- if ((0, _lodashEs.isUndefined)(touch.twist)) touch.twist = 0;
320
- if ((0, _lodashEs.isUndefined)(touch.tangentialPressure)) touch.tangentialPressure = 0;
321
- touch.isNormalized = true;
322
- touch.type = event.type; // ref to nativeEvent
323
- // touch.nativeEvent = event;
324
- // touch.isLast = event.changedTouches.length - 1 === i;
325
-
326
- normalizedEvents.push(touch);
327
- }
346
+ event.pointerType = 'touch';
347
+ return event;
328
348
  } else if (canvas.isMouseEvent(event)) {
329
349
  var tempEvent = event;
330
- if ((0, _lodashEs.isUndefined)(tempEvent.isPrimary)) tempEvent.isPrimary = true;
331
- if ((0, _lodashEs.isUndefined)(tempEvent.width)) tempEvent.width = 1;
332
- if ((0, _lodashEs.isUndefined)(tempEvent.height)) tempEvent.height = 1;
333
- if ((0, _lodashEs.isUndefined)(tempEvent.tiltX)) tempEvent.tiltX = 0;
334
- if ((0, _lodashEs.isUndefined)(tempEvent.tiltY)) tempEvent.tiltY = 0;
335
- if ((0, _lodashEs.isUndefined)(tempEvent.pointerType)) tempEvent.pointerType = 'mouse';
336
- if ((0, _lodashEs.isUndefined)(tempEvent.pointerId)) tempEvent.pointerId = _event.MOUSE_POINTER_ID;
337
- if ((0, _lodashEs.isUndefined)(tempEvent.pressure)) tempEvent.pressure = 0.5;
338
- if ((0, _lodashEs.isUndefined)(tempEvent.twist)) tempEvent.twist = 0;
339
- if ((0, _lodashEs.isUndefined)(tempEvent.tangentialPressure)) tempEvent.tangentialPressure = 0;
350
+ if ((0, _utils.isUndefined)(tempEvent.isPrimary)) tempEvent.isPrimary = true;
351
+ if ((0, _utils.isUndefined)(tempEvent.width)) tempEvent.width = 1;
352
+ if ((0, _utils.isUndefined)(tempEvent.height)) tempEvent.height = 1;
353
+ if ((0, _utils.isUndefined)(tempEvent.tiltX)) tempEvent.tiltX = 0;
354
+ if ((0, _utils.isUndefined)(tempEvent.tiltY)) tempEvent.tiltY = 0;
355
+ if ((0, _utils.isUndefined)(tempEvent.pointerType)) tempEvent.pointerType = 'mouse';
356
+ if ((0, _utils.isUndefined)(tempEvent.pointerId)) tempEvent.pointerId = _event.MOUSE_POINTER_ID;
357
+ if ((0, _utils.isUndefined)(tempEvent.pressure)) tempEvent.pressure = 0.5;
358
+ if ((0, _utils.isUndefined)(tempEvent.twist)) tempEvent.twist = 0;
359
+ if ((0, _utils.isUndefined)(tempEvent.tangentialPressure)) tempEvent.tangentialPressure = 0;
340
360
  tempEvent.isNormalized = true;
341
- normalizedEvents.push(tempEvent);
361
+ return tempEvent;
342
362
  } else {
343
- normalizedEvents.push(event);
363
+ return event;
344
364
  }
345
-
346
- return normalizedEvents;
347
365
  };
348
366
 
349
- var EventPlugin_1;
350
- EventPlugin.tag = 'EventPlugin';
351
367
  (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_types.CanvasConfig), (0, _tslib.__metadata)("design:type", Object)], EventPlugin.prototype, "canvasConfig", void 0);
352
368
  (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_services.ContextService), (0, _tslib.__metadata)("design:type", Object)], EventPlugin.prototype, "contextService", void 0);
353
369
  (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_services.RenderingService), (0, _tslib.__metadata)("design:type", _services.RenderingService)], EventPlugin.prototype, "renderingService", void 0);
354
370
  (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_services.RenderingContext), (0, _tslib.__metadata)("design:type", Object)], EventPlugin.prototype, "renderingContext", void 0);
355
371
  (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_services.EventService), (0, _tslib.__metadata)("design:type", _services.EventService)], EventPlugin.prototype, "eventService", void 0);
356
- EventPlugin = EventPlugin_1 = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
372
+ EventPlugin = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
357
373
  contrib: _services.RenderingPluginContribution
358
374
  })], EventPlugin);
359
375
  return EventPlugin;
@@ -1,6 +1,5 @@
1
1
  import type { RenderingService, RenderingPlugin } from '../services';
2
2
  export declare class PrepareRendererPlugin implements RenderingPlugin {
3
- static tag: string;
4
3
  private renderingContext;
5
4
  private styleValueRegistry;
6
5
  apply(renderingService: RenderingService): void;
@@ -20,8 +20,6 @@ var PrepareRendererPlugin =
20
20
  function () {
21
21
  function PrepareRendererPlugin() {}
22
22
 
23
- PrepareRendererPlugin_1 = PrepareRendererPlugin;
24
-
25
23
  PrepareRendererPlugin.prototype.apply = function (renderingService) {
26
24
  var _this = this;
27
25
 
@@ -50,16 +48,20 @@ function () {
50
48
  renderingService.dirtify();
51
49
  };
52
50
 
53
- renderingService.hooks.init.tap(PrepareRendererPlugin_1.tag, function () {
54
- _this.renderingContext.root.addEventListener(_dom.ElementEvent.MOUNTED, handleMounted);
55
-
56
- _this.renderingContext.root.addEventListener(_dom.ElementEvent.UNMOUNTED, handleUnmounted);
57
-
58
- _this.renderingContext.root.addEventListener(_dom.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
59
-
60
- _this.renderingContext.root.addEventListener(_dom.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
51
+ renderingService.hooks.init.tapPromise(function () {
52
+ return (0, _tslib.__awaiter)(_this, void 0, void 0, function () {
53
+ return (0, _tslib.__generator)(this, function (_a) {
54
+ this.renderingContext.root.addEventListener(_dom.ElementEvent.MOUNTED, handleMounted);
55
+ this.renderingContext.root.addEventListener(_dom.ElementEvent.UNMOUNTED, handleUnmounted);
56
+ this.renderingContext.root.addEventListener(_dom.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
57
+ this.renderingContext.root.addEventListener(_dom.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
58
+ return [2
59
+ /*return*/
60
+ ];
61
+ });
62
+ });
61
63
  });
62
- renderingService.hooks.destroy.tap(PrepareRendererPlugin_1.tag, function () {
64
+ renderingService.hooks.destroy.tap(function () {
63
65
  _this.renderingContext.root.removeEventListener(_dom.ElementEvent.MOUNTED, handleMounted);
64
66
 
65
67
  _this.renderingContext.root.removeEventListener(_dom.ElementEvent.UNMOUNTED, handleUnmounted);
@@ -70,11 +72,9 @@ function () {
70
72
  });
71
73
  };
72
74
 
73
- var PrepareRendererPlugin_1;
74
- PrepareRendererPlugin.tag = 'PrepareRendererPlugin';
75
75
  (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_services.RenderingContext), (0, _tslib.__metadata)("design:type", Object)], PrepareRendererPlugin.prototype, "renderingContext", void 0);
76
76
  (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_css.StyleValueRegistry), (0, _tslib.__metadata)("design:type", _css.StyleValueRegistry)], PrepareRendererPlugin.prototype, "styleValueRegistry", void 0);
77
- PrepareRendererPlugin = PrepareRendererPlugin_1 = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
77
+ PrepareRendererPlugin = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
78
78
  contrib: _services.RenderingPluginContribution
79
79
  })], PrepareRendererPlugin);
80
80
  return PrepareRendererPlugin;
@@ -32,6 +32,11 @@ export declare class EventService extends EventEmitter {
32
32
  setPickHandler(pickHandler: Picker): void;
33
33
  addEventMapping(type: string, fn: (e: FederatedEvent) => Promise<void>): void;
34
34
  mapEvent(e: FederatedEvent): void;
35
+ private handleTouchEvent;
36
+ onTouchStart: (from: FederatedEvent) => Promise<void>;
37
+ onTouchMove: (from: FederatedEvent) => Promise<void>;
38
+ onTouchEnd: (from: FederatedEvent) => Promise<void>;
39
+ onTouchCancel: (from: FederatedEvent) => Promise<void>;
35
40
  onPointerDown: (from: FederatedEvent) => Promise<void>;
36
41
  onPointerUp: (from: FederatedEvent) => Promise<void>;
37
42
  onPointerMove: (from: FederatedEvent) => Promise<void>;
@@ -44,12 +49,15 @@ export declare class EventService extends EventEmitter {
44
49
  propagationPath(target: IEventTarget): IEventTarget[];
45
50
  hitTest(position: EventPosition): Promise<IEventTarget | null>;
46
51
  private isNativeEventFromCanvas;
52
+ private pickTarget;
47
53
  private createPointerEvent;
54
+ private createTouchEvent;
48
55
  private createWheelEvent;
49
56
  private trackingData;
50
57
  private clonePointerEvent;
51
58
  private copyPointerData;
52
59
  private copyMouseData;
60
+ private copyTouchData;
53
61
  private copyWheelData;
54
62
  private copyData;
55
63
  private allocateEvent;