@nativescript/canvas 1.0.0-debug.0 → 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 (127) hide show
  1. package/Canvas/common.d.ts +34 -13
  2. package/Canvas/common.js +422 -202
  3. package/Canvas/common.js.map +1 -1
  4. package/Canvas/index.android.d.ts +2 -0
  5. package/Canvas/index.android.js +17 -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 +10 -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/DOMMatrix.android.js +3 -0
  17. package/Canvas2D/DOMMatrix/DOMMatrix.android.js.map +1 -1
  18. package/Canvas2D/DOMMatrix/DOMMatrix.ios.js +3 -0
  19. package/Canvas2D/DOMMatrix/DOMMatrix.ios.js.map +1 -1
  20. package/Canvas2D/DOMMatrix/common.d.ts +1 -0
  21. package/Canvas2D/DOMMatrix/common.js +4 -0
  22. package/Canvas2D/DOMMatrix/common.js.map +1 -1
  23. package/Canvas2D/ImageData/ImageData.android.js +11 -0
  24. package/Canvas2D/ImageData/ImageData.android.js.map +1 -1
  25. package/Canvas2D/ImageData/ImageData.ios.js +11 -0
  26. package/Canvas2D/ImageData/ImageData.ios.js.map +1 -1
  27. package/Canvas2D/ImageData/common.d.ts +1 -0
  28. package/Canvas2D/ImageData/common.js +4 -0
  29. package/Canvas2D/ImageData/common.js.map +1 -1
  30. package/Canvas2D/Path2D/common.d.ts +1 -0
  31. package/Canvas2D/Path2D/common.js +4 -0
  32. package/Canvas2D/Path2D/common.js.map +1 -1
  33. package/Canvas2D/TextMetrics/common.d.ts +1 -0
  34. package/Canvas2D/TextMetrics/common.js +4 -0
  35. package/Canvas2D/TextMetrics/common.js.map +1 -1
  36. package/ImageAsset/common.d.ts +1 -0
  37. package/ImageAsset/common.js +4 -0
  38. package/ImageAsset/common.js.map +1 -1
  39. package/ImageBitmap/common.d.ts +1 -0
  40. package/ImageBitmap/common.js +4 -0
  41. package/ImageBitmap/common.js.map +1 -1
  42. package/ImageBitmap/index.android.js +32 -0
  43. package/ImageBitmap/index.android.js.map +1 -1
  44. package/ImageBitmap/index.ios.js +32 -0
  45. package/ImageBitmap/index.ios.js.map +1 -1
  46. package/SVG/Image.js +2 -0
  47. package/SVG/Image.js.map +1 -1
  48. package/SVG/SVG.js +9 -0
  49. package/SVG/SVG.js.map +1 -1
  50. package/TextDecoder/TextDecoder.android.d.ts +1 -0
  51. package/TextDecoder/TextDecoder.android.js +29 -20
  52. package/TextDecoder/TextDecoder.android.js.map +1 -1
  53. package/TextDecoder/TextDecoder.ios.js +12 -16
  54. package/TextDecoder/TextDecoder.ios.js.map +1 -1
  55. package/TextDecoder/common.d.ts +1 -0
  56. package/TextDecoder/common.js +4 -0
  57. package/TextDecoder/common.js.map +1 -1
  58. package/TextEncoder/common.d.ts +1 -0
  59. package/TextEncoder/common.js +4 -0
  60. package/TextEncoder/common.js.map +1 -1
  61. package/WebGL/WebGLExtensions/index.android.js +1 -0
  62. package/WebGL/WebGLExtensions/index.android.js.map +1 -1
  63. package/WebGL/WebGLExtensions/index.ios.js +1 -0
  64. package/WebGL/WebGLExtensions/index.ios.js.map +1 -1
  65. package/WebGL/WebGLRenderingContext/index.android.d.ts +1 -0
  66. package/WebGL/WebGLRenderingContext/index.android.js +394 -111
  67. package/WebGL/WebGLRenderingContext/index.android.js.map +1 -1
  68. package/WebGL/WebGLRenderingContext/index.ios.js +35 -24
  69. package/WebGL/WebGLRenderingContext/index.ios.js.map +1 -1
  70. package/WebGL2/WebGL2RenderingContext/index.android.js +2 -2
  71. package/WebGL2/WebGL2RenderingContext/index.android.js.map +1 -1
  72. package/WebGL2/WebGL2RenderingContext/index.ios.js +39 -29
  73. package/WebGL2/WebGL2RenderingContext/index.ios.js.map +1 -1
  74. package/angular/bundles/nativescript-canvas-angular.umd.js +4 -4
  75. package/angular/bundles/nativescript-canvas-angular.umd.js.map +1 -1
  76. package/angular/esm2015/index.js +2 -2
  77. package/angular/fesm2015/nativescript-canvas-angular.js +1 -1
  78. package/angular/fesm2015/nativescript-canvas-angular.js.map +1 -1
  79. package/index.d.ts +3 -4
  80. package/index.js +54 -8
  81. package/index.js.map +1 -1
  82. package/package.json +1 -2
  83. package/platforms/android/include.gradle +21 -1
  84. package/platforms/ios/CanvasNative.xcframework/Info.plist +10 -5
  85. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
  86. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative-Swift.h +54 -1
  87. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +1084 -457
  88. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Info.plist +0 -0
  89. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
  90. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64.swiftsourceinfo +0 -0
  91. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  92. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +185 -116
  93. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64.swiftdoc +0 -0
  94. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64.swiftinterface +185 -116
  95. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/TNSCanvas.nib +0 -0
  96. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Info.plist +20 -0
  97. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  98. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
  99. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative-Swift.h +3998 -0
  100. package/platforms/ios/CanvasNative.xcframework/{ios-x86_64-simulator → ios-arm64_x86_64-simulator}/CanvasNative.framework/Headers/CanvasNative.h +0 -0
  101. package/platforms/ios/CanvasNative.xcframework/{ios-x86_64-simulator → ios-arm64_x86_64-simulator}/CanvasNative.framework/Headers/Utils.h +0 -0
  102. package/platforms/ios/CanvasNative.xcframework/{ios-x86_64-simulator → ios-arm64_x86_64-simulator}/CanvasNative.framework/Headers/canvas_native.h +1084 -457
  103. package/platforms/ios/CanvasNative.xcframework/{ios-x86_64-simulator → ios-arm64_x86_64-simulator}/CanvasNative.framework/Info.plist +0 -0
  104. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
  105. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64.swiftsourceinfo +0 -0
  106. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64-apple-ios-simulator.swiftsourceinfo +0 -0
  107. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64.swiftsourceinfo +0 -0
  108. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  109. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +3257 -0
  110. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64.swiftdoc +0 -0
  111. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64.swiftinterface +3257 -0
  112. package/platforms/ios/CanvasNative.xcframework/{ios-x86_64-simulator → ios-arm64_x86_64-simulator}/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  113. package/platforms/ios/CanvasNative.xcframework/{ios-x86_64-simulator → ios-arm64_x86_64-simulator}/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +185 -116
  114. package/platforms/ios/CanvasNative.xcframework/{ios-x86_64-simulator → ios-arm64_x86_64-simulator}/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64.swiftdoc +0 -0
  115. package/platforms/ios/CanvasNative.xcframework/{ios-x86_64-simulator → ios-arm64_x86_64-simulator}/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64.swiftinterface +185 -116
  116. package/platforms/ios/CanvasNative.xcframework/{ios-x86_64-simulator → ios-arm64_x86_64-simulator}/CanvasNative.framework/Modules/module.modulemap +0 -0
  117. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/TNSCanvas.nib +0 -0
  118. package/platforms/ios/CanvasNative.xcframework/{ios-x86_64-simulator → ios-arm64_x86_64-simulator}/CanvasNative.framework/_CodeSignature/CodeResources +120 -58
  119. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Info.plist +20 -0
  120. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  121. package/platforms/ios/Podfile +1 -1
  122. package/utils.d.ts +3 -0
  123. package/utils.js +27 -0
  124. package/utils.js.map +1 -1
  125. package/platforms/ios/CanvasNative.xcframework/ios-x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
  126. package/platforms/ios/CanvasNative.xcframework/ios-x86_64-simulator/CanvasNative.framework/Headers/CanvasNative-Swift.h +0 -1943
  127. package/platforms/ios/CanvasNative.xcframework/ios-x86_64-simulator/CanvasNative.framework/TNSCanvas.nib +0 -0
package/Canvas/common.js CHANGED
@@ -1,11 +1,44 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
1
10
  import { CSSType, PercentLength, View, Screen, GestureStateTypes, Utils, Application, Property, booleanConverter } from '@nativescript/core';
2
- import { TouchList } from '../common';
3
- 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'];
4
36
  export const ignorePixelScalingProperty = new Property({
5
37
  name: 'ignorePixelScaling',
6
38
  defaultValue: false,
7
39
  valueConverter: booleanConverter
8
40
  });
41
+ let pointerId = 0;
9
42
  let CanvasBase = class CanvasBase extends View {
10
43
  constructor() {
11
44
  super();
@@ -15,20 +48,10 @@ let CanvasBase = class CanvasBase extends View {
15
48
  this._previousX = 0;
16
49
  this._previousY = 0;
17
50
  this._previousPinchDistance = 0;
51
+ this._previousPointerCount = 0;
52
+ this._pointers = [];
18
53
  this._classList = new Set();
19
54
  }
20
- __ensureGestures() {
21
- if (!this._gesturesRegistered) {
22
- this._gesturesRegistered = true;
23
- this.on('touch, pan, pinch', this._touchEvent, this);
24
- }
25
- }
26
- __unregisterGestures() {
27
- if (this._gesturesRegistered) {
28
- this._gesturesRegistered = false;
29
- this.off('touch, pan, pinch', this._touchEvent, this);
30
- }
31
- }
32
55
  addEventListener(arg, callback, thisArg) {
33
56
  super.addEventListener(arg, callback, thisArg);
34
57
  if (WEB_GESTURE_EVENTS.indexOf(arg) !== -1) {
@@ -104,182 +127,6 @@ let CanvasBase = class CanvasBase extends View {
104
127
  }
105
128
  return null;
106
129
  }
107
- _touchEvent(event) {
108
- if (event.eventName === 'touch') {
109
- switch (event.action) {
110
- case 'down':
111
- // ensure we dont have multiple touchstart
112
- // on the web seems to be called only on first touch
113
- if (!this.__touchStart) {
114
- this.__touchStart = event.getActivePointers()[0];
115
- this._emitEvent('touchstart', event);
116
- }
117
- break;
118
- case 'up':
119
- if (event.getPointerCount() === 1 && this.__touchStart) {
120
- this._emitEvent('touchend', event);
121
- this._isPinching = false;
122
- this.__touchStart = undefined;
123
- }
124
- break;
125
- case 'cancel':
126
- this._emitEvent('touchcancel', event);
127
- this.__touchStart = undefined;
128
- break;
129
- case 'move':
130
- // NOOP
131
- break;
132
- default:
133
- break;
134
- }
135
- }
136
- else if (event.eventName === 'pinch') {
137
- if (!this._isPinching && event.getPointerCount() >= 2 && (event.state === GestureStateTypes.began || event.state === GestureStateTypes.changed)) {
138
- this._previousPinchDistance = 0;
139
- this._isPinching = true;
140
- }
141
- if (this._isPinching) {
142
- this._emitEvent('touchmove:pinch', event);
143
- }
144
- if (event.state === GestureStateTypes.ended || event.state === GestureStateTypes.cancelled) {
145
- this._isPinching = false;
146
- }
147
- }
148
- else if (event.eventName === 'pan') {
149
- if (this._isPinching) {
150
- return;
151
- }
152
- if (event.state === GestureStateTypes.began || event.state === GestureStateTypes.changed) {
153
- this._emitEvent('touchmove', event);
154
- }
155
- }
156
- }
157
- _getTouchEvent(name, event, target) {
158
- const pointers = new TouchList();
159
- let scale = 1;
160
- let activePointer;
161
- if (name === 'touchmove') {
162
- name = 'touchmove';
163
- activePointer = {
164
- clientX: event.getX() * scale,
165
- clientY: event.getY() * scale,
166
- force: 0.0,
167
- identifier: 0,
168
- pageX: event.getX() * scale,
169
- pageY: event.getY() * scale,
170
- radiusX: 0,
171
- radiusY: 0,
172
- rotationAngle: 0,
173
- screenX: event.getX() * scale,
174
- screenY: event.getY() * scale,
175
- target
176
- };
177
- const count = event.getAllPointers().length;
178
- for (let i = 0; i < count; i++) {
179
- const point = event.getAllPointers()[i];
180
- pointers.push({
181
- clientX: point.getX(),
182
- clientY: point.getY(),
183
- force: 0.0,
184
- identifier: i,
185
- pageX: point.getX(),
186
- pageY: point.getY(),
187
- radiusX: 0,
188
- radiusY: 0,
189
- rotationAngle: 0,
190
- screenX: point.getX(),
191
- screenY: point.getY(),
192
- target,
193
- });
194
- }
195
- /* mouse */
196
- // pointers.push({
197
- // // * SCALE ??
198
- // clientX: x,
199
- // clientY: y,
200
- // force: 0.0,
201
- // identifier: 0,
202
- // pageX: x,
203
- // pageY: y,
204
- // radiusX: 0,
205
- // radiusY: 0,
206
- // rotationAngle: 0,
207
- // screenX: x,
208
- // screenY: y,
209
- // target,
210
- // });
211
- this._previousX = event.deltaX;
212
- this._previousY = event.deltaY;
213
- }
214
- else if (name === 'touchmove:pinch') {
215
- const dx = event.extraData.positions[2] - event.extraData.positions[0];
216
- const dy = event.extraData.positions[3] - event.extraData.positions[1];
217
- let delta = 0;
218
- var distance = Math.sqrt(dx * dx + dy * dy);
219
- if (this._previousPinchDistance) {
220
- delta = this._previousPinchDistance - distance;
221
- }
222
- this._previousPinchDistance = distance;
223
- name = 'wheel';
224
- const x = event.getFocusX();
225
- const y = event.getFocusY();
226
- const scale = event.scale;
227
- // mouse event
228
- let data = {
229
- deltaMode: 0,
230
- clientX: x,
231
- clientY: y,
232
- screenX: x,
233
- screenY: x,
234
- deltaX: 0,
235
- deltaY: delta,
236
- deltaZ: 0,
237
- };
238
- return Object.assign(new TouchEvent(name), { eventName: name, object: null, defaultPrevented: false, cancelable: false, altKey: false, ctrlKey: true, metaKey: false, shiftKey: false, target }, data);
239
- }
240
- else {
241
- const count = event.getAllPointers().length;
242
- const point = event.getActivePointers()[0];
243
- if (!point) {
244
- return null;
245
- }
246
- // mouse event
247
- activePointer = {
248
- clientX: point.getX() * scale,
249
- clientY: point.getY() * scale,
250
- force: 0.0,
251
- identifier: 0,
252
- pageX: point.getX() * scale,
253
- pageY: point.getY() * scale,
254
- radiusX: 0,
255
- radiusY: 0,
256
- rotationAngle: 0,
257
- screenX: point.getX() * scale,
258
- screenY: point.getY() * scale,
259
- };
260
- for (let i = 0; i < count; i++) {
261
- const point = event.getAllPointers()[i];
262
- pointers.push({
263
- clientX: point.getX(),
264
- clientY: point.getY(),
265
- force: 0.0,
266
- identifier: i,
267
- pageX: point.getX(),
268
- pageY: point.getY(),
269
- radiusX: 0,
270
- radiusY: 0,
271
- rotationAngle: 0,
272
- screenX: point.getX(),
273
- screenY: point.getY(),
274
- target,
275
- });
276
- }
277
- }
278
- 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));
279
- }
280
- _emitEvent(name, event) {
281
- this.notify(this._getTouchEvent(name, event, this));
282
- }
283
130
  _readyEvent() {
284
131
  this.notify({
285
132
  eventName: 'ready',
@@ -347,6 +194,391 @@ let CanvasBase = class CanvasBase extends View {
347
194
  return 0;
348
195
  }
349
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
+ }
350
582
  };
351
583
  CanvasBase.readyEvent = 'ready';
352
584
  CanvasBase = __decorate([
@@ -354,17 +586,5 @@ CanvasBase = __decorate([
354
586
  __metadata("design:paramtypes", [])
355
587
  ], CanvasBase);
356
588
  export { CanvasBase };
357
- CanvasBase.prototype._observe = function (type, callback, thisArg) {
358
- const gestureObserve = require('@nativescript-community/gesturehandler/gestures_override').observe;
359
- if (!this._gestureObservers[type]) {
360
- this._gestureObservers[type] = [];
361
- }
362
- this._gestureObservers[type].push(gestureObserve(this, type, callback, thisArg));
363
- if (global.isAndroid) {
364
- if (this.isLoaded && !this.touchListenerIsSet) {
365
- this.setOnTouchListener();
366
- }
367
- }
368
- };
369
589
  ignorePixelScalingProperty.register(CanvasBase);
370
590
  //# sourceMappingURL=common.js.map