@meta2d/core 1.1.7 → 1.1.9
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/package.json +1 -1
- package/src/canvas/canvas.d.ts +8 -0
- package/src/canvas/canvas.js +45 -8
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.js +3 -3
- package/src/core.js.map +1 -1
package/package.json
CHANGED
package/src/canvas/canvas.d.ts
CHANGED
|
@@ -50,6 +50,9 @@ export declare class Canvas {
|
|
|
50
50
|
touchMoving?: boolean;
|
|
51
51
|
startTouches?: TouchList;
|
|
52
52
|
lastTouchY?: number;
|
|
53
|
+
startDistance?: number;
|
|
54
|
+
startCenter?: Point;
|
|
55
|
+
currentCenter?: Point;
|
|
53
56
|
lastOffsetX: number;
|
|
54
57
|
lastOffsetY: number;
|
|
55
58
|
drawingLineName?: string;
|
|
@@ -153,6 +156,11 @@ export declare class Canvas {
|
|
|
153
156
|
ontouchstart: (e: TouchEvent) => void;
|
|
154
157
|
ontouchmove: (event: TouchEvent) => void;
|
|
155
158
|
ontouchend: (event: TouchEvent) => void;
|
|
159
|
+
getDistance(touch1: any, touch2: any): number;
|
|
160
|
+
getCenter(touch1: any, touch2: any): {
|
|
161
|
+
x: number;
|
|
162
|
+
y: number;
|
|
163
|
+
};
|
|
156
164
|
onGesturestart: (e: any) => void;
|
|
157
165
|
/**
|
|
158
166
|
* 获取初始化的 pencilLine
|
package/src/canvas/canvas.js
CHANGED
|
@@ -52,6 +52,9 @@ export class Canvas {
|
|
|
52
52
|
touchMoving;
|
|
53
53
|
startTouches;
|
|
54
54
|
lastTouchY;
|
|
55
|
+
startDistance;
|
|
56
|
+
startCenter;
|
|
57
|
+
currentCenter;
|
|
55
58
|
lastOffsetX = 0;
|
|
56
59
|
lastOffsetY = 0;
|
|
57
60
|
drawingLineName;
|
|
@@ -1371,7 +1374,9 @@ export class Canvas {
|
|
|
1371
1374
|
const tapTime = currentTime - this.lastTapTime;
|
|
1372
1375
|
if (tapTime < 300 && tapTime > 0) {
|
|
1373
1376
|
//双击
|
|
1374
|
-
|
|
1377
|
+
if (e.touches.length !== 2) {
|
|
1378
|
+
this.ondblclick(e);
|
|
1379
|
+
}
|
|
1375
1380
|
}
|
|
1376
1381
|
this.lastTapTime = currentTime;
|
|
1377
1382
|
if (this.touchStartTimer) {
|
|
@@ -1409,6 +1414,11 @@ export class Canvas {
|
|
|
1409
1414
|
(e.touches[1].pageY - e.touches[0].pageY) / 2 -
|
|
1410
1415
|
this.clientRect.y,
|
|
1411
1416
|
};
|
|
1417
|
+
this.startDistance = this.getDistance(e.touches[0], e.touches[1]);
|
|
1418
|
+
this.startCenter = this.getCenter(e.touches[0], e.touches[1]);
|
|
1419
|
+
this.currentCenter = { ...this.startCenter };
|
|
1420
|
+
this.touchScaling = undefined;
|
|
1421
|
+
this.touchMoving = undefined;
|
|
1412
1422
|
return;
|
|
1413
1423
|
}
|
|
1414
1424
|
else if (e.touches.length === 3) {
|
|
@@ -1467,15 +1477,31 @@ export class Canvas {
|
|
|
1467
1477
|
else if (len === 2 && this.startTouches?.length === 2) {
|
|
1468
1478
|
this.mouseDown = undefined;
|
|
1469
1479
|
if (!this.touchMoving && !this.touchScaling) {
|
|
1470
|
-
const x1 = this.startTouches[0].pageX - touches[0].pageX;
|
|
1471
|
-
const x2 = this.startTouches[1].pageX - touches[1].pageX;
|
|
1472
|
-
const y1 = this.startTouches[0].pageY - touches[0].pageY;
|
|
1473
|
-
const y2 = this.startTouches[1].pageY - touches[1].pageY;
|
|
1474
|
-
if (
|
|
1475
|
-
|
|
1480
|
+
// const x1 = this.startTouches[0].pageX - touches[0].pageX;
|
|
1481
|
+
// const x2 = this.startTouches[1].pageX - touches[1].pageX;
|
|
1482
|
+
// const y1 = this.startTouches[0].pageY - touches[0].pageY;
|
|
1483
|
+
// const y2 = this.startTouches[1].pageY - touches[1].pageY;
|
|
1484
|
+
// if (
|
|
1485
|
+
// (((x1 >= 0 && x2 < 0) || (x1 <= 0 && x2 > 0)) &&
|
|
1486
|
+
// ((y1 >= 0 && y2 < 0) || (y1 <= 0 && y2 > 0)))||(x2==0&&y2==0)||(x1==0&&y1==0)
|
|
1487
|
+
// ) {
|
|
1488
|
+
// this.touchScaling = true;
|
|
1489
|
+
// } else if(y1*y2 > 0 && x1*x2 > 0){
|
|
1490
|
+
// this.touchMoving = true;
|
|
1491
|
+
// }
|
|
1492
|
+
// 当前距离和中心点
|
|
1493
|
+
const currentDistance = this.getDistance(touches[0], touches[1]);
|
|
1494
|
+
const newCenter = this.getCenter(touches[0], touches[1]);
|
|
1495
|
+
// 计算变化
|
|
1496
|
+
const distanceDiff = currentDistance - this.startDistance;
|
|
1497
|
+
const centerDiffX = newCenter.x - this.currentCenter.x;
|
|
1498
|
+
const centerDiffY = newCenter.y - this.currentCenter.y;
|
|
1499
|
+
const centerMoveDistance = Math.sqrt(centerDiffX * centerDiffX + centerDiffY * centerDiffY);
|
|
1500
|
+
const scaleRatio = Math.abs(distanceDiff) / this.startDistance;
|
|
1501
|
+
if (scaleRatio > centerMoveDistance / 100) {
|
|
1476
1502
|
this.touchScaling = true;
|
|
1477
1503
|
}
|
|
1478
|
-
else if (
|
|
1504
|
+
else if (centerMoveDistance > 5) {
|
|
1479
1505
|
this.touchMoving = true;
|
|
1480
1506
|
}
|
|
1481
1507
|
}
|
|
@@ -1530,6 +1556,17 @@ export class Canvas {
|
|
|
1530
1556
|
this.render();
|
|
1531
1557
|
}, 60);
|
|
1532
1558
|
};
|
|
1559
|
+
getDistance(touch1, touch2) {
|
|
1560
|
+
const dx = touch2.clientX - touch1.clientX;
|
|
1561
|
+
const dy = touch2.clientY - touch1.clientY;
|
|
1562
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
1563
|
+
}
|
|
1564
|
+
getCenter(touch1, touch2) {
|
|
1565
|
+
return {
|
|
1566
|
+
x: (touch1.clientX + touch2.clientX) / 2,
|
|
1567
|
+
y: (touch1.clientY + touch2.clientY) / 2
|
|
1568
|
+
};
|
|
1569
|
+
}
|
|
1533
1570
|
onGesturestart = (e) => {
|
|
1534
1571
|
e.preventDefault();
|
|
1535
1572
|
};
|