@nativescript/canvas 2.0.0-rc.2 → 2.0.0-rc.21
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 +13 -6
- package/Canvas/common.js +257 -206
- package/Canvas/common.js.map +1 -1
- package/Canvas/index.android.d.ts +2 -0
- package/Canvas/index.android.js +23 -4
- package/Canvas/index.android.js.map +1 -1
- package/Canvas/index.d.ts +3 -0
- package/Canvas/index.ios.d.ts +2 -0
- package/Canvas/index.ios.js +16 -3
- package/Canvas/index.ios.js.map +1 -1
- package/Canvas/utils.js +2 -1
- package/Canvas/utils.js.map +1 -1
- package/Canvas2D/CanvasRenderingContext2D/index.d.ts +1 -0
- package/Canvas2D/CanvasRenderingContext2D/index.js +158 -6
- package/Canvas2D/CanvasRenderingContext2D/index.js.map +1 -1
- package/Canvas2D/DOMMatrix/index.js +280 -2
- package/Canvas2D/DOMMatrix/index.js.map +1 -1
- package/Canvas2D/Path2D/index.js.map +1 -1
- package/Fonts/FontFace.android.js +7 -3
- package/Fonts/FontFace.android.js.map +1 -1
- package/Fonts/FontFace.ios.d.ts +1 -0
- package/Fonts/FontFace.ios.js +10 -3
- package/Fonts/FontFace.ios.js.map +1 -1
- package/TextDecoder/index.d.ts +1 -0
- package/TextDecoder/index.js +17 -0
- package/TextDecoder/index.js.map +1 -1
- package/WebGL/WebGLRenderingContext/index.js +0 -1
- package/WebGL/WebGLRenderingContext/index.js.map +1 -1
- package/WebGPU/GPUCanvasContext.d.ts +0 -1
- package/WebGPU/GPUCanvasContext.js +6 -18
- package/WebGPU/GPUCanvasContext.js.map +1 -1
- package/WebGPU/GPUCommandEncoder.d.ts +1 -1
- package/WebGPU/GPUCommandEncoder.js +1 -1
- package/WebGPU/GPUCommandEncoder.js.map +1 -1
- package/WebGPU/GPUCompilationInfo.d.ts +10 -0
- package/WebGPU/GPUCompilationInfo.js +20 -0
- package/WebGPU/GPUCompilationInfo.js.map +1 -0
- package/WebGPU/GPUCompilationMessage.d.ts +11 -0
- package/WebGPU/GPUCompilationMessage.js +30 -0
- package/WebGPU/GPUCompilationMessage.js.map +1 -0
- package/WebGPU/GPUDevice.d.ts +2 -2
- package/WebGPU/GPUDevice.js.map +1 -1
- package/WebGPU/GPUQueue.js +1 -4
- package/WebGPU/GPUQueue.js.map +1 -1
- package/WebGPU/GPURenderPassEncoder.d.ts +1 -1
- package/WebGPU/GPURenderPassEncoder.js +2 -2
- package/WebGPU/GPURenderPassEncoder.js.map +1 -1
- package/WebGPU/GPUShaderModule.d.ts +2 -0
- package/WebGPU/GPUShaderModule.js +10 -0
- package/WebGPU/GPUShaderModule.js.map +1 -1
- package/WebGPU/Interfaces.d.ts +1 -0
- package/WebGPU/Types.d.ts +3 -3
- package/WebGPU/Utils.d.ts +1 -1
- package/WebGPU/Utils.js +67 -93
- package/WebGPU/Utils.js.map +1 -1
- package/WebGPU/index.d.ts +2 -0
- package/WebGPU/index.js +2 -0
- package/WebGPU/index.js.map +1 -1
- package/angular/fesm2022/nativescript-canvas-angular.mjs +5 -5
- package/angular/package.json +0 -2
- package/helpers.d.ts +3 -0
- package/helpers.js +9 -0
- package/helpers.js.map +1 -1
- package/index.js +6 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/platforms/android/canvas-release.aar +0 -0
- 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 +10 -5
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +294 -47
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Info.plist +0 -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 +11317 -11881
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.private.swiftinterface +55 -49
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +55 -49
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +954 -994
- 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 +20 -10
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +294 -47
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Info.plist +0 -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 +11317 -11881
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +55 -49
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +55 -49
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +11317 -11881
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +55 -49
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +55 -49
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +29 -29
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +955 -993
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/x86_64/CanvasNative.yml +824 -1037
- package/platforms/ios/src/cpp/Caches.h +6 -0
- package/platforms/ios/src/cpp/CanvasJSIModule.cpp +1172 -1011
- package/platforms/ios/src/cpp/CanvasJSIModule.h +6 -0
- package/platforms/ios/src/cpp/Helpers.h +23 -2
- package/platforms/ios/src/cpp/NativeType.h +3 -1
- package/platforms/ios/src/cpp/OnRafCallback.cpp +15 -10
- package/platforms/ios/src/cpp/OnRafCallback.h +1 -0
- package/platforms/ios/src/cpp/PromiseCallback.h +42 -20
- package/platforms/ios/src/cpp/TextDecoderImpl.cpp +142 -0
- package/platforms/ios/src/cpp/TextDecoderImpl.h +2 -0
- package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.cpp +59 -15
- package/platforms/ios/src/cpp/canvas2d/Path2D.cpp +1 -1
- package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.cpp +4 -8
- package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.cpp +431 -326
- package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.h +98 -42
- package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.cpp +1150 -1144
- package/platforms/ios/src/cpp/webgpu/GPUCompilationInfoImpl.cpp +88 -0
- package/platforms/ios/src/cpp/webgpu/GPUCompilationInfoImpl.h +49 -0
- package/platforms/ios/src/cpp/webgpu/GPUCompilationMessageImpl.cpp +193 -0
- package/platforms/ios/src/cpp/webgpu/GPUCompilationMessageImpl.h +64 -0
- package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.cpp +69 -34
- package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.cpp +45 -18
- package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.cpp +22 -19
- package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.cpp +23 -0
- package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.h +2 -0
- package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.cpp +11 -0
- package/platforms/ios/src/cpp/webgpu/GPUUtils.h +25 -15
- package/angular/esm2022/index.mjs +0 -17
- package/angular/esm2022/nativescript-canvas-angular.mjs +0 -5
package/Canvas/common.js
CHANGED
|
@@ -34,12 +34,23 @@ export class Event {
|
|
|
34
34
|
this.type = type;
|
|
35
35
|
this.bubbles = options?.bubbles ?? false;
|
|
36
36
|
this.cancelable = options?.cancelable ?? false;
|
|
37
|
-
this.cancelable = options?.cancelable ?? false;
|
|
38
37
|
this.composed = options?.composed ?? false;
|
|
39
38
|
this.target = options?.target ?? null;
|
|
39
|
+
this._preventDefault = options?.preventDefault;
|
|
40
|
+
this._stopPropagation = options?.stopPropagation;
|
|
41
|
+
}
|
|
42
|
+
preventDefault() {
|
|
43
|
+
this._preventDefault?.();
|
|
44
|
+
}
|
|
45
|
+
stopPropagation() {
|
|
46
|
+
this._stopPropagation?.();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export class CustomEvent extends Event {
|
|
50
|
+
constructor(type, options) {
|
|
51
|
+
super(type, options);
|
|
52
|
+
this.detail = options?.detail ?? null;
|
|
40
53
|
}
|
|
41
|
-
preventDefault() { }
|
|
42
|
-
stopPropagation() { }
|
|
43
54
|
}
|
|
44
55
|
export class UIEvent extends Event {
|
|
45
56
|
constructor(type, options) {
|
|
@@ -85,8 +96,6 @@ export class PointerEvent extends MouseEvent {
|
|
|
85
96
|
this.twist = options?.twist ?? 0;
|
|
86
97
|
this.isPrimary = options?.isPrimary ?? false;
|
|
87
98
|
}
|
|
88
|
-
preventDefault() { }
|
|
89
|
-
stopPropagation() { }
|
|
90
99
|
}
|
|
91
100
|
export class Touch {
|
|
92
101
|
constructor(options) {
|
|
@@ -133,8 +142,6 @@ export class TouchEvent extends UIEvent {
|
|
|
133
142
|
this.ctrlKey = options?.ctrlKey ?? false;
|
|
134
143
|
this.shiftKey = options?.shiftKey ?? false;
|
|
135
144
|
}
|
|
136
|
-
preventDefault() { }
|
|
137
|
-
stopPropagation() { }
|
|
138
145
|
}
|
|
139
146
|
export class WheelEvent extends UIEvent {
|
|
140
147
|
constructor(type, options) {
|
|
@@ -188,7 +195,7 @@ let CanvasBase = class CanvasBase extends View {
|
|
|
188
195
|
this._touchCancelCallbacks = new Array();
|
|
189
196
|
this._touches = [];
|
|
190
197
|
this._touchesById = [];
|
|
191
|
-
this._lastPointerEventById =
|
|
198
|
+
this._lastPointerEventById = new Map();
|
|
192
199
|
this.__target = null;
|
|
193
200
|
this._classList = new Set();
|
|
194
201
|
this.style.width = { unit: '%', value: 1 };
|
|
@@ -327,19 +334,13 @@ let CanvasBase = class CanvasBase extends View {
|
|
|
327
334
|
_moveCallback(pointers) {
|
|
328
335
|
const hasPointerCallbacks = this._pointerMoveCallbacks.length > 0;
|
|
329
336
|
const hasMouseCallbacks = this._mouseMoveCallbacks.length > 0;
|
|
330
|
-
|
|
337
|
+
const hasTouchCallbacks = this._touchMoveCallbacks.length > 0;
|
|
338
|
+
if (hasPointerCallbacks || hasMouseCallbacks || hasTouchCallbacks) {
|
|
339
|
+
let preventDefault = false;
|
|
340
|
+
const changedTouches = hasTouchCallbacks ? TouchList.empty() : null;
|
|
331
341
|
for (const pointer of pointers) {
|
|
332
342
|
const pointerId = pointer.ptrId;
|
|
333
|
-
const
|
|
334
|
-
return item?.pointerId === pointerId;
|
|
335
|
-
});
|
|
336
|
-
let previousEvent;
|
|
337
|
-
if (index > -1) {
|
|
338
|
-
previousEvent = this._lastPointerEventById[index];
|
|
339
|
-
}
|
|
340
|
-
else {
|
|
341
|
-
previousEvent = { pointerId, x: 0, y: 0 };
|
|
342
|
-
}
|
|
343
|
+
const previousEvent = this._lastPointerEventById.get(pointerId) ?? { pointerId, x: 0, y: 0 };
|
|
343
344
|
if (hasPointerCallbacks) {
|
|
344
345
|
const event = new PointerEvent('pointermove', {
|
|
345
346
|
pointerType: 'touch',
|
|
@@ -355,12 +356,49 @@ let CanvasBase = class CanvasBase extends View {
|
|
|
355
356
|
isPrimary: pointer.isPrimary,
|
|
356
357
|
button: -1,
|
|
357
358
|
target: this.__target ?? this,
|
|
359
|
+
cancelable: true,
|
|
360
|
+
preventDefault: () => {
|
|
361
|
+
preventDefault = true;
|
|
362
|
+
},
|
|
358
363
|
});
|
|
359
364
|
for (const callback of this._pointerMoveCallbacks) {
|
|
360
365
|
callback(event);
|
|
361
366
|
}
|
|
362
367
|
}
|
|
363
|
-
if (
|
|
368
|
+
if (!preventDefault && hasTouchCallbacks) {
|
|
369
|
+
changedTouches.push(new Touch({
|
|
370
|
+
identifier: pointer.ptrId,
|
|
371
|
+
target: this.__target ?? this,
|
|
372
|
+
clientX: pointer.x,
|
|
373
|
+
clientY: pointer.y,
|
|
374
|
+
screenX: pointer.x,
|
|
375
|
+
screenY: pointer.y,
|
|
376
|
+
pageX: pointer.x,
|
|
377
|
+
pageY: pointer.y,
|
|
378
|
+
}));
|
|
379
|
+
}
|
|
380
|
+
this._lastPointerEventById.set(pointerId, { pointerId, x: pointer.x, y: pointer.y });
|
|
381
|
+
}
|
|
382
|
+
if ((changedTouches?.length ?? 0) > 0) {
|
|
383
|
+
const touches = TouchList.fromList(this._touches);
|
|
384
|
+
const event = new TouchEvent('touchmove', {
|
|
385
|
+
touches,
|
|
386
|
+
targetTouches: touches,
|
|
387
|
+
changedTouches,
|
|
388
|
+
target: this.__target ?? this,
|
|
389
|
+
cancelable: true,
|
|
390
|
+
preventDefault: () => {
|
|
391
|
+
preventDefault = true;
|
|
392
|
+
},
|
|
393
|
+
});
|
|
394
|
+
for (const callback of this._touchMoveCallbacks) {
|
|
395
|
+
callback(event);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (!preventDefault && hasMouseCallbacks) {
|
|
399
|
+
for (const pointer of pointers) {
|
|
400
|
+
const pointerId = pointer.ptrId;
|
|
401
|
+
const previousEvent = this._lastPointerEventById.get(pointerId) ?? { pointerId, x: 0, y: 0 };
|
|
364
402
|
const event = new MouseEvent('mousemove', {
|
|
365
403
|
clientX: pointer.x,
|
|
366
404
|
clientY: pointer.y,
|
|
@@ -372,48 +410,24 @@ let CanvasBase = class CanvasBase extends View {
|
|
|
372
410
|
movementY: pointer.y - previousEvent.y,
|
|
373
411
|
button: -1,
|
|
374
412
|
target: this.__target ?? this,
|
|
413
|
+
preventDefault: () => {
|
|
414
|
+
preventDefault = true;
|
|
415
|
+
},
|
|
375
416
|
});
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
// }
|
|
380
|
-
}
|
|
381
|
-
if (index > -1) {
|
|
382
|
-
this._lastPointerEventById[index] = { pointerId, x: pointer.x, y: pointer.y };
|
|
417
|
+
for (const callback of this._mouseMoveCallbacks) {
|
|
418
|
+
callback(event);
|
|
419
|
+
}
|
|
383
420
|
}
|
|
384
421
|
}
|
|
385
422
|
}
|
|
386
|
-
if (this._touchMoveCallbacks.length > 0) {
|
|
387
|
-
const changedTouches = TouchList.empty();
|
|
388
|
-
for (const pointer of pointers) {
|
|
389
|
-
changedTouches.push(new Touch({
|
|
390
|
-
identifier: pointer.ptrId,
|
|
391
|
-
target: this.__target ?? this,
|
|
392
|
-
clientX: pointer.x,
|
|
393
|
-
clientY: pointer.y,
|
|
394
|
-
screenX: pointer.x,
|
|
395
|
-
screenY: pointer.y,
|
|
396
|
-
pageX: pointer.x,
|
|
397
|
-
pageY: pointer.y,
|
|
398
|
-
}));
|
|
399
|
-
}
|
|
400
|
-
const touches = TouchList.fromList(this._touches);
|
|
401
|
-
const event = new TouchEvent('touchmove', {
|
|
402
|
-
touches,
|
|
403
|
-
targetTouches: touches,
|
|
404
|
-
changedTouches,
|
|
405
|
-
target: this.__target ?? this,
|
|
406
|
-
});
|
|
407
|
-
for (const callback of this._touchMoveCallbacks) {
|
|
408
|
-
callback(event);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
423
|
}
|
|
412
424
|
_upCallback(ptrId, x, y, isPrimary = false) {
|
|
413
425
|
const hasPointerCallbacks = this._pointerUpCallbacks.length > 0 || this._pointerOutCallbacks.length > 0 || this._pointerLeaveCallbacks.length > 0;
|
|
414
426
|
const hasMouseCallbacks = this._mouseUpCallbacks.length > 0;
|
|
415
|
-
|
|
416
|
-
|
|
427
|
+
const hasTouchCallbacks = this._touchEndCallbacks.length > 0;
|
|
428
|
+
const pointerId = ptrId;
|
|
429
|
+
if (hasPointerCallbacks || hasMouseCallbacks || hasTouchCallbacks) {
|
|
430
|
+
let preventDefault = false;
|
|
417
431
|
if (hasPointerCallbacks) {
|
|
418
432
|
const up = new PointerEvent('pointerup', {
|
|
419
433
|
pointerType: 'touch',
|
|
@@ -426,6 +440,10 @@ let CanvasBase = class CanvasBase extends View {
|
|
|
426
440
|
pageX: x,
|
|
427
441
|
pageY: y,
|
|
428
442
|
target: this.__target ?? this,
|
|
443
|
+
cancelable: true,
|
|
444
|
+
preventDefault: () => {
|
|
445
|
+
preventDefault = true;
|
|
446
|
+
},
|
|
429
447
|
});
|
|
430
448
|
const out = new PointerEvent('pointerout', {
|
|
431
449
|
pointerType: 'touch',
|
|
@@ -461,7 +479,35 @@ let CanvasBase = class CanvasBase extends View {
|
|
|
461
479
|
callback(leave);
|
|
462
480
|
}
|
|
463
481
|
}
|
|
464
|
-
if (
|
|
482
|
+
if (hasTouchCallbacks && !preventDefault) {
|
|
483
|
+
const touches = TouchList.fromList(this._touches.filter((t) => t.identifier !== ptrId));
|
|
484
|
+
const changedTouches = TouchList.fromList([
|
|
485
|
+
new Touch({
|
|
486
|
+
identifier: ptrId,
|
|
487
|
+
target: this.__target ?? this,
|
|
488
|
+
clientX: x,
|
|
489
|
+
clientY: y,
|
|
490
|
+
screenX: x,
|
|
491
|
+
screenY: y,
|
|
492
|
+
pageX: x,
|
|
493
|
+
pageY: y,
|
|
494
|
+
}),
|
|
495
|
+
]);
|
|
496
|
+
const event = new TouchEvent('touchend', {
|
|
497
|
+
touches,
|
|
498
|
+
targetTouches: touches,
|
|
499
|
+
changedTouches,
|
|
500
|
+
target: this.__target ?? this,
|
|
501
|
+
cancelable: true,
|
|
502
|
+
preventDefault: () => {
|
|
503
|
+
preventDefault = true;
|
|
504
|
+
},
|
|
505
|
+
});
|
|
506
|
+
for (const callback of this._touchEndCallbacks) {
|
|
507
|
+
callback(event);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (hasMouseCallbacks && !preventDefault) {
|
|
465
511
|
const event = new MouseEvent('mouseup', {
|
|
466
512
|
clientX: x,
|
|
467
513
|
clientY: y,
|
|
@@ -470,17 +516,13 @@ let CanvasBase = class CanvasBase extends View {
|
|
|
470
516
|
pageX: x,
|
|
471
517
|
pageY: y,
|
|
472
518
|
target: this.__target ?? this,
|
|
519
|
+
preventDefault: () => {
|
|
520
|
+
preventDefault = true;
|
|
521
|
+
},
|
|
473
522
|
});
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
// }
|
|
478
|
-
}
|
|
479
|
-
const index = this._lastPointerEventById.findIndex((item) => {
|
|
480
|
-
return item?.pointerId === pointerId;
|
|
481
|
-
});
|
|
482
|
-
if (index > -1) {
|
|
483
|
-
this._lastPointerEventById.splice(index, 1);
|
|
523
|
+
for (const callback of this._mouseUpCallbacks) {
|
|
524
|
+
callback(event);
|
|
525
|
+
}
|
|
484
526
|
}
|
|
485
527
|
}
|
|
486
528
|
const length = this._touches.length;
|
|
@@ -490,35 +532,14 @@ let CanvasBase = class CanvasBase extends View {
|
|
|
490
532
|
break;
|
|
491
533
|
}
|
|
492
534
|
}
|
|
493
|
-
|
|
494
|
-
const touches = TouchList.fromList(this._touches);
|
|
495
|
-
const changedTouches = TouchList.fromList([
|
|
496
|
-
new Touch({
|
|
497
|
-
identifier: ptrId,
|
|
498
|
-
target: this.__target ?? this,
|
|
499
|
-
clientX: x,
|
|
500
|
-
clientY: y,
|
|
501
|
-
screenX: x,
|
|
502
|
-
screenY: y,
|
|
503
|
-
pageX: x,
|
|
504
|
-
pageY: y,
|
|
505
|
-
}),
|
|
506
|
-
]);
|
|
507
|
-
const event = new TouchEvent('touchend', {
|
|
508
|
-
touches,
|
|
509
|
-
targetTouches: touches,
|
|
510
|
-
changedTouches,
|
|
511
|
-
target: this.__target ?? this,
|
|
512
|
-
});
|
|
513
|
-
for (const callback of this._touchEndCallbacks) {
|
|
514
|
-
callback(event);
|
|
515
|
-
}
|
|
516
|
-
}
|
|
535
|
+
this._lastPointerEventById.delete(pointerId);
|
|
517
536
|
}
|
|
518
537
|
_downCallback(ptrId, x, y, isPrimary = false) {
|
|
519
538
|
const hasPointerCallbacks = this._pointerDownCallbacks.length > 0;
|
|
520
539
|
const hasMouseCallbacks = this._mouseDownCallbacks.length > 0;
|
|
521
|
-
|
|
540
|
+
const hasTouchCallbacks = this._touchStartCallbacks.length > 0;
|
|
541
|
+
if (hasPointerCallbacks || hasMouseCallbacks || hasTouchCallbacks) {
|
|
542
|
+
let preventDefault = false;
|
|
522
543
|
const pointerId = ptrId;
|
|
523
544
|
if (hasPointerCallbacks) {
|
|
524
545
|
const event = new PointerEvent('pointerdown', {
|
|
@@ -532,57 +553,69 @@ let CanvasBase = class CanvasBase extends View {
|
|
|
532
553
|
pageX: x,
|
|
533
554
|
pageY: y,
|
|
534
555
|
target: this.__target ?? this,
|
|
556
|
+
cancelable: true,
|
|
557
|
+
preventDefault: () => {
|
|
558
|
+
preventDefault = true;
|
|
559
|
+
},
|
|
535
560
|
});
|
|
536
561
|
for (const callback of this._pointerDownCallbacks) {
|
|
537
562
|
callback(event);
|
|
538
563
|
}
|
|
539
564
|
}
|
|
540
|
-
if (
|
|
541
|
-
const
|
|
565
|
+
if (hasTouchCallbacks && !preventDefault) {
|
|
566
|
+
const touch = new Touch({
|
|
567
|
+
identifier: ptrId,
|
|
568
|
+
target: this.__target ?? this,
|
|
542
569
|
clientX: x,
|
|
543
570
|
clientY: y,
|
|
544
571
|
screenX: x,
|
|
545
572
|
screenY: y,
|
|
546
573
|
pageX: x,
|
|
547
574
|
pageY: y,
|
|
575
|
+
});
|
|
576
|
+
this._touches.push(touch);
|
|
577
|
+
this._touchesById[ptrId] = touch;
|
|
578
|
+
const touches = TouchList.fromList(this._touches);
|
|
579
|
+
const touchEvent = new TouchEvent('touchstart', {
|
|
580
|
+
touches,
|
|
581
|
+
targetTouches: touches,
|
|
582
|
+
changedTouches: this._touches,
|
|
548
583
|
target: this.__target ?? this,
|
|
584
|
+
cancelable: true,
|
|
585
|
+
preventDefault: () => {
|
|
586
|
+
preventDefault = true;
|
|
587
|
+
},
|
|
549
588
|
});
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
// }
|
|
589
|
+
for (const callback of this._touchStartCallbacks) {
|
|
590
|
+
callback(touchEvent);
|
|
591
|
+
}
|
|
554
592
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
const touchEvent = new TouchEvent('touchstart', {
|
|
572
|
-
touches,
|
|
573
|
-
targetTouches: touches,
|
|
574
|
-
changedTouches: this._touches,
|
|
575
|
-
target: this.__target ?? this,
|
|
576
|
-
});
|
|
577
|
-
for (const callback of this._touchStartCallbacks) {
|
|
578
|
-
callback(touchEvent);
|
|
593
|
+
if (hasMouseCallbacks && !preventDefault) {
|
|
594
|
+
const event = new MouseEvent('mousedown', {
|
|
595
|
+
clientX: x,
|
|
596
|
+
clientY: y,
|
|
597
|
+
screenX: x,
|
|
598
|
+
screenY: y,
|
|
599
|
+
pageX: x,
|
|
600
|
+
pageY: y,
|
|
601
|
+
target: this.__target ?? this,
|
|
602
|
+
preventDefault: () => {
|
|
603
|
+
preventDefault = true;
|
|
604
|
+
},
|
|
605
|
+
});
|
|
606
|
+
for (const callback of this._mouseDownCallbacks) {
|
|
607
|
+
callback(event);
|
|
608
|
+
}
|
|
579
609
|
}
|
|
610
|
+
this._lastPointerEventById.set(pointerId, { pointerId, x, y });
|
|
580
611
|
}
|
|
581
612
|
}
|
|
582
613
|
_cancelCallback(ptrId, x, y, isPrimary = false) {
|
|
583
614
|
const hasPointerCallbacks = this._pointerCancelCallbacks.length > 0;
|
|
584
615
|
const hasMouseCallbacks = this._mouseCancelCallbacks.length > 0;
|
|
585
|
-
|
|
616
|
+
const hasTouchCallbacks = this._touchCancelCallbacks.length > 0;
|
|
617
|
+
if (hasPointerCallbacks || hasMouseCallbacks || hasTouchCallbacks) {
|
|
618
|
+
let preventDefault = false;
|
|
586
619
|
const pointerId = ptrId;
|
|
587
620
|
if (hasPointerCallbacks) {
|
|
588
621
|
const event = new PointerEvent('pointercancel', {
|
|
@@ -596,51 +629,62 @@ let CanvasBase = class CanvasBase extends View {
|
|
|
596
629
|
pageY: y,
|
|
597
630
|
isPrimary,
|
|
598
631
|
target: this.__target ?? this,
|
|
632
|
+
cancelable: true,
|
|
633
|
+
preventDefault: () => {
|
|
634
|
+
preventDefault = true;
|
|
635
|
+
},
|
|
599
636
|
});
|
|
600
637
|
for (const callback of this._pointerCancelCallbacks) {
|
|
601
638
|
callback(event);
|
|
602
639
|
}
|
|
603
640
|
}
|
|
604
|
-
if (
|
|
605
|
-
const
|
|
641
|
+
if (hasTouchCallbacks && !preventDefault) {
|
|
642
|
+
const touch = new Touch({
|
|
643
|
+
identifier: ptrId,
|
|
644
|
+
target: this.__target ?? this,
|
|
606
645
|
clientX: x,
|
|
607
646
|
clientY: y,
|
|
608
647
|
screenX: x,
|
|
609
648
|
screenY: y,
|
|
610
649
|
pageX: x,
|
|
611
650
|
pageY: y,
|
|
651
|
+
});
|
|
652
|
+
const touchesList = [touch];
|
|
653
|
+
const touchesById = [];
|
|
654
|
+
touchesById[ptrId] = touch;
|
|
655
|
+
const touches = TouchList.fromList(touchesList);
|
|
656
|
+
const touchEvent = new TouchEvent('touchcancel', {
|
|
657
|
+
touches,
|
|
658
|
+
targetTouches: touches,
|
|
659
|
+
changedTouches: touchesList,
|
|
612
660
|
target: this.__target ?? this,
|
|
661
|
+
cancelable: true,
|
|
662
|
+
preventDefault: () => {
|
|
663
|
+
preventDefault = true;
|
|
664
|
+
},
|
|
613
665
|
});
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
// }
|
|
666
|
+
for (const callback of this._touchCancelCallbacks) {
|
|
667
|
+
callback(touchEvent);
|
|
668
|
+
}
|
|
618
669
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
const touchEvent = new TouchEvent('touchcancel', {
|
|
636
|
-
touches,
|
|
637
|
-
targetTouches: touches,
|
|
638
|
-
changedTouches: touchesList,
|
|
639
|
-
target: this.__target ?? this,
|
|
640
|
-
});
|
|
641
|
-
for (const callback of this._touchCancelCallbacks) {
|
|
642
|
-
callback(touchEvent);
|
|
670
|
+
if (hasMouseCallbacks && !preventDefault) {
|
|
671
|
+
const event = new MouseEvent('mouseout', {
|
|
672
|
+
clientX: x,
|
|
673
|
+
clientY: y,
|
|
674
|
+
screenX: x,
|
|
675
|
+
screenY: y,
|
|
676
|
+
pageX: x,
|
|
677
|
+
pageY: y,
|
|
678
|
+
target: this.__target ?? this,
|
|
679
|
+
preventDefault: () => {
|
|
680
|
+
preventDefault = true;
|
|
681
|
+
},
|
|
682
|
+
});
|
|
683
|
+
for (const callback of this._mouseCancelCallbacks) {
|
|
684
|
+
callback(event);
|
|
685
|
+
}
|
|
643
686
|
}
|
|
687
|
+
this._lastPointerEventById.set(pointerId, { pointerId, x, y });
|
|
644
688
|
}
|
|
645
689
|
}
|
|
646
690
|
_pinchCallback(data) {
|
|
@@ -648,19 +692,13 @@ let CanvasBase = class CanvasBase extends View {
|
|
|
648
692
|
const hasPointerCallbacks = this._pointerMoveCallbacks.length > 0;
|
|
649
693
|
const hasMouseCallbacks = this._mouseMoveCallbacks.length > 0;
|
|
650
694
|
const hasMouseWheel = this._mouseWheelCallbacks.length > 0;
|
|
651
|
-
|
|
695
|
+
const hasTouchCallbacks = this._touchMoveCallbacks.length > 0;
|
|
696
|
+
if (hasPointerCallbacks || hasMouseCallbacks || hasMouseWheel || hasTouchCallbacks) {
|
|
697
|
+
const changedTouches = hasTouchCallbacks ? TouchList.empty() : null;
|
|
698
|
+
let preventDefault = false;
|
|
652
699
|
for (const pointer of data.pointers) {
|
|
653
700
|
const pointerId = pointer.ptrId;
|
|
654
|
-
const
|
|
655
|
-
return item?.pointerId === pointerId;
|
|
656
|
-
});
|
|
657
|
-
let previousEvent;
|
|
658
|
-
if (index > -1) {
|
|
659
|
-
previousEvent = this._lastPointerEventById[index];
|
|
660
|
-
}
|
|
661
|
-
else {
|
|
662
|
-
previousEvent = { pointerId, x: 0, y: 0 };
|
|
663
|
-
}
|
|
701
|
+
const previousEvent = this._lastPointerEventById.get(pointerId) ?? { pointerId, x: 0, y: 0 };
|
|
664
702
|
if (hasPointerCallbacks) {
|
|
665
703
|
const event = new PointerEvent('pointermove', {
|
|
666
704
|
pointerType: 'touch',
|
|
@@ -675,12 +713,49 @@ let CanvasBase = class CanvasBase extends View {
|
|
|
675
713
|
movementY: pointer.y - previousEvent.y,
|
|
676
714
|
button: -1,
|
|
677
715
|
target: this.__target ?? this,
|
|
716
|
+
cancelable: true,
|
|
717
|
+
preventDefault: () => {
|
|
718
|
+
preventDefault = true;
|
|
719
|
+
},
|
|
678
720
|
});
|
|
679
721
|
for (const callback of this._pointerMoveCallbacks) {
|
|
680
722
|
callback(event);
|
|
681
723
|
}
|
|
682
724
|
}
|
|
683
|
-
if (
|
|
725
|
+
if (hasTouchCallbacks && !preventDefault) {
|
|
726
|
+
changedTouches.push(new Touch({
|
|
727
|
+
identifier: pointer.ptrId,
|
|
728
|
+
target: this.__target ?? this,
|
|
729
|
+
clientX: pointer.x,
|
|
730
|
+
clientY: pointer.y,
|
|
731
|
+
screenX: pointer.x,
|
|
732
|
+
screenY: pointer.y,
|
|
733
|
+
pageX: pointer.x,
|
|
734
|
+
pageY: pointer.y,
|
|
735
|
+
}));
|
|
736
|
+
}
|
|
737
|
+
this._lastPointerEventById.set(pointerId, { pointerId, x: pointer.x, y: pointer.y });
|
|
738
|
+
}
|
|
739
|
+
if ((changedTouches?.length ?? 0) > 0) {
|
|
740
|
+
const touches = TouchList.fromList(this._touches);
|
|
741
|
+
const event = new TouchEvent('touchmove', {
|
|
742
|
+
touches,
|
|
743
|
+
targetTouches: touches,
|
|
744
|
+
changedTouches,
|
|
745
|
+
target: this.__target ?? this,
|
|
746
|
+
cancelable: true,
|
|
747
|
+
preventDefault: () => {
|
|
748
|
+
preventDefault = true;
|
|
749
|
+
},
|
|
750
|
+
});
|
|
751
|
+
for (const callback of this._touchMoveCallbacks) {
|
|
752
|
+
callback(event);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
if (!preventDefault && hasMouseCallbacks) {
|
|
756
|
+
for (const pointer of data.pointers) {
|
|
757
|
+
const pointerId = pointer.ptrId;
|
|
758
|
+
const previousEvent = this._lastPointerEventById.get(pointerId) ?? { pointerId, x: 0, y: 0 };
|
|
684
759
|
const event = new MouseEvent('mousemove', {
|
|
685
760
|
clientX: pointer.x,
|
|
686
761
|
clientY: pointer.y,
|
|
@@ -692,53 +767,26 @@ let CanvasBase = class CanvasBase extends View {
|
|
|
692
767
|
movementY: pointer.y - previousEvent.y,
|
|
693
768
|
button: -1,
|
|
694
769
|
target: this.__target ?? this,
|
|
770
|
+
preventDefault: () => {
|
|
771
|
+
preventDefault = true;
|
|
772
|
+
},
|
|
695
773
|
});
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
// }
|
|
700
|
-
}
|
|
701
|
-
if (hasMouseWheel) {
|
|
702
|
-
const event = new WheelEvent('wheel', {
|
|
703
|
-
deltaX: data.deltaX,
|
|
704
|
-
deltaY: data.deltaY,
|
|
705
|
-
deltaZ: 0,
|
|
706
|
-
deltaMode: data.deltaMode,
|
|
707
|
-
target: this.__target ?? this,
|
|
708
|
-
});
|
|
709
|
-
// todo emit wheel when desktop is supported
|
|
710
|
-
// for (const callback of this._mouseWheelCallbacks) {
|
|
711
|
-
// callback(event);
|
|
712
|
-
// }
|
|
713
|
-
}
|
|
714
|
-
if (index > -1) {
|
|
715
|
-
this._lastPointerEventById[index] = { pointerId, x: pointer.x, y: pointer.y };
|
|
774
|
+
for (const callback of this._mouseMoveCallbacks) {
|
|
775
|
+
callback(event);
|
|
776
|
+
}
|
|
716
777
|
}
|
|
717
778
|
}
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
779
|
+
if (hasMouseWheel) {
|
|
780
|
+
const event = new WheelEvent('wheel', {
|
|
781
|
+
deltaX: data.deltaX,
|
|
782
|
+
deltaY: data.deltaY,
|
|
783
|
+
deltaZ: 0,
|
|
784
|
+
deltaMode: data.deltaMode,
|
|
724
785
|
target: this.__target ?? this,
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
pageX: pointer.x,
|
|
730
|
-
pageY: pointer.y,
|
|
731
|
-
}));
|
|
732
|
-
}
|
|
733
|
-
const touches = TouchList.fromList(this._touches);
|
|
734
|
-
const event = new TouchEvent('touchmove', {
|
|
735
|
-
touches,
|
|
736
|
-
targetTouches: touches,
|
|
737
|
-
changedTouches,
|
|
738
|
-
target: this.__target ?? this,
|
|
739
|
-
});
|
|
740
|
-
for (const callback of this._touchMoveCallbacks) {
|
|
741
|
-
callback(event);
|
|
786
|
+
});
|
|
787
|
+
for (const callback of this._mouseWheelCallbacks) {
|
|
788
|
+
callback(event);
|
|
789
|
+
}
|
|
742
790
|
}
|
|
743
791
|
}
|
|
744
792
|
}
|
|
@@ -784,6 +832,9 @@ let CanvasBase = class CanvasBase extends View {
|
|
|
784
832
|
}
|
|
785
833
|
setPointerCapture(id) { }
|
|
786
834
|
releasePointerCapture(id) { }
|
|
835
|
+
getRootNode() {
|
|
836
|
+
return this;
|
|
837
|
+
}
|
|
787
838
|
};
|
|
788
839
|
CanvasBase.readyEvent = 'ready';
|
|
789
840
|
CanvasBase = __decorate([
|