@antv/g 5.0.22 → 5.0.23-alpha.0

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