@inweb/viewer-visualize 25.7.6 → 25.7.8
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.
|
@@ -1611,7 +1611,7 @@ class KonvaMarkup {
|
|
|
1611
1611
|
this.fontSize = 34;
|
|
1612
1612
|
this.changeActiveDragger = event => {
|
|
1613
1613
|
const draggerName = event.data;
|
|
1614
|
-
this._markupContainer.className = this.
|
|
1614
|
+
this._markupContainer.className = this._container.className.split(" ").filter((x => !x.startsWith("oda-cursor-"))).filter((x => x)).concat(`oda-cursor-${draggerName.toLowerCase()}`).join(" ");
|
|
1615
1615
|
this.removeTextInput();
|
|
1616
1616
|
this.removeImageInput();
|
|
1617
1617
|
const konvaShape = MarkupMode2Konva[draggerName];
|
|
@@ -1623,10 +1623,12 @@ class KonvaMarkup {
|
|
|
1623
1623
|
this._konvaTransformer.nodes([]);
|
|
1624
1624
|
}
|
|
1625
1625
|
};
|
|
1626
|
-
this.
|
|
1626
|
+
this.resizeContainer = entries => {
|
|
1627
1627
|
var _a, _b;
|
|
1628
|
-
|
|
1629
|
-
(
|
|
1628
|
+
const {width: width, height: height} = entries[0].contentRect;
|
|
1629
|
+
if (!width || !height) return;
|
|
1630
|
+
(_a = this._konvaStage) === null || _a === void 0 ? void 0 : _a.width(width);
|
|
1631
|
+
(_b = this._konvaStage) === null || _b === void 0 ? void 0 : _b.height(height);
|
|
1630
1632
|
};
|
|
1631
1633
|
this.pan = event => {
|
|
1632
1634
|
const dX = event.dX / window.devicePixelRatio;
|
|
@@ -1640,26 +1642,26 @@ class KonvaMarkup {
|
|
|
1640
1642
|
if (this._viewer) this._viewer.emit(event);
|
|
1641
1643
|
};
|
|
1642
1644
|
}
|
|
1643
|
-
initialize(
|
|
1645
|
+
initialize(container, pointerEvents, viewer, worldTransformer) {
|
|
1644
1646
|
if (!Konva) throw new Error('Markup: Error during initialization. Konva is not initialized. Update node_modules or add to your page <script src="https://unpkg.com/konva@9/konva.min.js"><\/script>');
|
|
1645
1647
|
this._viewer = viewer;
|
|
1646
1648
|
this._worldTransformer = worldTransformer;
|
|
1647
|
-
this.
|
|
1648
|
-
this.
|
|
1649
|
+
this._container = container;
|
|
1650
|
+
this._pointerEvents = pointerEvents !== null && pointerEvents !== void 0 ? pointerEvents : [];
|
|
1649
1651
|
this._markupContainer = document.createElement("div");
|
|
1650
1652
|
this._markupContainer.id = this._markupContainerName;
|
|
1651
1653
|
this._markupContainer.style.position = "absolute";
|
|
1652
1654
|
this._markupContainer.style.top = "0px";
|
|
1653
1655
|
this._markupContainer.style.left = "0px";
|
|
1654
1656
|
this._markupContainer.style.outline = "0px";
|
|
1655
|
-
const parentDiv = this.
|
|
1657
|
+
const parentDiv = this._container.parentElement;
|
|
1656
1658
|
parentDiv.appendChild(this._markupContainer);
|
|
1659
|
+
this._resizeObserver = new ResizeObserver(this.resizeContainer);
|
|
1660
|
+
this._resizeObserver.observe(parentDiv);
|
|
1657
1661
|
this._markupColor.setColor(255, 0, 0);
|
|
1658
1662
|
this.initializeKonva();
|
|
1659
|
-
this.resize();
|
|
1660
|
-
this._canvasEvents.forEach((x => this._markupContainer.addEventListener(x, this.redirectToViewer)));
|
|
1661
1663
|
if (this._viewer) {
|
|
1662
|
-
this.
|
|
1664
|
+
this._pointerEvents.forEach((x => this._markupContainer.addEventListener(x, this.redirectToViewer)));
|
|
1663
1665
|
this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
|
|
1664
1666
|
this._viewer.addEventListener("pan", this.pan);
|
|
1665
1667
|
}
|
|
@@ -1670,13 +1672,14 @@ class KonvaMarkup {
|
|
|
1670
1672
|
if (this._viewer) {
|
|
1671
1673
|
this._viewer.removeEventListener("pan", this.pan);
|
|
1672
1674
|
this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
|
|
1673
|
-
this._viewer.removeEventListener("resize", this.resize);
|
|
1674
1675
|
}
|
|
1675
|
-
this.
|
|
1676
|
+
this._pointerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
|
|
1676
1677
|
this.destroyKonva();
|
|
1678
|
+
this._resizeObserver.disconnect();
|
|
1679
|
+
this._resizeObserver = undefined;
|
|
1677
1680
|
this._markupContainer.remove();
|
|
1678
1681
|
this._markupContainer = undefined;
|
|
1679
|
-
this.
|
|
1682
|
+
this._container = undefined;
|
|
1680
1683
|
this._viewer = undefined;
|
|
1681
1684
|
this._worldTransformer = undefined;
|
|
1682
1685
|
this._markupIsActive = false;
|
|
@@ -1920,8 +1923,8 @@ class KonvaMarkup {
|
|
|
1920
1923
|
initializeKonva() {
|
|
1921
1924
|
this._konvaStage = new Konva.Stage({
|
|
1922
1925
|
container: this._markupContainerName,
|
|
1923
|
-
width: this.
|
|
1924
|
-
height: this.
|
|
1926
|
+
width: this._container.clientWidth,
|
|
1927
|
+
height: this._container.clientHeight
|
|
1925
1928
|
});
|
|
1926
1929
|
const stage = this._konvaStage;
|
|
1927
1930
|
const layer = new Konva.Layer({
|
|
@@ -2315,15 +2318,12 @@ class KonvaMarkup {
|
|
|
2315
2318
|
}));
|
|
2316
2319
|
}
|
|
2317
2320
|
combineMarkupWithDrawing() {
|
|
2318
|
-
|
|
2319
|
-
if (trNodes.length > 0) {
|
|
2320
|
-
this._konvaTransformer.nodes([]);
|
|
2321
|
-
}
|
|
2321
|
+
this.clearSelected();
|
|
2322
2322
|
const tempCanvas = document.createElement("canvas");
|
|
2323
|
-
tempCanvas.
|
|
2324
|
-
tempCanvas.
|
|
2323
|
+
tempCanvas.width = this._konvaStage.width();
|
|
2324
|
+
tempCanvas.height = this._konvaStage.height();
|
|
2325
2325
|
const ctx = tempCanvas.getContext("2d");
|
|
2326
|
-
ctx.drawImage(this.
|
|
2326
|
+
if (this._container instanceof HTMLCanvasElement) ctx.drawImage(this._container, 0, 0);
|
|
2327
2327
|
ctx.drawImage(this._konvaStage.toCanvas({
|
|
2328
2328
|
pixelRatio: window.devicePixelRatio
|
|
2329
2329
|
}), 0, 0);
|