@meta2d/core 1.0.24 → 1.0.26
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 +1 -0
- package/src/canvas/canvas.js +199 -99
- package/src/canvas/canvas.js.map +1 -1
- package/src/canvas/canvasImage.js +7 -8
- package/src/canvas/canvasImage.js.map +1 -1
- package/src/core.d.ts +5 -1
- package/src/core.js +220 -47
- package/src/core.js.map +1 -1
- package/src/diagrams/iframe.d.ts +0 -3
- package/src/diagrams/iframe.js +204 -21
- package/src/diagrams/iframe.js.map +1 -1
- package/src/event/event.d.ts +5 -2
- package/src/event/event.js +2 -0
- package/src/event/event.js.map +1 -1
- package/src/options.d.ts +6 -0
- package/src/options.js +1 -0
- package/src/options.js.map +1 -1
- package/src/pen/model.d.ts +4 -0
- package/src/pen/model.js +1 -1
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.js +1 -1
- package/src/pen/render.js.map +1 -1
- package/src/pen/text.js +17 -1
- package/src/pen/text.js.map +1 -1
- package/src/rect/rect.js +15 -2
- package/src/rect/rect.js.map +1 -1
- package/src/store/store.d.ts +7 -0
- package/src/store/store.js +1 -0
- package/src/store/store.js.map +1 -1
- package/src/title/title.js +9 -9
- package/src/title/title.js.map +1 -1
- package/src/utils/clone.d.ts +1 -1
- package/src/utils/clone.js +14 -4
- package/src/utils/clone.js.map +1 -1
- package/src/utils/url.d.ts +3 -0
- package/src/utils/url.js +7 -0
- package/src/utils/url.js.map +1 -0
package/src/core.js
CHANGED
|
@@ -83,7 +83,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
83
83
|
};
|
|
84
84
|
import { commonAnchors, commonPens, cube } from './diagrams';
|
|
85
85
|
import { Canvas } from './canvas';
|
|
86
|
-
import { calcInView, calcTextDrawRect, calcTextLines, calcTextRect, facePen, formatAttrs, getAllChildren, getFromAnchor, getParent, getToAnchor, getWords, LockState, PenType, renderPenRaw, setElemPosition, connectLine, nearestAnchor, setChildValue, isAncestor, } from './pen';
|
|
86
|
+
import { calcInView, calcTextDrawRect, calcTextLines, calcTextRect, facePen, formatAttrs, getAllChildren, getFromAnchor, getParent, getToAnchor, getWords, LockState, PenType, renderPenRaw, setElemPosition, connectLine, nearestAnchor, setChildValue, isAncestor, isShowChild, } from './pen';
|
|
87
87
|
import { rotatePoint } from './point';
|
|
88
88
|
import { clearStore, EditType, globalStore, register, registerAnchors, registerCanvasDraw, useStore, } from './store';
|
|
89
89
|
import { formatPadding, loadCss, s8, valueInArray, valueInRange, } from './utils';
|
|
@@ -96,6 +96,7 @@ import pkg from '../package.json';
|
|
|
96
96
|
import { lockedError } from './utils/error';
|
|
97
97
|
import { Scroll } from './scroll';
|
|
98
98
|
import { getter } from './utils/object';
|
|
99
|
+
import { queryURLParams } from './utils/url';
|
|
99
100
|
var Meta2d = /** @class */ (function () {
|
|
100
101
|
function Meta2d(parent, opts) {
|
|
101
102
|
var _this = this;
|
|
@@ -169,6 +170,13 @@ var Meta2d = /** @class */ (function () {
|
|
|
169
170
|
_this.onSizeUpdate();
|
|
170
171
|
break;
|
|
171
172
|
}
|
|
173
|
+
if (_this.store.messageEvents[eventName]) {
|
|
174
|
+
_this.store.messageEvents[eventName].forEach(function (item) {
|
|
175
|
+
item.event.actions.forEach(function (action) {
|
|
176
|
+
_this.events[action.action](item.pen, action);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
}
|
|
172
180
|
};
|
|
173
181
|
this.doEvent = function (pen, eventName) {
|
|
174
182
|
var _a, _b;
|
|
@@ -549,7 +557,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
549
557
|
this.events[EventAction.SendData] = function (pen, e) {
|
|
550
558
|
var value = deepClone(e.value);
|
|
551
559
|
if (value && typeof value === 'object') {
|
|
552
|
-
if (e.targetType === '
|
|
560
|
+
if (e.targetType === 'id') {
|
|
553
561
|
var _pen = e.params ? _this.findOne(e.params) : pen;
|
|
554
562
|
for (var key in value) {
|
|
555
563
|
if (!value[key]) {
|
|
@@ -562,6 +570,31 @@ var Meta2d = /** @class */ (function () {
|
|
|
562
570
|
}
|
|
563
571
|
}
|
|
564
572
|
};
|
|
573
|
+
this.events[EventAction.PostMessage] = function (pen, e) {
|
|
574
|
+
if (typeof e.value !== 'string') {
|
|
575
|
+
console.warn('[meta2d] Emit value must be a string');
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
var _pen = e.params ? _this.findOne(e.params) : pen;
|
|
579
|
+
if (_pen.name !== 'iframe' || !_pen.iframe) {
|
|
580
|
+
console.warn('不是嵌入页面');
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
var params = queryURLParams(_pen.iframe.split('?')[1]);
|
|
584
|
+
_pen.calculative.singleton.div.children[0].contentWindow.postMessage(JSON.stringify({
|
|
585
|
+
name: e.value,
|
|
586
|
+
id: params.id,
|
|
587
|
+
}), '*');
|
|
588
|
+
return;
|
|
589
|
+
};
|
|
590
|
+
this.events[EventAction.PostMessageToParent] = function (pen, e) {
|
|
591
|
+
if (typeof e.value !== 'string') {
|
|
592
|
+
console.warn('[meta2d] Emit value must be a string');
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
window.parent.postMessage(JSON.stringify(e.value), '*');
|
|
596
|
+
return;
|
|
597
|
+
};
|
|
565
598
|
};
|
|
566
599
|
Meta2d.prototype.navigatorTo = function (id) {
|
|
567
600
|
if (!id) {
|
|
@@ -605,18 +638,34 @@ var Meta2d = /** @class */ (function () {
|
|
|
605
638
|
};
|
|
606
639
|
Meta2d.prototype.sendDataToNetWork = function (value, network) {
|
|
607
640
|
return __awaiter(this, void 0, void 0, function () {
|
|
608
|
-
var res, clients_1, mqttClient_1, websockets, websocket_1;
|
|
641
|
+
var i, keys, params, res, clients_1, mqttClient_1, websockets, websocket_1;
|
|
609
642
|
return __generator(this, function (_a) {
|
|
610
643
|
switch (_a.label) {
|
|
611
644
|
case 0:
|
|
612
645
|
if (!network.url) {
|
|
613
646
|
return [2 /*return*/];
|
|
614
647
|
}
|
|
615
|
-
if (!(network.
|
|
616
|
-
|
|
617
|
-
|
|
648
|
+
if (!(network.protocol === 'http')) return [3 /*break*/, 2];
|
|
649
|
+
if (typeof network.headers === 'object') {
|
|
650
|
+
for (i in network.headers) {
|
|
651
|
+
keys = network.headers[i].match(/(?<=\$\{).*?(?=\})/g);
|
|
652
|
+
if (keys) {
|
|
653
|
+
network.headers[i] = network.headers[i].replace("${" + keys[0] + "}", this.getDynamicParam(keys[0]));
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
params = undefined;
|
|
658
|
+
if (network.method === 'GET') {
|
|
659
|
+
params =
|
|
660
|
+
'?' +
|
|
661
|
+
Object.keys(value)
|
|
662
|
+
.map(function (key) { return key + '=' + value[key]; })
|
|
663
|
+
.join('&');
|
|
664
|
+
}
|
|
665
|
+
return [4 /*yield*/, fetch(network.url + (params ? params : ''), {
|
|
666
|
+
headers: network.headers || {},
|
|
618
667
|
method: network.method,
|
|
619
|
-
body: value,
|
|
668
|
+
body: network.method === 'POST' ? JSON.stringify(value) : undefined,
|
|
620
669
|
})];
|
|
621
670
|
case 1:
|
|
622
671
|
res = _a.sent();
|
|
@@ -625,7 +674,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
625
674
|
}
|
|
626
675
|
return [3 /*break*/, 3];
|
|
627
676
|
case 2:
|
|
628
|
-
if (network.
|
|
677
|
+
if (network.protocol === 'mqtt') {
|
|
629
678
|
clients_1 = this.mqttClients.filter(function (client) { return client.options.href === network.url; });
|
|
630
679
|
if (clients_1 && clients_1.length) {
|
|
631
680
|
if (clients_1[0].connected) {
|
|
@@ -645,7 +694,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
645
694
|
});
|
|
646
695
|
}
|
|
647
696
|
}
|
|
648
|
-
else if (network.
|
|
697
|
+
else if (network.protocol === 'websocket') {
|
|
649
698
|
websockets = this.websockets.filter(function (socket) { return socket.url === network.url; });
|
|
650
699
|
if (websockets && websockets.length) {
|
|
651
700
|
if (websockets[0].readyState === 1) {
|
|
@@ -842,6 +891,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
842
891
|
}
|
|
843
892
|
this.initBindDatas();
|
|
844
893
|
this.initBinds();
|
|
894
|
+
this.initMessageEvents();
|
|
845
895
|
this.render();
|
|
846
896
|
this.listenSocket();
|
|
847
897
|
this.connectSocket();
|
|
@@ -1008,6 +1058,9 @@ var Meta2d = /** @class */ (function () {
|
|
|
1008
1058
|
pen.onMove && pen.onMove(pen);
|
|
1009
1059
|
}
|
|
1010
1060
|
});
|
|
1061
|
+
if (lock > 0) {
|
|
1062
|
+
this.initMessageEvents();
|
|
1063
|
+
}
|
|
1011
1064
|
};
|
|
1012
1065
|
// end - 当前鼠标位置,是否作为终点
|
|
1013
1066
|
Meta2d.prototype.finishDrawLine = function (end) {
|
|
@@ -1117,6 +1170,10 @@ var Meta2d = /** @class */ (function () {
|
|
|
1117
1170
|
clearStore(this.store);
|
|
1118
1171
|
this.hideInput();
|
|
1119
1172
|
this.canvas.tooltip.hide();
|
|
1173
|
+
if (this.map && this.map.isShow) {
|
|
1174
|
+
this.map.show();
|
|
1175
|
+
this.map.setView();
|
|
1176
|
+
}
|
|
1120
1177
|
this.canvas.clearCanvas();
|
|
1121
1178
|
sessionStorage.removeItem('page');
|
|
1122
1179
|
this.store.clipboard = undefined;
|
|
@@ -1174,9 +1231,10 @@ var Meta2d = /** @class */ (function () {
|
|
|
1174
1231
|
var _this = this;
|
|
1175
1232
|
this.stopAnimate(idOrTagOrPens);
|
|
1176
1233
|
var pens;
|
|
1234
|
+
// 没有参数 则播放有自动播放属性的动画
|
|
1177
1235
|
if (!idOrTagOrPens) {
|
|
1178
1236
|
pens = this.store.data.pens.filter(function (pen) {
|
|
1179
|
-
return (pen.type || pen.frames) && pen.autoPlay;
|
|
1237
|
+
return ((pen.type || pen.frames) && pen.autoPlay) || (pen.animations && pen.autoPlay);
|
|
1180
1238
|
});
|
|
1181
1239
|
}
|
|
1182
1240
|
else if (typeof idOrTagOrPens === 'string') {
|
|
@@ -1186,6 +1244,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
1186
1244
|
pens = idOrTagOrPens;
|
|
1187
1245
|
}
|
|
1188
1246
|
pens.forEach(function (pen) {
|
|
1247
|
+
var _a;
|
|
1189
1248
|
if (pen.calculative.pause) {
|
|
1190
1249
|
var d = Date.now() - pen.calculative.pause;
|
|
1191
1250
|
pen.calculative.pause = undefined;
|
|
@@ -1193,8 +1252,8 @@ var Meta2d = /** @class */ (function () {
|
|
|
1193
1252
|
pen.calculative.frameEnd += d;
|
|
1194
1253
|
}
|
|
1195
1254
|
else {
|
|
1255
|
+
var index = -1;
|
|
1196
1256
|
if (params !== undefined && pen.animations) {
|
|
1197
|
-
var index = -1;
|
|
1198
1257
|
if (typeof params === 'string') {
|
|
1199
1258
|
index = pen.animations.findIndex(function (animation) { return animation.name === params; });
|
|
1200
1259
|
if (index === -1) {
|
|
@@ -1209,6 +1268,11 @@ var Meta2d = /** @class */ (function () {
|
|
|
1209
1268
|
return;
|
|
1210
1269
|
}
|
|
1211
1270
|
}
|
|
1271
|
+
}
|
|
1272
|
+
else if (params === undefined) {
|
|
1273
|
+
index = ((_a = pen.animations) === null || _a === void 0 ? void 0 : _a.findIndex(function (i) { return i.autoPlay; })) || -1;
|
|
1274
|
+
}
|
|
1275
|
+
if (index !== -1) {
|
|
1212
1276
|
var animate = deepClone(pen.animations[index]);
|
|
1213
1277
|
delete animate.name;
|
|
1214
1278
|
animate.currentAnimation = index;
|
|
@@ -1651,7 +1715,9 @@ var Meta2d = /** @class */ (function () {
|
|
|
1651
1715
|
return __generator(this, function (_a) {
|
|
1652
1716
|
switch (_a.label) {
|
|
1653
1717
|
case 0: return [4 /*yield*/, fetch(item.http, {
|
|
1718
|
+
method: item.method || 'GET',
|
|
1654
1719
|
headers: item.httpHeaders,
|
|
1720
|
+
body: item.method === 'POST' ? JSON.stringify(item.body) : undefined,
|
|
1655
1721
|
})];
|
|
1656
1722
|
case 1:
|
|
1657
1723
|
res = _a.sent();
|
|
@@ -1937,6 +2003,22 @@ var Meta2d = /** @class */ (function () {
|
|
|
1937
2003
|
}
|
|
1938
2004
|
}
|
|
1939
2005
|
};
|
|
2006
|
+
//获取动态参数
|
|
2007
|
+
Meta2d.prototype.getDynamicParam = function (key) {
|
|
2008
|
+
function getCookie(name) {
|
|
2009
|
+
var arr;
|
|
2010
|
+
var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)');
|
|
2011
|
+
if ((arr = document.cookie.match(reg))) {
|
|
2012
|
+
return decodeURIComponent(arr[2]);
|
|
2013
|
+
}
|
|
2014
|
+
else {
|
|
2015
|
+
return '';
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
var params = queryURLParams();
|
|
2019
|
+
var value = params[key] || localStorage[key] || getCookie(key) || '';
|
|
2020
|
+
return value;
|
|
2021
|
+
};
|
|
1940
2022
|
Meta2d.prototype.onNetworkConnect = function (https) {
|
|
1941
2023
|
var _this = this;
|
|
1942
2024
|
var enable = this.store.data.enableMock;
|
|
@@ -1950,15 +2032,31 @@ var Meta2d = /** @class */ (function () {
|
|
|
1950
2032
|
_this.penMock(pen);
|
|
1951
2033
|
});
|
|
1952
2034
|
https.forEach(function (item) { return __awaiter(_this, void 0, void 0, function () {
|
|
1953
|
-
var res, data;
|
|
2035
|
+
var i, keys, i, keys, res, data;
|
|
1954
2036
|
return __generator(this, function (_a) {
|
|
1955
2037
|
switch (_a.label) {
|
|
1956
2038
|
case 0:
|
|
1957
2039
|
if (!item.url) return [3 /*break*/, 3];
|
|
2040
|
+
if (typeof item.headers === 'object') {
|
|
2041
|
+
for (i in item.headers) {
|
|
2042
|
+
keys = item.headers[i].match(/(?<=\$\{).*?(?=\})/g);
|
|
2043
|
+
if (keys) {
|
|
2044
|
+
item.headers[i] = item.headers[i].replace("${" + keys[0] + "}", this.getDynamicParam(keys[0]));
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
if (typeof item.body === 'object') {
|
|
2049
|
+
for (i in item.body) {
|
|
2050
|
+
keys = item.body[i].match(/(?<=\$\{).*?(?=\})/g);
|
|
2051
|
+
if (keys) {
|
|
2052
|
+
item.body[i] = item.body[i].replace("${" + keys[0] + "}", this.getDynamicParam(keys[0]));
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
1958
2056
|
return [4 /*yield*/, fetch(item.url, {
|
|
1959
2057
|
headers: item.headers,
|
|
1960
2058
|
method: item.method,
|
|
1961
|
-
body: item.method === 'GET' ? undefined : item.body,
|
|
2059
|
+
body: item.method === 'GET' ? undefined : JSON.stringify(item.body),
|
|
1962
2060
|
})];
|
|
1963
2061
|
case 1:
|
|
1964
2062
|
res = _a.sent();
|
|
@@ -2228,6 +2326,23 @@ var Meta2d = /** @class */ (function () {
|
|
|
2228
2326
|
Meta2d.prototype.clearDropdownList = function () {
|
|
2229
2327
|
this.canvas.clearDropdownList();
|
|
2230
2328
|
};
|
|
2329
|
+
Meta2d.prototype.initMessageEvents = function () {
|
|
2330
|
+
var _this = this;
|
|
2331
|
+
this.store.data.pens.forEach(function (pen) {
|
|
2332
|
+
var _a;
|
|
2333
|
+
(_a = pen.events) === null || _a === void 0 ? void 0 : _a.forEach(function (event) {
|
|
2334
|
+
if (event.name === 'message' && event.message) {
|
|
2335
|
+
if (!_this.store.messageEvents[event.message]) {
|
|
2336
|
+
_this.store.messageEvents[event.message] = [];
|
|
2337
|
+
}
|
|
2338
|
+
_this.store.messageEvents[event.message].push({
|
|
2339
|
+
pen: pen,
|
|
2340
|
+
event: event,
|
|
2341
|
+
});
|
|
2342
|
+
}
|
|
2343
|
+
});
|
|
2344
|
+
});
|
|
2345
|
+
};
|
|
2231
2346
|
Meta2d.prototype.judgeCondition = function (pen, key, condition) {
|
|
2232
2347
|
var type = condition.type, target = condition.target, fnJs = condition.fnJs, fn = condition.fn, operator = condition.operator, valueType = condition.valueType;
|
|
2233
2348
|
var can = false;
|
|
@@ -2348,6 +2463,9 @@ var Meta2d = /** @class */ (function () {
|
|
|
2348
2463
|
if (containBkImg === void 0) { containBkImg = false; }
|
|
2349
2464
|
return this.canvas.toPng(padding, callback, containBkImg);
|
|
2350
2465
|
};
|
|
2466
|
+
Meta2d.prototype.activeToPng = function (padding) {
|
|
2467
|
+
return this.canvas.activeToPng(padding);
|
|
2468
|
+
};
|
|
2351
2469
|
/**
|
|
2352
2470
|
* 下载 png
|
|
2353
2471
|
* @param name 传入参数自带文件后缀名 例如:'test.png'
|
|
@@ -2382,6 +2500,53 @@ var Meta2d = /** @class */ (function () {
|
|
|
2382
2500
|
a.dispatchEvent(evt);
|
|
2383
2501
|
});
|
|
2384
2502
|
};
|
|
2503
|
+
Meta2d.prototype.downloadSvg = function () {
|
|
2504
|
+
var e_7, _a;
|
|
2505
|
+
if (!window.C2S) {
|
|
2506
|
+
console.error('请先加载乐吾乐官网下的canvas2svg.js', 'https://assets.le5lecdn.com/2d/canvas2svg.js');
|
|
2507
|
+
throw new Error('请先加载乐吾乐官网下的canvas2svg.js');
|
|
2508
|
+
}
|
|
2509
|
+
var rect = this.getRect();
|
|
2510
|
+
rect.x -= 10;
|
|
2511
|
+
rect.y -= 10;
|
|
2512
|
+
var ctx = new window.C2S(rect.width + 20, rect.height + 20);
|
|
2513
|
+
ctx.textBaseline = 'middle';
|
|
2514
|
+
try {
|
|
2515
|
+
for (var _b = __values(this.store.data.pens), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2516
|
+
var pen = _c.value;
|
|
2517
|
+
if (pen.visible == false || !isShowChild(pen, this.store)) {
|
|
2518
|
+
continue;
|
|
2519
|
+
}
|
|
2520
|
+
renderPenRaw(ctx, pen, rect);
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
2524
|
+
finally {
|
|
2525
|
+
try {
|
|
2526
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2527
|
+
}
|
|
2528
|
+
finally { if (e_7) throw e_7.error; }
|
|
2529
|
+
}
|
|
2530
|
+
var mySerializedSVG = ctx.getSerializedSvg();
|
|
2531
|
+
if (this.store.data.background) {
|
|
2532
|
+
mySerializedSVG = mySerializedSVG.replace('{{bk}}', '');
|
|
2533
|
+
mySerializedSVG = mySerializedSVG.replace('{{bkRect}}', "<rect x=\"0\" y=\"0\" width=\"100%\" height=\"100%\" fill=\"" + this.store.data.background + "\"></rect>");
|
|
2534
|
+
}
|
|
2535
|
+
else {
|
|
2536
|
+
mySerializedSVG = mySerializedSVG.replace('{{bk}}', '');
|
|
2537
|
+
mySerializedSVG = mySerializedSVG.replace('{{bkRect}}', '');
|
|
2538
|
+
}
|
|
2539
|
+
mySerializedSVG = mySerializedSVG.replace(/--le5le--/g, '&#x');
|
|
2540
|
+
var urlObject = window.URL;
|
|
2541
|
+
var export_blob = new Blob([mySerializedSVG]);
|
|
2542
|
+
var url = urlObject.createObjectURL(export_blob);
|
|
2543
|
+
var a = document.createElement('a');
|
|
2544
|
+
a.setAttribute('download', (this.store.data.name || 'le5le.meta2d') + ".svg");
|
|
2545
|
+
a.setAttribute('href', url);
|
|
2546
|
+
var evt = document.createEvent('MouseEvents');
|
|
2547
|
+
evt.initEvent('click', true, true);
|
|
2548
|
+
a.dispatchEvent(evt);
|
|
2549
|
+
};
|
|
2385
2550
|
Meta2d.prototype.getRect = function (pens) {
|
|
2386
2551
|
if (pens === void 0) { pens = this.store.data.pens; }
|
|
2387
2552
|
return getRect(pens);
|
|
@@ -2439,12 +2604,20 @@ var Meta2d = /** @class */ (function () {
|
|
|
2439
2604
|
var w = (width - padding[1] - padding[3]) / _width;
|
|
2440
2605
|
var h = (height - padding[0] - padding[2]) / _height;
|
|
2441
2606
|
var ratio = w;
|
|
2442
|
-
if (fit) {
|
|
2443
|
-
|
|
2444
|
-
|
|
2607
|
+
if (fit === 'width') {
|
|
2608
|
+
ratio = w;
|
|
2609
|
+
}
|
|
2610
|
+
else if (fit === 'height') {
|
|
2611
|
+
ratio = h;
|
|
2445
2612
|
}
|
|
2446
2613
|
else {
|
|
2447
|
-
|
|
2614
|
+
if (fit) {
|
|
2615
|
+
// 完整显示取小的
|
|
2616
|
+
ratio = w > h ? h : w;
|
|
2617
|
+
}
|
|
2618
|
+
else {
|
|
2619
|
+
ratio = w > h ? w : h;
|
|
2620
|
+
}
|
|
2448
2621
|
}
|
|
2449
2622
|
// 该方法直接更改画布的 scale 属性,所以比率应该乘以当前 scale
|
|
2450
2623
|
this.scale(ratio * this.store.data.scale);
|
|
@@ -2699,7 +2872,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
2699
2872
|
this.formatPainter();
|
|
2700
2873
|
};
|
|
2701
2874
|
Meta2d.prototype.alignNodes = function (align, pens, rect) {
|
|
2702
|
-
var
|
|
2875
|
+
var e_8, _a;
|
|
2703
2876
|
if (pens === void 0) { pens = this.store.data.pens; }
|
|
2704
2877
|
!rect && (rect = this.getPenRect(this.getRect(pens)));
|
|
2705
2878
|
var initPens = deepClone(pens); // 原 pens ,深拷贝一下
|
|
@@ -2709,12 +2882,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
2709
2882
|
this.alignPen(align, item, rect);
|
|
2710
2883
|
}
|
|
2711
2884
|
}
|
|
2712
|
-
catch (
|
|
2885
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
2713
2886
|
finally {
|
|
2714
2887
|
try {
|
|
2715
2888
|
if (pens_1_1 && !pens_1_1.done && (_a = pens_1.return)) _a.call(pens_1);
|
|
2716
2889
|
}
|
|
2717
|
-
finally { if (
|
|
2890
|
+
finally { if (e_8) throw e_8.error; }
|
|
2718
2891
|
}
|
|
2719
2892
|
this.render();
|
|
2720
2893
|
this.pushHistory({
|
|
@@ -2803,7 +2976,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
2803
2976
|
* @param distance 总的宽 or 高
|
|
2804
2977
|
*/
|
|
2805
2978
|
Meta2d.prototype.spaceBetweenByDirection = function (direction, pens, distance) {
|
|
2806
|
-
var
|
|
2979
|
+
var e_9, _a;
|
|
2807
2980
|
var _this = this;
|
|
2808
2981
|
if (pens === void 0) { pens = this.store.data.pens; }
|
|
2809
2982
|
!distance && (distance = this.getPenRect(this.getRect(pens))[direction]);
|
|
@@ -2837,12 +3010,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
2837
3010
|
this.setValue(__assign({ id: pen.id }, penRect), { render: false, doEvent: false });
|
|
2838
3011
|
}
|
|
2839
3012
|
}
|
|
2840
|
-
catch (
|
|
3013
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
2841
3014
|
finally {
|
|
2842
3015
|
try {
|
|
2843
3016
|
if (pens_2_1 && !pens_2_1.done && (_a = pens_2.return)) _a.call(pens_2);
|
|
2844
3017
|
}
|
|
2845
|
-
finally { if (
|
|
3018
|
+
finally { if (e_9) throw e_9.error; }
|
|
2846
3019
|
}
|
|
2847
3020
|
this.render();
|
|
2848
3021
|
this.pushHistory({
|
|
@@ -2959,7 +3132,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
2959
3132
|
* @param pens pen 置顶的画笔
|
|
2960
3133
|
*/
|
|
2961
3134
|
Meta2d.prototype.top = function (pens) {
|
|
2962
|
-
var
|
|
3135
|
+
var e_10, _a;
|
|
2963
3136
|
var _this = this;
|
|
2964
3137
|
if (!pens)
|
|
2965
3138
|
pens = this.store.active;
|
|
@@ -2987,12 +3160,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
2987
3160
|
_loop_3(pen);
|
|
2988
3161
|
}
|
|
2989
3162
|
}
|
|
2990
|
-
catch (
|
|
3163
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
2991
3164
|
finally {
|
|
2992
3165
|
try {
|
|
2993
3166
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2994
3167
|
}
|
|
2995
|
-
finally { if (
|
|
3168
|
+
finally { if (e_10) throw e_10.error; }
|
|
2996
3169
|
}
|
|
2997
3170
|
};
|
|
2998
3171
|
/**
|
|
@@ -3008,7 +3181,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3008
3181
|
* @param pens 画笔们,注意 pen 必须在该数组内才有效
|
|
3009
3182
|
*/
|
|
3010
3183
|
Meta2d.prototype.bottom = function (pens) {
|
|
3011
|
-
var
|
|
3184
|
+
var e_11, _a;
|
|
3012
3185
|
if (!pens)
|
|
3013
3186
|
pens = this.store.active;
|
|
3014
3187
|
if (!Array.isArray(pens))
|
|
@@ -3039,12 +3212,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3039
3212
|
_loop_4(pen);
|
|
3040
3213
|
}
|
|
3041
3214
|
}
|
|
3042
|
-
catch (
|
|
3215
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
3043
3216
|
finally {
|
|
3044
3217
|
try {
|
|
3045
3218
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3046
3219
|
}
|
|
3047
|
-
finally { if (
|
|
3220
|
+
finally { if (e_11) throw e_11.error; }
|
|
3048
3221
|
}
|
|
3049
3222
|
};
|
|
3050
3223
|
/**
|
|
@@ -3053,7 +3226,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3053
3226
|
* @param pen 画笔
|
|
3054
3227
|
*/
|
|
3055
3228
|
Meta2d.prototype.upByArea = function (pen) {
|
|
3056
|
-
var _a,
|
|
3229
|
+
var _a, e_12, _b;
|
|
3057
3230
|
var _this = this;
|
|
3058
3231
|
var index = this.store.data.pens.findIndex(function (p) { return p.id === pen.id; });
|
|
3059
3232
|
if (index === -1) {
|
|
@@ -3103,12 +3276,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3103
3276
|
_loop_6(pen_2);
|
|
3104
3277
|
}
|
|
3105
3278
|
}
|
|
3106
|
-
catch (
|
|
3279
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
3107
3280
|
finally {
|
|
3108
3281
|
try {
|
|
3109
3282
|
if (allPens_1_1 && !allPens_1_1.done && (_b = allPens_1.return)) _b.call(allPens_1);
|
|
3110
3283
|
}
|
|
3111
|
-
finally { if (
|
|
3284
|
+
finally { if (e_12) throw e_12.error; }
|
|
3112
3285
|
}
|
|
3113
3286
|
this.initImageCanvas([pen]);
|
|
3114
3287
|
};
|
|
@@ -3149,7 +3322,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3149
3322
|
* @param pens 画笔
|
|
3150
3323
|
*/
|
|
3151
3324
|
Meta2d.prototype.up = function (pens) {
|
|
3152
|
-
var
|
|
3325
|
+
var e_13, _a;
|
|
3153
3326
|
var _this = this;
|
|
3154
3327
|
if (!pens)
|
|
3155
3328
|
pens = this.store.active;
|
|
@@ -3202,12 +3375,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3202
3375
|
_loop_7(pen);
|
|
3203
3376
|
}
|
|
3204
3377
|
}
|
|
3205
|
-
catch (
|
|
3378
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
3206
3379
|
finally {
|
|
3207
3380
|
try {
|
|
3208
3381
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3209
3382
|
}
|
|
3210
|
-
finally { if (
|
|
3383
|
+
finally { if (e_13) throw e_13.error; }
|
|
3211
3384
|
}
|
|
3212
3385
|
};
|
|
3213
3386
|
/**
|
|
@@ -3215,7 +3388,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3215
3388
|
* @param pen 画笔
|
|
3216
3389
|
*/
|
|
3217
3390
|
Meta2d.prototype.down = function (pens) {
|
|
3218
|
-
var
|
|
3391
|
+
var e_14, _a;
|
|
3219
3392
|
var _this = this;
|
|
3220
3393
|
if (!pens)
|
|
3221
3394
|
pens = this.store.active;
|
|
@@ -3270,12 +3443,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3270
3443
|
_loop_9(pen);
|
|
3271
3444
|
}
|
|
3272
3445
|
}
|
|
3273
|
-
catch (
|
|
3446
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
3274
3447
|
finally {
|
|
3275
3448
|
try {
|
|
3276
3449
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3277
3450
|
}
|
|
3278
|
-
finally { if (
|
|
3451
|
+
finally { if (e_14) throw e_14.error; }
|
|
3279
3452
|
}
|
|
3280
3453
|
};
|
|
3281
3454
|
Meta2d.prototype.setLayer = function (pen, toIndex, pens) {
|
|
@@ -3350,7 +3523,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3350
3523
|
var nextNodes_1 = [];
|
|
3351
3524
|
// 2. 遍历出线的 nextNode
|
|
3352
3525
|
lines.forEach(function (line) {
|
|
3353
|
-
var
|
|
3526
|
+
var e_15, _a;
|
|
3354
3527
|
var lineNextNode = _this.nextNode(line);
|
|
3355
3528
|
var _loop_11 = function (node) {
|
|
3356
3529
|
var have = nextNodes_1.find(function (next) { return next.id === node.id; });
|
|
@@ -3363,12 +3536,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3363
3536
|
_loop_11(node);
|
|
3364
3537
|
}
|
|
3365
3538
|
}
|
|
3366
|
-
catch (
|
|
3539
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
3367
3540
|
finally {
|
|
3368
3541
|
try {
|
|
3369
3542
|
if (lineNextNode_1_1 && !lineNextNode_1_1.done && (_a = lineNextNode_1.return)) _a.call(lineNextNode_1);
|
|
3370
3543
|
}
|
|
3371
|
-
finally { if (
|
|
3544
|
+
finally { if (e_15) throw e_15.error; }
|
|
3372
3545
|
}
|
|
3373
3546
|
});
|
|
3374
3547
|
return nextNodes_1;
|
|
@@ -3391,7 +3564,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3391
3564
|
var preNodes_1 = [];
|
|
3392
3565
|
// 2. 遍历入线的 preNode
|
|
3393
3566
|
lines.forEach(function (line) {
|
|
3394
|
-
var
|
|
3567
|
+
var e_16, _a;
|
|
3395
3568
|
var linePreNode = _this.previousNode(line);
|
|
3396
3569
|
var _loop_12 = function (node) {
|
|
3397
3570
|
var have = preNodes_1.find(function (pre) { return pre.id === node.id; });
|
|
@@ -3404,12 +3577,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3404
3577
|
_loop_12(node);
|
|
3405
3578
|
}
|
|
3406
3579
|
}
|
|
3407
|
-
catch (
|
|
3580
|
+
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
3408
3581
|
finally {
|
|
3409
3582
|
try {
|
|
3410
3583
|
if (linePreNode_1_1 && !linePreNode_1_1.done && (_a = linePreNode_1.return)) _a.call(linePreNode_1);
|
|
3411
3584
|
}
|
|
3412
|
-
finally { if (
|
|
3585
|
+
finally { if (e_16) throw e_16.error; }
|
|
3413
3586
|
}
|
|
3414
3587
|
});
|
|
3415
3588
|
return preNodes_1;
|
|
@@ -3685,7 +3858,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3685
3858
|
: deepClone(__spreadArray([parent], __read(components), false));
|
|
3686
3859
|
};
|
|
3687
3860
|
Meta2d.prototype.setVisible = function (pen, visible, render) {
|
|
3688
|
-
var
|
|
3861
|
+
var e_17, _a;
|
|
3689
3862
|
if (render === void 0) { render = true; }
|
|
3690
3863
|
this.onSizeUpdate();
|
|
3691
3864
|
this.setValue({ id: pen.id, visible: visible }, { render: false, doEvent: false });
|
|
@@ -3697,12 +3870,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3697
3870
|
child && this.setVisible(child, visible, false);
|
|
3698
3871
|
}
|
|
3699
3872
|
}
|
|
3700
|
-
catch (
|
|
3873
|
+
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
3701
3874
|
finally {
|
|
3702
3875
|
try {
|
|
3703
3876
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3704
3877
|
}
|
|
3705
|
-
finally { if (
|
|
3878
|
+
finally { if (e_17) throw e_17.error; }
|
|
3706
3879
|
}
|
|
3707
3880
|
}
|
|
3708
3881
|
render && this.render();
|