@meta2d/core 1.0.18 → 1.0.20

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
@@ -770,50 +770,82 @@ 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, e_3, _c;
773
+ var e_1, _a, e_2, _b, e_3, _c, e_4, _e;
774
774
  var _this = this;
775
775
  if (render === void 0) { render = true; }
776
776
  this.clear(false);
777
- if (data) {
777
+ var index = this.store.meta2dDatas.findIndex(function (item) { return item._id === data._id; });
778
+ if (this.store.options.cacheLength && data._id && index !== -1) {
779
+ this.store.data = this.store.meta2dDatas[index];
778
780
  this.setBackgroundImage(data.bkImage);
779
- Object.assign(this.store.data, data);
780
- this.store.data.pens = [];
781
- try {
782
- // 第一遍赋初值
783
- for (var _e = __values(data.pens), _f = _e.next(); !_f.done; _f = _e.next()) {
784
- var pen = _f.value;
785
- if (!pen.id) {
786
- pen.id = s8();
781
+ this.store.pens = {};
782
+ this.store.data.pens.forEach(function (pen) {
783
+ pen.calculative.canvas = _this.canvas;
784
+ _this.store.pens[pen.id] = pen;
785
+ globalStore.path2dDraws[pen.name] &&
786
+ _this.store.path2dMap.set(pen, globalStore.path2dDraws[pen.name](pen));
787
+ pen.type &&
788
+ _this.store.path2dMap.set(pen, globalStore.path2dDraws[pen.name](pen));
789
+ _this.canvas.loadImage(pen);
790
+ });
791
+ }
792
+ else {
793
+ if (data) {
794
+ this.setBackgroundImage(data.bkImage);
795
+ Object.assign(this.store.data, data);
796
+ this.store.data.pens = [];
797
+ try {
798
+ // 第一遍赋初值
799
+ for (var _f = __values(data.pens), _g = _f.next(); !_g.done; _g = _f.next()) {
800
+ var pen = _g.value;
801
+ if (!pen.id) {
802
+ pen.id = s8();
803
+ }
804
+ !pen.calculative && (pen.calculative = { canvas: this.canvas });
805
+ this.store.pens[pen.id] = pen;
787
806
  }
788
- !pen.calculative && (pen.calculative = { canvas: this.canvas });
789
- this.store.pens[pen.id] = pen;
790
807
  }
791
- }
792
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
793
- finally {
808
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
809
+ finally {
810
+ try {
811
+ if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
812
+ }
813
+ finally { if (e_1) throw e_1.error; }
814
+ }
794
815
  try {
795
- if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
816
+ for (var _h = __values(data.pens), _j = _h.next(); !_j.done; _j = _h.next()) {
817
+ var pen = _j.value;
818
+ this.canvas.makePen(pen);
819
+ }
796
820
  }
797
- finally { if (e_1) throw e_1.error; }
798
- }
799
- try {
800
- for (var _g = __values(data.pens), _h = _g.next(); !_h.done; _h = _g.next()) {
801
- var pen = _h.value;
802
- this.canvas.makePen(pen);
821
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
822
+ finally {
823
+ try {
824
+ if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
825
+ }
826
+ finally { if (e_2) throw e_2.error; }
803
827
  }
804
- }
805
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
806
- finally {
807
828
  try {
808
- if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
829
+ for (var _k = __values(data.pens), _l = _k.next(); !_l.done; _l = _k.next()) {
830
+ var pen = _l.value;
831
+ this.canvas.updateLines(pen);
832
+ }
833
+ }
834
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
835
+ finally {
836
+ try {
837
+ if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
838
+ }
839
+ finally { if (e_3) throw e_3.error; }
809
840
  }
810
- finally { if (e_2) throw e_2.error; }
811
841
  }
812
842
  }
813
843
  if (!render) {
814
844
  this.canvas.opening = true;
815
845
  }
846
+ this.cacheMeta2dData(data);
816
847
  this.initBindDatas();
848
+ this.initBinds();
817
849
  this.render();
818
850
  this.listenSocket();
819
851
  this.connectSocket();
@@ -822,19 +854,19 @@ var Meta2d = /** @class */ (function () {
822
854
  this.doInitJS();
823
855
  if (this.store.data.iconUrls) {
824
856
  try {
825
- for (var _j = __values(this.store.data.iconUrls), _k = _j.next(); !_k.done; _k = _j.next()) {
826
- var item = _k.value;
857
+ for (var _m = __values(this.store.data.iconUrls), _o = _m.next(); !_o.done; _o = _m.next()) {
858
+ var item = _o.value;
827
859
  loadCss(item, function () {
828
860
  _this.render();
829
861
  });
830
862
  }
831
863
  }
832
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
864
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
833
865
  finally {
834
866
  try {
835
- if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
867
+ if (_o && !_o.done && (_e = _m.return)) _e.call(_m);
836
868
  }
837
- finally { if (e_3) throw e_3.error; }
869
+ finally { if (e_4) throw e_4.error; }
838
870
  }
839
871
  }
840
872
  this.store.emitter.emit('opened');
@@ -842,6 +874,21 @@ var Meta2d = /** @class */ (function () {
842
874
  this.canvas.scroll.init();
843
875
  }
844
876
  };
877
+ Meta2d.prototype.cacheMeta2dData = function (data) {
878
+ if (data._id && this.store.options.cacheLength) {
879
+ var index = this.store.meta2dDatas.findIndex(function (item) { return item._id === data._id; });
880
+ if (index === -1) {
881
+ this.store.meta2dDatas.push(deepClone(this.store.data, true));
882
+ if (this.store.meta2dDatas.length > this.store.options.cacheLength) {
883
+ this.store.meta2dDatas.shift();
884
+ }
885
+ }
886
+ else {
887
+ var meta2dData = this.store.meta2dDatas.splice(index, 1)[0];
888
+ this.store.meta2dDatas.push(meta2dData);
889
+ }
890
+ }
891
+ };
845
892
  Meta2d.prototype.initBindDatas = function () {
846
893
  var _this = this;
847
894
  this.store.bindDatas = {};
@@ -869,6 +916,24 @@ var Meta2d = /** @class */ (function () {
869
916
  });
870
917
  });
871
918
  };
919
+ Meta2d.prototype.initBinds = function () {
920
+ var _this = this;
921
+ this.store.binds = {};
922
+ this.store.data.pens.forEach(function (pen) {
923
+ var _a;
924
+ (_a = pen.realTimes) === null || _a === void 0 ? void 0 : _a.forEach(function (realTime) {
925
+ if (realTime.binds && realTime.binds.id) {
926
+ if (!_this.store.binds[realTime.binds.id]) {
927
+ _this.store.binds[realTime.binds.id] = [];
928
+ }
929
+ _this.store.binds[realTime.binds.id].push({
930
+ id: pen.id,
931
+ key: realTime.key,
932
+ });
933
+ }
934
+ });
935
+ });
936
+ };
872
937
  Meta2d.prototype.connectSocket = function () {
873
938
  this.connectWebsocket();
874
939
  this.connectMqtt();
@@ -1000,7 +1065,7 @@ var Meta2d = /** @class */ (function () {
1000
1065
  * @param render 是否重绘
1001
1066
  */
1002
1067
  Meta2d.prototype.clear = function (render) {
1003
- var e_4, _a;
1068
+ var e_5, _a;
1004
1069
  var _b;
1005
1070
  if (render === void 0) { render = true; }
1006
1071
  try {
@@ -1009,12 +1074,12 @@ var Meta2d = /** @class */ (function () {
1009
1074
  (_b = pen.onDestroy) === null || _b === void 0 ? void 0 : _b.call(pen, pen);
1010
1075
  }
1011
1076
  }
1012
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
1077
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
1013
1078
  finally {
1014
1079
  try {
1015
1080
  if (_e && !_e.done && (_a = _c.return)) _a.call(_c);
1016
1081
  }
1017
- finally { if (e_4) throw e_4.error; }
1082
+ finally { if (e_5) throw e_5.error; }
1018
1083
  }
1019
1084
  clearStore(this.store);
1020
1085
  this.hideInput();
@@ -1710,7 +1775,8 @@ var Meta2d = /** @class */ (function () {
1710
1775
  if (pen.realTimes) {
1711
1776
  var _d_1 = {};
1712
1777
  pen.realTimes.forEach(function (realTime) {
1713
- if (!realTime.binds || !realTime.binds.length) {
1778
+ if (realTime.value !== undefined &&
1779
+ (!realTime.binds || !realTime.binds.id)) {
1714
1780
  if (realTime.type === 'number') {
1715
1781
  if (realTime.value && realTime.value.indexOf(',') !== -1) {
1716
1782
  var arr = realTime.value.split(',');
@@ -1789,7 +1855,7 @@ var Meta2d = /** @class */ (function () {
1789
1855
  return [4 /*yield*/, fetch(item.url, {
1790
1856
  headers: item.headers,
1791
1857
  method: item.method,
1792
- body: item.body,
1858
+ body: item.method === 'GET' ? undefined : item.body,
1793
1859
  })];
1794
1860
  case 1:
1795
1861
  res = _a.sent();
@@ -1869,7 +1935,7 @@ var Meta2d = /** @class */ (function () {
1869
1935
  // 把{dataId: string; value: any}转成setValue格式数据
1870
1936
  var penValues = new Map();
1871
1937
  datas.forEach(function (v) {
1872
- var _a;
1938
+ var _a, _b;
1873
1939
  (_a = _this.store.bindDatas[v.dataId]) === null || _a === void 0 ? void 0 : _a.forEach(function (p) {
1874
1940
  var _a;
1875
1941
  var pen = _this.store.pens[p.id];
@@ -1897,6 +1963,34 @@ var Meta2d = /** @class */ (function () {
1897
1963
  penValues.set(pen, penValue);
1898
1964
  }
1899
1965
  });
1966
+ (_b = _this.store.binds[v.id]) === null || _b === void 0 ? void 0 : _b.forEach(function (p) {
1967
+ var _a;
1968
+ var pen = _this.store.pens[p.id];
1969
+ if (!pen) {
1970
+ return;
1971
+ }
1972
+ var penValue = penValues.get(pen);
1973
+ // if (typeof pen.onBinds === 'function') {
1974
+ // // 已经计算了
1975
+ // if (penValue) {
1976
+ // return;
1977
+ // }
1978
+ // //TODO onBinds的情况
1979
+ // penValues.set(pen, pen.onBinds(pen, datas));
1980
+ // return;
1981
+ // }
1982
+ if (penValue) {
1983
+ penValue[p.key] = v.value;
1984
+ }
1985
+ else {
1986
+ penValue = (_a = {
1987
+ id: p.id
1988
+ },
1989
+ _a[p.key] = v.value,
1990
+ _a);
1991
+ penValues.set(pen, penValue);
1992
+ }
1993
+ });
1900
1994
  });
1901
1995
  var initPens;
1902
1996
  var pens;
@@ -2138,7 +2232,7 @@ var Meta2d = /** @class */ (function () {
2138
2232
  * @param padding 上右下左的内边距
2139
2233
  */
2140
2234
  Meta2d.prototype.downloadPng = function (name, padding) {
2141
- var e_5, _a;
2235
+ var e_6, _a;
2142
2236
  var _this = this;
2143
2237
  var _b;
2144
2238
  try {
@@ -2150,12 +2244,12 @@ var Meta2d = /** @class */ (function () {
2150
2244
  }
2151
2245
  }
2152
2246
  }
2153
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
2247
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
2154
2248
  finally {
2155
2249
  try {
2156
2250
  if (_e && !_e.done && (_a = _c.return)) _a.call(_c);
2157
2251
  }
2158
- finally { if (e_5) throw e_5.error; }
2252
+ finally { if (e_6) throw e_6.error; }
2159
2253
  }
2160
2254
  setTimeout(function () {
2161
2255
  var a = document.createElement('a');
@@ -2485,7 +2579,7 @@ var Meta2d = /** @class */ (function () {
2485
2579
  this.formatPainter();
2486
2580
  };
2487
2581
  Meta2d.prototype.alignNodes = function (align, pens, rect) {
2488
- var e_6, _a;
2582
+ var e_7, _a;
2489
2583
  if (pens === void 0) { pens = this.store.data.pens; }
2490
2584
  !rect && (rect = this.getPenRect(this.getRect(pens)));
2491
2585
  var initPens = deepClone(pens); // 原 pens ,深拷贝一下
@@ -2495,12 +2589,12 @@ var Meta2d = /** @class */ (function () {
2495
2589
  this.alignPen(align, item, rect);
2496
2590
  }
2497
2591
  }
2498
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
2592
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
2499
2593
  finally {
2500
2594
  try {
2501
2595
  if (pens_1_1 && !pens_1_1.done && (_a = pens_1.return)) _a.call(pens_1);
2502
2596
  }
2503
- finally { if (e_6) throw e_6.error; }
2597
+ finally { if (e_7) throw e_7.error; }
2504
2598
  }
2505
2599
  this.render();
2506
2600
  this.pushHistory({
@@ -2589,7 +2683,7 @@ var Meta2d = /** @class */ (function () {
2589
2683
  * @param distance 总的宽 or 高
2590
2684
  */
2591
2685
  Meta2d.prototype.spaceBetweenByDirection = function (direction, pens, distance) {
2592
- var e_7, _a;
2686
+ var e_8, _a;
2593
2687
  var _this = this;
2594
2688
  if (pens === void 0) { pens = this.store.data.pens; }
2595
2689
  !distance && (distance = this.getPenRect(this.getRect(pens))[direction]);
@@ -2623,12 +2717,12 @@ var Meta2d = /** @class */ (function () {
2623
2717
  this.setValue(__assign({ id: pen.id }, penRect), { render: false, doEvent: false });
2624
2718
  }
2625
2719
  }
2626
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
2720
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
2627
2721
  finally {
2628
2722
  try {
2629
2723
  if (pens_2_1 && !pens_2_1.done && (_a = pens_2.return)) _a.call(pens_2);
2630
2724
  }
2631
- finally { if (e_7) throw e_7.error; }
2725
+ finally { if (e_8) throw e_8.error; }
2632
2726
  }
2633
2727
  this.render();
2634
2728
  this.pushHistory({
@@ -2745,7 +2839,7 @@ var Meta2d = /** @class */ (function () {
2745
2839
  * @param pens pen 置顶的画笔
2746
2840
  */
2747
2841
  Meta2d.prototype.top = function (pens) {
2748
- var e_8, _a;
2842
+ var e_9, _a;
2749
2843
  var _this = this;
2750
2844
  if (!pens)
2751
2845
  pens = this.store.active;
@@ -2763,16 +2857,8 @@ var Meta2d = /** @class */ (function () {
2763
2857
  _pens.splice(index, 1);
2764
2858
  _this.initImageCanvas([pen]);
2765
2859
  }
2860
+ _this.specificLayerMove(pen, 'top');
2766
2861
  });
2767
- //image
2768
- if (pen.image && pen.name !== 'gif') {
2769
- this_1.setValue({ id: pen.id, isBottom: false }, { render: false, doEvent: false, history: false });
2770
- }
2771
- //dom
2772
- if (pen.externElement || pen.name === 'gif') {
2773
- pen.calculative.canvas.maxZindex += 1;
2774
- this_1.setValue({ id: pen.id, zIndex: pen.calculative.canvas.maxZindex }, { render: false, doEvent: false, history: false });
2775
- }
2776
2862
  };
2777
2863
  var this_1 = this;
2778
2864
  try {
@@ -2781,12 +2867,12 @@ var Meta2d = /** @class */ (function () {
2781
2867
  _loop_3(pen);
2782
2868
  }
2783
2869
  }
2784
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
2870
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
2785
2871
  finally {
2786
2872
  try {
2787
2873
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2788
2874
  }
2789
- finally { if (e_8) throw e_8.error; }
2875
+ finally { if (e_9) throw e_9.error; }
2790
2876
  }
2791
2877
  };
2792
2878
  /**
@@ -2802,7 +2888,7 @@ var Meta2d = /** @class */ (function () {
2802
2888
  * @param pens 画笔们,注意 pen 必须在该数组内才有效
2803
2889
  */
2804
2890
  Meta2d.prototype.bottom = function (pens) {
2805
- var e_9, _a;
2891
+ var e_10, _a;
2806
2892
  if (!pens)
2807
2893
  pens = this.store.active;
2808
2894
  if (!Array.isArray(pens))
@@ -2819,19 +2905,12 @@ var Meta2d = /** @class */ (function () {
2819
2905
  _pens.splice(index + 1, 1);
2820
2906
  this_2.initImageCanvas([pen_1]);
2821
2907
  }
2908
+ this_2.specificLayerMove(pen_1, 'bottom');
2822
2909
  };
2823
2910
  // 从后往前,保证 allPens 顺序不变
2824
2911
  for (var i = allPens.length - 1; i >= 0; i--) {
2825
2912
  _loop_5(i);
2826
2913
  }
2827
- //image
2828
- if (pen.image && pen.name !== 'gif') {
2829
- this_2.setValue({ id: pen.id, isBottom: true }, { render: false, doEvent: false, history: false });
2830
- }
2831
- //dom
2832
- if (pen.externElement || pen.name === 'gif') {
2833
- this_2.setValue({ id: pen.id, zIndex: 0 }, { render: false, doEvent: false, history: false });
2834
- }
2835
2914
  };
2836
2915
  var this_2 = this;
2837
2916
  try {
@@ -2840,12 +2919,12 @@ var Meta2d = /** @class */ (function () {
2840
2919
  _loop_4(pen);
2841
2920
  }
2842
2921
  }
2843
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
2922
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
2844
2923
  finally {
2845
2924
  try {
2846
2925
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2847
2926
  }
2848
- finally { if (e_9) throw e_9.error; }
2927
+ finally { if (e_10) throw e_10.error; }
2849
2928
  }
2850
2929
  };
2851
2930
  /**
@@ -2854,7 +2933,7 @@ var Meta2d = /** @class */ (function () {
2854
2933
  * @param pen 画笔
2855
2934
  */
2856
2935
  Meta2d.prototype.upByArea = function (pen) {
2857
- var _a, e_10, _b;
2936
+ var _a, e_11, _b;
2858
2937
  var _this = this;
2859
2938
  var index = this.store.data.pens.findIndex(function (p) { return p.id === pen.id; });
2860
2939
  if (index === -1) {
@@ -2904,28 +2983,61 @@ var Meta2d = /** @class */ (function () {
2904
2983
  _loop_6(pen_2);
2905
2984
  }
2906
2985
  }
2907
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
2986
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
2908
2987
  finally {
2909
2988
  try {
2910
2989
  if (allPens_1_1 && !allPens_1_1.done && (_b = allPens_1.return)) _b.call(allPens_1);
2911
2990
  }
2912
- finally { if (e_10) throw e_10.error; }
2991
+ finally { if (e_11) throw e_11.error; }
2913
2992
  }
2914
2993
  this.initImageCanvas([pen]);
2915
2994
  };
2995
+ //特殊图元层级处理
2996
+ Meta2d.prototype.specificLayerMove = function (pen, type) {
2997
+ //image
2998
+ if (pen.image && pen.name !== 'gif') {
2999
+ var isBottom = false;
3000
+ if (type === 'bottom' || type === 'down') {
3001
+ isBottom = true;
3002
+ }
3003
+ this.setValue({ id: pen.id, isBottom: isBottom }, { render: false, doEvent: false, history: false });
3004
+ }
3005
+ //dom
3006
+ if (pen.externElement || pen.name === 'gif') {
3007
+ var zIndex = 0;
3008
+ // let zIndex = pen.calculative.zIndex === undefined ? 5 : pen.calculative.zIndex + 1;
3009
+ if (type === 'top') {
3010
+ pen.calculative.canvas.maxZindex += 1;
3011
+ zIndex = pen.calculative.canvas.maxZindex;
3012
+ }
3013
+ else if (type === 'up') {
3014
+ zIndex =
3015
+ pen.calculative.zIndex === undefined ? 5 : pen.calculative.zIndex + 1;
3016
+ }
3017
+ else if (type === 'down') {
3018
+ zIndex =
3019
+ pen.calculative.zIndex === undefined ? 3 : pen.calculative.zIndex - 1;
3020
+ if (zIndex < 0) {
3021
+ zIndex = 0;
3022
+ }
3023
+ }
3024
+ this.setValue({ id: pen.id, zIndex: zIndex }, { render: false, doEvent: false, history: false });
3025
+ }
3026
+ };
2916
3027
  /**
2917
3028
  * 该画笔上移,即把该画笔在数组中的位置向后移动一个
2918
3029
  * @param pens 画笔
2919
3030
  */
2920
3031
  Meta2d.prototype.up = function (pens) {
2921
- var e_11, _a;
3032
+ var e_12, _a;
3033
+ var _this = this;
2922
3034
  if (!pens)
2923
3035
  pens = this.store.active;
2924
3036
  if (!Array.isArray(pens))
2925
3037
  pens = [pens]; // 兼容
2926
3038
  var _loop_7 = function (pen) {
2927
3039
  var _pens = this_4.store.data.pens;
2928
- if (pen.children) {
3040
+ if (pen.children && pen.children.length) {
2929
3041
  //组合图元
2930
3042
  var preMovePens = __spreadArray(__spreadArray([], __read(getAllChildren(pen, this_4.store)), false), [pen], false);
2931
3043
  //先保证组合图元的顺序正确。
@@ -2948,8 +3060,10 @@ var Meta2d = /** @class */ (function () {
2948
3060
  offset_1 += 1;
2949
3061
  lastIndex_1 = _pen.temIndex;
2950
3062
  delete _pen.temIndex;
3063
+ _this.specificLayerMove(_pen, 'up');
2951
3064
  });
2952
- _pens.splice.apply(_pens, __spreadArray([lastIndex_1 + 1, 0], __read(preMovePens), false));
3065
+ _pens.splice.apply(_pens, __spreadArray([lastIndex_1 + 1, 0], __read(orderPens), false));
3066
+ this_4.initImageCanvas(orderPens);
2953
3067
  }
2954
3068
  else {
2955
3069
  var index = _pens.findIndex(function (p) { return p.id === pen.id; });
@@ -2958,15 +3072,7 @@ var Meta2d = /** @class */ (function () {
2958
3072
  _pens.splice(index, 1);
2959
3073
  this_4.initImageCanvas([pen]);
2960
3074
  }
2961
- }
2962
- //image
2963
- if (pen.image && pen.name !== 'gif') {
2964
- this_4.setValue({ id: pen.id, isBottom: false }, { render: false, doEvent: false, history: false });
2965
- }
2966
- //dom
2967
- if (pen.externElement || pen.name === 'gif') {
2968
- var zIndex = pen.calculative.zIndex === undefined ? 5 : pen.calculative.zIndex + 1;
2969
- this_4.setValue({ id: pen.id, zIndex: zIndex }, { render: false, doEvent: false, history: false });
3075
+ this_4.specificLayerMove(pen, 'up');
2970
3076
  }
2971
3077
  };
2972
3078
  var this_4 = this;
@@ -2976,12 +3082,12 @@ var Meta2d = /** @class */ (function () {
2976
3082
  _loop_7(pen);
2977
3083
  }
2978
3084
  }
2979
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
3085
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
2980
3086
  finally {
2981
3087
  try {
2982
3088
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2983
3089
  }
2984
- finally { if (e_11) throw e_11.error; }
3090
+ finally { if (e_12) throw e_12.error; }
2985
3091
  }
2986
3092
  };
2987
3093
  /**
@@ -2989,14 +3095,15 @@ var Meta2d = /** @class */ (function () {
2989
3095
  * @param pen 画笔
2990
3096
  */
2991
3097
  Meta2d.prototype.down = function (pens) {
2992
- var e_12, _a;
3098
+ var e_13, _a;
3099
+ var _this = this;
2993
3100
  if (!pens)
2994
3101
  pens = this.store.active;
2995
3102
  if (!Array.isArray(pens))
2996
3103
  pens = [pens]; // 兼容
2997
3104
  var _loop_9 = function (pen) {
2998
3105
  var _pens = this_5.store.data.pens;
2999
- if (pen.children) {
3106
+ if (pen.children && pen.children.length) {
3000
3107
  //组合图元
3001
3108
  var preMovePens = __spreadArray(__spreadArray([], __read(getAllChildren(pen, this_5.store)), false), [pen], false);
3002
3109
  //先保证组合图元的顺序正确。
@@ -3021,8 +3128,10 @@ var Meta2d = /** @class */ (function () {
3021
3128
  firstIndex_1 = _pen.temIndex;
3022
3129
  }
3023
3130
  delete _pen.temIndex;
3131
+ _this.specificLayerMove(_pen, 'down');
3024
3132
  });
3025
- _pens.splice.apply(_pens, __spreadArray([firstIndex_1 - 1, 0], __read(preMovePens), false));
3133
+ _pens.splice.apply(_pens, __spreadArray([firstIndex_1 - 1, 0], __read(orderPens), false));
3134
+ this_5.initImageCanvas(orderPens);
3026
3135
  }
3027
3136
  else {
3028
3137
  var index = _pens.findIndex(function (p) { return p.id === pen.id; });
@@ -3031,18 +3140,7 @@ var Meta2d = /** @class */ (function () {
3031
3140
  _pens.splice(index + 1, 1);
3032
3141
  this_5.initImageCanvas([pen]);
3033
3142
  }
3034
- }
3035
- //image
3036
- if (pen.image && pen.name !== 'gif') {
3037
- this_5.setValue({ id: pen.id, isBottom: true }, { render: false, doEvent: false, history: false });
3038
- }
3039
- //dom
3040
- if (pen.externElement || pen.name === 'gif') {
3041
- var zIndex = pen.calculative.zIndex === undefined ? 3 : pen.calculative.zIndex - 1;
3042
- if (zIndex < 0) {
3043
- zIndex = 0;
3044
- }
3045
- this_5.setValue({ id: pen.id, zIndex: zIndex }, { render: false, doEvent: false, history: false });
3143
+ this_5.specificLayerMove(pen, 'down');
3046
3144
  }
3047
3145
  };
3048
3146
  var this_5 = this;
@@ -3052,12 +3150,12 @@ var Meta2d = /** @class */ (function () {
3052
3150
  _loop_9(pen);
3053
3151
  }
3054
3152
  }
3055
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
3153
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
3056
3154
  finally {
3057
3155
  try {
3058
3156
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3059
3157
  }
3060
- finally { if (e_12) throw e_12.error; }
3158
+ finally { if (e_13) throw e_13.error; }
3061
3159
  }
3062
3160
  };
3063
3161
  Meta2d.prototype.setLayer = function (pen, toIndex, pens) {
@@ -3132,7 +3230,7 @@ var Meta2d = /** @class */ (function () {
3132
3230
  var nextNodes_1 = [];
3133
3231
  // 2. 遍历出线的 nextNode
3134
3232
  lines.forEach(function (line) {
3135
- var e_13, _a;
3233
+ var e_14, _a;
3136
3234
  var lineNextNode = _this.nextNode(line);
3137
3235
  var _loop_11 = function (node) {
3138
3236
  var have = nextNodes_1.find(function (next) { return next.id === node.id; });
@@ -3145,12 +3243,12 @@ var Meta2d = /** @class */ (function () {
3145
3243
  _loop_11(node);
3146
3244
  }
3147
3245
  }
3148
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
3246
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
3149
3247
  finally {
3150
3248
  try {
3151
3249
  if (lineNextNode_1_1 && !lineNextNode_1_1.done && (_a = lineNextNode_1.return)) _a.call(lineNextNode_1);
3152
3250
  }
3153
- finally { if (e_13) throw e_13.error; }
3251
+ finally { if (e_14) throw e_14.error; }
3154
3252
  }
3155
3253
  });
3156
3254
  return nextNodes_1;
@@ -3173,7 +3271,7 @@ var Meta2d = /** @class */ (function () {
3173
3271
  var preNodes_1 = [];
3174
3272
  // 2. 遍历入线的 preNode
3175
3273
  lines.forEach(function (line) {
3176
- var e_14, _a;
3274
+ var e_15, _a;
3177
3275
  var linePreNode = _this.previousNode(line);
3178
3276
  var _loop_12 = function (node) {
3179
3277
  var have = preNodes_1.find(function (pre) { return pre.id === node.id; });
@@ -3186,12 +3284,12 @@ var Meta2d = /** @class */ (function () {
3186
3284
  _loop_12(node);
3187
3285
  }
3188
3286
  }
3189
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
3287
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
3190
3288
  finally {
3191
3289
  try {
3192
3290
  if (linePreNode_1_1 && !linePreNode_1_1.done && (_a = linePreNode_1.return)) _a.call(linePreNode_1);
3193
3291
  }
3194
- finally { if (e_14) throw e_14.error; }
3292
+ finally { if (e_15) throw e_15.error; }
3195
3293
  }
3196
3294
  });
3197
3295
  return preNodes_1;
@@ -3467,7 +3565,7 @@ var Meta2d = /** @class */ (function () {
3467
3565
  : deepClone(__spreadArray([parent], __read(components), false));
3468
3566
  };
3469
3567
  Meta2d.prototype.setVisible = function (pen, visible, render) {
3470
- var e_15, _a;
3568
+ var e_16, _a;
3471
3569
  if (render === void 0) { render = true; }
3472
3570
  this.onSizeUpdate();
3473
3571
  this.setValue({ id: pen.id, visible: visible }, { render: false, doEvent: false });
@@ -3479,12 +3577,12 @@ var Meta2d = /** @class */ (function () {
3479
3577
  child && this.setVisible(child, visible, false);
3480
3578
  }
3481
3579
  }
3482
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
3580
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
3483
3581
  finally {
3484
3582
  try {
3485
3583
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3486
3584
  }
3487
- finally { if (e_15) throw e_15.error; }
3585
+ finally { if (e_16) throw e_16.error; }
3488
3586
  }
3489
3587
  }
3490
3588
  render && this.render();