@meta2d/core 1.0.46 → 1.0.48
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 +4 -0
- package/src/canvas/canvas.js +123 -25
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +7 -0
- package/src/core.js +76 -13
- package/src/core.js.map +1 -1
- package/src/diagrams/line/curve.js +3 -0
- package/src/diagrams/line/curve.js.map +1 -1
- package/src/options.d.ts +5 -0
- package/src/options.js +3 -0
- package/src/options.js.map +1 -1
- package/src/pen/model.d.ts +11 -0
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.js +20 -13
- package/src/pen/render.js.map +1 -1
- package/src/store/store.d.ts +1 -0
- package/src/store/store.js.map +1 -1
- package/src/utils/math.d.ts +1 -1
- package/src/utils/math.js +17 -6
- package/src/utils/math.js.map +1 -1
package/package.json
CHANGED
package/src/canvas/canvas.d.ts
CHANGED
|
@@ -195,6 +195,8 @@ export declare class Canvas {
|
|
|
195
195
|
button?: number;
|
|
196
196
|
}) => void;
|
|
197
197
|
private addRuleLine;
|
|
198
|
+
clearRuleLines(): void;
|
|
199
|
+
get ruleLines(): Pen[];
|
|
198
200
|
/**
|
|
199
201
|
* @description 调整pen的坐标,让pen按照网格自动对齐
|
|
200
202
|
* @author Joseph Ho
|
|
@@ -227,6 +229,7 @@ export declare class Canvas {
|
|
|
227
229
|
onScroll: () => void;
|
|
228
230
|
calibrateMouse: (pt: Point) => Point;
|
|
229
231
|
clearHover(): void;
|
|
232
|
+
private getContainerHover;
|
|
230
233
|
private getHover;
|
|
231
234
|
private inPens;
|
|
232
235
|
private dockInAnchor;
|
|
@@ -428,6 +431,7 @@ export declare class Canvas {
|
|
|
428
431
|
};
|
|
429
432
|
toPng(padding?: Padding, callback?: BlobCallback, containBkImg?: boolean, maxWidth?: number): string;
|
|
430
433
|
activeToPng(padding?: Padding): string;
|
|
434
|
+
pensToPng(pens?: Pen[], padding?: Padding): string;
|
|
431
435
|
toggleAnchorMode(): void;
|
|
432
436
|
addAnchorHand(): void;
|
|
433
437
|
removeAnchorHand(): void;
|
package/src/canvas/canvas.js
CHANGED
|
@@ -100,6 +100,7 @@ import { Dialog } from '../dialog';
|
|
|
100
100
|
import { setter } from '../utils/object';
|
|
101
101
|
import { Title } from '../title';
|
|
102
102
|
import { CanvasTemplate } from './canvasTemplate';
|
|
103
|
+
import { getLinePoints } from '../diagrams/line';
|
|
103
104
|
export var movingSuffix = '-moving';
|
|
104
105
|
var Canvas = /** @class */ (function () {
|
|
105
106
|
function Canvas(parent, parentElement, store) {
|
|
@@ -639,9 +640,16 @@ var Canvas = /** @class */ (function () {
|
|
|
639
640
|
_this.store.active.forEach(function (pen) {
|
|
640
641
|
if (pen.type) {
|
|
641
642
|
pen.close = !pen.close;
|
|
643
|
+
if (pen.close) {
|
|
644
|
+
getLinePoints(pen);
|
|
645
|
+
}
|
|
642
646
|
_this.store.path2dMap.set(pen, globalStore.path2dDraws.line(pen));
|
|
643
647
|
getLineLength(pen);
|
|
644
648
|
}
|
|
649
|
+
else {
|
|
650
|
+
//图元进入编辑模式
|
|
651
|
+
pen.calculative.focus = !pen.calculative.focus;
|
|
652
|
+
}
|
|
645
653
|
});
|
|
646
654
|
_this.render();
|
|
647
655
|
}
|
|
@@ -1343,11 +1351,17 @@ var Canvas = /** @class */ (function () {
|
|
|
1343
1351
|
}
|
|
1344
1352
|
if (_this.store.active.length === 1) {
|
|
1345
1353
|
var activePen = _this.store.active[0];
|
|
1346
|
-
if (activePen.locked < LockState.DisableMove) {
|
|
1354
|
+
if (activePen.locked === undefined || activePen.locked < LockState.DisableMove) {
|
|
1347
1355
|
(_e = activePen === null || activePen === void 0 ? void 0 : activePen.onMouseMove) === null || _e === void 0 ? void 0 : _e.call(activePen, activePen, _this.mousePos);
|
|
1348
1356
|
}
|
|
1357
|
+
if (activePen.calculative.focus) {
|
|
1358
|
+
//执行图元的操作
|
|
1359
|
+
return;
|
|
1360
|
+
}
|
|
1349
1361
|
}
|
|
1350
1362
|
_this.movePens(e);
|
|
1363
|
+
//图元是否进入容器图元
|
|
1364
|
+
_this.getContainerHover(e);
|
|
1351
1365
|
return;
|
|
1352
1366
|
}
|
|
1353
1367
|
}
|
|
@@ -1446,11 +1460,17 @@ var Canvas = /** @class */ (function () {
|
|
|
1446
1460
|
return;
|
|
1447
1461
|
}
|
|
1448
1462
|
if (_this.mouseRight === MouseRight.Down) {
|
|
1449
|
-
_this.store.
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1463
|
+
if (_this.store.hover && _this.store.hover.calculative.focus) {
|
|
1464
|
+
_this.store.hover.onContextmenu &&
|
|
1465
|
+
_this.store.hover.onContextmenu(_this.store.hover, e);
|
|
1466
|
+
}
|
|
1467
|
+
else {
|
|
1468
|
+
_this.store.emitter.emit('contextmenu', {
|
|
1469
|
+
e: e,
|
|
1470
|
+
clientRect: _this.clientRect,
|
|
1471
|
+
pen: _this.store.hover,
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1454
1474
|
}
|
|
1455
1475
|
_this.mouseRight = MouseRight.None;
|
|
1456
1476
|
_this.calibrateMouse(e);
|
|
@@ -1696,6 +1716,27 @@ var Canvas = /** @class */ (function () {
|
|
|
1696
1716
|
pt.y -= _this.store.data.y;
|
|
1697
1717
|
return pt;
|
|
1698
1718
|
};
|
|
1719
|
+
this.getContainerHover = function (pt) {
|
|
1720
|
+
var _a;
|
|
1721
|
+
if (_this.dragRect) {
|
|
1722
|
+
return;
|
|
1723
|
+
}
|
|
1724
|
+
var containerPens = _this.store.data.pens.filter(function (pen) { var _a; return pen.container || ((_a = _this.store.options.containerShapes) === null || _a === void 0 ? void 0 : _a.includes(pen.name)); });
|
|
1725
|
+
if (containerPens.length) {
|
|
1726
|
+
for (var i = containerPens.length - 1; i >= 0; --i) {
|
|
1727
|
+
var pen = containerPens[i];
|
|
1728
|
+
if (pen.visible == false ||
|
|
1729
|
+
pen.calculative.inView == false ||
|
|
1730
|
+
pen.locked === LockState.Disable ||
|
|
1731
|
+
pen.calculative.active) {
|
|
1732
|
+
continue;
|
|
1733
|
+
}
|
|
1734
|
+
if (pointInRect(pt, pen.calculative.worldRect)) {
|
|
1735
|
+
(_a = pen === null || pen === void 0 ? void 0 : pen.onMouseMove) === null || _a === void 0 ? void 0 : _a.call(pen, pen, pt);
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
};
|
|
1699
1740
|
this.getHover = function (pt) {
|
|
1700
1741
|
var _a, _b;
|
|
1701
1742
|
if (_this.dragRect) {
|
|
@@ -1878,6 +1919,9 @@ var Canvas = /** @class */ (function () {
|
|
|
1878
1919
|
else {
|
|
1879
1920
|
_this.externalElements.style.cursor = _this.store.options.hoverCursor;
|
|
1880
1921
|
}
|
|
1922
|
+
if (pen.calculative.disabled) {
|
|
1923
|
+
_this.externalElements.style.cursor = 'not-allowed';
|
|
1924
|
+
}
|
|
1881
1925
|
_this.store.hover = pen;
|
|
1882
1926
|
_this.store.pointAt = pos.point;
|
|
1883
1927
|
_this.store.pointAtIndex = pos.i;
|
|
@@ -1922,6 +1966,9 @@ var Canvas = /** @class */ (function () {
|
|
|
1922
1966
|
else {
|
|
1923
1967
|
_this.externalElements.style.cursor = _this.store.options.hoverCursor;
|
|
1924
1968
|
}
|
|
1969
|
+
if (pen.calculative.disabled) {
|
|
1970
|
+
_this.externalElements.style.cursor = 'not-allowed';
|
|
1971
|
+
}
|
|
1925
1972
|
_this.store.hover = pen;
|
|
1926
1973
|
_this.initTemplateCanvas([_this.store.hover]);
|
|
1927
1974
|
hoverType = HoverType.Node;
|
|
@@ -2465,7 +2512,8 @@ var Canvas = /** @class */ (function () {
|
|
|
2465
2512
|
!_this.store.hover ||
|
|
2466
2513
|
_this.store.hover.locked ||
|
|
2467
2514
|
_this.store.hover.externElement ||
|
|
2468
|
-
_this.store.hover.disableInput
|
|
2515
|
+
_this.store.hover.disableInput ||
|
|
2516
|
+
_this.store.hover.disabled) {
|
|
2469
2517
|
return;
|
|
2470
2518
|
}
|
|
2471
2519
|
if (_this.inputDiv.dataset.penId === pen.id) {
|
|
@@ -2489,7 +2537,7 @@ var Canvas = /** @class */ (function () {
|
|
|
2489
2537
|
}
|
|
2490
2538
|
var textRect = rect || pen.calculative.worldTextRect;
|
|
2491
2539
|
//value和innerText问题
|
|
2492
|
-
var preInputText = pen.calculative.tempText
|
|
2540
|
+
var preInputText = pen.calculative.tempText === undefined ? (pen.text + '' || '') : pen.calculative.tempText;
|
|
2493
2541
|
var textArr = preInputText.replace(/\x20/g, ' ').split(/[\s\n]/);
|
|
2494
2542
|
var finalText = (textArr.join('</div><div>') + "</div>")
|
|
2495
2543
|
.replace('</div>', '')
|
|
@@ -2743,7 +2791,8 @@ var Canvas = /** @class */ (function () {
|
|
|
2743
2791
|
this.setDropdownList = function (search) {
|
|
2744
2792
|
var e_6, _a;
|
|
2745
2793
|
_this.clearDropdownList();
|
|
2746
|
-
|
|
2794
|
+
var pen = _this.store.pens[_this.inputDiv.dataset.penId];
|
|
2795
|
+
if (!_this.store.data.locked && !['table'].includes(pen.name)) {
|
|
2747
2796
|
return;
|
|
2748
2797
|
}
|
|
2749
2798
|
_this.dropdown.style.display = 'block';
|
|
@@ -2752,7 +2801,6 @@ var Canvas = /** @class */ (function () {
|
|
|
2752
2801
|
_this.inputRight.style.transform = 'rotate(315deg)';
|
|
2753
2802
|
_this.inputRight.style.zoom = _this.store.data.scale;
|
|
2754
2803
|
});
|
|
2755
|
-
var pen = _this.store.pens[_this.inputDiv.dataset.penId];
|
|
2756
2804
|
if (!pen || !pen.dropdownList) {
|
|
2757
2805
|
_this.dropdown.style.display = 'none';
|
|
2758
2806
|
_this.inputRight.style.display = 'none';
|
|
@@ -3471,6 +3519,16 @@ var Canvas = /** @class */ (function () {
|
|
|
3471
3519
|
],
|
|
3472
3520
|
});
|
|
3473
3521
|
};
|
|
3522
|
+
Canvas.prototype.clearRuleLines = function () {
|
|
3523
|
+
this.delete(this.ruleLines);
|
|
3524
|
+
};
|
|
3525
|
+
Object.defineProperty(Canvas.prototype, "ruleLines", {
|
|
3526
|
+
get: function () {
|
|
3527
|
+
return this.store.data.pens.filter(function (p) { return p.isRuleLine; });
|
|
3528
|
+
},
|
|
3529
|
+
enumerable: false,
|
|
3530
|
+
configurable: true
|
|
3531
|
+
});
|
|
3474
3532
|
/**
|
|
3475
3533
|
* @description 调整pen的坐标,让pen按照网格自动对齐
|
|
3476
3534
|
* @author Joseph Ho
|
|
@@ -4078,7 +4136,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4078
4136
|
this.doEditAction(action_1, true);
|
|
4079
4137
|
step--;
|
|
4080
4138
|
}
|
|
4081
|
-
if (action.type == EditType.Add || action.type == EditType.Delete) {
|
|
4139
|
+
if (action.type == EditType.Add || action.type == EditType.Delete || action.type == EditType.Update) {
|
|
4082
4140
|
this.activeHistory();
|
|
4083
4141
|
}
|
|
4084
4142
|
};
|
|
@@ -4096,19 +4154,27 @@ var Canvas = /** @class */ (function () {
|
|
|
4096
4154
|
this.doEditAction(action_2, false);
|
|
4097
4155
|
step--;
|
|
4098
4156
|
}
|
|
4099
|
-
if (action.type == EditType.Add || action.type == EditType.Delete) {
|
|
4157
|
+
if (action.type == EditType.Add || action.type == EditType.Delete || action.type == EditType.Update) {
|
|
4100
4158
|
this.activeHistory();
|
|
4101
4159
|
}
|
|
4102
4160
|
};
|
|
4103
4161
|
Canvas.prototype.activeHistory = function () {
|
|
4104
4162
|
var _this = this;
|
|
4163
|
+
var now = this.store.histories[this.store.historyIndex + 1];
|
|
4164
|
+
var pens = [];
|
|
4165
|
+
if (now && (now.type === EditType.Update)) {
|
|
4166
|
+
now.pens.forEach(function (pen) {
|
|
4167
|
+
pens.push(_this.store.pens[pen.id]);
|
|
4168
|
+
});
|
|
4169
|
+
this.active(pens);
|
|
4170
|
+
return;
|
|
4171
|
+
}
|
|
4105
4172
|
var before = this.store.histories[this.store.historyIndex];
|
|
4106
|
-
if (before && before.type === EditType.Add) {
|
|
4107
|
-
var pens_8 = [];
|
|
4173
|
+
if (before && (before.type === EditType.Add || before.type === EditType.Delete)) {
|
|
4108
4174
|
before.pens.forEach(function (pen) {
|
|
4109
|
-
|
|
4175
|
+
pens.push(_this.store.pens[pen.id]);
|
|
4110
4176
|
});
|
|
4111
|
-
this.active(
|
|
4177
|
+
this.active(pens);
|
|
4112
4178
|
}
|
|
4113
4179
|
};
|
|
4114
4180
|
Canvas.prototype.doEditAction = function (action, undo) {
|
|
@@ -4206,7 +4272,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4206
4272
|
break;
|
|
4207
4273
|
case EditType.Replace: {
|
|
4208
4274
|
// undo pens则为新的pen
|
|
4209
|
-
var
|
|
4275
|
+
var pens_8 = undo ? action.initPens : action.pens;
|
|
4210
4276
|
var unPens_2 = undo ? action.pens : action.initPens;
|
|
4211
4277
|
// 删除旧的
|
|
4212
4278
|
unPens_2.forEach(function (aPen) {
|
|
@@ -4227,7 +4293,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4227
4293
|
}
|
|
4228
4294
|
});
|
|
4229
4295
|
// 放置新的
|
|
4230
|
-
|
|
4296
|
+
pens_8.reverse().forEach(function (aPen) {
|
|
4231
4297
|
var _a, _b;
|
|
4232
4298
|
var pen = deepClone(aPen, true);
|
|
4233
4299
|
if (!pen.calculative) {
|
|
@@ -4245,7 +4311,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4245
4311
|
}
|
|
4246
4312
|
pen.calculative.canvas = _this;
|
|
4247
4313
|
});
|
|
4248
|
-
|
|
4314
|
+
pens_8.reverse().forEach(function (aPen) {
|
|
4249
4315
|
var pen = _this.store.data.pens.find(function (i) { return i.id === aPen.id; });
|
|
4250
4316
|
var rect = _this.getPenRect(pen, action.origin, action.scale);
|
|
4251
4317
|
_this.setPenRect(pen, rect, false);
|
|
@@ -5397,8 +5463,18 @@ var Canvas = /** @class */ (function () {
|
|
|
5397
5463
|
}
|
|
5398
5464
|
}
|
|
5399
5465
|
else {
|
|
5400
|
-
|
|
5401
|
-
|
|
5466
|
+
if (!keyOptions.ctrlKey && keyOptions.shiftKey) {
|
|
5467
|
+
offsetX = pt.x - this.store.activeAnchor.x;
|
|
5468
|
+
offsetY = 0;
|
|
5469
|
+
}
|
|
5470
|
+
else if (keyOptions.ctrlKey && !keyOptions.shiftKey) {
|
|
5471
|
+
offsetX = 0;
|
|
5472
|
+
offsetY = pt.y - this.store.activeAnchor.y;
|
|
5473
|
+
}
|
|
5474
|
+
else {
|
|
5475
|
+
offsetX = pt.x - this.store.activeAnchor.x;
|
|
5476
|
+
offsetY = pt.y - this.store.activeAnchor.y;
|
|
5477
|
+
}
|
|
5402
5478
|
}
|
|
5403
5479
|
translatePoint(this.store.activeAnchor, offsetX, offsetY);
|
|
5404
5480
|
if (this.store.hover &&
|
|
@@ -6220,6 +6296,10 @@ var Canvas = /** @class */ (function () {
|
|
|
6220
6296
|
//根据pens顺序复制
|
|
6221
6297
|
copyPens.forEach(function (activePen) {
|
|
6222
6298
|
activePen.copyIndex = _this.store.data.pens.findIndex(function (pen) { return pen.id === activePen.id; });
|
|
6299
|
+
if (activePen.pathId) {
|
|
6300
|
+
//复制svgpath
|
|
6301
|
+
activePen.path = _this.store.data.paths[activePen.pathId];
|
|
6302
|
+
}
|
|
6223
6303
|
});
|
|
6224
6304
|
copyPens.sort(function (a, b) {
|
|
6225
6305
|
return a.copyIndex - b.copyIndex;
|
|
@@ -6369,15 +6449,15 @@ var Canvas = /** @class */ (function () {
|
|
|
6369
6449
|
var e_21, _a;
|
|
6370
6450
|
var retPens = [];
|
|
6371
6451
|
try {
|
|
6372
|
-
for (var
|
|
6373
|
-
var pen =
|
|
6452
|
+
for (var pens_9 = __values(pens), pens_9_1 = pens_9.next(); !pens_9_1.done; pens_9_1 = pens_9.next()) {
|
|
6453
|
+
var pen = pens_9_1.value;
|
|
6374
6454
|
retPens.push.apply(retPens, __spreadArray([], __read(deepClone(getAllChildren(pen, this.store), true)), false));
|
|
6375
6455
|
}
|
|
6376
6456
|
}
|
|
6377
6457
|
catch (e_21_1) { e_21 = { error: e_21_1 }; }
|
|
6378
6458
|
finally {
|
|
6379
6459
|
try {
|
|
6380
|
-
if (
|
|
6460
|
+
if (pens_9_1 && !pens_9_1.done && (_a = pens_9.return)) _a.call(pens_9);
|
|
6381
6461
|
}
|
|
6382
6462
|
finally { if (e_21) throw e_21.error; }
|
|
6383
6463
|
}
|
|
@@ -6724,6 +6804,16 @@ var Canvas = /** @class */ (function () {
|
|
|
6724
6804
|
}, 300);
|
|
6725
6805
|
};
|
|
6726
6806
|
this.inputDiv.oninput = function (e) {
|
|
6807
|
+
var pen = _this.store.pens[_this.inputDiv.dataset.penId];
|
|
6808
|
+
if (pen.inputType === 'number') {
|
|
6809
|
+
var value = e.target.innerText;
|
|
6810
|
+
var numericValue = value.replace(/[^0-9]/g, ''); // 移除非数字字符
|
|
6811
|
+
// 如果输入的值不是纯数字,则替换为纯数字
|
|
6812
|
+
if (value !== numericValue) {
|
|
6813
|
+
e.preventDefault();
|
|
6814
|
+
e.target.innerText = numericValue;
|
|
6815
|
+
}
|
|
6816
|
+
}
|
|
6727
6817
|
// //无文本时,光标确保居中
|
|
6728
6818
|
if (navigator.userAgent.includes('Firefox')) {
|
|
6729
6819
|
if (!e.target.innerText.trim()) {
|
|
@@ -7217,9 +7307,17 @@ var Canvas = /** @class */ (function () {
|
|
|
7217
7307
|
return canvas.toDataURL();
|
|
7218
7308
|
};
|
|
7219
7309
|
Canvas.prototype.activeToPng = function (padding) {
|
|
7310
|
+
if (padding === void 0) { padding = 2; }
|
|
7311
|
+
return this.pensToPng(this.store.active, padding);
|
|
7312
|
+
};
|
|
7313
|
+
Canvas.prototype.pensToPng = function (pens, padding) {
|
|
7220
7314
|
var e_24, _a;
|
|
7315
|
+
if (pens === void 0) { pens = this.store.active; }
|
|
7221
7316
|
if (padding === void 0) { padding = 2; }
|
|
7222
|
-
|
|
7317
|
+
if (pens.length === 0) {
|
|
7318
|
+
return;
|
|
7319
|
+
}
|
|
7320
|
+
var allPens = this.getAllByPens(pens);
|
|
7223
7321
|
var ids = allPens.map(function (pen) { return pen.id; });
|
|
7224
7322
|
var rect = getRect(allPens);
|
|
7225
7323
|
if (!isFinite(rect.width)) {
|