@meta2d/core 1.0.38 → 1.0.40
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 +6 -0
- package/src/canvas/canvas.js +105 -24
- package/src/canvas/canvas.js.map +1 -1
- package/src/canvas/canvasImage.js +42 -15
- package/src/canvas/canvasImage.js.map +1 -1
- package/src/core.d.ts +1 -0
- package/src/core.js +44 -12
- package/src/core.js.map +1 -1
- package/src/diagrams/line/line.js +4 -0
- package/src/diagrams/line/line.js.map +1 -1
- package/src/options.d.ts +9 -0
- package/src/options.js.map +1 -1
- package/src/pen/arrow.js +2 -0
- package/src/pen/arrow.js.map +1 -1
- package/src/pen/render.js +4 -4
- 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/clone.js +3 -1
- package/src/utils/clone.js.map +1 -1
package/package.json
CHANGED
package/src/canvas/canvas.d.ts
CHANGED
|
@@ -81,6 +81,12 @@ export declare class Canvas {
|
|
|
81
81
|
maxZindex: number;
|
|
82
82
|
canMoveLine: boolean;
|
|
83
83
|
randomIdObj: object;
|
|
84
|
+
keyOptions?: {
|
|
85
|
+
shiftKey?: boolean;
|
|
86
|
+
altKey?: boolean;
|
|
87
|
+
ctrlKey?: boolean;
|
|
88
|
+
metaKey?: boolean;
|
|
89
|
+
};
|
|
84
90
|
/**
|
|
85
91
|
* @deprecated 改用 beforeAddPens
|
|
86
92
|
*/
|
package/src/canvas/canvas.js
CHANGED
|
@@ -82,7 +82,7 @@ var __values = (this && this.__values) || function(o) {
|
|
|
82
82
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
83
83
|
};
|
|
84
84
|
import { KeydownType } from '../options';
|
|
85
|
-
import { addLineAnchor, calcIconRect, calcTextRect, calcWorldAnchors, calcWorldRects, LockState, nearestAnchor, PenType, pushPenAnchor, removePenAnchor, renderPen, scalePen, translateLine, deleteTempAnchor, connectLine, disconnectLine, getAnchor, calcAnchorDock, calcMoveDock, calcTextLines, setNodeAnimate, setLineAnimate, calcPenRect, setChildrenActive, getParent, setHover, randomId, getPensLock, getToAnchor, getFromAnchor, calcPadding, getPensDisableRotate, getPensDisableResize, needCalcTextRectProps, calcResizeDock, needPatchFlagsPenRectProps, needCalcIconRectProps, isDomShapes, renderPenRaw, needSetPenProps, getAllChildren, calcInView, isShowChild, getTextColor, getGlobalColor, clearLifeCycle, rotatePen, calcTextAutoWidth, getGradientAnimatePath, CanvasLayer, ctxFlip, ctxRotate, setGlobalAlpha, drawImage, } from '../pen';
|
|
85
|
+
import { addLineAnchor, calcIconRect, calcTextRect, calcWorldAnchors, calcWorldRects, LockState, nearestAnchor, PenType, pushPenAnchor, removePenAnchor, renderPen, scalePen, translateLine, deleteTempAnchor, connectLine, disconnectLine, getAnchor, calcAnchorDock, calcMoveDock, calcTextLines, setNodeAnimate, setLineAnimate, calcPenRect, setChildrenActive, getParent, setHover, randomId, getPensLock, getToAnchor, getFromAnchor, calcPadding, getPensDisableRotate, getPensDisableResize, needCalcTextRectProps, calcResizeDock, needPatchFlagsPenRectProps, needCalcIconRectProps, isDomShapes, renderPenRaw, needSetPenProps, getAllChildren, calcInView, isShowChild, getTextColor, getGlobalColor, clearLifeCycle, rotatePen, calcTextAutoWidth, getGradientAnimatePath, CanvasLayer, ctxFlip, ctxRotate, setGlobalAlpha, drawImage, setElemPosition, } from '../pen';
|
|
86
86
|
import { calcRotate, distance, getDistance, hitPoint, PointType, 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';
|
|
@@ -333,6 +333,13 @@ var Canvas = /** @class */ (function () {
|
|
|
333
333
|
if (_this.store.options.unavailableKeys.includes(e.key)) {
|
|
334
334
|
return;
|
|
335
335
|
}
|
|
336
|
+
if (!_this.keyOptions) {
|
|
337
|
+
_this.keyOptions = {};
|
|
338
|
+
}
|
|
339
|
+
_this.keyOptions.altKey = e.altKey;
|
|
340
|
+
_this.keyOptions.shiftKey = e.shiftKey;
|
|
341
|
+
_this.keyOptions.ctrlKey = e.ctrlKey;
|
|
342
|
+
_this.keyOptions.metaKey = e.metaKey;
|
|
336
343
|
var x = 10;
|
|
337
344
|
var y = 10;
|
|
338
345
|
var vRect = null;
|
|
@@ -427,6 +434,13 @@ var Canvas = /** @class */ (function () {
|
|
|
427
434
|
x = -10;
|
|
428
435
|
}
|
|
429
436
|
x = x * _this.store.data.scale;
|
|
437
|
+
if (_this.store.activeAnchor &&
|
|
438
|
+
_this.store.active &&
|
|
439
|
+
_this.store.active.length === 1 &&
|
|
440
|
+
_this.store.active[0].type) {
|
|
441
|
+
_this.moveLineAnchor({ x: _this.store.activeAnchor.x + x, y: _this.store.activeAnchor.y }, {});
|
|
442
|
+
break;
|
|
443
|
+
}
|
|
430
444
|
if (vRect && _this.activeRect.x + x < vRect.x) {
|
|
431
445
|
x = vRect.x - _this.activeRect.x;
|
|
432
446
|
}
|
|
@@ -448,6 +462,13 @@ var Canvas = /** @class */ (function () {
|
|
|
448
462
|
if (vRect && _this.activeRect.y + y < vRect.y) {
|
|
449
463
|
y = vRect.y - _this.activeRect.y;
|
|
450
464
|
}
|
|
465
|
+
if (_this.store.activeAnchor &&
|
|
466
|
+
_this.store.active &&
|
|
467
|
+
_this.store.active.length === 1 &&
|
|
468
|
+
_this.store.active[0].type) {
|
|
469
|
+
_this.moveLineAnchor({ x: _this.store.activeAnchor.x, y: _this.store.activeAnchor.y + y }, {});
|
|
470
|
+
break;
|
|
471
|
+
}
|
|
451
472
|
_this.translatePens(_this.store.active, 0, y);
|
|
452
473
|
break;
|
|
453
474
|
case 'ArrowRight':
|
|
@@ -463,6 +484,13 @@ var Canvas = /** @class */ (function () {
|
|
|
463
484
|
x = 10;
|
|
464
485
|
}
|
|
465
486
|
x = x * _this.store.data.scale;
|
|
487
|
+
if (_this.store.activeAnchor &&
|
|
488
|
+
_this.store.active &&
|
|
489
|
+
_this.store.active.length === 1 &&
|
|
490
|
+
_this.store.active[0].type) {
|
|
491
|
+
_this.moveLineAnchor({ x: _this.store.activeAnchor.x + x, y: _this.store.activeAnchor.y }, {});
|
|
492
|
+
break;
|
|
493
|
+
}
|
|
466
494
|
if (vRect &&
|
|
467
495
|
_this.activeRect.x + _this.activeRect.width + x > vRect.x + vRect.width) {
|
|
468
496
|
x =
|
|
@@ -491,6 +519,13 @@ var Canvas = /** @class */ (function () {
|
|
|
491
519
|
vRect.height -
|
|
492
520
|
(_this.activeRect.y + _this.activeRect.height);
|
|
493
521
|
}
|
|
522
|
+
if (_this.store.activeAnchor &&
|
|
523
|
+
_this.store.active &&
|
|
524
|
+
_this.store.active.length === 1 &&
|
|
525
|
+
_this.store.active[0].type) {
|
|
526
|
+
_this.moveLineAnchor({ x: _this.store.activeAnchor.x, y: _this.store.activeAnchor.y + y }, {});
|
|
527
|
+
break;
|
|
528
|
+
}
|
|
494
529
|
_this.translatePens(_this.store.active, 0, y);
|
|
495
530
|
break;
|
|
496
531
|
case 'd':
|
|
@@ -541,6 +576,7 @@ var Canvas = /** @class */ (function () {
|
|
|
541
576
|
_this.cut();
|
|
542
577
|
}
|
|
543
578
|
break;
|
|
579
|
+
case '√': //MAC OPTION + V
|
|
544
580
|
case 'v':
|
|
545
581
|
case 'V':
|
|
546
582
|
if (!e.ctrlKey && !e.metaKey) {
|
|
@@ -555,7 +591,9 @@ var Canvas = /** @class */ (function () {
|
|
|
555
591
|
_this.drawingLineName = _this.store.options.drawingLineName;
|
|
556
592
|
}
|
|
557
593
|
}
|
|
558
|
-
if ((e.ctrlKey || e.metaKey) && _this.store.options.disableClipboard
|
|
594
|
+
if ((e.ctrlKey || e.metaKey) && (_this.store.options.disableClipboard ||
|
|
595
|
+
(!_this.store.options.disableClipboard && e.altKey)) //alt按下,paste事件无效
|
|
596
|
+
) {
|
|
559
597
|
_this.paste();
|
|
560
598
|
}
|
|
561
599
|
break;
|
|
@@ -657,6 +695,22 @@ var Canvas = /** @class */ (function () {
|
|
|
657
695
|
case 'L':
|
|
658
696
|
_this.canMoveLine = true;
|
|
659
697
|
break;
|
|
698
|
+
case '[':
|
|
699
|
+
//下一层
|
|
700
|
+
_this.parent.down();
|
|
701
|
+
break;
|
|
702
|
+
case ']':
|
|
703
|
+
//上一层
|
|
704
|
+
_this.parent.up();
|
|
705
|
+
break;
|
|
706
|
+
case '{':
|
|
707
|
+
// 置底
|
|
708
|
+
_this.parent.bottom();
|
|
709
|
+
break;
|
|
710
|
+
case '}':
|
|
711
|
+
//置顶
|
|
712
|
+
_this.parent.top();
|
|
713
|
+
break;
|
|
660
714
|
}
|
|
661
715
|
_this.render(false);
|
|
662
716
|
};
|
|
@@ -1241,7 +1295,7 @@ var Canvas = /** @class */ (function () {
|
|
|
1241
1295
|
var pt = { x: e.x, y: e.y };
|
|
1242
1296
|
// Move line anchor
|
|
1243
1297
|
if (_this.hoverType === HoverType.LineAnchor) {
|
|
1244
|
-
if ((_this.store.active[0].lineName === 'line'
|
|
1298
|
+
if ((_this.dockInAnchor(e) || _this.store.active[0].lineName === 'line') &&
|
|
1245
1299
|
!_this.store.options.disableDock &&
|
|
1246
1300
|
!_this.store.options.disableLineDock) {
|
|
1247
1301
|
_this.clearDock();
|
|
@@ -2103,7 +2157,7 @@ var Canvas = /** @class */ (function () {
|
|
|
2103
2157
|
ctx.translate(-_this.activeRect.center.x, -_this.activeRect.center.y);
|
|
2104
2158
|
}
|
|
2105
2159
|
ctx.strokeStyle = _this.store.options.activeColor;
|
|
2106
|
-
ctx.globalAlpha = _this.store.options.activeGlobalAlpha
|
|
2160
|
+
ctx.globalAlpha = _this.store.options.activeGlobalAlpha === undefined ? 0.3 : _this.store.options.activeGlobalAlpha;
|
|
2107
2161
|
ctx.beginPath();
|
|
2108
2162
|
ctx.lineWidth = _this.store.options.activeLineWidth || 1;
|
|
2109
2163
|
ctx.setLineDash(_this.store.options.activeLineDash || []);
|
|
@@ -2335,8 +2389,16 @@ var Canvas = /** @class */ (function () {
|
|
|
2335
2389
|
pen.x -= initRect.center.x - _this.store.clipboard.pos.x;
|
|
2336
2390
|
pen.y -= initRect.center.y - _this.store.clipboard.pos.y;
|
|
2337
2391
|
}
|
|
2338
|
-
|
|
2339
|
-
|
|
2392
|
+
if (_this.keyOptions && _this.keyOptions.altKey && (_this.keyOptions.ctrlKey || _this.keyOptions.metaKey)) {
|
|
2393
|
+
pen.x = -_this.store.data.x + _this.width / 2 - pen.width / 2;
|
|
2394
|
+
pen.y = -_this.store.data.y + _this.height / 2 - pen.height / 2;
|
|
2395
|
+
}
|
|
2396
|
+
else if (_this.keyOptions && _this.keyOptions.shiftKey && (_this.keyOptions.ctrlKey || _this.keyOptions.metaKey)) {
|
|
2397
|
+
}
|
|
2398
|
+
else {
|
|
2399
|
+
pen.x += _this.store.clipboard.offset * _this.store.data.scale;
|
|
2400
|
+
pen.y += _this.store.clipboard.offset * _this.store.data.scale;
|
|
2401
|
+
}
|
|
2340
2402
|
}
|
|
2341
2403
|
_this.makePen(pen);
|
|
2342
2404
|
var newChildren = [];
|
|
@@ -2360,6 +2422,7 @@ var Canvas = /** @class */ (function () {
|
|
|
2360
2422
|
}
|
|
2361
2423
|
}
|
|
2362
2424
|
pen.children = newChildren;
|
|
2425
|
+
calcInView(pen, true);
|
|
2363
2426
|
return pen;
|
|
2364
2427
|
};
|
|
2365
2428
|
this.ondblclick = function (e) {
|
|
@@ -2649,6 +2712,9 @@ var Canvas = /** @class */ (function () {
|
|
|
2649
2712
|
});
|
|
2650
2713
|
_this.store.emitter.emit('valueUpdate', pen);
|
|
2651
2714
|
}
|
|
2715
|
+
else if (pen.text === _this.inputDiv.dataset.value && pen.calculative.textLines.length == 0) {
|
|
2716
|
+
calcTextRect(pen);
|
|
2717
|
+
}
|
|
2652
2718
|
_this.initTemplateCanvas([pen]);
|
|
2653
2719
|
}
|
|
2654
2720
|
_this.inputDiv.dataset.penId = undefined;
|
|
@@ -4297,6 +4363,8 @@ var Canvas = /** @class */ (function () {
|
|
|
4297
4363
|
calcPadding(pen, rect);
|
|
4298
4364
|
calcTextRect(pen);
|
|
4299
4365
|
calcInView(pen);
|
|
4366
|
+
pen.calculative &&
|
|
4367
|
+
(pen.calculative.gradientAnimatePath = undefined);
|
|
4300
4368
|
this.store.path2dMap.set(pen, globalStore.path2dDraws[pen.name](pen));
|
|
4301
4369
|
if (pen.calculative.worldAnchors) {
|
|
4302
4370
|
pen.anchors = pen.calculative.worldAnchors.map(function (pt) {
|
|
@@ -4317,6 +4385,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4317
4385
|
Canvas.prototype.finishDrawline = function (end) {
|
|
4318
4386
|
return __awaiter(this, void 0, void 0, function () {
|
|
4319
4387
|
var from, to, line, rect, allowAdd, _a;
|
|
4388
|
+
var _this = this;
|
|
4320
4389
|
return __generator(this, function (_b) {
|
|
4321
4390
|
switch (_b.label) {
|
|
4322
4391
|
case 0:
|
|
@@ -4341,6 +4410,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4341
4410
|
if (!from.connectTo || !to.connectTo) {
|
|
4342
4411
|
if (this.store.options.disableEmptyLine) {
|
|
4343
4412
|
// 有一端未连线,且 禁止创建空线条
|
|
4413
|
+
this.store.pens[from.connectTo].connectedLines = this.store.pens[from.connectTo].connectedLines.filter(function (item) { return item.lineId !== _this.drawingLine.id; });
|
|
4344
4414
|
this.drawingLine = undefined;
|
|
4345
4415
|
this.render();
|
|
4346
4416
|
return [2 /*return*/];
|
|
@@ -4703,7 +4773,6 @@ var Canvas = /** @class */ (function () {
|
|
|
4703
4773
|
}, 50);
|
|
4704
4774
|
};
|
|
4705
4775
|
Canvas.prototype.translate = function (x, y) {
|
|
4706
|
-
var _this = this;
|
|
4707
4776
|
if (x === void 0) { x = 0; }
|
|
4708
4777
|
if (y === void 0) { y = 0; }
|
|
4709
4778
|
this.store.data.x += x * this.store.data.scale;
|
|
@@ -4747,12 +4816,13 @@ var Canvas = /** @class */ (function () {
|
|
|
4747
4816
|
}
|
|
4748
4817
|
}
|
|
4749
4818
|
}
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4819
|
+
//TODO 当初为什么加异步
|
|
4820
|
+
// setTimeout(() => {
|
|
4821
|
+
this.canvasTemplate.init();
|
|
4822
|
+
this.canvasImage.init();
|
|
4823
|
+
this.canvasImageBottom.init();
|
|
4824
|
+
this.render();
|
|
4825
|
+
// });
|
|
4756
4826
|
this.store.emitter.emit('translate', {
|
|
4757
4827
|
x: this.store.data.x,
|
|
4758
4828
|
y: this.store.data.y,
|
|
@@ -4843,17 +4913,17 @@ var Canvas = /** @class */ (function () {
|
|
|
4843
4913
|
_this.execPenResize(pen);
|
|
4844
4914
|
});
|
|
4845
4915
|
this.calcActiveRect();
|
|
4846
|
-
setTimeout(
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
});
|
|
4916
|
+
// setTimeout(() => {
|
|
4917
|
+
this.canvasTemplate.init();
|
|
4918
|
+
this.canvasImage.init();
|
|
4919
|
+
this.canvasImageBottom.init();
|
|
4920
|
+
var map = this.parent.map;
|
|
4921
|
+
if (map && map.isShow) {
|
|
4922
|
+
map.setView();
|
|
4923
|
+
}
|
|
4924
|
+
this.render();
|
|
4925
|
+
this.store.emitter.emit('scale', this.store.data.scale);
|
|
4926
|
+
// });
|
|
4857
4927
|
};
|
|
4858
4928
|
Canvas.prototype.templateScale = function (scale, center) {
|
|
4859
4929
|
var _this = this;
|
|
@@ -5325,6 +5395,10 @@ var Canvas = /** @class */ (function () {
|
|
|
5325
5395
|
this.render();
|
|
5326
5396
|
this.store.active[0].calculative &&
|
|
5327
5397
|
(this.store.active[0].calculative.gradientAnimatePath = undefined);
|
|
5398
|
+
this.store.emitter.emit('moveLineAnchor', {
|
|
5399
|
+
pen: this.store.active[0],
|
|
5400
|
+
anchor: this.store.activeAnchor,
|
|
5401
|
+
});
|
|
5328
5402
|
if (this.timer) {
|
|
5329
5403
|
clearTimeout(this.timer);
|
|
5330
5404
|
}
|
|
@@ -6025,6 +6099,9 @@ var Canvas = /** @class */ (function () {
|
|
|
6025
6099
|
if (pen.calculative[k] === undefined) {
|
|
6026
6100
|
continue;
|
|
6027
6101
|
}
|
|
6102
|
+
if (k === 'length') {
|
|
6103
|
+
continue;
|
|
6104
|
+
}
|
|
6028
6105
|
if (typeof pen[k] !== 'object' || k === 'lineDash') {
|
|
6029
6106
|
if (k === 'lineWidth') {
|
|
6030
6107
|
pen[k] =
|
|
@@ -6894,6 +6971,10 @@ var Canvas = /** @class */ (function () {
|
|
|
6894
6971
|
pen.canvasLayer === CanvasLayer.CanvasTemplate) {
|
|
6895
6972
|
this.initTemplateCanvas([pen]);
|
|
6896
6973
|
}
|
|
6974
|
+
if (data.zIndex !== undefined) {
|
|
6975
|
+
pen.calculative.singleton.div &&
|
|
6976
|
+
setElemPosition(pen, pen.calculative.singleton.div);
|
|
6977
|
+
}
|
|
6897
6978
|
};
|
|
6898
6979
|
/**
|
|
6899
6980
|
* 执行 pen ,以及 pen 的子孙节点的 onResize 生命周期函数
|