@meta2d/core 1.0.16 → 1.0.18
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 +4 -3
- package/src/canvas/canvas.js +233 -201
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +20 -11
- package/src/core.js +423 -163
- package/src/core.js.map +1 -1
- package/src/diagrams/gif.js +4 -1
- package/src/diagrams/gif.js.map +1 -1
- package/src/pen/model.d.ts +2 -0
- package/src/pen/model.js +3 -0
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.js +6 -3
- package/src/pen/render.js.map +1 -1
- package/src/store/store.d.ts +1 -0
- package/src/store/store.js.map +1 -1
- package/src/utils/file.d.ts +1 -0
- package/src/utils/file.js +8 -0
- package/src/utils/file.js.map +1 -1
- package/src/utils/index.d.ts +0 -1
- package/src/utils/index.js +0 -1
- package/src/utils/index.js.map +1 -1
- package/src/utils/object.d.ts +2 -0
- package/src/utils/object.js +21 -0
- package/src/utils/object.js.map +1 -0
package/src/canvas/canvas.js
CHANGED
|
@@ -86,7 +86,7 @@ import { addLineAnchor, calcIconRect, calcTextRect, calcWorldAnchors, calcWorldR
|
|
|
86
86
|
import { calcRotate, distance, hitPoint, PrevNextType, rotatePoint, samePoint, scalePoint, translatePoint, TwoWay, } from '../point';
|
|
87
87
|
import { calcCenter, calcRightBottom, calcRelativePoint, getRect, getRectOfPoints, pointInRect, pointInSimpleRect, rectInRect, rectToPoints, resizeRect, translateRect, } from '../rect';
|
|
88
88
|
import { EditType, globalStore, } from '../store';
|
|
89
|
-
import { deepClone, fileToBase64, uploadFile, formatPadding,
|
|
89
|
+
import { deepClone, fileToBase64, uploadFile, formatPadding, rgba, s8, } from '../utils';
|
|
90
90
|
import { inheritanceProps, defaultCursors, defaultDrawLineFns, HotkeyType, HoverType, MouseRight, rotatedCursors, } from '../data';
|
|
91
91
|
import { createOffscreen } from './offscreen';
|
|
92
92
|
import { curve, mind, getLineLength, getLineRect, pointInLine, simplify, smoothLine, lineSegment, getLineR, lineInRect, } from '../diagrams';
|
|
@@ -97,6 +97,7 @@ import { CanvasImage } from './canvasImage';
|
|
|
97
97
|
import { MagnifierCanvas } from './magnifierCanvas';
|
|
98
98
|
import { lockedError } from '../utils/error';
|
|
99
99
|
import { Dialog } from '../dialog';
|
|
100
|
+
import { setter } from '../utils/object';
|
|
100
101
|
export var movingSuffix = '-moving';
|
|
101
102
|
var Canvas = /** @class */ (function () {
|
|
102
103
|
function Canvas(parent, parentElement, store) {
|
|
@@ -123,6 +124,8 @@ var Canvas = /** @class */ (function () {
|
|
|
123
124
|
this.animateRendering = false;
|
|
124
125
|
this.pointSize = 8;
|
|
125
126
|
this.pasteOffset = 10;
|
|
127
|
+
this.opening = false;
|
|
128
|
+
this.maxZindex = 4;
|
|
126
129
|
this.inputParent = document.createElement('div');
|
|
127
130
|
// input = document.createElement('textarea');
|
|
128
131
|
this.inputDiv = document.createElement('div');
|
|
@@ -236,69 +239,50 @@ var Canvas = /** @class */ (function () {
|
|
|
236
239
|
if (_this.pencil) {
|
|
237
240
|
return;
|
|
238
241
|
}
|
|
239
|
-
e.preventDefault();
|
|
240
|
-
e.stopPropagation();
|
|
241
242
|
if (_this.store.options.disableScale) {
|
|
242
243
|
return;
|
|
243
244
|
}
|
|
245
|
+
e.preventDefault();
|
|
246
|
+
e.stopPropagation();
|
|
244
247
|
if (_this.store.data.locked === LockState.Disable)
|
|
245
248
|
return;
|
|
246
249
|
if (_this.store.data.locked === LockState.DisableScale)
|
|
247
250
|
return;
|
|
248
251
|
if (_this.store.data.locked === LockState.DisableMoveScale)
|
|
249
252
|
return;
|
|
250
|
-
|
|
251
|
-
if (
|
|
252
|
-
e.
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
//window触控板只允许平移 触摸屏一般不超过100
|
|
257
|
-
var isWin = navigator.userAgent.indexOf('Win') !== -1;
|
|
258
|
-
if (isWin && !e.ctrlKey && Math.abs(e.deltaY) < 100) {
|
|
259
|
-
_this.translate(-e.deltaX, -e.deltaY);
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
//mac触控板只允许平移(排除普通鼠标的情况)
|
|
263
|
-
var isMac = /macintosh|mac os x/i.test(navigator.userAgent) ||
|
|
264
|
-
navigator.platform.indexOf('Mac') !== -1;
|
|
265
|
-
if (isMac && !e.ctrlKey && e.wheelDeltaY % 240 !== 0) {
|
|
253
|
+
// e.ctrlKey: false - 平移; true - 缩放。老windows触摸板不支持
|
|
254
|
+
if (!e.ctrlKey && Math.abs(e.wheelDelta) < 100) {
|
|
255
|
+
if (_this.store.options.scroll && !e.metaKey && _this.scroll) {
|
|
256
|
+
_this.scroll.wheel(e.deltaY < 0);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
266
259
|
_this.translate(-e.deltaX, -e.deltaY);
|
|
267
260
|
return;
|
|
268
261
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
// 触摸板平移
|
|
274
|
-
var isTouchPad = !(!e.deltaX && e.deltaY);
|
|
275
|
-
var now = performance.now();
|
|
276
|
-
var _scale = 0.1;
|
|
277
|
-
if (now - _this.touchStart < 50) {
|
|
262
|
+
//禁止触摸屏双指缩放操作
|
|
263
|
+
if (_this.store.options.disableTouchPadScale) {
|
|
278
264
|
return;
|
|
279
265
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
_this.touchStart = now;
|
|
290
|
-
var x = e.offsetX, y = e.offsetY;
|
|
291
|
-
if (isTouchPad) {
|
|
292
|
-
_this.translate(e.deltaX, e.deltaY);
|
|
266
|
+
var scaleOff = 0.015;
|
|
267
|
+
var isMac = /mac os /i.test(navigator.userAgent);
|
|
268
|
+
if (isMac) {
|
|
269
|
+
if (!e.ctrlKey) {
|
|
270
|
+
scaleOff *= e.wheelDeltaY / 240;
|
|
271
|
+
}
|
|
272
|
+
else if (e.deltaY > 0) {
|
|
273
|
+
scaleOff *= -1;
|
|
274
|
+
}
|
|
293
275
|
}
|
|
294
276
|
else {
|
|
295
|
-
if (e.deltaY
|
|
296
|
-
|
|
277
|
+
if (e.deltaY > 0) {
|
|
278
|
+
scaleOff = -0.2;
|
|
297
279
|
}
|
|
298
280
|
else {
|
|
299
|
-
|
|
281
|
+
scaleOff = 0.2;
|
|
300
282
|
}
|
|
301
283
|
}
|
|
284
|
+
var x = e.offsetX, y = e.offsetY;
|
|
285
|
+
_this.scale(_this.store.data.scale + scaleOff, { x: x, y: y });
|
|
302
286
|
_this.externalElements.focus(); // 聚焦
|
|
303
287
|
};
|
|
304
288
|
this.onkeydown = function (e) {
|
|
@@ -603,34 +587,40 @@ var Canvas = /** @class */ (function () {
|
|
|
603
587
|
console.warn('canvas is locked, can not drop');
|
|
604
588
|
return [2 /*return*/];
|
|
605
589
|
}
|
|
606
|
-
|
|
607
|
-
case 1:
|
|
608
|
-
_a.trys.push([1, 4, , 5]);
|
|
609
|
-
// TODO: 若画布锁定,阻止默认行为不再执行。在 firefox 上拖拽图片会打开新页
|
|
590
|
+
// Fix bug: 在 firefox 上拖拽图片会打开新页
|
|
610
591
|
event.preventDefault();
|
|
611
592
|
event.stopPropagation();
|
|
612
593
|
json = event.dataTransfer.getData('Meta2d') ||
|
|
613
594
|
event.dataTransfer.getData('Text');
|
|
614
595
|
obj = null;
|
|
615
|
-
|
|
596
|
+
_a.label = 1;
|
|
597
|
+
case 1:
|
|
598
|
+
_a.trys.push([1, 5, , 6]);
|
|
599
|
+
if (!json) return [3 /*break*/, 2];
|
|
600
|
+
obj = JSON.parse(json);
|
|
601
|
+
return [3 /*break*/, 4];
|
|
602
|
+
case 2:
|
|
616
603
|
files = event.dataTransfer.files;
|
|
617
|
-
if (!(files.length && files[0].type.match('image.*'))) return [3 /*break*/,
|
|
604
|
+
if (!(files.length && files[0].type.match('image.*'))) return [3 /*break*/, 4];
|
|
618
605
|
isGif = files[0].type === 'image/gif';
|
|
619
606
|
return [4 /*yield*/, this.fileToPen(files[0], isGif)];
|
|
620
|
-
case 2:
|
|
621
|
-
obj = _a.sent();
|
|
622
|
-
_a.label = 3;
|
|
623
607
|
case 3:
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
pt = { x: event.offsetX, y: event.offsetY };
|
|
627
|
-
this.calibrateMouse(pt);
|
|
628
|
-
this.dropPens(obj, pt);
|
|
629
|
-
return [3 /*break*/, 5];
|
|
608
|
+
obj = _a.sent();
|
|
609
|
+
_a.label = 4;
|
|
630
610
|
case 4:
|
|
611
|
+
if (obj && obj.draggable !== false) {
|
|
612
|
+
obj = Array.isArray(obj) ? obj : [obj];
|
|
613
|
+
pt = { x: event.offsetX, y: event.offsetY };
|
|
614
|
+
this.calibrateMouse(pt);
|
|
615
|
+
this.dropPens(obj, pt);
|
|
616
|
+
}
|
|
617
|
+
return [3 /*break*/, 6];
|
|
618
|
+
case 5:
|
|
631
619
|
e_1 = _a.sent();
|
|
632
|
-
return [3 /*break*/,
|
|
633
|
-
case
|
|
620
|
+
return [3 /*break*/, 6];
|
|
621
|
+
case 6:
|
|
622
|
+
this.store.emitter.emit('drop', obj || json);
|
|
623
|
+
return [2 /*return*/];
|
|
634
624
|
}
|
|
635
625
|
});
|
|
636
626
|
}); };
|
|
@@ -782,7 +772,9 @@ var Canvas = /** @class */ (function () {
|
|
|
782
772
|
altKey: event.altKey,
|
|
783
773
|
buttons: 1,
|
|
784
774
|
});
|
|
785
|
-
|
|
775
|
+
setTimeout(function () {
|
|
776
|
+
_this.render();
|
|
777
|
+
}, 20);
|
|
786
778
|
};
|
|
787
779
|
this.onGesturestart = function (e) {
|
|
788
780
|
e.preventDefault();
|
|
@@ -1461,6 +1453,7 @@ var Canvas = /** @class */ (function () {
|
|
|
1461
1453
|
_this.clearDock();
|
|
1462
1454
|
_this.dragRect = undefined;
|
|
1463
1455
|
_this.initActiveRect = undefined;
|
|
1456
|
+
_this.render();
|
|
1464
1457
|
};
|
|
1465
1458
|
this.clearDock = function () {
|
|
1466
1459
|
var _a, _b, _c, _d;
|
|
@@ -1809,6 +1802,12 @@ var Canvas = /** @class */ (function () {
|
|
|
1809
1802
|
}
|
|
1810
1803
|
};
|
|
1811
1804
|
this.render = function (patchFlags) {
|
|
1805
|
+
if (patchFlags) {
|
|
1806
|
+
_this.opening = false;
|
|
1807
|
+
}
|
|
1808
|
+
if (_this.opening) {
|
|
1809
|
+
return;
|
|
1810
|
+
}
|
|
1812
1811
|
var now;
|
|
1813
1812
|
if (patchFlags == null || patchFlags === true || patchFlags === Infinity) {
|
|
1814
1813
|
now = performance.now();
|
|
@@ -2322,7 +2321,7 @@ var Canvas = /** @class */ (function () {
|
|
|
2322
2321
|
var _textWidth = null;
|
|
2323
2322
|
if (pen.textWidth) {
|
|
2324
2323
|
_textWidth =
|
|
2325
|
-
|
|
2324
|
+
pen.textWidth < 1 && pen.textWidth > -1
|
|
2326
2325
|
? pen.textWidth * pen.calculative.worldRect.width
|
|
2327
2326
|
: pen.textWidth;
|
|
2328
2327
|
if (pen.whiteSpace !== 'pre-line') {
|
|
@@ -2563,66 +2562,62 @@ var Canvas = /** @class */ (function () {
|
|
|
2563
2562
|
this.externalElements.ondragover = function (e) { return e.preventDefault(); };
|
|
2564
2563
|
this.externalElements.ondrop = this.ondrop;
|
|
2565
2564
|
this.externalElements.oncontextmenu = function (e) { return e.preventDefault(); };
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
_this.store.lastHover = undefined;
|
|
2623
|
-
}
|
|
2624
|
-
};
|
|
2625
|
-
}
|
|
2565
|
+
this.store.options.interval = 50;
|
|
2566
|
+
this.externalElements.ontouchstart = this.ontouchstart;
|
|
2567
|
+
this.externalElements.ontouchmove = this.ontouchmove;
|
|
2568
|
+
this.externalElements.ontouchend = this.ontouchend;
|
|
2569
|
+
this.externalElements.onmousedown = function (e) {
|
|
2570
|
+
_this.onMouseDown({
|
|
2571
|
+
x: e.offsetX,
|
|
2572
|
+
y: e.offsetY,
|
|
2573
|
+
clientX: e.clientX,
|
|
2574
|
+
clientY: e.clientY,
|
|
2575
|
+
pageX: e.pageX,
|
|
2576
|
+
pageY: e.pageY,
|
|
2577
|
+
ctrlKey: e.ctrlKey || e.metaKey,
|
|
2578
|
+
shiftKey: e.shiftKey,
|
|
2579
|
+
altKey: e.altKey,
|
|
2580
|
+
buttons: e.buttons,
|
|
2581
|
+
});
|
|
2582
|
+
};
|
|
2583
|
+
this.externalElements.onmousemove = function (e) {
|
|
2584
|
+
if (e.target !== _this.externalElements) {
|
|
2585
|
+
return;
|
|
2586
|
+
}
|
|
2587
|
+
_this.onMouseMove({
|
|
2588
|
+
x: e.offsetX,
|
|
2589
|
+
y: e.offsetY,
|
|
2590
|
+
clientX: e.clientX,
|
|
2591
|
+
clientY: e.clientY,
|
|
2592
|
+
pageX: e.pageX,
|
|
2593
|
+
pageY: e.pageY,
|
|
2594
|
+
ctrlKey: e.ctrlKey || e.metaKey,
|
|
2595
|
+
shiftKey: e.shiftKey,
|
|
2596
|
+
altKey: e.altKey,
|
|
2597
|
+
buttons: e.buttons,
|
|
2598
|
+
});
|
|
2599
|
+
};
|
|
2600
|
+
this.externalElements.onmouseup = function (e) {
|
|
2601
|
+
_this.onMouseUp({
|
|
2602
|
+
x: e.offsetX,
|
|
2603
|
+
y: e.offsetY,
|
|
2604
|
+
clientX: e.clientX,
|
|
2605
|
+
clientY: e.clientY,
|
|
2606
|
+
pageX: e.pageX,
|
|
2607
|
+
pageY: e.pageY,
|
|
2608
|
+
ctrlKey: e.ctrlKey || e.metaKey,
|
|
2609
|
+
shiftKey: e.shiftKey,
|
|
2610
|
+
altKey: e.altKey,
|
|
2611
|
+
buttons: e.buttons,
|
|
2612
|
+
button: e.button,
|
|
2613
|
+
});
|
|
2614
|
+
};
|
|
2615
|
+
this.externalElements.onmouseleave = function (e) {
|
|
2616
|
+
if (e.toElement !== _this.tooltip.box) {
|
|
2617
|
+
_this.tooltip.hide();
|
|
2618
|
+
_this.store.lastHover = undefined;
|
|
2619
|
+
}
|
|
2620
|
+
};
|
|
2626
2621
|
this.externalElements.ondblclick = this.ondblclick;
|
|
2627
2622
|
this.externalElements.tabIndex = 0;
|
|
2628
2623
|
this.externalElements.onblur = function () {
|
|
@@ -2759,10 +2754,10 @@ var Canvas = /** @class */ (function () {
|
|
|
2759
2754
|
};
|
|
2760
2755
|
Canvas.prototype.dropPens = function (pens, e) {
|
|
2761
2756
|
return __awaiter(this, void 0, void 0, function () {
|
|
2762
|
-
var pens_2, pens_2_1, pen, pens_3, pens_3_1, pen, pens_4, pens_4_1, pen;
|
|
2763
|
-
var e_8, _a, e_9, _b, e_10, _c;
|
|
2764
|
-
return __generator(this, function (
|
|
2765
|
-
switch (
|
|
2757
|
+
var pens_2, pens_2_1, pen, pens_3, pens_3_1, pen, pens_4, pens_4_1, pen, width, height, rect_1, flag, pens_5, pens_5_1, pen, points;
|
|
2758
|
+
var e_8, _a, e_9, _b, e_10, _c, e_11, _d;
|
|
2759
|
+
return __generator(this, function (_e) {
|
|
2760
|
+
switch (_e.label) {
|
|
2766
2761
|
case 0:
|
|
2767
2762
|
try {
|
|
2768
2763
|
for (pens_2 = __values(pens), pens_2_1 = pens_2.next(); !pens_2_1.done; pens_2_1 = pens_2.next()) {
|
|
@@ -2819,9 +2814,48 @@ var Canvas = /** @class */ (function () {
|
|
|
2819
2814
|
}
|
|
2820
2815
|
finally { if (e_10) throw e_10.error; }
|
|
2821
2816
|
}
|
|
2817
|
+
width = this.store.data.width || this.store.options.width;
|
|
2818
|
+
height = this.store.data.height || this.store.options.height;
|
|
2819
|
+
if (width && height) {
|
|
2820
|
+
rect_1 = {
|
|
2821
|
+
x: this.store.data.origin.x,
|
|
2822
|
+
y: this.store.data.origin.y,
|
|
2823
|
+
width: width * this.store.data.scale,
|
|
2824
|
+
height: height * this.store.data.scale,
|
|
2825
|
+
};
|
|
2826
|
+
flag = true;
|
|
2827
|
+
try {
|
|
2828
|
+
for (pens_5 = __values(pens), pens_5_1 = pens_5.next(); !pens_5_1.done; pens_5_1 = pens_5.next()) {
|
|
2829
|
+
pen = pens_5_1.value;
|
|
2830
|
+
if (!pen.parentId) {
|
|
2831
|
+
points = [
|
|
2832
|
+
{ x: pen.x, y: pen.y },
|
|
2833
|
+
{ x: pen.x + pen.width, y: pen.y },
|
|
2834
|
+
{ x: pen.x, y: pen.y + pen.height },
|
|
2835
|
+
{ x: pen.x + pen.width, y: pen.y + pen.height },
|
|
2836
|
+
];
|
|
2837
|
+
if (points.some(function (point) { return pointInRect(point, rect_1); })) {
|
|
2838
|
+
flag = false;
|
|
2839
|
+
break;
|
|
2840
|
+
}
|
|
2841
|
+
}
|
|
2842
|
+
}
|
|
2843
|
+
}
|
|
2844
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
2845
|
+
finally {
|
|
2846
|
+
try {
|
|
2847
|
+
if (pens_5_1 && !pens_5_1.done && (_d = pens_5.return)) _d.call(pens_5);
|
|
2848
|
+
}
|
|
2849
|
+
finally { if (e_11) throw e_11.error; }
|
|
2850
|
+
}
|
|
2851
|
+
if (flag) {
|
|
2852
|
+
console.info('画笔在大屏范围外');
|
|
2853
|
+
return [2 /*return*/];
|
|
2854
|
+
}
|
|
2855
|
+
}
|
|
2822
2856
|
return [4 /*yield*/, this.addPens(pens, true)];
|
|
2823
2857
|
case 1:
|
|
2824
|
-
|
|
2858
|
+
_e.sent();
|
|
2825
2859
|
this.active(pens.filter(function (pen) { return !pen.parentId; }));
|
|
2826
2860
|
this.render();
|
|
2827
2861
|
this.externalElements.focus(); // 聚焦
|
|
@@ -2831,7 +2865,7 @@ var Canvas = /** @class */ (function () {
|
|
|
2831
2865
|
});
|
|
2832
2866
|
};
|
|
2833
2867
|
Canvas.prototype.randomCombineId = function (pen, pens, parentId) {
|
|
2834
|
-
var
|
|
2868
|
+
var e_12, _a;
|
|
2835
2869
|
randomId(pen);
|
|
2836
2870
|
pen.parentId = parentId;
|
|
2837
2871
|
var newChildren = [];
|
|
@@ -2848,12 +2882,12 @@ var Canvas = /** @class */ (function () {
|
|
|
2848
2882
|
_loop_4(childId);
|
|
2849
2883
|
}
|
|
2850
2884
|
}
|
|
2851
|
-
catch (
|
|
2885
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
2852
2886
|
finally {
|
|
2853
2887
|
try {
|
|
2854
2888
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2855
2889
|
}
|
|
2856
|
-
finally { if (
|
|
2890
|
+
finally { if (e_12) throw e_12.error; }
|
|
2857
2891
|
}
|
|
2858
2892
|
}
|
|
2859
2893
|
pen.children = newChildren;
|
|
@@ -2861,8 +2895,8 @@ var Canvas = /** @class */ (function () {
|
|
|
2861
2895
|
};
|
|
2862
2896
|
Canvas.prototype.addPens = function (pens, history) {
|
|
2863
2897
|
return __awaiter(this, void 0, void 0, function () {
|
|
2864
|
-
var _a, list,
|
|
2865
|
-
var
|
|
2898
|
+
var _a, list, pens_6, pens_6_1, pen;
|
|
2899
|
+
var e_13, _b;
|
|
2866
2900
|
return __generator(this, function (_c) {
|
|
2867
2901
|
switch (_c.label) {
|
|
2868
2902
|
case 0:
|
|
@@ -2878,8 +2912,8 @@ var Canvas = /** @class */ (function () {
|
|
|
2878
2912
|
}
|
|
2879
2913
|
list = [];
|
|
2880
2914
|
try {
|
|
2881
|
-
for (
|
|
2882
|
-
pen =
|
|
2915
|
+
for (pens_6 = __values(pens), pens_6_1 = pens_6.next(); !pens_6_1.done; pens_6_1 = pens_6.next()) {
|
|
2916
|
+
pen = pens_6_1.value;
|
|
2883
2917
|
if (this.beforeAddPen && this.beforeAddPen(pen) != true) {
|
|
2884
2918
|
continue;
|
|
2885
2919
|
}
|
|
@@ -2887,12 +2921,12 @@ var Canvas = /** @class */ (function () {
|
|
|
2887
2921
|
list.push(pen);
|
|
2888
2922
|
}
|
|
2889
2923
|
}
|
|
2890
|
-
catch (
|
|
2924
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
2891
2925
|
finally {
|
|
2892
2926
|
try {
|
|
2893
|
-
if (
|
|
2927
|
+
if (pens_6_1 && !pens_6_1.done && (_b = pens_6.return)) _b.call(pens_6);
|
|
2894
2928
|
}
|
|
2895
|
-
finally { if (
|
|
2929
|
+
finally { if (e_13) throw e_13.error; }
|
|
2896
2930
|
}
|
|
2897
2931
|
this.render();
|
|
2898
2932
|
this.store.emitter.emit('add', list);
|
|
@@ -3158,7 +3192,7 @@ var Canvas = /** @class */ (function () {
|
|
|
3158
3192
|
this.patchFlags = true;
|
|
3159
3193
|
};
|
|
3160
3194
|
Canvas.prototype.active = function (pens, emit) {
|
|
3161
|
-
var
|
|
3195
|
+
var e_14, _a, _b;
|
|
3162
3196
|
if (emit === void 0) { emit = true; }
|
|
3163
3197
|
if (this.store.active) {
|
|
3164
3198
|
try {
|
|
@@ -3168,12 +3202,12 @@ var Canvas = /** @class */ (function () {
|
|
|
3168
3202
|
setChildrenActive(pen, false);
|
|
3169
3203
|
}
|
|
3170
3204
|
}
|
|
3171
|
-
catch (
|
|
3205
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
3172
3206
|
finally {
|
|
3173
3207
|
try {
|
|
3174
3208
|
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
3175
3209
|
}
|
|
3176
|
-
finally { if (
|
|
3210
|
+
finally { if (e_14) throw e_14.error; }
|
|
3177
3211
|
}
|
|
3178
3212
|
}
|
|
3179
3213
|
this.store.active = [];
|
|
@@ -3312,18 +3346,6 @@ var Canvas = /** @class */ (function () {
|
|
|
3312
3346
|
}
|
|
3313
3347
|
this.store.hoverAnchor = anchor;
|
|
3314
3348
|
this.store.hover = pen;
|
|
3315
|
-
// if (pen.name === 'line' && anchor.connectTo) {
|
|
3316
|
-
// const connectPen = this.findOne(anchor.connectTo);
|
|
3317
|
-
// if (!connectPen.calculative.active) {
|
|
3318
|
-
// this.store.hover = connectPen;
|
|
3319
|
-
// const connectAnchor = connectPen.calculative.worldAnchors.find(
|
|
3320
|
-
// (item) => item.id === anchor.anchorId
|
|
3321
|
-
// );
|
|
3322
|
-
// this.store.hoverAnchor = connectAnchor;
|
|
3323
|
-
// console.log('hover', connectAnchor);
|
|
3324
|
-
// }
|
|
3325
|
-
// }
|
|
3326
|
-
// console.log('hover', pen, anchor);
|
|
3327
3349
|
if (pen.type) {
|
|
3328
3350
|
if (anchor.connectTo && !pen.calculative.active) {
|
|
3329
3351
|
this.store.hover = this.store.pens[anchor.connectTo];
|
|
@@ -3371,7 +3393,7 @@ var Canvas = /** @class */ (function () {
|
|
|
3371
3393
|
return HoverType.None;
|
|
3372
3394
|
};
|
|
3373
3395
|
Canvas.prototype.resize = function (w, h) {
|
|
3374
|
-
var
|
|
3396
|
+
var e_15, _a;
|
|
3375
3397
|
w = w || this.parentElement.clientWidth;
|
|
3376
3398
|
h = h || this.parentElement.clientHeight;
|
|
3377
3399
|
this.width = w;
|
|
@@ -3412,12 +3434,12 @@ var Canvas = /** @class */ (function () {
|
|
|
3412
3434
|
calcInView(pen);
|
|
3413
3435
|
}
|
|
3414
3436
|
}
|
|
3415
|
-
catch (
|
|
3437
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
3416
3438
|
finally {
|
|
3417
3439
|
try {
|
|
3418
3440
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3419
3441
|
}
|
|
3420
|
-
finally { if (
|
|
3442
|
+
finally { if (e_15) throw e_15.error; }
|
|
3421
3443
|
}
|
|
3422
3444
|
};
|
|
3423
3445
|
Canvas.prototype.clearCanvas = function () {
|
|
@@ -3482,7 +3504,7 @@ var Canvas = /** @class */ (function () {
|
|
|
3482
3504
|
this.store.histories.splice(this.store.historyIndex + 1, this.store.histories.length - this.store.historyIndex - 1);
|
|
3483
3505
|
}
|
|
3484
3506
|
(_a = action.pens) === null || _a === void 0 ? void 0 : _a.forEach(function (pen) {
|
|
3485
|
-
var
|
|
3507
|
+
var e_16, _a;
|
|
3486
3508
|
var found;
|
|
3487
3509
|
if (action.initPens) {
|
|
3488
3510
|
try {
|
|
@@ -3493,12 +3515,12 @@ var Canvas = /** @class */ (function () {
|
|
|
3493
3515
|
}
|
|
3494
3516
|
}
|
|
3495
3517
|
}
|
|
3496
|
-
catch (
|
|
3518
|
+
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
3497
3519
|
finally {
|
|
3498
3520
|
try {
|
|
3499
3521
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3500
3522
|
}
|
|
3501
|
-
finally { if (
|
|
3523
|
+
finally { if (e_16) throw e_16.error; }
|
|
3502
3524
|
}
|
|
3503
3525
|
}
|
|
3504
3526
|
if (found) {
|
|
@@ -3556,11 +3578,11 @@ var Canvas = /** @class */ (function () {
|
|
|
3556
3578
|
var _this = this;
|
|
3557
3579
|
var before = this.store.histories[this.store.historyIndex];
|
|
3558
3580
|
if (before && before.type === EditType.Add) {
|
|
3559
|
-
var
|
|
3581
|
+
var pens_7 = [];
|
|
3560
3582
|
before.pens.forEach(function (pen) {
|
|
3561
|
-
|
|
3583
|
+
pens_7.push(_this.store.pens[pen.id]);
|
|
3562
3584
|
});
|
|
3563
|
-
this.active(
|
|
3585
|
+
this.active(pens_7);
|
|
3564
3586
|
}
|
|
3565
3587
|
};
|
|
3566
3588
|
Canvas.prototype.doEditAction = function (action, undo) {
|
|
@@ -3649,6 +3671,7 @@ var Canvas = /** @class */ (function () {
|
|
|
3649
3671
|
else {
|
|
3650
3672
|
this.initImageCanvas(action.pens);
|
|
3651
3673
|
}
|
|
3674
|
+
this.parent.onSizeUpdate();
|
|
3652
3675
|
this.render();
|
|
3653
3676
|
this.store.emitter.emit(undo ? 'undo' : 'redo', action);
|
|
3654
3677
|
};
|
|
@@ -3953,7 +3976,10 @@ var Canvas = /** @class */ (function () {
|
|
|
3953
3976
|
}
|
|
3954
3977
|
else {
|
|
3955
3978
|
var img_1 = new Image();
|
|
3956
|
-
img_1.crossOrigin =
|
|
3979
|
+
img_1.crossOrigin =
|
|
3980
|
+
pen.crossOrigin === 'undefined'
|
|
3981
|
+
? undefined
|
|
3982
|
+
: pen.crossOrigin || 'anonymous';
|
|
3957
3983
|
img_1.src = pen.image;
|
|
3958
3984
|
if (this.store.options.cdn &&
|
|
3959
3985
|
!(pen.image.startsWith('http') ||
|
|
@@ -3962,6 +3988,7 @@ var Canvas = /** @class */ (function () {
|
|
|
3962
3988
|
img_1.src = this.store.options.cdn + pen.image;
|
|
3963
3989
|
}
|
|
3964
3990
|
img_1.onload = function () {
|
|
3991
|
+
// TODO: 连续的加载两张图片,若后开始加载 的图片先加载完成,可能会导致展示的是 先开始加载的图片
|
|
3965
3992
|
pen.calculative.img = img_1;
|
|
3966
3993
|
pen.calculative.imgNaturalWidth =
|
|
3967
3994
|
img_1.naturalWidth || pen.iconWidth;
|
|
@@ -4142,7 +4169,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4142
4169
|
this.onMovePens();
|
|
4143
4170
|
};
|
|
4144
4171
|
Canvas.prototype.onMovePens = function () {
|
|
4145
|
-
var
|
|
4172
|
+
var e_17, _a;
|
|
4146
4173
|
var _b;
|
|
4147
4174
|
var map = this.parent.map;
|
|
4148
4175
|
if (map && map.isShow) {
|
|
@@ -4167,12 +4194,12 @@ var Canvas = /** @class */ (function () {
|
|
|
4167
4194
|
}
|
|
4168
4195
|
}
|
|
4169
4196
|
}
|
|
4170
|
-
catch (
|
|
4197
|
+
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
4171
4198
|
finally {
|
|
4172
4199
|
try {
|
|
4173
4200
|
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
4174
4201
|
}
|
|
4175
|
-
finally { if (
|
|
4202
|
+
finally { if (e_17) throw e_17.error; }
|
|
4176
4203
|
}
|
|
4177
4204
|
};
|
|
4178
4205
|
/**
|
|
@@ -4232,7 +4259,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4232
4259
|
});
|
|
4233
4260
|
};
|
|
4234
4261
|
Canvas.prototype.rotatePens = function (e) {
|
|
4235
|
-
var
|
|
4262
|
+
var e_18, _a;
|
|
4236
4263
|
var _this = this;
|
|
4237
4264
|
if (!this.initPens) {
|
|
4238
4265
|
this.initPens = deepClone(this.getAllByPens(this.store.active));
|
|
@@ -4259,12 +4286,12 @@ var Canvas = /** @class */ (function () {
|
|
|
4259
4286
|
this.updateLines(pen);
|
|
4260
4287
|
}
|
|
4261
4288
|
}
|
|
4262
|
-
catch (
|
|
4289
|
+
catch (e_18_1) { e_18 = { error: e_18_1 }; }
|
|
4263
4290
|
finally {
|
|
4264
4291
|
try {
|
|
4265
4292
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
4266
4293
|
}
|
|
4267
|
-
finally { if (
|
|
4294
|
+
finally { if (e_18) throw e_18.error; }
|
|
4268
4295
|
}
|
|
4269
4296
|
this.lastRotate = this.activeRect.rotate;
|
|
4270
4297
|
this.getSizeCPs();
|
|
@@ -5128,7 +5155,7 @@ var Canvas = /** @class */ (function () {
|
|
|
5128
5155
|
return;
|
|
5129
5156
|
}
|
|
5130
5157
|
requestAnimationFrame(function () {
|
|
5131
|
-
var
|
|
5158
|
+
var e_19, _a;
|
|
5132
5159
|
var now = Date.now();
|
|
5133
5160
|
if (now - _this.lastAnimateRender < _this.store.options.animateInterval) {
|
|
5134
5161
|
if (_this.store.animates.size > 0) {
|
|
@@ -5213,12 +5240,12 @@ var Canvas = /** @class */ (function () {
|
|
|
5213
5240
|
_loop_5(pen);
|
|
5214
5241
|
}
|
|
5215
5242
|
}
|
|
5216
|
-
catch (
|
|
5243
|
+
catch (e_19_1) { e_19 = { error: e_19_1 }; }
|
|
5217
5244
|
finally {
|
|
5218
5245
|
try {
|
|
5219
5246
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
5220
5247
|
}
|
|
5221
|
-
finally { if (
|
|
5248
|
+
finally { if (e_19) throw e_19.error; }
|
|
5222
5249
|
}
|
|
5223
5250
|
if (active) {
|
|
5224
5251
|
_this.calcActiveRect();
|
|
@@ -5238,7 +5265,8 @@ var Canvas = /** @class */ (function () {
|
|
|
5238
5265
|
enumerable: false,
|
|
5239
5266
|
configurable: true
|
|
5240
5267
|
});
|
|
5241
|
-
Canvas.prototype.copy = function (pens) {
|
|
5268
|
+
Canvas.prototype.copy = function (pens, emit) {
|
|
5269
|
+
if (emit === void 0) { emit = true; }
|
|
5242
5270
|
return __awaiter(this, void 0, void 0, function () {
|
|
5243
5271
|
var page, _a, origin, scale, copyPens, clipboard, _b;
|
|
5244
5272
|
var _this = this;
|
|
@@ -5288,20 +5316,23 @@ var Canvas = /** @class */ (function () {
|
|
|
5288
5316
|
case 5:
|
|
5289
5317
|
localStorage.setItem(this.clipboardName, JSON.stringify(clipboard));
|
|
5290
5318
|
_c.label = 6;
|
|
5291
|
-
case 6:
|
|
5319
|
+
case 6:
|
|
5320
|
+
emit && this.store.emitter.emit('copy', clipboard.pens);
|
|
5321
|
+
return [2 /*return*/];
|
|
5292
5322
|
}
|
|
5293
5323
|
});
|
|
5294
5324
|
});
|
|
5295
5325
|
};
|
|
5296
5326
|
Canvas.prototype.cut = function (pens) {
|
|
5297
|
-
this.copy(pens);
|
|
5327
|
+
this.copy(pens, false);
|
|
5298
5328
|
this.delete(pens);
|
|
5329
|
+
this.store.emitter.emit('cut', pens);
|
|
5299
5330
|
};
|
|
5300
5331
|
Canvas.prototype.paste = function () {
|
|
5301
5332
|
var _a;
|
|
5302
5333
|
return __awaiter(this, void 0, void 0, function () {
|
|
5303
5334
|
var clipboardText, clipboard, _b, _c, offset, pos, curPage, rootPens, rootPens_1, rootPens_1_1, pen;
|
|
5304
|
-
var
|
|
5335
|
+
var e_20, _d;
|
|
5305
5336
|
return __generator(this, function (_e) {
|
|
5306
5337
|
switch (_e.label) {
|
|
5307
5338
|
case 0:
|
|
@@ -5370,18 +5401,19 @@ var Canvas = /** @class */ (function () {
|
|
|
5370
5401
|
this.pastePen(pen, undefined);
|
|
5371
5402
|
}
|
|
5372
5403
|
}
|
|
5373
|
-
catch (
|
|
5404
|
+
catch (e_20_1) { e_20 = { error: e_20_1 }; }
|
|
5374
5405
|
finally {
|
|
5375
5406
|
try {
|
|
5376
5407
|
if (rootPens_1_1 && !rootPens_1_1.done && (_d = rootPens_1.return)) _d.call(rootPens_1);
|
|
5377
5408
|
}
|
|
5378
|
-
finally { if (
|
|
5409
|
+
finally { if (e_20) throw e_20.error; }
|
|
5379
5410
|
}
|
|
5380
5411
|
sessionStorage.setItem('page', clipboard.page);
|
|
5381
5412
|
this.active(rootPens);
|
|
5382
5413
|
this.pushHistory({ type: EditType.Add, pens: this.store.clipboard.pens });
|
|
5383
5414
|
this.render();
|
|
5384
5415
|
this.store.emitter.emit('add', this.store.clipboard.pens);
|
|
5416
|
+
this.store.emitter.emit('paste', this.store.clipboard.pens);
|
|
5385
5417
|
return [2 /*return*/];
|
|
5386
5418
|
}
|
|
5387
5419
|
});
|
|
@@ -5392,20 +5424,20 @@ var Canvas = /** @class */ (function () {
|
|
|
5392
5424
|
* @param pens 不包含子节点
|
|
5393
5425
|
*/
|
|
5394
5426
|
Canvas.prototype.getAllByPens = function (pens) {
|
|
5395
|
-
var
|
|
5427
|
+
var e_21, _a;
|
|
5396
5428
|
var retPens = [];
|
|
5397
5429
|
try {
|
|
5398
|
-
for (var
|
|
5399
|
-
var pen =
|
|
5430
|
+
for (var pens_8 = __values(pens), pens_8_1 = pens_8.next(); !pens_8_1.done; pens_8_1 = pens_8.next()) {
|
|
5431
|
+
var pen = pens_8_1.value;
|
|
5400
5432
|
retPens.push.apply(retPens, __spreadArray([], __read(deepClone(getAllChildren(pen, this.store), true)), false));
|
|
5401
5433
|
}
|
|
5402
5434
|
}
|
|
5403
|
-
catch (
|
|
5435
|
+
catch (e_21_1) { e_21 = { error: e_21_1 }; }
|
|
5404
5436
|
finally {
|
|
5405
5437
|
try {
|
|
5406
|
-
if (
|
|
5438
|
+
if (pens_8_1 && !pens_8_1.done && (_a = pens_8.return)) _a.call(pens_8);
|
|
5407
5439
|
}
|
|
5408
|
-
finally { if (
|
|
5440
|
+
finally { if (e_21) throw e_21.error; }
|
|
5409
5441
|
}
|
|
5410
5442
|
return retPens.concat(pens);
|
|
5411
5443
|
};
|
|
@@ -5448,7 +5480,7 @@ var Canvas = /** @class */ (function () {
|
|
|
5448
5480
|
* @param pastePens 此处复制的全部 pens (包含子节点)
|
|
5449
5481
|
*/
|
|
5450
5482
|
Canvas.prototype.changeNodeConnectedLine = function (oldId, line, pastePens) {
|
|
5451
|
-
var
|
|
5483
|
+
var e_22, _a;
|
|
5452
5484
|
var _b;
|
|
5453
5485
|
var from = line.anchors[0];
|
|
5454
5486
|
var to = line.anchors[line.anchors.length - 1];
|
|
@@ -5484,12 +5516,12 @@ var Canvas = /** @class */ (function () {
|
|
|
5484
5516
|
_loop_7(anchor);
|
|
5485
5517
|
}
|
|
5486
5518
|
}
|
|
5487
|
-
catch (
|
|
5519
|
+
catch (e_22_1) { e_22 = { error: e_22_1 }; }
|
|
5488
5520
|
finally {
|
|
5489
5521
|
try {
|
|
5490
5522
|
if (anchors_1_1 && !anchors_1_1.done && (_a = anchors_1.return)) _a.call(anchors_1);
|
|
5491
5523
|
}
|
|
5492
|
-
finally { if (
|
|
5524
|
+
finally { if (e_22) throw e_22.error; }
|
|
5493
5525
|
}
|
|
5494
5526
|
};
|
|
5495
5527
|
Canvas.prototype.delete = function (pens, canDelLocked, history) {
|
|
@@ -5871,6 +5903,10 @@ var Canvas = /** @class */ (function () {
|
|
|
5871
5903
|
if (k === 'image') {
|
|
5872
5904
|
willRenderImage = true;
|
|
5873
5905
|
}
|
|
5906
|
+
if (k.indexOf('.') !== -1) {
|
|
5907
|
+
delete pen[k];
|
|
5908
|
+
setter(pen, k, data[k]);
|
|
5909
|
+
}
|
|
5874
5910
|
}
|
|
5875
5911
|
this.setCalculativeByScale(pen); // 该方法计算量并不大,所以每次修改都计算一次
|
|
5876
5912
|
if (isChangedName) {
|
|
@@ -5999,7 +6035,7 @@ var Canvas = /** @class */ (function () {
|
|
|
5999
6035
|
};
|
|
6000
6036
|
};
|
|
6001
6037
|
Canvas.prototype.toPng = function (padding, callback, containBkImg) {
|
|
6002
|
-
var
|
|
6038
|
+
var e_23, _a;
|
|
6003
6039
|
if (padding === void 0) { padding = 2; }
|
|
6004
6040
|
if (containBkImg === void 0) { containBkImg = false; }
|
|
6005
6041
|
var rect = getRect(this.store.data.pens);
|
|
@@ -6087,12 +6123,12 @@ var Canvas = /** @class */ (function () {
|
|
|
6087
6123
|
pen.calculative.active = active;
|
|
6088
6124
|
}
|
|
6089
6125
|
}
|
|
6090
|
-
catch (
|
|
6126
|
+
catch (e_23_1) { e_23 = { error: e_23_1 }; }
|
|
6091
6127
|
finally {
|
|
6092
6128
|
try {
|
|
6093
6129
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
6094
6130
|
}
|
|
6095
|
-
finally { if (
|
|
6131
|
+
finally { if (e_23) throw e_23.error; }
|
|
6096
6132
|
}
|
|
6097
6133
|
if (callback) {
|
|
6098
6134
|
canvas.toBlob(callback);
|
|
@@ -6232,17 +6268,13 @@ var Canvas = /** @class */ (function () {
|
|
|
6232
6268
|
this.externalElements.removeEventListener('gesturestart', this.onGesturestart);
|
|
6233
6269
|
this.externalElements.ondragover = function (e) { return e.preventDefault(); };
|
|
6234
6270
|
this.externalElements.ondrop = undefined;
|
|
6235
|
-
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
this.externalElements.onmousemove = undefined;
|
|
6243
|
-
this.externalElements.onmouseup = undefined;
|
|
6244
|
-
this.externalElements.onmouseleave = undefined;
|
|
6245
|
-
}
|
|
6271
|
+
this.externalElements.ontouchstart = undefined;
|
|
6272
|
+
this.externalElements.ontouchmove = undefined;
|
|
6273
|
+
this.externalElements.ontouchend = undefined;
|
|
6274
|
+
this.externalElements.onmousedown = undefined;
|
|
6275
|
+
this.externalElements.onmousemove = undefined;
|
|
6276
|
+
this.externalElements.onmouseup = undefined;
|
|
6277
|
+
this.externalElements.onmouseleave = undefined;
|
|
6246
6278
|
this.externalElements.ondblclick = undefined;
|
|
6247
6279
|
switch (this.store.options.keydown) {
|
|
6248
6280
|
case KeydownType.Document:
|