@inweb/markup 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.
@@ -1,18 +1,5 @@
1
1
  import Konva from "konva";
2
2
 
3
- var MarkupMode;
4
-
5
- (function(MarkupMode) {
6
- MarkupMode["SelectMarkup"] = "SelectMarkup";
7
- MarkupMode["Line"] = "Line";
8
- MarkupMode["Text"] = "Text";
9
- MarkupMode["Rectangle"] = "Rectangle";
10
- MarkupMode["Ellipse"] = "Ellipse";
11
- MarkupMode["Arrow"] = "Arrow";
12
- MarkupMode["Image"] = "Image";
13
- MarkupMode["Cloud"] = "Cloud";
14
- })(MarkupMode || (MarkupMode = {}));
15
-
16
3
  class MarkupColor {
17
4
  get HexColor() {
18
5
  return "#" + this._hex;
@@ -872,31 +859,40 @@ class KonvaCloud {
872
859
  }
873
860
  }
874
861
 
875
- const MarkupMode2Konva = new Map([ [ MarkupMode.SelectMarkup, {
876
- name: "SelectMarkup",
877
- initializer: () => {}
878
- } ], [ MarkupMode.Line, {
879
- name: "Line",
880
- initializer: ref => new KonvaLine(null, ref)
881
- } ], [ MarkupMode.Text, {
882
- name: "Text",
883
- initializer: ref => new KonvaText(null, ref)
884
- } ], [ MarkupMode.Rectangle, {
885
- name: "Rect",
886
- initializer: ref => new KonvaRectangle(null, ref)
887
- } ], [ MarkupMode.Ellipse, {
888
- name: "Ellipse",
889
- initializer: ref => new KonvaEllipse(null, ref)
890
- } ], [ MarkupMode.Arrow, {
891
- name: "Arrow",
892
- initializer: ref => new KonvaArrow(null, ref)
893
- } ], [ MarkupMode.Image, {
894
- name: "Image",
895
- initializer: ref => new KonvaImage(null, ref)
896
- } ], [ MarkupMode.Cloud, {
897
- name: "Cloud",
898
- initializer: ref => new KonvaCloud(null, ref)
899
- } ] ]);
862
+ const MarkupMode2Konva = {
863
+ SelectMarkup: {
864
+ name: "SelectMarkup",
865
+ initializer: null
866
+ },
867
+ Line: {
868
+ name: "Line",
869
+ initializer: ref => new KonvaLine(null, ref)
870
+ },
871
+ Text: {
872
+ name: "Text",
873
+ initializer: ref => new KonvaText(null, ref)
874
+ },
875
+ Rectangle: {
876
+ name: "Rect",
877
+ initializer: ref => new KonvaRectangle(null, ref)
878
+ },
879
+ Ellipse: {
880
+ name: "Ellipse",
881
+ initializer: ref => new KonvaEllipse(null, ref)
882
+ },
883
+ Arrow: {
884
+ name: "Arrow",
885
+ initializer: ref => new KonvaArrow(null, ref)
886
+ },
887
+ Image: {
888
+ name: "Image",
889
+ initializer: ref => new KonvaImage(null, ref)
890
+ },
891
+ Cloud: {
892
+ name: "Cloud",
893
+ initializer: ref => new KonvaCloud(null, ref)
894
+ }
895
+ };
900
896
 
901
897
  class KonvaMarkup {
902
898
  constructor() {
@@ -913,10 +909,9 @@ class KonvaMarkup {
913
909
  this._markupContainer.className = this._canvasOriginal.className.split(" ").filter((x => !x.startsWith("oda-cursor-"))).filter((x => x)).concat(`oda-cursor-${draggerName.toLowerCase()}`).join(" ");
914
910
  this.removeTextInput();
915
911
  this.removeImageInput();
916
- const markupMode = MarkupMode[draggerName];
917
- const konvaMode = MarkupMode2Konva.get(markupMode);
918
- if (konvaMode) {
919
- this._markupMode = markupMode;
912
+ const konvaShape = MarkupMode2Konva[draggerName];
913
+ if (konvaShape) {
914
+ this._markupMode = draggerName;
920
915
  this._markupIsActive = true;
921
916
  } else {
922
917
  this._markupIsActive = false;
@@ -931,7 +926,7 @@ class KonvaMarkup {
931
926
  this.pan = event => {
932
927
  const dX = event.dX / window.devicePixelRatio;
933
928
  const dY = event.dY / window.devicePixelRatio;
934
- Object.values(MarkupMode).forEach((mode => this.konvaLayerFind(mode).forEach((x => x.move({
929
+ Object.keys(MarkupMode2Konva).forEach((mode => this.konvaLayerFind(mode).forEach((ref => ref.move({
935
930
  x: dX,
936
931
  y: dY
937
932
  })))));
@@ -987,7 +982,7 @@ class KonvaMarkup {
987
982
  this.removeTextInput();
988
983
  this.removeImageInput();
989
984
  this._konvaTransformer.nodes([]);
990
- Object.values(MarkupMode).forEach((mode => this.konvaLayerFind(mode).forEach((x => x.destroy()))));
985
+ Object.keys(MarkupMode2Konva).forEach((mode => this.konvaLayerFind(mode).forEach((ref => ref.destroy()))));
991
986
  }
992
987
  getMarkupColor() {
993
988
  return this._markupColor.RGB;
@@ -997,11 +992,11 @@ class KonvaMarkup {
997
992
  }
998
993
  colorizeAllMarkup(r = 255, g = 0, b = 0) {
999
994
  const hex = new MarkupColor(r, g, b).HexColor;
1000
- Object.values(MarkupMode).forEach((mode => {
1001
- this.konvaLayerFind(mode).forEach((x => {
1002
- var _a;
1003
- const konvaObj = (_a = MarkupMode2Konva.get(mode)) === null || _a === void 0 ? void 0 : _a.initializer(x);
1004
- if (konvaObj && konvaObj.setColor) konvaObj.setColor(hex);
995
+ Object.keys(MarkupMode2Konva).forEach((mode => {
996
+ this.konvaLayerFind(mode).forEach((ref => {
997
+ const konvaShape = MarkupMode2Konva[mode];
998
+ const konvaObj = konvaShape.initializer(ref);
999
+ if (konvaObj.setColor) konvaObj.setColor(hex);
1005
1000
  }));
1006
1001
  }));
1007
1002
  this._konvaLayer.draw();
@@ -1090,25 +1085,25 @@ class KonvaMarkup {
1090
1085
  }
1091
1086
  getObjects() {
1092
1087
  const objects = [];
1093
- this.konvaLayerFind(MarkupMode.Line).forEach((line => {
1088
+ this.konvaLayerFind("Line").forEach((line => {
1094
1089
  objects.push(new KonvaLine(null, line));
1095
1090
  }));
1096
- this.konvaLayerFind(MarkupMode.Text).forEach((text => {
1091
+ this.konvaLayerFind("Text").forEach((text => {
1097
1092
  objects.push(new KonvaText(null, text));
1098
1093
  }));
1099
- this.konvaLayerFind(MarkupMode.Rectangle).forEach((rectangle => {
1094
+ this.konvaLayerFind("Rectangle").forEach((rectangle => {
1100
1095
  objects.push(new KonvaRectangle(null, rectangle));
1101
1096
  }));
1102
- this.konvaLayerFind(MarkupMode.Ellipse).forEach((ellipse => {
1097
+ this.konvaLayerFind("Ellipse").forEach((ellipse => {
1103
1098
  objects.push(new KonvaEllipse(null, ellipse));
1104
1099
  }));
1105
- this.konvaLayerFind(MarkupMode.Arrow).forEach((arrow => {
1100
+ this.konvaLayerFind("Arrow").forEach((arrow => {
1106
1101
  objects.push(new KonvaArrow(null, arrow));
1107
1102
  }));
1108
- this.konvaLayerFind(MarkupMode.Image).forEach((image => {
1103
+ this.konvaLayerFind("Image").forEach((image => {
1109
1104
  objects.push(new KonvaImage(null, image));
1110
1105
  }));
1111
- this.konvaLayerFind(MarkupMode.Cloud).forEach((cloud => {
1106
+ this.konvaLayerFind("Cloud").forEach((cloud => {
1112
1107
  objects.push(new KonvaCloud(null, cloud));
1113
1108
  }));
1114
1109
  return objects;
@@ -1211,10 +1206,9 @@ class KonvaMarkup {
1211
1206
  this._konvaLayer.add(object.ref());
1212
1207
  }
1213
1208
  konvaLayerFind(markupShape) {
1214
- const konvaShape = MarkupMode2Konva.get(markupShape);
1215
- if (konvaShape) {
1216
- const konvaShapes = this._konvaLayer.find(konvaShape.name).filter((x => x.parent instanceof Konva.Layer));
1217
- return konvaShapes;
1209
+ const konvaShape = MarkupMode2Konva[markupShape];
1210
+ if (konvaShape && konvaShape.initializer) {
1211
+ return this._konvaLayer.find(konvaShape.name).filter((ref => ref.parent === this._konvaLayer));
1218
1212
  }
1219
1213
  return [];
1220
1214
  }
@@ -1242,15 +1236,15 @@ class KonvaMarkup {
1242
1236
  let mouseDownPos;
1243
1237
  let lastObj;
1244
1238
  stage.on("mousedown touchstart", (e => {
1245
- if (!this._markupIsActive || e.target !== stage || this._markupMode === MarkupMode.Text || this._markupMode === MarkupMode.Image) return;
1239
+ if (!this._markupIsActive || e.target !== stage || this._markupMode === "Text" || this._markupMode === "Image") return;
1246
1240
  if (e.target === stage && transformer.nodes().length > 0) {
1247
1241
  transformer.nodes([]);
1248
1242
  return;
1249
1243
  }
1250
1244
  const pos = stage.getPointerPosition();
1251
1245
  mouseDownPos = pos;
1252
- isPaint = [ MarkupMode.Arrow, MarkupMode.Cloud, MarkupMode.Ellipse, MarkupMode.Line, MarkupMode.Rectangle ].some((m => m === this._markupMode));
1253
- if (this._markupMode === MarkupMode.Line) {
1246
+ isPaint = [ "Arrow", "Cloud", "Ellipse", "Line", "Rectangle" ].some((m => m === this._markupMode));
1247
+ if (this._markupMode === "Line") {
1254
1248
  lastLine = this.addLine([ pos.x, pos.y, pos.x, pos.y ]);
1255
1249
  }
1256
1250
  }));
@@ -1264,12 +1258,12 @@ class KonvaMarkup {
1264
1258
  const dX = defParams ? 200 : Math.abs(mouseDownPos.x - pos.x);
1265
1259
  const dY = defParams ? 200 : Math.abs(mouseDownPos.y - pos.y);
1266
1260
  if (defParams) {
1267
- if (this._markupMode === MarkupMode.Rectangle) {
1261
+ if (this._markupMode === "Rectangle") {
1268
1262
  this.addRectangle({
1269
1263
  x: startX,
1270
1264
  y: startY
1271
1265
  }, dX, dY);
1272
- } else if (this._markupMode === MarkupMode.Ellipse) {
1266
+ } else if (this._markupMode === "Ellipse") {
1273
1267
  this.addEllipse({
1274
1268
  x: startX,
1275
1269
  y: startY
@@ -1277,7 +1271,7 @@ class KonvaMarkup {
1277
1271
  x: dX / 2,
1278
1272
  y: dY / 2
1279
1273
  });
1280
- } else if (this._markupMode === MarkupMode.Arrow) {
1274
+ } else if (this._markupMode === "Arrow") {
1281
1275
  this.addArrow({
1282
1276
  x: mouseDownPos.x,
1283
1277
  y: mouseDownPos.y
@@ -1285,7 +1279,7 @@ class KonvaMarkup {
1285
1279
  x: defParams ? mouseDownPos.x + 200 : pos.x,
1286
1280
  y: defParams ? startY : pos.y
1287
1281
  });
1288
- } else if (this._markupMode === MarkupMode.Cloud) {
1282
+ } else if (this._markupMode === "Cloud") {
1289
1283
  this.addCloud({
1290
1284
  x: startX,
1291
1285
  y: startY
@@ -1307,12 +1301,12 @@ class KonvaMarkup {
1307
1301
  const startY = defParams ? mouseDownPos.y : Math.min(mouseDownPos.y, pos.y);
1308
1302
  const dX = defParams ? 200 : Math.abs(mouseDownPos.x - pos.x);
1309
1303
  const dY = defParams ? 200 : Math.abs(mouseDownPos.y - pos.y);
1310
- if (this._markupMode === MarkupMode.Line) {
1304
+ if (this._markupMode === "Line") {
1311
1305
  lastLine.addPoints([ {
1312
1306
  x: pos.x,
1313
1307
  y: pos.y
1314
1308
  } ]);
1315
- } else if (this._markupMode === MarkupMode.Arrow) {
1309
+ } else if (this._markupMode === "Arrow") {
1316
1310
  if (lastObj) lastObj.setEndPoint(pos.x, pos.y); else lastObj = this.addArrow({
1317
1311
  x: mouseDownPos.x,
1318
1312
  y: mouseDownPos.y
@@ -1320,7 +1314,7 @@ class KonvaMarkup {
1320
1314
  x: pos.x,
1321
1315
  y: pos.y
1322
1316
  });
1323
- } else if (this._markupMode === MarkupMode.Rectangle) {
1317
+ } else if (this._markupMode === "Rectangle") {
1324
1318
  if (lastObj) {
1325
1319
  lastObj.setPosition(startX, startY);
1326
1320
  lastObj.setWidth(dX);
@@ -1329,7 +1323,7 @@ class KonvaMarkup {
1329
1323
  x: startX,
1330
1324
  y: startY
1331
1325
  }, dX, dY);
1332
- } else if (this._markupMode === MarkupMode.Ellipse) {
1326
+ } else if (this._markupMode === "Ellipse") {
1333
1327
  if (lastObj) {
1334
1328
  lastObj.setPosition(startX, startY);
1335
1329
  lastObj.setRadiusX(dX);
@@ -1341,7 +1335,7 @@ class KonvaMarkup {
1341
1335
  x: dX,
1342
1336
  y: dY
1343
1337
  });
1344
- } else if (this._markupMode === MarkupMode.Cloud) {
1338
+ } else if (this._markupMode === "Cloud") {
1345
1339
  if (lastObj) {
1346
1340
  lastObj.setPosition(startX, startY);
1347
1341
  lastObj.setWidth(Math.max(100, dX));
@@ -1355,12 +1349,12 @@ class KonvaMarkup {
1355
1349
  stage.on("click tap", (e => {
1356
1350
  if (!this._markupIsActive) return;
1357
1351
  if (e.target === stage) {
1358
- if (this._markupMode === MarkupMode.Text) {
1352
+ if (this._markupMode === "Text") {
1359
1353
  if (this._textInputRef && this._textInputRef.value) this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle); else if (transformer.nodes().length === 0) {
1360
1354
  const pos = stage.getPointerPosition();
1361
1355
  this.createTextInput(pos, e.evt.pageX, e.evt.pageY, 0, null);
1362
1356
  }
1363
- } else if (this._markupMode === MarkupMode.Image) {
1357
+ } else if (this._markupMode === "Image") {
1364
1358
  if (this._imageInputRef && this._imageInputRef.value) this.addImage({
1365
1359
  x: this._imageInputPos.x,
1366
1360
  y: this._imageInputPos.y
@@ -1372,7 +1366,7 @@ class KonvaMarkup {
1372
1366
  transformer.nodes([]);
1373
1367
  return;
1374
1368
  }
1375
- if (this._markupMode === MarkupMode.Text || this._markupMode === MarkupMode.SelectMarkup) {
1369
+ if (this._markupMode === "Text" || this._markupMode === "SelectMarkup") {
1376
1370
  if (e.target.className === "Text" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
1377
1371
  if (this._textInputRef && this._textInputRef.value) this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle); else this.createTextInput({
1378
1372
  x: e.target.attrs.x,
@@ -1383,7 +1377,7 @@ class KonvaMarkup {
1383
1377
  this.removeTextInput();
1384
1378
  }
1385
1379
  }
1386
- if (this._markupMode === MarkupMode.Image || this._markupMode === MarkupMode.SelectMarkup) {
1380
+ if (this._markupMode === "Image" || this._markupMode === "SelectMarkup") {
1387
1381
  if (e.target.className === "Image" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
1388
1382
  if (this._imageInputRef && this._imageInputRef.value) this.addImage(this._imageInputPos, this._imageInputRef.value, 0, 0); else this.createImageInput({
1389
1383
  x: e.target.attrs.x,
@@ -1438,7 +1432,7 @@ class KonvaMarkup {
1438
1432
  }
1439
1433
  getMarkupLines() {
1440
1434
  const lines = [];
1441
- this.konvaLayerFind(MarkupMode.Line).forEach((line => {
1435
+ this.konvaLayerFind("Line").forEach((line => {
1442
1436
  const linePoints = line.points();
1443
1437
  if (!linePoints) return;
1444
1438
  const worldPoints = [];
@@ -1466,7 +1460,7 @@ class KonvaMarkup {
1466
1460
  const texts = [];
1467
1461
  const textSize = .02;
1468
1462
  const textScale = this._worldTransformer.getScale();
1469
- this.konvaLayerFind(MarkupMode.Text).forEach((text => {
1463
+ this.konvaLayerFind("Text").forEach((text => {
1470
1464
  if (!text) return;
1471
1465
  const position = this._worldTransformer.screenToWorld({
1472
1466
  x: text.x(),
@@ -1487,7 +1481,7 @@ class KonvaMarkup {
1487
1481
  }
1488
1482
  getMarkupRectangles() {
1489
1483
  const rectangles = [];
1490
- this.konvaLayerFind(MarkupMode.Rectangle).forEach((rect => {
1484
+ this.konvaLayerFind("Rectangle").forEach((rect => {
1491
1485
  const position = rect.position();
1492
1486
  const worldPoint = this._worldTransformer.screenToWorld(position);
1493
1487
  const shape = new KonvaRectangle(null, rect);
@@ -1504,7 +1498,7 @@ class KonvaMarkup {
1504
1498
  }
1505
1499
  getMarkupEllipses() {
1506
1500
  const ellipses = [];
1507
- this.konvaLayerFind(MarkupMode.Ellipse).forEach((ellipse => {
1501
+ this.konvaLayerFind("Ellipse").forEach((ellipse => {
1508
1502
  const position = ellipse.position();
1509
1503
  const worldPoint = this._worldTransformer.screenToWorld(position);
1510
1504
  const shape = new KonvaEllipse(null, ellipse);
@@ -1523,7 +1517,7 @@ class KonvaMarkup {
1523
1517
  }
1524
1518
  getMarkupArrows() {
1525
1519
  const arrows = [];
1526
- this.konvaLayerFind(MarkupMode.Arrow).forEach((arrow => {
1520
+ this.konvaLayerFind("Arrow").forEach((arrow => {
1527
1521
  const absoluteTransform = arrow.getAbsoluteTransform();
1528
1522
  const atStartPoint = absoluteTransform.point({
1529
1523
  x: arrow.points()[0],
@@ -1547,7 +1541,7 @@ class KonvaMarkup {
1547
1541
  }
1548
1542
  getMarkupImages() {
1549
1543
  const images = [];
1550
- this.konvaLayerFind(MarkupMode.Image).forEach((image => {
1544
+ this.konvaLayerFind("Image").forEach((image => {
1551
1545
  const position = image.position();
1552
1546
  const worldPoint = this._worldTransformer.screenToWorld(position);
1553
1547
  const shape = new KonvaImage(null, image);
@@ -1563,7 +1557,7 @@ class KonvaMarkup {
1563
1557
  }
1564
1558
  getMarkupClouds() {
1565
1559
  const clouds = [];
1566
- this.konvaLayerFind(MarkupMode.Cloud).forEach((cloud => {
1560
+ this.konvaLayerFind("Cloud").forEach((cloud => {
1567
1561
  const position = cloud.position();
1568
1562
  const worldPoint = this._worldTransformer.screenToWorld(position);
1569
1563
  const shape = new KonvaCloud(null, cloud);
@@ -1834,5 +1828,5 @@ class KonvaMarkup {
1834
1828
  }
1835
1829
  }
1836
1830
 
1837
- export { KonvaMarkup as Markup, MarkupMode };
1831
+ export { KonvaMarkup as Markup };
1838
1832
  //# sourceMappingURL=markup.module.js.map