@inweb/viewer-visualize 25.8.2 → 25.8.4

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.
@@ -13068,11 +13068,10 @@
13068
13068
 
13069
13069
  class KonvaMarkup {
13070
13070
  constructor() {
13071
- this._isInitialized = false;
13071
+ this._pointerEvents = [];
13072
13072
  this._markupIsActive = false;
13073
13073
  this._markupColor = new MarkupColor(255, 0, 0);
13074
13074
  this._zIndex = 1;
13075
- this._markupContainerName = "markupContainer";
13076
13075
  this.lineWidth = 4;
13077
13076
  this.lineType = "solid";
13078
13077
  this.fontSize = 34;
@@ -13084,11 +13083,11 @@
13084
13083
  this.enableEditMode(draggerName);
13085
13084
  };
13086
13085
  this.resizeContainer = entries => {
13087
- var _a, _b;
13088
13086
  const {width: width, height: height} = entries[0].contentRect;
13089
13087
  if (!width || !height) return;
13090
- (_a = this._konvaStage) === null || _a === void 0 ? void 0 : _a.width(width);
13091
- (_b = this._konvaStage) === null || _b === void 0 ? void 0 : _b.height(height);
13088
+ if (!this._konvaStage) return;
13089
+ this._konvaStage.width(width);
13090
+ this._konvaStage.height(height);
13092
13091
  };
13093
13092
  this.pan = event => {
13094
13093
  const dX = event.dX / window.devicePixelRatio;
@@ -13103,13 +13102,16 @@
13103
13102
  };
13104
13103
  }
13105
13104
  initialize(container, pointerEvents, viewer, worldTransformer) {
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>');
13105
+ if (!Konva) {
13106
+ console.error('Markup error: Konva is not initialized. Update node_modules or add to your page <script src="https://unpkg.com/konva@9/konva.min.js"><\/script>');
13107
+ return;
13108
+ }
13107
13109
  this._viewer = viewer;
13108
13110
  this._worldTransformer = worldTransformer !== null && worldTransformer !== void 0 ? worldTransformer : new WorldTransform;
13109
13111
  this._container = container;
13110
13112
  this._pointerEvents = pointerEvents !== null && pointerEvents !== void 0 ? pointerEvents : [];
13111
13113
  this._markupContainer = document.createElement("div");
13112
- this._markupContainer.id = this._markupContainerName;
13114
+ this._markupContainer.id = "markup-container";
13113
13115
  this._markupContainer.style.position = "absolute";
13114
13116
  this._markupContainer.style.top = "0px";
13115
13117
  this._markupContainer.style.left = "0px";
@@ -13125,32 +13127,30 @@
13125
13127
  this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
13126
13128
  this._viewer.addEventListener("pan", this.pan);
13127
13129
  }
13128
- this._isInitialized = true;
13129
13130
  }
13130
13131
  dispose() {
13131
- if (!this._isInitialized) return;
13132
+ var _a, _b;
13132
13133
  if (this._viewer) {
13133
13134
  this._viewer.removeEventListener("pan", this.pan);
13134
13135
  this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
13136
+ this._pointerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
13135
13137
  }
13136
- this._pointerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
13137
13138
  this.destroyKonva();
13138
- this._resizeObserver.disconnect();
13139
+ (_a = this._resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
13139
13140
  this._resizeObserver = undefined;
13140
- this._markupContainer.remove();
13141
+ (_b = this._markupContainer) === null || _b === void 0 ? void 0 : _b.remove();
13141
13142
  this._markupContainer = undefined;
13142
13143
  this._container = undefined;
13143
13144
  this._viewer = undefined;
13144
13145
  this._worldTransformer = undefined;
13145
13146
  this._markupIsActive = false;
13146
- this._isInitialized = false;
13147
13147
  }
13148
13148
  syncOverlay() {}
13149
13149
  clearOverlay() {
13150
13150
  this.removeTextInput();
13151
13151
  this.removeImageInput();
13152
13152
  this.clearSelected();
13153
- this.getObjects().forEach((obj => obj.ref().destroy()));
13153
+ this.getObjects().forEach((obj => obj.delete()));
13154
13154
  }
13155
13155
  getMarkupColor() {
13156
13156
  return this._markupColor.RGB;
@@ -13160,45 +13160,76 @@
13160
13160
  }
13161
13161
  colorizeAllMarkup(r, g, b) {
13162
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);
13163
+ this.getObjects().filter((obj => {
13164
+ var _a;
13165
+ return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor);
13166
13166
  }));
13167
- this._konvaLayer.draw();
13168
13167
  }
13169
13168
  colorizeSelectedMarkups(r, g, b) {
13170
13169
  const hexColor = new MarkupColor(r, g, b).HexColor;
13171
- this.getSelectedObjects().forEach((obj => {
13172
- const colorable = obj;
13173
- if (colorable && colorable.setColor) colorable.setColor(hexColor);
13170
+ this.getSelectedObjects().filter((obj => {
13171
+ var _a;
13172
+ return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor);
13174
13173
  }));
13175
13174
  }
13176
13175
  setViewpoint(viewpoint) {
13177
- const markupColor = viewpoint.custom_fields.markup_color || {
13176
+ var _a, _b, _c, _d, _e, _f, _g, _h;
13177
+ const markupColor = ((_a = viewpoint.custom_fields) === null || _a === void 0 ? void 0 : _a.markup_color) || {
13178
13178
  r: 255,
13179
13179
  g: 0,
13180
13180
  b: 0
13181
13181
  };
13182
13182
  this.setMarkupColor(markupColor.r, markupColor.g, markupColor.b);
13183
- this.loadMarkup(viewpoint);
13183
+ (_b = viewpoint.lines) === null || _b === void 0 ? void 0 : _b.forEach((line => {
13184
+ const linePoints = [];
13185
+ line.points.forEach((point => {
13186
+ const screenPoint = this._worldTransformer.worldToScreen(point);
13187
+ linePoints.push(screenPoint.x);
13188
+ linePoints.push(screenPoint.y);
13189
+ }));
13190
+ this.addLine(linePoints, line.color, line.type, line.width, line.id);
13191
+ }));
13192
+ (_c = viewpoint.texts) === null || _c === void 0 ? void 0 : _c.forEach((text => {
13193
+ const screenPoint = this._worldTransformer.worldToScreen(text.position);
13194
+ this.addText(text.text, screenPoint, text.angle, text.color, text.text_size, text.font_size, text.id);
13195
+ }));
13196
+ (_d = viewpoint.rectangles) === null || _d === void 0 ? void 0 : _d.forEach((rect => {
13197
+ const screenPoint = this._worldTransformer.worldToScreen(rect.position);
13198
+ this.addRectangle(screenPoint, rect.width, rect.height, rect.line_width, rect.color, rect.id);
13199
+ }));
13200
+ (_e = viewpoint.ellipses) === null || _e === void 0 ? void 0 : _e.forEach((ellipse => {
13201
+ const screenPoint = this._worldTransformer.worldToScreen(ellipse.position);
13202
+ this.addEllipse(screenPoint, ellipse.radius, ellipse.line_width, ellipse.color, ellipse.id);
13203
+ }));
13204
+ (_f = viewpoint.arrows) === null || _f === void 0 ? void 0 : _f.forEach((arrow => {
13205
+ const startPoint = this._worldTransformer.worldToScreen(arrow.start);
13206
+ const endPoint = this._worldTransformer.worldToScreen(arrow.end);
13207
+ this.addArrow(startPoint, endPoint, arrow.color, arrow.id);
13208
+ }));
13209
+ (_g = viewpoint.clouds) === null || _g === void 0 ? void 0 : _g.forEach((cloud => {
13210
+ const screenPoint = this._worldTransformer.worldToScreen(cloud.position);
13211
+ this.addCloud(screenPoint, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
13212
+ }));
13213
+ (_h = viewpoint.images) === null || _h === void 0 ? void 0 : _h.forEach((image => {
13214
+ const screenPoint = this._worldTransformer.worldToScreen(image.position);
13215
+ this.addImage(screenPoint, image.src, image.width, image.height, image.id);
13216
+ }));
13184
13217
  }
13185
13218
  getViewpoint() {
13186
- const viewpoint = {
13187
- lines: [],
13188
- texts: [],
13189
- arrows: [],
13190
- clouds: [],
13191
- ellipses: [],
13192
- images: [],
13193
- rectangles: []
13219
+ const viewpoint = {};
13220
+ viewpoint.lines = this.getMarkupLines();
13221
+ viewpoint.texts = this.getMarkupTexts();
13222
+ viewpoint.arrows = this.getMarkupArrows();
13223
+ viewpoint.clouds = this.getMarkupClouds();
13224
+ viewpoint.ellipses = this.getMarkupEllipses();
13225
+ viewpoint.images = this.getMarkupImages();
13226
+ viewpoint.rectangles = this.getMarkupRectangles();
13227
+ viewpoint.custom_fields = {
13228
+ markup_color: this.getMarkupColor()
13194
13229
  };
13195
13230
  viewpoint.snapshot = {
13196
13231
  data: this.combineMarkupWithDrawing()
13197
13232
  };
13198
- viewpoint.custom_fields = {
13199
- markup_color: this.getMarkupColor()
13200
- };
13201
- this.fillViewpointShapes(viewpoint);
13202
13233
  viewpoint.description = (new Date).toDateString();
13203
13234
  return viewpoint;
13204
13235
  }
@@ -13231,6 +13262,7 @@
13231
13262
  return objects;
13232
13263
  }
13233
13264
  getSelectedObjects() {
13265
+ if (!this._konvaTransformer) return [];
13234
13266
  return this._konvaTransformer.nodes().map((ref => {
13235
13267
  const name = ref.className;
13236
13268
  const konvaShape = Object.values(MarkupMode2Konva).find((shape => shape.name === name));
@@ -13238,73 +13270,29 @@
13238
13270
  })).filter((x => x));
13239
13271
  }
13240
13272
  selectObjects(objects) {
13273
+ if (!this._konvaTransformer) return;
13241
13274
  const selectedObjs = this._konvaTransformer.nodes().concat(objects.map((x => x.ref())));
13242
13275
  this._konvaTransformer.nodes(selectedObjs);
13243
13276
  }
13244
13277
  clearSelected() {
13245
- this._konvaTransformer.nodes([]);
13246
- }
13247
- fillViewpointShapes(viewpoint) {
13248
- const markupLines = this.getMarkupLines();
13249
- if (markupLines && markupLines.length > 0) {
13250
- markupLines === null || markupLines === void 0 ? void 0 : markupLines.forEach((line => {
13251
- viewpoint.lines.push(line);
13252
- }));
13253
- }
13254
- const markupTexts = this.getMarkupTexts();
13255
- if (markupTexts && markupTexts.length > 0) {
13256
- markupTexts === null || markupTexts === void 0 ? void 0 : markupTexts.forEach((text => {
13257
- viewpoint.texts.push(text);
13258
- }));
13259
- }
13260
- const markupRectangles = this.getMarkupRectangles();
13261
- if (markupRectangles && markupRectangles.length > 0) {
13262
- markupRectangles === null || markupRectangles === void 0 ? void 0 : markupRectangles.forEach((rectangle => {
13263
- viewpoint.rectangles.push(rectangle);
13264
- }));
13265
- }
13266
- const markupEllipses = this.getMarkupEllipses();
13267
- if (markupEllipses && markupEllipses.length > 0) {
13268
- markupEllipses === null || markupEllipses === void 0 ? void 0 : markupEllipses.forEach((ellipse => {
13269
- viewpoint.ellipses.push(ellipse);
13270
- }));
13271
- }
13272
- const markupArrows = this.getMarkupArrows();
13273
- if (markupArrows && markupArrows.length > 0) {
13274
- markupArrows === null || markupArrows === void 0 ? void 0 : markupArrows.forEach((arrow => {
13275
- viewpoint.arrows.push(arrow);
13276
- }));
13277
- }
13278
- const markupImages = this.getMarkupImages();
13279
- if (markupImages && markupImages.length > 0) {
13280
- markupImages === null || markupImages === void 0 ? void 0 : markupImages.forEach((image => {
13281
- viewpoint.images.push(image);
13282
- }));
13283
- }
13284
- const markupClouds = this.getMarkupClouds();
13285
- if (markupClouds && markupClouds.length > 0) {
13286
- markupClouds === null || markupClouds === void 0 ? void 0 : markupClouds.forEach((cloud => {
13287
- viewpoint.clouds.push(cloud);
13288
- }));
13289
- }
13278
+ if (this._konvaTransformer) this._konvaTransformer.nodes([]);
13290
13279
  }
13291
13280
  addObject(object) {
13292
- this._konvaLayer.add(object.ref());
13281
+ if (this._konvaLayer) this._konvaLayer.add(object.ref());
13293
13282
  }
13294
13283
  konvaLayerFind(type) {
13284
+ if (!this._konvaLayer) return [];
13295
13285
  const konvaShape = MarkupMode2Konva[type];
13296
- if (konvaShape && konvaShape.initializer) {
13297
- return this._konvaLayer.find(konvaShape.name).filter((ref => ref.parent === this._konvaLayer));
13298
- }
13299
- return [];
13286
+ if (!konvaShape || !konvaShape.initializer) return [];
13287
+ return this._konvaLayer.find(konvaShape.name).filter((ref => ref.parent === this._konvaLayer));
13300
13288
  }
13301
13289
  initializeKonva() {
13302
- this._konvaStage = new Konva.Stage({
13303
- container: this._markupContainerName,
13290
+ const stage = new Konva.Stage({
13291
+ container: this._markupContainer,
13304
13292
  width: this._container.clientWidth,
13305
13293
  height: this._container.clientHeight
13306
13294
  });
13307
- const stage = this._konvaStage;
13295
+ this._konvaStage = stage;
13308
13296
  const layer = new Konva.Layer({
13309
13297
  pixelRation: window.devicePixelRatio
13310
13298
  });
@@ -13315,8 +13303,8 @@
13315
13303
  keepRatio: false,
13316
13304
  flipEnabled: false
13317
13305
  });
13318
- this._konvaTransformer = transformer;
13319
13306
  layer.add(transformer);
13307
+ this._konvaTransformer = transformer;
13320
13308
  let isPaint = false;
13321
13309
  let lastLine;
13322
13310
  let mouseDownPos;
@@ -13498,31 +13486,28 @@
13498
13486
  container.addEventListener("keydown", (e => {
13499
13487
  if (!this._markupIsActive) return;
13500
13488
  if (e.code === "Delete") {
13501
- const trNodes = this._konvaTransformer.nodes();
13502
- if (trNodes.length > 0) {
13503
- this._konvaTransformer.nodes().forEach((x => x.destroy()));
13504
- this._konvaTransformer.nodes([]);
13505
- }
13506
- layer.draw();
13489
+ this.getSelectedObjects().forEach((obj => obj.delete()));
13490
+ this.clearSelected();
13507
13491
  return;
13508
13492
  }
13509
13493
  e.preventDefault();
13510
13494
  }));
13511
13495
  }
13512
13496
  destroyKonva() {
13497
+ var _a;
13513
13498
  this.clearOverlay();
13514
- this._konvaStage.destroy();
13499
+ (_a = this._konvaStage) === null || _a === void 0 ? void 0 : _a.destroy();
13515
13500
  this._konvaLayer = undefined;
13516
13501
  this._konvaTransformer = undefined;
13517
13502
  this._konvaStage = undefined;
13518
13503
  }
13519
13504
  getMarkupLines() {
13520
13505
  const lines = [];
13521
- this.konvaLayerFind("Line").forEach((line => {
13522
- const linePoints = line.points();
13506
+ this.konvaLayerFind("Line").forEach((ref => {
13507
+ const linePoints = ref.points();
13523
13508
  if (!linePoints) return;
13524
13509
  const worldPoints = [];
13525
- const absoluteTransform = line.getAbsoluteTransform();
13510
+ const absoluteTransform = ref.getAbsoluteTransform();
13526
13511
  for (let i = 0; i < linePoints.length; i += 2) {
13527
13512
  const atPoint = absoluteTransform.point({
13528
13513
  x: linePoints[i],
@@ -13531,30 +13516,30 @@
13531
13516
  const worldPoint = this._worldTransformer.screenToWorld(atPoint);
13532
13517
  worldPoints.push(worldPoint);
13533
13518
  }
13534
- const konvaLine = new KonvaLine(null, line);
13535
- lines.push({
13519
+ const konvaLine = new KonvaLine(null, ref);
13520
+ const line = {
13536
13521
  id: konvaLine.id(),
13537
13522
  points: worldPoints,
13538
13523
  color: konvaLine.getColor() || "#ff0000",
13539
13524
  type: konvaLine.getLineType() || this.lineType,
13540
13525
  width: konvaLine.getLineWidth() || this.lineWidth
13541
- });
13526
+ };
13527
+ lines.push(line);
13542
13528
  }));
13543
13529
  return lines;
13544
13530
  }
13545
13531
  getMarkupTexts() {
13546
13532
  const texts = [];
13547
- const textSize = .02;
13548
- const textScale = this._worldTransformer.getScale();
13549
- this.konvaLayerFind("Text").forEach((text => {
13550
- if (!text) return;
13533
+ this.konvaLayerFind("Text").forEach((ref => {
13534
+ const textSize = .02;
13535
+ const textScale = this._worldTransformer.getScale();
13551
13536
  const position = {
13552
- x: text.x(),
13553
- y: text.y()
13537
+ x: ref.x(),
13538
+ y: ref.y()
13554
13539
  };
13555
13540
  const worldPoint = this._worldTransformer.screenToWorld(position);
13556
- const shape = new KonvaText(null, text);
13557
- texts.push({
13541
+ const shape = new KonvaText(null, ref);
13542
+ const text = {
13558
13543
  id: shape.id(),
13559
13544
  position: worldPoint,
13560
13545
  text: shape.getText(),
@@ -13562,150 +13547,121 @@
13562
13547
  angle: shape.getRotation(),
13563
13548
  color: shape.getColor(),
13564
13549
  font_size: shape.getFontSize()
13565
- });
13550
+ };
13551
+ texts.push(text);
13566
13552
  }));
13567
13553
  return texts;
13568
13554
  }
13569
13555
  getMarkupRectangles() {
13570
13556
  const rectangles = [];
13571
- this.konvaLayerFind("Rectangle").forEach((rect => {
13572
- const position = rect.position();
13557
+ this.konvaLayerFind("Rectangle").forEach((ref => {
13558
+ const position = ref.position();
13573
13559
  const worldPoint = this._worldTransformer.screenToWorld(position);
13574
- const shape = new KonvaRectangle(null, rect);
13575
- rectangles.push({
13560
+ const shape = new KonvaRectangle(null, ref);
13561
+ const rectangle = {
13576
13562
  id: shape.id(),
13577
13563
  position: worldPoint,
13578
13564
  width: shape.getWidth(),
13579
13565
  height: shape.getHeigth(),
13580
13566
  line_width: shape.getLineWidth(),
13581
13567
  color: shape.getColor()
13582
- });
13568
+ };
13569
+ rectangles.push(rectangle);
13583
13570
  }));
13584
13571
  return rectangles;
13585
13572
  }
13586
13573
  getMarkupEllipses() {
13587
13574
  const ellipses = [];
13588
- this.konvaLayerFind("Ellipse").forEach((ellipse => {
13589
- const position = ellipse.position();
13575
+ this.konvaLayerFind("Ellipse").forEach((ref => {
13576
+ const position = ref.position();
13590
13577
  const worldPoint = this._worldTransformer.screenToWorld(position);
13591
- const shape = new KonvaEllipse(null, ellipse);
13592
- ellipses.push({
13578
+ const shape = new KonvaEllipse(null, ref);
13579
+ const ellipse = {
13593
13580
  id: shape.id(),
13594
13581
  position: worldPoint,
13595
13582
  radius: {
13596
- x: ellipse.getRadiusX(),
13597
- y: ellipse.getRadiusY()
13583
+ x: ref.getRadiusX(),
13584
+ y: ref.getRadiusY()
13598
13585
  },
13599
13586
  line_width: shape.getLineWidth(),
13600
13587
  color: shape.getColor()
13601
- });
13588
+ };
13589
+ ellipses.push(ellipse);
13602
13590
  }));
13603
13591
  return ellipses;
13604
13592
  }
13605
13593
  getMarkupArrows() {
13606
13594
  const arrows = [];
13607
- this.konvaLayerFind("Arrow").forEach((arrow => {
13608
- const absoluteTransform = arrow.getAbsoluteTransform();
13595
+ this.konvaLayerFind("Arrow").forEach((ref => {
13596
+ const absoluteTransform = ref.getAbsoluteTransform();
13609
13597
  const atStartPoint = absoluteTransform.point({
13610
- x: arrow.points()[0],
13611
- y: arrow.points()[1]
13598
+ x: ref.points()[0],
13599
+ y: ref.points()[1]
13612
13600
  });
13613
13601
  const worldStartPoint = this._worldTransformer.screenToWorld(atStartPoint);
13614
13602
  const atEndPoint = absoluteTransform.point({
13615
- x: arrow.points()[2],
13616
- y: arrow.points()[3]
13603
+ x: ref.points()[2],
13604
+ y: ref.points()[3]
13617
13605
  });
13618
13606
  const worldEndPoint = this._worldTransformer.screenToWorld(atEndPoint);
13619
- const shape = new KonvaArrow(null, arrow);
13620
- arrows.push({
13607
+ const shape = new KonvaArrow(null, ref);
13608
+ const arrow = {
13621
13609
  id: shape.id(),
13622
13610
  start: worldStartPoint,
13623
13611
  end: worldEndPoint,
13624
13612
  color: shape.getColor()
13625
- });
13613
+ };
13614
+ arrows.push(arrow);
13626
13615
  }));
13627
13616
  return arrows;
13628
13617
  }
13629
13618
  getMarkupImages() {
13630
13619
  const images = [];
13631
- this.konvaLayerFind("Image").forEach((image => {
13632
- const position = image.position();
13620
+ this.konvaLayerFind("Image").forEach((ref => {
13621
+ const position = ref.position();
13633
13622
  const worldPoint = this._worldTransformer.screenToWorld(position);
13634
- const shape = new KonvaImage(null, image);
13635
- images.push({
13623
+ const shape = new KonvaImage(null, ref);
13624
+ const image = {
13636
13625
  id: shape.id(),
13637
13626
  position: worldPoint,
13638
13627
  src: shape.getSrc(),
13639
13628
  width: shape.getWidth(),
13640
13629
  height: shape.getHeight()
13641
- });
13630
+ };
13631
+ images.push(image);
13642
13632
  }));
13643
13633
  return images;
13644
13634
  }
13645
13635
  getMarkupClouds() {
13646
13636
  const clouds = [];
13647
- this.konvaLayerFind("Cloud").forEach((cloud => {
13648
- const position = cloud.position();
13637
+ this.konvaLayerFind("Cloud").forEach((ref => {
13638
+ const position = ref.position();
13649
13639
  const worldPoint = this._worldTransformer.screenToWorld(position);
13650
- const shape = new KonvaCloud(null, cloud);
13651
- clouds.push({
13640
+ const shape = new KonvaCloud(null, ref);
13641
+ const cloud = {
13652
13642
  id: shape.id(),
13653
13643
  position: worldPoint,
13654
13644
  width: shape.getWidth(),
13655
13645
  height: shape.getHeigth(),
13656
13646
  line_width: shape.getLineWidth(),
13657
13647
  color: shape.getColor()
13658
- });
13648
+ };
13649
+ clouds.push(cloud);
13659
13650
  }));
13660
13651
  return clouds;
13661
13652
  }
13662
- loadMarkup(viewpoint) {
13663
- var _a, _b, _c, _d, _e, _f, _g;
13664
- (_a = viewpoint.lines) === null || _a === void 0 ? void 0 : _a.forEach((vpLine => {
13665
- const linePoints = [];
13666
- vpLine.points.forEach((point => {
13667
- const screenPoint = this._worldTransformer.worldToScreen(point);
13668
- linePoints.push(screenPoint.x);
13669
- linePoints.push(screenPoint.y);
13670
- }));
13671
- this.addLine(linePoints, vpLine.color, vpLine.type, vpLine.width, vpLine.id);
13672
- }));
13673
- (_b = viewpoint.texts) === null || _b === void 0 ? void 0 : _b.forEach((vpText => {
13674
- const screenPoint = this._worldTransformer.worldToScreen(vpText.position);
13675
- this.addText(vpText.text, screenPoint, vpText.angle, vpText.color, vpText.text_size, vpText.font_size, vpText.id);
13676
- }));
13677
- (_c = viewpoint.rectangles) === null || _c === void 0 ? void 0 : _c.forEach((vpRect => {
13678
- const screenPoint = this._worldTransformer.worldToScreen(vpRect.position);
13679
- this.addRectangle(screenPoint, vpRect.width, vpRect.height, vpRect.line_width, vpRect.color, vpRect.id);
13680
- }));
13681
- (_d = viewpoint.ellipses) === null || _d === void 0 ? void 0 : _d.forEach((vpEllipse => {
13682
- const screenPoint = this._worldTransformer.worldToScreen(vpEllipse.position);
13683
- this.addEllipse(screenPoint, vpEllipse.radius, vpEllipse.line_width, vpEllipse.color, vpEllipse.id);
13684
- }));
13685
- (_e = viewpoint.arrows) === null || _e === void 0 ? void 0 : _e.forEach((vpArrow => {
13686
- const startPoint = this._worldTransformer.worldToScreen(vpArrow.start);
13687
- const endPoint = this._worldTransformer.worldToScreen(vpArrow.end);
13688
- this.addArrow(startPoint, endPoint, vpArrow.color, vpArrow.id);
13689
- }));
13690
- (_f = viewpoint.clouds) === null || _f === void 0 ? void 0 : _f.forEach((vpCloud => {
13691
- const screenPoint = this._worldTransformer.worldToScreen(vpCloud.position);
13692
- this.addCloud(screenPoint, vpCloud.width, vpCloud.height, vpCloud.line_width, vpCloud.color, vpCloud.id);
13693
- }));
13694
- (_g = viewpoint.images) === null || _g === void 0 ? void 0 : _g.forEach((vpImage => {
13695
- const screenPoint = this._worldTransformer.worldToScreen(vpImage.position);
13696
- this.addImage(screenPoint, vpImage.src, vpImage.width, vpImage.height, vpImage.id);
13697
- }));
13698
- }
13699
13653
  combineMarkupWithDrawing() {
13700
13654
  this.clearSelected();
13701
13655
  const tempCanvas = document.createElement("canvas");
13702
- tempCanvas.width = this._konvaStage.width();
13703
- tempCanvas.height = this._konvaStage.height();
13704
- const ctx = tempCanvas.getContext("2d");
13705
- if (this._container instanceof HTMLCanvasElement) ctx.drawImage(this._container, 0, 0);
13706
- ctx.drawImage(this._konvaStage.toCanvas({
13707
- pixelRatio: window.devicePixelRatio
13708
- }), 0, 0);
13656
+ if (this._konvaStage) {
13657
+ tempCanvas.width = this._konvaStage.width();
13658
+ tempCanvas.height = this._konvaStage.height();
13659
+ const ctx = tempCanvas.getContext("2d");
13660
+ if (this._container instanceof HTMLCanvasElement) ctx.drawImage(this._container, 0, 0);
13661
+ ctx.drawImage(this._konvaStage.toCanvas({
13662
+ pixelRatio: window.devicePixelRatio
13663
+ }), 0, 0);
13664
+ }
13709
13665
  return tempCanvas.toDataURL("image/jpeg", .25);
13710
13666
  }
13711
13667
  addLine(linePoints, color, type, width, id) {
@@ -13724,8 +13680,7 @@
13724
13680
  color: color || this._markupColor.HexColor,
13725
13681
  id: id
13726
13682
  });
13727
- const obj = konvaLine.ref();
13728
- this._konvaLayer.add(obj);
13683
+ this.addObject(konvaLine);
13729
13684
  return konvaLine;
13730
13685
  }
13731
13686
  createTextInput(pos, inputX, inputY, angle, text) {
@@ -13806,34 +13761,31 @@
13806
13761
  this._imageInputRef = null;
13807
13762
  this._imageInputPos = null;
13808
13763
  }
13809
- addText(specifiedText, position, angle, color, textSize, fontSize, id) {
13810
- const trNodes = this._konvaTransformer.nodes();
13811
- if (trNodes.length > 0) {
13812
- trNodes[0].destroy();
13813
- this._konvaTransformer.nodes([]);
13814
- }
13764
+ addText(text, position, angle, color, textSize, fontSize, id) {
13765
+ var _a;
13766
+ if (!text) return;
13767
+ (_a = this.getSelectedObjects().at(0)) === null || _a === void 0 ? void 0 : _a.delete();
13768
+ this.clearSelected();
13815
13769
  this.removeTextInput();
13816
- if (specifiedText) {
13817
- const tolerance = 1e-6;
13818
- if (textSize && textSize > tolerance && (!fontSize || fontSize < tolerance)) {
13819
- const size = .02;
13820
- const scale = this._worldTransformer.getScale();
13821
- fontSize = textSize / (scale.y / size) / 34;
13822
- }
13823
- const konvaText = new KonvaText({
13824
- position: {
13825
- x: position.x,
13826
- y: position.y
13827
- },
13828
- text: specifiedText,
13829
- rotation: angle,
13830
- fontSize: fontSize || this.fontSize,
13831
- color: color || this._markupColor.HexColor,
13832
- id: id
13833
- });
13834
- this._konvaLayer.add(konvaText.ref());
13835
- return konvaText;
13836
- }
13770
+ const tolerance = 1e-6;
13771
+ if (textSize && textSize > tolerance && (!fontSize || fontSize < tolerance)) {
13772
+ const size = .02;
13773
+ const scale = this._worldTransformer.getScale();
13774
+ fontSize = textSize / (scale.y / size) / 34;
13775
+ }
13776
+ const konvaText = new KonvaText({
13777
+ position: {
13778
+ x: position.x,
13779
+ y: position.y
13780
+ },
13781
+ text: text,
13782
+ rotation: angle,
13783
+ fontSize: fontSize || this.fontSize,
13784
+ color: color || this._markupColor.HexColor,
13785
+ id: id
13786
+ });
13787
+ this.addObject(konvaText);
13788
+ return konvaText;
13837
13789
  }
13838
13790
  addRectangle(position, width, height, lineWidth, color, id) {
13839
13791
  if (!position) return;
@@ -13845,8 +13797,7 @@
13845
13797
  color: color || this._markupColor.HexColor,
13846
13798
  id: id
13847
13799
  });
13848
- const obj = konvaRectangle.ref();
13849
- this._konvaLayer.add(obj);
13800
+ this.addObject(konvaRectangle);
13850
13801
  return konvaRectangle;
13851
13802
  }
13852
13803
  addEllipse(position, radius, lineWidth, color, id) {
@@ -13858,8 +13809,7 @@
13858
13809
  color: color || this._markupColor.HexColor,
13859
13810
  id: id
13860
13811
  });
13861
- const obj = konvaEllipse.ref();
13862
- this._konvaLayer.add(obj);
13812
+ this.addObject(konvaEllipse);
13863
13813
  return konvaEllipse;
13864
13814
  }
13865
13815
  addArrow(start, end, color, id) {
@@ -13870,8 +13820,7 @@
13870
13820
  color: color || this._markupColor.HexColor,
13871
13821
  id: id
13872
13822
  });
13873
- const obj = konvaArrow.ref();
13874
- this._konvaLayer.add(obj);
13823
+ this.addObject(konvaArrow);
13875
13824
  return konvaArrow;
13876
13825
  }
13877
13826
  addCloud(position, width, height, lineWidth, color, id) {
@@ -13884,30 +13833,23 @@
13884
13833
  lineWidth: lineWidth || this.lineWidth,
13885
13834
  id: id
13886
13835
  });
13887
- const obj = konvaCloud.ref();
13888
- this._konvaLayer.add(obj);
13836
+ this.addObject(konvaCloud);
13889
13837
  return konvaCloud;
13890
13838
  }
13891
13839
  addImage(position, src, width, height, id) {
13892
- if (!position) return;
13893
- let konvaImage;
13894
- if (src) {
13895
- konvaImage = new KonvaImage({
13896
- position: position,
13897
- src: src,
13898
- width: width,
13899
- height: height,
13900
- id: id
13901
- });
13902
- const obj = konvaImage.ref();
13903
- this._konvaLayer.add(obj);
13904
- const trNodes = this._konvaTransformer.nodes();
13905
- if (trNodes.length > 0) {
13906
- trNodes[0].destroy();
13907
- this._konvaTransformer.nodes([]);
13908
- }
13909
- }
13840
+ var _a;
13841
+ if (!position || !src) return;
13842
+ (_a = this.getSelectedObjects().at(0)) === null || _a === void 0 ? void 0 : _a.delete();
13843
+ this.clearSelected();
13910
13844
  this.removeImageInput();
13845
+ const konvaImage = new KonvaImage({
13846
+ position: position,
13847
+ src: src,
13848
+ width: width,
13849
+ height: height,
13850
+ id: id
13851
+ });
13852
+ this.addObject(konvaImage);
13911
13853
  return konvaImage;
13912
13854
  }
13913
13855
  }
@@ -16718,12 +16660,18 @@
16718
16660
  canvas.style.touchAction = "none";
16719
16661
  canvas.width = canvas.clientWidth * window.devicePixelRatio;
16720
16662
  canvas.height = canvas.clientHeight * window.devicePixelRatio;
16663
+ this._visualizeTimestamp = Date.now();
16664
+ const visualizeTimestamp = this._visualizeTimestamp;
16721
16665
  const visualizeJs = await loadVisualizeJs(this.visualizeJsUrl, (event) => {
16722
16666
  const { loaded, total } = event;
16723
16667
  if (onProgress)
16724
16668
  onProgress(new ProgressEvent("progress", { lengthComputable: true, loaded, total }));
16725
16669
  this.emitEvent({ type: "initializeprogress", data: loaded / total, loaded, total });
16726
16670
  });
16671
+ if (visualizeTimestamp !== this._visualizeTimestamp) {
16672
+ console.error("Viewer error: dispose() was called before initialize() completed. Are you using React strict mode?");
16673
+ return this;
16674
+ }
16727
16675
  this._visualizeJs = visualizeJs;
16728
16676
  this.visualizeJs.canvas = canvas;
16729
16677
  this.visualizeJs.Viewer.create();
@@ -16774,6 +16722,7 @@
16774
16722
  if (this._visualizeJs)
16775
16723
  this._visualizeJs.getViewer().clear();
16776
16724
  this._visualizeJs = undefined;
16725
+ this._visualizeTimestamp = undefined;
16777
16726
  return this;
16778
16727
  }
16779
16728
  /**