@inweb/viewer-visualize 25.7.10 → 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.
@@ -13009,31 +13009,37 @@
13009
13009
  },
13010
13010
  Line: {
13011
13011
  name: "Line",
13012
- initializer: ref => new KonvaLine(null, ref)
13012
+ initializer: (ref, params = null) => new KonvaLine(params, ref),
13013
+ zIndex: 1
13013
13014
  },
13014
13015
  Text: {
13015
13016
  name: "Text",
13016
- initializer: ref => new KonvaText(null, ref)
13017
+ initializer: (ref, params = null) => new KonvaText(params, ref)
13017
13018
  },
13018
13019
  Rectangle: {
13019
13020
  name: "Rect",
13020
- initializer: ref => new KonvaRectangle(null, ref)
13021
+ initializer: (ref, params = null) => new KonvaRectangle(params, ref),
13022
+ zIndex: 1
13021
13023
  },
13022
13024
  Ellipse: {
13023
13025
  name: "Ellipse",
13024
- initializer: ref => new KonvaEllipse(null, ref)
13026
+ initializer: (ref, params = null) => new KonvaEllipse(params, ref),
13027
+ zIndex: 1
13025
13028
  },
13026
13029
  Arrow: {
13027
13030
  name: "Arrow",
13028
- initializer: ref => new KonvaArrow(null, ref)
13031
+ initializer: (ref, params = null) => new KonvaArrow(params, ref),
13032
+ zIndex: 1
13029
13033
  },
13030
13034
  Image: {
13031
13035
  name: "Image",
13032
- initializer: ref => new KonvaImage(null, ref)
13036
+ initializer: (ref, params = null) => new KonvaImage(params, ref),
13037
+ zIndex: 0
13033
13038
  },
13034
13039
  Cloud: {
13035
13040
  name: "Cloud",
13036
- initializer: ref => new KonvaCloud(null, ref)
13041
+ initializer: ref => new KonvaCloud(null, ref),
13042
+ zIndex: 1
13037
13043
  }
13038
13044
  };
13039
13045
 
@@ -13064,10 +13070,10 @@
13064
13070
  this.pan = event => {
13065
13071
  const dX = event.dX / window.devicePixelRatio;
13066
13072
  const dY = event.dY / window.devicePixelRatio;
13067
- Object.keys(MarkupMode2Konva).forEach((mode => this.konvaLayerFind(mode).forEach((ref => ref.move({
13073
+ this.getObjects().forEach((obj => obj.ref().move({
13068
13074
  x: dX,
13069
13075
  y: dY
13070
- })))));
13076
+ })));
13071
13077
  };
13072
13078
  this.redirectToViewer = event => {
13073
13079
  if (this._viewer) this._viewer.emit(event);
@@ -13120,8 +13126,8 @@
13120
13126
  clearOverlay() {
13121
13127
  this.removeTextInput();
13122
13128
  this.removeImageInput();
13123
- this._konvaTransformer.nodes([]);
13124
- Object.keys(MarkupMode2Konva).forEach((mode => this.konvaLayerFind(mode).forEach((ref => ref.destroy()))));
13129
+ this.clearSelected();
13130
+ this.getObjects().forEach((obj => obj.ref().destroy()));
13125
13131
  }
13126
13132
  getMarkupColor() {
13127
13133
  return this._markupColor.RGB;
@@ -13129,23 +13135,19 @@
13129
13135
  setMarkupColor(r, g, b) {
13130
13136
  this._markupColor.setColor(r, g, b);
13131
13137
  }
13132
- colorizeAllMarkup(r = 255, g = 0, b = 0) {
13133
- const hex = new MarkupColor(r, g, b).HexColor;
13134
- Object.keys(MarkupMode2Konva).forEach((mode => {
13135
- this.konvaLayerFind(mode).forEach((ref => {
13136
- const konvaShape = MarkupMode2Konva[mode];
13137
- const konvaObj = konvaShape.initializer(ref);
13138
- if (konvaObj.setColor) konvaObj.setColor(hex);
13139
- }));
13138
+ colorizeAllMarkup(r, g, b) {
13139
+ const hexColor = new MarkupColor(r, g, b).HexColor;
13140
+ this.getObjects().forEach((obj => {
13141
+ const colorable = obj;
13142
+ if (colorable && colorable.setColor) colorable.setColor(hexColor);
13140
13143
  }));
13141
13144
  this._konvaLayer.draw();
13142
13145
  }
13143
13146
  colorizeSelectedMarkups(r, g, b) {
13147
+ const hexColor = new MarkupColor(r, g, b).HexColor;
13144
13148
  this.getSelectedObjects().forEach((obj => {
13145
13149
  const colorable = obj;
13146
- if (colorable && colorable.setColor) {
13147
- colorable.setColor(new MarkupColor(r, g, b).HexColor);
13148
- }
13150
+ if (colorable && colorable.setColor) colorable.setColor(hexColor);
13149
13151
  }));
13150
13152
  }
13151
13153
  setViewpoint(viewpoint) {
@@ -13188,110 +13190,29 @@
13188
13190
  return this;
13189
13191
  }
13190
13192
  createObject(type, params) {
13191
- let object = null;
13192
- let zIndex = this._zIndex;
13193
- switch (type.toLocaleLowerCase()) {
13194
- case "line":
13195
- object = new KonvaLine(params);
13196
- zIndex = 1;
13197
- break;
13198
-
13199
- case "text":
13200
- object = new KonvaText(params);
13201
- break;
13202
-
13203
- case "rectangle":
13204
- object = new KonvaRectangle(params);
13205
- zIndex = 1;
13206
- break;
13207
-
13208
- case "ellipse":
13209
- object = new KonvaEllipse(params);
13210
- zIndex = 1;
13211
- break;
13212
-
13213
- case "arrow":
13214
- object = new KonvaArrow(params);
13215
- break;
13216
-
13217
- case "image":
13218
- object = new KonvaImage(params);
13219
- zIndex = 0;
13220
- break;
13221
-
13222
- case "cloud":
13223
- object = new KonvaCloud(params);
13224
- zIndex = 1;
13225
- break;
13226
-
13227
- default:
13228
- throw new Error("Markup CreateObject - unsupported type has been detected.");
13229
- }
13193
+ var _a;
13194
+ const konvaShape = MarkupMode2Konva[type];
13195
+ if (!konvaShape || !konvaShape.initializer) throw new Error(`Markup CreateObject - unsupported markup type ${type}`);
13196
+ const object = konvaShape.initializer(null, params);
13230
13197
  this.addObject(object);
13231
- object.setZIndex(zIndex);
13198
+ object.setZIndex((_a = konvaShape.zIndex) !== null && _a !== void 0 ? _a : this._zIndex);
13232
13199
  this._zIndex++;
13233
13200
  return object;
13234
13201
  }
13235
13202
  getObjects() {
13236
13203
  const objects = [];
13237
- this.konvaLayerFind("Line").forEach((line => {
13238
- objects.push(new KonvaLine(null, line));
13239
- }));
13240
- this.konvaLayerFind("Text").forEach((text => {
13241
- objects.push(new KonvaText(null, text));
13242
- }));
13243
- this.konvaLayerFind("Rectangle").forEach((rectangle => {
13244
- objects.push(new KonvaRectangle(null, rectangle));
13245
- }));
13246
- this.konvaLayerFind("Ellipse").forEach((ellipse => {
13247
- objects.push(new KonvaEllipse(null, ellipse));
13248
- }));
13249
- this.konvaLayerFind("Arrow").forEach((arrow => {
13250
- objects.push(new KonvaArrow(null, arrow));
13251
- }));
13252
- this.konvaLayerFind("Image").forEach((image => {
13253
- objects.push(new KonvaImage(null, image));
13254
- }));
13255
- this.konvaLayerFind("Cloud").forEach((cloud => {
13256
- objects.push(new KonvaCloud(null, cloud));
13204
+ Object.keys(MarkupMode2Konva).forEach((type => {
13205
+ const konvaShape = MarkupMode2Konva[type];
13206
+ this.konvaLayerFind(type).forEach((ref => objects.push(konvaShape.initializer(ref))));
13257
13207
  }));
13258
13208
  return objects;
13259
13209
  }
13260
13210
  getSelectedObjects() {
13261
- const objects = [];
13262
- this._konvaTransformer.nodes().forEach((obj => {
13263
- const konvaShapeName = obj.className;
13264
- switch (konvaShapeName) {
13265
- case "Line":
13266
- objects.push(new KonvaLine(null, obj));
13267
- break;
13268
-
13269
- case "Text":
13270
- objects.push(new KonvaText(null, obj));
13271
- break;
13272
-
13273
- case "Rect":
13274
- objects.push(new KonvaRectangle(null, obj));
13275
- break;
13276
-
13277
- case "Ellipse":
13278
- objects.push(new KonvaEllipse(null, obj));
13279
- break;
13280
-
13281
- case "Arrow":
13282
- objects.push(new KonvaArrow(null, obj));
13283
- break;
13284
-
13285
- case "Image":
13286
- objects.push(new KonvaImage(null, obj));
13287
- break;
13288
-
13289
- case "Cloud":
13290
- objects.push(new KonvaCloud(null, obj));
13291
- break;
13292
- }
13293
- }));
13294
- return objects;
13211
+ return this._konvaTransformer.nodes().map((ref => {
13212
+ const name = ref.className;
13213
+ const konvaShape = Object.values(MarkupMode2Konva).find((shape => shape.name === name));
13214
+ return konvaShape ? konvaShape.initializer(ref) : null;
13215
+ })).filter((x => x));
13295
13216
  }
13296
13217
  selectObjects(objects) {
13297
13218
  const selectedObjs = this._konvaTransformer.nodes().concat(objects.map((x => x.ref())));
@@ -13354,8 +13275,8 @@
13354
13275
  addObject(object) {
13355
13276
  this._konvaLayer.add(object.ref());
13356
13277
  }
13357
- konvaLayerFind(markupShape) {
13358
- const konvaShape = MarkupMode2Konva[markupShape];
13278
+ konvaLayerFind(type) {
13279
+ const konvaShape = MarkupMode2Konva[type];
13359
13280
  if (konvaShape && konvaShape.initializer) {
13360
13281
  return this._konvaLayer.find(konvaShape.name).filter((ref => ref.parent === this._konvaLayer));
13361
13282
  }