@meta2d/core 1.0.52 → 1.0.53
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 +10 -1
- package/src/canvas/canvas.js +475 -29
- package/src/canvas/canvas.js.map +1 -1
- package/src/canvas/canvasImage.d.ts +5 -1
- package/src/canvas/canvasImage.js +54 -12
- package/src/canvas/canvasImage.js.map +1 -1
- package/src/canvas/magnifierCanvas.js +5 -3
- package/src/canvas/magnifierCanvas.js.map +1 -1
- package/src/core.d.ts +1 -0
- package/src/core.js +284 -83
- package/src/core.js.map +1 -1
- package/src/map/map.d.ts +1 -0
- package/src/map/map.js +68 -1
- package/src/map/map.js.map +1 -1
- package/src/pen/model.d.ts +3 -0
- package/src/pen/model.js +1 -0
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.d.ts +2 -0
- package/src/pen/render.js +135 -4
- package/src/pen/render.js.map +1 -1
- package/src/store/store.d.ts +21 -0
- package/src/store/store.js.map +1 -1
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, setElemPosition, getAllFollowers, } 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, getAllFollowers, calcChildrenInitRect, } 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, pointInPolygon } from '../rect';
|
|
88
88
|
import { EditType, globalStore, } from '../store';
|
|
@@ -120,6 +120,7 @@ var Canvas = /** @class */ (function () {
|
|
|
120
120
|
this.patchFlagsLines = new Set();
|
|
121
121
|
this.lastMouseTime = 0;
|
|
122
122
|
this.hoverTimer = 0;
|
|
123
|
+
this.fitTimer = 0;
|
|
123
124
|
this.patchFlags = false;
|
|
124
125
|
this.lastRender = 0;
|
|
125
126
|
this.touchStart = 0;
|
|
@@ -319,6 +320,33 @@ var Canvas = /** @class */ (function () {
|
|
|
319
320
|
}
|
|
320
321
|
}
|
|
321
322
|
var x = e.offsetX, y = e.offsetY;
|
|
323
|
+
// if (this.parent.map && e.target === this.parent.map?.box) {
|
|
324
|
+
// //放大镜缩放
|
|
325
|
+
// const width = this.store.data.width || this.store.options.width;
|
|
326
|
+
// const height = this.store.data.height || this.store.options.height;
|
|
327
|
+
// if (width && height) {
|
|
328
|
+
// //大屏
|
|
329
|
+
// x =
|
|
330
|
+
// (x / this.parent.map.boxWidth) * width * this.store.data.scale +
|
|
331
|
+
// this.store.data.origin.x;
|
|
332
|
+
// y =
|
|
333
|
+
// (y / this.parent.map.boxHeight) * height * this.store.data.scale +
|
|
334
|
+
// this.store.data.origin.y;
|
|
335
|
+
// const rect = this.canvas.getBoundingClientRect();
|
|
336
|
+
// x = x + rect.left;
|
|
337
|
+
// y = y + rect.top;
|
|
338
|
+
// } else {
|
|
339
|
+
// const rect = this.parent.getRect();
|
|
340
|
+
// x =
|
|
341
|
+
// (x / this.parent.map.boxWidth) * rect.width +
|
|
342
|
+
// rect.x +
|
|
343
|
+
// this.store.data.x;
|
|
344
|
+
// y =
|
|
345
|
+
// (y / this.parent.map.boxHeight) * rect.height +
|
|
346
|
+
// rect.y +
|
|
347
|
+
// this.store.data.y;
|
|
348
|
+
// }
|
|
349
|
+
// }
|
|
322
350
|
_this.scale(_this.store.data.scale + scaleOff, { x: x, y: y });
|
|
323
351
|
_this.externalElements.focus(); // 聚焦
|
|
324
352
|
};
|
|
@@ -428,6 +456,10 @@ var Canvas = /** @class */ (function () {
|
|
|
428
456
|
break;
|
|
429
457
|
case 'Delete':
|
|
430
458
|
case 'Backspace':
|
|
459
|
+
if (_this.canvasImage.fitFlag && _this.canvasImage.activeFit) {
|
|
460
|
+
_this.deleteFit();
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
431
463
|
!_this.store.data.locked && _this.delete();
|
|
432
464
|
break;
|
|
433
465
|
case 'ArrowLeft':
|
|
@@ -991,6 +1023,13 @@ var Canvas = /** @class */ (function () {
|
|
|
991
1023
|
_this.mousePos.y = e.y;
|
|
992
1024
|
_this.mouseDown = e;
|
|
993
1025
|
_this.lastMouseTime = performance.now();
|
|
1026
|
+
if (_this.canvasImage.fitFlag) {
|
|
1027
|
+
if (!_this.canvasImage.currentFit) {
|
|
1028
|
+
//选中布局容器
|
|
1029
|
+
_this.calcuActiveFit();
|
|
1030
|
+
}
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
994
1033
|
// Set anchor of pen.
|
|
995
1034
|
if (_this.hotkeyType === HotkeyType.AddAnchor) {
|
|
996
1035
|
_this.setAnchor(_this.store.pointAt);
|
|
@@ -1229,7 +1268,7 @@ var Canvas = /** @class */ (function () {
|
|
|
1229
1268
|
_this.render();
|
|
1230
1269
|
};
|
|
1231
1270
|
this.onMouseMove = function (e) {
|
|
1232
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1271
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1233
1272
|
if (_this.store.data.locked === LockState.Disable) {
|
|
1234
1273
|
_this.hoverType = HoverType.None;
|
|
1235
1274
|
return;
|
|
@@ -1258,6 +1297,22 @@ var Canvas = /** @class */ (function () {
|
|
|
1258
1297
|
_this.render();
|
|
1259
1298
|
return;
|
|
1260
1299
|
}
|
|
1300
|
+
if (_this.canvasImage.fitFlag) {
|
|
1301
|
+
if (_this.canvasImage.activeFit) {
|
|
1302
|
+
var now_2 = performance.now();
|
|
1303
|
+
if (now_2 - _this.fitTimer > 100) {
|
|
1304
|
+
if (_this.mouseDown) {
|
|
1305
|
+
// 容器大小变化
|
|
1306
|
+
_this.updateFit(e);
|
|
1307
|
+
}
|
|
1308
|
+
else {
|
|
1309
|
+
_this.inFitBorder(_this.mousePos);
|
|
1310
|
+
}
|
|
1311
|
+
_this.fitTimer = now_2;
|
|
1312
|
+
}
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1261
1316
|
if (_this.mouseDown && !_this.store.options.disableTranslate) {
|
|
1262
1317
|
// 画布平移前提
|
|
1263
1318
|
if (_this.mouseRight === MouseRight.Down) {
|
|
@@ -1311,7 +1366,7 @@ var Canvas = /** @class */ (function () {
|
|
|
1311
1366
|
return;
|
|
1312
1367
|
}
|
|
1313
1368
|
// 框选
|
|
1314
|
-
if (e.buttons === 1 && (e.ctrlKey || !_this.hoverType && !_this.hotkeyType)) {
|
|
1369
|
+
if (e.buttons === 1 && (e.ctrlKey || !_this.hoverType && !_this.hotkeyType) && !(e.ctrlKey && (_this.store.activeAnchor || ((_a = _this.store.active) === null || _a === void 0 ? void 0 : _a.length)))) {
|
|
1315
1370
|
_this.dragRect = {
|
|
1316
1371
|
x: Math.min(_this.mouseDown.x, e.x),
|
|
1317
1372
|
y: Math.min(_this.mouseDown.y, e.y),
|
|
@@ -1331,17 +1386,17 @@ var Canvas = /** @class */ (function () {
|
|
|
1331
1386
|
_this.render();
|
|
1332
1387
|
return;
|
|
1333
1388
|
}
|
|
1334
|
-
else if (!((
|
|
1389
|
+
else if (!((_b = _this.store.active[0]) === null || _b === void 0 ? void 0 : _b.locked)) {
|
|
1335
1390
|
var pt = { x: e.x, y: e.y };
|
|
1336
1391
|
// Move line anchor
|
|
1337
1392
|
if (_this.hoverType === HoverType.LineAnchor) {
|
|
1338
|
-
if ((_this.dockInAnchor(e) || ((
|
|
1393
|
+
if ((_this.dockInAnchor(e) || ((_c = _this.store.active[0]) === null || _c === void 0 ? void 0 : _c.lineName) === 'line') &&
|
|
1339
1394
|
!_this.store.options.disableDock &&
|
|
1340
1395
|
!_this.store.options.disableLineDock) {
|
|
1341
1396
|
_this.clearDock();
|
|
1342
1397
|
_this.dock = calcAnchorDock(_this.store, pt, _this.store.activeAnchor);
|
|
1343
|
-
((
|
|
1344
|
-
((
|
|
1398
|
+
((_d = _this.dock) === null || _d === void 0 ? void 0 : _d.xDock) && (pt.x += _this.dock.xDock.step);
|
|
1399
|
+
((_e = _this.dock) === null || _e === void 0 ? void 0 : _e.yDock) && (pt.y += _this.dock.yDock.step);
|
|
1345
1400
|
}
|
|
1346
1401
|
_this.moveLineAnchor(pt, e);
|
|
1347
1402
|
return;
|
|
@@ -1381,7 +1436,7 @@ var Canvas = /** @class */ (function () {
|
|
|
1381
1436
|
if (_this.store.active.length === 1) {
|
|
1382
1437
|
var activePen = _this.store.active[0];
|
|
1383
1438
|
if (activePen.locked === undefined || activePen.locked < LockState.DisableMove) {
|
|
1384
|
-
(
|
|
1439
|
+
(_f = activePen === null || activePen === void 0 ? void 0 : activePen.onMouseMove) === null || _f === void 0 ? void 0 : _f.call(activePen, activePen, _this.mousePos);
|
|
1385
1440
|
}
|
|
1386
1441
|
if (activePen.calculative.focus) {
|
|
1387
1442
|
//执行图元的操作
|
|
@@ -1412,8 +1467,8 @@ var Canvas = /** @class */ (function () {
|
|
|
1412
1467
|
!_this.store.options.disableLineDock) {
|
|
1413
1468
|
_this.clearDock();
|
|
1414
1469
|
_this.dock = calcAnchorDock(_this.store, pt);
|
|
1415
|
-
((
|
|
1416
|
-
((
|
|
1470
|
+
((_g = _this.dock) === null || _g === void 0 ? void 0 : _g.xDock) && (pt.x += _this.dock.xDock.step);
|
|
1471
|
+
((_h = _this.dock) === null || _h === void 0 ? void 0 : _h.yDock) && (pt.y += _this.dock.yDock.step);
|
|
1417
1472
|
}
|
|
1418
1473
|
if (_this.mouseDown &&
|
|
1419
1474
|
_this.drawingLineName === 'curve' &&
|
|
@@ -1642,22 +1697,27 @@ var Canvas = /** @class */ (function () {
|
|
|
1642
1697
|
});
|
|
1643
1698
|
_this.patchFlagsLines.clear();
|
|
1644
1699
|
if (_this.dragRect) {
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1700
|
+
if (_this.canvasImage.fitFlag) {
|
|
1701
|
+
_this.makeFit();
|
|
1702
|
+
}
|
|
1703
|
+
else {
|
|
1704
|
+
var pens = _this.store.data.pens.filter(function (pen) {
|
|
1705
|
+
if (pen.visible === false ||
|
|
1706
|
+
pen.locked >= LockState.DisableMove ||
|
|
1707
|
+
pen.parentId || pen.isRuleLine) {
|
|
1708
|
+
return false;
|
|
1709
|
+
}
|
|
1710
|
+
if (rectInRect(pen.calculative.worldRect, _this.dragRect, e.ctrlKey || _this.store.options.dragAllIn)) {
|
|
1711
|
+
// 先判断在区域内,若不在区域内,则锚点肯定不在框选区域内,避免每条连线过度计算
|
|
1712
|
+
if (pen.type === PenType.Line && !_this.store.options.dragAllIn) {
|
|
1713
|
+
return lineInRect(pen, _this.dragRect);
|
|
1714
|
+
}
|
|
1715
|
+
return true;
|
|
1655
1716
|
}
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
_this.active(pens);
|
|
1717
|
+
});
|
|
1718
|
+
//框选
|
|
1719
|
+
_this.active(pens);
|
|
1720
|
+
}
|
|
1661
1721
|
}
|
|
1662
1722
|
if (e.button !== 2) {
|
|
1663
1723
|
if (distance(_this.mouseDown, e) < 2) {
|
|
@@ -1687,7 +1747,10 @@ var Canvas = /** @class */ (function () {
|
|
|
1687
1747
|
if (_this.willInactivePen) {
|
|
1688
1748
|
_this.willInactivePen.calculative.active = undefined;
|
|
1689
1749
|
setChildrenActive(_this.willInactivePen, false); // 子节点取消激活
|
|
1690
|
-
_this.store.active.
|
|
1750
|
+
var index = _this.store.active.findIndex(function (p) { return p === _this.willInactivePen; });
|
|
1751
|
+
if (index >= 0) {
|
|
1752
|
+
_this.store.active.splice(index, 1);
|
|
1753
|
+
}
|
|
1691
1754
|
_this.calcActiveRect();
|
|
1692
1755
|
_this.willInactivePen = undefined;
|
|
1693
1756
|
_this.store.emitter.emit('inactive', [_this.willInactivePen]);
|
|
@@ -1804,6 +1867,9 @@ var Canvas = /** @class */ (function () {
|
|
|
1804
1867
|
if (_this.dragRect) {
|
|
1805
1868
|
return;
|
|
1806
1869
|
}
|
|
1870
|
+
if (_this.canvasImage.fitFlag) {
|
|
1871
|
+
return;
|
|
1872
|
+
}
|
|
1807
1873
|
var hoverType = HoverType.None;
|
|
1808
1874
|
_this.store.hover = undefined;
|
|
1809
1875
|
_this.store.hoverAnchor = undefined;
|
|
@@ -2946,6 +3012,36 @@ var Canvas = /** @class */ (function () {
|
|
|
2946
3012
|
_this.render();
|
|
2947
3013
|
_this.store.emitter.emit('valueUpdate', pen);
|
|
2948
3014
|
};
|
|
3015
|
+
this.inFitBorder = function (pt) {
|
|
3016
|
+
var current = undefined;
|
|
3017
|
+
var width = (_this.store.data.width || _this.store.options.width);
|
|
3018
|
+
var height = (_this.store.data.height || _this.store.options.height);
|
|
3019
|
+
var point = {
|
|
3020
|
+
x: (pt.x - _this.store.data.origin.x) / _this.store.data.scale,
|
|
3021
|
+
y: (pt.y - _this.store.data.origin.y) / _this.store.data.scale,
|
|
3022
|
+
};
|
|
3023
|
+
var fit = _this.canvasImage.activeFit;
|
|
3024
|
+
// if (pointInRect(point, { x:fit.x-0.01, y:0, width, height })) {
|
|
3025
|
+
_this.externalElements.style.cursor = 'default';
|
|
3026
|
+
if (point.y > height * fit.y - 10 && point.y < height * fit.y + 10) {
|
|
3027
|
+
current = 'top';
|
|
3028
|
+
_this.externalElements.style.cursor = 'row-resize';
|
|
3029
|
+
}
|
|
3030
|
+
if (point.y > height * (fit.y + fit.height) - 10 && point.y < height * (fit.y + fit.height) + 10) {
|
|
3031
|
+
current = 'bottom';
|
|
3032
|
+
_this.externalElements.style.cursor = 'row-resize';
|
|
3033
|
+
}
|
|
3034
|
+
if (point.x > width * fit.x - 10 && point.x < width * fit.x) {
|
|
3035
|
+
current = 'left';
|
|
3036
|
+
_this.externalElements.style.cursor = 'col-resize';
|
|
3037
|
+
}
|
|
3038
|
+
if (point.x > width * (fit.x + fit.width) - 10 && point.x < width * (fit.x + fit.width) + 10) {
|
|
3039
|
+
current = 'right';
|
|
3040
|
+
_this.externalElements.style.cursor = 'col-resize';
|
|
3041
|
+
}
|
|
3042
|
+
// }
|
|
3043
|
+
_this.canvasImage.currentFit = current;
|
|
3044
|
+
};
|
|
2949
3045
|
this.canvasTemplate = new CanvasTemplate(parentElement, store);
|
|
2950
3046
|
this.canvasTemplate.canvas.style.zIndex = '1';
|
|
2951
3047
|
this.canvasImageBottom = new CanvasImage(parentElement, store, true);
|
|
@@ -3286,14 +3382,14 @@ var Canvas = /** @class */ (function () {
|
|
|
3286
3382
|
}
|
|
3287
3383
|
if (pen.dataset) {
|
|
3288
3384
|
if (num % 2 === 0) {
|
|
3289
|
-
lastW = pen.width - 40;
|
|
3385
|
+
lastW = pen.width - 40 * this.store.data.scale;
|
|
3290
3386
|
}
|
|
3291
3387
|
else {
|
|
3292
3388
|
lastW = 0;
|
|
3293
3389
|
}
|
|
3294
3390
|
num++;
|
|
3295
3391
|
if (num % 2 === 0) {
|
|
3296
|
-
lastH += pen.height + 10;
|
|
3392
|
+
lastH += pen.height + 10 * this.store.data.scale;
|
|
3297
3393
|
}
|
|
3298
3394
|
}
|
|
3299
3395
|
}
|
|
@@ -3687,6 +3783,7 @@ var Canvas = /** @class */ (function () {
|
|
|
3687
3783
|
pen.calculative.initRect.ey =
|
|
3688
3784
|
pen.calculative.y + pen.calculative.height;
|
|
3689
3785
|
}
|
|
3786
|
+
calcChildrenInitRect(pen);
|
|
3690
3787
|
});
|
|
3691
3788
|
// active 消息表示拖拽结束
|
|
3692
3789
|
// this.store.emitter.emit('active', this.store.active);
|
|
@@ -7061,7 +7158,7 @@ var Canvas = /** @class */ (function () {
|
|
|
7061
7158
|
};
|
|
7062
7159
|
Canvas.prototype.changePenId = function (oldId, newId) {
|
|
7063
7160
|
var _this = this;
|
|
7064
|
-
var _a, _b, _c, _d, _e;
|
|
7161
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
7065
7162
|
if (oldId === newId) {
|
|
7066
7163
|
return;
|
|
7067
7164
|
}
|
|
@@ -7101,6 +7198,9 @@ var Canvas = /** @class */ (function () {
|
|
|
7101
7198
|
calcWorldAnchors(line);
|
|
7102
7199
|
});
|
|
7103
7200
|
}
|
|
7201
|
+
//锚点
|
|
7202
|
+
(_f = pen.anchors) === null || _f === void 0 ? void 0 : _f.forEach(function (anchor) { return anchor.penId = newId; });
|
|
7203
|
+
(_g = pen.calculative.worldAnchors) === null || _g === void 0 ? void 0 : _g.forEach(function (anchor) { return anchor.penId = newId; });
|
|
7104
7204
|
};
|
|
7105
7205
|
Canvas.prototype.updateValue = function (pen, data) {
|
|
7106
7206
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -7638,6 +7738,17 @@ var Canvas = /** @class */ (function () {
|
|
|
7638
7738
|
if (!isFinite(rect.width)) {
|
|
7639
7739
|
throw new Error('can not move view, because width is not finite');
|
|
7640
7740
|
}
|
|
7741
|
+
var width = this.store.data.width || this.store.options.width;
|
|
7742
|
+
var height = this.store.data.height || this.store.options.height;
|
|
7743
|
+
if (width && height) {
|
|
7744
|
+
//大屏
|
|
7745
|
+
rect = {
|
|
7746
|
+
x: this.store.data.origin.x,
|
|
7747
|
+
y: this.store.data.origin.y,
|
|
7748
|
+
width: width * this.store.data.scale,
|
|
7749
|
+
height: height * this.store.data.scale,
|
|
7750
|
+
};
|
|
7751
|
+
}
|
|
7641
7752
|
this.store.data.x = this.canvas.clientWidth / 2 - x * rect.width - rect.x;
|
|
7642
7753
|
this.store.data.y = this.canvas.clientHeight / 2 - y * rect.height - rect.y;
|
|
7643
7754
|
this.onMovePens();
|
|
@@ -7656,6 +7767,341 @@ var Canvas = /** @class */ (function () {
|
|
|
7656
7767
|
this.externalElements.style.cursor = 'default';
|
|
7657
7768
|
this.render();
|
|
7658
7769
|
};
|
|
7770
|
+
Canvas.prototype.showFit = function () {
|
|
7771
|
+
this.store.data.locked = 0;
|
|
7772
|
+
this.canvasImage.fitFlag = true;
|
|
7773
|
+
this.canvasImage.activeFit = undefined;
|
|
7774
|
+
this.canvasImage.currentFit = undefined;
|
|
7775
|
+
if (!this.store.data.fits) {
|
|
7776
|
+
this.store.data.fits = [];
|
|
7777
|
+
}
|
|
7778
|
+
this.store.data.fits.forEach(function (fit) { return fit.active = false; });
|
|
7779
|
+
this.canvasImage.init();
|
|
7780
|
+
this.canvasImage.render();
|
|
7781
|
+
};
|
|
7782
|
+
Canvas.prototype.hideFit = function () {
|
|
7783
|
+
this.canvasImage.fitFlag = false;
|
|
7784
|
+
this.canvasImage.activeFit = undefined;
|
|
7785
|
+
this.canvasImage.currentFit = undefined;
|
|
7786
|
+
this.canvasImage.init();
|
|
7787
|
+
this.canvasImage.render();
|
|
7788
|
+
};
|
|
7789
|
+
Canvas.prototype.makeFit = function () {
|
|
7790
|
+
var _this = this;
|
|
7791
|
+
if (this.dragRect.width < 100 && this.dragRect.height < 100) {
|
|
7792
|
+
return;
|
|
7793
|
+
}
|
|
7794
|
+
//将所有当前框选的图元设置到该容器中
|
|
7795
|
+
var pens = this.store.data.pens.filter(function (pen) {
|
|
7796
|
+
if (
|
|
7797
|
+
// pen.locked >= LockState.DisableMove ||
|
|
7798
|
+
pen.parentId || pen.isRuleLine) {
|
|
7799
|
+
return false;
|
|
7800
|
+
}
|
|
7801
|
+
if (rectInRect(pen.calculative.worldRect, _this.dragRect, true)) {
|
|
7802
|
+
// 先判断在区域内,若不在区域内,则锚点肯定不在框选区域内,避免每条连线过度计算
|
|
7803
|
+
if (pen.type === PenType.Line && !_this.store.options.dragAllIn) {
|
|
7804
|
+
return lineInRect(pen, _this.dragRect);
|
|
7805
|
+
}
|
|
7806
|
+
return true;
|
|
7807
|
+
}
|
|
7808
|
+
});
|
|
7809
|
+
if (!pens.length) {
|
|
7810
|
+
return;
|
|
7811
|
+
}
|
|
7812
|
+
var _rect = this.parent.getRect(pens);
|
|
7813
|
+
var scale = this.store.data.scale;
|
|
7814
|
+
var width = this.store.data.width || this.store.options.width;
|
|
7815
|
+
var height = this.store.data.height || this.store.options.height;
|
|
7816
|
+
var x = (Math.floor(_rect.x) - this.store.data.origin.x) / scale / width;
|
|
7817
|
+
var y = (Math.floor(_rect.y) - this.store.data.origin.y) / scale / height;
|
|
7818
|
+
var rect = {
|
|
7819
|
+
x: x,
|
|
7820
|
+
y: y,
|
|
7821
|
+
width: (Math.ceil(_rect.width) + 1) / scale / width,
|
|
7822
|
+
height: (Math.ceil(_rect.height) + 1) / scale / height,
|
|
7823
|
+
children: pens.map(function (pen) { return pen.id; }),
|
|
7824
|
+
id: s8(),
|
|
7825
|
+
active: true
|
|
7826
|
+
};
|
|
7827
|
+
if (rect.x < -0.1) {
|
|
7828
|
+
rect.x = -0.1;
|
|
7829
|
+
}
|
|
7830
|
+
if (rect.y < -0.1) {
|
|
7831
|
+
rect.y = -0.1;
|
|
7832
|
+
}
|
|
7833
|
+
if (rect.width > 0.5) {
|
|
7834
|
+
rect.left = true;
|
|
7835
|
+
rect.right = true;
|
|
7836
|
+
rect.leftValue = (rect.x - 0) * scale * width;
|
|
7837
|
+
rect.rightValue = (1 - (rect.x + rect.width)) * scale * width;
|
|
7838
|
+
}
|
|
7839
|
+
else {
|
|
7840
|
+
if (rect.x < 0.5) {
|
|
7841
|
+
rect.left = true;
|
|
7842
|
+
rect.leftValue = (rect.x - 0) * scale * width;
|
|
7843
|
+
}
|
|
7844
|
+
else {
|
|
7845
|
+
rect.right = true;
|
|
7846
|
+
rect.rightValue = (1 - (rect.x + rect.width)) * scale * width;
|
|
7847
|
+
}
|
|
7848
|
+
}
|
|
7849
|
+
if (rect.leftValue < 1) {
|
|
7850
|
+
rect.leftValue = 0;
|
|
7851
|
+
}
|
|
7852
|
+
if (rect.rightValue < 1) {
|
|
7853
|
+
rect.rightValue = 0;
|
|
7854
|
+
}
|
|
7855
|
+
if (rect.height > 0.5) {
|
|
7856
|
+
rect.top = true;
|
|
7857
|
+
rect.bottom = true;
|
|
7858
|
+
rect.topValue = (rect.y - 0) * scale * height;
|
|
7859
|
+
rect.bottomValue = (1 - (rect.y + rect.height)) * scale * height;
|
|
7860
|
+
}
|
|
7861
|
+
else {
|
|
7862
|
+
if (rect.y < 0.5) {
|
|
7863
|
+
rect.top = true;
|
|
7864
|
+
rect.topValue = (rect.y - 0) * scale * height;
|
|
7865
|
+
}
|
|
7866
|
+
else {
|
|
7867
|
+
rect.bottom = true;
|
|
7868
|
+
rect.bottomValue = (1 - (rect.y + rect.height)) * scale * height;
|
|
7869
|
+
}
|
|
7870
|
+
}
|
|
7871
|
+
if (rect.topValue < 1) {
|
|
7872
|
+
rect.topValue = 0;
|
|
7873
|
+
}
|
|
7874
|
+
if (rect.bottomValue < 1) {
|
|
7875
|
+
rect.bottomValue = 0;
|
|
7876
|
+
}
|
|
7877
|
+
if (!this.store.data.fits) {
|
|
7878
|
+
this.store.data.fits = [];
|
|
7879
|
+
}
|
|
7880
|
+
this.store.data.fits.forEach(function (fit) { fit.active = false; });
|
|
7881
|
+
this.store.data.fits.push(rect);
|
|
7882
|
+
this.canvasImage.activeFit = rect;
|
|
7883
|
+
this.store.emitter.emit('fit', rect);
|
|
7884
|
+
this.canvasImage.init();
|
|
7885
|
+
this.canvasImage.render();
|
|
7886
|
+
};
|
|
7887
|
+
Canvas.prototype.updateFit = function (e) {
|
|
7888
|
+
var _this = this;
|
|
7889
|
+
var scale = this.store.data.scale;
|
|
7890
|
+
var width = this.store.data.width || this.store.options.width;
|
|
7891
|
+
var height = this.store.data.height || this.store.options.height;
|
|
7892
|
+
var x = (e.x - this.store.data.origin.x) / scale / width;
|
|
7893
|
+
var y = (e.y - this.store.data.origin.y) / scale / height;
|
|
7894
|
+
if (this.canvasImage.currentFit) {
|
|
7895
|
+
var fit = this.canvasImage.activeFit;
|
|
7896
|
+
if (this.canvasImage.currentFit === 'top') {
|
|
7897
|
+
if (y < -0.1) {
|
|
7898
|
+
y = -0.1;
|
|
7899
|
+
}
|
|
7900
|
+
var gap = y - fit.y;
|
|
7901
|
+
fit.height -= gap;
|
|
7902
|
+
if (fit.height < 0.01) {
|
|
7903
|
+
fit.height = 0.01;
|
|
7904
|
+
return;
|
|
7905
|
+
}
|
|
7906
|
+
fit.y = y;
|
|
7907
|
+
}
|
|
7908
|
+
if (this.canvasImage.currentFit === 'bottom') {
|
|
7909
|
+
if (y > 1.1) {
|
|
7910
|
+
y = 1.1;
|
|
7911
|
+
}
|
|
7912
|
+
fit.height = y - fit.y;
|
|
7913
|
+
if (fit.height <= 0.01) {
|
|
7914
|
+
fit.height = 0.01;
|
|
7915
|
+
}
|
|
7916
|
+
}
|
|
7917
|
+
if (this.canvasImage.currentFit === 'left') {
|
|
7918
|
+
if (x < -0.1) {
|
|
7919
|
+
x = -0.1;
|
|
7920
|
+
}
|
|
7921
|
+
var gap = x - fit.x;
|
|
7922
|
+
fit.width -= gap;
|
|
7923
|
+
if (fit.width < 0.01) {
|
|
7924
|
+
fit.width = 0.01;
|
|
7925
|
+
return;
|
|
7926
|
+
}
|
|
7927
|
+
fit.x = x;
|
|
7928
|
+
}
|
|
7929
|
+
if (this.canvasImage.currentFit === 'right') {
|
|
7930
|
+
if (x > 1.1) {
|
|
7931
|
+
x = 1.1;
|
|
7932
|
+
}
|
|
7933
|
+
fit.width = x - fit.x;
|
|
7934
|
+
if (fit.width <= 0.01) {
|
|
7935
|
+
fit.width = 0.01;
|
|
7936
|
+
}
|
|
7937
|
+
}
|
|
7938
|
+
var rect_2 = {
|
|
7939
|
+
x: fit.x * width * scale + this.store.data.origin.x,
|
|
7940
|
+
y: fit.y * height * scale + this.store.data.origin.y,
|
|
7941
|
+
width: fit.width * width * scale,
|
|
7942
|
+
height: fit.height * height * scale,
|
|
7943
|
+
};
|
|
7944
|
+
calcRightBottom(rect_2);
|
|
7945
|
+
var pens = this.store.data.pens.filter(function (pen) {
|
|
7946
|
+
if (
|
|
7947
|
+
// pen.locked >= LockState.DisableMove ||
|
|
7948
|
+
pen.parentId || pen.isRuleLine) {
|
|
7949
|
+
return false;
|
|
7950
|
+
}
|
|
7951
|
+
if (rectInRect(pen.calculative.worldRect, rect_2, true)) {
|
|
7952
|
+
if (pen.type === PenType.Line && !_this.store.options.dragAllIn) {
|
|
7953
|
+
return lineInRect(pen, rect_2);
|
|
7954
|
+
}
|
|
7955
|
+
return true;
|
|
7956
|
+
}
|
|
7957
|
+
});
|
|
7958
|
+
fit.left = undefined;
|
|
7959
|
+
fit.leftValue = undefined;
|
|
7960
|
+
fit.right = undefined;
|
|
7961
|
+
fit.rightValue = undefined;
|
|
7962
|
+
fit.top = undefined;
|
|
7963
|
+
fit.topValue = undefined;
|
|
7964
|
+
fit.bottom = undefined;
|
|
7965
|
+
fit.bottomValue = undefined;
|
|
7966
|
+
if (fit.width > 0.5) {
|
|
7967
|
+
fit.left = true;
|
|
7968
|
+
fit.right = true;
|
|
7969
|
+
fit.leftValue = (fit.x - 0) * scale * width;
|
|
7970
|
+
fit.rightValue = ((1 - (fit.x + fit.width)) * scale * width);
|
|
7971
|
+
}
|
|
7972
|
+
else {
|
|
7973
|
+
if (fit.x < 0.5) {
|
|
7974
|
+
fit.left = true;
|
|
7975
|
+
fit.leftValue = (fit.x - 0) * scale * width;
|
|
7976
|
+
}
|
|
7977
|
+
else {
|
|
7978
|
+
fit.right = true;
|
|
7979
|
+
fit.rightValue = ((1 - (fit.x + fit.width)) * scale * width);
|
|
7980
|
+
}
|
|
7981
|
+
}
|
|
7982
|
+
if (Math.abs(fit.leftValue) < 1) {
|
|
7983
|
+
fit.leftValue = 0;
|
|
7984
|
+
}
|
|
7985
|
+
if (Math.abs(fit.rightValue) < 1) {
|
|
7986
|
+
fit.rightValue = 0;
|
|
7987
|
+
}
|
|
7988
|
+
if (fit.height > 0.5) {
|
|
7989
|
+
fit.top = true;
|
|
7990
|
+
fit.bottom = true;
|
|
7991
|
+
fit.topValue = (fit.y - 0) * scale * height;
|
|
7992
|
+
fit.bottomValue = (1 - (fit.y + fit.height)) * scale * height;
|
|
7993
|
+
}
|
|
7994
|
+
else {
|
|
7995
|
+
if (fit.y < 0.5) {
|
|
7996
|
+
fit.top = true;
|
|
7997
|
+
fit.topValue = (fit.y - 0) * scale * height;
|
|
7998
|
+
}
|
|
7999
|
+
else {
|
|
8000
|
+
fit.bottom = true;
|
|
8001
|
+
fit.bottomValue = (1 - (fit.y + fit.height)) * scale * height;
|
|
8002
|
+
}
|
|
8003
|
+
}
|
|
8004
|
+
if (Math.abs(fit.topValue) < 1) {
|
|
8005
|
+
fit.topValue = 0;
|
|
8006
|
+
}
|
|
8007
|
+
if (Math.abs(fit.bottomValue) < 1) {
|
|
8008
|
+
fit.bottomValue = 0;
|
|
8009
|
+
}
|
|
8010
|
+
fit.children = pens.map(function (pen) { return pen.id; });
|
|
8011
|
+
this.store.emitter.emit('fit', fit);
|
|
8012
|
+
this.mouseDown.x = e.x;
|
|
8013
|
+
this.mouseDown.y = e.y;
|
|
8014
|
+
this.canvasImage.init();
|
|
8015
|
+
this.canvasImage.render();
|
|
8016
|
+
}
|
|
8017
|
+
};
|
|
8018
|
+
Canvas.prototype.updateFitRect = function (fit) {
|
|
8019
|
+
if (fit === void 0) { fit = this.canvasImage.activeFit; }
|
|
8020
|
+
var width = this.store.data.width || this.store.options.width;
|
|
8021
|
+
var height = this.store.data.height || this.store.options.height;
|
|
8022
|
+
if (fit.left) {
|
|
8023
|
+
if (fit.leftValue) {
|
|
8024
|
+
fit.x = Math.abs(fit.leftValue) < 1 ? fit.leftValue : fit.leftValue / width;
|
|
8025
|
+
}
|
|
8026
|
+
else {
|
|
8027
|
+
fit.x = 0;
|
|
8028
|
+
}
|
|
8029
|
+
}
|
|
8030
|
+
if (fit.right) {
|
|
8031
|
+
if (fit.rightValue) {
|
|
8032
|
+
fit.width = 1 - (Math.abs(fit.rightValue) < 1 ? fit.rightValue : fit.rightValue / width) - fit.x;
|
|
8033
|
+
}
|
|
8034
|
+
else {
|
|
8035
|
+
fit.width = 1 - fit.x;
|
|
8036
|
+
}
|
|
8037
|
+
}
|
|
8038
|
+
if (fit.top) {
|
|
8039
|
+
if (fit.topValue) {
|
|
8040
|
+
fit.y = Math.abs(fit.topValue) < 1 ? fit.topValue : fit.topValue / height;
|
|
8041
|
+
}
|
|
8042
|
+
else {
|
|
8043
|
+
fit.y = 0;
|
|
8044
|
+
}
|
|
8045
|
+
}
|
|
8046
|
+
if (fit.bottom) {
|
|
8047
|
+
if (fit.bottomValue) {
|
|
8048
|
+
fit.height = 1 - (Math.abs(fit.bottomValue) < 1 ? fit.bottomValue : fit.bottomValue / height) - fit.y;
|
|
8049
|
+
}
|
|
8050
|
+
else {
|
|
8051
|
+
fit.height = 1 - fit.y;
|
|
8052
|
+
}
|
|
8053
|
+
}
|
|
8054
|
+
this.canvasImage.init();
|
|
8055
|
+
this.canvasImage.render();
|
|
8056
|
+
};
|
|
8057
|
+
Canvas.prototype.deleteFit = function (fit) {
|
|
8058
|
+
if (fit === void 0) { fit = this.canvasImage.activeFit; }
|
|
8059
|
+
if (!fit) {
|
|
8060
|
+
return;
|
|
8061
|
+
}
|
|
8062
|
+
var index = this.store.data.fits.findIndex(function (item) { return item.id === fit.id; });
|
|
8063
|
+
this.store.data.fits.splice(index, 1);
|
|
8064
|
+
this.canvasImage.activeFit = undefined;
|
|
8065
|
+
this.canvasImage.init();
|
|
8066
|
+
this.canvasImage.render();
|
|
8067
|
+
this.store.emitter.emit('fit', undefined);
|
|
8068
|
+
};
|
|
8069
|
+
Canvas.prototype.calcuActiveFit = function () {
|
|
8070
|
+
var _a;
|
|
8071
|
+
var width = this.store.data.width || this.store.options.width;
|
|
8072
|
+
var height = this.store.data.height || this.store.options.height;
|
|
8073
|
+
var downX = (this.mouseDown.x - this.store.data.origin.x) / this.store.data.scale / width;
|
|
8074
|
+
var downY = (this.mouseDown.y - this.store.data.origin.y) / this.store.data.scale / height;
|
|
8075
|
+
var idx = -1;
|
|
8076
|
+
var lastActiveIdx = -1;
|
|
8077
|
+
(_a = this.store.data.fits) === null || _a === void 0 ? void 0 : _a.forEach(function (fit, index) {
|
|
8078
|
+
fit.ex = null;
|
|
8079
|
+
fit.ey = null;
|
|
8080
|
+
if (pointInRect({ x: downX, y: downY }, fit)) {
|
|
8081
|
+
idx = index;
|
|
8082
|
+
}
|
|
8083
|
+
;
|
|
8084
|
+
if (fit.active) {
|
|
8085
|
+
lastActiveIdx = index;
|
|
8086
|
+
}
|
|
8087
|
+
});
|
|
8088
|
+
if (idx !== -1 && idx !== lastActiveIdx) {
|
|
8089
|
+
this.canvasImage.activeFit = this.store.data.fits[idx];
|
|
8090
|
+
this.store.data.fits[idx].active = true;
|
|
8091
|
+
if (lastActiveIdx !== -1) {
|
|
8092
|
+
this.store.data.fits[lastActiveIdx].active = false;
|
|
8093
|
+
}
|
|
8094
|
+
this.store.emitter.emit('fit', this.store.data.fits[idx]);
|
|
8095
|
+
}
|
|
8096
|
+
else if (idx === -1 && lastActiveIdx !== -1) {
|
|
8097
|
+
this.store.data.fits[lastActiveIdx].active = false;
|
|
8098
|
+
this.store.emitter.emit('fit', undefined);
|
|
8099
|
+
this.canvasImage.activeFit = null;
|
|
8100
|
+
}
|
|
8101
|
+
this.inactive();
|
|
8102
|
+
this.canvasImage.init();
|
|
8103
|
+
this.canvasImage.render();
|
|
8104
|
+
};
|
|
7659
8105
|
Canvas.prototype.toggleMagnifier = function () {
|
|
7660
8106
|
this.magnifierCanvas.magnifier = !this.magnifierCanvas.magnifier;
|
|
7661
8107
|
if (this.magnifierCanvas.magnifier) {
|