@meta2d/core 1.0.50 → 1.0.52

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.50",
3
+ "version": "1.0.52",
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",
@@ -432,8 +432,8 @@ export declare class Canvas {
432
432
  height: number;
433
433
  };
434
434
  toPng(padding?: Padding, callback?: BlobCallback, containBkImg?: boolean, maxWidth?: number): string;
435
- activeToPng(padding?: Padding): string;
436
- pensToPng(pens?: Pen[], padding?: Padding): string;
435
+ activeToPng(padding?: Padding, maxWidth?: number): string;
436
+ pensToPng(pens?: Pen[], padding?: Padding, maxWidth?: number): string;
437
437
  toggleAnchorMode(): void;
438
438
  addAnchorHand(): void;
439
439
  removeAnchorHand(): void;
@@ -279,7 +279,7 @@ var Canvas = /** @class */ (function () {
279
279
  }
280
280
  if (Math.abs(e.wheelDelta) > 100) {
281
281
  //鼠标滚轮滚动 scroll模式下是上下滚动而不是缩放
282
- if (_this.store.options.scroll && _this.scroll) {
282
+ if (_this.store.options.scroll && _this.scroll && !_this.store.options.scrollButScale) {
283
283
  _this.scroll.wheel(e.deltaY < 0);
284
284
  return;
285
285
  }
@@ -656,7 +656,7 @@ var Canvas = /** @class */ (function () {
656
656
  }
657
657
  else {
658
658
  //图元进入编辑模式
659
- pen.calculative.focus = !pen.calculative.focus;
659
+ pen.calculative.focus = true;
660
660
  }
661
661
  });
662
662
  _this.render();
@@ -668,6 +668,16 @@ var Canvas = /** @class */ (function () {
668
668
  }
669
669
  _this.drawingLineName = undefined;
670
670
  _this.stopPencil();
671
+ if (_this.store.active) {
672
+ _this.store.active.forEach(function (pen) {
673
+ if (pen.type) {
674
+ }
675
+ else {
676
+ //图元退出编辑模式
677
+ pen.calculative.focus = false;
678
+ }
679
+ });
680
+ }
671
681
  if (_this.movingPens) {
672
682
  _this.getAllByPens(_this.movingPens).forEach(function (pen) {
673
683
  _this.store.pens[pen.id] = undefined;
@@ -1207,6 +1217,9 @@ var Canvas = /** @class */ (function () {
1207
1217
  });
1208
1218
  break;
1209
1219
  }
1220
+ if (_this.store.hover) {
1221
+ _this.store.hover.calculative.mouseDown = true;
1222
+ }
1210
1223
  _this.store.emitter.emit('mousedown', {
1211
1224
  x: e.x,
1212
1225
  y: e.y,
@@ -1657,6 +1670,9 @@ var Canvas = /** @class */ (function () {
1657
1670
  pen: _this.store.hover,
1658
1671
  });
1659
1672
  }
1673
+ if (_this.store.hover) {
1674
+ _this.store.hover.calculative.mouseDown = false;
1675
+ }
1660
1676
  _this.store.emitter.emit('mouseup', {
1661
1677
  x: e.x,
1662
1678
  y: e.y,
@@ -2839,7 +2855,7 @@ var Canvas = /** @class */ (function () {
2839
2855
  var e_6, _a;
2840
2856
  _this.clearDropdownList();
2841
2857
  var pen = _this.store.pens[_this.inputDiv.dataset.penId];
2842
- if (!_this.store.data.locked && !['table'].includes(pen.name)) {
2858
+ if (!_this.store.data.locked && !['tablePlus'].includes(pen.name)) {
2843
2859
  return;
2844
2860
  }
2845
2861
  _this.dropdown.style.display = 'block';
@@ -3270,7 +3286,7 @@ var Canvas = /** @class */ (function () {
3270
3286
  }
3271
3287
  if (pen.dataset) {
3272
3288
  if (num % 2 === 0) {
3273
- lastW = pen.width + 10;
3289
+ lastW = pen.width - 40;
3274
3290
  }
3275
3291
  else {
3276
3292
  lastW = 0;
@@ -4468,6 +4484,11 @@ var Canvas = /** @class */ (function () {
4468
4484
  }
4469
4485
  globalStore.anchors[pen.name](pen);
4470
4486
  }
4487
+ if (!pen.anchors) {
4488
+ var anchors = deepClone(this.store.options.defaultAnchors);
4489
+ anchors.forEach(function (item, index) { item.id = "" + index; item.penId = pen.id; });
4490
+ pen.anchors = anchors;
4491
+ }
4471
4492
  this.updatePenRect(pen);
4472
4493
  if (!pen.anchors && pen.calculative.worldAnchors) {
4473
4494
  pen.anchors = pen.calculative.worldAnchors.map(function (pt) {
@@ -5465,7 +5486,7 @@ var Canvas = /** @class */ (function () {
5465
5486
  };
5466
5487
  Canvas.prototype.moveLineAnchor = function (pt, keyOptions) {
5467
5488
  var _this = this;
5468
- var _a, _b, _c, _d;
5489
+ var _a, _b, _c, _d, _e;
5469
5490
  if (!this.activeRect || this.store.data.locked) {
5470
5491
  return;
5471
5492
  }
@@ -5476,8 +5497,8 @@ var Canvas = /** @class */ (function () {
5476
5497
  var pen = this.store.pens[this.store.activeAnchor.connectTo];
5477
5498
  disconnectLine(pen, getAnchor(pen, this.store.activeAnchor.anchorId), this.store.pens[this.store.activeAnchor.penId], this.store.activeAnchor);
5478
5499
  }
5479
- var anchorId = this.store.activeAnchor.id;
5480
- var connectedLine = (_c = (_b = this.store.pens[this.store.activeAnchor.penId]) === null || _b === void 0 ? void 0 : _b.connectedLines) === null || _c === void 0 ? void 0 : _c.filter(function (item) { return item.anchor === anchorId; });
5500
+ var anchorId = (_b = this.store.activeAnchor) === null || _b === void 0 ? void 0 : _b.id;
5501
+ var connectedLine = (_d = (_c = this.store.pens[this.store.activeAnchor.penId]) === null || _c === void 0 ? void 0 : _c.connectedLines) === null || _d === void 0 ? void 0 : _d.filter(function (item) { return item.anchor === anchorId; });
5481
5502
  if (connectedLine && connectedLine.length > 0) {
5482
5503
  connectedLine.forEach(function (connected) {
5483
5504
  var pen = _this.store.pens[connected.lineId];
@@ -5557,7 +5578,7 @@ var Canvas = /** @class */ (function () {
5557
5578
  to.prev = undefined;
5558
5579
  // 重新自动计算连线
5559
5580
  if (line.lineName !== 'polyline') {
5560
- (_d = this[line.lineName]) === null || _d === void 0 ? void 0 : _d.call(this, this.store, line);
5581
+ (_e = this[line.lineName]) === null || _e === void 0 ? void 0 : _e.call(this, this.store, line);
5561
5582
  }
5562
5583
  }
5563
5584
  }
@@ -6934,7 +6955,7 @@ var Canvas = /** @class */ (function () {
6934
6955
  };
6935
6956
  this.inputDiv.oninput = function (e) {
6936
6957
  var pen = _this.store.pens[_this.inputDiv.dataset.penId];
6937
- if (pen.inputType === 'number') {
6958
+ if (pen && pen.inputType === 'number') {
6938
6959
  var value = e.target.innerText;
6939
6960
  var numericValue = value.replace(/[^0-9]/g, ''); // 移除非数字字符
6940
6961
  // 如果输入的值不是纯数字,则替换为纯数字
@@ -7127,6 +7148,9 @@ var Canvas = /** @class */ (function () {
7127
7148
  if (needCalcIconRectProps.includes(k)) {
7128
7149
  willCalcIconRect = true;
7129
7150
  }
7151
+ if (pen.image && pen.name !== 'gif' && ['globalAlpha', 'flipY', 'flipX', 'x', 'y', 'width', 'height'].includes(k)) {
7152
+ willRenderImage = true;
7153
+ }
7130
7154
  }
7131
7155
  else {
7132
7156
  // 复合属性,如abc.def.ghi
@@ -7435,11 +7459,11 @@ var Canvas = /** @class */ (function () {
7435
7459
  }
7436
7460
  return canvas.toDataURL();
7437
7461
  };
7438
- Canvas.prototype.activeToPng = function (padding) {
7462
+ Canvas.prototype.activeToPng = function (padding, maxWidth) {
7439
7463
  if (padding === void 0) { padding = 2; }
7440
- return this.pensToPng(this.store.active, padding);
7464
+ return this.pensToPng(this.store.active, padding, maxWidth);
7441
7465
  };
7442
- Canvas.prototype.pensToPng = function (pens, padding) {
7466
+ Canvas.prototype.pensToPng = function (pens, padding, maxWidth) {
7443
7467
  var e_26, _a;
7444
7468
  if (pens === void 0) { pens = this.store.active; }
7445
7469
  if (padding === void 0) { padding = 2; }
@@ -7459,6 +7483,9 @@ var Canvas = /** @class */ (function () {
7459
7483
  rect.width += p[3] + p[1];
7460
7484
  rect.height += p[0] + p[2];
7461
7485
  calcRightBottom(rect);
7486
+ var scale = (maxWidth || rect.width) / rect.width;
7487
+ rect.width *= scale;
7488
+ rect.height *= scale;
7462
7489
  var canvas = document.createElement('canvas');
7463
7490
  canvas.width = rect.width;
7464
7491
  canvas.height = rect.height;
@@ -7472,8 +7499,17 @@ var Canvas = /** @class */ (function () {
7472
7499
  }
7473
7500
  var ctx = canvas.getContext('2d');
7474
7501
  ctx.textBaseline = 'middle'; // 默认垂直居中
7502
+ ctx.scale(scale, scale);
7503
+ var background = this.store.data.background || this.store.options.background;
7504
+ if (background) {
7505
+ // 绘制背景颜色
7506
+ ctx.save();
7507
+ ctx.fillStyle = background;
7508
+ ctx.fillRect(0, 0, oldRect.width + (p[3] + p[1]), oldRect.height + (p[0] + p[2]));
7509
+ ctx.restore();
7510
+ }
7475
7511
  // // 平移画布,画笔的 worldRect 不变化
7476
- ctx.translate(-oldRect.x, -oldRect.y);
7512
+ ctx.translate(-oldRect.x + p[3], -oldRect.y + p[0]);
7477
7513
  try {
7478
7514
  for (var _b = __values(this.store.data.pens), _c = _b.next(); !_c.done; _c = _b.next()) {
7479
7515
  var pen = _c.value;