@meta2d/core 1.0.20 → 1.0.21

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.21",
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",
@@ -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';
@@ -630,7 +630,7 @@ var Canvas = /** @class */ (function () {
630
630
  obj = _a.sent();
631
631
  return [3 /*break*/, 3];
632
632
  case 2:
633
- if (this.addCaches.length) {
633
+ if (this.addCaches && this.addCaches.length) {
634
634
  obj = this.addCaches;
635
635
  this.addCaches = [];
636
636
  }
@@ -864,8 +864,13 @@ var Canvas = /** @class */ (function () {
864
864
  // 单击在锚点上,完成绘画
865
865
  if (_this.store.hoverAnchor) {
866
866
  var to_1 = getToAnchor(_this.drawingLine);
867
- to_1.x = _this.store.hoverAnchor.x;
868
- to_1.y = _this.store.hoverAnchor.y;
867
+ if (_this.store.hoverAnchor.type === PointType.Line) {
868
+ getDistance(to_1, _this.store.hoverAnchor, _this.store);
869
+ }
870
+ else {
871
+ to_1.x = _this.store.hoverAnchor.x;
872
+ to_1.y = _this.store.hoverAnchor.y;
873
+ }
869
874
  connectLine(_this.store.hover, _this.store.hoverAnchor, _this.drawingLine, to_1);
870
875
  _this.drawline();
871
876
  _this.finishDrawline(true);
@@ -1249,8 +1254,10 @@ var Canvas = /** @class */ (function () {
1249
1254
  }
1250
1255
  if (_this.hoverType === HoverType.NodeAnchor ||
1251
1256
  _this.hoverType === HoverType.LineAnchor) {
1252
- to.x = _this.store.hoverAnchor.x;
1253
- to.y = _this.store.hoverAnchor.y;
1257
+ if (_this.store.hoverAnchor.type !== PointType.Line) {
1258
+ to.x = _this.store.hoverAnchor.x;
1259
+ to.y = _this.store.hoverAnchor.y;
1260
+ }
1254
1261
  to.connectTo = _this.store.hoverAnchor.penId;
1255
1262
  if (_this.drawingLineName === 'polyline') {
1256
1263
  to.isTemp = false;
@@ -1309,8 +1316,13 @@ var Canvas = /** @class */ (function () {
1309
1316
  // 在锚点上,完成绘画
1310
1317
  if (_this.store.hoverAnchor) {
1311
1318
  var to = getToAnchor(_this.drawingLine);
1312
- to.x = _this.store.hoverAnchor.x;
1313
- to.y = _this.store.hoverAnchor.y;
1319
+ if (_this.store.hoverAnchor.type === PointType.Line) {
1320
+ getDistance(to, _this.store.hoverAnchor, _this.store);
1321
+ }
1322
+ else {
1323
+ to.x = _this.store.hoverAnchor.x;
1324
+ to.y = _this.store.hoverAnchor.y;
1325
+ }
1314
1326
  connectLine(_this.store.hover, _this.store.hoverAnchor, _this.drawingLine, to);
1315
1327
  _this.drawline();
1316
1328
  _this.finishDrawline(true);
@@ -1376,8 +1388,16 @@ var Canvas = /** @class */ (function () {
1376
1388
  else {
1377
1389
  // 连接连线
1378
1390
  if (_this.store.activeAnchor) {
1379
- _this.store.activeAnchor.x = _this.store.hoverAnchor.x;
1380
- _this.store.activeAnchor.y = _this.store.hoverAnchor.y;
1391
+ /**
1392
+ * 线的锚点需要存所连接锚点的位置
1393
+ */
1394
+ if (_this.store.hoverAnchor.type === PointType.Line) {
1395
+ getDistance(_this.store.activeAnchor, _this.store.hoverAnchor, _this.store);
1396
+ }
1397
+ else {
1398
+ _this.store.activeAnchor.x = _this.store.hoverAnchor.x;
1399
+ _this.store.activeAnchor.y = _this.store.hoverAnchor.y;
1400
+ }
1381
1401
  connectLine(_this.store.hover, _this.store.hoverAnchor, line_1, _this.store.activeAnchor);
1382
1402
  }
1383
1403
  }
@@ -1398,7 +1418,7 @@ var Canvas = /** @class */ (function () {
1398
1418
  }
1399
1419
  }
1400
1420
  // Add pen
1401
- if (_this.addCaches) {
1421
+ if (_this.addCaches && _this.addCaches.length) {
1402
1422
  if (!_this.store.data.locked) {
1403
1423
  _this.dropPens(_this.addCaches, e);
1404
1424
  }
@@ -1639,7 +1659,7 @@ var Canvas = /** @class */ (function () {
1639
1659
  try {
1640
1660
  for (var _d = (e_1 = void 0, __values(pen.calculative.worldAnchors)), _e = _d.next(); !_e.done; _e = _d.next()) {
1641
1661
  var anchor = _e.value;
1642
- if (hitPoint(pt, anchor, _this.pointSize)) {
1662
+ if (hitPoint(pt, anchor, _this.pointSize, anchor.penId ? _this.store.pens[anchor.penId] : undefined)) {
1643
1663
  _this.title.show(anchor);
1644
1664
  if (anchor.title) {
1645
1665
  return "break-outer";
@@ -2030,7 +2050,32 @@ var Canvas = /** @class */ (function () {
2030
2050
  size = _this.store.hover.calculative.lineWidth;
2031
2051
  }
2032
2052
  }
2033
- ctx.arc(anchor.x, anchor.y, size, 0, Math.PI * 2);
2053
+ if (anchor.type === PointType.Line) {
2054
+ //旋转的情况
2055
+ var _rotate = _this.store.pens[anchor.penId].rotate;
2056
+ if (_this.store.pens[anchor.penId].calculative.flipX) {
2057
+ _rotate *= -1;
2058
+ }
2059
+ if (_this.store.pens[anchor.penId].calculative.flipY) {
2060
+ _rotate *= -1;
2061
+ }
2062
+ var rotate = anchor.rotate + _rotate;
2063
+ if (_this.store.pens[anchor.penId].calculative.flipX) {
2064
+ rotate *= -1;
2065
+ }
2066
+ if (_this.store.pens[anchor.penId].calculative.flipY) {
2067
+ rotate *= -1;
2068
+ }
2069
+ ctx.save();
2070
+ ctx.translate(anchor.x, anchor.y);
2071
+ ctx.rotate((rotate * Math.PI) / 180);
2072
+ ctx.translate(-anchor.x, -anchor.y);
2073
+ ctx.rect(anchor.x - (anchor.length * _this.store.data.scale) / 2, anchor.y - size, anchor.length * _this.store.data.scale, size * 2);
2074
+ ctx.restore();
2075
+ }
2076
+ else {
2077
+ ctx.arc(anchor.x, anchor.y, size, 0, Math.PI * 2);
2078
+ }
2034
2079
  if (_this.store.hover.type && _this.store.hoverAnchor === anchor) {
2035
2080
  ctx.save();
2036
2081
  ctx.strokeStyle =
@@ -3404,7 +3449,7 @@ var Canvas = /** @class */ (function () {
3404
3449
  return HoverType.None;
3405
3450
  }
3406
3451
  }
3407
- if (hitPoint(pt, anchor, this.pointSize)) {
3452
+ if (hitPoint(pt, anchor, this.pointSize, anchor.penId ? this.store.pens[anchor.penId] : undefined)) {
3408
3453
  if (anchor !== this.store.hoverAnchor) {
3409
3454
  this.patchFlags = true;
3410
3455
  }
@@ -4655,8 +4700,15 @@ var Canvas = /** @class */ (function () {
4655
4700
  if (this.store.hover &&
4656
4701
  this.store.hoverAnchor &&
4657
4702
  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;
4703
+ if (this.store.hoverAnchor.type === PointType.Line) {
4704
+ offsetX = pt.x - this.store.activeAnchor.x;
4705
+ offsetY = pt.y - this.store.activeAnchor.y;
4706
+ getDistance(this.store.activeAnchor, this.store.hoverAnchor, this.store);
4707
+ }
4708
+ else {
4709
+ offsetX = this.store.hoverAnchor.x - this.store.activeAnchor.x;
4710
+ offsetY = this.store.hoverAnchor.y - this.store.activeAnchor.y;
4711
+ }
4660
4712
  translatePoint(this.store.activeAnchor, offsetX, offsetY);
4661
4713
  to.prev = undefined;
4662
4714
  // 重新自动计算连线
@@ -4729,7 +4781,9 @@ var Canvas = /** @class */ (function () {
4729
4781
  };
4730
4782
  Canvas.prototype.moveLineAnchorNext = function (e) {
4731
4783
  var _this = this;
4732
- if (!this.activeRect || this.store.data.locked) {
4784
+ if (!this.activeRect ||
4785
+ this.store.data.locked ||
4786
+ !this.store.activeAnchor) {
4733
4787
  return;
4734
4788
  }
4735
4789
  if (!this.initPens) {
@@ -5066,9 +5120,29 @@ var Canvas = /** @class */ (function () {
5066
5120
  if (!penAnchor) {
5067
5121
  return;
5068
5122
  }
5069
- translatePoint(lineAnchor, penAnchor.x - lineAnchor.x, penAnchor.y - lineAnchor.y);
5123
+ var rotate = pen.rotate;
5124
+ if (pen.flipX) {
5125
+ rotate *= -1;
5126
+ }
5127
+ if (pen.flipY) {
5128
+ rotate *= -1;
5129
+ }
5130
+ var offsetX = lineAnchor.distance *
5131
+ _this.store.data.scale *
5132
+ Math.cos(((rotate + penAnchor.rotate) / 180) * Math.PI) || 0;
5133
+ var offsetY = lineAnchor.distance *
5134
+ _this.store.data.scale *
5135
+ Math.sin(((rotate + penAnchor.rotate) / 180) * Math.PI) || 0;
5136
+ if (pen.flipX) {
5137
+ offsetX = -offsetX;
5138
+ }
5139
+ if (pen.flipY) {
5140
+ offsetY = -offsetY;
5141
+ }
5142
+ translatePoint(lineAnchor, penAnchor.x - lineAnchor.x + offsetX, penAnchor.y - lineAnchor.y + offsetY);
5070
5143
  if (_this.store.options.autoPolyline &&
5071
5144
  line.autoPolyline !== false &&
5145
+ line.calculative.autoPolylineFlag === true &&
5072
5146
  line.lineName === 'polyline') {
5073
5147
  var from = getFromAnchor(line);
5074
5148
  var to = getToAnchor(line);