@inweb/viewer-visualize 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/viewer-visualize.js +63 -60
- package/dist/viewer-visualize.js.map +1 -1
- package/dist/viewer-visualize.min.js +1 -1
- package/dist/viewer-visualize.module.js +63 -60
- package/dist/viewer-visualize.module.js.map +1 -1
- package/lib/Viewer/Viewer.d.ts +1 -0
- package/package.json +5 -5
- package/src/Viewer/Viewer.ts +12 -0
package/dist/viewer-visualize.js
CHANGED
|
@@ -13068,11 +13068,10 @@
|
|
|
13068
13068
|
|
|
13069
13069
|
class KonvaMarkup {
|
|
13070
13070
|
constructor() {
|
|
13071
|
-
this.
|
|
13071
|
+
this._pointerEvents = [];
|
|
13072
13072
|
this._markupIsActive = false;
|
|
13073
13073
|
this._markupColor = new MarkupColor(255, 0, 0);
|
|
13074
13074
|
this._zIndex = 1;
|
|
13075
|
-
this._markupContainerName = "markupContainer";
|
|
13076
13075
|
this.lineWidth = 4;
|
|
13077
13076
|
this.lineType = "solid";
|
|
13078
13077
|
this.fontSize = 34;
|
|
@@ -13084,11 +13083,11 @@
|
|
|
13084
13083
|
this.enableEditMode(draggerName);
|
|
13085
13084
|
};
|
|
13086
13085
|
this.resizeContainer = entries => {
|
|
13087
|
-
var _a, _b;
|
|
13088
13086
|
const {width: width, height: height} = entries[0].contentRect;
|
|
13089
13087
|
if (!width || !height) return;
|
|
13090
|
-
(
|
|
13091
|
-
|
|
13088
|
+
if (!this._konvaStage) return;
|
|
13089
|
+
this._konvaStage.width(width);
|
|
13090
|
+
this._konvaStage.height(height);
|
|
13092
13091
|
};
|
|
13093
13092
|
this.pan = event => {
|
|
13094
13093
|
const dX = event.dX / window.devicePixelRatio;
|
|
@@ -13103,13 +13102,16 @@
|
|
|
13103
13102
|
};
|
|
13104
13103
|
}
|
|
13105
13104
|
initialize(container, pointerEvents, viewer, worldTransformer) {
|
|
13106
|
-
if (!Konva)
|
|
13105
|
+
if (!Konva) {
|
|
13106
|
+
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>');
|
|
13107
|
+
return;
|
|
13108
|
+
}
|
|
13107
13109
|
this._viewer = viewer;
|
|
13108
13110
|
this._worldTransformer = worldTransformer !== null && worldTransformer !== void 0 ? worldTransformer : new WorldTransform;
|
|
13109
13111
|
this._container = container;
|
|
13110
13112
|
this._pointerEvents = pointerEvents !== null && pointerEvents !== void 0 ? pointerEvents : [];
|
|
13111
13113
|
this._markupContainer = document.createElement("div");
|
|
13112
|
-
this._markupContainer.id =
|
|
13114
|
+
this._markupContainer.id = "markup-container";
|
|
13113
13115
|
this._markupContainer.style.position = "absolute";
|
|
13114
13116
|
this._markupContainer.style.top = "0px";
|
|
13115
13117
|
this._markupContainer.style.left = "0px";
|
|
@@ -13125,32 +13127,30 @@
|
|
|
13125
13127
|
this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
|
|
13126
13128
|
this._viewer.addEventListener("pan", this.pan);
|
|
13127
13129
|
}
|
|
13128
|
-
this._isInitialized = true;
|
|
13129
13130
|
}
|
|
13130
13131
|
dispose() {
|
|
13131
|
-
|
|
13132
|
+
var _a, _b;
|
|
13132
13133
|
if (this._viewer) {
|
|
13133
13134
|
this._viewer.removeEventListener("pan", this.pan);
|
|
13134
13135
|
this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
|
|
13136
|
+
this._pointerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
|
|
13135
13137
|
}
|
|
13136
|
-
this._pointerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
|
|
13137
13138
|
this.destroyKonva();
|
|
13138
|
-
this._resizeObserver.disconnect();
|
|
13139
|
+
(_a = this._resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
13139
13140
|
this._resizeObserver = undefined;
|
|
13140
|
-
this._markupContainer.remove();
|
|
13141
|
+
(_b = this._markupContainer) === null || _b === void 0 ? void 0 : _b.remove();
|
|
13141
13142
|
this._markupContainer = undefined;
|
|
13142
13143
|
this._container = undefined;
|
|
13143
13144
|
this._viewer = undefined;
|
|
13144
13145
|
this._worldTransformer = undefined;
|
|
13145
13146
|
this._markupIsActive = false;
|
|
13146
|
-
this._isInitialized = false;
|
|
13147
13147
|
}
|
|
13148
13148
|
syncOverlay() {}
|
|
13149
13149
|
clearOverlay() {
|
|
13150
13150
|
this.removeTextInput();
|
|
13151
13151
|
this.removeImageInput();
|
|
13152
13152
|
this.clearSelected();
|
|
13153
|
-
this.getObjects().forEach((obj => obj.
|
|
13153
|
+
this.getObjects().forEach((obj => obj.delete()));
|
|
13154
13154
|
}
|
|
13155
13155
|
getMarkupColor() {
|
|
13156
13156
|
return this._markupColor.RGB;
|
|
@@ -13262,6 +13262,7 @@
|
|
|
13262
13262
|
return objects;
|
|
13263
13263
|
}
|
|
13264
13264
|
getSelectedObjects() {
|
|
13265
|
+
if (!this._konvaTransformer) return [];
|
|
13265
13266
|
return this._konvaTransformer.nodes().map((ref => {
|
|
13266
13267
|
const name = ref.className;
|
|
13267
13268
|
const konvaShape = Object.values(MarkupMode2Konva).find((shape => shape.name === name));
|
|
@@ -13269,29 +13270,29 @@
|
|
|
13269
13270
|
})).filter((x => x));
|
|
13270
13271
|
}
|
|
13271
13272
|
selectObjects(objects) {
|
|
13273
|
+
if (!this._konvaTransformer) return;
|
|
13272
13274
|
const selectedObjs = this._konvaTransformer.nodes().concat(objects.map((x => x.ref())));
|
|
13273
13275
|
this._konvaTransformer.nodes(selectedObjs);
|
|
13274
13276
|
}
|
|
13275
13277
|
clearSelected() {
|
|
13276
|
-
this._konvaTransformer.nodes([]);
|
|
13278
|
+
if (this._konvaTransformer) this._konvaTransformer.nodes([]);
|
|
13277
13279
|
}
|
|
13278
13280
|
addObject(object) {
|
|
13279
|
-
this._konvaLayer.add(object.ref());
|
|
13281
|
+
if (this._konvaLayer) this._konvaLayer.add(object.ref());
|
|
13280
13282
|
}
|
|
13281
13283
|
konvaLayerFind(type) {
|
|
13284
|
+
if (!this._konvaLayer) return [];
|
|
13282
13285
|
const konvaShape = MarkupMode2Konva[type];
|
|
13283
|
-
if (konvaShape
|
|
13284
|
-
|
|
13285
|
-
}
|
|
13286
|
-
return [];
|
|
13286
|
+
if (!konvaShape || !konvaShape.initializer) return [];
|
|
13287
|
+
return this._konvaLayer.find(konvaShape.name).filter((ref => ref.parent === this._konvaLayer));
|
|
13287
13288
|
}
|
|
13288
13289
|
initializeKonva() {
|
|
13289
|
-
|
|
13290
|
-
container: this.
|
|
13290
|
+
const stage = new Konva.Stage({
|
|
13291
|
+
container: this._markupContainer,
|
|
13291
13292
|
width: this._container.clientWidth,
|
|
13292
13293
|
height: this._container.clientHeight
|
|
13293
13294
|
});
|
|
13294
|
-
|
|
13295
|
+
this._konvaStage = stage;
|
|
13295
13296
|
const layer = new Konva.Layer({
|
|
13296
13297
|
pixelRation: window.devicePixelRatio
|
|
13297
13298
|
});
|
|
@@ -13302,8 +13303,8 @@
|
|
|
13302
13303
|
keepRatio: false,
|
|
13303
13304
|
flipEnabled: false
|
|
13304
13305
|
});
|
|
13305
|
-
this._konvaTransformer = transformer;
|
|
13306
13306
|
layer.add(transformer);
|
|
13307
|
+
this._konvaTransformer = transformer;
|
|
13307
13308
|
let isPaint = false;
|
|
13308
13309
|
let lastLine;
|
|
13309
13310
|
let mouseDownPos;
|
|
@@ -13485,20 +13486,17 @@
|
|
|
13485
13486
|
container.addEventListener("keydown", (e => {
|
|
13486
13487
|
if (!this._markupIsActive) return;
|
|
13487
13488
|
if (e.code === "Delete") {
|
|
13488
|
-
|
|
13489
|
-
|
|
13490
|
-
this._konvaTransformer.nodes().forEach((x => x.destroy()));
|
|
13491
|
-
this._konvaTransformer.nodes([]);
|
|
13492
|
-
}
|
|
13493
|
-
layer.draw();
|
|
13489
|
+
this.getSelectedObjects().forEach((obj => obj.delete()));
|
|
13490
|
+
this.clearSelected();
|
|
13494
13491
|
return;
|
|
13495
13492
|
}
|
|
13496
13493
|
e.preventDefault();
|
|
13497
13494
|
}));
|
|
13498
13495
|
}
|
|
13499
13496
|
destroyKonva() {
|
|
13497
|
+
var _a;
|
|
13500
13498
|
this.clearOverlay();
|
|
13501
|
-
this._konvaStage.destroy();
|
|
13499
|
+
(_a = this._konvaStage) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
13502
13500
|
this._konvaLayer = undefined;
|
|
13503
13501
|
this._konvaTransformer = undefined;
|
|
13504
13502
|
this._konvaStage = undefined;
|
|
@@ -13532,9 +13530,9 @@
|
|
|
13532
13530
|
}
|
|
13533
13531
|
getMarkupTexts() {
|
|
13534
13532
|
const texts = [];
|
|
13535
|
-
const textSize = .02;
|
|
13536
|
-
const textScale = this._worldTransformer.getScale();
|
|
13537
13533
|
this.konvaLayerFind("Text").forEach((ref => {
|
|
13534
|
+
const textSize = .02;
|
|
13535
|
+
const textScale = this._worldTransformer.getScale();
|
|
13538
13536
|
const position = {
|
|
13539
13537
|
x: ref.x(),
|
|
13540
13538
|
y: ref.y()
|
|
@@ -13655,13 +13653,15 @@
|
|
|
13655
13653
|
combineMarkupWithDrawing() {
|
|
13656
13654
|
this.clearSelected();
|
|
13657
13655
|
const tempCanvas = document.createElement("canvas");
|
|
13658
|
-
|
|
13659
|
-
|
|
13660
|
-
|
|
13661
|
-
|
|
13662
|
-
|
|
13663
|
-
|
|
13664
|
-
|
|
13656
|
+
if (this._konvaStage) {
|
|
13657
|
+
tempCanvas.width = this._konvaStage.width();
|
|
13658
|
+
tempCanvas.height = this._konvaStage.height();
|
|
13659
|
+
const ctx = tempCanvas.getContext("2d");
|
|
13660
|
+
if (this._container instanceof HTMLCanvasElement) ctx.drawImage(this._container, 0, 0);
|
|
13661
|
+
ctx.drawImage(this._konvaStage.toCanvas({
|
|
13662
|
+
pixelRatio: window.devicePixelRatio
|
|
13663
|
+
}), 0, 0);
|
|
13664
|
+
}
|
|
13665
13665
|
return tempCanvas.toDataURL("image/jpeg", .25);
|
|
13666
13666
|
}
|
|
13667
13667
|
addLine(linePoints, color, type, width, id) {
|
|
@@ -13680,7 +13680,7 @@
|
|
|
13680
13680
|
color: color || this._markupColor.HexColor,
|
|
13681
13681
|
id: id
|
|
13682
13682
|
});
|
|
13683
|
-
this.
|
|
13683
|
+
this.addObject(konvaLine);
|
|
13684
13684
|
return konvaLine;
|
|
13685
13685
|
}
|
|
13686
13686
|
createTextInput(pos, inputX, inputY, angle, text) {
|
|
@@ -13761,13 +13761,11 @@
|
|
|
13761
13761
|
this._imageInputRef = null;
|
|
13762
13762
|
this._imageInputPos = null;
|
|
13763
13763
|
}
|
|
13764
|
-
addText(
|
|
13765
|
-
|
|
13766
|
-
|
|
13767
|
-
|
|
13768
|
-
|
|
13769
|
-
this._konvaTransformer.nodes([]);
|
|
13770
|
-
}
|
|
13764
|
+
addText(text, position, angle, color, textSize, fontSize, id) {
|
|
13765
|
+
var _a;
|
|
13766
|
+
if (!text) return;
|
|
13767
|
+
(_a = this.getSelectedObjects().at(0)) === null || _a === void 0 ? void 0 : _a.delete();
|
|
13768
|
+
this.clearSelected();
|
|
13771
13769
|
this.removeTextInput();
|
|
13772
13770
|
const tolerance = 1e-6;
|
|
13773
13771
|
if (textSize && textSize > tolerance && (!fontSize || fontSize < tolerance)) {
|
|
@@ -13780,13 +13778,13 @@
|
|
|
13780
13778
|
x: position.x,
|
|
13781
13779
|
y: position.y
|
|
13782
13780
|
},
|
|
13783
|
-
text:
|
|
13781
|
+
text: text,
|
|
13784
13782
|
rotation: angle,
|
|
13785
13783
|
fontSize: fontSize || this.fontSize,
|
|
13786
13784
|
color: color || this._markupColor.HexColor,
|
|
13787
13785
|
id: id
|
|
13788
13786
|
});
|
|
13789
|
-
this.
|
|
13787
|
+
this.addObject(konvaText);
|
|
13790
13788
|
return konvaText;
|
|
13791
13789
|
}
|
|
13792
13790
|
addRectangle(position, width, height, lineWidth, color, id) {
|
|
@@ -13799,7 +13797,7 @@
|
|
|
13799
13797
|
color: color || this._markupColor.HexColor,
|
|
13800
13798
|
id: id
|
|
13801
13799
|
});
|
|
13802
|
-
this.
|
|
13800
|
+
this.addObject(konvaRectangle);
|
|
13803
13801
|
return konvaRectangle;
|
|
13804
13802
|
}
|
|
13805
13803
|
addEllipse(position, radius, lineWidth, color, id) {
|
|
@@ -13811,7 +13809,7 @@
|
|
|
13811
13809
|
color: color || this._markupColor.HexColor,
|
|
13812
13810
|
id: id
|
|
13813
13811
|
});
|
|
13814
|
-
this.
|
|
13812
|
+
this.addObject(konvaEllipse);
|
|
13815
13813
|
return konvaEllipse;
|
|
13816
13814
|
}
|
|
13817
13815
|
addArrow(start, end, color, id) {
|
|
@@ -13822,7 +13820,7 @@
|
|
|
13822
13820
|
color: color || this._markupColor.HexColor,
|
|
13823
13821
|
id: id
|
|
13824
13822
|
});
|
|
13825
|
-
this.
|
|
13823
|
+
this.addObject(konvaArrow);
|
|
13826
13824
|
return konvaArrow;
|
|
13827
13825
|
}
|
|
13828
13826
|
addCloud(position, width, height, lineWidth, color, id) {
|
|
@@ -13835,16 +13833,14 @@
|
|
|
13835
13833
|
lineWidth: lineWidth || this.lineWidth,
|
|
13836
13834
|
id: id
|
|
13837
13835
|
});
|
|
13838
|
-
this.
|
|
13836
|
+
this.addObject(konvaCloud);
|
|
13839
13837
|
return konvaCloud;
|
|
13840
13838
|
}
|
|
13841
13839
|
addImage(position, src, width, height, id) {
|
|
13840
|
+
var _a;
|
|
13842
13841
|
if (!position || !src) return;
|
|
13843
|
-
|
|
13844
|
-
|
|
13845
|
-
trNodes[0].destroy();
|
|
13846
|
-
this._konvaTransformer.nodes([]);
|
|
13847
|
-
}
|
|
13842
|
+
(_a = this.getSelectedObjects().at(0)) === null || _a === void 0 ? void 0 : _a.delete();
|
|
13843
|
+
this.clearSelected();
|
|
13848
13844
|
this.removeImageInput();
|
|
13849
13845
|
const konvaImage = new KonvaImage({
|
|
13850
13846
|
position: position,
|
|
@@ -13853,7 +13849,7 @@
|
|
|
13853
13849
|
height: height,
|
|
13854
13850
|
id: id
|
|
13855
13851
|
});
|
|
13856
|
-
this.
|
|
13852
|
+
this.addObject(konvaImage);
|
|
13857
13853
|
return konvaImage;
|
|
13858
13854
|
}
|
|
13859
13855
|
}
|
|
@@ -16664,12 +16660,18 @@
|
|
|
16664
16660
|
canvas.style.touchAction = "none";
|
|
16665
16661
|
canvas.width = canvas.clientWidth * window.devicePixelRatio;
|
|
16666
16662
|
canvas.height = canvas.clientHeight * window.devicePixelRatio;
|
|
16663
|
+
this._visualizeTimestamp = Date.now();
|
|
16664
|
+
const visualizeTimestamp = this._visualizeTimestamp;
|
|
16667
16665
|
const visualizeJs = await loadVisualizeJs(this.visualizeJsUrl, (event) => {
|
|
16668
16666
|
const { loaded, total } = event;
|
|
16669
16667
|
if (onProgress)
|
|
16670
16668
|
onProgress(new ProgressEvent("progress", { lengthComputable: true, loaded, total }));
|
|
16671
16669
|
this.emitEvent({ type: "initializeprogress", data: loaded / total, loaded, total });
|
|
16672
16670
|
});
|
|
16671
|
+
if (visualizeTimestamp !== this._visualizeTimestamp) {
|
|
16672
|
+
console.error("Viewer error: dispose() was called before initialize() completed. Are you using React strict mode?");
|
|
16673
|
+
return this;
|
|
16674
|
+
}
|
|
16673
16675
|
this._visualizeJs = visualizeJs;
|
|
16674
16676
|
this.visualizeJs.canvas = canvas;
|
|
16675
16677
|
this.visualizeJs.Viewer.create();
|
|
@@ -16720,6 +16722,7 @@
|
|
|
16720
16722
|
if (this._visualizeJs)
|
|
16721
16723
|
this._visualizeJs.getViewer().clear();
|
|
16722
16724
|
this._visualizeJs = undefined;
|
|
16725
|
+
this._visualizeTimestamp = undefined;
|
|
16723
16726
|
return this;
|
|
16724
16727
|
}
|
|
16725
16728
|
/**
|