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