@meta2d/core 1.0.52 → 1.0.54

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.
@@ -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':
@@ -811,6 +843,15 @@ var Canvas = /** @class */ (function () {
811
843
  this.calibrateMouse(pt);
812
844
  this.dropPens(obj, pt);
813
845
  this.addCaches = [];
846
+ // 拖拽新增图元判断是否是在容器上
847
+ this.getContainerHover(pt);
848
+ this.mousePos.x = pt.x;
849
+ this.mousePos.y = pt.y;
850
+ this.store.emitter.emit('mouseup', {
851
+ x: pt.x,
852
+ y: pt.y,
853
+ pen: this.store.hoverContainer,
854
+ });
814
855
  }
815
856
  this.store.emitter.emit('drop', obj || json);
816
857
  return [2 /*return*/];
@@ -991,6 +1032,13 @@ var Canvas = /** @class */ (function () {
991
1032
  _this.mousePos.y = e.y;
992
1033
  _this.mouseDown = e;
993
1034
  _this.lastMouseTime = performance.now();
1035
+ if (_this.canvasImage.fitFlag) {
1036
+ if (!_this.canvasImage.currentFit) {
1037
+ //选中布局容器
1038
+ _this.calcuActiveFit();
1039
+ }
1040
+ return;
1041
+ }
994
1042
  // Set anchor of pen.
995
1043
  if (_this.hotkeyType === HotkeyType.AddAnchor) {
996
1044
  _this.setAnchor(_this.store.pointAt);
@@ -1229,7 +1277,7 @@ var Canvas = /** @class */ (function () {
1229
1277
  _this.render();
1230
1278
  };
1231
1279
  this.onMouseMove = function (e) {
1232
- var _a, _b, _c, _d, _e, _f, _g;
1280
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1233
1281
  if (_this.store.data.locked === LockState.Disable) {
1234
1282
  _this.hoverType = HoverType.None;
1235
1283
  return;
@@ -1258,6 +1306,22 @@ var Canvas = /** @class */ (function () {
1258
1306
  _this.render();
1259
1307
  return;
1260
1308
  }
1309
+ if (_this.canvasImage.fitFlag) {
1310
+ if (_this.canvasImage.activeFit) {
1311
+ var now_2 = performance.now();
1312
+ if (now_2 - _this.fitTimer > 100) {
1313
+ if (_this.mouseDown) {
1314
+ // 容器大小变化
1315
+ _this.updateFit(e);
1316
+ }
1317
+ else {
1318
+ _this.inFitBorder(_this.mousePos);
1319
+ }
1320
+ _this.fitTimer = now_2;
1321
+ }
1322
+ return;
1323
+ }
1324
+ }
1261
1325
  if (_this.mouseDown && !_this.store.options.disableTranslate) {
1262
1326
  // 画布平移前提
1263
1327
  if (_this.mouseRight === MouseRight.Down) {
@@ -1311,7 +1375,7 @@ var Canvas = /** @class */ (function () {
1311
1375
  return;
1312
1376
  }
1313
1377
  // 框选
1314
- if (e.buttons === 1 && (e.ctrlKey || !_this.hoverType && !_this.hotkeyType)) {
1378
+ 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
1379
  _this.dragRect = {
1316
1380
  x: Math.min(_this.mouseDown.x, e.x),
1317
1381
  y: Math.min(_this.mouseDown.y, e.y),
@@ -1331,17 +1395,17 @@ var Canvas = /** @class */ (function () {
1331
1395
  _this.render();
1332
1396
  return;
1333
1397
  }
1334
- else if (!((_a = _this.store.active[0]) === null || _a === void 0 ? void 0 : _a.locked)) {
1398
+ else if (!((_b = _this.store.active[0]) === null || _b === void 0 ? void 0 : _b.locked)) {
1335
1399
  var pt = { x: e.x, y: e.y };
1336
1400
  // Move line anchor
1337
1401
  if (_this.hoverType === HoverType.LineAnchor) {
1338
- if ((_this.dockInAnchor(e) || ((_b = _this.store.active[0]) === null || _b === void 0 ? void 0 : _b.lineName) === 'line') &&
1402
+ if ((_this.dockInAnchor(e) || ((_c = _this.store.active[0]) === null || _c === void 0 ? void 0 : _c.lineName) === 'line') &&
1339
1403
  !_this.store.options.disableDock &&
1340
1404
  !_this.store.options.disableLineDock) {
1341
1405
  _this.clearDock();
1342
1406
  _this.dock = calcAnchorDock(_this.store, pt, _this.store.activeAnchor);
1343
- ((_c = _this.dock) === null || _c === void 0 ? void 0 : _c.xDock) && (pt.x += _this.dock.xDock.step);
1344
- ((_d = _this.dock) === null || _d === void 0 ? void 0 : _d.yDock) && (pt.y += _this.dock.yDock.step);
1407
+ ((_d = _this.dock) === null || _d === void 0 ? void 0 : _d.xDock) && (pt.x += _this.dock.xDock.step);
1408
+ ((_e = _this.dock) === null || _e === void 0 ? void 0 : _e.yDock) && (pt.y += _this.dock.yDock.step);
1345
1409
  }
1346
1410
  _this.moveLineAnchor(pt, e);
1347
1411
  return;
@@ -1381,7 +1445,7 @@ var Canvas = /** @class */ (function () {
1381
1445
  if (_this.store.active.length === 1) {
1382
1446
  var activePen = _this.store.active[0];
1383
1447
  if (activePen.locked === undefined || activePen.locked < LockState.DisableMove) {
1384
- (_e = activePen === null || activePen === void 0 ? void 0 : activePen.onMouseMove) === null || _e === void 0 ? void 0 : _e.call(activePen, activePen, _this.mousePos);
1448
+ (_f = activePen === null || activePen === void 0 ? void 0 : activePen.onMouseMove) === null || _f === void 0 ? void 0 : _f.call(activePen, activePen, _this.mousePos);
1385
1449
  }
1386
1450
  if (activePen.calculative.focus) {
1387
1451
  //执行图元的操作
@@ -1412,8 +1476,8 @@ var Canvas = /** @class */ (function () {
1412
1476
  !_this.store.options.disableLineDock) {
1413
1477
  _this.clearDock();
1414
1478
  _this.dock = calcAnchorDock(_this.store, pt);
1415
- ((_f = _this.dock) === null || _f === void 0 ? void 0 : _f.xDock) && (pt.x += _this.dock.xDock.step);
1416
- ((_g = _this.dock) === null || _g === void 0 ? void 0 : _g.yDock) && (pt.y += _this.dock.yDock.step);
1479
+ ((_g = _this.dock) === null || _g === void 0 ? void 0 : _g.xDock) && (pt.x += _this.dock.xDock.step);
1480
+ ((_h = _this.dock) === null || _h === void 0 ? void 0 : _h.yDock) && (pt.y += _this.dock.yDock.step);
1417
1481
  }
1418
1482
  if (_this.mouseDown &&
1419
1483
  _this.drawingLineName === 'curve' &&
@@ -1642,22 +1706,27 @@ var Canvas = /** @class */ (function () {
1642
1706
  });
1643
1707
  _this.patchFlagsLines.clear();
1644
1708
  if (_this.dragRect) {
1645
- var pens = _this.store.data.pens.filter(function (pen) {
1646
- if (pen.visible === false ||
1647
- pen.locked >= LockState.DisableMove ||
1648
- pen.parentId || pen.isRuleLine) {
1649
- return false;
1650
- }
1651
- if (rectInRect(pen.calculative.worldRect, _this.dragRect, e.ctrlKey || _this.store.options.dragAllIn)) {
1652
- // 先判断在区域内,若不在区域内,则锚点肯定不在框选区域内,避免每条连线过度计算
1653
- if (pen.type === PenType.Line && !_this.store.options.dragAllIn) {
1654
- return lineInRect(pen, _this.dragRect);
1709
+ if (_this.canvasImage.fitFlag) {
1710
+ _this.makeFit();
1711
+ }
1712
+ else {
1713
+ var pens = _this.store.data.pens.filter(function (pen) {
1714
+ if (pen.visible === false ||
1715
+ pen.locked >= LockState.DisableMove ||
1716
+ pen.parentId || pen.isRuleLine) {
1717
+ return false;
1718
+ }
1719
+ if (rectInRect(pen.calculative.worldRect, _this.dragRect, e.ctrlKey || _this.store.options.dragAllIn)) {
1720
+ // 先判断在区域内,若不在区域内,则锚点肯定不在框选区域内,避免每条连线过度计算
1721
+ if (pen.type === PenType.Line && !_this.store.options.dragAllIn) {
1722
+ return lineInRect(pen, _this.dragRect);
1723
+ }
1724
+ return true;
1655
1725
  }
1656
- return true;
1657
- }
1658
- });
1659
- //框选
1660
- _this.active(pens);
1726
+ });
1727
+ //框选
1728
+ _this.active(pens);
1729
+ }
1661
1730
  }
1662
1731
  if (e.button !== 2) {
1663
1732
  if (distance(_this.mouseDown, e) < 2) {
@@ -1673,11 +1742,13 @@ var Canvas = /** @class */ (function () {
1673
1742
  if (_this.store.hover) {
1674
1743
  _this.store.hover.calculative.mouseDown = false;
1675
1744
  }
1676
- _this.store.emitter.emit('mouseup', {
1677
- x: e.x,
1678
- y: e.y,
1679
- pen: _this.store.hover,
1680
- });
1745
+ if (_this.store.hover != _this.store.hoverContainer) {
1746
+ _this.store.emitter.emit('mouseup', {
1747
+ x: e.x,
1748
+ y: e.y,
1749
+ pen: _this.store.hover,
1750
+ });
1751
+ }
1681
1752
  _this.store.emitter.emit('mouseup', {
1682
1753
  x: e.x,
1683
1754
  y: e.y,
@@ -1687,7 +1758,10 @@ var Canvas = /** @class */ (function () {
1687
1758
  if (_this.willInactivePen) {
1688
1759
  _this.willInactivePen.calculative.active = undefined;
1689
1760
  setChildrenActive(_this.willInactivePen, false); // 子节点取消激活
1690
- _this.store.active.splice(_this.store.active.findIndex(function (p) { return p === _this.willInactivePen; }), 1);
1761
+ var index = _this.store.active.findIndex(function (p) { return p === _this.willInactivePen; });
1762
+ if (index >= 0) {
1763
+ _this.store.active.splice(index, 1);
1764
+ }
1691
1765
  _this.calcActiveRect();
1692
1766
  _this.willInactivePen = undefined;
1693
1767
  _this.store.emitter.emit('inactive', [_this.willInactivePen]);
@@ -1765,8 +1839,7 @@ var Canvas = /** @class */ (function () {
1765
1839
  var pen = containerPens[i];
1766
1840
  if (pen.visible == false ||
1767
1841
  pen.calculative.inView == false ||
1768
- pen.locked === LockState.Disable ||
1769
- pen.calculative.active) {
1842
+ pen.locked === LockState.Disable) {
1770
1843
  continue;
1771
1844
  }
1772
1845
  if (pointInRect(pt, pen.calculative.worldRect)) {
@@ -1789,7 +1862,8 @@ var Canvas = /** @class */ (function () {
1789
1862
  _this.store.hoverContainer = undefined;
1790
1863
  if (_this.store.lastHoverContainer !== _this.store.hoverContainer) {
1791
1864
  _this.patchFlags = true;
1792
- if (_this.store.lastHoverContainer) {
1865
+ var movingPen = _this.store.lastHoverContainer.calculative.canvas.store.pens[_this.store.lastHoverContainer.id + movingSuffix];
1866
+ if (_this.store.lastHoverContainer && !movingPen) {
1793
1867
  _this.store.lastHoverContainer.calculative.containerHover = false;
1794
1868
  _this.store.emitter.emit('leave', _this.store.lastHoverContainer);
1795
1869
  }
@@ -1804,6 +1878,9 @@ var Canvas = /** @class */ (function () {
1804
1878
  if (_this.dragRect) {
1805
1879
  return;
1806
1880
  }
1881
+ if (_this.canvasImage.fitFlag) {
1882
+ return;
1883
+ }
1807
1884
  var hoverType = HoverType.None;
1808
1885
  _this.store.hover = undefined;
1809
1886
  _this.store.hoverAnchor = undefined;
@@ -2838,6 +2915,7 @@ var Canvas = /** @class */ (function () {
2838
2915
  pens: [deepClone(pen, true)],
2839
2916
  initPens: initPens,
2840
2917
  });
2918
+ _this.store.emitter.emit('change', pen);
2841
2919
  _this.store.emitter.emit('valueUpdate', pen);
2842
2920
  }
2843
2921
  else if (pen.text === _this.inputDiv.dataset.value && pen.calculative.textLines.length == 0) {
@@ -2944,8 +3022,39 @@ var Canvas = /** @class */ (function () {
2944
3022
  initPens: initPens,
2945
3023
  });
2946
3024
  _this.render();
3025
+ _this.store.emitter.emit('change', pen);
2947
3026
  _this.store.emitter.emit('valueUpdate', pen);
2948
3027
  };
3028
+ this.inFitBorder = function (pt) {
3029
+ var current = undefined;
3030
+ var width = (_this.store.data.width || _this.store.options.width);
3031
+ var height = (_this.store.data.height || _this.store.options.height);
3032
+ var point = {
3033
+ x: (pt.x - _this.store.data.origin.x) / _this.store.data.scale,
3034
+ y: (pt.y - _this.store.data.origin.y) / _this.store.data.scale,
3035
+ };
3036
+ var fit = _this.canvasImage.activeFit;
3037
+ // if (pointInRect(point, { x:fit.x-0.01, y:0, width, height })) {
3038
+ _this.externalElements.style.cursor = 'default';
3039
+ if (point.y > height * fit.y - 10 && point.y < height * fit.y + 10) {
3040
+ current = 'top';
3041
+ _this.externalElements.style.cursor = 'row-resize';
3042
+ }
3043
+ if (point.y > height * (fit.y + fit.height) - 10 && point.y < height * (fit.y + fit.height) + 10) {
3044
+ current = 'bottom';
3045
+ _this.externalElements.style.cursor = 'row-resize';
3046
+ }
3047
+ if (point.x > width * fit.x - 10 && point.x < width * fit.x) {
3048
+ current = 'left';
3049
+ _this.externalElements.style.cursor = 'col-resize';
3050
+ }
3051
+ if (point.x > width * (fit.x + fit.width) - 10 && point.x < width * (fit.x + fit.width) + 10) {
3052
+ current = 'right';
3053
+ _this.externalElements.style.cursor = 'col-resize';
3054
+ }
3055
+ // }
3056
+ _this.canvasImage.currentFit = current;
3057
+ };
2949
3058
  this.canvasTemplate = new CanvasTemplate(parentElement, store);
2950
3059
  this.canvasTemplate.canvas.style.zIndex = '1';
2951
3060
  this.canvasImageBottom = new CanvasImage(parentElement, store, true);
@@ -3286,14 +3395,14 @@ var Canvas = /** @class */ (function () {
3286
3395
  }
3287
3396
  if (pen.dataset) {
3288
3397
  if (num % 2 === 0) {
3289
- lastW = pen.width - 40;
3398
+ lastW = pen.width - 40 * this.store.data.scale;
3290
3399
  }
3291
3400
  else {
3292
3401
  lastW = 0;
3293
3402
  }
3294
3403
  num++;
3295
3404
  if (num % 2 === 0) {
3296
- lastH += pen.height + 10;
3405
+ lastH += pen.height + 10 * this.store.data.scale;
3297
3406
  }
3298
3407
  }
3299
3408
  }
@@ -3687,6 +3796,7 @@ var Canvas = /** @class */ (function () {
3687
3796
  pen.calculative.initRect.ey =
3688
3797
  pen.calculative.y + pen.calculative.height;
3689
3798
  }
3799
+ calcChildrenInitRect(pen);
3690
3800
  });
3691
3801
  // active 消息表示拖拽结束
3692
3802
  // this.store.emitter.emit('active', this.store.active);
@@ -4292,8 +4402,8 @@ var Canvas = /** @class */ (function () {
4292
4402
  if (_this.store.data.pens[i].type &&
4293
4403
  _this.store.data.pens[i].lastConnected) {
4294
4404
  for (var key in _this.store.data.pens[i].lastConnected) {
4295
- _this.store.pens[key].connectedLines =
4296
- _this.store.data.pens[i].lastConnected[key];
4405
+ _this.store.pens[key] && (_this.store.pens[key].connectedLines =
4406
+ _this.store.data.pens[i].lastConnected[key]);
4297
4407
  }
4298
4408
  }
4299
4409
  _this.store.data.pens[i] = pen;
@@ -4333,7 +4443,7 @@ var Canvas = /** @class */ (function () {
4333
4443
  _this.store.pens[pen.id] = pen;
4334
4444
  if (pen.type && pen.lastConnected) {
4335
4445
  for (var key in pen.lastConnected) {
4336
- _this.store.pens[key].connectedLines = pen.lastConnected[key];
4446
+ _this.store.pens[key] && (_this.store.pens[key].connectedLines = pen.lastConnected[key]);
4337
4447
  }
4338
4448
  }
4339
4449
  pen.calculative.canvas = _this;
@@ -4385,7 +4495,7 @@ var Canvas = /** @class */ (function () {
4385
4495
  _this.store.pens[pen.id] = pen;
4386
4496
  if (pen.type && pen.lastConnected) {
4387
4497
  for (var key in pen.lastConnected) {
4388
- _this.store.pens[key].connectedLines = pen.lastConnected[key];
4498
+ _this.store.pens[key] && (_this.store.pens[key].connectedLines = pen.lastConnected[key]);
4389
4499
  }
4390
4500
  }
4391
4501
  pen.calculative.canvas = _this;
@@ -6019,7 +6129,7 @@ var Canvas = /** @class */ (function () {
6019
6129
  if (!pen.connectedLines) {
6020
6130
  return;
6021
6131
  }
6022
- pen.connectedLines.forEach(function (item) {
6132
+ pen.connectedLines.forEach(function (item, index) {
6023
6133
  var line = _this.store.pens[item.lineId];
6024
6134
  // 活动层的线不需要更新,会在活动层处理
6025
6135
  if (!line || line.calculative.active) {
@@ -6029,6 +6139,11 @@ var Canvas = /** @class */ (function () {
6029
6139
  if (!lineAnchor) {
6030
6140
  return;
6031
6141
  }
6142
+ if (!lineAnchor.connectTo) {
6143
+ // 如果pen有连接关系但连线中没有连接关系,删除pen的连接关系
6144
+ pen.connectedLines.splice(index, 1);
6145
+ return;
6146
+ }
6032
6147
  if (line.autoFrom) {
6033
6148
  var from = getFromAnchor(line);
6034
6149
  if (from.id === lineAnchor.id) {
@@ -6987,6 +7102,7 @@ var Canvas = /** @class */ (function () {
6987
7102
  _this.inputDiv.style.paddingTop = '';
6988
7103
  }
6989
7104
  }
7105
+ _this.store.emitter.emit('input', pen);
6990
7106
  };
6991
7107
  this.inputDiv.onclick = function (e) {
6992
7108
  e.stopPropagation();
@@ -7061,7 +7177,7 @@ var Canvas = /** @class */ (function () {
7061
7177
  };
7062
7178
  Canvas.prototype.changePenId = function (oldId, newId) {
7063
7179
  var _this = this;
7064
- var _a, _b, _c, _d, _e;
7180
+ var _a, _b, _c, _d, _e, _f, _g;
7065
7181
  if (oldId === newId) {
7066
7182
  return;
7067
7183
  }
@@ -7101,6 +7217,9 @@ var Canvas = /** @class */ (function () {
7101
7217
  calcWorldAnchors(line);
7102
7218
  });
7103
7219
  }
7220
+ //锚点
7221
+ (_f = pen.anchors) === null || _f === void 0 ? void 0 : _f.forEach(function (anchor) { return anchor.penId = newId; });
7222
+ (_g = pen.calculative.worldAnchors) === null || _g === void 0 ? void 0 : _g.forEach(function (anchor) { return anchor.penId = newId; });
7104
7223
  };
7105
7224
  Canvas.prototype.updateValue = function (pen, data) {
7106
7225
  var _a, _b, _c, _d, _e, _f;
@@ -7638,6 +7757,17 @@ var Canvas = /** @class */ (function () {
7638
7757
  if (!isFinite(rect.width)) {
7639
7758
  throw new Error('can not move view, because width is not finite');
7640
7759
  }
7760
+ var width = this.store.data.width || this.store.options.width;
7761
+ var height = this.store.data.height || this.store.options.height;
7762
+ if (width && height) {
7763
+ //大屏
7764
+ rect = {
7765
+ x: this.store.data.origin.x,
7766
+ y: this.store.data.origin.y,
7767
+ width: width * this.store.data.scale,
7768
+ height: height * this.store.data.scale,
7769
+ };
7770
+ }
7641
7771
  this.store.data.x = this.canvas.clientWidth / 2 - x * rect.width - rect.x;
7642
7772
  this.store.data.y = this.canvas.clientHeight / 2 - y * rect.height - rect.y;
7643
7773
  this.onMovePens();
@@ -7656,6 +7786,341 @@ var Canvas = /** @class */ (function () {
7656
7786
  this.externalElements.style.cursor = 'default';
7657
7787
  this.render();
7658
7788
  };
7789
+ Canvas.prototype.showFit = function () {
7790
+ this.store.data.locked = 0;
7791
+ this.canvasImage.fitFlag = true;
7792
+ this.canvasImage.activeFit = undefined;
7793
+ this.canvasImage.currentFit = undefined;
7794
+ if (!this.store.data.fits) {
7795
+ this.store.data.fits = [];
7796
+ }
7797
+ this.store.data.fits.forEach(function (fit) { return fit.active = false; });
7798
+ this.canvasImage.init();
7799
+ this.canvasImage.render();
7800
+ };
7801
+ Canvas.prototype.hideFit = function () {
7802
+ this.canvasImage.fitFlag = false;
7803
+ this.canvasImage.activeFit = undefined;
7804
+ this.canvasImage.currentFit = undefined;
7805
+ this.canvasImage.init();
7806
+ this.canvasImage.render();
7807
+ };
7808
+ Canvas.prototype.makeFit = function () {
7809
+ var _this = this;
7810
+ if (this.dragRect.width < 100 && this.dragRect.height < 100) {
7811
+ return;
7812
+ }
7813
+ //将所有当前框选的图元设置到该容器中
7814
+ var pens = this.store.data.pens.filter(function (pen) {
7815
+ if (
7816
+ // pen.locked >= LockState.DisableMove ||
7817
+ pen.parentId || pen.isRuleLine) {
7818
+ return false;
7819
+ }
7820
+ if (rectInRect(pen.calculative.worldRect, _this.dragRect, true)) {
7821
+ // 先判断在区域内,若不在区域内,则锚点肯定不在框选区域内,避免每条连线过度计算
7822
+ if (pen.type === PenType.Line && !_this.store.options.dragAllIn) {
7823
+ return lineInRect(pen, _this.dragRect);
7824
+ }
7825
+ return true;
7826
+ }
7827
+ });
7828
+ if (!pens.length) {
7829
+ return;
7830
+ }
7831
+ var _rect = this.parent.getRect(pens);
7832
+ var scale = this.store.data.scale;
7833
+ var width = this.store.data.width || this.store.options.width;
7834
+ var height = this.store.data.height || this.store.options.height;
7835
+ var x = (Math.floor(_rect.x) - this.store.data.origin.x) / scale / width;
7836
+ var y = (Math.floor(_rect.y) - this.store.data.origin.y) / scale / height;
7837
+ var rect = {
7838
+ x: x,
7839
+ y: y,
7840
+ width: (Math.ceil(_rect.width) + 1) / scale / width,
7841
+ height: (Math.ceil(_rect.height) + 1) / scale / height,
7842
+ children: pens.map(function (pen) { return pen.id; }),
7843
+ id: s8(),
7844
+ active: true
7845
+ };
7846
+ if (rect.x < -0.1) {
7847
+ rect.x = -0.1;
7848
+ }
7849
+ if (rect.y < -0.1) {
7850
+ rect.y = -0.1;
7851
+ }
7852
+ if (rect.width > 0.5) {
7853
+ rect.left = true;
7854
+ rect.right = true;
7855
+ rect.leftValue = (rect.x - 0) * scale * width;
7856
+ rect.rightValue = (1 - (rect.x + rect.width)) * scale * width;
7857
+ }
7858
+ else {
7859
+ if (rect.x < 0.5) {
7860
+ rect.left = true;
7861
+ rect.leftValue = (rect.x - 0) * scale * width;
7862
+ }
7863
+ else {
7864
+ rect.right = true;
7865
+ rect.rightValue = (1 - (rect.x + rect.width)) * scale * width;
7866
+ }
7867
+ }
7868
+ if (rect.leftValue < 1) {
7869
+ rect.leftValue = 0;
7870
+ }
7871
+ if (rect.rightValue < 1) {
7872
+ rect.rightValue = 0;
7873
+ }
7874
+ if (rect.height > 0.5) {
7875
+ rect.top = true;
7876
+ rect.bottom = true;
7877
+ rect.topValue = (rect.y - 0) * scale * height;
7878
+ rect.bottomValue = (1 - (rect.y + rect.height)) * scale * height;
7879
+ }
7880
+ else {
7881
+ if (rect.y < 0.5) {
7882
+ rect.top = true;
7883
+ rect.topValue = (rect.y - 0) * scale * height;
7884
+ }
7885
+ else {
7886
+ rect.bottom = true;
7887
+ rect.bottomValue = (1 - (rect.y + rect.height)) * scale * height;
7888
+ }
7889
+ }
7890
+ if (rect.topValue < 1) {
7891
+ rect.topValue = 0;
7892
+ }
7893
+ if (rect.bottomValue < 1) {
7894
+ rect.bottomValue = 0;
7895
+ }
7896
+ if (!this.store.data.fits) {
7897
+ this.store.data.fits = [];
7898
+ }
7899
+ this.store.data.fits.forEach(function (fit) { fit.active = false; });
7900
+ this.store.data.fits.push(rect);
7901
+ this.canvasImage.activeFit = rect;
7902
+ this.store.emitter.emit('fit', rect);
7903
+ this.canvasImage.init();
7904
+ this.canvasImage.render();
7905
+ };
7906
+ Canvas.prototype.updateFit = function (e) {
7907
+ var _this = this;
7908
+ var scale = this.store.data.scale;
7909
+ var width = this.store.data.width || this.store.options.width;
7910
+ var height = this.store.data.height || this.store.options.height;
7911
+ var x = (e.x - this.store.data.origin.x) / scale / width;
7912
+ var y = (e.y - this.store.data.origin.y) / scale / height;
7913
+ if (this.canvasImage.currentFit) {
7914
+ var fit = this.canvasImage.activeFit;
7915
+ if (this.canvasImage.currentFit === 'top') {
7916
+ if (y < -0.1) {
7917
+ y = -0.1;
7918
+ }
7919
+ var gap = y - fit.y;
7920
+ fit.height -= gap;
7921
+ if (fit.height < 0.01) {
7922
+ fit.height = 0.01;
7923
+ return;
7924
+ }
7925
+ fit.y = y;
7926
+ }
7927
+ if (this.canvasImage.currentFit === 'bottom') {
7928
+ if (y > 1.1) {
7929
+ y = 1.1;
7930
+ }
7931
+ fit.height = y - fit.y;
7932
+ if (fit.height <= 0.01) {
7933
+ fit.height = 0.01;
7934
+ }
7935
+ }
7936
+ if (this.canvasImage.currentFit === 'left') {
7937
+ if (x < -0.1) {
7938
+ x = -0.1;
7939
+ }
7940
+ var gap = x - fit.x;
7941
+ fit.width -= gap;
7942
+ if (fit.width < 0.01) {
7943
+ fit.width = 0.01;
7944
+ return;
7945
+ }
7946
+ fit.x = x;
7947
+ }
7948
+ if (this.canvasImage.currentFit === 'right') {
7949
+ if (x > 1.1) {
7950
+ x = 1.1;
7951
+ }
7952
+ fit.width = x - fit.x;
7953
+ if (fit.width <= 0.01) {
7954
+ fit.width = 0.01;
7955
+ }
7956
+ }
7957
+ var rect_2 = {
7958
+ x: fit.x * width * scale + this.store.data.origin.x,
7959
+ y: fit.y * height * scale + this.store.data.origin.y,
7960
+ width: fit.width * width * scale,
7961
+ height: fit.height * height * scale,
7962
+ };
7963
+ calcRightBottom(rect_2);
7964
+ var pens = this.store.data.pens.filter(function (pen) {
7965
+ if (
7966
+ // pen.locked >= LockState.DisableMove ||
7967
+ pen.parentId || pen.isRuleLine) {
7968
+ return false;
7969
+ }
7970
+ if (rectInRect(pen.calculative.worldRect, rect_2, true)) {
7971
+ if (pen.type === PenType.Line && !_this.store.options.dragAllIn) {
7972
+ return lineInRect(pen, rect_2);
7973
+ }
7974
+ return true;
7975
+ }
7976
+ });
7977
+ fit.left = undefined;
7978
+ fit.leftValue = undefined;
7979
+ fit.right = undefined;
7980
+ fit.rightValue = undefined;
7981
+ fit.top = undefined;
7982
+ fit.topValue = undefined;
7983
+ fit.bottom = undefined;
7984
+ fit.bottomValue = undefined;
7985
+ if (fit.width > 0.5) {
7986
+ fit.left = true;
7987
+ fit.right = true;
7988
+ fit.leftValue = (fit.x - 0) * scale * width;
7989
+ fit.rightValue = ((1 - (fit.x + fit.width)) * scale * width);
7990
+ }
7991
+ else {
7992
+ if (fit.x < 0.5) {
7993
+ fit.left = true;
7994
+ fit.leftValue = (fit.x - 0) * scale * width;
7995
+ }
7996
+ else {
7997
+ fit.right = true;
7998
+ fit.rightValue = ((1 - (fit.x + fit.width)) * scale * width);
7999
+ }
8000
+ }
8001
+ if (Math.abs(fit.leftValue) < 1) {
8002
+ fit.leftValue = 0;
8003
+ }
8004
+ if (Math.abs(fit.rightValue) < 1) {
8005
+ fit.rightValue = 0;
8006
+ }
8007
+ if (fit.height > 0.5) {
8008
+ fit.top = true;
8009
+ fit.bottom = true;
8010
+ fit.topValue = (fit.y - 0) * scale * height;
8011
+ fit.bottomValue = (1 - (fit.y + fit.height)) * scale * height;
8012
+ }
8013
+ else {
8014
+ if (fit.y < 0.5) {
8015
+ fit.top = true;
8016
+ fit.topValue = (fit.y - 0) * scale * height;
8017
+ }
8018
+ else {
8019
+ fit.bottom = true;
8020
+ fit.bottomValue = (1 - (fit.y + fit.height)) * scale * height;
8021
+ }
8022
+ }
8023
+ if (Math.abs(fit.topValue) < 1) {
8024
+ fit.topValue = 0;
8025
+ }
8026
+ if (Math.abs(fit.bottomValue) < 1) {
8027
+ fit.bottomValue = 0;
8028
+ }
8029
+ fit.children = pens.map(function (pen) { return pen.id; });
8030
+ this.store.emitter.emit('fit', fit);
8031
+ this.mouseDown.x = e.x;
8032
+ this.mouseDown.y = e.y;
8033
+ this.canvasImage.init();
8034
+ this.canvasImage.render();
8035
+ }
8036
+ };
8037
+ Canvas.prototype.updateFitRect = function (fit) {
8038
+ if (fit === void 0) { fit = this.canvasImage.activeFit; }
8039
+ var width = this.store.data.width || this.store.options.width;
8040
+ var height = this.store.data.height || this.store.options.height;
8041
+ if (fit.left) {
8042
+ if (fit.leftValue) {
8043
+ fit.x = Math.abs(fit.leftValue) < 1 ? fit.leftValue : fit.leftValue / width;
8044
+ }
8045
+ else {
8046
+ fit.x = 0;
8047
+ }
8048
+ }
8049
+ if (fit.right) {
8050
+ if (fit.rightValue) {
8051
+ fit.width = 1 - (Math.abs(fit.rightValue) < 1 ? fit.rightValue : fit.rightValue / width) - fit.x;
8052
+ }
8053
+ else {
8054
+ fit.width = 1 - fit.x;
8055
+ }
8056
+ }
8057
+ if (fit.top) {
8058
+ if (fit.topValue) {
8059
+ fit.y = Math.abs(fit.topValue) < 1 ? fit.topValue : fit.topValue / height;
8060
+ }
8061
+ else {
8062
+ fit.y = 0;
8063
+ }
8064
+ }
8065
+ if (fit.bottom) {
8066
+ if (fit.bottomValue) {
8067
+ fit.height = 1 - (Math.abs(fit.bottomValue) < 1 ? fit.bottomValue : fit.bottomValue / height) - fit.y;
8068
+ }
8069
+ else {
8070
+ fit.height = 1 - fit.y;
8071
+ }
8072
+ }
8073
+ this.canvasImage.init();
8074
+ this.canvasImage.render();
8075
+ };
8076
+ Canvas.prototype.deleteFit = function (fit) {
8077
+ if (fit === void 0) { fit = this.canvasImage.activeFit; }
8078
+ if (!fit) {
8079
+ return;
8080
+ }
8081
+ var index = this.store.data.fits.findIndex(function (item) { return item.id === fit.id; });
8082
+ this.store.data.fits.splice(index, 1);
8083
+ this.canvasImage.activeFit = undefined;
8084
+ this.canvasImage.init();
8085
+ this.canvasImage.render();
8086
+ this.store.emitter.emit('fit', undefined);
8087
+ };
8088
+ Canvas.prototype.calcuActiveFit = function () {
8089
+ var _a;
8090
+ var width = this.store.data.width || this.store.options.width;
8091
+ var height = this.store.data.height || this.store.options.height;
8092
+ var downX = (this.mouseDown.x - this.store.data.origin.x) / this.store.data.scale / width;
8093
+ var downY = (this.mouseDown.y - this.store.data.origin.y) / this.store.data.scale / height;
8094
+ var idx = -1;
8095
+ var lastActiveIdx = -1;
8096
+ (_a = this.store.data.fits) === null || _a === void 0 ? void 0 : _a.forEach(function (fit, index) {
8097
+ fit.ex = null;
8098
+ fit.ey = null;
8099
+ if (pointInRect({ x: downX, y: downY }, fit)) {
8100
+ idx = index;
8101
+ }
8102
+ ;
8103
+ if (fit.active) {
8104
+ lastActiveIdx = index;
8105
+ }
8106
+ });
8107
+ if (idx !== -1 && idx !== lastActiveIdx) {
8108
+ this.canvasImage.activeFit = this.store.data.fits[idx];
8109
+ this.store.data.fits[idx].active = true;
8110
+ if (lastActiveIdx !== -1) {
8111
+ this.store.data.fits[lastActiveIdx].active = false;
8112
+ }
8113
+ this.store.emitter.emit('fit', this.store.data.fits[idx]);
8114
+ }
8115
+ else if (idx === -1 && lastActiveIdx !== -1) {
8116
+ this.store.data.fits[lastActiveIdx].active = false;
8117
+ this.store.emitter.emit('fit', undefined);
8118
+ this.canvasImage.activeFit = null;
8119
+ }
8120
+ this.inactive();
8121
+ this.canvasImage.init();
8122
+ this.canvasImage.render();
8123
+ };
7659
8124
  Canvas.prototype.toggleMagnifier = function () {
7660
8125
  this.magnifierCanvas.magnifier = !this.magnifierCanvas.magnifier;
7661
8126
  if (this.magnifierCanvas.magnifier) {