@inweb/viewer-visualize 25.8.19 → 25.8.21

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.
@@ -767,24 +767,24 @@ async function autoTransformAllModelsToCentralPoint(viewer, model) {
767
767
  commands("VisualizeJS").registerCommand("autoTransformAllModelsToCentralPoint", autoTransformAllModelsToCentralPoint);
768
768
 
769
769
  class MarkupColor {
770
- get HexColor() {
771
- return "#" + this._hex;
770
+ constructor(r, g, b) {
771
+ this.setColor(r, g, b);
772
+ }
773
+ asHex() {
774
+ return "#" + this.HEX;
772
775
  }
773
- get RGB() {
776
+ asRGB() {
774
777
  return {
775
778
  r: this.R,
776
779
  g: this.G,
777
780
  b: this.B
778
781
  };
779
782
  }
780
- constructor(r, g, b) {
781
- this.setColor(r, g, b);
782
- }
783
783
  setColor(r, g, b) {
784
784
  this.R = r;
785
785
  this.G = g;
786
786
  this.B = b;
787
- this._hex = this.rgbToHex(r, g, b);
787
+ this.HEX = this.rgbToHex(r, g, b);
788
788
  }
789
789
  rgbToHex(r, g, b) {
790
790
  const valueToHex = c => {
@@ -827,7 +827,14 @@ class KonvaLine {
827
827
  this._ref = ref;
828
828
  return;
829
829
  }
830
- if (!params || !params.points) return;
830
+ if (!params) params = {};
831
+ if (!params.points) params.points = [ {
832
+ x: 50,
833
+ y: 50
834
+ }, {
835
+ x: 100,
836
+ y: 100
837
+ } ];
831
838
  const konvaPoints = [];
832
839
  params.points.forEach((point => konvaPoints.push(point.x, point.y)));
833
840
  this._ref = new Konva.Line({
@@ -929,7 +936,12 @@ class KonvaText {
929
936
  this._ref = ref;
930
937
  return;
931
938
  }
932
- if (!params || !params.position || !params.text) return;
939
+ if (!params) params = {};
940
+ if (!params.position) params.position = {
941
+ x: 100,
942
+ y: 100
943
+ };
944
+ if (!params.text) params.text = "default";
933
945
  this._ref = new Konva.Text({
934
946
  x: params.position.x,
935
947
  y: params.position.y,
@@ -1031,7 +1043,11 @@ class KonvaRectangle {
1031
1043
  this._ref = ref;
1032
1044
  return;
1033
1045
  }
1034
- if (!params || !params.position) return;
1046
+ if (!params) params = {};
1047
+ if (!params.position) params.position = {
1048
+ x: 100,
1049
+ y: 100
1050
+ };
1035
1051
  this._ref = new Konva.Rect({
1036
1052
  stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
1037
1053
  strokeWidth: (_b = params.lineWidth) !== null && _b !== void 0 ? _b : 4,
@@ -1141,7 +1157,15 @@ class KonvaEllipse {
1141
1157
  this._ref = ref;
1142
1158
  return;
1143
1159
  }
1144
- if (!params || !params.position || !params.radius) return;
1160
+ if (!params) params = {};
1161
+ if (!params.position) params.position = {
1162
+ x: 100,
1163
+ y: 100
1164
+ };
1165
+ if (!params.radius) params.radius = {
1166
+ x: 25,
1167
+ y: 25
1168
+ };
1145
1169
  this._ref = new Konva.Ellipse({
1146
1170
  stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
1147
1171
  strokeWidth: (_b = params.lineWidth) !== null && _b !== void 0 ? _b : 4,
@@ -1263,7 +1287,15 @@ class KonvaArrow {
1263
1287
  this._ref = ref;
1264
1288
  return;
1265
1289
  }
1266
- if (!params || !params.start || !params.end) return;
1290
+ if (!params) params = {};
1291
+ if (!params.start) params.start = {
1292
+ x: 50,
1293
+ y: 50
1294
+ };
1295
+ if (!params.end) params.end = {
1296
+ x: 100,
1297
+ y: 100
1298
+ };
1267
1299
  this._ref = new Konva.Arrow({
1268
1300
  stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
1269
1301
  fill: (_b = params.color) !== null && _b !== void 0 ? _b : "#ff0000",
@@ -1360,22 +1392,24 @@ class KonvaImage {
1360
1392
  var _a, _b;
1361
1393
  this._ratio = 1;
1362
1394
  this.EPSILON = 1e-5;
1395
+ this.BASE64_NOT_FOUND = "data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAADsAAAA7AF5KHG9AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAmhJREFUWIXtlr9rVEEQxz+H8RQUJIdeIopYm0vkCg0GBBtbG1NF7Kxt7dR/IGIw/uhTaBNLERURg2kCEUyCYCPi70b0InjGS57FzOZN3r19d+9HJIVfWO52dma/s7Mz8xa2KAaBCWAR+AkECWOmSOIdwC1gtQOpHc+NfQ8wClQ8+1d0vcdH/lQ3bSIRGAZ2pTjAqNovANXIWlXlAXA2zvi2Ln4AjqYgtagYEutENSLvjRoOImFv5iB32Ae8UrLXwFBk3h9ndF0VJnKSO9gTu3yKu5Z1LKnS8YIcABgw5Ks692JZFXcXRJ46Aq6kikCnHNi/mQ50WwVtfaIoBzL3gRk2drSscJ2wrc4VvUoe2wn/41/iBfoVLRnBGnDSY3AAKacy8AmYR+o7K1zCl6wgrgpOAc/MuhvfgMuk+1JGHQgSBcAloKXy78AjYBppJk5/noTulseBMZ23iD/piHFkEdgTQzKk+5wHjmHC3cmBg0BD5xcSTrFXyQPgIWFtDwMvab+2N8DpbhyY1v/3E8gdDgNfVX9SCVZ0/gW4B0wB71S2BpxLcuCM/jaQSHSDEeAX4VMuAG4gTzyHbcAVXXO6GxxwIX+vvxe7JHcYQ07nHqklj96UIW/YhSWzMKcep8VVtf8B1Dw6h4DfhB+sdbgn2R+gnoEc5NR3dZ+3QJ9H74HqXLPCGlJyTfI9y3YCs0owq3OLOpKkLeBI1HhSDT/mdKIPiUCARMTlQx34TMLjtww8IczmO8AJ/N/2JNSQXAiQ671JePePge0+wzJSQq4FFzlaenIvucUAkiQLhC/mLGNZ9xgn5s63BP4CCk0QDtm4BhoAAAAASUVORK5CYII=";
1396
+ this.BASE64_HEADER_START = "data:image/";
1363
1397
  if (ref) {
1398
+ if (!ref.src || !ref.src.startsWith(this.BASE64_HEADER_START)) ref.src = this.BASE64_NOT_FOUND;
1399
+ if (ref.height() <= this.EPSILON) ref.height(32);
1400
+ if (ref.width() <= this.EPSILON) ref.width(32);
1364
1401
  this._ref = ref;
1365
1402
  this._canvasImage = ref.image();
1366
1403
  this._ratio = this._ref.height() <= this.EPSILON || this._ref.width() <= this.EPSILON ? 1 : this._ref.height() / this._ref.width();
1367
1404
  return;
1368
1405
  }
1369
- if (!params || !params.position || !params.src) return;
1406
+ if (!params) params = {};
1407
+ if (!params.position) params.position = {
1408
+ x: 50,
1409
+ y: 50
1410
+ };
1411
+ if (!params.src || !params.src.startsWith(this.BASE64_HEADER_START)) params.src = this.BASE64_NOT_FOUND;
1370
1412
  this._canvasImage = new Image;
1371
- this._ref = new Konva.Image({
1372
- x: params.position.x,
1373
- y: params.position.y,
1374
- image: this._canvasImage,
1375
- width: (_a = params.width) !== null && _a !== void 0 ? _a : 0,
1376
- height: (_b = params.height) !== null && _b !== void 0 ? _b : 0,
1377
- draggable: true
1378
- });
1379
1413
  this._canvasImage.onload = () => {
1380
1414
  this._ref.image(this._canvasImage);
1381
1415
  if (this._ref.height() <= this.EPSILON) this._ref.height(this._canvasImage.height);
@@ -1395,7 +1429,19 @@ class KonvaImage {
1395
1429
  }
1396
1430
  }
1397
1431
  };
1432
+ this._canvasImage.onerror = () => {
1433
+ this._canvasImage.onerror = function() {};
1434
+ this._canvasImage.src = this.BASE64_NOT_FOUND;
1435
+ };
1398
1436
  this._canvasImage.src = params.src;
1437
+ this._ref = new Konva.Image({
1438
+ x: params.position.x,
1439
+ y: params.position.y,
1440
+ image: this._canvasImage,
1441
+ width: (_a = params.width) !== null && _a !== void 0 ? _a : 0,
1442
+ height: (_b = params.height) !== null && _b !== void 0 ? _b : 0,
1443
+ draggable: true
1444
+ });
1399
1445
  this._ref.on("transform", (e => {
1400
1446
  const attrs = e.target.attrs;
1401
1447
  if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
@@ -1494,7 +1540,11 @@ class KonvaCloud {
1494
1540
  this._ref = ref;
1495
1541
  return;
1496
1542
  }
1497
- if (!params || !params.position) return;
1543
+ if (!params) params = {};
1544
+ if (!params.position) params.position = {
1545
+ x: 100,
1546
+ y: 100
1547
+ };
1498
1548
  const arcRadius = 16;
1499
1549
  this._ref = new Konva.Shape({
1500
1550
  x: params.position.x,
@@ -1699,7 +1749,7 @@ const MarkupMode2Konva = {
1699
1749
 
1700
1750
  class KonvaMarkup {
1701
1751
  constructor() {
1702
- this._pointerEvents = [];
1752
+ this._containerEvents = [];
1703
1753
  this._markupIsActive = false;
1704
1754
  this._markupColor = new MarkupColor(255, 0, 0);
1705
1755
  this.lineWidth = 4;
@@ -1731,12 +1781,12 @@ class KonvaMarkup {
1731
1781
  if (this._viewer) this._viewer.emit(event);
1732
1782
  };
1733
1783
  }
1734
- initialize(container, pointerEvents, viewer, worldTransformer) {
1784
+ initialize(container, containerEvents, viewer, worldTransformer) {
1735
1785
  if (!Konva) throw new Error('Markup error: Konva is not initialized. Forgot to add <script src="https://unpkg.com/konva@9/konva.min.js"><\/script> to your page?');
1736
1786
  this._viewer = viewer;
1737
1787
  this._worldTransformer = worldTransformer !== null && worldTransformer !== void 0 ? worldTransformer : new WorldTransform;
1738
1788
  this._container = container;
1739
- this._pointerEvents = pointerEvents !== null && pointerEvents !== void 0 ? pointerEvents : [];
1789
+ this._containerEvents = containerEvents !== null && containerEvents !== void 0 ? containerEvents : [];
1740
1790
  this._markupContainer = document.createElement("div");
1741
1791
  this._markupContainer.id = "markup-container";
1742
1792
  this._markupContainer.style.position = "absolute";
@@ -1750,7 +1800,7 @@ class KonvaMarkup {
1750
1800
  this._markupColor.setColor(255, 0, 0);
1751
1801
  this.initializeKonva();
1752
1802
  if (this._viewer) {
1753
- this._pointerEvents.forEach((x => this._markupContainer.addEventListener(x, this.redirectToViewer)));
1803
+ this._containerEvents.forEach((x => this._markupContainer.addEventListener(x, this.redirectToViewer)));
1754
1804
  this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
1755
1805
  this._viewer.addEventListener("pan", this.pan);
1756
1806
  }
@@ -1760,7 +1810,7 @@ class KonvaMarkup {
1760
1810
  if (this._viewer) {
1761
1811
  this._viewer.removeEventListener("pan", this.pan);
1762
1812
  this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
1763
- this._pointerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
1813
+ this._containerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
1764
1814
  }
1765
1815
  this.destroyKonva();
1766
1816
  (_a = this._resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
@@ -1780,20 +1830,20 @@ class KonvaMarkup {
1780
1830
  this.getObjects().forEach((obj => obj.delete()));
1781
1831
  }
1782
1832
  getMarkupColor() {
1783
- return this._markupColor.RGB;
1833
+ return this._markupColor.asRGB();
1784
1834
  }
1785
1835
  setMarkupColor(r, g, b) {
1786
1836
  this._markupColor.setColor(r, g, b);
1787
1837
  }
1788
1838
  colorizeAllMarkup(r, g, b) {
1789
- const hexColor = new MarkupColor(r, g, b).HexColor;
1839
+ const hexColor = new MarkupColor(r, g, b).asHex();
1790
1840
  this.getObjects().filter((obj => {
1791
1841
  var _a;
1792
1842
  return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor);
1793
1843
  }));
1794
1844
  }
1795
1845
  colorizeSelectedMarkups(r, g, b) {
1796
- const hexColor = new MarkupColor(r, g, b).HexColor;
1846
+ const hexColor = new MarkupColor(r, g, b).asHex();
1797
1847
  this.getSelectedObjects().filter((obj => {
1798
1848
  var _a;
1799
1849
  return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor);
@@ -2317,7 +2367,7 @@ class KonvaMarkup {
2317
2367
  points: points,
2318
2368
  type: type || this.lineType,
2319
2369
  width: width || this.lineWidth,
2320
- color: color || this._markupColor.HexColor,
2370
+ color: color || this._markupColor.asHex(),
2321
2371
  id: id
2322
2372
  });
2323
2373
  this.addObject(konvaLine);
@@ -2334,7 +2384,7 @@ class KonvaMarkup {
2334
2384
  this._textInputRef.style.top = inputY + "px";
2335
2385
  this._textInputRef.style.left = inputX + "px";
2336
2386
  this._textInputRef.style.fontSize = `${this.fontSize}px`;
2337
- this._textInputRef.style.color = `${this._markupColor.HexColor}`;
2387
+ this._textInputRef.style.color = `${this._markupColor.asHex()}`;
2338
2388
  this._textInputRef.style.fontFamily = "Calibri";
2339
2389
  this._textInputRef.onkeydown = event => {
2340
2390
  if (event.key === "Enter" && !event.shiftKey) {
@@ -2424,7 +2474,7 @@ class KonvaMarkup {
2424
2474
  text: text,
2425
2475
  rotation: angle,
2426
2476
  fontSize: fontSize || this.fontSize,
2427
- color: color || this._markupColor.HexColor,
2477
+ color: color || this._markupColor.asHex(),
2428
2478
  id: id
2429
2479
  });
2430
2480
  this.addObject(konvaText);
@@ -2437,7 +2487,7 @@ class KonvaMarkup {
2437
2487
  width: width,
2438
2488
  height: height,
2439
2489
  lineWidth: lineWidth || this.lineWidth,
2440
- color: color || this._markupColor.HexColor,
2490
+ color: color || this._markupColor.asHex(),
2441
2491
  id: id
2442
2492
  });
2443
2493
  this.addObject(konvaRectangle);
@@ -2449,7 +2499,7 @@ class KonvaMarkup {
2449
2499
  position: position,
2450
2500
  radius: radius,
2451
2501
  lineWidth: lineWidth,
2452
- color: color || this._markupColor.HexColor,
2502
+ color: color || this._markupColor.asHex(),
2453
2503
  id: id
2454
2504
  });
2455
2505
  this.addObject(konvaEllipse);
@@ -2460,7 +2510,7 @@ class KonvaMarkup {
2460
2510
  const konvaArrow = new KonvaArrow({
2461
2511
  start: start,
2462
2512
  end: end,
2463
- color: color || this._markupColor.HexColor,
2513
+ color: color || this._markupColor.asHex(),
2464
2514
  id: id
2465
2515
  });
2466
2516
  this.addObject(konvaArrow);
@@ -2472,7 +2522,7 @@ class KonvaMarkup {
2472
2522
  position: position,
2473
2523
  width: width,
2474
2524
  height: height,
2475
- color: color || this._markupColor.HexColor,
2525
+ color: color || this._markupColor.asHex(),
2476
2526
  lineWidth: lineWidth || this.lineWidth,
2477
2527
  id: id
2478
2528
  });
@@ -4935,7 +4985,7 @@ class VisualizeMarkup {
4935
4985
  this.lineWidth = 4;
4936
4986
  this.fontSize = 34;
4937
4987
  }
4938
- initialize(canvas, canvasEvents, viewer, worldTransformer) {
4988
+ initialize(container, containerEvents, viewer, worldTransformer) {
4939
4989
  this._viewer = viewer;
4940
4990
  this._viewer.registerDragger("Line", OdaLineDragger);
4941
4991
  this._viewer.registerDragger("Text", OdaTextDragger);