@meta2d/core 1.0.43 → 1.0.45

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.43",
3
+ "version": "1.0.45",
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",
@@ -84,7 +84,7 @@ var __values = (this && this.__values) || function(o) {
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, 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
- import { calcCenter, calcRightBottom, calcRelativePoint, getRect, getRectOfPoints, pointInRect, pointInSimpleRect, rectInRect, rectToPoints, resizeRect, translateRect, } from '../rect';
87
+ import { calcCenter, calcRightBottom, calcRelativePoint, getRect, getRectOfPoints, pointInRect, pointInSimpleRect, rectInRect, rectToPoints, resizeRect, translateRect, pointInPolygon } from '../rect';
88
88
  import { EditType, globalStore, } from '../store';
89
89
  import { deepClone, fileToBase64, uploadFile, formatPadding, rgba, s8, } from '../utils';
90
90
  import { inheritanceProps, defaultCursors, defaultDrawLineFns, HotkeyType, HoverType, MouseRight, rotatedCursors, } from '../data';
@@ -166,7 +166,7 @@ var Canvas = /** @class */ (function () {
166
166
  _this.cut();
167
167
  };
168
168
  this.onPaste = function (event) {
169
- if (_this.store.options.disableClipboard) {
169
+ if (_this.store.data.locked || _this.store.options.disableClipboard) {
170
170
  return;
171
171
  }
172
172
  if (event.target !== _this.externalElements &&
@@ -591,7 +591,7 @@ var Canvas = /** @class */ (function () {
591
591
  _this.drawingLineName = _this.store.options.drawingLineName;
592
592
  }
593
593
  }
594
- if ((e.ctrlKey || e.metaKey) && (_this.store.options.disableClipboard ||
594
+ if (!_this.store.data.locked && (e.ctrlKey || e.metaKey) && (_this.store.options.disableClipboard ||
595
595
  (!_this.store.options.disableClipboard && e.altKey)) //alt按下,paste事件无效
596
596
  ) {
597
597
  _this.paste();
@@ -1192,7 +1192,7 @@ var Canvas = /** @class */ (function () {
1192
1192
  _this.render();
1193
1193
  };
1194
1194
  this.onMouseMove = function (e) {
1195
- var _a, _b, _c, _d, _e, _f;
1195
+ var _a, _b, _c, _d, _e, _f, _g;
1196
1196
  if (_this.store.data.locked === LockState.Disable) {
1197
1197
  _this.hoverType = HoverType.None;
1198
1198
  return;
@@ -1249,6 +1249,9 @@ var Canvas = /** @class */ (function () {
1249
1249
  if (!_this.drawingLineName && !_this.movingAnchor) {
1250
1250
  // 在锚点上开始连线
1251
1251
  if (_this.hoverType === HoverType.NodeAnchor) {
1252
+ if (!_this.store.hoverAnchor) {
1253
+ return;
1254
+ }
1252
1255
  _this.drawingLineName = _this.store.options.drawingLineName;
1253
1256
  var pt = {
1254
1257
  id: s8(),
@@ -1295,13 +1298,13 @@ var Canvas = /** @class */ (function () {
1295
1298
  var pt = { x: e.x, y: e.y };
1296
1299
  // Move line anchor
1297
1300
  if (_this.hoverType === HoverType.LineAnchor) {
1298
- if ((_this.dockInAnchor(e) || _this.store.active[0].lineName === 'line') &&
1301
+ if ((_this.dockInAnchor(e) || ((_b = _this.store.active[0]) === null || _b === void 0 ? void 0 : _b.lineName) === 'line') &&
1299
1302
  !_this.store.options.disableDock &&
1300
1303
  !_this.store.options.disableLineDock) {
1301
1304
  _this.clearDock();
1302
1305
  _this.dock = calcAnchorDock(_this.store, pt, _this.store.activeAnchor);
1303
- ((_b = _this.dock) === null || _b === void 0 ? void 0 : _b.xDock) && (pt.x += _this.dock.xDock.step);
1304
- ((_c = _this.dock) === null || _c === void 0 ? void 0 : _c.yDock) && (pt.y += _this.dock.yDock.step);
1306
+ ((_c = _this.dock) === null || _c === void 0 ? void 0 : _c.xDock) && (pt.x += _this.dock.xDock.step);
1307
+ ((_d = _this.dock) === null || _d === void 0 ? void 0 : _d.yDock) && (pt.y += _this.dock.yDock.step);
1305
1308
  }
1306
1309
  _this.moveLineAnchor(pt, e);
1307
1310
  return;
@@ -1341,7 +1344,7 @@ var Canvas = /** @class */ (function () {
1341
1344
  if (_this.store.active.length === 1) {
1342
1345
  var activePen = _this.store.active[0];
1343
1346
  if (activePen.locked < LockState.DisableMove) {
1344
- (_d = activePen === null || activePen === void 0 ? void 0 : activePen.onMouseMove) === null || _d === void 0 ? void 0 : _d.call(activePen, activePen, _this.mousePos);
1347
+ (_e = activePen === null || activePen === void 0 ? void 0 : activePen.onMouseMove) === null || _e === void 0 ? void 0 : _e.call(activePen, activePen, _this.mousePos);
1345
1348
  }
1346
1349
  }
1347
1350
  _this.movePens(e);
@@ -1366,8 +1369,8 @@ var Canvas = /** @class */ (function () {
1366
1369
  !_this.store.options.disableLineDock) {
1367
1370
  _this.clearDock();
1368
1371
  _this.dock = calcAnchorDock(_this.store, pt);
1369
- ((_e = _this.dock) === null || _e === void 0 ? void 0 : _e.xDock) && (pt.x += _this.dock.xDock.step);
1370
- ((_f = _this.dock) === null || _f === void 0 ? void 0 : _f.yDock) && (pt.y += _this.dock.yDock.step);
1372
+ ((_f = _this.dock) === null || _f === void 0 ? void 0 : _f.xDock) && (pt.x += _this.dock.xDock.step);
1373
+ ((_g = _this.dock) === null || _g === void 0 ? void 0 : _g.yDock) && (pt.y += _this.dock.yDock.step);
1371
1374
  }
1372
1375
  if (_this.mouseDown &&
1373
1376
  _this.drawingLineName === 'curve' &&
@@ -1593,7 +1596,7 @@ var Canvas = /** @class */ (function () {
1593
1596
  var pens = _this.store.data.pens.filter(function (pen) {
1594
1597
  if (pen.visible === false ||
1595
1598
  pen.locked >= LockState.DisableMove ||
1596
- pen.parentId) {
1599
+ pen.parentId || pen.isRuleLine) {
1597
1600
  return false;
1598
1601
  }
1599
1602
  if (rectInRect(pen.calculative.worldRect, _this.dragRect, _this.store.options.dragAllIn)) {
@@ -1791,9 +1794,10 @@ var Canvas = /** @class */ (function () {
1791
1794
  (_b = (_a = _this.store.hover) === null || _a === void 0 ? void 0 : _a.onMouseMove) === null || _b === void 0 ? void 0 : _b.call(_a, _this.store.hover, _this.mousePos);
1792
1795
  };
1793
1796
  this.inPens = function (pt, pens) {
1797
+ var _a;
1794
1798
  var hoverType = HoverType.None;
1795
1799
  var _loop_2 = function (i) {
1796
- var e_1, _a, e_2, _b;
1800
+ var e_1, _b, e_2, _c;
1797
1801
  var pen = pens[i];
1798
1802
  if (pen.visible == false ||
1799
1803
  pen.calculative.inView == false ||
@@ -1831,8 +1835,8 @@ var Canvas = /** @class */ (function () {
1831
1835
  if (!_this.store.data.locked && _this.hotkeyType !== HotkeyType.Resize) {
1832
1836
  if (pen.calculative.worldAnchors) {
1833
1837
  try {
1834
- for (var _c = (e_1 = void 0, __values(pen.calculative.worldAnchors)), _d = _c.next(); !_d.done; _d = _c.next()) {
1835
- var anchor = _d.value;
1838
+ for (var _d = (e_1 = void 0, __values(pen.calculative.worldAnchors)), _e = _d.next(); !_e.done; _e = _d.next()) {
1839
+ var anchor = _e.value;
1836
1840
  hoverType = _this.inAnchor(pt, pen, anchor);
1837
1841
  if (hoverType) {
1838
1842
  //title显示
@@ -1846,7 +1850,7 @@ var Canvas = /** @class */ (function () {
1846
1850
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
1847
1851
  finally {
1848
1852
  try {
1849
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
1853
+ if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
1850
1854
  }
1851
1855
  finally { if (e_1) throw e_1.error; }
1852
1856
  }
@@ -1854,6 +1858,13 @@ var Canvas = /** @class */ (function () {
1854
1858
  }
1855
1859
  // 图形
1856
1860
  if (pen.type) {
1861
+ if (pen.isRuleLine) {
1862
+ var ruleH = ((_a = _this.store.options.ruleOptions) === null || _a === void 0 ? void 0 : _a.height) || 20;
1863
+ if (pt.x + _this.store.data.x > ruleH &&
1864
+ pt.y + _this.store.data.y > ruleH) {
1865
+ return "break";
1866
+ }
1867
+ }
1857
1868
  var pos = pointInLine(pt, pen);
1858
1869
  if (pos) {
1859
1870
  if (!_this.store.data.locked && !pen.locked) {
@@ -1894,6 +1905,12 @@ var Canvas = /** @class */ (function () {
1894
1905
  isIn = pointInRect(pt, pen.calculative.worldRect);
1895
1906
  }
1896
1907
  if (isIn) {
1908
+ if (pen.type === PenType.Node && pen.name === 'line') {
1909
+ var pIn = pointInPolygon(pt, pen.calculative.worldAnchors);
1910
+ if (!pIn) {
1911
+ return "continue";
1912
+ }
1913
+ }
1897
1914
  if (!_this.store.data.locked && !pen.locked) {
1898
1915
  if (_this.hotkeyType === HotkeyType.AddAnchor) {
1899
1916
  _this.externalElements.style.cursor = 'pointer';
@@ -1911,7 +1928,7 @@ var Canvas = /** @class */ (function () {
1911
1928
  _this.store.pointAt = pt;
1912
1929
  // 锚点贴边吸附
1913
1930
  if (!pt.ctrlKey) {
1914
- var _e = _this.store.hover.calculative.worldRect, x = _e.x, y = _e.y, ex = _e.ex, ey = _e.ey, rotate_1 = _e.rotate, center_1 = _e.center;
1931
+ var _f = _this.store.hover.calculative.worldRect, x = _f.x, y = _f.y, ex = _f.ex, ey = _f.ey, rotate_1 = _f.rotate, center_1 = _f.center;
1915
1932
  if (rotate_1) {
1916
1933
  var pts = [
1917
1934
  { x: x, y: y },
@@ -1939,7 +1956,7 @@ var Canvas = /** @class */ (function () {
1939
1956
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
1940
1957
  finally {
1941
1958
  try {
1942
- if (pts_1_1 && !pts_1_1.done && (_b = pts_1.return)) _b.call(pts_1);
1959
+ if (pts_1_1 && !pts_1_1.done && (_c = pts_1.return)) _c.call(pts_1);
1943
1960
  }
1944
1961
  finally { if (e_2) throw e_2.error; }
1945
1962
  }
@@ -3846,6 +3863,9 @@ var Canvas = /** @class */ (function () {
3846
3863
  if (this.store.hover) {
3847
3864
  this.store.hoverAnchor =
3848
3865
  this.store.hover.calculative.worldAnchors.find(function (a) { return a.id === anchor.anchorId; });
3866
+ if (!this.store.hoverAnchor) {
3867
+ return HoverType.None;
3868
+ }
3849
3869
  this.externalElements.style.cursor = 'crosshair';
3850
3870
  return HoverType.NodeAnchor;
3851
3871
  }
@@ -5641,6 +5661,9 @@ var Canvas = /** @class */ (function () {
5641
5661
  if (!_this.store.options.moveConnectedLine && !_this.canMoveLine) {
5642
5662
  return;
5643
5663
  }
5664
+ if (pen.isRuleLine) {
5665
+ return;
5666
+ }
5644
5667
  translateLine(pen, x, y);
5645
5668
  _this.checkDisconnect(pen, containChildPens);
5646
5669
  _this.store.path2dMap.set(pen, globalStore.path2dDraws[pen.name](pen));
@@ -5808,6 +5831,10 @@ var Canvas = /** @class */ (function () {
5808
5831
  }
5809
5832
  this.updatePenRect(pen, { worldRectIsReady: true });
5810
5833
  this.updateLines(pen);
5834
+ if (pen.image && pen.name !== 'gif') {
5835
+ this.canvasImage.init();
5836
+ this.canvasImageBottom.init();
5837
+ }
5811
5838
  if (pen.calculative.text !== pen.text) {
5812
5839
  pen.calculative.text = pen.text;
5813
5840
  calcTextLines(pen);
@@ -6691,6 +6718,9 @@ var Canvas = /** @class */ (function () {
6691
6718
  }
6692
6719
  }
6693
6720
  };
6721
+ this.inputDiv.onblur = function () {
6722
+ _this.hideInput();
6723
+ };
6694
6724
  this.inputDiv.oninput = function (e) {
6695
6725
  // //无文本时,光标确保居中
6696
6726
  if (navigator.userAgent.includes('Firefox')) {
@@ -6831,7 +6861,7 @@ var Canvas = /** @class */ (function () {
6831
6861
  }
6832
6862
  };
6833
6863
  Canvas.prototype.updateValue = function (pen, data) {
6834
- var _a, _b, _c, _d, _e;
6864
+ var _a, _b, _c, _d, _e, _f;
6835
6865
  var penRect = this.getPenRect(pen);
6836
6866
  var oldName = pen.name;
6837
6867
  Object.assign(pen, data);
@@ -6972,9 +7002,9 @@ var Canvas = /** @class */ (function () {
6972
7002
  this.canvasImage.init();
6973
7003
  }
6974
7004
  }
6975
- else {
6976
- this.initImageCanvas([pen]);
6977
- }
7005
+ // else {
7006
+ // this.initImageCanvas([pen]);
7007
+ // }
6978
7008
  // if (data.template !== undefined || pen.template) {
6979
7009
  // this.initTemplateCanvas([pen]);
6980
7010
  // }
@@ -6983,7 +7013,7 @@ var Canvas = /** @class */ (function () {
6983
7013
  this.initTemplateCanvas([pen]);
6984
7014
  }
6985
7015
  if (data.zIndex !== undefined) {
6986
- pen.calculative.singleton.div &&
7016
+ ((_f = pen.calculative.singleton) === null || _f === void 0 ? void 0 : _f.div) &&
6987
7017
  setElemPosition(pen, pen.calculative.singleton.div);
6988
7018
  }
6989
7019
  };