@inweb/viewer-visualize 25.7.10 → 25.8.1

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.
@@ -12172,6 +12172,29 @@
12172
12172
  }
12173
12173
  }
12174
12174
 
12175
+ class WorldTransform {
12176
+ screenToWorld(position) {
12177
+ return {
12178
+ x: position.x,
12179
+ y: position.y,
12180
+ z: 0
12181
+ };
12182
+ }
12183
+ worldToScreen(position) {
12184
+ return {
12185
+ x: position.x,
12186
+ y: position.y
12187
+ };
12188
+ }
12189
+ getScale() {
12190
+ return {
12191
+ x: 1,
12192
+ y: 1,
12193
+ z: 1
12194
+ };
12195
+ }
12196
+ }
12197
+
12175
12198
  const LineTypeSpecs = new Map([ [ "solid", [] ], [ "dot", [ 30, 30, .001, 30 ] ], [ "dash", [ 30, 30 ] ] ]);
12176
12199
 
12177
12200
  class KonvaLine {
@@ -13009,31 +13032,37 @@
13009
13032
  },
13010
13033
  Line: {
13011
13034
  name: "Line",
13012
- initializer: ref => new KonvaLine(null, ref)
13035
+ initializer: (ref, params = null) => new KonvaLine(params, ref),
13036
+ zIndex: 1
13013
13037
  },
13014
13038
  Text: {
13015
13039
  name: "Text",
13016
- initializer: ref => new KonvaText(null, ref)
13040
+ initializer: (ref, params = null) => new KonvaText(params, ref)
13017
13041
  },
13018
13042
  Rectangle: {
13019
13043
  name: "Rect",
13020
- initializer: ref => new KonvaRectangle(null, ref)
13044
+ initializer: (ref, params = null) => new KonvaRectangle(params, ref),
13045
+ zIndex: 1
13021
13046
  },
13022
13047
  Ellipse: {
13023
13048
  name: "Ellipse",
13024
- initializer: ref => new KonvaEllipse(null, ref)
13049
+ initializer: (ref, params = null) => new KonvaEllipse(params, ref),
13050
+ zIndex: 1
13025
13051
  },
13026
13052
  Arrow: {
13027
13053
  name: "Arrow",
13028
- initializer: ref => new KonvaArrow(null, ref)
13054
+ initializer: (ref, params = null) => new KonvaArrow(params, ref),
13055
+ zIndex: 1
13029
13056
  },
13030
13057
  Image: {
13031
13058
  name: "Image",
13032
- initializer: ref => new KonvaImage(null, ref)
13059
+ initializer: (ref, params = null) => new KonvaImage(params, ref),
13060
+ zIndex: 0
13033
13061
  },
13034
13062
  Cloud: {
13035
13063
  name: "Cloud",
13036
- initializer: ref => new KonvaCloud(null, ref)
13064
+ initializer: ref => new KonvaCloud(null, ref),
13065
+ zIndex: 1
13037
13066
  }
13038
13067
  };
13039
13068
 
@@ -13064,10 +13093,10 @@
13064
13093
  this.pan = event => {
13065
13094
  const dX = event.dX / window.devicePixelRatio;
13066
13095
  const dY = event.dY / window.devicePixelRatio;
13067
- Object.keys(MarkupMode2Konva).forEach((mode => this.konvaLayerFind(mode).forEach((ref => ref.move({
13096
+ this.getObjects().forEach((obj => obj.ref().move({
13068
13097
  x: dX,
13069
13098
  y: dY
13070
- })))));
13099
+ })));
13071
13100
  };
13072
13101
  this.redirectToViewer = event => {
13073
13102
  if (this._viewer) this._viewer.emit(event);
@@ -13076,7 +13105,7 @@
13076
13105
  initialize(container, pointerEvents, viewer, worldTransformer) {
13077
13106
  if (!Konva) throw new Error('Markup: Error during initialization. Konva is not initialized. Update node_modules or add to your page <script src="https://unpkg.com/konva@9/konva.min.js"><\/script>');
13078
13107
  this._viewer = viewer;
13079
- this._worldTransformer = worldTransformer;
13108
+ this._worldTransformer = worldTransformer !== null && worldTransformer !== void 0 ? worldTransformer : new WorldTransform;
13080
13109
  this._container = container;
13081
13110
  this._pointerEvents = pointerEvents !== null && pointerEvents !== void 0 ? pointerEvents : [];
13082
13111
  this._markupContainer = document.createElement("div");
@@ -13120,8 +13149,8 @@
13120
13149
  clearOverlay() {
13121
13150
  this.removeTextInput();
13122
13151
  this.removeImageInput();
13123
- this._konvaTransformer.nodes([]);
13124
- Object.keys(MarkupMode2Konva).forEach((mode => this.konvaLayerFind(mode).forEach((ref => ref.destroy()))));
13152
+ this.clearSelected();
13153
+ this.getObjects().forEach((obj => obj.ref().destroy()));
13125
13154
  }
13126
13155
  getMarkupColor() {
13127
13156
  return this._markupColor.RGB;
@@ -13129,23 +13158,19 @@
13129
13158
  setMarkupColor(r, g, b) {
13130
13159
  this._markupColor.setColor(r, g, b);
13131
13160
  }
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
- }));
13161
+ colorizeAllMarkup(r, g, b) {
13162
+ const hexColor = new MarkupColor(r, g, b).HexColor;
13163
+ this.getObjects().forEach((obj => {
13164
+ const colorable = obj;
13165
+ if (colorable && colorable.setColor) colorable.setColor(hexColor);
13140
13166
  }));
13141
13167
  this._konvaLayer.draw();
13142
13168
  }
13143
13169
  colorizeSelectedMarkups(r, g, b) {
13170
+ const hexColor = new MarkupColor(r, g, b).HexColor;
13144
13171
  this.getSelectedObjects().forEach((obj => {
13145
13172
  const colorable = obj;
13146
- if (colorable && colorable.setColor) {
13147
- colorable.setColor(new MarkupColor(r, g, b).HexColor);
13148
- }
13173
+ if (colorable && colorable.setColor) colorable.setColor(hexColor);
13149
13174
  }));
13150
13175
  }
13151
13176
  setViewpoint(viewpoint) {
@@ -13188,110 +13213,29 @@
13188
13213
  return this;
13189
13214
  }
13190
13215
  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
- }
13216
+ var _a;
13217
+ const konvaShape = MarkupMode2Konva[type];
13218
+ if (!konvaShape || !konvaShape.initializer) throw new Error(`Markup CreateObject - unsupported markup type ${type}`);
13219
+ const object = konvaShape.initializer(null, params);
13230
13220
  this.addObject(object);
13231
- object.setZIndex(zIndex);
13221
+ object.setZIndex((_a = konvaShape.zIndex) !== null && _a !== void 0 ? _a : this._zIndex);
13232
13222
  this._zIndex++;
13233
13223
  return object;
13234
13224
  }
13235
13225
  getObjects() {
13236
13226
  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));
13227
+ Object.keys(MarkupMode2Konva).forEach((type => {
13228
+ const konvaShape = MarkupMode2Konva[type];
13229
+ this.konvaLayerFind(type).forEach((ref => objects.push(konvaShape.initializer(ref))));
13257
13230
  }));
13258
13231
  return objects;
13259
13232
  }
13260
13233
  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;
13234
+ return this._konvaTransformer.nodes().map((ref => {
13235
+ const name = ref.className;
13236
+ const konvaShape = Object.values(MarkupMode2Konva).find((shape => shape.name === name));
13237
+ return konvaShape ? konvaShape.initializer(ref) : null;
13238
+ })).filter((x => x));
13295
13239
  }
13296
13240
  selectObjects(objects) {
13297
13241
  const selectedObjs = this._konvaTransformer.nodes().concat(objects.map((x => x.ref())));
@@ -13300,13 +13244,6 @@
13300
13244
  clearSelected() {
13301
13245
  this._konvaTransformer.nodes([]);
13302
13246
  }
13303
- getPoint3dFromArray(array) {
13304
- return {
13305
- x: array[0],
13306
- y: array[1],
13307
- z: array[2]
13308
- };
13309
- }
13310
13247
  fillViewpointShapes(viewpoint) {
13311
13248
  const markupLines = this.getMarkupLines();
13312
13249
  if (markupLines && markupLines.length > 0) {
@@ -13354,8 +13291,8 @@
13354
13291
  addObject(object) {
13355
13292
  this._konvaLayer.add(object.ref());
13356
13293
  }
13357
- konvaLayerFind(markupShape) {
13358
- const konvaShape = MarkupMode2Konva[markupShape];
13294
+ konvaLayerFind(type) {
13295
+ const konvaShape = MarkupMode2Konva[type];
13359
13296
  if (konvaShape && konvaShape.initializer) {
13360
13297
  return this._konvaLayer.find(konvaShape.name).filter((ref => ref.parent === this._konvaLayer));
13361
13298
  }
@@ -13597,7 +13534,7 @@
13597
13534
  const konvaLine = new KonvaLine(null, line);
13598
13535
  lines.push({
13599
13536
  id: konvaLine.id(),
13600
- points: worldPoints.map((p => this.getPoint3dFromArray(p))),
13537
+ points: worldPoints,
13601
13538
  color: konvaLine.getColor() || "#ff0000",
13602
13539
  type: konvaLine.getLineType() || this.lineType,
13603
13540
  width: konvaLine.getLineWidth() || this.lineWidth
@@ -13611,14 +13548,15 @@
13611
13548
  const textScale = this._worldTransformer.getScale();
13612
13549
  this.konvaLayerFind("Text").forEach((text => {
13613
13550
  if (!text) return;
13614
- const position = this._worldTransformer.screenToWorld({
13551
+ const position = {
13615
13552
  x: text.x(),
13616
13553
  y: text.y()
13617
- });
13554
+ };
13555
+ const worldPoint = this._worldTransformer.screenToWorld(position);
13618
13556
  const shape = new KonvaText(null, text);
13619
13557
  texts.push({
13620
13558
  id: shape.id(),
13621
- position: this.getPoint3dFromArray(position),
13559
+ position: worldPoint,
13622
13560
  text: shape.getText(),
13623
13561
  text_size: textSize * textScale.y,
13624
13562
  angle: shape.getRotation(),
@@ -13636,7 +13574,7 @@
13636
13574
  const shape = new KonvaRectangle(null, rect);
13637
13575
  rectangles.push({
13638
13576
  id: shape.id(),
13639
- position: this.getPoint3dFromArray(worldPoint),
13577
+ position: worldPoint,
13640
13578
  width: shape.getWidth(),
13641
13579
  height: shape.getHeigth(),
13642
13580
  line_width: shape.getLineWidth(),
@@ -13653,7 +13591,7 @@
13653
13591
  const shape = new KonvaEllipse(null, ellipse);
13654
13592
  ellipses.push({
13655
13593
  id: shape.id(),
13656
- position: this.getPoint3dFromArray(worldPoint),
13594
+ position: worldPoint,
13657
13595
  radius: {
13658
13596
  x: ellipse.getRadiusX(),
13659
13597
  y: ellipse.getRadiusY()
@@ -13681,8 +13619,8 @@
13681
13619
  const shape = new KonvaArrow(null, arrow);
13682
13620
  arrows.push({
13683
13621
  id: shape.id(),
13684
- start: this.getPoint3dFromArray(worldStartPoint),
13685
- end: this.getPoint3dFromArray(worldEndPoint),
13622
+ start: worldStartPoint,
13623
+ end: worldEndPoint,
13686
13624
  color: shape.getColor()
13687
13625
  });
13688
13626
  }));
@@ -13696,7 +13634,7 @@
13696
13634
  const shape = new KonvaImage(null, image);
13697
13635
  images.push({
13698
13636
  id: shape.id(),
13699
- position: this.getPoint3dFromArray(worldPoint),
13637
+ position: worldPoint,
13700
13638
  src: shape.getSrc(),
13701
13639
  width: shape.getWidth(),
13702
13640
  height: shape.getHeight()
@@ -13712,7 +13650,7 @@
13712
13650
  const shape = new KonvaCloud(null, cloud);
13713
13651
  clouds.push({
13714
13652
  id: shape.id(),
13715
- position: this.getPoint3dFromArray(worldPoint),
13653
+ position: worldPoint,
13716
13654
  width: shape.getWidth(),
13717
13655
  height: shape.getHeigth(),
13718
13656
  line_width: shape.getLineWidth(),