@meta2d/core 1.0.64 → 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.64",
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
  /**
@@ -146,7 +146,7 @@ export class Canvas {
146
146
  setHover(hover, false);
147
147
  };
148
148
  this.popconfirm = new Popconfirm(parentElement, store);
149
- this.dialog = new Dialog(parentElement);
149
+ this.dialog = new Dialog(parentElement, store);
150
150
  this.title = new Title(parentElement);
151
151
  if (this.store.options.scroll) {
152
152
  this.scroll = new Scroll(this);
@@ -366,7 +366,7 @@ export class Canvas {
366
366
  }
367
367
  let data = JSON.parse(e.data);
368
368
  if (typeof data === 'object') {
369
- this.parent.doMessageEvent(data.name, data.value);
369
+ this.parent.doMessageEvent(data.name, JSON.stringify(data.data));
370
370
  }
371
371
  else {
372
372
  this.parent.doMessageEvent(data);
@@ -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
  }
@@ -2208,7 +2216,12 @@ export class Canvas {
2208
2216
  if (e.button !== 2) {
2209
2217
  if (distance(this.mouseDown, e) < 2) {
2210
2218
  if (this.store.hover && this.store.hover.input) {
2211
- this.showInput(this.store.hover);
2219
+ if (this.store.hover.onShowInput) {
2220
+ this.store.hover.onShowInput(this.store.hover, e);
2221
+ }
2222
+ else {
2223
+ this.showInput(this.store.hover);
2224
+ }
2212
2225
  }
2213
2226
  this.store.emitter.emit('click', {
2214
2227
  x: e.x,
@@ -3523,7 +3536,13 @@ export class Canvas {
3523
3536
  this.updatePenRect(pen);
3524
3537
  return;
3525
3538
  }
3526
- 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
+ }
3527
3546
  this.store.pens[pen.id] = pen;
3528
3547
  // 集中存储path,避免数据冗余过大
3529
3548
  if (pen.path) {
@@ -4101,7 +4120,11 @@ export class Canvas {
4101
4120
  }
4102
4121
  };
4103
4122
  renderPenContainChild = (ctx, pen) => {
4104
- pen.calculative.inView && renderPen(ctx, pen); // 可见才绘制,组合为状态只显示其中一个
4123
+ if (pen.calculative.inView) {
4124
+ if (!(pen.name === 'combine' && !pen.draw)) {
4125
+ renderPen(ctx, pen); // 可见才绘制,组合为状态只显示其中一个
4126
+ }
4127
+ }
4105
4128
  pen.children?.forEach((id) => {
4106
4129
  const child = this.store.pens[id];
4107
4130
  child && this.renderPenContainChild(ctx, child);
@@ -4322,6 +4345,7 @@ export class Canvas {
4322
4345
  }
4323
4346
  ctx.restore();
4324
4347
  };
4348
+ transTimeout;
4325
4349
  translate(x = 0, y = 0) {
4326
4350
  this.store.data.x += x * this.store.data.scale;
4327
4351
  this.store.data.y += y * this.store.data.scale;
@@ -4366,10 +4390,21 @@ export class Canvas {
4366
4390
  }
4367
4391
  //TODO 当初为什么加异步
4368
4392
  // setTimeout(() => {
4369
- this.canvasTemplate.init();
4370
- this.canvasImage.init();
4371
- this.canvasImageBottom.init();
4372
- 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
+ }
4373
4408
  // });
4374
4409
  this.store.emitter.emit('translate', {
4375
4410
  x: this.store.data.x,
@@ -5666,9 +5701,9 @@ export class Canvas {
5666
5701
  copyPens.sort((a, b) => {
5667
5702
  return a.copyIndex - b.copyIndex;
5668
5703
  });
5669
- copyPens.forEach((activePen) => {
5670
- delete activePen.copyIndex;
5671
- });
5704
+ // copyPens.forEach((activePen: any) => {
5705
+ // delete activePen.copyIndex;
5706
+ // });
5672
5707
  const clipboard = {
5673
5708
  meta2d: true,
5674
5709
  pens: copyPens,
@@ -5677,6 +5712,7 @@ export class Canvas {
5677
5712
  page,
5678
5713
  initRect: deepClone(this.activeRect),
5679
5714
  offset: 10,
5715
+ mousePos: deepClone(this.mousePos),
5680
5716
  };
5681
5717
  if (navigator.clipboard &&
5682
5718
  !this.store.options.disableClipboard &&
@@ -5741,7 +5777,14 @@ export class Canvas {
5741
5777
  }
5742
5778
  this.store.clipboard = deepClone(clipboard);
5743
5779
  const curPage = sessionStorage.getItem('page');
5744
- 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) {
5745
5788
  this.store.clipboard.pos = { x: this.mousePos.x, y: this.mousePos.y };
5746
5789
  this.store.clipboard.offset = 0;
5747
5790
  }
@@ -5753,6 +5796,11 @@ export class Canvas {
5753
5796
  offset && (this.store.clipboard.offset = offset);
5754
5797
  pos && (this.store.clipboard.pos = pos);
5755
5798
  }
5799
+ if (!this.keyOptions.F) {
5800
+ this.store.clipboard.pens.forEach((pen) => {
5801
+ delete pen.copyIndex;
5802
+ });
5803
+ }
5756
5804
  const rootPens = this.store.clipboard.pens.filter((pen) => !pen.parentId);
5757
5805
  for (const pen of rootPens) {
5758
5806
  this.pastePen(pen, undefined);
@@ -5850,7 +5898,7 @@ export class Canvas {
5850
5898
  pen.x = -this.store.data.x + this.width / 2 - pen.width / 2;
5851
5899
  pen.y = -this.store.data.y + this.height / 2 - pen.height / 2;
5852
5900
  }
5853
- 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)) {
5854
5902
  }
5855
5903
  else {
5856
5904
  pen.x += this.store.clipboard.offset * this.store.data.scale;
@@ -6156,9 +6204,9 @@ export class Canvas {
6156
6204
  // this.inputDiv.style.fontSize = pen.calculative.fontSize + 'px';
6157
6205
  // this.inputDiv.style.color = getTextColor(pen, this.store);
6158
6206
  this.inputParent.style.left =
6159
- textRect.x + this.store.data.x - (pen.textLeft || 0) + 'px'; //+ 5
6207
+ textRect.x + this.store.data.x - (pen.calculative.textLeft || 0) + 'px'; //+ 5
6160
6208
  this.inputParent.style.top =
6161
- textRect.y + this.store.data.y - (pen.textTop || 0) + 'px'; //+ 5
6209
+ textRect.y + this.store.data.y - (pen.calculative.textTop || 0) + 'px'; //+ 5
6162
6210
  let _width = textRect.width; //+ (pen.textLeft || 0);
6163
6211
  this.inputParent.style.width = (_width < 0 ? 12 : _width) + 'px'; //(textRect.width < pen.width ? 0 : 10)
6164
6212
  this.inputParent.style.height = textRect.height + (pen.textTop || 0) + 'px'; // (textRect.height < pen.height ? 0 : 10)
@@ -6180,6 +6228,8 @@ export class Canvas {
6180
6228
  // }
6181
6229
  this.dropdown.style.background = pen.dropdownBackground || '#fff';
6182
6230
  this.dropdown.style.color = pen.dropdownColor || '#bdc7db';
6231
+ this.dropdown.style.width = this.inputParent.style.width;
6232
+ this.dropdown.style.fontSize = (pen.fontSize || 12) + 'px';
6183
6233
  this.setDropdownList();
6184
6234
  this.externalElements.style.zIndex = '9999';
6185
6235
  }
@@ -6387,7 +6437,7 @@ export class Canvas {
6387
6437
  pen.text = this.inputDiv.dataset.value;
6388
6438
  pen.calculative.text = pen.text;
6389
6439
  this.inputDiv.dataset.penId = undefined;
6390
- if (pen.text && pen.textAutoAdjust) {
6440
+ if (pen.text && pen.textAutoAdjust && !pen.parentId) {
6391
6441
  calcTextAutoWidth(pen);
6392
6442
  }
6393
6443
  calcTextRect(pen);
@@ -6442,7 +6492,7 @@ export class Canvas {
6442
6492
  sheet.insertRule('.meta2d-input{display:none;position:absolute;outline:none;align-items: center;}');
6443
6493
  sheet.insertRule('.meta2d-input textarea{resize:none;border:none;outline:none;background:transparent;flex-grow:1;height:100%;left:0;top:0}');
6444
6494
  sheet.insertRule('.meta2d-input .right{width:10px;height:10px;flex-shrink:0;border-top: 1px solid;border-right: 1px solid;margin-right: 5px;transition: all .3s cubic-bezier(.645,.045,.355,1);position:absolute;right:1px;}');
6445
- sheet.insertRule('.meta2d-input ul{position:absolute;top:100%;left:-5px;width:calc(100% + 10px);min-height:30px;border-radius: 2px;box-shadow: 0 2px 8px #00000026;list-style-type: none;background-color: #fff;padding: 4px 0;max-height: 105px;overflow-y: auto;}');
6495
+ sheet.insertRule('.meta2d-input ul{position:absolute;top:100%;margin-top:4px; width:calc(100% + 10px);min-height:30px;border-radius: 2px;box-shadow: 0 2px 8px #00000026;list-style-type: none;background-color: #fff;padding: 4px 0;max-height: 105px;overflow-y: auto;}');
6446
6496
  sheet.insertRule('.meta2d-input ul li{padding: 5px 12px;line-height: 22px;white-space: nowrap;cursor: pointer;}');
6447
6497
  sheet.insertRule('.meta2d-input ul li:hover{background: #eeeeee;}');
6448
6498
  sheet.insertRule(`.input-div::-webkit-scrollbar {display:none}`);
@@ -7055,6 +7105,9 @@ export class Canvas {
7055
7105
  if (!isShowChild(pen, this.store) || pen.visible == false) {
7056
7106
  continue;
7057
7107
  }
7108
+ if (pen.name === 'combine' && !pen.draw) {
7109
+ continue;
7110
+ }
7058
7111
  // TODO: hover 待考虑,若出现再补上
7059
7112
  const { active } = pen.calculative;
7060
7113
  pen.calculative.active = false;