@meta2d/core 1.0.45 → 1.0.47

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;
@@ -238,6 +239,7 @@ export declare class Meta2d {
238
239
  showInput(pen: Pen, rect?: Rect): void;
239
240
  hideInput(): void;
240
241
  clearDropdownList(): void;
242
+ clearRuleLines(): void;
241
243
  private onEvent;
242
244
  private doEvent;
243
245
  initGlobalTriggers(): void;
@@ -247,6 +249,7 @@ export declare class Meta2d {
247
249
  renderPenRaw: typeof renderPenRaw;
248
250
  toPng(padding?: Padding, callback?: BlobCallback, containBkImg?: boolean, maxWidth?: number): string;
249
251
  activeToPng(padding?: Padding): string;
252
+ pensToPng(pens?: Pen[], padding?: Padding): string;
250
253
  /**
251
254
  * 下载 png
252
255
  * @param name 传入参数自带文件后缀名 例如:'test.png'
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);
@@ -2603,6 +2655,9 @@ var Meta2d = /** @class */ (function () {
2603
2655
  Meta2d.prototype.clearDropdownList = function () {
2604
2656
  this.canvas.clearDropdownList();
2605
2657
  };
2658
+ Meta2d.prototype.clearRuleLines = function () {
2659
+ this.canvas.clearRuleLines();
2660
+ };
2606
2661
  Meta2d.prototype.initGlobalTriggers = function () {
2607
2662
  var _this = this;
2608
2663
  var _a;
@@ -2761,6 +2816,10 @@ var Meta2d = /** @class */ (function () {
2761
2816
  Meta2d.prototype.activeToPng = function (padding) {
2762
2817
  return this.canvas.activeToPng(padding);
2763
2818
  };
2819
+ Meta2d.prototype.pensToPng = function (pens, padding) {
2820
+ if (pens === void 0) { pens = this.store.active; }
2821
+ return this.canvas.pensToPng(pens, padding);
2822
+ };
2764
2823
  /**
2765
2824
  * 下载 png
2766
2825
  * @param name 传入参数自带文件后缀名 例如:'test.png'
@@ -3272,6 +3331,8 @@ var Meta2d = /** @class */ (function () {
3272
3331
  }
3273
3332
  finally { if (e_8) throw e_8.error; }
3274
3333
  }
3334
+ this.initImageCanvas(pens);
3335
+ this.initTemplateCanvas(pens);
3275
3336
  this.render();
3276
3337
  this.pushHistory({
3277
3338
  type: EditType.Update,
@@ -3305,6 +3366,9 @@ var Meta2d = /** @class */ (function () {
3305
3366
  }
3306
3367
  finally { if (e_9) throw e_9.error; }
3307
3368
  }
3369
+ this.initImageCanvas(pens);
3370
+ this.initTemplateCanvas(pens);
3371
+ this.render();
3308
3372
  this.pushHistory({
3309
3373
  type: EditType.Update,
3310
3374
  initPens: initPens,
@@ -3325,6 +3389,8 @@ var Meta2d = /** @class */ (function () {
3325
3389
  var pen = pens[i];
3326
3390
  this.alignPen(align, pen, rect);
3327
3391
  }
3392
+ this.initImageCanvas(pens);
3393
+ this.initTemplateCanvas(pens);
3328
3394
  this.render();
3329
3395
  this.pushHistory({
3330
3396
  type: EditType.Update,
@@ -3346,6 +3412,8 @@ var Meta2d = /** @class */ (function () {
3346
3412
  var pen = pens[i];
3347
3413
  this.alignPen(align, pen, rect);
3348
3414
  }
3415
+ this.initImageCanvas(pens);
3416
+ this.initTemplateCanvas(pens);
3349
3417
  this.render();
3350
3418
  this.pushHistory({
3351
3419
  type: EditType.Update,
@@ -3432,6 +3500,8 @@ var Meta2d = /** @class */ (function () {
3432
3500
  }
3433
3501
  finally { if (e_10) throw e_10.error; }
3434
3502
  }
3503
+ this.initImageCanvas(pens);
3504
+ this.initTemplateCanvas(pens);
3435
3505
  this.render();
3436
3506
  this.pushHistory({
3437
3507
  type: EditType.Update,
@@ -3482,6 +3552,8 @@ var Meta2d = /** @class */ (function () {
3482
3552
  currentY += maxHeight + space;
3483
3553
  }
3484
3554
  });
3555
+ this.initImageCanvas(pens);
3556
+ this.initTemplateCanvas(pens);
3485
3557
  this.render();
3486
3558
  this.pushHistory({
3487
3559
  type: EditType.Update,
@@ -4398,6 +4470,8 @@ var Meta2d = /** @class */ (function () {
4398
4470
  finally { if (e_18) throw e_18.error; }
4399
4471
  }
4400
4472
  }
4473
+ var allPens = getAllChildren(pen, this.store);
4474
+ this.initImageCanvas(allPens);
4401
4475
  render && this.render();
4402
4476
  };
4403
4477
  Meta2d.prototype.clearHover = function () {