@meta2d/core 1.0.63 → 1.0.65

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.63",
3
+ "version": "1.0.65",
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",
@@ -129,7 +129,7 @@ export declare class Canvas {
129
129
  listen(): void;
130
130
  onCopy: (event: ClipboardEvent) => void;
131
131
  onCut: (event: ClipboardEvent) => void;
132
- onPaste: (event: ClipboardEvent) => void;
132
+ onPaste: (event: ClipboardEvent) => Promise<void>;
133
133
  onMessage: (e: MessageEvent) => void;
134
134
  onwheel: (e: WheelEvent) => void;
135
135
  onkeydown: (e: KeyboardEvent) => void;
@@ -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);
@@ -285,7 +285,7 @@ export class Canvas {
285
285
  }
286
286
  this.cut();
287
287
  };
288
- onPaste = (event) => {
288
+ onPaste = async (event) => {
289
289
  if (this.store.data.locked || this.store.options.disableClipboard) {
290
290
  return;
291
291
  }
@@ -316,29 +316,39 @@ export class Canvas {
316
316
  const blob = items[i].getAsFile();
317
317
  let name = items[i].type.slice(6) === 'gif' ? 'gif' : 'image';
318
318
  if (blob !== null) {
319
- let base64_str;
320
- const reader = new FileReader();
321
- reader.onload = (e) => {
322
- base64_str = e.target.result;
323
- const image = new Image();
324
- image.src = base64_str;
325
- image.onload = () => {
326
- const { width, height } = image;
327
- const pen = {
328
- name,
329
- x: x - 50 / 2,
330
- y: y - (height / width) * 50,
331
- externElement: name === 'gif',
332
- width: 100,
333
- height: (height / width) * 100,
334
- image: base64_str,
335
- };
336
- this.addPens([pen]);
337
- this.active([pen]);
338
- this.copy([pen]);
339
- };
340
- };
341
- reader.readAsDataURL(blob);
319
+ const isGif = name === 'gif';
320
+ const pen = await this.fileToPen(blob, isGif);
321
+ pen.height = (pen.height / pen.width) * 100,
322
+ pen.width = 100;
323
+ pen.x = x - 50 / 2,
324
+ pen.y = y - (pen.height / pen.width) * 50,
325
+ pen.externElement = isGif,
326
+ this.addPens([pen]);
327
+ this.active([pen]);
328
+ this.copy([pen]);
329
+ // let base64_str: any;
330
+ // const reader = new FileReader();
331
+ // reader.onload = (e) => {
332
+ // base64_str = e.target.result;
333
+ // const image = new Image();
334
+ // image.src = base64_str;
335
+ // image.onload = () => {
336
+ // const { width, height } = image;
337
+ // const pen = {
338
+ // name,
339
+ // x: x - 50 / 2,
340
+ // y: y - (height / width) * 50,
341
+ // externElement: name === 'gif',
342
+ // width: 100,
343
+ // height: (height / width) * 100,
344
+ // image: base64_str as any,
345
+ // };
346
+ // this.addPens([pen]);
347
+ // this.active([pen]);
348
+ // this.copy([pen]);
349
+ // };
350
+ // };
351
+ // reader.readAsDataURL(blob);
342
352
  }
343
353
  }
344
354
  }
@@ -356,7 +366,7 @@ export class Canvas {
356
366
  }
357
367
  let data = JSON.parse(e.data);
358
368
  if (typeof data === 'object') {
359
- this.parent.doMessageEvent(data.name, data.value);
369
+ this.parent.doMessageEvent(data.name, JSON.stringify(data.data));
360
370
  }
361
371
  else {
362
372
  this.parent.doMessageEvent(data);
@@ -2198,7 +2208,12 @@ export class Canvas {
2198
2208
  if (e.button !== 2) {
2199
2209
  if (distance(this.mouseDown, e) < 2) {
2200
2210
  if (this.store.hover && this.store.hover.input) {
2201
- this.showInput(this.store.hover);
2211
+ if (this.store.hover.onShowInput) {
2212
+ this.store.hover.onShowInput(this.store.hover, e);
2213
+ }
2214
+ else {
2215
+ this.showInput(this.store.hover);
2216
+ }
2202
2217
  }
2203
2218
  this.store.emitter.emit('click', {
2204
2219
  x: e.x,
@@ -6146,9 +6161,9 @@ export class Canvas {
6146
6161
  // this.inputDiv.style.fontSize = pen.calculative.fontSize + 'px';
6147
6162
  // this.inputDiv.style.color = getTextColor(pen, this.store);
6148
6163
  this.inputParent.style.left =
6149
- textRect.x + this.store.data.x - (pen.textLeft || 0) + 'px'; //+ 5
6164
+ textRect.x + this.store.data.x - (pen.calculative.textLeft || 0) + 'px'; //+ 5
6150
6165
  this.inputParent.style.top =
6151
- textRect.y + this.store.data.y - (pen.textTop || 0) + 'px'; //+ 5
6166
+ textRect.y + this.store.data.y - (pen.calculative.textTop || 0) + 'px'; //+ 5
6152
6167
  let _width = textRect.width; //+ (pen.textLeft || 0);
6153
6168
  this.inputParent.style.width = (_width < 0 ? 12 : _width) + 'px'; //(textRect.width < pen.width ? 0 : 10)
6154
6169
  this.inputParent.style.height = textRect.height + (pen.textTop || 0) + 'px'; // (textRect.height < pen.height ? 0 : 10)
@@ -6170,7 +6185,10 @@ export class Canvas {
6170
6185
  // }
6171
6186
  this.dropdown.style.background = pen.dropdownBackground || '#fff';
6172
6187
  this.dropdown.style.color = pen.dropdownColor || '#bdc7db';
6188
+ this.dropdown.style.width = this.inputParent.style.width;
6189
+ this.dropdown.style.fontSize = (pen.fontSize || 12) + 'px';
6173
6190
  this.setDropdownList();
6191
+ this.externalElements.style.zIndex = '9999';
6174
6192
  }
6175
6193
  else {
6176
6194
  // this.inputRight.style.display = 'none';
@@ -6353,6 +6371,7 @@ export class Canvas {
6353
6371
  });
6354
6372
  }
6355
6373
  hideInput = () => {
6374
+ this.externalElements.style.zIndex = '5';
6356
6375
  if (this.inputParent.style.display === 'flex') {
6357
6376
  this.inputParent.style.display = 'none';
6358
6377
  const pen = this.store.pens[this.inputDiv.dataset.penId];
@@ -6430,7 +6449,7 @@ export class Canvas {
6430
6449
  sheet.insertRule('.meta2d-input{display:none;position:absolute;outline:none;align-items: center;}');
6431
6450
  sheet.insertRule('.meta2d-input textarea{resize:none;border:none;outline:none;background:transparent;flex-grow:1;height:100%;left:0;top:0}');
6432
6451
  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;}');
6433
- 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;}');
6452
+ 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;}');
6434
6453
  sheet.insertRule('.meta2d-input ul li{padding: 5px 12px;line-height: 22px;white-space: nowrap;cursor: pointer;}');
6435
6454
  sheet.insertRule('.meta2d-input ul li:hover{background: #eeeeee;}');
6436
6455
  sheet.insertRule(`.input-div::-webkit-scrollbar {display:none}`);
@@ -7043,6 +7062,9 @@ export class Canvas {
7043
7062
  if (!isShowChild(pen, this.store) || pen.visible == false) {
7044
7063
  continue;
7045
7064
  }
7065
+ if (pen.name === 'combine' && !pen.draw) {
7066
+ continue;
7067
+ }
7046
7068
  // TODO: hover 待考虑,若出现再补上
7047
7069
  const { active } = pen.calculative;
7048
7070
  pen.calculative.active = false;