@inweb/viewer-visualize 25.7.4 → 25.7.6

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.
@@ -705,19 +705,6 @@ function zoomToSelected(viewer) {
705
705
 
706
706
  commands("VisualizeJS").registerCommand("zoomToSelected", zoomToSelected);
707
707
 
708
- var MarkupMode;
709
-
710
- (function(MarkupMode) {
711
- MarkupMode["SelectMarkup"] = "SelectMarkup";
712
- MarkupMode["Line"] = "Line";
713
- MarkupMode["Text"] = "Text";
714
- MarkupMode["Rectangle"] = "Rectangle";
715
- MarkupMode["Ellipse"] = "Ellipse";
716
- MarkupMode["Arrow"] = "Arrow";
717
- MarkupMode["Image"] = "Image";
718
- MarkupMode["Cloud"] = "Cloud";
719
- })(MarkupMode || (MarkupMode = {}));
720
-
721
708
  class MarkupColor {
722
709
  get HexColor() {
723
710
  return "#" + this._hex;
@@ -1577,31 +1564,40 @@ class KonvaCloud {
1577
1564
  }
1578
1565
  }
1579
1566
 
1580
- const MarkupMode2Konva = new Map([ [ MarkupMode.SelectMarkup, {
1581
- name: "SelectMarkup",
1582
- initializer: () => {}
1583
- } ], [ MarkupMode.Line, {
1584
- name: "Line",
1585
- initializer: ref => new KonvaLine(null, ref)
1586
- } ], [ MarkupMode.Text, {
1587
- name: "Text",
1588
- initializer: ref => new KonvaText(null, ref)
1589
- } ], [ MarkupMode.Rectangle, {
1590
- name: "Rect",
1591
- initializer: ref => new KonvaRectangle(null, ref)
1592
- } ], [ MarkupMode.Ellipse, {
1593
- name: "Ellipse",
1594
- initializer: ref => new KonvaEllipse(null, ref)
1595
- } ], [ MarkupMode.Arrow, {
1596
- name: "Arrow",
1597
- initializer: ref => new KonvaArrow(null, ref)
1598
- } ], [ MarkupMode.Image, {
1599
- name: "Image",
1600
- initializer: ref => new KonvaImage(null, ref)
1601
- } ], [ MarkupMode.Cloud, {
1602
- name: "Cloud",
1603
- initializer: ref => new KonvaCloud(null, ref)
1604
- } ] ]);
1567
+ const MarkupMode2Konva = {
1568
+ SelectMarkup: {
1569
+ name: "SelectMarkup",
1570
+ initializer: null
1571
+ },
1572
+ Line: {
1573
+ name: "Line",
1574
+ initializer: ref => new KonvaLine(null, ref)
1575
+ },
1576
+ Text: {
1577
+ name: "Text",
1578
+ initializer: ref => new KonvaText(null, ref)
1579
+ },
1580
+ Rectangle: {
1581
+ name: "Rect",
1582
+ initializer: ref => new KonvaRectangle(null, ref)
1583
+ },
1584
+ Ellipse: {
1585
+ name: "Ellipse",
1586
+ initializer: ref => new KonvaEllipse(null, ref)
1587
+ },
1588
+ Arrow: {
1589
+ name: "Arrow",
1590
+ initializer: ref => new KonvaArrow(null, ref)
1591
+ },
1592
+ Image: {
1593
+ name: "Image",
1594
+ initializer: ref => new KonvaImage(null, ref)
1595
+ },
1596
+ Cloud: {
1597
+ name: "Cloud",
1598
+ initializer: ref => new KonvaCloud(null, ref)
1599
+ }
1600
+ };
1605
1601
 
1606
1602
  class KonvaMarkup {
1607
1603
  constructor() {
@@ -1618,10 +1614,9 @@ class KonvaMarkup {
1618
1614
  this._markupContainer.className = this._canvasOriginal.className.split(" ").filter((x => !x.startsWith("oda-cursor-"))).filter((x => x)).concat(`oda-cursor-${draggerName.toLowerCase()}`).join(" ");
1619
1615
  this.removeTextInput();
1620
1616
  this.removeImageInput();
1621
- const markupMode = MarkupMode[draggerName];
1622
- const konvaMode = MarkupMode2Konva.get(markupMode);
1623
- if (konvaMode) {
1624
- this._markupMode = markupMode;
1617
+ const konvaShape = MarkupMode2Konva[draggerName];
1618
+ if (konvaShape) {
1619
+ this._markupMode = draggerName;
1625
1620
  this._markupIsActive = true;
1626
1621
  } else {
1627
1622
  this._markupIsActive = false;
@@ -1636,7 +1631,7 @@ class KonvaMarkup {
1636
1631
  this.pan = event => {
1637
1632
  const dX = event.dX / window.devicePixelRatio;
1638
1633
  const dY = event.dY / window.devicePixelRatio;
1639
- Object.values(MarkupMode).forEach((mode => this.konvaLayerFind(mode).forEach((x => x.move({
1634
+ Object.keys(MarkupMode2Konva).forEach((mode => this.konvaLayerFind(mode).forEach((ref => ref.move({
1640
1635
  x: dX,
1641
1636
  y: dY
1642
1637
  })))));
@@ -1692,7 +1687,7 @@ class KonvaMarkup {
1692
1687
  this.removeTextInput();
1693
1688
  this.removeImageInput();
1694
1689
  this._konvaTransformer.nodes([]);
1695
- Object.values(MarkupMode).forEach((mode => this.konvaLayerFind(mode).forEach((x => x.destroy()))));
1690
+ Object.keys(MarkupMode2Konva).forEach((mode => this.konvaLayerFind(mode).forEach((ref => ref.destroy()))));
1696
1691
  }
1697
1692
  getMarkupColor() {
1698
1693
  return this._markupColor.RGB;
@@ -1702,11 +1697,11 @@ class KonvaMarkup {
1702
1697
  }
1703
1698
  colorizeAllMarkup(r = 255, g = 0, b = 0) {
1704
1699
  const hex = new MarkupColor(r, g, b).HexColor;
1705
- Object.values(MarkupMode).forEach((mode => {
1706
- this.konvaLayerFind(mode).forEach((x => {
1707
- var _a;
1708
- const konvaObj = (_a = MarkupMode2Konva.get(mode)) === null || _a === void 0 ? void 0 : _a.initializer(x);
1709
- if (konvaObj && konvaObj.setColor) konvaObj.setColor(hex);
1700
+ Object.keys(MarkupMode2Konva).forEach((mode => {
1701
+ this.konvaLayerFind(mode).forEach((ref => {
1702
+ const konvaShape = MarkupMode2Konva[mode];
1703
+ const konvaObj = konvaShape.initializer(ref);
1704
+ if (konvaObj.setColor) konvaObj.setColor(hex);
1710
1705
  }));
1711
1706
  }));
1712
1707
  this._konvaLayer.draw();
@@ -1795,25 +1790,25 @@ class KonvaMarkup {
1795
1790
  }
1796
1791
  getObjects() {
1797
1792
  const objects = [];
1798
- this.konvaLayerFind(MarkupMode.Line).forEach((line => {
1793
+ this.konvaLayerFind("Line").forEach((line => {
1799
1794
  objects.push(new KonvaLine(null, line));
1800
1795
  }));
1801
- this.konvaLayerFind(MarkupMode.Text).forEach((text => {
1796
+ this.konvaLayerFind("Text").forEach((text => {
1802
1797
  objects.push(new KonvaText(null, text));
1803
1798
  }));
1804
- this.konvaLayerFind(MarkupMode.Rectangle).forEach((rectangle => {
1799
+ this.konvaLayerFind("Rectangle").forEach((rectangle => {
1805
1800
  objects.push(new KonvaRectangle(null, rectangle));
1806
1801
  }));
1807
- this.konvaLayerFind(MarkupMode.Ellipse).forEach((ellipse => {
1802
+ this.konvaLayerFind("Ellipse").forEach((ellipse => {
1808
1803
  objects.push(new KonvaEllipse(null, ellipse));
1809
1804
  }));
1810
- this.konvaLayerFind(MarkupMode.Arrow).forEach((arrow => {
1805
+ this.konvaLayerFind("Arrow").forEach((arrow => {
1811
1806
  objects.push(new KonvaArrow(null, arrow));
1812
1807
  }));
1813
- this.konvaLayerFind(MarkupMode.Image).forEach((image => {
1808
+ this.konvaLayerFind("Image").forEach((image => {
1814
1809
  objects.push(new KonvaImage(null, image));
1815
1810
  }));
1816
- this.konvaLayerFind(MarkupMode.Cloud).forEach((cloud => {
1811
+ this.konvaLayerFind("Cloud").forEach((cloud => {
1817
1812
  objects.push(new KonvaCloud(null, cloud));
1818
1813
  }));
1819
1814
  return objects;
@@ -1916,10 +1911,9 @@ class KonvaMarkup {
1916
1911
  this._konvaLayer.add(object.ref());
1917
1912
  }
1918
1913
  konvaLayerFind(markupShape) {
1919
- const konvaShape = MarkupMode2Konva.get(markupShape);
1920
- if (konvaShape) {
1921
- const konvaShapes = this._konvaLayer.find(konvaShape.name).filter((x => x.parent instanceof Konva.Layer));
1922
- return konvaShapes;
1914
+ const konvaShape = MarkupMode2Konva[markupShape];
1915
+ if (konvaShape && konvaShape.initializer) {
1916
+ return this._konvaLayer.find(konvaShape.name).filter((ref => ref.parent === this._konvaLayer));
1923
1917
  }
1924
1918
  return [];
1925
1919
  }
@@ -1947,15 +1941,15 @@ class KonvaMarkup {
1947
1941
  let mouseDownPos;
1948
1942
  let lastObj;
1949
1943
  stage.on("mousedown touchstart", (e => {
1950
- if (!this._markupIsActive || e.target !== stage || this._markupMode === MarkupMode.Text || this._markupMode === MarkupMode.Image) return;
1944
+ if (!this._markupIsActive || e.target !== stage || this._markupMode === "Text" || this._markupMode === "Image") return;
1951
1945
  if (e.target === stage && transformer.nodes().length > 0) {
1952
1946
  transformer.nodes([]);
1953
1947
  return;
1954
1948
  }
1955
1949
  const pos = stage.getPointerPosition();
1956
1950
  mouseDownPos = pos;
1957
- isPaint = [ MarkupMode.Arrow, MarkupMode.Cloud, MarkupMode.Ellipse, MarkupMode.Line, MarkupMode.Rectangle ].some((m => m === this._markupMode));
1958
- if (this._markupMode === MarkupMode.Line) {
1951
+ isPaint = [ "Arrow", "Cloud", "Ellipse", "Line", "Rectangle" ].some((m => m === this._markupMode));
1952
+ if (this._markupMode === "Line") {
1959
1953
  lastLine = this.addLine([ pos.x, pos.y, pos.x, pos.y ]);
1960
1954
  }
1961
1955
  }));
@@ -1969,12 +1963,12 @@ class KonvaMarkup {
1969
1963
  const dX = defParams ? 200 : Math.abs(mouseDownPos.x - pos.x);
1970
1964
  const dY = defParams ? 200 : Math.abs(mouseDownPos.y - pos.y);
1971
1965
  if (defParams) {
1972
- if (this._markupMode === MarkupMode.Rectangle) {
1966
+ if (this._markupMode === "Rectangle") {
1973
1967
  this.addRectangle({
1974
1968
  x: startX,
1975
1969
  y: startY
1976
1970
  }, dX, dY);
1977
- } else if (this._markupMode === MarkupMode.Ellipse) {
1971
+ } else if (this._markupMode === "Ellipse") {
1978
1972
  this.addEllipse({
1979
1973
  x: startX,
1980
1974
  y: startY
@@ -1982,7 +1976,7 @@ class KonvaMarkup {
1982
1976
  x: dX / 2,
1983
1977
  y: dY / 2
1984
1978
  });
1985
- } else if (this._markupMode === MarkupMode.Arrow) {
1979
+ } else if (this._markupMode === "Arrow") {
1986
1980
  this.addArrow({
1987
1981
  x: mouseDownPos.x,
1988
1982
  y: mouseDownPos.y
@@ -1990,7 +1984,7 @@ class KonvaMarkup {
1990
1984
  x: defParams ? mouseDownPos.x + 200 : pos.x,
1991
1985
  y: defParams ? startY : pos.y
1992
1986
  });
1993
- } else if (this._markupMode === MarkupMode.Cloud) {
1987
+ } else if (this._markupMode === "Cloud") {
1994
1988
  this.addCloud({
1995
1989
  x: startX,
1996
1990
  y: startY
@@ -2012,12 +2006,12 @@ class KonvaMarkup {
2012
2006
  const startY = defParams ? mouseDownPos.y : Math.min(mouseDownPos.y, pos.y);
2013
2007
  const dX = defParams ? 200 : Math.abs(mouseDownPos.x - pos.x);
2014
2008
  const dY = defParams ? 200 : Math.abs(mouseDownPos.y - pos.y);
2015
- if (this._markupMode === MarkupMode.Line) {
2009
+ if (this._markupMode === "Line") {
2016
2010
  lastLine.addPoints([ {
2017
2011
  x: pos.x,
2018
2012
  y: pos.y
2019
2013
  } ]);
2020
- } else if (this._markupMode === MarkupMode.Arrow) {
2014
+ } else if (this._markupMode === "Arrow") {
2021
2015
  if (lastObj) lastObj.setEndPoint(pos.x, pos.y); else lastObj = this.addArrow({
2022
2016
  x: mouseDownPos.x,
2023
2017
  y: mouseDownPos.y
@@ -2025,7 +2019,7 @@ class KonvaMarkup {
2025
2019
  x: pos.x,
2026
2020
  y: pos.y
2027
2021
  });
2028
- } else if (this._markupMode === MarkupMode.Rectangle) {
2022
+ } else if (this._markupMode === "Rectangle") {
2029
2023
  if (lastObj) {
2030
2024
  lastObj.setPosition(startX, startY);
2031
2025
  lastObj.setWidth(dX);
@@ -2034,7 +2028,7 @@ class KonvaMarkup {
2034
2028
  x: startX,
2035
2029
  y: startY
2036
2030
  }, dX, dY);
2037
- } else if (this._markupMode === MarkupMode.Ellipse) {
2031
+ } else if (this._markupMode === "Ellipse") {
2038
2032
  if (lastObj) {
2039
2033
  lastObj.setPosition(startX, startY);
2040
2034
  lastObj.setRadiusX(dX);
@@ -2046,7 +2040,7 @@ class KonvaMarkup {
2046
2040
  x: dX,
2047
2041
  y: dY
2048
2042
  });
2049
- } else if (this._markupMode === MarkupMode.Cloud) {
2043
+ } else if (this._markupMode === "Cloud") {
2050
2044
  if (lastObj) {
2051
2045
  lastObj.setPosition(startX, startY);
2052
2046
  lastObj.setWidth(Math.max(100, dX));
@@ -2060,12 +2054,12 @@ class KonvaMarkup {
2060
2054
  stage.on("click tap", (e => {
2061
2055
  if (!this._markupIsActive) return;
2062
2056
  if (e.target === stage) {
2063
- if (this._markupMode === MarkupMode.Text) {
2057
+ if (this._markupMode === "Text") {
2064
2058
  if (this._textInputRef && this._textInputRef.value) this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle); else if (transformer.nodes().length === 0) {
2065
2059
  const pos = stage.getPointerPosition();
2066
2060
  this.createTextInput(pos, e.evt.pageX, e.evt.pageY, 0, null);
2067
2061
  }
2068
- } else if (this._markupMode === MarkupMode.Image) {
2062
+ } else if (this._markupMode === "Image") {
2069
2063
  if (this._imageInputRef && this._imageInputRef.value) this.addImage({
2070
2064
  x: this._imageInputPos.x,
2071
2065
  y: this._imageInputPos.y
@@ -2077,7 +2071,7 @@ class KonvaMarkup {
2077
2071
  transformer.nodes([]);
2078
2072
  return;
2079
2073
  }
2080
- if (this._markupMode === MarkupMode.Text || this._markupMode === MarkupMode.SelectMarkup) {
2074
+ if (this._markupMode === "Text" || this._markupMode === "SelectMarkup") {
2081
2075
  if (e.target.className === "Text" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
2082
2076
  if (this._textInputRef && this._textInputRef.value) this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle); else this.createTextInput({
2083
2077
  x: e.target.attrs.x,
@@ -2088,7 +2082,7 @@ class KonvaMarkup {
2088
2082
  this.removeTextInput();
2089
2083
  }
2090
2084
  }
2091
- if (this._markupMode === MarkupMode.Image || this._markupMode === MarkupMode.SelectMarkup) {
2085
+ if (this._markupMode === "Image" || this._markupMode === "SelectMarkup") {
2092
2086
  if (e.target.className === "Image" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
2093
2087
  if (this._imageInputRef && this._imageInputRef.value) this.addImage(this._imageInputPos, this._imageInputRef.value, 0, 0); else this.createImageInput({
2094
2088
  x: e.target.attrs.x,
@@ -2143,7 +2137,7 @@ class KonvaMarkup {
2143
2137
  }
2144
2138
  getMarkupLines() {
2145
2139
  const lines = [];
2146
- this.konvaLayerFind(MarkupMode.Line).forEach((line => {
2140
+ this.konvaLayerFind("Line").forEach((line => {
2147
2141
  const linePoints = line.points();
2148
2142
  if (!linePoints) return;
2149
2143
  const worldPoints = [];
@@ -2171,7 +2165,7 @@ class KonvaMarkup {
2171
2165
  const texts = [];
2172
2166
  const textSize = .02;
2173
2167
  const textScale = this._worldTransformer.getScale();
2174
- this.konvaLayerFind(MarkupMode.Text).forEach((text => {
2168
+ this.konvaLayerFind("Text").forEach((text => {
2175
2169
  if (!text) return;
2176
2170
  const position = this._worldTransformer.screenToWorld({
2177
2171
  x: text.x(),
@@ -2192,7 +2186,7 @@ class KonvaMarkup {
2192
2186
  }
2193
2187
  getMarkupRectangles() {
2194
2188
  const rectangles = [];
2195
- this.konvaLayerFind(MarkupMode.Rectangle).forEach((rect => {
2189
+ this.konvaLayerFind("Rectangle").forEach((rect => {
2196
2190
  const position = rect.position();
2197
2191
  const worldPoint = this._worldTransformer.screenToWorld(position);
2198
2192
  const shape = new KonvaRectangle(null, rect);
@@ -2209,7 +2203,7 @@ class KonvaMarkup {
2209
2203
  }
2210
2204
  getMarkupEllipses() {
2211
2205
  const ellipses = [];
2212
- this.konvaLayerFind(MarkupMode.Ellipse).forEach((ellipse => {
2206
+ this.konvaLayerFind("Ellipse").forEach((ellipse => {
2213
2207
  const position = ellipse.position();
2214
2208
  const worldPoint = this._worldTransformer.screenToWorld(position);
2215
2209
  const shape = new KonvaEllipse(null, ellipse);
@@ -2228,7 +2222,7 @@ class KonvaMarkup {
2228
2222
  }
2229
2223
  getMarkupArrows() {
2230
2224
  const arrows = [];
2231
- this.konvaLayerFind(MarkupMode.Arrow).forEach((arrow => {
2225
+ this.konvaLayerFind("Arrow").forEach((arrow => {
2232
2226
  const absoluteTransform = arrow.getAbsoluteTransform();
2233
2227
  const atStartPoint = absoluteTransform.point({
2234
2228
  x: arrow.points()[0],
@@ -2252,7 +2246,7 @@ class KonvaMarkup {
2252
2246
  }
2253
2247
  getMarkupImages() {
2254
2248
  const images = [];
2255
- this.konvaLayerFind(MarkupMode.Image).forEach((image => {
2249
+ this.konvaLayerFind("Image").forEach((image => {
2256
2250
  const position = image.position();
2257
2251
  const worldPoint = this._worldTransformer.screenToWorld(position);
2258
2252
  const shape = new KonvaImage(null, image);
@@ -2268,7 +2262,7 @@ class KonvaMarkup {
2268
2262
  }
2269
2263
  getMarkupClouds() {
2270
2264
  const clouds = [];
2271
- this.konvaLayerFind(MarkupMode.Cloud).forEach((cloud => {
2265
+ this.konvaLayerFind("Cloud").forEach((cloud => {
2272
2266
  const position = cloud.position();
2273
2267
  const worldPoint = this._worldTransformer.screenToWorld(position);
2274
2268
  const shape = new KonvaCloud(null, cloud);
@@ -5924,5 +5918,5 @@ class Viewer extends EventEmitter2 {
5924
5918
  }
5925
5919
  }
5926
5920
 
5927
- export { CANVAS_EVENTS, CanvasEvents, Dragger, KonvaMarkup as Markup, MarkupMode, MarkupType, OdBaseDragger, Options, Viewer, commands, defaultOptions };
5921
+ export { CANVAS_EVENTS, CanvasEvents, Dragger, KonvaMarkup as Markup, MarkupType, OdBaseDragger, Options, Viewer, commands, defaultOptions };
5928
5922
  //# sourceMappingURL=viewer-visualize.module.js.map