@meta2d/core 1.0.35 → 1.0.36

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.35",
3
+ "version": "1.0.36",
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",
@@ -82,7 +82,7 @@ var __values = (this && this.__values) || function(o) {
82
82
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
83
83
  };
84
84
  import { KeydownType } from '../options';
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, } from '../pen';
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, } from '../pen';
86
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';
@@ -719,8 +719,8 @@ var Canvas = /** @class */ (function () {
719
719
  }
720
720
  _a.label = 3;
721
721
  case 3:
722
- if (obj && obj.draggable !== false) {
723
- obj = Array.isArray(obj) ? obj : [obj];
722
+ obj = Array.isArray(obj) ? obj : [obj];
723
+ if (obj[0] && obj[0].draggable !== false) {
724
724
  pt = { x: event.offsetX, y: event.offsetY };
725
725
  this.calibrateMouse(pt);
726
726
  this.dropPens(obj, pt);
@@ -1239,7 +1239,7 @@ var Canvas = /** @class */ (function () {
1239
1239
  var pt = { x: e.x, y: e.y };
1240
1240
  // Move line anchor
1241
1241
  if (_this.hoverType === HoverType.LineAnchor) {
1242
- if (_this.dockInAnchor(e) &&
1242
+ if ((_this.store.active[0].lineName === 'line' || _this.dockInAnchor(e)) &&
1243
1243
  !_this.store.options.disableDock &&
1244
1244
  !_this.store.options.disableLineDock) {
1245
1245
  _this.clearDock();
@@ -2037,10 +2037,24 @@ var Canvas = /** @class */ (function () {
2037
2037
  if (!isFinite(pen.x)) {
2038
2038
  continue;
2039
2039
  }
2040
- if (pen.template) {
2040
+ // if (pen.template) {
2041
+ if (pen.canvasLayer === CanvasLayer.CanvasTemplate) {
2041
2042
  continue;
2042
2043
  }
2043
2044
  if (pen.calculative.inView) {
2045
+ if (pen.canvasLayer === CanvasLayer.CanvasMain &&
2046
+ pen.name !== 'gif' &&
2047
+ pen.image &&
2048
+ pen.calculative.img) {
2049
+ ctx.save();
2050
+ ctxFlip(ctx, pen);
2051
+ if (pen.calculative.rotate) {
2052
+ ctxRotate(ctx, pen);
2053
+ }
2054
+ setGlobalAlpha(ctx, pen);
2055
+ drawImage(ctx, pen);
2056
+ ctx.restore();
2057
+ }
2044
2058
  renderPen(ctx, pen);
2045
2059
  }
2046
2060
  }
@@ -3381,7 +3395,8 @@ var Canvas = /** @class */ (function () {
3381
3395
  Canvas.prototype.alignPenToGrid = function (pen) {
3382
3396
  var _a;
3383
3397
  var autoAlignGrid = this.store.options.autoAlignGrid && this.store.data.grid;
3384
- if (autoAlignGrid) {
3398
+ // 如果开启了自动网格,并且不是连线,则使pen对齐网格
3399
+ if (autoAlignGrid && !pen.type) {
3385
3400
  var gridSize = this.store.data.gridSize || this.store.options.gridSize;
3386
3401
  var _b = this.store.data, origin_2 = _b.origin, scale = _b.scale;
3387
3402
  var x = pen.x, y = pen.y;
@@ -3390,7 +3405,6 @@ var Canvas = /** @class */ (function () {
3390
3405
  // 算出偏移了多少个网格
3391
3406
  var m = parseInt((rect.x / gridSize).toFixed());
3392
3407
  var n = parseInt((rect.y / gridSize).toFixed());
3393
- console.log(m, n);
3394
3408
  var x1 = m * gridSize;
3395
3409
  var y1 = n * gridSize;
3396
3410
  // 算出最终的偏移坐标
@@ -3419,7 +3433,7 @@ var Canvas = /** @class */ (function () {
3419
3433
  var _b = _this.movingPens[i], x = _b.x, y = _b.y;
3420
3434
  var obj = { x: x, y: y };
3421
3435
  // 根据是否开启了自动网格对齐,来修正坐标
3422
- if (autoAlignGrid) {
3436
+ if (autoAlignGrid && !_this.movingPens[i].type) {
3423
3437
  var rect = _this.getPenRect(_this.movingPens[i]);
3424
3438
  // 算出偏移了多少个网格
3425
3439
  var m = parseInt((rect.x / gridSize).toFixed());
@@ -3549,14 +3563,34 @@ var Canvas = /** @class */ (function () {
3549
3563
  this.canvasImageBottom.init();
3550
3564
  };
3551
3565
  Canvas.prototype.initTemplateCanvas = function (pens) {
3552
- pens.some(function (pen) { return pen.template !== undefined; }) &&
3566
+ // pens.some((pen) => pen.template !== undefined) &&
3567
+ // this.canvasTemplate.init();
3568
+ pens.some(function (pen) { return pen.canvasLayer === CanvasLayer.CanvasTemplate; }) &&
3553
3569
  this.canvasTemplate.init();
3554
3570
  };
3555
3571
  Canvas.prototype.hasImage = function (pen, isBottom) {
3556
3572
  var _this = this;
3557
3573
  var _a;
3558
- if (pen.image && pen.name !== 'gif' && !pen.isBottom == !isBottom) {
3559
- return true;
3574
+ // if (pen.image && pen.name !== 'gif' && !pen.isBottom == !isBottom) {
3575
+ // return true;
3576
+ // }
3577
+ if (pen.image && pen.name !== 'gif') {
3578
+ if (isBottom) {
3579
+ if (pen.canvasLayer === CanvasLayer.CanvasImageBottom) {
3580
+ return true;
3581
+ }
3582
+ else {
3583
+ return false;
3584
+ }
3585
+ }
3586
+ else {
3587
+ if (pen.canvasLayer === CanvasLayer.CanvasImage) {
3588
+ return true;
3589
+ }
3590
+ else {
3591
+ return false;
3592
+ }
3593
+ }
3560
3594
  }
3561
3595
  return (_a = pen.children) === null || _a === void 0 ? void 0 : _a.some(function (childId) {
3562
3596
  var child = _this.store.pens[childId];
@@ -4015,9 +4049,11 @@ var Canvas = /** @class */ (function () {
4015
4049
  var i = _this.store.data.pens.findIndex(function (item) { return item.id === pen.id; });
4016
4050
  if (i > -1) {
4017
4051
  pen.calculative = _this.store.data.pens[i].calculative;
4018
- if (_this.store.data.pens[i].type && _this.store.data.pens[i].lastConnected) {
4052
+ if (_this.store.data.pens[i].type &&
4053
+ _this.store.data.pens[i].lastConnected) {
4019
4054
  for (var key in _this.store.data.pens[i].lastConnected) {
4020
- _this.store.pens[key].connectedLines = _this.store.data.pens[i].lastConnected[key];
4055
+ _this.store.pens[key].connectedLines =
4056
+ _this.store.data.pens[i].lastConnected[key];
4021
4057
  }
4022
4058
  }
4023
4059
  _this.store.data.pens[i] = pen;
@@ -4096,7 +4132,8 @@ var Canvas = /** @class */ (function () {
4096
4132
  if (Math.abs(this.store.lastScale - this.store.data.scale) < 0.0001 &&
4097
4133
  this.store.sameTemplate &&
4098
4134
  this.store.templatePens[pen.id] &&
4099
- pen.template) {
4135
+ // pen.template
4136
+ pen.canvasLayer === CanvasLayer.CanvasTemplate) {
4100
4137
  pen = this.store.templatePens[pen.id];
4101
4138
  this.store.data.pens.push(pen);
4102
4139
  this.updatePenRect(pen);
@@ -4122,6 +4159,18 @@ var Canvas = /** @class */ (function () {
4122
4159
  if (!pen.lineHeight) {
4123
4160
  pen.lineHeight = lineHeight;
4124
4161
  }
4162
+ if (pen.image && pen.name !== 'gif' && pen.canvasLayer === undefined) {
4163
+ if (pen.isBottom) {
4164
+ pen.canvasLayer = CanvasLayer.CanvasImageBottom;
4165
+ }
4166
+ else {
4167
+ pen.canvasLayer = CanvasLayer.CanvasImage;
4168
+ }
4169
+ delete pen.isBottom;
4170
+ }
4171
+ if (pen.template) {
4172
+ pen.canvasLayer = CanvasLayer.CanvasTemplate;
4173
+ }
4125
4174
  pen.calculative = { canvas: this, singleton: (_a = pen.calculative) === null || _a === void 0 ? void 0 : _a.singleton };
4126
4175
  if (pen.video || pen.audio) {
4127
4176
  pen.calculative.onended = function (pen) {
@@ -4372,7 +4421,8 @@ var Canvas = /** @class */ (function () {
4372
4421
  pen.calculative.imgNaturalHeight = img.naturalHeight || pen.iconHeight;
4373
4422
  globalStore.htmlElements[pen.image] = img;
4374
4423
  _this.imageLoaded();
4375
- if (pen.template) {
4424
+ // if (pen.template) {
4425
+ if (pen.canvasLayer === CanvasLayer.CanvasTemplate) {
4376
4426
  _this.templateImageLoaded();
4377
4427
  }
4378
4428
  };
@@ -4392,7 +4442,8 @@ var Canvas = /** @class */ (function () {
4392
4442
  pen.calculative.imgNaturalHeight =
4393
4443
  img.naturalHeight || pen.iconHeight;
4394
4444
  this.imageLoaded(); // TODO: 重绘图片层 有延时器,可能卡顿
4395
- if (pen.template) {
4445
+ // if (pen.template) {
4446
+ if (pen.canvasLayer === CanvasLayer.CanvasTemplate) {
4396
4447
  this.templateImageLoaded();
4397
4448
  }
4398
4449
  }
@@ -4424,7 +4475,8 @@ var Canvas = /** @class */ (function () {
4424
4475
  img_1.naturalHeight || pen.iconHeight;
4425
4476
  globalStore.htmlElements[pen.image] = img_1;
4426
4477
  _this.imageLoaded();
4427
- if (pen.template) {
4478
+ // if (pen.template) {
4479
+ if (pen.canvasLayer === CanvasLayer.CanvasTemplate) {
4428
4480
  _this.templateImageLoaded();
4429
4481
  }
4430
4482
  };
@@ -4454,7 +4506,8 @@ var Canvas = /** @class */ (function () {
4454
4506
  pen.calculative.backgroundImg = img_2;
4455
4507
  globalStore.htmlElements[pen.backgroundImage] = img_2;
4456
4508
  _this.imageLoaded();
4457
- if (pen.template) {
4509
+ // if (pen.template) {
4510
+ if (pen.canvasLayer === CanvasLayer.CanvasTemplate) {
4458
4511
  _this.templateImageLoaded();
4459
4512
  }
4460
4513
  };
@@ -4483,7 +4536,10 @@ var Canvas = /** @class */ (function () {
4483
4536
  pen.calculative.strokeImg = img_3;
4484
4537
  globalStore.htmlElements[pen.strokeImage] = img_3;
4485
4538
  _this.imageLoaded();
4486
- if (pen.template && pen.name !== 'gif') {
4539
+ if (
4540
+ // pen.template
4541
+ pen.canvasLayer === CanvasLayer.CanvasTemplate &&
4542
+ pen.name !== 'gif') {
4487
4543
  _this.templateImageLoaded();
4488
4544
  }
4489
4545
  };
@@ -6648,7 +6704,7 @@ var Canvas = /** @class */ (function () {
6648
6704
  if (k === 'rotate') {
6649
6705
  oldRotate = pen.calculative.rotate || 0;
6650
6706
  }
6651
- else if (k === 'isBottom') {
6707
+ else if (k === 'canvasLayer' || k === 'isBottom') {
6652
6708
  containIsBottom = true;
6653
6709
  }
6654
6710
  else if (k === 'image') {
@@ -6752,17 +6808,30 @@ var Canvas = /** @class */ (function () {
6752
6808
  }
6753
6809
  else if (willRenderImage) {
6754
6810
  // 存在先有 image 后无 image 的情况
6755
- if (pen.isBottom) {
6811
+ // if (pen.isBottom) {
6812
+ // this.canvasImageBottom.init();
6813
+ // } else {
6814
+ // this.canvasImage.init();
6815
+ // }
6816
+ if (pen.canvasLayer === undefined) {
6817
+ pen.canvasLayer = CanvasLayer.CanvasImageBottom;
6818
+ pen.calculative.canvasLayer = CanvasLayer.CanvasImageBottom;
6819
+ }
6820
+ if (pen.canvasLayer === CanvasLayer.CanvasImageBottom) {
6756
6821
  this.canvasImageBottom.init();
6757
6822
  }
6758
- else {
6823
+ else if (pen.canvasLayer === CanvasLayer.CanvasImage) {
6759
6824
  this.canvasImage.init();
6760
6825
  }
6761
6826
  }
6762
6827
  else {
6763
6828
  this.initImageCanvas([pen]);
6764
6829
  }
6765
- if (data.template !== undefined || pen.template) {
6830
+ // if (data.template !== undefined || pen.template) {
6831
+ // this.initTemplateCanvas([pen]);
6832
+ // }
6833
+ if (data.canvasLayer !== undefined ||
6834
+ pen.canvasLayer === CanvasLayer.CanvasTemplate) {
6766
6835
  this.initTemplateCanvas([pen]);
6767
6836
  }
6768
6837
  };