@meta2d/core 1.0.99 → 1.1.1
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 +5 -1
- package/src/canvas/canvas.js +91 -33
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.js +21 -4
- package/src/core.js.map +1 -1
- package/src/diagrams/iframe.d.ts +2 -0
- package/src/diagrams/iframe.js +46 -5
- package/src/diagrams/iframe.js.map +1 -1
- package/src/dialog/dialog.d.ts +1 -0
- package/src/dialog/dialog.js +1 -1
- package/src/dialog/dialog.js.map +1 -1
- package/src/options.d.ts +1 -0
- package/src/options.js.map +1 -1
- package/src/pen/model.d.ts +4 -0
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.js +143 -37
- package/src/pen/render.js.map +1 -1
- package/src/pen/text.js +8 -0
- package/src/pen/text.js.map +1 -1
- package/src/store/store.d.ts +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
|
*/
|
|
@@ -261,7 +264,8 @@ export declare class Canvas {
|
|
|
261
264
|
*/
|
|
262
265
|
private firefoxLoadSvg;
|
|
263
266
|
loadImage(pen: Pen): void;
|
|
264
|
-
|
|
267
|
+
__loadMap: Map<any, any>;
|
|
268
|
+
__loadImage(src: string, retryNum?: number): any;
|
|
265
269
|
private imageTimer;
|
|
266
270
|
imageLoaded(): void;
|
|
267
271
|
private templateImageTimer;
|
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';
|
|
@@ -3292,6 +3324,7 @@ export class Canvas {
|
|
|
3292
3324
|
clearCanvas() {
|
|
3293
3325
|
this.activeRect = undefined;
|
|
3294
3326
|
this.sizeCPs = undefined;
|
|
3327
|
+
this.__loadMap = new Map();
|
|
3295
3328
|
this.canvas
|
|
3296
3329
|
.getContext('2d')
|
|
3297
3330
|
.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
@@ -3999,28 +4032,50 @@ export class Canvas {
|
|
|
3999
4032
|
pen.calculative.strokeImage = pen.strokeImage;
|
|
4000
4033
|
}
|
|
4001
4034
|
}
|
|
4035
|
+
__loadMap = new Map();
|
|
4002
4036
|
// 加载图片到全局缓存
|
|
4003
|
-
__loadImage(src) {
|
|
4004
|
-
|
|
4037
|
+
__loadImage(src, retryNum = 5) {
|
|
4038
|
+
if (this.__loadMap.has(src))
|
|
4039
|
+
return this.__loadMap.get(src); // promise
|
|
4040
|
+
const promise = new Promise((resolve, reject) => {
|
|
4005
4041
|
if (!globalStore.htmlElements[src]) {
|
|
4006
4042
|
const img = new Image();
|
|
4007
4043
|
img.crossOrigin = 'anonymous';
|
|
4008
|
-
|
|
4044
|
+
// 处理 CDN 路径
|
|
4009
4045
|
if (this.store.options.cdn &&
|
|
4010
4046
|
!(src.startsWith('http') ||
|
|
4011
4047
|
src.startsWith('//') ||
|
|
4012
4048
|
src.startsWith('data:image'))) {
|
|
4013
4049
|
img.src = this.store.options.cdn + src;
|
|
4014
4050
|
}
|
|
4051
|
+
else {
|
|
4052
|
+
img.src = src;
|
|
4053
|
+
}
|
|
4015
4054
|
img.onload = () => {
|
|
4016
4055
|
globalStore.htmlElements[src] = img;
|
|
4056
|
+
this.__loadMap.delete(src); // 成功后清理
|
|
4017
4057
|
resolve(img);
|
|
4018
4058
|
};
|
|
4059
|
+
img.onerror = () => {
|
|
4060
|
+
if (retryNum > 0) {
|
|
4061
|
+
console.warn(`Image ${src} load failed, retrying... (${retryNum})`);
|
|
4062
|
+
setTimeout(() => {
|
|
4063
|
+
this.__loadMap.delete(src);
|
|
4064
|
+
this.__loadImage(src, retryNum - 1).then(resolve).catch(reject);
|
|
4065
|
+
}, 1000);
|
|
4066
|
+
}
|
|
4067
|
+
else {
|
|
4068
|
+
this.__loadMap.set(src, 0);
|
|
4069
|
+
reject(new Error(`Failed to load image: ${src}`));
|
|
4070
|
+
}
|
|
4071
|
+
};
|
|
4019
4072
|
}
|
|
4020
4073
|
else {
|
|
4021
4074
|
resolve(globalStore.htmlElements[src]);
|
|
4022
4075
|
}
|
|
4023
4076
|
});
|
|
4077
|
+
this.__loadMap.set(src, promise);
|
|
4078
|
+
return promise;
|
|
4024
4079
|
}
|
|
4025
4080
|
imageTimer;
|
|
4026
4081
|
// 避免初始化图片加载重复调用 render,此处防抖
|
|
@@ -6526,7 +6581,7 @@ export class Canvas {
|
|
|
6526
6581
|
else {
|
|
6527
6582
|
// this.inputRight.style.display = 'none';
|
|
6528
6583
|
}
|
|
6529
|
-
this.inputDiv.contentEditable = 'true';
|
|
6584
|
+
this.inputDiv.contentEditable = pen.readonly ? 'false' : 'true';
|
|
6530
6585
|
this.inputDiv.focus();
|
|
6531
6586
|
const range = window.getSelection(); //创建range
|
|
6532
6587
|
range.selectAllChildren(this.inputDiv); //range 选择obj下所有子内容
|
|
@@ -6589,8 +6644,8 @@ export class Canvas {
|
|
|
6589
6644
|
}
|
|
6590
6645
|
if (pen.fontSize) {
|
|
6591
6646
|
if (pen.fontSize * scale < 12) {
|
|
6592
|
-
style += `font-size:${pen.fontSize}px;`;
|
|
6593
|
-
style += `zoom:${(pen.fontSize / 12) * scale};`;
|
|
6647
|
+
style += `font-size:${pen.calculative.fontSize}px;`;
|
|
6648
|
+
// style += `zoom:${(pen.fontSize / 12) * scale};`;
|
|
6594
6649
|
}
|
|
6595
6650
|
else {
|
|
6596
6651
|
style += `font-size:${pen.fontSize * scale}px;`;
|
|
@@ -6605,18 +6660,20 @@ export class Canvas {
|
|
|
6605
6660
|
}
|
|
6606
6661
|
if (pen.textLeft) {
|
|
6607
6662
|
style += `margin-left:${scale > 1
|
|
6608
|
-
? pen.textLeft *
|
|
6609
|
-
: (pen.textLeft *
|
|
6663
|
+
? pen.textLeft * scale
|
|
6664
|
+
: (pen.textLeft * scale) // scale
|
|
6665
|
+
}px;`;
|
|
6610
6666
|
}
|
|
6611
6667
|
if (pen.textTop) {
|
|
6612
6668
|
style += `margin-top:${scale > 1
|
|
6613
6669
|
? pen.textTop * font_scale
|
|
6614
|
-
: (pen.textTop * font_scale)
|
|
6670
|
+
: (pen.textTop * font_scale) // scale
|
|
6671
|
+
}px;`;
|
|
6615
6672
|
}
|
|
6616
6673
|
if (pen.lineHeight) {
|
|
6617
6674
|
style += `line-height:${scale > 1
|
|
6618
6675
|
? pen.fontSize * pen.lineHeight * scale
|
|
6619
|
-
: pen.fontSize * pen.lineHeight
|
|
6676
|
+
: pen.calculative.fontSize * pen.lineHeight}px;`;
|
|
6620
6677
|
}
|
|
6621
6678
|
if (pen.textHeight) {
|
|
6622
6679
|
style += `height:${scale > 1
|
|
@@ -6628,7 +6685,7 @@ export class Canvas {
|
|
|
6628
6685
|
if (tem < 0) {
|
|
6629
6686
|
tem = 0;
|
|
6630
6687
|
}
|
|
6631
|
-
let height = pen.fontSize * scale < 12 ? tem * font_scale : tem * scale * font_scale;
|
|
6688
|
+
let height = pen.fontSize * scale < 12 ? tem * scale * font_scale : tem * scale * font_scale;
|
|
6632
6689
|
if (height < pen.fontSize * pen.lineHeight * scale) {
|
|
6633
6690
|
height = pen.fontSize * pen.lineHeight * scale;
|
|
6634
6691
|
style += `top:-${height / 2}px;`;
|
|
@@ -6640,17 +6697,18 @@ export class Canvas {
|
|
|
6640
6697
|
}
|
|
6641
6698
|
let _textWidth = null;
|
|
6642
6699
|
if (pen.textWidth) {
|
|
6643
|
-
_textWidth =
|
|
6644
|
-
|
|
6645
|
-
|
|
6646
|
-
|
|
6700
|
+
// _textWidth =
|
|
6701
|
+
// pen.textWidth < 1 && pen.textWidth > -1
|
|
6702
|
+
// ? pen.textWidth * pen.calculative.worldRect.width
|
|
6703
|
+
// : pen.textWidth;
|
|
6704
|
+
_textWidth = pen.calculative.textWidth;
|
|
6647
6705
|
if (pen.whiteSpace !== 'pre-line') {
|
|
6648
6706
|
if (_textWidth < pen.fontSize) {
|
|
6649
6707
|
style += `width:${pen.fontSize * 1.2 * font_scale}px;`;
|
|
6650
6708
|
}
|
|
6651
6709
|
else {
|
|
6652
6710
|
style += `width:${scale > 1
|
|
6653
|
-
? _textWidth * font_scale
|
|
6711
|
+
? _textWidth * font_scale
|
|
6654
6712
|
: _textWidth * font_scale}px;`;
|
|
6655
6713
|
}
|
|
6656
6714
|
}
|
|
@@ -6661,7 +6719,7 @@ export class Canvas {
|
|
|
6661
6719
|
if (tem < 0) {
|
|
6662
6720
|
tem = 0;
|
|
6663
6721
|
}
|
|
6664
|
-
style += `width:${pen.fontSize * scale < 12 ? tem *
|
|
6722
|
+
style += `width:${pen.fontSize * scale < 12 ? tem * scale : tem * scale}px;`;
|
|
6665
6723
|
}
|
|
6666
6724
|
// if (pen.whiteSpace === 'pre-line') {
|
|
6667
6725
|
// //回车换行
|