@meta2d/core 1.0.2 → 1.0.4

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.2",
3
+ "version": "1.0.4",
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",
@@ -237,6 +237,25 @@ var Canvas = /** @class */ (function () {
237
237
  }
238
238
  e.preventDefault();
239
239
  e.stopPropagation();
240
+ //禁止触摸屏双指缩放操作
241
+ if (_this.store.options.disableTouchPadScale &&
242
+ e.ctrlKey &&
243
+ e.deltaY !== 0) {
244
+ return;
245
+ }
246
+ //window触控板只允许平移 触摸屏一般不超过100
247
+ var isWin = navigator.userAgent.indexOf('Win') !== -1;
248
+ if (isWin && !e.ctrlKey && Math.abs(e.deltaY) < 100) {
249
+ _this.translate(-e.deltaX, -e.deltaY);
250
+ return;
251
+ }
252
+ //mac触控板只允许平移(排除普通鼠标的情况)
253
+ var isMac = /macintosh|mac os x/i.test(navigator.userAgent) ||
254
+ navigator.platform.indexOf('Mac') !== -1;
255
+ if (isMac && !e.ctrlKey && e.wheelDeltaY % 240 !== 0) {
256
+ _this.translate(-e.deltaX, -e.deltaY);
257
+ return;
258
+ }
240
259
  if (_this.store.options.scroll && !e.ctrlKey && !e.metaKey && _this.scroll) {
241
260
  _this.scroll.wheel(e.deltaY < 0);
242
261
  return;
@@ -542,6 +561,20 @@ var Canvas = /** @class */ (function () {
542
561
  _this.store.options.disableAnchor = !_this.store.options.disableAnchor;
543
562
  _this.store.emitter.emit('disableAnchor', _this.store.options.disableAnchor);
544
563
  break;
564
+ case '=':
565
+ if (e.ctrlKey || e.metaKey) {
566
+ _this.scale(_this.store.data.scale + 0.1);
567
+ e.preventDefault();
568
+ e.stopPropagation();
569
+ }
570
+ break;
571
+ case '-':
572
+ if (e.ctrlKey || e.metaKey) {
573
+ _this.scale(_this.store.data.scale - 0.1);
574
+ e.preventDefault();
575
+ e.stopPropagation();
576
+ }
577
+ break;
545
578
  }
546
579
  _this.render(false);
547
580
  };
@@ -779,7 +812,7 @@ var Canvas = /** @class */ (function () {
779
812
  }
780
813
  //shift 快捷添加锚点并连线
781
814
  if (!_this.store.options.autoAnchor && !_this.drawingLine) {
782
- if (e.shiftKey) {
815
+ if (e.shiftKey && !e.ctrlKey) {
783
816
  _this.setAnchor(_this.store.pointAt);
784
817
  _this.drawingLineName = _this.store.options.drawingLineName;
785
818
  var anchor = _this.store.activeAnchor;
@@ -1968,7 +2001,9 @@ var Canvas = /** @class */ (function () {
1968
2001
  var size = anchor.radius ||
1969
2002
  _this.store.hover.anchorRadius ||
1970
2003
  _this.store.options.anchorRadius;
1971
- if (_this.store.hover.type) {
2004
+ if (_this.store.hover.type &&
2005
+ !anchor.radius &&
2006
+ !_this.store.hover.anchorRadius) {
1972
2007
  size = 3;
1973
2008
  if (_this.store.hover.calculative.lineWidth > 3) {
1974
2009
  size = _this.store.hover.calculative.lineWidth;
@@ -2187,7 +2222,8 @@ var Canvas = /** @class */ (function () {
2187
2222
  textRect.x + _this.store.data.x - (pen.textLeft || 0) + 'px'; //+ 5
2188
2223
  _this.inputParent.style.top =
2189
2224
  textRect.y + _this.store.data.y - (pen.textTop || 0) + 'px'; //+ 5
2190
- _this.inputParent.style.width = textRect.width + (pen.textLeft || 0) + 'px'; //(textRect.width < pen.width ? 0 : 10)
2225
+ var _width = textRect.width + (pen.textLeft || 0);
2226
+ _this.inputParent.style.width = (_width < 0 ? 12 : _width) + 'px'; //(textRect.width < pen.width ? 0 : 10)
2191
2227
  _this.inputParent.style.height = textRect.height + (pen.textTop || 0) + 'px'; // (textRect.height < pen.height ? 0 : 10)
2192
2228
  _this.inputParent.style.zIndex = '9999';
2193
2229
  _this.inputParent.style.background = background;
@@ -2307,7 +2343,7 @@ var Canvas = /** @class */ (function () {
2307
2343
  : pen.textHeight * font_scale) + "px;";
2308
2344
  }
2309
2345
  else {
2310
- var tem = pen.height / scale - (pen.textTop || 0);
2346
+ var tem = pen.calculative.worldRect.height / scale - (pen.textTop || 0);
2311
2347
  if (tem < 0) {
2312
2348
  tem = 0;
2313
2349
  }
@@ -2327,7 +2363,7 @@ var Canvas = /** @class */ (function () {
2327
2363
  }
2328
2364
  else {
2329
2365
  if (pen.whiteSpace === undefined || pen.whiteSpace === 'break-all') {
2330
- var tem = pen.width / scale - (pen.textLeft || 0);
2366
+ var tem = (pen.calculative.worldTextRect.width || 12) / scale; //pen.width / scale - ( pen.textLeft || 0);
2331
2367
  if (tem < 0) {
2332
2368
  tem = 0;
2333
2369
  }
@@ -2354,8 +2390,10 @@ var Canvas = /** @class */ (function () {
2354
2390
  }
2355
2391
  if (pen.whiteSpace !== 'nowrap') {
2356
2392
  var textWidth = pen.fontSize * 1.2 * pen.text.length;
2357
- var contentWidth = (pen.textWidth || pen.width / scale) *
2358
- Math.floor(pen.height / scale / (pen.lineHeight * pen.fontSize));
2393
+ var contentWidth = (pen.textWidth || pen.calculative.worldRect.width / scale) *
2394
+ Math.floor(pen.calculative.worldRect.height /
2395
+ scale /
2396
+ (pen.lineHeight * pen.fontSize));
2359
2397
  if (textWidth > contentWidth) {
2360
2398
  style += 'justify-content: start;';
2361
2399
  }
@@ -2993,7 +3031,7 @@ var Canvas = /** @class */ (function () {
2993
3031
  var _this = this;
2994
3032
  // 鼠标松手才更新,此处是更新前的值
2995
3033
  var initPens = deepClone(this.store.active, true);
2996
- var pens = deepClone(this.store.active, true);
3034
+ // const pens = deepClone(this.store.active, true);
2997
3035
  this.store.active.forEach(function (pen, i) {
2998
3036
  var _a;
2999
3037
  var _b = _this.movingPens[i], x = _b.x, y = _b.y;
@@ -3033,6 +3071,7 @@ var Canvas = /** @class */ (function () {
3033
3071
  if (!dockPen && yDock) {
3034
3072
  dockPen = this.store.pens[yDock.penId];
3035
3073
  }
3074
+ var pens = deepClone(this.store.active, true);
3036
3075
  // 移动到连线端点,自动连线
3037
3076
  if (readyConnect &&
3038
3077
  this.store.active.length === 1 &&
@@ -3203,7 +3242,7 @@ var Canvas = /** @class */ (function () {
3203
3242
  pen.name === 'line' &&
3204
3243
  anchor.connectTo) {
3205
3244
  var connectPen = this.findOne(anchor.connectTo);
3206
- if (!(connectPen === null || connectPen === void 0 ? void 0 : connectPen.calculative.active)) {
3245
+ if ((connectPen === null || connectPen === void 0 ? void 0 : connectPen.calculative) && !(connectPen === null || connectPen === void 0 ? void 0 : connectPen.calculative.active)) {
3207
3246
  pen = connectPen;
3208
3247
  var connectAnchor = connectPen.calculative.worldAnchors.find(function (item) { return item.id === anchor.anchorId; });
3209
3248
  connectAnchor && (anchor = connectAnchor);
@@ -3479,7 +3518,7 @@ var Canvas = /** @class */ (function () {
3479
3518
  Canvas.prototype.activeHistory = function () {
3480
3519
  var _this = this;
3481
3520
  var before = this.store.histories[this.store.historyIndex];
3482
- if (before) {
3521
+ if (before && before.type === EditType.Add) {
3483
3522
  before.pens.forEach(function (pen) {
3484
3523
  if (!pen.calculative) {
3485
3524
  return;
@@ -4373,7 +4412,7 @@ var Canvas = /** @class */ (function () {
4373
4412
  };
4374
4413
  Canvas.prototype.moveLineAnchor = function (pt, keyOptions) {
4375
4414
  var _this = this;
4376
- var _a, _b;
4415
+ var _a, _b, _c;
4377
4416
  if (!this.activeRect || this.store.data.locked) {
4378
4417
  return;
4379
4418
  }
@@ -4384,6 +4423,14 @@ var Canvas = /** @class */ (function () {
4384
4423
  var pen = this.store.pens[this.store.activeAnchor.connectTo];
4385
4424
  disconnectLine(pen, getAnchor(pen, this.store.activeAnchor.anchorId), this.store.pens[this.store.activeAnchor.penId], this.store.activeAnchor);
4386
4425
  }
4426
+ var anchorId = this.store.activeAnchor.id;
4427
+ var connectedLine = (_b = this.store.pens[this.store.activeAnchor.penId].connectedLines) === null || _b === void 0 ? void 0 : _b.filter(function (item) { return item.anchor === anchorId; });
4428
+ if (connectedLine && connectedLine.length > 0) {
4429
+ connectedLine.forEach(function (connected) {
4430
+ var pen = _this.store.pens[connected.lineId];
4431
+ disconnectLine(_this.store.pens[_this.store.activeAnchor.penId], _this.store.activeAnchor, pen, getAnchor(pen, connected.lineAnchor));
4432
+ });
4433
+ }
4387
4434
  var line = this.store.active[0];
4388
4435
  var from = getFromAnchor(line);
4389
4436
  var to = getToAnchor(line);
@@ -4403,7 +4450,7 @@ var Canvas = /** @class */ (function () {
4403
4450
  to.prev = undefined;
4404
4451
  // 重新自动计算连线
4405
4452
  if (line.lineName !== 'polyline') {
4406
- (_b = this[line.lineName]) === null || _b === void 0 ? void 0 : _b.call(this, this.store, line);
4453
+ (_c = this[line.lineName]) === null || _c === void 0 ? void 0 : _c.call(this, this.store, line);
4407
4454
  }
4408
4455
  }
4409
4456
  }
@@ -4626,7 +4673,7 @@ var Canvas = /** @class */ (function () {
4626
4673
  return;
4627
4674
  }
4628
4675
  var initPens = !doing && deepClone(pens, true);
4629
- translateRect(this.activeRect, x, y);
4676
+ this.activeRect && translateRect(this.activeRect, x, y);
4630
4677
  var containChildPens = this.getAllByPens(pens);
4631
4678
  pens.forEach(function (pen) {
4632
4679
  var _a, _b;
@@ -4665,7 +4712,7 @@ var Canvas = /** @class */ (function () {
4665
4712
  _this.updateLines(pen);
4666
4713
  (_b = pen.onMove) === null || _b === void 0 ? void 0 : _b.call(pen, pen);
4667
4714
  });
4668
- this.getSizeCPs();
4715
+ this.activeRect && this.getSizeCPs();
4669
4716
  this.render();
4670
4717
  this.tooltip.translate(x, y);
4671
4718
  if (!doing) {
@@ -4745,7 +4792,6 @@ var Canvas = /** @class */ (function () {
4745
4792
  else {
4746
4793
  pen.calculative.rotate = pen.rotate;
4747
4794
  }
4748
- pen.calculative.worldRect = pen.calculative.initRect;
4749
4795
  //其他回到最初始状态
4750
4796
  var originStatus = deepClone(this.store.animateMap.get(pen));
4751
4797
  if (originStatus) {
@@ -4756,6 +4802,7 @@ var Canvas = /** @class */ (function () {
4756
4802
  history: false,
4757
4803
  });
4758
4804
  }
4805
+ pen.calculative.worldRect = pen.calculative.initRect;
4759
4806
  }
4760
4807
  this.updatePenRect(pen, { worldRectIsReady: true });
4761
4808
  if (pen.calculative.text !== pen.text) {