@meta2d/core 1.0.65 → 1.0.67

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.65",
3
+ "version": "1.0.67",
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",
@@ -88,6 +88,7 @@ export declare class Canvas {
88
88
  altKey?: boolean;
89
89
  ctrlKey?: boolean;
90
90
  metaKey?: boolean;
91
+ F?: boolean;
91
92
  };
92
93
  /**
93
94
  * @deprecated 改用 beforeAddPens
@@ -274,6 +275,7 @@ export declare class Canvas {
274
275
  private renderPenContainChild;
275
276
  renderBorder: () => void;
276
277
  renderHoverPoint: () => void;
278
+ transTimeout: any;
277
279
  translate(x?: number, y?: number): void;
278
280
  onMovePens(): void;
279
281
  /**
@@ -514,6 +514,10 @@ export class Canvas {
514
514
  this.keyOptions.shiftKey = e.shiftKey;
515
515
  this.keyOptions.ctrlKey = e.ctrlKey;
516
516
  this.keyOptions.metaKey = e.metaKey;
517
+ this.keyOptions.F = false;
518
+ if (e.key === 'F' || e.key === 'f') {
519
+ this.keyOptions.F = true;
520
+ }
517
521
  let x = 10;
518
522
  let y = 10;
519
523
  let vRect = null;
@@ -908,6 +912,10 @@ export class Canvas {
908
912
  break;
909
913
  case 'F':
910
914
  case 'f':
915
+ if (!this.store.data.locked && (e.ctrlKey || e.metaKey) && !this.store.options.disableClipboard) {
916
+ //粘贴到被复制图元上一层
917
+ this.paste();
918
+ }
911
919
  this.setFollowers();
912
920
  break;
913
921
  }
@@ -3528,7 +3536,13 @@ export class Canvas {
3528
3536
  this.updatePenRect(pen);
3529
3537
  return;
3530
3538
  }
3531
- this.store.data.pens.push(pen);
3539
+ if (pen.copyIndex) {
3540
+ this.store.data.pens.splice(pen.copyIndex + 1, 0, pen);
3541
+ delete pen.copyIndex;
3542
+ }
3543
+ else {
3544
+ this.store.data.pens.push(pen);
3545
+ }
3532
3546
  this.store.pens[pen.id] = pen;
3533
3547
  // 集中存储path,避免数据冗余过大
3534
3548
  if (pen.path) {
@@ -4106,7 +4120,11 @@ export class Canvas {
4106
4120
  }
4107
4121
  };
4108
4122
  renderPenContainChild = (ctx, pen) => {
4109
- pen.calculative.inView && renderPen(ctx, pen); // 可见才绘制,组合为状态只显示其中一个
4123
+ if (pen.calculative.inView) {
4124
+ if (!(pen.name === 'combine' && !pen.draw)) {
4125
+ renderPen(ctx, pen); // 可见才绘制,组合为状态只显示其中一个
4126
+ }
4127
+ }
4110
4128
  pen.children?.forEach((id) => {
4111
4129
  const child = this.store.pens[id];
4112
4130
  child && this.renderPenContainChild(ctx, child);
@@ -4327,6 +4345,7 @@ export class Canvas {
4327
4345
  }
4328
4346
  ctx.restore();
4329
4347
  };
4348
+ transTimeout;
4330
4349
  translate(x = 0, y = 0) {
4331
4350
  this.store.data.x += x * this.store.data.scale;
4332
4351
  this.store.data.y += y * this.store.data.scale;
@@ -4371,10 +4390,21 @@ export class Canvas {
4371
4390
  }
4372
4391
  //TODO 当初为什么加异步
4373
4392
  // setTimeout(() => {
4374
- this.canvasTemplate.init();
4375
- this.canvasImage.init();
4376
- this.canvasImageBottom.init();
4377
- this.render();
4393
+ if (this.store.data.asyncTranslate) {
4394
+ clearTimeout(this.transTimeout);
4395
+ this.transTimeout = setTimeout(() => {
4396
+ this.canvasTemplate.init();
4397
+ this.canvasImage.init();
4398
+ this.canvasImageBottom.init();
4399
+ this.render();
4400
+ }, 300);
4401
+ }
4402
+ else {
4403
+ this.canvasTemplate.init();
4404
+ this.canvasImage.init();
4405
+ this.canvasImageBottom.init();
4406
+ this.render();
4407
+ }
4378
4408
  // });
4379
4409
  this.store.emitter.emit('translate', {
4380
4410
  x: this.store.data.x,
@@ -5671,9 +5701,9 @@ export class Canvas {
5671
5701
  copyPens.sort((a, b) => {
5672
5702
  return a.copyIndex - b.copyIndex;
5673
5703
  });
5674
- copyPens.forEach((activePen) => {
5675
- delete activePen.copyIndex;
5676
- });
5704
+ // copyPens.forEach((activePen: any) => {
5705
+ // delete activePen.copyIndex;
5706
+ // });
5677
5707
  const clipboard = {
5678
5708
  meta2d: true,
5679
5709
  pens: copyPens,
@@ -5682,6 +5712,7 @@ export class Canvas {
5682
5712
  page,
5683
5713
  initRect: deepClone(this.activeRect),
5684
5714
  offset: 10,
5715
+ mousePos: deepClone(this.mousePos),
5685
5716
  };
5686
5717
  if (navigator.clipboard &&
5687
5718
  !this.store.options.disableClipboard &&
@@ -5746,7 +5777,14 @@ export class Canvas {
5746
5777
  }
5747
5778
  this.store.clipboard = deepClone(clipboard);
5748
5779
  const curPage = sessionStorage.getItem('page');
5749
- if (curPage !== clipboard.page) {
5780
+ const scale = this.store.data.scale;
5781
+ if (this.store.clipboard.mousePos && (Math.abs(this.store.clipboard.mousePos.x - this.mousePos.x) > 100 * scale || Math.abs(this.store.clipboard.mousePos.y - this.mousePos.y) > 100 * scale)) {
5782
+ const offsetX = (scale - this.store.clipboard.scale) * this.store.clipboard.initRect.width / 2;
5783
+ const offsetY = (scale - this.store.clipboard.scale) * this.store.clipboard.initRect.height / 2;
5784
+ this.store.clipboard.pos = { x: this.mousePos.x - offsetX, y: this.mousePos.y - offsetY };
5785
+ this.store.clipboard.offset = 0;
5786
+ }
5787
+ else if (curPage !== clipboard.page) {
5750
5788
  this.store.clipboard.pos = { x: this.mousePos.x, y: this.mousePos.y };
5751
5789
  this.store.clipboard.offset = 0;
5752
5790
  }
@@ -5758,6 +5796,11 @@ export class Canvas {
5758
5796
  offset && (this.store.clipboard.offset = offset);
5759
5797
  pos && (this.store.clipboard.pos = pos);
5760
5798
  }
5799
+ if (!this.keyOptions.F) {
5800
+ this.store.clipboard.pens.forEach((pen) => {
5801
+ delete pen.copyIndex;
5802
+ });
5803
+ }
5761
5804
  const rootPens = this.store.clipboard.pens.filter((pen) => !pen.parentId);
5762
5805
  for (const pen of rootPens) {
5763
5806
  this.pastePen(pen, undefined);
@@ -5855,7 +5898,7 @@ export class Canvas {
5855
5898
  pen.x = -this.store.data.x + this.width / 2 - pen.width / 2;
5856
5899
  pen.y = -this.store.data.y + this.height / 2 - pen.height / 2;
5857
5900
  }
5858
- else if (this.keyOptions && this.keyOptions.shiftKey && (this.keyOptions.ctrlKey || this.keyOptions.metaKey)) {
5901
+ else if (this.keyOptions && this.keyOptions.shiftKey && (this.keyOptions.ctrlKey || this.keyOptions.metaKey || this.keyOptions.F)) {
5859
5902
  }
5860
5903
  else {
5861
5904
  pen.x += this.store.clipboard.offset * this.store.data.scale;
@@ -6008,7 +6051,9 @@ export class Canvas {
6008
6051
  const i = this.store.data.pens.findIndex((item) => item.id === pen.id);
6009
6052
  if (i > -1) {
6010
6053
  const delPen = this.store.pens[pen.id];
6011
- delPen.calculative.active = undefined;
6054
+ if (delPen && delPen.calculative) {
6055
+ delPen.calculative.active = undefined;
6056
+ }
6012
6057
  delPens.push(delPen);
6013
6058
  }
6014
6059
  if (pen.children) {
@@ -6394,7 +6439,7 @@ export class Canvas {
6394
6439
  pen.text = this.inputDiv.dataset.value;
6395
6440
  pen.calculative.text = pen.text;
6396
6441
  this.inputDiv.dataset.penId = undefined;
6397
- if (pen.text && pen.textAutoAdjust) {
6442
+ if (pen.text && pen.textAutoAdjust && !pen.parentId) {
6398
6443
  calcTextAutoWidth(pen);
6399
6444
  }
6400
6445
  calcTextRect(pen);
@@ -6952,7 +6997,7 @@ export class Canvas {
6952
6997
  const oldRect = deepClone(rect);
6953
6998
  const storeData = this.store.data;
6954
6999
  // TODO: 目前背景颜色优先级更高
6955
- const isDrawBkImg = containBkImg && !storeData.background && this.store.bkImg;
7000
+ const isDrawBkImg = containBkImg && this.store.bkImg;
6956
7001
  // 主体在背景的右侧,下侧
6957
7002
  let isRight = false, isBottom = false;
6958
7003
  if (isDrawBkImg) {
@@ -7023,16 +7068,11 @@ export class Canvas {
7023
7068
  ctx.textBaseline = 'middle'; // 默认垂直居中
7024
7069
  ctx.scale(scale, scale);
7025
7070
  const background = this.store.data.background || this.store.options.background;
7026
- if (background) {
7071
+ if (background && isV) {
7027
7072
  // 绘制背景颜色
7028
7073
  ctx.save();
7029
7074
  ctx.fillStyle = background;
7030
- if (isV) {
7031
- ctx.fillRect(0, 0, vRect.width + (p[1] + p[3]) * _scale, vRect.height + (p[0] + p[2]) * _scale);
7032
- }
7033
- else {
7034
- ctx.fillRect(0, 0, oldRect.width + (p[3] + p[1]) * _scale, oldRect.height + (p[0] + p[2]) * _scale);
7035
- }
7075
+ ctx.fillRect(0, 0, vRect.width + (p[1] + p[3]) * _scale, vRect.height + (p[0] + p[2]) * _scale);
7036
7076
  ctx.restore();
7037
7077
  }
7038
7078
  if (isDrawBkImg) {
@@ -7045,6 +7085,23 @@ export class Canvas {
7045
7085
  ctx.drawImage(this.store.bkImg, x, y, this.canvasRect.width, this.canvasRect.height);
7046
7086
  }
7047
7087
  }
7088
+ if (background && !isV) {
7089
+ // 绘制背景颜色
7090
+ if (isDrawBkImg) {
7091
+ const x = rect.x < 0 ? -rect.x : 0;
7092
+ const y = rect.y < 0 ? -rect.y : 0;
7093
+ ctx.save();
7094
+ ctx.fillStyle = background;
7095
+ ctx.fillRect(x, y, this.canvasRect.width, this.canvasRect.height);
7096
+ ctx.restore();
7097
+ }
7098
+ else {
7099
+ ctx.save();
7100
+ ctx.fillStyle = background;
7101
+ ctx.fillRect(0, 0, oldRect.width + (p[3] + p[1]) * _scale, oldRect.height + (p[0] + p[2]) * _scale);
7102
+ ctx.restore();
7103
+ }
7104
+ }
7048
7105
  if (!isDrawBkImg) {
7049
7106
  ctx.translate(-rect.x, -rect.y);
7050
7107
  }