@meta2d/core 1.0.50 → 1.0.51

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);
@@ -798,7 +865,7 @@ var Meta2d = /** @class */ (function () {
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,14 @@ 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, res, data, fnJs, clients_1, mqttClient_1, websockets, websocket_1;
943
+ return __generator(this, function (_b) {
944
+ switch (_b.label) {
877
945
  case 0:
878
- network = deepClone(_network);
946
+ network = deepClone(e.network);
879
947
  if (network.data) {
880
948
  Object.assign(network, network.data);
881
949
  delete network.data;
@@ -883,7 +951,7 @@ var Meta2d = /** @class */ (function () {
883
951
  if (!network.url) {
884
952
  return [2 /*return*/];
885
953
  }
886
- if (!(network.protocol === 'http')) return [3 /*break*/, 2];
954
+ if (!(network.protocol === 'http')) return [3 /*break*/, 5];
887
955
  if (typeof network.headers === 'object') {
888
956
  for (i in network.headers) {
889
957
  keys = network.headers[i].match(/(?<=\$\{).*?(?=\})/g);
@@ -906,12 +974,31 @@ var Meta2d = /** @class */ (function () {
906
974
  body: network.method === 'POST' ? JSON.stringify(value) : undefined,
907
975
  })];
908
976
  case 1:
909
- res = _a.sent();
910
- if (res.ok) {
911
- console.info('http消息发送成功');
912
- }
913
- return [3 /*break*/, 3];
977
+ res = _b.sent();
978
+ if (!res.ok) return [3 /*break*/, 4];
979
+ if (!e.callback) return [3 /*break*/, 3];
980
+ return [4 /*yield*/, res.text()];
914
981
  case 2:
982
+ data = _b.sent();
983
+ if (!e.fn) {
984
+ try {
985
+ if (typeof e.callback !== 'string') {
986
+ throw new Error('[meta2d] Function callback must be string');
987
+ }
988
+ fnJs = e.callback;
989
+ e.fn = new Function('pen', 'data', 'context', fnJs);
990
+ }
991
+ catch (err) {
992
+ console.error('[meta2d]: Error on make a function:', err);
993
+ }
994
+ }
995
+ (_a = e.fn) === null || _a === void 0 ? void 0 : _a.call(e, pen, data, { meta2d: this, e: e });
996
+ _b.label = 3;
997
+ case 3:
998
+ console.info('http消息发送成功');
999
+ _b.label = 4;
1000
+ case 4: return [3 /*break*/, 6];
1001
+ case 5:
915
1002
  if (network.protocol === 'mqtt') {
916
1003
  clients_1 = this.mqttClients.filter(function (client) { return client.options.href === network.url; });
917
1004
  if (clients_1 && clients_1.length) {
@@ -950,8 +1037,8 @@ var Meta2d = /** @class */ (function () {
950
1037
  };
951
1038
  }
952
1039
  }
953
- _a.label = 3;
954
- case 3: return [2 /*return*/];
1040
+ _b.label = 6;
1041
+ case 6: return [2 /*return*/];
955
1042
  }
956
1043
  });
957
1044
  });
@@ -1076,7 +1163,7 @@ var Meta2d = /** @class */ (function () {
1076
1163
  this.store.patchFlagsTop = true;
1077
1164
  };
1078
1165
  Meta2d.prototype.open = function (data, render) {
1079
- var e_1, _a, e_2, _b, e_3, _c, e_4, _e;
1166
+ var e_3, _a, e_4, _b, e_5, _c, e_6, _e;
1080
1167
  var _this = this;
1081
1168
  if (render === void 0) { render = true; }
1082
1169
  this.clear(false, data === null || data === void 0 ? void 0 : data.template);
@@ -1096,12 +1183,12 @@ var Meta2d = /** @class */ (function () {
1096
1183
  this.store.pens[pen.id] = pen;
1097
1184
  }
1098
1185
  }
1099
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1186
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1100
1187
  finally {
1101
1188
  try {
1102
1189
  if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
1103
1190
  }
1104
- finally { if (e_1) throw e_1.error; }
1191
+ finally { if (e_3) throw e_3.error; }
1105
1192
  }
1106
1193
  try {
1107
1194
  for (var _h = __values(data.pens), _j = _h.next(); !_j.done; _j = _h.next()) {
@@ -1109,12 +1196,12 @@ var Meta2d = /** @class */ (function () {
1109
1196
  this.canvas.makePen(pen);
1110
1197
  }
1111
1198
  }
1112
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1199
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1113
1200
  finally {
1114
1201
  try {
1115
1202
  if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
1116
1203
  }
1117
- finally { if (e_2) throw e_2.error; }
1204
+ finally { if (e_4) throw e_4.error; }
1118
1205
  }
1119
1206
  try {
1120
1207
  for (var _k = __values(data.pens), _l = _k.next(); !_l.done; _l = _k.next()) {
@@ -1122,12 +1209,12 @@ var Meta2d = /** @class */ (function () {
1122
1209
  this.canvas.updateLines(pen);
1123
1210
  }
1124
1211
  }
1125
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
1212
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
1126
1213
  finally {
1127
1214
  try {
1128
1215
  if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
1129
1216
  }
1130
- finally { if (e_3) throw e_3.error; }
1217
+ finally { if (e_5) throw e_5.error; }
1131
1218
  }
1132
1219
  }
1133
1220
  this.canvas.patchFlagsLines.forEach(function (pen) {
@@ -1162,12 +1249,12 @@ var Meta2d = /** @class */ (function () {
1162
1249
  });
1163
1250
  }
1164
1251
  }
1165
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
1252
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
1166
1253
  finally {
1167
1254
  try {
1168
1255
  if (_o && !_o.done && (_e = _m.return)) _e.call(_m);
1169
1256
  }
1170
- finally { if (e_4) throw e_4.error; }
1257
+ finally { if (e_6) throw e_6.error; }
1171
1258
  }
1172
1259
  }
1173
1260
  this.canvas.autoPolylineFlag = false;
@@ -1408,7 +1495,7 @@ var Meta2d = /** @class */ (function () {
1408
1495
  * @param render 是否重绘
1409
1496
  */
1410
1497
  Meta2d.prototype.clear = function (render, template) {
1411
- var e_5, _a;
1498
+ var e_7, _a;
1412
1499
  var _b;
1413
1500
  if (render === void 0) { render = true; }
1414
1501
  try {
@@ -1417,12 +1504,12 @@ var Meta2d = /** @class */ (function () {
1417
1504
  (_b = pen.onDestroy) === null || _b === void 0 ? void 0 : _b.call(pen, pen);
1418
1505
  }
1419
1506
  }
1420
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
1507
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
1421
1508
  finally {
1422
1509
  try {
1423
1510
  if (_e && !_e.done && (_a = _c.return)) _a.call(_c);
1424
1511
  }
1425
- finally { if (e_5) throw e_5.error; }
1512
+ finally { if (e_7) throw e_7.error; }
1426
1513
  }
1427
1514
  clearStore(this.store, template);
1428
1515
  this.hideInput();
@@ -2579,7 +2666,7 @@ var Meta2d = /** @class */ (function () {
2579
2666
  return;
2580
2667
  }
2581
2668
  var penValue = penValues.get(pen);
2582
- if (typeof pen.onBinds === 'function') {
2669
+ if (!pen.noOnBinds && typeof pen.onBinds === 'function') {
2583
2670
  // 已经计算了
2584
2671
  if (penValue) {
2585
2672
  return;
@@ -2654,6 +2741,9 @@ var Meta2d = /** @class */ (function () {
2654
2741
  var _this = this;
2655
2742
  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
2743
  var pens = [];
2744
+ if (!data) {
2745
+ return;
2746
+ }
2657
2747
  if (data.id) {
2658
2748
  if (data.id === this.store.data.id) {
2659
2749
  this.setDatabyOptions(data);
@@ -3013,7 +3103,7 @@ var Meta2d = /** @class */ (function () {
3013
3103
  * @param padding 上右下左的内边距
3014
3104
  */
3015
3105
  Meta2d.prototype.downloadPng = function (name, padding, maxWidth) {
3016
- var e_6, _a;
3106
+ var e_8, _a;
3017
3107
  var _this = this;
3018
3108
  var _b;
3019
3109
  try {
@@ -3025,12 +3115,12 @@ var Meta2d = /** @class */ (function () {
3025
3115
  }
3026
3116
  }
3027
3117
  }
3028
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
3118
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
3029
3119
  finally {
3030
3120
  try {
3031
3121
  if (_e && !_e.done && (_a = _c.return)) _a.call(_c);
3032
3122
  }
3033
- finally { if (e_6) throw e_6.error; }
3123
+ finally { if (e_8) throw e_8.error; }
3034
3124
  }
3035
3125
  setTimeout(function () {
3036
3126
  var a = document.createElement('a');
@@ -3042,7 +3132,7 @@ var Meta2d = /** @class */ (function () {
3042
3132
  }, 1000);
3043
3133
  };
3044
3134
  Meta2d.prototype.downloadSvg = function () {
3045
- var e_7, _a;
3135
+ var e_9, _a;
3046
3136
  if (!window.C2S) {
3047
3137
  console.error('请先加载乐吾乐官网下的canvas2svg.js', 'https://assets.le5lecdn.com/2d/canvas2svg.js');
3048
3138
  throw new Error('请先加载乐吾乐官网下的canvas2svg.js');
@@ -3061,12 +3151,12 @@ var Meta2d = /** @class */ (function () {
3061
3151
  renderPenRaw(ctx, pen, rect, true);
3062
3152
  }
3063
3153
  }
3064
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
3154
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
3065
3155
  finally {
3066
3156
  try {
3067
3157
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3068
3158
  }
3069
- finally { if (e_7) throw e_7.error; }
3159
+ finally { if (e_9) throw e_9.error; }
3070
3160
  }
3071
3161
  var mySerializedSVG = ctx.getSerializedSvg();
3072
3162
  if (this.store.data.background) {
@@ -3525,7 +3615,7 @@ var Meta2d = /** @class */ (function () {
3525
3615
  });
3526
3616
  };
3527
3617
  Meta2d.prototype.alignNodes = function (align, pens, rect) {
3528
- var e_8, _a;
3618
+ var e_10, _a;
3529
3619
  if (pens === void 0) { pens = this.store.data.pens; }
3530
3620
  !rect && (rect = this.getPenRect(this.getRect(pens)));
3531
3621
  var initPens = deepClone(pens); // 原 pens ,深拷贝一下
@@ -3535,12 +3625,12 @@ var Meta2d = /** @class */ (function () {
3535
3625
  this.alignPen(align, item, rect);
3536
3626
  }
3537
3627
  }
3538
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
3628
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
3539
3629
  finally {
3540
3630
  try {
3541
3631
  if (pens_1_1 && !pens_1_1.done && (_a = pens_1.return)) _a.call(pens_1);
3542
3632
  }
3543
- finally { if (e_8) throw e_8.error; }
3633
+ finally { if (e_10) throw e_10.error; }
3544
3634
  }
3545
3635
  this.initImageCanvas(pens);
3546
3636
  this.initTemplateCanvas(pens);
@@ -3553,7 +3643,7 @@ var Meta2d = /** @class */ (function () {
3553
3643
  };
3554
3644
  //对齐大屏
3555
3645
  Meta2d.prototype.alignNodesV = function (align, pens) {
3556
- var e_9, _a;
3646
+ var e_11, _a;
3557
3647
  if (pens === void 0) { pens = this.store.data.pens; }
3558
3648
  var width = this.store.data.width || this.store.options.width;
3559
3649
  var height = this.store.data.height || this.store.options.height;
@@ -3570,12 +3660,12 @@ var Meta2d = /** @class */ (function () {
3570
3660
  this.alignPen(align, item, rect);
3571
3661
  }
3572
3662
  }
3573
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
3663
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
3574
3664
  finally {
3575
3665
  try {
3576
3666
  if (pens_2_1 && !pens_2_1.done && (_a = pens_2.return)) _a.call(pens_2);
3577
3667
  }
3578
- finally { if (e_9) throw e_9.error; }
3668
+ finally { if (e_11) throw e_11.error; }
3579
3669
  }
3580
3670
  this.initImageCanvas(pens);
3581
3671
  this.initTemplateCanvas(pens);
@@ -3670,7 +3760,7 @@ var Meta2d = /** @class */ (function () {
3670
3760
  * @param distance 总的宽 or 高
3671
3761
  */
3672
3762
  Meta2d.prototype.spaceBetweenByDirection = function (direction, pens, distance) {
3673
- var e_10, _a;
3763
+ var e_12, _a;
3674
3764
  var _this = this;
3675
3765
  if (pens === void 0) { pens = this.store.data.pens; }
3676
3766
  !distance && (distance = this.getPenRect(this.getRect(pens))[direction]);
@@ -3704,12 +3794,12 @@ var Meta2d = /** @class */ (function () {
3704
3794
  this.setValue(__assign({ id: pen.id }, penRect), { render: false, doEvent: false });
3705
3795
  }
3706
3796
  }
3707
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
3797
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
3708
3798
  finally {
3709
3799
  try {
3710
3800
  if (pens_3_1 && !pens_3_1.done && (_a = pens_3.return)) _a.call(pens_3);
3711
3801
  }
3712
- finally { if (e_10) throw e_10.error; }
3802
+ finally { if (e_12) throw e_12.error; }
3713
3803
  }
3714
3804
  this.initImageCanvas(pens);
3715
3805
  this.initTemplateCanvas(pens);
@@ -3773,6 +3863,7 @@ var Meta2d = /** @class */ (function () {
3773
3863
  });
3774
3864
  };
3775
3865
  Meta2d.prototype.gotoView = function (pen) {
3866
+ var e_13, _a;
3776
3867
  var center = this.getViewCenter();
3777
3868
  var x = center.x -
3778
3869
  pen.calculative.worldRect.x -
@@ -3785,6 +3876,19 @@ var Meta2d = /** @class */ (function () {
3785
3876
  }
3786
3877
  this.store.data.x = x;
3787
3878
  this.store.data.y = y;
3879
+ try {
3880
+ for (var _b = __values(this.store.data.pens), _c = _b.next(); !_c.done; _c = _b.next()) {
3881
+ var pen_1 = _c.value;
3882
+ calcInView(pen_1);
3883
+ }
3884
+ }
3885
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
3886
+ finally {
3887
+ try {
3888
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3889
+ }
3890
+ finally { if (e_13) throw e_13.error; }
3891
+ }
3788
3892
  this.canvas.canvasImage.init();
3789
3893
  this.canvas.canvasImageBottom.init();
3790
3894
  this.render();
@@ -3830,7 +3934,7 @@ var Meta2d = /** @class */ (function () {
3830
3934
  * @param pens pen 置顶的画笔
3831
3935
  */
3832
3936
  Meta2d.prototype.top = function (pens) {
3833
- var e_11, _a;
3937
+ var e_14, _a;
3834
3938
  var _this = this;
3835
3939
  if (!pens)
3836
3940
  pens = this.store.active;
@@ -3859,12 +3963,12 @@ var Meta2d = /** @class */ (function () {
3859
3963
  _loop_3(pen);
3860
3964
  }
3861
3965
  }
3862
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
3966
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
3863
3967
  finally {
3864
3968
  try {
3865
3969
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3866
3970
  }
3867
- finally { if (e_11) throw e_11.error; }
3971
+ finally { if (e_14) throw e_14.error; }
3868
3972
  }
3869
3973
  this.store.emitter.emit('layer', { type: 'top', pens: pens });
3870
3974
  };
@@ -3888,7 +3992,7 @@ var Meta2d = /** @class */ (function () {
3888
3992
  * @param pens 画笔们,注意 pen 必须在该数组内才有效
3889
3993
  */
3890
3994
  Meta2d.prototype.bottom = function (pens) {
3891
- var e_12, _a;
3995
+ var e_15, _a;
3892
3996
  if (!pens)
3893
3997
  pens = this.store.active;
3894
3998
  if (!Array.isArray(pens))
@@ -3898,15 +4002,15 @@ var Meta2d = /** @class */ (function () {
3898
4002
  var allIds = __spreadArray(__spreadArray([], __read(getAllChildren(pen, this_2.store)), false), [pen], false).map(function (p) { return p.id; });
3899
4003
  var allPens = _pens.filter(function (p) { return allIds.includes(p.id); });
3900
4004
  var _loop_5 = function (i) {
3901
- var pen_1 = allPens[i];
3902
- var index = _pens.findIndex(function (p) { return p.id === pen_1.id; });
4005
+ var pen_2 = allPens[i];
4006
+ var index = _pens.findIndex(function (p) { return p.id === pen_2.id; });
3903
4007
  if (index > -1) {
3904
4008
  _pens.unshift(_pens[index]);
3905
4009
  _pens.splice(index + 1, 1);
3906
- this_2.initTemplateCanvas([pen_1]);
3907
- this_2.initImageCanvas([pen_1]);
4010
+ this_2.initTemplateCanvas([pen_2]);
4011
+ this_2.initImageCanvas([pen_2]);
3908
4012
  }
3909
- this_2.specificLayerMove(pen_1, 'bottom');
4013
+ this_2.specificLayerMove(pen_2, 'bottom');
3910
4014
  };
3911
4015
  // 从后往前,保证 allPens 顺序不变
3912
4016
  for (var i = allPens.length - 1; i >= 0; i--) {
@@ -3920,12 +4024,12 @@ var Meta2d = /** @class */ (function () {
3920
4024
  _loop_4(pen);
3921
4025
  }
3922
4026
  }
3923
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
4027
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
3924
4028
  finally {
3925
4029
  try {
3926
4030
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3927
4031
  }
3928
- finally { if (e_12) throw e_12.error; }
4032
+ finally { if (e_15) throw e_15.error; }
3929
4033
  }
3930
4034
  this.store.emitter.emit('layer', { type: 'bottom', pens: pens });
3931
4035
  };
@@ -3935,7 +4039,7 @@ var Meta2d = /** @class */ (function () {
3935
4039
  * @param pen 画笔
3936
4040
  */
3937
4041
  Meta2d.prototype.upByArea = function (pen) {
3938
- var _a, e_13, _b;
4042
+ var _a, e_16, _b;
3939
4043
  var _this = this;
3940
4044
  var index = this.store.data.pens.findIndex(function (p) { return p.id === pen.id; });
3941
4045
  if (index === -1) {
@@ -3971,8 +4075,8 @@ var Meta2d = /** @class */ (function () {
3971
4075
  return;
3972
4076
  }
3973
4077
  (_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; });
4078
+ var _loop_6 = function (pen_3) {
4079
+ var index_1 = this_3.store.data.pens.findIndex(function (p) { return p.id === pen_3.id; });
3976
4080
  if (index_1 > -1) {
3977
4081
  this_3.store.data.pens.splice(index_1, 1);
3978
4082
  }
@@ -3981,16 +4085,16 @@ var Meta2d = /** @class */ (function () {
3981
4085
  try {
3982
4086
  // 删除靠前的 allPens
3983
4087
  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);
4088
+ var pen_3 = allPens_1_1.value;
4089
+ _loop_6(pen_3);
3986
4090
  }
3987
4091
  }
3988
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
4092
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
3989
4093
  finally {
3990
4094
  try {
3991
4095
  if (allPens_1_1 && !allPens_1_1.done && (_b = allPens_1.return)) _b.call(allPens_1);
3992
4096
  }
3993
- finally { if (e_13) throw e_13.error; }
4097
+ finally { if (e_16) throw e_16.error; }
3994
4098
  }
3995
4099
  this.initImageCanvas([pen]);
3996
4100
  };
@@ -4044,7 +4148,7 @@ var Meta2d = /** @class */ (function () {
4044
4148
  * @param pens 画笔
4045
4149
  */
4046
4150
  Meta2d.prototype.up = function (pens) {
4047
- var e_14, _a;
4151
+ var e_17, _a;
4048
4152
  var _this = this;
4049
4153
  if (!pens)
4050
4154
  pens = this.store.active;
@@ -4099,12 +4203,12 @@ var Meta2d = /** @class */ (function () {
4099
4203
  _loop_7(pen);
4100
4204
  }
4101
4205
  }
4102
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
4206
+ catch (e_17_1) { e_17 = { error: e_17_1 }; }
4103
4207
  finally {
4104
4208
  try {
4105
4209
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
4106
4210
  }
4107
- finally { if (e_14) throw e_14.error; }
4211
+ finally { if (e_17) throw e_17.error; }
4108
4212
  }
4109
4213
  this.store.emitter.emit('layer', { type: 'up', pens: pens });
4110
4214
  };
@@ -4113,7 +4217,7 @@ var Meta2d = /** @class */ (function () {
4113
4217
  * @param pen 画笔
4114
4218
  */
4115
4219
  Meta2d.prototype.down = function (pens) {
4116
- var e_15, _a;
4220
+ var e_18, _a;
4117
4221
  var _this = this;
4118
4222
  if (!pens)
4119
4223
  pens = this.store.active;
@@ -4170,12 +4274,12 @@ var Meta2d = /** @class */ (function () {
4170
4274
  _loop_9(pen);
4171
4275
  }
4172
4276
  }
4173
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
4277
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
4174
4278
  finally {
4175
4279
  try {
4176
4280
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
4177
4281
  }
4178
- finally { if (e_15) throw e_15.error; }
4282
+ finally { if (e_18) throw e_18.error; }
4179
4283
  }
4180
4284
  this.store.emitter.emit('layer', { type: 'down', pens: pens });
4181
4285
  };
@@ -4255,7 +4359,7 @@ var Meta2d = /** @class */ (function () {
4255
4359
  var nextNodes_1 = [];
4256
4360
  // 2. 遍历出线的 nextNode
4257
4361
  lines.forEach(function (line) {
4258
- var e_16, _a;
4362
+ var e_19, _a;
4259
4363
  var lineNextNode = _this.nextNode(line);
4260
4364
  var _loop_11 = function (node) {
4261
4365
  var have = nextNodes_1.find(function (next) { return next.id === node.id; });
@@ -4268,12 +4372,12 @@ var Meta2d = /** @class */ (function () {
4268
4372
  _loop_11(node);
4269
4373
  }
4270
4374
  }
4271
- catch (e_16_1) { e_16 = { error: e_16_1 }; }
4375
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
4272
4376
  finally {
4273
4377
  try {
4274
4378
  if (lineNextNode_1_1 && !lineNextNode_1_1.done && (_a = lineNextNode_1.return)) _a.call(lineNextNode_1);
4275
4379
  }
4276
- finally { if (e_16) throw e_16.error; }
4380
+ finally { if (e_19) throw e_19.error; }
4277
4381
  }
4278
4382
  });
4279
4383
  return nextNodes_1;
@@ -4296,7 +4400,7 @@ var Meta2d = /** @class */ (function () {
4296
4400
  var preNodes_1 = [];
4297
4401
  // 2. 遍历入线的 preNode
4298
4402
  lines.forEach(function (line) {
4299
- var e_17, _a;
4403
+ var e_20, _a;
4300
4404
  var linePreNode = _this.previousNode(line);
4301
4405
  var _loop_12 = function (node) {
4302
4406
  var have = preNodes_1.find(function (pre) { return pre.id === node.id; });
@@ -4309,12 +4413,12 @@ var Meta2d = /** @class */ (function () {
4309
4413
  _loop_12(node);
4310
4414
  }
4311
4415
  }
4312
- catch (e_17_1) { e_17 = { error: e_17_1 }; }
4416
+ catch (e_20_1) { e_20 = { error: e_20_1 }; }
4313
4417
  finally {
4314
4418
  try {
4315
4419
  if (linePreNode_1_1 && !linePreNode_1_1.done && (_a = linePreNode_1.return)) _a.call(linePreNode_1);
4316
4420
  }
4317
- finally { if (e_17) throw e_17.error; }
4421
+ finally { if (e_20) throw e_20.error; }
4318
4422
  }
4319
4423
  });
4320
4424
  return preNodes_1;
@@ -4661,7 +4765,7 @@ var Meta2d = /** @class */ (function () {
4661
4765
  });
4662
4766
  };
4663
4767
  Meta2d.prototype.setVisible = function (pen, visible, render) {
4664
- var e_18, _a;
4768
+ var e_21, _a;
4665
4769
  if (render === void 0) { render = true; }
4666
4770
  this.onSizeUpdate();
4667
4771
  this.setValue({ id: pen.id, visible: visible }, { render: false, doEvent: false });
@@ -4673,12 +4777,12 @@ var Meta2d = /** @class */ (function () {
4673
4777
  child && this.setVisible(child, visible, false);
4674
4778
  }
4675
4779
  }
4676
- catch (e_18_1) { e_18 = { error: e_18_1 }; }
4780
+ catch (e_21_1) { e_21 = { error: e_21_1 }; }
4677
4781
  finally {
4678
4782
  try {
4679
4783
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
4680
4784
  }
4681
- finally { if (e_18) throw e_18.error; }
4785
+ finally { if (e_21) throw e_21.error; }
4682
4786
  }
4683
4787
  }
4684
4788
  var allPens = getAllChildren(pen, this.store);