@inweb/viewer-visualize 25.7.9 → 25.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1571,31 +1571,37 @@ const MarkupMode2Konva = {
1571
1571
  },
1572
1572
  Line: {
1573
1573
  name: "Line",
1574
- initializer: ref => new KonvaLine(null, ref)
1574
+ initializer: (ref, params = null) => new KonvaLine(params, ref),
1575
+ zIndex: 1
1575
1576
  },
1576
1577
  Text: {
1577
1578
  name: "Text",
1578
- initializer: ref => new KonvaText(null, ref)
1579
+ initializer: (ref, params = null) => new KonvaText(params, ref)
1579
1580
  },
1580
1581
  Rectangle: {
1581
1582
  name: "Rect",
1582
- initializer: ref => new KonvaRectangle(null, ref)
1583
+ initializer: (ref, params = null) => new KonvaRectangle(params, ref),
1584
+ zIndex: 1
1583
1585
  },
1584
1586
  Ellipse: {
1585
1587
  name: "Ellipse",
1586
- initializer: ref => new KonvaEllipse(null, ref)
1588
+ initializer: (ref, params = null) => new KonvaEllipse(params, ref),
1589
+ zIndex: 1
1587
1590
  },
1588
1591
  Arrow: {
1589
1592
  name: "Arrow",
1590
- initializer: ref => new KonvaArrow(null, ref)
1593
+ initializer: (ref, params = null) => new KonvaArrow(params, ref),
1594
+ zIndex: 1
1591
1595
  },
1592
1596
  Image: {
1593
1597
  name: "Image",
1594
- initializer: ref => new KonvaImage(null, ref)
1598
+ initializer: (ref, params = null) => new KonvaImage(params, ref),
1599
+ zIndex: 0
1595
1600
  },
1596
1601
  Cloud: {
1597
1602
  name: "Cloud",
1598
- initializer: ref => new KonvaCloud(null, ref)
1603
+ initializer: ref => new KonvaCloud(null, ref),
1604
+ zIndex: 1
1599
1605
  }
1600
1606
  };
1601
1607
 
@@ -1614,14 +1620,7 @@ class KonvaMarkup {
1614
1620
  this._markupContainer.className = this._container.className.split(" ").filter((x => !x.startsWith("oda-cursor-"))).filter((x => x)).concat(`oda-cursor-${draggerName.toLowerCase()}`).join(" ");
1615
1621
  this.removeTextInput();
1616
1622
  this.removeImageInput();
1617
- const konvaShape = MarkupMode2Konva[draggerName];
1618
- if (konvaShape) {
1619
- this._markupMode = draggerName;
1620
- this._markupIsActive = true;
1621
- } else {
1622
- this._markupIsActive = false;
1623
- this._konvaTransformer.nodes([]);
1624
- }
1623
+ this.enableEditMode(draggerName);
1625
1624
  };
1626
1625
  this.resizeContainer = entries => {
1627
1626
  var _a, _b;
@@ -1633,10 +1632,10 @@ class KonvaMarkup {
1633
1632
  this.pan = event => {
1634
1633
  const dX = event.dX / window.devicePixelRatio;
1635
1634
  const dY = event.dY / window.devicePixelRatio;
1636
- Object.keys(MarkupMode2Konva).forEach((mode => this.konvaLayerFind(mode).forEach((ref => ref.move({
1635
+ this.getObjects().forEach((obj => obj.ref().move({
1637
1636
  x: dX,
1638
1637
  y: dY
1639
- })))));
1638
+ })));
1640
1639
  };
1641
1640
  this.redirectToViewer = event => {
1642
1641
  if (this._viewer) this._viewer.emit(event);
@@ -1689,8 +1688,8 @@ class KonvaMarkup {
1689
1688
  clearOverlay() {
1690
1689
  this.removeTextInput();
1691
1690
  this.removeImageInput();
1692
- this._konvaTransformer.nodes([]);
1693
- Object.keys(MarkupMode2Konva).forEach((mode => this.konvaLayerFind(mode).forEach((ref => ref.destroy()))));
1691
+ this.clearSelected();
1692
+ this.getObjects().forEach((obj => obj.ref().destroy()));
1694
1693
  }
1695
1694
  getMarkupColor() {
1696
1695
  return this._markupColor.RGB;
@@ -1698,23 +1697,19 @@ class KonvaMarkup {
1698
1697
  setMarkupColor(r, g, b) {
1699
1698
  this._markupColor.setColor(r, g, b);
1700
1699
  }
1701
- colorizeAllMarkup(r = 255, g = 0, b = 0) {
1702
- const hex = new MarkupColor(r, g, b).HexColor;
1703
- Object.keys(MarkupMode2Konva).forEach((mode => {
1704
- this.konvaLayerFind(mode).forEach((ref => {
1705
- const konvaShape = MarkupMode2Konva[mode];
1706
- const konvaObj = konvaShape.initializer(ref);
1707
- if (konvaObj.setColor) konvaObj.setColor(hex);
1708
- }));
1700
+ colorizeAllMarkup(r, g, b) {
1701
+ const hexColor = new MarkupColor(r, g, b).HexColor;
1702
+ this.getObjects().forEach((obj => {
1703
+ const colorable = obj;
1704
+ if (colorable && colorable.setColor) colorable.setColor(hexColor);
1709
1705
  }));
1710
1706
  this._konvaLayer.draw();
1711
1707
  }
1712
1708
  colorizeSelectedMarkups(r, g, b) {
1709
+ const hexColor = new MarkupColor(r, g, b).HexColor;
1713
1710
  this.getSelectedObjects().forEach((obj => {
1714
1711
  const colorable = obj;
1715
- if (colorable && colorable.setColor) {
1716
- colorable.setColor(new MarkupColor(r, g, b).HexColor);
1717
- }
1712
+ if (colorable && colorable.setColor) colorable.setColor(hexColor);
1718
1713
  }));
1719
1714
  }
1720
1715
  setViewpoint(viewpoint) {
@@ -1746,111 +1741,40 @@ class KonvaMarkup {
1746
1741
  viewpoint.description = (new Date).toDateString();
1747
1742
  return viewpoint;
1748
1743
  }
1749
- createObject(type, params) {
1750
- let object = null;
1751
- let zIndex = this._zIndex;
1752
- switch (type.toLocaleLowerCase()) {
1753
- case "line":
1754
- object = new KonvaLine(params);
1755
- zIndex = 1;
1756
- break;
1757
-
1758
- case "text":
1759
- object = new KonvaText(params);
1760
- break;
1761
-
1762
- case "rectangle":
1763
- object = new KonvaRectangle(params);
1764
- zIndex = 1;
1765
- break;
1766
-
1767
- case "ellipse":
1768
- object = new KonvaEllipse(params);
1769
- zIndex = 1;
1770
- break;
1771
-
1772
- case "arrow":
1773
- object = new KonvaArrow(params);
1774
- break;
1775
-
1776
- case "image":
1777
- object = new KonvaImage(params);
1778
- zIndex = 0;
1779
- break;
1780
-
1781
- case "cloud":
1782
- object = new KonvaCloud(params);
1783
- zIndex = 1;
1784
- break;
1785
-
1786
- default:
1787
- throw new Error("Markup CreateObject - unsupported type has been detected.");
1744
+ enableEditMode(mode) {
1745
+ if (!mode || !MarkupMode2Konva[mode]) {
1746
+ this.clearSelected();
1747
+ this._markupIsActive = false;
1748
+ } else {
1749
+ this._markupMode = mode;
1750
+ this._markupIsActive = true;
1788
1751
  }
1752
+ return this;
1753
+ }
1754
+ createObject(type, params) {
1755
+ var _a;
1756
+ const konvaShape = MarkupMode2Konva[type];
1757
+ if (!konvaShape || !konvaShape.initializer) throw new Error(`Markup CreateObject - unsupported markup type ${type}`);
1758
+ const object = konvaShape.initializer(null, params);
1789
1759
  this.addObject(object);
1790
- object.setZIndex(zIndex);
1760
+ object.setZIndex((_a = konvaShape.zIndex) !== null && _a !== void 0 ? _a : this._zIndex);
1791
1761
  this._zIndex++;
1792
1762
  return object;
1793
1763
  }
1794
1764
  getObjects() {
1795
1765
  const objects = [];
1796
- this.konvaLayerFind("Line").forEach((line => {
1797
- objects.push(new KonvaLine(null, line));
1798
- }));
1799
- this.konvaLayerFind("Text").forEach((text => {
1800
- objects.push(new KonvaText(null, text));
1801
- }));
1802
- this.konvaLayerFind("Rectangle").forEach((rectangle => {
1803
- objects.push(new KonvaRectangle(null, rectangle));
1804
- }));
1805
- this.konvaLayerFind("Ellipse").forEach((ellipse => {
1806
- objects.push(new KonvaEllipse(null, ellipse));
1807
- }));
1808
- this.konvaLayerFind("Arrow").forEach((arrow => {
1809
- objects.push(new KonvaArrow(null, arrow));
1810
- }));
1811
- this.konvaLayerFind("Image").forEach((image => {
1812
- objects.push(new KonvaImage(null, image));
1813
- }));
1814
- this.konvaLayerFind("Cloud").forEach((cloud => {
1815
- objects.push(new KonvaCloud(null, cloud));
1766
+ Object.keys(MarkupMode2Konva).forEach((type => {
1767
+ const konvaShape = MarkupMode2Konva[type];
1768
+ this.konvaLayerFind(type).forEach((ref => objects.push(konvaShape.initializer(ref))));
1816
1769
  }));
1817
1770
  return objects;
1818
1771
  }
1819
1772
  getSelectedObjects() {
1820
- const objects = [];
1821
- this._konvaTransformer.nodes().forEach((obj => {
1822
- const konvaShapeName = obj.className;
1823
- switch (konvaShapeName) {
1824
- case "Line":
1825
- objects.push(new KonvaLine(null, obj));
1826
- break;
1827
-
1828
- case "Text":
1829
- objects.push(new KonvaText(null, obj));
1830
- break;
1831
-
1832
- case "Rect":
1833
- objects.push(new KonvaRectangle(null, obj));
1834
- break;
1835
-
1836
- case "Ellipse":
1837
- objects.push(new KonvaEllipse(null, obj));
1838
- break;
1839
-
1840
- case "Arrow":
1841
- objects.push(new KonvaArrow(null, obj));
1842
- break;
1843
-
1844
- case "Image":
1845
- objects.push(new KonvaImage(null, obj));
1846
- break;
1847
-
1848
- case "Cloud":
1849
- objects.push(new KonvaCloud(null, obj));
1850
- break;
1851
- }
1852
- }));
1853
- return objects;
1773
+ return this._konvaTransformer.nodes().map((ref => {
1774
+ const name = ref.className;
1775
+ const konvaShape = Object.values(MarkupMode2Konva).find((shape => shape.name === name));
1776
+ return konvaShape ? konvaShape.initializer(ref) : null;
1777
+ })).filter((x => x));
1854
1778
  }
1855
1779
  selectObjects(objects) {
1856
1780
  const selectedObjs = this._konvaTransformer.nodes().concat(objects.map((x => x.ref())));
@@ -1913,8 +1837,8 @@ class KonvaMarkup {
1913
1837
  addObject(object) {
1914
1838
  this._konvaLayer.add(object.ref());
1915
1839
  }
1916
- konvaLayerFind(markupShape) {
1917
- const konvaShape = MarkupMode2Konva[markupShape];
1840
+ konvaLayerFind(type) {
1841
+ const konvaShape = MarkupMode2Konva[type];
1918
1842
  if (konvaShape && konvaShape.initializer) {
1919
1843
  return this._konvaLayer.find(konvaShape.name).filter((ref => ref.parent === this._konvaLayer));
1920
1844
  }
@@ -5144,6 +5068,9 @@ class VisualizeMarkup {
5144
5068
  viewpoint.description = (new Date).toDateString();
5145
5069
  return viewpoint;
5146
5070
  }
5071
+ enableEditMode(mode) {
5072
+ throw new Error("Not implemented yet");
5073
+ }
5147
5074
  createObject(type, params) {
5148
5075
  throw new Error("Not implemented yet");
5149
5076
  }