@nativescript/canvas 1.0.0-alpha.8 → 1.0.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 (95) hide show
  1. package/Canvas/common.d.ts +34 -14
  2. package/Canvas/common.js +413 -202
  3. package/Canvas/common.js.map +1 -1
  4. package/Canvas/index.android.d.ts +2 -0
  5. package/Canvas/index.android.js +8 -7
  6. package/Canvas/index.android.js.map +1 -1
  7. package/Canvas/index.d.ts +14 -0
  8. package/Canvas/index.ios.d.ts +1 -0
  9. package/Canvas/index.ios.js +1 -2
  10. package/Canvas/index.ios.js.map +1 -1
  11. package/Canvas2D/CanvasGradient/CanvasGradient.android.js.map +1 -1
  12. package/Canvas2D/CanvasRenderingContext2D/index.android.js +6 -0
  13. package/Canvas2D/CanvasRenderingContext2D/index.android.js.map +1 -1
  14. package/Canvas2D/CanvasRenderingContext2D/index.ios.js +9 -0
  15. package/Canvas2D/CanvasRenderingContext2D/index.ios.js.map +1 -1
  16. package/Canvas2D/DOMMatrix/common.d.ts +1 -0
  17. package/Canvas2D/DOMMatrix/common.js +4 -0
  18. package/Canvas2D/DOMMatrix/common.js.map +1 -1
  19. package/Canvas2D/ImageData/common.d.ts +1 -0
  20. package/Canvas2D/ImageData/common.js +4 -0
  21. package/Canvas2D/ImageData/common.js.map +1 -1
  22. package/Canvas2D/Path2D/common.d.ts +1 -0
  23. package/Canvas2D/Path2D/common.js +4 -0
  24. package/Canvas2D/Path2D/common.js.map +1 -1
  25. package/Canvas2D/TextMetrics/common.d.ts +1 -0
  26. package/Canvas2D/TextMetrics/common.js +4 -0
  27. package/Canvas2D/TextMetrics/common.js.map +1 -1
  28. package/ImageAsset/common.d.ts +1 -0
  29. package/ImageAsset/common.js +4 -0
  30. package/ImageAsset/common.js.map +1 -1
  31. package/ImageBitmap/common.d.ts +1 -0
  32. package/ImageBitmap/common.js +4 -0
  33. package/ImageBitmap/common.js.map +1 -1
  34. package/TextDecoder/common.d.ts +1 -0
  35. package/TextDecoder/common.js +4 -0
  36. package/TextDecoder/common.js.map +1 -1
  37. package/TextEncoder/common.d.ts +1 -0
  38. package/TextEncoder/common.js +4 -0
  39. package/TextEncoder/common.js.map +1 -1
  40. package/WebGL/WebGLRenderingContext/index.android.js +4 -1
  41. package/WebGL/WebGLRenderingContext/index.android.js.map +1 -1
  42. package/WebGL/WebGLRenderingContext/index.ios.js +2 -2
  43. package/WebGL/WebGLRenderingContext/index.ios.js.map +1 -1
  44. package/WebGL2/WebGL2RenderingContext/index.android.js +2 -2
  45. package/WebGL2/WebGL2RenderingContext/index.android.js.map +1 -1
  46. package/WebGL2/WebGL2RenderingContext/index.ios.js +25 -15
  47. package/WebGL2/WebGL2RenderingContext/index.ios.js.map +1 -1
  48. package/angular/bundles/nativescript-canvas-angular.umd.js.map +1 -1
  49. package/angular/fesm2015/nativescript-canvas-angular.js.map +1 -1
  50. package/index.d.ts +2 -1
  51. package/index.js +17 -7
  52. package/index.js.map +1 -1
  53. package/package.json +1 -2
  54. package/platforms/android/include.gradle +1 -1
  55. package/platforms/ios/CanvasNative.xcframework/Info.plist +44 -0
  56. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
  57. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative-Swift.h +1996 -0
  58. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative.h +21 -0
  59. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/Utils.h +26 -0
  60. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +1592 -0
  61. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Info.plist +0 -0
  62. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
  63. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64.swiftsourceinfo +0 -0
  64. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  65. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +3257 -0
  66. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64.swiftdoc +0 -0
  67. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64.swiftinterface +3257 -0
  68. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/module.modulemap +11 -0
  69. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/TNSCanvas.nib +0 -0
  70. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Info.plist +20 -0
  71. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  72. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
  73. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative-Swift.h +3998 -0
  74. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative.h +21 -0
  75. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/Utils.h +26 -0
  76. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +1592 -0
  77. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Info.plist +0 -0
  78. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
  79. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64.swiftsourceinfo +0 -0
  80. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64-apple-ios-simulator.swiftsourceinfo +0 -0
  81. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64.swiftsourceinfo +0 -0
  82. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  83. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +3257 -0
  84. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64.swiftdoc +0 -0
  85. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64.swiftinterface +3257 -0
  86. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  87. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +3257 -0
  88. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64.swiftdoc +0 -0
  89. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64.swiftinterface +3257 -0
  90. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/module.modulemap +11 -0
  91. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/TNSCanvas.nib +0 -0
  92. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +344 -0
  93. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Info.plist +20 -0
  94. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  95. package/platforms/ios/Podfile +1 -1
package/Canvas/common.js CHANGED
@@ -8,14 +8,37 @@ var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
10
  import { CSSType, PercentLength, View, Screen, GestureStateTypes, Utils, Application, Property, booleanConverter } from '@nativescript/core';
11
- import { TouchList } from '../common';
12
- const WEB_GESTURE_EVENTS = ['touchmove', 'touchstart', 'touchcancel', 'touchend'];
11
+ export class TouchEvent {
12
+ constructor(name, init) {
13
+ this.type = name;
14
+ if (init && typeof init === 'object') {
15
+ Object.keys(init).forEach(key => {
16
+ this[key] = init[key];
17
+ });
18
+ }
19
+ }
20
+ preventDefault() { }
21
+ stopPropagation() { }
22
+ }
23
+ export class PointerEvent {
24
+ constructor(name, init) {
25
+ this.type = name;
26
+ if (init && typeof init === 'object') {
27
+ Object.keys(init).forEach(key => {
28
+ this[key] = init[key];
29
+ });
30
+ }
31
+ }
32
+ preventDefault() { }
33
+ stopPropagation() { }
34
+ }
35
+ const WEB_GESTURE_EVENTS = ['touchmove', 'touchstart', 'touchcancel', 'touchend', 'change', 'pointerup', 'pointerdown', 'pointermove', 'pointercancel'];
13
36
  export const ignorePixelScalingProperty = new Property({
14
37
  name: 'ignorePixelScaling',
15
38
  defaultValue: false,
16
39
  valueConverter: booleanConverter
17
40
  });
18
- import { observe as gestureObserve } from '@nativescript-community/gesturehandler/gestures_override';
41
+ let pointerId = 0;
19
42
  let CanvasBase = class CanvasBase extends View {
20
43
  constructor() {
21
44
  super();
@@ -25,31 +48,10 @@ let CanvasBase = class CanvasBase extends View {
25
48
  this._previousX = 0;
26
49
  this._previousY = 0;
27
50
  this._previousPinchDistance = 0;
51
+ this._previousPointerCount = 0;
52
+ this._pointers = [];
28
53
  this._classList = new Set();
29
54
  }
30
- __ensureGestures() {
31
- if (!this._gesturesRegistered) {
32
- this._gesturesRegistered = true;
33
- this.on('touch, pan, pinch', this._touchEvent, this);
34
- }
35
- }
36
- __unregisterGestures() {
37
- if (this._gesturesRegistered) {
38
- this._gesturesRegistered = false;
39
- this.off('touch, pan, pinch', this._touchEvent, this);
40
- }
41
- }
42
- _observe(type, callback, thisArg) {
43
- if (!this._gestureObservers[type]) {
44
- this._gestureObservers[type] = [];
45
- }
46
- this._gestureObservers[type].push(gestureObserve(this, type, callback, thisArg));
47
- if (global.isAndroid) {
48
- if (this.isLoaded && !this.touchListenerIsSet) {
49
- this.setOnTouchListener();
50
- }
51
- }
52
- }
53
55
  addEventListener(arg, callback, thisArg) {
54
56
  super.addEventListener(arg, callback, thisArg);
55
57
  if (WEB_GESTURE_EVENTS.indexOf(arg) !== -1) {
@@ -125,182 +127,6 @@ let CanvasBase = class CanvasBase extends View {
125
127
  }
126
128
  return null;
127
129
  }
128
- _touchEvent(event) {
129
- if (event.eventName === 'touch') {
130
- switch (event.action) {
131
- case 'down':
132
- // ensure we dont have multiple touchstart
133
- // on the web seems to be called only on first touch
134
- if (!this.__touchStart) {
135
- this.__touchStart = event.getActivePointers()[0];
136
- this._emitEvent('touchstart', event);
137
- }
138
- break;
139
- case 'up':
140
- if (event.getPointerCount() === 1 && this.__touchStart) {
141
- this._emitEvent('touchend', event);
142
- this._isPinching = false;
143
- this.__touchStart = undefined;
144
- }
145
- break;
146
- case 'cancel':
147
- this._emitEvent('touchcancel', event);
148
- this.__touchStart = undefined;
149
- break;
150
- case 'move':
151
- // NOOP
152
- break;
153
- default:
154
- break;
155
- }
156
- }
157
- else if (event.eventName === 'pinch') {
158
- if (!this._isPinching && event.getPointerCount() >= 2 && (event.state === GestureStateTypes.began || event.state === GestureStateTypes.changed)) {
159
- this._previousPinchDistance = 0;
160
- this._isPinching = true;
161
- }
162
- if (this._isPinching) {
163
- this._emitEvent('touchmove:pinch', event);
164
- }
165
- if (event.state === GestureStateTypes.ended || event.state === GestureStateTypes.cancelled) {
166
- this._isPinching = false;
167
- }
168
- }
169
- else if (event.eventName === 'pan') {
170
- if (this._isPinching) {
171
- return;
172
- }
173
- if (event.state === GestureStateTypes.began || event.state === GestureStateTypes.changed) {
174
- this._emitEvent('touchmove', event);
175
- }
176
- }
177
- }
178
- _getTouchEvent(name, event, target) {
179
- const pointers = new TouchList();
180
- let scale = 1;
181
- let activePointer;
182
- if (name === 'touchmove') {
183
- name = 'touchmove';
184
- activePointer = {
185
- clientX: event.getX() * scale,
186
- clientY: event.getY() * scale,
187
- force: 0.0,
188
- identifier: 0,
189
- pageX: event.getX() * scale,
190
- pageY: event.getY() * scale,
191
- radiusX: 0,
192
- radiusY: 0,
193
- rotationAngle: 0,
194
- screenX: event.getX() * scale,
195
- screenY: event.getY() * scale,
196
- target
197
- };
198
- const count = event.getAllPointers().length;
199
- for (let i = 0; i < count; i++) {
200
- const point = event.getAllPointers()[i];
201
- pointers.push({
202
- clientX: point.getX(),
203
- clientY: point.getY(),
204
- force: 0.0,
205
- identifier: i,
206
- pageX: point.getX(),
207
- pageY: point.getY(),
208
- radiusX: 0,
209
- radiusY: 0,
210
- rotationAngle: 0,
211
- screenX: point.getX(),
212
- screenY: point.getY(),
213
- target,
214
- });
215
- }
216
- /* mouse */
217
- // pointers.push({
218
- // // * SCALE ??
219
- // clientX: x,
220
- // clientY: y,
221
- // force: 0.0,
222
- // identifier: 0,
223
- // pageX: x,
224
- // pageY: y,
225
- // radiusX: 0,
226
- // radiusY: 0,
227
- // rotationAngle: 0,
228
- // screenX: x,
229
- // screenY: y,
230
- // target,
231
- // });
232
- this._previousX = event.deltaX;
233
- this._previousY = event.deltaY;
234
- }
235
- else if (name === 'touchmove:pinch') {
236
- const dx = event.extraData.positions[2] - event.extraData.positions[0];
237
- const dy = event.extraData.positions[3] - event.extraData.positions[1];
238
- let delta = 0;
239
- var distance = Math.sqrt(dx * dx + dy * dy);
240
- if (this._previousPinchDistance) {
241
- delta = this._previousPinchDistance - distance;
242
- }
243
- this._previousPinchDistance = distance;
244
- name = 'wheel';
245
- const x = event.getFocusX();
246
- const y = event.getFocusY();
247
- const scale = event.scale;
248
- // mouse event
249
- let data = {
250
- deltaMode: 0,
251
- clientX: x,
252
- clientY: y,
253
- screenX: x,
254
- screenY: x,
255
- deltaX: 0,
256
- deltaY: delta,
257
- deltaZ: 0,
258
- };
259
- return Object.assign(new TouchEvent(name), { eventName: name, object: null, defaultPrevented: false, cancelable: false, altKey: false, ctrlKey: true, metaKey: false, shiftKey: false, target }, data);
260
- }
261
- else {
262
- const count = event.getAllPointers().length;
263
- const point = event.getActivePointers()[0];
264
- if (!point) {
265
- return null;
266
- }
267
- // mouse event
268
- activePointer = {
269
- clientX: point.getX() * scale,
270
- clientY: point.getY() * scale,
271
- force: 0.0,
272
- identifier: 0,
273
- pageX: point.getX() * scale,
274
- pageY: point.getY() * scale,
275
- radiusX: 0,
276
- radiusY: 0,
277
- rotationAngle: 0,
278
- screenX: point.getX() * scale,
279
- screenY: point.getY() * scale,
280
- };
281
- for (let i = 0; i < count; i++) {
282
- const point = event.getAllPointers()[i];
283
- pointers.push({
284
- clientX: point.getX(),
285
- clientY: point.getY(),
286
- force: 0.0,
287
- identifier: i,
288
- pageX: point.getX(),
289
- pageY: point.getY(),
290
- radiusX: 0,
291
- radiusY: 0,
292
- rotationAngle: 0,
293
- screenX: point.getX(),
294
- screenY: point.getY(),
295
- target,
296
- });
297
- }
298
- }
299
- return Object.assign(new TouchEvent(name), Object.assign({ eventName: name, defaultPrevented: false, cancelable: false, altKey: false, changedTouches: pointers, ctrlKey: false, metaKey: false, shiftKey: false, targetTouches: pointers, touches: pointers, target }, activePointer));
300
- }
301
- _emitEvent(name, event) {
302
- this.notify(this._getTouchEvent(name, event, this));
303
- }
304
130
  _readyEvent() {
305
131
  this.notify({
306
132
  eventName: 'ready',
@@ -368,6 +194,391 @@ let CanvasBase = class CanvasBase extends View {
368
194
  return 0;
369
195
  }
370
196
  }
197
+ setPointerCapture() { }
198
+ releasePointerCapture() { }
199
+ __ensureGestures() {
200
+ if (!this._gesturesRegistered) {
201
+ this._gesturesRegistered = true;
202
+ this.on(global.isAndroid ? 'touch, pan, pinch' : 'touch, pan, pinch', this._touchEvent, this);
203
+ }
204
+ }
205
+ __unregisterGestures() {
206
+ if (this._gesturesRegistered) {
207
+ this._gesturesRegistered = false;
208
+ this.off(global.isAndroid ? 'touch, pan' : 'touch, pan, pinch', this._touchEvent, this);
209
+ }
210
+ }
211
+ _pointerCountFromEvent(event) {
212
+ var _a, _b, _c, _d;
213
+ let count = 0;
214
+ if (global.isIOS) {
215
+ count = (_a = event.ios.numberOfTouches) !== null && _a !== void 0 ? _a : 0;
216
+ }
217
+ else if (global.isAndroid) {
218
+ count = (_d = (_c = (_b = (event.android.current || event.android.initial || event.android)).getPointerCount) === null || _c === void 0 ? void 0 : _c.call(_b)) !== null && _d !== void 0 ? _d : 0;
219
+ }
220
+ return count;
221
+ }
222
+ _positionsFromEvent(event) {
223
+ var _a, _b, _c, _d;
224
+ const positions = [];
225
+ if (global.isIOS) {
226
+ const set = (_a = event === null || event === void 0 ? void 0 : event.ios) === null || _a === void 0 ? void 0 : _a.touches;
227
+ if (((_b = event === null || event === void 0 ? void 0 : event.ios) === null || _b === void 0 ? void 0 : _b.touches) instanceof NSSet) {
228
+ const objects = set.allObjects;
229
+ for (let i = 0; i < set.count; i++) {
230
+ const touch = objects.objectAtIndex(i);
231
+ const point = touch.locationInView(touch.view);
232
+ positions.push(point.x, point.y);
233
+ }
234
+ }
235
+ else {
236
+ const count = event.ios.numberOfTouches;
237
+ const rec = event.ios;
238
+ for (let i = 0; i < count; i++) {
239
+ const point = rec.locationOfTouchInView(i, rec.view);
240
+ positions.push(point.x, point.y);
241
+ }
242
+ }
243
+ }
244
+ else if (global.isAndroid) {
245
+ const motionEvent = (_d = (_c = event.android) === null || _c === void 0 ? void 0 : _c.current) !== null && _d !== void 0 ? _d : event.android;
246
+ const count = motionEvent.getPointerCount();
247
+ const coords = new android.view.MotionEvent.PointerCoords();
248
+ for (let i = 0; i < count; i++) {
249
+ motionEvent.getPointerCoords(i, coords);
250
+ positions.push(coords.x / Screen.mainScreen.scale, coords.y / Screen.mainScreen.scale);
251
+ coords.clear();
252
+ }
253
+ }
254
+ return positions;
255
+ }
256
+ _touchEvent(event) {
257
+ let extraData;
258
+ let hasPointerDown = false;
259
+ let hasTouchStart = false;
260
+ let hasPointerMove = false;
261
+ let hasTouchMove = false;
262
+ let hasPointerUp = false;
263
+ let hasTouchEnd = false;
264
+ let hasPointerCancel = false;
265
+ let hasTouchCancel = false;
266
+ if (event.eventName === 'touch') {
267
+ switch (event.action) {
268
+ case 'down':
269
+ hasPointerDown = this.hasListeners('pointerdown');
270
+ hasTouchStart = this.hasListeners('touchstart');
271
+ if (hasPointerDown || hasTouchStart) {
272
+ const numberOfPointers = event.getPointerCount();
273
+ const positions = this._positionsFromEvent(event);
274
+ const x = event.getX();
275
+ const y = event.getY();
276
+ extraData = {
277
+ numberOfPointers,
278
+ positions,
279
+ x,
280
+ y
281
+ };
282
+ }
283
+ if (hasPointerDown && this._previousPointerCount !== extraData.numberOfPointers) {
284
+ this._previousPointerCount = extraData.numberOfPointers;
285
+ pointerId++;
286
+ this._pointers[this._previousPointerCount - 1] = {
287
+ id: pointerId,
288
+ coords: {
289
+ x: extraData.x,
290
+ y: extraData.y
291
+ }
292
+ };
293
+ this.notify(Object.assign(Object.assign({}, this._createPointerEvent('pointerdown', extraData)), { pointerId: pointerId }));
294
+ }
295
+ if (hasTouchStart) {
296
+ this.notify(this._createTouchEvent('touchstart', extraData));
297
+ }
298
+ break;
299
+ case 'up':
300
+ hasPointerUp = this.hasListeners('pointerup');
301
+ hasTouchEnd = this.hasListeners('touchend');
302
+ if (hasPointerUp || hasTouchEnd) {
303
+ const numberOfPointers = event.getPointerCount();
304
+ const positions = this._positionsFromEvent(event);
305
+ const x = event.getX();
306
+ const y = event.getY();
307
+ extraData = {
308
+ numberOfPointers,
309
+ positions,
310
+ x,
311
+ y
312
+ };
313
+ }
314
+ if (hasPointerUp) {
315
+ this._previousPointerCount -= extraData.numberOfPointers;
316
+ for (let i = 0; i < extraData.numberOfPointers; i++) {
317
+ const x = extraData.positions[i];
318
+ const y = extraData.positions[i + 1];
319
+ this.notify(Object.assign(Object.assign({}, this._createPointerEvent('pointerup', Object.assign(Object.assign({}, extraData), { x, y }))), { pointerId: this._pointers[i].id }));
320
+ }
321
+ }
322
+ if (hasTouchEnd) {
323
+ this.notify(this._createTouchEvent('touchend', extraData));
324
+ }
325
+ break;
326
+ case 'cancel':
327
+ hasPointerCancel = this.hasListeners('pointercancel');
328
+ hasTouchCancel = this.hasListeners('touchcancel');
329
+ if (hasPointerCancel || hasTouchCancel) {
330
+ const numberOfPointers = event.getPointerCount();
331
+ const positions = this._positionsFromEvent(event);
332
+ const x = event.getX();
333
+ const y = event.getY();
334
+ extraData = {
335
+ numberOfPointers,
336
+ positions,
337
+ x,
338
+ y
339
+ };
340
+ }
341
+ if (hasPointerCancel) {
342
+ if (global.isAndroid) {
343
+ this._previousPointerCount -= extraData.numberOfPointers;
344
+ }
345
+ else if (global.isIOS) {
346
+ this._previousPointerCount -= 1;
347
+ }
348
+ for (let i = 0; i < extraData.numberOfPointers; i++) {
349
+ const x = extraData.positions[i];
350
+ const y = extraData.positions[i + 1];
351
+ this.notify(Object.assign(Object.assign({}, this._createPointerEvent('pointercancel', Object.assign(Object.assign({}, extraData), { x, y }))), { pointerId: this._pointers[i].id }));
352
+ }
353
+ }
354
+ if (hasTouchCancel) {
355
+ this.notify(this._createTouchEvent('touchcancel', extraData));
356
+ }
357
+ break;
358
+ case 'move':
359
+ if (this._isPinching && global.isAndroid) {
360
+ const numberOfPointers = this._pointerCountFromEvent(event);
361
+ hasPointerMove = this.hasListeners('pointermove');
362
+ hasTouchMove = this.hasListeners('touchmove');
363
+ let data = {};
364
+ if (hasPointerMove || hasTouchMove) {
365
+ const positions = this._positionsFromEvent(event);
366
+ extraData = {
367
+ numberOfPointers,
368
+ positions,
369
+ x: positions[0],
370
+ y: positions[1]
371
+ };
372
+ const dx = extraData.positions[2] - extraData.positions[0];
373
+ const dy = extraData.positions[3] - extraData.positions[1];
374
+ let delta = 0;
375
+ var distance = Math.sqrt(dx * dx + dy * dy);
376
+ if (this._previousPinchDistance) {
377
+ delta = this._previousPinchDistance - distance;
378
+ }
379
+ this._previousPinchDistance = distance;
380
+ const x = dx; //event.getFocusX();
381
+ const y = dy; //event.getFocusY();
382
+ const scale = event.scale;
383
+ data = {
384
+ deltaMode: 0,
385
+ clientX: x,
386
+ clientY: y,
387
+ screenX: x,
388
+ screenY: y,
389
+ deltaX: 0,
390
+ deltaY: delta,
391
+ deltaZ: 0,
392
+ };
393
+ }
394
+ if (hasPointerMove) {
395
+ const count = extraData.numberOfPointers;
396
+ const positions = extraData.positions;
397
+ for (let i = 0; i < count; i++) {
398
+ let x = positions[i] - extraData.x;
399
+ let y = positions[i + 1] - extraData.y;
400
+ this.notify(Object.assign(Object.assign({}, this._createPointerEvent('pointermove', Object.assign(Object.assign({}, extraData), { x, y }))), { pointerId: this._pointers[i].id }));
401
+ }
402
+ }
403
+ if (hasTouchMove) {
404
+ this.notify(this._createTouchEvent('touchmove', Object.assign(Object.assign({}, extraData), { data })));
405
+ }
406
+ }
407
+ break;
408
+ default:
409
+ break;
410
+ }
411
+ }
412
+ else if (event.eventName === 'pinch') {
413
+ if (global.isAndroid) {
414
+ if ((event.state === GestureStateTypes.began || event.state === GestureStateTypes.changed)) {
415
+ this._isPinching = true;
416
+ this._previousPinchDistance = 0;
417
+ }
418
+ if (event.state === GestureStateTypes.ended || event.state === GestureStateTypes.cancelled) {
419
+ this._isPinching = false;
420
+ }
421
+ }
422
+ else {
423
+ const numberOfPointers = this._pointerCountFromEvent(event);
424
+ if (!this._isPinching && numberOfPointers >= 2 && (event.state === GestureStateTypes.began || event.state === GestureStateTypes.changed)) {
425
+ this._previousPinchDistance = 0;
426
+ this._isPinching = true;
427
+ }
428
+ if (event.state === GestureStateTypes.ended || event.state === GestureStateTypes.cancelled) {
429
+ this._isPinching = false;
430
+ }
431
+ if (this._isPinching && numberOfPointers >= 2) {
432
+ if (global.isIOS) {
433
+ hasPointerMove = this.hasListeners('pointermove');
434
+ hasTouchMove = this.hasListeners('touchmove');
435
+ let data = {};
436
+ let delta = 0;
437
+ if (hasPointerMove || hasTouchMove) {
438
+ const positions = this._positionsFromEvent(event);
439
+ extraData = {
440
+ numberOfPointers,
441
+ positions,
442
+ x: positions[0],
443
+ y: positions[1]
444
+ };
445
+ const dx = extraData.positions[2] - extraData.positions[0];
446
+ const dy = extraData.positions[3] - extraData.positions[1];
447
+ var distance = Math.sqrt(dx * dx + dy * dy);
448
+ if (this._previousPinchDistance) {
449
+ delta = this._previousPinchDistance - distance;
450
+ }
451
+ this._previousPinchDistance = distance;
452
+ const x = event.getFocusX();
453
+ const y = event.getFocusY();
454
+ const scale = event.scale;
455
+ data = {
456
+ deltaMode: 0,
457
+ clientX: x,
458
+ clientY: y,
459
+ screenX: x,
460
+ screenY: y,
461
+ deltaX: 0,
462
+ deltaY: delta,
463
+ deltaZ: 0,
464
+ };
465
+ }
466
+ if (hasPointerMove) {
467
+ const count = extraData.numberOfPointers;
468
+ const positions = extraData.positions;
469
+ for (let i = 0; i < count; i++) {
470
+ let x = positions[i] - extraData.x;
471
+ let y = positions[i + 1] - extraData.y;
472
+ this.notify(Object.assign(Object.assign({}, this._createPointerEvent('pointermove', Object.assign(Object.assign({}, extraData), { x, y }))), { pointerId: this._pointers[i].id }));
473
+ }
474
+ }
475
+ if (hasTouchMove) {
476
+ this.notify(this._createTouchEvent('touchmove', Object.assign(Object.assign({}, extraData), { data })));
477
+ }
478
+ }
479
+ }
480
+ }
481
+ }
482
+ else if (event.eventName === 'pan') {
483
+ if (this._isPinching) {
484
+ return;
485
+ }
486
+ if (event.state === GestureStateTypes.began || event.state === GestureStateTypes.changed) {
487
+ hasPointerMove = this.hasListeners('pointermove');
488
+ hasTouchMove = this.hasListeners('touchmove');
489
+ if (hasPointerMove || hasTouchMove) {
490
+ const numberOfPointers = this._pointerCountFromEvent(event);
491
+ const positions = this._positionsFromEvent(event);
492
+ const x = positions[0];
493
+ const y = positions[1];
494
+ extraData = {
495
+ numberOfPointers,
496
+ positions,
497
+ x,
498
+ y
499
+ };
500
+ }
501
+ if (hasPointerMove) {
502
+ const positions = extraData.positions;
503
+ for (let i = 0; i < extraData.numberOfPointers; i++) {
504
+ const x = positions[i];
505
+ const y = positions[i + 1];
506
+ this.notify(Object.assign(Object.assign({}, this._createPointerEvent('pointermove', { numberOfPointers: extraData.numberOfPointers, positions, x, y })), { pointerId: this._pointers[i].id }));
507
+ }
508
+ }
509
+ if (hasTouchMove) {
510
+ this.notify(this._createTouchEvent('touchmove', extraData));
511
+ }
512
+ }
513
+ }
514
+ }
515
+ _createTouchEvent(name, extraData) {
516
+ const count = extraData.numberOfPointers;
517
+ const point = extraData.positions;
518
+ if (!point) {
519
+ return null;
520
+ }
521
+ const x = extraData.x;
522
+ const y = extraData.y;
523
+ const activePointer = {
524
+ clientX: x,
525
+ clientY: y,
526
+ force: 0.0,
527
+ identifier: 0,
528
+ pageX: x,
529
+ pageY: y,
530
+ radiusX: 0,
531
+ radiusY: 0,
532
+ rotationAngle: 0,
533
+ screenX: x,
534
+ screenY: y,
535
+ };
536
+ const pointers = [];
537
+ for (let i = 0; i < count; i++) {
538
+ const x = extraData.positions[i];
539
+ const y = extraData.positions[i + 1];
540
+ pointers.push({
541
+ clientX: x,
542
+ clientY: y,
543
+ force: 0.0,
544
+ identifier: i,
545
+ pageX: x,
546
+ pageY: y,
547
+ radiusX: 0,
548
+ radiusY: 0,
549
+ rotationAngle: 0,
550
+ screenX: x,
551
+ screenY: y,
552
+ target: this,
553
+ });
554
+ }
555
+ return Object.assign(new TouchEvent(name), Object.assign({ eventName: name, defaultPrevented: false, cancelable: false, altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, target: this, changedTouches: pointers, targetTouches: pointers, touches: pointers }, activePointer));
556
+ }
557
+ _createPointerEvent(name, extraData) {
558
+ const x = extraData.x;
559
+ const y = extraData.y;
560
+ const activePointer = {
561
+ clientX: x,
562
+ clientY: y,
563
+ force: 0.0,
564
+ identifier: 0,
565
+ pageX: x,
566
+ pageY: y,
567
+ radiusX: 0,
568
+ radiusY: 0,
569
+ rotationAngle: 0,
570
+ screenX: x,
571
+ screenY: y,
572
+ pointerId: 0,
573
+ pointerType: 'touch',
574
+ x,
575
+ y,
576
+ width: 23.4375,
577
+ height: 23.4375,
578
+ isPrimary: true
579
+ };
580
+ return Object.assign(new PointerEvent(name), Object.assign({ eventName: name, defaultPrevented: false, cancelable: false, altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, target: this }, activePointer));
581
+ }
371
582
  };
372
583
  CanvasBase.readyEvent = 'ready';
373
584
  CanvasBase = __decorate([