@meta2d/core 1.0.30 → 1.0.32
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 +2 -2
- package/src/canvas/canvas.js +19 -2
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +7 -2
- package/src/core.js +78 -20
- package/src/core.js.map +1 -1
- package/src/diagrams/line/polyline.js +19 -0
- package/src/diagrams/line/polyline.js.map +1 -1
- package/src/pen/render.js +3 -1
- package/src/pen/render.js.map +1 -1
- package/src/scroll/scroll.js +2 -0
- package/src/scroll/scroll.js.map +1 -1
package/src/core.d.ts
CHANGED
|
@@ -54,7 +54,7 @@ export declare class Meta2d {
|
|
|
54
54
|
initEventFns(): void;
|
|
55
55
|
navigatorTo(id: string): void;
|
|
56
56
|
doSendDataEvent(value: any, topics?: string): void;
|
|
57
|
-
sendDataToNetWork(value: any,
|
|
57
|
+
sendDataToNetWork(value: any, _network: Network): Promise<void>;
|
|
58
58
|
resize(width?: number, height?: number): void;
|
|
59
59
|
/**
|
|
60
60
|
*
|
|
@@ -63,7 +63,7 @@ export declare class Meta2d {
|
|
|
63
63
|
addPen(pen: Pen, history?: boolean, emit?: boolean): Promise<Pen>;
|
|
64
64
|
addPens(pens: Pen[], history?: boolean): Promise<Pen[]>;
|
|
65
65
|
render(patchFlags?: boolean | number): void;
|
|
66
|
-
setBackgroundImage(url: string): Promise<void>;
|
|
66
|
+
setBackgroundImage(url: string, data?: any): Promise<void>;
|
|
67
67
|
setBackgroundColor(color?: string): void;
|
|
68
68
|
setGrid({ grid, gridColor, gridSize, gridRotate, }?: {
|
|
69
69
|
grid?: boolean;
|
|
@@ -341,6 +341,11 @@ export declare class Meta2d {
|
|
|
341
341
|
* @param pens 本次改变的 pens
|
|
342
342
|
*/
|
|
343
343
|
initImageCanvas(pens: Pen[]): void;
|
|
344
|
+
/**
|
|
345
|
+
* 模版图元图层改变
|
|
346
|
+
* @param pens 本次改变的 pens
|
|
347
|
+
*/
|
|
348
|
+
initTemplateCanvas(pens: Pen[]): void;
|
|
344
349
|
/**
|
|
345
350
|
* 该画笔置底,即放到数组最前,最后绘制即在底部
|
|
346
351
|
* @param pens 画笔们,注意 pen 必须在该数组内才有效
|
package/src/core.js
CHANGED
|
@@ -347,6 +347,21 @@ var Meta2d = /** @class */ (function () {
|
|
|
347
347
|
});
|
|
348
348
|
Meta2d.prototype.setOptions = function (opts) {
|
|
349
349
|
if (opts === void 0) { opts = {}; }
|
|
350
|
+
if (opts.grid !== undefined ||
|
|
351
|
+
opts.gridColor !== undefined ||
|
|
352
|
+
opts.gridSize !== undefined) {
|
|
353
|
+
this.setGrid({
|
|
354
|
+
grid: opts.grid,
|
|
355
|
+
gridColor: opts.gridColor,
|
|
356
|
+
gridSize: opts.gridSize,
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
if (opts.rule !== undefined || opts.ruleColor !== undefined) {
|
|
360
|
+
this.setRule({
|
|
361
|
+
rule: opts.rule,
|
|
362
|
+
ruleColor: opts.ruleColor,
|
|
363
|
+
});
|
|
364
|
+
}
|
|
350
365
|
this.store.options = Object.assign(this.store.options, opts);
|
|
351
366
|
if (this.canvas && opts.scroll !== undefined) {
|
|
352
367
|
if (opts.scroll) {
|
|
@@ -403,7 +418,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
403
418
|
// TODO: 若频繁地触发,重复 render 可能带来性能问题,待考虑
|
|
404
419
|
var value = e.value;
|
|
405
420
|
if (value && typeof value === 'object') {
|
|
406
|
-
var pens = e.params ? _this.find(e.params) :
|
|
421
|
+
var pens = e.params ? _this.find(e.params) : _this.find(pen.id);
|
|
407
422
|
pens.forEach(function (pen) {
|
|
408
423
|
if (value.hasOwnProperty('visible')) {
|
|
409
424
|
_this.setVisible(pen, value.visible);
|
|
@@ -636,12 +651,13 @@ var Meta2d = /** @class */ (function () {
|
|
|
636
651
|
}
|
|
637
652
|
this.store.emitter.emit('sendData', data);
|
|
638
653
|
};
|
|
639
|
-
Meta2d.prototype.sendDataToNetWork = function (value,
|
|
654
|
+
Meta2d.prototype.sendDataToNetWork = function (value, _network) {
|
|
640
655
|
return __awaiter(this, void 0, void 0, function () {
|
|
641
|
-
var i, keys, params, res, clients_1, mqttClient_1, websockets, websocket_1;
|
|
656
|
+
var network, i, keys, params, res, clients_1, mqttClient_1, websockets, websocket_1;
|
|
642
657
|
return __generator(this, function (_a) {
|
|
643
658
|
switch (_a.label) {
|
|
644
659
|
case 0:
|
|
660
|
+
network = deepClone(_network);
|
|
645
661
|
if (!network.url) {
|
|
646
662
|
return [2 /*return*/];
|
|
647
663
|
}
|
|
@@ -755,7 +771,8 @@ var Meta2d = /** @class */ (function () {
|
|
|
755
771
|
var _a;
|
|
756
772
|
(_a = this.canvas) === null || _a === void 0 ? void 0 : _a.render(patchFlags);
|
|
757
773
|
};
|
|
758
|
-
Meta2d.prototype.setBackgroundImage = function (url) {
|
|
774
|
+
Meta2d.prototype.setBackgroundImage = function (url, data) {
|
|
775
|
+
var _a, _b, _c, _e;
|
|
759
776
|
return __awaiter(this, void 0, void 0, function () {
|
|
760
777
|
function loadImage(url) {
|
|
761
778
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -778,13 +795,13 @@ var Meta2d = /** @class */ (function () {
|
|
|
778
795
|
});
|
|
779
796
|
}
|
|
780
797
|
var that, width, height, img;
|
|
781
|
-
return __generator(this, function (
|
|
782
|
-
switch (
|
|
798
|
+
return __generator(this, function (_f) {
|
|
799
|
+
switch (_f.label) {
|
|
783
800
|
case 0:
|
|
784
801
|
that = this;
|
|
785
802
|
this.store.data.bkImage = url;
|
|
786
|
-
width = this.store.data.width || this.store.options.width;
|
|
787
|
-
height = this.store.data.height || this.store.options.height;
|
|
803
|
+
width = (data === null || data === void 0 ? void 0 : data.width) || ((_a = this.store.data) === null || _a === void 0 ? void 0 : _a.width) || ((_b = this.store.options) === null || _b === void 0 ? void 0 : _b.width);
|
|
804
|
+
height = (data === null || data === void 0 ? void 0 : data.height) || ((_c = this.store.data) === null || _c === void 0 ? void 0 : _c.height) || ((_e = this.store.options) === null || _e === void 0 ? void 0 : _e.height);
|
|
788
805
|
if (width && height) {
|
|
789
806
|
this.canvas.canvasTemplate.canvas.style.backgroundImage = null;
|
|
790
807
|
this.canvas && (this.canvas.canvasTemplate.bgPatchFlags = true);
|
|
@@ -797,13 +814,19 @@ var Meta2d = /** @class */ (function () {
|
|
|
797
814
|
if (!url) return [3 /*break*/, 2];
|
|
798
815
|
return [4 /*yield*/, loadImage(url)];
|
|
799
816
|
case 1:
|
|
800
|
-
img =
|
|
817
|
+
img = _f.sent();
|
|
801
818
|
// 用作 toPng 的绘制
|
|
802
819
|
this.store.bkImg = img;
|
|
820
|
+
if (width && height) {
|
|
821
|
+
if (this.canvas) {
|
|
822
|
+
this.canvas.canvasTemplate.init();
|
|
823
|
+
this.render();
|
|
824
|
+
}
|
|
825
|
+
}
|
|
803
826
|
return [3 /*break*/, 3];
|
|
804
827
|
case 2:
|
|
805
828
|
this.store.bkImg = null;
|
|
806
|
-
|
|
829
|
+
_f.label = 3;
|
|
807
830
|
case 3: return [2 /*return*/];
|
|
808
831
|
}
|
|
809
832
|
});
|
|
@@ -837,7 +860,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
837
860
|
this.clear(false, data.template);
|
|
838
861
|
this.canvas.autoPolylineFlag = true;
|
|
839
862
|
if (data) {
|
|
840
|
-
this.setBackgroundImage(data.bkImage);
|
|
863
|
+
this.setBackgroundImage(data.bkImage, data);
|
|
841
864
|
Object.assign(this.store.data, data);
|
|
842
865
|
this.store.data.pens = [];
|
|
843
866
|
try {
|
|
@@ -2043,11 +2066,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
2043
2066
|
_this.store.data.pens.forEach(function (pen) {
|
|
2044
2067
|
_this.penMock(pen);
|
|
2045
2068
|
});
|
|
2046
|
-
https.forEach(function (
|
|
2047
|
-
var i, keys, i, keys, res, data;
|
|
2069
|
+
https.forEach(function (_item) { return __awaiter(_this, void 0, void 0, function () {
|
|
2070
|
+
var item, i, keys, i, keys, res, data;
|
|
2048
2071
|
return __generator(this, function (_a) {
|
|
2049
2072
|
switch (_a.label) {
|
|
2050
2073
|
case 0:
|
|
2074
|
+
item = deepClone(_item);
|
|
2051
2075
|
if (!item.url) return [3 /*break*/, 3];
|
|
2052
2076
|
if (typeof item.headers === 'object') {
|
|
2053
2077
|
for (i in item.headers) {
|
|
@@ -2937,15 +2961,36 @@ var Meta2d = /** @class */ (function () {
|
|
|
2937
2961
|
};
|
|
2938
2962
|
Meta2d.prototype.clearFormatPainter = function () {
|
|
2939
2963
|
var _this = this;
|
|
2940
|
-
var
|
|
2964
|
+
var pens = this.store.active;
|
|
2965
|
+
var initPens = deepClone(pens);
|
|
2941
2966
|
formatAttrs.forEach(function (attr) {
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2967
|
+
for (var i = 0; i < pens.length; i++) {
|
|
2968
|
+
var pen = pens[i];
|
|
2969
|
+
var _a = _this.store.options, fontSize = _a.fontSize, lineHeight = _a.lineHeight;
|
|
2970
|
+
if (attr === 'lineWidth') {
|
|
2971
|
+
pen.lineWidth = 1;
|
|
2972
|
+
pen.calculative.lineWidth = 1;
|
|
2973
|
+
}
|
|
2974
|
+
else if (attr === 'fontSize') {
|
|
2975
|
+
pen.fontSize = fontSize;
|
|
2976
|
+
pen.calculative.fontSize = fontSize;
|
|
2977
|
+
}
|
|
2978
|
+
else if (attr === 'lineHeight') {
|
|
2979
|
+
pen.lineHeight = lineHeight;
|
|
2980
|
+
pen.calculative.lineHeight = lineHeight;
|
|
2981
|
+
}
|
|
2982
|
+
else {
|
|
2983
|
+
delete pen[attr];
|
|
2984
|
+
delete pen.calculative[attr];
|
|
2985
|
+
}
|
|
2986
|
+
}
|
|
2987
|
+
});
|
|
2988
|
+
this.render();
|
|
2989
|
+
this.pushHistory({
|
|
2990
|
+
type: EditType.Update,
|
|
2991
|
+
initPens: initPens,
|
|
2992
|
+
pens: pens,
|
|
2946
2993
|
});
|
|
2947
|
-
localStorage.setItem('meta2d-formatPainter', JSON.stringify(attrs));
|
|
2948
|
-
this.formatPainter();
|
|
2949
2994
|
};
|
|
2950
2995
|
Meta2d.prototype.alignNodes = function (align, pens, rect) {
|
|
2951
2996
|
var e_8, _a;
|
|
@@ -3256,6 +3301,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3256
3301
|
if (index > -1) {
|
|
3257
3302
|
_pens.push(_pens[index]);
|
|
3258
3303
|
_pens.splice(index, 1);
|
|
3304
|
+
_this.initTemplateCanvas([pen]);
|
|
3259
3305
|
_this.initImageCanvas([pen]);
|
|
3260
3306
|
}
|
|
3261
3307
|
_this.specificLayerMove(pen, 'top');
|
|
@@ -3284,6 +3330,13 @@ var Meta2d = /** @class */ (function () {
|
|
|
3284
3330
|
Meta2d.prototype.initImageCanvas = function (pens) {
|
|
3285
3331
|
this.canvas.initImageCanvas(pens);
|
|
3286
3332
|
};
|
|
3333
|
+
/**
|
|
3334
|
+
* 模版图元图层改变
|
|
3335
|
+
* @param pens 本次改变的 pens
|
|
3336
|
+
*/
|
|
3337
|
+
Meta2d.prototype.initTemplateCanvas = function (pens) {
|
|
3338
|
+
this.canvas.initTemplateCanvas(pens);
|
|
3339
|
+
};
|
|
3287
3340
|
/**
|
|
3288
3341
|
* 该画笔置底,即放到数组最前,最后绘制即在底部
|
|
3289
3342
|
* @param pens 画笔们,注意 pen 必须在该数组内才有效
|
|
@@ -3304,6 +3357,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3304
3357
|
if (index > -1) {
|
|
3305
3358
|
_pens.unshift(_pens[index]);
|
|
3306
3359
|
_pens.splice(index + 1, 1);
|
|
3360
|
+
this_2.initTemplateCanvas([pen_1]);
|
|
3307
3361
|
this_2.initImageCanvas([pen_1]);
|
|
3308
3362
|
}
|
|
3309
3363
|
this_2.specificLayerMove(pen_1, 'bottom');
|
|
@@ -3464,6 +3518,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3464
3518
|
_this.specificLayerMove(_pen, 'up');
|
|
3465
3519
|
});
|
|
3466
3520
|
_pens.splice.apply(_pens, __spreadArray([lastIndex_1 + 1, 0], __read(orderPens), false));
|
|
3521
|
+
this_4.initTemplateCanvas(orderPens);
|
|
3467
3522
|
this_4.initImageCanvas(orderPens);
|
|
3468
3523
|
}
|
|
3469
3524
|
else {
|
|
@@ -3471,6 +3526,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3471
3526
|
if (index > -1 && index !== _pens.length - 1) {
|
|
3472
3527
|
_pens.splice(index + 2, 0, _pens[index]);
|
|
3473
3528
|
_pens.splice(index, 1);
|
|
3529
|
+
this_4.initTemplateCanvas([pen]);
|
|
3474
3530
|
this_4.initImageCanvas([pen]);
|
|
3475
3531
|
}
|
|
3476
3532
|
this_4.specificLayerMove(pen, 'up');
|
|
@@ -3532,6 +3588,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3532
3588
|
_this.specificLayerMove(_pen, 'down');
|
|
3533
3589
|
});
|
|
3534
3590
|
_pens.splice.apply(_pens, __spreadArray([firstIndex_1 - 1, 0], __read(orderPens), false));
|
|
3591
|
+
this_5.initTemplateCanvas(orderPens);
|
|
3535
3592
|
this_5.initImageCanvas(orderPens);
|
|
3536
3593
|
}
|
|
3537
3594
|
else {
|
|
@@ -3539,6 +3596,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3539
3596
|
if (index > -1 && index !== 0) {
|
|
3540
3597
|
_pens.splice(index - 1, 0, _pens[index]);
|
|
3541
3598
|
_pens.splice(index + 1, 1);
|
|
3599
|
+
this_5.initTemplateCanvas([pen]);
|
|
3542
3600
|
this_5.initImageCanvas([pen]);
|
|
3543
3601
|
}
|
|
3544
3602
|
this_5.specificLayerMove(pen, 'down');
|