@nativescript/canvas 1.0.0-debug.0 → 1.1.0-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 (144) hide show
  1. package/Canvas/common.d.ts +35 -13
  2. package/Canvas/common.js +458 -204
  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.d.ts +3 -0
  13. package/Canvas2D/CanvasRenderingContext2D/index.android.js +53 -35
  14. package/Canvas2D/CanvasRenderingContext2D/index.android.js.map +1 -1
  15. package/Canvas2D/CanvasRenderingContext2D/index.d.ts +6 -0
  16. package/Canvas2D/CanvasRenderingContext2D/index.ios.d.ts +4 -1
  17. package/Canvas2D/CanvasRenderingContext2D/index.ios.js +126 -113
  18. package/Canvas2D/CanvasRenderingContext2D/index.ios.js.map +1 -1
  19. package/Canvas2D/DOMMatrix/DOMMatrix.android.js +3 -0
  20. package/Canvas2D/DOMMatrix/DOMMatrix.android.js.map +1 -1
  21. package/Canvas2D/DOMMatrix/DOMMatrix.ios.js +3 -0
  22. package/Canvas2D/DOMMatrix/DOMMatrix.ios.js.map +1 -1
  23. package/Canvas2D/DOMMatrix/common.d.ts +1 -0
  24. package/Canvas2D/DOMMatrix/common.js +4 -0
  25. package/Canvas2D/DOMMatrix/common.js.map +1 -1
  26. package/Canvas2D/ImageData/ImageData.android.js +11 -0
  27. package/Canvas2D/ImageData/ImageData.android.js.map +1 -1
  28. package/Canvas2D/ImageData/ImageData.ios.js +11 -0
  29. package/Canvas2D/ImageData/ImageData.ios.js.map +1 -1
  30. package/Canvas2D/ImageData/common.d.ts +1 -0
  31. package/Canvas2D/ImageData/common.js +4 -0
  32. package/Canvas2D/ImageData/common.js.map +1 -1
  33. package/Canvas2D/Path2D/common.d.ts +1 -0
  34. package/Canvas2D/Path2D/common.js +4 -0
  35. package/Canvas2D/Path2D/common.js.map +1 -1
  36. package/Canvas2D/TextMetrics/common.d.ts +1 -0
  37. package/Canvas2D/TextMetrics/common.js +4 -0
  38. package/Canvas2D/TextMetrics/common.js.map +1 -1
  39. package/ImageAsset/common.d.ts +1 -0
  40. package/ImageAsset/common.js +4 -0
  41. package/ImageAsset/common.js.map +1 -1
  42. package/ImageBitmap/common.d.ts +1 -0
  43. package/ImageBitmap/common.js +4 -0
  44. package/ImageBitmap/common.js.map +1 -1
  45. package/ImageBitmap/index.android.js +32 -0
  46. package/ImageBitmap/index.android.js.map +1 -1
  47. package/ImageBitmap/index.ios.js +41 -9
  48. package/ImageBitmap/index.ios.js.map +1 -1
  49. package/SVG/Image.js +2 -0
  50. package/SVG/Image.js.map +1 -1
  51. package/SVG/SVG.js +9 -0
  52. package/SVG/SVG.js.map +1 -1
  53. package/TextDecoder/TextDecoder.android.d.ts +1 -0
  54. package/TextDecoder/TextDecoder.android.js +29 -20
  55. package/TextDecoder/TextDecoder.android.js.map +1 -1
  56. package/TextDecoder/TextDecoder.ios.js +12 -16
  57. package/TextDecoder/TextDecoder.ios.js.map +1 -1
  58. package/TextDecoder/common.d.ts +1 -0
  59. package/TextDecoder/common.js +4 -0
  60. package/TextDecoder/common.js.map +1 -1
  61. package/TextEncoder/common.d.ts +1 -0
  62. package/TextEncoder/common.js +4 -0
  63. package/TextEncoder/common.js.map +1 -1
  64. package/WebGL/WebGLExtensions/index.android.js +1 -0
  65. package/WebGL/WebGLExtensions/index.android.js.map +1 -1
  66. package/WebGL/WebGLExtensions/index.ios.js +1 -0
  67. package/WebGL/WebGLExtensions/index.ios.js.map +1 -1
  68. package/WebGL/WebGLRenderingContext/index.android.d.ts +1 -0
  69. package/WebGL/WebGLRenderingContext/index.android.js +394 -111
  70. package/WebGL/WebGLRenderingContext/index.android.js.map +1 -1
  71. package/WebGL/WebGLRenderingContext/index.ios.js +35 -24
  72. package/WebGL/WebGLRenderingContext/index.ios.js.map +1 -1
  73. package/WebGL2/WebGL2RenderingContext/index.android.js +2 -2
  74. package/WebGL2/WebGL2RenderingContext/index.android.js.map +1 -1
  75. package/WebGL2/WebGL2RenderingContext/index.ios.js +39 -29
  76. package/WebGL2/WebGL2RenderingContext/index.ios.js.map +1 -1
  77. package/angular/esm2020/index.mjs +17 -0
  78. package/angular/esm2020/nativescript-canvas-angular.mjs +5 -0
  79. package/angular/fesm2015/nativescript-canvas-angular.mjs +24 -0
  80. package/angular/fesm2015/nativescript-canvas-angular.mjs.map +1 -0
  81. package/angular/fesm2020/nativescript-canvas-angular.mjs +24 -0
  82. package/angular/fesm2020/nativescript-canvas-angular.mjs.map +1 -0
  83. package/angular/index.d.ts +4 -0
  84. package/angular/package.json +20 -8
  85. package/index.d.ts +3 -4
  86. package/index.js +54 -8
  87. package/index.js.map +1 -1
  88. package/package.json +2 -3
  89. package/platforms/android/include.gradle +21 -1
  90. package/platforms/ios/CanvasNative.xcframework/Info.plist +10 -5
  91. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
  92. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative-Swift.h +120 -3
  93. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +1122 -471
  94. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Info.plist +0 -0
  95. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
  96. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.abi.json +74840 -0
  97. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/{arm64.swiftinterface → arm64-apple-ios.private.swiftinterface} +203 -121
  98. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  99. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +203 -121
  100. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/module.modulemap +2 -2
  101. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/TNSCanvas.nib +0 -0
  102. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Info.plist +20 -0
  103. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  104. package/platforms/ios/CanvasNative.xcframework/{ios-x86_64-simulator → ios-arm64_x86_64-simulator}/CanvasNative.framework/CanvasNative +0 -0
  105. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative-Swift.h +4116 -0
  106. package/platforms/ios/CanvasNative.xcframework/{ios-x86_64-simulator → ios-arm64_x86_64-simulator}/CanvasNative.framework/Headers/CanvasNative.h +0 -0
  107. package/platforms/ios/CanvasNative.xcframework/{ios-x86_64-simulator → ios-arm64_x86_64-simulator}/CanvasNative.framework/Headers/Utils.h +0 -0
  108. package/platforms/ios/CanvasNative.xcframework/{ios-x86_64-simulator → ios-arm64_x86_64-simulator}/CanvasNative.framework/Headers/canvas_native.h +1122 -471
  109. package/platforms/ios/CanvasNative.xcframework/{ios-x86_64-simulator → ios-arm64_x86_64-simulator}/CanvasNative.framework/Info.plist +0 -0
  110. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
  111. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64-apple-ios-simulator.swiftsourceinfo +0 -0
  112. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.abi.json +74840 -0
  113. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +3270 -0
  114. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  115. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +3270 -0
  116. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +74840 -0
  117. package/platforms/ios/CanvasNative.xcframework/{ios-x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64.swiftinterface → ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface} +203 -121
  118. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  119. 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 +203 -121
  120. package/platforms/ios/CanvasNative.xcframework/{ios-x86_64-simulator → ios-arm64_x86_64-simulator}/CanvasNative.framework/Modules/module.modulemap +2 -2
  121. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/TNSCanvas.nib +0 -0
  122. package/platforms/ios/CanvasNative.xcframework/{ios-x86_64-simulator → ios-arm64_x86_64-simulator}/CanvasNative.framework/_CodeSignature/CodeResources +87 -69
  123. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Info.plist +20 -0
  124. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  125. package/platforms/ios/Podfile +1 -1
  126. package/typings/objc!CanvasNative.d.ts +2018 -0
  127. package/typings/objc!CanvasNative.js +1 -0
  128. package/typings/objc!CanvasNative.js.map +1 -0
  129. package/utils.d.ts +3 -0
  130. package/utils.js +27 -0
  131. package/utils.js.map +1 -1
  132. package/angular/bundles/nativescript-canvas-angular.umd.js +0 -29
  133. package/angular/bundles/nativescript-canvas-angular.umd.js.map +0 -1
  134. package/angular/esm2015/index.js +0 -12
  135. package/angular/esm2015/nativescript-canvas-angular.js +0 -5
  136. package/angular/fesm2015/nativescript-canvas-angular.js +0 -19
  137. package/angular/fesm2015/nativescript-canvas-angular.js.map +0 -1
  138. package/angular/nativescript-canvas-angular.d.ts +0 -4
  139. package/angular/nativescript-canvas-angular.metadata.json +0 -1
  140. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64.swiftdoc +0 -0
  141. package/platforms/ios/CanvasNative.xcframework/ios-x86_64-simulator/CanvasNative.framework/Headers/CanvasNative-Swift.h +0 -1943
  142. package/platforms/ios/CanvasNative.xcframework/ios-x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  143. package/platforms/ios/CanvasNative.xcframework/ios-x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64.swiftdoc +0 -0
  144. 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', 'mousedown', 'mousemove'];
4
36
  export const ignorePixelScalingProperty = new Property({
5
37
  name: 'ignorePixelScaling',
6
38
  defaultValue: false,
7
- valueConverter: booleanConverter
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) {
@@ -39,7 +62,7 @@ let CanvasBase = class CanvasBase extends View {
39
62
  super.removeEventListener(arg, callback, thisArg);
40
63
  if (WEB_GESTURE_EVENTS.indexOf(arg) !== -1) {
41
64
  // if we dont have any other web gestures we can unregister gestures
42
- if (!WEB_GESTURE_EVENTS.some(e => this.hasListeners(e))) {
65
+ if (!WEB_GESTURE_EVENTS.some((e) => this.hasListeners(e))) {
43
66
  this.__unregisterGestures();
44
67
  }
45
68
  }
@@ -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,425 @@ 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 hasMouseDown = false;
261
+ let hasPointerMove = false;
262
+ let hasTouchMove = false;
263
+ let hasMouseMove = false;
264
+ let hasPointerUp = false;
265
+ let hasTouchEnd = false;
266
+ let hasMouseUp = false;
267
+ let hasPointerCancel = false;
268
+ let hasTouchCancel = false;
269
+ if (event.eventName === 'touch') {
270
+ switch (event.action) {
271
+ case 'down':
272
+ hasPointerDown = this.hasListeners('pointerdown');
273
+ hasTouchStart = this.hasListeners('touchstart');
274
+ hasMouseDown = this.hasListeners('mousedown');
275
+ if (hasPointerDown || hasTouchStart || hasMouseDown) {
276
+ const numberOfPointers = event.getPointerCount();
277
+ const positions = this._positionsFromEvent(event);
278
+ const x = event.getX();
279
+ const y = event.getY();
280
+ extraData = {
281
+ numberOfPointers,
282
+ positions,
283
+ x,
284
+ y,
285
+ };
286
+ }
287
+ if ((hasPointerDown || hasMouseDown) && this._previousPointerCount !== extraData.numberOfPointers) {
288
+ this._previousPointerCount = extraData.numberOfPointers;
289
+ pointerId++;
290
+ this._pointers[this._previousPointerCount - 1] = {
291
+ id: pointerId,
292
+ coords: {
293
+ x: extraData.x,
294
+ y: extraData.y,
295
+ },
296
+ };
297
+ if (hasPointerDown) {
298
+ this.notify(Object.assign(Object.assign({}, this._createPointerEvent('pointerdown', extraData)), { pointerId: pointerId }));
299
+ }
300
+ if (hasMouseDown) {
301
+ this.notify(Object.assign(Object.assign({}, this._createPointerEvent('mousedown', extraData)), { pointerId: pointerId }));
302
+ }
303
+ }
304
+ if (hasTouchStart) {
305
+ this.notify(this._createTouchEvent('touchstart', extraData));
306
+ }
307
+ break;
308
+ case 'up':
309
+ hasPointerUp = this.hasListeners('pointerup');
310
+ hasTouchEnd = this.hasListeners('touchend');
311
+ hasMouseUp = this.hasListeners('mouseup');
312
+ if (hasPointerUp || hasTouchEnd || hasMouseUp) {
313
+ const numberOfPointers = event.getPointerCount();
314
+ const positions = this._positionsFromEvent(event);
315
+ const x = event.getX();
316
+ const y = event.getY();
317
+ extraData = {
318
+ numberOfPointers,
319
+ positions,
320
+ x,
321
+ y,
322
+ };
323
+ }
324
+ if (hasPointerUp || hasMouseUp) {
325
+ this._previousPointerCount -= extraData.numberOfPointers;
326
+ for (let i = 0; i < extraData.numberOfPointers; i++) {
327
+ const x = extraData.positions[i];
328
+ const y = extraData.positions[i + 1];
329
+ if (hasPointerUp) {
330
+ this.notify(Object.assign(Object.assign({}, this._createPointerEvent('pointerup', Object.assign(Object.assign({}, extraData), { x, y }))), { pointerId: this._pointers[i].id }));
331
+ }
332
+ if (hasMouseUp) {
333
+ this.notify(Object.assign(Object.assign({}, this._createPointerEvent('mouseup', Object.assign(Object.assign({}, extraData), { x, y }))), { pointerId: this._pointers[i].id }));
334
+ }
335
+ }
336
+ }
337
+ if (hasTouchEnd) {
338
+ this.notify(this._createTouchEvent('touchend', extraData));
339
+ }
340
+ break;
341
+ case 'cancel':
342
+ hasPointerCancel = this.hasListeners('pointercancel');
343
+ hasTouchCancel = this.hasListeners('touchcancel');
344
+ if (hasPointerCancel || hasTouchCancel) {
345
+ const numberOfPointers = event.getPointerCount();
346
+ const positions = this._positionsFromEvent(event);
347
+ const x = event.getX();
348
+ const y = event.getY();
349
+ extraData = {
350
+ numberOfPointers,
351
+ positions,
352
+ x,
353
+ y,
354
+ };
355
+ }
356
+ if (hasPointerCancel) {
357
+ if (global.isAndroid) {
358
+ this._previousPointerCount -= extraData.numberOfPointers;
359
+ }
360
+ else if (global.isIOS) {
361
+ this._previousPointerCount -= 1;
362
+ }
363
+ for (let i = 0; i < extraData.numberOfPointers; i++) {
364
+ const x = extraData.positions[i];
365
+ const y = extraData.positions[i + 1];
366
+ this.notify(Object.assign(Object.assign({}, this._createPointerEvent('pointercancel', Object.assign(Object.assign({}, extraData), { x, y }))), { pointerId: this._pointers[i].id }));
367
+ }
368
+ }
369
+ if (hasTouchCancel) {
370
+ this.notify(this._createTouchEvent('touchcancel', extraData));
371
+ }
372
+ break;
373
+ case 'move':
374
+ if (this._isPinching && global.isAndroid) {
375
+ const numberOfPointers = this._pointerCountFromEvent(event);
376
+ hasPointerMove = this.hasListeners('pointermove');
377
+ hasTouchMove = this.hasListeners('touchmove');
378
+ hasMouseMove = this.hasListeners('mousemove');
379
+ let data = {};
380
+ if (hasPointerMove || hasTouchMove || hasMouseMove) {
381
+ const positions = this._positionsFromEvent(event);
382
+ extraData = {
383
+ numberOfPointers,
384
+ positions,
385
+ x: positions[0],
386
+ y: positions[1],
387
+ };
388
+ const dx = extraData.positions[2] - extraData.positions[0];
389
+ const dy = extraData.positions[3] - extraData.positions[1];
390
+ let delta = 0;
391
+ var distance = Math.sqrt(dx * dx + dy * dy);
392
+ if (this._previousPinchDistance) {
393
+ delta = this._previousPinchDistance - distance;
394
+ }
395
+ this._previousPinchDistance = distance;
396
+ const x = dx; //event.getFocusX();
397
+ const y = dy; //event.getFocusY();
398
+ const scale = event.scale;
399
+ data = {
400
+ deltaMode: 0,
401
+ clientX: x,
402
+ clientY: y,
403
+ screenX: x,
404
+ screenY: y,
405
+ deltaX: 0,
406
+ deltaY: delta,
407
+ deltaZ: 0,
408
+ };
409
+ }
410
+ if (hasPointerMove || hasMouseMove) {
411
+ const count = extraData.numberOfPointers;
412
+ const positions = extraData.positions;
413
+ for (let i = 0; i < count; i++) {
414
+ let x = positions[i] - extraData.x;
415
+ let y = positions[i + 1] - extraData.y;
416
+ if (hasPointerMove) {
417
+ this.notify(Object.assign(Object.assign({}, this._createPointerEvent('pointermove', Object.assign(Object.assign({}, extraData), { x, y }))), { pointerId: this._pointers[i].id }));
418
+ }
419
+ if (hasMouseMove) {
420
+ this.notify(Object.assign(Object.assign({}, this._createPointerEvent('mousemove', Object.assign(Object.assign({}, extraData), { x, y }))), { pointerId: this._pointers[i].id }));
421
+ }
422
+ }
423
+ }
424
+ if (hasTouchMove) {
425
+ this.notify(this._createTouchEvent('touchmove', Object.assign(Object.assign({}, extraData), { data })));
426
+ }
427
+ }
428
+ break;
429
+ default:
430
+ break;
431
+ }
432
+ }
433
+ else if (event.eventName === 'pinch') {
434
+ if (global.isAndroid) {
435
+ if (event.state === GestureStateTypes.began || event.state === GestureStateTypes.changed) {
436
+ this._isPinching = true;
437
+ this._previousPinchDistance = 0;
438
+ }
439
+ if (event.state === GestureStateTypes.ended || event.state === GestureStateTypes.cancelled) {
440
+ this._isPinching = false;
441
+ }
442
+ }
443
+ else {
444
+ const numberOfPointers = this._pointerCountFromEvent(event);
445
+ if (!this._isPinching && numberOfPointers >= 2 && (event.state === GestureStateTypes.began || event.state === GestureStateTypes.changed)) {
446
+ this._previousPinchDistance = 0;
447
+ this._isPinching = true;
448
+ }
449
+ if (event.state === GestureStateTypes.ended || event.state === GestureStateTypes.cancelled) {
450
+ this._isPinching = false;
451
+ }
452
+ if (this._isPinching && numberOfPointers >= 2) {
453
+ if (global.isIOS) {
454
+ hasPointerMove = this.hasListeners('pointermove');
455
+ hasTouchMove = this.hasListeners('touchmove');
456
+ hasMouseMove = this.hasListeners('mousemove');
457
+ let data = {};
458
+ let delta = 0;
459
+ if (hasPointerMove || hasTouchMove || hasMouseMove) {
460
+ const positions = this._positionsFromEvent(event);
461
+ extraData = {
462
+ numberOfPointers,
463
+ positions,
464
+ x: positions[0],
465
+ y: positions[1],
466
+ };
467
+ const dx = extraData.positions[2] - extraData.positions[0];
468
+ const dy = extraData.positions[3] - extraData.positions[1];
469
+ var distance = Math.sqrt(dx * dx + dy * dy);
470
+ if (this._previousPinchDistance) {
471
+ delta = this._previousPinchDistance - distance;
472
+ }
473
+ this._previousPinchDistance = distance;
474
+ const x = event.getFocusX();
475
+ const y = event.getFocusY();
476
+ const scale = event.scale;
477
+ data = {
478
+ deltaMode: 0,
479
+ clientX: x,
480
+ clientY: y,
481
+ screenX: x,
482
+ screenY: y,
483
+ deltaX: 0,
484
+ deltaY: delta,
485
+ deltaZ: 0,
486
+ };
487
+ }
488
+ if (hasPointerMove || hasMouseMove) {
489
+ const count = extraData.numberOfPointers;
490
+ const positions = extraData.positions;
491
+ for (let i = 0; i < count; i++) {
492
+ let x = positions[i] - extraData.x;
493
+ let y = positions[i + 1] - extraData.y;
494
+ if (hasPointerMove) {
495
+ this.notify(Object.assign(Object.assign({}, this._createPointerEvent('pointermove', Object.assign(Object.assign({}, extraData), { x, y }))), { pointerId: this._pointers[i].id }));
496
+ }
497
+ if (hasMouseMove) {
498
+ this.notify(Object.assign(Object.assign({}, this._createPointerEvent('mousemove', Object.assign(Object.assign({}, extraData), { x, y }))), { pointerId: this._pointers[i].id }));
499
+ }
500
+ }
501
+ }
502
+ if (hasTouchMove) {
503
+ this.notify(this._createTouchEvent('touchmove', Object.assign(Object.assign({}, extraData), { data })));
504
+ }
505
+ }
506
+ }
507
+ }
508
+ }
509
+ else if (event.eventName === 'pan') {
510
+ if (this._isPinching) {
511
+ return;
512
+ }
513
+ if (event.state === GestureStateTypes.began || event.state === GestureStateTypes.changed) {
514
+ hasPointerMove = this.hasListeners('pointermove');
515
+ hasTouchMove = this.hasListeners('touchmove');
516
+ hasMouseMove = this.hasListeners('mousemove');
517
+ if (hasPointerMove || hasTouchMove || hasMouseMove) {
518
+ const numberOfPointers = this._pointerCountFromEvent(event);
519
+ const positions = this._positionsFromEvent(event);
520
+ const x = positions[0];
521
+ const y = positions[1];
522
+ extraData = {
523
+ numberOfPointers,
524
+ positions,
525
+ x,
526
+ y,
527
+ };
528
+ }
529
+ if (hasPointerMove || hasMouseMove) {
530
+ const positions = extraData.positions;
531
+ for (let i = 0; i < extraData.numberOfPointers; i++) {
532
+ const x = positions[i];
533
+ const y = positions[i + 1];
534
+ if (hasPointerMove) {
535
+ this.notify(Object.assign(Object.assign({}, this._createPointerEvent('pointermove', { numberOfPointers: extraData.numberOfPointers, positions, x, y })), { pointerId: this._pointers[i].id }));
536
+ }
537
+ if (hasMouseMove) {
538
+ this.notify(Object.assign(Object.assign({}, this._createPointerEvent('mousemove', { numberOfPointers: extraData.numberOfPointers, positions, x, y })), { pointerId: this._pointers[i].id }));
539
+ }
540
+ }
541
+ }
542
+ if (hasTouchMove) {
543
+ this.notify(this._createTouchEvent('touchmove', extraData));
544
+ }
545
+ }
546
+ }
547
+ }
548
+ _createTouchEvent(name, extraData) {
549
+ const count = extraData.numberOfPointers;
550
+ const point = extraData.positions;
551
+ if (!point) {
552
+ return null;
553
+ }
554
+ const x = extraData.x;
555
+ const y = extraData.y;
556
+ const activePointer = {
557
+ clientX: x,
558
+ clientY: y,
559
+ force: 0.0,
560
+ identifier: 0,
561
+ pageX: x,
562
+ pageY: y,
563
+ radiusX: 0,
564
+ radiusY: 0,
565
+ rotationAngle: 0,
566
+ screenX: x,
567
+ screenY: y,
568
+ };
569
+ const pointers = [];
570
+ for (let i = 0; i < count; i++) {
571
+ const x = extraData.positions[i];
572
+ const y = extraData.positions[i + 1];
573
+ pointers.push({
574
+ clientX: x,
575
+ clientY: y,
576
+ force: 0.0,
577
+ identifier: i,
578
+ pageX: x,
579
+ pageY: y,
580
+ radiusX: 0,
581
+ radiusY: 0,
582
+ rotationAngle: 0,
583
+ screenX: x,
584
+ screenY: y,
585
+ target: this,
586
+ });
587
+ }
588
+ 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));
589
+ }
590
+ _createPointerEvent(name, extraData) {
591
+ const x = extraData.x;
592
+ const y = extraData.y;
593
+ const activePointer = {
594
+ clientX: x,
595
+ clientY: y,
596
+ force: 0.0,
597
+ identifier: 0,
598
+ pageX: x,
599
+ pageY: y,
600
+ radiusX: 0,
601
+ radiusY: 0,
602
+ rotationAngle: 0,
603
+ screenX: x,
604
+ screenY: y,
605
+ pointerId: 0,
606
+ pointerType: 'touch',
607
+ x,
608
+ y,
609
+ width: 23.4375,
610
+ height: 23.4375,
611
+ isPrimary: true,
612
+ };
613
+ return Object.assign(new PointerEvent(name), Object.assign(Object.assign({ eventName: name, defaultPrevented: false, cancelable: false, altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, target: this }, activePointer), { preventDefault: () => { } }));
614
+ }
615
+ preventDefault() { }
350
616
  };
351
617
  CanvasBase.readyEvent = 'ready';
352
618
  CanvasBase = __decorate([
@@ -354,17 +620,5 @@ CanvasBase = __decorate([
354
620
  __metadata("design:paramtypes", [])
355
621
  ], CanvasBase);
356
622
  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
623
  ignorePixelScalingProperty.register(CanvasBase);
370
624
  //# sourceMappingURL=common.js.map