@inweb/markup 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.
- package/dist/markup.js +25 -23
- package/dist/markup.js.map +1 -1
- package/dist/markup.min.js +1 -1
- package/dist/markup.module.js +23 -23
- package/dist/markup.module.js.map +1 -1
- package/lib/markup/IMarkup.d.ts +15 -14
- package/lib/markup/Konva/KonvaMarkup.d.ts +5 -4
- package/package.json +3 -3
- package/src/markup/IMarkup.ts +14 -13
- package/src/markup/Konva/KonvaMarkup.ts +33 -27
package/dist/markup.module.js
CHANGED
|
@@ -906,7 +906,7 @@ class KonvaMarkup {
|
|
|
906
906
|
this.fontSize = 34;
|
|
907
907
|
this.changeActiveDragger = event => {
|
|
908
908
|
const draggerName = event.data;
|
|
909
|
-
this._markupContainer.className = this.
|
|
909
|
+
this._markupContainer.className = this._container.className.split(" ").filter((x => !x.startsWith("oda-cursor-"))).filter((x => x)).concat(`oda-cursor-${draggerName.toLowerCase()}`).join(" ");
|
|
910
910
|
this.removeTextInput();
|
|
911
911
|
this.removeImageInput();
|
|
912
912
|
const konvaShape = MarkupMode2Konva[draggerName];
|
|
@@ -918,10 +918,12 @@ class KonvaMarkup {
|
|
|
918
918
|
this._konvaTransformer.nodes([]);
|
|
919
919
|
}
|
|
920
920
|
};
|
|
921
|
-
this.
|
|
921
|
+
this.resizeContainer = entries => {
|
|
922
922
|
var _a, _b;
|
|
923
|
-
|
|
924
|
-
(
|
|
923
|
+
const {width: width, height: height} = entries[0].contentRect;
|
|
924
|
+
if (!width || !height) return;
|
|
925
|
+
(_a = this._konvaStage) === null || _a === void 0 ? void 0 : _a.width(width);
|
|
926
|
+
(_b = this._konvaStage) === null || _b === void 0 ? void 0 : _b.height(height);
|
|
925
927
|
};
|
|
926
928
|
this.pan = event => {
|
|
927
929
|
const dX = event.dX / window.devicePixelRatio;
|
|
@@ -935,26 +937,26 @@ class KonvaMarkup {
|
|
|
935
937
|
if (this._viewer) this._viewer.emit(event);
|
|
936
938
|
};
|
|
937
939
|
}
|
|
938
|
-
initialize(
|
|
940
|
+
initialize(container, pointerEvents, viewer, worldTransformer) {
|
|
939
941
|
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>');
|
|
940
942
|
this._viewer = viewer;
|
|
941
943
|
this._worldTransformer = worldTransformer;
|
|
942
|
-
this.
|
|
943
|
-
this.
|
|
944
|
+
this._container = container;
|
|
945
|
+
this._pointerEvents = pointerEvents !== null && pointerEvents !== void 0 ? pointerEvents : [];
|
|
944
946
|
this._markupContainer = document.createElement("div");
|
|
945
947
|
this._markupContainer.id = this._markupContainerName;
|
|
946
948
|
this._markupContainer.style.position = "absolute";
|
|
947
949
|
this._markupContainer.style.top = "0px";
|
|
948
950
|
this._markupContainer.style.left = "0px";
|
|
949
951
|
this._markupContainer.style.outline = "0px";
|
|
950
|
-
const parentDiv = this.
|
|
952
|
+
const parentDiv = this._container.parentElement;
|
|
951
953
|
parentDiv.appendChild(this._markupContainer);
|
|
954
|
+
this._resizeObserver = new ResizeObserver(this.resizeContainer);
|
|
955
|
+
this._resizeObserver.observe(parentDiv);
|
|
952
956
|
this._markupColor.setColor(255, 0, 0);
|
|
953
957
|
this.initializeKonva();
|
|
954
|
-
this.resize();
|
|
955
|
-
this._canvasEvents.forEach((x => this._markupContainer.addEventListener(x, this.redirectToViewer)));
|
|
956
958
|
if (this._viewer) {
|
|
957
|
-
this.
|
|
959
|
+
this._pointerEvents.forEach((x => this._markupContainer.addEventListener(x, this.redirectToViewer)));
|
|
958
960
|
this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
|
|
959
961
|
this._viewer.addEventListener("pan", this.pan);
|
|
960
962
|
}
|
|
@@ -965,13 +967,14 @@ class KonvaMarkup {
|
|
|
965
967
|
if (this._viewer) {
|
|
966
968
|
this._viewer.removeEventListener("pan", this.pan);
|
|
967
969
|
this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
|
|
968
|
-
this._viewer.removeEventListener("resize", this.resize);
|
|
969
970
|
}
|
|
970
|
-
this.
|
|
971
|
+
this._pointerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
|
|
971
972
|
this.destroyKonva();
|
|
973
|
+
this._resizeObserver.disconnect();
|
|
974
|
+
this._resizeObserver = undefined;
|
|
972
975
|
this._markupContainer.remove();
|
|
973
976
|
this._markupContainer = undefined;
|
|
974
|
-
this.
|
|
977
|
+
this._container = undefined;
|
|
975
978
|
this._viewer = undefined;
|
|
976
979
|
this._worldTransformer = undefined;
|
|
977
980
|
this._markupIsActive = false;
|
|
@@ -1215,8 +1218,8 @@ class KonvaMarkup {
|
|
|
1215
1218
|
initializeKonva() {
|
|
1216
1219
|
this._konvaStage = new Konva.Stage({
|
|
1217
1220
|
container: this._markupContainerName,
|
|
1218
|
-
width: this.
|
|
1219
|
-
height: this.
|
|
1221
|
+
width: this._container.clientWidth,
|
|
1222
|
+
height: this._container.clientHeight
|
|
1220
1223
|
});
|
|
1221
1224
|
const stage = this._konvaStage;
|
|
1222
1225
|
const layer = new Konva.Layer({
|
|
@@ -1610,15 +1613,12 @@ class KonvaMarkup {
|
|
|
1610
1613
|
}));
|
|
1611
1614
|
}
|
|
1612
1615
|
combineMarkupWithDrawing() {
|
|
1613
|
-
|
|
1614
|
-
if (trNodes.length > 0) {
|
|
1615
|
-
this._konvaTransformer.nodes([]);
|
|
1616
|
-
}
|
|
1616
|
+
this.clearSelected();
|
|
1617
1617
|
const tempCanvas = document.createElement("canvas");
|
|
1618
|
-
tempCanvas.
|
|
1619
|
-
tempCanvas.
|
|
1618
|
+
tempCanvas.width = this._konvaStage.width();
|
|
1619
|
+
tempCanvas.height = this._konvaStage.height();
|
|
1620
1620
|
const ctx = tempCanvas.getContext("2d");
|
|
1621
|
-
ctx.drawImage(this.
|
|
1621
|
+
if (this._container instanceof HTMLCanvasElement) ctx.drawImage(this._container, 0, 0);
|
|
1622
1622
|
ctx.drawImage(this._konvaStage.toCanvas({
|
|
1623
1623
|
pixelRatio: window.devicePixelRatio
|
|
1624
1624
|
}), 0, 0);
|