@inweb/viewer-visualize 27.1.3 → 27.1.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 +79 -37
- package/dist/viewer-visualize.js.map +1 -1
- package/dist/viewer-visualize.min.js +1 -1
- package/dist/viewer-visualize.module.js +64 -23
- package/dist/viewer-visualize.module.js.map +1 -1
- package/lib/Viewer/Commands/GetSnapshot.d.ts +2 -0
- package/lib/Viewer/Components/CanvasRemoveComponent.d.ts +9 -0
- package/lib/Viewer/Components/{ResizeCanvasComponent.d.ts → CanvasResizeComponent.d.ts} +1 -1
- package/lib/Viewer/Markup/Visualize/VisualizeMarkup.d.ts +1 -0
- package/lib/Viewer/Viewer.d.ts +3 -1
- package/package.json +5 -5
- package/src/Viewer/Commands/{CreatePreview.ts → GetSnapshot.ts} +9 -2
- package/src/Viewer/Commands/index.ts +3 -2
- package/src/Viewer/Components/CanvasRemoveComponent.ts +55 -0
- package/src/Viewer/Components/{ResizeCanvasComponent.ts → CanvasResizeComponent.ts} +1 -1
- package/src/Viewer/Components/index.ts +4 -2
- package/src/Viewer/Markup/Visualize/VisualizeMarkup.ts +7 -2
- package/src/Viewer/Viewer.ts +8 -1
- package/lib/Viewer/Commands/CreatePreview.d.ts +0 -2
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IComponent } from "@inweb/viewer-core";
|
|
2
|
+
import type { Viewer } from "../Viewer";
|
|
3
|
+
export declare class CanvasRemoveComponent implements IComponent {
|
|
4
|
+
protected viewer: Viewer;
|
|
5
|
+
protected mutationObserver: MutationObserver;
|
|
6
|
+
constructor(viewer: Viewer);
|
|
7
|
+
dispose(): void;
|
|
8
|
+
cleanupViewer: (mutations: MutationRecord[]) => void;
|
|
9
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IComponent } from "@inweb/viewer-core";
|
|
2
2
|
import type { Viewer } from "../Viewer";
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class CanvasResizeComponent implements IComponent {
|
|
4
4
|
protected viewer: Viewer;
|
|
5
5
|
protected resizeObserver: ResizeObserver;
|
|
6
6
|
constructor(viewer: Viewer);
|
|
@@ -25,6 +25,7 @@ export declare class VisualizeMarkup implements IMarkup {
|
|
|
25
25
|
colorizeSelectedMarkups(r?: number, g?: number, b?: number): void;
|
|
26
26
|
setViewpoint(viewpoint: IViewpoint): void;
|
|
27
27
|
getViewpoint(viewpoint: IViewpoint): IViewpoint;
|
|
28
|
+
getSnapshot(type?: string, quality?: number): string;
|
|
28
29
|
enableEditMode(mode: MarkupMode | false): this;
|
|
29
30
|
createObject(type: string, params: any): IMarkupObject;
|
|
30
31
|
getObjects(): IMarkupObject[];
|
package/lib/Viewer/Viewer.d.ts
CHANGED
|
@@ -110,7 +110,8 @@ export declare class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMa
|
|
|
110
110
|
*
|
|
111
111
|
* @param canvas -
|
|
112
112
|
* {@link https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement | HTMLCanvasElement} for
|
|
113
|
-
* `VisualizeJS`.
|
|
113
|
+
* `VisualizeJS`. The canvas element must have an `id` attribute, otherwise an exception will be
|
|
114
|
+
* thrown.
|
|
114
115
|
* @param onProgress - A callback function that handles events measuring progress of loading of the
|
|
115
116
|
* `VisualizeJS` library.
|
|
116
117
|
*/
|
|
@@ -251,6 +252,7 @@ export declare class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMa
|
|
|
251
252
|
getComponent(name: string): IComponent;
|
|
252
253
|
drawViewpoint(viewpoint: IViewpoint): void;
|
|
253
254
|
createViewpoint(): IViewpoint;
|
|
255
|
+
getSnapshot(type?: string, quality?: number): string;
|
|
254
256
|
screenToWorld(position: {
|
|
255
257
|
x: number;
|
|
256
258
|
y: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inweb/viewer-visualize",
|
|
3
|
-
"version": "27.1.
|
|
3
|
+
"version": "27.1.5",
|
|
4
4
|
"description": "JavaScript library for rendering CAD and BIM files in a browser using VisualizeJS",
|
|
5
5
|
"homepage": "https://cloud.opendesign.com/docs/index.html",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"docs": "typedoc"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@inweb/client": "~27.1.
|
|
33
|
-
"@inweb/eventemitter2": "~27.1.
|
|
34
|
-
"@inweb/markup": "~27.1.
|
|
35
|
-
"@inweb/viewer-core": "~27.1.
|
|
32
|
+
"@inweb/client": "~27.1.5",
|
|
33
|
+
"@inweb/eventemitter2": "~27.1.5",
|
|
34
|
+
"@inweb/markup": "~27.1.5",
|
|
35
|
+
"@inweb/viewer-core": "~27.1.5"
|
|
36
36
|
},
|
|
37
37
|
"visualizeJS": "https://public-fhemb7e3embacwec.z02.azurefd.net/libs/visualizejs/master/Visualize.js"
|
|
38
38
|
}
|
|
@@ -23,8 +23,15 @@
|
|
|
23
23
|
|
|
24
24
|
import { Viewer } from "../Viewer";
|
|
25
25
|
|
|
26
|
-
export function
|
|
26
|
+
export function getSnapshot(viewer: Viewer, type?: string, quality?: number): string {
|
|
27
27
|
if (!viewer.visualizeJs) return "";
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
const mimeType = type ?? viewer.options.snapshotMimeType ?? "image/jpeg";
|
|
30
|
+
const imageQuality = quality ?? viewer.options.snapshotQuality ?? 0.25;
|
|
31
|
+
|
|
32
|
+
if (viewer.markup) {
|
|
33
|
+
return viewer.markup.getSnapshot(mimeType, imageQuality);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return viewer.canvas?.toDataURL(mimeType, imageQuality) || "";
|
|
30
37
|
}
|
|
@@ -27,7 +27,7 @@ import { applyModelTransform } from "./ApplyModelTransform";
|
|
|
27
27
|
import { clearMarkup } from "./ClearMarkup";
|
|
28
28
|
import { clearSelected } from "./ClearSelected";
|
|
29
29
|
import { clearSlices } from "./ClearSlices";
|
|
30
|
-
import {
|
|
30
|
+
import { getSnapshot } from "./GetSnapshot";
|
|
31
31
|
import { explode, collect } from "./Explode";
|
|
32
32
|
import { getDefaultViewPositions } from "./GetDefaultViewPositions";
|
|
33
33
|
import { getModels } from "./GetModels";
|
|
@@ -83,7 +83,7 @@ commands.registerCommand("applyModelTransform", applyModelTransform);
|
|
|
83
83
|
commands.registerCommand("clearMarkup", clearMarkup);
|
|
84
84
|
commands.registerCommand("clearSelected", clearSelected);
|
|
85
85
|
commands.registerCommand("clearSlices", clearSlices);
|
|
86
|
-
commands.registerCommand("
|
|
86
|
+
commands.registerCommand("getSnapshot", getSnapshot);
|
|
87
87
|
commands.registerCommand("explode", explode);
|
|
88
88
|
commands.registerCommand("collect", collect);
|
|
89
89
|
commands.registerCommand("getDefaultViewPositions", getDefaultViewPositions);
|
|
@@ -119,4 +119,5 @@ commands.registerCommand("k3DViewNW", (viewer) => setDefaultViewPosition(viewer,
|
|
|
119
119
|
|
|
120
120
|
commands.registerCommandAlias("clearMarkup", "clearOverlay");
|
|
121
121
|
commands.registerCommandAlias("clearSelected", "unselect");
|
|
122
|
+
commands.registerCommandAlias("getSnapshot", "createPreview");
|
|
122
123
|
commands.registerCommandAlias("zoomToExtents", "zoomExtents");
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2002-2025, Open Design Alliance (the "Alliance").
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
//
|
|
5
|
+
// This software and its documentation and related materials are owned by
|
|
6
|
+
// the Alliance. The software may only be incorporated into application
|
|
7
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
8
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
9
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
10
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
11
|
+
// protected by copyright law and international treaty provisions. Application
|
|
12
|
+
// programs incorporating this software must include the following statement
|
|
13
|
+
// with their copyright notices:
|
|
14
|
+
//
|
|
15
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
16
|
+
// license agreement with Open Design Alliance.
|
|
17
|
+
// Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance.
|
|
18
|
+
// All rights reserved.
|
|
19
|
+
//
|
|
20
|
+
// By use of this software, its documentation or related materials, you
|
|
21
|
+
// acknowledge and accept the above terms.
|
|
22
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
|
|
24
|
+
import { IComponent } from "@inweb/viewer-core";
|
|
25
|
+
import type { Viewer } from "../Viewer";
|
|
26
|
+
|
|
27
|
+
export class CanvasRemoveComponent implements IComponent {
|
|
28
|
+
protected viewer: Viewer;
|
|
29
|
+
protected mutationObserver: MutationObserver;
|
|
30
|
+
|
|
31
|
+
constructor(viewer: Viewer) {
|
|
32
|
+
this.viewer = viewer;
|
|
33
|
+
this.mutationObserver = new MutationObserver(this.cleanupViewer);
|
|
34
|
+
this.mutationObserver.observe(document, { childList: true, subtree: true });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
dispose() {
|
|
38
|
+
this.mutationObserver.disconnect();
|
|
39
|
+
this.mutationObserver = undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
cleanupViewer = (mutations: MutationRecord[]) => {
|
|
43
|
+
for (const mutation of mutations) {
|
|
44
|
+
if (mutation.type === "childList" && mutation.removedNodes.length > 0) {
|
|
45
|
+
for (const node of mutation.removedNodes) {
|
|
46
|
+
if (node === this.viewer.canvas || node.contains(this.viewer.canvas)) {
|
|
47
|
+
this.viewer.emitEvent({ type: "canvasremoved" });
|
|
48
|
+
this.viewer.dispose();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
import { IComponent } from "@inweb/viewer-core";
|
|
25
25
|
import type { Viewer } from "../Viewer";
|
|
26
26
|
|
|
27
|
-
export class
|
|
27
|
+
export class CanvasResizeComponent implements IComponent {
|
|
28
28
|
protected viewer: Viewer;
|
|
29
29
|
protected resizeObserver: ResizeObserver;
|
|
30
30
|
|
|
@@ -25,8 +25,9 @@ import { IComponentsRegistry, componentsRegistry } from "@inweb/viewer-core";
|
|
|
25
25
|
|
|
26
26
|
import { CameraComponent } from "./CameraComponent";
|
|
27
27
|
import { InfoComponent } from "./InfoComponent";
|
|
28
|
+
import { CanvasResizeComponent } from "./CanvasResizeComponent";
|
|
29
|
+
import { CanvasRemoveComponent } from "./CanvasRemoveComponent";
|
|
28
30
|
import { RenderLoopComponent } from "./RenderLoopComponent";
|
|
29
|
-
import { ResizeCanvasComponent } from "./ResizeCanvasComponent";
|
|
30
31
|
import { ZoomWheelComponent } from "./ZoomWheelComponent";
|
|
31
32
|
import { GestureManagerComponent } from "./GestureManagerComponent";
|
|
32
33
|
import { ResetComponent } from "./ResetComponent";
|
|
@@ -76,7 +77,8 @@ export const components: IComponentsRegistry = componentsRegistry("visualizejs")
|
|
|
76
77
|
|
|
77
78
|
components.registerComponent("CameraComponent", (viewer) => new CameraComponent(viewer));
|
|
78
79
|
components.registerComponent("InfoComponent", (viewer) => new InfoComponent(viewer));
|
|
79
|
-
components.registerComponent("
|
|
80
|
+
components.registerComponent("CanvasResizeComponent", (viewer) => new CanvasResizeComponent(viewer));
|
|
81
|
+
components.registerComponent("CanvasRemoveComponent", (viewer) => new CanvasRemoveComponent(viewer));
|
|
80
82
|
components.registerComponent("RenderLoopComponent", (viewer) => new RenderLoopComponent(viewer));
|
|
81
83
|
components.registerComponent("ZoomWheelComponent", (viewer) => new ZoomWheelComponent(viewer));
|
|
82
84
|
components.registerComponent("GestureManagerComponent", (viewer) => new GestureManagerComponent(viewer));
|
|
@@ -164,7 +164,6 @@ export class VisualizeMarkup implements IMarkup {
|
|
|
164
164
|
return { x: array[0], y: array[1], z: array[2] };
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
const visLib = this._viewer.visLib();
|
|
168
167
|
const visViewer = this._viewer.visViewer();
|
|
169
168
|
|
|
170
169
|
if (!viewpoint) viewpoint = { custom_fields: {} };
|
|
@@ -219,12 +218,18 @@ export class VisualizeMarkup implements IMarkup {
|
|
|
219
218
|
}
|
|
220
219
|
itr.delete();
|
|
221
220
|
|
|
222
|
-
viewpoint.snapshot = { data: visLib.canvas.toDataURL("image/jpeg", 0.25) };
|
|
223
221
|
viewpoint.custom_fields.markup_color = this.getMarkupColor();
|
|
224
222
|
|
|
225
223
|
return viewpoint;
|
|
226
224
|
}
|
|
227
225
|
|
|
226
|
+
getSnapshot(type = "image/jpeg", quality = 0.25): string {
|
|
227
|
+
if (!this._viewer.visualizeJs) return "";
|
|
228
|
+
|
|
229
|
+
const visLib = this._viewer.visLib();
|
|
230
|
+
return visLib.canvas?.toDataURL(type, quality) || "";
|
|
231
|
+
}
|
|
232
|
+
|
|
228
233
|
enableEditMode(mode: MarkupMode | false): this {
|
|
229
234
|
return this;
|
|
230
235
|
}
|
package/src/Viewer/Viewer.ts
CHANGED
|
@@ -226,7 +226,8 @@ export class Viewer
|
|
|
226
226
|
*
|
|
227
227
|
* @param canvas -
|
|
228
228
|
* {@link https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement | HTMLCanvasElement} for
|
|
229
|
-
* `VisualizeJS`.
|
|
229
|
+
* `VisualizeJS`. The canvas element must have an `id` attribute, otherwise an exception will be
|
|
230
|
+
* thrown.
|
|
230
231
|
* @param onProgress - A callback function that handles events measuring progress of loading of the
|
|
231
232
|
* `VisualizeJS` library.
|
|
232
233
|
*/
|
|
@@ -1195,6 +1196,8 @@ export class Viewer
|
|
|
1195
1196
|
viewpoint.clipping_planes = getClippingPlanes();
|
|
1196
1197
|
viewpoint.selection = getSelection();
|
|
1197
1198
|
viewpoint.description = new Date().toDateString();
|
|
1199
|
+
viewpoint.snapshot = { data: this.getSnapshot() };
|
|
1200
|
+
|
|
1198
1201
|
this._markup.getViewpoint(viewpoint);
|
|
1199
1202
|
|
|
1200
1203
|
viewpoint.custom_fields.selection2 = getSelection2();
|
|
@@ -1204,6 +1207,10 @@ export class Viewer
|
|
|
1204
1207
|
return viewpoint;
|
|
1205
1208
|
}
|
|
1206
1209
|
|
|
1210
|
+
getSnapshot(type?: string, quality?: number): string {
|
|
1211
|
+
return this.executeCommand("getSnapshot", type, quality);
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1207
1214
|
// IWorldTransform
|
|
1208
1215
|
|
|
1209
1216
|
screenToWorld(position: { x: number; y: number }): { x: number; y: number; z: number } {
|