@meta2d/core 1.0.50 → 1.0.52

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/src/core.js CHANGED
@@ -212,13 +212,14 @@ var Meta2d = /** @class */ (function () {
212
212
  }
213
213
  };
214
214
  this.doEvent = function (pen, eventName) {
215
- var _a, _b, _c, _e, _f, _g;
215
+ var e_1, _a, e_2, _b;
216
+ var _c, _e, _f, _g, _h, _j, _k, _l, _m, _o;
216
217
  if (!pen) {
217
218
  return;
218
219
  }
219
220
  var old = false; //是否是旧的事件
220
221
  var indexArr = []; //事件条件成立的索引
221
- (_a = pen.events) === null || _a === void 0 ? void 0 : _a.forEach(function (event, index) {
222
+ (_c = pen.events) === null || _c === void 0 ? void 0 : _c.forEach(function (event, index) {
222
223
  var _a;
223
224
  if (event.actions && event.actions.length) {
224
225
  if (event.name === eventName) {
@@ -318,14 +319,14 @@ var Meta2d = /** @class */ (function () {
318
319
  });
319
320
  //所有的条件判断后,再统一执行条件成立的事件
320
321
  if (old) {
321
- (_b = pen.events) === null || _b === void 0 ? void 0 : _b.forEach(function (event, index) {
322
+ (_e = pen.events) === null || _e === void 0 ? void 0 : _e.forEach(function (event, index) {
322
323
  if (indexArr.includes(index)) {
323
324
  _this.events[event.action](pen, event);
324
325
  }
325
326
  });
326
327
  }
327
328
  else {
328
- (_c = pen.events) === null || _c === void 0 ? void 0 : _c.forEach(function (event, index) {
329
+ (_f = pen.events) === null || _f === void 0 ? void 0 : _f.forEach(function (event, index) {
329
330
  if (indexArr.includes(index)) {
330
331
  event.actions.forEach(function (action) {
331
332
  if (_this.events[action.action]) {
@@ -336,20 +337,27 @@ var Meta2d = /** @class */ (function () {
336
337
  });
337
338
  }
338
339
  if (eventName === 'valueUpdate') {
339
- (_e = pen.realTimes) === null || _e === void 0 ? void 0 : _e.forEach(function (realTime) {
340
+ (_g = pen.realTimes) === null || _g === void 0 ? void 0 : _g.forEach(function (realTime) {
340
341
  var _a, _b;
341
342
  var indexArr = [];
342
343
  (_a = realTime.triggers) === null || _a === void 0 ? void 0 : _a.forEach(function (trigger, index) {
344
+ var _a;
343
345
  var flag = false;
344
- if (trigger.conditionType === 'and') {
345
- flag = trigger.conditions.every(function (condition) {
346
- return _this.judgeCondition(pen, realTime.key, condition);
347
- });
346
+ if ((_a = trigger.conditions) === null || _a === void 0 ? void 0 : _a.length) {
347
+ if (trigger.conditionType === 'and') {
348
+ flag = trigger.conditions.every(function (condition) {
349
+ return _this.judgeCondition(pen, realTime.key, condition);
350
+ });
351
+ }
352
+ else if (trigger.conditionType === 'or') {
353
+ flag = trigger.conditions.some(function (condition) {
354
+ return _this.judgeCondition(pen, realTime.key, condition);
355
+ });
356
+ }
348
357
  }
349
- else if (trigger.conditionType === 'or') {
350
- flag = trigger.conditions.some(function (condition) {
351
- return _this.judgeCondition(pen, realTime.key, condition);
352
- });
358
+ else {
359
+ //无条件
360
+ flag = true;
353
361
  }
354
362
  if (flag) {
355
363
  indexArr.push(index);
@@ -370,23 +378,30 @@ var Meta2d = /** @class */ (function () {
370
378
  });
371
379
  //全局
372
380
  var indexArr_1 = [];
373
- (_f = _this.store.globalTriggers[pen.id]) === null || _f === void 0 ? void 0 : _f.forEach(function (trigger, index) {
381
+ (_h = _this.store.globalTriggers[pen.id]) === null || _h === void 0 ? void 0 : _h.forEach(function (trigger, index) {
382
+ var _a;
374
383
  var flag = false;
375
- if (trigger.conditionType === 'and') {
376
- flag = trigger.conditions.every(function (condition) {
377
- return _this.judgeCondition(_this.store.pens[condition.source], condition.key, condition);
378
- });
384
+ if ((_a = trigger.conditions) === null || _a === void 0 ? void 0 : _a.length) {
385
+ if (trigger.conditionType === 'and') {
386
+ flag = trigger.conditions.every(function (condition) {
387
+ return _this.judgeCondition(_this.store.pens[condition.source], condition.key, condition);
388
+ });
389
+ }
390
+ else if (trigger.conditionType === 'or') {
391
+ flag = trigger.conditions.some(function (condition) {
392
+ return _this.judgeCondition(_this.store.pens[condition.source], condition.key, condition);
393
+ });
394
+ }
379
395
  }
380
- else if (trigger.conditionType === 'or') {
381
- flag = trigger.conditions.some(function (condition) {
382
- return _this.judgeCondition(_this.store.pens[condition.source], condition.key, condition);
383
- });
396
+ else {
397
+ //无条件
398
+ flag = true;
384
399
  }
385
400
  if (flag) {
386
401
  indexArr_1.push(index);
387
402
  }
388
403
  });
389
- (_g = _this.store.globalTriggers[pen.id]) === null || _g === void 0 ? void 0 : _g.forEach(function (trigger, index) {
404
+ (_j = _this.store.globalTriggers[pen.id]) === null || _j === void 0 ? void 0 : _j.forEach(function (trigger, index) {
390
405
  var _a;
391
406
  if (indexArr_1.includes(index)) {
392
407
  (_a = trigger.actions) === null || _a === void 0 ? void 0 : _a.forEach(function (event) {
@@ -394,6 +409,58 @@ var Meta2d = /** @class */ (function () {
394
409
  });
395
410
  }
396
411
  });
412
+ //triggers
413
+ if ((_k = pen.triggers) === null || _k === void 0 ? void 0 : _k.length) {
414
+ try {
415
+ for (var _p = __values(pen.triggers), _q = _p.next(); !_q.done; _q = _p.next()) {
416
+ var trigger = _q.value;
417
+ if ((_l = trigger.status) === null || _l === void 0 ? void 0 : _l.length) {
418
+ try {
419
+ for (var _r = (e_2 = void 0, __values(trigger.status)), _s = _r.next(); !_s.done; _s = _r.next()) {
420
+ var state = _s.value;
421
+ var flag = false;
422
+ if ((_m = state.conditions) === null || _m === void 0 ? void 0 : _m.length) {
423
+ if (state.conditionType === 'and') {
424
+ flag = state.conditions.every(function (condition) {
425
+ return _this.judgeCondition(pen, condition.key, condition);
426
+ });
427
+ }
428
+ else if (trigger.conditionType === 'or') {
429
+ flag = state.conditions.some(function (condition) {
430
+ return _this.judgeCondition(pen, condition.key, condition);
431
+ });
432
+ }
433
+ }
434
+ else {
435
+ //无条件
436
+ flag = true;
437
+ }
438
+ if (flag) {
439
+ (_o = state.actions) === null || _o === void 0 ? void 0 : _o.forEach(function (event) {
440
+ _this.events[event.action](pen, event);
441
+ });
442
+ break;
443
+ }
444
+ }
445
+ }
446
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
447
+ finally {
448
+ try {
449
+ if (_s && !_s.done && (_b = _r.return)) _b.call(_r);
450
+ }
451
+ finally { if (e_2) throw e_2.error; }
452
+ }
453
+ }
454
+ }
455
+ }
456
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
457
+ finally {
458
+ try {
459
+ if (_q && !_q.done && (_a = _p.return)) _a.call(_p);
460
+ }
461
+ finally { if (e_1) throw e_1.error; }
462
+ }
463
+ }
397
464
  }
398
465
  // 事件冒泡,子执行完,父执行
399
466
  _this.doEvent(_this.store.pens[pen.parentId], eventName);
@@ -794,11 +861,11 @@ var Meta2d = /** @class */ (function () {
794
861
  value[key] = _pen[key];
795
862
  }
796
863
  }
797
- value.id = _pen.id;
864
+ // value.id = _pen.id;
798
865
  if (_pen.deviceId) {
799
866
  value.deviceId = _pen.deviceId;
800
867
  }
801
- _this.sendDataToNetWork(value, e.network);
868
+ _this.sendDataToNetWork(value, pen, e);
802
869
  return;
803
870
  }
804
871
  }
@@ -869,13 +936,15 @@ var Meta2d = /** @class */ (function () {
869
936
  }
870
937
  this.store.emitter.emit('sendData', data);
871
938
  };
872
- Meta2d.prototype.sendDataToNetWork = function (value, _network) {
939
+ Meta2d.prototype.sendDataToNetWork = function (value, pen, e) {
940
+ var _a;
873
941
  return __awaiter(this, void 0, void 0, function () {
874
- var network, i, keys, params, res, clients_1, mqttClient_1, websockets, websocket_1;
875
- return __generator(this, function (_a) {
876
- switch (_a.label) {
942
+ var network, i, keys, params, url_1, keys, res, data, fnJs, clients_1, mqttClient_1, websockets, websocket_1;
943
+ var _this = this;
944
+ return __generator(this, function (_b) {
945
+ switch (_b.label) {
877
946
  case 0:
878
- network = deepClone(_network);
947
+ network = deepClone(e.network);
879
948
  if (network.data) {
880
949
  Object.assign(network, network.data);
881
950
  delete network.data;
@@ -883,16 +952,19 @@ var Meta2d = /** @class */ (function () {
883
952
  if (!network.url) {
884
953
  return [2 /*return*/];
885
954
  }
886
- if (!(network.protocol === 'http')) return [3 /*break*/, 2];
955
+ if (!(network.protocol === 'http')) return [3 /*break*/, 5];
887
956
  if (typeof network.headers === 'object') {
888
957
  for (i in network.headers) {
889
- keys = network.headers[i].match(/(?<=\$\{).*?(?=\})/g);
890
- if (keys) {
891
- network.headers[i] = network.headers[i].replace("${" + keys[0] + "}", this.getDynamicParam(keys[0]));
958
+ if (typeof network.headers[i] === 'string') {
959
+ keys = network.headers[i].match(/(?<=\$\{).*?(?=\})/g);
960
+ if (keys) {
961
+ network.headers[i] = network.headers[i].replace("${" + keys[0] + "}", this.getDynamicParam(keys[0]));
962
+ }
892
963
  }
893
964
  }
894
965
  }
895
966
  params = undefined;
967
+ url_1 = network.url;
896
968
  if (network.method === 'GET') {
897
969
  params =
898
970
  '?' +
@@ -900,18 +972,47 @@ var Meta2d = /** @class */ (function () {
900
972
  .map(function (key) { return key + '=' + value[key]; })
901
973
  .join('&');
902
974
  }
903
- return [4 /*yield*/, fetch(network.url + (params ? params : ''), {
975
+ if (network.method === 'POST') {
976
+ if (url_1.indexOf('${') > -1) {
977
+ keys = url_1.match(/(?<=\$\{).*?(?=\})/g);
978
+ if (keys) {
979
+ keys.forEach(function (key) {
980
+ url_1 = url_1.replace("${" + key + "}", getter(pen, key) || _this.getDynamicParam(key));
981
+ });
982
+ }
983
+ }
984
+ }
985
+ return [4 /*yield*/, fetch(url_1 + (params ? params : ''), {
904
986
  headers: network.headers || {},
905
987
  method: network.method,
906
988
  body: network.method === 'POST' ? JSON.stringify(value) : undefined,
907
989
  })];
908
990
  case 1:
909
- res = _a.sent();
910
- if (res.ok) {
911
- console.info('http消息发送成功');
912
- }
913
- return [3 /*break*/, 3];
991
+ res = _b.sent();
992
+ if (!res.ok) return [3 /*break*/, 4];
993
+ if (!e.callback) return [3 /*break*/, 3];
994
+ return [4 /*yield*/, res.text()];
914
995
  case 2:
996
+ data = _b.sent();
997
+ if (!e.fn) {
998
+ try {
999
+ if (typeof e.callback !== 'string') {
1000
+ throw new Error('[meta2d] Function callback must be string');
1001
+ }
1002
+ fnJs = e.callback;
1003
+ e.fn = new Function('pen', 'data', 'context', fnJs);
1004
+ }
1005
+ catch (err) {
1006
+ console.error('[meta2d]: Error on make a function:', err);
1007
+ }
1008
+ }
1009
+ (_a = e.fn) === null || _a === void 0 ? void 0 : _a.call(e, pen, data, { meta2d: this, e: e });
1010
+ _b.label = 3;
1011
+ case 3:
1012
+ console.info('http消息发送成功');
1013
+ _b.label = 4;
1014
+ case 4: return [3 /*break*/, 6];
1015
+ case 5:
915
1016
  if (network.protocol === 'mqtt') {
916
1017
  clients_1 = this.mqttClients.filter(function (client) { return client.options.href === network.url; });
917
1018
  if (clients_1 && clients_1.length) {
@@ -950,8 +1051,8 @@ var Meta2d = /** @class */ (function () {
950
1051
  };
951
1052
  }
952
1053
  }
953
- _a.label = 3;
954
- case 3: return [2 /*return*/];
1054
+ _b.label = 6;
1055
+ case 6: return [2 /*return*/];
955
1056
  }
956
1057
  });
957
1058
  });
@@ -1076,7 +1177,7 @@ var Meta2d = /** @class */ (function () {
1076
1177
  this.store.patchFlagsTop = true;
1077
1178
  };
1078
1179
  Meta2d.prototype.open = function (data, render) {
1079
- var e_1, _a, e_2, _b, e_3, _c, e_4, _e;
1180
+ var e_3, _a, e_4, _b, e_5, _c, e_6, _e;
1080
1181
  var _this = this;
1081
1182
  if (render === void 0) { render = true; }
1082
1183
  this.clear(false, data === null || data === void 0 ? void 0 : data.template);
@@ -1096,12 +1197,12 @@ var Meta2d = /** @class */ (function () {
1096
1197
  this.store.pens[pen.id] = pen;
1097
1198
  }
1098
1199
  }
1099
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1200
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1100
1201
  finally {
1101
1202
  try {
1102
1203
  if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
1103
1204
  }
1104
- finally { if (e_1) throw e_1.error; }
1205
+ finally { if (e_3) throw e_3.error; }
1105
1206
  }
1106
1207
  try {
1107
1208
  for (var _h = __values(data.pens), _j = _h.next(); !_j.done; _j = _h.next()) {
@@ -1109,12 +1210,12 @@ var Meta2d = /** @class */ (function () {
1109
1210
  this.canvas.makePen(pen);
1110
1211
  }
1111
1212
  }
1112
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1213
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1113
1214
  finally {
1114
1215
  try {
1115
1216
  if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
1116
1217
  }
1117
- finally { if (e_2) throw e_2.error; }
1218
+ finally { if (e_4) throw e_4.error; }
1118
1219
  }
1119
1220
  try {
1120
1221
  for (var _k = __values(data.pens), _l = _k.next(); !_l.done; _l = _k.next()) {
@@ -1122,12 +1223,12 @@ var Meta2d = /** @class */ (function () {
1122
1223
  this.canvas.updateLines(pen);
1123
1224
  }
1124
1225
  }
1125
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
1226
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
1126
1227
  finally {
1127
1228
  try {
1128
1229
  if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
1129
1230
  }
1130
- finally { if (e_3) throw e_3.error; }
1231
+ finally { if (e_5) throw e_5.error; }
1131
1232
  }
1132
1233
  }
1133
1234
  this.canvas.patchFlagsLines.forEach(function (pen) {
@@ -1162,12 +1263,12 @@ var Meta2d = /** @class */ (function () {
1162
1263
  });
1163
1264
  }
1164
1265
  }
1165
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
1266
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
1166
1267
  finally {
1167
1268
  try {
1168
1269
  if (_o && !_o.done && (_e = _m.return)) _e.call(_m);
1169
1270
  }
1170
- finally { if (e_4) throw e_4.error; }
1271
+ finally { if (e_6) throw e_6.error; }
1171
1272
  }
1172
1273
  }
1173
1274
  this.canvas.autoPolylineFlag = false;
@@ -1408,7 +1509,7 @@ var Meta2d = /** @class */ (function () {
1408
1509
  * @param render 是否重绘
1409
1510
  */
1410
1511
  Meta2d.prototype.clear = function (render, template) {
1411
- var e_5, _a;
1512
+ var e_7, _a;
1412
1513
  var _b;
1413
1514
  if (render === void 0) { render = true; }
1414
1515
  try {
@@ -1417,12 +1518,12 @@ var Meta2d = /** @class */ (function () {
1417
1518
  (_b = pen.onDestroy) === null || _b === void 0 ? void 0 : _b.call(pen, pen);
1418
1519
  }
1419
1520
  }
1420
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
1521
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
1421
1522
  finally {
1422
1523
  try {
1423
1524
  if (_e && !_e.done && (_a = _c.return)) _a.call(_c);
1424
1525
  }
1425
- finally { if (e_5) throw e_5.error; }
1526
+ finally { if (e_7) throw e_7.error; }
1426
1527
  }
1427
1528
  clearStore(this.store, template);
1428
1529
  this.hideInput();
@@ -1777,6 +1878,7 @@ var Meta2d = /** @class */ (function () {
1777
1878
  }
1778
1879
  this.store.emitter.emit('combine', [parent]);
1779
1880
  this.render();
1881
+ return parent;
1780
1882
  };
1781
1883
  Meta2d.prototype.uncombine = function (pen) {
1782
1884
  var _this = this;
@@ -2579,7 +2681,7 @@ var Meta2d = /** @class */ (function () {
2579
2681
  return;
2580
2682
  }
2581
2683
  var penValue = penValues.get(pen);
2582
- if (typeof pen.onBinds === 'function') {
2684
+ if (!pen.noOnBinds && typeof pen.onBinds === 'function') {
2583
2685
  // 已经计算了
2584
2686
  if (penValue) {
2585
2687
  return;
@@ -2654,6 +2756,9 @@ var Meta2d = /** @class */ (function () {
2654
2756
  var _this = this;
2655
2757
  var _b = _a === void 0 ? {} : _a, _c = _b.render, render = _c === void 0 ? true : _c, _e = _b.doEvent, doEvent = _e === void 0 ? true : _e, history = _b.history;
2656
2758
  var pens = [];
2759
+ if (!data) {
2760
+ return;
2761
+ }
2657
2762
  if (data.id) {
2658
2763
  if (data.id === this.store.data.id) {
2659
2764
  this.setDatabyOptions(data);
@@ -3000,12 +3105,12 @@ var Meta2d = /** @class */ (function () {
3000
3105
  if (containBkImg === void 0) { containBkImg = false; }
3001
3106
  return this.canvas.toPng(padding, callback, containBkImg, maxWidth);
3002
3107
  };
3003
- Meta2d.prototype.activeToPng = function (padding) {
3004
- return this.canvas.activeToPng(padding);
3108
+ Meta2d.prototype.activeToPng = function (padding, maxWidth) {
3109
+ return this.canvas.activeToPng(padding, maxWidth);
3005
3110
  };
3006
- Meta2d.prototype.pensToPng = function (pens, padding) {
3111
+ Meta2d.prototype.pensToPng = function (pens, padding, maxWidth) {
3007
3112
  if (pens === void 0) { pens = this.store.active; }
3008
- return this.canvas.pensToPng(pens, padding);
3113
+ return this.canvas.pensToPng(pens, padding, maxWidth);
3009
3114
  };
3010
3115
  /**
3011
3116
  * 下载 png
@@ -3013,7 +3118,7 @@ var Meta2d = /** @class */ (function () {
3013
3118
  * @param padding 上右下左的内边距
3014
3119
  */
3015
3120
  Meta2d.prototype.downloadPng = function (name, padding, maxWidth) {
3016
- var e_6, _a;
3121
+ var e_8, _a;
3017
3122
  var _this = this;
3018
3123
  var _b;
3019
3124
  try {
@@ -3025,12 +3130,12 @@ var Meta2d = /** @class */ (function () {
3025
3130
  }
3026
3131
  }
3027
3132
  }
3028
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
3133
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
3029
3134
  finally {
3030
3135
  try {
3031
3136
  if (_e && !_e.done && (_a = _c.return)) _a.call(_c);
3032
3137
  }
3033
- finally { if (e_6) throw e_6.error; }
3138
+ finally { if (e_8) throw e_8.error; }
3034
3139
  }
3035
3140
  setTimeout(function () {
3036
3141
  var a = document.createElement('a');
@@ -3042,7 +3147,7 @@ var Meta2d = /** @class */ (function () {
3042
3147
  }, 1000);
3043
3148
  };
3044
3149
  Meta2d.prototype.downloadSvg = function () {
3045
- var e_7, _a;
3150
+ var e_9, _a;
3046
3151
  if (!window.C2S) {
3047
3152
  console.error('请先加载乐吾乐官网下的canvas2svg.js', 'https://assets.le5lecdn.com/2d/canvas2svg.js');
3048
3153
  throw new Error('请先加载乐吾乐官网下的canvas2svg.js');
@@ -3061,12 +3166,12 @@ var Meta2d = /** @class */ (function () {
3061
3166
  renderPenRaw(ctx, pen, rect, true);
3062
3167
  }
3063
3168
  }
3064
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
3169
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
3065
3170
  finally {
3066
3171
  try {
3067
3172
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3068
3173
  }
3069
- finally { if (e_7) throw e_7.error; }
3174
+ finally { if (e_9) throw e_9.error; }
3070
3175
  }
3071
3176
  var mySerializedSVG = ctx.getSerializedSvg();
3072
3177
  if (this.store.data.background) {
@@ -3525,7 +3630,7 @@ var Meta2d = /** @class */ (function () {
3525
3630
  });
3526
3631
  };
3527
3632
  Meta2d.prototype.alignNodes = function (align, pens, rect) {
3528
- var e_8, _a;
3633
+ var e_10, _a;
3529
3634
  if (pens === void 0) { pens = this.store.data.pens; }
3530
3635
  !rect && (rect = this.getPenRect(this.getRect(pens)));
3531
3636
  var initPens = deepClone(pens); // 原 pens ,深拷贝一下
@@ -3535,12 +3640,12 @@ var Meta2d = /** @class */ (function () {
3535
3640
  this.alignPen(align, item, rect);
3536
3641
  }
3537
3642
  }
3538
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
3643
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
3539
3644
  finally {
3540
3645
  try {
3541
3646
  if (pens_1_1 && !pens_1_1.done && (_a = pens_1.return)) _a.call(pens_1);
3542
3647
  }
3543
- finally { if (e_8) throw e_8.error; }
3648
+ finally { if (e_10) throw e_10.error; }
3544
3649
  }
3545
3650
  this.initImageCanvas(pens);
3546
3651
  this.initTemplateCanvas(pens);
@@ -3553,7 +3658,7 @@ var Meta2d = /** @class */ (function () {
3553
3658
  };
3554
3659
  //对齐大屏
3555
3660
  Meta2d.prototype.alignNodesV = function (align, pens) {
3556
- var e_9, _a;
3661
+ var e_11, _a;
3557
3662
  if (pens === void 0) { pens = this.store.data.pens; }
3558
3663
  var width = this.store.data.width || this.store.options.width;
3559
3664
  var height = this.store.data.height || this.store.options.height;
@@ -3570,12 +3675,12 @@ var Meta2d = /** @class */ (function () {
3570
3675
  this.alignPen(align, item, rect);
3571
3676
  }
3572
3677
  }
3573
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
3678
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
3574
3679
  finally {
3575
3680
  try {
3576
3681
  if (pens_2_1 && !pens_2_1.done && (_a = pens_2.return)) _a.call(pens_2);
3577
3682
  }
3578
- finally { if (e_9) throw e_9.error; }
3683
+ finally { if (e_11) throw e_11.error; }
3579
3684
  }
3580
3685
  this.initImageCanvas(pens);
3581
3686
  this.initTemplateCanvas(pens);
@@ -3670,7 +3775,7 @@ var Meta2d = /** @class */ (function () {
3670
3775
  * @param distance 总的宽 or 高
3671
3776
  */
3672
3777
  Meta2d.prototype.spaceBetweenByDirection = function (direction, pens, distance) {
3673
- var e_10, _a;
3778
+ var e_12, _a;
3674
3779
  var _this = this;
3675
3780
  if (pens === void 0) { pens = this.store.data.pens; }
3676
3781
  !distance && (distance = this.getPenRect(this.getRect(pens))[direction]);
@@ -3704,12 +3809,12 @@ var Meta2d = /** @class */ (function () {
3704
3809
  this.setValue(__assign({ id: pen.id }, penRect), { render: false, doEvent: false });
3705
3810
  }
3706
3811
  }
3707
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
3812
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
3708
3813
  finally {
3709
3814
  try {
3710
3815
  if (pens_3_1 && !pens_3_1.done && (_a = pens_3.return)) _a.call(pens_3);
3711
3816
  }
3712
- finally { if (e_10) throw e_10.error; }
3817
+ finally { if (e_12) throw e_12.error; }
3713
3818
  }
3714
3819
  this.initImageCanvas(pens);
3715
3820
  this.initTemplateCanvas(pens);
@@ -3773,6 +3878,7 @@ var Meta2d = /** @class */ (function () {
3773
3878
  });
3774
3879
  };
3775
3880
  Meta2d.prototype.gotoView = function (pen) {
3881
+ var e_13, _a;
3776
3882
  var center = this.getViewCenter();
3777
3883
  var x = center.x -
3778
3884
  pen.calculative.worldRect.x -
@@ -3785,6 +3891,19 @@ var Meta2d = /** @class */ (function () {
3785
3891
  }
3786
3892
  this.store.data.x = x;
3787
3893
  this.store.data.y = y;
3894
+ try {
3895
+ for (var _b = __values(this.store.data.pens), _c = _b.next(); !_c.done; _c = _b.next()) {
3896
+ var pen_1 = _c.value;
3897
+ calcInView(pen_1);
3898
+ }
3899
+ }
3900
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
3901
+ finally {
3902
+ try {
3903
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3904
+ }
3905
+ finally { if (e_13) throw e_13.error; }
3906
+ }
3788
3907
  this.canvas.canvasImage.init();
3789
3908
  this.canvas.canvasImageBottom.init();
3790
3909
  this.render();
@@ -3830,7 +3949,7 @@ var Meta2d = /** @class */ (function () {
3830
3949
  * @param pens pen 置顶的画笔
3831
3950
  */
3832
3951
  Meta2d.prototype.top = function (pens) {
3833
- var e_11, _a;
3952
+ var e_14, _a;
3834
3953
  var _this = this;
3835
3954
  if (!pens)
3836
3955
  pens = this.store.active;
@@ -3859,12 +3978,12 @@ var Meta2d = /** @class */ (function () {
3859
3978
  _loop_3(pen);
3860
3979
  }
3861
3980
  }
3862
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
3981
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
3863
3982
  finally {
3864
3983
  try {
3865
3984
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3866
3985
  }
3867
- finally { if (e_11) throw e_11.error; }
3986
+ finally { if (e_14) throw e_14.error; }
3868
3987
  }
3869
3988
  this.store.emitter.emit('layer', { type: 'top', pens: pens });
3870
3989
  };
@@ -3888,7 +4007,7 @@ var Meta2d = /** @class */ (function () {
3888
4007
  * @param pens 画笔们,注意 pen 必须在该数组内才有效
3889
4008
  */
3890
4009
  Meta2d.prototype.bottom = function (pens) {
3891
- var e_12, _a;
4010
+ var e_15, _a;
3892
4011
  if (!pens)
3893
4012
  pens = this.store.active;
3894
4013
  if (!Array.isArray(pens))
@@ -3898,15 +4017,15 @@ var Meta2d = /** @class */ (function () {
3898
4017
  var allIds = __spreadArray(__spreadArray([], __read(getAllChildren(pen, this_2.store)), false), [pen], false).map(function (p) { return p.id; });
3899
4018
  var allPens = _pens.filter(function (p) { return allIds.includes(p.id); });
3900
4019
  var _loop_5 = function (i) {
3901
- var pen_1 = allPens[i];
3902
- var index = _pens.findIndex(function (p) { return p.id === pen_1.id; });
4020
+ var pen_2 = allPens[i];
4021
+ var index = _pens.findIndex(function (p) { return p.id === pen_2.id; });
3903
4022
  if (index > -1) {
3904
4023
  _pens.unshift(_pens[index]);
3905
4024
  _pens.splice(index + 1, 1);
3906
- this_2.initTemplateCanvas([pen_1]);
3907
- this_2.initImageCanvas([pen_1]);
4025
+ this_2.initTemplateCanvas([pen_2]);
4026
+ this_2.initImageCanvas([pen_2]);
3908
4027
  }
3909
- this_2.specificLayerMove(pen_1, 'bottom');
4028
+ this_2.specificLayerMove(pen_2, 'bottom');
3910
4029
  };
3911
4030
  // 从后往前,保证 allPens 顺序不变
3912
4031
  for (var i = allPens.length - 1; i >= 0; i--) {
@@ -3920,12 +4039,12 @@ var Meta2d = /** @class */ (function () {
3920
4039
  _loop_4(pen);
3921
4040
  }
3922
4041
  }
3923
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
4042
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
3924
4043
  finally {
3925
4044
  try {
3926
4045
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3927
4046
  }
3928
- finally { if (e_12) throw e_12.error; }
4047
+ finally { if (e_15) throw e_15.error; }
3929
4048
  }
3930
4049
  this.store.emitter.emit('layer', { type: 'bottom', pens: pens });
3931
4050
  };
@@ -3935,7 +4054,7 @@ var Meta2d = /** @class */ (function () {
3935
4054
  * @param pen 画笔
3936
4055
  */
3937
4056
  Meta2d.prototype.upByArea = function (pen) {
3938
- var _a, e_13, _b;
4057
+ var _a, e_16, _b;
3939
4058
  var _this = this;
3940
4059
  var index = this.store.data.pens.findIndex(function (p) { return p.id === pen.id; });
3941
4060
  if (index === -1) {
@@ -3971,8 +4090,8 @@ var Meta2d = /** @class */ (function () {
3971
4090
  return;
3972
4091
  }
3973
4092
  (_a = this.store.data.pens).splice.apply(_a, __spreadArray([nextHitIndex + 1, 0], __read(allPens), false));
3974
- var _loop_6 = function (pen_2) {
3975
- var index_1 = this_3.store.data.pens.findIndex(function (p) { return p.id === pen_2.id; });
4093
+ var _loop_6 = function (pen_3) {
4094
+ var index_1 = this_3.store.data.pens.findIndex(function (p) { return p.id === pen_3.id; });
3976
4095
  if (index_1 > -1) {
3977
4096
  this_3.store.data.pens.splice(index_1, 1);
3978
4097
  }
@@ -3981,16 +4100,16 @@ var Meta2d = /** @class */ (function () {
3981
4100
  try {
3982
4101
  // 删除靠前的 allPens
3983
4102
  for (var allPens_1 = __values(allPens), allPens_1_1 = allPens_1.next(); !allPens_1_1.done; allPens_1_1 = allPens_1.next()) {
3984
- var pen_2 = allPens_1_1.value;
3985
- _loop_6(pen_2);
4103
+ var pen_3 = allPens_1_1.value;
4104
+ _loop_6(pen_3);
3986
4105
  }
3987
4106
  }
3988
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
4107
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
3989
4108
  finally {
3990
4109
  try {
3991
4110
  if (allPens_1_1 && !allPens_1_1.done && (_b = allPens_1.return)) _b.call(allPens_1);
3992
4111
  }
3993
- finally { if (e_13) throw e_13.error; }
4112
+ finally { if (e_16) throw e_16.error; }
3994
4113
  }
3995
4114
  this.initImageCanvas([pen]);
3996
4115
  };
@@ -4044,7 +4163,7 @@ var Meta2d = /** @class */ (function () {
4044
4163
  * @param pens 画笔
4045
4164
  */
4046
4165
  Meta2d.prototype.up = function (pens) {
4047
- var e_14, _a;
4166
+ var e_17, _a;
4048
4167
  var _this = this;
4049
4168
  if (!pens)
4050
4169
  pens = this.store.active;
@@ -4099,12 +4218,12 @@ var Meta2d = /** @class */ (function () {
4099
4218
  _loop_7(pen);
4100
4219
  }
4101
4220
  }
4102
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
4221
+ catch (e_17_1) { e_17 = { error: e_17_1 }; }
4103
4222
  finally {
4104
4223
  try {
4105
4224
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
4106
4225
  }
4107
- finally { if (e_14) throw e_14.error; }
4226
+ finally { if (e_17) throw e_17.error; }
4108
4227
  }
4109
4228
  this.store.emitter.emit('layer', { type: 'up', pens: pens });
4110
4229
  };
@@ -4113,7 +4232,7 @@ var Meta2d = /** @class */ (function () {
4113
4232
  * @param pen 画笔
4114
4233
  */
4115
4234
  Meta2d.prototype.down = function (pens) {
4116
- var e_15, _a;
4235
+ var e_18, _a;
4117
4236
  var _this = this;
4118
4237
  if (!pens)
4119
4238
  pens = this.store.active;
@@ -4170,12 +4289,12 @@ var Meta2d = /** @class */ (function () {
4170
4289
  _loop_9(pen);
4171
4290
  }
4172
4291
  }
4173
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
4292
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
4174
4293
  finally {
4175
4294
  try {
4176
4295
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
4177
4296
  }
4178
- finally { if (e_15) throw e_15.error; }
4297
+ finally { if (e_18) throw e_18.error; }
4179
4298
  }
4180
4299
  this.store.emitter.emit('layer', { type: 'down', pens: pens });
4181
4300
  };
@@ -4255,7 +4374,7 @@ var Meta2d = /** @class */ (function () {
4255
4374
  var nextNodes_1 = [];
4256
4375
  // 2. 遍历出线的 nextNode
4257
4376
  lines.forEach(function (line) {
4258
- var e_16, _a;
4377
+ var e_19, _a;
4259
4378
  var lineNextNode = _this.nextNode(line);
4260
4379
  var _loop_11 = function (node) {
4261
4380
  var have = nextNodes_1.find(function (next) { return next.id === node.id; });
@@ -4268,12 +4387,12 @@ var Meta2d = /** @class */ (function () {
4268
4387
  _loop_11(node);
4269
4388
  }
4270
4389
  }
4271
- catch (e_16_1) { e_16 = { error: e_16_1 }; }
4390
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
4272
4391
  finally {
4273
4392
  try {
4274
4393
  if (lineNextNode_1_1 && !lineNextNode_1_1.done && (_a = lineNextNode_1.return)) _a.call(lineNextNode_1);
4275
4394
  }
4276
- finally { if (e_16) throw e_16.error; }
4395
+ finally { if (e_19) throw e_19.error; }
4277
4396
  }
4278
4397
  });
4279
4398
  return nextNodes_1;
@@ -4296,7 +4415,7 @@ var Meta2d = /** @class */ (function () {
4296
4415
  var preNodes_1 = [];
4297
4416
  // 2. 遍历入线的 preNode
4298
4417
  lines.forEach(function (line) {
4299
- var e_17, _a;
4418
+ var e_20, _a;
4300
4419
  var linePreNode = _this.previousNode(line);
4301
4420
  var _loop_12 = function (node) {
4302
4421
  var have = preNodes_1.find(function (pre) { return pre.id === node.id; });
@@ -4309,12 +4428,12 @@ var Meta2d = /** @class */ (function () {
4309
4428
  _loop_12(node);
4310
4429
  }
4311
4430
  }
4312
- catch (e_17_1) { e_17 = { error: e_17_1 }; }
4431
+ catch (e_20_1) { e_20 = { error: e_20_1 }; }
4313
4432
  finally {
4314
4433
  try {
4315
4434
  if (linePreNode_1_1 && !linePreNode_1_1.done && (_a = linePreNode_1.return)) _a.call(linePreNode_1);
4316
4435
  }
4317
- finally { if (e_17) throw e_17.error; }
4436
+ finally { if (e_20) throw e_20.error; }
4318
4437
  }
4319
4438
  });
4320
4439
  return preNodes_1;
@@ -4661,7 +4780,7 @@ var Meta2d = /** @class */ (function () {
4661
4780
  });
4662
4781
  };
4663
4782
  Meta2d.prototype.setVisible = function (pen, visible, render) {
4664
- var e_18, _a;
4783
+ var e_21, _a;
4665
4784
  if (render === void 0) { render = true; }
4666
4785
  this.onSizeUpdate();
4667
4786
  this.setValue({ id: pen.id, visible: visible }, { render: false, doEvent: false });
@@ -4673,12 +4792,12 @@ var Meta2d = /** @class */ (function () {
4673
4792
  child && this.setVisible(child, visible, false);
4674
4793
  }
4675
4794
  }
4676
- catch (e_18_1) { e_18 = { error: e_18_1 }; }
4795
+ catch (e_21_1) { e_21 = { error: e_21_1 }; }
4677
4796
  finally {
4678
4797
  try {
4679
4798
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
4680
4799
  }
4681
- finally { if (e_18) throw e_18.error; }
4800
+ finally { if (e_21) throw e_21.error; }
4682
4801
  }
4683
4802
  }
4684
4803
  var allPens = getAllChildren(pen, this.store);