@inweb/markup 25.8.3 → 25.8.5
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.
- package/dist/markup.js +65 -64
- package/dist/markup.js.map +1 -1
- package/dist/markup.min.js +1 -1
- package/dist/markup.module.js +56 -60
- package/dist/markup.module.js.map +1 -1
- package/lib/markup/Konva/KonvaMarkup.d.ts +0 -2
- package/package.json +3 -3
- package/src/markup/Konva/KonvaMarkup.ts +60 -69
package/dist/markup.module.js
CHANGED
|
@@ -925,11 +925,10 @@ const MarkupMode2Konva = {
|
|
|
925
925
|
|
|
926
926
|
class KonvaMarkup {
|
|
927
927
|
constructor() {
|
|
928
|
-
this.
|
|
928
|
+
this._pointerEvents = [];
|
|
929
929
|
this._markupIsActive = false;
|
|
930
930
|
this._markupColor = new MarkupColor(255, 0, 0);
|
|
931
931
|
this._zIndex = 1;
|
|
932
|
-
this._markupContainerName = "markupContainer";
|
|
933
932
|
this.lineWidth = 4;
|
|
934
933
|
this.lineType = "solid";
|
|
935
934
|
this.fontSize = 34;
|
|
@@ -941,11 +940,11 @@ class KonvaMarkup {
|
|
|
941
940
|
this.enableEditMode(draggerName);
|
|
942
941
|
};
|
|
943
942
|
this.resizeContainer = entries => {
|
|
944
|
-
var _a, _b;
|
|
945
943
|
const {width: width, height: height} = entries[0].contentRect;
|
|
946
944
|
if (!width || !height) return;
|
|
947
|
-
(
|
|
948
|
-
|
|
945
|
+
if (!this._konvaStage) return;
|
|
946
|
+
this._konvaStage.width(width);
|
|
947
|
+
this._konvaStage.height(height);
|
|
949
948
|
};
|
|
950
949
|
this.pan = event => {
|
|
951
950
|
const dX = event.dX / window.devicePixelRatio;
|
|
@@ -960,13 +959,16 @@ class KonvaMarkup {
|
|
|
960
959
|
};
|
|
961
960
|
}
|
|
962
961
|
initialize(container, pointerEvents, viewer, worldTransformer) {
|
|
963
|
-
if (!Konva)
|
|
962
|
+
if (!Konva) {
|
|
963
|
+
console.error('Markup error: Konva is not initialized. Update node_modules or add to your page <script src="https://unpkg.com/konva@9/konva.min.js"><\/script>');
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
964
966
|
this._viewer = viewer;
|
|
965
967
|
this._worldTransformer = worldTransformer !== null && worldTransformer !== void 0 ? worldTransformer : new WorldTransform;
|
|
966
968
|
this._container = container;
|
|
967
969
|
this._pointerEvents = pointerEvents !== null && pointerEvents !== void 0 ? pointerEvents : [];
|
|
968
970
|
this._markupContainer = document.createElement("div");
|
|
969
|
-
this._markupContainer.id =
|
|
971
|
+
this._markupContainer.id = "markup-container";
|
|
970
972
|
this._markupContainer.style.position = "absolute";
|
|
971
973
|
this._markupContainer.style.top = "0px";
|
|
972
974
|
this._markupContainer.style.left = "0px";
|
|
@@ -982,32 +984,30 @@ class KonvaMarkup {
|
|
|
982
984
|
this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
|
|
983
985
|
this._viewer.addEventListener("pan", this.pan);
|
|
984
986
|
}
|
|
985
|
-
this._isInitialized = true;
|
|
986
987
|
}
|
|
987
988
|
dispose() {
|
|
988
|
-
|
|
989
|
+
var _a, _b;
|
|
989
990
|
if (this._viewer) {
|
|
990
991
|
this._viewer.removeEventListener("pan", this.pan);
|
|
991
992
|
this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
|
|
993
|
+
this._pointerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
|
|
992
994
|
}
|
|
993
|
-
this._pointerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
|
|
994
995
|
this.destroyKonva();
|
|
995
|
-
this._resizeObserver.disconnect();
|
|
996
|
+
(_a = this._resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
996
997
|
this._resizeObserver = undefined;
|
|
997
|
-
this._markupContainer.remove();
|
|
998
|
+
(_b = this._markupContainer) === null || _b === void 0 ? void 0 : _b.remove();
|
|
998
999
|
this._markupContainer = undefined;
|
|
999
1000
|
this._container = undefined;
|
|
1000
1001
|
this._viewer = undefined;
|
|
1001
1002
|
this._worldTransformer = undefined;
|
|
1002
1003
|
this._markupIsActive = false;
|
|
1003
|
-
this._isInitialized = false;
|
|
1004
1004
|
}
|
|
1005
1005
|
syncOverlay() {}
|
|
1006
1006
|
clearOverlay() {
|
|
1007
1007
|
this.removeTextInput();
|
|
1008
1008
|
this.removeImageInput();
|
|
1009
1009
|
this.clearSelected();
|
|
1010
|
-
this.getObjects().forEach((obj => obj.
|
|
1010
|
+
this.getObjects().forEach((obj => obj.delete()));
|
|
1011
1011
|
}
|
|
1012
1012
|
getMarkupColor() {
|
|
1013
1013
|
return this._markupColor.RGB;
|
|
@@ -1119,6 +1119,7 @@ class KonvaMarkup {
|
|
|
1119
1119
|
return objects;
|
|
1120
1120
|
}
|
|
1121
1121
|
getSelectedObjects() {
|
|
1122
|
+
if (!this._konvaTransformer) return [];
|
|
1122
1123
|
return this._konvaTransformer.nodes().map((ref => {
|
|
1123
1124
|
const name = ref.className;
|
|
1124
1125
|
const konvaShape = Object.values(MarkupMode2Konva).find((shape => shape.name === name));
|
|
@@ -1126,29 +1127,29 @@ class KonvaMarkup {
|
|
|
1126
1127
|
})).filter((x => x));
|
|
1127
1128
|
}
|
|
1128
1129
|
selectObjects(objects) {
|
|
1130
|
+
if (!this._konvaTransformer) return;
|
|
1129
1131
|
const selectedObjs = this._konvaTransformer.nodes().concat(objects.map((x => x.ref())));
|
|
1130
1132
|
this._konvaTransformer.nodes(selectedObjs);
|
|
1131
1133
|
}
|
|
1132
1134
|
clearSelected() {
|
|
1133
|
-
this._konvaTransformer.nodes([]);
|
|
1135
|
+
if (this._konvaTransformer) this._konvaTransformer.nodes([]);
|
|
1134
1136
|
}
|
|
1135
1137
|
addObject(object) {
|
|
1136
|
-
this._konvaLayer.add(object.ref());
|
|
1138
|
+
if (this._konvaLayer) this._konvaLayer.add(object.ref());
|
|
1137
1139
|
}
|
|
1138
1140
|
konvaLayerFind(type) {
|
|
1141
|
+
if (!this._konvaLayer) return [];
|
|
1139
1142
|
const konvaShape = MarkupMode2Konva[type];
|
|
1140
|
-
if (konvaShape
|
|
1141
|
-
|
|
1142
|
-
}
|
|
1143
|
-
return [];
|
|
1143
|
+
if (!konvaShape || !konvaShape.initializer) return [];
|
|
1144
|
+
return this._konvaLayer.find(konvaShape.name).filter((ref => ref.parent === this._konvaLayer));
|
|
1144
1145
|
}
|
|
1145
1146
|
initializeKonva() {
|
|
1146
|
-
|
|
1147
|
-
container: this.
|
|
1147
|
+
const stage = new Konva.Stage({
|
|
1148
|
+
container: this._markupContainer,
|
|
1148
1149
|
width: this._container.clientWidth,
|
|
1149
1150
|
height: this._container.clientHeight
|
|
1150
1151
|
});
|
|
1151
|
-
|
|
1152
|
+
this._konvaStage = stage;
|
|
1152
1153
|
const layer = new Konva.Layer({
|
|
1153
1154
|
pixelRation: window.devicePixelRatio
|
|
1154
1155
|
});
|
|
@@ -1159,8 +1160,8 @@ class KonvaMarkup {
|
|
|
1159
1160
|
keepRatio: false,
|
|
1160
1161
|
flipEnabled: false
|
|
1161
1162
|
});
|
|
1162
|
-
this._konvaTransformer = transformer;
|
|
1163
1163
|
layer.add(transformer);
|
|
1164
|
+
this._konvaTransformer = transformer;
|
|
1164
1165
|
let isPaint = false;
|
|
1165
1166
|
let lastLine;
|
|
1166
1167
|
let mouseDownPos;
|
|
@@ -1342,20 +1343,17 @@ class KonvaMarkup {
|
|
|
1342
1343
|
container.addEventListener("keydown", (e => {
|
|
1343
1344
|
if (!this._markupIsActive) return;
|
|
1344
1345
|
if (e.code === "Delete") {
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
this._konvaTransformer.nodes().forEach((x => x.destroy()));
|
|
1348
|
-
this._konvaTransformer.nodes([]);
|
|
1349
|
-
}
|
|
1350
|
-
layer.draw();
|
|
1346
|
+
this.getSelectedObjects().forEach((obj => obj.delete()));
|
|
1347
|
+
this.clearSelected();
|
|
1351
1348
|
return;
|
|
1352
1349
|
}
|
|
1353
1350
|
e.preventDefault();
|
|
1354
1351
|
}));
|
|
1355
1352
|
}
|
|
1356
1353
|
destroyKonva() {
|
|
1354
|
+
var _a;
|
|
1357
1355
|
this.clearOverlay();
|
|
1358
|
-
this._konvaStage.destroy();
|
|
1356
|
+
(_a = this._konvaStage) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
1359
1357
|
this._konvaLayer = undefined;
|
|
1360
1358
|
this._konvaTransformer = undefined;
|
|
1361
1359
|
this._konvaStage = undefined;
|
|
@@ -1389,9 +1387,9 @@ class KonvaMarkup {
|
|
|
1389
1387
|
}
|
|
1390
1388
|
getMarkupTexts() {
|
|
1391
1389
|
const texts = [];
|
|
1392
|
-
const textSize = .02;
|
|
1393
|
-
const textScale = this._worldTransformer.getScale();
|
|
1394
1390
|
this.konvaLayerFind("Text").forEach((ref => {
|
|
1391
|
+
const textSize = .02;
|
|
1392
|
+
const textScale = this._worldTransformer.getScale();
|
|
1395
1393
|
const position = {
|
|
1396
1394
|
x: ref.x(),
|
|
1397
1395
|
y: ref.y()
|
|
@@ -1512,13 +1510,15 @@ class KonvaMarkup {
|
|
|
1512
1510
|
combineMarkupWithDrawing() {
|
|
1513
1511
|
this.clearSelected();
|
|
1514
1512
|
const tempCanvas = document.createElement("canvas");
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1513
|
+
if (this._konvaStage) {
|
|
1514
|
+
tempCanvas.width = this._konvaStage.width();
|
|
1515
|
+
tempCanvas.height = this._konvaStage.height();
|
|
1516
|
+
const ctx = tempCanvas.getContext("2d");
|
|
1517
|
+
if (this._container instanceof HTMLCanvasElement) ctx.drawImage(this._container, 0, 0);
|
|
1518
|
+
ctx.drawImage(this._konvaStage.toCanvas({
|
|
1519
|
+
pixelRatio: window.devicePixelRatio
|
|
1520
|
+
}), 0, 0);
|
|
1521
|
+
}
|
|
1522
1522
|
return tempCanvas.toDataURL("image/jpeg", .25);
|
|
1523
1523
|
}
|
|
1524
1524
|
addLine(linePoints, color, type, width, id) {
|
|
@@ -1537,7 +1537,7 @@ class KonvaMarkup {
|
|
|
1537
1537
|
color: color || this._markupColor.HexColor,
|
|
1538
1538
|
id: id
|
|
1539
1539
|
});
|
|
1540
|
-
this.
|
|
1540
|
+
this.addObject(konvaLine);
|
|
1541
1541
|
return konvaLine;
|
|
1542
1542
|
}
|
|
1543
1543
|
createTextInput(pos, inputX, inputY, angle, text) {
|
|
@@ -1618,13 +1618,11 @@ class KonvaMarkup {
|
|
|
1618
1618
|
this._imageInputRef = null;
|
|
1619
1619
|
this._imageInputPos = null;
|
|
1620
1620
|
}
|
|
1621
|
-
addText(
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
this._konvaTransformer.nodes([]);
|
|
1627
|
-
}
|
|
1621
|
+
addText(text, position, angle, color, textSize, fontSize, id) {
|
|
1622
|
+
var _a;
|
|
1623
|
+
if (!text) return;
|
|
1624
|
+
(_a = this.getSelectedObjects().at(0)) === null || _a === void 0 ? void 0 : _a.delete();
|
|
1625
|
+
this.clearSelected();
|
|
1628
1626
|
this.removeTextInput();
|
|
1629
1627
|
const tolerance = 1e-6;
|
|
1630
1628
|
if (textSize && textSize > tolerance && (!fontSize || fontSize < tolerance)) {
|
|
@@ -1637,13 +1635,13 @@ class KonvaMarkup {
|
|
|
1637
1635
|
x: position.x,
|
|
1638
1636
|
y: position.y
|
|
1639
1637
|
},
|
|
1640
|
-
text:
|
|
1638
|
+
text: text,
|
|
1641
1639
|
rotation: angle,
|
|
1642
1640
|
fontSize: fontSize || this.fontSize,
|
|
1643
1641
|
color: color || this._markupColor.HexColor,
|
|
1644
1642
|
id: id
|
|
1645
1643
|
});
|
|
1646
|
-
this.
|
|
1644
|
+
this.addObject(konvaText);
|
|
1647
1645
|
return konvaText;
|
|
1648
1646
|
}
|
|
1649
1647
|
addRectangle(position, width, height, lineWidth, color, id) {
|
|
@@ -1656,7 +1654,7 @@ class KonvaMarkup {
|
|
|
1656
1654
|
color: color || this._markupColor.HexColor,
|
|
1657
1655
|
id: id
|
|
1658
1656
|
});
|
|
1659
|
-
this.
|
|
1657
|
+
this.addObject(konvaRectangle);
|
|
1660
1658
|
return konvaRectangle;
|
|
1661
1659
|
}
|
|
1662
1660
|
addEllipse(position, radius, lineWidth, color, id) {
|
|
@@ -1668,7 +1666,7 @@ class KonvaMarkup {
|
|
|
1668
1666
|
color: color || this._markupColor.HexColor,
|
|
1669
1667
|
id: id
|
|
1670
1668
|
});
|
|
1671
|
-
this.
|
|
1669
|
+
this.addObject(konvaEllipse);
|
|
1672
1670
|
return konvaEllipse;
|
|
1673
1671
|
}
|
|
1674
1672
|
addArrow(start, end, color, id) {
|
|
@@ -1679,7 +1677,7 @@ class KonvaMarkup {
|
|
|
1679
1677
|
color: color || this._markupColor.HexColor,
|
|
1680
1678
|
id: id
|
|
1681
1679
|
});
|
|
1682
|
-
this.
|
|
1680
|
+
this.addObject(konvaArrow);
|
|
1683
1681
|
return konvaArrow;
|
|
1684
1682
|
}
|
|
1685
1683
|
addCloud(position, width, height, lineWidth, color, id) {
|
|
@@ -1692,16 +1690,14 @@ class KonvaMarkup {
|
|
|
1692
1690
|
lineWidth: lineWidth || this.lineWidth,
|
|
1693
1691
|
id: id
|
|
1694
1692
|
});
|
|
1695
|
-
this.
|
|
1693
|
+
this.addObject(konvaCloud);
|
|
1696
1694
|
return konvaCloud;
|
|
1697
1695
|
}
|
|
1698
1696
|
addImage(position, src, width, height, id) {
|
|
1697
|
+
var _a;
|
|
1699
1698
|
if (!position || !src) return;
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
trNodes[0].destroy();
|
|
1703
|
-
this._konvaTransformer.nodes([]);
|
|
1704
|
-
}
|
|
1699
|
+
(_a = this.getSelectedObjects().at(0)) === null || _a === void 0 ? void 0 : _a.delete();
|
|
1700
|
+
this.clearSelected();
|
|
1705
1701
|
this.removeImageInput();
|
|
1706
1702
|
const konvaImage = new KonvaImage({
|
|
1707
1703
|
position: position,
|
|
@@ -1710,7 +1706,7 @@ class KonvaMarkup {
|
|
|
1710
1706
|
height: height,
|
|
1711
1707
|
id: id
|
|
1712
1708
|
});
|
|
1713
|
-
this.
|
|
1709
|
+
this.addObject(konvaImage);
|
|
1714
1710
|
return konvaImage;
|
|
1715
1711
|
}
|
|
1716
1712
|
}
|