@inweb/markup 25.7.9 → 25.8.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.
@@ -866,31 +866,37 @@ const MarkupMode2Konva = {
866
866
  },
867
867
  Line: {
868
868
  name: "Line",
869
- initializer: ref => new KonvaLine(null, ref)
869
+ initializer: (ref, params = null) => new KonvaLine(params, ref),
870
+ zIndex: 1
870
871
  },
871
872
  Text: {
872
873
  name: "Text",
873
- initializer: ref => new KonvaText(null, ref)
874
+ initializer: (ref, params = null) => new KonvaText(params, ref)
874
875
  },
875
876
  Rectangle: {
876
877
  name: "Rect",
877
- initializer: ref => new KonvaRectangle(null, ref)
878
+ initializer: (ref, params = null) => new KonvaRectangle(params, ref),
879
+ zIndex: 1
878
880
  },
879
881
  Ellipse: {
880
882
  name: "Ellipse",
881
- initializer: ref => new KonvaEllipse(null, ref)
883
+ initializer: (ref, params = null) => new KonvaEllipse(params, ref),
884
+ zIndex: 1
882
885
  },
883
886
  Arrow: {
884
887
  name: "Arrow",
885
- initializer: ref => new KonvaArrow(null, ref)
888
+ initializer: (ref, params = null) => new KonvaArrow(params, ref),
889
+ zIndex: 1
886
890
  },
887
891
  Image: {
888
892
  name: "Image",
889
- initializer: ref => new KonvaImage(null, ref)
893
+ initializer: (ref, params = null) => new KonvaImage(params, ref),
894
+ zIndex: 0
890
895
  },
891
896
  Cloud: {
892
897
  name: "Cloud",
893
- initializer: ref => new KonvaCloud(null, ref)
898
+ initializer: ref => new KonvaCloud(null, ref),
899
+ zIndex: 1
894
900
  }
895
901
  };
896
902
 
@@ -909,14 +915,7 @@ class KonvaMarkup {
909
915
  this._markupContainer.className = this._container.className.split(" ").filter((x => !x.startsWith("oda-cursor-"))).filter((x => x)).concat(`oda-cursor-${draggerName.toLowerCase()}`).join(" ");
910
916
  this.removeTextInput();
911
917
  this.removeImageInput();
912
- const konvaShape = MarkupMode2Konva[draggerName];
913
- if (konvaShape) {
914
- this._markupMode = draggerName;
915
- this._markupIsActive = true;
916
- } else {
917
- this._markupIsActive = false;
918
- this._konvaTransformer.nodes([]);
919
- }
918
+ this.enableEditMode(draggerName);
920
919
  };
921
920
  this.resizeContainer = entries => {
922
921
  var _a, _b;
@@ -928,10 +927,10 @@ class KonvaMarkup {
928
927
  this.pan = event => {
929
928
  const dX = event.dX / window.devicePixelRatio;
930
929
  const dY = event.dY / window.devicePixelRatio;
931
- Object.keys(MarkupMode2Konva).forEach((mode => this.konvaLayerFind(mode).forEach((ref => ref.move({
930
+ this.getObjects().forEach((obj => obj.ref().move({
932
931
  x: dX,
933
932
  y: dY
934
- })))));
933
+ })));
935
934
  };
936
935
  this.redirectToViewer = event => {
937
936
  if (this._viewer) this._viewer.emit(event);
@@ -984,8 +983,8 @@ class KonvaMarkup {
984
983
  clearOverlay() {
985
984
  this.removeTextInput();
986
985
  this.removeImageInput();
987
- this._konvaTransformer.nodes([]);
988
- Object.keys(MarkupMode2Konva).forEach((mode => this.konvaLayerFind(mode).forEach((ref => ref.destroy()))));
986
+ this.clearSelected();
987
+ this.getObjects().forEach((obj => obj.ref().destroy()));
989
988
  }
990
989
  getMarkupColor() {
991
990
  return this._markupColor.RGB;
@@ -993,23 +992,19 @@ class KonvaMarkup {
993
992
  setMarkupColor(r, g, b) {
994
993
  this._markupColor.setColor(r, g, b);
995
994
  }
996
- colorizeAllMarkup(r = 255, g = 0, b = 0) {
997
- const hex = new MarkupColor(r, g, b).HexColor;
998
- Object.keys(MarkupMode2Konva).forEach((mode => {
999
- this.konvaLayerFind(mode).forEach((ref => {
1000
- const konvaShape = MarkupMode2Konva[mode];
1001
- const konvaObj = konvaShape.initializer(ref);
1002
- if (konvaObj.setColor) konvaObj.setColor(hex);
1003
- }));
995
+ colorizeAllMarkup(r, g, b) {
996
+ const hexColor = new MarkupColor(r, g, b).HexColor;
997
+ this.getObjects().forEach((obj => {
998
+ const colorable = obj;
999
+ if (colorable && colorable.setColor) colorable.setColor(hexColor);
1004
1000
  }));
1005
1001
  this._konvaLayer.draw();
1006
1002
  }
1007
1003
  colorizeSelectedMarkups(r, g, b) {
1004
+ const hexColor = new MarkupColor(r, g, b).HexColor;
1008
1005
  this.getSelectedObjects().forEach((obj => {
1009
1006
  const colorable = obj;
1010
- if (colorable && colorable.setColor) {
1011
- colorable.setColor(new MarkupColor(r, g, b).HexColor);
1012
- }
1007
+ if (colorable && colorable.setColor) colorable.setColor(hexColor);
1013
1008
  }));
1014
1009
  }
1015
1010
  setViewpoint(viewpoint) {
@@ -1041,111 +1036,40 @@ class KonvaMarkup {
1041
1036
  viewpoint.description = (new Date).toDateString();
1042
1037
  return viewpoint;
1043
1038
  }
1044
- createObject(type, params) {
1045
- let object = null;
1046
- let zIndex = this._zIndex;
1047
- switch (type.toLocaleLowerCase()) {
1048
- case "line":
1049
- object = new KonvaLine(params);
1050
- zIndex = 1;
1051
- break;
1052
-
1053
- case "text":
1054
- object = new KonvaText(params);
1055
- break;
1056
-
1057
- case "rectangle":
1058
- object = new KonvaRectangle(params);
1059
- zIndex = 1;
1060
- break;
1061
-
1062
- case "ellipse":
1063
- object = new KonvaEllipse(params);
1064
- zIndex = 1;
1065
- break;
1066
-
1067
- case "arrow":
1068
- object = new KonvaArrow(params);
1069
- break;
1070
-
1071
- case "image":
1072
- object = new KonvaImage(params);
1073
- zIndex = 0;
1074
- break;
1075
-
1076
- case "cloud":
1077
- object = new KonvaCloud(params);
1078
- zIndex = 1;
1079
- break;
1080
-
1081
- default:
1082
- throw new Error("Markup CreateObject - unsupported type has been detected.");
1039
+ enableEditMode(mode) {
1040
+ if (!mode || !MarkupMode2Konva[mode]) {
1041
+ this.clearSelected();
1042
+ this._markupIsActive = false;
1043
+ } else {
1044
+ this._markupMode = mode;
1045
+ this._markupIsActive = true;
1083
1046
  }
1047
+ return this;
1048
+ }
1049
+ createObject(type, params) {
1050
+ var _a;
1051
+ const konvaShape = MarkupMode2Konva[type];
1052
+ if (!konvaShape || !konvaShape.initializer) throw new Error(`Markup CreateObject - unsupported markup type ${type}`);
1053
+ const object = konvaShape.initializer(null, params);
1084
1054
  this.addObject(object);
1085
- object.setZIndex(zIndex);
1055
+ object.setZIndex((_a = konvaShape.zIndex) !== null && _a !== void 0 ? _a : this._zIndex);
1086
1056
  this._zIndex++;
1087
1057
  return object;
1088
1058
  }
1089
1059
  getObjects() {
1090
1060
  const objects = [];
1091
- this.konvaLayerFind("Line").forEach((line => {
1092
- objects.push(new KonvaLine(null, line));
1093
- }));
1094
- this.konvaLayerFind("Text").forEach((text => {
1095
- objects.push(new KonvaText(null, text));
1096
- }));
1097
- this.konvaLayerFind("Rectangle").forEach((rectangle => {
1098
- objects.push(new KonvaRectangle(null, rectangle));
1099
- }));
1100
- this.konvaLayerFind("Ellipse").forEach((ellipse => {
1101
- objects.push(new KonvaEllipse(null, ellipse));
1102
- }));
1103
- this.konvaLayerFind("Arrow").forEach((arrow => {
1104
- objects.push(new KonvaArrow(null, arrow));
1105
- }));
1106
- this.konvaLayerFind("Image").forEach((image => {
1107
- objects.push(new KonvaImage(null, image));
1108
- }));
1109
- this.konvaLayerFind("Cloud").forEach((cloud => {
1110
- objects.push(new KonvaCloud(null, cloud));
1061
+ Object.keys(MarkupMode2Konva).forEach((type => {
1062
+ const konvaShape = MarkupMode2Konva[type];
1063
+ this.konvaLayerFind(type).forEach((ref => objects.push(konvaShape.initializer(ref))));
1111
1064
  }));
1112
1065
  return objects;
1113
1066
  }
1114
1067
  getSelectedObjects() {
1115
- const objects = [];
1116
- this._konvaTransformer.nodes().forEach((obj => {
1117
- const konvaShapeName = obj.className;
1118
- switch (konvaShapeName) {
1119
- case "Line":
1120
- objects.push(new KonvaLine(null, obj));
1121
- break;
1122
-
1123
- case "Text":
1124
- objects.push(new KonvaText(null, obj));
1125
- break;
1126
-
1127
- case "Rect":
1128
- objects.push(new KonvaRectangle(null, obj));
1129
- break;
1130
-
1131
- case "Ellipse":
1132
- objects.push(new KonvaEllipse(null, obj));
1133
- break;
1134
-
1135
- case "Arrow":
1136
- objects.push(new KonvaArrow(null, obj));
1137
- break;
1138
-
1139
- case "Image":
1140
- objects.push(new KonvaImage(null, obj));
1141
- break;
1142
-
1143
- case "Cloud":
1144
- objects.push(new KonvaCloud(null, obj));
1145
- break;
1146
- }
1147
- }));
1148
- return objects;
1068
+ return this._konvaTransformer.nodes().map((ref => {
1069
+ const name = ref.className;
1070
+ const konvaShape = Object.values(MarkupMode2Konva).find((shape => shape.name === name));
1071
+ return konvaShape ? konvaShape.initializer(ref) : null;
1072
+ })).filter((x => x));
1149
1073
  }
1150
1074
  selectObjects(objects) {
1151
1075
  const selectedObjs = this._konvaTransformer.nodes().concat(objects.map((x => x.ref())));
@@ -1208,8 +1132,8 @@ class KonvaMarkup {
1208
1132
  addObject(object) {
1209
1133
  this._konvaLayer.add(object.ref());
1210
1134
  }
1211
- konvaLayerFind(markupShape) {
1212
- const konvaShape = MarkupMode2Konva[markupShape];
1135
+ konvaLayerFind(type) {
1136
+ const konvaShape = MarkupMode2Konva[type];
1213
1137
  if (konvaShape && konvaShape.initializer) {
1214
1138
  return this._konvaLayer.find(konvaShape.name).filter((ref => ref.parent === this._konvaLayer));
1215
1139
  }