@meta2d/core 1.0.52 → 1.0.54
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 +10 -1
- package/src/canvas/canvas.js +507 -42
- package/src/canvas/canvas.js.map +1 -1
- package/src/canvas/canvasImage.d.ts +5 -1
- package/src/canvas/canvasImage.js +54 -12
- package/src/canvas/canvasImage.js.map +1 -1
- package/src/canvas/magnifierCanvas.js +5 -3
- package/src/canvas/magnifierCanvas.js.map +1 -1
- package/src/core.d.ts +4 -0
- package/src/core.js +429 -98
- package/src/core.js.map +1 -1
- package/src/event/event.d.ts +1 -1
- package/src/event/event.js.map +1 -1
- package/src/map/map.d.ts +1 -0
- package/src/map/map.js +68 -1
- package/src/map/map.js.map +1 -1
- package/src/options.d.ts +1 -0
- package/src/options.js.map +1 -1
- package/src/pen/model.d.ts +9 -0
- package/src/pen/model.js +11 -0
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.d.ts +2 -0
- package/src/pen/render.js +158 -13
- package/src/pen/render.js.map +1 -1
- package/src/store/store.d.ts +24 -0
- package/src/store/store.js.map +1 -1
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, isShowChild, CanvasLayer, validationPlugin, setLifeCycleFunc, getAllFollowers } from './pen';
|
|
86
|
+
import { calcInView, calcTextDrawRect, calcTextLines, calcTextRect, facePen, formatAttrs, getAllChildren, getFromAnchor, getParent, getToAnchor, getWords, LockState, PenType, renderPenRaw, setElemPosition, connectLine, nearestAnchor, setChildValue, isAncestor, isShowChild, CanvasLayer, validationPlugin, setLifeCycleFunc, getAllFollowers, isInteraction } 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';
|
|
@@ -112,6 +112,8 @@ var Meta2d = /** @class */ (function () {
|
|
|
112
112
|
this.register = register;
|
|
113
113
|
this.registerCanvasDraw = registerCanvasDraw;
|
|
114
114
|
this.registerAnchors = registerAnchors;
|
|
115
|
+
this.websocketTimes = 0;
|
|
116
|
+
this.mqttTimes = 0;
|
|
115
117
|
this.httpTimerList = [];
|
|
116
118
|
this.updateTimerList = [];
|
|
117
119
|
this.onEvent = function (eventName, e) {
|
|
@@ -184,6 +186,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
184
186
|
}
|
|
185
187
|
_this.navigatorTo(e.params);
|
|
186
188
|
break;
|
|
189
|
+
case 'input':
|
|
190
|
+
_this.store.data.locked && e && (!e.disabled) && _this.doEvent(e, eventName);
|
|
191
|
+
break;
|
|
192
|
+
case 'change':
|
|
193
|
+
_this.store.data.locked && e && (!e.disabled) && _this.doEvent(e, eventName);
|
|
194
|
+
break;
|
|
187
195
|
}
|
|
188
196
|
if (_this.store.messageEvents[eventName]) {
|
|
189
197
|
_this.store.messageEvents[eventName].forEach(function (item) {
|
|
@@ -425,7 +433,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
425
433
|
return _this.judgeCondition(pen, condition.key, condition);
|
|
426
434
|
});
|
|
427
435
|
}
|
|
428
|
-
else if (
|
|
436
|
+
else if (state.conditionType === 'or') {
|
|
429
437
|
flag = state.conditions.some(function (condition) {
|
|
430
438
|
return _this.judgeCondition(pen, condition.key, condition);
|
|
431
439
|
});
|
|
@@ -612,6 +620,9 @@ var Meta2d = /** @class */ (function () {
|
|
|
612
620
|
}
|
|
613
621
|
if (opts.width !== undefined || opts.height !== undefined) {
|
|
614
622
|
this.canvas && (this.canvas.canvasTemplate.bgPatchFlags = true);
|
|
623
|
+
if (this.canvas && this.canvas.canvasTemplate.canvas.style.backgroundImage) {
|
|
624
|
+
this.canvas.canvasTemplate.canvas.style.backgroundImage = '';
|
|
625
|
+
}
|
|
615
626
|
}
|
|
616
627
|
this.store.options = Object.assign(this.store.options, opts);
|
|
617
628
|
if (this.canvas && opts.scroll !== undefined) {
|
|
@@ -1177,7 +1188,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
1177
1188
|
this.store.patchFlagsTop = true;
|
|
1178
1189
|
};
|
|
1179
1190
|
Meta2d.prototype.open = function (data, render) {
|
|
1180
|
-
var e_3, _a, e_4, _b, e_5, _c
|
|
1191
|
+
var e_3, _a, e_4, _b, e_5, _c;
|
|
1181
1192
|
var _this = this;
|
|
1182
1193
|
if (render === void 0) { render = true; }
|
|
1183
1194
|
this.clear(false, data === null || data === void 0 ? void 0 : data.template);
|
|
@@ -1188,8 +1199,8 @@ var Meta2d = /** @class */ (function () {
|
|
|
1188
1199
|
this.store.data.pens = [];
|
|
1189
1200
|
try {
|
|
1190
1201
|
// 第一遍赋初值
|
|
1191
|
-
for (var
|
|
1192
|
-
var pen =
|
|
1202
|
+
for (var _e = __values(data.pens), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
1203
|
+
var pen = _f.value;
|
|
1193
1204
|
if (!pen.id) {
|
|
1194
1205
|
pen.id = s8();
|
|
1195
1206
|
}
|
|
@@ -1200,36 +1211,27 @@ var Meta2d = /** @class */ (function () {
|
|
|
1200
1211
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1201
1212
|
finally {
|
|
1202
1213
|
try {
|
|
1203
|
-
if (
|
|
1214
|
+
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
1204
1215
|
}
|
|
1205
1216
|
finally { if (e_3) throw e_3.error; }
|
|
1206
1217
|
}
|
|
1207
1218
|
try {
|
|
1208
|
-
for (var
|
|
1209
|
-
var pen =
|
|
1219
|
+
for (var _g = __values(data.pens), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
1220
|
+
var pen = _h.value;
|
|
1210
1221
|
this.canvas.makePen(pen);
|
|
1211
1222
|
}
|
|
1212
1223
|
}
|
|
1213
1224
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1214
1225
|
finally {
|
|
1215
1226
|
try {
|
|
1216
|
-
if (
|
|
1227
|
+
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
1217
1228
|
}
|
|
1218
1229
|
finally { if (e_4) throw e_4.error; }
|
|
1219
1230
|
}
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
}
|
|
1225
|
-
}
|
|
1226
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1227
|
-
finally {
|
|
1228
|
-
try {
|
|
1229
|
-
if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
|
|
1230
|
-
}
|
|
1231
|
-
finally { if (e_5) throw e_5.error; }
|
|
1232
|
-
}
|
|
1231
|
+
//首次计算连线bug
|
|
1232
|
+
// for (const pen of data.pens) {
|
|
1233
|
+
// this.canvas.updateLines(pen);
|
|
1234
|
+
// }
|
|
1233
1235
|
}
|
|
1234
1236
|
this.canvas.patchFlagsLines.forEach(function (pen) {
|
|
1235
1237
|
if (pen.type) {
|
|
@@ -1256,19 +1258,19 @@ var Meta2d = /** @class */ (function () {
|
|
|
1256
1258
|
this.doInitJS();
|
|
1257
1259
|
if (this.store.data.iconUrls) {
|
|
1258
1260
|
try {
|
|
1259
|
-
for (var
|
|
1260
|
-
var item =
|
|
1261
|
+
for (var _j = __values(this.store.data.iconUrls), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
1262
|
+
var item = _k.value;
|
|
1261
1263
|
loadCss(item, function () {
|
|
1262
1264
|
_this.render();
|
|
1263
1265
|
});
|
|
1264
1266
|
}
|
|
1265
1267
|
}
|
|
1266
|
-
catch (
|
|
1268
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1267
1269
|
finally {
|
|
1268
1270
|
try {
|
|
1269
|
-
if (
|
|
1271
|
+
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
1270
1272
|
}
|
|
1271
|
-
finally { if (
|
|
1273
|
+
finally { if (e_5) throw e_5.error; }
|
|
1272
1274
|
}
|
|
1273
1275
|
}
|
|
1274
1276
|
this.canvas.autoPolylineFlag = false;
|
|
@@ -1412,8 +1414,10 @@ var Meta2d = /** @class */ (function () {
|
|
|
1412
1414
|
this.stopPencil();
|
|
1413
1415
|
//恢复可选状态
|
|
1414
1416
|
this.store.data.pens.forEach(function (pen) {
|
|
1417
|
+
var _a;
|
|
1415
1418
|
if (pen.externElement === true) {
|
|
1416
|
-
pen.onMove && pen.onMove(pen);
|
|
1419
|
+
// pen.onMove && pen.onMove(pen);
|
|
1420
|
+
((_a = pen.calculative.singleton) === null || _a === void 0 ? void 0 : _a.div) && setElemPosition(pen, pen.calculative.singleton.div);
|
|
1417
1421
|
}
|
|
1418
1422
|
});
|
|
1419
1423
|
if (lock > 0) {
|
|
@@ -1509,7 +1513,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
1509
1513
|
* @param render 是否重绘
|
|
1510
1514
|
*/
|
|
1511
1515
|
Meta2d.prototype.clear = function (render, template) {
|
|
1512
|
-
var
|
|
1516
|
+
var e_6, _a;
|
|
1513
1517
|
var _b;
|
|
1514
1518
|
if (render === void 0) { render = true; }
|
|
1515
1519
|
try {
|
|
@@ -1518,12 +1522,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
1518
1522
|
(_b = pen.onDestroy) === null || _b === void 0 ? void 0 : _b.call(pen, pen);
|
|
1519
1523
|
}
|
|
1520
1524
|
}
|
|
1521
|
-
catch (
|
|
1525
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1522
1526
|
finally {
|
|
1523
1527
|
try {
|
|
1524
1528
|
if (_e && !_e.done && (_a = _c.return)) _a.call(_c);
|
|
1525
1529
|
}
|
|
1526
|
-
finally { if (
|
|
1530
|
+
finally { if (e_6) throw e_6.error; }
|
|
1527
1531
|
}
|
|
1528
1532
|
clearStore(this.store, template);
|
|
1529
1533
|
this.hideInput();
|
|
@@ -1829,7 +1833,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
1829
1833
|
if (index < minIndex) {
|
|
1830
1834
|
minIndex = index;
|
|
1831
1835
|
}
|
|
1832
|
-
if (pen === parent || pen.parentId === parent.id) {
|
|
1836
|
+
if (pen === parent || pen.parentId === parent.id || pen.id === parent.id) {
|
|
1833
1837
|
return;
|
|
1834
1838
|
}
|
|
1835
1839
|
// pen 来自于 store.active ,不存在有 parentId 的情况
|
|
@@ -1838,6 +1842,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
1838
1842
|
var childRect = calcRelativeRect(pen.calculative.worldRect, rect);
|
|
1839
1843
|
Object.assign(pen, childRect);
|
|
1840
1844
|
pen.locked = (_a = pen.lockedOnCombine) !== null && _a !== void 0 ? _a : LockState.DisableMove;
|
|
1845
|
+
pen.locked = (pen.interaction || isInteraction.includes(pen.name)) ? 0 : pen.locked;
|
|
1841
1846
|
});
|
|
1842
1847
|
//将组合后的父节点置底
|
|
1843
1848
|
this.store.data.pens.splice(minIndex, 0, parent);
|
|
@@ -2063,7 +2068,18 @@ var Meta2d = /** @class */ (function () {
|
|
|
2063
2068
|
url: _this.store.data.websocket,
|
|
2064
2069
|
});
|
|
2065
2070
|
};
|
|
2071
|
+
this.websocket.onerror = function (error) {
|
|
2072
|
+
_this.store.emitter.emit('error', { type: 'websocket', error: error });
|
|
2073
|
+
};
|
|
2066
2074
|
this.websocket.onclose = function () {
|
|
2075
|
+
if (_this.store.options.reconnetTimes) {
|
|
2076
|
+
_this.websocketTimes++;
|
|
2077
|
+
if (_this.websocketTimes >= _this.store.options.reconnetTimes) {
|
|
2078
|
+
_this.websocketTimes = 0;
|
|
2079
|
+
_this.closeWebsocket();
|
|
2080
|
+
return;
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2067
2083
|
console.info('Canvas websocket closed and reconneting...');
|
|
2068
2084
|
_this.connectWebsocket();
|
|
2069
2085
|
};
|
|
@@ -2089,16 +2105,43 @@ var Meta2d = /** @class */ (function () {
|
|
|
2089
2105
|
!this.store.data.mqttOptions.customClientId) {
|
|
2090
2106
|
this.store.data.mqttOptions.clientId = s8();
|
|
2091
2107
|
}
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2108
|
+
var mqttOptions = __assign({}, this.store.data.mqttOptions);
|
|
2109
|
+
// 如果没有username/password或为空字符串则删除username/password
|
|
2110
|
+
if (!mqttOptions.username) {
|
|
2111
|
+
delete mqttOptions.username;
|
|
2112
|
+
}
|
|
2113
|
+
if (!mqttOptions.password) {
|
|
2114
|
+
delete mqttOptions.password;
|
|
2115
|
+
}
|
|
2116
|
+
var username = mqttOptions.username, password = mqttOptions.password;
|
|
2117
|
+
// username 和 password 必须同时存在或者同时不存在才去建立mqtt连接
|
|
2118
|
+
if ((username && password) || (!username && !password)) {
|
|
2119
|
+
this.mqttClient = mqtt.connect(this.store.data.mqtt, mqttOptions);
|
|
2120
|
+
this.mqttClient.on('message', function (topic, message) {
|
|
2121
|
+
_this.socketCallback(message.toString(), {
|
|
2122
|
+
topic: topic,
|
|
2123
|
+
type: 'mqtt',
|
|
2124
|
+
url: _this.store.data.mqtt,
|
|
2125
|
+
});
|
|
2098
2126
|
});
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2127
|
+
this.mqttClient.on('error', function (error) {
|
|
2128
|
+
_this.store.emitter.emit('error', { type: 'mqtt', error: error });
|
|
2129
|
+
});
|
|
2130
|
+
this.mqttClient.on('close', function () {
|
|
2131
|
+
if (_this.store.options.reconnetTimes) {
|
|
2132
|
+
_this.mqttTimes++;
|
|
2133
|
+
if (_this.mqttTimes >= _this.store.options.reconnetTimes) {
|
|
2134
|
+
_this.mqttTimes = 0;
|
|
2135
|
+
_this.closeMqtt();
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
});
|
|
2139
|
+
if (this.store.data.mqttTopics) {
|
|
2140
|
+
this.mqttClient.subscribe(this.store.data.mqttTopics.split(','));
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
else {
|
|
2144
|
+
console.warn('缺少用户名或密码');
|
|
2102
2145
|
}
|
|
2103
2146
|
}
|
|
2104
2147
|
};
|
|
@@ -2121,10 +2164,19 @@ var Meta2d = /** @class */ (function () {
|
|
|
2121
2164
|
}
|
|
2122
2165
|
https.forEach(function (item, index) {
|
|
2123
2166
|
if (item.http) {
|
|
2167
|
+
item.times = 0;
|
|
2124
2168
|
_this.httpTimerList[index] = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2125
2169
|
return __generator(this, function (_a) {
|
|
2126
2170
|
// 默认每一秒请求一次
|
|
2127
2171
|
this.oldRequestHttp(item);
|
|
2172
|
+
if (this.store.options.reconnetTimes) {
|
|
2173
|
+
item.times++;
|
|
2174
|
+
if (item.times >= this.store.options.reconnetTimes) {
|
|
2175
|
+
item.times = 0;
|
|
2176
|
+
clearInterval(this.httpTimerList[index]);
|
|
2177
|
+
this.httpTimerList[index] = undefined;
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2128
2180
|
return [2 /*return*/];
|
|
2129
2181
|
});
|
|
2130
2182
|
}); }, item.httpTimeInterval || 1000);
|
|
@@ -2163,7 +2215,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
2163
2215
|
switch (_a.label) {
|
|
2164
2216
|
case 0:
|
|
2165
2217
|
req = deepClone(_req);
|
|
2166
|
-
if (!req.http) return [3 /*break*/,
|
|
2218
|
+
if (!req.http) return [3 /*break*/, 4];
|
|
2167
2219
|
return [4 /*yield*/, fetch(req.http, {
|
|
2168
2220
|
headers: req.httpHeaders,
|
|
2169
2221
|
method: req.method || 'GET',
|
|
@@ -2176,8 +2228,11 @@ var Meta2d = /** @class */ (function () {
|
|
|
2176
2228
|
case 2:
|
|
2177
2229
|
data = _a.sent();
|
|
2178
2230
|
this.socketCallback(data, { type: 'http', url: req.http });
|
|
2179
|
-
|
|
2180
|
-
case 3:
|
|
2231
|
+
return [3 /*break*/, 4];
|
|
2232
|
+
case 3:
|
|
2233
|
+
this.store.emitter.emit('error', { type: 'http', error: res });
|
|
2234
|
+
_a.label = 4;
|
|
2235
|
+
case 4: return [2 /*return*/];
|
|
2181
2236
|
}
|
|
2182
2237
|
});
|
|
2183
2238
|
});
|
|
@@ -2254,9 +2309,11 @@ var Meta2d = /** @class */ (function () {
|
|
|
2254
2309
|
networks.forEach(function (net) {
|
|
2255
2310
|
if (net.type === 'subscribe') {
|
|
2256
2311
|
if (net.protocol === 'mqtt') {
|
|
2312
|
+
net.index = mqttIndex_1;
|
|
2257
2313
|
if (net.options.clientId && !net.options.customClientId) {
|
|
2258
2314
|
net.options.clientId = s8();
|
|
2259
2315
|
}
|
|
2316
|
+
net.times = 0;
|
|
2260
2317
|
_this.mqttClients[mqttIndex_1] = mqtt.connect(net.url, net.options);
|
|
2261
2318
|
_this.mqttClients[mqttIndex_1].on('message', function (topic, message) {
|
|
2262
2319
|
_this.socketCallback(message.toString(), {
|
|
@@ -2265,16 +2322,48 @@ var Meta2d = /** @class */ (function () {
|
|
|
2265
2322
|
url: net.url,
|
|
2266
2323
|
});
|
|
2267
2324
|
});
|
|
2325
|
+
_this.mqttClients[mqttIndex_1].on('error', function (error) {
|
|
2326
|
+
_this.store.emitter.emit('error', { type: 'mqtt', error: error });
|
|
2327
|
+
});
|
|
2328
|
+
_this.mqttClients[mqttIndex_1].on('close', function () {
|
|
2329
|
+
var _a;
|
|
2330
|
+
if (_this.store.options.reconnetTimes) {
|
|
2331
|
+
net.times++;
|
|
2332
|
+
if (net.times >= _this.store.options.reconnetTimes) {
|
|
2333
|
+
net.times = 0;
|
|
2334
|
+
_this.mqttClients && ((_a = _this.mqttClients[net.index]) === null || _a === void 0 ? void 0 : _a.end());
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
});
|
|
2268
2338
|
if (net.topics) {
|
|
2269
2339
|
_this.mqttClients[mqttIndex_1].subscribe(net.topics.split(','));
|
|
2270
2340
|
}
|
|
2271
2341
|
mqttIndex_1 += 1;
|
|
2272
2342
|
}
|
|
2273
2343
|
else if (net.protocol === 'websocket') {
|
|
2274
|
-
|
|
2275
|
-
_this.
|
|
2276
|
-
|
|
2277
|
-
|
|
2344
|
+
net.index = websocketIndex_1;
|
|
2345
|
+
_this.connectNetWebSocket(net);
|
|
2346
|
+
// this.websockets[websocketIndex] = new WebSocket(
|
|
2347
|
+
// net.url,
|
|
2348
|
+
// net.protocols || undefined
|
|
2349
|
+
// );
|
|
2350
|
+
// this.websockets[websocketIndex].onmessage = (e) => {
|
|
2351
|
+
// this.socketCallback(e.data, { type: 'websocket', url: net.url });
|
|
2352
|
+
// };
|
|
2353
|
+
// this.websockets[websocketIndex].onerror = (error) => {
|
|
2354
|
+
// this.store.emitter.emit('error', { type: 'websocket', error });
|
|
2355
|
+
// };
|
|
2356
|
+
// this.websockets[websocketIndex].onclose = () => {
|
|
2357
|
+
// if (this.store.options.reconnetTimes) {
|
|
2358
|
+
// net.times++;
|
|
2359
|
+
// if (net.times >= this.store.options.reconnetTimes) {
|
|
2360
|
+
// net.times = 0;
|
|
2361
|
+
// this.websockets[net.index]?.close();
|
|
2362
|
+
// return;
|
|
2363
|
+
// }
|
|
2364
|
+
// }
|
|
2365
|
+
// console.info('Canvas websocket closed and reconneting...');
|
|
2366
|
+
// };
|
|
2278
2367
|
websocketIndex_1 += 1;
|
|
2279
2368
|
}
|
|
2280
2369
|
else if (net.protocol === 'http') {
|
|
@@ -2291,6 +2380,39 @@ var Meta2d = /** @class */ (function () {
|
|
|
2291
2380
|
}
|
|
2292
2381
|
this.onNetworkConnect(https);
|
|
2293
2382
|
};
|
|
2383
|
+
Meta2d.prototype.connectNetWebSocket = function (net) {
|
|
2384
|
+
var _this = this;
|
|
2385
|
+
var _a;
|
|
2386
|
+
if (this.websockets[net.index]) {
|
|
2387
|
+
this.websockets[net.index].onclose = undefined;
|
|
2388
|
+
(_a = this.websockets[net.index]) === null || _a === void 0 ? void 0 : _a.close();
|
|
2389
|
+
this.websockets[net.index] = undefined;
|
|
2390
|
+
}
|
|
2391
|
+
this.websockets[net.index] = new WebSocket(net.url, net.protocols || undefined);
|
|
2392
|
+
this.websockets[net.index].onmessage = function (e) {
|
|
2393
|
+
_this.socketCallback(e.data, { type: 'websocket', url: net.url });
|
|
2394
|
+
};
|
|
2395
|
+
this.websockets[net.index].onerror = function (error) {
|
|
2396
|
+
_this.store.emitter.emit('error', { type: 'websocket', error: error });
|
|
2397
|
+
};
|
|
2398
|
+
this.websockets[net.index].onclose = function () {
|
|
2399
|
+
var _a;
|
|
2400
|
+
if (_this.store.options.reconnetTimes) {
|
|
2401
|
+
net.times++;
|
|
2402
|
+
if (net.times >= _this.store.options.reconnetTimes) {
|
|
2403
|
+
net.times = 0;
|
|
2404
|
+
_this.websockets[net.index].onclose = undefined;
|
|
2405
|
+
(_a = _this.websockets[net.index]) === null || _a === void 0 ? void 0 : _a.close();
|
|
2406
|
+
_this.websockets[net.index] = undefined;
|
|
2407
|
+
return;
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
setTimeout(function () {
|
|
2411
|
+
console.info('Canvas websocket closed and reconneting...');
|
|
2412
|
+
_this.connectNetWebSocket(net);
|
|
2413
|
+
}, 2000);
|
|
2414
|
+
};
|
|
2415
|
+
};
|
|
2294
2416
|
Meta2d.prototype.randomString = function (e) {
|
|
2295
2417
|
e = e || 32;
|
|
2296
2418
|
var t = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678', a = t.length, n = '';
|
|
@@ -2470,8 +2592,9 @@ var Meta2d = /** @class */ (function () {
|
|
|
2470
2592
|
if (Object.keys(_d_1).length) {
|
|
2471
2593
|
var data = pen.onBeforeValue ? pen.onBeforeValue(pen, _d_1) : _d_1;
|
|
2472
2594
|
this.canvas.updateValue(pen, data);
|
|
2473
|
-
this.store.emitter.emit('valueUpdate', pen);
|
|
2595
|
+
// this.store.emitter.emit('valueUpdate', pen);
|
|
2474
2596
|
(_a = pen.onValue) === null || _a === void 0 ? void 0 : _a.call(pen, pen);
|
|
2597
|
+
this.store.emitter.emit('valueUpdate', pen);
|
|
2475
2598
|
}
|
|
2476
2599
|
}
|
|
2477
2600
|
};
|
|
@@ -2542,9 +2665,18 @@ var Meta2d = /** @class */ (function () {
|
|
|
2542
2665
|
// }, this.store.data.networkInterval || 1000);
|
|
2543
2666
|
// }
|
|
2544
2667
|
https.forEach(function (_item, index) {
|
|
2668
|
+
_item.times = 0;
|
|
2545
2669
|
_this.updateTimerList[index] = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2546
2670
|
return __generator(this, function (_a) {
|
|
2547
2671
|
this.requestHttp(_item);
|
|
2672
|
+
if (this.store.options.reconnetTimes) {
|
|
2673
|
+
_item.times++;
|
|
2674
|
+
if (_item.times >= this.store.options.reconnetTimes) {
|
|
2675
|
+
_item.times = 0;
|
|
2676
|
+
clearInterval(this.updateTimerList[index]);
|
|
2677
|
+
this.updateTimerList[index] = undefined;
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2548
2680
|
return [2 /*return*/];
|
|
2549
2681
|
});
|
|
2550
2682
|
}); }, _item.interval || 1000);
|
|
@@ -2557,7 +2689,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
2557
2689
|
switch (_a.label) {
|
|
2558
2690
|
case 0:
|
|
2559
2691
|
req = deepClone(_req);
|
|
2560
|
-
if (!req.url) return [3 /*break*/,
|
|
2692
|
+
if (!req.url) return [3 /*break*/, 4];
|
|
2561
2693
|
if (typeof req.headers === 'object') {
|
|
2562
2694
|
for (i in req.headers) {
|
|
2563
2695
|
if (typeof req.headers[i] === 'string') {
|
|
@@ -2590,8 +2722,11 @@ var Meta2d = /** @class */ (function () {
|
|
|
2590
2722
|
case 2:
|
|
2591
2723
|
data = _a.sent();
|
|
2592
2724
|
this.socketCallback(data, { type: 'http', url: req.url });
|
|
2593
|
-
|
|
2594
|
-
case 3:
|
|
2725
|
+
return [3 /*break*/, 4];
|
|
2726
|
+
case 3:
|
|
2727
|
+
this.store.emitter.emit('error', { type: 'http', error: res });
|
|
2728
|
+
_a.label = 4;
|
|
2729
|
+
case 4: return [2 /*return*/];
|
|
2595
2730
|
}
|
|
2596
2731
|
});
|
|
2597
2732
|
});
|
|
@@ -2603,7 +2738,11 @@ var Meta2d = /** @class */ (function () {
|
|
|
2603
2738
|
});
|
|
2604
2739
|
this.websockets &&
|
|
2605
2740
|
this.websockets.forEach(function (websocket) {
|
|
2606
|
-
websocket
|
|
2741
|
+
if (websocket) {
|
|
2742
|
+
websocket.onclose = undefined;
|
|
2743
|
+
websocket.close();
|
|
2744
|
+
websocket = undefined;
|
|
2745
|
+
}
|
|
2607
2746
|
});
|
|
2608
2747
|
this.mqttClients = undefined;
|
|
2609
2748
|
this.websockets = undefined;
|
|
@@ -3118,7 +3257,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3118
3257
|
* @param padding 上右下左的内边距
|
|
3119
3258
|
*/
|
|
3120
3259
|
Meta2d.prototype.downloadPng = function (name, padding, maxWidth) {
|
|
3121
|
-
var
|
|
3260
|
+
var e_7, _a;
|
|
3122
3261
|
var _this = this;
|
|
3123
3262
|
var _b;
|
|
3124
3263
|
try {
|
|
@@ -3130,12 +3269,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3130
3269
|
}
|
|
3131
3270
|
}
|
|
3132
3271
|
}
|
|
3133
|
-
catch (
|
|
3272
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
3134
3273
|
finally {
|
|
3135
3274
|
try {
|
|
3136
3275
|
if (_e && !_e.done && (_a = _c.return)) _a.call(_c);
|
|
3137
3276
|
}
|
|
3138
|
-
finally { if (
|
|
3277
|
+
finally { if (e_7) throw e_7.error; }
|
|
3139
3278
|
}
|
|
3140
3279
|
setTimeout(function () {
|
|
3141
3280
|
var a = document.createElement('a');
|
|
@@ -3147,7 +3286,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3147
3286
|
}, 1000);
|
|
3148
3287
|
};
|
|
3149
3288
|
Meta2d.prototype.downloadSvg = function () {
|
|
3150
|
-
var
|
|
3289
|
+
var e_8, _a;
|
|
3151
3290
|
if (!window.C2S) {
|
|
3152
3291
|
console.error('请先加载乐吾乐官网下的canvas2svg.js', 'https://assets.le5lecdn.com/2d/canvas2svg.js');
|
|
3153
3292
|
throw new Error('请先加载乐吾乐官网下的canvas2svg.js');
|
|
@@ -3166,12 +3305,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3166
3305
|
renderPenRaw(ctx, pen, rect, true);
|
|
3167
3306
|
}
|
|
3168
3307
|
}
|
|
3169
|
-
catch (
|
|
3308
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
3170
3309
|
finally {
|
|
3171
3310
|
try {
|
|
3172
3311
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3173
3312
|
}
|
|
3174
|
-
finally { if (
|
|
3313
|
+
finally { if (e_8) throw e_8.error; }
|
|
3175
3314
|
}
|
|
3176
3315
|
var mySerializedSVG = ctx.getSerializedSvg();
|
|
3177
3316
|
if (this.store.data.background) {
|
|
@@ -3219,6 +3358,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3219
3358
|
* @param fit true,填满但完整展示;false,填满,但长边可能截取(即显示不完整)
|
|
3220
3359
|
*/
|
|
3221
3360
|
Meta2d.prototype.fitView = function (fit, viewPadding) {
|
|
3361
|
+
var _a, _b;
|
|
3222
3362
|
if (fit === void 0) { fit = true; }
|
|
3223
3363
|
if (viewPadding === void 0) { viewPadding = 10; }
|
|
3224
3364
|
// 默认垂直填充,两边留白
|
|
@@ -3243,10 +3383,194 @@ var Meta2d = /** @class */ (function () {
|
|
|
3243
3383
|
else {
|
|
3244
3384
|
ratio = w > h ? w : h;
|
|
3245
3385
|
}
|
|
3386
|
+
if ((_a = this.store.data.fits) === null || _a === void 0 ? void 0 : _a.length) {
|
|
3387
|
+
this.canvas.opening = true;
|
|
3388
|
+
}
|
|
3246
3389
|
// 该方法直接更改画布的 scale 属性,所以比率应该乘以当前 scale
|
|
3247
3390
|
this.scale(ratio * this.store.data.scale);
|
|
3248
3391
|
// 5. 居中
|
|
3249
3392
|
this.centerView();
|
|
3393
|
+
if ((_b = this.store.data.fits) === null || _b === void 0 ? void 0 : _b.length) {
|
|
3394
|
+
this.fillView();
|
|
3395
|
+
}
|
|
3396
|
+
};
|
|
3397
|
+
Meta2d.prototype.fillView = function () {
|
|
3398
|
+
var _this = this;
|
|
3399
|
+
var _a, _b;
|
|
3400
|
+
var rect = this.getRect();
|
|
3401
|
+
var wGap = this.canvas.width - rect.width;
|
|
3402
|
+
var hGap = this.canvas.height - rect.height;
|
|
3403
|
+
//宽度拉伸
|
|
3404
|
+
if (Math.abs(wGap) > 10) {
|
|
3405
|
+
(_a = this.store.data.fits) === null || _a === void 0 ? void 0 : _a.forEach(function (fit) {
|
|
3406
|
+
var pens = [];
|
|
3407
|
+
fit.children.forEach(function (id) {
|
|
3408
|
+
_this.store.pens[id].locked = LockState.None;
|
|
3409
|
+
pens.push(_this.store.pens[id]);
|
|
3410
|
+
});
|
|
3411
|
+
var r = wGap / 2;
|
|
3412
|
+
if (fit.left && fit.right) {
|
|
3413
|
+
//整体拉伸
|
|
3414
|
+
var left_1 = fit.leftValue;
|
|
3415
|
+
var right = fit.rightValue;
|
|
3416
|
+
if (left_1) {
|
|
3417
|
+
left_1 = Math.abs(left_1) < 1 ? left_1 * _this.canvas.width : left_1;
|
|
3418
|
+
}
|
|
3419
|
+
else {
|
|
3420
|
+
left_1 = 0;
|
|
3421
|
+
}
|
|
3422
|
+
if (right) {
|
|
3423
|
+
right = Math.abs(right) < 1 ? right * _this.canvas.width : right;
|
|
3424
|
+
}
|
|
3425
|
+
else {
|
|
3426
|
+
right = 0;
|
|
3427
|
+
}
|
|
3428
|
+
var ratio_1 = (_this.canvas.width - left_1 - right) / (rect.width - left_1 - right);
|
|
3429
|
+
pens.forEach(function (pen) {
|
|
3430
|
+
var _a;
|
|
3431
|
+
if (pen.image && pen.imageRatio) {
|
|
3432
|
+
if (pen.calculative.worldRect.width / _this.canvas.width > 0.1) {
|
|
3433
|
+
pen.imageRatio = false;
|
|
3434
|
+
}
|
|
3435
|
+
}
|
|
3436
|
+
pen.calculative.worldRect.x = rect.x - wGap / 2 + left_1 + (pen.calculative.worldRect.x - rect.x) * ratio_1; //(fit.leftValue || 0)+ (pen.calculative.worldRect.x + pen.calculative.worldRect.width/2)-( pen.calculative.worldRect.width*ratio)*(range/2- (fit.rightValue || 0))/(range- (fit.leftValue || 0)-(fit.rightValue || 0));
|
|
3437
|
+
pen.calculative.worldRect.width *= ratio_1;
|
|
3438
|
+
pen.calculative.worldRect.ex = pen.calculative.worldRect.x + pen.calculative.worldRect.width;
|
|
3439
|
+
pen.calculative.width = pen.calculative.worldRect.width;
|
|
3440
|
+
pen.calculative.x = pen.calculative.worldRect.x;
|
|
3441
|
+
pen.width = pen.calculative.worldRect.width;
|
|
3442
|
+
pen.x = pen.calculative.worldRect.x;
|
|
3443
|
+
_this.canvas.updatePenRect(pen, { worldRectIsReady: false });
|
|
3444
|
+
if (pen.externElement) {
|
|
3445
|
+
(_a = pen.onResize) === null || _a === void 0 ? void 0 : _a.call(pen, pen);
|
|
3446
|
+
}
|
|
3447
|
+
});
|
|
3448
|
+
}
|
|
3449
|
+
else if (fit.left) {
|
|
3450
|
+
//左移
|
|
3451
|
+
r = -r;
|
|
3452
|
+
if (fit.leftValue) {
|
|
3453
|
+
r += (Math.abs(fit.leftValue) < 1 ? fit.leftValue * _this.canvas.width : fit.leftValue);
|
|
3454
|
+
}
|
|
3455
|
+
_this.translatePens(pens, r, 0);
|
|
3456
|
+
}
|
|
3457
|
+
else if (fit.right) {
|
|
3458
|
+
//右移
|
|
3459
|
+
if (fit.rightValue) {
|
|
3460
|
+
r = r - (Math.abs(fit.rightValue) < 1 ? fit.rightValue * _this.canvas.width : fit.rightValue);
|
|
3461
|
+
}
|
|
3462
|
+
_this.translatePens(pens, r, 0);
|
|
3463
|
+
}
|
|
3464
|
+
});
|
|
3465
|
+
var iframePens = this.store.data.pens.filter(function (pen) { return pen.name === 'iframe'; });
|
|
3466
|
+
iframePens === null || iframePens === void 0 ? void 0 : iframePens.forEach(function (pen) {
|
|
3467
|
+
var _a, _b;
|
|
3468
|
+
var worldRect = pen.calculative.worldRect;
|
|
3469
|
+
if (worldRect.width / _this.store.data.scale > rect.width * 0.8) {
|
|
3470
|
+
var bfW = worldRect.width;
|
|
3471
|
+
pen.calculative.worldRect.x = worldRect.x - wGap / 2;
|
|
3472
|
+
pen.calculative.worldRect.width =
|
|
3473
|
+
worldRect.width + wGap;
|
|
3474
|
+
pen.calculative.worldRect.ex = worldRect.ex + wGap;
|
|
3475
|
+
pen.operationalRect.x =
|
|
3476
|
+
(pen.operationalRect.x * bfW) / pen.calculative.worldRect.width;
|
|
3477
|
+
pen.operationalRect.width =
|
|
3478
|
+
(pen.calculative.worldRect.width -
|
|
3479
|
+
(1 - pen.operationalRect.width) * bfW) /
|
|
3480
|
+
pen.calculative.worldRect.width;
|
|
3481
|
+
(_a = pen.onBeforeValue) === null || _a === void 0 ? void 0 : _a.call(pen, pen, {
|
|
3482
|
+
operationalRect: pen.operationalRect,
|
|
3483
|
+
});
|
|
3484
|
+
(_b = pen.onResize) === null || _b === void 0 ? void 0 : _b.call(pen, pen);
|
|
3485
|
+
}
|
|
3486
|
+
});
|
|
3487
|
+
}
|
|
3488
|
+
//高度拉伸
|
|
3489
|
+
if (Math.abs(hGap) > 10) {
|
|
3490
|
+
(_b = this.store.data.fits) === null || _b === void 0 ? void 0 : _b.forEach(function (fit) {
|
|
3491
|
+
var pens = [];
|
|
3492
|
+
fit.children.forEach(function (id) {
|
|
3493
|
+
_this.store.pens[id].locked = LockState.None;
|
|
3494
|
+
pens.push(_this.store.pens[id]);
|
|
3495
|
+
});
|
|
3496
|
+
var r = hGap / 2;
|
|
3497
|
+
if (fit.top && fit.bottom) {
|
|
3498
|
+
var top_1 = fit.topValue;
|
|
3499
|
+
var bottom = fit.bottomValue;
|
|
3500
|
+
if (top_1) {
|
|
3501
|
+
top_1 = Math.abs(top_1) < 1 ? top_1 * _this.canvas.height : top_1;
|
|
3502
|
+
}
|
|
3503
|
+
else {
|
|
3504
|
+
top_1 = 0;
|
|
3505
|
+
}
|
|
3506
|
+
if (bottom) {
|
|
3507
|
+
bottom = Math.abs(bottom) < 1 ? bottom * _this.canvas.height : bottom;
|
|
3508
|
+
}
|
|
3509
|
+
else {
|
|
3510
|
+
bottom = 0;
|
|
3511
|
+
}
|
|
3512
|
+
var ratio_2 = (_this.canvas.height - top_1 - bottom) / (rect.height - top_1 - bottom);
|
|
3513
|
+
pens.forEach(function (pen) {
|
|
3514
|
+
var _a;
|
|
3515
|
+
if (pen.image && pen.imageRatio) {
|
|
3516
|
+
if (pen.calculative.worldRect.height / _this.canvas.height > 0.1) {
|
|
3517
|
+
pen.imageRatio = false;
|
|
3518
|
+
}
|
|
3519
|
+
}
|
|
3520
|
+
pen.calculative.worldRect.y = rect.y - hGap / 2 + top_1 + (pen.calculative.worldRect.y - rect.y) * ratio_2; //(fit.leftValue || 0)+ (pen.calculative.worldRect.x + pen.calculative.worldRect.width/2)-( pen.calculative.worldRect.width*ratio)*(range/2- (fit.rightValue || 0))/(range- (fit.leftValue || 0)-(fit.rightValue || 0));
|
|
3521
|
+
pen.calculative.worldRect.height *= ratio_2;
|
|
3522
|
+
pen.calculative.worldRect.ey = pen.calculative.worldRect.y + pen.calculative.worldRect.height;
|
|
3523
|
+
pen.calculative.height = pen.calculative.worldRect.height;
|
|
3524
|
+
pen.calculative.y = pen.calculative.worldRect.y;
|
|
3525
|
+
pen.height = pen.calculative.worldRect.height;
|
|
3526
|
+
pen.y = pen.calculative.worldRect.y;
|
|
3527
|
+
_this.canvas.updatePenRect(pen, { worldRectIsReady: false });
|
|
3528
|
+
if (pen.externElement) {
|
|
3529
|
+
(_a = pen.onResize) === null || _a === void 0 ? void 0 : _a.call(pen, pen);
|
|
3530
|
+
}
|
|
3531
|
+
});
|
|
3532
|
+
}
|
|
3533
|
+
else if (fit.top) {
|
|
3534
|
+
r = -r;
|
|
3535
|
+
if (fit.topValue) {
|
|
3536
|
+
r += (Math.abs(fit.topValue) < 1 ? fit.topValue * _this.canvas.height : fit.topValue);
|
|
3537
|
+
}
|
|
3538
|
+
_this.translatePens(pens, 0, r);
|
|
3539
|
+
}
|
|
3540
|
+
else if (fit.bottom) {
|
|
3541
|
+
if (fit.bottomValue) {
|
|
3542
|
+
r = r - (Math.abs(fit.bottomValue) < 1 ? fit.bottomValue * _this.canvas.height : fit.bottomValue);
|
|
3543
|
+
}
|
|
3544
|
+
_this.translatePens(pens, 0, r);
|
|
3545
|
+
}
|
|
3546
|
+
});
|
|
3547
|
+
var iframePens = this.store.data.pens.filter(function (pen) { return pen.name === 'iframe'; });
|
|
3548
|
+
iframePens === null || iframePens === void 0 ? void 0 : iframePens.forEach(function (pen) {
|
|
3549
|
+
var _a, _b;
|
|
3550
|
+
var worldRect = pen.calculative.worldRect;
|
|
3551
|
+
if (worldRect.height / _this.store.data.scale > rect.height * 0.8) {
|
|
3552
|
+
var bfH = worldRect.height;
|
|
3553
|
+
pen.calculative.worldRect.y = worldRect.y - hGap / 2;
|
|
3554
|
+
pen.calculative.worldRect.height =
|
|
3555
|
+
worldRect.height + hGap;
|
|
3556
|
+
pen.calculative.worldRect.ey = worldRect.ey + hGap;
|
|
3557
|
+
pen.operationalRect.y =
|
|
3558
|
+
(pen.operationalRect.y * bfH) / pen.calculative.worldRect.width;
|
|
3559
|
+
pen.operationalRect.height =
|
|
3560
|
+
(pen.calculative.worldRect.height -
|
|
3561
|
+
(1 - pen.operationalRect.height) * bfH) /
|
|
3562
|
+
pen.calculative.worldRect.height;
|
|
3563
|
+
(_a = pen.onBeforeValue) === null || _a === void 0 ? void 0 : _a.call(pen, pen, {
|
|
3564
|
+
operationalRect: pen.operationalRect,
|
|
3565
|
+
});
|
|
3566
|
+
(_b = pen.onResize) === null || _b === void 0 ? void 0 : _b.call(pen, pen);
|
|
3567
|
+
}
|
|
3568
|
+
});
|
|
3569
|
+
}
|
|
3570
|
+
this.canvas.canvasTemplate.init();
|
|
3571
|
+
this.canvas.canvasImage.init();
|
|
3572
|
+
this.canvas.canvasImageBottom.init();
|
|
3573
|
+
this.render(true);
|
|
3250
3574
|
};
|
|
3251
3575
|
Meta2d.prototype.trimPens = function () {
|
|
3252
3576
|
//去除空连线
|
|
@@ -3299,6 +3623,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3299
3623
|
this.centerView();
|
|
3300
3624
|
};
|
|
3301
3625
|
Meta2d.prototype.fitSizeView = function (fit, viewPadding) {
|
|
3626
|
+
var _a, _b;
|
|
3302
3627
|
if (fit === void 0) { fit = true; }
|
|
3303
3628
|
if (viewPadding === void 0) { viewPadding = 10; }
|
|
3304
3629
|
// 默认垂直填充,两边留白
|
|
@@ -3332,10 +3657,16 @@ var Meta2d = /** @class */ (function () {
|
|
|
3332
3657
|
ratio = w > h ? w : h;
|
|
3333
3658
|
}
|
|
3334
3659
|
}
|
|
3660
|
+
if ((_a = this.store.data.fits) === null || _a === void 0 ? void 0 : _a.length) {
|
|
3661
|
+
this.canvas.opening = true;
|
|
3662
|
+
}
|
|
3335
3663
|
// 该方法直接更改画布的 scale 属性,所以比率应该乘以当前 scale
|
|
3336
3664
|
this.scale(ratio * this.store.data.scale);
|
|
3337
3665
|
// 5. 居中
|
|
3338
3666
|
this.centerSizeView();
|
|
3667
|
+
if ((_b = this.store.data.fits) === null || _b === void 0 ? void 0 : _b.length) {
|
|
3668
|
+
this.fillView();
|
|
3669
|
+
}
|
|
3339
3670
|
};
|
|
3340
3671
|
Meta2d.prototype.centerSizeView = function () {
|
|
3341
3672
|
// if (!this.hasView()) return;
|
|
@@ -3564,9 +3895,9 @@ var Meta2d = /** @class */ (function () {
|
|
|
3564
3895
|
var firstPen_1 = pens[0];
|
|
3565
3896
|
formatAttrs.forEach(function (attr) {
|
|
3566
3897
|
attrs[attr] =
|
|
3567
|
-
firstPen_1[attr]
|
|
3568
|
-
_this.store.options.defaultFormat[attr] ||
|
|
3569
|
-
|
|
3898
|
+
firstPen_1[attr] !== undefined ? firstPen_1[attr] :
|
|
3899
|
+
(_this.store.options.defaultFormat[attr] ||
|
|
3900
|
+
_this.store.options[attr]);
|
|
3570
3901
|
});
|
|
3571
3902
|
}
|
|
3572
3903
|
else {
|
|
@@ -3630,7 +3961,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3630
3961
|
});
|
|
3631
3962
|
};
|
|
3632
3963
|
Meta2d.prototype.alignNodes = function (align, pens, rect) {
|
|
3633
|
-
var
|
|
3964
|
+
var e_9, _a;
|
|
3634
3965
|
if (pens === void 0) { pens = this.store.data.pens; }
|
|
3635
3966
|
!rect && (rect = this.getPenRect(this.getRect(pens)));
|
|
3636
3967
|
var initPens = deepClone(pens); // 原 pens ,深拷贝一下
|
|
@@ -3640,12 +3971,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3640
3971
|
this.alignPen(align, item, rect);
|
|
3641
3972
|
}
|
|
3642
3973
|
}
|
|
3643
|
-
catch (
|
|
3974
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
3644
3975
|
finally {
|
|
3645
3976
|
try {
|
|
3646
3977
|
if (pens_1_1 && !pens_1_1.done && (_a = pens_1.return)) _a.call(pens_1);
|
|
3647
3978
|
}
|
|
3648
|
-
finally { if (
|
|
3979
|
+
finally { if (e_9) throw e_9.error; }
|
|
3649
3980
|
}
|
|
3650
3981
|
this.initImageCanvas(pens);
|
|
3651
3982
|
this.initTemplateCanvas(pens);
|
|
@@ -3658,7 +3989,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3658
3989
|
};
|
|
3659
3990
|
//对齐大屏
|
|
3660
3991
|
Meta2d.prototype.alignNodesV = function (align, pens) {
|
|
3661
|
-
var
|
|
3992
|
+
var e_10, _a;
|
|
3662
3993
|
if (pens === void 0) { pens = this.store.data.pens; }
|
|
3663
3994
|
var width = this.store.data.width || this.store.options.width;
|
|
3664
3995
|
var height = this.store.data.height || this.store.options.height;
|
|
@@ -3675,12 +4006,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3675
4006
|
this.alignPen(align, item, rect);
|
|
3676
4007
|
}
|
|
3677
4008
|
}
|
|
3678
|
-
catch (
|
|
4009
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
3679
4010
|
finally {
|
|
3680
4011
|
try {
|
|
3681
4012
|
if (pens_2_1 && !pens_2_1.done && (_a = pens_2.return)) _a.call(pens_2);
|
|
3682
4013
|
}
|
|
3683
|
-
finally { if (
|
|
4014
|
+
finally { if (e_10) throw e_10.error; }
|
|
3684
4015
|
}
|
|
3685
4016
|
this.initImageCanvas(pens);
|
|
3686
4017
|
this.initTemplateCanvas(pens);
|
|
@@ -3775,7 +4106,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3775
4106
|
* @param distance 总的宽 or 高
|
|
3776
4107
|
*/
|
|
3777
4108
|
Meta2d.prototype.spaceBetweenByDirection = function (direction, pens, distance) {
|
|
3778
|
-
var
|
|
4109
|
+
var e_11, _a;
|
|
3779
4110
|
var _this = this;
|
|
3780
4111
|
if (pens === void 0) { pens = this.store.data.pens; }
|
|
3781
4112
|
!distance && (distance = this.getPenRect(this.getRect(pens))[direction]);
|
|
@@ -3809,12 +4140,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3809
4140
|
this.setValue(__assign({ id: pen.id }, penRect), { render: false, doEvent: false });
|
|
3810
4141
|
}
|
|
3811
4142
|
}
|
|
3812
|
-
catch (
|
|
4143
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
3813
4144
|
finally {
|
|
3814
4145
|
try {
|
|
3815
4146
|
if (pens_3_1 && !pens_3_1.done && (_a = pens_3.return)) _a.call(pens_3);
|
|
3816
4147
|
}
|
|
3817
|
-
finally { if (
|
|
4148
|
+
finally { if (e_11) throw e_11.error; }
|
|
3818
4149
|
}
|
|
3819
4150
|
this.initImageCanvas(pens);
|
|
3820
4151
|
this.initTemplateCanvas(pens);
|
|
@@ -3878,7 +4209,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3878
4209
|
});
|
|
3879
4210
|
};
|
|
3880
4211
|
Meta2d.prototype.gotoView = function (pen) {
|
|
3881
|
-
var
|
|
4212
|
+
var e_12, _a;
|
|
3882
4213
|
var center = this.getViewCenter();
|
|
3883
4214
|
var x = center.x -
|
|
3884
4215
|
pen.calculative.worldRect.x -
|
|
@@ -3897,12 +4228,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3897
4228
|
calcInView(pen_1);
|
|
3898
4229
|
}
|
|
3899
4230
|
}
|
|
3900
|
-
catch (
|
|
4231
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
3901
4232
|
finally {
|
|
3902
4233
|
try {
|
|
3903
4234
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3904
4235
|
}
|
|
3905
|
-
finally { if (
|
|
4236
|
+
finally { if (e_12) throw e_12.error; }
|
|
3906
4237
|
}
|
|
3907
4238
|
this.canvas.canvasImage.init();
|
|
3908
4239
|
this.canvas.canvasImageBottom.init();
|
|
@@ -3949,7 +4280,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3949
4280
|
* @param pens pen 置顶的画笔
|
|
3950
4281
|
*/
|
|
3951
4282
|
Meta2d.prototype.top = function (pens) {
|
|
3952
|
-
var
|
|
4283
|
+
var e_13, _a;
|
|
3953
4284
|
var _this = this;
|
|
3954
4285
|
if (!pens)
|
|
3955
4286
|
pens = this.store.active;
|
|
@@ -3978,12 +4309,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3978
4309
|
_loop_3(pen);
|
|
3979
4310
|
}
|
|
3980
4311
|
}
|
|
3981
|
-
catch (
|
|
4312
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
3982
4313
|
finally {
|
|
3983
4314
|
try {
|
|
3984
4315
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3985
4316
|
}
|
|
3986
|
-
finally { if (
|
|
4317
|
+
finally { if (e_13) throw e_13.error; }
|
|
3987
4318
|
}
|
|
3988
4319
|
this.store.emitter.emit('layer', { type: 'top', pens: pens });
|
|
3989
4320
|
};
|
|
@@ -4007,7 +4338,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
4007
4338
|
* @param pens 画笔们,注意 pen 必须在该数组内才有效
|
|
4008
4339
|
*/
|
|
4009
4340
|
Meta2d.prototype.bottom = function (pens) {
|
|
4010
|
-
var
|
|
4341
|
+
var e_14, _a;
|
|
4011
4342
|
if (!pens)
|
|
4012
4343
|
pens = this.store.active;
|
|
4013
4344
|
if (!Array.isArray(pens))
|
|
@@ -4039,12 +4370,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
4039
4370
|
_loop_4(pen);
|
|
4040
4371
|
}
|
|
4041
4372
|
}
|
|
4042
|
-
catch (
|
|
4373
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
4043
4374
|
finally {
|
|
4044
4375
|
try {
|
|
4045
4376
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
4046
4377
|
}
|
|
4047
|
-
finally { if (
|
|
4378
|
+
finally { if (e_14) throw e_14.error; }
|
|
4048
4379
|
}
|
|
4049
4380
|
this.store.emitter.emit('layer', { type: 'bottom', pens: pens });
|
|
4050
4381
|
};
|
|
@@ -4054,7 +4385,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
4054
4385
|
* @param pen 画笔
|
|
4055
4386
|
*/
|
|
4056
4387
|
Meta2d.prototype.upByArea = function (pen) {
|
|
4057
|
-
var _a,
|
|
4388
|
+
var _a, e_15, _b;
|
|
4058
4389
|
var _this = this;
|
|
4059
4390
|
var index = this.store.data.pens.findIndex(function (p) { return p.id === pen.id; });
|
|
4060
4391
|
if (index === -1) {
|
|
@@ -4104,12 +4435,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
4104
4435
|
_loop_6(pen_3);
|
|
4105
4436
|
}
|
|
4106
4437
|
}
|
|
4107
|
-
catch (
|
|
4438
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
4108
4439
|
finally {
|
|
4109
4440
|
try {
|
|
4110
4441
|
if (allPens_1_1 && !allPens_1_1.done && (_b = allPens_1.return)) _b.call(allPens_1);
|
|
4111
4442
|
}
|
|
4112
|
-
finally { if (
|
|
4443
|
+
finally { if (e_15) throw e_15.error; }
|
|
4113
4444
|
}
|
|
4114
4445
|
this.initImageCanvas([pen]);
|
|
4115
4446
|
};
|
|
@@ -4163,7 +4494,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
4163
4494
|
* @param pens 画笔
|
|
4164
4495
|
*/
|
|
4165
4496
|
Meta2d.prototype.up = function (pens) {
|
|
4166
|
-
var
|
|
4497
|
+
var e_16, _a;
|
|
4167
4498
|
var _this = this;
|
|
4168
4499
|
if (!pens)
|
|
4169
4500
|
pens = this.store.active;
|
|
@@ -4218,12 +4549,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
4218
4549
|
_loop_7(pen);
|
|
4219
4550
|
}
|
|
4220
4551
|
}
|
|
4221
|
-
catch (
|
|
4552
|
+
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
4222
4553
|
finally {
|
|
4223
4554
|
try {
|
|
4224
4555
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
4225
4556
|
}
|
|
4226
|
-
finally { if (
|
|
4557
|
+
finally { if (e_16) throw e_16.error; }
|
|
4227
4558
|
}
|
|
4228
4559
|
this.store.emitter.emit('layer', { type: 'up', pens: pens });
|
|
4229
4560
|
};
|
|
@@ -4232,7 +4563,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
4232
4563
|
* @param pen 画笔
|
|
4233
4564
|
*/
|
|
4234
4565
|
Meta2d.prototype.down = function (pens) {
|
|
4235
|
-
var
|
|
4566
|
+
var e_17, _a;
|
|
4236
4567
|
var _this = this;
|
|
4237
4568
|
if (!pens)
|
|
4238
4569
|
pens = this.store.active;
|
|
@@ -4289,12 +4620,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
4289
4620
|
_loop_9(pen);
|
|
4290
4621
|
}
|
|
4291
4622
|
}
|
|
4292
|
-
catch (
|
|
4623
|
+
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
4293
4624
|
finally {
|
|
4294
4625
|
try {
|
|
4295
4626
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
4296
4627
|
}
|
|
4297
|
-
finally { if (
|
|
4628
|
+
finally { if (e_17) throw e_17.error; }
|
|
4298
4629
|
}
|
|
4299
4630
|
this.store.emitter.emit('layer', { type: 'down', pens: pens });
|
|
4300
4631
|
};
|
|
@@ -4374,7 +4705,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
4374
4705
|
var nextNodes_1 = [];
|
|
4375
4706
|
// 2. 遍历出线的 nextNode
|
|
4376
4707
|
lines.forEach(function (line) {
|
|
4377
|
-
var
|
|
4708
|
+
var e_18, _a;
|
|
4378
4709
|
var lineNextNode = _this.nextNode(line);
|
|
4379
4710
|
var _loop_11 = function (node) {
|
|
4380
4711
|
var have = nextNodes_1.find(function (next) { return next.id === node.id; });
|
|
@@ -4387,12 +4718,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
4387
4718
|
_loop_11(node);
|
|
4388
4719
|
}
|
|
4389
4720
|
}
|
|
4390
|
-
catch (
|
|
4721
|
+
catch (e_18_1) { e_18 = { error: e_18_1 }; }
|
|
4391
4722
|
finally {
|
|
4392
4723
|
try {
|
|
4393
4724
|
if (lineNextNode_1_1 && !lineNextNode_1_1.done && (_a = lineNextNode_1.return)) _a.call(lineNextNode_1);
|
|
4394
4725
|
}
|
|
4395
|
-
finally { if (
|
|
4726
|
+
finally { if (e_18) throw e_18.error; }
|
|
4396
4727
|
}
|
|
4397
4728
|
});
|
|
4398
4729
|
return nextNodes_1;
|
|
@@ -4415,7 +4746,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
4415
4746
|
var preNodes_1 = [];
|
|
4416
4747
|
// 2. 遍历入线的 preNode
|
|
4417
4748
|
lines.forEach(function (line) {
|
|
4418
|
-
var
|
|
4749
|
+
var e_19, _a;
|
|
4419
4750
|
var linePreNode = _this.previousNode(line);
|
|
4420
4751
|
var _loop_12 = function (node) {
|
|
4421
4752
|
var have = preNodes_1.find(function (pre) { return pre.id === node.id; });
|
|
@@ -4428,12 +4759,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
4428
4759
|
_loop_12(node);
|
|
4429
4760
|
}
|
|
4430
4761
|
}
|
|
4431
|
-
catch (
|
|
4762
|
+
catch (e_19_1) { e_19 = { error: e_19_1 }; }
|
|
4432
4763
|
finally {
|
|
4433
4764
|
try {
|
|
4434
4765
|
if (linePreNode_1_1 && !linePreNode_1_1.done && (_a = linePreNode_1.return)) _a.call(linePreNode_1);
|
|
4435
4766
|
}
|
|
4436
|
-
finally { if (
|
|
4767
|
+
finally { if (e_19) throw e_19.error; }
|
|
4437
4768
|
}
|
|
4438
4769
|
});
|
|
4439
4770
|
return preNodes_1;
|
|
@@ -4780,7 +5111,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
4780
5111
|
});
|
|
4781
5112
|
};
|
|
4782
5113
|
Meta2d.prototype.setVisible = function (pen, visible, render) {
|
|
4783
|
-
var
|
|
5114
|
+
var e_20, _a;
|
|
4784
5115
|
if (render === void 0) { render = true; }
|
|
4785
5116
|
this.onSizeUpdate();
|
|
4786
5117
|
this.setValue({ id: pen.id, visible: visible }, { render: false, doEvent: false });
|
|
@@ -4792,12 +5123,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
4792
5123
|
child && this.setVisible(child, visible, false);
|
|
4793
5124
|
}
|
|
4794
5125
|
}
|
|
4795
|
-
catch (
|
|
5126
|
+
catch (e_20_1) { e_20 = { error: e_20_1 }; }
|
|
4796
5127
|
finally {
|
|
4797
5128
|
try {
|
|
4798
5129
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
4799
5130
|
}
|
|
4800
|
-
finally { if (
|
|
5131
|
+
finally { if (e_20) throw e_20.error; }
|
|
4801
5132
|
}
|
|
4802
5133
|
}
|
|
4803
5134
|
var allPens = getAllChildren(pen, this.store);
|