@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.
@@ -1630,11 +1630,10 @@ const MarkupMode2Konva = {
1630
1630
 
1631
1631
  class KonvaMarkup {
1632
1632
  constructor() {
1633
- this._isInitialized = false;
1633
+ this._pointerEvents = [];
1634
1634
  this._markupIsActive = false;
1635
1635
  this._markupColor = new MarkupColor(255, 0, 0);
1636
1636
  this._zIndex = 1;
1637
- this._markupContainerName = "markupContainer";
1638
1637
  this.lineWidth = 4;
1639
1638
  this.lineType = "solid";
1640
1639
  this.fontSize = 34;
@@ -1646,11 +1645,11 @@ class KonvaMarkup {
1646
1645
  this.enableEditMode(draggerName);
1647
1646
  };
1648
1647
  this.resizeContainer = entries => {
1649
- var _a, _b;
1650
1648
  const {width: width, height: height} = entries[0].contentRect;
1651
1649
  if (!width || !height) return;
1652
- (_a = this._konvaStage) === null || _a === void 0 ? void 0 : _a.width(width);
1653
- (_b = this._konvaStage) === null || _b === void 0 ? void 0 : _b.height(height);
1650
+ if (!this._konvaStage) return;
1651
+ this._konvaStage.width(width);
1652
+ this._konvaStage.height(height);
1654
1653
  };
1655
1654
  this.pan = event => {
1656
1655
  const dX = event.dX / window.devicePixelRatio;
@@ -1665,13 +1664,16 @@ class KonvaMarkup {
1665
1664
  };
1666
1665
  }
1667
1666
  initialize(container, pointerEvents, viewer, worldTransformer) {
1668
- 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>');
1667
+ if (!Konva) {
1668
+ 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>');
1669
+ return;
1670
+ }
1669
1671
  this._viewer = viewer;
1670
1672
  this._worldTransformer = worldTransformer !== null && worldTransformer !== void 0 ? worldTransformer : new WorldTransform;
1671
1673
  this._container = container;
1672
1674
  this._pointerEvents = pointerEvents !== null && pointerEvents !== void 0 ? pointerEvents : [];
1673
1675
  this._markupContainer = document.createElement("div");
1674
- this._markupContainer.id = this._markupContainerName;
1676
+ this._markupContainer.id = "markup-container";
1675
1677
  this._markupContainer.style.position = "absolute";
1676
1678
  this._markupContainer.style.top = "0px";
1677
1679
  this._markupContainer.style.left = "0px";
@@ -1687,32 +1689,30 @@ class KonvaMarkup {
1687
1689
  this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
1688
1690
  this._viewer.addEventListener("pan", this.pan);
1689
1691
  }
1690
- this._isInitialized = true;
1691
1692
  }
1692
1693
  dispose() {
1693
- if (!this._isInitialized) return;
1694
+ var _a, _b;
1694
1695
  if (this._viewer) {
1695
1696
  this._viewer.removeEventListener("pan", this.pan);
1696
1697
  this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
1698
+ this._pointerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
1697
1699
  }
1698
- this._pointerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
1699
1700
  this.destroyKonva();
1700
- this._resizeObserver.disconnect();
1701
+ (_a = this._resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
1701
1702
  this._resizeObserver = undefined;
1702
- this._markupContainer.remove();
1703
+ (_b = this._markupContainer) === null || _b === void 0 ? void 0 : _b.remove();
1703
1704
  this._markupContainer = undefined;
1704
1705
  this._container = undefined;
1705
1706
  this._viewer = undefined;
1706
1707
  this._worldTransformer = undefined;
1707
1708
  this._markupIsActive = false;
1708
- this._isInitialized = false;
1709
1709
  }
1710
1710
  syncOverlay() {}
1711
1711
  clearOverlay() {
1712
1712
  this.removeTextInput();
1713
1713
  this.removeImageInput();
1714
1714
  this.clearSelected();
1715
- this.getObjects().forEach((obj => obj.ref().destroy()));
1715
+ this.getObjects().forEach((obj => obj.delete()));
1716
1716
  }
1717
1717
  getMarkupColor() {
1718
1718
  return this._markupColor.RGB;
@@ -1722,45 +1722,76 @@ class KonvaMarkup {
1722
1722
  }
1723
1723
  colorizeAllMarkup(r, g, b) {
1724
1724
  const hexColor = new MarkupColor(r, g, b).HexColor;
1725
- this.getObjects().forEach((obj => {
1726
- const colorable = obj;
1727
- if (colorable && colorable.setColor) colorable.setColor(hexColor);
1725
+ this.getObjects().filter((obj => {
1726
+ var _a;
1727
+ return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor);
1728
1728
  }));
1729
- this._konvaLayer.draw();
1730
1729
  }
1731
1730
  colorizeSelectedMarkups(r, g, b) {
1732
1731
  const hexColor = new MarkupColor(r, g, b).HexColor;
1733
- this.getSelectedObjects().forEach((obj => {
1734
- const colorable = obj;
1735
- if (colorable && colorable.setColor) colorable.setColor(hexColor);
1732
+ this.getSelectedObjects().filter((obj => {
1733
+ var _a;
1734
+ return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor);
1736
1735
  }));
1737
1736
  }
1738
1737
  setViewpoint(viewpoint) {
1739
- const markupColor = viewpoint.custom_fields.markup_color || {
1738
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1739
+ const markupColor = ((_a = viewpoint.custom_fields) === null || _a === void 0 ? void 0 : _a.markup_color) || {
1740
1740
  r: 255,
1741
1741
  g: 0,
1742
1742
  b: 0
1743
1743
  };
1744
1744
  this.setMarkupColor(markupColor.r, markupColor.g, markupColor.b);
1745
- this.loadMarkup(viewpoint);
1745
+ (_b = viewpoint.lines) === null || _b === void 0 ? void 0 : _b.forEach((line => {
1746
+ const linePoints = [];
1747
+ line.points.forEach((point => {
1748
+ const screenPoint = this._worldTransformer.worldToScreen(point);
1749
+ linePoints.push(screenPoint.x);
1750
+ linePoints.push(screenPoint.y);
1751
+ }));
1752
+ this.addLine(linePoints, line.color, line.type, line.width, line.id);
1753
+ }));
1754
+ (_c = viewpoint.texts) === null || _c === void 0 ? void 0 : _c.forEach((text => {
1755
+ const screenPoint = this._worldTransformer.worldToScreen(text.position);
1756
+ this.addText(text.text, screenPoint, text.angle, text.color, text.text_size, text.font_size, text.id);
1757
+ }));
1758
+ (_d = viewpoint.rectangles) === null || _d === void 0 ? void 0 : _d.forEach((rect => {
1759
+ const screenPoint = this._worldTransformer.worldToScreen(rect.position);
1760
+ this.addRectangle(screenPoint, rect.width, rect.height, rect.line_width, rect.color, rect.id);
1761
+ }));
1762
+ (_e = viewpoint.ellipses) === null || _e === void 0 ? void 0 : _e.forEach((ellipse => {
1763
+ const screenPoint = this._worldTransformer.worldToScreen(ellipse.position);
1764
+ this.addEllipse(screenPoint, ellipse.radius, ellipse.line_width, ellipse.color, ellipse.id);
1765
+ }));
1766
+ (_f = viewpoint.arrows) === null || _f === void 0 ? void 0 : _f.forEach((arrow => {
1767
+ const startPoint = this._worldTransformer.worldToScreen(arrow.start);
1768
+ const endPoint = this._worldTransformer.worldToScreen(arrow.end);
1769
+ this.addArrow(startPoint, endPoint, arrow.color, arrow.id);
1770
+ }));
1771
+ (_g = viewpoint.clouds) === null || _g === void 0 ? void 0 : _g.forEach((cloud => {
1772
+ const screenPoint = this._worldTransformer.worldToScreen(cloud.position);
1773
+ this.addCloud(screenPoint, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
1774
+ }));
1775
+ (_h = viewpoint.images) === null || _h === void 0 ? void 0 : _h.forEach((image => {
1776
+ const screenPoint = this._worldTransformer.worldToScreen(image.position);
1777
+ this.addImage(screenPoint, image.src, image.width, image.height, image.id);
1778
+ }));
1746
1779
  }
1747
1780
  getViewpoint() {
1748
- const viewpoint = {
1749
- lines: [],
1750
- texts: [],
1751
- arrows: [],
1752
- clouds: [],
1753
- ellipses: [],
1754
- images: [],
1755
- rectangles: []
1781
+ const viewpoint = {};
1782
+ viewpoint.lines = this.getMarkupLines();
1783
+ viewpoint.texts = this.getMarkupTexts();
1784
+ viewpoint.arrows = this.getMarkupArrows();
1785
+ viewpoint.clouds = this.getMarkupClouds();
1786
+ viewpoint.ellipses = this.getMarkupEllipses();
1787
+ viewpoint.images = this.getMarkupImages();
1788
+ viewpoint.rectangles = this.getMarkupRectangles();
1789
+ viewpoint.custom_fields = {
1790
+ markup_color: this.getMarkupColor()
1756
1791
  };
1757
1792
  viewpoint.snapshot = {
1758
1793
  data: this.combineMarkupWithDrawing()
1759
1794
  };
1760
- viewpoint.custom_fields = {
1761
- markup_color: this.getMarkupColor()
1762
- };
1763
- this.fillViewpointShapes(viewpoint);
1764
1795
  viewpoint.description = (new Date).toDateString();
1765
1796
  return viewpoint;
1766
1797
  }
@@ -1793,6 +1824,7 @@ class KonvaMarkup {
1793
1824
  return objects;
1794
1825
  }
1795
1826
  getSelectedObjects() {
1827
+ if (!this._konvaTransformer) return [];
1796
1828
  return this._konvaTransformer.nodes().map((ref => {
1797
1829
  const name = ref.className;
1798
1830
  const konvaShape = Object.values(MarkupMode2Konva).find((shape => shape.name === name));
@@ -1800,73 +1832,29 @@ class KonvaMarkup {
1800
1832
  })).filter((x => x));
1801
1833
  }
1802
1834
  selectObjects(objects) {
1835
+ if (!this._konvaTransformer) return;
1803
1836
  const selectedObjs = this._konvaTransformer.nodes().concat(objects.map((x => x.ref())));
1804
1837
  this._konvaTransformer.nodes(selectedObjs);
1805
1838
  }
1806
1839
  clearSelected() {
1807
- this._konvaTransformer.nodes([]);
1808
- }
1809
- fillViewpointShapes(viewpoint) {
1810
- const markupLines = this.getMarkupLines();
1811
- if (markupLines && markupLines.length > 0) {
1812
- markupLines === null || markupLines === void 0 ? void 0 : markupLines.forEach((line => {
1813
- viewpoint.lines.push(line);
1814
- }));
1815
- }
1816
- const markupTexts = this.getMarkupTexts();
1817
- if (markupTexts && markupTexts.length > 0) {
1818
- markupTexts === null || markupTexts === void 0 ? void 0 : markupTexts.forEach((text => {
1819
- viewpoint.texts.push(text);
1820
- }));
1821
- }
1822
- const markupRectangles = this.getMarkupRectangles();
1823
- if (markupRectangles && markupRectangles.length > 0) {
1824
- markupRectangles === null || markupRectangles === void 0 ? void 0 : markupRectangles.forEach((rectangle => {
1825
- viewpoint.rectangles.push(rectangle);
1826
- }));
1827
- }
1828
- const markupEllipses = this.getMarkupEllipses();
1829
- if (markupEllipses && markupEllipses.length > 0) {
1830
- markupEllipses === null || markupEllipses === void 0 ? void 0 : markupEllipses.forEach((ellipse => {
1831
- viewpoint.ellipses.push(ellipse);
1832
- }));
1833
- }
1834
- const markupArrows = this.getMarkupArrows();
1835
- if (markupArrows && markupArrows.length > 0) {
1836
- markupArrows === null || markupArrows === void 0 ? void 0 : markupArrows.forEach((arrow => {
1837
- viewpoint.arrows.push(arrow);
1838
- }));
1839
- }
1840
- const markupImages = this.getMarkupImages();
1841
- if (markupImages && markupImages.length > 0) {
1842
- markupImages === null || markupImages === void 0 ? void 0 : markupImages.forEach((image => {
1843
- viewpoint.images.push(image);
1844
- }));
1845
- }
1846
- const markupClouds = this.getMarkupClouds();
1847
- if (markupClouds && markupClouds.length > 0) {
1848
- markupClouds === null || markupClouds === void 0 ? void 0 : markupClouds.forEach((cloud => {
1849
- viewpoint.clouds.push(cloud);
1850
- }));
1851
- }
1840
+ if (this._konvaTransformer) this._konvaTransformer.nodes([]);
1852
1841
  }
1853
1842
  addObject(object) {
1854
- this._konvaLayer.add(object.ref());
1843
+ if (this._konvaLayer) this._konvaLayer.add(object.ref());
1855
1844
  }
1856
1845
  konvaLayerFind(type) {
1846
+ if (!this._konvaLayer) return [];
1857
1847
  const konvaShape = MarkupMode2Konva[type];
1858
- if (konvaShape && konvaShape.initializer) {
1859
- return this._konvaLayer.find(konvaShape.name).filter((ref => ref.parent === this._konvaLayer));
1860
- }
1861
- return [];
1848
+ if (!konvaShape || !konvaShape.initializer) return [];
1849
+ return this._konvaLayer.find(konvaShape.name).filter((ref => ref.parent === this._konvaLayer));
1862
1850
  }
1863
1851
  initializeKonva() {
1864
- this._konvaStage = new Konva.Stage({
1865
- container: this._markupContainerName,
1852
+ const stage = new Konva.Stage({
1853
+ container: this._markupContainer,
1866
1854
  width: this._container.clientWidth,
1867
1855
  height: this._container.clientHeight
1868
1856
  });
1869
- const stage = this._konvaStage;
1857
+ this._konvaStage = stage;
1870
1858
  const layer = new Konva.Layer({
1871
1859
  pixelRation: window.devicePixelRatio
1872
1860
  });
@@ -1877,8 +1865,8 @@ class KonvaMarkup {
1877
1865
  keepRatio: false,
1878
1866
  flipEnabled: false
1879
1867
  });
1880
- this._konvaTransformer = transformer;
1881
1868
  layer.add(transformer);
1869
+ this._konvaTransformer = transformer;
1882
1870
  let isPaint = false;
1883
1871
  let lastLine;
1884
1872
  let mouseDownPos;
@@ -2060,31 +2048,28 @@ class KonvaMarkup {
2060
2048
  container.addEventListener("keydown", (e => {
2061
2049
  if (!this._markupIsActive) return;
2062
2050
  if (e.code === "Delete") {
2063
- const trNodes = this._konvaTransformer.nodes();
2064
- if (trNodes.length > 0) {
2065
- this._konvaTransformer.nodes().forEach((x => x.destroy()));
2066
- this._konvaTransformer.nodes([]);
2067
- }
2068
- layer.draw();
2051
+ this.getSelectedObjects().forEach((obj => obj.delete()));
2052
+ this.clearSelected();
2069
2053
  return;
2070
2054
  }
2071
2055
  e.preventDefault();
2072
2056
  }));
2073
2057
  }
2074
2058
  destroyKonva() {
2059
+ var _a;
2075
2060
  this.clearOverlay();
2076
- this._konvaStage.destroy();
2061
+ (_a = this._konvaStage) === null || _a === void 0 ? void 0 : _a.destroy();
2077
2062
  this._konvaLayer = undefined;
2078
2063
  this._konvaTransformer = undefined;
2079
2064
  this._konvaStage = undefined;
2080
2065
  }
2081
2066
  getMarkupLines() {
2082
2067
  const lines = [];
2083
- this.konvaLayerFind("Line").forEach((line => {
2084
- const linePoints = line.points();
2068
+ this.konvaLayerFind("Line").forEach((ref => {
2069
+ const linePoints = ref.points();
2085
2070
  if (!linePoints) return;
2086
2071
  const worldPoints = [];
2087
- const absoluteTransform = line.getAbsoluteTransform();
2072
+ const absoluteTransform = ref.getAbsoluteTransform();
2088
2073
  for (let i = 0; i < linePoints.length; i += 2) {
2089
2074
  const atPoint = absoluteTransform.point({
2090
2075
  x: linePoints[i],
@@ -2093,30 +2078,30 @@ class KonvaMarkup {
2093
2078
  const worldPoint = this._worldTransformer.screenToWorld(atPoint);
2094
2079
  worldPoints.push(worldPoint);
2095
2080
  }
2096
- const konvaLine = new KonvaLine(null, line);
2097
- lines.push({
2081
+ const konvaLine = new KonvaLine(null, ref);
2082
+ const line = {
2098
2083
  id: konvaLine.id(),
2099
2084
  points: worldPoints,
2100
2085
  color: konvaLine.getColor() || "#ff0000",
2101
2086
  type: konvaLine.getLineType() || this.lineType,
2102
2087
  width: konvaLine.getLineWidth() || this.lineWidth
2103
- });
2088
+ };
2089
+ lines.push(line);
2104
2090
  }));
2105
2091
  return lines;
2106
2092
  }
2107
2093
  getMarkupTexts() {
2108
2094
  const texts = [];
2109
- const textSize = .02;
2110
- const textScale = this._worldTransformer.getScale();
2111
- this.konvaLayerFind("Text").forEach((text => {
2112
- if (!text) return;
2095
+ this.konvaLayerFind("Text").forEach((ref => {
2096
+ const textSize = .02;
2097
+ const textScale = this._worldTransformer.getScale();
2113
2098
  const position = {
2114
- x: text.x(),
2115
- y: text.y()
2099
+ x: ref.x(),
2100
+ y: ref.y()
2116
2101
  };
2117
2102
  const worldPoint = this._worldTransformer.screenToWorld(position);
2118
- const shape = new KonvaText(null, text);
2119
- texts.push({
2103
+ const shape = new KonvaText(null, ref);
2104
+ const text = {
2120
2105
  id: shape.id(),
2121
2106
  position: worldPoint,
2122
2107
  text: shape.getText(),
@@ -2124,150 +2109,121 @@ class KonvaMarkup {
2124
2109
  angle: shape.getRotation(),
2125
2110
  color: shape.getColor(),
2126
2111
  font_size: shape.getFontSize()
2127
- });
2112
+ };
2113
+ texts.push(text);
2128
2114
  }));
2129
2115
  return texts;
2130
2116
  }
2131
2117
  getMarkupRectangles() {
2132
2118
  const rectangles = [];
2133
- this.konvaLayerFind("Rectangle").forEach((rect => {
2134
- const position = rect.position();
2119
+ this.konvaLayerFind("Rectangle").forEach((ref => {
2120
+ const position = ref.position();
2135
2121
  const worldPoint = this._worldTransformer.screenToWorld(position);
2136
- const shape = new KonvaRectangle(null, rect);
2137
- rectangles.push({
2122
+ const shape = new KonvaRectangle(null, ref);
2123
+ const rectangle = {
2138
2124
  id: shape.id(),
2139
2125
  position: worldPoint,
2140
2126
  width: shape.getWidth(),
2141
2127
  height: shape.getHeigth(),
2142
2128
  line_width: shape.getLineWidth(),
2143
2129
  color: shape.getColor()
2144
- });
2130
+ };
2131
+ rectangles.push(rectangle);
2145
2132
  }));
2146
2133
  return rectangles;
2147
2134
  }
2148
2135
  getMarkupEllipses() {
2149
2136
  const ellipses = [];
2150
- this.konvaLayerFind("Ellipse").forEach((ellipse => {
2151
- const position = ellipse.position();
2137
+ this.konvaLayerFind("Ellipse").forEach((ref => {
2138
+ const position = ref.position();
2152
2139
  const worldPoint = this._worldTransformer.screenToWorld(position);
2153
- const shape = new KonvaEllipse(null, ellipse);
2154
- ellipses.push({
2140
+ const shape = new KonvaEllipse(null, ref);
2141
+ const ellipse = {
2155
2142
  id: shape.id(),
2156
2143
  position: worldPoint,
2157
2144
  radius: {
2158
- x: ellipse.getRadiusX(),
2159
- y: ellipse.getRadiusY()
2145
+ x: ref.getRadiusX(),
2146
+ y: ref.getRadiusY()
2160
2147
  },
2161
2148
  line_width: shape.getLineWidth(),
2162
2149
  color: shape.getColor()
2163
- });
2150
+ };
2151
+ ellipses.push(ellipse);
2164
2152
  }));
2165
2153
  return ellipses;
2166
2154
  }
2167
2155
  getMarkupArrows() {
2168
2156
  const arrows = [];
2169
- this.konvaLayerFind("Arrow").forEach((arrow => {
2170
- const absoluteTransform = arrow.getAbsoluteTransform();
2157
+ this.konvaLayerFind("Arrow").forEach((ref => {
2158
+ const absoluteTransform = ref.getAbsoluteTransform();
2171
2159
  const atStartPoint = absoluteTransform.point({
2172
- x: arrow.points()[0],
2173
- y: arrow.points()[1]
2160
+ x: ref.points()[0],
2161
+ y: ref.points()[1]
2174
2162
  });
2175
2163
  const worldStartPoint = this._worldTransformer.screenToWorld(atStartPoint);
2176
2164
  const atEndPoint = absoluteTransform.point({
2177
- x: arrow.points()[2],
2178
- y: arrow.points()[3]
2165
+ x: ref.points()[2],
2166
+ y: ref.points()[3]
2179
2167
  });
2180
2168
  const worldEndPoint = this._worldTransformer.screenToWorld(atEndPoint);
2181
- const shape = new KonvaArrow(null, arrow);
2182
- arrows.push({
2169
+ const shape = new KonvaArrow(null, ref);
2170
+ const arrow = {
2183
2171
  id: shape.id(),
2184
2172
  start: worldStartPoint,
2185
2173
  end: worldEndPoint,
2186
2174
  color: shape.getColor()
2187
- });
2175
+ };
2176
+ arrows.push(arrow);
2188
2177
  }));
2189
2178
  return arrows;
2190
2179
  }
2191
2180
  getMarkupImages() {
2192
2181
  const images = [];
2193
- this.konvaLayerFind("Image").forEach((image => {
2194
- const position = image.position();
2182
+ this.konvaLayerFind("Image").forEach((ref => {
2183
+ const position = ref.position();
2195
2184
  const worldPoint = this._worldTransformer.screenToWorld(position);
2196
- const shape = new KonvaImage(null, image);
2197
- images.push({
2185
+ const shape = new KonvaImage(null, ref);
2186
+ const image = {
2198
2187
  id: shape.id(),
2199
2188
  position: worldPoint,
2200
2189
  src: shape.getSrc(),
2201
2190
  width: shape.getWidth(),
2202
2191
  height: shape.getHeight()
2203
- });
2192
+ };
2193
+ images.push(image);
2204
2194
  }));
2205
2195
  return images;
2206
2196
  }
2207
2197
  getMarkupClouds() {
2208
2198
  const clouds = [];
2209
- this.konvaLayerFind("Cloud").forEach((cloud => {
2210
- const position = cloud.position();
2199
+ this.konvaLayerFind("Cloud").forEach((ref => {
2200
+ const position = ref.position();
2211
2201
  const worldPoint = this._worldTransformer.screenToWorld(position);
2212
- const shape = new KonvaCloud(null, cloud);
2213
- clouds.push({
2202
+ const shape = new KonvaCloud(null, ref);
2203
+ const cloud = {
2214
2204
  id: shape.id(),
2215
2205
  position: worldPoint,
2216
2206
  width: shape.getWidth(),
2217
2207
  height: shape.getHeigth(),
2218
2208
  line_width: shape.getLineWidth(),
2219
2209
  color: shape.getColor()
2220
- });
2210
+ };
2211
+ clouds.push(cloud);
2221
2212
  }));
2222
2213
  return clouds;
2223
2214
  }
2224
- loadMarkup(viewpoint) {
2225
- var _a, _b, _c, _d, _e, _f, _g;
2226
- (_a = viewpoint.lines) === null || _a === void 0 ? void 0 : _a.forEach((vpLine => {
2227
- const linePoints = [];
2228
- vpLine.points.forEach((point => {
2229
- const screenPoint = this._worldTransformer.worldToScreen(point);
2230
- linePoints.push(screenPoint.x);
2231
- linePoints.push(screenPoint.y);
2232
- }));
2233
- this.addLine(linePoints, vpLine.color, vpLine.type, vpLine.width, vpLine.id);
2234
- }));
2235
- (_b = viewpoint.texts) === null || _b === void 0 ? void 0 : _b.forEach((vpText => {
2236
- const screenPoint = this._worldTransformer.worldToScreen(vpText.position);
2237
- this.addText(vpText.text, screenPoint, vpText.angle, vpText.color, vpText.text_size, vpText.font_size, vpText.id);
2238
- }));
2239
- (_c = viewpoint.rectangles) === null || _c === void 0 ? void 0 : _c.forEach((vpRect => {
2240
- const screenPoint = this._worldTransformer.worldToScreen(vpRect.position);
2241
- this.addRectangle(screenPoint, vpRect.width, vpRect.height, vpRect.line_width, vpRect.color, vpRect.id);
2242
- }));
2243
- (_d = viewpoint.ellipses) === null || _d === void 0 ? void 0 : _d.forEach((vpEllipse => {
2244
- const screenPoint = this._worldTransformer.worldToScreen(vpEllipse.position);
2245
- this.addEllipse(screenPoint, vpEllipse.radius, vpEllipse.line_width, vpEllipse.color, vpEllipse.id);
2246
- }));
2247
- (_e = viewpoint.arrows) === null || _e === void 0 ? void 0 : _e.forEach((vpArrow => {
2248
- const startPoint = this._worldTransformer.worldToScreen(vpArrow.start);
2249
- const endPoint = this._worldTransformer.worldToScreen(vpArrow.end);
2250
- this.addArrow(startPoint, endPoint, vpArrow.color, vpArrow.id);
2251
- }));
2252
- (_f = viewpoint.clouds) === null || _f === void 0 ? void 0 : _f.forEach((vpCloud => {
2253
- const screenPoint = this._worldTransformer.worldToScreen(vpCloud.position);
2254
- this.addCloud(screenPoint, vpCloud.width, vpCloud.height, vpCloud.line_width, vpCloud.color, vpCloud.id);
2255
- }));
2256
- (_g = viewpoint.images) === null || _g === void 0 ? void 0 : _g.forEach((vpImage => {
2257
- const screenPoint = this._worldTransformer.worldToScreen(vpImage.position);
2258
- this.addImage(screenPoint, vpImage.src, vpImage.width, vpImage.height, vpImage.id);
2259
- }));
2260
- }
2261
2215
  combineMarkupWithDrawing() {
2262
2216
  this.clearSelected();
2263
2217
  const tempCanvas = document.createElement("canvas");
2264
- tempCanvas.width = this._konvaStage.width();
2265
- tempCanvas.height = this._konvaStage.height();
2266
- const ctx = tempCanvas.getContext("2d");
2267
- if (this._container instanceof HTMLCanvasElement) ctx.drawImage(this._container, 0, 0);
2268
- ctx.drawImage(this._konvaStage.toCanvas({
2269
- pixelRatio: window.devicePixelRatio
2270
- }), 0, 0);
2218
+ if (this._konvaStage) {
2219
+ tempCanvas.width = this._konvaStage.width();
2220
+ tempCanvas.height = this._konvaStage.height();
2221
+ const ctx = tempCanvas.getContext("2d");
2222
+ if (this._container instanceof HTMLCanvasElement) ctx.drawImage(this._container, 0, 0);
2223
+ ctx.drawImage(this._konvaStage.toCanvas({
2224
+ pixelRatio: window.devicePixelRatio
2225
+ }), 0, 0);
2226
+ }
2271
2227
  return tempCanvas.toDataURL("image/jpeg", .25);
2272
2228
  }
2273
2229
  addLine(linePoints, color, type, width, id) {
@@ -2286,8 +2242,7 @@ class KonvaMarkup {
2286
2242
  color: color || this._markupColor.HexColor,
2287
2243
  id: id
2288
2244
  });
2289
- const obj = konvaLine.ref();
2290
- this._konvaLayer.add(obj);
2245
+ this.addObject(konvaLine);
2291
2246
  return konvaLine;
2292
2247
  }
2293
2248
  createTextInput(pos, inputX, inputY, angle, text) {
@@ -2368,34 +2323,31 @@ class KonvaMarkup {
2368
2323
  this._imageInputRef = null;
2369
2324
  this._imageInputPos = null;
2370
2325
  }
2371
- addText(specifiedText, position, angle, color, textSize, fontSize, id) {
2372
- const trNodes = this._konvaTransformer.nodes();
2373
- if (trNodes.length > 0) {
2374
- trNodes[0].destroy();
2375
- this._konvaTransformer.nodes([]);
2376
- }
2326
+ addText(text, position, angle, color, textSize, fontSize, id) {
2327
+ var _a;
2328
+ if (!text) return;
2329
+ (_a = this.getSelectedObjects().at(0)) === null || _a === void 0 ? void 0 : _a.delete();
2330
+ this.clearSelected();
2377
2331
  this.removeTextInput();
2378
- if (specifiedText) {
2379
- const tolerance = 1e-6;
2380
- if (textSize && textSize > tolerance && (!fontSize || fontSize < tolerance)) {
2381
- const size = .02;
2382
- const scale = this._worldTransformer.getScale();
2383
- fontSize = textSize / (scale.y / size) / 34;
2384
- }
2385
- const konvaText = new KonvaText({
2386
- position: {
2387
- x: position.x,
2388
- y: position.y
2389
- },
2390
- text: specifiedText,
2391
- rotation: angle,
2392
- fontSize: fontSize || this.fontSize,
2393
- color: color || this._markupColor.HexColor,
2394
- id: id
2395
- });
2396
- this._konvaLayer.add(konvaText.ref());
2397
- return konvaText;
2398
- }
2332
+ const tolerance = 1e-6;
2333
+ if (textSize && textSize > tolerance && (!fontSize || fontSize < tolerance)) {
2334
+ const size = .02;
2335
+ const scale = this._worldTransformer.getScale();
2336
+ fontSize = textSize / (scale.y / size) / 34;
2337
+ }
2338
+ const konvaText = new KonvaText({
2339
+ position: {
2340
+ x: position.x,
2341
+ y: position.y
2342
+ },
2343
+ text: text,
2344
+ rotation: angle,
2345
+ fontSize: fontSize || this.fontSize,
2346
+ color: color || this._markupColor.HexColor,
2347
+ id: id
2348
+ });
2349
+ this.addObject(konvaText);
2350
+ return konvaText;
2399
2351
  }
2400
2352
  addRectangle(position, width, height, lineWidth, color, id) {
2401
2353
  if (!position) return;
@@ -2407,8 +2359,7 @@ class KonvaMarkup {
2407
2359
  color: color || this._markupColor.HexColor,
2408
2360
  id: id
2409
2361
  });
2410
- const obj = konvaRectangle.ref();
2411
- this._konvaLayer.add(obj);
2362
+ this.addObject(konvaRectangle);
2412
2363
  return konvaRectangle;
2413
2364
  }
2414
2365
  addEllipse(position, radius, lineWidth, color, id) {
@@ -2420,8 +2371,7 @@ class KonvaMarkup {
2420
2371
  color: color || this._markupColor.HexColor,
2421
2372
  id: id
2422
2373
  });
2423
- const obj = konvaEllipse.ref();
2424
- this._konvaLayer.add(obj);
2374
+ this.addObject(konvaEllipse);
2425
2375
  return konvaEllipse;
2426
2376
  }
2427
2377
  addArrow(start, end, color, id) {
@@ -2432,8 +2382,7 @@ class KonvaMarkup {
2432
2382
  color: color || this._markupColor.HexColor,
2433
2383
  id: id
2434
2384
  });
2435
- const obj = konvaArrow.ref();
2436
- this._konvaLayer.add(obj);
2385
+ this.addObject(konvaArrow);
2437
2386
  return konvaArrow;
2438
2387
  }
2439
2388
  addCloud(position, width, height, lineWidth, color, id) {
@@ -2446,30 +2395,23 @@ class KonvaMarkup {
2446
2395
  lineWidth: lineWidth || this.lineWidth,
2447
2396
  id: id
2448
2397
  });
2449
- const obj = konvaCloud.ref();
2450
- this._konvaLayer.add(obj);
2398
+ this.addObject(konvaCloud);
2451
2399
  return konvaCloud;
2452
2400
  }
2453
2401
  addImage(position, src, width, height, id) {
2454
- if (!position) return;
2455
- let konvaImage;
2456
- if (src) {
2457
- konvaImage = new KonvaImage({
2458
- position: position,
2459
- src: src,
2460
- width: width,
2461
- height: height,
2462
- id: id
2463
- });
2464
- const obj = konvaImage.ref();
2465
- this._konvaLayer.add(obj);
2466
- const trNodes = this._konvaTransformer.nodes();
2467
- if (trNodes.length > 0) {
2468
- trNodes[0].destroy();
2469
- this._konvaTransformer.nodes([]);
2470
- }
2471
- }
2402
+ var _a;
2403
+ if (!position || !src) return;
2404
+ (_a = this.getSelectedObjects().at(0)) === null || _a === void 0 ? void 0 : _a.delete();
2405
+ this.clearSelected();
2472
2406
  this.removeImageInput();
2407
+ const konvaImage = new KonvaImage({
2408
+ position: position,
2409
+ src: src,
2410
+ width: width,
2411
+ height: height,
2412
+ id: id
2413
+ });
2414
+ this.addObject(konvaImage);
2473
2415
  return konvaImage;
2474
2416
  }
2475
2417
  }
@@ -5190,6 +5132,8 @@ class Viewer extends EventEmitter2 {
5190
5132
  canvas.style.touchAction = "none";
5191
5133
  canvas.width = canvas.clientWidth * window.devicePixelRatio;
5192
5134
  canvas.height = canvas.clientHeight * window.devicePixelRatio;
5135
+ this._visualizeTimestamp = Date.now();
5136
+ const visualizeTimestamp = this._visualizeTimestamp;
5193
5137
  const visualizeJs = await loadVisualizeJs(this.visualizeJsUrl, (event => {
5194
5138
  const {loaded: loaded, total: total} = event;
5195
5139
  if (onProgress) onProgress(new ProgressEvent("progress", {
@@ -5204,6 +5148,10 @@ class Viewer extends EventEmitter2 {
5204
5148
  total: total
5205
5149
  });
5206
5150
  }));
5151
+ if (visualizeTimestamp !== this._visualizeTimestamp) {
5152
+ console.error("Viewer error: dispose() was called before initialize() completed. Are you using React strict mode?");
5153
+ return this;
5154
+ }
5207
5155
  this._visualizeJs = visualizeJs;
5208
5156
  this.visualizeJs.canvas = canvas;
5209
5157
  this.visualizeJs.Viewer.create();
@@ -5249,6 +5197,7 @@ class Viewer extends EventEmitter2 {
5249
5197
  }
5250
5198
  if (this._visualizeJs) this._visualizeJs.getViewer().clear();
5251
5199
  this._visualizeJs = undefined;
5200
+ this._visualizeTimestamp = undefined;
5252
5201
  return this;
5253
5202
  }
5254
5203
  isInitialized() {