@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.js
CHANGED
|
@@ -12419,11 +12419,10 @@
|
|
|
12419
12419
|
*/
|
|
12420
12420
|
class KonvaMarkup {
|
|
12421
12421
|
constructor() {
|
|
12422
|
-
this.
|
|
12422
|
+
this._pointerEvents = [];
|
|
12423
12423
|
this._markupIsActive = false;
|
|
12424
12424
|
this._markupColor = new MarkupColor(255, 0, 0);
|
|
12425
12425
|
this._zIndex = 1;
|
|
12426
|
-
this._markupContainerName = "markupContainer";
|
|
12427
12426
|
this.lineWidth = 4;
|
|
12428
12427
|
this.lineType = "solid";
|
|
12429
12428
|
this.fontSize = 34;
|
|
@@ -12440,12 +12439,13 @@
|
|
|
12440
12439
|
this.enableEditMode(draggerName);
|
|
12441
12440
|
};
|
|
12442
12441
|
this.resizeContainer = (entries) => {
|
|
12443
|
-
var _a, _b;
|
|
12444
12442
|
const { width, height } = entries[0].contentRect;
|
|
12445
12443
|
if (!width || !height)
|
|
12446
12444
|
return; // <- invisible container, or container with parent removed
|
|
12447
|
-
(
|
|
12448
|
-
|
|
12445
|
+
if (!this._konvaStage)
|
|
12446
|
+
return;
|
|
12447
|
+
this._konvaStage.width(width);
|
|
12448
|
+
this._konvaStage.height(height);
|
|
12449
12449
|
};
|
|
12450
12450
|
this.pan = (event) => {
|
|
12451
12451
|
const dX = event.dX / window.devicePixelRatio;
|
|
@@ -12458,14 +12458,16 @@
|
|
|
12458
12458
|
};
|
|
12459
12459
|
}
|
|
12460
12460
|
initialize(container, pointerEvents, viewer, worldTransformer) {
|
|
12461
|
-
if (!Konva)
|
|
12462
|
-
|
|
12461
|
+
if (!Konva) {
|
|
12462
|
+
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>');
|
|
12463
|
+
return;
|
|
12464
|
+
}
|
|
12463
12465
|
this._viewer = viewer;
|
|
12464
12466
|
this._worldTransformer = worldTransformer !== null && worldTransformer !== void 0 ? worldTransformer : new WorldTransform();
|
|
12465
12467
|
this._container = container;
|
|
12466
12468
|
this._pointerEvents = pointerEvents !== null && pointerEvents !== void 0 ? pointerEvents : [];
|
|
12467
12469
|
this._markupContainer = document.createElement("div");
|
|
12468
|
-
this._markupContainer.id =
|
|
12470
|
+
this._markupContainer.id = "markup-container";
|
|
12469
12471
|
this._markupContainer.style.position = "absolute";
|
|
12470
12472
|
this._markupContainer.style.top = "0px";
|
|
12471
12473
|
this._markupContainer.style.left = "0px";
|
|
@@ -12482,33 +12484,30 @@
|
|
|
12482
12484
|
this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
|
|
12483
12485
|
this._viewer.addEventListener("pan", this.pan);
|
|
12484
12486
|
}
|
|
12485
|
-
this._isInitialized = true;
|
|
12486
12487
|
}
|
|
12487
12488
|
dispose() {
|
|
12488
|
-
|
|
12489
|
-
return;
|
|
12489
|
+
var _a, _b;
|
|
12490
12490
|
if (this._viewer) {
|
|
12491
12491
|
this._viewer.removeEventListener("pan", this.pan);
|
|
12492
12492
|
this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
|
|
12493
|
+
this._pointerEvents.forEach((x) => this._markupContainer.removeEventListener(x, this.redirectToViewer));
|
|
12493
12494
|
}
|
|
12494
|
-
this._pointerEvents.forEach((x) => this._markupContainer.removeEventListener(x, this.redirectToViewer));
|
|
12495
12495
|
this.destroyKonva();
|
|
12496
|
-
this._resizeObserver.disconnect();
|
|
12496
|
+
(_a = this._resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
12497
12497
|
this._resizeObserver = undefined;
|
|
12498
|
-
this._markupContainer.remove();
|
|
12498
|
+
(_b = this._markupContainer) === null || _b === void 0 ? void 0 : _b.remove();
|
|
12499
12499
|
this._markupContainer = undefined;
|
|
12500
12500
|
this._container = undefined;
|
|
12501
12501
|
this._viewer = undefined;
|
|
12502
12502
|
this._worldTransformer = undefined;
|
|
12503
12503
|
this._markupIsActive = false;
|
|
12504
|
-
this._isInitialized = false;
|
|
12505
12504
|
}
|
|
12506
12505
|
syncOverlay() { }
|
|
12507
12506
|
clearOverlay() {
|
|
12508
12507
|
this.removeTextInput();
|
|
12509
12508
|
this.removeImageInput();
|
|
12510
12509
|
this.clearSelected();
|
|
12511
|
-
this.getObjects().forEach((obj) => obj.
|
|
12510
|
+
this.getObjects().forEach((obj) => obj.delete());
|
|
12512
12511
|
}
|
|
12513
12512
|
getMarkupColor() {
|
|
12514
12513
|
return this._markupColor.RGB;
|
|
@@ -12518,43 +12517,62 @@
|
|
|
12518
12517
|
}
|
|
12519
12518
|
colorizeAllMarkup(r, g, b) {
|
|
12520
12519
|
const hexColor = new MarkupColor(r, g, b).HexColor;
|
|
12521
|
-
this.getObjects().
|
|
12522
|
-
const colorable = obj;
|
|
12523
|
-
if (colorable && colorable.setColor)
|
|
12524
|
-
colorable.setColor(hexColor);
|
|
12525
|
-
});
|
|
12526
|
-
this._konvaLayer.draw();
|
|
12520
|
+
this.getObjects().filter((obj) => { var _a; return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor); });
|
|
12527
12521
|
}
|
|
12528
12522
|
colorizeSelectedMarkups(r, g, b) {
|
|
12529
12523
|
const hexColor = new MarkupColor(r, g, b).HexColor;
|
|
12530
|
-
this.getSelectedObjects().
|
|
12531
|
-
const colorable = obj;
|
|
12532
|
-
if (colorable && colorable.setColor)
|
|
12533
|
-
colorable.setColor(hexColor);
|
|
12534
|
-
});
|
|
12524
|
+
this.getSelectedObjects().filter((obj) => { var _a; return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor); });
|
|
12535
12525
|
}
|
|
12536
12526
|
setViewpoint(viewpoint) {
|
|
12537
|
-
|
|
12527
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
12528
|
+
const markupColor = ((_a = viewpoint.custom_fields) === null || _a === void 0 ? void 0 : _a.markup_color) || { r: 255, g: 0, b: 0 };
|
|
12538
12529
|
this.setMarkupColor(markupColor.r, markupColor.g, markupColor.b);
|
|
12539
|
-
|
|
12530
|
+
(_b = viewpoint.lines) === null || _b === void 0 ? void 0 : _b.forEach((line) => {
|
|
12531
|
+
const linePoints = [];
|
|
12532
|
+
line.points.forEach((point) => {
|
|
12533
|
+
const screenPoint = this._worldTransformer.worldToScreen(point);
|
|
12534
|
+
linePoints.push(screenPoint.x);
|
|
12535
|
+
linePoints.push(screenPoint.y);
|
|
12536
|
+
});
|
|
12537
|
+
this.addLine(linePoints, line.color, line.type, line.width, line.id);
|
|
12538
|
+
});
|
|
12539
|
+
(_c = viewpoint.texts) === null || _c === void 0 ? void 0 : _c.forEach((text) => {
|
|
12540
|
+
const screenPoint = this._worldTransformer.worldToScreen(text.position);
|
|
12541
|
+
this.addText(text.text, screenPoint, text.angle, text.color, text.text_size, text.font_size, text.id);
|
|
12542
|
+
});
|
|
12543
|
+
(_d = viewpoint.rectangles) === null || _d === void 0 ? void 0 : _d.forEach((rect) => {
|
|
12544
|
+
const screenPoint = this._worldTransformer.worldToScreen(rect.position);
|
|
12545
|
+
this.addRectangle(screenPoint, rect.width, rect.height, rect.line_width, rect.color, rect.id);
|
|
12546
|
+
});
|
|
12547
|
+
(_e = viewpoint.ellipses) === null || _e === void 0 ? void 0 : _e.forEach((ellipse) => {
|
|
12548
|
+
const screenPoint = this._worldTransformer.worldToScreen(ellipse.position);
|
|
12549
|
+
this.addEllipse(screenPoint, ellipse.radius, ellipse.line_width, ellipse.color, ellipse.id);
|
|
12550
|
+
});
|
|
12551
|
+
(_f = viewpoint.arrows) === null || _f === void 0 ? void 0 : _f.forEach((arrow) => {
|
|
12552
|
+
const startPoint = this._worldTransformer.worldToScreen(arrow.start);
|
|
12553
|
+
const endPoint = this._worldTransformer.worldToScreen(arrow.end);
|
|
12554
|
+
this.addArrow(startPoint, endPoint, arrow.color, arrow.id);
|
|
12555
|
+
});
|
|
12556
|
+
(_g = viewpoint.clouds) === null || _g === void 0 ? void 0 : _g.forEach((cloud) => {
|
|
12557
|
+
const screenPoint = this._worldTransformer.worldToScreen(cloud.position);
|
|
12558
|
+
this.addCloud(screenPoint, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
|
|
12559
|
+
});
|
|
12560
|
+
(_h = viewpoint.images) === null || _h === void 0 ? void 0 : _h.forEach((image) => {
|
|
12561
|
+
const screenPoint = this._worldTransformer.worldToScreen(image.position);
|
|
12562
|
+
this.addImage(screenPoint, image.src, image.width, image.height, image.id);
|
|
12563
|
+
});
|
|
12540
12564
|
}
|
|
12541
12565
|
getViewpoint() {
|
|
12542
|
-
const viewpoint = {
|
|
12543
|
-
|
|
12544
|
-
|
|
12545
|
-
|
|
12546
|
-
|
|
12547
|
-
|
|
12548
|
-
|
|
12549
|
-
|
|
12550
|
-
};
|
|
12551
|
-
viewpoint.snapshot = {
|
|
12552
|
-
data: this.combineMarkupWithDrawing(),
|
|
12553
|
-
};
|
|
12554
|
-
viewpoint.custom_fields = {
|
|
12555
|
-
markup_color: this.getMarkupColor(),
|
|
12556
|
-
};
|
|
12557
|
-
this.fillViewpointShapes(viewpoint);
|
|
12566
|
+
const viewpoint = {};
|
|
12567
|
+
viewpoint.lines = this.getMarkupLines();
|
|
12568
|
+
viewpoint.texts = this.getMarkupTexts();
|
|
12569
|
+
viewpoint.arrows = this.getMarkupArrows();
|
|
12570
|
+
viewpoint.clouds = this.getMarkupClouds();
|
|
12571
|
+
viewpoint.ellipses = this.getMarkupEllipses();
|
|
12572
|
+
viewpoint.images = this.getMarkupImages();
|
|
12573
|
+
viewpoint.rectangles = this.getMarkupRectangles();
|
|
12574
|
+
viewpoint.custom_fields = { markup_color: this.getMarkupColor() };
|
|
12575
|
+
viewpoint.snapshot = { data: this.combineMarkupWithDrawing() };
|
|
12558
12576
|
viewpoint.description = new Date().toDateString();
|
|
12559
12577
|
return viewpoint;
|
|
12560
12578
|
}
|
|
@@ -12591,6 +12609,8 @@
|
|
|
12591
12609
|
return objects;
|
|
12592
12610
|
}
|
|
12593
12611
|
getSelectedObjects() {
|
|
12612
|
+
if (!this._konvaTransformer)
|
|
12613
|
+
return [];
|
|
12594
12614
|
return this._konvaTransformer
|
|
12595
12615
|
.nodes()
|
|
12596
12616
|
.map((ref) => {
|
|
@@ -12601,75 +12621,36 @@
|
|
|
12601
12621
|
.filter((x) => x);
|
|
12602
12622
|
}
|
|
12603
12623
|
selectObjects(objects) {
|
|
12624
|
+
if (!this._konvaTransformer)
|
|
12625
|
+
return;
|
|
12604
12626
|
const selectedObjs = this._konvaTransformer.nodes().concat(objects.map((x) => x.ref()));
|
|
12605
12627
|
this._konvaTransformer.nodes(selectedObjs);
|
|
12606
12628
|
}
|
|
12607
12629
|
clearSelected() {
|
|
12608
|
-
this._konvaTransformer
|
|
12609
|
-
|
|
12610
|
-
fillViewpointShapes(viewpoint) {
|
|
12611
|
-
const markupLines = this.getMarkupLines();
|
|
12612
|
-
if (markupLines && markupLines.length > 0) {
|
|
12613
|
-
markupLines === null || markupLines === void 0 ? void 0 : markupLines.forEach((line) => {
|
|
12614
|
-
viewpoint.lines.push(line);
|
|
12615
|
-
});
|
|
12616
|
-
}
|
|
12617
|
-
const markupTexts = this.getMarkupTexts();
|
|
12618
|
-
if (markupTexts && markupTexts.length > 0) {
|
|
12619
|
-
markupTexts === null || markupTexts === void 0 ? void 0 : markupTexts.forEach((text) => {
|
|
12620
|
-
viewpoint.texts.push(text);
|
|
12621
|
-
});
|
|
12622
|
-
}
|
|
12623
|
-
const markupRectangles = this.getMarkupRectangles();
|
|
12624
|
-
if (markupRectangles && markupRectangles.length > 0) {
|
|
12625
|
-
markupRectangles === null || markupRectangles === void 0 ? void 0 : markupRectangles.forEach((rectangle) => {
|
|
12626
|
-
viewpoint.rectangles.push(rectangle);
|
|
12627
|
-
});
|
|
12628
|
-
}
|
|
12629
|
-
const markupEllipses = this.getMarkupEllipses();
|
|
12630
|
-
if (markupEllipses && markupEllipses.length > 0) {
|
|
12631
|
-
markupEllipses === null || markupEllipses === void 0 ? void 0 : markupEllipses.forEach((ellipse) => {
|
|
12632
|
-
viewpoint.ellipses.push(ellipse);
|
|
12633
|
-
});
|
|
12634
|
-
}
|
|
12635
|
-
const markupArrows = this.getMarkupArrows();
|
|
12636
|
-
if (markupArrows && markupArrows.length > 0) {
|
|
12637
|
-
markupArrows === null || markupArrows === void 0 ? void 0 : markupArrows.forEach((arrow) => {
|
|
12638
|
-
viewpoint.arrows.push(arrow);
|
|
12639
|
-
});
|
|
12640
|
-
}
|
|
12641
|
-
const markupImages = this.getMarkupImages();
|
|
12642
|
-
if (markupImages && markupImages.length > 0) {
|
|
12643
|
-
markupImages === null || markupImages === void 0 ? void 0 : markupImages.forEach((image) => {
|
|
12644
|
-
viewpoint.images.push(image);
|
|
12645
|
-
});
|
|
12646
|
-
}
|
|
12647
|
-
const markupClouds = this.getMarkupClouds();
|
|
12648
|
-
if (markupClouds && markupClouds.length > 0) {
|
|
12649
|
-
markupClouds === null || markupClouds === void 0 ? void 0 : markupClouds.forEach((cloud) => {
|
|
12650
|
-
viewpoint.clouds.push(cloud);
|
|
12651
|
-
});
|
|
12652
|
-
}
|
|
12630
|
+
if (this._konvaTransformer)
|
|
12631
|
+
this._konvaTransformer.nodes([]);
|
|
12653
12632
|
}
|
|
12654
12633
|
addObject(object) {
|
|
12655
|
-
this._konvaLayer
|
|
12634
|
+
if (this._konvaLayer)
|
|
12635
|
+
this._konvaLayer.add(object.ref());
|
|
12656
12636
|
}
|
|
12657
12637
|
konvaLayerFind(type) {
|
|
12638
|
+
if (!this._konvaLayer)
|
|
12639
|
+
return [];
|
|
12658
12640
|
const konvaShape = MarkupMode2Konva[type];
|
|
12659
|
-
if (konvaShape
|
|
12660
|
-
|
|
12661
|
-
|
|
12662
|
-
|
|
12663
|
-
return [];
|
|
12641
|
+
if (!konvaShape || !konvaShape.initializer)
|
|
12642
|
+
return [];
|
|
12643
|
+
// for "draggable" Konva uses Rectangles in Transformer. We need only Shapes from layer.
|
|
12644
|
+
return this._konvaLayer.find(konvaShape.name).filter((ref) => ref.parent === this._konvaLayer);
|
|
12664
12645
|
}
|
|
12665
12646
|
initializeKonva() {
|
|
12666
12647
|
// first we need Konva core things: stage and layer
|
|
12667
|
-
|
|
12668
|
-
container: this.
|
|
12648
|
+
const stage = new Konva.Stage({
|
|
12649
|
+
container: this._markupContainer,
|
|
12669
12650
|
width: this._container.clientWidth,
|
|
12670
12651
|
height: this._container.clientHeight,
|
|
12671
12652
|
});
|
|
12672
|
-
|
|
12653
|
+
this._konvaStage = stage;
|
|
12673
12654
|
const layer = new Konva.Layer({ pixelRation: window.devicePixelRatio });
|
|
12674
12655
|
stage.add(layer);
|
|
12675
12656
|
this._konvaLayer = layer;
|
|
@@ -12678,8 +12659,8 @@
|
|
|
12678
12659
|
keepRatio: false,
|
|
12679
12660
|
flipEnabled: false,
|
|
12680
12661
|
});
|
|
12681
|
-
this._konvaTransformer = transformer;
|
|
12682
12662
|
layer.add(transformer);
|
|
12663
|
+
this._konvaTransformer = transformer;
|
|
12683
12664
|
let isPaint = false;
|
|
12684
12665
|
let lastLine;
|
|
12685
12666
|
let mouseDownPos;
|
|
@@ -12865,32 +12846,29 @@
|
|
|
12865
12846
|
if (!this._markupIsActive)
|
|
12866
12847
|
return;
|
|
12867
12848
|
if (e.code === "Delete") {
|
|
12868
|
-
|
|
12869
|
-
|
|
12870
|
-
this._konvaTransformer.nodes().forEach((x) => x.destroy());
|
|
12871
|
-
this._konvaTransformer.nodes([]);
|
|
12872
|
-
}
|
|
12873
|
-
layer.draw();
|
|
12849
|
+
this.getSelectedObjects().forEach((obj) => obj.delete());
|
|
12850
|
+
this.clearSelected();
|
|
12874
12851
|
return;
|
|
12875
12852
|
}
|
|
12876
12853
|
e.preventDefault();
|
|
12877
12854
|
});
|
|
12878
12855
|
}
|
|
12879
12856
|
destroyKonva() {
|
|
12857
|
+
var _a;
|
|
12880
12858
|
this.clearOverlay();
|
|
12881
|
-
this._konvaStage.destroy();
|
|
12859
|
+
(_a = this._konvaStage) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
12882
12860
|
this._konvaLayer = undefined;
|
|
12883
12861
|
this._konvaTransformer = undefined;
|
|
12884
12862
|
this._konvaStage = undefined;
|
|
12885
12863
|
}
|
|
12886
12864
|
getMarkupLines() {
|
|
12887
12865
|
const lines = [];
|
|
12888
|
-
this.konvaLayerFind("Line").forEach((
|
|
12889
|
-
const linePoints =
|
|
12866
|
+
this.konvaLayerFind("Line").forEach((ref) => {
|
|
12867
|
+
const linePoints = ref.points();
|
|
12890
12868
|
if (!linePoints)
|
|
12891
12869
|
return;
|
|
12892
12870
|
const worldPoints = [];
|
|
12893
|
-
const absoluteTransform =
|
|
12871
|
+
const absoluteTransform = ref.getAbsoluteTransform();
|
|
12894
12872
|
for (let i = 0; i < linePoints.length; i += 2) {
|
|
12895
12873
|
// we need getAbsoluteTransform because inside Konva position starts from {0, 0}
|
|
12896
12874
|
// https://stackoverflow.com/a/57641487 - check answer's comments
|
|
@@ -12898,28 +12876,27 @@
|
|
|
12898
12876
|
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
12899
12877
|
worldPoints.push(worldPoint);
|
|
12900
12878
|
}
|
|
12901
|
-
const konvaLine = new KonvaLine(null,
|
|
12902
|
-
|
|
12879
|
+
const konvaLine = new KonvaLine(null, ref);
|
|
12880
|
+
const line = {
|
|
12903
12881
|
id: konvaLine.id(),
|
|
12904
12882
|
points: worldPoints,
|
|
12905
12883
|
color: konvaLine.getColor() || "#ff0000",
|
|
12906
12884
|
type: konvaLine.getLineType() || this.lineType,
|
|
12907
12885
|
width: konvaLine.getLineWidth() || this.lineWidth,
|
|
12908
|
-
}
|
|
12886
|
+
};
|
|
12887
|
+
lines.push(line);
|
|
12909
12888
|
});
|
|
12910
12889
|
return lines;
|
|
12911
12890
|
}
|
|
12912
12891
|
getMarkupTexts() {
|
|
12913
12892
|
const texts = [];
|
|
12914
|
-
|
|
12915
|
-
|
|
12916
|
-
|
|
12917
|
-
|
|
12918
|
-
return;
|
|
12919
|
-
const position = { x: text.x(), y: text.y() };
|
|
12893
|
+
this.konvaLayerFind("Text").forEach((ref) => {
|
|
12894
|
+
const textSize = 0.02;
|
|
12895
|
+
const textScale = this._worldTransformer.getScale();
|
|
12896
|
+
const position = { x: ref.x(), y: ref.y() };
|
|
12920
12897
|
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
12921
|
-
const shape = new KonvaText(null,
|
|
12922
|
-
|
|
12898
|
+
const shape = new KonvaText(null, ref);
|
|
12899
|
+
const text = {
|
|
12923
12900
|
id: shape.id(),
|
|
12924
12901
|
position: worldPoint,
|
|
12925
12902
|
text: shape.getText(),
|
|
@@ -12927,141 +12904,112 @@
|
|
|
12927
12904
|
angle: shape.getRotation(),
|
|
12928
12905
|
color: shape.getColor(),
|
|
12929
12906
|
font_size: shape.getFontSize(),
|
|
12930
|
-
}
|
|
12907
|
+
};
|
|
12908
|
+
texts.push(text);
|
|
12931
12909
|
});
|
|
12932
12910
|
return texts;
|
|
12933
12911
|
}
|
|
12934
12912
|
getMarkupRectangles() {
|
|
12935
12913
|
const rectangles = [];
|
|
12936
|
-
this.konvaLayerFind("Rectangle").forEach((
|
|
12937
|
-
const position =
|
|
12914
|
+
this.konvaLayerFind("Rectangle").forEach((ref) => {
|
|
12915
|
+
const position = ref.position();
|
|
12938
12916
|
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
12939
|
-
const shape = new KonvaRectangle(null,
|
|
12940
|
-
|
|
12917
|
+
const shape = new KonvaRectangle(null, ref);
|
|
12918
|
+
const rectangle = {
|
|
12941
12919
|
id: shape.id(),
|
|
12942
12920
|
position: worldPoint,
|
|
12943
12921
|
width: shape.getWidth(),
|
|
12944
12922
|
height: shape.getHeigth(),
|
|
12945
12923
|
line_width: shape.getLineWidth(),
|
|
12946
12924
|
color: shape.getColor(),
|
|
12947
|
-
}
|
|
12925
|
+
};
|
|
12926
|
+
rectangles.push(rectangle);
|
|
12948
12927
|
});
|
|
12949
12928
|
return rectangles;
|
|
12950
12929
|
}
|
|
12951
12930
|
getMarkupEllipses() {
|
|
12952
12931
|
const ellipses = [];
|
|
12953
|
-
this.konvaLayerFind("Ellipse").forEach((
|
|
12954
|
-
const position =
|
|
12932
|
+
this.konvaLayerFind("Ellipse").forEach((ref) => {
|
|
12933
|
+
const position = ref.position();
|
|
12955
12934
|
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
12956
|
-
const shape = new KonvaEllipse(null,
|
|
12957
|
-
|
|
12935
|
+
const shape = new KonvaEllipse(null, ref);
|
|
12936
|
+
const ellipse = {
|
|
12958
12937
|
id: shape.id(),
|
|
12959
12938
|
position: worldPoint,
|
|
12960
|
-
radius: { x:
|
|
12939
|
+
radius: { x: ref.getRadiusX(), y: ref.getRadiusY() },
|
|
12961
12940
|
line_width: shape.getLineWidth(),
|
|
12962
12941
|
color: shape.getColor(),
|
|
12963
|
-
}
|
|
12942
|
+
};
|
|
12943
|
+
ellipses.push(ellipse);
|
|
12964
12944
|
});
|
|
12965
12945
|
return ellipses;
|
|
12966
12946
|
}
|
|
12967
12947
|
getMarkupArrows() {
|
|
12968
12948
|
const arrows = [];
|
|
12969
|
-
this.konvaLayerFind("Arrow").forEach((
|
|
12949
|
+
this.konvaLayerFind("Arrow").forEach((ref) => {
|
|
12970
12950
|
// we need getAbsoluteTransform because inside Konva position starts from {0, 0}
|
|
12971
|
-
const absoluteTransform =
|
|
12972
|
-
const atStartPoint = absoluteTransform.point({ x:
|
|
12951
|
+
const absoluteTransform = ref.getAbsoluteTransform();
|
|
12952
|
+
const atStartPoint = absoluteTransform.point({ x: ref.points()[0], y: ref.points()[1] });
|
|
12973
12953
|
const worldStartPoint = this._worldTransformer.screenToWorld(atStartPoint);
|
|
12974
|
-
const atEndPoint = absoluteTransform.point({ x:
|
|
12954
|
+
const atEndPoint = absoluteTransform.point({ x: ref.points()[2], y: ref.points()[3] });
|
|
12975
12955
|
const worldEndPoint = this._worldTransformer.screenToWorld(atEndPoint);
|
|
12976
|
-
const shape = new KonvaArrow(null,
|
|
12977
|
-
|
|
12956
|
+
const shape = new KonvaArrow(null, ref);
|
|
12957
|
+
const arrow = {
|
|
12978
12958
|
id: shape.id(),
|
|
12979
12959
|
start: worldStartPoint,
|
|
12980
12960
|
end: worldEndPoint,
|
|
12981
12961
|
color: shape.getColor(),
|
|
12982
|
-
}
|
|
12962
|
+
};
|
|
12963
|
+
arrows.push(arrow);
|
|
12983
12964
|
});
|
|
12984
12965
|
return arrows;
|
|
12985
12966
|
}
|
|
12986
12967
|
getMarkupImages() {
|
|
12987
12968
|
const images = [];
|
|
12988
|
-
this.konvaLayerFind("Image").forEach((
|
|
12989
|
-
const position =
|
|
12969
|
+
this.konvaLayerFind("Image").forEach((ref) => {
|
|
12970
|
+
const position = ref.position();
|
|
12990
12971
|
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
12991
|
-
const shape = new KonvaImage(null,
|
|
12992
|
-
|
|
12972
|
+
const shape = new KonvaImage(null, ref);
|
|
12973
|
+
const image = {
|
|
12993
12974
|
id: shape.id(),
|
|
12994
12975
|
position: worldPoint,
|
|
12995
12976
|
src: shape.getSrc(),
|
|
12996
12977
|
width: shape.getWidth(),
|
|
12997
12978
|
height: shape.getHeight(),
|
|
12998
|
-
}
|
|
12979
|
+
};
|
|
12980
|
+
images.push(image);
|
|
12999
12981
|
});
|
|
13000
12982
|
return images;
|
|
13001
12983
|
}
|
|
13002
12984
|
getMarkupClouds() {
|
|
13003
12985
|
const clouds = [];
|
|
13004
|
-
this.konvaLayerFind("Cloud").forEach((
|
|
13005
|
-
const position =
|
|
12986
|
+
this.konvaLayerFind("Cloud").forEach((ref) => {
|
|
12987
|
+
const position = ref.position();
|
|
13006
12988
|
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
13007
|
-
const shape = new KonvaCloud(null,
|
|
13008
|
-
|
|
12989
|
+
const shape = new KonvaCloud(null, ref);
|
|
12990
|
+
const cloud = {
|
|
13009
12991
|
id: shape.id(),
|
|
13010
12992
|
position: worldPoint,
|
|
13011
12993
|
width: shape.getWidth(),
|
|
13012
12994
|
height: shape.getHeigth(),
|
|
13013
12995
|
line_width: shape.getLineWidth(),
|
|
13014
12996
|
color: shape.getColor(),
|
|
13015
|
-
}
|
|
12997
|
+
};
|
|
12998
|
+
clouds.push(cloud);
|
|
13016
12999
|
});
|
|
13017
13000
|
return clouds;
|
|
13018
13001
|
}
|
|
13019
|
-
loadMarkup(viewpoint) {
|
|
13020
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
13021
|
-
(_a = viewpoint.lines) === null || _a === void 0 ? void 0 : _a.forEach((vpLine) => {
|
|
13022
|
-
const linePoints = [];
|
|
13023
|
-
vpLine.points.forEach((point) => {
|
|
13024
|
-
const screenPoint = this._worldTransformer.worldToScreen(point);
|
|
13025
|
-
linePoints.push(screenPoint.x);
|
|
13026
|
-
linePoints.push(screenPoint.y);
|
|
13027
|
-
});
|
|
13028
|
-
this.addLine(linePoints, vpLine.color, vpLine.type, vpLine.width, vpLine.id);
|
|
13029
|
-
});
|
|
13030
|
-
(_b = viewpoint.texts) === null || _b === void 0 ? void 0 : _b.forEach((vpText) => {
|
|
13031
|
-
const screenPoint = this._worldTransformer.worldToScreen(vpText.position);
|
|
13032
|
-
this.addText(vpText.text, screenPoint, vpText.angle, vpText.color, vpText.text_size, vpText.font_size, vpText.id);
|
|
13033
|
-
});
|
|
13034
|
-
(_c = viewpoint.rectangles) === null || _c === void 0 ? void 0 : _c.forEach((vpRect) => {
|
|
13035
|
-
const screenPoint = this._worldTransformer.worldToScreen(vpRect.position);
|
|
13036
|
-
this.addRectangle(screenPoint, vpRect.width, vpRect.height, vpRect.line_width, vpRect.color, vpRect.id);
|
|
13037
|
-
});
|
|
13038
|
-
(_d = viewpoint.ellipses) === null || _d === void 0 ? void 0 : _d.forEach((vpEllipse) => {
|
|
13039
|
-
const screenPoint = this._worldTransformer.worldToScreen(vpEllipse.position);
|
|
13040
|
-
this.addEllipse(screenPoint, vpEllipse.radius, vpEllipse.line_width, vpEllipse.color, vpEllipse.id);
|
|
13041
|
-
});
|
|
13042
|
-
(_e = viewpoint.arrows) === null || _e === void 0 ? void 0 : _e.forEach((vpArrow) => {
|
|
13043
|
-
const startPoint = this._worldTransformer.worldToScreen(vpArrow.start);
|
|
13044
|
-
const endPoint = this._worldTransformer.worldToScreen(vpArrow.end);
|
|
13045
|
-
this.addArrow(startPoint, endPoint, vpArrow.color, vpArrow.id);
|
|
13046
|
-
});
|
|
13047
|
-
(_f = viewpoint.clouds) === null || _f === void 0 ? void 0 : _f.forEach((vpCloud) => {
|
|
13048
|
-
const screenPoint = this._worldTransformer.worldToScreen(vpCloud.position);
|
|
13049
|
-
this.addCloud(screenPoint, vpCloud.width, vpCloud.height, vpCloud.line_width, vpCloud.color, vpCloud.id);
|
|
13050
|
-
});
|
|
13051
|
-
(_g = viewpoint.images) === null || _g === void 0 ? void 0 : _g.forEach((vpImage) => {
|
|
13052
|
-
const screenPoint = this._worldTransformer.worldToScreen(vpImage.position);
|
|
13053
|
-
this.addImage(screenPoint, vpImage.src, vpImage.width, vpImage.height, vpImage.id);
|
|
13054
|
-
});
|
|
13055
|
-
}
|
|
13056
13002
|
combineMarkupWithDrawing() {
|
|
13057
13003
|
this.clearSelected();
|
|
13058
13004
|
const tempCanvas = document.createElement("canvas");
|
|
13059
|
-
|
|
13060
|
-
|
|
13061
|
-
|
|
13062
|
-
|
|
13063
|
-
|
|
13064
|
-
|
|
13005
|
+
if (this._konvaStage) {
|
|
13006
|
+
tempCanvas.width = this._konvaStage.width();
|
|
13007
|
+
tempCanvas.height = this._konvaStage.height();
|
|
13008
|
+
const ctx = tempCanvas.getContext("2d");
|
|
13009
|
+
if (this._container instanceof HTMLCanvasElement)
|
|
13010
|
+
ctx.drawImage(this._container, 0, 0);
|
|
13011
|
+
ctx.drawImage(this._konvaStage.toCanvas({ pixelRatio: window.devicePixelRatio }), 0, 0);
|
|
13012
|
+
}
|
|
13065
13013
|
return tempCanvas.toDataURL("image/jpeg", 0.25);
|
|
13066
13014
|
}
|
|
13067
13015
|
addLine(linePoints, color, type, width, id) {
|
|
@@ -13078,8 +13026,7 @@
|
|
|
13078
13026
|
color: color || this._markupColor.HexColor,
|
|
13079
13027
|
id,
|
|
13080
13028
|
});
|
|
13081
|
-
|
|
13082
|
-
this._konvaLayer.add(obj);
|
|
13029
|
+
this.addObject(konvaLine);
|
|
13083
13030
|
return konvaLine;
|
|
13084
13031
|
}
|
|
13085
13032
|
createTextInput(pos, inputX, inputY, angle, text) {
|
|
@@ -13162,33 +13109,31 @@
|
|
|
13162
13109
|
this._imageInputRef = null;
|
|
13163
13110
|
this._imageInputPos = null;
|
|
13164
13111
|
}
|
|
13165
|
-
addText(
|
|
13166
|
-
|
|
13167
|
-
if (
|
|
13168
|
-
|
|
13169
|
-
|
|
13170
|
-
|
|
13171
|
-
|
|
13112
|
+
addText(text, position, angle, color, textSize, fontSize, id) {
|
|
13113
|
+
var _a;
|
|
13114
|
+
if (!text)
|
|
13115
|
+
return;
|
|
13116
|
+
// in case of edit - remove old Konva.Text object
|
|
13117
|
+
(_a = this.getSelectedObjects().at(0)) === null || _a === void 0 ? void 0 : _a.delete();
|
|
13118
|
+
this.clearSelected();
|
|
13172
13119
|
this.removeTextInput();
|
|
13173
|
-
|
|
13174
|
-
|
|
13175
|
-
|
|
13176
|
-
|
|
13177
|
-
|
|
13178
|
-
|
|
13179
|
-
|
|
13180
|
-
|
|
13181
|
-
|
|
13182
|
-
|
|
13183
|
-
|
|
13184
|
-
|
|
13185
|
-
|
|
13186
|
-
|
|
13187
|
-
|
|
13188
|
-
|
|
13189
|
-
|
|
13190
|
-
return konvaText;
|
|
13191
|
-
}
|
|
13120
|
+
// in case we have old viewpoint without font_size
|
|
13121
|
+
const tolerance = 1.0e-6;
|
|
13122
|
+
if (textSize && textSize > tolerance && (!fontSize || fontSize < tolerance)) {
|
|
13123
|
+
const size = 0.02;
|
|
13124
|
+
const scale = this._worldTransformer.getScale();
|
|
13125
|
+
fontSize = textSize / (scale.y / size) / 34;
|
|
13126
|
+
}
|
|
13127
|
+
const konvaText = new KonvaText({
|
|
13128
|
+
position: { x: position.x, y: position.y },
|
|
13129
|
+
text,
|
|
13130
|
+
rotation: angle,
|
|
13131
|
+
fontSize: fontSize || this.fontSize,
|
|
13132
|
+
color: color || this._markupColor.HexColor,
|
|
13133
|
+
id,
|
|
13134
|
+
});
|
|
13135
|
+
this.addObject(konvaText);
|
|
13136
|
+
return konvaText;
|
|
13192
13137
|
}
|
|
13193
13138
|
addRectangle(position, width, height, lineWidth, color, id) {
|
|
13194
13139
|
if (!position)
|
|
@@ -13201,8 +13146,7 @@
|
|
|
13201
13146
|
color: color || this._markupColor.HexColor,
|
|
13202
13147
|
id,
|
|
13203
13148
|
});
|
|
13204
|
-
|
|
13205
|
-
this._konvaLayer.add(obj);
|
|
13149
|
+
this.addObject(konvaRectangle);
|
|
13206
13150
|
return konvaRectangle;
|
|
13207
13151
|
}
|
|
13208
13152
|
addEllipse(position, radius, lineWidth, color, id) {
|
|
@@ -13215,8 +13159,7 @@
|
|
|
13215
13159
|
color: color || this._markupColor.HexColor,
|
|
13216
13160
|
id,
|
|
13217
13161
|
});
|
|
13218
|
-
|
|
13219
|
-
this._konvaLayer.add(obj);
|
|
13162
|
+
this.addObject(konvaEllipse);
|
|
13220
13163
|
return konvaEllipse;
|
|
13221
13164
|
}
|
|
13222
13165
|
addArrow(start, end, color, id) {
|
|
@@ -13228,8 +13171,7 @@
|
|
|
13228
13171
|
color: color || this._markupColor.HexColor,
|
|
13229
13172
|
id,
|
|
13230
13173
|
});
|
|
13231
|
-
|
|
13232
|
-
this._konvaLayer.add(obj);
|
|
13174
|
+
this.addObject(konvaArrow);
|
|
13233
13175
|
return konvaArrow;
|
|
13234
13176
|
}
|
|
13235
13177
|
addCloud(position, width, height, lineWidth, color, id) {
|
|
@@ -13243,32 +13185,25 @@
|
|
|
13243
13185
|
lineWidth: lineWidth || this.lineWidth,
|
|
13244
13186
|
id,
|
|
13245
13187
|
});
|
|
13246
|
-
|
|
13247
|
-
this._konvaLayer.add(obj);
|
|
13188
|
+
this.addObject(konvaCloud);
|
|
13248
13189
|
return konvaCloud;
|
|
13249
13190
|
}
|
|
13250
13191
|
addImage(position, src, width, height, id) {
|
|
13251
|
-
|
|
13192
|
+
var _a;
|
|
13193
|
+
if (!position || !src)
|
|
13252
13194
|
return;
|
|
13253
|
-
|
|
13254
|
-
|
|
13255
|
-
|
|
13256
|
-
position,
|
|
13257
|
-
src,
|
|
13258
|
-
width,
|
|
13259
|
-
height,
|
|
13260
|
-
id,
|
|
13261
|
-
});
|
|
13262
|
-
const obj = konvaImage.ref();
|
|
13263
|
-
this._konvaLayer.add(obj);
|
|
13264
|
-
const trNodes = this._konvaTransformer.nodes();
|
|
13265
|
-
if (trNodes.length > 0) {
|
|
13266
|
-
// in case of edit - remove old Image placeholder object
|
|
13267
|
-
trNodes[0].destroy();
|
|
13268
|
-
this._konvaTransformer.nodes([]);
|
|
13269
|
-
}
|
|
13270
|
-
}
|
|
13195
|
+
// in case of edit - remove old Image placeholder object
|
|
13196
|
+
(_a = this.getSelectedObjects().at(0)) === null || _a === void 0 ? void 0 : _a.delete();
|
|
13197
|
+
this.clearSelected();
|
|
13271
13198
|
this.removeImageInput();
|
|
13199
|
+
const konvaImage = new KonvaImage({
|
|
13200
|
+
position,
|
|
13201
|
+
src,
|
|
13202
|
+
width,
|
|
13203
|
+
height,
|
|
13204
|
+
id,
|
|
13205
|
+
});
|
|
13206
|
+
this.addObject(konvaImage);
|
|
13272
13207
|
return konvaImage;
|
|
13273
13208
|
}
|
|
13274
13209
|
}
|