@meta2d/core 1.0.99 → 1.1.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.
- package/package.json +1 -1
- package/src/canvas/canvas.d.ts +3 -0
- package/src/canvas/canvas.js +64 -29
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.js +17 -2
- package/src/core.js.map +1 -1
- package/src/options.d.ts +1 -0
- package/src/options.js.map +1 -1
- package/src/pen/model.d.ts +2 -0
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.js +137 -28
- package/src/pen/render.js.map +1 -1
package/package.json
CHANGED
package/src/canvas/canvas.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ export declare class Canvas {
|
|
|
49
49
|
touchScaling?: boolean;
|
|
50
50
|
touchMoving?: boolean;
|
|
51
51
|
startTouches?: TouchList;
|
|
52
|
+
lastTouchY?: number;
|
|
52
53
|
lastOffsetX: number;
|
|
53
54
|
lastOffsetY: number;
|
|
54
55
|
drawingLineName?: string;
|
|
@@ -73,6 +74,7 @@ export declare class Canvas {
|
|
|
73
74
|
touchStart: number;
|
|
74
75
|
touchStartTimer: any;
|
|
75
76
|
timer: any;
|
|
77
|
+
lastTapTime: number;
|
|
76
78
|
private lastAnimateRender;
|
|
77
79
|
animateRendering: boolean;
|
|
78
80
|
renderTimer: number;
|
|
@@ -90,6 +92,7 @@ export declare class Canvas {
|
|
|
90
92
|
metaKey?: boolean;
|
|
91
93
|
F?: boolean;
|
|
92
94
|
};
|
|
95
|
+
isMobile?: boolean;
|
|
93
96
|
/**
|
|
94
97
|
* @deprecated 改用 beforeAddPens
|
|
95
98
|
*/
|
package/src/canvas/canvas.js
CHANGED
|
@@ -51,6 +51,7 @@ export class Canvas {
|
|
|
51
51
|
touchScaling;
|
|
52
52
|
touchMoving;
|
|
53
53
|
startTouches;
|
|
54
|
+
lastTouchY;
|
|
54
55
|
lastOffsetX = 0;
|
|
55
56
|
lastOffsetY = 0;
|
|
56
57
|
drawingLineName;
|
|
@@ -73,6 +74,7 @@ export class Canvas {
|
|
|
73
74
|
touchStart = 0;
|
|
74
75
|
touchStartTimer;
|
|
75
76
|
timer;
|
|
77
|
+
lastTapTime = 0;
|
|
76
78
|
lastAnimateRender = 0;
|
|
77
79
|
animateRendering = false;
|
|
78
80
|
renderTimer;
|
|
@@ -84,6 +86,7 @@ export class Canvas {
|
|
|
84
86
|
canMoveLine = false; //moveConnectedLine=false
|
|
85
87
|
randomIdObj; //记录拖拽前后id变化
|
|
86
88
|
keyOptions;
|
|
89
|
+
isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
87
90
|
/**
|
|
88
91
|
* @deprecated 改用 beforeAddPens
|
|
89
92
|
*/
|
|
@@ -138,6 +141,7 @@ export class Canvas {
|
|
|
138
141
|
this.externalElements.style.background = 'transparent';
|
|
139
142
|
this.externalElements.style.zIndex = '5';
|
|
140
143
|
parentElement.style.position = 'relative';
|
|
144
|
+
parentElement.style['-webkit-tap-highlight-color'] = 'transparent';
|
|
141
145
|
parentElement.appendChild(this.externalElements);
|
|
142
146
|
this.createInput();
|
|
143
147
|
this.tooltip = new Tooltip(parentElement, store);
|
|
@@ -181,6 +185,9 @@ export class Canvas {
|
|
|
181
185
|
this.externalElements.ontouchmove = this.ontouchmove;
|
|
182
186
|
this.externalElements.ontouchend = this.ontouchend;
|
|
183
187
|
this.externalElements.onmousedown = (e) => {
|
|
188
|
+
if (this.isMobile) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
184
191
|
this.onMouseDown({
|
|
185
192
|
x: e.offsetX,
|
|
186
193
|
y: e.offsetY,
|
|
@@ -195,6 +202,9 @@ export class Canvas {
|
|
|
195
202
|
});
|
|
196
203
|
};
|
|
197
204
|
this.externalElements.onmousemove = (e) => {
|
|
205
|
+
if (this.isMobile) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
198
208
|
if (e.target !== this.externalElements) {
|
|
199
209
|
return;
|
|
200
210
|
}
|
|
@@ -212,6 +222,9 @@ export class Canvas {
|
|
|
212
222
|
});
|
|
213
223
|
};
|
|
214
224
|
this.externalElements.onmouseup = (e) => {
|
|
225
|
+
if (this.isMobile) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
215
228
|
this.onMouseUp({
|
|
216
229
|
x: e.offsetX,
|
|
217
230
|
y: e.offsetY,
|
|
@@ -245,7 +258,12 @@ export class Canvas {
|
|
|
245
258
|
this.store.lastHover = undefined;
|
|
246
259
|
}
|
|
247
260
|
};
|
|
248
|
-
this.externalElements.ondblclick =
|
|
261
|
+
this.externalElements.ondblclick = (e) => {
|
|
262
|
+
if (this.isMobile) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
this.ondblclick(e);
|
|
266
|
+
};
|
|
249
267
|
this.externalElements.tabIndex = 0;
|
|
250
268
|
this.externalElements.onblur = () => {
|
|
251
269
|
this.mouseDown = undefined;
|
|
@@ -1319,9 +1337,17 @@ export class Canvas {
|
|
|
1319
1337
|
return list;
|
|
1320
1338
|
}
|
|
1321
1339
|
ontouchstart = (e) => {
|
|
1340
|
+
this.lastTouchY = e.touches[0].clientY;
|
|
1322
1341
|
if (this.store.data.locked === LockState.Disable) {
|
|
1323
1342
|
return;
|
|
1324
1343
|
}
|
|
1344
|
+
const currentTime = new Date().getTime();
|
|
1345
|
+
const tapTime = currentTime - this.lastTapTime;
|
|
1346
|
+
if (tapTime < 300 && tapTime > 0) {
|
|
1347
|
+
//双击
|
|
1348
|
+
this.ondblclick(e);
|
|
1349
|
+
}
|
|
1350
|
+
this.lastTapTime = currentTime;
|
|
1325
1351
|
if (this.touchStartTimer) {
|
|
1326
1352
|
clearTimeout(this.touchStartTimer);
|
|
1327
1353
|
}
|
|
@@ -1392,6 +1418,12 @@ export class Canvas {
|
|
|
1392
1418
|
const x = event.touches[0].pageX - this.clientRect.x;
|
|
1393
1419
|
const y = event.touches[0].pageY - this.clientRect.y;
|
|
1394
1420
|
if (len === 1) {
|
|
1421
|
+
if (this.store.options.scroll && this.scroll && !this.store.options.scrollButScale) {
|
|
1422
|
+
let diff = this.lastTouchY - event.touches[0].clientY;
|
|
1423
|
+
this.scroll.wheel(diff < 0);
|
|
1424
|
+
this.lastTouchY = event.touches[0].clientY;
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1395
1427
|
this.onMouseMove({
|
|
1396
1428
|
x,
|
|
1397
1429
|
y,
|
|
@@ -1454,21 +1486,21 @@ export class Canvas {
|
|
|
1454
1486
|
this.lastOffsetY = 0;
|
|
1455
1487
|
const x = event.changedTouches[0].pageX - this.clientRect.x;
|
|
1456
1488
|
const y = event.changedTouches[0].pageY - this.clientRect.y;
|
|
1457
|
-
this.onMouseUp({
|
|
1458
|
-
x,
|
|
1459
|
-
y,
|
|
1460
|
-
clientX: event.changedTouches[0].clientX,
|
|
1461
|
-
clientY: event.changedTouches[0].clientY,
|
|
1462
|
-
pageX: event.changedTouches[0].pageX,
|
|
1463
|
-
pageY: event.changedTouches[0].pageY,
|
|
1464
|
-
ctrlKey: event.ctrlKey || event.metaKey,
|
|
1465
|
-
shiftKey: event.shiftKey,
|
|
1466
|
-
altKey: event.altKey,
|
|
1467
|
-
buttons: 1,
|
|
1468
|
-
});
|
|
1469
1489
|
setTimeout(() => {
|
|
1490
|
+
this.onMouseUp({
|
|
1491
|
+
x,
|
|
1492
|
+
y,
|
|
1493
|
+
clientX: event.changedTouches[0].clientX,
|
|
1494
|
+
clientY: event.changedTouches[0].clientY,
|
|
1495
|
+
pageX: event.changedTouches[0].pageX,
|
|
1496
|
+
pageY: event.changedTouches[0].pageY,
|
|
1497
|
+
ctrlKey: event.ctrlKey || event.metaKey,
|
|
1498
|
+
shiftKey: event.shiftKey,
|
|
1499
|
+
altKey: event.altKey,
|
|
1500
|
+
buttons: 1,
|
|
1501
|
+
});
|
|
1470
1502
|
this.render();
|
|
1471
|
-
},
|
|
1503
|
+
}, 60);
|
|
1472
1504
|
};
|
|
1473
1505
|
onGesturestart = (e) => {
|
|
1474
1506
|
e.preventDefault();
|
|
@@ -2992,7 +3024,7 @@ export class Canvas {
|
|
|
2992
3024
|
}
|
|
2993
3025
|
}
|
|
2994
3026
|
else {
|
|
2995
|
-
this.externalElements.style.cursor = this.store.options.hoverCursor;
|
|
3027
|
+
this.externalElements.style.cursor = pen.hoverCursor || this.store.options.hoverCursor;
|
|
2996
3028
|
}
|
|
2997
3029
|
if (pen.calculative.disabled) {
|
|
2998
3030
|
this.externalElements.style.cursor = 'not-allowed';
|
|
@@ -3039,7 +3071,7 @@ export class Canvas {
|
|
|
3039
3071
|
}
|
|
3040
3072
|
}
|
|
3041
3073
|
else {
|
|
3042
|
-
this.externalElements.style.cursor = this.store.options.hoverCursor;
|
|
3074
|
+
this.externalElements.style.cursor = pen.hoverCursor || this.store.options.hoverCursor;
|
|
3043
3075
|
}
|
|
3044
3076
|
if (pen.calculative.disabled) {
|
|
3045
3077
|
this.externalElements.style.cursor = 'not-allowed';
|
|
@@ -6589,8 +6621,8 @@ export class Canvas {
|
|
|
6589
6621
|
}
|
|
6590
6622
|
if (pen.fontSize) {
|
|
6591
6623
|
if (pen.fontSize * scale < 12) {
|
|
6592
|
-
style += `font-size:${pen.fontSize}px;`;
|
|
6593
|
-
style += `zoom:${(pen.fontSize / 12) * scale};`;
|
|
6624
|
+
style += `font-size:${pen.calculative.fontSize}px;`;
|
|
6625
|
+
// style += `zoom:${(pen.fontSize / 12) * scale};`;
|
|
6594
6626
|
}
|
|
6595
6627
|
else {
|
|
6596
6628
|
style += `font-size:${pen.fontSize * scale}px;`;
|
|
@@ -6605,18 +6637,20 @@ export class Canvas {
|
|
|
6605
6637
|
}
|
|
6606
6638
|
if (pen.textLeft) {
|
|
6607
6639
|
style += `margin-left:${scale > 1
|
|
6608
|
-
? pen.textLeft *
|
|
6609
|
-
: (pen.textLeft *
|
|
6640
|
+
? pen.textLeft * scale
|
|
6641
|
+
: (pen.textLeft * scale) // scale
|
|
6642
|
+
}px;`;
|
|
6610
6643
|
}
|
|
6611
6644
|
if (pen.textTop) {
|
|
6612
6645
|
style += `margin-top:${scale > 1
|
|
6613
6646
|
? pen.textTop * font_scale
|
|
6614
|
-
: (pen.textTop * font_scale)
|
|
6647
|
+
: (pen.textTop * font_scale) // scale
|
|
6648
|
+
}px;`;
|
|
6615
6649
|
}
|
|
6616
6650
|
if (pen.lineHeight) {
|
|
6617
6651
|
style += `line-height:${scale > 1
|
|
6618
6652
|
? pen.fontSize * pen.lineHeight * scale
|
|
6619
|
-
: pen.fontSize * pen.lineHeight
|
|
6653
|
+
: pen.calculative.fontSize * pen.lineHeight}px;`;
|
|
6620
6654
|
}
|
|
6621
6655
|
if (pen.textHeight) {
|
|
6622
6656
|
style += `height:${scale > 1
|
|
@@ -6628,7 +6662,7 @@ export class Canvas {
|
|
|
6628
6662
|
if (tem < 0) {
|
|
6629
6663
|
tem = 0;
|
|
6630
6664
|
}
|
|
6631
|
-
let height = pen.fontSize * scale < 12 ? tem * font_scale : tem * scale * font_scale;
|
|
6665
|
+
let height = pen.fontSize * scale < 12 ? tem * scale * font_scale : tem * scale * font_scale;
|
|
6632
6666
|
if (height < pen.fontSize * pen.lineHeight * scale) {
|
|
6633
6667
|
height = pen.fontSize * pen.lineHeight * scale;
|
|
6634
6668
|
style += `top:-${height / 2}px;`;
|
|
@@ -6640,17 +6674,18 @@ export class Canvas {
|
|
|
6640
6674
|
}
|
|
6641
6675
|
let _textWidth = null;
|
|
6642
6676
|
if (pen.textWidth) {
|
|
6643
|
-
_textWidth =
|
|
6644
|
-
|
|
6645
|
-
|
|
6646
|
-
|
|
6677
|
+
// _textWidth =
|
|
6678
|
+
// pen.textWidth < 1 && pen.textWidth > -1
|
|
6679
|
+
// ? pen.textWidth * pen.calculative.worldRect.width
|
|
6680
|
+
// : pen.textWidth;
|
|
6681
|
+
_textWidth = pen.calculative.textWidth;
|
|
6647
6682
|
if (pen.whiteSpace !== 'pre-line') {
|
|
6648
6683
|
if (_textWidth < pen.fontSize) {
|
|
6649
6684
|
style += `width:${pen.fontSize * 1.2 * font_scale}px;`;
|
|
6650
6685
|
}
|
|
6651
6686
|
else {
|
|
6652
6687
|
style += `width:${scale > 1
|
|
6653
|
-
? _textWidth * font_scale
|
|
6688
|
+
? _textWidth * font_scale
|
|
6654
6689
|
: _textWidth * font_scale}px;`;
|
|
6655
6690
|
}
|
|
6656
6691
|
}
|
|
@@ -6661,7 +6696,7 @@ export class Canvas {
|
|
|
6661
6696
|
if (tem < 0) {
|
|
6662
6697
|
tem = 0;
|
|
6663
6698
|
}
|
|
6664
|
-
style += `width:${pen.fontSize * scale < 12 ? tem *
|
|
6699
|
+
style += `width:${pen.fontSize * scale < 12 ? tem * scale : tem * scale}px;`;
|
|
6665
6700
|
}
|
|
6666
6701
|
// if (pen.whiteSpace === 'pre-line') {
|
|
6667
6702
|
// //回车换行
|