@nativescript/canvas 2.0.0-alpha.22 → 2.0.0-alpha.24
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.
- package/Canvas/common.d.ts +199 -25
- package/Canvas/common.js +624 -489
- package/Canvas/common.js.map +1 -1
- package/Canvas/index.android.js +19 -9
- package/Canvas/index.android.js.map +1 -1
- package/Canvas/index.ios.js +13 -12
- package/Canvas/index.ios.js.map +1 -1
- package/Canvas2D/CanvasRenderingContext2D/index.d.ts +0 -1
- package/Canvas2D/CanvasRenderingContext2D/index.js +9 -121
- package/Canvas2D/CanvasRenderingContext2D/index.js.map +1 -1
- package/WebGL/WebGLExtensions/index.d.ts +4 -3
- package/WebGL/WebGLExtensions/index.js +10 -3
- package/WebGL/WebGLExtensions/index.js.map +1 -1
- package/WebGL/WebGLRenderingContext/index.d.ts +15 -15
- package/WebGL/WebGLRenderingContext/index.js +15 -277
- package/WebGL/WebGLRenderingContext/index.js.map +1 -1
- package/WebGL2/WebGL2RenderingContext/index.js +0 -86
- package/WebGL2/WebGL2RenderingContext/index.js.map +1 -1
- package/package.json +1 -1
- package/platforms/android/canvas-release.aar +0 -0
- package/platforms/ios/CanvasNative.xcframework/Info.plist +5 -5
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative-Swift.h +2 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.abi.json +1035 -83
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.private.swiftinterface +2 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +2 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative-Swift.h +4 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64-apple-ios-simulator.swiftsourceinfo +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.abi.json +1035 -83
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +2 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +2 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +1035 -83
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +2 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +2 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +22 -22
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
- package/platforms/ios/src/cpp/ImageAssetImpl.cpp +4 -4
- package/platforms/ios/src/cpp/webgl/WebGLActiveInfoImpl.cpp +0 -2
- package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.cpp +643 -624
- package/platforms/ios/src/cpp/webgl/extensions/ANGLE_instanced_arraysImpl.cpp +14 -14
- package/platforms/ios/src/cpp/webgl/extensions/EXT_blend_minmaxImpl.cpp +2 -2
- package/platforms/ios/src/cpp/webgl/extensions/EXT_color_buffer_half_floatImpl.cpp +4 -4
- package/platforms/ios/src/cpp/webgl/extensions/EXT_disjoint_timer_queryImpl.cpp +58 -71
- package/platforms/ios/src/cpp/webgl/extensions/EXT_sRGBImpl.h +4 -4
- package/platforms/ios/src/cpp/webgl/extensions/EXT_texture_filter_anisotropicImpl.h +2 -2
- package/platforms/ios/src/cpp/webgl/extensions/OES_element_index_uintImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/OES_standard_derivativesImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/OES_texture_half_floatImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/OES_vertex_array_objectImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_color_buffer_floatImpl.h +4 -4
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_atcImpl.h +3 -3
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_etc1Impl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_etcImpl.h +10 -10
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_pvrtcImpl.h +4 -4
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_s3tcImpl.h +4 -4
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_s3tc_srgbImpl.h +4 -4
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_depth_textureImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_draw_buffersImpl.cpp +5 -13
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_draw_buffersImpl.h +40 -39
- package/platforms/ios/src/cpp/webgl2/WebGL2RenderingContext.cpp +695 -690
package/Canvas/common.js
CHANGED
|
@@ -7,32 +7,160 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
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
|
-
import { CSSType, PercentLength, View, Screen,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
import { CSSType, PercentLength, View, Screen, Utils, Application, Property, booleanConverter } from '@nativescript/core';
|
|
11
|
+
const defaultGLOptions = {
|
|
12
|
+
alpha: true,
|
|
13
|
+
antialias: true,
|
|
14
|
+
depth: true,
|
|
15
|
+
failIfMajorPerformanceCaveat: false,
|
|
16
|
+
powerPreference: 'default',
|
|
17
|
+
premultipliedAlpha: true,
|
|
18
|
+
preserveDrawingBuffer: false,
|
|
19
|
+
stencil: false,
|
|
20
|
+
desynchronized: false,
|
|
21
|
+
xrCompatible: false,
|
|
22
|
+
};
|
|
23
|
+
const default2DOptions = {
|
|
24
|
+
alpha: true,
|
|
25
|
+
antialias: true,
|
|
26
|
+
depth: true,
|
|
27
|
+
failIfMajorPerformanceCaveat: false,
|
|
28
|
+
powerPreference: 'default',
|
|
29
|
+
premultipliedAlpha: true,
|
|
30
|
+
preserveDrawingBuffer: false,
|
|
31
|
+
stencil: false,
|
|
32
|
+
desynchronized: false,
|
|
33
|
+
xrCompatible: false,
|
|
34
|
+
};
|
|
35
|
+
export class Event {
|
|
36
|
+
constructor(type, options) {
|
|
37
|
+
this.bubbles = false;
|
|
38
|
+
this.cancelable = false;
|
|
39
|
+
this.composed = false;
|
|
40
|
+
this.type = type;
|
|
41
|
+
this.bubbles = options?.bubbles ?? false;
|
|
42
|
+
this.cancelable = options?.cancelable ?? false;
|
|
43
|
+
this.cancelable = options?.cancelable ?? false;
|
|
44
|
+
this.composed = options?.composed ?? false;
|
|
19
45
|
}
|
|
20
46
|
preventDefault() { }
|
|
21
47
|
stopPropagation() { }
|
|
22
48
|
}
|
|
23
|
-
export class
|
|
24
|
-
constructor(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
49
|
+
export class UIEvent extends Event {
|
|
50
|
+
constructor(type, options) {
|
|
51
|
+
super(type, options);
|
|
52
|
+
this.detail = options?.detail ?? 0;
|
|
53
|
+
this.view = options?.view ?? null;
|
|
54
|
+
this.sourceCapabilities = options.sourceCapabilities ?? {};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export class MouseEvent extends UIEvent {
|
|
58
|
+
constructor(type, options) {
|
|
59
|
+
super(type, options);
|
|
60
|
+
this.screenX = options.screenX ?? 0;
|
|
61
|
+
this.screenY = options.screenY ?? 0;
|
|
62
|
+
this.clientX = options?.clientX ?? 0;
|
|
63
|
+
this.clientY = options?.clientY ?? 0;
|
|
64
|
+
this.ctrlKey = options?.ctrlKey ?? false;
|
|
65
|
+
this.shiftKey = options?.ctrlKey ?? false;
|
|
66
|
+
this.altKey = options?.ctrlKey ?? false;
|
|
67
|
+
this.metaKey = options?.ctrlKey ?? false;
|
|
68
|
+
this.button = options?.button ?? 0;
|
|
69
|
+
this.buttons = options?.buttons ?? 0;
|
|
70
|
+
this.relatedTarget = options?.relatedTarget ?? null;
|
|
71
|
+
this.region = options?.region ?? null;
|
|
72
|
+
this.movementX = options?.movementX ?? 0;
|
|
73
|
+
this.movementY = options?.movementY ?? 0;
|
|
74
|
+
this.pageX = options?.pageX ?? 0;
|
|
75
|
+
this.pageY = options?.pageY ?? 0;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export class PointerEvent extends MouseEvent {
|
|
79
|
+
constructor(type, options) {
|
|
80
|
+
super(type, options);
|
|
81
|
+
this.pointerType = options?.pointerType ?? '';
|
|
82
|
+
this.type = type;
|
|
83
|
+
this.pointerId = options?.pointerId ?? 0;
|
|
84
|
+
this.width = options?.width ?? 1;
|
|
85
|
+
this.height = options?.height ?? 1;
|
|
86
|
+
this.pressure = options?.pressure ?? 0;
|
|
87
|
+
this.tangentialPressure = options?.tangentialPressure ?? 0;
|
|
88
|
+
this.tiltX = options?.tiltX ?? 0;
|
|
89
|
+
this.tiltY = options?.tiltY ?? 0;
|
|
90
|
+
this.twist = options?.twist ?? 0;
|
|
91
|
+
this.isPrimary = options?.isPrimary ?? false;
|
|
92
|
+
}
|
|
93
|
+
preventDefault() { }
|
|
94
|
+
stopPropagation() { }
|
|
95
|
+
}
|
|
96
|
+
export class Touch {
|
|
97
|
+
constructor(options) {
|
|
98
|
+
this.identifier = options.identifier;
|
|
99
|
+
this.target = options.target;
|
|
100
|
+
this.clientX = options?.clientX ?? 0;
|
|
101
|
+
this.clientY = options?.clientY ?? 0;
|
|
102
|
+
this.screenX = options?.screenX ?? 0;
|
|
103
|
+
this.screenY = options?.screenY ?? 0;
|
|
104
|
+
this.pageX = options?.pageX ?? 0;
|
|
105
|
+
this.pageY = options?.pageY ?? 0;
|
|
106
|
+
this.radiusX = options?.radiusX ?? 0;
|
|
107
|
+
this.radiusY = options?.radiusY ?? 0;
|
|
108
|
+
this.rotationAngle = options?.rotationAngle ?? 0;
|
|
109
|
+
this.force = options?.force ?? 0;
|
|
110
|
+
}
|
|
111
|
+
preventDefault() { }
|
|
112
|
+
stopPropagation() { }
|
|
113
|
+
}
|
|
114
|
+
export class TouchList {
|
|
115
|
+
static fromList(list) {
|
|
116
|
+
const ret = new TouchList();
|
|
117
|
+
ret._list = list;
|
|
118
|
+
return ret;
|
|
119
|
+
}
|
|
120
|
+
static empty() {
|
|
121
|
+
const ret = new TouchList();
|
|
122
|
+
ret._list = [];
|
|
123
|
+
return ret;
|
|
124
|
+
}
|
|
125
|
+
item(index) {
|
|
126
|
+
return this._list[index];
|
|
127
|
+
}
|
|
128
|
+
get length() {
|
|
129
|
+
return this._list.length;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
export class TouchEvent extends UIEvent {
|
|
133
|
+
constructor(type, options) {
|
|
134
|
+
super(type, options);
|
|
135
|
+
this.touches = options?.touches ?? TouchList.empty();
|
|
136
|
+
this.targetTouches = options?.touches ?? TouchList.empty();
|
|
137
|
+
this.changedTouches = options?.changedTouches ?? [];
|
|
138
|
+
this.altKey = options?.altKey ?? false;
|
|
139
|
+
this.metaKey = options?.metaKey ?? false;
|
|
140
|
+
this.ctrlKey = options?.ctrlKey ?? false;
|
|
141
|
+
this.shiftKey = options?.shiftKey ?? false;
|
|
31
142
|
}
|
|
32
143
|
preventDefault() { }
|
|
33
144
|
stopPropagation() { }
|
|
34
145
|
}
|
|
35
|
-
|
|
146
|
+
export class WheelEvent extends UIEvent {
|
|
147
|
+
constructor(type, options) {
|
|
148
|
+
super('wheel', options);
|
|
149
|
+
this.deltaX = options?.deltaX ?? 0;
|
|
150
|
+
this.deltaY = options?.deltaY ?? 0;
|
|
151
|
+
this.deltaZ = options?.deltaZ ?? 0;
|
|
152
|
+
this.deltaMode = options?.deltaMode ?? 0;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
class Rectangle {
|
|
156
|
+
constructor(top, left, width, height) {
|
|
157
|
+
this.top = top;
|
|
158
|
+
this.left = left;
|
|
159
|
+
// check name of fields!
|
|
160
|
+
this.width = width;
|
|
161
|
+
this.height = height;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
36
164
|
export const ignorePixelScalingProperty = new Property({
|
|
37
165
|
name: 'ignorePixelScaling',
|
|
38
166
|
defaultValue: false,
|
|
@@ -43,34 +171,476 @@ export const upscaleProperty = new Property({
|
|
|
43
171
|
defaultValue: false,
|
|
44
172
|
valueConverter: booleanConverter,
|
|
45
173
|
});
|
|
46
|
-
let pointerId = 0;
|
|
47
174
|
let CanvasBase = class CanvasBase extends View {
|
|
48
175
|
constructor() {
|
|
49
176
|
super();
|
|
50
177
|
this._isCustom = false;
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
54
|
-
this.
|
|
55
|
-
|
|
56
|
-
this.
|
|
57
|
-
this.
|
|
178
|
+
this._pointerMoveCallbacks = new Set();
|
|
179
|
+
this._pointerUpCallbacks = new Set();
|
|
180
|
+
this._pointerDownCallbacks = new Set();
|
|
181
|
+
this._pointerCancelCallbacks = new Set();
|
|
182
|
+
// For mouse compat because wtf
|
|
183
|
+
this._mouseMoveCallbacks = new Set();
|
|
184
|
+
this._mouseUpCallbacks = new Set();
|
|
185
|
+
this._mouseDownCallbacks = new Set();
|
|
186
|
+
this._mouseCancelCallbacks = new Set();
|
|
187
|
+
this._mouseWheelCallbacks = new Set();
|
|
188
|
+
this._touchStartCallbacks = new Set();
|
|
189
|
+
this._touchEndCallbacks = new Set();
|
|
190
|
+
this._touchMoveCallbacks = new Set();
|
|
191
|
+
this._touchCancelCallbacks = new Set();
|
|
192
|
+
this._touches = [];
|
|
193
|
+
this._touchesById = [];
|
|
194
|
+
this._lastPointerEventById = new Array(10);
|
|
58
195
|
this._classList = new Set();
|
|
59
196
|
}
|
|
60
197
|
addEventListener(arg, callback, thisArg) {
|
|
61
198
|
super.addEventListener(arg, callback, thisArg);
|
|
62
|
-
|
|
63
|
-
|
|
199
|
+
const eventtype = arg.toLowerCase();
|
|
200
|
+
switch (eventtype) {
|
|
201
|
+
case 'mousemove':
|
|
202
|
+
this._mouseMoveCallbacks.add(callback);
|
|
203
|
+
break;
|
|
204
|
+
case 'pointermove':
|
|
205
|
+
this._pointerMoveCallbacks.add(callback);
|
|
206
|
+
break;
|
|
207
|
+
case 'mousedown':
|
|
208
|
+
this._mouseDownCallbacks.add(callback);
|
|
209
|
+
break;
|
|
210
|
+
case 'pointerdown':
|
|
211
|
+
this._pointerDownCallbacks.add(callback);
|
|
212
|
+
break;
|
|
213
|
+
case 'mouseup':
|
|
214
|
+
this._mouseUpCallbacks.add(callback);
|
|
215
|
+
break;
|
|
216
|
+
case 'pointerup':
|
|
217
|
+
this._pointerUpCallbacks.add(callback);
|
|
218
|
+
break;
|
|
219
|
+
case 'moveout':
|
|
220
|
+
case 'mousecancel':
|
|
221
|
+
this._mouseCancelCallbacks.add(callback);
|
|
222
|
+
break;
|
|
223
|
+
case 'pointercancel':
|
|
224
|
+
this._pointerCancelCallbacks.add(callback);
|
|
225
|
+
break;
|
|
226
|
+
case 'touchstart':
|
|
227
|
+
this._touchStartCallbacks.add(callback);
|
|
228
|
+
break;
|
|
229
|
+
case 'touchend':
|
|
230
|
+
this._touchEndCallbacks.add(callback);
|
|
231
|
+
break;
|
|
232
|
+
case 'touchmove':
|
|
233
|
+
this._touchMoveCallbacks.add(callback);
|
|
234
|
+
break;
|
|
235
|
+
case 'touchcancel':
|
|
236
|
+
this._touchCancelCallbacks.add(callback);
|
|
237
|
+
break;
|
|
238
|
+
case 'wheel':
|
|
239
|
+
case 'mousewheel':
|
|
240
|
+
case 'dommousescroll':
|
|
241
|
+
this._mouseWheelCallbacks.add(callback);
|
|
242
|
+
break;
|
|
64
243
|
}
|
|
65
244
|
}
|
|
66
245
|
removeEventListener(arg, callback, thisArg) {
|
|
67
246
|
super.removeEventListener(arg, callback, thisArg);
|
|
68
|
-
if (WEB_GESTURE_EVENTS.indexOf(arg) !== -1) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
247
|
+
// if (WEB_GESTURE_EVENTS.indexOf(arg) !== -1) {
|
|
248
|
+
// // if we dont have any other web gestures we can unregister gestures
|
|
249
|
+
// if (!WEB_GESTURE_EVENTS.some((e) => this.hasListeners(e))) {
|
|
250
|
+
// this.__unregisterGestures();
|
|
251
|
+
// }
|
|
252
|
+
// }
|
|
253
|
+
const eventtype = arg.toLowerCase();
|
|
254
|
+
switch (eventtype) {
|
|
255
|
+
case 'mousemove':
|
|
256
|
+
this._mouseMoveCallbacks.delete(callback);
|
|
257
|
+
break;
|
|
258
|
+
case 'pointermove':
|
|
259
|
+
this._pointerMoveCallbacks.delete(callback);
|
|
260
|
+
break;
|
|
261
|
+
case 'mousedown':
|
|
262
|
+
this._mouseDownCallbacks.delete(callback);
|
|
263
|
+
break;
|
|
264
|
+
case 'pointerdown':
|
|
265
|
+
this._pointerDownCallbacks.delete(callback);
|
|
266
|
+
break;
|
|
267
|
+
case 'mouseup':
|
|
268
|
+
this._mouseUpCallbacks.delete(callback);
|
|
269
|
+
break;
|
|
270
|
+
case 'pointerup':
|
|
271
|
+
this._pointerUpCallbacks.delete(callback);
|
|
272
|
+
break;
|
|
273
|
+
case 'moveout':
|
|
274
|
+
case 'mousecancel':
|
|
275
|
+
this._mouseCancelCallbacks.delete(callback);
|
|
276
|
+
break;
|
|
277
|
+
case 'pointercancel':
|
|
278
|
+
this._pointerCancelCallbacks.delete(callback);
|
|
279
|
+
break;
|
|
280
|
+
case 'touchstart':
|
|
281
|
+
this._touchStartCallbacks.delete(callback);
|
|
282
|
+
break;
|
|
283
|
+
case 'touchend':
|
|
284
|
+
this._touchEndCallbacks.delete(callback);
|
|
285
|
+
break;
|
|
286
|
+
case 'touchmove':
|
|
287
|
+
this._touchMoveCallbacks.delete(callback);
|
|
288
|
+
break;
|
|
289
|
+
case 'touchcancel':
|
|
290
|
+
this._touchCancelCallbacks.delete(callback);
|
|
291
|
+
break;
|
|
292
|
+
case 'wheel':
|
|
293
|
+
case 'mousewheel':
|
|
294
|
+
case 'dommousescroll':
|
|
295
|
+
this._mouseWheelCallbacks.delete(callback);
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
_moveCallback(pointers) {
|
|
300
|
+
const hasPointerCallbacks = this._pointerMoveCallbacks.size > 0;
|
|
301
|
+
const hasMouseCallbacks = this._mouseMoveCallbacks.size > 0;
|
|
302
|
+
if (hasPointerCallbacks || hasMouseCallbacks) {
|
|
303
|
+
for (const pointer of pointers) {
|
|
304
|
+
const pointerId = pointer.ptrId;
|
|
305
|
+
const previousEvent = this._lastPointerEventById[pointerId];
|
|
306
|
+
if (hasPointerCallbacks) {
|
|
307
|
+
const event = new PointerEvent('pointermove', {
|
|
308
|
+
pointerType: 'touch',
|
|
309
|
+
pointerId,
|
|
310
|
+
clientX: pointer.x,
|
|
311
|
+
clientY: pointer.y,
|
|
312
|
+
screenX: pointer.x,
|
|
313
|
+
screenY: pointer.y,
|
|
314
|
+
pageX: pointer.x,
|
|
315
|
+
pageY: pointer.y,
|
|
316
|
+
movementX: pointer.x - previousEvent.x,
|
|
317
|
+
movementY: pointer.y - previousEvent.y,
|
|
318
|
+
isPrimary: pointerId === 0,
|
|
319
|
+
});
|
|
320
|
+
for (const callback of this._pointerMoveCallbacks) {
|
|
321
|
+
callback(event);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (hasMouseCallbacks) {
|
|
325
|
+
const event = new MouseEvent('mousemove', {
|
|
326
|
+
clientX: pointer.x,
|
|
327
|
+
clientY: pointer.y,
|
|
328
|
+
screenX: pointer.x,
|
|
329
|
+
screenY: pointer.y,
|
|
330
|
+
pageX: pointer.x,
|
|
331
|
+
pageY: pointer.y,
|
|
332
|
+
movementX: pointer.x - previousEvent.x,
|
|
333
|
+
movementY: pointer.y - previousEvent.y,
|
|
334
|
+
});
|
|
335
|
+
for (const callback of this._mouseMoveCallbacks) {
|
|
336
|
+
callback(event);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
this._lastPointerEventById[pointerId] = { pointerId, x: pointer.x, y: pointer.y };
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (this._touchMoveCallbacks.size > 0) {
|
|
343
|
+
const changedTouches = [];
|
|
344
|
+
for (const pointer of pointers) {
|
|
345
|
+
changedTouches.push(new Touch({
|
|
346
|
+
identifier: pointer.ptrId,
|
|
347
|
+
target: null,
|
|
348
|
+
clientX: pointer.x,
|
|
349
|
+
clientY: pointer.y,
|
|
350
|
+
screenX: pointer.x,
|
|
351
|
+
screenY: pointer.y,
|
|
352
|
+
pageX: pointer.x,
|
|
353
|
+
pageY: pointer.y,
|
|
354
|
+
}));
|
|
355
|
+
}
|
|
356
|
+
const touches = TouchList.fromList(this._touches);
|
|
357
|
+
const event = new TouchEvent('touchmove', {
|
|
358
|
+
touches,
|
|
359
|
+
targetTouches: touches,
|
|
360
|
+
changedTouches,
|
|
361
|
+
});
|
|
362
|
+
for (const callback of this._touchMoveCallbacks) {
|
|
363
|
+
callback(event);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
_upCallback(ptrId, x, y) {
|
|
368
|
+
const hasPointerCallbacks = this._pointerUpCallbacks.size > 0;
|
|
369
|
+
const hasMouseCallbacks = this._mouseUpCallbacks.size > 0;
|
|
370
|
+
if (hasPointerCallbacks || hasMouseCallbacks) {
|
|
371
|
+
const pointerId = ptrId;
|
|
372
|
+
if (hasPointerCallbacks) {
|
|
373
|
+
const event = new PointerEvent('pointerup', {
|
|
374
|
+
pointerType: 'touch',
|
|
375
|
+
pointerId,
|
|
376
|
+
clientX: x,
|
|
377
|
+
clientY: y,
|
|
378
|
+
screenX: x,
|
|
379
|
+
screenY: y,
|
|
380
|
+
isPrimary: pointerId === 0,
|
|
381
|
+
pageX: x,
|
|
382
|
+
pageY: y,
|
|
383
|
+
});
|
|
384
|
+
for (const callback of this._pointerUpCallbacks) {
|
|
385
|
+
callback(event);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (hasMouseCallbacks) {
|
|
389
|
+
const event = new MouseEvent('mouseup', {
|
|
390
|
+
clientX: x,
|
|
391
|
+
clientY: y,
|
|
392
|
+
screenX: x,
|
|
393
|
+
screenY: y,
|
|
394
|
+
pageX: x,
|
|
395
|
+
pageY: y,
|
|
396
|
+
});
|
|
397
|
+
for (const callback of this._mouseUpCallbacks) {
|
|
398
|
+
callback(event);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
delete this._lastPointerEventById[pointerId];
|
|
402
|
+
}
|
|
403
|
+
if (this._touchEndCallbacks.size > 0) {
|
|
404
|
+
const length = this._touches.length;
|
|
405
|
+
for (var i = 0; i < length; i++) {
|
|
406
|
+
if (this._touches[i].identifier == ptrId) {
|
|
407
|
+
this._touches.splice(i, 1);
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
const touches = TouchList.fromList(this._touches);
|
|
412
|
+
const event = new TouchEvent('touchend', {
|
|
413
|
+
touches,
|
|
414
|
+
targetTouches: touches,
|
|
415
|
+
changedTouches: this._touches,
|
|
416
|
+
});
|
|
417
|
+
for (const callback of this._touchEndCallbacks) {
|
|
418
|
+
callback(event);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
_downCallback(ptrId, x, y) {
|
|
423
|
+
const hasPointerCallbacks = this._pointerDownCallbacks.size > 0;
|
|
424
|
+
const hasMouseCallbacks = this._mouseDownCallbacks.size > 0;
|
|
425
|
+
if (hasPointerCallbacks || hasMouseCallbacks) {
|
|
426
|
+
const pointerId = ptrId;
|
|
427
|
+
if (hasPointerCallbacks) {
|
|
428
|
+
const event = new PointerEvent('pointerdown', {
|
|
429
|
+
pointerType: 'touch',
|
|
430
|
+
pointerId,
|
|
431
|
+
clientX: x,
|
|
432
|
+
clientY: y,
|
|
433
|
+
screenX: x,
|
|
434
|
+
screenY: y,
|
|
435
|
+
isPrimary: pointerId === 0,
|
|
436
|
+
pageX: x,
|
|
437
|
+
pageY: y,
|
|
438
|
+
});
|
|
439
|
+
for (const callback of this._pointerDownCallbacks) {
|
|
440
|
+
callback(event);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
if (hasMouseCallbacks) {
|
|
444
|
+
const event = new MouseEvent('mousedown', {
|
|
445
|
+
clientX: x,
|
|
446
|
+
clientY: y,
|
|
447
|
+
screenX: x,
|
|
448
|
+
screenY: y,
|
|
449
|
+
pageX: x,
|
|
450
|
+
pageY: y,
|
|
451
|
+
});
|
|
452
|
+
for (const callback of this._mouseDownCallbacks) {
|
|
453
|
+
callback(event);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
this._lastPointerEventById[pointerId] = { pointerId, x, y };
|
|
457
|
+
}
|
|
458
|
+
if (this._touchStartCallbacks.size > 0) {
|
|
459
|
+
const touch = new Touch({
|
|
460
|
+
identifier: ptrId,
|
|
461
|
+
target: this,
|
|
462
|
+
clientX: x,
|
|
463
|
+
clientY: y,
|
|
464
|
+
screenX: x,
|
|
465
|
+
screenY: y,
|
|
466
|
+
pageX: x,
|
|
467
|
+
pageY: y,
|
|
468
|
+
});
|
|
469
|
+
this._touches.push(touch);
|
|
470
|
+
this._touchesById[ptrId] = touch;
|
|
471
|
+
const touches = TouchList.fromList(this._touches);
|
|
472
|
+
const touchEvent = new TouchEvent('touchstart', {
|
|
473
|
+
touches,
|
|
474
|
+
targetTouches: touches,
|
|
475
|
+
changedTouches: this._touches,
|
|
476
|
+
});
|
|
477
|
+
for (const callback of this._touchStartCallbacks) {
|
|
478
|
+
callback(touchEvent);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
_cancelCallback(ptrid, x, y) {
|
|
483
|
+
const hasPointerCallbacks = this._pointerCancelCallbacks.size > 0;
|
|
484
|
+
const hasMouseCallbacks = this._mouseCancelCallbacks.size > 0;
|
|
485
|
+
if (hasPointerCallbacks || hasMouseCallbacks) {
|
|
486
|
+
const pointerId = ptrid;
|
|
487
|
+
if (hasPointerCallbacks) {
|
|
488
|
+
const event = new PointerEvent('pointercancel', {
|
|
489
|
+
pointerType: 'touch',
|
|
490
|
+
pointerId,
|
|
491
|
+
clientX: x,
|
|
492
|
+
clientY: y,
|
|
493
|
+
screenX: x,
|
|
494
|
+
screenY: y,
|
|
495
|
+
pageX: x,
|
|
496
|
+
pageY: y,
|
|
497
|
+
});
|
|
498
|
+
for (const callback of this._pointerCancelCallbacks) {
|
|
499
|
+
callback(event);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
if (hasMouseCallbacks) {
|
|
503
|
+
const event = new MouseEvent('mouseout', {
|
|
504
|
+
clientX: x,
|
|
505
|
+
clientY: y,
|
|
506
|
+
screenX: x,
|
|
507
|
+
screenY: y,
|
|
508
|
+
pageX: x,
|
|
509
|
+
pageY: y,
|
|
510
|
+
});
|
|
511
|
+
for (const callback of this._mouseCancelCallbacks) {
|
|
512
|
+
callback(event);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (this._touchCancelCallbacks.size > 0) {
|
|
517
|
+
const touch = new Touch({
|
|
518
|
+
identifier: ptrid,
|
|
519
|
+
target: this,
|
|
520
|
+
clientX: x,
|
|
521
|
+
clientY: y,
|
|
522
|
+
screenX: x,
|
|
523
|
+
screenY: y,
|
|
524
|
+
pageX: x,
|
|
525
|
+
pageY: y,
|
|
526
|
+
});
|
|
527
|
+
this._touches.push(touch);
|
|
528
|
+
this._touchesById[ptrid] = touch;
|
|
529
|
+
const touches = TouchList.fromList(this._touches);
|
|
530
|
+
const touchEvent = new TouchEvent('touchcancel', {
|
|
531
|
+
touches,
|
|
532
|
+
targetTouches: touches,
|
|
533
|
+
changedTouches: this._touches,
|
|
534
|
+
});
|
|
535
|
+
for (const callback of this._touchCancelCallbacks) {
|
|
536
|
+
callback(touchEvent);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
_pinchCallback(data) {
|
|
541
|
+
// move callback
|
|
542
|
+
const hasPointerCallbacks = this._pointerMoveCallbacks.size > 0;
|
|
543
|
+
const hasMouseCallbacks = this._mouseMoveCallbacks.size > 0;
|
|
544
|
+
const hasMouseWheel = this._mouseWheelCallbacks.size > 0;
|
|
545
|
+
if (hasPointerCallbacks || hasMouseCallbacks || hasMouseWheel) {
|
|
546
|
+
for (const pointer of data.pointers) {
|
|
547
|
+
const pointerId = pointer.ptrId;
|
|
548
|
+
const previousEvent = this._lastPointerEventById[pointerId];
|
|
549
|
+
if (hasPointerCallbacks) {
|
|
550
|
+
const event = new PointerEvent('pointermove', {
|
|
551
|
+
pointerType: 'touch',
|
|
552
|
+
pointerId,
|
|
553
|
+
clientX: pointer.x,
|
|
554
|
+
clientY: pointer.y,
|
|
555
|
+
screenX: pointer.x,
|
|
556
|
+
screenY: pointer.y,
|
|
557
|
+
pageX: pointer.x,
|
|
558
|
+
pageY: pointer.y,
|
|
559
|
+
movementX: pointer.x - previousEvent.x,
|
|
560
|
+
movementY: pointer.y - previousEvent.y,
|
|
561
|
+
});
|
|
562
|
+
for (const callback of this._pointerMoveCallbacks) {
|
|
563
|
+
callback(event);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
if (hasMouseCallbacks) {
|
|
567
|
+
const event = new MouseEvent('mousemove', {
|
|
568
|
+
clientX: pointer.x,
|
|
569
|
+
clientY: pointer.y,
|
|
570
|
+
screenX: pointer.x,
|
|
571
|
+
screenY: pointer.y,
|
|
572
|
+
pageX: pointer.x,
|
|
573
|
+
pageY: pointer.y,
|
|
574
|
+
movementX: pointer.x - previousEvent.x,
|
|
575
|
+
movementY: pointer.y - previousEvent.y,
|
|
576
|
+
});
|
|
577
|
+
for (const callback of this._mouseMoveCallbacks) {
|
|
578
|
+
callback(event);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
if (hasMouseWheel) {
|
|
582
|
+
const event = new WheelEvent('wheel', {
|
|
583
|
+
deltaX: data.deltaX,
|
|
584
|
+
deltaY: data.deltaY,
|
|
585
|
+
deltaZ: 0,
|
|
586
|
+
deltaMode: data.deltaMode,
|
|
587
|
+
});
|
|
588
|
+
for (const callback of this._mouseWheelCallbacks) {
|
|
589
|
+
callback(event);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
this._lastPointerEventById[pointerId] = { pointerId, x: pointer.x, y: pointer.y };
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
if (this._touchMoveCallbacks.size > 0) {
|
|
596
|
+
const changedTouches = [];
|
|
597
|
+
for (const pointer of data.pointers) {
|
|
598
|
+
changedTouches.push(new Touch({
|
|
599
|
+
identifier: pointer.ptrId,
|
|
600
|
+
target: this,
|
|
601
|
+
clientX: pointer.x,
|
|
602
|
+
clientY: pointer.y,
|
|
603
|
+
screenX: pointer.x,
|
|
604
|
+
screenY: pointer.y,
|
|
605
|
+
pageX: pointer.x,
|
|
606
|
+
pageY: pointer.y,
|
|
607
|
+
}));
|
|
608
|
+
}
|
|
609
|
+
const touches = TouchList.fromList(this._touches);
|
|
610
|
+
const event = new TouchEvent('touchmove', {
|
|
611
|
+
touches,
|
|
612
|
+
targetTouches: touches,
|
|
613
|
+
changedTouches,
|
|
614
|
+
});
|
|
615
|
+
for (const callback of this._touchMoveCallbacks) {
|
|
616
|
+
callback(event);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
_handleEvents(event) {
|
|
621
|
+
try {
|
|
622
|
+
const data = JSON.parse(event);
|
|
623
|
+
switch (data.event) {
|
|
624
|
+
case 'down':
|
|
625
|
+
this._downCallback(data.ptrId, data.x, data.y);
|
|
626
|
+
break;
|
|
627
|
+
case 'move':
|
|
628
|
+
this._moveCallback(data.pointers);
|
|
629
|
+
break;
|
|
630
|
+
case 'up':
|
|
631
|
+
this._upCallback(data.ptrId, data.x, data.y);
|
|
632
|
+
break;
|
|
633
|
+
case 'scale':
|
|
634
|
+
this._pinchCallback(data);
|
|
635
|
+
break;
|
|
636
|
+
case 'cancel':
|
|
637
|
+
this._cancelCallback(data.ptrId, data.x, data.y);
|
|
638
|
+
break;
|
|
639
|
+
default:
|
|
640
|
+
break;
|
|
72
641
|
}
|
|
73
642
|
}
|
|
643
|
+
catch (error) { }
|
|
74
644
|
}
|
|
75
645
|
get classList() {
|
|
76
646
|
return this._classList;
|
|
@@ -82,35 +652,12 @@ let CanvasBase = class CanvasBase extends View {
|
|
|
82
652
|
};
|
|
83
653
|
}
|
|
84
654
|
_handleContextOptions(type, contextOpts) {
|
|
85
|
-
const defaultGLOptions = {
|
|
86
|
-
alpha: true,
|
|
87
|
-
antialias: true,
|
|
88
|
-
depth: true,
|
|
89
|
-
failIfMajorPerformanceCaveat: false,
|
|
90
|
-
powerPreference: 'default',
|
|
91
|
-
premultipliedAlpha: true,
|
|
92
|
-
preserveDrawingBuffer: false,
|
|
93
|
-
stencil: false,
|
|
94
|
-
desynchronized: false,
|
|
95
|
-
xrCompatible: false,
|
|
96
|
-
};
|
|
97
655
|
if (!contextOpts) {
|
|
98
656
|
if (type === '2d') {
|
|
99
|
-
return {
|
|
100
|
-
alpha: true,
|
|
101
|
-
antialias: true,
|
|
102
|
-
depth: true,
|
|
103
|
-
failIfMajorPerformanceCaveat: false,
|
|
104
|
-
powerPreference: 'default',
|
|
105
|
-
premultipliedAlpha: true,
|
|
106
|
-
preserveDrawingBuffer: false,
|
|
107
|
-
stencil: false,
|
|
108
|
-
desynchronized: false,
|
|
109
|
-
xrCompatible: false,
|
|
110
|
-
};
|
|
657
|
+
return { ...default2DOptions };
|
|
111
658
|
}
|
|
112
659
|
if (type.indexOf('webgl') > -1) {
|
|
113
|
-
return defaultGLOptions;
|
|
660
|
+
return { ...defaultGLOptions };
|
|
114
661
|
}
|
|
115
662
|
}
|
|
116
663
|
if (type === '2d') {
|
|
@@ -121,10 +668,11 @@ let CanvasBase = class CanvasBase extends View {
|
|
|
121
668
|
return { alpha: true };
|
|
122
669
|
}
|
|
123
670
|
}
|
|
671
|
+
const glOptions = { ...defaultGLOptions };
|
|
124
672
|
const setIfDefined = (prop, value) => {
|
|
125
|
-
const property =
|
|
673
|
+
const property = glOptions[prop];
|
|
126
674
|
if (property !== undefined && typeof value === typeof property) {
|
|
127
|
-
|
|
675
|
+
glOptions[prop] = value;
|
|
128
676
|
}
|
|
129
677
|
};
|
|
130
678
|
if (type.indexOf('webgl') > -1) {
|
|
@@ -137,7 +685,7 @@ let CanvasBase = class CanvasBase extends View {
|
|
|
137
685
|
setIfDefined('preserveDrawingBuffer', contextOpts.preserveDrawingBuffer);
|
|
138
686
|
setIfDefined('stencil', contextOpts.stencil);
|
|
139
687
|
setIfDefined('desynchronized', contextOpts.desynchronized);
|
|
140
|
-
return
|
|
688
|
+
return glOptions;
|
|
141
689
|
}
|
|
142
690
|
return null;
|
|
143
691
|
}
|
|
@@ -179,451 +727,38 @@ let CanvasBase = class CanvasBase extends View {
|
|
|
179
727
|
value = PercentLength.parse(value);
|
|
180
728
|
}
|
|
181
729
|
if (typeof value === 'number') {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
730
|
+
if (global.isAndroid) {
|
|
731
|
+
return Utils.layout.toDevicePixels(value) || 0;
|
|
732
|
+
}
|
|
185
733
|
return value || 0;
|
|
186
734
|
}
|
|
187
735
|
else if ((value !== null || true) && typeof value === 'object' && typeof value.value && typeof value.unit) {
|
|
188
736
|
if (value.unit === 'px') {
|
|
737
|
+
if (global.isIOS) {
|
|
738
|
+
return Utils.layout.toDeviceIndependentPixels(value.value || 0);
|
|
739
|
+
}
|
|
189
740
|
return value.value || 0;
|
|
190
741
|
}
|
|
191
742
|
else if (value.unit === 'dip') {
|
|
192
|
-
|
|
743
|
+
if (global.isAndroid) {
|
|
744
|
+
return Utils.layout.toDevicePixels(value.value) || 0;
|
|
745
|
+
}
|
|
746
|
+
return value.value || 0;
|
|
193
747
|
}
|
|
194
748
|
else if (value.unit === '%') {
|
|
195
749
|
const orientation = Application.orientation();
|
|
196
750
|
if (orientation === 'portrait' || orientation === 'landscape') {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return 0;
|
|
202
|
-
}
|
|
203
|
-
setPointerCapture() { }
|
|
204
|
-
releasePointerCapture() { }
|
|
205
|
-
__ensureGestures() {
|
|
206
|
-
if (!this._gesturesRegistered) {
|
|
207
|
-
this._gesturesRegistered = true;
|
|
208
|
-
this.on(global.isAndroid ? 'touch, pan, pinch' : 'touch, pan, pinch', this._touchEvent, this);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
__unregisterGestures() {
|
|
212
|
-
if (this._gesturesRegistered) {
|
|
213
|
-
this._gesturesRegistered = false;
|
|
214
|
-
this.off(global.isAndroid ? 'touch, pan' : 'touch, pan, pinch', this._touchEvent, this);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
_pointerCountFromEvent(event) {
|
|
218
|
-
let count = 0;
|
|
219
|
-
if (global.isIOS) {
|
|
220
|
-
count = event.ios.numberOfTouches ?? 0;
|
|
221
|
-
}
|
|
222
|
-
else if (global.isAndroid) {
|
|
223
|
-
count = (event.android.current || event.android.initial || event.android).getPointerCount?.() ?? 0;
|
|
224
|
-
}
|
|
225
|
-
return count;
|
|
226
|
-
}
|
|
227
|
-
_positionsFromEvent(event) {
|
|
228
|
-
const positions = [];
|
|
229
|
-
if (global.isIOS) {
|
|
230
|
-
const set = event?.ios?.touches;
|
|
231
|
-
if (event?.ios?.touches instanceof NSSet) {
|
|
232
|
-
const objects = set.allObjects;
|
|
233
|
-
for (let i = 0; i < set.count; i++) {
|
|
234
|
-
const touch = objects.objectAtIndex(i);
|
|
235
|
-
const point = touch.locationInView(touch.view);
|
|
236
|
-
positions.push(point.x, point.y);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
const count = event.ios.numberOfTouches;
|
|
241
|
-
const rec = event.ios;
|
|
242
|
-
for (let i = 0; i < count; i++) {
|
|
243
|
-
const point = rec.locationOfTouchInView(i, rec.view);
|
|
244
|
-
positions.push(point.x, point.y);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
else if (global.isAndroid) {
|
|
249
|
-
const motionEvent = event.android?.current ?? event.android;
|
|
250
|
-
const count = motionEvent.getPointerCount();
|
|
251
|
-
const coords = new android.view.MotionEvent.PointerCoords();
|
|
252
|
-
for (let i = 0; i < count; i++) {
|
|
253
|
-
motionEvent.getPointerCoords(i, coords);
|
|
254
|
-
positions.push(coords.x / Screen.mainScreen.scale, coords.y / Screen.mainScreen.scale);
|
|
255
|
-
coords.clear();
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
return positions;
|
|
259
|
-
}
|
|
260
|
-
_touchEvent(event) {
|
|
261
|
-
let extraData;
|
|
262
|
-
let hasPointerDown = false;
|
|
263
|
-
let hasTouchStart = false;
|
|
264
|
-
let hasPointerMove = false;
|
|
265
|
-
let hasTouchMove = false;
|
|
266
|
-
let hasPointerUp = false;
|
|
267
|
-
let hasTouchEnd = false;
|
|
268
|
-
let hasPointerCancel = false;
|
|
269
|
-
let hasTouchCancel = false;
|
|
270
|
-
if (event.eventName === 'touch') {
|
|
271
|
-
switch (event.action) {
|
|
272
|
-
case 'down':
|
|
273
|
-
hasPointerDown = this.hasListeners('pointerdown');
|
|
274
|
-
hasTouchStart = this.hasListeners('touchstart');
|
|
275
|
-
if (hasPointerDown || hasTouchStart) {
|
|
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 && 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
|
-
this.notify({
|
|
298
|
-
...this._createPointerEvent('pointerdown', extraData),
|
|
299
|
-
pointerId: pointerId,
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
if (hasTouchStart) {
|
|
303
|
-
this.notify(this._createTouchEvent('touchstart', extraData));
|
|
304
|
-
}
|
|
305
|
-
break;
|
|
306
|
-
case 'up':
|
|
307
|
-
hasPointerUp = this.hasListeners('pointerup');
|
|
308
|
-
hasTouchEnd = this.hasListeners('touchend');
|
|
309
|
-
if (hasPointerUp || hasTouchEnd) {
|
|
310
|
-
const numberOfPointers = event.getPointerCount();
|
|
311
|
-
const positions = this._positionsFromEvent(event);
|
|
312
|
-
const x = event.getX();
|
|
313
|
-
const y = event.getY();
|
|
314
|
-
extraData = {
|
|
315
|
-
numberOfPointers,
|
|
316
|
-
positions,
|
|
317
|
-
x,
|
|
318
|
-
y,
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
if (hasPointerUp) {
|
|
322
|
-
this._previousPointerCount -= extraData.numberOfPointers;
|
|
323
|
-
for (let i = 0; i < extraData.numberOfPointers; i++) {
|
|
324
|
-
const x = extraData.positions[i];
|
|
325
|
-
const y = extraData.positions[i + 1];
|
|
326
|
-
this.notify({
|
|
327
|
-
...this._createPointerEvent('pointerup', { ...extraData, x, y }),
|
|
328
|
-
pointerId: this._pointers[i].id,
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
if (hasTouchEnd) {
|
|
333
|
-
this.notify(this._createTouchEvent('touchend', extraData));
|
|
334
|
-
}
|
|
335
|
-
break;
|
|
336
|
-
case 'cancel':
|
|
337
|
-
hasPointerCancel = this.hasListeners('pointercancel');
|
|
338
|
-
hasTouchCancel = this.hasListeners('touchcancel');
|
|
339
|
-
if (hasPointerCancel || hasTouchCancel) {
|
|
340
|
-
const numberOfPointers = event.getPointerCount();
|
|
341
|
-
const positions = this._positionsFromEvent(event);
|
|
342
|
-
const x = event.getX();
|
|
343
|
-
const y = event.getY();
|
|
344
|
-
extraData = {
|
|
345
|
-
numberOfPointers,
|
|
346
|
-
positions,
|
|
347
|
-
x,
|
|
348
|
-
y,
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
if (hasPointerCancel) {
|
|
352
|
-
if (global.isAndroid) {
|
|
353
|
-
this._previousPointerCount -= extraData.numberOfPointers;
|
|
354
|
-
}
|
|
355
|
-
else if (global.isIOS) {
|
|
356
|
-
this._previousPointerCount -= 1;
|
|
357
|
-
}
|
|
358
|
-
for (let i = 0; i < extraData.numberOfPointers; i++) {
|
|
359
|
-
const x = extraData.positions[i];
|
|
360
|
-
const y = extraData.positions[i + 1];
|
|
361
|
-
this.notify({
|
|
362
|
-
...this._createPointerEvent('pointercancel', { ...extraData, x, y }),
|
|
363
|
-
pointerId: this._pointers[i].id,
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
if (hasTouchCancel) {
|
|
368
|
-
this.notify(this._createTouchEvent('touchcancel', extraData));
|
|
369
|
-
}
|
|
370
|
-
break;
|
|
371
|
-
case 'move':
|
|
372
|
-
if (this._isPinching && global.isAndroid) {
|
|
373
|
-
const numberOfPointers = this._pointerCountFromEvent(event);
|
|
374
|
-
hasPointerMove = this.hasListeners('pointermove');
|
|
375
|
-
hasTouchMove = this.hasListeners('touchmove');
|
|
376
|
-
let data = {};
|
|
377
|
-
if (hasPointerMove || hasTouchMove) {
|
|
378
|
-
const positions = this._positionsFromEvent(event);
|
|
379
|
-
extraData = {
|
|
380
|
-
numberOfPointers,
|
|
381
|
-
positions,
|
|
382
|
-
x: positions[0],
|
|
383
|
-
y: positions[1],
|
|
384
|
-
};
|
|
385
|
-
const dx = extraData.positions[2] - extraData.positions[0];
|
|
386
|
-
const dy = extraData.positions[3] - extraData.positions[1];
|
|
387
|
-
let delta = 0;
|
|
388
|
-
var distance = Math.sqrt(dx * dx + dy * dy);
|
|
389
|
-
if (this._previousPinchDistance) {
|
|
390
|
-
delta = this._previousPinchDistance - distance;
|
|
391
|
-
}
|
|
392
|
-
this._previousPinchDistance = distance;
|
|
393
|
-
const x = dx; //event.getFocusX();
|
|
394
|
-
const y = dy; //event.getFocusY();
|
|
395
|
-
const scale = event.scale;
|
|
396
|
-
data = {
|
|
397
|
-
deltaMode: 0,
|
|
398
|
-
clientX: x,
|
|
399
|
-
clientY: y,
|
|
400
|
-
screenX: x,
|
|
401
|
-
screenY: y,
|
|
402
|
-
deltaX: 0,
|
|
403
|
-
deltaY: delta,
|
|
404
|
-
deltaZ: 0,
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
if (hasPointerMove) {
|
|
408
|
-
const count = extraData.numberOfPointers;
|
|
409
|
-
const positions = extraData.positions;
|
|
410
|
-
for (let i = 0; i < count; i++) {
|
|
411
|
-
let x = positions[i] - extraData.x;
|
|
412
|
-
let y = positions[i + 1] - extraData.y;
|
|
413
|
-
this.notify({
|
|
414
|
-
...this._createPointerEvent('pointermove', { ...extraData, x, y }),
|
|
415
|
-
pointerId: this._pointers[i].id,
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
if (hasTouchMove) {
|
|
420
|
-
this.notify(this._createTouchEvent('touchmove', { ...extraData, data }));
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
break;
|
|
424
|
-
default:
|
|
425
|
-
break;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
else if (event.eventName === 'pinch') {
|
|
429
|
-
if (global.isAndroid) {
|
|
430
|
-
if (event.state === GestureStateTypes.began || event.state === GestureStateTypes.changed) {
|
|
431
|
-
this._isPinching = true;
|
|
432
|
-
this._previousPinchDistance = 0;
|
|
433
|
-
}
|
|
434
|
-
if (event.state === GestureStateTypes.ended || event.state === GestureStateTypes.cancelled) {
|
|
435
|
-
this._isPinching = false;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
else {
|
|
439
|
-
const numberOfPointers = this._pointerCountFromEvent(event);
|
|
440
|
-
if (!this._isPinching && numberOfPointers >= 2 && (event.state === GestureStateTypes.began || event.state === GestureStateTypes.changed)) {
|
|
441
|
-
this._previousPinchDistance = 0;
|
|
442
|
-
this._isPinching = true;
|
|
443
|
-
}
|
|
444
|
-
if (event.state === GestureStateTypes.ended || event.state === GestureStateTypes.cancelled) {
|
|
445
|
-
this._isPinching = false;
|
|
446
|
-
}
|
|
447
|
-
if (this._isPinching && numberOfPointers >= 2) {
|
|
448
|
-
if (global.isIOS) {
|
|
449
|
-
hasPointerMove = this.hasListeners('pointermove');
|
|
450
|
-
hasTouchMove = this.hasListeners('touchmove');
|
|
451
|
-
let data = {};
|
|
452
|
-
let delta = 0;
|
|
453
|
-
if (hasPointerMove || hasTouchMove) {
|
|
454
|
-
const positions = this._positionsFromEvent(event);
|
|
455
|
-
extraData = {
|
|
456
|
-
numberOfPointers,
|
|
457
|
-
positions,
|
|
458
|
-
x: positions[0],
|
|
459
|
-
y: positions[1],
|
|
460
|
-
};
|
|
461
|
-
const dx = extraData.positions[2] - extraData.positions[0];
|
|
462
|
-
const dy = extraData.positions[3] - extraData.positions[1];
|
|
463
|
-
var distance = Math.sqrt(dx * dx + dy * dy);
|
|
464
|
-
if (this._previousPinchDistance) {
|
|
465
|
-
delta = this._previousPinchDistance - distance;
|
|
466
|
-
}
|
|
467
|
-
this._previousPinchDistance = distance;
|
|
468
|
-
const x = event.getFocusX();
|
|
469
|
-
const y = event.getFocusY();
|
|
470
|
-
const scale = event.scale;
|
|
471
|
-
data = {
|
|
472
|
-
deltaMode: 0,
|
|
473
|
-
clientX: x,
|
|
474
|
-
clientY: y,
|
|
475
|
-
screenX: x,
|
|
476
|
-
screenY: y,
|
|
477
|
-
deltaX: 0,
|
|
478
|
-
deltaY: delta,
|
|
479
|
-
deltaZ: 0,
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
if (hasPointerMove) {
|
|
483
|
-
const count = extraData.numberOfPointers;
|
|
484
|
-
const positions = extraData.positions;
|
|
485
|
-
for (let i = 0; i < count; i++) {
|
|
486
|
-
let x = positions[i] - extraData.x;
|
|
487
|
-
let y = positions[i + 1] - extraData.y;
|
|
488
|
-
this.notify({
|
|
489
|
-
...this._createPointerEvent('pointermove', { ...extraData, x, y }),
|
|
490
|
-
pointerId: this._pointers[i].id,
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
if (hasTouchMove) {
|
|
495
|
-
this.notify(this._createTouchEvent('touchmove', { ...extraData, data }));
|
|
496
|
-
}
|
|
751
|
+
if (global.isAndroid) {
|
|
752
|
+
return (measuredSize ?? (type === 'width' ? Screen.mainScreen.widthPixels : Screen.mainScreen.heightPixels)) * value.value ?? 0;
|
|
497
753
|
}
|
|
754
|
+
return (measuredSize ?? (type === 'width' ? Screen.mainScreen.widthDIPs : Screen.mainScreen.heightDIPs)) * value.value ?? 0;
|
|
498
755
|
}
|
|
499
756
|
}
|
|
500
757
|
}
|
|
501
|
-
|
|
502
|
-
if (this._isPinching) {
|
|
503
|
-
return;
|
|
504
|
-
}
|
|
505
|
-
if (event.state === GestureStateTypes.began || event.state === GestureStateTypes.changed) {
|
|
506
|
-
hasPointerMove = this.hasListeners('pointermove');
|
|
507
|
-
hasTouchMove = this.hasListeners('touchmove');
|
|
508
|
-
if (hasPointerMove || hasTouchMove) {
|
|
509
|
-
const numberOfPointers = this._pointerCountFromEvent(event);
|
|
510
|
-
const positions = this._positionsFromEvent(event);
|
|
511
|
-
const x = positions[0];
|
|
512
|
-
const y = positions[1];
|
|
513
|
-
extraData = {
|
|
514
|
-
numberOfPointers,
|
|
515
|
-
positions,
|
|
516
|
-
x,
|
|
517
|
-
y,
|
|
518
|
-
};
|
|
519
|
-
}
|
|
520
|
-
if (hasPointerMove) {
|
|
521
|
-
const positions = extraData.positions;
|
|
522
|
-
for (let i = 0; i < extraData.numberOfPointers; i++) {
|
|
523
|
-
const x = positions[i];
|
|
524
|
-
const y = positions[i + 1];
|
|
525
|
-
this.notify({
|
|
526
|
-
...this._createPointerEvent('pointermove', { numberOfPointers: extraData.numberOfPointers, positions, x, y }),
|
|
527
|
-
pointerId: this._pointers[i].id,
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
if (hasTouchMove) {
|
|
532
|
-
this.notify(this._createTouchEvent('touchmove', extraData));
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
_createTouchEvent(name, extraData) {
|
|
538
|
-
const count = extraData.numberOfPointers;
|
|
539
|
-
const point = extraData.positions;
|
|
540
|
-
if (!point) {
|
|
541
|
-
return null;
|
|
542
|
-
}
|
|
543
|
-
const x = extraData.x;
|
|
544
|
-
const y = extraData.y;
|
|
545
|
-
const activePointer = {
|
|
546
|
-
clientX: x,
|
|
547
|
-
clientY: y,
|
|
548
|
-
force: 0.0,
|
|
549
|
-
identifier: 0,
|
|
550
|
-
pageX: x,
|
|
551
|
-
pageY: y,
|
|
552
|
-
radiusX: 0,
|
|
553
|
-
radiusY: 0,
|
|
554
|
-
rotationAngle: 0,
|
|
555
|
-
screenX: x,
|
|
556
|
-
screenY: y,
|
|
557
|
-
};
|
|
558
|
-
const pointers = [];
|
|
559
|
-
for (let i = 0; i < count; i++) {
|
|
560
|
-
const x = extraData.positions[i];
|
|
561
|
-
const y = extraData.positions[i + 1];
|
|
562
|
-
pointers.push({
|
|
563
|
-
clientX: x,
|
|
564
|
-
clientY: y,
|
|
565
|
-
force: 0.0,
|
|
566
|
-
identifier: i,
|
|
567
|
-
pageX: x,
|
|
568
|
-
pageY: y,
|
|
569
|
-
radiusX: 0,
|
|
570
|
-
radiusY: 0,
|
|
571
|
-
rotationAngle: 0,
|
|
572
|
-
screenX: x,
|
|
573
|
-
screenY: y,
|
|
574
|
-
target: this,
|
|
575
|
-
});
|
|
576
|
-
}
|
|
577
|
-
return Object.assign(new TouchEvent(name), {
|
|
578
|
-
eventName: name,
|
|
579
|
-
defaultPrevented: false,
|
|
580
|
-
cancelable: false,
|
|
581
|
-
altKey: false,
|
|
582
|
-
ctrlKey: false,
|
|
583
|
-
metaKey: false,
|
|
584
|
-
shiftKey: false,
|
|
585
|
-
target: this,
|
|
586
|
-
changedTouches: pointers,
|
|
587
|
-
targetTouches: pointers,
|
|
588
|
-
touches: pointers,
|
|
589
|
-
...activePointer,
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
_createPointerEvent(name, extraData) {
|
|
593
|
-
const x = extraData.x;
|
|
594
|
-
const y = extraData.y;
|
|
595
|
-
const activePointer = {
|
|
596
|
-
clientX: x,
|
|
597
|
-
clientY: y,
|
|
598
|
-
force: 0.0,
|
|
599
|
-
identifier: 0,
|
|
600
|
-
pageX: x,
|
|
601
|
-
pageY: y,
|
|
602
|
-
radiusX: 0,
|
|
603
|
-
radiusY: 0,
|
|
604
|
-
rotationAngle: 0,
|
|
605
|
-
screenX: x,
|
|
606
|
-
screenY: y,
|
|
607
|
-
pointerId: 0,
|
|
608
|
-
pointerType: 'touch',
|
|
609
|
-
x,
|
|
610
|
-
y,
|
|
611
|
-
width: 23.4375,
|
|
612
|
-
height: 23.4375,
|
|
613
|
-
isPrimary: true,
|
|
614
|
-
};
|
|
615
|
-
return Object.assign(new PointerEvent(name), {
|
|
616
|
-
eventName: name,
|
|
617
|
-
defaultPrevented: false,
|
|
618
|
-
cancelable: false,
|
|
619
|
-
altKey: false,
|
|
620
|
-
ctrlKey: false,
|
|
621
|
-
metaKey: false,
|
|
622
|
-
shiftKey: false,
|
|
623
|
-
target: this,
|
|
624
|
-
...activePointer,
|
|
625
|
-
});
|
|
758
|
+
return 0;
|
|
626
759
|
}
|
|
760
|
+
setPointerCapture(id) { }
|
|
761
|
+
releasePointerCapture(id) { }
|
|
627
762
|
};
|
|
628
763
|
CanvasBase.readyEvent = 'ready';
|
|
629
764
|
CanvasBase = __decorate([
|