@meta2d/core 1.1.1 → 1.1.3
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 +1 -1
- package/src/canvas/canvas.d.ts +2 -0
- package/src/canvas/canvas.js +94 -30
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +3 -1
- package/src/core.js +70 -40
- package/src/core.js.map +1 -1
- package/src/diagrams/iframe.js +2 -2
- package/src/diagrams/iframe.js.map +1 -1
- package/src/dialog/dialog.d.ts +13 -7
- package/src/dialog/dialog.js +28 -22
- package/src/dialog/dialog.js.map +1 -1
- package/src/pen/model.d.ts +1 -1
- package/src/pen/render.js +2 -2
- package/src/pen/render.js.map +1 -1
- package/src/scroll/scroll.d.ts +1 -1
- package/src/scroll/scroll.js +7 -2
- package/src/scroll/scroll.js.map +1 -1
package/package.json
CHANGED
package/src/canvas/canvas.d.ts
CHANGED
|
@@ -245,6 +245,7 @@ export declare class Canvas {
|
|
|
245
245
|
resize(w?: number, h?: number): void;
|
|
246
246
|
clearCanvas(): void;
|
|
247
247
|
addPen(pen: Pen, history?: boolean, emit?: boolean, abs?: boolean): Promise<Pen>;
|
|
248
|
+
addPenSync(pen: Pen, history?: boolean, emit?: boolean, abs?: boolean): Pen;
|
|
248
249
|
pushHistory(action: EditAction): void;
|
|
249
250
|
undo(): void;
|
|
250
251
|
redo(): void;
|
|
@@ -410,6 +411,7 @@ export declare class Canvas {
|
|
|
410
411
|
*/
|
|
411
412
|
changeNodeConnectedLine(oldId: string, line: Pen, pastePens: Pen[]): void;
|
|
412
413
|
delete(pens?: Pen[], canDelLocked?: boolean, history?: boolean): Promise<void>;
|
|
414
|
+
deleteSync(pens?: Pen[], canDelLocked?: boolean, history?: boolean): void;
|
|
413
415
|
private _del;
|
|
414
416
|
getDelPens(pen: Pen, delPens: Pen[]): void;
|
|
415
417
|
private getLockedParent;
|
package/src/canvas/canvas.js
CHANGED
|
@@ -394,6 +394,9 @@ export class Canvas {
|
|
|
394
394
|
data: this.dialog.data
|
|
395
395
|
}), '*');
|
|
396
396
|
}
|
|
397
|
+
if (data.name === 'closeDialog') {
|
|
398
|
+
this.dialog.hide();
|
|
399
|
+
}
|
|
397
400
|
this.parent.doMessageEvent(data.name, JSON.stringify(data.data));
|
|
398
401
|
}
|
|
399
402
|
else {
|
|
@@ -1206,6 +1209,15 @@ export class Canvas {
|
|
|
1206
1209
|
if (num % 2 === 0) {
|
|
1207
1210
|
lastH += pen.height + 10 * this.store.data.scale;
|
|
1208
1211
|
}
|
|
1212
|
+
delete pen.dataset;
|
|
1213
|
+
}
|
|
1214
|
+
if (pen.temOffsetX) {
|
|
1215
|
+
pen.x += pen.temOffsetX * this.store.data.scale;
|
|
1216
|
+
delete pen.temOffsetX;
|
|
1217
|
+
}
|
|
1218
|
+
if (pen.temOffsetY) {
|
|
1219
|
+
pen.y += pen.temOffsetY * this.store.data.scale;
|
|
1220
|
+
delete pen.temOffsetY;
|
|
1209
1221
|
}
|
|
1210
1222
|
}
|
|
1211
1223
|
}
|
|
@@ -1420,7 +1432,7 @@ export class Canvas {
|
|
|
1420
1432
|
if (len === 1) {
|
|
1421
1433
|
if (this.store.options.scroll && this.scroll && !this.store.options.scrollButScale) {
|
|
1422
1434
|
let diff = this.lastTouchY - event.touches[0].clientY;
|
|
1423
|
-
this.scroll.wheel(diff
|
|
1435
|
+
this.scroll.wheel(diff);
|
|
1424
1436
|
this.lastTouchY = event.touches[0].clientY;
|
|
1425
1437
|
return;
|
|
1426
1438
|
}
|
|
@@ -3359,6 +3371,25 @@ export class Canvas {
|
|
|
3359
3371
|
}
|
|
3360
3372
|
return pen;
|
|
3361
3373
|
}
|
|
3374
|
+
addPenSync(pen, history, emit, abs) {
|
|
3375
|
+
if (this.beforeAddPen && this.beforeAddPen(pen) != true) {
|
|
3376
|
+
return;
|
|
3377
|
+
}
|
|
3378
|
+
if (abs) {
|
|
3379
|
+
pen.x = pen.x * this.store.data.scale + this.store.data.origin.x;
|
|
3380
|
+
pen.y = pen.y * this.store.data.scale + this.store.data.origin.y;
|
|
3381
|
+
pen.width = pen.width * this.store.data.scale;
|
|
3382
|
+
pen.height = pen.height * this.store.data.scale;
|
|
3383
|
+
}
|
|
3384
|
+
this.makePen(pen);
|
|
3385
|
+
this.active([pen]);
|
|
3386
|
+
this.render();
|
|
3387
|
+
emit && this.store.emitter.emit('add', [pen]);
|
|
3388
|
+
if (history) {
|
|
3389
|
+
this.pushHistory({ type: EditType.Add, pens: [pen] });
|
|
3390
|
+
}
|
|
3391
|
+
return pen;
|
|
3392
|
+
}
|
|
3362
3393
|
pushHistory(action) {
|
|
3363
3394
|
if (this.store.data.locked) {
|
|
3364
3395
|
return;
|
|
@@ -4975,7 +5006,7 @@ export class Canvas {
|
|
|
4975
5006
|
calcRightBottom(pen.calculative.worldRect);
|
|
4976
5007
|
calcCenter(pen.calculative.worldRect);
|
|
4977
5008
|
this.updatePenRect(pen, { worldRectIsReady: true });
|
|
4978
|
-
this.execPenResize(pen);
|
|
5009
|
+
this.execPenResize(pen, true);
|
|
4979
5010
|
this.updateLines(pen);
|
|
4980
5011
|
});
|
|
4981
5012
|
this.getSizeCPs();
|
|
@@ -6321,6 +6352,31 @@ export class Canvas {
|
|
|
6321
6352
|
}
|
|
6322
6353
|
this.store.emitter.emit('delete', pens);
|
|
6323
6354
|
}
|
|
6355
|
+
deleteSync(pens = this.store.active, canDelLocked = false, history = true) {
|
|
6356
|
+
if (!pens || !pens.length) {
|
|
6357
|
+
return;
|
|
6358
|
+
}
|
|
6359
|
+
if (!canDelLocked) {
|
|
6360
|
+
pens = pens.filter((pen) => !pen.locked);
|
|
6361
|
+
}
|
|
6362
|
+
if (!pens || !pens.length) {
|
|
6363
|
+
return;
|
|
6364
|
+
}
|
|
6365
|
+
const deletePens = [];
|
|
6366
|
+
this._del(pens, deletePens, canDelLocked);
|
|
6367
|
+
this.initImageCanvas(deletePens);
|
|
6368
|
+
this.initTemplateCanvas(deletePens);
|
|
6369
|
+
this.inactive();
|
|
6370
|
+
this.clearHover();
|
|
6371
|
+
this.render();
|
|
6372
|
+
// TODO: 连线的删除 ,连接的 node 的 connectLines 会变化(删除 node ,line 的 anchors 类似),未记历史记录
|
|
6373
|
+
if (history) {
|
|
6374
|
+
if (deletePens.length === 0)
|
|
6375
|
+
return;
|
|
6376
|
+
this.pushHistory({ type: EditType.Delete, pens: deletePens });
|
|
6377
|
+
}
|
|
6378
|
+
this.store.emitter.emit('delete', pens);
|
|
6379
|
+
}
|
|
6324
6380
|
_del(pens, delPens, canDelLocked) {
|
|
6325
6381
|
if (!pens) {
|
|
6326
6382
|
return;
|
|
@@ -7301,11 +7357,11 @@ export class Canvas {
|
|
|
7301
7357
|
/**
|
|
7302
7358
|
* 执行 pen ,以及 pen 的子孙节点的 onResize 生命周期函数
|
|
7303
7359
|
*/
|
|
7304
|
-
execPenResize(pen) {
|
|
7305
|
-
pen.onResize?.(pen);
|
|
7360
|
+
execPenResize(pen, raw) {
|
|
7361
|
+
pen.onResize?.(pen, raw);
|
|
7306
7362
|
pen.children?.forEach((chlidId) => {
|
|
7307
7363
|
const child = this.store.pens[chlidId];
|
|
7308
|
-
child && this.execPenResize(child);
|
|
7364
|
+
child && this.execPenResize(child, raw);
|
|
7309
7365
|
});
|
|
7310
7366
|
}
|
|
7311
7367
|
setPenRect(pen, rect, render = true) {
|
|
@@ -7321,7 +7377,7 @@ export class Canvas {
|
|
|
7321
7377
|
pen.height = rect.height * scale;
|
|
7322
7378
|
}
|
|
7323
7379
|
this.updatePenRect(pen);
|
|
7324
|
-
this.execPenResize(pen);
|
|
7380
|
+
this.execPenResize(pen, true);
|
|
7325
7381
|
render && this.render();
|
|
7326
7382
|
}
|
|
7327
7383
|
getPenRect(pen, origin = this.store.data.origin, scale = this.store.data.scale) {
|
|
@@ -7798,45 +7854,49 @@ export class Canvas {
|
|
|
7798
7854
|
if (rect.width > 0.5) {
|
|
7799
7855
|
rect.left = true;
|
|
7800
7856
|
rect.right = true;
|
|
7801
|
-
rect.leftValue =
|
|
7802
|
-
rect.rightValue =
|
|
7857
|
+
rect.leftValue = rect.x;
|
|
7858
|
+
rect.rightValue = 1 - (rect.x + rect.width);
|
|
7803
7859
|
}
|
|
7804
7860
|
else {
|
|
7805
7861
|
if (rect.x < 0.5) {
|
|
7806
7862
|
rect.left = true;
|
|
7807
|
-
rect.leftValue =
|
|
7863
|
+
rect.leftValue = rect.x;
|
|
7864
|
+
if (rect.x > 0.2 && (rect.x + rect.width) > 0.5) {
|
|
7865
|
+
rect.right = true;
|
|
7866
|
+
rect.rightValue = 1 - (rect.x + rect.width);
|
|
7867
|
+
}
|
|
7808
7868
|
}
|
|
7809
7869
|
else {
|
|
7810
7870
|
rect.right = true;
|
|
7811
|
-
rect.rightValue =
|
|
7871
|
+
rect.rightValue = 1 - (rect.x + rect.width);
|
|
7812
7872
|
}
|
|
7813
7873
|
}
|
|
7814
|
-
if (rect.leftValue <
|
|
7874
|
+
if (rect.leftValue < 0.05) {
|
|
7815
7875
|
rect.leftValue = 0;
|
|
7816
7876
|
}
|
|
7817
|
-
if (rect.rightValue <
|
|
7877
|
+
if (rect.rightValue < 0.05) {
|
|
7818
7878
|
rect.rightValue = 0;
|
|
7819
7879
|
}
|
|
7820
7880
|
if (rect.height > 0.5) {
|
|
7821
7881
|
rect.top = true;
|
|
7822
7882
|
rect.bottom = true;
|
|
7823
|
-
rect.topValue =
|
|
7824
|
-
rect.bottomValue =
|
|
7883
|
+
rect.topValue = rect.y;
|
|
7884
|
+
rect.bottomValue = 1 - (rect.y + rect.height);
|
|
7825
7885
|
}
|
|
7826
7886
|
else {
|
|
7827
7887
|
if (rect.y < 0.5) {
|
|
7828
7888
|
rect.top = true;
|
|
7829
|
-
rect.topValue =
|
|
7889
|
+
rect.topValue = rect.y;
|
|
7830
7890
|
}
|
|
7831
7891
|
else {
|
|
7832
7892
|
rect.bottom = true;
|
|
7833
|
-
rect.bottomValue =
|
|
7893
|
+
rect.bottomValue = 1 - (rect.y + rect.height);
|
|
7834
7894
|
}
|
|
7835
7895
|
}
|
|
7836
|
-
if (rect.topValue <
|
|
7896
|
+
if (rect.topValue < 0.05) {
|
|
7837
7897
|
rect.topValue = 0;
|
|
7838
7898
|
}
|
|
7839
|
-
if (rect.bottomValue <
|
|
7899
|
+
if (rect.bottomValue < 0.05) {
|
|
7840
7900
|
rect.bottomValue = 0;
|
|
7841
7901
|
}
|
|
7842
7902
|
if (!this.store.data.fits) {
|
|
@@ -7930,45 +7990,49 @@ export class Canvas {
|
|
|
7930
7990
|
if (fit.width > 0.5) {
|
|
7931
7991
|
fit.left = true;
|
|
7932
7992
|
fit.right = true;
|
|
7933
|
-
fit.leftValue =
|
|
7934
|
-
fit.rightValue =
|
|
7993
|
+
fit.leftValue = fit.x;
|
|
7994
|
+
fit.rightValue = 1 - (fit.x + fit.width);
|
|
7935
7995
|
}
|
|
7936
7996
|
else {
|
|
7937
7997
|
if (fit.x < 0.5) {
|
|
7938
7998
|
fit.left = true;
|
|
7939
|
-
fit.leftValue =
|
|
7999
|
+
fit.leftValue = fit.x;
|
|
8000
|
+
if (fit.x > 0.2 && (fit.x + fit.width) > 0.5) {
|
|
8001
|
+
fit.right = true;
|
|
8002
|
+
fit.rightValue = 1 - (fit.x + fit.width);
|
|
8003
|
+
}
|
|
7940
8004
|
}
|
|
7941
8005
|
else {
|
|
7942
8006
|
fit.right = true;
|
|
7943
|
-
fit.rightValue =
|
|
8007
|
+
fit.rightValue = 1 - (fit.x + fit.width);
|
|
7944
8008
|
}
|
|
7945
8009
|
}
|
|
7946
|
-
if (Math.abs(fit.leftValue) <
|
|
8010
|
+
if (Math.abs(fit.leftValue) < 0.05) {
|
|
7947
8011
|
fit.leftValue = 0;
|
|
7948
8012
|
}
|
|
7949
|
-
if (Math.abs(fit.rightValue) <
|
|
8013
|
+
if (Math.abs(fit.rightValue) < 0.05) {
|
|
7950
8014
|
fit.rightValue = 0;
|
|
7951
8015
|
}
|
|
7952
8016
|
if (fit.height > 0.5) {
|
|
7953
8017
|
fit.top = true;
|
|
7954
8018
|
fit.bottom = true;
|
|
7955
|
-
fit.topValue =
|
|
7956
|
-
fit.bottomValue =
|
|
8019
|
+
fit.topValue = fit.y;
|
|
8020
|
+
fit.bottomValue = 1 - (fit.y + fit.height);
|
|
7957
8021
|
}
|
|
7958
8022
|
else {
|
|
7959
8023
|
if (fit.y < 0.5) {
|
|
7960
8024
|
fit.top = true;
|
|
7961
|
-
fit.topValue =
|
|
8025
|
+
fit.topValue = fit.y - 0;
|
|
7962
8026
|
}
|
|
7963
8027
|
else {
|
|
7964
8028
|
fit.bottom = true;
|
|
7965
|
-
fit.bottomValue =
|
|
8029
|
+
fit.bottomValue = 1 - (fit.y + fit.height);
|
|
7966
8030
|
}
|
|
7967
8031
|
}
|
|
7968
|
-
if (Math.abs(fit.topValue) <
|
|
8032
|
+
if (Math.abs(fit.topValue) < 0.05) {
|
|
7969
8033
|
fit.topValue = 0;
|
|
7970
8034
|
}
|
|
7971
|
-
if (Math.abs(fit.bottomValue) <
|
|
8035
|
+
if (Math.abs(fit.bottomValue) < 0.05) {
|
|
7972
8036
|
fit.bottomValue = 0;
|
|
7973
8037
|
}
|
|
7974
8038
|
fit.children = pens.map(pen => pen.id);
|