@meta2d/core 1.0.17 → 1.0.19

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
@@ -86,7 +86,7 @@ import { Canvas } from './canvas';
86
86
  import { calcInView, calcTextDrawRect, calcTextLines, calcTextRect, facePen, formatAttrs, getAllChildren, getFromAnchor, getParent, getToAnchor, getWords, LockState, PenType, renderPenRaw, setElemPosition, connectLine, nearestAnchor, setChildValue, isAncestor, } from './pen';
87
87
  import { rotatePoint } from './point';
88
88
  import { clearStore, EditType, globalStore, register, registerAnchors, registerCanvasDraw, useStore, } from './store';
89
- import { formatPadding, s8, valueInArray, valueInRange, } from './utils';
89
+ import { formatPadding, loadCss, s8, valueInArray, valueInRange, } from './utils';
90
90
  import { calcCenter, calcRelativeRect, getRect, rectInRect, } from './rect';
91
91
  import { deepClone } from './utils/clone';
92
92
  import { EventAction } from './event';
@@ -770,7 +770,8 @@ var Meta2d = /** @class */ (function () {
770
770
  this.store.patchFlagsTop = true;
771
771
  };
772
772
  Meta2d.prototype.open = function (data, render) {
773
- var e_1, _a, e_2, _b;
773
+ var e_1, _a, e_2, _b, e_3, _c, e_4, _e;
774
+ var _this = this;
774
775
  if (render === void 0) { render = true; }
775
776
  this.clear(false);
776
777
  if (data) {
@@ -779,8 +780,8 @@ var Meta2d = /** @class */ (function () {
779
780
  this.store.data.pens = [];
780
781
  try {
781
782
  // 第一遍赋初值
782
- for (var _c = __values(data.pens), _e = _c.next(); !_e.done; _e = _c.next()) {
783
- var pen = _e.value;
783
+ for (var _f = __values(data.pens), _g = _f.next(); !_g.done; _g = _f.next()) {
784
+ var pen = _g.value;
784
785
  if (!pen.id) {
785
786
  pen.id = s8();
786
787
  }
@@ -791,34 +792,65 @@ var Meta2d = /** @class */ (function () {
791
792
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
792
793
  finally {
793
794
  try {
794
- if (_e && !_e.done && (_a = _c.return)) _a.call(_c);
795
+ if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
795
796
  }
796
797
  finally { if (e_1) throw e_1.error; }
797
798
  }
798
799
  try {
799
- for (var _f = __values(data.pens), _g = _f.next(); !_g.done; _g = _f.next()) {
800
- var pen = _g.value;
800
+ for (var _h = __values(data.pens), _j = _h.next(); !_j.done; _j = _h.next()) {
801
+ var pen = _j.value;
801
802
  this.canvas.makePen(pen);
802
803
  }
803
804
  }
804
805
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
805
806
  finally {
806
807
  try {
807
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
808
+ if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
808
809
  }
809
810
  finally { if (e_2) throw e_2.error; }
810
811
  }
812
+ try {
813
+ for (var _k = __values(data.pens), _l = _k.next(); !_l.done; _l = _k.next()) {
814
+ var pen = _l.value;
815
+ this.canvas.updateLines(pen);
816
+ }
817
+ }
818
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
819
+ finally {
820
+ try {
821
+ if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
822
+ }
823
+ finally { if (e_3) throw e_3.error; }
824
+ }
811
825
  }
812
826
  if (!render) {
813
827
  this.canvas.opening = true;
814
828
  }
815
829
  this.initBindDatas();
830
+ this.initBinds();
816
831
  this.render();
817
832
  this.listenSocket();
818
833
  this.connectSocket();
819
834
  this.startAnimate();
820
835
  this.startVideo();
821
836
  this.doInitJS();
837
+ if (this.store.data.iconUrls) {
838
+ try {
839
+ for (var _m = __values(this.store.data.iconUrls), _o = _m.next(); !_o.done; _o = _m.next()) {
840
+ var item = _o.value;
841
+ loadCss(item, function () {
842
+ _this.render();
843
+ });
844
+ }
845
+ }
846
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
847
+ finally {
848
+ try {
849
+ if (_o && !_o.done && (_e = _m.return)) _e.call(_m);
850
+ }
851
+ finally { if (e_4) throw e_4.error; }
852
+ }
853
+ }
822
854
  this.store.emitter.emit('opened');
823
855
  if (this.canvas.scroll && this.canvas.scroll.isShow) {
824
856
  this.canvas.scroll.init();
@@ -851,6 +883,24 @@ var Meta2d = /** @class */ (function () {
851
883
  });
852
884
  });
853
885
  };
886
+ Meta2d.prototype.initBinds = function () {
887
+ var _this = this;
888
+ this.store.binds = {};
889
+ this.store.data.pens.forEach(function (pen) {
890
+ var _a;
891
+ (_a = pen.realTimes) === null || _a === void 0 ? void 0 : _a.forEach(function (realTime) {
892
+ if (realTime.binds && realTime.binds.id) {
893
+ if (!_this.store.binds[realTime.binds.id]) {
894
+ _this.store.binds[realTime.binds.id] = [];
895
+ }
896
+ _this.store.binds[realTime.binds.id].push({
897
+ id: pen.id,
898
+ key: realTime.key,
899
+ });
900
+ }
901
+ });
902
+ });
903
+ };
854
904
  Meta2d.prototype.connectSocket = function () {
855
905
  this.connectWebsocket();
856
906
  this.connectMqtt();
@@ -982,7 +1032,7 @@ var Meta2d = /** @class */ (function () {
982
1032
  * @param render 是否重绘
983
1033
  */
984
1034
  Meta2d.prototype.clear = function (render) {
985
- var e_3, _a;
1035
+ var e_5, _a;
986
1036
  var _b;
987
1037
  if (render === void 0) { render = true; }
988
1038
  try {
@@ -991,12 +1041,12 @@ var Meta2d = /** @class */ (function () {
991
1041
  (_b = pen.onDestroy) === null || _b === void 0 ? void 0 : _b.call(pen, pen);
992
1042
  }
993
1043
  }
994
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
1044
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
995
1045
  finally {
996
1046
  try {
997
1047
  if (_e && !_e.done && (_a = _c.return)) _a.call(_c);
998
1048
  }
999
- finally { if (e_3) throw e_3.error; }
1049
+ finally { if (e_5) throw e_5.error; }
1000
1050
  }
1001
1051
  clearStore(this.store);
1002
1052
  this.hideInput();
@@ -1692,7 +1742,8 @@ var Meta2d = /** @class */ (function () {
1692
1742
  if (pen.realTimes) {
1693
1743
  var _d_1 = {};
1694
1744
  pen.realTimes.forEach(function (realTime) {
1695
- if (!realTime.binds || !realTime.binds.length) {
1745
+ if (realTime.value !== undefined &&
1746
+ (!realTime.binds || !realTime.binds.id)) {
1696
1747
  if (realTime.type === 'number') {
1697
1748
  if (realTime.value && realTime.value.indexOf(',') !== -1) {
1698
1749
  var arr = realTime.value.split(',');
@@ -1771,7 +1822,7 @@ var Meta2d = /** @class */ (function () {
1771
1822
  return [4 /*yield*/, fetch(item.url, {
1772
1823
  headers: item.headers,
1773
1824
  method: item.method,
1774
- body: item.body,
1825
+ body: item.method === 'GET' ? undefined : item.body,
1775
1826
  })];
1776
1827
  case 1:
1777
1828
  res = _a.sent();
@@ -1851,7 +1902,7 @@ var Meta2d = /** @class */ (function () {
1851
1902
  // 把{dataId: string; value: any}转成setValue格式数据
1852
1903
  var penValues = new Map();
1853
1904
  datas.forEach(function (v) {
1854
- var _a;
1905
+ var _a, _b;
1855
1906
  (_a = _this.store.bindDatas[v.dataId]) === null || _a === void 0 ? void 0 : _a.forEach(function (p) {
1856
1907
  var _a;
1857
1908
  var pen = _this.store.pens[p.id];
@@ -1879,6 +1930,34 @@ var Meta2d = /** @class */ (function () {
1879
1930
  penValues.set(pen, penValue);
1880
1931
  }
1881
1932
  });
1933
+ (_b = _this.store.binds[v.id]) === null || _b === void 0 ? void 0 : _b.forEach(function (p) {
1934
+ var _a;
1935
+ var pen = _this.store.pens[p.id];
1936
+ if (!pen) {
1937
+ return;
1938
+ }
1939
+ var penValue = penValues.get(pen);
1940
+ // if (typeof pen.onBinds === 'function') {
1941
+ // // 已经计算了
1942
+ // if (penValue) {
1943
+ // return;
1944
+ // }
1945
+ // //TODO onBinds的情况
1946
+ // penValues.set(pen, pen.onBinds(pen, datas));
1947
+ // return;
1948
+ // }
1949
+ if (penValue) {
1950
+ penValue[p.key] = v.value;
1951
+ }
1952
+ else {
1953
+ penValue = (_a = {
1954
+ id: p.id
1955
+ },
1956
+ _a[p.key] = v.value,
1957
+ _a);
1958
+ penValues.set(pen, penValue);
1959
+ }
1960
+ });
1882
1961
  });
1883
1962
  var initPens;
1884
1963
  var pens;
@@ -2120,7 +2199,7 @@ var Meta2d = /** @class */ (function () {
2120
2199
  * @param padding 上右下左的内边距
2121
2200
  */
2122
2201
  Meta2d.prototype.downloadPng = function (name, padding) {
2123
- var e_4, _a;
2202
+ var e_6, _a;
2124
2203
  var _this = this;
2125
2204
  var _b;
2126
2205
  try {
@@ -2132,12 +2211,12 @@ var Meta2d = /** @class */ (function () {
2132
2211
  }
2133
2212
  }
2134
2213
  }
2135
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
2214
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
2136
2215
  finally {
2137
2216
  try {
2138
2217
  if (_e && !_e.done && (_a = _c.return)) _a.call(_c);
2139
2218
  }
2140
- finally { if (e_4) throw e_4.error; }
2219
+ finally { if (e_6) throw e_6.error; }
2141
2220
  }
2142
2221
  setTimeout(function () {
2143
2222
  var a = document.createElement('a');
@@ -2467,7 +2546,7 @@ var Meta2d = /** @class */ (function () {
2467
2546
  this.formatPainter();
2468
2547
  };
2469
2548
  Meta2d.prototype.alignNodes = function (align, pens, rect) {
2470
- var e_5, _a;
2549
+ var e_7, _a;
2471
2550
  if (pens === void 0) { pens = this.store.data.pens; }
2472
2551
  !rect && (rect = this.getPenRect(this.getRect(pens)));
2473
2552
  var initPens = deepClone(pens); // 原 pens ,深拷贝一下
@@ -2477,12 +2556,12 @@ var Meta2d = /** @class */ (function () {
2477
2556
  this.alignPen(align, item, rect);
2478
2557
  }
2479
2558
  }
2480
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
2559
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
2481
2560
  finally {
2482
2561
  try {
2483
2562
  if (pens_1_1 && !pens_1_1.done && (_a = pens_1.return)) _a.call(pens_1);
2484
2563
  }
2485
- finally { if (e_5) throw e_5.error; }
2564
+ finally { if (e_7) throw e_7.error; }
2486
2565
  }
2487
2566
  this.render();
2488
2567
  this.pushHistory({
@@ -2571,7 +2650,7 @@ var Meta2d = /** @class */ (function () {
2571
2650
  * @param distance 总的宽 or 高
2572
2651
  */
2573
2652
  Meta2d.prototype.spaceBetweenByDirection = function (direction, pens, distance) {
2574
- var e_6, _a;
2653
+ var e_8, _a;
2575
2654
  var _this = this;
2576
2655
  if (pens === void 0) { pens = this.store.data.pens; }
2577
2656
  !distance && (distance = this.getPenRect(this.getRect(pens))[direction]);
@@ -2605,12 +2684,12 @@ var Meta2d = /** @class */ (function () {
2605
2684
  this.setValue(__assign({ id: pen.id }, penRect), { render: false, doEvent: false });
2606
2685
  }
2607
2686
  }
2608
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
2687
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
2609
2688
  finally {
2610
2689
  try {
2611
2690
  if (pens_2_1 && !pens_2_1.done && (_a = pens_2.return)) _a.call(pens_2);
2612
2691
  }
2613
- finally { if (e_6) throw e_6.error; }
2692
+ finally { if (e_8) throw e_8.error; }
2614
2693
  }
2615
2694
  this.render();
2616
2695
  this.pushHistory({
@@ -2724,22 +2803,44 @@ var Meta2d = /** @class */ (function () {
2724
2803
  };
2725
2804
  /**
2726
2805
  * 将该画笔置顶,即放到数组最后,最后绘制即在顶部
2727
- * @param pen pen 置顶的画笔
2806
+ * @param pens pen 置顶的画笔
2728
2807
  */
2729
- Meta2d.prototype.top = function (pen) {
2808
+ Meta2d.prototype.top = function (pens) {
2809
+ var e_9, _a;
2730
2810
  var _this = this;
2731
- var pens = this.store.data.pens;
2732
- // 获取它包含它的子节点
2733
- var allIds = __spreadArray(__spreadArray([], __read(getAllChildren(pen, this.store)), false), [pen], false).map(function (p) { return p.id; });
2734
- var allPens = pens.filter(function (p) { return allIds.includes(p.id); });
2735
- allPens.forEach(function (pen) {
2736
- var index = pens.findIndex(function (p) { return p.id === pen.id; });
2737
- if (index > -1) {
2738
- pens.push(pens[index]);
2739
- pens.splice(index, 1);
2740
- _this.initImageCanvas([pen]);
2811
+ if (!pens)
2812
+ pens = this.store.active;
2813
+ if (!Array.isArray(pens))
2814
+ pens = [pens]; // 兼容
2815
+ var _loop_3 = function (pen) {
2816
+ var _pens = this_1.store.data.pens;
2817
+ // 获取它包含它的子节点
2818
+ var allIds = __spreadArray(__spreadArray([], __read(getAllChildren(pen, this_1.store)), false), [pen], false).map(function (p) { return p.id; });
2819
+ var allPens = _pens.filter(function (p) { return allIds.includes(p.id); });
2820
+ allPens.forEach(function (pen) {
2821
+ var index = _pens.findIndex(function (p) { return p.id === pen.id; });
2822
+ if (index > -1) {
2823
+ _pens.push(_pens[index]);
2824
+ _pens.splice(index, 1);
2825
+ _this.initImageCanvas([pen]);
2826
+ }
2827
+ _this.specificLayerMove(pen, 'top');
2828
+ });
2829
+ };
2830
+ var this_1 = this;
2831
+ try {
2832
+ for (var _b = __values(pens), _c = _b.next(); !_c.done; _c = _b.next()) {
2833
+ var pen = _c.value;
2834
+ _loop_3(pen);
2741
2835
  }
2742
- });
2836
+ }
2837
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
2838
+ finally {
2839
+ try {
2840
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2841
+ }
2842
+ finally { if (e_9) throw e_9.error; }
2843
+ }
2743
2844
  };
2744
2845
  /**
2745
2846
  * 若本次改变的画笔存在图片,并且在上层 or 下层,需要擦除上层 or 下层
@@ -2753,23 +2854,44 @@ var Meta2d = /** @class */ (function () {
2753
2854
  * 该画笔置底,即放到数组最前,最后绘制即在底部
2754
2855
  * @param pens 画笔们,注意 pen 必须在该数组内才有效
2755
2856
  */
2756
- Meta2d.prototype.bottom = function (pen) {
2757
- var pens = this.store.data.pens;
2758
- var allIds = __spreadArray(__spreadArray([], __read(getAllChildren(pen, this.store)), false), [pen], false).map(function (p) { return p.id; });
2759
- var allPens = pens.filter(function (p) { return allIds.includes(p.id); });
2760
- var _loop_3 = function (i) {
2761
- var pen_1 = allPens[i];
2762
- var index = pens.findIndex(function (p) { return p.id === pen_1.id; });
2763
- if (index > -1) {
2764
- pens.unshift(pens[index]);
2765
- pens.splice(index + 1, 1);
2766
- this_1.initImageCanvas([pen_1]);
2857
+ Meta2d.prototype.bottom = function (pens) {
2858
+ var e_10, _a;
2859
+ if (!pens)
2860
+ pens = this.store.active;
2861
+ if (!Array.isArray(pens))
2862
+ pens = [pens]; // 兼容
2863
+ var _loop_4 = function (pen) {
2864
+ var _pens = this_2.store.data.pens;
2865
+ var allIds = __spreadArray(__spreadArray([], __read(getAllChildren(pen, this_2.store)), false), [pen], false).map(function (p) { return p.id; });
2866
+ var allPens = _pens.filter(function (p) { return allIds.includes(p.id); });
2867
+ var _loop_5 = function (i) {
2868
+ var pen_1 = allPens[i];
2869
+ var index = _pens.findIndex(function (p) { return p.id === pen_1.id; });
2870
+ if (index > -1) {
2871
+ _pens.unshift(_pens[index]);
2872
+ _pens.splice(index + 1, 1);
2873
+ this_2.initImageCanvas([pen_1]);
2874
+ }
2875
+ this_2.specificLayerMove(pen_1, 'bottom');
2876
+ };
2877
+ // 从后往前,保证 allPens 顺序不变
2878
+ for (var i = allPens.length - 1; i >= 0; i--) {
2879
+ _loop_5(i);
2767
2880
  }
2768
2881
  };
2769
- var this_1 = this;
2770
- // 从后往前,保证 allPens 顺序不变
2771
- for (var i = allPens.length - 1; i >= 0; i--) {
2772
- _loop_3(i);
2882
+ var this_2 = this;
2883
+ try {
2884
+ for (var _b = __values(pens), _c = _b.next(); !_c.done; _c = _b.next()) {
2885
+ var pen = _c.value;
2886
+ _loop_4(pen);
2887
+ }
2888
+ }
2889
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
2890
+ finally {
2891
+ try {
2892
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2893
+ }
2894
+ finally { if (e_10) throw e_10.error; }
2773
2895
  }
2774
2896
  };
2775
2897
  /**
@@ -2778,7 +2900,7 @@ var Meta2d = /** @class */ (function () {
2778
2900
  * @param pen 画笔
2779
2901
  */
2780
2902
  Meta2d.prototype.upByArea = function (pen) {
2781
- var _a, e_7, _b;
2903
+ var _a, e_11, _b;
2782
2904
  var _this = this;
2783
2905
  var index = this.store.data.pens.findIndex(function (p) { return p.id === pen.id; });
2784
2906
  if (index === -1) {
@@ -2814,111 +2936,193 @@ var Meta2d = /** @class */ (function () {
2814
2936
  return;
2815
2937
  }
2816
2938
  (_a = this.store.data.pens).splice.apply(_a, __spreadArray([nextHitIndex + 1, 0], __read(allPens), false));
2817
- var _loop_4 = function (pen_2) {
2818
- var index_1 = this_2.store.data.pens.findIndex(function (p) { return p.id === pen_2.id; });
2939
+ var _loop_6 = function (pen_2) {
2940
+ var index_1 = this_3.store.data.pens.findIndex(function (p) { return p.id === pen_2.id; });
2819
2941
  if (index_1 > -1) {
2820
- this_2.store.data.pens.splice(index_1, 1);
2942
+ this_3.store.data.pens.splice(index_1, 1);
2821
2943
  }
2822
2944
  };
2823
- var this_2 = this;
2945
+ var this_3 = this;
2824
2946
  try {
2825
2947
  // 删除靠前的 allPens
2826
2948
  for (var allPens_1 = __values(allPens), allPens_1_1 = allPens_1.next(); !allPens_1_1.done; allPens_1_1 = allPens_1.next()) {
2827
2949
  var pen_2 = allPens_1_1.value;
2828
- _loop_4(pen_2);
2950
+ _loop_6(pen_2);
2829
2951
  }
2830
2952
  }
2831
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
2953
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
2832
2954
  finally {
2833
2955
  try {
2834
2956
  if (allPens_1_1 && !allPens_1_1.done && (_b = allPens_1.return)) _b.call(allPens_1);
2835
2957
  }
2836
- finally { if (e_7) throw e_7.error; }
2958
+ finally { if (e_11) throw e_11.error; }
2837
2959
  }
2838
2960
  this.initImageCanvas([pen]);
2839
2961
  };
2962
+ //特殊图元层级处理
2963
+ Meta2d.prototype.specificLayerMove = function (pen, type) {
2964
+ //image
2965
+ if (pen.image && pen.name !== 'gif') {
2966
+ var isBottom = false;
2967
+ if (type === 'bottom' || type === 'down') {
2968
+ isBottom = true;
2969
+ }
2970
+ this.setValue({ id: pen.id, isBottom: isBottom }, { render: false, doEvent: false, history: false });
2971
+ }
2972
+ //dom
2973
+ if (pen.externElement || pen.name === 'gif') {
2974
+ var zIndex = 0;
2975
+ // let zIndex = pen.calculative.zIndex === undefined ? 5 : pen.calculative.zIndex + 1;
2976
+ if (type === 'top') {
2977
+ pen.calculative.canvas.maxZindex += 1;
2978
+ zIndex = pen.calculative.canvas.maxZindex;
2979
+ }
2980
+ else if (type === 'up') {
2981
+ zIndex =
2982
+ pen.calculative.zIndex === undefined ? 5 : pen.calculative.zIndex + 1;
2983
+ }
2984
+ else if (type === 'down') {
2985
+ zIndex =
2986
+ pen.calculative.zIndex === undefined ? 3 : pen.calculative.zIndex - 1;
2987
+ if (zIndex < 0) {
2988
+ zIndex = 0;
2989
+ }
2990
+ }
2991
+ this.setValue({ id: pen.id, zIndex: zIndex }, { render: false, doEvent: false, history: false });
2992
+ }
2993
+ };
2840
2994
  /**
2841
2995
  * 该画笔上移,即把该画笔在数组中的位置向后移动一个
2842
- * @param pen 画笔
2996
+ * @param pens 画笔
2843
2997
  */
2844
- Meta2d.prototype.up = function (pen) {
2845
- var pens = this.store.data.pens;
2846
- if (pen.children) {
2847
- //组合图元
2848
- var preMovePens = __spreadArray(__spreadArray([], __read(getAllChildren(pen, this.store)), false), [pen], false);
2849
- //先保证组合图元的顺序正确。
2850
- var orderPens = [];
2851
- var _loop_5 = function (index) {
2852
- var _pen = pens[index];
2853
- if (preMovePens.findIndex(function (p) { return p.id === _pen.id; }) !== -1) {
2854
- _pen.temIndex = index;
2855
- orderPens.push(_pen);
2998
+ Meta2d.prototype.up = function (pens) {
2999
+ var e_12, _a;
3000
+ var _this = this;
3001
+ if (!pens)
3002
+ pens = this.store.active;
3003
+ if (!Array.isArray(pens))
3004
+ pens = [pens]; // 兼容
3005
+ var _loop_7 = function (pen) {
3006
+ var _pens = this_4.store.data.pens;
3007
+ if (pen.children && pen.children.length) {
3008
+ //组合图元
3009
+ var preMovePens = __spreadArray(__spreadArray([], __read(getAllChildren(pen, this_4.store)), false), [pen], false);
3010
+ //先保证组合图元的顺序正确。
3011
+ var orderPens = [];
3012
+ var _loop_8 = function (index) {
3013
+ var _pen = _pens[index];
3014
+ if (preMovePens.findIndex(function (p) { return p.id === _pen.id; }) !== -1) {
3015
+ _pen.temIndex = index;
3016
+ orderPens.push(_pen);
3017
+ }
3018
+ };
3019
+ for (var index = 0; index < _pens.length; index++) {
3020
+ _loop_8(index);
2856
3021
  }
2857
- };
2858
- for (var index = 0; index < pens.length; index++) {
2859
- _loop_5(index);
2860
- }
2861
- var lastIndex_1 = -1;
2862
- var offset_1 = 0;
2863
- orderPens.forEach(function (_pen) {
2864
- _pen.temIndex -= offset_1;
2865
- pens.splice(_pen.temIndex, 1);
2866
- offset_1 += 1;
2867
- lastIndex_1 = _pen.temIndex;
2868
- delete _pen.temIndex;
2869
- });
2870
- pens.splice.apply(pens, __spreadArray([lastIndex_1 + 1, 0], __read(preMovePens), false));
3022
+ var lastIndex_1 = -1;
3023
+ var offset_1 = 0;
3024
+ orderPens.forEach(function (_pen) {
3025
+ _pen.temIndex -= offset_1;
3026
+ _pens.splice(_pen.temIndex, 1);
3027
+ offset_1 += 1;
3028
+ lastIndex_1 = _pen.temIndex;
3029
+ delete _pen.temIndex;
3030
+ _this.specificLayerMove(_pen, 'up');
3031
+ });
3032
+ _pens.splice.apply(_pens, __spreadArray([lastIndex_1 + 1, 0], __read(orderPens), false));
3033
+ this_4.initImageCanvas(orderPens);
3034
+ }
3035
+ else {
3036
+ var index = _pens.findIndex(function (p) { return p.id === pen.id; });
3037
+ if (index > -1 && index !== _pens.length - 1) {
3038
+ _pens.splice(index + 2, 0, _pens[index]);
3039
+ _pens.splice(index, 1);
3040
+ this_4.initImageCanvas([pen]);
3041
+ }
3042
+ this_4.specificLayerMove(pen, 'up');
3043
+ }
3044
+ };
3045
+ var this_4 = this;
3046
+ try {
3047
+ for (var _b = __values(pens), _c = _b.next(); !_c.done; _c = _b.next()) {
3048
+ var pen = _c.value;
3049
+ _loop_7(pen);
3050
+ }
2871
3051
  }
2872
- else {
2873
- var index = pens.findIndex(function (p) { return p.id === pen.id; });
2874
- if (index > -1 && index !== pens.length - 1) {
2875
- pens.splice(index + 2, 0, pens[index]);
2876
- pens.splice(index, 1);
2877
- this.initImageCanvas([pen]);
3052
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
3053
+ finally {
3054
+ try {
3055
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2878
3056
  }
3057
+ finally { if (e_12) throw e_12.error; }
2879
3058
  }
2880
3059
  };
2881
3060
  /**
2882
3061
  * 该画笔下移,即把该画笔在该数组中的位置前移一个
2883
3062
  * @param pen 画笔
2884
3063
  */
2885
- Meta2d.prototype.down = function (pen) {
2886
- var pens = this.store.data.pens;
2887
- if (pen.children) {
2888
- //组合图元
2889
- var preMovePens = __spreadArray(__spreadArray([], __read(getAllChildren(pen, this.store)), false), [pen], false);
2890
- //先保证组合图元的顺序正确。
2891
- var orderPens = [];
2892
- var _loop_6 = function (index) {
2893
- var _pen = pens[index];
2894
- if (preMovePens.findIndex(function (p) { return p.id === _pen.id; }) !== -1) {
2895
- _pen.temIndex = index;
2896
- orderPens.push(_pen);
3064
+ Meta2d.prototype.down = function (pens) {
3065
+ var e_13, _a;
3066
+ var _this = this;
3067
+ if (!pens)
3068
+ pens = this.store.active;
3069
+ if (!Array.isArray(pens))
3070
+ pens = [pens]; // 兼容
3071
+ var _loop_9 = function (pen) {
3072
+ var _pens = this_5.store.data.pens;
3073
+ if (pen.children && pen.children.length) {
3074
+ //组合图元
3075
+ var preMovePens = __spreadArray(__spreadArray([], __read(getAllChildren(pen, this_5.store)), false), [pen], false);
3076
+ //先保证组合图元的顺序正确。
3077
+ var orderPens = [];
3078
+ var _loop_10 = function (index) {
3079
+ var _pen = _pens[index];
3080
+ if (preMovePens.findIndex(function (p) { return p.id === _pen.id; }) !== -1) {
3081
+ _pen.temIndex = index;
3082
+ orderPens.push(_pen);
3083
+ }
3084
+ };
3085
+ for (var index = 0; index < _pens.length; index++) {
3086
+ _loop_10(index);
2897
3087
  }
2898
- };
2899
- for (var index = 0; index < pens.length; index++) {
2900
- _loop_6(index);
2901
- }
2902
- var firstIndex_1 = -1;
2903
- var offset_2 = 0;
2904
- orderPens.forEach(function (_pen, index) {
2905
- _pen.temIndex -= offset_2;
2906
- pens.splice(_pen.temIndex, 1);
2907
- offset_2 += 1;
2908
- if (index === 0) {
2909
- firstIndex_1 = _pen.temIndex;
3088
+ var firstIndex_1 = -1;
3089
+ var offset_2 = 0;
3090
+ orderPens.forEach(function (_pen, index) {
3091
+ _pen.temIndex -= offset_2;
3092
+ _pens.splice(_pen.temIndex, 1);
3093
+ offset_2 += 1;
3094
+ if (index === 0) {
3095
+ firstIndex_1 = _pen.temIndex;
3096
+ }
3097
+ delete _pen.temIndex;
3098
+ _this.specificLayerMove(_pen, 'down');
3099
+ });
3100
+ _pens.splice.apply(_pens, __spreadArray([firstIndex_1 - 1, 0], __read(orderPens), false));
3101
+ this_5.initImageCanvas(orderPens);
3102
+ }
3103
+ else {
3104
+ var index = _pens.findIndex(function (p) { return p.id === pen.id; });
3105
+ if (index > -1 && index !== 0) {
3106
+ _pens.splice(index - 1, 0, _pens[index]);
3107
+ _pens.splice(index + 1, 1);
3108
+ this_5.initImageCanvas([pen]);
2910
3109
  }
2911
- delete _pen.temIndex;
2912
- });
2913
- pens.splice.apply(pens, __spreadArray([firstIndex_1 - 1, 0], __read(preMovePens), false));
3110
+ this_5.specificLayerMove(pen, 'down');
3111
+ }
3112
+ };
3113
+ var this_5 = this;
3114
+ try {
3115
+ for (var _b = __values(pens), _c = _b.next(); !_c.done; _c = _b.next()) {
3116
+ var pen = _c.value;
3117
+ _loop_9(pen);
3118
+ }
2914
3119
  }
2915
- else {
2916
- var index = pens.findIndex(function (p) { return p.id === pen.id; });
2917
- if (index > -1 && index !== 0) {
2918
- pens.splice(index - 1, 0, pens[index]);
2919
- pens.splice(index + 1, 1);
2920
- this.initImageCanvas([pen]);
3120
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
3121
+ finally {
3122
+ try {
3123
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2921
3124
  }
3125
+ finally { if (e_13) throw e_13.error; }
2922
3126
  }
2923
3127
  };
2924
3128
  Meta2d.prototype.setLayer = function (pen, toIndex, pens) {
@@ -2993,9 +3197,9 @@ var Meta2d = /** @class */ (function () {
2993
3197
  var nextNodes_1 = [];
2994
3198
  // 2. 遍历出线的 nextNode
2995
3199
  lines.forEach(function (line) {
2996
- var e_8, _a;
3200
+ var e_14, _a;
2997
3201
  var lineNextNode = _this.nextNode(line);
2998
- var _loop_7 = function (node) {
3202
+ var _loop_11 = function (node) {
2999
3203
  var have = nextNodes_1.find(function (next) { return next.id === node.id; });
3000
3204
  // 3. 不重复的才加进去
3001
3205
  !have && nextNodes_1.push(node);
@@ -3003,15 +3207,15 @@ var Meta2d = /** @class */ (function () {
3003
3207
  try {
3004
3208
  for (var lineNextNode_1 = __values(lineNextNode), lineNextNode_1_1 = lineNextNode_1.next(); !lineNextNode_1_1.done; lineNextNode_1_1 = lineNextNode_1.next()) {
3005
3209
  var node = lineNextNode_1_1.value;
3006
- _loop_7(node);
3210
+ _loop_11(node);
3007
3211
  }
3008
3212
  }
3009
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
3213
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
3010
3214
  finally {
3011
3215
  try {
3012
3216
  if (lineNextNode_1_1 && !lineNextNode_1_1.done && (_a = lineNextNode_1.return)) _a.call(lineNextNode_1);
3013
3217
  }
3014
- finally { if (e_8) throw e_8.error; }
3218
+ finally { if (e_14) throw e_14.error; }
3015
3219
  }
3016
3220
  });
3017
3221
  return nextNodes_1;
@@ -3034,9 +3238,9 @@ var Meta2d = /** @class */ (function () {
3034
3238
  var preNodes_1 = [];
3035
3239
  // 2. 遍历入线的 preNode
3036
3240
  lines.forEach(function (line) {
3037
- var e_9, _a;
3241
+ var e_15, _a;
3038
3242
  var linePreNode = _this.previousNode(line);
3039
- var _loop_8 = function (node) {
3243
+ var _loop_12 = function (node) {
3040
3244
  var have = preNodes_1.find(function (pre) { return pre.id === node.id; });
3041
3245
  // 3. 不重复的才加进去
3042
3246
  !have && preNodes_1.push(node);
@@ -3044,15 +3248,15 @@ var Meta2d = /** @class */ (function () {
3044
3248
  try {
3045
3249
  for (var linePreNode_1 = __values(linePreNode), linePreNode_1_1 = linePreNode_1.next(); !linePreNode_1_1.done; linePreNode_1_1 = linePreNode_1.next()) {
3046
3250
  var node = linePreNode_1_1.value;
3047
- _loop_8(node);
3251
+ _loop_12(node);
3048
3252
  }
3049
3253
  }
3050
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
3254
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
3051
3255
  finally {
3052
3256
  try {
3053
3257
  if (linePreNode_1_1 && !linePreNode_1_1.done && (_a = linePreNode_1.return)) _a.call(linePreNode_1);
3054
3258
  }
3055
- finally { if (e_9) throw e_9.error; }
3259
+ finally { if (e_15) throw e_15.error; }
3056
3260
  }
3057
3261
  });
3058
3262
  return preNodes_1;
@@ -3328,7 +3532,7 @@ var Meta2d = /** @class */ (function () {
3328
3532
  : deepClone(__spreadArray([parent], __read(components), false));
3329
3533
  };
3330
3534
  Meta2d.prototype.setVisible = function (pen, visible, render) {
3331
- var e_10, _a;
3535
+ var e_16, _a;
3332
3536
  if (render === void 0) { render = true; }
3333
3537
  this.onSizeUpdate();
3334
3538
  this.setValue({ id: pen.id, visible: visible }, { render: false, doEvent: false });
@@ -3340,12 +3544,12 @@ var Meta2d = /** @class */ (function () {
3340
3544
  child && this.setVisible(child, visible, false);
3341
3545
  }
3342
3546
  }
3343
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
3547
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
3344
3548
  finally {
3345
3549
  try {
3346
3550
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3347
3551
  }
3348
- finally { if (e_10) throw e_10.error; }
3552
+ finally { if (e_16) throw e_16.error; }
3349
3553
  }
3350
3554
  }
3351
3555
  render && this.render();