@meta2d/core 1.0.54 → 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.54",
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
  }
@@ -961,7 +975,7 @@ var Canvas = /** @class */ (function () {
961
975
  }
962
976
  }
963
977
  if (_this.touchScaling) {
964
- if (_this.store.options.disableScale) {
978
+ if (_this.store.data.disableScale || _this.store.options.disableScale) {
965
979
  return;
966
980
  }
967
981
  var scale = Math.hypot(touches[0].pageX - touches[1].pageX, touches[0].pageY - touches[1].pageY) / _this.initTouchDis;
@@ -970,6 +984,7 @@ var Canvas = /** @class */ (function () {
970
984
  if (_this.touchMoving) {
971
985
  if ((_this.store.data.locked >= LockState.DisableMove &&
972
986
  _this.store.data.locked !== LockState.DisableScale) ||
987
+ _this.store.data.disableScale ||
973
988
  _this.store.options.disableScale) {
974
989
  return;
975
990
  }
@@ -1322,7 +1337,7 @@ var Canvas = /** @class */ (function () {
1322
1337
  return;
1323
1338
  }
1324
1339
  }
1325
- if (_this.mouseDown && !_this.store.options.disableTranslate) {
1340
+ if (_this.mouseDown && !_this.store.options.disableTranslate && !_this.store.data.disableTranslate) {
1326
1341
  // 画布平移前提
1327
1342
  if (_this.mouseRight === MouseRight.Down) {
1328
1343
  _this.mouseRight = MouseRight.Translate;
@@ -1859,15 +1874,17 @@ var Canvas = /** @class */ (function () {
1859
1874
  }
1860
1875
  }
1861
1876
  else {
1862
- _this.store.hoverContainer = undefined;
1863
- if (_this.store.lastHoverContainer !== _this.store.hoverContainer) {
1864
- _this.patchFlags = true;
1865
- var movingPen = _this.store.lastHoverContainer.calculative.canvas.store.pens[_this.store.lastHoverContainer.id + movingSuffix];
1866
- if (_this.store.lastHoverContainer && !movingPen) {
1867
- _this.store.lastHoverContainer.calculative.containerHover = false;
1868
- _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;
1869
1887
  }
1870
- _this.store.lastHoverContainer = _this.store.hoverContainer;
1871
1888
  }
1872
1889
  }
1873
1890
  }
@@ -3100,6 +3117,7 @@ var Canvas = /** @class */ (function () {
3100
3117
  this.listen();
3101
3118
  window === null || window === void 0 ? void 0 : window.addEventListener('resize', this.onResize);
3102
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);
3103
3121
  }
3104
3122
  Canvas.prototype.listen = function () {
3105
3123
  var _this = this;
@@ -8159,6 +8177,7 @@ var Canvas = /** @class */ (function () {
8159
8177
  document.removeEventListener('copy', this.onCopy);
8160
8178
  document.removeEventListener('cut', this.onCut);
8161
8179
  document.removeEventListener('paste', this.onPaste);
8180
+ window && window.removeEventListener('message', this.onMessage);
8162
8181
  window && window.removeEventListener('resize', this.onResize);
8163
8182
  window && window.removeEventListener('scroll', this.onScroll);
8164
8183
  };