@inweb/markup 26.4.1 → 26.5.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.
@@ -443,8 +443,8 @@ class KonvaRectangle {
443
443
  y: 0
444
444
  };
445
445
  if (params.position2) {
446
- params.width = params.position.x - params.position2.x;
447
- params.height = params.position.y - params.position2.y;
446
+ params.width = params.position2.x - params.position.x;
447
+ params.height = params.position2.y - params.position.y;
448
448
  } else {
449
449
  if (!params.width || !params.height) {
450
450
  params.position2 = {
@@ -568,6 +568,12 @@ class KonvaRectangle {
568
568
  x: x,
569
569
  y: y
570
570
  }));
571
+ const rightLowerPoint = {
572
+ x: x + this._ref.width(),
573
+ y: y + this._ref.y()
574
+ };
575
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
576
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
571
577
  }
572
578
  ref() {
573
579
  return this._ref;
@@ -625,6 +631,10 @@ class KonvaRectangle {
625
631
  }
626
632
  }
627
633
 
634
+ function getDistanceIn2D(p1, p2) {
635
+ return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
636
+ }
637
+
628
638
  class KonvaEllipse {
629
639
  constructor(params, ref = null, worldTransformer = new WorldTransform) {
630
640
  var _a, _b;
@@ -659,10 +669,15 @@ class KonvaEllipse {
659
669
  x: 0,
660
670
  y: 0
661
671
  };
662
- if (!params.radius) params.radius = {
663
- x: 25,
664
- y: 25
665
- };
672
+ if (params.position2) {
673
+ params.radius.x = getDistanceIn2D(params.position, params.position2);
674
+ if (params.position3) params.radius.y = getDistanceIn2D(params.position, params.position3); else params.radius.x = params.radius.y;
675
+ } else {
676
+ if (!params.radius) params.radius = {
677
+ x: 25,
678
+ y: 25
679
+ };
680
+ }
666
681
  this._ref = new Konva.Ellipse({
667
682
  stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
668
683
  strokeWidth: (_b = params.lineWidth) !== null && _b !== undefined ? _b : 4,
@@ -1055,12 +1070,23 @@ class KonvaImage {
1055
1070
  this._canvasImage = ref.image();
1056
1071
  this._ratio = this._ref.height() <= this.EPSILON || this._ref.width() <= this.EPSILON ? 1 : this._ref.height() / this._ref.width();
1057
1072
  const wcsStart = this._ref.getAttr("wcsStart");
1073
+ const wcsEnd = this._ref.getAttr("wcsEnd");
1058
1074
  if (!wcsStart) {
1059
1075
  this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
1060
1076
  x: ref.x(),
1061
1077
  y: ref.y()
1062
1078
  }));
1063
1079
  }
1080
+ if (!wcsEnd) {
1081
+ const rightBottomPoint = {
1082
+ x: ref.x() + ref.width(),
1083
+ y: ref.y() + ref.height()
1084
+ };
1085
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
1086
+ x: rightBottomPoint.x,
1087
+ y: rightBottomPoint.y
1088
+ }));
1089
+ }
1064
1090
  return;
1065
1091
  }
1066
1092
  if (!params) params = {};
@@ -1069,6 +1095,10 @@ class KonvaImage {
1069
1095
  y: 0
1070
1096
  };
1071
1097
  if (!params.src || !params.src.startsWith(this.BASE64_HEADER_START)) params.src = this.BASE64_NOT_FOUND;
1098
+ if (params.position2) {
1099
+ params.width = params.position2.x - params.position.x;
1100
+ params.height = params.position2.y - params.position.y;
1101
+ }
1072
1102
  this._canvasImage = new Image;
1073
1103
  this._canvasImage.onload = () => {
1074
1104
  this._ref.image(this._canvasImage);
@@ -1086,6 +1116,11 @@ class KonvaImage {
1086
1116
  this._ref.width(params.maxHeight / this._ratio);
1087
1117
  this._ref.height(params.maxHeight);
1088
1118
  }
1119
+ const wcsEnd = this._worldTransformer.screenToWorld({
1120
+ x: params.position.x + this._ref.width(),
1121
+ y: params.position.y + this._ref.height()
1122
+ });
1123
+ this._ref.setAttr("wcsEnd", wcsEnd);
1089
1124
  }
1090
1125
  }
1091
1126
  };
@@ -1143,6 +1178,10 @@ class KonvaImage {
1143
1178
  y: this._ref.y()
1144
1179
  });
1145
1180
  this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
1181
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
1182
+ x: position.x + this._ref.width(),
1183
+ y: position.y + this._ref.height()
1184
+ }));
1146
1185
  }));
1147
1186
  this._ref.on("dragend", (e => {
1148
1187
  const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
@@ -1151,6 +1190,10 @@ class KonvaImage {
1151
1190
  y: this._ref.y()
1152
1191
  });
1153
1192
  this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
1193
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
1194
+ x: position.x + this._ref.width(),
1195
+ y: position.y + this._ref.height()
1196
+ }));
1154
1197
  }));
1155
1198
  this._ref.id(this._ref._id.toString());
1156
1199
  }
@@ -1166,6 +1209,12 @@ class KonvaImage {
1166
1209
  setWidth(w) {
1167
1210
  this._ref.width(w);
1168
1211
  this._ref.height(w * this._ratio);
1212
+ const rightLowerPoint = {
1213
+ x: this._ref.x() + w,
1214
+ y: this._ref.y() + this._ref.height()
1215
+ };
1216
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
1217
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
1169
1218
  }
1170
1219
  getHeight() {
1171
1220
  return this._ref.height();
@@ -1173,6 +1222,12 @@ class KonvaImage {
1173
1222
  setHeight(h) {
1174
1223
  this._ref.height(h);
1175
1224
  this._ref.width(h / this._ratio);
1225
+ const rightLowerPoint = {
1226
+ x: this._ref.x() + this._ref.width(),
1227
+ y: this._ref.y() + h
1228
+ };
1229
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
1230
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
1176
1231
  }
1177
1232
  ref() {
1178
1233
  return this._ref;
@@ -1214,16 +1269,26 @@ class KonvaImage {
1214
1269
  x: x,
1215
1270
  y: y
1216
1271
  }));
1272
+ const rightLowerPoint = {
1273
+ x: x + this._ref.width(),
1274
+ y: y + this._ref.y()
1275
+ };
1276
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
1277
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
1217
1278
  }
1218
1279
  updateScreenCoordinates() {
1219
1280
  let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
1281
+ let screenPositionEnd = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));
1220
1282
  let invert = this._ref.getStage().getAbsoluteTransform().copy();
1221
1283
  invert = invert.invert();
1222
1284
  const positionStart = invert.point(screenPositionStart);
1285
+ const positionEnd = invert.point(screenPositionEnd);
1223
1286
  this._ref.position({
1224
1287
  x: positionStart.x,
1225
1288
  y: positionStart.y
1226
1289
  });
1290
+ this._ref.width(Math.abs(positionEnd.x - positionStart.x));
1291
+ this._ref.height(Math.abs(positionEnd.y - positionStart.y));
1227
1292
  }
1228
1293
  }
1229
1294
 
@@ -1259,8 +1324,8 @@ class KonvaCloud {
1259
1324
  y: 0
1260
1325
  };
1261
1326
  if (params.position2) {
1262
- params.width = params.position.x - params.position2.x;
1263
- params.height = params.position.y - params.position2.y;
1327
+ params.width = params.position2.x - params.position.x;
1328
+ params.height = params.position2.y - params.position.y;
1264
1329
  } else {
1265
1330
  if (!params.width || !params.height) {
1266
1331
  params.position2 = {
@@ -1459,6 +1524,12 @@ class KonvaCloud {
1459
1524
  x: x,
1460
1525
  y: y
1461
1526
  }));
1527
+ const rightLowerPoint = {
1528
+ x: x + this._ref.width(),
1529
+ y: y + this._ref.y()
1530
+ };
1531
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
1532
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
1462
1533
  }
1463
1534
  getWidth() {
1464
1535
  return this._ref.width();
@@ -1717,11 +1788,14 @@ class KonvaMarkup {
1717
1788
  }));
1718
1789
  (_d = viewpoint.rectangles) === null || _d === undefined ? undefined : _d.forEach((rect => {
1719
1790
  const screenPoint = this._worldTransformer.worldToScreen(rect.position);
1720
- this.addRectangle(screenPoint, null, rect.width, rect.height, rect.line_width, rect.color, rect.id);
1791
+ const screenPoint2 = rect.position2 ? this._worldTransformer.worldToScreen(rect.position2) : null;
1792
+ this.addRectangle(screenPoint, screenPoint2, rect.width, rect.height, rect.line_width, rect.color, rect.id);
1721
1793
  }));
1722
1794
  (_e = viewpoint.ellipses) === null || _e === undefined ? undefined : _e.forEach((ellipse => {
1723
1795
  const screenPoint = this._worldTransformer.worldToScreen(ellipse.position);
1724
- this.addEllipse(screenPoint, ellipse.radius, ellipse.line_width, ellipse.color, ellipse.id);
1796
+ const screenPoint2 = ellipse.position2 ? this._worldTransformer.worldToScreen(ellipse.position2) : null;
1797
+ const screenPoint3 = ellipse.position3 ? this._worldTransformer.worldToScreen(ellipse.position3) : null;
1798
+ this.addEllipse(screenPoint, screenPoint2, screenPoint3, ellipse.radius, ellipse.line_width, ellipse.color, ellipse.id);
1725
1799
  }));
1726
1800
  (_f = viewpoint.arrows) === null || _f === undefined ? undefined : _f.forEach((arrow => {
1727
1801
  const startPoint = this._worldTransformer.worldToScreen(arrow.start);
@@ -1730,11 +1804,13 @@ class KonvaMarkup {
1730
1804
  }));
1731
1805
  (_g = viewpoint.clouds) === null || _g === undefined ? undefined : _g.forEach((cloud => {
1732
1806
  const screenPoint = this._worldTransformer.worldToScreen(cloud.position);
1733
- this.addCloud(screenPoint, null, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
1807
+ const screenPoint2 = cloud.position2 ? this._worldTransformer.worldToScreen(cloud.position2) : null;
1808
+ this.addCloud(screenPoint, screenPoint2, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
1734
1809
  }));
1735
1810
  (_h = viewpoint.images) === null || _h === undefined ? undefined : _h.forEach((image => {
1736
1811
  const screenPoint = this._worldTransformer.worldToScreen(image.position);
1737
- this.addImage(screenPoint, image.src, image.width, image.height, image.id);
1812
+ const screenPoint2 = image.position2 ? this._worldTransformer.worldToScreen(image.position2) : null;
1813
+ this.addImage(screenPoint, screenPoint2, image.src, image.width, image.height, image.id);
1738
1814
  }));
1739
1815
  }
1740
1816
  getViewpoint(viewpoint) {
@@ -1869,7 +1945,7 @@ class KonvaMarkup {
1869
1945
  this.addEllipse({
1870
1946
  x: startX,
1871
1947
  y: startY
1872
- }, {
1948
+ }, null, null, {
1873
1949
  x: dX / 2,
1874
1950
  y: dY / 2
1875
1951
  });
@@ -1933,7 +2009,7 @@ class KonvaMarkup {
1933
2009
  } else lastObj = this.addEllipse({
1934
2010
  x: startX,
1935
2011
  y: startY
1936
- }, {
2012
+ }, null, null, {
1937
2013
  x: dX,
1938
2014
  y: dY
1939
2015
  });
@@ -1960,7 +2036,7 @@ class KonvaMarkup {
1960
2036
  if (this._imageInputRef && this._imageInputRef.value) this.addImage({
1961
2037
  x: this._imageInputPos.x,
1962
2038
  y: this._imageInputPos.y
1963
- }, this._imageInputRef.value, 0, 0, this._imageInputRef.value); else if (transformer.nodes().length === 0) {
2039
+ }, null, this._imageInputRef.value, 0, 0, this._imageInputRef.value); else if (transformer.nodes().length === 0) {
1964
2040
  const pos = this.getRelativePointerPosition(stage);
1965
2041
  this.createImageInput(pos);
1966
2042
  }
@@ -1981,7 +2057,7 @@ class KonvaMarkup {
1981
2057
  }
1982
2058
  if (this._markupMode === "Image" || this._markupMode === "SelectMarkup") {
1983
2059
  if (e.target.className === "Image" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
1984
- if (this._imageInputRef && this._imageInputRef.value) this.addImage(this._imageInputPos, this._imageInputRef.value, 0, 0); else this.createImageInput({
2060
+ if (this._imageInputRef && this._imageInputRef.value) this.addImage(this._imageInputPos, null, this._imageInputRef.value, 0, 0); else this.createImageInput({
1985
2061
  x: e.target.attrs.x,
1986
2062
  y: e.target.attrs.y
1987
2063
  });
@@ -2083,6 +2159,7 @@ class KonvaMarkup {
2083
2159
  const rectangle = {
2084
2160
  id: shape.id(),
2085
2161
  position: wcsStart,
2162
+ position2: wcsEnd,
2086
2163
  width: Math.abs(screenStart.x - screenEnd.x),
2087
2164
  height: Math.abs(screenStart.y - screenEnd.y),
2088
2165
  line_width: shape.getLineWidth(),
@@ -2096,12 +2173,16 @@ class KonvaMarkup {
2096
2173
  const ellipses = [];
2097
2174
  this.konvaLayerFind("Ellipse").forEach((ref => {
2098
2175
  const wcsPosition = ref.getAttr("wcsPosition");
2176
+ const wcsPosition2 = ref.getAttr("wcsRadiusX");
2177
+ const wcsPosition3 = ref.getAttr("wcsRadiusY");
2099
2178
  const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
2100
2179
  const scale = stageAbsoluteTransform.getMatrix()[0];
2101
2180
  const shape = new KonvaEllipse(null, ref, this._worldTransformer);
2102
2181
  const ellipse = {
2103
2182
  id: shape.id(),
2104
2183
  position: wcsPosition,
2184
+ position2: wcsPosition2,
2185
+ position3: wcsPosition3,
2105
2186
  radius: {
2106
2187
  x: ref.getRadiusX() * scale,
2107
2188
  y: ref.getRadiusY() * scale
@@ -2133,12 +2214,14 @@ class KonvaMarkup {
2133
2214
  const images = [];
2134
2215
  this.konvaLayerFind("Image").forEach((ref => {
2135
2216
  const wcsStart = ref.getAttr("wcsStart");
2217
+ const wcsEnd = ref.getAttr("wcsEnd");
2136
2218
  const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
2137
2219
  const scale = stageAbsoluteTransform.getMatrix()[0];
2138
2220
  const shape = new KonvaImage(null, ref, this._worldTransformer);
2139
2221
  const image = {
2140
2222
  id: shape.id(),
2141
2223
  position: wcsStart,
2224
+ position2: wcsEnd,
2142
2225
  src: shape.getSrc(),
2143
2226
  width: shape.getWidth() * scale,
2144
2227
  height: shape.getHeight() * scale
@@ -2158,6 +2241,7 @@ class KonvaMarkup {
2158
2241
  const cloud = {
2159
2242
  id: shape.id(),
2160
2243
  position: wcsStart,
2244
+ position2: wcsEnd,
2161
2245
  width: Math.abs(screenStart.x - screenEnd.x),
2162
2246
  height: Math.abs(screenStart.y - screenEnd.y),
2163
2247
  line_width: shape.getLineWidth(),
@@ -2262,7 +2346,7 @@ class KonvaMarkup {
2262
2346
  this.addImage({
2263
2347
  x: this._imageInputPos.x,
2264
2348
  y: this._imageInputPos.y
2265
- }, base64.toString(), 0, 0);
2349
+ }, null, base64.toString(), 0, 0);
2266
2350
  };
2267
2351
  this._imageInputRef.oncancel = event => {
2268
2352
  this.removeImageInput();
@@ -2321,10 +2405,12 @@ class KonvaMarkup {
2321
2405
  this.addObject(konvaRectangle);
2322
2406
  return konvaRectangle;
2323
2407
  }
2324
- addEllipse(position, radius, lineWidth, color, id) {
2408
+ addEllipse(position, position2, position3, radius, lineWidth, color, id) {
2325
2409
  if (!position) return;
2326
2410
  const konvaEllipse = new KonvaEllipse({
2327
2411
  position: position,
2412
+ position2: position2,
2413
+ position3: position3,
2328
2414
  radius: radius,
2329
2415
  lineWidth: lineWidth,
2330
2416
  color: color || this._markupColor.asHex(),
@@ -2358,7 +2444,7 @@ class KonvaMarkup {
2358
2444
  this.addObject(konvaCloud);
2359
2445
  return konvaCloud;
2360
2446
  }
2361
- addImage(position, src, width, height, id) {
2447
+ addImage(position, position2, src, width, height, id) {
2362
2448
  var _a;
2363
2449
  if (!position || !src) return;
2364
2450
  (_a = this.getSelectedObjects().at(0)) === null || _a === undefined ? undefined : _a.delete();
@@ -2366,6 +2452,7 @@ class KonvaMarkup {
2366
2452
  this.removeImageInput();
2367
2453
  const konvaImage = new KonvaImage({
2368
2454
  position: position,
2455
+ position2: position2,
2369
2456
  src: src,
2370
2457
  width: width,
2371
2458
  height: height,