@meta2d/core 1.0.45 → 1.0.46

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.d.ts CHANGED
@@ -27,7 +27,7 @@ export declare class Meta2d {
27
27
  type?: string;
28
28
  topic?: string;
29
29
  url?: string;
30
- }) => boolean;
30
+ }) => boolean | string;
31
31
  events: Record<number, (pen: Pen, e: Event) => void>;
32
32
  map: ViewMap;
33
33
  mapTimer: any;
@@ -158,6 +158,7 @@ export declare class Meta2d {
158
158
  */
159
159
  combine(pens?: Pen[], showChild?: number): void;
160
160
  uncombine(pen?: Pen): void;
161
+ appendChild(pens?: Pen[]): void;
161
162
  isCombine(pen: Pen): boolean;
162
163
  active(pens: Pen[], emit?: boolean): void;
163
164
  inactive(): void;
package/src/core.js CHANGED
@@ -187,9 +187,27 @@ var Meta2d = /** @class */ (function () {
187
187
  }
188
188
  if (_this.store.messageEvents[eventName]) {
189
189
  _this.store.messageEvents[eventName].forEach(function (item) {
190
- item.event.actions.forEach(function (action) {
191
- _this.events[action.action](item.pen, action);
192
- });
190
+ var flag = false;
191
+ if (item.event.conditions && item.event.conditions.length) {
192
+ if (item.event.conditionType === 'and') {
193
+ flag = item.event.conditions.every(function (condition) {
194
+ return _this.judgeCondition(item.pen, condition.key, condition);
195
+ });
196
+ }
197
+ else if (item.event.conditionType === 'or') {
198
+ flag = item.event.conditions.some(function (condition) {
199
+ return _this.judgeCondition(item.pen, condition.key, condition);
200
+ });
201
+ }
202
+ }
203
+ else {
204
+ flag = true;
205
+ }
206
+ if (flag) {
207
+ item.event.actions.forEach(function (action) {
208
+ _this.events[action.action](item.pen, action);
209
+ });
210
+ }
193
211
  });
194
212
  }
195
213
  };
@@ -553,7 +571,9 @@ var Meta2d = /** @class */ (function () {
553
571
  var pens = e.params ? _this.find(e.params) : _this.find(pen.id);
554
572
  pens.forEach(function (pen) {
555
573
  if (value.hasOwnProperty('visible')) {
556
- _this.setVisible(pen, value.visible);
574
+ if (pen.visible !== value.visible) {
575
+ _this.setVisible(pen, value.visible);
576
+ }
557
577
  }
558
578
  _this.setValue(__assign({ id: pen.id }, value), { render: false, doEvent: false });
559
579
  });
@@ -1436,6 +1456,9 @@ var Meta2d = /** @class */ (function () {
1436
1456
  else {
1437
1457
  pens = idOrTagOrPens;
1438
1458
  }
1459
+ if (!pens.length) {
1460
+ return;
1461
+ }
1439
1462
  pens.forEach(function (pen) {
1440
1463
  var _a, _b;
1441
1464
  if (pen.calculative.pause) {
@@ -1488,8 +1511,9 @@ var Meta2d = /** @class */ (function () {
1488
1511
  }
1489
1512
  }
1490
1513
  });
1491
- this.canvas.canvasImage.init();
1492
- this.canvas.canvasImageBottom.init();
1514
+ // this.canvas.canvasImage.init();
1515
+ // this.canvas.canvasImageBottom.init();
1516
+ this.initImageCanvas(pens);
1493
1517
  this.canvas.animate();
1494
1518
  };
1495
1519
  Meta2d.prototype.pauseAnimate = function (idOrTagOrPens) {
@@ -1749,6 +1773,28 @@ var Meta2d = /** @class */ (function () {
1749
1773
  }
1750
1774
  this.inactive();
1751
1775
  };
1776
+ Meta2d.prototype.appendChild = function (pens) {
1777
+ if (pens === void 0) { pens = this.store.active; }
1778
+ if (!pens) {
1779
+ return;
1780
+ }
1781
+ if (pens.length < 2) {
1782
+ return;
1783
+ }
1784
+ var pIdx = pens.findIndex(function (pen) { return pen.name === 'combine' && pen.showChild !== undefined; });
1785
+ if (pIdx !== -1) {
1786
+ var parent_1 = pens[pIdx];
1787
+ this.pushChildren(parent_1, __spreadArray(__spreadArray([], __read(pens.slice(0, pIdx)), false), __read(pens.slice(pIdx + 1)), false));
1788
+ pens.forEach(function (pen) {
1789
+ calcInView(pen, true);
1790
+ });
1791
+ this.initImageCanvas(pens);
1792
+ this.render();
1793
+ }
1794
+ else {
1795
+ console.warn('Invalid operation!');
1796
+ }
1797
+ };
1752
1798
  Meta2d.prototype.isCombine = function (pen) {
1753
1799
  if (pen.name === 'combine') {
1754
1800
  return true;
@@ -2286,7 +2332,7 @@ var Meta2d = /** @class */ (function () {
2286
2332
  // https.forEach(async (_item) => {
2287
2333
  // this.requestHttp(_item);
2288
2334
  // });
2289
- // this.render();
2335
+ _this.render();
2290
2336
  }, this.store.data.networkInterval || 1000);
2291
2337
  }
2292
2338
  https.forEach(function (_item, index) {
@@ -2366,22 +2412,28 @@ var Meta2d = /** @class */ (function () {
2366
2412
  Meta2d.prototype.socketCallback = function (message, context) {
2367
2413
  var _this = this;
2368
2414
  this.store.emitter.emit('socket', { message: message, context: context });
2369
- if (this.socketFn &&
2370
- !this.socketFn(message, {
2415
+ var _message = message;
2416
+ if (this.socketFn) {
2417
+ _message = this.socketFn(message, {
2371
2418
  meta2d: this,
2372
2419
  type: context.type,
2373
2420
  topic: context.topic,
2374
2421
  url: context.url,
2375
- })) {
2376
- return;
2422
+ });
2423
+ if (!_message) {
2424
+ return;
2425
+ }
2426
+ }
2427
+ if (_message === true) {
2428
+ _message = message;
2377
2429
  }
2378
2430
  var data;
2379
- if (message.constructor === Object || message.constructor === Array) {
2380
- data = message;
2431
+ if (_message.constructor === Object || _message.constructor === Array) {
2432
+ data = _message;
2381
2433
  }
2382
- else if (typeof message === 'string') {
2434
+ else if (typeof _message === 'string') {
2383
2435
  try {
2384
- data = JSON.parse(message);
2436
+ data = JSON.parse(_message);
2385
2437
  }
2386
2438
  catch (error) {
2387
2439
  console.warn('Invalid socket data:', data, error);