@meta2d/core 1.0.15 → 1.0.17
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 -2
- package/src/canvas/canvas.js +210 -194
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +42 -13
- package/src/core.js +669 -172
- package/src/core.js.map +1 -1
- package/src/diagrams/gif.js +3 -0
- package/src/diagrams/gif.js.map +1 -1
- package/src/dialog/dialog.d.ts +14 -0
- package/src/dialog/dialog.js +77 -0
- package/src/dialog/dialog.js.map +1 -0
- package/src/dialog/index.d.ts +1 -0
- package/src/dialog/index.js +2 -0
- package/src/dialog/index.js.map +1 -0
- package/src/event/event.d.ts +48 -3
- package/src/event/event.js +3 -0
- package/src/event/event.js.map +1 -1
- package/src/options.d.ts +1 -0
- package/src/options.js +1 -0
- package/src/options.js.map +1 -1
- package/src/pen/model.d.ts +4 -1
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.d.ts +1 -0
- package/src/pen/render.js +18 -6
- package/src/pen/render.js.map +1 -1
- package/src/store/store.d.ts +19 -14
- package/src/store/store.js.map +1 -1
- package/src/tooltip/tooltip.js +2 -2
- package/src/tooltip/tooltip.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';
|
|
@@ -96,6 +96,8 @@ import { Scroll } from '../scroll';
|
|
|
96
96
|
import { CanvasImage } from './canvasImage';
|
|
97
97
|
import { MagnifierCanvas } from './magnifierCanvas';
|
|
98
98
|
import { lockedError } from '../utils/error';
|
|
99
|
+
import { Dialog } from '../dialog';
|
|
100
|
+
import { setter } from '../utils/object';
|
|
99
101
|
export var movingSuffix = '-moving';
|
|
100
102
|
var Canvas = /** @class */ (function () {
|
|
101
103
|
function Canvas(parent, parentElement, store) {
|
|
@@ -122,6 +124,7 @@ var Canvas = /** @class */ (function () {
|
|
|
122
124
|
this.animateRendering = false;
|
|
123
125
|
this.pointSize = 8;
|
|
124
126
|
this.pasteOffset = 10;
|
|
127
|
+
this.opening = false;
|
|
125
128
|
this.inputParent = document.createElement('div');
|
|
126
129
|
// input = document.createElement('textarea');
|
|
127
130
|
this.inputDiv = document.createElement('div');
|
|
@@ -246,57 +249,25 @@ var Canvas = /** @class */ (function () {
|
|
|
246
249
|
return;
|
|
247
250
|
if (_this.store.data.locked === LockState.DisableMoveScale)
|
|
248
251
|
return;
|
|
249
|
-
|
|
250
|
-
if (
|
|
251
|
-
e.
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
//window触控板只允许平移 触摸屏一般不超过100
|
|
256
|
-
var isWin = navigator.userAgent.indexOf('Win') !== -1;
|
|
257
|
-
if (isWin && !e.ctrlKey && Math.abs(e.deltaY) < 100) {
|
|
258
|
-
_this.translate(-e.deltaX, -e.deltaY);
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
//mac触控板只允许平移(排除普通鼠标的情况)
|
|
262
|
-
var isMac = /macintosh|mac os x/i.test(navigator.userAgent) ||
|
|
263
|
-
navigator.platform.indexOf('Mac') !== -1;
|
|
264
|
-
if (isMac && !e.ctrlKey && e.wheelDeltaY % 240 !== 0) {
|
|
252
|
+
// e.ctrlKey: false - 平移; true - 缩放。老windows触摸板不支持
|
|
253
|
+
if (!e.ctrlKey) {
|
|
254
|
+
if (_this.store.options.scroll && !e.metaKey && _this.scroll) {
|
|
255
|
+
_this.scroll.wheel(e.deltaY < 0);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
265
258
|
_this.translate(-e.deltaX, -e.deltaY);
|
|
266
259
|
return;
|
|
267
260
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
// 触摸板平移
|
|
273
|
-
var isTouchPad = !(!e.deltaX && e.deltaY);
|
|
274
|
-
var now = performance.now();
|
|
275
|
-
var _scale = 0.1;
|
|
276
|
-
if (now - _this.touchStart < 50) {
|
|
261
|
+
//禁止触摸屏双指缩放操作
|
|
262
|
+
if (_this.store.options.disableTouchPadScale) {
|
|
277
263
|
return;
|
|
278
264
|
}
|
|
279
|
-
if (now - _this.touchStart < 100) {
|
|
280
|
-
_scale = 0.5;
|
|
281
|
-
}
|
|
282
|
-
else if (now - _this.touchStart < 200) {
|
|
283
|
-
_scale = 0.3;
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
_scale = 0.1;
|
|
287
|
-
}
|
|
288
|
-
_this.touchStart = now;
|
|
289
265
|
var x = e.offsetX, y = e.offsetY;
|
|
290
|
-
if (
|
|
291
|
-
_this.
|
|
266
|
+
if (e.deltaY < 0) {
|
|
267
|
+
_this.scale(_this.store.data.scale + 0.015, { x: x, y: y });
|
|
292
268
|
}
|
|
293
269
|
else {
|
|
294
|
-
|
|
295
|
-
_this.scale(_this.store.data.scale + _scale, { x: x, y: y });
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
_this.scale(_this.store.data.scale - _scale, { x: x, y: y });
|
|
299
|
-
}
|
|
270
|
+
_this.scale(_this.store.data.scale - 0.015, { x: x, y: y });
|
|
300
271
|
}
|
|
301
272
|
_this.externalElements.focus(); // 聚焦
|
|
302
273
|
};
|
|
@@ -781,7 +752,9 @@ var Canvas = /** @class */ (function () {
|
|
|
781
752
|
altKey: event.altKey,
|
|
782
753
|
buttons: 1,
|
|
783
754
|
});
|
|
784
|
-
|
|
755
|
+
setTimeout(function () {
|
|
756
|
+
_this.render();
|
|
757
|
+
}, 20);
|
|
785
758
|
};
|
|
786
759
|
this.onGesturestart = function (e) {
|
|
787
760
|
e.preventDefault();
|
|
@@ -1460,6 +1433,7 @@ var Canvas = /** @class */ (function () {
|
|
|
1460
1433
|
_this.clearDock();
|
|
1461
1434
|
_this.dragRect = undefined;
|
|
1462
1435
|
_this.initActiveRect = undefined;
|
|
1436
|
+
_this.render();
|
|
1463
1437
|
};
|
|
1464
1438
|
this.clearDock = function () {
|
|
1465
1439
|
var _a, _b, _c, _d;
|
|
@@ -1808,6 +1782,12 @@ var Canvas = /** @class */ (function () {
|
|
|
1808
1782
|
}
|
|
1809
1783
|
};
|
|
1810
1784
|
this.render = function (patchFlags) {
|
|
1785
|
+
if (patchFlags) {
|
|
1786
|
+
_this.opening = false;
|
|
1787
|
+
}
|
|
1788
|
+
if (_this.opening) {
|
|
1789
|
+
return;
|
|
1790
|
+
}
|
|
1811
1791
|
var now;
|
|
1812
1792
|
if (patchFlags == null || patchFlags === true || patchFlags === Infinity) {
|
|
1813
1793
|
now = performance.now();
|
|
@@ -2321,7 +2301,7 @@ var Canvas = /** @class */ (function () {
|
|
|
2321
2301
|
var _textWidth = null;
|
|
2322
2302
|
if (pen.textWidth) {
|
|
2323
2303
|
_textWidth =
|
|
2324
|
-
|
|
2304
|
+
pen.textWidth < 1 && pen.textWidth > -1
|
|
2325
2305
|
? pen.textWidth * pen.calculative.worldRect.width
|
|
2326
2306
|
: pen.textWidth;
|
|
2327
2307
|
if (pen.whiteSpace !== 'pre-line') {
|
|
@@ -2539,6 +2519,7 @@ var Canvas = /** @class */ (function () {
|
|
|
2539
2519
|
var hover = _this.store.data.pens.find(function (item) { return item.calculative.hover === true; });
|
|
2540
2520
|
setHover(hover, false);
|
|
2541
2521
|
};
|
|
2522
|
+
this.dialog = new Dialog(parentElement);
|
|
2542
2523
|
if (this.store.options.scroll) {
|
|
2543
2524
|
this.scroll = new Scroll(this);
|
|
2544
2525
|
}
|
|
@@ -2561,66 +2542,62 @@ var Canvas = /** @class */ (function () {
|
|
|
2561
2542
|
this.externalElements.ondragover = function (e) { return e.preventDefault(); };
|
|
2562
2543
|
this.externalElements.ondrop = this.ondrop;
|
|
2563
2544
|
this.externalElements.oncontextmenu = function (e) { return e.preventDefault(); };
|
|
2564
|
-
|
|
2565
|
-
|
|
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
|
-
_this.store.lastHover = undefined;
|
|
2621
|
-
}
|
|
2622
|
-
};
|
|
2623
|
-
}
|
|
2545
|
+
this.store.options.interval = 50;
|
|
2546
|
+
this.externalElements.ontouchstart = this.ontouchstart;
|
|
2547
|
+
this.externalElements.ontouchmove = this.ontouchmove;
|
|
2548
|
+
this.externalElements.ontouchend = this.ontouchend;
|
|
2549
|
+
this.externalElements.onmousedown = function (e) {
|
|
2550
|
+
_this.onMouseDown({
|
|
2551
|
+
x: e.offsetX,
|
|
2552
|
+
y: e.offsetY,
|
|
2553
|
+
clientX: e.clientX,
|
|
2554
|
+
clientY: e.clientY,
|
|
2555
|
+
pageX: e.pageX,
|
|
2556
|
+
pageY: e.pageY,
|
|
2557
|
+
ctrlKey: e.ctrlKey || e.metaKey,
|
|
2558
|
+
shiftKey: e.shiftKey,
|
|
2559
|
+
altKey: e.altKey,
|
|
2560
|
+
buttons: e.buttons,
|
|
2561
|
+
});
|
|
2562
|
+
};
|
|
2563
|
+
this.externalElements.onmousemove = function (e) {
|
|
2564
|
+
if (e.target !== _this.externalElements) {
|
|
2565
|
+
return;
|
|
2566
|
+
}
|
|
2567
|
+
_this.onMouseMove({
|
|
2568
|
+
x: e.offsetX,
|
|
2569
|
+
y: e.offsetY,
|
|
2570
|
+
clientX: e.clientX,
|
|
2571
|
+
clientY: e.clientY,
|
|
2572
|
+
pageX: e.pageX,
|
|
2573
|
+
pageY: e.pageY,
|
|
2574
|
+
ctrlKey: e.ctrlKey || e.metaKey,
|
|
2575
|
+
shiftKey: e.shiftKey,
|
|
2576
|
+
altKey: e.altKey,
|
|
2577
|
+
buttons: e.buttons,
|
|
2578
|
+
});
|
|
2579
|
+
};
|
|
2580
|
+
this.externalElements.onmouseup = function (e) {
|
|
2581
|
+
_this.onMouseUp({
|
|
2582
|
+
x: e.offsetX,
|
|
2583
|
+
y: e.offsetY,
|
|
2584
|
+
clientX: e.clientX,
|
|
2585
|
+
clientY: e.clientY,
|
|
2586
|
+
pageX: e.pageX,
|
|
2587
|
+
pageY: e.pageY,
|
|
2588
|
+
ctrlKey: e.ctrlKey || e.metaKey,
|
|
2589
|
+
shiftKey: e.shiftKey,
|
|
2590
|
+
altKey: e.altKey,
|
|
2591
|
+
buttons: e.buttons,
|
|
2592
|
+
button: e.button,
|
|
2593
|
+
});
|
|
2594
|
+
};
|
|
2595
|
+
this.externalElements.onmouseleave = function (e) {
|
|
2596
|
+
if (e.toElement !== _this.tooltip.box) {
|
|
2597
|
+
_this.tooltip.hide();
|
|
2598
|
+
_this.store.lastHover = undefined;
|
|
2599
|
+
}
|
|
2600
|
+
};
|
|
2624
2601
|
this.externalElements.ondblclick = this.ondblclick;
|
|
2625
2602
|
this.externalElements.tabIndex = 0;
|
|
2626
2603
|
this.externalElements.onblur = function () {
|
|
@@ -2757,10 +2734,10 @@ var Canvas = /** @class */ (function () {
|
|
|
2757
2734
|
};
|
|
2758
2735
|
Canvas.prototype.dropPens = function (pens, e) {
|
|
2759
2736
|
return __awaiter(this, void 0, void 0, function () {
|
|
2760
|
-
var pens_2, pens_2_1, pen, pens_3, pens_3_1, pen, pens_4, pens_4_1, pen;
|
|
2761
|
-
var e_8, _a, e_9, _b, e_10, _c;
|
|
2762
|
-
return __generator(this, function (
|
|
2763
|
-
switch (
|
|
2737
|
+
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;
|
|
2738
|
+
var e_8, _a, e_9, _b, e_10, _c, e_11, _d;
|
|
2739
|
+
return __generator(this, function (_e) {
|
|
2740
|
+
switch (_e.label) {
|
|
2764
2741
|
case 0:
|
|
2765
2742
|
try {
|
|
2766
2743
|
for (pens_2 = __values(pens), pens_2_1 = pens_2.next(); !pens_2_1.done; pens_2_1 = pens_2.next()) {
|
|
@@ -2817,9 +2794,48 @@ var Canvas = /** @class */ (function () {
|
|
|
2817
2794
|
}
|
|
2818
2795
|
finally { if (e_10) throw e_10.error; }
|
|
2819
2796
|
}
|
|
2797
|
+
width = this.store.data.width || this.store.options.width;
|
|
2798
|
+
height = this.store.data.height || this.store.options.height;
|
|
2799
|
+
if (width && height) {
|
|
2800
|
+
rect_1 = {
|
|
2801
|
+
x: this.store.data.origin.x,
|
|
2802
|
+
y: this.store.data.origin.y,
|
|
2803
|
+
width: width * this.store.data.scale,
|
|
2804
|
+
height: height * this.store.data.scale,
|
|
2805
|
+
};
|
|
2806
|
+
flag = true;
|
|
2807
|
+
try {
|
|
2808
|
+
for (pens_5 = __values(pens), pens_5_1 = pens_5.next(); !pens_5_1.done; pens_5_1 = pens_5.next()) {
|
|
2809
|
+
pen = pens_5_1.value;
|
|
2810
|
+
if (!pen.parentId) {
|
|
2811
|
+
points = [
|
|
2812
|
+
{ x: pen.x, y: pen.y },
|
|
2813
|
+
{ x: pen.x + pen.width, y: pen.y },
|
|
2814
|
+
{ x: pen.x, y: pen.y + pen.height },
|
|
2815
|
+
{ x: pen.x + pen.width, y: pen.y + pen.height },
|
|
2816
|
+
];
|
|
2817
|
+
if (points.some(function (point) { return pointInRect(point, rect_1); })) {
|
|
2818
|
+
flag = false;
|
|
2819
|
+
break;
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
}
|
|
2824
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
2825
|
+
finally {
|
|
2826
|
+
try {
|
|
2827
|
+
if (pens_5_1 && !pens_5_1.done && (_d = pens_5.return)) _d.call(pens_5);
|
|
2828
|
+
}
|
|
2829
|
+
finally { if (e_11) throw e_11.error; }
|
|
2830
|
+
}
|
|
2831
|
+
if (flag) {
|
|
2832
|
+
console.info('画笔在大屏范围外');
|
|
2833
|
+
return [2 /*return*/];
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2820
2836
|
return [4 /*yield*/, this.addPens(pens, true)];
|
|
2821
2837
|
case 1:
|
|
2822
|
-
|
|
2838
|
+
_e.sent();
|
|
2823
2839
|
this.active(pens.filter(function (pen) { return !pen.parentId; }));
|
|
2824
2840
|
this.render();
|
|
2825
2841
|
this.externalElements.focus(); // 聚焦
|
|
@@ -2829,7 +2845,7 @@ var Canvas = /** @class */ (function () {
|
|
|
2829
2845
|
});
|
|
2830
2846
|
};
|
|
2831
2847
|
Canvas.prototype.randomCombineId = function (pen, pens, parentId) {
|
|
2832
|
-
var
|
|
2848
|
+
var e_12, _a;
|
|
2833
2849
|
randomId(pen);
|
|
2834
2850
|
pen.parentId = parentId;
|
|
2835
2851
|
var newChildren = [];
|
|
@@ -2846,12 +2862,12 @@ var Canvas = /** @class */ (function () {
|
|
|
2846
2862
|
_loop_4(childId);
|
|
2847
2863
|
}
|
|
2848
2864
|
}
|
|
2849
|
-
catch (
|
|
2865
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
2850
2866
|
finally {
|
|
2851
2867
|
try {
|
|
2852
2868
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2853
2869
|
}
|
|
2854
|
-
finally { if (
|
|
2870
|
+
finally { if (e_12) throw e_12.error; }
|
|
2855
2871
|
}
|
|
2856
2872
|
}
|
|
2857
2873
|
pen.children = newChildren;
|
|
@@ -2859,8 +2875,8 @@ var Canvas = /** @class */ (function () {
|
|
|
2859
2875
|
};
|
|
2860
2876
|
Canvas.prototype.addPens = function (pens, history) {
|
|
2861
2877
|
return __awaiter(this, void 0, void 0, function () {
|
|
2862
|
-
var _a, list,
|
|
2863
|
-
var
|
|
2878
|
+
var _a, list, pens_6, pens_6_1, pen;
|
|
2879
|
+
var e_13, _b;
|
|
2864
2880
|
return __generator(this, function (_c) {
|
|
2865
2881
|
switch (_c.label) {
|
|
2866
2882
|
case 0:
|
|
@@ -2876,8 +2892,8 @@ var Canvas = /** @class */ (function () {
|
|
|
2876
2892
|
}
|
|
2877
2893
|
list = [];
|
|
2878
2894
|
try {
|
|
2879
|
-
for (
|
|
2880
|
-
pen =
|
|
2895
|
+
for (pens_6 = __values(pens), pens_6_1 = pens_6.next(); !pens_6_1.done; pens_6_1 = pens_6.next()) {
|
|
2896
|
+
pen = pens_6_1.value;
|
|
2881
2897
|
if (this.beforeAddPen && this.beforeAddPen(pen) != true) {
|
|
2882
2898
|
continue;
|
|
2883
2899
|
}
|
|
@@ -2885,12 +2901,12 @@ var Canvas = /** @class */ (function () {
|
|
|
2885
2901
|
list.push(pen);
|
|
2886
2902
|
}
|
|
2887
2903
|
}
|
|
2888
|
-
catch (
|
|
2904
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
2889
2905
|
finally {
|
|
2890
2906
|
try {
|
|
2891
|
-
if (
|
|
2907
|
+
if (pens_6_1 && !pens_6_1.done && (_b = pens_6.return)) _b.call(pens_6);
|
|
2892
2908
|
}
|
|
2893
|
-
finally { if (
|
|
2909
|
+
finally { if (e_13) throw e_13.error; }
|
|
2894
2910
|
}
|
|
2895
2911
|
this.render();
|
|
2896
2912
|
this.store.emitter.emit('add', list);
|
|
@@ -3156,7 +3172,7 @@ var Canvas = /** @class */ (function () {
|
|
|
3156
3172
|
this.patchFlags = true;
|
|
3157
3173
|
};
|
|
3158
3174
|
Canvas.prototype.active = function (pens, emit) {
|
|
3159
|
-
var
|
|
3175
|
+
var e_14, _a, _b;
|
|
3160
3176
|
if (emit === void 0) { emit = true; }
|
|
3161
3177
|
if (this.store.active) {
|
|
3162
3178
|
try {
|
|
@@ -3166,12 +3182,12 @@ var Canvas = /** @class */ (function () {
|
|
|
3166
3182
|
setChildrenActive(pen, false);
|
|
3167
3183
|
}
|
|
3168
3184
|
}
|
|
3169
|
-
catch (
|
|
3185
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
3170
3186
|
finally {
|
|
3171
3187
|
try {
|
|
3172
3188
|
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
3173
3189
|
}
|
|
3174
|
-
finally { if (
|
|
3190
|
+
finally { if (e_14) throw e_14.error; }
|
|
3175
3191
|
}
|
|
3176
3192
|
}
|
|
3177
3193
|
this.store.active = [];
|
|
@@ -3310,18 +3326,6 @@ var Canvas = /** @class */ (function () {
|
|
|
3310
3326
|
}
|
|
3311
3327
|
this.store.hoverAnchor = anchor;
|
|
3312
3328
|
this.store.hover = pen;
|
|
3313
|
-
// if (pen.name === 'line' && anchor.connectTo) {
|
|
3314
|
-
// const connectPen = this.findOne(anchor.connectTo);
|
|
3315
|
-
// if (!connectPen.calculative.active) {
|
|
3316
|
-
// this.store.hover = connectPen;
|
|
3317
|
-
// const connectAnchor = connectPen.calculative.worldAnchors.find(
|
|
3318
|
-
// (item) => item.id === anchor.anchorId
|
|
3319
|
-
// );
|
|
3320
|
-
// this.store.hoverAnchor = connectAnchor;
|
|
3321
|
-
// console.log('hover', connectAnchor);
|
|
3322
|
-
// }
|
|
3323
|
-
// }
|
|
3324
|
-
// console.log('hover', pen, anchor);
|
|
3325
3329
|
if (pen.type) {
|
|
3326
3330
|
if (anchor.connectTo && !pen.calculative.active) {
|
|
3327
3331
|
this.store.hover = this.store.pens[anchor.connectTo];
|
|
@@ -3369,7 +3373,7 @@ var Canvas = /** @class */ (function () {
|
|
|
3369
3373
|
return HoverType.None;
|
|
3370
3374
|
};
|
|
3371
3375
|
Canvas.prototype.resize = function (w, h) {
|
|
3372
|
-
var
|
|
3376
|
+
var e_15, _a;
|
|
3373
3377
|
w = w || this.parentElement.clientWidth;
|
|
3374
3378
|
h = h || this.parentElement.clientHeight;
|
|
3375
3379
|
this.width = w;
|
|
@@ -3410,12 +3414,12 @@ var Canvas = /** @class */ (function () {
|
|
|
3410
3414
|
calcInView(pen);
|
|
3411
3415
|
}
|
|
3412
3416
|
}
|
|
3413
|
-
catch (
|
|
3417
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
3414
3418
|
finally {
|
|
3415
3419
|
try {
|
|
3416
3420
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3417
3421
|
}
|
|
3418
|
-
finally { if (
|
|
3422
|
+
finally { if (e_15) throw e_15.error; }
|
|
3419
3423
|
}
|
|
3420
3424
|
};
|
|
3421
3425
|
Canvas.prototype.clearCanvas = function () {
|
|
@@ -3480,7 +3484,7 @@ var Canvas = /** @class */ (function () {
|
|
|
3480
3484
|
this.store.histories.splice(this.store.historyIndex + 1, this.store.histories.length - this.store.historyIndex - 1);
|
|
3481
3485
|
}
|
|
3482
3486
|
(_a = action.pens) === null || _a === void 0 ? void 0 : _a.forEach(function (pen) {
|
|
3483
|
-
var
|
|
3487
|
+
var e_16, _a;
|
|
3484
3488
|
var found;
|
|
3485
3489
|
if (action.initPens) {
|
|
3486
3490
|
try {
|
|
@@ -3491,12 +3495,12 @@ var Canvas = /** @class */ (function () {
|
|
|
3491
3495
|
}
|
|
3492
3496
|
}
|
|
3493
3497
|
}
|
|
3494
|
-
catch (
|
|
3498
|
+
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
3495
3499
|
finally {
|
|
3496
3500
|
try {
|
|
3497
3501
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3498
3502
|
}
|
|
3499
|
-
finally { if (
|
|
3503
|
+
finally { if (e_16) throw e_16.error; }
|
|
3500
3504
|
}
|
|
3501
3505
|
}
|
|
3502
3506
|
if (found) {
|
|
@@ -3554,11 +3558,11 @@ var Canvas = /** @class */ (function () {
|
|
|
3554
3558
|
var _this = this;
|
|
3555
3559
|
var before = this.store.histories[this.store.historyIndex];
|
|
3556
3560
|
if (before && before.type === EditType.Add) {
|
|
3557
|
-
var
|
|
3561
|
+
var pens_7 = [];
|
|
3558
3562
|
before.pens.forEach(function (pen) {
|
|
3559
|
-
|
|
3563
|
+
pens_7.push(_this.store.pens[pen.id]);
|
|
3560
3564
|
});
|
|
3561
|
-
this.active(
|
|
3565
|
+
this.active(pens_7);
|
|
3562
3566
|
}
|
|
3563
3567
|
};
|
|
3564
3568
|
Canvas.prototype.doEditAction = function (action, undo) {
|
|
@@ -3951,7 +3955,10 @@ var Canvas = /** @class */ (function () {
|
|
|
3951
3955
|
}
|
|
3952
3956
|
else {
|
|
3953
3957
|
var img_1 = new Image();
|
|
3954
|
-
img_1.crossOrigin =
|
|
3958
|
+
img_1.crossOrigin =
|
|
3959
|
+
pen.crossOrigin === 'undefined'
|
|
3960
|
+
? undefined
|
|
3961
|
+
: pen.crossOrigin || 'anonymous';
|
|
3955
3962
|
img_1.src = pen.image;
|
|
3956
3963
|
if (this.store.options.cdn &&
|
|
3957
3964
|
!(pen.image.startsWith('http') ||
|
|
@@ -3960,6 +3967,7 @@ var Canvas = /** @class */ (function () {
|
|
|
3960
3967
|
img_1.src = this.store.options.cdn + pen.image;
|
|
3961
3968
|
}
|
|
3962
3969
|
img_1.onload = function () {
|
|
3970
|
+
// TODO: 连续的加载两张图片,若后开始加载 的图片先加载完成,可能会导致展示的是 先开始加载的图片
|
|
3963
3971
|
pen.calculative.img = img_1;
|
|
3964
3972
|
pen.calculative.imgNaturalWidth =
|
|
3965
3973
|
img_1.naturalWidth || pen.iconWidth;
|
|
@@ -4117,15 +4125,18 @@ var Canvas = /** @class */ (function () {
|
|
|
4117
4125
|
}, 50);
|
|
4118
4126
|
};
|
|
4119
4127
|
Canvas.prototype.translate = function (x, y) {
|
|
4128
|
+
var _this = this;
|
|
4120
4129
|
if (x === void 0) { x = 0; }
|
|
4121
4130
|
if (y === void 0) { y = 0; }
|
|
4122
4131
|
this.store.data.x += x * this.store.data.scale;
|
|
4123
4132
|
this.store.data.y += y * this.store.data.scale;
|
|
4124
4133
|
this.store.data.x = Math.round(this.store.data.x);
|
|
4125
4134
|
this.store.data.y = Math.round(this.store.data.y);
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4135
|
+
setTimeout(function () {
|
|
4136
|
+
_this.canvasImage.init();
|
|
4137
|
+
_this.canvasImageBottom.init();
|
|
4138
|
+
_this.render();
|
|
4139
|
+
});
|
|
4129
4140
|
this.store.emitter.emit('translate', {
|
|
4130
4141
|
x: this.store.data.x,
|
|
4131
4142
|
y: this.store.data.y,
|
|
@@ -4137,7 +4148,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4137
4148
|
this.onMovePens();
|
|
4138
4149
|
};
|
|
4139
4150
|
Canvas.prototype.onMovePens = function () {
|
|
4140
|
-
var
|
|
4151
|
+
var e_17, _a;
|
|
4141
4152
|
var _b;
|
|
4142
4153
|
var map = this.parent.map;
|
|
4143
4154
|
if (map && map.isShow) {
|
|
@@ -4162,12 +4173,12 @@ var Canvas = /** @class */ (function () {
|
|
|
4162
4173
|
}
|
|
4163
4174
|
}
|
|
4164
4175
|
}
|
|
4165
|
-
catch (
|
|
4176
|
+
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
4166
4177
|
finally {
|
|
4167
4178
|
try {
|
|
4168
4179
|
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
4169
4180
|
}
|
|
4170
|
-
finally { if (
|
|
4181
|
+
finally { if (e_17) throw e_17.error; }
|
|
4171
4182
|
}
|
|
4172
4183
|
};
|
|
4173
4184
|
/**
|
|
@@ -4215,17 +4226,19 @@ var Canvas = /** @class */ (function () {
|
|
|
4215
4226
|
_this.execPenResize(pen);
|
|
4216
4227
|
});
|
|
4217
4228
|
this.calcActiveRect();
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
map.
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4229
|
+
setTimeout(function () {
|
|
4230
|
+
_this.canvasImage.init();
|
|
4231
|
+
_this.canvasImageBottom.init();
|
|
4232
|
+
var map = _this.parent.map;
|
|
4233
|
+
if (map && map.isShow) {
|
|
4234
|
+
map.setView();
|
|
4235
|
+
}
|
|
4236
|
+
_this.render();
|
|
4237
|
+
_this.store.emitter.emit('scale', _this.store.data.scale);
|
|
4238
|
+
});
|
|
4226
4239
|
};
|
|
4227
4240
|
Canvas.prototype.rotatePens = function (e) {
|
|
4228
|
-
var
|
|
4241
|
+
var e_18, _a;
|
|
4229
4242
|
var _this = this;
|
|
4230
4243
|
if (!this.initPens) {
|
|
4231
4244
|
this.initPens = deepClone(this.getAllByPens(this.store.active));
|
|
@@ -4252,12 +4265,12 @@ var Canvas = /** @class */ (function () {
|
|
|
4252
4265
|
this.updateLines(pen);
|
|
4253
4266
|
}
|
|
4254
4267
|
}
|
|
4255
|
-
catch (
|
|
4268
|
+
catch (e_18_1) { e_18 = { error: e_18_1 }; }
|
|
4256
4269
|
finally {
|
|
4257
4270
|
try {
|
|
4258
4271
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
4259
4272
|
}
|
|
4260
|
-
finally { if (
|
|
4273
|
+
finally { if (e_18) throw e_18.error; }
|
|
4261
4274
|
}
|
|
4262
4275
|
this.lastRotate = this.activeRect.rotate;
|
|
4263
4276
|
this.getSizeCPs();
|
|
@@ -4478,7 +4491,9 @@ var Canvas = /** @class */ (function () {
|
|
|
4478
4491
|
// 线宽为 0 ,看不到外边框,拖动过程中给个外边框
|
|
4479
4492
|
pen.lineWidth === 0 && (value.lineWidth = 1);
|
|
4480
4493
|
// TODO: 例如 pen.name = 'triangle' 的情况,但有图片,是否还需要变成矩形呢?
|
|
4481
|
-
if (isDomShapes.includes(pen.name) ||
|
|
4494
|
+
if (isDomShapes.includes(pen.name) ||
|
|
4495
|
+
_this.store.options.domShapes.includes(pen.name) ||
|
|
4496
|
+
pen.image) {
|
|
4482
4497
|
// 修改名称会执行 onDestroy ,清空它
|
|
4483
4498
|
value.name = 'rectangle';
|
|
4484
4499
|
value.onDestroy = undefined;
|
|
@@ -5119,7 +5134,7 @@ var Canvas = /** @class */ (function () {
|
|
|
5119
5134
|
return;
|
|
5120
5135
|
}
|
|
5121
5136
|
requestAnimationFrame(function () {
|
|
5122
|
-
var
|
|
5137
|
+
var e_19, _a;
|
|
5123
5138
|
var now = Date.now();
|
|
5124
5139
|
if (now - _this.lastAnimateRender < _this.store.options.animateInterval) {
|
|
5125
5140
|
if (_this.store.animates.size > 0) {
|
|
@@ -5204,12 +5219,12 @@ var Canvas = /** @class */ (function () {
|
|
|
5204
5219
|
_loop_5(pen);
|
|
5205
5220
|
}
|
|
5206
5221
|
}
|
|
5207
|
-
catch (
|
|
5222
|
+
catch (e_19_1) { e_19 = { error: e_19_1 }; }
|
|
5208
5223
|
finally {
|
|
5209
5224
|
try {
|
|
5210
5225
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
5211
5226
|
}
|
|
5212
|
-
finally { if (
|
|
5227
|
+
finally { if (e_19) throw e_19.error; }
|
|
5213
5228
|
}
|
|
5214
5229
|
if (active) {
|
|
5215
5230
|
_this.calcActiveRect();
|
|
@@ -5292,7 +5307,7 @@ var Canvas = /** @class */ (function () {
|
|
|
5292
5307
|
var _a;
|
|
5293
5308
|
return __awaiter(this, void 0, void 0, function () {
|
|
5294
5309
|
var clipboardText, clipboard, _b, _c, offset, pos, curPage, rootPens, rootPens_1, rootPens_1_1, pen;
|
|
5295
|
-
var
|
|
5310
|
+
var e_20, _d;
|
|
5296
5311
|
return __generator(this, function (_e) {
|
|
5297
5312
|
switch (_e.label) {
|
|
5298
5313
|
case 0:
|
|
@@ -5361,12 +5376,12 @@ var Canvas = /** @class */ (function () {
|
|
|
5361
5376
|
this.pastePen(pen, undefined);
|
|
5362
5377
|
}
|
|
5363
5378
|
}
|
|
5364
|
-
catch (
|
|
5379
|
+
catch (e_20_1) { e_20 = { error: e_20_1 }; }
|
|
5365
5380
|
finally {
|
|
5366
5381
|
try {
|
|
5367
5382
|
if (rootPens_1_1 && !rootPens_1_1.done && (_d = rootPens_1.return)) _d.call(rootPens_1);
|
|
5368
5383
|
}
|
|
5369
|
-
finally { if (
|
|
5384
|
+
finally { if (e_20) throw e_20.error; }
|
|
5370
5385
|
}
|
|
5371
5386
|
sessionStorage.setItem('page', clipboard.page);
|
|
5372
5387
|
this.active(rootPens);
|
|
@@ -5383,20 +5398,20 @@ var Canvas = /** @class */ (function () {
|
|
|
5383
5398
|
* @param pens 不包含子节点
|
|
5384
5399
|
*/
|
|
5385
5400
|
Canvas.prototype.getAllByPens = function (pens) {
|
|
5386
|
-
var
|
|
5401
|
+
var e_21, _a;
|
|
5387
5402
|
var retPens = [];
|
|
5388
5403
|
try {
|
|
5389
|
-
for (var
|
|
5390
|
-
var pen =
|
|
5404
|
+
for (var pens_8 = __values(pens), pens_8_1 = pens_8.next(); !pens_8_1.done; pens_8_1 = pens_8.next()) {
|
|
5405
|
+
var pen = pens_8_1.value;
|
|
5391
5406
|
retPens.push.apply(retPens, __spreadArray([], __read(deepClone(getAllChildren(pen, this.store), true)), false));
|
|
5392
5407
|
}
|
|
5393
5408
|
}
|
|
5394
|
-
catch (
|
|
5409
|
+
catch (e_21_1) { e_21 = { error: e_21_1 }; }
|
|
5395
5410
|
finally {
|
|
5396
5411
|
try {
|
|
5397
|
-
if (
|
|
5412
|
+
if (pens_8_1 && !pens_8_1.done && (_a = pens_8.return)) _a.call(pens_8);
|
|
5398
5413
|
}
|
|
5399
|
-
finally { if (
|
|
5414
|
+
finally { if (e_21) throw e_21.error; }
|
|
5400
5415
|
}
|
|
5401
5416
|
return retPens.concat(pens);
|
|
5402
5417
|
};
|
|
@@ -5439,7 +5454,7 @@ var Canvas = /** @class */ (function () {
|
|
|
5439
5454
|
* @param pastePens 此处复制的全部 pens (包含子节点)
|
|
5440
5455
|
*/
|
|
5441
5456
|
Canvas.prototype.changeNodeConnectedLine = function (oldId, line, pastePens) {
|
|
5442
|
-
var
|
|
5457
|
+
var e_22, _a;
|
|
5443
5458
|
var _b;
|
|
5444
5459
|
var from = line.anchors[0];
|
|
5445
5460
|
var to = line.anchors[line.anchors.length - 1];
|
|
@@ -5475,12 +5490,12 @@ var Canvas = /** @class */ (function () {
|
|
|
5475
5490
|
_loop_7(anchor);
|
|
5476
5491
|
}
|
|
5477
5492
|
}
|
|
5478
|
-
catch (
|
|
5493
|
+
catch (e_22_1) { e_22 = { error: e_22_1 }; }
|
|
5479
5494
|
finally {
|
|
5480
5495
|
try {
|
|
5481
5496
|
if (anchors_1_1 && !anchors_1_1.done && (_a = anchors_1.return)) _a.call(anchors_1);
|
|
5482
5497
|
}
|
|
5483
|
-
finally { if (
|
|
5498
|
+
finally { if (e_22) throw e_22.error; }
|
|
5484
5499
|
}
|
|
5485
5500
|
};
|
|
5486
5501
|
Canvas.prototype.delete = function (pens, canDelLocked, history) {
|
|
@@ -5862,6 +5877,10 @@ var Canvas = /** @class */ (function () {
|
|
|
5862
5877
|
if (k === 'image') {
|
|
5863
5878
|
willRenderImage = true;
|
|
5864
5879
|
}
|
|
5880
|
+
if (k.indexOf('.') !== -1) {
|
|
5881
|
+
delete pen[k];
|
|
5882
|
+
setter(pen, k, data[k]);
|
|
5883
|
+
}
|
|
5865
5884
|
}
|
|
5866
5885
|
this.setCalculativeByScale(pen); // 该方法计算量并不大,所以每次修改都计算一次
|
|
5867
5886
|
if (isChangedName) {
|
|
@@ -5990,7 +6009,7 @@ var Canvas = /** @class */ (function () {
|
|
|
5990
6009
|
};
|
|
5991
6010
|
};
|
|
5992
6011
|
Canvas.prototype.toPng = function (padding, callback, containBkImg) {
|
|
5993
|
-
var
|
|
6012
|
+
var e_23, _a;
|
|
5994
6013
|
if (padding === void 0) { padding = 2; }
|
|
5995
6014
|
if (containBkImg === void 0) { containBkImg = false; }
|
|
5996
6015
|
var rect = getRect(this.store.data.pens);
|
|
@@ -6078,12 +6097,12 @@ var Canvas = /** @class */ (function () {
|
|
|
6078
6097
|
pen.calculative.active = active;
|
|
6079
6098
|
}
|
|
6080
6099
|
}
|
|
6081
|
-
catch (
|
|
6100
|
+
catch (e_23_1) { e_23 = { error: e_23_1 }; }
|
|
6082
6101
|
finally {
|
|
6083
6102
|
try {
|
|
6084
6103
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
6085
6104
|
}
|
|
6086
|
-
finally { if (
|
|
6105
|
+
finally { if (e_23) throw e_23.error; }
|
|
6087
6106
|
}
|
|
6088
6107
|
if (callback) {
|
|
6089
6108
|
canvas.toBlob(callback);
|
|
@@ -6215,24 +6234,21 @@ var Canvas = /** @class */ (function () {
|
|
|
6215
6234
|
this.render();
|
|
6216
6235
|
};
|
|
6217
6236
|
Canvas.prototype.destroy = function () {
|
|
6218
|
-
var _a;
|
|
6237
|
+
var _a, _b;
|
|
6219
6238
|
this.scroll && this.scroll.destroy();
|
|
6220
6239
|
(_a = this.tooltip) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
6240
|
+
(_b = this.dialog) === null || _b === void 0 ? void 0 : _b.destroy();
|
|
6221
6241
|
// ios
|
|
6222
6242
|
this.externalElements.removeEventListener('gesturestart', this.onGesturestart);
|
|
6223
6243
|
this.externalElements.ondragover = function (e) { return e.preventDefault(); };
|
|
6224
6244
|
this.externalElements.ondrop = undefined;
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
this.externalElements.onmousemove = undefined;
|
|
6233
|
-
this.externalElements.onmouseup = undefined;
|
|
6234
|
-
this.externalElements.onmouseleave = undefined;
|
|
6235
|
-
}
|
|
6245
|
+
this.externalElements.ontouchstart = undefined;
|
|
6246
|
+
this.externalElements.ontouchmove = undefined;
|
|
6247
|
+
this.externalElements.ontouchend = undefined;
|
|
6248
|
+
this.externalElements.onmousedown = undefined;
|
|
6249
|
+
this.externalElements.onmousemove = undefined;
|
|
6250
|
+
this.externalElements.onmouseup = undefined;
|
|
6251
|
+
this.externalElements.onmouseleave = undefined;
|
|
6236
6252
|
this.externalElements.ondblclick = undefined;
|
|
6237
6253
|
switch (this.store.options.keydown) {
|
|
6238
6254
|
case KeydownType.Document:
|