@inweb/viewer-visualize 26.2.0 → 26.2.2
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 +28 -18
- package/dist/viewer-visualize.js.map +1 -1
- package/dist/viewer-visualize.min.js +1 -1
- package/dist/viewer-visualize.module.js +23 -15
- package/dist/viewer-visualize.module.js.map +1 -1
- package/lib/Viewer/Viewer.d.ts +11 -0
- package/lib/Viewer/utils.d.ts +6 -2
- package/package.json +5 -5
- package/src/Viewer/Viewer.ts +21 -7
- package/src/Viewer/utils.ts +21 -16
package/lib/Viewer/Viewer.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMa
|
|
|
18
18
|
protected _visualizeJsUrl: string;
|
|
19
19
|
protected _visualizeJs: any;
|
|
20
20
|
protected _visualizeTimestamp: number;
|
|
21
|
+
protected _crossOrigin: any;
|
|
21
22
|
private canvaseventlistener;
|
|
22
23
|
canvasEvents: string[];
|
|
23
24
|
private _markup;
|
|
@@ -34,6 +35,10 @@ export declare class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMa
|
|
|
34
35
|
* @param params.visualizeJsUrl - `VisualizeJS` library URL. Set this URL to use your own library
|
|
35
36
|
* instance, or specify `undefined` or blank to use the default URL defined by `Viewer.visualize`
|
|
36
37
|
* library you are using.
|
|
38
|
+
* @param params.crossOrigin - The
|
|
39
|
+
* {@link https://developer.mozilla.org/docs/Web/HTML/Attributes/crossorigin | crossorigin} content
|
|
40
|
+
* attribute on `Visalize.js` script element. One of the following values: `""`, `anonymous` or
|
|
41
|
+
* `use-credentials`.
|
|
37
42
|
* @param params.enableAutoUpdate - Enable auto-update of the viewer after any changes. If the
|
|
38
43
|
* auto-update is disabled, you need to register an `update` event handler and update the
|
|
39
44
|
* `VisualizeJS` viewer and active dragger manually. Default is `true`.
|
|
@@ -42,6 +47,7 @@ export declare class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMa
|
|
|
42
47
|
*/
|
|
43
48
|
constructor(client?: Client, params?: {
|
|
44
49
|
visualizeJsUrl?: string;
|
|
50
|
+
crossOrigin?: string;
|
|
45
51
|
enableAutoUpdate?: boolean;
|
|
46
52
|
markupType?: MarkupType;
|
|
47
53
|
});
|
|
@@ -68,9 +74,14 @@ export declare class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMa
|
|
|
68
74
|
* @param params.visualizeJsUrl - `VisualizeJS` library URL. Set this URL to use your own library
|
|
69
75
|
* instance or specify `undefined` or blank to use the default URL defined by `Viewer.visualize`
|
|
70
76
|
* library you are using.
|
|
77
|
+
* @param params.crossOrigin - The
|
|
78
|
+
* {@link https://developer.mozilla.org/docs/Web/HTML/Attributes/crossorigin | crossorigin} content
|
|
79
|
+
* attribute on `Visalize.js` script element. One of the following values: `""`, `anonymous` or
|
|
80
|
+
* `use-credentials`.
|
|
71
81
|
*/
|
|
72
82
|
configure(params: {
|
|
73
83
|
visualizeJsUrl?: string;
|
|
84
|
+
crossOrigin?: string;
|
|
74
85
|
}): this;
|
|
75
86
|
/**
|
|
76
87
|
* Loads the `VisualizeJS` module and initializes it with the specified canvas. Call
|
package/lib/Viewer/utils.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
interface LoadParams {
|
|
2
|
+
crossOrigin?: string;
|
|
3
|
+
}
|
|
4
|
+
export declare function loadScript(url: string, params?: LoadParams): Promise<HTMLScriptElement>;
|
|
5
|
+
export declare const loadVisualizeJs: (url: string, onprogress: any, params?: LoadParams) => Promise<any>;
|
|
6
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inweb/viewer-visualize",
|
|
3
|
-
"version": "26.2.
|
|
3
|
+
"version": "26.2.2",
|
|
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": "~26.2.
|
|
33
|
-
"@inweb/eventemitter2": "~26.2.
|
|
34
|
-
"@inweb/markup": "~26.2.
|
|
35
|
-
"@inweb/viewer-core": "~26.2.
|
|
32
|
+
"@inweb/client": "~26.2.2",
|
|
33
|
+
"@inweb/eventemitter2": "~26.2.2",
|
|
34
|
+
"@inweb/markup": "~26.2.2",
|
|
35
|
+
"@inweb/viewer-core": "~26.2.2"
|
|
36
36
|
},
|
|
37
37
|
"visualizeJS": "https://public-fhemb7e3embacwec.z02.azurefd.net/libs/visualizejs/master/Visualize.js"
|
|
38
38
|
}
|
package/src/Viewer/Viewer.ts
CHANGED
|
@@ -73,6 +73,7 @@ export class Viewer
|
|
|
73
73
|
protected _visualizeJsUrl = "";
|
|
74
74
|
protected _visualizeJs: any;
|
|
75
75
|
protected _visualizeTimestamp: number;
|
|
76
|
+
protected _crossOrigin;
|
|
76
77
|
|
|
77
78
|
private canvaseventlistener: (event: Event) => void;
|
|
78
79
|
|
|
@@ -93,6 +94,10 @@ export class Viewer
|
|
|
93
94
|
* @param params.visualizeJsUrl - `VisualizeJS` library URL. Set this URL to use your own library
|
|
94
95
|
* instance, or specify `undefined` or blank to use the default URL defined by `Viewer.visualize`
|
|
95
96
|
* library you are using.
|
|
97
|
+
* @param params.crossOrigin - The
|
|
98
|
+
* {@link https://developer.mozilla.org/docs/Web/HTML/Attributes/crossorigin | crossorigin} content
|
|
99
|
+
* attribute on `Visalize.js` script element. One of the following values: `""`, `anonymous` or
|
|
100
|
+
* `use-credentials`.
|
|
96
101
|
* @param params.enableAutoUpdate - Enable auto-update of the viewer after any changes. If the
|
|
97
102
|
* auto-update is disabled, you need to register an `update` event handler and update the
|
|
98
103
|
* `VisualizeJS` viewer and active dragger manually. Default is `true`.
|
|
@@ -101,7 +106,7 @@ export class Viewer
|
|
|
101
106
|
*/
|
|
102
107
|
constructor(
|
|
103
108
|
client?: Client,
|
|
104
|
-
params: { visualizeJsUrl?: string; enableAutoUpdate?: boolean; markupType?: MarkupType } = {}
|
|
109
|
+
params: { visualizeJsUrl?: string; crossOrigin?: string; enableAutoUpdate?: boolean; markupType?: MarkupType } = {}
|
|
105
110
|
) {
|
|
106
111
|
super();
|
|
107
112
|
this.configure(params);
|
|
@@ -160,9 +165,14 @@ export class Viewer
|
|
|
160
165
|
* @param params.visualizeJsUrl - `VisualizeJS` library URL. Set this URL to use your own library
|
|
161
166
|
* instance or specify `undefined` or blank to use the default URL defined by `Viewer.visualize`
|
|
162
167
|
* library you are using.
|
|
168
|
+
* @param params.crossOrigin - The
|
|
169
|
+
* {@link https://developer.mozilla.org/docs/Web/HTML/Attributes/crossorigin | crossorigin} content
|
|
170
|
+
* attribute on `Visalize.js` script element. One of the following values: `""`, `anonymous` or
|
|
171
|
+
* `use-credentials`.
|
|
163
172
|
*/
|
|
164
|
-
configure(params: { visualizeJsUrl?: string }): this {
|
|
173
|
+
configure(params: { visualizeJsUrl?: string; crossOrigin?: string }): this {
|
|
165
174
|
this._visualizeJsUrl = params.visualizeJsUrl || "VISUALIZE_JS_URL";
|
|
175
|
+
this._crossOrigin = params.crossOrigin;
|
|
166
176
|
return this;
|
|
167
177
|
}
|
|
168
178
|
|
|
@@ -197,11 +207,15 @@ export class Viewer
|
|
|
197
207
|
this._visualizeTimestamp = Date.now();
|
|
198
208
|
const visualizeTimestamp = this._visualizeTimestamp;
|
|
199
209
|
|
|
200
|
-
const visualizeJs: any = await loadVisualizeJs(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
210
|
+
const visualizeJs: any = await loadVisualizeJs(
|
|
211
|
+
this.visualizeJsUrl,
|
|
212
|
+
(event: ProgressEvent) => {
|
|
213
|
+
const { loaded, total } = event;
|
|
214
|
+
if (onProgress) onProgress(new ProgressEvent("progress", { lengthComputable: true, loaded, total }));
|
|
215
|
+
this.emitEvent({ type: "initializeprogress", data: loaded / total, loaded, total });
|
|
216
|
+
},
|
|
217
|
+
{ crossOrigin: this._crossOrigin }
|
|
218
|
+
);
|
|
205
219
|
|
|
206
220
|
if (visualizeTimestamp !== this._visualizeTimestamp)
|
|
207
221
|
throw new Error(
|
package/src/Viewer/utils.ts
CHANGED
|
@@ -21,11 +21,16 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
interface LoadParams {
|
|
25
|
+
crossOrigin?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function loadScript(url: string, params: LoadParams = {}): Promise<HTMLScriptElement> {
|
|
25
29
|
return new Promise((resolve, reject) => {
|
|
26
30
|
const script = document.createElement("script");
|
|
27
31
|
script.src = url;
|
|
28
32
|
script.async = true;
|
|
33
|
+
script.crossOrigin = params.crossOrigin;
|
|
29
34
|
script.onload = () => resolve(script);
|
|
30
35
|
script.onerror = () => {
|
|
31
36
|
script.remove();
|
|
@@ -35,7 +40,7 @@ export function loadScript(url: string): Promise<HTMLScriptElement> {
|
|
|
35
40
|
});
|
|
36
41
|
}
|
|
37
42
|
|
|
38
|
-
function loadVisuazlizeJsScript(url: string): Promise<HTMLScriptElement> {
|
|
43
|
+
function loadVisuazlizeJsScript(url: string, params: LoadParams): Promise<HTMLScriptElement> {
|
|
39
44
|
if (window["getVisualizeLibInst"]) {
|
|
40
45
|
const script = window["getVisualizeLibInst"].script;
|
|
41
46
|
if (script) {
|
|
@@ -44,22 +49,22 @@ function loadVisuazlizeJsScript(url: string): Promise<HTMLScriptElement> {
|
|
|
44
49
|
}
|
|
45
50
|
delete window["getVisualizeLibInst"];
|
|
46
51
|
}
|
|
47
|
-
return loadScript(url);
|
|
52
|
+
return loadScript(url, params);
|
|
48
53
|
}
|
|
49
54
|
|
|
50
|
-
export const loadVisualizeJs = (url: string, onprogress): Promise<any> => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
export const loadVisualizeJs = async (url: string, onprogress, params: LoadParams = {}): Promise<any> => {
|
|
56
|
+
const script = await loadVisuazlizeJsScript(url, params);
|
|
57
|
+
return await new Promise((resolve, reject) => {
|
|
58
|
+
const options = {
|
|
59
|
+
urlMemFile: url + ".wasm",
|
|
60
|
+
TOTAL_MEMORY: 134217728,
|
|
61
|
+
onprogress,
|
|
62
|
+
};
|
|
63
|
+
const instance = window["getVisualizeLibInst"](options);
|
|
64
|
+
instance.loadWasmError = reject;
|
|
65
|
+
instance.postRun.push(() => {
|
|
66
|
+
window["getVisualizeLibInst"].script = script;
|
|
67
|
+
resolve(instance);
|
|
63
68
|
});
|
|
64
69
|
});
|
|
65
70
|
};
|