@idraw/util 0.4.0-alpha.6 → 0.4.0-beta.0

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.
@@ -1,5 +1,24 @@
1
1
  var iDrawUtil = function(exports) {
2
- "use strict";
2
+ "use strict";var __accessCheck = (obj, member, msg) => {
3
+ if (!member.has(obj))
4
+ throw TypeError("Cannot " + msg);
5
+ };
6
+ var __privateGet = (obj, member, getter) => {
7
+ __accessCheck(obj, member, "read from private field");
8
+ return getter ? getter.call(obj) : member.get(obj);
9
+ };
10
+ var __privateAdd = (obj, member, value) => {
11
+ if (member.has(obj))
12
+ throw TypeError("Cannot add the same private member more than once");
13
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
14
+ };
15
+ var __privateSet = (obj, member, value, setter) => {
16
+ __accessCheck(obj, member, "write to private field");
17
+ setter ? setter.call(obj, value) : member.set(obj, value);
18
+ return value;
19
+ };
20
+
21
+ var _ctx, _opts;
3
22
  function compose(middleware) {
4
23
  return function(context, next) {
5
24
  return dispatch(0);
@@ -775,19 +794,19 @@ var iDrawUtil = function(exports) {
775
794
  // private _width: number = 0;
776
795
  // private _height: number = 0;
777
796
  constructor(ctx, opts) {
778
- this._devicePixelRatio = 1;
779
- const { devicePixelRatio = 1 } = opts;
780
- this._ctx = ctx;
781
- this._devicePixelRatio = devicePixelRatio;
797
+ __privateAdd(this, _ctx, void 0);
798
+ __privateAdd(this, _opts, void 0);
799
+ __privateSet(this, _ctx, ctx);
800
+ __privateSet(this, _opts, { ...{ devicePixelRatio: 1, offscreenCanvas: null }, ...opts });
782
801
  }
783
802
  $undoPixelRatio(num) {
784
- return num / this._devicePixelRatio;
803
+ return num / __privateGet(this, _opts).devicePixelRatio;
785
804
  }
786
805
  $doPixelRatio(num) {
787
- return this._devicePixelRatio * num;
806
+ return __privateGet(this, _opts).devicePixelRatio * num;
788
807
  }
789
808
  $getContext() {
790
- return this._ctx;
809
+ return __privateGet(this, _ctx);
791
810
  }
792
811
  $setFont(opts) {
793
812
  const strList = [];
@@ -796,135 +815,156 @@ var iDrawUtil = function(exports) {
796
815
  }
797
816
  strList.push(`${this.$doPixelRatio(opts.fontSize || 12)}px`);
798
817
  strList.push(`${opts.fontFamily || "sans-serif"}`);
799
- this._ctx.font = `${strList.join(" ")}`;
818
+ __privateGet(this, _ctx).font = `${strList.join(" ")}`;
819
+ }
820
+ $getOffscreenCanvas() {
821
+ return __privateGet(this, _opts).offscreenCanvas;
800
822
  }
801
823
  $resize(opts) {
802
- const { width, height, devicePixelRatio } = opts;
803
- const { canvas } = this._ctx;
824
+ const { width, height, devicePixelRatio, resetStyle } = opts;
825
+ const { canvas } = __privateGet(this, _ctx);
804
826
  canvas.width = width * devicePixelRatio;
805
827
  canvas.height = height * devicePixelRatio;
806
- this._devicePixelRatio = devicePixelRatio;
828
+ __privateSet(this, _opts, {
829
+ ...__privateGet(this, _opts),
830
+ ...{
831
+ devicePixelRatio
832
+ }
833
+ });
834
+ if (resetStyle === true) {
835
+ canvas.style.width = `${width}px`;
836
+ canvas.style.height = `${height}px`;
837
+ }
838
+ }
839
+ $getSize() {
840
+ const { devicePixelRatio } = __privateGet(this, _opts);
841
+ const { width, height } = __privateGet(this, _ctx).canvas;
842
+ return {
843
+ width: width / devicePixelRatio,
844
+ height: height / devicePixelRatio,
845
+ devicePixelRatio
846
+ };
807
847
  }
808
848
  get canvas() {
809
- return this._ctx.canvas;
849
+ return __privateGet(this, _ctx).canvas;
810
850
  }
811
851
  get fillStyle() {
812
- return this._ctx.fillStyle;
852
+ return __privateGet(this, _ctx).fillStyle;
813
853
  }
814
854
  set fillStyle(value) {
815
- this._ctx.fillStyle = value;
855
+ __privateGet(this, _ctx).fillStyle = value;
816
856
  }
817
857
  get strokeStyle() {
818
- return this._ctx.strokeStyle;
858
+ return __privateGet(this, _ctx).strokeStyle;
819
859
  }
820
860
  set strokeStyle(color2) {
821
- this._ctx.strokeStyle = color2;
861
+ __privateGet(this, _ctx).strokeStyle = color2;
822
862
  }
823
863
  get lineWidth() {
824
- return this.$undoPixelRatio(this._ctx.lineWidth);
864
+ return this.$undoPixelRatio(__privateGet(this, _ctx).lineWidth);
825
865
  }
826
866
  set lineWidth(w2) {
827
- this._ctx.lineWidth = this.$doPixelRatio(w2);
867
+ __privateGet(this, _ctx).lineWidth = this.$doPixelRatio(w2);
828
868
  }
829
869
  get textAlign() {
830
- return this._ctx.textAlign;
870
+ return __privateGet(this, _ctx).textAlign;
831
871
  }
832
872
  set textAlign(align) {
833
- this._ctx.textAlign = align;
873
+ __privateGet(this, _ctx).textAlign = align;
834
874
  }
835
875
  get textBaseline() {
836
- return this._ctx.textBaseline;
876
+ return __privateGet(this, _ctx).textBaseline;
837
877
  }
838
878
  set textBaseline(baseline) {
839
- this._ctx.textBaseline = baseline;
879
+ __privateGet(this, _ctx).textBaseline = baseline;
840
880
  }
841
881
  get globalAlpha() {
842
- return this._ctx.globalAlpha;
882
+ return __privateGet(this, _ctx).globalAlpha;
843
883
  }
844
884
  set globalAlpha(alpha) {
845
- this._ctx.globalAlpha = alpha;
885
+ __privateGet(this, _ctx).globalAlpha = alpha;
846
886
  }
847
887
  get shadowColor() {
848
- return this._ctx.shadowColor;
888
+ return __privateGet(this, _ctx).shadowColor;
849
889
  }
850
890
  set shadowColor(color2) {
851
- this._ctx.shadowColor = color2;
891
+ __privateGet(this, _ctx).shadowColor = color2;
852
892
  }
853
893
  get shadowOffsetX() {
854
- return this.$undoPixelRatio(this._ctx.shadowOffsetX);
894
+ return this.$undoPixelRatio(__privateGet(this, _ctx).shadowOffsetX);
855
895
  }
856
896
  set shadowOffsetX(offsetX) {
857
- this._ctx.shadowOffsetX = this.$doPixelRatio(offsetX);
897
+ __privateGet(this, _ctx).shadowOffsetX = this.$doPixelRatio(offsetX);
858
898
  }
859
899
  get shadowOffsetY() {
860
- return this.$undoPixelRatio(this._ctx.shadowOffsetY);
900
+ return this.$undoPixelRatio(__privateGet(this, _ctx).shadowOffsetY);
861
901
  }
862
902
  set shadowOffsetY(offsetY) {
863
- this._ctx.shadowOffsetY = this.$doPixelRatio(offsetY);
903
+ __privateGet(this, _ctx).shadowOffsetY = this.$doPixelRatio(offsetY);
864
904
  }
865
905
  get shadowBlur() {
866
- return this.$undoPixelRatio(this._ctx.shadowBlur);
906
+ return this.$undoPixelRatio(__privateGet(this, _ctx).shadowBlur);
867
907
  }
868
908
  set shadowBlur(blur) {
869
- this._ctx.shadowBlur = this.$doPixelRatio(blur);
909
+ __privateGet(this, _ctx).shadowBlur = this.$doPixelRatio(blur);
870
910
  }
871
911
  get lineCap() {
872
- return this._ctx.lineCap;
912
+ return __privateGet(this, _ctx).lineCap;
873
913
  }
874
914
  set lineCap(lineCap) {
875
- this._ctx.lineCap = lineCap;
915
+ __privateGet(this, _ctx).lineCap = lineCap;
876
916
  }
877
917
  get globalCompositeOperation() {
878
- return this._ctx.globalCompositeOperation;
918
+ return __privateGet(this, _ctx).globalCompositeOperation;
879
919
  }
880
920
  set globalCompositeOperation(operations) {
881
- this._ctx.globalCompositeOperation = operations;
921
+ __privateGet(this, _ctx).globalCompositeOperation = operations;
882
922
  }
883
923
  fill(...args) {
884
- return this._ctx.fill(...args);
924
+ return __privateGet(this, _ctx).fill(...args);
885
925
  }
886
926
  arc(x2, y2, radius, startAngle, endAngle, anticlockwise) {
887
- return this._ctx.arc(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(radius), startAngle, endAngle, anticlockwise);
927
+ return __privateGet(this, _ctx).arc(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(radius), startAngle, endAngle, anticlockwise);
888
928
  }
889
929
  rect(x2, y2, w2, h2) {
890
- return this._ctx.rect(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(w2), this.$doPixelRatio(h2));
930
+ return __privateGet(this, _ctx).rect(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(w2), this.$doPixelRatio(h2));
891
931
  }
892
932
  fillRect(x2, y2, w2, h2) {
893
- return this._ctx.fillRect(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(w2), this.$doPixelRatio(h2));
933
+ return __privateGet(this, _ctx).fillRect(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(w2), this.$doPixelRatio(h2));
894
934
  }
895
935
  clearRect(x2, y2, w2, h2) {
896
- return this._ctx.clearRect(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(w2), this.$doPixelRatio(h2));
936
+ return __privateGet(this, _ctx).clearRect(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(w2), this.$doPixelRatio(h2));
897
937
  }
898
938
  beginPath() {
899
- return this._ctx.beginPath();
939
+ return __privateGet(this, _ctx).beginPath();
900
940
  }
901
941
  closePath() {
902
- return this._ctx.closePath();
942
+ return __privateGet(this, _ctx).closePath();
903
943
  }
904
944
  lineTo(x2, y2) {
905
- return this._ctx.lineTo(this.$doPixelRatio(x2), this.$doPixelRatio(y2));
945
+ return __privateGet(this, _ctx).lineTo(this.$doPixelRatio(x2), this.$doPixelRatio(y2));
906
946
  }
907
947
  moveTo(x2, y2) {
908
- return this._ctx.moveTo(this.$doPixelRatio(x2), this.$doPixelRatio(y2));
948
+ return __privateGet(this, _ctx).moveTo(this.$doPixelRatio(x2), this.$doPixelRatio(y2));
909
949
  }
910
950
  arcTo(x1, y1, x2, y2, radius) {
911
- return this._ctx.arcTo(this.$doPixelRatio(x1), this.$doPixelRatio(y1), this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(radius));
951
+ return __privateGet(this, _ctx).arcTo(this.$doPixelRatio(x1), this.$doPixelRatio(y1), this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(radius));
912
952
  }
913
953
  getLineDash() {
914
- return this._ctx.getLineDash();
954
+ return __privateGet(this, _ctx).getLineDash();
915
955
  }
916
956
  setLineDash(nums) {
917
957
  const dash = nums.map((n) => this.$doPixelRatio(n));
918
- return this._ctx.setLineDash(dash);
958
+ return __privateGet(this, _ctx).setLineDash(dash);
919
959
  }
920
960
  stroke(path) {
921
- return path ? this._ctx.stroke(path) : this._ctx.stroke();
961
+ return path ? __privateGet(this, _ctx).stroke(path) : __privateGet(this, _ctx).stroke();
922
962
  }
923
963
  translate(x2, y2) {
924
- return this._ctx.translate(this.$doPixelRatio(x2), this.$doPixelRatio(y2));
964
+ return __privateGet(this, _ctx).translate(this.$doPixelRatio(x2), this.$doPixelRatio(y2));
925
965
  }
926
966
  rotate(angle2) {
927
- return this._ctx.rotate(angle2);
967
+ return __privateGet(this, _ctx).rotate(angle2);
928
968
  }
929
969
  drawImage(...args) {
930
970
  const image = args[0];
@@ -937,7 +977,7 @@ var iDrawUtil = function(exports) {
937
977
  const dw = args[args.length - 2];
938
978
  const dh = args[args.length - 1];
939
979
  if (args.length === 9) {
940
- return this._ctx.drawImage(
980
+ return __privateGet(this, _ctx).drawImage(
941
981
  image,
942
982
  this.$doPixelRatio(sx),
943
983
  this.$doPixelRatio(sy),
@@ -949,41 +989,41 @@ var iDrawUtil = function(exports) {
949
989
  this.$doPixelRatio(dh)
950
990
  );
951
991
  } else {
952
- return this._ctx.drawImage(image, this.$doPixelRatio(dx), this.$doPixelRatio(dy), this.$doPixelRatio(dw), this.$doPixelRatio(dh));
992
+ return __privateGet(this, _ctx).drawImage(image, this.$doPixelRatio(dx), this.$doPixelRatio(dy), this.$doPixelRatio(dw), this.$doPixelRatio(dh));
953
993
  }
954
994
  }
955
995
  createPattern(image, repetition) {
956
- return this._ctx.createPattern(image, repetition);
996
+ return __privateGet(this, _ctx).createPattern(image, repetition);
957
997
  }
958
998
  measureText(text2) {
959
- const textMetrics = this._ctx.measureText(text2);
999
+ const textMetrics = __privateGet(this, _ctx).measureText(text2);
960
1000
  return textMetrics;
961
1001
  }
962
1002
  fillText(text2, x2, y2, maxWidth) {
963
1003
  if (maxWidth !== void 0) {
964
- return this._ctx.fillText(text2, this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(maxWidth));
1004
+ return __privateGet(this, _ctx).fillText(text2, this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(maxWidth));
965
1005
  } else {
966
- return this._ctx.fillText(text2, this.$doPixelRatio(x2), this.$doPixelRatio(y2));
1006
+ return __privateGet(this, _ctx).fillText(text2, this.$doPixelRatio(x2), this.$doPixelRatio(y2));
967
1007
  }
968
1008
  }
969
1009
  strokeText(text2, x2, y2, maxWidth) {
970
1010
  if (maxWidth !== void 0) {
971
- return this._ctx.strokeText(text2, this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(maxWidth));
1011
+ return __privateGet(this, _ctx).strokeText(text2, this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(maxWidth));
972
1012
  } else {
973
- return this._ctx.strokeText(text2, this.$doPixelRatio(x2), this.$doPixelRatio(y2));
1013
+ return __privateGet(this, _ctx).strokeText(text2, this.$doPixelRatio(x2), this.$doPixelRatio(y2));
974
1014
  }
975
1015
  }
976
1016
  save() {
977
- this._ctx.save();
1017
+ __privateGet(this, _ctx).save();
978
1018
  }
979
1019
  restore() {
980
- this._ctx.restore();
1020
+ __privateGet(this, _ctx).restore();
981
1021
  }
982
1022
  scale(ratioX, ratioY) {
983
- this._ctx.scale(ratioX, ratioY);
1023
+ __privateGet(this, _ctx).scale(ratioX, ratioY);
984
1024
  }
985
1025
  circle(x2, y2, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise) {
986
- this._ctx.ellipse(
1026
+ __privateGet(this, _ctx).ellipse(
987
1027
  this.$doPixelRatio(x2),
988
1028
  this.$doPixelRatio(y2),
989
1029
  this.$doPixelRatio(radiusX),
@@ -995,24 +1035,24 @@ var iDrawUtil = function(exports) {
995
1035
  );
996
1036
  }
997
1037
  isPointInPath(x2, y2) {
998
- return this._ctx.isPointInPath(this.$doPixelRatio(x2), this.$doPixelRatio(y2));
1038
+ return __privateGet(this, _ctx).isPointInPath(this.$doPixelRatio(x2), this.$doPixelRatio(y2));
999
1039
  }
1000
1040
  // clip(fillRule?: CanvasFillRule): void;
1001
1041
  // clip(path: Path2D, fillRule?: CanvasFillRule): void;
1002
1042
  clip(...args) {
1003
- return this._ctx.clip(...args);
1043
+ return __privateGet(this, _ctx).clip(...args);
1004
1044
  }
1005
1045
  setTransform(a, b, c, d, e, f) {
1006
- return this._ctx.setTransform(a, b, c, d, e, f);
1046
+ return __privateGet(this, _ctx).setTransform(a, b, c, d, e, f);
1007
1047
  }
1008
1048
  getTransform() {
1009
- return this._ctx.getTransform();
1049
+ return __privateGet(this, _ctx).getTransform();
1010
1050
  }
1011
1051
  createLinearGradient(x0, y0, x1, y1) {
1012
- return this._ctx.createLinearGradient(this.$doPixelRatio(x0), this.$doPixelRatio(y0), this.$doPixelRatio(x1), this.$doPixelRatio(y1));
1052
+ return __privateGet(this, _ctx).createLinearGradient(this.$doPixelRatio(x0), this.$doPixelRatio(y0), this.$doPixelRatio(x1), this.$doPixelRatio(y1));
1013
1053
  }
1014
1054
  createRadialGradient(x0, y0, r0, x1, y1, r1) {
1015
- return this._ctx.createRadialGradient(
1055
+ return __privateGet(this, _ctx).createRadialGradient(
1016
1056
  this.$doPixelRatio(x0),
1017
1057
  this.$doPixelRatio(y0),
1018
1058
  this.$doPixelRatio(r0),
@@ -1022,9 +1062,11 @@ var iDrawUtil = function(exports) {
1022
1062
  );
1023
1063
  }
1024
1064
  createConicGradient(startAngle, x2, y2) {
1025
- return this._ctx.createConicGradient(startAngle, this.$doPixelRatio(x2), this.$doPixelRatio(y2));
1065
+ return __privateGet(this, _ctx).createConicGradient(startAngle, this.$doPixelRatio(x2), this.$doPixelRatio(y2));
1026
1066
  }
1027
1067
  }
1068
+ _ctx = new WeakMap();
1069
+ _opts = new WeakMap();
1028
1070
  function createContext2D(opts) {
1029
1071
  const { width, height, ctx, devicePixelRatio } = opts;
1030
1072
  let context = ctx;
@@ -1038,29 +1080,71 @@ var iDrawUtil = function(exports) {
1038
1080
  return context2d;
1039
1081
  }
1040
1082
  function createOffscreenContext2D(opts) {
1041
- const { width, height } = opts;
1042
- const offCanvas = new OffscreenCanvas(width, height);
1083
+ const { width, height, devicePixelRatio } = opts;
1084
+ const offCanvas = new OffscreenCanvas(width * devicePixelRatio, height * devicePixelRatio);
1043
1085
  const offRenderCtx = offCanvas.getContext("2d");
1044
1086
  const offCtx = offRenderCtx.canvas.getContext("2d");
1045
- return offCtx;
1087
+ const context2d = new Context2D(offCtx, {
1088
+ devicePixelRatio,
1089
+ offscreenCanvas: offCanvas
1090
+ });
1091
+ return context2d;
1046
1092
  }
1047
- function createBoardContexts(ctx, opts) {
1093
+ function createViewContent(canvas, opts) {
1094
+ const { width, height, devicePixelRatio, offscreen } = opts;
1048
1095
  const ctxOpts = {
1049
- width: ctx.canvas.width,
1050
- height: ctx.canvas.height,
1051
- devicePixelRatio: (opts == null ? void 0 : opts.devicePixelRatio) || 1
1096
+ width,
1097
+ height,
1098
+ devicePixelRatio
1052
1099
  };
1053
- const viewContext = createContext2D(ctxOpts);
1054
- const helperContext = createContext2D(ctxOpts);
1055
- const underContext = createContext2D(ctxOpts);
1056
- const boardContext = createContext2D({ ctx, ...ctxOpts });
1057
- const content = {
1058
- underContext,
1059
- viewContext,
1060
- helperContext,
1061
- boardContext
1062
- };
1063
- return content;
1100
+ if (offscreen === true) {
1101
+ const ctx = canvas.getContext("2d");
1102
+ const viewContext = createOffscreenContext2D(ctxOpts);
1103
+ const helperContext = createOffscreenContext2D(ctxOpts);
1104
+ const underContext = createOffscreenContext2D(ctxOpts);
1105
+ const boardContext = createContext2D({ ctx, ...ctxOpts });
1106
+ const drawView = () => {
1107
+ const { width: w2, height: h2 } = viewContext.$getSize();
1108
+ boardContext.clearRect(0, 0, w2, h2);
1109
+ boardContext.drawImage(underContext.canvas, 0, 0, w2, h2);
1110
+ boardContext.drawImage(viewContext.canvas, 0, 0, w2, h2);
1111
+ boardContext.drawImage(helperContext.canvas, 0, 0, w2, h2);
1112
+ underContext.clearRect(0, 0, w2, h2);
1113
+ viewContext.clearRect(0, 0, w2, h2);
1114
+ helperContext.clearRect(0, 0, w2, h2);
1115
+ };
1116
+ const content = {
1117
+ underContext,
1118
+ viewContext,
1119
+ helperContext,
1120
+ boardContext,
1121
+ drawView
1122
+ };
1123
+ return content;
1124
+ } else {
1125
+ const ctx = canvas.getContext("2d");
1126
+ const viewContext = createContext2D(ctxOpts);
1127
+ const helperContext = createContext2D(ctxOpts);
1128
+ const underContext = createContext2D(ctxOpts);
1129
+ const boardContext = createContext2D({ ctx, ...ctxOpts });
1130
+ const drawView = () => {
1131
+ boardContext.clearRect(0, 0, width, height);
1132
+ boardContext.drawImage(underContext.canvas, 0, 0, width, height);
1133
+ boardContext.drawImage(viewContext.canvas, 0, 0, width, height);
1134
+ boardContext.drawImage(helperContext.canvas, 0, 0, width, height);
1135
+ underContext.clearRect(0, 0, width, height);
1136
+ viewContext.clearRect(0, 0, width, height);
1137
+ helperContext.clearRect(0, 0, width, height);
1138
+ };
1139
+ const content = {
1140
+ underContext,
1141
+ viewContext,
1142
+ helperContext,
1143
+ boardContext,
1144
+ drawView
1145
+ };
1146
+ return content;
1147
+ }
1064
1148
  }
1065
1149
  class EventEmitter {
1066
1150
  constructor() {
@@ -1556,51 +1640,6 @@ var iDrawUtil = function(exports) {
1556
1640
  _scan(uuid, elements);
1557
1641
  return groupQueue;
1558
1642
  }
1559
- function mergeElement(originElem, updateContent) {
1560
- var _a;
1561
- const commonKeys = Object.keys(updateContent);
1562
- for (let i = 0; i < commonKeys.length; i++) {
1563
- const commonKey = commonKeys[i];
1564
- if (["x", "y", "w", "h", "angle", "name"].includes(commonKey)) {
1565
- originElem[commonKey] = updateContent[commonKey];
1566
- } else if (["detail", "operations"].includes(commonKey)) {
1567
- if (istype.json(updateContent[commonKey])) {
1568
- if (!(originElem == null ? void 0 : originElem.hasOwnProperty(commonKey))) {
1569
- originElem[commonKey] = {};
1570
- }
1571
- if (istype.json(originElem[commonKey])) {
1572
- originElem[commonKey] = { ...originElem[commonKey], ...updateContent[commonKey] };
1573
- }
1574
- } else if (istype.array(updateContent[commonKey])) {
1575
- if (!(originElem == null ? void 0 : originElem.hasOwnProperty(commonKey))) {
1576
- originElem[commonKey] = [];
1577
- }
1578
- if (istype.array(originElem[commonKey])) {
1579
- (_a = updateContent == null ? void 0 : updateContent[commonKey]) == null ? void 0 : _a.forEach((item, i2) => {
1580
- originElem[commonKey][i2] = item;
1581
- });
1582
- originElem[commonKey] = [...originElem[commonKey], ...updateContent[commonKey]];
1583
- }
1584
- }
1585
- }
1586
- }
1587
- return originElem;
1588
- }
1589
- function updateElementInList(uuid, updateContent, elements) {
1590
- var _a;
1591
- let targetElement = null;
1592
- for (let i = 0; i < elements.length; i++) {
1593
- const elem = elements[i];
1594
- if (elem.uuid === uuid) {
1595
- mergeElement(elem, updateContent);
1596
- targetElement = elem;
1597
- break;
1598
- } else if (elem.type === "group") {
1599
- targetElement = updateElementInList(uuid, updateContent, ((_a = elem == null ? void 0 : elem.detail) == null ? void 0 : _a.children) || []);
1600
- }
1601
- }
1602
- return targetElement;
1603
- }
1604
1643
  function getElementSize(elem) {
1605
1644
  const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = elem;
1606
1645
  const size = { x: x2, y: y2, w: w2, h: h2, angle: angle2 };
@@ -1691,52 +1730,30 @@ var iDrawUtil = function(exports) {
1691
1730
  }
1692
1731
  return result;
1693
1732
  }
1694
- function insertElementToListByPosition(element, position, list) {
1695
- let result = false;
1696
- if (position.length === 1) {
1697
- const pos = position[0];
1698
- list.splice(pos, 0, element);
1699
- result = true;
1700
- } else if (position.length > 1) {
1701
- let tempList = list;
1702
- for (let i = 0; i < position.length; i++) {
1703
- const pos = position[i];
1704
- const item = tempList[pos];
1705
- if (i === position.length - 1) {
1706
- const pos2 = position[i];
1707
- tempList.splice(pos2, 0, element);
1708
- result = true;
1709
- } else if (i < position.length - 1 && item.type === "group") {
1710
- tempList = item.detail.children;
1711
- } else {
1733
+ function getElementPositionFromList(uuid, elements) {
1734
+ let result = [];
1735
+ let over = false;
1736
+ const _loop = (list) => {
1737
+ var _a;
1738
+ for (let i = 0; i < list.length; i++) {
1739
+ if (over === true) {
1712
1740
  break;
1713
1741
  }
1714
- }
1715
- }
1716
- return result;
1717
- }
1718
- function deleteElementInListByPosition(position, list) {
1719
- let result = false;
1720
- if (position.length === 1) {
1721
- const pos = position[0];
1722
- list.splice(pos, 1);
1723
- result = true;
1724
- } else if (position.length > 1) {
1725
- let tempList = list;
1726
- for (let i = 0; i < position.length; i++) {
1727
- const pos = position[i];
1728
- const item = tempList[pos];
1729
- if (i === position.length - 1) {
1730
- const pos2 = position[i];
1731
- tempList.splice(pos2, 1);
1732
- result = true;
1733
- } else if (i < position.length - 1 && item.type === "group") {
1734
- tempList = item.detail.children;
1735
- } else {
1742
+ result.push(i);
1743
+ const elem = list[i];
1744
+ if (elem.uuid === uuid) {
1745
+ over = true;
1736
1746
  break;
1747
+ } else if (elem.type === "group") {
1748
+ _loop(((_a = elem == null ? void 0 : elem.detail) == null ? void 0 : _a.children) || []);
1737
1749
  }
1750
+ if (over) {
1751
+ break;
1752
+ }
1753
+ result.pop();
1738
1754
  }
1739
- }
1755
+ };
1756
+ _loop(elements);
1740
1757
  return result;
1741
1758
  }
1742
1759
  function checkRectIntersect(rect1, rect2) {
@@ -2532,6 +2549,58 @@ var iDrawUtil = function(exports) {
2532
2549
  };
2533
2550
  return elem;
2534
2551
  }
2552
+ function insertElementToListByPosition(element, position, list) {
2553
+ let result = false;
2554
+ if (position.length === 1) {
2555
+ const pos = position[0];
2556
+ list.splice(pos, 0, element);
2557
+ result = true;
2558
+ } else if (position.length > 1) {
2559
+ let tempList = list;
2560
+ for (let i = 0; i < position.length; i++) {
2561
+ const pos = position[i];
2562
+ const item = tempList[pos];
2563
+ if (i === position.length - 1) {
2564
+ const pos2 = position[i];
2565
+ tempList.splice(pos2, 0, element);
2566
+ result = true;
2567
+ } else if (i < position.length - 1 && item.type === "group") {
2568
+ tempList = item.detail.children;
2569
+ } else {
2570
+ break;
2571
+ }
2572
+ }
2573
+ }
2574
+ return result;
2575
+ }
2576
+ function deleteElementInListByPosition(position, list) {
2577
+ let result = false;
2578
+ if (position.length === 1) {
2579
+ const pos = position[0];
2580
+ list.splice(pos, 1);
2581
+ result = true;
2582
+ } else if (position.length > 1) {
2583
+ let tempList = list;
2584
+ for (let i = 0; i < position.length; i++) {
2585
+ const pos = position[i];
2586
+ const item = tempList[pos];
2587
+ if (i === position.length - 1) {
2588
+ const pos2 = position[i];
2589
+ tempList.splice(pos2, 1);
2590
+ result = true;
2591
+ } else if (i < position.length - 1 && item.type === "group") {
2592
+ tempList = item.detail.children;
2593
+ } else {
2594
+ break;
2595
+ }
2596
+ }
2597
+ }
2598
+ return result;
2599
+ }
2600
+ function deleteElementInList(uuid, list) {
2601
+ const position = getElementPositionFromList(uuid, list);
2602
+ return deleteElementInListByPosition(position, list);
2603
+ }
2535
2604
  function moveElementPosition(elements, opts) {
2536
2605
  const { from, to } = opts;
2537
2606
  if (from.length === 0 || to.length === 0) {
@@ -2574,6 +2643,51 @@ var iDrawUtil = function(exports) {
2574
2643
  }
2575
2644
  return elements;
2576
2645
  }
2646
+ function mergeElement(originElem, updateContent) {
2647
+ var _a;
2648
+ const commonKeys = Object.keys(updateContent);
2649
+ for (let i = 0; i < commonKeys.length; i++) {
2650
+ const commonKey = commonKeys[i];
2651
+ if (["x", "y", "w", "h", "angle", "name"].includes(commonKey)) {
2652
+ originElem[commonKey] = updateContent[commonKey];
2653
+ } else if (["detail", "operations"].includes(commonKey)) {
2654
+ if (istype.json(updateContent[commonKey])) {
2655
+ if (!(originElem == null ? void 0 : originElem.hasOwnProperty(commonKey))) {
2656
+ originElem[commonKey] = {};
2657
+ }
2658
+ if (istype.json(originElem[commonKey])) {
2659
+ originElem[commonKey] = { ...originElem[commonKey], ...updateContent[commonKey] };
2660
+ }
2661
+ } else if (istype.array(updateContent[commonKey])) {
2662
+ if (!(originElem == null ? void 0 : originElem.hasOwnProperty(commonKey))) {
2663
+ originElem[commonKey] = [];
2664
+ }
2665
+ if (istype.array(originElem[commonKey])) {
2666
+ (_a = updateContent == null ? void 0 : updateContent[commonKey]) == null ? void 0 : _a.forEach((item, i2) => {
2667
+ originElem[commonKey][i2] = item;
2668
+ });
2669
+ originElem[commonKey] = [...originElem[commonKey], ...updateContent[commonKey]];
2670
+ }
2671
+ }
2672
+ }
2673
+ }
2674
+ return originElem;
2675
+ }
2676
+ function updateElementInList(uuid, updateContent, elements) {
2677
+ var _a;
2678
+ let targetElement = null;
2679
+ for (let i = 0; i < elements.length; i++) {
2680
+ const elem = elements[i];
2681
+ if (elem.uuid === uuid) {
2682
+ mergeElement(elem, updateContent);
2683
+ targetElement = elem;
2684
+ break;
2685
+ } else if (elem.type === "group") {
2686
+ targetElement = updateElementInList(uuid, updateContent, ((_a = elem == null ? void 0 : elem.detail) == null ? void 0 : _a.children) || []);
2687
+ }
2688
+ }
2689
+ return targetElement;
2690
+ }
2577
2691
  exports.Context2D = Context2D;
2578
2692
  exports.EventEmitter = EventEmitter;
2579
2693
  exports.Store = Store;
@@ -2600,13 +2714,15 @@ var iDrawUtil = function(exports) {
2600
2714
  exports.compose = compose;
2601
2715
  exports.compressImage = compressImage;
2602
2716
  exports.createAssetId = createAssetId;
2603
- exports.createBoardContexts = createBoardContexts;
2604
2717
  exports.createContext2D = createContext2D;
2605
2718
  exports.createElement = createElement;
2606
2719
  exports.createOffscreenContext2D = createOffscreenContext2D;
2607
2720
  exports.createUUID = createUUID;
2721
+ exports.createViewContent = createViewContent;
2608
2722
  exports.deepClone = deepClone;
2609
2723
  exports.delay = delay;
2724
+ exports.deleteElementInList = deleteElementInList;
2725
+ exports.deleteElementInListByPosition = deleteElementInListByPosition;
2610
2726
  exports.downloadImageFromCanvas = downloadImageFromCanvas;
2611
2727
  exports.equalPoint = equalPoint;
2612
2728
  exports.equalTouchPoint = equalTouchPoint;
@@ -2622,6 +2738,7 @@ var iDrawUtil = function(exports) {
2622
2738
  exports.getDefaultElementDetailConfig = getDefaultElementDetailConfig;
2623
2739
  exports.getDefaultElementRectDetail = getDefaultElementRectDetail;
2624
2740
  exports.getElemenetsAssetIds = getElemenetsAssetIds;
2741
+ exports.getElementPositionFromList = getElementPositionFromList;
2625
2742
  exports.getElementRotateVertexes = getElementRotateVertexes;
2626
2743
  exports.getElementSize = getElementSize;
2627
2744
  exports.getElementVertexes = getElementVertexes;
@@ -2630,6 +2747,7 @@ var iDrawUtil = function(exports) {
2630
2747
  exports.getViewPointAtElement = getViewPointAtElement;
2631
2748
  exports.getViewScaleInfoFromSnapshot = getViewScaleInfoFromSnapshot;
2632
2749
  exports.getViewSizeInfoFromSnapshot = getViewSizeInfoFromSnapshot;
2750
+ exports.insertElementToListByPosition = insertElementToListByPosition;
2633
2751
  exports.is = is;
2634
2752
  exports.isAssetId = isAssetId;
2635
2753
  exports.isColorStr = isColorStr;