@inweb/viewer-visualize 25.8.3 → 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/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
|
@@ -1630,11 +1630,10 @@ const MarkupMode2Konva = {
|
|
|
1630
1630
|
|
|
1631
1631
|
class KonvaMarkup {
|
|
1632
1632
|
constructor() {
|
|
1633
|
-
this.
|
|
1633
|
+
this._pointerEvents = [];
|
|
1634
1634
|
this._markupIsActive = false;
|
|
1635
1635
|
this._markupColor = new MarkupColor(255, 0, 0);
|
|
1636
1636
|
this._zIndex = 1;
|
|
1637
|
-
this._markupContainerName = "markupContainer";
|
|
1638
1637
|
this.lineWidth = 4;
|
|
1639
1638
|
this.lineType = "solid";
|
|
1640
1639
|
this.fontSize = 34;
|
|
@@ -1646,11 +1645,11 @@ class KonvaMarkup {
|
|
|
1646
1645
|
this.enableEditMode(draggerName);
|
|
1647
1646
|
};
|
|
1648
1647
|
this.resizeContainer = entries => {
|
|
1649
|
-
var _a, _b;
|
|
1650
1648
|
const {width: width, height: height} = entries[0].contentRect;
|
|
1651
1649
|
if (!width || !height) return;
|
|
1652
|
-
(
|
|
1653
|
-
|
|
1650
|
+
if (!this._konvaStage) return;
|
|
1651
|
+
this._konvaStage.width(width);
|
|
1652
|
+
this._konvaStage.height(height);
|
|
1654
1653
|
};
|
|
1655
1654
|
this.pan = event => {
|
|
1656
1655
|
const dX = event.dX / window.devicePixelRatio;
|
|
@@ -1665,13 +1664,16 @@ class KonvaMarkup {
|
|
|
1665
1664
|
};
|
|
1666
1665
|
}
|
|
1667
1666
|
initialize(container, pointerEvents, viewer, worldTransformer) {
|
|
1668
|
-
if (!Konva)
|
|
1667
|
+
if (!Konva) {
|
|
1668
|
+
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>');
|
|
1669
|
+
return;
|
|
1670
|
+
}
|
|
1669
1671
|
this._viewer = viewer;
|
|
1670
1672
|
this._worldTransformer = worldTransformer !== null && worldTransformer !== void 0 ? worldTransformer : new WorldTransform;
|
|
1671
1673
|
this._container = container;
|
|
1672
1674
|
this._pointerEvents = pointerEvents !== null && pointerEvents !== void 0 ? pointerEvents : [];
|
|
1673
1675
|
this._markupContainer = document.createElement("div");
|
|
1674
|
-
this._markupContainer.id =
|
|
1676
|
+
this._markupContainer.id = "markup-container";
|
|
1675
1677
|
this._markupContainer.style.position = "absolute";
|
|
1676
1678
|
this._markupContainer.style.top = "0px";
|
|
1677
1679
|
this._markupContainer.style.left = "0px";
|
|
@@ -1687,32 +1689,30 @@ class KonvaMarkup {
|
|
|
1687
1689
|
this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
|
|
1688
1690
|
this._viewer.addEventListener("pan", this.pan);
|
|
1689
1691
|
}
|
|
1690
|
-
this._isInitialized = true;
|
|
1691
1692
|
}
|
|
1692
1693
|
dispose() {
|
|
1693
|
-
|
|
1694
|
+
var _a, _b;
|
|
1694
1695
|
if (this._viewer) {
|
|
1695
1696
|
this._viewer.removeEventListener("pan", this.pan);
|
|
1696
1697
|
this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
|
|
1698
|
+
this._pointerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
|
|
1697
1699
|
}
|
|
1698
|
-
this._pointerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
|
|
1699
1700
|
this.destroyKonva();
|
|
1700
|
-
this._resizeObserver.disconnect();
|
|
1701
|
+
(_a = this._resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
1701
1702
|
this._resizeObserver = undefined;
|
|
1702
|
-
this._markupContainer.remove();
|
|
1703
|
+
(_b = this._markupContainer) === null || _b === void 0 ? void 0 : _b.remove();
|
|
1703
1704
|
this._markupContainer = undefined;
|
|
1704
1705
|
this._container = undefined;
|
|
1705
1706
|
this._viewer = undefined;
|
|
1706
1707
|
this._worldTransformer = undefined;
|
|
1707
1708
|
this._markupIsActive = false;
|
|
1708
|
-
this._isInitialized = false;
|
|
1709
1709
|
}
|
|
1710
1710
|
syncOverlay() {}
|
|
1711
1711
|
clearOverlay() {
|
|
1712
1712
|
this.removeTextInput();
|
|
1713
1713
|
this.removeImageInput();
|
|
1714
1714
|
this.clearSelected();
|
|
1715
|
-
this.getObjects().forEach((obj => obj.
|
|
1715
|
+
this.getObjects().forEach((obj => obj.delete()));
|
|
1716
1716
|
}
|
|
1717
1717
|
getMarkupColor() {
|
|
1718
1718
|
return this._markupColor.RGB;
|
|
@@ -1824,6 +1824,7 @@ class KonvaMarkup {
|
|
|
1824
1824
|
return objects;
|
|
1825
1825
|
}
|
|
1826
1826
|
getSelectedObjects() {
|
|
1827
|
+
if (!this._konvaTransformer) return [];
|
|
1827
1828
|
return this._konvaTransformer.nodes().map((ref => {
|
|
1828
1829
|
const name = ref.className;
|
|
1829
1830
|
const konvaShape = Object.values(MarkupMode2Konva).find((shape => shape.name === name));
|
|
@@ -1831,29 +1832,29 @@ class KonvaMarkup {
|
|
|
1831
1832
|
})).filter((x => x));
|
|
1832
1833
|
}
|
|
1833
1834
|
selectObjects(objects) {
|
|
1835
|
+
if (!this._konvaTransformer) return;
|
|
1834
1836
|
const selectedObjs = this._konvaTransformer.nodes().concat(objects.map((x => x.ref())));
|
|
1835
1837
|
this._konvaTransformer.nodes(selectedObjs);
|
|
1836
1838
|
}
|
|
1837
1839
|
clearSelected() {
|
|
1838
|
-
this._konvaTransformer.nodes([]);
|
|
1840
|
+
if (this._konvaTransformer) this._konvaTransformer.nodes([]);
|
|
1839
1841
|
}
|
|
1840
1842
|
addObject(object) {
|
|
1841
|
-
this._konvaLayer.add(object.ref());
|
|
1843
|
+
if (this._konvaLayer) this._konvaLayer.add(object.ref());
|
|
1842
1844
|
}
|
|
1843
1845
|
konvaLayerFind(type) {
|
|
1846
|
+
if (!this._konvaLayer) return [];
|
|
1844
1847
|
const konvaShape = MarkupMode2Konva[type];
|
|
1845
|
-
if (konvaShape
|
|
1846
|
-
|
|
1847
|
-
}
|
|
1848
|
-
return [];
|
|
1848
|
+
if (!konvaShape || !konvaShape.initializer) return [];
|
|
1849
|
+
return this._konvaLayer.find(konvaShape.name).filter((ref => ref.parent === this._konvaLayer));
|
|
1849
1850
|
}
|
|
1850
1851
|
initializeKonva() {
|
|
1851
|
-
|
|
1852
|
-
container: this.
|
|
1852
|
+
const stage = new Konva.Stage({
|
|
1853
|
+
container: this._markupContainer,
|
|
1853
1854
|
width: this._container.clientWidth,
|
|
1854
1855
|
height: this._container.clientHeight
|
|
1855
1856
|
});
|
|
1856
|
-
|
|
1857
|
+
this._konvaStage = stage;
|
|
1857
1858
|
const layer = new Konva.Layer({
|
|
1858
1859
|
pixelRation: window.devicePixelRatio
|
|
1859
1860
|
});
|
|
@@ -1864,8 +1865,8 @@ class KonvaMarkup {
|
|
|
1864
1865
|
keepRatio: false,
|
|
1865
1866
|
flipEnabled: false
|
|
1866
1867
|
});
|
|
1867
|
-
this._konvaTransformer = transformer;
|
|
1868
1868
|
layer.add(transformer);
|
|
1869
|
+
this._konvaTransformer = transformer;
|
|
1869
1870
|
let isPaint = false;
|
|
1870
1871
|
let lastLine;
|
|
1871
1872
|
let mouseDownPos;
|
|
@@ -2047,20 +2048,17 @@ class KonvaMarkup {
|
|
|
2047
2048
|
container.addEventListener("keydown", (e => {
|
|
2048
2049
|
if (!this._markupIsActive) return;
|
|
2049
2050
|
if (e.code === "Delete") {
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
this._konvaTransformer.nodes().forEach((x => x.destroy()));
|
|
2053
|
-
this._konvaTransformer.nodes([]);
|
|
2054
|
-
}
|
|
2055
|
-
layer.draw();
|
|
2051
|
+
this.getSelectedObjects().forEach((obj => obj.delete()));
|
|
2052
|
+
this.clearSelected();
|
|
2056
2053
|
return;
|
|
2057
2054
|
}
|
|
2058
2055
|
e.preventDefault();
|
|
2059
2056
|
}));
|
|
2060
2057
|
}
|
|
2061
2058
|
destroyKonva() {
|
|
2059
|
+
var _a;
|
|
2062
2060
|
this.clearOverlay();
|
|
2063
|
-
this._konvaStage.destroy();
|
|
2061
|
+
(_a = this._konvaStage) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
2064
2062
|
this._konvaLayer = undefined;
|
|
2065
2063
|
this._konvaTransformer = undefined;
|
|
2066
2064
|
this._konvaStage = undefined;
|
|
@@ -2094,9 +2092,9 @@ class KonvaMarkup {
|
|
|
2094
2092
|
}
|
|
2095
2093
|
getMarkupTexts() {
|
|
2096
2094
|
const texts = [];
|
|
2097
|
-
const textSize = .02;
|
|
2098
|
-
const textScale = this._worldTransformer.getScale();
|
|
2099
2095
|
this.konvaLayerFind("Text").forEach((ref => {
|
|
2096
|
+
const textSize = .02;
|
|
2097
|
+
const textScale = this._worldTransformer.getScale();
|
|
2100
2098
|
const position = {
|
|
2101
2099
|
x: ref.x(),
|
|
2102
2100
|
y: ref.y()
|
|
@@ -2217,13 +2215,15 @@ class KonvaMarkup {
|
|
|
2217
2215
|
combineMarkupWithDrawing() {
|
|
2218
2216
|
this.clearSelected();
|
|
2219
2217
|
const tempCanvas = document.createElement("canvas");
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2218
|
+
if (this._konvaStage) {
|
|
2219
|
+
tempCanvas.width = this._konvaStage.width();
|
|
2220
|
+
tempCanvas.height = this._konvaStage.height();
|
|
2221
|
+
const ctx = tempCanvas.getContext("2d");
|
|
2222
|
+
if (this._container instanceof HTMLCanvasElement) ctx.drawImage(this._container, 0, 0);
|
|
2223
|
+
ctx.drawImage(this._konvaStage.toCanvas({
|
|
2224
|
+
pixelRatio: window.devicePixelRatio
|
|
2225
|
+
}), 0, 0);
|
|
2226
|
+
}
|
|
2227
2227
|
return tempCanvas.toDataURL("image/jpeg", .25);
|
|
2228
2228
|
}
|
|
2229
2229
|
addLine(linePoints, color, type, width, id) {
|
|
@@ -2242,7 +2242,7 @@ class KonvaMarkup {
|
|
|
2242
2242
|
color: color || this._markupColor.HexColor,
|
|
2243
2243
|
id: id
|
|
2244
2244
|
});
|
|
2245
|
-
this.
|
|
2245
|
+
this.addObject(konvaLine);
|
|
2246
2246
|
return konvaLine;
|
|
2247
2247
|
}
|
|
2248
2248
|
createTextInput(pos, inputX, inputY, angle, text) {
|
|
@@ -2323,13 +2323,11 @@ class KonvaMarkup {
|
|
|
2323
2323
|
this._imageInputRef = null;
|
|
2324
2324
|
this._imageInputPos = null;
|
|
2325
2325
|
}
|
|
2326
|
-
addText(
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
this._konvaTransformer.nodes([]);
|
|
2332
|
-
}
|
|
2326
|
+
addText(text, position, angle, color, textSize, fontSize, id) {
|
|
2327
|
+
var _a;
|
|
2328
|
+
if (!text) return;
|
|
2329
|
+
(_a = this.getSelectedObjects().at(0)) === null || _a === void 0 ? void 0 : _a.delete();
|
|
2330
|
+
this.clearSelected();
|
|
2333
2331
|
this.removeTextInput();
|
|
2334
2332
|
const tolerance = 1e-6;
|
|
2335
2333
|
if (textSize && textSize > tolerance && (!fontSize || fontSize < tolerance)) {
|
|
@@ -2342,13 +2340,13 @@ class KonvaMarkup {
|
|
|
2342
2340
|
x: position.x,
|
|
2343
2341
|
y: position.y
|
|
2344
2342
|
},
|
|
2345
|
-
text:
|
|
2343
|
+
text: text,
|
|
2346
2344
|
rotation: angle,
|
|
2347
2345
|
fontSize: fontSize || this.fontSize,
|
|
2348
2346
|
color: color || this._markupColor.HexColor,
|
|
2349
2347
|
id: id
|
|
2350
2348
|
});
|
|
2351
|
-
this.
|
|
2349
|
+
this.addObject(konvaText);
|
|
2352
2350
|
return konvaText;
|
|
2353
2351
|
}
|
|
2354
2352
|
addRectangle(position, width, height, lineWidth, color, id) {
|
|
@@ -2361,7 +2359,7 @@ class KonvaMarkup {
|
|
|
2361
2359
|
color: color || this._markupColor.HexColor,
|
|
2362
2360
|
id: id
|
|
2363
2361
|
});
|
|
2364
|
-
this.
|
|
2362
|
+
this.addObject(konvaRectangle);
|
|
2365
2363
|
return konvaRectangle;
|
|
2366
2364
|
}
|
|
2367
2365
|
addEllipse(position, radius, lineWidth, color, id) {
|
|
@@ -2373,7 +2371,7 @@ class KonvaMarkup {
|
|
|
2373
2371
|
color: color || this._markupColor.HexColor,
|
|
2374
2372
|
id: id
|
|
2375
2373
|
});
|
|
2376
|
-
this.
|
|
2374
|
+
this.addObject(konvaEllipse);
|
|
2377
2375
|
return konvaEllipse;
|
|
2378
2376
|
}
|
|
2379
2377
|
addArrow(start, end, color, id) {
|
|
@@ -2384,7 +2382,7 @@ class KonvaMarkup {
|
|
|
2384
2382
|
color: color || this._markupColor.HexColor,
|
|
2385
2383
|
id: id
|
|
2386
2384
|
});
|
|
2387
|
-
this.
|
|
2385
|
+
this.addObject(konvaArrow);
|
|
2388
2386
|
return konvaArrow;
|
|
2389
2387
|
}
|
|
2390
2388
|
addCloud(position, width, height, lineWidth, color, id) {
|
|
@@ -2397,16 +2395,14 @@ class KonvaMarkup {
|
|
|
2397
2395
|
lineWidth: lineWidth || this.lineWidth,
|
|
2398
2396
|
id: id
|
|
2399
2397
|
});
|
|
2400
|
-
this.
|
|
2398
|
+
this.addObject(konvaCloud);
|
|
2401
2399
|
return konvaCloud;
|
|
2402
2400
|
}
|
|
2403
2401
|
addImage(position, src, width, height, id) {
|
|
2402
|
+
var _a;
|
|
2404
2403
|
if (!position || !src) return;
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
trNodes[0].destroy();
|
|
2408
|
-
this._konvaTransformer.nodes([]);
|
|
2409
|
-
}
|
|
2404
|
+
(_a = this.getSelectedObjects().at(0)) === null || _a === void 0 ? void 0 : _a.delete();
|
|
2405
|
+
this.clearSelected();
|
|
2410
2406
|
this.removeImageInput();
|
|
2411
2407
|
const konvaImage = new KonvaImage({
|
|
2412
2408
|
position: position,
|
|
@@ -2415,7 +2411,7 @@ class KonvaMarkup {
|
|
|
2415
2411
|
height: height,
|
|
2416
2412
|
id: id
|
|
2417
2413
|
});
|
|
2418
|
-
this.
|
|
2414
|
+
this.addObject(konvaImage);
|
|
2419
2415
|
return konvaImage;
|
|
2420
2416
|
}
|
|
2421
2417
|
}
|
|
@@ -5136,6 +5132,8 @@ class Viewer extends EventEmitter2 {
|
|
|
5136
5132
|
canvas.style.touchAction = "none";
|
|
5137
5133
|
canvas.width = canvas.clientWidth * window.devicePixelRatio;
|
|
5138
5134
|
canvas.height = canvas.clientHeight * window.devicePixelRatio;
|
|
5135
|
+
this._visualizeTimestamp = Date.now();
|
|
5136
|
+
const visualizeTimestamp = this._visualizeTimestamp;
|
|
5139
5137
|
const visualizeJs = await loadVisualizeJs(this.visualizeJsUrl, (event => {
|
|
5140
5138
|
const {loaded: loaded, total: total} = event;
|
|
5141
5139
|
if (onProgress) onProgress(new ProgressEvent("progress", {
|
|
@@ -5150,6 +5148,10 @@ class Viewer extends EventEmitter2 {
|
|
|
5150
5148
|
total: total
|
|
5151
5149
|
});
|
|
5152
5150
|
}));
|
|
5151
|
+
if (visualizeTimestamp !== this._visualizeTimestamp) {
|
|
5152
|
+
console.error("Viewer error: dispose() was called before initialize() completed. Are you using React strict mode?");
|
|
5153
|
+
return this;
|
|
5154
|
+
}
|
|
5153
5155
|
this._visualizeJs = visualizeJs;
|
|
5154
5156
|
this.visualizeJs.canvas = canvas;
|
|
5155
5157
|
this.visualizeJs.Viewer.create();
|
|
@@ -5195,6 +5197,7 @@ class Viewer extends EventEmitter2 {
|
|
|
5195
5197
|
}
|
|
5196
5198
|
if (this._visualizeJs) this._visualizeJs.getViewer().clear();
|
|
5197
5199
|
this._visualizeJs = undefined;
|
|
5200
|
+
this._visualizeTimestamp = undefined;
|
|
5198
5201
|
return this;
|
|
5199
5202
|
}
|
|
5200
5203
|
isInitialized() {
|