@meta2d/core 1.0.62 → 1.0.64

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.62",
3
+ "version": "1.0.64",
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",
@@ -14,6 +14,7 @@ import { Meta2d } from '../core';
14
14
  import { Dialog } from '../dialog';
15
15
  import { Title } from '../title';
16
16
  import { CanvasTemplate } from './canvasTemplate';
17
+ import { Popconfirm } from '../popconfirm';
17
18
  export declare const movingSuffix: "-moving";
18
19
  export declare class Canvas {
19
20
  parent: Meta2d;
@@ -108,6 +109,7 @@ export declare class Canvas {
108
109
  inputDiv: HTMLDivElement;
109
110
  dropdown: HTMLUListElement;
110
111
  tooltip: Tooltip;
112
+ popconfirm: Popconfirm;
111
113
  title: Title;
112
114
  mousePos: Point;
113
115
  scroll: Scroll;
@@ -127,7 +129,7 @@ export declare class Canvas {
127
129
  listen(): void;
128
130
  onCopy: (event: ClipboardEvent) => void;
129
131
  onCut: (event: ClipboardEvent) => void;
130
- onPaste: (event: ClipboardEvent) => void;
132
+ onPaste: (event: ClipboardEvent) => Promise<void>;
131
133
  onMessage: (e: MessageEvent) => void;
132
134
  onwheel: (e: WheelEvent) => void;
133
135
  onkeydown: (e: KeyboardEvent) => void;
@@ -143,7 +145,7 @@ export declare class Canvas {
143
145
  ondrop: (event: DragEvent) => Promise<void>;
144
146
  dropPens(pens: Pen[], e: Point): Promise<void>;
145
147
  randomCombineId(pen: Pen, pens: Pen[], parentId?: string): Pen;
146
- addPens(pens: Pen[], history?: boolean): Promise<Pen[]>;
148
+ addPens(pens: Pen[], history?: boolean, abs?: boolean): Promise<Pen[]>;
147
149
  ontouchstart: (e: TouchEvent) => void;
148
150
  ontouchmove: (event: TouchEvent) => void;
149
151
  ontouchend: (event: TouchEvent) => void;
@@ -237,7 +239,7 @@ export declare class Canvas {
237
239
  inAnchor(pt: Point, pen: Pen, anchor: Point): HoverType;
238
240
  resize(w?: number, h?: number): void;
239
241
  clearCanvas(): void;
240
- addPen(pen: Pen, history?: boolean, emit?: boolean): Promise<Pen>;
242
+ addPen(pen: Pen, history?: boolean, emit?: boolean, abs?: boolean): Promise<Pen>;
241
243
  pushHistory(action: EditAction): void;
242
244
  undo(): void;
243
245
  redo(): void;
@@ -18,6 +18,7 @@ import { setter } from '../utils/object';
18
18
  import { Title } from '../title';
19
19
  import { CanvasTemplate } from './canvasTemplate';
20
20
  import { getLinePoints } from '../diagrams/line';
21
+ import { Popconfirm } from '../popconfirm';
21
22
  export const movingSuffix = '-moving';
22
23
  export class Canvas {
23
24
  parent;
@@ -97,6 +98,7 @@ export class Canvas {
97
98
  // inputRight = document.createElement('div');
98
99
  dropdown = document.createElement('ul');
99
100
  tooltip;
101
+ popconfirm;
100
102
  title;
101
103
  mousePos = { x: 0, y: 0 };
102
104
  scroll;
@@ -143,6 +145,7 @@ export class Canvas {
143
145
  let hover = this.store.data.pens.find((item) => item.calculative.hover === true);
144
146
  setHover(hover, false);
145
147
  };
148
+ this.popconfirm = new Popconfirm(parentElement, store);
146
149
  this.dialog = new Dialog(parentElement);
147
150
  this.title = new Title(parentElement);
148
151
  if (this.store.options.scroll) {
@@ -282,7 +285,7 @@ export class Canvas {
282
285
  }
283
286
  this.cut();
284
287
  };
285
- onPaste = (event) => {
288
+ onPaste = async (event) => {
286
289
  if (this.store.data.locked || this.store.options.disableClipboard) {
287
290
  return;
288
291
  }
@@ -313,29 +316,39 @@ export class Canvas {
313
316
  const blob = items[i].getAsFile();
314
317
  let name = items[i].type.slice(6) === 'gif' ? 'gif' : 'image';
315
318
  if (blob !== null) {
316
- let base64_str;
317
- const reader = new FileReader();
318
- reader.onload = (e) => {
319
- base64_str = e.target.result;
320
- const image = new Image();
321
- image.src = base64_str;
322
- image.onload = () => {
323
- const { width, height } = image;
324
- const pen = {
325
- name,
326
- x: x - 50 / 2,
327
- y: y - (height / width) * 50,
328
- externElement: name === 'gif',
329
- width: 100,
330
- height: (height / width) * 100,
331
- image: base64_str,
332
- };
333
- this.addPens([pen]);
334
- this.active([pen]);
335
- this.copy([pen]);
336
- };
337
- };
338
- 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);
339
352
  }
340
353
  }
341
354
  }
@@ -1229,7 +1242,7 @@ export class Canvas {
1229
1242
  pen.children = newChildren;
1230
1243
  return pen;
1231
1244
  }
1232
- async addPens(pens, history) {
1245
+ async addPens(pens, history, abs) {
1233
1246
  if (this.beforeAddPens && (await this.beforeAddPens(pens)) != true) {
1234
1247
  return [];
1235
1248
  }
@@ -1238,6 +1251,12 @@ export class Canvas {
1238
1251
  if (this.beforeAddPen && this.beforeAddPen(pen) != true) {
1239
1252
  continue;
1240
1253
  }
1254
+ if (abs) {
1255
+ pen.x = pen.x * this.store.data.scale + this.store.data.origin.x;
1256
+ pen.y = pen.y * this.store.data.scale + this.store.data.origin.y;
1257
+ pen.width = pen.width * this.store.data.scale;
1258
+ pen.height = pen.height * this.store.data.scale;
1259
+ }
1241
1260
  this.makePen(pen);
1242
1261
  list.push(pen);
1243
1262
  }
@@ -1462,6 +1481,7 @@ export class Canvas {
1462
1481
  this.mouseRight = MouseRight.Down;
1463
1482
  }
1464
1483
  this.hideInput();
1484
+ this.popconfirm.hide();
1465
1485
  if (this.store.data.locked === LockState.Disable ||
1466
1486
  (e.buttons !== 1 && e.buttons !== 2)) {
1467
1487
  this.hoverType = HoverType.None;
@@ -3210,13 +3230,19 @@ export class Canvas {
3210
3230
  this.canvasImage.clear();
3211
3231
  this.canvasImageBottom.clear();
3212
3232
  }
3213
- async addPen(pen, history, emit) {
3233
+ async addPen(pen, history, emit, abs) {
3214
3234
  if (this.beforeAddPens && (await this.beforeAddPens([pen])) != true) {
3215
3235
  return;
3216
3236
  }
3217
3237
  if (this.beforeAddPen && this.beforeAddPen(pen) != true) {
3218
3238
  return;
3219
3239
  }
3240
+ if (abs) {
3241
+ pen.x = pen.x * this.store.data.scale + this.store.data.origin.x;
3242
+ pen.y = pen.y * this.store.data.scale + this.store.data.origin.y;
3243
+ pen.width = pen.width * this.store.data.scale;
3244
+ pen.height = pen.height * this.store.data.scale;
3245
+ }
3220
3246
  this.makePen(pen);
3221
3247
  this.active([pen]);
3222
3248
  this.render();
@@ -6155,6 +6181,7 @@ export class Canvas {
6155
6181
  this.dropdown.style.background = pen.dropdownBackground || '#fff';
6156
6182
  this.dropdown.style.color = pen.dropdownColor || '#bdc7db';
6157
6183
  this.setDropdownList();
6184
+ this.externalElements.style.zIndex = '9999';
6158
6185
  }
6159
6186
  else {
6160
6187
  // this.inputRight.style.display = 'none';
@@ -6337,6 +6364,7 @@ export class Canvas {
6337
6364
  });
6338
6365
  }
6339
6366
  hideInput = () => {
6367
+ this.externalElements.style.zIndex = '5';
6340
6368
  if (this.inputParent.style.display === 'flex') {
6341
6369
  this.inputParent.style.display = 'none';
6342
6370
  const pen = this.store.pens[this.inputDiv.dataset.penId];
@@ -6715,7 +6743,12 @@ export class Canvas {
6715
6743
  // 单属性
6716
6744
  if (k.indexOf('.') === -1) {
6717
6745
  if (k === 'rotate') {
6718
- oldRotate = pen.calculative.rotate || 0;
6746
+ if (pen.disableRotate) { //当图元禁止旋转时不重新设置旋转角度
6747
+ pen.rotate = pen.calculative.rotate || 0;
6748
+ }
6749
+ else {
6750
+ oldRotate = pen.calculative.rotate || 0;
6751
+ }
6719
6752
  }
6720
6753
  else if (k === 'canvasLayer' || k === 'isBottom' || k === 'showChild') {
6721
6754
  containIsBottom = true;
@@ -6724,7 +6757,9 @@ export class Canvas {
6724
6757
  willRenderImage = true;
6725
6758
  }
6726
6759
  if (typeof pen[k] !== 'object' || k === 'lineDash') {
6727
- pen.calculative[k] = data[k];
6760
+ if (!pen.disableRotate || k !== 'rotate') { //当图元禁止旋转时不重新设置旋转角度
6761
+ pen.calculative[k] = data[k];
6762
+ }
6728
6763
  }
6729
6764
  if (needCalcTextRectProps.includes(k)) {
6730
6765
  willCalcTextRect = true;
@@ -7607,6 +7642,7 @@ export class Canvas {
7607
7642
  this.tooltip?.destroy();
7608
7643
  this.dialog?.destroy();
7609
7644
  this.title?.destroy();
7645
+ this.popconfirm?.destroy();
7610
7646
  // ios
7611
7647
  this.externalElements.removeEventListener('gesturestart', this.onGesturestart);
7612
7648
  this.externalElements.ondragover = (e) => e.preventDefault();