@meta2d/core 1.0.49 → 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,10 +409,103 @@ 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);
400
467
  };
468
+ this.doDataEvent = function (datas) {
469
+ var _a, _b, _c;
470
+ if (!((_a = _this.store.data.dataEvents) === null || _a === void 0 ? void 0 : _a.length)) {
471
+ return;
472
+ }
473
+ var data = datas.reduce(function (accumulator, _a) {
474
+ var dataId = _a.dataId, id = _a.id, value = _a.value;
475
+ accumulator[id || dataId] = value;
476
+ return accumulator;
477
+ }, {});
478
+ var indexArr = [];
479
+ (_b = _this.store.data.dataEvents) === null || _b === void 0 ? void 0 : _b.forEach(function (event, index) {
480
+ var flag = false;
481
+ if (event.conditions && event.conditions.length) {
482
+ if (event.conditionType === 'and') {
483
+ flag = event.conditions.every(function (condition) {
484
+ return _this.dataJudegeCondition(data, condition.key, condition);
485
+ });
486
+ }
487
+ else if (event.conditionType === 'or') {
488
+ flag = event.conditions.some(function (condition) {
489
+ return _this.dataJudegeCondition(data, condition.key, condition);
490
+ });
491
+ }
492
+ }
493
+ else {
494
+ flag = true;
495
+ }
496
+ if (flag) {
497
+ indexArr.push(index);
498
+ }
499
+ });
500
+ (_c = _this.store.data.dataEvents) === null || _c === void 0 ? void 0 : _c.forEach(function (event, index) {
501
+ var _a;
502
+ if (indexArr.includes(index)) {
503
+ (_a = event.actions) === null || _a === void 0 ? void 0 : _a.forEach(function (action) {
504
+ _this.events[action.action](data, action);
505
+ });
506
+ }
507
+ });
508
+ };
401
509
  this.renderPenRaw = renderPenRaw;
402
510
  this.setElemPosition = setElemPosition;
403
511
  this.setLifeCycleFunc = setLifeCycleFunc;
@@ -757,7 +865,7 @@ var Meta2d = /** @class */ (function () {
757
865
  if (_pen.deviceId) {
758
866
  value.deviceId = _pen.deviceId;
759
867
  }
760
- _this.sendDataToNetWork(value, e.network);
868
+ _this.sendDataToNetWork(value, pen, e);
761
869
  return;
762
870
  }
763
871
  }
@@ -828,13 +936,14 @@ var Meta2d = /** @class */ (function () {
828
936
  }
829
937
  this.store.emitter.emit('sendData', data);
830
938
  };
831
- Meta2d.prototype.sendDataToNetWork = function (value, _network) {
939
+ Meta2d.prototype.sendDataToNetWork = function (value, pen, e) {
940
+ var _a;
832
941
  return __awaiter(this, void 0, void 0, function () {
833
- var network, i, keys, params, res, clients_1, mqttClient_1, websockets, websocket_1;
834
- return __generator(this, function (_a) {
835
- 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) {
836
945
  case 0:
837
- network = deepClone(_network);
946
+ network = deepClone(e.network);
838
947
  if (network.data) {
839
948
  Object.assign(network, network.data);
840
949
  delete network.data;
@@ -842,7 +951,7 @@ var Meta2d = /** @class */ (function () {
842
951
  if (!network.url) {
843
952
  return [2 /*return*/];
844
953
  }
845
- if (!(network.protocol === 'http')) return [3 /*break*/, 2];
954
+ if (!(network.protocol === 'http')) return [3 /*break*/, 5];
846
955
  if (typeof network.headers === 'object') {
847
956
  for (i in network.headers) {
848
957
  keys = network.headers[i].match(/(?<=\$\{).*?(?=\})/g);
@@ -865,12 +974,31 @@ var Meta2d = /** @class */ (function () {
865
974
  body: network.method === 'POST' ? JSON.stringify(value) : undefined,
866
975
  })];
867
976
  case 1:
868
- res = _a.sent();
869
- if (res.ok) {
870
- console.info('http消息发送成功');
871
- }
872
- 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()];
873
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:
874
1002
  if (network.protocol === 'mqtt') {
875
1003
  clients_1 = this.mqttClients.filter(function (client) { return client.options.href === network.url; });
876
1004
  if (clients_1 && clients_1.length) {
@@ -909,8 +1037,8 @@ var Meta2d = /** @class */ (function () {
909
1037
  };
910
1038
  }
911
1039
  }
912
- _a.label = 3;
913
- case 3: return [2 /*return*/];
1040
+ _b.label = 6;
1041
+ case 6: return [2 /*return*/];
914
1042
  }
915
1043
  });
916
1044
  });
@@ -1035,7 +1163,7 @@ var Meta2d = /** @class */ (function () {
1035
1163
  this.store.patchFlagsTop = true;
1036
1164
  };
1037
1165
  Meta2d.prototype.open = function (data, render) {
1038
- 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;
1039
1167
  var _this = this;
1040
1168
  if (render === void 0) { render = true; }
1041
1169
  this.clear(false, data === null || data === void 0 ? void 0 : data.template);
@@ -1055,12 +1183,12 @@ var Meta2d = /** @class */ (function () {
1055
1183
  this.store.pens[pen.id] = pen;
1056
1184
  }
1057
1185
  }
1058
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1186
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1059
1187
  finally {
1060
1188
  try {
1061
1189
  if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
1062
1190
  }
1063
- finally { if (e_1) throw e_1.error; }
1191
+ finally { if (e_3) throw e_3.error; }
1064
1192
  }
1065
1193
  try {
1066
1194
  for (var _h = __values(data.pens), _j = _h.next(); !_j.done; _j = _h.next()) {
@@ -1068,12 +1196,12 @@ var Meta2d = /** @class */ (function () {
1068
1196
  this.canvas.makePen(pen);
1069
1197
  }
1070
1198
  }
1071
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1199
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1072
1200
  finally {
1073
1201
  try {
1074
1202
  if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
1075
1203
  }
1076
- finally { if (e_2) throw e_2.error; }
1204
+ finally { if (e_4) throw e_4.error; }
1077
1205
  }
1078
1206
  try {
1079
1207
  for (var _k = __values(data.pens), _l = _k.next(); !_l.done; _l = _k.next()) {
@@ -1081,12 +1209,12 @@ var Meta2d = /** @class */ (function () {
1081
1209
  this.canvas.updateLines(pen);
1082
1210
  }
1083
1211
  }
1084
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
1212
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
1085
1213
  finally {
1086
1214
  try {
1087
1215
  if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
1088
1216
  }
1089
- finally { if (e_3) throw e_3.error; }
1217
+ finally { if (e_5) throw e_5.error; }
1090
1218
  }
1091
1219
  }
1092
1220
  this.canvas.patchFlagsLines.forEach(function (pen) {
@@ -1108,6 +1236,7 @@ var Meta2d = /** @class */ (function () {
1108
1236
  this.listenSocket();
1109
1237
  this.connectSocket();
1110
1238
  this.connectNetwork();
1239
+ this.startDataMock();
1111
1240
  this.startAnimate();
1112
1241
  this.startVideo();
1113
1242
  this.doInitJS();
@@ -1120,12 +1249,12 @@ var Meta2d = /** @class */ (function () {
1120
1249
  });
1121
1250
  }
1122
1251
  }
1123
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
1252
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
1124
1253
  finally {
1125
1254
  try {
1126
1255
  if (_o && !_o.done && (_e = _m.return)) _e.call(_m);
1127
1256
  }
1128
- finally { if (e_4) throw e_4.error; }
1257
+ finally { if (e_6) throw e_6.error; }
1129
1258
  }
1130
1259
  }
1131
1260
  this.canvas.autoPolylineFlag = false;
@@ -1366,7 +1495,7 @@ var Meta2d = /** @class */ (function () {
1366
1495
  * @param render 是否重绘
1367
1496
  */
1368
1497
  Meta2d.prototype.clear = function (render, template) {
1369
- var e_5, _a;
1498
+ var e_7, _a;
1370
1499
  var _b;
1371
1500
  if (render === void 0) { render = true; }
1372
1501
  try {
@@ -1375,12 +1504,12 @@ var Meta2d = /** @class */ (function () {
1375
1504
  (_b = pen.onDestroy) === null || _b === void 0 ? void 0 : _b.call(pen, pen);
1376
1505
  }
1377
1506
  }
1378
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
1507
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
1379
1508
  finally {
1380
1509
  try {
1381
1510
  if (_e && !_e.done && (_a = _c.return)) _a.call(_c);
1382
1511
  }
1383
- finally { if (e_5) throw e_5.error; }
1512
+ finally { if (e_7) throw e_7.error; }
1384
1513
  }
1385
1514
  clearStore(this.store, template);
1386
1515
  this.hideInput();
@@ -2155,124 +2284,172 @@ var Meta2d = /** @class */ (function () {
2155
2284
  }
2156
2285
  return n;
2157
2286
  };
2158
- Meta2d.prototype.penMock = function (pen) {
2159
- var _this = this;
2160
- var _a;
2161
- if (pen.realTimes) {
2162
- var _d_1 = {};
2163
- pen.realTimes.forEach(function (realTime) {
2164
- if (realTime.enableMock && realTime.mock !== undefined) {
2165
- if (realTime.type === 'float') {
2166
- if (realTime.mock && realTime.mock.indexOf(',') !== -1) {
2167
- var arr = realTime.mock.split(',');
2168
- var rai = Math.floor(Math.random() * arr.length);
2169
- _d_1[realTime.key] = parseFloat(arr[rai]);
2170
- }
2171
- else if (realTime.mock && realTime.mock.indexOf('-') !== -1) {
2172
- var max = void 0;
2173
- var min = void 0;
2174
- var len = void 0;
2175
- var arr = realTime.mock.split('-');
2176
- if (realTime.mock.charAt(0) === '-') {
2177
- //负数
2178
- if (arr.length === 4) {
2179
- max = -parseFloat(arr[3]);
2180
- min = -parseFloat(arr[1]);
2181
- len = arr[3];
2182
- }
2183
- else {
2184
- max = parseFloat(arr[2]);
2185
- min = -parseFloat(arr[1]);
2186
- len = arr[2];
2187
- }
2188
- }
2189
- else {
2190
- max = parseFloat(arr[1]);
2191
- min = parseFloat(arr[0]);
2192
- len = arr[1];
2193
- }
2194
- if ((len + '').indexOf('.') !== -1) {
2195
- var length_1 = (len + '').split('.')[1].length;
2196
- _d_1[realTime.key] = (Math.random() * (max - min) + min).toFixed(length_1);
2197
- }
2198
- else {
2199
- _d_1[realTime.key] = Math.random() * (max - min) + min;
2200
- }
2201
- }
2202
- else {
2203
- _d_1[realTime.key] = parseFloat(realTime.mock);
2204
- }
2205
- }
2206
- else if (realTime.type === 'integer') {
2207
- if (realTime.mock && realTime.mock.indexOf(',') !== -1) {
2208
- var arr = realTime.mock.split(',');
2209
- var rai = Math.floor(Math.random() * arr.length);
2210
- _d_1[realTime.key] = parseInt(arr[rai]);
2211
- }
2212
- else if (realTime.mock && realTime.mock.indexOf('-') !== -1) {
2213
- var max = void 0;
2214
- var min = void 0;
2215
- var arr = realTime.mock.split('-');
2216
- if (realTime.mock.charAt(0) === '-') {
2217
- if (arr.length === 4) {
2218
- max = -parseFloat(arr[3]);
2219
- min = -parseFloat(arr[1]);
2220
- }
2221
- else {
2222
- max = parseFloat(arr[2]);
2223
- min = -parseFloat(arr[1]);
2224
- }
2225
- }
2226
- else {
2227
- max = parseInt(arr[1]);
2228
- min = parseInt(arr[0]);
2229
- }
2230
- _d_1[realTime.key] = parseInt(Math.random() * (max - min) + min + '');
2287
+ Meta2d.prototype.mockValue = function (data) {
2288
+ var value = undefined;
2289
+ if (data.enableMock && data.mock !== undefined) {
2290
+ if (data.type === 'float') {
2291
+ if (data.mock && data.mock.indexOf(',') !== -1) {
2292
+ var arr = data.mock.split(',');
2293
+ var rai = Math.floor(Math.random() * arr.length);
2294
+ value = parseFloat(arr[rai]);
2295
+ }
2296
+ else if (data.mock && data.mock.indexOf('-') !== -1) {
2297
+ var max = void 0;
2298
+ var min = void 0;
2299
+ var len = void 0;
2300
+ var arr = data.mock.split('-');
2301
+ if (data.mock.charAt(0) === '-') {
2302
+ //负数
2303
+ if (arr.length === 4) {
2304
+ max = -parseFloat(arr[3]);
2305
+ min = -parseFloat(arr[1]);
2306
+ len = arr[3];
2231
2307
  }
2232
2308
  else {
2233
- _d_1[realTime.key] = parseInt(realTime.mock);
2309
+ max = parseFloat(arr[2]);
2310
+ min = -parseFloat(arr[1]);
2311
+ len = arr[2];
2234
2312
  }
2235
2313
  }
2236
- else if (realTime.type === 'bool') {
2237
- if (typeof realTime.mock === 'boolean') {
2238
- _d_1[realTime.key] = realTime.mock;
2239
- }
2240
- else if ('true' === realTime.mock) {
2241
- _d_1[realTime.key] = true;
2242
- }
2243
- else if ('false' === realTime.mock) {
2244
- _d_1[realTime.key] = false;
2245
- }
2246
- else {
2247
- _d_1[realTime.key] = Math.random() < 0.5;
2248
- }
2314
+ else {
2315
+ max = parseFloat(arr[1]);
2316
+ min = parseFloat(arr[0]);
2317
+ len = arr[1];
2249
2318
  }
2250
- else if (realTime.type === 'object' || realTime.type === 'array') {
2251
- if (realTime.mock) {
2252
- //对象or数组 不mock
2253
- // _d[realTime.key] = realTime.value;
2254
- }
2319
+ if ((len + '').indexOf('.') !== -1) {
2320
+ var length_1 = (len + '').split('.')[1].length;
2321
+ value = (Math.random() * (max - min) + min).toFixed(length_1);
2255
2322
  }
2256
2323
  else {
2257
- //if (realTime.type === 'string')
2258
- if (realTime.mock &&
2259
- realTime.mock.startsWith('{') &&
2260
- realTime.mock.endsWith('}')) {
2261
- var str = realTime.mock.substring(1, realTime.mock.length - 1);
2262
- var arr = str.split(',');
2263
- var rai = Math.floor(Math.random() * arr.length);
2264
- _d_1[realTime.key] = arr[rai];
2265
- }
2266
- else if (realTime.mock &&
2267
- realTime.mock.startsWith('[') &&
2268
- realTime.mock.endsWith(']')) {
2269
- var len = parseInt(realTime.mock.substring(1, realTime.mock.length - 1));
2270
- _d_1[realTime.key] = _this.randomString(len);
2324
+ value = Math.random() * (max - min) + min;
2325
+ }
2326
+ }
2327
+ else {
2328
+ value = parseFloat(data.mock);
2329
+ }
2330
+ }
2331
+ else if (data.type === 'integer') {
2332
+ if (data.mock && data.mock.indexOf(',') !== -1) {
2333
+ var arr = data.mock.split(',');
2334
+ var rai = Math.floor(Math.random() * arr.length);
2335
+ value = parseInt(arr[rai]);
2336
+ }
2337
+ else if (data.mock && data.mock.indexOf('-') !== -1) {
2338
+ var max = void 0;
2339
+ var min = void 0;
2340
+ var arr = data.mock.split('-');
2341
+ if (data.mock.charAt(0) === '-') {
2342
+ if (arr.length === 4) {
2343
+ max = -parseFloat(arr[3]);
2344
+ min = -parseFloat(arr[1]);
2271
2345
  }
2272
2346
  else {
2273
- _d_1[realTime.key] = realTime.mock;
2347
+ max = parseFloat(arr[2]);
2348
+ min = -parseFloat(arr[1]);
2274
2349
  }
2275
2350
  }
2351
+ else {
2352
+ max = parseInt(arr[1]);
2353
+ min = parseInt(arr[0]);
2354
+ }
2355
+ value = parseInt(Math.random() * (max - min) + min + '');
2356
+ }
2357
+ else {
2358
+ value = parseInt(data.mock);
2359
+ }
2360
+ }
2361
+ else if (data.type === 'bool') {
2362
+ if (typeof data.mock === 'boolean') {
2363
+ value = data.mock;
2364
+ }
2365
+ else if ('true' === data.mock) {
2366
+ value = true;
2367
+ }
2368
+ else if ('false' === data.mock) {
2369
+ value = false;
2370
+ }
2371
+ else {
2372
+ value = Math.random() < 0.5;
2373
+ }
2374
+ }
2375
+ else if (data.type === 'object' || data.type === 'array') {
2376
+ if (data.mock) {
2377
+ //对象or数组 不mock
2378
+ // _d[realTime.key] = realTime.value;
2379
+ }
2380
+ }
2381
+ else {
2382
+ //if (realTime.type === 'string')
2383
+ if (data.mock && data.mock.indexOf(',') !== -1) {
2384
+ var str = data.mock.substring(1, data.mock.length - 1);
2385
+ var arr = str.split(',');
2386
+ var rai = Math.floor(Math.random() * arr.length);
2387
+ value = arr[rai];
2388
+ }
2389
+ else if (data.mock &&
2390
+ data.mock.startsWith('[') &&
2391
+ data.mock.endsWith(']')) {
2392
+ var len = parseInt(data.mock.substring(1, data.mock.length - 1));
2393
+ value = this.randomString(len);
2394
+ }
2395
+ else {
2396
+ value = data.mock;
2397
+ }
2398
+ }
2399
+ }
2400
+ return value;
2401
+ };
2402
+ //数据模拟
2403
+ Meta2d.prototype.dataMock = function () {
2404
+ var _this = this;
2405
+ var _a, _b;
2406
+ var arr = [];
2407
+ (_b = (_a = this.store.data.dataset) === null || _a === void 0 ? void 0 : _a.devices) === null || _b === void 0 ? void 0 : _b.forEach(function (data) {
2408
+ var value = _this.mockValue(data);
2409
+ if (value !== undefined) {
2410
+ arr.push({
2411
+ id: data.id,
2412
+ value: value
2413
+ });
2414
+ }
2415
+ });
2416
+ if (arr.length) {
2417
+ this.setDatas(arr, {
2418
+ render: true,
2419
+ doEvent: true,
2420
+ history: false,
2421
+ });
2422
+ }
2423
+ };
2424
+ Meta2d.prototype.startDataMock = function () {
2425
+ var _this = this;
2426
+ var enable = this.store.data.enableMock;
2427
+ if (enable) {
2428
+ this.stopDataMock();
2429
+ this.initBinds();
2430
+ this.updateTimer = setInterval(function () {
2431
+ //本地调试
2432
+ _this.store.data.pens.forEach(function (pen) {
2433
+ _this.penMock(pen);
2434
+ });
2435
+ _this.dataMock();
2436
+ _this.render();
2437
+ }, this.store.data.networkInterval || 1000);
2438
+ }
2439
+ };
2440
+ Meta2d.prototype.stopDataMock = function () {
2441
+ clearInterval(this.updateTimer);
2442
+ this.updateTimer = undefined;
2443
+ };
2444
+ Meta2d.prototype.penMock = function (pen) {
2445
+ var _this = this;
2446
+ var _a;
2447
+ if (pen.realTimes) {
2448
+ var _d_1 = {};
2449
+ pen.realTimes.forEach(function (realTime) {
2450
+ var value = _this.mockValue(realTime);
2451
+ if (value !== undefined) {
2452
+ _d_1[realTime.key] = value;
2276
2453
  }
2277
2454
  });
2278
2455
  if (Object.keys(_d_1).length) {
@@ -2320,8 +2497,8 @@ var Meta2d = /** @class */ (function () {
2320
2497
  };
2321
2498
  Meta2d.prototype.onNetworkConnect = function (https) {
2322
2499
  var _this = this;
2323
- var enable = this.store.data.enableMock;
2324
- if (!(https && https.length) && !enable) {
2500
+ // let enable = this.store.data.enableMock;
2501
+ if (!(https && https.length)) {
2325
2502
  return;
2326
2503
  }
2327
2504
  if (this.store.pensNetwork) {
@@ -2337,18 +2514,18 @@ var Meta2d = /** @class */ (function () {
2337
2514
  });
2338
2515
  }); });
2339
2516
  }
2340
- if (enable) {
2341
- this.updateTimer = setInterval(function () {
2342
- //模拟数据
2343
- _this.store.data.pens.forEach(function (pen) {
2344
- _this.penMock(pen);
2345
- });
2346
- // https.forEach(async (_item) => {
2347
- // this.requestHttp(_item);
2348
- // });
2349
- _this.render();
2350
- }, this.store.data.networkInterval || 1000);
2351
- }
2517
+ // if( enable ){
2518
+ // this.updateTimer = setInterval(() => {
2519
+ // //模拟数据
2520
+ // this.store.data.pens.forEach((pen) => {
2521
+ // this.penMock(pen);
2522
+ // });
2523
+ // // https.forEach(async (_item) => {
2524
+ // // this.requestHttp(_item);
2525
+ // // });
2526
+ // this.render();
2527
+ // }, this.store.data.networkInterval || 1000);
2528
+ // }
2352
2529
  https.forEach(function (_item, index) {
2353
2530
  _this.updateTimerList[index] = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
2354
2531
  return __generator(this, function (_a) {
@@ -2415,8 +2592,8 @@ var Meta2d = /** @class */ (function () {
2415
2592
  });
2416
2593
  this.mqttClients = undefined;
2417
2594
  this.websockets = undefined;
2418
- clearInterval(this.updateTimer);
2419
- this.updateTimer = undefined;
2595
+ // clearInterval(this.updateTimer);
2596
+ // this.updateTimer = undefined;
2420
2597
  this.updateTimerList &&
2421
2598
  this.updateTimerList.forEach(function (_updateTimer) {
2422
2599
  clearInterval(_updateTimer);
@@ -2489,7 +2666,7 @@ var Meta2d = /** @class */ (function () {
2489
2666
  return;
2490
2667
  }
2491
2668
  var penValue = penValues.get(pen);
2492
- if (typeof pen.onBinds === 'function') {
2669
+ if (!pen.noOnBinds && typeof pen.onBinds === 'function') {
2493
2670
  // 已经计算了
2494
2671
  if (penValue) {
2495
2672
  return;
@@ -2538,6 +2715,7 @@ var Meta2d = /** @class */ (function () {
2538
2715
  }
2539
2716
  });
2540
2717
  });
2718
+ this.store.data.locked && this.doDataEvent(datas);
2541
2719
  var initPens;
2542
2720
  var pens;
2543
2721
  if (history) {
@@ -2563,6 +2741,9 @@ var Meta2d = /** @class */ (function () {
2563
2741
  var _this = this;
2564
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;
2565
2743
  var pens = [];
2744
+ if (!data) {
2745
+ return;
2746
+ }
2566
2747
  if (data.id) {
2567
2748
  if (data.id === this.store.data.id) {
2568
2749
  this.setDatabyOptions(data);
@@ -2723,6 +2904,69 @@ var Meta2d = /** @class */ (function () {
2723
2904
  });
2724
2905
  });
2725
2906
  };
2907
+ Meta2d.prototype.dataJudegeCondition = function (data, key, condition) {
2908
+ var type = condition.type, target = condition.target, fnJs = condition.fnJs, fn = condition.fn, operator = condition.operator, valueType = condition.valueType;
2909
+ var can = false;
2910
+ if (type === 'fn') {
2911
+ //方法
2912
+ if (fn) {
2913
+ can = fn(data, { meta2d: this });
2914
+ }
2915
+ else if (fnJs) {
2916
+ try {
2917
+ condition.fn = new Function('data', 'context', fnJs);
2918
+ }
2919
+ catch (err) {
2920
+ console.error('Error: make function:', err);
2921
+ }
2922
+ if (condition.fn) {
2923
+ can = condition.fn(data, { meta2d: this });
2924
+ }
2925
+ }
2926
+ }
2927
+ else {
2928
+ //TODO boolean类型 数字类型
2929
+ var value = condition.value;
2930
+ if (valueType === 'prop') {
2931
+ value = data[condition.value];
2932
+ }
2933
+ var compareValue = data[key];
2934
+ switch (operator) {
2935
+ case '>':
2936
+ can = compareValue > +value;
2937
+ break;
2938
+ case '>=':
2939
+ can = compareValue >= +value;
2940
+ break;
2941
+ case '<':
2942
+ can = compareValue < +value;
2943
+ break;
2944
+ case '<=':
2945
+ can = compareValue <= +value;
2946
+ break;
2947
+ case '=':
2948
+ case '==':
2949
+ can = compareValue == value;
2950
+ break;
2951
+ case '!=':
2952
+ can = compareValue != value;
2953
+ break;
2954
+ case '[)':
2955
+ can = valueInRange(+compareValue, value);
2956
+ break;
2957
+ case '![)':
2958
+ can = !valueInRange(+compareValue, value);
2959
+ break;
2960
+ case '[]':
2961
+ can = valueInArray(compareValue, value);
2962
+ break;
2963
+ case '![]':
2964
+ can = !valueInArray(compareValue, value);
2965
+ break;
2966
+ }
2967
+ }
2968
+ return can;
2969
+ };
2726
2970
  Meta2d.prototype.judgeCondition = function (pen, key, condition) {
2727
2971
  var type = condition.type, target = condition.target, fnJs = condition.fnJs, fn = condition.fn, operator = condition.operator, valueType = condition.valueType;
2728
2972
  var can = false;
@@ -2859,7 +3103,7 @@ var Meta2d = /** @class */ (function () {
2859
3103
  * @param padding 上右下左的内边距
2860
3104
  */
2861
3105
  Meta2d.prototype.downloadPng = function (name, padding, maxWidth) {
2862
- var e_6, _a;
3106
+ var e_8, _a;
2863
3107
  var _this = this;
2864
3108
  var _b;
2865
3109
  try {
@@ -2871,12 +3115,12 @@ var Meta2d = /** @class */ (function () {
2871
3115
  }
2872
3116
  }
2873
3117
  }
2874
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
3118
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
2875
3119
  finally {
2876
3120
  try {
2877
3121
  if (_e && !_e.done && (_a = _c.return)) _a.call(_c);
2878
3122
  }
2879
- finally { if (e_6) throw e_6.error; }
3123
+ finally { if (e_8) throw e_8.error; }
2880
3124
  }
2881
3125
  setTimeout(function () {
2882
3126
  var a = document.createElement('a');
@@ -2888,7 +3132,7 @@ var Meta2d = /** @class */ (function () {
2888
3132
  }, 1000);
2889
3133
  };
2890
3134
  Meta2d.prototype.downloadSvg = function () {
2891
- var e_7, _a;
3135
+ var e_9, _a;
2892
3136
  if (!window.C2S) {
2893
3137
  console.error('请先加载乐吾乐官网下的canvas2svg.js', 'https://assets.le5lecdn.com/2d/canvas2svg.js');
2894
3138
  throw new Error('请先加载乐吾乐官网下的canvas2svg.js');
@@ -2907,12 +3151,12 @@ var Meta2d = /** @class */ (function () {
2907
3151
  renderPenRaw(ctx, pen, rect, true);
2908
3152
  }
2909
3153
  }
2910
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
3154
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
2911
3155
  finally {
2912
3156
  try {
2913
3157
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2914
3158
  }
2915
- finally { if (e_7) throw e_7.error; }
3159
+ finally { if (e_9) throw e_9.error; }
2916
3160
  }
2917
3161
  var mySerializedSVG = ctx.getSerializedSvg();
2918
3162
  if (this.store.data.background) {
@@ -3371,7 +3615,7 @@ var Meta2d = /** @class */ (function () {
3371
3615
  });
3372
3616
  };
3373
3617
  Meta2d.prototype.alignNodes = function (align, pens, rect) {
3374
- var e_8, _a;
3618
+ var e_10, _a;
3375
3619
  if (pens === void 0) { pens = this.store.data.pens; }
3376
3620
  !rect && (rect = this.getPenRect(this.getRect(pens)));
3377
3621
  var initPens = deepClone(pens); // 原 pens ,深拷贝一下
@@ -3381,12 +3625,12 @@ var Meta2d = /** @class */ (function () {
3381
3625
  this.alignPen(align, item, rect);
3382
3626
  }
3383
3627
  }
3384
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
3628
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
3385
3629
  finally {
3386
3630
  try {
3387
3631
  if (pens_1_1 && !pens_1_1.done && (_a = pens_1.return)) _a.call(pens_1);
3388
3632
  }
3389
- finally { if (e_8) throw e_8.error; }
3633
+ finally { if (e_10) throw e_10.error; }
3390
3634
  }
3391
3635
  this.initImageCanvas(pens);
3392
3636
  this.initTemplateCanvas(pens);
@@ -3399,7 +3643,7 @@ var Meta2d = /** @class */ (function () {
3399
3643
  };
3400
3644
  //对齐大屏
3401
3645
  Meta2d.prototype.alignNodesV = function (align, pens) {
3402
- var e_9, _a;
3646
+ var e_11, _a;
3403
3647
  if (pens === void 0) { pens = this.store.data.pens; }
3404
3648
  var width = this.store.data.width || this.store.options.width;
3405
3649
  var height = this.store.data.height || this.store.options.height;
@@ -3416,12 +3660,12 @@ var Meta2d = /** @class */ (function () {
3416
3660
  this.alignPen(align, item, rect);
3417
3661
  }
3418
3662
  }
3419
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
3663
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
3420
3664
  finally {
3421
3665
  try {
3422
3666
  if (pens_2_1 && !pens_2_1.done && (_a = pens_2.return)) _a.call(pens_2);
3423
3667
  }
3424
- finally { if (e_9) throw e_9.error; }
3668
+ finally { if (e_11) throw e_11.error; }
3425
3669
  }
3426
3670
  this.initImageCanvas(pens);
3427
3671
  this.initTemplateCanvas(pens);
@@ -3516,7 +3760,7 @@ var Meta2d = /** @class */ (function () {
3516
3760
  * @param distance 总的宽 or 高
3517
3761
  */
3518
3762
  Meta2d.prototype.spaceBetweenByDirection = function (direction, pens, distance) {
3519
- var e_10, _a;
3763
+ var e_12, _a;
3520
3764
  var _this = this;
3521
3765
  if (pens === void 0) { pens = this.store.data.pens; }
3522
3766
  !distance && (distance = this.getPenRect(this.getRect(pens))[direction]);
@@ -3550,12 +3794,12 @@ var Meta2d = /** @class */ (function () {
3550
3794
  this.setValue(__assign({ id: pen.id }, penRect), { render: false, doEvent: false });
3551
3795
  }
3552
3796
  }
3553
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
3797
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
3554
3798
  finally {
3555
3799
  try {
3556
3800
  if (pens_3_1 && !pens_3_1.done && (_a = pens_3.return)) _a.call(pens_3);
3557
3801
  }
3558
- finally { if (e_10) throw e_10.error; }
3802
+ finally { if (e_12) throw e_12.error; }
3559
3803
  }
3560
3804
  this.initImageCanvas(pens);
3561
3805
  this.initTemplateCanvas(pens);
@@ -3619,6 +3863,7 @@ var Meta2d = /** @class */ (function () {
3619
3863
  });
3620
3864
  };
3621
3865
  Meta2d.prototype.gotoView = function (pen) {
3866
+ var e_13, _a;
3622
3867
  var center = this.getViewCenter();
3623
3868
  var x = center.x -
3624
3869
  pen.calculative.worldRect.x -
@@ -3631,6 +3876,19 @@ var Meta2d = /** @class */ (function () {
3631
3876
  }
3632
3877
  this.store.data.x = x;
3633
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
+ }
3634
3892
  this.canvas.canvasImage.init();
3635
3893
  this.canvas.canvasImageBottom.init();
3636
3894
  this.render();
@@ -3676,7 +3934,7 @@ var Meta2d = /** @class */ (function () {
3676
3934
  * @param pens pen 置顶的画笔
3677
3935
  */
3678
3936
  Meta2d.prototype.top = function (pens) {
3679
- var e_11, _a;
3937
+ var e_14, _a;
3680
3938
  var _this = this;
3681
3939
  if (!pens)
3682
3940
  pens = this.store.active;
@@ -3705,12 +3963,12 @@ var Meta2d = /** @class */ (function () {
3705
3963
  _loop_3(pen);
3706
3964
  }
3707
3965
  }
3708
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
3966
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
3709
3967
  finally {
3710
3968
  try {
3711
3969
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3712
3970
  }
3713
- finally { if (e_11) throw e_11.error; }
3971
+ finally { if (e_14) throw e_14.error; }
3714
3972
  }
3715
3973
  this.store.emitter.emit('layer', { type: 'top', pens: pens });
3716
3974
  };
@@ -3734,7 +3992,7 @@ var Meta2d = /** @class */ (function () {
3734
3992
  * @param pens 画笔们,注意 pen 必须在该数组内才有效
3735
3993
  */
3736
3994
  Meta2d.prototype.bottom = function (pens) {
3737
- var e_12, _a;
3995
+ var e_15, _a;
3738
3996
  if (!pens)
3739
3997
  pens = this.store.active;
3740
3998
  if (!Array.isArray(pens))
@@ -3744,15 +4002,15 @@ var Meta2d = /** @class */ (function () {
3744
4002
  var allIds = __spreadArray(__spreadArray([], __read(getAllChildren(pen, this_2.store)), false), [pen], false).map(function (p) { return p.id; });
3745
4003
  var allPens = _pens.filter(function (p) { return allIds.includes(p.id); });
3746
4004
  var _loop_5 = function (i) {
3747
- var pen_1 = allPens[i];
3748
- 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; });
3749
4007
  if (index > -1) {
3750
4008
  _pens.unshift(_pens[index]);
3751
4009
  _pens.splice(index + 1, 1);
3752
- this_2.initTemplateCanvas([pen_1]);
3753
- this_2.initImageCanvas([pen_1]);
4010
+ this_2.initTemplateCanvas([pen_2]);
4011
+ this_2.initImageCanvas([pen_2]);
3754
4012
  }
3755
- this_2.specificLayerMove(pen_1, 'bottom');
4013
+ this_2.specificLayerMove(pen_2, 'bottom');
3756
4014
  };
3757
4015
  // 从后往前,保证 allPens 顺序不变
3758
4016
  for (var i = allPens.length - 1; i >= 0; i--) {
@@ -3766,12 +4024,12 @@ var Meta2d = /** @class */ (function () {
3766
4024
  _loop_4(pen);
3767
4025
  }
3768
4026
  }
3769
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
4027
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
3770
4028
  finally {
3771
4029
  try {
3772
4030
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3773
4031
  }
3774
- finally { if (e_12) throw e_12.error; }
4032
+ finally { if (e_15) throw e_15.error; }
3775
4033
  }
3776
4034
  this.store.emitter.emit('layer', { type: 'bottom', pens: pens });
3777
4035
  };
@@ -3781,7 +4039,7 @@ var Meta2d = /** @class */ (function () {
3781
4039
  * @param pen 画笔
3782
4040
  */
3783
4041
  Meta2d.prototype.upByArea = function (pen) {
3784
- var _a, e_13, _b;
4042
+ var _a, e_16, _b;
3785
4043
  var _this = this;
3786
4044
  var index = this.store.data.pens.findIndex(function (p) { return p.id === pen.id; });
3787
4045
  if (index === -1) {
@@ -3817,8 +4075,8 @@ var Meta2d = /** @class */ (function () {
3817
4075
  return;
3818
4076
  }
3819
4077
  (_a = this.store.data.pens).splice.apply(_a, __spreadArray([nextHitIndex + 1, 0], __read(allPens), false));
3820
- var _loop_6 = function (pen_2) {
3821
- 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; });
3822
4080
  if (index_1 > -1) {
3823
4081
  this_3.store.data.pens.splice(index_1, 1);
3824
4082
  }
@@ -3827,16 +4085,16 @@ var Meta2d = /** @class */ (function () {
3827
4085
  try {
3828
4086
  // 删除靠前的 allPens
3829
4087
  for (var allPens_1 = __values(allPens), allPens_1_1 = allPens_1.next(); !allPens_1_1.done; allPens_1_1 = allPens_1.next()) {
3830
- var pen_2 = allPens_1_1.value;
3831
- _loop_6(pen_2);
4088
+ var pen_3 = allPens_1_1.value;
4089
+ _loop_6(pen_3);
3832
4090
  }
3833
4091
  }
3834
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
4092
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
3835
4093
  finally {
3836
4094
  try {
3837
4095
  if (allPens_1_1 && !allPens_1_1.done && (_b = allPens_1.return)) _b.call(allPens_1);
3838
4096
  }
3839
- finally { if (e_13) throw e_13.error; }
4097
+ finally { if (e_16) throw e_16.error; }
3840
4098
  }
3841
4099
  this.initImageCanvas([pen]);
3842
4100
  };
@@ -3863,7 +4121,7 @@ var Meta2d = /** @class */ (function () {
3863
4121
  this.setValue({ id: pen.id, canvasLayer: layer }, { render: false, doEvent: false, history: false });
3864
4122
  }
3865
4123
  else if (pen.externElement || pen.name === 'gif') {
3866
- var zIndex = 1;
4124
+ var zIndex = 0;
3867
4125
  // let zIndex = pen.calculative.zIndex === undefined ? 5 : pen.calculative.zIndex + 1;
3868
4126
  if (type === 'top') {
3869
4127
  pen.calculative.canvas.maxZindex += 1;
@@ -3876,8 +4134,8 @@ var Meta2d = /** @class */ (function () {
3876
4134
  else if (type === 'down') {
3877
4135
  zIndex =
3878
4136
  pen.calculative.zIndex === undefined ? 3 : pen.calculative.zIndex - 1;
3879
- if (zIndex < 1) {
3880
- zIndex = 1;
4137
+ if (zIndex < 0) {
4138
+ zIndex = 0;
3881
4139
  }
3882
4140
  }
3883
4141
  this.setValue({ id: pen.id, zIndex: zIndex }, { render: false, doEvent: false, history: false });
@@ -3890,7 +4148,7 @@ var Meta2d = /** @class */ (function () {
3890
4148
  * @param pens 画笔
3891
4149
  */
3892
4150
  Meta2d.prototype.up = function (pens) {
3893
- var e_14, _a;
4151
+ var e_17, _a;
3894
4152
  var _this = this;
3895
4153
  if (!pens)
3896
4154
  pens = this.store.active;
@@ -3945,12 +4203,12 @@ var Meta2d = /** @class */ (function () {
3945
4203
  _loop_7(pen);
3946
4204
  }
3947
4205
  }
3948
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
4206
+ catch (e_17_1) { e_17 = { error: e_17_1 }; }
3949
4207
  finally {
3950
4208
  try {
3951
4209
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3952
4210
  }
3953
- finally { if (e_14) throw e_14.error; }
4211
+ finally { if (e_17) throw e_17.error; }
3954
4212
  }
3955
4213
  this.store.emitter.emit('layer', { type: 'up', pens: pens });
3956
4214
  };
@@ -3959,7 +4217,7 @@ var Meta2d = /** @class */ (function () {
3959
4217
  * @param pen 画笔
3960
4218
  */
3961
4219
  Meta2d.prototype.down = function (pens) {
3962
- var e_15, _a;
4220
+ var e_18, _a;
3963
4221
  var _this = this;
3964
4222
  if (!pens)
3965
4223
  pens = this.store.active;
@@ -4016,12 +4274,12 @@ var Meta2d = /** @class */ (function () {
4016
4274
  _loop_9(pen);
4017
4275
  }
4018
4276
  }
4019
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
4277
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
4020
4278
  finally {
4021
4279
  try {
4022
4280
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
4023
4281
  }
4024
- finally { if (e_15) throw e_15.error; }
4282
+ finally { if (e_18) throw e_18.error; }
4025
4283
  }
4026
4284
  this.store.emitter.emit('layer', { type: 'down', pens: pens });
4027
4285
  };
@@ -4101,7 +4359,7 @@ var Meta2d = /** @class */ (function () {
4101
4359
  var nextNodes_1 = [];
4102
4360
  // 2. 遍历出线的 nextNode
4103
4361
  lines.forEach(function (line) {
4104
- var e_16, _a;
4362
+ var e_19, _a;
4105
4363
  var lineNextNode = _this.nextNode(line);
4106
4364
  var _loop_11 = function (node) {
4107
4365
  var have = nextNodes_1.find(function (next) { return next.id === node.id; });
@@ -4114,12 +4372,12 @@ var Meta2d = /** @class */ (function () {
4114
4372
  _loop_11(node);
4115
4373
  }
4116
4374
  }
4117
- catch (e_16_1) { e_16 = { error: e_16_1 }; }
4375
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
4118
4376
  finally {
4119
4377
  try {
4120
4378
  if (lineNextNode_1_1 && !lineNextNode_1_1.done && (_a = lineNextNode_1.return)) _a.call(lineNextNode_1);
4121
4379
  }
4122
- finally { if (e_16) throw e_16.error; }
4380
+ finally { if (e_19) throw e_19.error; }
4123
4381
  }
4124
4382
  });
4125
4383
  return nextNodes_1;
@@ -4142,7 +4400,7 @@ var Meta2d = /** @class */ (function () {
4142
4400
  var preNodes_1 = [];
4143
4401
  // 2. 遍历入线的 preNode
4144
4402
  lines.forEach(function (line) {
4145
- var e_17, _a;
4403
+ var e_20, _a;
4146
4404
  var linePreNode = _this.previousNode(line);
4147
4405
  var _loop_12 = function (node) {
4148
4406
  var have = preNodes_1.find(function (pre) { return pre.id === node.id; });
@@ -4155,12 +4413,12 @@ var Meta2d = /** @class */ (function () {
4155
4413
  _loop_12(node);
4156
4414
  }
4157
4415
  }
4158
- catch (e_17_1) { e_17 = { error: e_17_1 }; }
4416
+ catch (e_20_1) { e_20 = { error: e_20_1 }; }
4159
4417
  finally {
4160
4418
  try {
4161
4419
  if (linePreNode_1_1 && !linePreNode_1_1.done && (_a = linePreNode_1.return)) _a.call(linePreNode_1);
4162
4420
  }
4163
- finally { if (e_17) throw e_17.error; }
4421
+ finally { if (e_20) throw e_20.error; }
4164
4422
  }
4165
4423
  });
4166
4424
  return preNodes_1;
@@ -4507,7 +4765,7 @@ var Meta2d = /** @class */ (function () {
4507
4765
  });
4508
4766
  };
4509
4767
  Meta2d.prototype.setVisible = function (pen, visible, render) {
4510
- var e_18, _a;
4768
+ var e_21, _a;
4511
4769
  if (render === void 0) { render = true; }
4512
4770
  this.onSizeUpdate();
4513
4771
  this.setValue({ id: pen.id, visible: visible }, { render: false, doEvent: false });
@@ -4519,12 +4777,12 @@ var Meta2d = /** @class */ (function () {
4519
4777
  child && this.setVisible(child, visible, false);
4520
4778
  }
4521
4779
  }
4522
- catch (e_18_1) { e_18 = { error: e_18_1 }; }
4780
+ catch (e_21_1) { e_21 = { error: e_21_1 }; }
4523
4781
  finally {
4524
4782
  try {
4525
4783
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
4526
4784
  }
4527
- finally { if (e_18) throw e_18.error; }
4785
+ finally { if (e_21) throw e_21.error; }
4528
4786
  }
4529
4787
  }
4530
4788
  var allPens = getAllChildren(pen, this.store);