@inweb/markup 25.8.2 → 25.8.4
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 +183 -248
- package/dist/markup.js.map +1 -1
- package/dist/markup.min.js +1 -1
- package/dist/markup.module.js +182 -240
- package/dist/markup.module.js.map +1 -1
- package/lib/markup/Konva/KonvaMarkup.d.ts +0 -4
- package/package.json +3 -3
- package/src/markup/Konva/KonvaMarkup.ts +218 -281
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;
|
|
@@ -1017,45 +1017,76 @@ class KonvaMarkup {
|
|
|
1017
1017
|
}
|
|
1018
1018
|
colorizeAllMarkup(r, g, b) {
|
|
1019
1019
|
const hexColor = new MarkupColor(r, g, b).HexColor;
|
|
1020
|
-
this.getObjects().
|
|
1021
|
-
|
|
1022
|
-
|
|
1020
|
+
this.getObjects().filter((obj => {
|
|
1021
|
+
var _a;
|
|
1022
|
+
return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor);
|
|
1023
1023
|
}));
|
|
1024
|
-
this._konvaLayer.draw();
|
|
1025
1024
|
}
|
|
1026
1025
|
colorizeSelectedMarkups(r, g, b) {
|
|
1027
1026
|
const hexColor = new MarkupColor(r, g, b).HexColor;
|
|
1028
|
-
this.getSelectedObjects().
|
|
1029
|
-
|
|
1030
|
-
|
|
1027
|
+
this.getSelectedObjects().filter((obj => {
|
|
1028
|
+
var _a;
|
|
1029
|
+
return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor);
|
|
1031
1030
|
}));
|
|
1032
1031
|
}
|
|
1033
1032
|
setViewpoint(viewpoint) {
|
|
1034
|
-
|
|
1033
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1034
|
+
const markupColor = ((_a = viewpoint.custom_fields) === null || _a === void 0 ? void 0 : _a.markup_color) || {
|
|
1035
1035
|
r: 255,
|
|
1036
1036
|
g: 0,
|
|
1037
1037
|
b: 0
|
|
1038
1038
|
};
|
|
1039
1039
|
this.setMarkupColor(markupColor.r, markupColor.g, markupColor.b);
|
|
1040
|
-
|
|
1040
|
+
(_b = viewpoint.lines) === null || _b === void 0 ? void 0 : _b.forEach((line => {
|
|
1041
|
+
const linePoints = [];
|
|
1042
|
+
line.points.forEach((point => {
|
|
1043
|
+
const screenPoint = this._worldTransformer.worldToScreen(point);
|
|
1044
|
+
linePoints.push(screenPoint.x);
|
|
1045
|
+
linePoints.push(screenPoint.y);
|
|
1046
|
+
}));
|
|
1047
|
+
this.addLine(linePoints, line.color, line.type, line.width, line.id);
|
|
1048
|
+
}));
|
|
1049
|
+
(_c = viewpoint.texts) === null || _c === void 0 ? void 0 : _c.forEach((text => {
|
|
1050
|
+
const screenPoint = this._worldTransformer.worldToScreen(text.position);
|
|
1051
|
+
this.addText(text.text, screenPoint, text.angle, text.color, text.text_size, text.font_size, text.id);
|
|
1052
|
+
}));
|
|
1053
|
+
(_d = viewpoint.rectangles) === null || _d === void 0 ? void 0 : _d.forEach((rect => {
|
|
1054
|
+
const screenPoint = this._worldTransformer.worldToScreen(rect.position);
|
|
1055
|
+
this.addRectangle(screenPoint, rect.width, rect.height, rect.line_width, rect.color, rect.id);
|
|
1056
|
+
}));
|
|
1057
|
+
(_e = viewpoint.ellipses) === null || _e === void 0 ? void 0 : _e.forEach((ellipse => {
|
|
1058
|
+
const screenPoint = this._worldTransformer.worldToScreen(ellipse.position);
|
|
1059
|
+
this.addEllipse(screenPoint, ellipse.radius, ellipse.line_width, ellipse.color, ellipse.id);
|
|
1060
|
+
}));
|
|
1061
|
+
(_f = viewpoint.arrows) === null || _f === void 0 ? void 0 : _f.forEach((arrow => {
|
|
1062
|
+
const startPoint = this._worldTransformer.worldToScreen(arrow.start);
|
|
1063
|
+
const endPoint = this._worldTransformer.worldToScreen(arrow.end);
|
|
1064
|
+
this.addArrow(startPoint, endPoint, arrow.color, arrow.id);
|
|
1065
|
+
}));
|
|
1066
|
+
(_g = viewpoint.clouds) === null || _g === void 0 ? void 0 : _g.forEach((cloud => {
|
|
1067
|
+
const screenPoint = this._worldTransformer.worldToScreen(cloud.position);
|
|
1068
|
+
this.addCloud(screenPoint, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
|
|
1069
|
+
}));
|
|
1070
|
+
(_h = viewpoint.images) === null || _h === void 0 ? void 0 : _h.forEach((image => {
|
|
1071
|
+
const screenPoint = this._worldTransformer.worldToScreen(image.position);
|
|
1072
|
+
this.addImage(screenPoint, image.src, image.width, image.height, image.id);
|
|
1073
|
+
}));
|
|
1041
1074
|
}
|
|
1042
1075
|
getViewpoint() {
|
|
1043
|
-
const viewpoint = {
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1076
|
+
const viewpoint = {};
|
|
1077
|
+
viewpoint.lines = this.getMarkupLines();
|
|
1078
|
+
viewpoint.texts = this.getMarkupTexts();
|
|
1079
|
+
viewpoint.arrows = this.getMarkupArrows();
|
|
1080
|
+
viewpoint.clouds = this.getMarkupClouds();
|
|
1081
|
+
viewpoint.ellipses = this.getMarkupEllipses();
|
|
1082
|
+
viewpoint.images = this.getMarkupImages();
|
|
1083
|
+
viewpoint.rectangles = this.getMarkupRectangles();
|
|
1084
|
+
viewpoint.custom_fields = {
|
|
1085
|
+
markup_color: this.getMarkupColor()
|
|
1051
1086
|
};
|
|
1052
1087
|
viewpoint.snapshot = {
|
|
1053
1088
|
data: this.combineMarkupWithDrawing()
|
|
1054
1089
|
};
|
|
1055
|
-
viewpoint.custom_fields = {
|
|
1056
|
-
markup_color: this.getMarkupColor()
|
|
1057
|
-
};
|
|
1058
|
-
this.fillViewpointShapes(viewpoint);
|
|
1059
1090
|
viewpoint.description = (new Date).toDateString();
|
|
1060
1091
|
return viewpoint;
|
|
1061
1092
|
}
|
|
@@ -1088,6 +1119,7 @@ class KonvaMarkup {
|
|
|
1088
1119
|
return objects;
|
|
1089
1120
|
}
|
|
1090
1121
|
getSelectedObjects() {
|
|
1122
|
+
if (!this._konvaTransformer) return [];
|
|
1091
1123
|
return this._konvaTransformer.nodes().map((ref => {
|
|
1092
1124
|
const name = ref.className;
|
|
1093
1125
|
const konvaShape = Object.values(MarkupMode2Konva).find((shape => shape.name === name));
|
|
@@ -1095,73 +1127,29 @@ class KonvaMarkup {
|
|
|
1095
1127
|
})).filter((x => x));
|
|
1096
1128
|
}
|
|
1097
1129
|
selectObjects(objects) {
|
|
1130
|
+
if (!this._konvaTransformer) return;
|
|
1098
1131
|
const selectedObjs = this._konvaTransformer.nodes().concat(objects.map((x => x.ref())));
|
|
1099
1132
|
this._konvaTransformer.nodes(selectedObjs);
|
|
1100
1133
|
}
|
|
1101
1134
|
clearSelected() {
|
|
1102
|
-
this._konvaTransformer.nodes([]);
|
|
1103
|
-
}
|
|
1104
|
-
fillViewpointShapes(viewpoint) {
|
|
1105
|
-
const markupLines = this.getMarkupLines();
|
|
1106
|
-
if (markupLines && markupLines.length > 0) {
|
|
1107
|
-
markupLines === null || markupLines === void 0 ? void 0 : markupLines.forEach((line => {
|
|
1108
|
-
viewpoint.lines.push(line);
|
|
1109
|
-
}));
|
|
1110
|
-
}
|
|
1111
|
-
const markupTexts = this.getMarkupTexts();
|
|
1112
|
-
if (markupTexts && markupTexts.length > 0) {
|
|
1113
|
-
markupTexts === null || markupTexts === void 0 ? void 0 : markupTexts.forEach((text => {
|
|
1114
|
-
viewpoint.texts.push(text);
|
|
1115
|
-
}));
|
|
1116
|
-
}
|
|
1117
|
-
const markupRectangles = this.getMarkupRectangles();
|
|
1118
|
-
if (markupRectangles && markupRectangles.length > 0) {
|
|
1119
|
-
markupRectangles === null || markupRectangles === void 0 ? void 0 : markupRectangles.forEach((rectangle => {
|
|
1120
|
-
viewpoint.rectangles.push(rectangle);
|
|
1121
|
-
}));
|
|
1122
|
-
}
|
|
1123
|
-
const markupEllipses = this.getMarkupEllipses();
|
|
1124
|
-
if (markupEllipses && markupEllipses.length > 0) {
|
|
1125
|
-
markupEllipses === null || markupEllipses === void 0 ? void 0 : markupEllipses.forEach((ellipse => {
|
|
1126
|
-
viewpoint.ellipses.push(ellipse);
|
|
1127
|
-
}));
|
|
1128
|
-
}
|
|
1129
|
-
const markupArrows = this.getMarkupArrows();
|
|
1130
|
-
if (markupArrows && markupArrows.length > 0) {
|
|
1131
|
-
markupArrows === null || markupArrows === void 0 ? void 0 : markupArrows.forEach((arrow => {
|
|
1132
|
-
viewpoint.arrows.push(arrow);
|
|
1133
|
-
}));
|
|
1134
|
-
}
|
|
1135
|
-
const markupImages = this.getMarkupImages();
|
|
1136
|
-
if (markupImages && markupImages.length > 0) {
|
|
1137
|
-
markupImages === null || markupImages === void 0 ? void 0 : markupImages.forEach((image => {
|
|
1138
|
-
viewpoint.images.push(image);
|
|
1139
|
-
}));
|
|
1140
|
-
}
|
|
1141
|
-
const markupClouds = this.getMarkupClouds();
|
|
1142
|
-
if (markupClouds && markupClouds.length > 0) {
|
|
1143
|
-
markupClouds === null || markupClouds === void 0 ? void 0 : markupClouds.forEach((cloud => {
|
|
1144
|
-
viewpoint.clouds.push(cloud);
|
|
1145
|
-
}));
|
|
1146
|
-
}
|
|
1135
|
+
if (this._konvaTransformer) this._konvaTransformer.nodes([]);
|
|
1147
1136
|
}
|
|
1148
1137
|
addObject(object) {
|
|
1149
|
-
this._konvaLayer.add(object.ref());
|
|
1138
|
+
if (this._konvaLayer) this._konvaLayer.add(object.ref());
|
|
1150
1139
|
}
|
|
1151
1140
|
konvaLayerFind(type) {
|
|
1141
|
+
if (!this._konvaLayer) return [];
|
|
1152
1142
|
const konvaShape = MarkupMode2Konva[type];
|
|
1153
|
-
if (konvaShape
|
|
1154
|
-
|
|
1155
|
-
}
|
|
1156
|
-
return [];
|
|
1143
|
+
if (!konvaShape || !konvaShape.initializer) return [];
|
|
1144
|
+
return this._konvaLayer.find(konvaShape.name).filter((ref => ref.parent === this._konvaLayer));
|
|
1157
1145
|
}
|
|
1158
1146
|
initializeKonva() {
|
|
1159
|
-
|
|
1160
|
-
container: this.
|
|
1147
|
+
const stage = new Konva.Stage({
|
|
1148
|
+
container: this._markupContainer,
|
|
1161
1149
|
width: this._container.clientWidth,
|
|
1162
1150
|
height: this._container.clientHeight
|
|
1163
1151
|
});
|
|
1164
|
-
|
|
1152
|
+
this._konvaStage = stage;
|
|
1165
1153
|
const layer = new Konva.Layer({
|
|
1166
1154
|
pixelRation: window.devicePixelRatio
|
|
1167
1155
|
});
|
|
@@ -1172,8 +1160,8 @@ class KonvaMarkup {
|
|
|
1172
1160
|
keepRatio: false,
|
|
1173
1161
|
flipEnabled: false
|
|
1174
1162
|
});
|
|
1175
|
-
this._konvaTransformer = transformer;
|
|
1176
1163
|
layer.add(transformer);
|
|
1164
|
+
this._konvaTransformer = transformer;
|
|
1177
1165
|
let isPaint = false;
|
|
1178
1166
|
let lastLine;
|
|
1179
1167
|
let mouseDownPos;
|
|
@@ -1355,31 +1343,28 @@ class KonvaMarkup {
|
|
|
1355
1343
|
container.addEventListener("keydown", (e => {
|
|
1356
1344
|
if (!this._markupIsActive) return;
|
|
1357
1345
|
if (e.code === "Delete") {
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
this._konvaTransformer.nodes().forEach((x => x.destroy()));
|
|
1361
|
-
this._konvaTransformer.nodes([]);
|
|
1362
|
-
}
|
|
1363
|
-
layer.draw();
|
|
1346
|
+
this.getSelectedObjects().forEach((obj => obj.delete()));
|
|
1347
|
+
this.clearSelected();
|
|
1364
1348
|
return;
|
|
1365
1349
|
}
|
|
1366
1350
|
e.preventDefault();
|
|
1367
1351
|
}));
|
|
1368
1352
|
}
|
|
1369
1353
|
destroyKonva() {
|
|
1354
|
+
var _a;
|
|
1370
1355
|
this.clearOverlay();
|
|
1371
|
-
this._konvaStage.destroy();
|
|
1356
|
+
(_a = this._konvaStage) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
1372
1357
|
this._konvaLayer = undefined;
|
|
1373
1358
|
this._konvaTransformer = undefined;
|
|
1374
1359
|
this._konvaStage = undefined;
|
|
1375
1360
|
}
|
|
1376
1361
|
getMarkupLines() {
|
|
1377
1362
|
const lines = [];
|
|
1378
|
-
this.konvaLayerFind("Line").forEach((
|
|
1379
|
-
const linePoints =
|
|
1363
|
+
this.konvaLayerFind("Line").forEach((ref => {
|
|
1364
|
+
const linePoints = ref.points();
|
|
1380
1365
|
if (!linePoints) return;
|
|
1381
1366
|
const worldPoints = [];
|
|
1382
|
-
const absoluteTransform =
|
|
1367
|
+
const absoluteTransform = ref.getAbsoluteTransform();
|
|
1383
1368
|
for (let i = 0; i < linePoints.length; i += 2) {
|
|
1384
1369
|
const atPoint = absoluteTransform.point({
|
|
1385
1370
|
x: linePoints[i],
|
|
@@ -1388,30 +1373,30 @@ class KonvaMarkup {
|
|
|
1388
1373
|
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
1389
1374
|
worldPoints.push(worldPoint);
|
|
1390
1375
|
}
|
|
1391
|
-
const konvaLine = new KonvaLine(null,
|
|
1392
|
-
|
|
1376
|
+
const konvaLine = new KonvaLine(null, ref);
|
|
1377
|
+
const line = {
|
|
1393
1378
|
id: konvaLine.id(),
|
|
1394
1379
|
points: worldPoints,
|
|
1395
1380
|
color: konvaLine.getColor() || "#ff0000",
|
|
1396
1381
|
type: konvaLine.getLineType() || this.lineType,
|
|
1397
1382
|
width: konvaLine.getLineWidth() || this.lineWidth
|
|
1398
|
-
}
|
|
1383
|
+
};
|
|
1384
|
+
lines.push(line);
|
|
1399
1385
|
}));
|
|
1400
1386
|
return lines;
|
|
1401
1387
|
}
|
|
1402
1388
|
getMarkupTexts() {
|
|
1403
1389
|
const texts = [];
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
if (!text) return;
|
|
1390
|
+
this.konvaLayerFind("Text").forEach((ref => {
|
|
1391
|
+
const textSize = .02;
|
|
1392
|
+
const textScale = this._worldTransformer.getScale();
|
|
1408
1393
|
const position = {
|
|
1409
|
-
x:
|
|
1410
|
-
y:
|
|
1394
|
+
x: ref.x(),
|
|
1395
|
+
y: ref.y()
|
|
1411
1396
|
};
|
|
1412
1397
|
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
1413
|
-
const shape = new KonvaText(null,
|
|
1414
|
-
|
|
1398
|
+
const shape = new KonvaText(null, ref);
|
|
1399
|
+
const text = {
|
|
1415
1400
|
id: shape.id(),
|
|
1416
1401
|
position: worldPoint,
|
|
1417
1402
|
text: shape.getText(),
|
|
@@ -1419,150 +1404,121 @@ class KonvaMarkup {
|
|
|
1419
1404
|
angle: shape.getRotation(),
|
|
1420
1405
|
color: shape.getColor(),
|
|
1421
1406
|
font_size: shape.getFontSize()
|
|
1422
|
-
}
|
|
1407
|
+
};
|
|
1408
|
+
texts.push(text);
|
|
1423
1409
|
}));
|
|
1424
1410
|
return texts;
|
|
1425
1411
|
}
|
|
1426
1412
|
getMarkupRectangles() {
|
|
1427
1413
|
const rectangles = [];
|
|
1428
|
-
this.konvaLayerFind("Rectangle").forEach((
|
|
1429
|
-
const position =
|
|
1414
|
+
this.konvaLayerFind("Rectangle").forEach((ref => {
|
|
1415
|
+
const position = ref.position();
|
|
1430
1416
|
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
1431
|
-
const shape = new KonvaRectangle(null,
|
|
1432
|
-
|
|
1417
|
+
const shape = new KonvaRectangle(null, ref);
|
|
1418
|
+
const rectangle = {
|
|
1433
1419
|
id: shape.id(),
|
|
1434
1420
|
position: worldPoint,
|
|
1435
1421
|
width: shape.getWidth(),
|
|
1436
1422
|
height: shape.getHeigth(),
|
|
1437
1423
|
line_width: shape.getLineWidth(),
|
|
1438
1424
|
color: shape.getColor()
|
|
1439
|
-
}
|
|
1425
|
+
};
|
|
1426
|
+
rectangles.push(rectangle);
|
|
1440
1427
|
}));
|
|
1441
1428
|
return rectangles;
|
|
1442
1429
|
}
|
|
1443
1430
|
getMarkupEllipses() {
|
|
1444
1431
|
const ellipses = [];
|
|
1445
|
-
this.konvaLayerFind("Ellipse").forEach((
|
|
1446
|
-
const position =
|
|
1432
|
+
this.konvaLayerFind("Ellipse").forEach((ref => {
|
|
1433
|
+
const position = ref.position();
|
|
1447
1434
|
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
1448
|
-
const shape = new KonvaEllipse(null,
|
|
1449
|
-
|
|
1435
|
+
const shape = new KonvaEllipse(null, ref);
|
|
1436
|
+
const ellipse = {
|
|
1450
1437
|
id: shape.id(),
|
|
1451
1438
|
position: worldPoint,
|
|
1452
1439
|
radius: {
|
|
1453
|
-
x:
|
|
1454
|
-
y:
|
|
1440
|
+
x: ref.getRadiusX(),
|
|
1441
|
+
y: ref.getRadiusY()
|
|
1455
1442
|
},
|
|
1456
1443
|
line_width: shape.getLineWidth(),
|
|
1457
1444
|
color: shape.getColor()
|
|
1458
|
-
}
|
|
1445
|
+
};
|
|
1446
|
+
ellipses.push(ellipse);
|
|
1459
1447
|
}));
|
|
1460
1448
|
return ellipses;
|
|
1461
1449
|
}
|
|
1462
1450
|
getMarkupArrows() {
|
|
1463
1451
|
const arrows = [];
|
|
1464
|
-
this.konvaLayerFind("Arrow").forEach((
|
|
1465
|
-
const absoluteTransform =
|
|
1452
|
+
this.konvaLayerFind("Arrow").forEach((ref => {
|
|
1453
|
+
const absoluteTransform = ref.getAbsoluteTransform();
|
|
1466
1454
|
const atStartPoint = absoluteTransform.point({
|
|
1467
|
-
x:
|
|
1468
|
-
y:
|
|
1455
|
+
x: ref.points()[0],
|
|
1456
|
+
y: ref.points()[1]
|
|
1469
1457
|
});
|
|
1470
1458
|
const worldStartPoint = this._worldTransformer.screenToWorld(atStartPoint);
|
|
1471
1459
|
const atEndPoint = absoluteTransform.point({
|
|
1472
|
-
x:
|
|
1473
|
-
y:
|
|
1460
|
+
x: ref.points()[2],
|
|
1461
|
+
y: ref.points()[3]
|
|
1474
1462
|
});
|
|
1475
1463
|
const worldEndPoint = this._worldTransformer.screenToWorld(atEndPoint);
|
|
1476
|
-
const shape = new KonvaArrow(null,
|
|
1477
|
-
|
|
1464
|
+
const shape = new KonvaArrow(null, ref);
|
|
1465
|
+
const arrow = {
|
|
1478
1466
|
id: shape.id(),
|
|
1479
1467
|
start: worldStartPoint,
|
|
1480
1468
|
end: worldEndPoint,
|
|
1481
1469
|
color: shape.getColor()
|
|
1482
|
-
}
|
|
1470
|
+
};
|
|
1471
|
+
arrows.push(arrow);
|
|
1483
1472
|
}));
|
|
1484
1473
|
return arrows;
|
|
1485
1474
|
}
|
|
1486
1475
|
getMarkupImages() {
|
|
1487
1476
|
const images = [];
|
|
1488
|
-
this.konvaLayerFind("Image").forEach((
|
|
1489
|
-
const position =
|
|
1477
|
+
this.konvaLayerFind("Image").forEach((ref => {
|
|
1478
|
+
const position = ref.position();
|
|
1490
1479
|
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
1491
|
-
const shape = new KonvaImage(null,
|
|
1492
|
-
|
|
1480
|
+
const shape = new KonvaImage(null, ref);
|
|
1481
|
+
const image = {
|
|
1493
1482
|
id: shape.id(),
|
|
1494
1483
|
position: worldPoint,
|
|
1495
1484
|
src: shape.getSrc(),
|
|
1496
1485
|
width: shape.getWidth(),
|
|
1497
1486
|
height: shape.getHeight()
|
|
1498
|
-
}
|
|
1487
|
+
};
|
|
1488
|
+
images.push(image);
|
|
1499
1489
|
}));
|
|
1500
1490
|
return images;
|
|
1501
1491
|
}
|
|
1502
1492
|
getMarkupClouds() {
|
|
1503
1493
|
const clouds = [];
|
|
1504
|
-
this.konvaLayerFind("Cloud").forEach((
|
|
1505
|
-
const position =
|
|
1494
|
+
this.konvaLayerFind("Cloud").forEach((ref => {
|
|
1495
|
+
const position = ref.position();
|
|
1506
1496
|
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
1507
|
-
const shape = new KonvaCloud(null,
|
|
1508
|
-
|
|
1497
|
+
const shape = new KonvaCloud(null, ref);
|
|
1498
|
+
const cloud = {
|
|
1509
1499
|
id: shape.id(),
|
|
1510
1500
|
position: worldPoint,
|
|
1511
1501
|
width: shape.getWidth(),
|
|
1512
1502
|
height: shape.getHeigth(),
|
|
1513
1503
|
line_width: shape.getLineWidth(),
|
|
1514
1504
|
color: shape.getColor()
|
|
1515
|
-
}
|
|
1505
|
+
};
|
|
1506
|
+
clouds.push(cloud);
|
|
1516
1507
|
}));
|
|
1517
1508
|
return clouds;
|
|
1518
1509
|
}
|
|
1519
|
-
loadMarkup(viewpoint) {
|
|
1520
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1521
|
-
(_a = viewpoint.lines) === null || _a === void 0 ? void 0 : _a.forEach((vpLine => {
|
|
1522
|
-
const linePoints = [];
|
|
1523
|
-
vpLine.points.forEach((point => {
|
|
1524
|
-
const screenPoint = this._worldTransformer.worldToScreen(point);
|
|
1525
|
-
linePoints.push(screenPoint.x);
|
|
1526
|
-
linePoints.push(screenPoint.y);
|
|
1527
|
-
}));
|
|
1528
|
-
this.addLine(linePoints, vpLine.color, vpLine.type, vpLine.width, vpLine.id);
|
|
1529
|
-
}));
|
|
1530
|
-
(_b = viewpoint.texts) === null || _b === void 0 ? void 0 : _b.forEach((vpText => {
|
|
1531
|
-
const screenPoint = this._worldTransformer.worldToScreen(vpText.position);
|
|
1532
|
-
this.addText(vpText.text, screenPoint, vpText.angle, vpText.color, vpText.text_size, vpText.font_size, vpText.id);
|
|
1533
|
-
}));
|
|
1534
|
-
(_c = viewpoint.rectangles) === null || _c === void 0 ? void 0 : _c.forEach((vpRect => {
|
|
1535
|
-
const screenPoint = this._worldTransformer.worldToScreen(vpRect.position);
|
|
1536
|
-
this.addRectangle(screenPoint, vpRect.width, vpRect.height, vpRect.line_width, vpRect.color, vpRect.id);
|
|
1537
|
-
}));
|
|
1538
|
-
(_d = viewpoint.ellipses) === null || _d === void 0 ? void 0 : _d.forEach((vpEllipse => {
|
|
1539
|
-
const screenPoint = this._worldTransformer.worldToScreen(vpEllipse.position);
|
|
1540
|
-
this.addEllipse(screenPoint, vpEllipse.radius, vpEllipse.line_width, vpEllipse.color, vpEllipse.id);
|
|
1541
|
-
}));
|
|
1542
|
-
(_e = viewpoint.arrows) === null || _e === void 0 ? void 0 : _e.forEach((vpArrow => {
|
|
1543
|
-
const startPoint = this._worldTransformer.worldToScreen(vpArrow.start);
|
|
1544
|
-
const endPoint = this._worldTransformer.worldToScreen(vpArrow.end);
|
|
1545
|
-
this.addArrow(startPoint, endPoint, vpArrow.color, vpArrow.id);
|
|
1546
|
-
}));
|
|
1547
|
-
(_f = viewpoint.clouds) === null || _f === void 0 ? void 0 : _f.forEach((vpCloud => {
|
|
1548
|
-
const screenPoint = this._worldTransformer.worldToScreen(vpCloud.position);
|
|
1549
|
-
this.addCloud(screenPoint, vpCloud.width, vpCloud.height, vpCloud.line_width, vpCloud.color, vpCloud.id);
|
|
1550
|
-
}));
|
|
1551
|
-
(_g = viewpoint.images) === null || _g === void 0 ? void 0 : _g.forEach((vpImage => {
|
|
1552
|
-
const screenPoint = this._worldTransformer.worldToScreen(vpImage.position);
|
|
1553
|
-
this.addImage(screenPoint, vpImage.src, vpImage.width, vpImage.height, vpImage.id);
|
|
1554
|
-
}));
|
|
1555
|
-
}
|
|
1556
1510
|
combineMarkupWithDrawing() {
|
|
1557
1511
|
this.clearSelected();
|
|
1558
1512
|
const tempCanvas = document.createElement("canvas");
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
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
|
+
}
|
|
1566
1522
|
return tempCanvas.toDataURL("image/jpeg", .25);
|
|
1567
1523
|
}
|
|
1568
1524
|
addLine(linePoints, color, type, width, id) {
|
|
@@ -1581,8 +1537,7 @@ class KonvaMarkup {
|
|
|
1581
1537
|
color: color || this._markupColor.HexColor,
|
|
1582
1538
|
id: id
|
|
1583
1539
|
});
|
|
1584
|
-
|
|
1585
|
-
this._konvaLayer.add(obj);
|
|
1540
|
+
this.addObject(konvaLine);
|
|
1586
1541
|
return konvaLine;
|
|
1587
1542
|
}
|
|
1588
1543
|
createTextInput(pos, inputX, inputY, angle, text) {
|
|
@@ -1663,34 +1618,31 @@ class KonvaMarkup {
|
|
|
1663
1618
|
this._imageInputRef = null;
|
|
1664
1619
|
this._imageInputPos = null;
|
|
1665
1620
|
}
|
|
1666
|
-
addText(
|
|
1667
|
-
|
|
1668
|
-
if (
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
}
|
|
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();
|
|
1672
1626
|
this.removeTextInput();
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
fontSize = textSize / (scale.y / size) / 34;
|
|
1679
|
-
}
|
|
1680
|
-
const konvaText = new KonvaText({
|
|
1681
|
-
position: {
|
|
1682
|
-
x: position.x,
|
|
1683
|
-
y: position.y
|
|
1684
|
-
},
|
|
1685
|
-
text: specifiedText,
|
|
1686
|
-
rotation: angle,
|
|
1687
|
-
fontSize: fontSize || this.fontSize,
|
|
1688
|
-
color: color || this._markupColor.HexColor,
|
|
1689
|
-
id: id
|
|
1690
|
-
});
|
|
1691
|
-
this._konvaLayer.add(konvaText.ref());
|
|
1692
|
-
return konvaText;
|
|
1627
|
+
const tolerance = 1e-6;
|
|
1628
|
+
if (textSize && textSize > tolerance && (!fontSize || fontSize < tolerance)) {
|
|
1629
|
+
const size = .02;
|
|
1630
|
+
const scale = this._worldTransformer.getScale();
|
|
1631
|
+
fontSize = textSize / (scale.y / size) / 34;
|
|
1693
1632
|
}
|
|
1633
|
+
const konvaText = new KonvaText({
|
|
1634
|
+
position: {
|
|
1635
|
+
x: position.x,
|
|
1636
|
+
y: position.y
|
|
1637
|
+
},
|
|
1638
|
+
text: text,
|
|
1639
|
+
rotation: angle,
|
|
1640
|
+
fontSize: fontSize || this.fontSize,
|
|
1641
|
+
color: color || this._markupColor.HexColor,
|
|
1642
|
+
id: id
|
|
1643
|
+
});
|
|
1644
|
+
this.addObject(konvaText);
|
|
1645
|
+
return konvaText;
|
|
1694
1646
|
}
|
|
1695
1647
|
addRectangle(position, width, height, lineWidth, color, id) {
|
|
1696
1648
|
if (!position) return;
|
|
@@ -1702,8 +1654,7 @@ class KonvaMarkup {
|
|
|
1702
1654
|
color: color || this._markupColor.HexColor,
|
|
1703
1655
|
id: id
|
|
1704
1656
|
});
|
|
1705
|
-
|
|
1706
|
-
this._konvaLayer.add(obj);
|
|
1657
|
+
this.addObject(konvaRectangle);
|
|
1707
1658
|
return konvaRectangle;
|
|
1708
1659
|
}
|
|
1709
1660
|
addEllipse(position, radius, lineWidth, color, id) {
|
|
@@ -1715,8 +1666,7 @@ class KonvaMarkup {
|
|
|
1715
1666
|
color: color || this._markupColor.HexColor,
|
|
1716
1667
|
id: id
|
|
1717
1668
|
});
|
|
1718
|
-
|
|
1719
|
-
this._konvaLayer.add(obj);
|
|
1669
|
+
this.addObject(konvaEllipse);
|
|
1720
1670
|
return konvaEllipse;
|
|
1721
1671
|
}
|
|
1722
1672
|
addArrow(start, end, color, id) {
|
|
@@ -1727,8 +1677,7 @@ class KonvaMarkup {
|
|
|
1727
1677
|
color: color || this._markupColor.HexColor,
|
|
1728
1678
|
id: id
|
|
1729
1679
|
});
|
|
1730
|
-
|
|
1731
|
-
this._konvaLayer.add(obj);
|
|
1680
|
+
this.addObject(konvaArrow);
|
|
1732
1681
|
return konvaArrow;
|
|
1733
1682
|
}
|
|
1734
1683
|
addCloud(position, width, height, lineWidth, color, id) {
|
|
@@ -1741,30 +1690,23 @@ class KonvaMarkup {
|
|
|
1741
1690
|
lineWidth: lineWidth || this.lineWidth,
|
|
1742
1691
|
id: id
|
|
1743
1692
|
});
|
|
1744
|
-
|
|
1745
|
-
this._konvaLayer.add(obj);
|
|
1693
|
+
this.addObject(konvaCloud);
|
|
1746
1694
|
return konvaCloud;
|
|
1747
1695
|
}
|
|
1748
1696
|
addImage(position, src, width, height, id) {
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
position: position,
|
|
1754
|
-
src: src,
|
|
1755
|
-
width: width,
|
|
1756
|
-
height: height,
|
|
1757
|
-
id: id
|
|
1758
|
-
});
|
|
1759
|
-
const obj = konvaImage.ref();
|
|
1760
|
-
this._konvaLayer.add(obj);
|
|
1761
|
-
const trNodes = this._konvaTransformer.nodes();
|
|
1762
|
-
if (trNodes.length > 0) {
|
|
1763
|
-
trNodes[0].destroy();
|
|
1764
|
-
this._konvaTransformer.nodes([]);
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1697
|
+
var _a;
|
|
1698
|
+
if (!position || !src) return;
|
|
1699
|
+
(_a = this.getSelectedObjects().at(0)) === null || _a === void 0 ? void 0 : _a.delete();
|
|
1700
|
+
this.clearSelected();
|
|
1767
1701
|
this.removeImageInput();
|
|
1702
|
+
const konvaImage = new KonvaImage({
|
|
1703
|
+
position: position,
|
|
1704
|
+
src: src,
|
|
1705
|
+
width: width,
|
|
1706
|
+
height: height,
|
|
1707
|
+
id: id
|
|
1708
|
+
});
|
|
1709
|
+
this.addObject(konvaImage);
|
|
1768
1710
|
return konvaImage;
|
|
1769
1711
|
}
|
|
1770
1712
|
}
|