@meta2d/core 1.0.20 → 1.0.22

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meta2d/core",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "description": "@meta2d/core: Powerful, Beautiful, Simple, Open - Web-Based 2D At Its Best .",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -75,7 +75,7 @@ export declare class Canvas {
75
75
  renderTimer: number;
76
76
  initPens?: Pen[];
77
77
  pointSize: 8;
78
- pasteOffset: number;
78
+ pasteOffset: boolean;
79
79
  opening: boolean;
80
80
  maxZindex: number;
81
81
  canMoveLine: boolean;
@@ -108,6 +108,7 @@ export declare class Canvas {
108
108
  canvasImageBottom: CanvasImage;
109
109
  magnifierCanvas: MagnifierCanvas;
110
110
  dialog: Dialog;
111
+ autoPolylineFlag: boolean;
111
112
  stopPropagation: (e: MouseEvent) => void;
112
113
  constructor(parent: Meta2d, parentElement: HTMLElement, store: Meta2dStore);
113
114
  curve: typeof curve;
@@ -83,7 +83,7 @@ var __values = (this && this.__values) || function(o) {
83
83
  };
84
84
  import { KeydownType } from '../options';
85
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, } from '../pen';
86
- import { calcRotate, distance, hitPoint, PrevNextType, rotatePoint, samePoint, scalePoint, translatePoint, TwoWay, } from '../point';
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';
89
89
  import { deepClone, fileToBase64, uploadFile, formatPadding, rgba, s8, } from '../utils';
@@ -124,7 +124,7 @@ var Canvas = /** @class */ (function () {
124
124
  this.lastAnimateRender = 0;
125
125
  this.animateRendering = false;
126
126
  this.pointSize = 8;
127
- this.pasteOffset = 10;
127
+ this.pasteOffset = true;
128
128
  this.opening = false;
129
129
  this.maxZindex = 4;
130
130
  this.canMoveLine = false; //moveConnectedLine=false
@@ -134,6 +134,7 @@ var Canvas = /** @class */ (function () {
134
134
  this.inputRight = document.createElement('div');
135
135
  this.dropdown = document.createElement('ul');
136
136
  this.mousePos = { x: 0, y: 0 };
137
+ this.autoPolylineFlag = false; //标记open不自动计算
137
138
  this.stopPropagation = function (e) {
138
139
  e.stopPropagation();
139
140
  };
@@ -630,7 +631,7 @@ var Canvas = /** @class */ (function () {
630
631
  obj = _a.sent();
631
632
  return [3 /*break*/, 3];
632
633
  case 2:
633
- if (this.addCaches.length) {
634
+ if (this.addCaches && this.addCaches.length) {
634
635
  obj = this.addCaches;
635
636
  this.addCaches = [];
636
637
  }
@@ -864,8 +865,13 @@ var Canvas = /** @class */ (function () {
864
865
  // 单击在锚点上,完成绘画
865
866
  if (_this.store.hoverAnchor) {
866
867
  var to_1 = getToAnchor(_this.drawingLine);
867
- to_1.x = _this.store.hoverAnchor.x;
868
- to_1.y = _this.store.hoverAnchor.y;
868
+ if (_this.store.hoverAnchor.type === PointType.Line) {
869
+ getDistance(to_1, _this.store.hoverAnchor, _this.store);
870
+ }
871
+ else {
872
+ to_1.x = _this.store.hoverAnchor.x;
873
+ to_1.y = _this.store.hoverAnchor.y;
874
+ }
869
875
  connectLine(_this.store.hover, _this.store.hoverAnchor, _this.drawingLine, to_1);
870
876
  _this.drawline();
871
877
  _this.finishDrawline(true);
@@ -1249,8 +1255,10 @@ var Canvas = /** @class */ (function () {
1249
1255
  }
1250
1256
  if (_this.hoverType === HoverType.NodeAnchor ||
1251
1257
  _this.hoverType === HoverType.LineAnchor) {
1252
- to.x = _this.store.hoverAnchor.x;
1253
- to.y = _this.store.hoverAnchor.y;
1258
+ if (_this.store.hoverAnchor.type !== PointType.Line) {
1259
+ to.x = _this.store.hoverAnchor.x;
1260
+ to.y = _this.store.hoverAnchor.y;
1261
+ }
1254
1262
  to.connectTo = _this.store.hoverAnchor.penId;
1255
1263
  if (_this.drawingLineName === 'polyline') {
1256
1264
  to.isTemp = false;
@@ -1309,8 +1317,13 @@ var Canvas = /** @class */ (function () {
1309
1317
  // 在锚点上,完成绘画
1310
1318
  if (_this.store.hoverAnchor) {
1311
1319
  var to = getToAnchor(_this.drawingLine);
1312
- to.x = _this.store.hoverAnchor.x;
1313
- to.y = _this.store.hoverAnchor.y;
1320
+ if (_this.store.hoverAnchor.type === PointType.Line) {
1321
+ getDistance(to, _this.store.hoverAnchor, _this.store);
1322
+ }
1323
+ else {
1324
+ to.x = _this.store.hoverAnchor.x;
1325
+ to.y = _this.store.hoverAnchor.y;
1326
+ }
1314
1327
  connectLine(_this.store.hover, _this.store.hoverAnchor, _this.drawingLine, to);
1315
1328
  _this.drawline();
1316
1329
  _this.finishDrawline(true);
@@ -1376,8 +1389,16 @@ var Canvas = /** @class */ (function () {
1376
1389
  else {
1377
1390
  // 连接连线
1378
1391
  if (_this.store.activeAnchor) {
1379
- _this.store.activeAnchor.x = _this.store.hoverAnchor.x;
1380
- _this.store.activeAnchor.y = _this.store.hoverAnchor.y;
1392
+ /**
1393
+ * 线的锚点需要存所连接锚点的位置
1394
+ */
1395
+ if (_this.store.hoverAnchor.type === PointType.Line) {
1396
+ getDistance(_this.store.activeAnchor, _this.store.hoverAnchor, _this.store);
1397
+ }
1398
+ else {
1399
+ _this.store.activeAnchor.x = _this.store.hoverAnchor.x;
1400
+ _this.store.activeAnchor.y = _this.store.hoverAnchor.y;
1401
+ }
1381
1402
  connectLine(_this.store.hover, _this.store.hoverAnchor, line_1, _this.store.activeAnchor);
1382
1403
  }
1383
1404
  }
@@ -1398,7 +1419,7 @@ var Canvas = /** @class */ (function () {
1398
1419
  }
1399
1420
  }
1400
1421
  // Add pen
1401
- if (_this.addCaches) {
1422
+ if (_this.addCaches && _this.addCaches.length) {
1402
1423
  if (!_this.store.data.locked) {
1403
1424
  _this.dropPens(_this.addCaches, e);
1404
1425
  }
@@ -1420,7 +1441,7 @@ var Canvas = /** @class */ (function () {
1420
1441
  if (_this.dragRect) {
1421
1442
  var pens = _this.store.data.pens.filter(function (pen) {
1422
1443
  if (pen.visible === false ||
1423
- pen.locked === LockState.Disable ||
1444
+ pen.locked >= LockState.DisableMove ||
1424
1445
  pen.parentId) {
1425
1446
  return false;
1426
1447
  }
@@ -1432,6 +1453,7 @@ var Canvas = /** @class */ (function () {
1432
1453
  return true;
1433
1454
  }
1434
1455
  });
1456
+ //框选
1435
1457
  _this.active(pens);
1436
1458
  }
1437
1459
  if (e.button !== 2) {
@@ -1639,7 +1661,7 @@ var Canvas = /** @class */ (function () {
1639
1661
  try {
1640
1662
  for (var _d = (e_1 = void 0, __values(pen.calculative.worldAnchors)), _e = _d.next(); !_e.done; _e = _d.next()) {
1641
1663
  var anchor = _e.value;
1642
- if (hitPoint(pt, anchor, _this.pointSize)) {
1664
+ if (hitPoint(pt, anchor, _this.pointSize, anchor.penId ? _this.store.pens[anchor.penId] : undefined)) {
1643
1665
  _this.title.show(anchor);
1644
1666
  if (anchor.title) {
1645
1667
  return "break-outer";
@@ -2030,7 +2052,32 @@ var Canvas = /** @class */ (function () {
2030
2052
  size = _this.store.hover.calculative.lineWidth;
2031
2053
  }
2032
2054
  }
2033
- ctx.arc(anchor.x, anchor.y, size, 0, Math.PI * 2);
2055
+ if (anchor.type === PointType.Line) {
2056
+ //旋转的情况
2057
+ var _rotate = _this.store.pens[anchor.penId].rotate;
2058
+ if (_this.store.pens[anchor.penId].calculative.flipX) {
2059
+ _rotate *= -1;
2060
+ }
2061
+ if (_this.store.pens[anchor.penId].calculative.flipY) {
2062
+ _rotate *= -1;
2063
+ }
2064
+ var rotate = anchor.rotate + _rotate;
2065
+ if (_this.store.pens[anchor.penId].calculative.flipX) {
2066
+ rotate *= -1;
2067
+ }
2068
+ if (_this.store.pens[anchor.penId].calculative.flipY) {
2069
+ rotate *= -1;
2070
+ }
2071
+ ctx.save();
2072
+ ctx.translate(anchor.x, anchor.y);
2073
+ ctx.rotate((rotate * Math.PI) / 180);
2074
+ ctx.translate(-anchor.x, -anchor.y);
2075
+ ctx.rect(anchor.x - (anchor.length * _this.store.data.scale) / 2, anchor.y - size, anchor.length * _this.store.data.scale, size * 2);
2076
+ ctx.restore();
2077
+ }
2078
+ else {
2079
+ ctx.arc(anchor.x, anchor.y, size, 0, Math.PI * 2);
2080
+ }
2034
2081
  if (_this.store.hover.type && _this.store.hoverAnchor === anchor) {
2035
2082
  ctx.save();
2036
2083
  ctx.strokeStyle =
@@ -3211,7 +3258,7 @@ var Canvas = /** @class */ (function () {
3211
3258
  return __assign(__assign({}, pen), { x: x, y: y });
3212
3259
  }));
3213
3260
  // 偏移量 0
3214
- this.pasteOffset = 0;
3261
+ this.pasteOffset = false;
3215
3262
  this.paste();
3216
3263
  };
3217
3264
  /**
@@ -3404,7 +3451,7 @@ var Canvas = /** @class */ (function () {
3404
3451
  return HoverType.None;
3405
3452
  }
3406
3453
  }
3407
- if (hitPoint(pt, anchor, this.pointSize)) {
3454
+ if (hitPoint(pt, anchor, this.pointSize, anchor.penId ? this.store.pens[anchor.penId] : undefined)) {
3408
3455
  if (anchor !== this.store.hoverAnchor) {
3409
3456
  this.patchFlags = true;
3410
3457
  }
@@ -3661,6 +3708,7 @@ var Canvas = /** @class */ (function () {
3661
3708
  var pen = deepClone(aPen, true);
3662
3709
  var i = _this.store.data.pens.findIndex(function (item) { return item.id === pen.id; });
3663
3710
  if (i > -1) {
3711
+ (_a = pen.onDestroy) === null || _a === void 0 ? void 0 : _a.call(pen, _this.store.pens[pen.id]);
3664
3712
  _this.store.data.pens.splice(i, 1);
3665
3713
  _this.store.pens[pen.id] = undefined;
3666
3714
  if (!pen.calculative) {
@@ -3669,7 +3717,6 @@ var Canvas = /** @class */ (function () {
3669
3717
  pen.calculative.canvas = _this;
3670
3718
  _this.store.animates.delete(pen);
3671
3719
  _this.store.animateMap.delete(pen);
3672
- (_a = pen.onDestroy) === null || _a === void 0 ? void 0 : _a.call(pen, pen);
3673
3720
  }
3674
3721
  });
3675
3722
  action.type = EditType.Delete;
@@ -4655,8 +4702,15 @@ var Canvas = /** @class */ (function () {
4655
4702
  if (this.store.hover &&
4656
4703
  this.store.hoverAnchor &&
4657
4704
  this.store.hoverAnchor.penId !== this.store.activeAnchor.penId) {
4658
- offsetX = this.store.hoverAnchor.x - this.store.activeAnchor.x;
4659
- offsetY = this.store.hoverAnchor.y - this.store.activeAnchor.y;
4705
+ if (this.store.hoverAnchor.type === PointType.Line) {
4706
+ offsetX = pt.x - this.store.activeAnchor.x;
4707
+ offsetY = pt.y - this.store.activeAnchor.y;
4708
+ getDistance(this.store.activeAnchor, this.store.hoverAnchor, this.store);
4709
+ }
4710
+ else {
4711
+ offsetX = this.store.hoverAnchor.x - this.store.activeAnchor.x;
4712
+ offsetY = this.store.hoverAnchor.y - this.store.activeAnchor.y;
4713
+ }
4660
4714
  translatePoint(this.store.activeAnchor, offsetX, offsetY);
4661
4715
  to.prev = undefined;
4662
4716
  // 重新自动计算连线
@@ -4729,7 +4783,9 @@ var Canvas = /** @class */ (function () {
4729
4783
  };
4730
4784
  Canvas.prototype.moveLineAnchorNext = function (e) {
4731
4785
  var _this = this;
4732
- if (!this.activeRect || this.store.data.locked) {
4786
+ if (!this.activeRect ||
4787
+ this.store.data.locked ||
4788
+ !this.store.activeAnchor) {
4733
4789
  return;
4734
4790
  }
4735
4791
  if (!this.initPens) {
@@ -5066,8 +5122,28 @@ var Canvas = /** @class */ (function () {
5066
5122
  if (!penAnchor) {
5067
5123
  return;
5068
5124
  }
5069
- translatePoint(lineAnchor, penAnchor.x - lineAnchor.x, penAnchor.y - lineAnchor.y);
5125
+ var rotate = pen.rotate;
5126
+ if (pen.flipX) {
5127
+ rotate *= -1;
5128
+ }
5129
+ if (pen.flipY) {
5130
+ rotate *= -1;
5131
+ }
5132
+ var offsetX = lineAnchor.distance *
5133
+ _this.store.data.scale *
5134
+ Math.cos(((rotate + penAnchor.rotate) / 180) * Math.PI) || 0;
5135
+ var offsetY = lineAnchor.distance *
5136
+ _this.store.data.scale *
5137
+ Math.sin(((rotate + penAnchor.rotate) / 180) * Math.PI) || 0;
5138
+ if (pen.flipX) {
5139
+ offsetX = -offsetX;
5140
+ }
5141
+ if (pen.flipY) {
5142
+ offsetY = -offsetY;
5143
+ }
5144
+ translatePoint(lineAnchor, penAnchor.x - lineAnchor.x + offsetX, penAnchor.y - lineAnchor.y + offsetY);
5070
5145
  if (_this.store.options.autoPolyline &&
5146
+ !_this.autoPolylineFlag &&
5071
5147
  line.autoPolyline !== false &&
5072
5148
  line.lineName === 'polyline') {
5073
5149
  var from = getFromAnchor(line);
@@ -5455,6 +5531,10 @@ var Canvas = /** @class */ (function () {
5455
5531
  this.store.clipboard.pos = { x: this.mousePos.x, y: this.mousePos.y };
5456
5532
  this.store.clipboard.offset = 0;
5457
5533
  }
5534
+ else if (!this.pasteOffset) {
5535
+ this.store.clipboard.offset = 0;
5536
+ this.pasteOffset = true;
5537
+ }
5458
5538
  else {
5459
5539
  offset && (this.store.clipboard.offset = offset);
5460
5540
  pos && (this.store.clipboard.pos = pos);