@meta2d/core 1.0.18 → 1.0.19
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 +87 -33
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +2 -0
- package/src/core.js +158 -93
- package/src/core.js.map +1 -1
- package/src/event/event.d.ts +1 -1
- package/src/options.d.ts +2 -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 +108 -10
- 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 +6 -0
- package/src/store/store.js +2 -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');
|
|
@@ -287,6 +289,14 @@ var Canvas = /** @class */ (function () {
|
|
|
287
289
|
};
|
|
288
290
|
this.onkeydown = function (e) {
|
|
289
291
|
var _a, _b, _c;
|
|
292
|
+
if (_this.store.data.locked >= LockState.DisableEdit &&
|
|
293
|
+
e.target.tagName !== 'INPUT' &&
|
|
294
|
+
e.target.tagName !== 'TEXTAREA') {
|
|
295
|
+
_this.store.active.forEach(function (pen) {
|
|
296
|
+
var _a;
|
|
297
|
+
(_a = pen.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(pen, pen, e.key);
|
|
298
|
+
});
|
|
299
|
+
}
|
|
290
300
|
if (_this.store.data.locked >= LockState.DisableEdit ||
|
|
291
301
|
e.target.tagName === 'INPUT' ||
|
|
292
302
|
e.target.tagName === 'TEXTAREA') {
|
|
@@ -560,17 +570,25 @@ var Canvas = /** @class */ (function () {
|
|
|
560
570
|
e.stopPropagation();
|
|
561
571
|
}
|
|
562
572
|
break;
|
|
573
|
+
case 'l':
|
|
574
|
+
case 'L':
|
|
575
|
+
_this.canMoveLine = true;
|
|
576
|
+
break;
|
|
563
577
|
}
|
|
564
578
|
_this.render(false);
|
|
565
579
|
};
|
|
566
580
|
this.onkeyup = function (e) {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
581
|
+
switch (e.key) {
|
|
582
|
+
case 'l':
|
|
583
|
+
case 'L':
|
|
584
|
+
_this.canMoveLine = false;
|
|
585
|
+
break;
|
|
586
|
+
// case 'Alt':
|
|
587
|
+
// if (this.drawingLine) {
|
|
588
|
+
// this.store.options.autoAnchor = !this.store.options.autoAnchor;
|
|
589
|
+
// }
|
|
590
|
+
// break;
|
|
591
|
+
}
|
|
574
592
|
if (_this.hotkeyType) {
|
|
575
593
|
_this.render();
|
|
576
594
|
}
|
|
@@ -579,7 +597,7 @@ var Canvas = /** @class */ (function () {
|
|
|
579
597
|
}
|
|
580
598
|
};
|
|
581
599
|
this.ondrop = function (event) { return __awaiter(_this, void 0, void 0, function () {
|
|
582
|
-
var json, obj, files, isGif, pt
|
|
600
|
+
var json, obj, files, isGif, pt;
|
|
583
601
|
return __generator(this, function (_a) {
|
|
584
602
|
switch (_a.label) {
|
|
585
603
|
case 0:
|
|
@@ -593,32 +611,38 @@ var Canvas = /** @class */ (function () {
|
|
|
593
611
|
json = event.dataTransfer.getData('Meta2d') ||
|
|
594
612
|
event.dataTransfer.getData('Text');
|
|
595
613
|
obj = null;
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
614
|
+
try {
|
|
615
|
+
if (json) {
|
|
616
|
+
obj = JSON.parse(json);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
catch (e) { }
|
|
620
|
+
if (!!obj) return [3 /*break*/, 3];
|
|
603
621
|
files = event.dataTransfer.files;
|
|
604
|
-
if (!(files.length && files[0].type.match('image.*'))) return [3 /*break*/,
|
|
622
|
+
if (!(files.length && files[0].type.match('image.*'))) return [3 /*break*/, 2];
|
|
605
623
|
isGif = files[0].type === 'image/gif';
|
|
606
624
|
return [4 /*yield*/, this.fileToPen(files[0], isGif)];
|
|
607
|
-
case
|
|
625
|
+
case 1:
|
|
608
626
|
obj = _a.sent();
|
|
609
|
-
|
|
610
|
-
case
|
|
627
|
+
return [3 /*break*/, 3];
|
|
628
|
+
case 2:
|
|
629
|
+
if (this.addCaches.length) {
|
|
630
|
+
obj = this.addCaches;
|
|
631
|
+
this.addCaches = [];
|
|
632
|
+
}
|
|
633
|
+
else {
|
|
634
|
+
this.store.emitter.emit('drop', undefined);
|
|
635
|
+
return [2 /*return*/];
|
|
636
|
+
}
|
|
637
|
+
_a.label = 3;
|
|
638
|
+
case 3:
|
|
611
639
|
if (obj && obj.draggable !== false) {
|
|
612
640
|
obj = Array.isArray(obj) ? obj : [obj];
|
|
613
641
|
pt = { x: event.offsetX, y: event.offsetY };
|
|
614
642
|
this.calibrateMouse(pt);
|
|
615
643
|
this.dropPens(obj, pt);
|
|
644
|
+
this.addCaches = [];
|
|
616
645
|
}
|
|
617
|
-
return [3 /*break*/, 6];
|
|
618
|
-
case 5:
|
|
619
|
-
e_1 = _a.sent();
|
|
620
|
-
return [3 /*break*/, 6];
|
|
621
|
-
case 6:
|
|
622
646
|
this.store.emitter.emit('drop', obj || json);
|
|
623
647
|
return [2 /*return*/];
|
|
624
648
|
}
|
|
@@ -1591,7 +1615,7 @@ var Canvas = /** @class */ (function () {
|
|
|
1591
1615
|
this.inPens = function (pt, pens) {
|
|
1592
1616
|
var hoverType = HoverType.None;
|
|
1593
1617
|
var _loop_2 = function (i) {
|
|
1594
|
-
var
|
|
1618
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
1595
1619
|
var pen = pens[i];
|
|
1596
1620
|
if (pen.visible == false ||
|
|
1597
1621
|
pen.calculative.inView == false ||
|
|
@@ -1604,12 +1628,36 @@ var Canvas = /** @class */ (function () {
|
|
|
1604
1628
|
!pointInRect(pt, pen.calculative.worldRect)) {
|
|
1605
1629
|
return "continue";
|
|
1606
1630
|
}
|
|
1631
|
+
//anchor title
|
|
1632
|
+
if (_this.store.data.locked) {
|
|
1633
|
+
// locked>0
|
|
1634
|
+
if (pen.calculative.worldAnchors) {
|
|
1635
|
+
try {
|
|
1636
|
+
for (var _d = (e_1 = void 0, __values(pen.calculative.worldAnchors)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1637
|
+
var anchor = _e.value;
|
|
1638
|
+
if (hitPoint(pt, anchor, _this.pointSize)) {
|
|
1639
|
+
_this.title.show(anchor);
|
|
1640
|
+
if (anchor.title) {
|
|
1641
|
+
return "break-outer";
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1647
|
+
finally {
|
|
1648
|
+
try {
|
|
1649
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
1650
|
+
}
|
|
1651
|
+
finally { if (e_1) throw e_1.error; }
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1607
1655
|
// 锚点
|
|
1608
1656
|
if (!_this.store.data.locked && _this.hotkeyType !== HotkeyType.Resize) {
|
|
1609
1657
|
if (pen.calculative.worldAnchors) {
|
|
1610
1658
|
try {
|
|
1611
|
-
for (var
|
|
1612
|
-
var anchor =
|
|
1659
|
+
for (var _f = (e_2 = void 0, __values(pen.calculative.worldAnchors)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1660
|
+
var anchor = _g.value;
|
|
1613
1661
|
hoverType = _this.inAnchor(pt, pen, anchor);
|
|
1614
1662
|
if (hoverType) {
|
|
1615
1663
|
return "break-outer";
|
|
@@ -1619,7 +1667,7 @@ var Canvas = /** @class */ (function () {
|
|
|
1619
1667
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1620
1668
|
finally {
|
|
1621
1669
|
try {
|
|
1622
|
-
if (
|
|
1670
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
1623
1671
|
}
|
|
1624
1672
|
finally { if (e_2) throw e_2.error; }
|
|
1625
1673
|
}
|
|
@@ -1682,7 +1730,7 @@ var Canvas = /** @class */ (function () {
|
|
|
1682
1730
|
_this.store.pointAt = pt;
|
|
1683
1731
|
// 锚点贴边吸附
|
|
1684
1732
|
if (!pt.ctrlKey) {
|
|
1685
|
-
var
|
|
1733
|
+
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
1734
|
if (rotate_1) {
|
|
1687
1735
|
var pts = [
|
|
1688
1736
|
{ x: x, y: y },
|
|
@@ -1710,7 +1758,7 @@ var Canvas = /** @class */ (function () {
|
|
|
1710
1758
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1711
1759
|
finally {
|
|
1712
1760
|
try {
|
|
1713
|
-
if (pts_1_1 && !pts_1_1.done && (
|
|
1761
|
+
if (pts_1_1 && !pts_1_1.done && (_c = pts_1.return)) _c.call(pts_1);
|
|
1714
1762
|
}
|
|
1715
1763
|
finally { if (e_3) throw e_3.error; }
|
|
1716
1764
|
}
|
|
@@ -2540,6 +2588,7 @@ var Canvas = /** @class */ (function () {
|
|
|
2540
2588
|
setHover(hover, false);
|
|
2541
2589
|
};
|
|
2542
2590
|
this.dialog = new Dialog(parentElement);
|
|
2591
|
+
this.title = new Title(parentElement);
|
|
2543
2592
|
if (this.store.options.scroll) {
|
|
2544
2593
|
this.scroll = new Scroll(this);
|
|
2545
2594
|
}
|
|
@@ -3182,6 +3231,7 @@ var Canvas = /** @class */ (function () {
|
|
|
3182
3231
|
this.store.active.forEach(function (pen) {
|
|
3183
3232
|
pen.calculative.active = undefined;
|
|
3184
3233
|
pen.calculative.activeAnchor = undefined;
|
|
3234
|
+
pen.calculative.hover = false;
|
|
3185
3235
|
setChildrenActive(pen, false);
|
|
3186
3236
|
});
|
|
3187
3237
|
!drawing && this.store.emitter.emit('inactive', this.store.active);
|
|
@@ -3195,10 +3245,12 @@ var Canvas = /** @class */ (function () {
|
|
|
3195
3245
|
var e_14, _a, _b;
|
|
3196
3246
|
if (emit === void 0) { emit = true; }
|
|
3197
3247
|
if (this.store.active) {
|
|
3248
|
+
emit && this.store.emitter.emit('inactive', this.store.active);
|
|
3198
3249
|
try {
|
|
3199
3250
|
for (var _c = __values(this.store.active), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
3200
3251
|
var pen = _d.value;
|
|
3201
3252
|
pen.calculative.active = undefined;
|
|
3253
|
+
pen.calculative.hover = false;
|
|
3202
3254
|
setChildrenActive(pen, false);
|
|
3203
3255
|
}
|
|
3204
3256
|
}
|
|
@@ -4404,6 +4456,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4404
4456
|
return;
|
|
4405
4457
|
}
|
|
4406
4458
|
if (!this.store.options.moveConnectedLine &&
|
|
4459
|
+
!this.canMoveLine &&
|
|
4407
4460
|
this.store.active.length === 1 &&
|
|
4408
4461
|
(((_a = this.store.active[0].anchors[0]) === null || _a === void 0 ? void 0 : _a.connectTo) ||
|
|
4409
4462
|
((_b = this.store.active[0].anchors[this.store.active[0].anchors.length - 1]) === null || _b === void 0 ? void 0 : _b.connectTo))) {
|
|
@@ -4487,7 +4540,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4487
4540
|
Canvas.prototype.initMovingPens = function () {
|
|
4488
4541
|
var _this = this;
|
|
4489
4542
|
var _a, _b;
|
|
4490
|
-
if (!this.store.options.moveConnectedLine) {
|
|
4543
|
+
if (!this.store.options.moveConnectedLine && !this.canMoveLine) {
|
|
4491
4544
|
for (var i = 0; i < this.store.active.length; i++) {
|
|
4492
4545
|
var pen = this.store.active[i];
|
|
4493
4546
|
if (((_a = pen.anchors[0]) === null || _a === void 0 ? void 0 : _a.connectTo) ||
|
|
@@ -4831,7 +4884,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4831
4884
|
return;
|
|
4832
4885
|
}
|
|
4833
4886
|
if (pen.type === PenType.Line) {
|
|
4834
|
-
if (!_this.store.options.moveConnectedLine) {
|
|
4887
|
+
if (!_this.store.options.moveConnectedLine && !_this.canMoveLine) {
|
|
4835
4888
|
return;
|
|
4836
4889
|
}
|
|
4837
4890
|
translateLine(pen, x, y);
|
|
@@ -6260,10 +6313,11 @@ var Canvas = /** @class */ (function () {
|
|
|
6260
6313
|
this.render();
|
|
6261
6314
|
};
|
|
6262
6315
|
Canvas.prototype.destroy = function () {
|
|
6263
|
-
var _a, _b;
|
|
6316
|
+
var _a, _b, _c;
|
|
6264
6317
|
this.scroll && this.scroll.destroy();
|
|
6265
6318
|
(_a = this.tooltip) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
6266
6319
|
(_b = this.dialog) === null || _b === void 0 ? void 0 : _b.destroy();
|
|
6320
|
+
(_c = this.title) === null || _c === void 0 ? void 0 : _c.destroy();
|
|
6267
6321
|
// ios
|
|
6268
6322
|
this.externalElements.removeEventListener('gesturestart', this.onGesturestart);
|
|
6269
6323
|
this.externalElements.ondragover = function (e) { return e.preventDefault(); };
|