@meta2d/core 1.0.18 → 1.0.20
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 +101 -35
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +3 -0
- package/src/core.js +211 -113
- package/src/core.js.map +1 -1
- package/src/diagrams/gif.js +4 -2
- package/src/diagrams/gif.js.map +1 -1
- package/src/event/event.d.ts +1 -1
- package/src/options.d.ts +3 -0
- package/src/options.js +2 -0
- package/src/options.js.map +1 -1
- package/src/pen/model.d.ts +5 -0
- package/src/pen/model.js +6 -1
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.d.ts +1 -1
- package/src/pen/render.js +116 -18
- package/src/pen/render.js.map +1 -1
- package/src/point/point.d.ts +2 -0
- package/src/point/point.js.map +1 -1
- package/src/store/store.d.ts +8 -0
- package/src/store/store.js +3 -0
- package/src/store/store.js.map +1 -1
- package/src/title/index.d.ts +1 -0
- package/src/title/index.js +2 -0
- package/src/title/index.js.map +1 -0
- package/src/title/title.d.ts +29 -0
- package/src/title/title.js +95 -0
- package/src/title/title.js.map +1 -0
package/package.json
CHANGED
package/src/canvas/canvas.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { CanvasImage } from './canvasImage';
|
|
|
12
12
|
import { MagnifierCanvas } from './magnifierCanvas';
|
|
13
13
|
import { Meta2d } from '../core';
|
|
14
14
|
import { Dialog } from '../dialog';
|
|
15
|
+
import { Title } from '../title';
|
|
15
16
|
export declare const movingSuffix: "-moving";
|
|
16
17
|
export declare class Canvas {
|
|
17
18
|
parent: Meta2d;
|
|
@@ -77,6 +78,7 @@ export declare class Canvas {
|
|
|
77
78
|
pasteOffset: number;
|
|
78
79
|
opening: boolean;
|
|
79
80
|
maxZindex: number;
|
|
81
|
+
canMoveLine: boolean;
|
|
80
82
|
/**
|
|
81
83
|
* @deprecated 改用 beforeAddPens
|
|
82
84
|
*/
|
|
@@ -98,6 +100,7 @@ export declare class Canvas {
|
|
|
98
100
|
inputRight: HTMLDivElement;
|
|
99
101
|
dropdown: HTMLUListElement;
|
|
100
102
|
tooltip: Tooltip;
|
|
103
|
+
title: Title;
|
|
101
104
|
mousePos: Point;
|
|
102
105
|
scroll: Scroll;
|
|
103
106
|
movingAnchor: Point;
|
package/src/canvas/canvas.js
CHANGED
|
@@ -98,6 +98,7 @@ import { MagnifierCanvas } from './magnifierCanvas';
|
|
|
98
98
|
import { lockedError } from '../utils/error';
|
|
99
99
|
import { Dialog } from '../dialog';
|
|
100
100
|
import { setter } from '../utils/object';
|
|
101
|
+
import { Title } from '../title';
|
|
101
102
|
export var movingSuffix = '-moving';
|
|
102
103
|
var Canvas = /** @class */ (function () {
|
|
103
104
|
function Canvas(parent, parentElement, store) {
|
|
@@ -126,6 +127,7 @@ var Canvas = /** @class */ (function () {
|
|
|
126
127
|
this.pasteOffset = 10;
|
|
127
128
|
this.opening = false;
|
|
128
129
|
this.maxZindex = 4;
|
|
130
|
+
this.canMoveLine = false; //moveConnectedLine=false
|
|
129
131
|
this.inputParent = document.createElement('div');
|
|
130
132
|
// input = document.createElement('textarea');
|
|
131
133
|
this.inputDiv = document.createElement('div');
|
|
@@ -244,6 +246,10 @@ var Canvas = /** @class */ (function () {
|
|
|
244
246
|
}
|
|
245
247
|
e.preventDefault();
|
|
246
248
|
e.stopPropagation();
|
|
249
|
+
//移动画笔过程中不允许缩放
|
|
250
|
+
if (_this.mouseDown &&
|
|
251
|
+
(_this.hoverType === HoverType.Node || _this.hoverType === HoverType.Line))
|
|
252
|
+
return;
|
|
247
253
|
if (_this.store.data.locked === LockState.Disable)
|
|
248
254
|
return;
|
|
249
255
|
if (_this.store.data.locked === LockState.DisableScale)
|
|
@@ -287,6 +293,14 @@ var Canvas = /** @class */ (function () {
|
|
|
287
293
|
};
|
|
288
294
|
this.onkeydown = function (e) {
|
|
289
295
|
var _a, _b, _c;
|
|
296
|
+
if (_this.store.data.locked >= LockState.DisableEdit &&
|
|
297
|
+
e.target.tagName !== 'INPUT' &&
|
|
298
|
+
e.target.tagName !== 'TEXTAREA') {
|
|
299
|
+
_this.store.active.forEach(function (pen) {
|
|
300
|
+
var _a;
|
|
301
|
+
(_a = pen.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(pen, pen, e.key);
|
|
302
|
+
});
|
|
303
|
+
}
|
|
290
304
|
if (_this.store.data.locked >= LockState.DisableEdit ||
|
|
291
305
|
e.target.tagName === 'INPUT' ||
|
|
292
306
|
e.target.tagName === 'TEXTAREA') {
|
|
@@ -560,17 +574,25 @@ var Canvas = /** @class */ (function () {
|
|
|
560
574
|
e.stopPropagation();
|
|
561
575
|
}
|
|
562
576
|
break;
|
|
577
|
+
case 'l':
|
|
578
|
+
case 'L':
|
|
579
|
+
_this.canMoveLine = true;
|
|
580
|
+
break;
|
|
563
581
|
}
|
|
564
582
|
_this.render(false);
|
|
565
583
|
};
|
|
566
584
|
this.onkeyup = function (e) {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
585
|
+
switch (e.key) {
|
|
586
|
+
case 'l':
|
|
587
|
+
case 'L':
|
|
588
|
+
_this.canMoveLine = false;
|
|
589
|
+
break;
|
|
590
|
+
// case 'Alt':
|
|
591
|
+
// if (this.drawingLine) {
|
|
592
|
+
// this.store.options.autoAnchor = !this.store.options.autoAnchor;
|
|
593
|
+
// }
|
|
594
|
+
// break;
|
|
595
|
+
}
|
|
574
596
|
if (_this.hotkeyType) {
|
|
575
597
|
_this.render();
|
|
576
598
|
}
|
|
@@ -579,7 +601,7 @@ var Canvas = /** @class */ (function () {
|
|
|
579
601
|
}
|
|
580
602
|
};
|
|
581
603
|
this.ondrop = function (event) { return __awaiter(_this, void 0, void 0, function () {
|
|
582
|
-
var json, obj, files, isGif, pt
|
|
604
|
+
var json, obj, files, isGif, pt;
|
|
583
605
|
return __generator(this, function (_a) {
|
|
584
606
|
switch (_a.label) {
|
|
585
607
|
case 0:
|
|
@@ -593,32 +615,38 @@ var Canvas = /** @class */ (function () {
|
|
|
593
615
|
json = event.dataTransfer.getData('Meta2d') ||
|
|
594
616
|
event.dataTransfer.getData('Text');
|
|
595
617
|
obj = null;
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
618
|
+
try {
|
|
619
|
+
if (json) {
|
|
620
|
+
obj = JSON.parse(json);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
catch (e) { }
|
|
624
|
+
if (!!obj) return [3 /*break*/, 3];
|
|
603
625
|
files = event.dataTransfer.files;
|
|
604
|
-
if (!(files.length && files[0].type.match('image.*'))) return [3 /*break*/,
|
|
626
|
+
if (!(files.length && files[0].type.match('image.*'))) return [3 /*break*/, 2];
|
|
605
627
|
isGif = files[0].type === 'image/gif';
|
|
606
628
|
return [4 /*yield*/, this.fileToPen(files[0], isGif)];
|
|
607
|
-
case
|
|
629
|
+
case 1:
|
|
608
630
|
obj = _a.sent();
|
|
609
|
-
|
|
610
|
-
case
|
|
631
|
+
return [3 /*break*/, 3];
|
|
632
|
+
case 2:
|
|
633
|
+
if (this.addCaches.length) {
|
|
634
|
+
obj = this.addCaches;
|
|
635
|
+
this.addCaches = [];
|
|
636
|
+
}
|
|
637
|
+
else {
|
|
638
|
+
this.store.emitter.emit('drop', undefined);
|
|
639
|
+
return [2 /*return*/];
|
|
640
|
+
}
|
|
641
|
+
_a.label = 3;
|
|
642
|
+
case 3:
|
|
611
643
|
if (obj && obj.draggable !== false) {
|
|
612
644
|
obj = Array.isArray(obj) ? obj : [obj];
|
|
613
645
|
pt = { x: event.offsetX, y: event.offsetY };
|
|
614
646
|
this.calibrateMouse(pt);
|
|
615
647
|
this.dropPens(obj, pt);
|
|
648
|
+
this.addCaches = [];
|
|
616
649
|
}
|
|
617
|
-
return [3 /*break*/, 6];
|
|
618
|
-
case 5:
|
|
619
|
-
e_1 = _a.sent();
|
|
620
|
-
return [3 /*break*/, 6];
|
|
621
|
-
case 6:
|
|
622
650
|
this.store.emitter.emit('drop', obj || json);
|
|
623
651
|
return [2 /*return*/];
|
|
624
652
|
}
|
|
@@ -1591,7 +1619,7 @@ var Canvas = /** @class */ (function () {
|
|
|
1591
1619
|
this.inPens = function (pt, pens) {
|
|
1592
1620
|
var hoverType = HoverType.None;
|
|
1593
1621
|
var _loop_2 = function (i) {
|
|
1594
|
-
var
|
|
1622
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
1595
1623
|
var pen = pens[i];
|
|
1596
1624
|
if (pen.visible == false ||
|
|
1597
1625
|
pen.calculative.inView == false ||
|
|
@@ -1604,12 +1632,36 @@ var Canvas = /** @class */ (function () {
|
|
|
1604
1632
|
!pointInRect(pt, pen.calculative.worldRect)) {
|
|
1605
1633
|
return "continue";
|
|
1606
1634
|
}
|
|
1635
|
+
//anchor title
|
|
1636
|
+
if (_this.store.data.locked) {
|
|
1637
|
+
// locked>0
|
|
1638
|
+
if (pen.calculative.worldAnchors) {
|
|
1639
|
+
try {
|
|
1640
|
+
for (var _d = (e_1 = void 0, __values(pen.calculative.worldAnchors)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1641
|
+
var anchor = _e.value;
|
|
1642
|
+
if (hitPoint(pt, anchor, _this.pointSize)) {
|
|
1643
|
+
_this.title.show(anchor);
|
|
1644
|
+
if (anchor.title) {
|
|
1645
|
+
return "break-outer";
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1651
|
+
finally {
|
|
1652
|
+
try {
|
|
1653
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
1654
|
+
}
|
|
1655
|
+
finally { if (e_1) throw e_1.error; }
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1607
1659
|
// 锚点
|
|
1608
1660
|
if (!_this.store.data.locked && _this.hotkeyType !== HotkeyType.Resize) {
|
|
1609
1661
|
if (pen.calculative.worldAnchors) {
|
|
1610
1662
|
try {
|
|
1611
|
-
for (var
|
|
1612
|
-
var anchor =
|
|
1663
|
+
for (var _f = (e_2 = void 0, __values(pen.calculative.worldAnchors)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1664
|
+
var anchor = _g.value;
|
|
1613
1665
|
hoverType = _this.inAnchor(pt, pen, anchor);
|
|
1614
1666
|
if (hoverType) {
|
|
1615
1667
|
return "break-outer";
|
|
@@ -1619,7 +1671,7 @@ var Canvas = /** @class */ (function () {
|
|
|
1619
1671
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1620
1672
|
finally {
|
|
1621
1673
|
try {
|
|
1622
|
-
if (
|
|
1674
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
1623
1675
|
}
|
|
1624
1676
|
finally { if (e_2) throw e_2.error; }
|
|
1625
1677
|
}
|
|
@@ -1682,7 +1734,7 @@ var Canvas = /** @class */ (function () {
|
|
|
1682
1734
|
_this.store.pointAt = pt;
|
|
1683
1735
|
// 锚点贴边吸附
|
|
1684
1736
|
if (!pt.ctrlKey) {
|
|
1685
|
-
var
|
|
1737
|
+
var _h = _this.store.hover.calculative.worldRect, x = _h.x, y = _h.y, ex = _h.ex, ey = _h.ey, rotate_1 = _h.rotate, center_1 = _h.center;
|
|
1686
1738
|
if (rotate_1) {
|
|
1687
1739
|
var pts = [
|
|
1688
1740
|
{ x: x, y: y },
|
|
@@ -1710,7 +1762,7 @@ var Canvas = /** @class */ (function () {
|
|
|
1710
1762
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1711
1763
|
finally {
|
|
1712
1764
|
try {
|
|
1713
|
-
if (pts_1_1 && !pts_1_1.done && (
|
|
1765
|
+
if (pts_1_1 && !pts_1_1.done && (_c = pts_1.return)) _c.call(pts_1);
|
|
1714
1766
|
}
|
|
1715
1767
|
finally { if (e_3) throw e_3.error; }
|
|
1716
1768
|
}
|
|
@@ -2540,6 +2592,7 @@ var Canvas = /** @class */ (function () {
|
|
|
2540
2592
|
setHover(hover, false);
|
|
2541
2593
|
};
|
|
2542
2594
|
this.dialog = new Dialog(parentElement);
|
|
2595
|
+
this.title = new Title(parentElement);
|
|
2543
2596
|
if (this.store.options.scroll) {
|
|
2544
2597
|
this.scroll = new Scroll(this);
|
|
2545
2598
|
}
|
|
@@ -2804,6 +2857,10 @@ var Canvas = /** @class */ (function () {
|
|
|
2804
2857
|
pen.height *= this.store.data.scale;
|
|
2805
2858
|
pen.x = e.x - pen.width / 2;
|
|
2806
2859
|
pen.y = e.y - pen.height / 2;
|
|
2860
|
+
if (pen.tags && pen.tags.includes('meta3d')) {
|
|
2861
|
+
pen.x = this.store.data.origin.x;
|
|
2862
|
+
pen.y = this.store.data.origin.y;
|
|
2863
|
+
}
|
|
2807
2864
|
}
|
|
2808
2865
|
}
|
|
2809
2866
|
}
|
|
@@ -2834,7 +2891,11 @@ var Canvas = /** @class */ (function () {
|
|
|
2834
2891
|
{ x: pen.x, y: pen.y + pen.height },
|
|
2835
2892
|
{ x: pen.x + pen.width, y: pen.y + pen.height },
|
|
2836
2893
|
];
|
|
2837
|
-
if (
|
|
2894
|
+
if ((pen.x === rect_1.x &&
|
|
2895
|
+
pen.y === rect_1.y &&
|
|
2896
|
+
pen.width === rect_1.width &&
|
|
2897
|
+
pen.height === rect_1.height) ||
|
|
2898
|
+
points.some(function (point) { return pointInRect(point, rect_1); })) {
|
|
2838
2899
|
flag = false;
|
|
2839
2900
|
break;
|
|
2840
2901
|
}
|
|
@@ -3182,6 +3243,7 @@ var Canvas = /** @class */ (function () {
|
|
|
3182
3243
|
this.store.active.forEach(function (pen) {
|
|
3183
3244
|
pen.calculative.active = undefined;
|
|
3184
3245
|
pen.calculative.activeAnchor = undefined;
|
|
3246
|
+
pen.calculative.hover = false;
|
|
3185
3247
|
setChildrenActive(pen, false);
|
|
3186
3248
|
});
|
|
3187
3249
|
!drawing && this.store.emitter.emit('inactive', this.store.active);
|
|
@@ -3195,10 +3257,12 @@ var Canvas = /** @class */ (function () {
|
|
|
3195
3257
|
var e_14, _a, _b;
|
|
3196
3258
|
if (emit === void 0) { emit = true; }
|
|
3197
3259
|
if (this.store.active) {
|
|
3260
|
+
emit && this.store.emitter.emit('inactive', this.store.active);
|
|
3198
3261
|
try {
|
|
3199
3262
|
for (var _c = __values(this.store.active), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
3200
3263
|
var pen = _d.value;
|
|
3201
3264
|
pen.calculative.active = undefined;
|
|
3265
|
+
pen.calculative.hover = false;
|
|
3202
3266
|
setChildrenActive(pen, false);
|
|
3203
3267
|
}
|
|
3204
3268
|
}
|
|
@@ -3957,7 +4021,7 @@ var Canvas = /** @class */ (function () {
|
|
|
3957
4021
|
};
|
|
3958
4022
|
Canvas.prototype.loadImage = function (pen) {
|
|
3959
4023
|
var _this = this;
|
|
3960
|
-
if (pen.image !== pen.calculative.image) {
|
|
4024
|
+
if (pen.image !== pen.calculative.image || !pen.calculative.img) {
|
|
3961
4025
|
pen.calculative.img = undefined;
|
|
3962
4026
|
if (pen.image) {
|
|
3963
4027
|
if (globalStore.htmlElements[pen.image]) {
|
|
@@ -4404,6 +4468,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4404
4468
|
return;
|
|
4405
4469
|
}
|
|
4406
4470
|
if (!this.store.options.moveConnectedLine &&
|
|
4471
|
+
!this.canMoveLine &&
|
|
4407
4472
|
this.store.active.length === 1 &&
|
|
4408
4473
|
(((_a = this.store.active[0].anchors[0]) === null || _a === void 0 ? void 0 : _a.connectTo) ||
|
|
4409
4474
|
((_b = this.store.active[0].anchors[this.store.active[0].anchors.length - 1]) === null || _b === void 0 ? void 0 : _b.connectTo))) {
|
|
@@ -4487,7 +4552,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4487
4552
|
Canvas.prototype.initMovingPens = function () {
|
|
4488
4553
|
var _this = this;
|
|
4489
4554
|
var _a, _b;
|
|
4490
|
-
if (!this.store.options.moveConnectedLine) {
|
|
4555
|
+
if (!this.store.options.moveConnectedLine && !this.canMoveLine) {
|
|
4491
4556
|
for (var i = 0; i < this.store.active.length; i++) {
|
|
4492
4557
|
var pen = this.store.active[i];
|
|
4493
4558
|
if (((_a = pen.anchors[0]) === null || _a === void 0 ? void 0 : _a.connectTo) ||
|
|
@@ -4831,7 +4896,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4831
4896
|
return;
|
|
4832
4897
|
}
|
|
4833
4898
|
if (pen.type === PenType.Line) {
|
|
4834
|
-
if (!_this.store.options.moveConnectedLine) {
|
|
4899
|
+
if (!_this.store.options.moveConnectedLine && !_this.canMoveLine) {
|
|
4835
4900
|
return;
|
|
4836
4901
|
}
|
|
4837
4902
|
translateLine(pen, x, y);
|
|
@@ -6260,10 +6325,11 @@ var Canvas = /** @class */ (function () {
|
|
|
6260
6325
|
this.render();
|
|
6261
6326
|
};
|
|
6262
6327
|
Canvas.prototype.destroy = function () {
|
|
6263
|
-
var _a, _b;
|
|
6328
|
+
var _a, _b, _c;
|
|
6264
6329
|
this.scroll && this.scroll.destroy();
|
|
6265
6330
|
(_a = this.tooltip) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
6266
6331
|
(_b = this.dialog) === null || _b === void 0 ? void 0 : _b.destroy();
|
|
6332
|
+
(_c = this.title) === null || _c === void 0 ? void 0 : _c.destroy();
|
|
6267
6333
|
// ios
|
|
6268
6334
|
this.externalElements.removeEventListener('gesturestart', this.onGesturestart);
|
|
6269
6335
|
this.externalElements.ondragover = function (e) { return e.preventDefault(); };
|