@meta2d/core 1.0.65 → 1.0.66

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.66",
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;
@@ -6394,7 +6437,7 @@ export class Canvas {
6394
6437
  pen.text = this.inputDiv.dataset.value;
6395
6438
  pen.calculative.text = pen.text;
6396
6439
  this.inputDiv.dataset.penId = undefined;
6397
- if (pen.text && pen.textAutoAdjust) {
6440
+ if (pen.text && pen.textAutoAdjust && !pen.parentId) {
6398
6441
  calcTextAutoWidth(pen);
6399
6442
  }
6400
6443
  calcTextRect(pen);