@shapediver/viewer.shared.services 1.15.7 → 2.0.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/converter/Converter.js +1 -1
- package/dist/converter/Converter.js.map +1 -1
- package/dist/dom-event-engine/DomEventEngine.d.ts +1 -2
- 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 +3 -3
- package/dist/event-engine/EventEngine.d.ts.map +1 -1
- package/dist/event-engine/EventEngine.js +2 -2
- package/dist/event-engine/EventEngine.js.map +1 -1
- package/dist/event-engine/EventTypes.d.ts +20 -24
- package/dist/event-engine/EventTypes.d.ts.map +1 -1
- package/dist/event-engine/EventTypes.js +55 -85
- package/dist/event-engine/EventTypes.js.map +1 -1
- package/dist/http-client/HttpClient.d.ts.map +1 -1
- package/dist/http-client/HttpClient.js +5 -5
- package/dist/http-client/HttpClient.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -3
- package/dist/index.js.map +1 -1
- package/dist/input-validator/InputValidator.d.ts +3 -3
- package/dist/input-validator/InputValidator.d.ts.map +1 -1
- package/dist/input-validator/InputValidator.js +6 -2
- package/dist/input-validator/InputValidator.js.map +1 -1
- package/dist/logger/Logger.d.ts +16 -16
- package/dist/logger/Logger.d.ts.map +1 -1
- package/dist/logger/Logger.js +77 -76
- package/dist/logger/Logger.js.map +1 -1
- package/dist/logger/ShapeDiverError.d.ts +1 -1
- package/dist/logger/ShapeDiverError.d.ts.map +1 -1
- package/dist/logger/ShapeDiverError.js +1 -1
- package/dist/logger/ShapeDiverError.js.map +1 -1
- package/dist/logger/ShapeDiverViewerErrors.d.ts +24 -24
- package/dist/logger/ShapeDiverViewerErrors.d.ts.map +1 -1
- package/dist/logger/ShapeDiverViewerErrors.js +1 -1
- package/dist/logger/ShapeDiverViewerErrors.js.map +1 -1
- package/dist/performance-evaluator/PerformanceEvaluator.js +1 -1
- package/dist/performance-evaluator/PerformanceEvaluator.js.map +1 -1
- package/dist/settings-engine/SettingsEngine.d.ts +1 -1
- package/dist/settings-engine/SettingsEngine.d.ts.map +1 -1
- package/dist/settings-engine/SettingsEngine.js +16 -25
- package/dist/settings-engine/SettingsEngine.js.map +1 -1
- package/dist/state-engine/StateEngine.d.ts +7 -16
- package/dist/state-engine/StateEngine.d.ts.map +1 -1
- package/dist/state-engine/StateEngine.js +8 -21
- package/dist/state-engine/StateEngine.js.map +1 -1
- package/dist/system-info/SystemInfo.js +1 -1
- package/dist/system-info/SystemInfo.js.map +1 -1
- package/dist/type-check/TypeChecker.js +1 -1
- package/dist/type-check/TypeChecker.js.map +1 -1
- package/dist/uuid-generator/UuidGenerator.js +5 -5
- package/dist/uuid-generator/UuidGenerator.js.map +1 -1
- package/package.json +11 -8
- package/src/converter/Converter.ts +299 -0
- package/src/dom-event-engine/DomEventEngine.ts +334 -0
- package/src/dom-event-engine/IDomEventListener.ts +14 -0
- package/src/event-engine/EventEngine.ts +116 -0
- package/src/event-engine/EventTypes.ts +66 -0
- package/src/event-engine/interfaces/ICallback.ts +5 -0
- package/src/event-engine/interfaces/IEvent.ts +1 -0
- package/src/event-engine/interfaces/IListener.ts +8 -0
- package/src/http-client/HttpClient.ts +177 -0
- package/src/http-client/HttpResponse.ts +4 -0
- package/src/index.ts +82 -0
- package/src/input-validator/InputValidator.ts +100 -0
- package/src/logger/Logger.ts +297 -0
- package/src/logger/ShapeDiverError.ts +48 -0
- package/src/logger/ShapeDiverViewerErrors.ts +115 -0
- package/src/performance-evaluator/PerformanceEvaluator.ts +102 -0
- package/src/settings-engine/SettingsEngine.ts +176 -0
- package/src/state-engine/StateEngine.ts +73 -0
- package/src/state-engine/StatePromise.ts +54 -0
- package/src/system-info/SystemInfo.ts +117 -0
- package/src/type-check/TypeChecker.ts +13 -0
- package/src/uuid-generator/UuidGenerator.ts +41 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { convert, validate, DefaultsV3_1, ISettingsV3_1 } from '@shapediver/viewer.settings';
|
|
2
|
+
import { container, singleton } from 'tsyringe'
|
|
3
|
+
|
|
4
|
+
import { EventEngine } from '../event-engine/EventEngine'
|
|
5
|
+
import { Logger, LOGGING_TOPIC } from '../logger/Logger';
|
|
6
|
+
import { ShapeDiverViewerSettingsError } from '../logger/ShapeDiverViewerErrors';
|
|
7
|
+
|
|
8
|
+
type IARSettings = ISettingsV3_1["ar"];
|
|
9
|
+
type ICameraSettings = ISettingsV3_1["camera"];
|
|
10
|
+
type IEnvironmentSettings = ISettingsV3_1["environment"];
|
|
11
|
+
type IEnvironmentGeometrySettings = ISettingsV3_1["environmentGeometry"];
|
|
12
|
+
type IGeneralSettings = ISettingsV3_1["general"];
|
|
13
|
+
type ILightSettings = ISettingsV3_1["light"];
|
|
14
|
+
type IRenderingSettings = ISettingsV3_1["rendering"];
|
|
15
|
+
type ISessionSettings = ISettingsV3_1["session"];
|
|
16
|
+
|
|
17
|
+
export class SettingsEngine {
|
|
18
|
+
// #region Properties (8)
|
|
19
|
+
|
|
20
|
+
private readonly _eventEngine: EventEngine = <EventEngine>container.resolve(EventEngine);
|
|
21
|
+
private readonly _logger: Logger = <Logger>container.resolve(Logger);
|
|
22
|
+
private readonly _settings: ISettingsV3_1 = DefaultsV3_1();
|
|
23
|
+
private _settings_version: '1.0' | '2.0' | '3.0' | '3.1' = '3.1';
|
|
24
|
+
|
|
25
|
+
// #endregion Properties (8)
|
|
26
|
+
|
|
27
|
+
// #region Public Accessors (10)
|
|
28
|
+
|
|
29
|
+
public get ar(): IARSettings {
|
|
30
|
+
return this._settings.ar;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public get camera(): ICameraSettings {
|
|
34
|
+
return this._settings.camera;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public get environment(): IEnvironmentSettings {
|
|
38
|
+
return this._settings.environment;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public get environmentGeometry(): IEnvironmentGeometrySettings {
|
|
42
|
+
return this._settings.environmentGeometry;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public get general(): IGeneralSettings {
|
|
46
|
+
return this._settings.general;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public get light(): ILightSettings {
|
|
50
|
+
return this._settings.light;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public get rendering(): IRenderingSettings {
|
|
54
|
+
return this._settings.rendering;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public get session(): ISessionSettings {
|
|
58
|
+
return this._settings.session;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public set session(value: ISessionSettings) {
|
|
62
|
+
this._settings.session = value;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public get settings(): ISettingsV3_1 {
|
|
66
|
+
return this._settings;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// #endregion Public Accessors (10)
|
|
70
|
+
|
|
71
|
+
// #region Public Methods (4)
|
|
72
|
+
|
|
73
|
+
public convertToTargetVersion(): any {
|
|
74
|
+
return convert(this._settings, this._settings_version);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public flatten() {
|
|
78
|
+
const flattenObject = (ob: any) => {
|
|
79
|
+
const toReturn: { [key: string]: any } = {};
|
|
80
|
+
for (let i in ob) {
|
|
81
|
+
if (!ob.hasOwnProperty(i)) continue;
|
|
82
|
+
if ((typeof ob[i]) == 'object') {
|
|
83
|
+
const flatObject = flattenObject(ob[i]);
|
|
84
|
+
for (var x in flatObject) {
|
|
85
|
+
if (!flatObject.hasOwnProperty(x)) continue;
|
|
86
|
+
toReturn[i + '.' + x] = flatObject[x];
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
toReturn[i] = ob[i];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return toReturn;
|
|
93
|
+
};
|
|
94
|
+
return flattenObject(this.settings);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public loadSettings(json: any) {
|
|
98
|
+
if (JSON.stringify(json) !== JSON.stringify({})) {
|
|
99
|
+
try {
|
|
100
|
+
validate(json, '1.0');
|
|
101
|
+
this._settings_version = '1.0';
|
|
102
|
+
(<any>this._settings) = convert(json, '3.1');
|
|
103
|
+
this.cleanSettings(this._settings);
|
|
104
|
+
return;
|
|
105
|
+
} catch (e) {}
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
validate(json, '2.0');
|
|
109
|
+
this._settings_version = '2.0';
|
|
110
|
+
(<any>this._settings) = convert(json, '3.1');
|
|
111
|
+
this.cleanSettings(this._settings);
|
|
112
|
+
return;
|
|
113
|
+
} catch (e) {}
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
validate(json, '3.0');
|
|
117
|
+
this._settings_version = '3.0';
|
|
118
|
+
(<any>this._settings) = convert(json, '3.1');
|
|
119
|
+
this.cleanSettings(this._settings);
|
|
120
|
+
return;
|
|
121
|
+
} catch (e) {}
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
validate(json, '3.1');
|
|
125
|
+
this._settings_version = '3.1';
|
|
126
|
+
(<any>this._settings) = convert(json, '3.1');
|
|
127
|
+
this.cleanSettings(this._settings);
|
|
128
|
+
return;
|
|
129
|
+
} catch (e) {
|
|
130
|
+
const error = new ShapeDiverViewerSettingsError('SettingsEngine.loadSettings: Settings could not be validated.', <Error>e);
|
|
131
|
+
throw this._logger.handleError(LOGGING_TOPIC.SETTINGS, `SettingsEngine.loadSettings`, error);
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
this._settings_version = '3.1';
|
|
135
|
+
(<any>this._settings) = DefaultsV3_1();
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
public reset() {
|
|
141
|
+
this._settings_version = '3.1';
|
|
142
|
+
(<any>this._settings) = DefaultsV3_1();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// #endregion Public Methods (4)
|
|
146
|
+
|
|
147
|
+
// #region Private Methods (1)
|
|
148
|
+
|
|
149
|
+
private cleanSettings(json: ISettingsV3_1) {
|
|
150
|
+
for(let c in json.camera.cameras) {
|
|
151
|
+
const camera = json.camera.cameras[c];
|
|
152
|
+
if(camera.type === 'perspective') {
|
|
153
|
+
const restrictions = (<any>camera.controls).restrictions;
|
|
154
|
+
if(restrictions.position.cube.min.x === null) restrictions.position.cube.min.x = -Infinity;
|
|
155
|
+
if(restrictions.position.cube.min.y === null) restrictions.position.cube.min.y = -Infinity;
|
|
156
|
+
if(restrictions.position.cube.min.z === null) restrictions.position.cube.min.z = -Infinity;
|
|
157
|
+
if(restrictions.position.cube.max.x === null) restrictions.position.cube.max.x = Infinity;
|
|
158
|
+
if(restrictions.position.cube.max.y === null) restrictions.position.cube.max.y = Infinity;
|
|
159
|
+
if(restrictions.position.cube.max.z === null) restrictions.position.cube.max.z = Infinity;
|
|
160
|
+
if(restrictions.position.sphere.radius === null) restrictions.position.sphere.radius = Infinity;
|
|
161
|
+
if(restrictions.target.cube.min.x === null) restrictions.target.cube.min.x = -Infinity;
|
|
162
|
+
if(restrictions.target.cube.min.y === null) restrictions.target.cube.min.y = -Infinity;
|
|
163
|
+
if(restrictions.target.cube.min.z === null) restrictions.target.cube.min.z = -Infinity;
|
|
164
|
+
if(restrictions.target.cube.max.x === null) restrictions.target.cube.max.x = Infinity;
|
|
165
|
+
if(restrictions.target.cube.max.y === null) restrictions.target.cube.max.y = Infinity;
|
|
166
|
+
if(restrictions.target.cube.max.z === null) restrictions.target.cube.max.z = Infinity;
|
|
167
|
+
if(restrictions.target.sphere.radius === null) restrictions.target.sphere.radius = Infinity;
|
|
168
|
+
if(restrictions.rotation.minAzimuthAngle === null) restrictions.rotation.minAzimuthAngle = -Infinity;
|
|
169
|
+
if(restrictions.rotation.maxAzimuthAngle === null) restrictions.rotation.maxAzimuthAngle = Infinity;
|
|
170
|
+
if(restrictions.zoom.maxDistance === null) restrictions.zoom.maxDistance = Infinity;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// #endregion Private Methods (1)
|
|
176
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { container, singleton } from 'tsyringe'
|
|
2
|
+
|
|
3
|
+
import { EventEngine } from '../index'
|
|
4
|
+
import { StatePromise } from './StatePromise'
|
|
5
|
+
|
|
6
|
+
@singleton()
|
|
7
|
+
export class StateEngine {
|
|
8
|
+
// #region Properties (8)
|
|
9
|
+
|
|
10
|
+
private readonly _customStates: {
|
|
11
|
+
[key: string]: StatePromise<boolean>
|
|
12
|
+
} = {};
|
|
13
|
+
private readonly _eventEngine: EventEngine = <EventEngine>container.resolve(EventEngine);
|
|
14
|
+
private readonly _fontLoaded: StatePromise<boolean>;
|
|
15
|
+
private readonly _sessionEngines: {
|
|
16
|
+
[key: string]: {
|
|
17
|
+
id: string,
|
|
18
|
+
initialized: StatePromise<boolean>,
|
|
19
|
+
settingsRegistered: StatePromise<boolean>,
|
|
20
|
+
}
|
|
21
|
+
} = {};
|
|
22
|
+
private readonly _renderingEngines: {
|
|
23
|
+
[key: string]: {
|
|
24
|
+
id: string,
|
|
25
|
+
initialized: StatePromise<boolean>,
|
|
26
|
+
settingsAssigned: StatePromise<boolean>,
|
|
27
|
+
environmentMapLoaded: StatePromise<boolean>,
|
|
28
|
+
boundingBoxCreated: StatePromise<boolean>,
|
|
29
|
+
busy: string[]
|
|
30
|
+
}
|
|
31
|
+
} = {};
|
|
32
|
+
|
|
33
|
+
// #endregion Properties (8)
|
|
34
|
+
|
|
35
|
+
// #region Constructors (1)
|
|
36
|
+
|
|
37
|
+
constructor() {
|
|
38
|
+
this._fontLoaded = new StatePromise();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// #endregion Constructors (1)
|
|
42
|
+
|
|
43
|
+
// #region Public Accessors (7)
|
|
44
|
+
|
|
45
|
+
public get fontLoaded(): StatePromise<boolean> {
|
|
46
|
+
return this._fontLoaded;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public get sessionEngines(): {
|
|
50
|
+
[key: string]: {
|
|
51
|
+
id: string,
|
|
52
|
+
initialized: StatePromise<boolean>,
|
|
53
|
+
settingsRegistered: StatePromise<boolean>,
|
|
54
|
+
}
|
|
55
|
+
} {
|
|
56
|
+
return this._sessionEngines;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public get renderingEngines(): {
|
|
60
|
+
[key: string]: {
|
|
61
|
+
id: string,
|
|
62
|
+
initialized: StatePromise<boolean>,
|
|
63
|
+
settingsAssigned: StatePromise<boolean>,
|
|
64
|
+
environmentMapLoaded: StatePromise<boolean>,
|
|
65
|
+
boundingBoxCreated: StatePromise<boolean>,
|
|
66
|
+
busy: string[]
|
|
67
|
+
}
|
|
68
|
+
} {
|
|
69
|
+
return this._renderingEngines;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// #endregion Public Accessors (7)
|
|
73
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export class StatePromise<T> {
|
|
2
|
+
private _resolved: boolean = false;
|
|
3
|
+
private _resolve!: (value: T | PromiseLike<T>) => void;
|
|
4
|
+
private _reject!: (value: T | PromiseLike<T>) => void;
|
|
5
|
+
|
|
6
|
+
private _promise: Promise<T>;
|
|
7
|
+
private _callbacks: (() => void)[] = [];
|
|
8
|
+
|
|
9
|
+
constructor() {
|
|
10
|
+
this._promise = new Promise((resolve, reject) => {
|
|
11
|
+
this._resolve = resolve;
|
|
12
|
+
this._reject = reject;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
this._promise.finally(() => {
|
|
16
|
+
this._resolved = true;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public get resolved(): boolean {
|
|
21
|
+
return this._resolved;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public get resolve(): (value: T | PromiseLike<T>) => void {
|
|
25
|
+
return this._resolve;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public get reject(): (value: T | PromiseLike<T>) => void {
|
|
29
|
+
return this._reject;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public async then(callback: () => void ) {
|
|
33
|
+
this._callbacks.push(callback);
|
|
34
|
+
this.resolved === true ? callback() : this._promise.then(callback);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public reset() {
|
|
38
|
+
this._resolved = false;
|
|
39
|
+
|
|
40
|
+
this._promise = new Promise((resolve, reject) => {
|
|
41
|
+
this._resolve = resolve;
|
|
42
|
+
this._reject = reject;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
this._promise.finally(() => {
|
|
46
|
+
this._resolved = true;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const callbackCopy = [...this._callbacks];
|
|
50
|
+
this._callbacks = [];
|
|
51
|
+
for(let i = 0; i < callbackCopy.length; i++)
|
|
52
|
+
this.then(callbackCopy[i])
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { singleton } from 'tsyringe'
|
|
2
|
+
import UAParser from 'ua-parser-js';
|
|
3
|
+
|
|
4
|
+
@singleton()
|
|
5
|
+
export class SystemInfo {
|
|
6
|
+
|
|
7
|
+
private readonly _isBrowser: boolean;
|
|
8
|
+
private readonly _isIframe: boolean;
|
|
9
|
+
private readonly _origin: string;
|
|
10
|
+
private readonly _parser: UAParser;
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
this._parser = new UAParser();
|
|
14
|
+
const isInternetExplorer = typeof window !== 'undefined' && window.navigator && window.navigator.userAgent.indexOf('Trident') > -1;
|
|
15
|
+
this._isBrowser = isInternetExplorer ||
|
|
16
|
+
(typeof document !== 'undefined'
|
|
17
|
+
&& typeof document.getElementById === 'function'
|
|
18
|
+
&& window
|
|
19
|
+
&& typeof window.Event === 'function'
|
|
20
|
+
);
|
|
21
|
+
this._isIframe = false;
|
|
22
|
+
if (this._isBrowser) {
|
|
23
|
+
// in case we are running in an iframe, parent and window are different, in
|
|
24
|
+
// that case we use the referrer
|
|
25
|
+
this._isIframe = parent !== window;
|
|
26
|
+
this._origin = this._isIframe ? document.referrer : window.location.origin;
|
|
27
|
+
} else {
|
|
28
|
+
this._origin = 'direct';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Check if we are on a Mac OS device
|
|
34
|
+
*/
|
|
35
|
+
public get isMacOS(): boolean {
|
|
36
|
+
const osName = this._parser.getOS().name;
|
|
37
|
+
return osName === 'Mac OS';
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Check if we are on an IOS device
|
|
42
|
+
*/
|
|
43
|
+
public get isIOS(): boolean {
|
|
44
|
+
const osName = this._parser.getOS().name;
|
|
45
|
+
return osName === 'iOS' ||
|
|
46
|
+
(window.navigator && window.navigator.maxTouchPoints === 5 && window.navigator.platform === 'MacIntel');
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Check if we are on an Android device
|
|
51
|
+
*/
|
|
52
|
+
public get isAndroid(): boolean {
|
|
53
|
+
const osName = this._parser.getOS().name;
|
|
54
|
+
return osName === 'Android';
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Check if we are on a mobile device
|
|
59
|
+
*/
|
|
60
|
+
public get isMobile(): boolean {
|
|
61
|
+
const type = this._parser.getDevice().type;
|
|
62
|
+
return type === 'mobile' || type === 'tablet';
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Check if we are running in internet explorer (arrrggghhhh!!!!)
|
|
67
|
+
*/
|
|
68
|
+
public get isIE(): boolean {
|
|
69
|
+
const browserName = this._parser.getBrowser().name;
|
|
70
|
+
return !!(browserName && browserName.includes('IE'));
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Check if we are running in Safari
|
|
75
|
+
*/
|
|
76
|
+
public get isChrome(): boolean {
|
|
77
|
+
const browserName = this._parser.getBrowser().name;
|
|
78
|
+
return !!(browserName && browserName.includes('Chrome'));
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Check if we are running in Safari
|
|
83
|
+
*/
|
|
84
|
+
public get isSafari(): boolean {
|
|
85
|
+
const browserName = this._parser.getBrowser().name;
|
|
86
|
+
return !!(browserName && browserName.includes('Safari'));
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Check if we are running in Firefox
|
|
91
|
+
*/
|
|
92
|
+
public get isFirefox(): boolean {
|
|
93
|
+
const browserName = this._parser.getBrowser().name;
|
|
94
|
+
return !!(browserName && browserName.includes('Firefox'));
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Check if we are running in a browser
|
|
99
|
+
*/
|
|
100
|
+
public get isBrowser(): boolean {
|
|
101
|
+
return this._isBrowser;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Check if we are running in an iframe
|
|
106
|
+
*/
|
|
107
|
+
public get isIframe(): boolean {
|
|
108
|
+
return this._isIframe;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Get guessed origin of embedding website
|
|
113
|
+
*/
|
|
114
|
+
public get origin(): string {
|
|
115
|
+
return this._origin + '';
|
|
116
|
+
};
|
|
117
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { singleton } from 'tsyringe'
|
|
2
|
+
|
|
3
|
+
@singleton()
|
|
4
|
+
export class TypeChecker {
|
|
5
|
+
|
|
6
|
+
public isTypeOf(value: any, type: string): boolean {
|
|
7
|
+
return typeof value === type;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
public isHTMLCanvasElement(value: any): boolean {
|
|
11
|
+
return value instanceof HTMLCanvasElement;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { singleton } from 'tsyringe'
|
|
2
|
+
import { parse as parseUUID, stringify as stringifyUUID, v4, validate as validateUUID } from 'uuid'
|
|
3
|
+
|
|
4
|
+
@singleton()
|
|
5
|
+
export class UuidGenerator {
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new uuid v4.
|
|
8
|
+
*/
|
|
9
|
+
public create(): string {
|
|
10
|
+
return v4();
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Checks if the provided string is a valid uuid.
|
|
15
|
+
*
|
|
16
|
+
* @param uuid the uuid to check
|
|
17
|
+
*/
|
|
18
|
+
public validate(uuid: string): boolean {
|
|
19
|
+
return validateUUID(uuid);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Parse the uuid to array of bytes
|
|
24
|
+
*
|
|
25
|
+
* @param uuid the uuid to convert
|
|
26
|
+
* @returns ArrayLike collection of 16 values
|
|
27
|
+
*/
|
|
28
|
+
public parse(uuid: string): ArrayLike<number> {
|
|
29
|
+
return parseUUID(uuid);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Stringify an array of bytes to an uuid
|
|
34
|
+
*
|
|
35
|
+
* @param uuid the array of bytes
|
|
36
|
+
* @returns the converted uuid
|
|
37
|
+
*/
|
|
38
|
+
public stringify(uuid: ArrayLike<number>): string {
|
|
39
|
+
return stringifyUUID(uuid);
|
|
40
|
+
};
|
|
41
|
+
}
|
package/tsconfig.json
ADDED