@meta2d/core 1.0.27 → 1.0.29
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 +17 -0
- package/src/canvas/canvas.js +150 -8
- package/src/canvas/canvas.js.map +1 -1
- package/src/canvas/canvasImage.d.ts +0 -1
- package/src/canvas/canvasImage.js +94 -65
- package/src/canvas/canvasImage.js.map +1 -1
- package/src/canvas/canvasTemplate.d.ts +19 -0
- package/src/canvas/canvasTemplate.js +194 -0
- package/src/canvas/canvasTemplate.js.map +1 -0
- package/src/core.d.ts +10 -1
- package/src/core.js +84 -10
- package/src/core.js.map +1 -1
- package/src/diagrams/iframe.js +97 -5
- package/src/diagrams/iframe.js.map +1 -1
- package/src/diagrams/line/polyline.js +1 -0
- package/src/diagrams/line/polyline.js.map +1 -1
- package/src/pen/model.d.ts +2 -1
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.js +1 -1
- package/src/store/store.d.ts +7 -2
- package/src/store/store.js +36 -1
- package/src/store/store.js.map +1 -1
- package/src/utils/index.d.ts +2 -0
- package/src/utils/index.js +2 -0
- package/src/utils/index.js.map +1 -1
- package/src/utils/url.d.ts +1 -0
- package/src/utils/url.js +20 -0
- package/src/utils/url.js.map +1 -1
package/src/core.js
CHANGED
|
@@ -752,7 +752,8 @@ var Meta2d = /** @class */ (function () {
|
|
|
752
752
|
});
|
|
753
753
|
};
|
|
754
754
|
Meta2d.prototype.render = function (patchFlags) {
|
|
755
|
-
|
|
755
|
+
var _a;
|
|
756
|
+
(_a = this.canvas) === null || _a === void 0 ? void 0 : _a.render(patchFlags);
|
|
756
757
|
};
|
|
757
758
|
Meta2d.prototype.setBackgroundImage = function (url) {
|
|
758
759
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -786,6 +787,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
786
787
|
height = this.store.data.height || this.store.options.height;
|
|
787
788
|
if (width && height) {
|
|
788
789
|
this.canvas.canvasImageBottom.canvas.style.backgroundImage = null;
|
|
790
|
+
this.canvas && (this.canvas.canvasTemplate.bgPatchFlags = true);
|
|
789
791
|
}
|
|
790
792
|
else {
|
|
791
793
|
this.canvas.canvasImageBottom.canvas.style.backgroundImage = url
|
|
@@ -810,7 +812,8 @@ var Meta2d = /** @class */ (function () {
|
|
|
810
812
|
Meta2d.prototype.setBackgroundColor = function (color) {
|
|
811
813
|
if (color === void 0) { color = this.store.data.background; }
|
|
812
814
|
this.store.data.background = color;
|
|
813
|
-
this.store.patchFlagsBackground = true;
|
|
815
|
+
// this.store.patchFlagsBackground = true;
|
|
816
|
+
this.canvas && (this.canvas.canvasTemplate.bgPatchFlags = true);
|
|
814
817
|
};
|
|
815
818
|
Meta2d.prototype.setGrid = function (_a) {
|
|
816
819
|
var _b = _a === void 0 ? {} : _a, _c = _b.grid, grid = _c === void 0 ? this.store.data.grid : _c, _e = _b.gridColor, gridColor = _e === void 0 ? this.store.data.gridColor : _e, _f = _b.gridSize, gridSize = _f === void 0 ? this.store.data.gridSize : _f, _g = _b.gridRotate, gridRotate = _g === void 0 ? this.store.data.gridRotate : _g;
|
|
@@ -818,7 +821,8 @@ var Meta2d = /** @class */ (function () {
|
|
|
818
821
|
this.store.data.gridColor = gridColor;
|
|
819
822
|
this.store.data.gridSize = gridSize;
|
|
820
823
|
this.store.data.gridRotate = gridRotate;
|
|
821
|
-
this.store.patchFlagsBackground = true;
|
|
824
|
+
// this.store.patchFlagsBackground = true;
|
|
825
|
+
this.canvas && (this.canvas.canvasTemplate.bgPatchFlags = true);
|
|
822
826
|
};
|
|
823
827
|
Meta2d.prototype.setRule = function (_a) {
|
|
824
828
|
var _b = _a === void 0 ? {} : _a, _c = _b.rule, rule = _c === void 0 ? this.store.data.rule : _c, _e = _b.ruleColor, ruleColor = _e === void 0 ? this.store.data.ruleColor : _e;
|
|
@@ -830,7 +834,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
830
834
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _e;
|
|
831
835
|
var _this = this;
|
|
832
836
|
if (render === void 0) { render = true; }
|
|
833
|
-
this.clear(false);
|
|
837
|
+
this.clear(false, data.template);
|
|
834
838
|
this.canvas.autoPolylineFlag = true;
|
|
835
839
|
if (data) {
|
|
836
840
|
this.setBackgroundImage(data.bkImage);
|
|
@@ -886,6 +890,9 @@ var Meta2d = /** @class */ (function () {
|
|
|
886
890
|
_this.canvas.initLineRect(pen);
|
|
887
891
|
}
|
|
888
892
|
});
|
|
893
|
+
if (!this.store.data.template) {
|
|
894
|
+
this.store.data.template = s8();
|
|
895
|
+
}
|
|
889
896
|
if (!render) {
|
|
890
897
|
this.canvas.opening = true;
|
|
891
898
|
}
|
|
@@ -1150,7 +1157,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
1150
1157
|
* 擦除画布,释放 store 上的 pens
|
|
1151
1158
|
* @param render 是否重绘
|
|
1152
1159
|
*/
|
|
1153
|
-
Meta2d.prototype.clear = function (render) {
|
|
1160
|
+
Meta2d.prototype.clear = function (render, template) {
|
|
1154
1161
|
var e_5, _a;
|
|
1155
1162
|
var _b;
|
|
1156
1163
|
if (render === void 0) { render = true; }
|
|
@@ -1167,7 +1174,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
1167
1174
|
}
|
|
1168
1175
|
finally { if (e_5) throw e_5.error; }
|
|
1169
1176
|
}
|
|
1170
|
-
clearStore(this.store);
|
|
1177
|
+
clearStore(this.store, template);
|
|
1171
1178
|
this.hideInput();
|
|
1172
1179
|
this.canvas.tooltip.hide();
|
|
1173
1180
|
if (this.map && this.map.isShow) {
|
|
@@ -1178,7 +1185,10 @@ var Meta2d = /** @class */ (function () {
|
|
|
1178
1185
|
sessionStorage.removeItem('page');
|
|
1179
1186
|
this.store.clipboard = undefined;
|
|
1180
1187
|
// 非必要,为的是 open 时重绘 背景与网格
|
|
1181
|
-
this.store.patchFlagsBackground = true;
|
|
1188
|
+
// this.store.patchFlagsBackground = true;
|
|
1189
|
+
if (!this.store.sameTemplate) {
|
|
1190
|
+
this.canvas.canvasTemplate.bgPatchFlags = true;
|
|
1191
|
+
}
|
|
1182
1192
|
this.store.patchFlagsTop = true;
|
|
1183
1193
|
this.setBackgroundImage(undefined);
|
|
1184
1194
|
render && this.render();
|
|
@@ -2480,7 +2490,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
2480
2490
|
try {
|
|
2481
2491
|
for (var _c = __values(this.store.data.pens), _e = _c.next(); !_e.done; _e = _c.next()) {
|
|
2482
2492
|
var pen = _e.value;
|
|
2483
|
-
if (pen.calculative.img) {
|
|
2493
|
+
if (pen.calculative.img || ['iframe'].includes(pen.name)) {
|
|
2484
2494
|
//重新生成绘制图片
|
|
2485
2495
|
(_b = pen.onRenderPenRaw) === null || _b === void 0 ? void 0 : _b.call(pen, pen);
|
|
2486
2496
|
}
|
|
@@ -2500,7 +2510,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
2500
2510
|
var evt = document.createEvent('MouseEvents');
|
|
2501
2511
|
evt.initEvent('click', true, true);
|
|
2502
2512
|
a.dispatchEvent(evt);
|
|
2503
|
-
});
|
|
2513
|
+
}, 1000);
|
|
2504
2514
|
};
|
|
2505
2515
|
Meta2d.prototype.downloadSvg = function () {
|
|
2506
2516
|
var e_7, _a;
|
|
@@ -2553,6 +2563,20 @@ var Meta2d = /** @class */ (function () {
|
|
|
2553
2563
|
if (pens === void 0) { pens = this.store.data.pens; }
|
|
2554
2564
|
return getRect(pens);
|
|
2555
2565
|
};
|
|
2566
|
+
Meta2d.prototype.hiddenTemplate = function () {
|
|
2567
|
+
this.canvas.canvasTemplate.hidden();
|
|
2568
|
+
};
|
|
2569
|
+
Meta2d.prototype.showTemplate = function () {
|
|
2570
|
+
this.canvas.canvasTemplate.show();
|
|
2571
|
+
};
|
|
2572
|
+
Meta2d.prototype.lockTemplate = function (lock) {
|
|
2573
|
+
//锁定
|
|
2574
|
+
this.store.data.pens.forEach(function (pen) {
|
|
2575
|
+
if (pen.template) {
|
|
2576
|
+
pen.locked = lock;
|
|
2577
|
+
}
|
|
2578
|
+
});
|
|
2579
|
+
};
|
|
2556
2580
|
/**
|
|
2557
2581
|
* 放大到屏幕尺寸,并居中
|
|
2558
2582
|
* @param fit true,填满但完整展示;false,填满,但长边可能截取(即显示不完整)
|
|
@@ -2587,6 +2611,56 @@ var Meta2d = /** @class */ (function () {
|
|
|
2587
2611
|
// 5. 居中
|
|
2588
2612
|
this.centerView();
|
|
2589
2613
|
};
|
|
2614
|
+
Meta2d.prototype.trimPens = function () {
|
|
2615
|
+
//去除空连线
|
|
2616
|
+
var pens = this.store.data.pens.filter(function (pen) { return pen.name === 'line' && pen.anchors.length < 2; });
|
|
2617
|
+
this.delete(pens);
|
|
2618
|
+
};
|
|
2619
|
+
/**
|
|
2620
|
+
* 放大到屏幕尺寸,并居中
|
|
2621
|
+
* @param fit true,填满但完整展示;false,填满,但长边可能截取(即显示不完整)
|
|
2622
|
+
*/
|
|
2623
|
+
Meta2d.prototype.fitTemplateView = function (fit, viewPadding) {
|
|
2624
|
+
var _this = this;
|
|
2625
|
+
if (fit === void 0) { fit = true; }
|
|
2626
|
+
if (viewPadding === void 0) { viewPadding = 10; }
|
|
2627
|
+
// 默认垂直填充,两边留白
|
|
2628
|
+
if (!this.hasView())
|
|
2629
|
+
return;
|
|
2630
|
+
// 1. 重置画布尺寸为容器尺寸
|
|
2631
|
+
var canvas = this.canvas.canvas;
|
|
2632
|
+
var width = canvas.offsetWidth, height = canvas.offsetHeight;
|
|
2633
|
+
// 2. 获取设置的留白值
|
|
2634
|
+
var padding = formatPadding(viewPadding);
|
|
2635
|
+
// 3. 获取图形尺寸
|
|
2636
|
+
var rect = this.getRect();
|
|
2637
|
+
// 4. 计算缩放比例
|
|
2638
|
+
var w = (width - padding[1] - padding[3]) / rect.width;
|
|
2639
|
+
var h = (height - padding[0] - padding[2]) / rect.height;
|
|
2640
|
+
var ratio = w;
|
|
2641
|
+
if (fit) {
|
|
2642
|
+
// 完整显示取小的
|
|
2643
|
+
ratio = w > h ? h : w;
|
|
2644
|
+
}
|
|
2645
|
+
else {
|
|
2646
|
+
ratio = w > h ? w : h;
|
|
2647
|
+
}
|
|
2648
|
+
// 该方法直接更改画布的 scale 属性,所以比率应该乘以当前 scale
|
|
2649
|
+
this.canvas.templateScale(ratio * this.store.data.scale);
|
|
2650
|
+
var _rect = this.getRect();
|
|
2651
|
+
var pens = this.store.data.pens.filter(function (pen) { return !pen.parentId; });
|
|
2652
|
+
this.canvas.templateTranslatePens(pens, -_rect.x, -_rect.y);
|
|
2653
|
+
// 5. 居中
|
|
2654
|
+
this.store.data.pens.forEach(function (pen) {
|
|
2655
|
+
if (!pen.type) {
|
|
2656
|
+
_this.canvas.updateLines(pen);
|
|
2657
|
+
}
|
|
2658
|
+
else {
|
|
2659
|
+
_this.canvas.initLineRect(pen);
|
|
2660
|
+
}
|
|
2661
|
+
});
|
|
2662
|
+
this.centerView();
|
|
2663
|
+
};
|
|
2590
2664
|
Meta2d.prototype.fitSizeView = function (fit, viewPadding) {
|
|
2591
2665
|
if (fit === void 0) { fit = true; }
|
|
2592
2666
|
if (viewPadding === void 0) { viewPadding = 10; }
|
|
@@ -3339,7 +3413,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3339
3413
|
}
|
|
3340
3414
|
else if (type === 'up') {
|
|
3341
3415
|
zIndex =
|
|
3342
|
-
pen.calculative.zIndex === undefined ?
|
|
3416
|
+
pen.calculative.zIndex === undefined ? 6 : pen.calculative.zIndex + 1;
|
|
3343
3417
|
}
|
|
3344
3418
|
else if (type === 'down') {
|
|
3345
3419
|
zIndex =
|