@meta2d/core 1.0.53 → 1.0.55

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.53",
3
+ "version": "1.0.55",
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",
@@ -129,6 +129,7 @@ export declare class Canvas {
129
129
  onCopy: (event: ClipboardEvent) => void;
130
130
  onCut: (event: ClipboardEvent) => void;
131
131
  onPaste: (event: ClipboardEvent) => void;
132
+ onMessage: (e: MessageEvent) => void;
132
133
  onwheel: (e: WheelEvent) => void;
133
134
  onkeydown: (e: KeyboardEvent) => void;
134
135
  /**
@@ -233,6 +233,20 @@ var Canvas = /** @class */ (function () {
233
233
  _this.paste();
234
234
  }
235
235
  };
236
+ this.onMessage = function (e) {
237
+ if (typeof e.data !== 'string' ||
238
+ !e.data ||
239
+ e.data.startsWith('setImmediate')) {
240
+ return;
241
+ }
242
+ var data = JSON.parse(e.data);
243
+ if (typeof data === 'object') {
244
+ _this.parent.doMessageEvent(data.name);
245
+ }
246
+ else {
247
+ _this.parent.doMessageEvent(data);
248
+ }
249
+ };
236
250
  this.onwheel = function (e) {
237
251
  //输入模式不允许滚动
238
252
  if (_this.inputDiv.contentEditable === 'true') {
@@ -251,7 +265,7 @@ var Canvas = /** @class */ (function () {
251
265
  return;
252
266
  }
253
267
  }
254
- if (_this.store.options.disableScale) {
268
+ if (_this.store.data.disableScale || _this.store.options.disableScale) {
255
269
  return;
256
270
  }
257
271
  e.preventDefault();
@@ -279,8 +293,8 @@ var Canvas = /** @class */ (function () {
279
293
  return;
280
294
  }
281
295
  if (Math.abs(e.wheelDelta) > 100) {
282
- //鼠标滚轮滚动 scroll模式下是上下滚动而不是缩放
283
- if (_this.store.options.scroll && _this.scroll && !_this.store.options.scrollButScale) {
296
+ //鼠标滚轮滚动 scroll模式下是上下滚动而不是缩放 ctrl可以控制缩放
297
+ if (_this.store.options.scroll && _this.scroll && !_this.store.options.scrollButScale && !(e.ctrlKey || e.metaKey)) {
284
298
  _this.scroll.wheel(e.deltaY < 0);
285
299
  return;
286
300
  }
@@ -843,6 +857,15 @@ var Canvas = /** @class */ (function () {
843
857
  this.calibrateMouse(pt);
844
858
  this.dropPens(obj, pt);
845
859
  this.addCaches = [];
860
+ // 拖拽新增图元判断是否是在容器上
861
+ this.getContainerHover(pt);
862
+ this.mousePos.x = pt.x;
863
+ this.mousePos.y = pt.y;
864
+ this.store.emitter.emit('mouseup', {
865
+ x: pt.x,
866
+ y: pt.y,
867
+ pen: this.store.hoverContainer,
868
+ });
846
869
  }
847
870
  this.store.emitter.emit('drop', obj || json);
848
871
  return [2 /*return*/];
@@ -952,7 +975,7 @@ var Canvas = /** @class */ (function () {
952
975
  }
953
976
  }
954
977
  if (_this.touchScaling) {
955
- if (_this.store.options.disableScale) {
978
+ if (_this.store.data.disableScale || _this.store.options.disableScale) {
956
979
  return;
957
980
  }
958
981
  var scale = Math.hypot(touches[0].pageX - touches[1].pageX, touches[0].pageY - touches[1].pageY) / _this.initTouchDis;
@@ -961,6 +984,7 @@ var Canvas = /** @class */ (function () {
961
984
  if (_this.touchMoving) {
962
985
  if ((_this.store.data.locked >= LockState.DisableMove &&
963
986
  _this.store.data.locked !== LockState.DisableScale) ||
987
+ _this.store.data.disableScale ||
964
988
  _this.store.options.disableScale) {
965
989
  return;
966
990
  }
@@ -1313,7 +1337,7 @@ var Canvas = /** @class */ (function () {
1313
1337
  return;
1314
1338
  }
1315
1339
  }
1316
- if (_this.mouseDown && !_this.store.options.disableTranslate) {
1340
+ if (_this.mouseDown && !_this.store.options.disableTranslate && !_this.store.data.disableTranslate) {
1317
1341
  // 画布平移前提
1318
1342
  if (_this.mouseRight === MouseRight.Down) {
1319
1343
  _this.mouseRight = MouseRight.Translate;
@@ -1733,11 +1757,13 @@ var Canvas = /** @class */ (function () {
1733
1757
  if (_this.store.hover) {
1734
1758
  _this.store.hover.calculative.mouseDown = false;
1735
1759
  }
1736
- _this.store.emitter.emit('mouseup', {
1737
- x: e.x,
1738
- y: e.y,
1739
- pen: _this.store.hover,
1740
- });
1760
+ if (_this.store.hover != _this.store.hoverContainer) {
1761
+ _this.store.emitter.emit('mouseup', {
1762
+ x: e.x,
1763
+ y: e.y,
1764
+ pen: _this.store.hover,
1765
+ });
1766
+ }
1741
1767
  _this.store.emitter.emit('mouseup', {
1742
1768
  x: e.x,
1743
1769
  y: e.y,
@@ -1828,8 +1854,7 @@ var Canvas = /** @class */ (function () {
1828
1854
  var pen = containerPens[i];
1829
1855
  if (pen.visible == false ||
1830
1856
  pen.calculative.inView == false ||
1831
- pen.locked === LockState.Disable ||
1832
- pen.calculative.active) {
1857
+ pen.locked === LockState.Disable) {
1833
1858
  continue;
1834
1859
  }
1835
1860
  if (pointInRect(pt, pen.calculative.worldRect)) {
@@ -1849,14 +1874,17 @@ var Canvas = /** @class */ (function () {
1849
1874
  }
1850
1875
  }
1851
1876
  else {
1852
- _this.store.hoverContainer = undefined;
1853
- if (_this.store.lastHoverContainer !== _this.store.hoverContainer) {
1854
- _this.patchFlags = true;
1855
- if (_this.store.lastHoverContainer) {
1856
- _this.store.lastHoverContainer.calculative.containerHover = false;
1857
- _this.store.emitter.emit('leave', _this.store.lastHoverContainer);
1877
+ if (pen === _this.store.hoverContainer) {
1878
+ _this.store.hoverContainer = undefined;
1879
+ if (_this.store.lastHoverContainer !== _this.store.hoverContainer) {
1880
+ _this.patchFlags = true;
1881
+ var movingPen = _this.store.lastHoverContainer.calculative.canvas.store.pens[_this.store.lastHoverContainer.id + movingSuffix];
1882
+ if (_this.store.lastHoverContainer && !movingPen) {
1883
+ _this.store.lastHoverContainer.calculative.containerHover = false;
1884
+ _this.store.emitter.emit('leave', _this.store.lastHoverContainer);
1885
+ }
1886
+ _this.store.lastHoverContainer = _this.store.hoverContainer;
1858
1887
  }
1859
- _this.store.lastHoverContainer = _this.store.hoverContainer;
1860
1888
  }
1861
1889
  }
1862
1890
  }
@@ -2904,6 +2932,7 @@ var Canvas = /** @class */ (function () {
2904
2932
  pens: [deepClone(pen, true)],
2905
2933
  initPens: initPens,
2906
2934
  });
2935
+ _this.store.emitter.emit('change', pen);
2907
2936
  _this.store.emitter.emit('valueUpdate', pen);
2908
2937
  }
2909
2938
  else if (pen.text === _this.inputDiv.dataset.value && pen.calculative.textLines.length == 0) {
@@ -3010,6 +3039,7 @@ var Canvas = /** @class */ (function () {
3010
3039
  initPens: initPens,
3011
3040
  });
3012
3041
  _this.render();
3042
+ _this.store.emitter.emit('change', pen);
3013
3043
  _this.store.emitter.emit('valueUpdate', pen);
3014
3044
  };
3015
3045
  this.inFitBorder = function (pt) {
@@ -3087,6 +3117,7 @@ var Canvas = /** @class */ (function () {
3087
3117
  this.listen();
3088
3118
  window === null || window === void 0 ? void 0 : window.addEventListener('resize', this.onResize);
3089
3119
  window === null || window === void 0 ? void 0 : window.addEventListener('scroll', this.onScroll);
3120
+ window === null || window === void 0 ? void 0 : window.addEventListener('message', this.onMessage);
3090
3121
  }
3091
3122
  Canvas.prototype.listen = function () {
3092
3123
  var _this = this;
@@ -4389,8 +4420,8 @@ var Canvas = /** @class */ (function () {
4389
4420
  if (_this.store.data.pens[i].type &&
4390
4421
  _this.store.data.pens[i].lastConnected) {
4391
4422
  for (var key in _this.store.data.pens[i].lastConnected) {
4392
- _this.store.pens[key].connectedLines =
4393
- _this.store.data.pens[i].lastConnected[key];
4423
+ _this.store.pens[key] && (_this.store.pens[key].connectedLines =
4424
+ _this.store.data.pens[i].lastConnected[key]);
4394
4425
  }
4395
4426
  }
4396
4427
  _this.store.data.pens[i] = pen;
@@ -4430,7 +4461,7 @@ var Canvas = /** @class */ (function () {
4430
4461
  _this.store.pens[pen.id] = pen;
4431
4462
  if (pen.type && pen.lastConnected) {
4432
4463
  for (var key in pen.lastConnected) {
4433
- _this.store.pens[key].connectedLines = pen.lastConnected[key];
4464
+ _this.store.pens[key] && (_this.store.pens[key].connectedLines = pen.lastConnected[key]);
4434
4465
  }
4435
4466
  }
4436
4467
  pen.calculative.canvas = _this;
@@ -4482,7 +4513,7 @@ var Canvas = /** @class */ (function () {
4482
4513
  _this.store.pens[pen.id] = pen;
4483
4514
  if (pen.type && pen.lastConnected) {
4484
4515
  for (var key in pen.lastConnected) {
4485
- _this.store.pens[key].connectedLines = pen.lastConnected[key];
4516
+ _this.store.pens[key] && (_this.store.pens[key].connectedLines = pen.lastConnected[key]);
4486
4517
  }
4487
4518
  }
4488
4519
  pen.calculative.canvas = _this;
@@ -6116,7 +6147,7 @@ var Canvas = /** @class */ (function () {
6116
6147
  if (!pen.connectedLines) {
6117
6148
  return;
6118
6149
  }
6119
- pen.connectedLines.forEach(function (item) {
6150
+ pen.connectedLines.forEach(function (item, index) {
6120
6151
  var line = _this.store.pens[item.lineId];
6121
6152
  // 活动层的线不需要更新,会在活动层处理
6122
6153
  if (!line || line.calculative.active) {
@@ -6126,6 +6157,11 @@ var Canvas = /** @class */ (function () {
6126
6157
  if (!lineAnchor) {
6127
6158
  return;
6128
6159
  }
6160
+ if (!lineAnchor.connectTo) {
6161
+ // 如果pen有连接关系但连线中没有连接关系,删除pen的连接关系
6162
+ pen.connectedLines.splice(index, 1);
6163
+ return;
6164
+ }
6129
6165
  if (line.autoFrom) {
6130
6166
  var from = getFromAnchor(line);
6131
6167
  if (from.id === lineAnchor.id) {
@@ -7084,6 +7120,7 @@ var Canvas = /** @class */ (function () {
7084
7120
  _this.inputDiv.style.paddingTop = '';
7085
7121
  }
7086
7122
  }
7123
+ _this.store.emitter.emit('input', pen);
7087
7124
  };
7088
7125
  this.inputDiv.onclick = function (e) {
7089
7126
  e.stopPropagation();
@@ -8140,6 +8177,7 @@ var Canvas = /** @class */ (function () {
8140
8177
  document.removeEventListener('copy', this.onCopy);
8141
8178
  document.removeEventListener('cut', this.onCut);
8142
8179
  document.removeEventListener('paste', this.onPaste);
8180
+ window && window.removeEventListener('message', this.onMessage);
8143
8181
  window && window.removeEventListener('resize', this.onResize);
8144
8182
  window && window.removeEventListener('scroll', this.onScroll);
8145
8183
  };