@shapediver/viewer.shared.services 2.7.10 → 2.8.1
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/converter/Converter.d.ts +8 -6
- package/dist/converter/Converter.d.ts.map +1 -1
- package/dist/converter/Converter.js +63 -61
- package/dist/converter/Converter.js.map +1 -1
- package/dist/dom-event-engine/DomEventEngine.d.ts.map +1 -1
- package/dist/dom-event-engine/DomEventEngine.js +1 -2
- package/dist/dom-event-engine/DomEventEngine.js.map +1 -1
- package/dist/event-engine/EventEngine.d.ts +6 -4
- package/dist/event-engine/EventEngine.d.ts.map +1 -1
- package/dist/event-engine/EventEngine.js +24 -32
- package/dist/event-engine/EventEngine.js.map +1 -1
- package/dist/http-client/HttpClient.d.ts +4 -3
- package/dist/http-client/HttpClient.d.ts.map +1 -1
- package/dist/http-client/HttpClient.js +28 -41
- package/dist/http-client/HttpClient.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/input-validator/InputValidator.d.ts +4 -3
- package/dist/input-validator/InputValidator.d.ts.map +1 -1
- package/dist/input-validator/InputValidator.js +20 -20
- package/dist/input-validator/InputValidator.js.map +1 -1
- package/dist/logger/Logger.d.ts +11 -37
- package/dist/logger/Logger.d.ts.map +1 -1
- package/dist/logger/Logger.js +79 -235
- package/dist/logger/Logger.js.map +1 -1
- package/dist/logger/ShapeDiverViewerErrors.d.ts +5 -0
- package/dist/logger/ShapeDiverViewerErrors.d.ts.map +1 -1
- package/dist/logger/ShapeDiverViewerErrors.js +9 -1
- package/dist/logger/ShapeDiverViewerErrors.js.map +1 -1
- package/dist/performance-evaluator/PerformanceEvaluator.d.ts +16 -14
- package/dist/performance-evaluator/PerformanceEvaluator.d.ts.map +1 -1
- package/dist/performance-evaluator/PerformanceEvaluator.js +37 -40
- package/dist/performance-evaluator/PerformanceEvaluator.js.map +1 -1
- package/dist/settings-engine/SettingsEngine.d.ts.map +1 -1
- package/dist/settings-engine/SettingsEngine.js +3 -5
- package/dist/settings-engine/SettingsEngine.js.map +1 -1
- package/dist/state-engine/StateEngine.d.ts +11 -11
- package/dist/state-engine/StateEngine.d.ts.map +1 -1
- package/dist/state-engine/StateEngine.js +15 -26
- package/dist/state-engine/StateEngine.js.map +1 -1
- package/dist/system-info/SystemInfo.d.ts +21 -19
- package/dist/system-info/SystemInfo.d.ts.map +1 -1
- package/dist/system-info/SystemInfo.js +45 -61
- package/dist/system-info/SystemInfo.js.map +1 -1
- package/dist/type-check/TypeChecker.d.ts +3 -1
- package/dist/type-check/TypeChecker.d.ts.map +1 -1
- package/dist/type-check/TypeChecker.js +11 -14
- package/dist/type-check/TypeChecker.js.map +1 -1
- package/dist/uuid-generator/UuidGenerator.d.ts +8 -6
- package/dist/uuid-generator/UuidGenerator.d.ts.map +1 -1
- package/dist/uuid-generator/UuidGenerator.js +17 -24
- package/dist/uuid-generator/UuidGenerator.js.map +1 -1
- package/package.json +5 -8
- package/src/converter/Converter.ts +67 -47
- package/src/dom-event-engine/DomEventEngine.ts +1 -2
- package/src/event-engine/EventEngine.ts +34 -22
- package/src/http-client/HttpClient.ts +35 -32
- package/src/index.ts +4 -3
- package/src/input-validator/InputValidator.ts +29 -11
- package/src/logger/Logger.ts +60 -183
- package/src/logger/ShapeDiverViewerErrors.ts +9 -0
- package/src/performance-evaluator/PerformanceEvaluator.ts +45 -31
- package/src/settings-engine/SettingsEngine.ts +4 -6
- package/src/state-engine/StateEngine.ts +32 -30
- package/src/system-info/SystemInfo.ts +66 -47
- package/src/type-check/TypeChecker.ts +19 -5
- package/src/uuid-generator/UuidGenerator.ts +30 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapediver/viewer.shared.services",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Michael Oppitz <michael@shapediver.com>",
|
|
@@ -40,20 +40,17 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@ctrl/tinycolor": "^3.4.0",
|
|
43
|
-
"@sentry/browser": "^6.7.2",
|
|
44
|
-
"@sentry/tracing": "^6.7.2",
|
|
45
43
|
"@shapediver/sdk.geometry-api-sdk-v2": "1.3.0",
|
|
46
44
|
"@shapediver/viewer.settings": "0.3.0",
|
|
47
|
-
"@shapediver/viewer.shared.build-data": "2.
|
|
45
|
+
"@shapediver/viewer.shared.build-data": "2.8.1",
|
|
48
46
|
"@types/dompurify": "^2.3.1",
|
|
49
47
|
"@types/ua-parser-js": "^0.7.36",
|
|
50
|
-
"@types/uuid": "^
|
|
48
|
+
"@types/uuid": "^9.0.0",
|
|
51
49
|
"axios": "^1.2.6",
|
|
52
50
|
"dompurify": "^2.3.3",
|
|
53
51
|
"gl-matrix": "3.3.0",
|
|
54
|
-
"tsyringe": "^4.5.0",
|
|
55
52
|
"ua-parser-js": "^0.7.28",
|
|
56
|
-
"uuid": "^
|
|
53
|
+
"uuid": "^9.0.0"
|
|
57
54
|
},
|
|
58
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "0ec5dfbaed9b9fd24067bf1d64f1a8a925473034"
|
|
59
56
|
}
|
|
@@ -1,47 +1,26 @@
|
|
|
1
1
|
import { vec3, vec4 } from 'gl-matrix'
|
|
2
2
|
import { TinyColor } from '@ctrl/tinycolor'
|
|
3
|
-
import { container, singleton } from 'tsyringe'
|
|
4
3
|
import { HttpClient } from '../http-client/HttpClient';
|
|
5
4
|
import { HttpResponse } from '../http-client/HttpResponse';
|
|
6
5
|
|
|
7
|
-
@singleton()
|
|
8
6
|
export class Converter {
|
|
9
|
-
|
|
7
|
+
// #region Properties (2)
|
|
10
8
|
|
|
11
|
-
private
|
|
12
|
-
return color.toHex8String();
|
|
13
|
-
}
|
|
9
|
+
private readonly _httpClient: HttpClient = HttpClient.instance;
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
* @param color
|
|
17
|
-
* @param defColor
|
|
18
|
-
*/
|
|
19
|
-
public toHex8Color(color: any, defColorString: string = '#199b9b'): string {
|
|
20
|
-
const c = this.toHexColor(color, defColorString);
|
|
21
|
-
const tColor = new TinyColor(c);
|
|
22
|
-
const cH8 = tColor.toHex8String();
|
|
23
|
-
return cH8.replace('#', '0x');
|
|
24
|
-
}
|
|
11
|
+
private static _instance: Converter;
|
|
25
12
|
|
|
26
|
-
|
|
27
|
-
if(typeof color !== 'string' || !color.startsWith("#"))
|
|
28
|
-
color = this.toHexColor(color);
|
|
29
|
-
const tColor = new TinyColor(color);
|
|
30
|
-
const rgb = tColor.toRgb()
|
|
31
|
-
return [rgb.r / 255.0, rgb.g / 255.0, rgb.b / 255.0];
|
|
32
|
-
}
|
|
13
|
+
// #endregion Properties (2)
|
|
33
14
|
|
|
34
|
-
|
|
35
|
-
const c = this.toHexColor(color);
|
|
36
|
-
if (c.length <= 8) return 1;
|
|
37
|
-
return parseInt(c.slice(c.length - 2, c.length), 16) / 255;
|
|
38
|
-
}
|
|
15
|
+
// #region Public Static Accessors (1)
|
|
39
16
|
|
|
40
|
-
public
|
|
41
|
-
|
|
42
|
-
return c.slice(0, c.length - 2);
|
|
17
|
+
public static get instance() {
|
|
18
|
+
return this._instance || (this._instance = new this());
|
|
43
19
|
}
|
|
44
20
|
|
|
21
|
+
// #endregion Public Static Accessors (1)
|
|
22
|
+
|
|
23
|
+
// #region Public Methods (8)
|
|
45
24
|
|
|
46
25
|
public async processSVG(blob: Blob): Promise<HTMLImageElement> {
|
|
47
26
|
let data = <string>await new Promise((resolve, _) => {
|
|
@@ -168,6 +147,50 @@ export class Converter {
|
|
|
168
147
|
return img;
|
|
169
148
|
}
|
|
170
149
|
|
|
150
|
+
public async responseToImage(response: HttpResponse<ArrayBuffer>): Promise<HTMLImageElement> {
|
|
151
|
+
const arrayBufferView = new Uint8Array( response.data );
|
|
152
|
+
const blob = new Blob([ arrayBufferView ], { type: response.headers['content-type'] } );
|
|
153
|
+
if (response.headers['content-type'] === 'image/svg+xml') {
|
|
154
|
+
const img = await this.processSVG(blob);
|
|
155
|
+
return img;
|
|
156
|
+
} else {
|
|
157
|
+
const img = new Image();
|
|
158
|
+
const promise = new Promise<void>(resolve => {
|
|
159
|
+
img.onload = () => resolve();
|
|
160
|
+
})
|
|
161
|
+
img.crossOrigin = "anonymous";
|
|
162
|
+
img.src = URL.createObjectURL(blob);
|
|
163
|
+
await promise;
|
|
164
|
+
URL.revokeObjectURL(img.src);
|
|
165
|
+
return img;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public toAlpha(color: any): number {
|
|
170
|
+
const c = this.toHexColor(color);
|
|
171
|
+
if (c.length <= 8) return 1;
|
|
172
|
+
return parseInt(c.slice(c.length - 2, c.length), 16) / 255;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
public toColorArray(color: any): number[] {
|
|
176
|
+
if(typeof color !== 'string' || !color.startsWith("#"))
|
|
177
|
+
color = this.toHexColor(color);
|
|
178
|
+
const tColor = new TinyColor(color);
|
|
179
|
+
const rgb = tColor.toRgb()
|
|
180
|
+
return [rgb.r / 255.0, rgb.g / 255.0, rgb.b / 255.0];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @param color
|
|
185
|
+
* @param defColor
|
|
186
|
+
*/
|
|
187
|
+
public toHex8Color(color: any, defColorString: string = '#199b9b'): string {
|
|
188
|
+
const c = this.toHexColor(color, defColorString);
|
|
189
|
+
const tColor = new TinyColor(c);
|
|
190
|
+
const cH8 = tColor.toHex8String();
|
|
191
|
+
return cH8.replace('#', '0x');
|
|
192
|
+
}
|
|
193
|
+
|
|
171
194
|
/**
|
|
172
195
|
* This color converter is mostly left 'as-is' from viewer v2.
|
|
173
196
|
* I didn't want to break something that works.
|
|
@@ -262,6 +285,11 @@ export class Converter {
|
|
|
262
285
|
return tc.isValid ? this.tinyColorToString(tc) : defColorString;
|
|
263
286
|
}
|
|
264
287
|
|
|
288
|
+
public toThreeJsColorInput(color: any): string {
|
|
289
|
+
const c = this.toHexColor(color);
|
|
290
|
+
return c.slice(0, c.length - 2);
|
|
291
|
+
}
|
|
292
|
+
|
|
265
293
|
public toVec3(point: any): vec3 {
|
|
266
294
|
if (Array.isArray(point) && point.length >= 3 && typeof point[0] === 'number' && typeof point[1] === 'number' && typeof point[2] === 'number')
|
|
267
295
|
return vec3.fromValues(point[0], point[1], point[2]);
|
|
@@ -275,21 +303,13 @@ export class Converter {
|
|
|
275
303
|
return vec3.create();
|
|
276
304
|
}
|
|
277
305
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
} else {
|
|
285
|
-
const img = new Image();
|
|
286
|
-
const promise = new Promise<void>(resolve => {
|
|
287
|
-
img.onload = () => resolve();
|
|
288
|
-
})
|
|
289
|
-
img.crossOrigin = "anonymous";
|
|
290
|
-
img.src = URL.createObjectURL(blob);
|
|
291
|
-
await promise;
|
|
292
|
-
return img;
|
|
293
|
-
}
|
|
306
|
+
// #endregion Public Methods (8)
|
|
307
|
+
|
|
308
|
+
// #region Private Methods (1)
|
|
309
|
+
|
|
310
|
+
private tinyColorToString(color: TinyColor): string {
|
|
311
|
+
return color.toHex8String();
|
|
294
312
|
}
|
|
313
|
+
|
|
314
|
+
// #endregion Private Methods (1)
|
|
295
315
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { container } from 'tsyringe'
|
|
2
1
|
import { UuidGenerator } from '../uuid-generator/UuidGenerator';
|
|
3
2
|
|
|
4
3
|
import { IDomEventListener } from './IDomEventListener'
|
|
@@ -9,7 +8,7 @@ export class DomEventEngine {
|
|
|
9
8
|
private readonly _domEventListeners: {
|
|
10
9
|
[key: string]: IDomEventListener
|
|
11
10
|
} = {};
|
|
12
|
-
private readonly _uuidGenerator: UuidGenerator =
|
|
11
|
+
private readonly _uuidGenerator: UuidGenerator = UuidGenerator.instance;
|
|
13
12
|
|
|
14
13
|
private _allowListeners = {
|
|
15
14
|
mousewheel: true,
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { container, singleton } from 'tsyringe'
|
|
2
|
-
|
|
3
1
|
import { EVENTTYPE, MainEventTypes } from './EventTypes'
|
|
4
2
|
import { IListener } from './interfaces/IListener'
|
|
5
3
|
import { ICallback } from './interfaces/ICallback'
|
|
6
4
|
import { IEvent } from './interfaces/IEvent'
|
|
7
5
|
import { UuidGenerator } from '../uuid-generator/UuidGenerator'
|
|
8
|
-
import { Logger
|
|
6
|
+
import { Logger } from '../logger/Logger'
|
|
9
7
|
|
|
10
|
-
@singleton()
|
|
11
8
|
export class EventEngine {
|
|
12
|
-
// #region Properties (
|
|
9
|
+
// #region Properties (4)
|
|
10
|
+
|
|
11
|
+
private static _instance: EventEngine;
|
|
13
12
|
|
|
14
|
-
protected readonly _uuidGenerator: UuidGenerator = <UuidGenerator>container.resolve(UuidGenerator);
|
|
15
|
-
protected readonly _logger: Logger = <Logger>container.resolve(Logger);
|
|
16
13
|
private _eventListeners: {
|
|
17
14
|
[key: string]: IListener[]
|
|
18
15
|
};
|
|
19
16
|
|
|
20
|
-
|
|
17
|
+
protected readonly _logger: Logger = Logger.instance;
|
|
18
|
+
protected readonly _uuidGenerator: UuidGenerator = UuidGenerator.instance;
|
|
19
|
+
|
|
20
|
+
// #endregion Properties (4)
|
|
21
21
|
|
|
22
22
|
// #region Constructors (1)
|
|
23
23
|
|
|
24
|
-
constructor() {
|
|
24
|
+
private constructor() {
|
|
25
25
|
this._eventListeners = {};
|
|
26
26
|
for (const type in EVENTTYPE) {
|
|
27
27
|
const subEventType = EVENTTYPE[type as keyof typeof EVENTTYPE];
|
|
@@ -34,22 +34,14 @@ export class EventEngine {
|
|
|
34
34
|
|
|
35
35
|
// #endregion Constructors (1)
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
let typeString: string = '';
|
|
39
|
-
if(typeof type === 'string') typeString = type;
|
|
37
|
+
// #region Public Static Accessors (1)
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
typeString = mainType.toLowerCase();
|
|
44
|
-
|
|
45
|
-
if(!typeString || !this._eventListeners[typeString]) {
|
|
46
|
-
this._logger.warn(LOGGING_TOPIC.GENERAL, 'EventEngine.convertTypeToString: No valid type provided.');
|
|
47
|
-
return '';
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return typeString;
|
|
39
|
+
public static get instance() {
|
|
40
|
+
return this._instance || (this._instance = new this());
|
|
51
41
|
}
|
|
52
42
|
|
|
43
|
+
// #endregion Public Static Accessors (1)
|
|
44
|
+
|
|
53
45
|
// #region Public Methods (3)
|
|
54
46
|
|
|
55
47
|
/**
|
|
@@ -116,4 +108,24 @@ export class EventEngine {
|
|
|
116
108
|
}
|
|
117
109
|
|
|
118
110
|
// #endregion Public Methods (3)
|
|
111
|
+
|
|
112
|
+
// #region Private Methods (1)
|
|
113
|
+
|
|
114
|
+
private convertTypeToString(type: string | MainEventTypes): string {
|
|
115
|
+
let typeString: string = '';
|
|
116
|
+
if(typeof type === 'string') typeString = type;
|
|
117
|
+
|
|
118
|
+
for (const mainType in EVENTTYPE)
|
|
119
|
+
if(type === EVENTTYPE[mainType as keyof typeof EVENTTYPE])
|
|
120
|
+
typeString = mainType.toLowerCase();
|
|
121
|
+
|
|
122
|
+
if(!typeString || !this._eventListeners[typeString]) {
|
|
123
|
+
this._logger.warn('EventEngine.convertTypeToString: No valid type provided.');
|
|
124
|
+
return '';
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return typeString;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// #endregion Private Methods (1)
|
|
119
131
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'
|
|
2
|
-
import { singleton } from 'tsyringe'
|
|
3
2
|
import { ShapeDiverViewerConnectionError } from '../logger/ShapeDiverViewerErrors';
|
|
4
3
|
import { HttpResponse } from './HttpResponse';
|
|
5
4
|
|
|
@@ -17,13 +16,10 @@ const errorHandler = (error: any) => {
|
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
@singleton()
|
|
21
19
|
export class HttpClient {
|
|
22
|
-
// #region Properties (
|
|
20
|
+
// #region Properties (3)
|
|
23
21
|
|
|
24
|
-
private
|
|
25
|
-
[key: string]: Promise<HttpResponse<any>>
|
|
26
|
-
} = {};
|
|
22
|
+
private static _instance: HttpClient;
|
|
27
23
|
|
|
28
24
|
private _sessionLoading: {
|
|
29
25
|
[key: string]: {
|
|
@@ -32,11 +28,11 @@ export class HttpClient {
|
|
|
32
28
|
}
|
|
33
29
|
} = {};
|
|
34
30
|
|
|
35
|
-
// #endregion Properties (
|
|
31
|
+
// #endregion Properties (3)
|
|
36
32
|
|
|
37
33
|
// #region Constructors (1)
|
|
38
34
|
|
|
39
|
-
constructor() {
|
|
35
|
+
private constructor() {
|
|
40
36
|
axios.interceptors.response.use(
|
|
41
37
|
response => {
|
|
42
38
|
return response;
|
|
@@ -55,23 +51,16 @@ export class HttpClient {
|
|
|
55
51
|
|
|
56
52
|
// #endregion Constructors (1)
|
|
57
53
|
|
|
58
|
-
// #region Public
|
|
54
|
+
// #region Public Static Accessors (1)
|
|
59
55
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const parts = href.split('/');
|
|
63
|
-
const sessionPartIndex = parts.indexOf('session');
|
|
64
|
-
|
|
65
|
-
// There have to be at exactly 4 parts, including the session
|
|
66
|
-
if (sessionPartIndex !== -1 && parts.length === sessionPartIndex + 4) {
|
|
67
|
-
const sessionId = parts[sessionPartIndex + 1];
|
|
68
|
-
// no such session has been registered, should never happen
|
|
69
|
-
if (!this._sessionLoading[sessionId]) return;
|
|
70
|
-
return sessionId;
|
|
71
|
-
}
|
|
72
|
-
return;
|
|
56
|
+
public static get instance() {
|
|
57
|
+
return this._instance || (this._instance = new this());
|
|
73
58
|
}
|
|
74
59
|
|
|
60
|
+
// #endregion Public Static Accessors (1)
|
|
61
|
+
|
|
62
|
+
// #region Public Methods (4)
|
|
63
|
+
|
|
75
64
|
public addDataLoading(sessionId: string, callbacks: {
|
|
76
65
|
getAsset: (url: string) => Promise<[ArrayBuffer, string, string]>,
|
|
77
66
|
downloadTexture: (sessionId: string, url: string) => Promise<[ArrayBuffer, string]>,
|
|
@@ -80,9 +69,6 @@ export class HttpClient {
|
|
|
80
69
|
}
|
|
81
70
|
|
|
82
71
|
public async get(href: string, config: AxiosRequestConfig = { responseType: 'arraybuffer' }, textureLoading: boolean = false): Promise<HttpResponse<any>> {
|
|
83
|
-
const dataKey = btoa(href);
|
|
84
|
-
if (dataKey in this._dataCache) return await this._dataCache[dataKey];
|
|
85
|
-
|
|
86
72
|
// try to get sessionId from href
|
|
87
73
|
let sessionId = this.getSessionId(href);
|
|
88
74
|
|
|
@@ -103,7 +89,7 @@ export class HttpClient {
|
|
|
103
89
|
// if we have a sessionId and the sessionLoading functions and the image is not a blob or data, we load it via the sdk
|
|
104
90
|
if(sessionLoading !== undefined && sessionId !== undefined && !href.startsWith('blob:') && !href.startsWith('data:')) {
|
|
105
91
|
// take first session to load a texture that is not session related
|
|
106
|
-
|
|
92
|
+
return new Promise<HttpResponse<any>>((resolve, reject) => {
|
|
107
93
|
sessionLoading!.downloadTexture(sessionId!, href).then((result) => {
|
|
108
94
|
resolve({
|
|
109
95
|
data: result[0],
|
|
@@ -118,15 +104,15 @@ export class HttpClient {
|
|
|
118
104
|
} else {
|
|
119
105
|
// we can load blobs and data urls directly
|
|
120
106
|
// or load it directly if we don't have a session
|
|
121
|
-
|
|
107
|
+
return axios(href, Object.assign({ method: 'get' }, config));
|
|
122
108
|
}
|
|
123
109
|
} else {
|
|
124
110
|
if(!sessionLoading) {
|
|
125
111
|
// if there is no session to load from, we use the fallback option
|
|
126
|
-
|
|
112
|
+
return axios(href, Object.assign({ method: 'get' }, config));
|
|
127
113
|
} else {
|
|
128
114
|
// all data links where we could somehow find a session to load it with
|
|
129
|
-
|
|
115
|
+
return new Promise<HttpResponse<ArrayBuffer>>((resolve, reject) => {
|
|
130
116
|
sessionLoading!.getAsset(href)
|
|
131
117
|
.then((result) => {
|
|
132
118
|
resolve({
|
|
@@ -143,8 +129,6 @@ export class HttpClient {
|
|
|
143
129
|
});
|
|
144
130
|
}
|
|
145
131
|
}
|
|
146
|
-
|
|
147
|
-
return this._dataCache[dataKey];
|
|
148
132
|
}
|
|
149
133
|
|
|
150
134
|
public async loadTexture(href: string): Promise<HttpResponse<ArrayBuffer>> {
|
|
@@ -155,5 +139,24 @@ export class HttpClient {
|
|
|
155
139
|
delete this._sessionLoading[sessionId];
|
|
156
140
|
}
|
|
157
141
|
|
|
158
|
-
// #endregion Public Methods (
|
|
142
|
+
// #endregion Public Methods (4)
|
|
143
|
+
|
|
144
|
+
// #region Private Methods (1)
|
|
145
|
+
|
|
146
|
+
private getSessionId(href: string): string | undefined {
|
|
147
|
+
// searching for "/session/SESSION_ID/{'output' | 'export' | 'texture'}/ASSET_DATA"
|
|
148
|
+
const parts = href.split('/');
|
|
149
|
+
const sessionPartIndex = parts.indexOf('session');
|
|
150
|
+
|
|
151
|
+
// There have to be at exactly 4 parts, including the session
|
|
152
|
+
if (sessionPartIndex !== -1 && parts.length === sessionPartIndex + 4) {
|
|
153
|
+
const sessionId = parts[sessionPartIndex + 1];
|
|
154
|
+
// no such session has been registered, should never happen
|
|
155
|
+
if (!this._sessionLoading[sessionId]) return;
|
|
156
|
+
return sessionId;
|
|
157
|
+
}
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// #endregion Private Methods (1)
|
|
159
162
|
}
|
package/src/index.ts
CHANGED
|
@@ -12,9 +12,9 @@ import { InputValidator } from './input-validator/InputValidator'
|
|
|
12
12
|
import { TypeChecker } from './type-check/TypeChecker'
|
|
13
13
|
import { UuidGenerator } from './uuid-generator/UuidGenerator'
|
|
14
14
|
import { PerformanceEvaluator } from './performance-evaluator/PerformanceEvaluator'
|
|
15
|
-
import { Logger, LOGGING_LEVEL
|
|
15
|
+
import { Logger, LOGGING_LEVEL } from './logger/Logger'
|
|
16
16
|
import { StatePromise } from './state-engine/StatePromise'
|
|
17
|
-
import { ShapeDiverViewerArError, ShapeDiverViewerCameraError, ShapeDiverViewerDataProcessingError, ShapeDiverViewerEnvironmentMapError, ShapeDiverViewerLightError, ShapeDiverViewerSessionError, ShapeDiverViewerSettingsError, ShapeDiverViewerUnknownError, ShapeDiverViewerValidationError, ShapeDiverViewerGeneralError, ShapeDiverViewerWebGLError, ShapeDiverViewerInteractionError } from './logger/ShapeDiverViewerErrors'
|
|
17
|
+
import { ShapeDiverViewerArError, ShapeDiverViewerCameraError, ShapeDiverViewerDataProcessingError, ShapeDiverViewerEnvironmentMapError, ShapeDiverViewerLightError, ShapeDiverViewerSessionError, ShapeDiverViewerSettingsError, ShapeDiverViewerUnknownError, ShapeDiverViewerValidationError, ShapeDiverViewerGeneralError, ShapeDiverViewerWebGLError, ShapeDiverViewerInteractionError, ShapeDiverViewerViewportError } from './logger/ShapeDiverViewerErrors'
|
|
18
18
|
import { ShapeDiverError as ShapeDiverBackendError } from '@shapediver/sdk.geometry-api-sdk-v2'
|
|
19
19
|
import { ShapeDiverViewerError } from './logger/ShapeDiverError'
|
|
20
20
|
import { HttpResponse } from './http-client/HttpResponse'
|
|
@@ -61,13 +61,14 @@ export {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
export {
|
|
64
|
-
Logger, LOGGING_LEVEL,
|
|
64
|
+
Logger, LOGGING_LEVEL,
|
|
65
65
|
ShapeDiverViewerError,
|
|
66
66
|
ShapeDiverViewerDataProcessingError,
|
|
67
67
|
ShapeDiverViewerEnvironmentMapError,
|
|
68
68
|
ShapeDiverViewerWebGLError,
|
|
69
69
|
ShapeDiverViewerSettingsError,
|
|
70
70
|
ShapeDiverViewerSessionError,
|
|
71
|
+
ShapeDiverViewerViewportError,
|
|
71
72
|
ShapeDiverViewerGeneralError,
|
|
72
73
|
ShapeDiverViewerUnknownError,
|
|
73
74
|
ShapeDiverViewerArError,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { container, singleton } from 'tsyringe'
|
|
2
1
|
import DOMPurify from 'dompurify';
|
|
3
|
-
import { Logger
|
|
2
|
+
import { Logger } from '../logger/Logger'
|
|
4
3
|
import { ShapeDiverViewerValidationError } from '../logger/ShapeDiverViewerErrors';
|
|
5
4
|
import { TypeChecker } from '../type-check/TypeChecker'
|
|
6
5
|
|
|
@@ -9,20 +8,41 @@ export type Types = 'string' | 'boolean' | 'function' |
|
|
|
9
8
|
'number' | 'factor' | 'positive' |
|
|
10
9
|
'vec3' | 'mat4' | 'cubeMap' | 'array' | 'stringArray' | 'object' | 'file' | 'color';
|
|
11
10
|
|
|
12
|
-
@singleton()
|
|
13
11
|
export class InputValidator {
|
|
12
|
+
// #region Properties (3)
|
|
14
13
|
|
|
15
|
-
private readonly _logger: Logger =
|
|
16
|
-
private readonly _typeChecker: TypeChecker =
|
|
14
|
+
private readonly _logger: Logger = Logger.instance;
|
|
15
|
+
private readonly _typeChecker: TypeChecker = TypeChecker.instance;
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
private static _instance: InputValidator;
|
|
18
|
+
|
|
19
|
+
// #endregion Properties (3)
|
|
20
|
+
|
|
21
|
+
// #region Public Static Accessors (1)
|
|
22
|
+
|
|
23
|
+
public static get instance() {
|
|
24
|
+
return this._instance || (this._instance = new this());
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// #endregion Public Static Accessors (1)
|
|
28
|
+
|
|
29
|
+
// #region Public Methods (2)
|
|
30
|
+
|
|
31
|
+
public sanitize(input: string): string {
|
|
32
|
+
return DOMPurify.sanitize(input);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public validateAndError(scope: string, value: any, type: Types, defined: boolean = true, enumValues: string[] = []) {
|
|
19
36
|
const res = this.validate(value, type, defined, enumValues);
|
|
20
37
|
if(res) return;
|
|
21
38
|
|
|
22
|
-
|
|
23
|
-
throw this._logger.handleError(LOGGING_TOPIC.GENERAL, 'InputValidator.validateAndError', error, false);
|
|
39
|
+
throw new ShapeDiverViewerValidationError(`${scope}: Input could not be validated. ${value} is not of type ${type}.${defined === false ? ' (Can also be undefined)' : ''}`, value, type);
|
|
24
40
|
}
|
|
25
41
|
|
|
42
|
+
// #endregion Public Methods (2)
|
|
43
|
+
|
|
44
|
+
// #region Private Methods (1)
|
|
45
|
+
|
|
26
46
|
private validate(value: any, stringLiteral: Types, defined: boolean = true, enumValues: string[] = []): boolean {
|
|
27
47
|
if (defined === false && typeof value === 'undefined') return true;
|
|
28
48
|
|
|
@@ -94,7 +114,5 @@ export class InputValidator {
|
|
|
94
114
|
return false;
|
|
95
115
|
}
|
|
96
116
|
|
|
97
|
-
|
|
98
|
-
return DOMPurify.sanitize(input);
|
|
99
|
-
}
|
|
117
|
+
// #endregion Private Methods (1)
|
|
100
118
|
}
|