@equinor/echo-framework 0.10.26 → 0.10.27
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.
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/// <reference types="user-agent-data-types" />
|
|
2
|
+
import UAParser from 'ua-parser-js';
|
|
3
|
+
import { DetailedDeviceInformation } from '../../types/device';
|
|
4
|
+
/**
|
|
5
|
+
* This object is concerned with gathering and holding information about the users device.
|
|
6
|
+
* This object will be read-only after initialization and should as a rule throw errors if the
|
|
7
|
+
* deviceInformation property is altered after intialization.
|
|
8
|
+
*/
|
|
9
|
+
declare class DetailedDeviceInformationProvider {
|
|
10
|
+
/** Represents the user agent string parser.
|
|
11
|
+
* This method is treated as a fallback if the User-Agent Client Hints API does not provide a coherent value
|
|
12
|
+
* or if the browser does not yet support it.
|
|
13
|
+
*/
|
|
14
|
+
private readonly _uaParser;
|
|
15
|
+
/**
|
|
16
|
+
* Stores the system report from a call to the underlying system.
|
|
17
|
+
* - If this is undefined, it is not yet initialized (it happens asynchronously).
|
|
18
|
+
*/
|
|
19
|
+
private readonly _uaDataValues;
|
|
20
|
+
/** Holds the current device information and should be the single source of truth.
|
|
21
|
+
*
|
|
22
|
+
* It can be undefined because we have to asynchronously fetch underlying system information.
|
|
23
|
+
*/
|
|
24
|
+
private readonly _deviceInformation;
|
|
25
|
+
private constructor();
|
|
26
|
+
get deviceInformation(): DetailedDeviceInformation;
|
|
27
|
+
get uaDataValues(): UADataValues | null | undefined;
|
|
28
|
+
get uaParser(): UAParser.UAParserInstance;
|
|
29
|
+
/** Constructs the parser and returns it. */
|
|
30
|
+
static initialize(): DetailedDeviceInformationProvider;
|
|
31
|
+
private static getPlatform;
|
|
32
|
+
private static getWebBrowser;
|
|
33
|
+
private static getOperatingSystem;
|
|
34
|
+
/**
|
|
35
|
+
* TODO: Get the device model from Client Hints API.
|
|
36
|
+
* This requires top-level await support, which in turn has to be implemented to modules downstream.
|
|
37
|
+
*/
|
|
38
|
+
private static getDeviceModel;
|
|
39
|
+
}
|
|
40
|
+
declare const detailedDeviceInformationProvider: DetailedDeviceInformationProvider;
|
|
41
|
+
export { DetailedDeviceInformationProvider, detailedDeviceInformationProvider };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Browser, DetailedDeviceInformation, DeviceType, IDeviceSummary, ScreenDimensions, ScreenOrientation, UserInput } from '../../types/device';
|
|
2
|
+
import { detailedDeviceInformationProvider } from './deepDeviceInfo';
|
|
3
|
+
type Props = {
|
|
4
|
+
detailedDeviceInfo: typeof detailedDeviceInformationProvider;
|
|
5
|
+
};
|
|
6
|
+
declare class DeviceInformation {
|
|
7
|
+
/**
|
|
8
|
+
* Represents the current viewport orientation.
|
|
9
|
+
* If the viewport is square, it will default to portrait.
|
|
10
|
+
*/
|
|
11
|
+
private _orientation;
|
|
12
|
+
/**
|
|
13
|
+
* Represents an abstracted device type: desktop, tablet or mobile.
|
|
14
|
+
*/
|
|
15
|
+
private readonly _deviceType;
|
|
16
|
+
/**
|
|
17
|
+
* Represents the current input source.
|
|
18
|
+
* Note: On a touchscreen device which has a mouse plugged in, it will return the mouse.
|
|
19
|
+
*/
|
|
20
|
+
private readonly _userInput;
|
|
21
|
+
private readonly _browser?;
|
|
22
|
+
/**
|
|
23
|
+
* Represents the viewport (layout and visual) and (full)screen dimensions.
|
|
24
|
+
* WebKit browsers prior to 15 will only support layout dimensions.
|
|
25
|
+
*/
|
|
26
|
+
private _dimensions;
|
|
27
|
+
protected orientationIsLandscapeQuery: MediaQueryList;
|
|
28
|
+
private _detailedDeviceInfo;
|
|
29
|
+
constructor(props: Props);
|
|
30
|
+
private getUpdatedScreenDimensions;
|
|
31
|
+
private getBrowser;
|
|
32
|
+
private getUserInput;
|
|
33
|
+
/** Returns the current viewing medium.*/
|
|
34
|
+
private getDeviceType;
|
|
35
|
+
private getOrientation;
|
|
36
|
+
getDeviceDetails(): DetailedDeviceInformation;
|
|
37
|
+
get orientation(): ScreenOrientation;
|
|
38
|
+
get deviceType(): DeviceType;
|
|
39
|
+
get userInput(): UserInput;
|
|
40
|
+
get screenDimensions(): ScreenDimensions;
|
|
41
|
+
get browser(): Browser | undefined;
|
|
42
|
+
getDeviceSummary(): IDeviceSummary;
|
|
43
|
+
}
|
|
44
|
+
declare const deviceInfo: DeviceInformation;
|
|
45
|
+
export { deviceInfo, DeviceInformation };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export type SupportedPlatforms = 'Android' | 'Linux' | 'MacOs' | 'iOS' | 'iPadOS' | 'Windows' | 'Platform not found.';
|
|
2
|
+
export type DetailedDeviceInformation = {
|
|
3
|
+
operatingSystem: string;
|
|
4
|
+
webBrowser: string;
|
|
5
|
+
deviceModel: string;
|
|
6
|
+
platform?: SupportedPlatforms;
|
|
7
|
+
};
|
|
8
|
+
export type IDeepDeviceInformation = {
|
|
9
|
+
operatingSystem: string;
|
|
10
|
+
webBrowser: string;
|
|
11
|
+
deviceModel: string;
|
|
12
|
+
platform?: SupportedPlatforms;
|
|
13
|
+
};
|
|
14
|
+
/** If the viewport is a square, then the orientation will be portrait. */
|
|
15
|
+
export type ScreenOrientation = 'portrait' | 'landscape';
|
|
16
|
+
/** Keep in mind, this is calculated when the page loads, so be sure to do refresh if simulating a device in DevTools. */
|
|
17
|
+
export type DeviceType = 'mobile' | 'tablet' | 'desktop';
|
|
18
|
+
export type UserInput = 'touch' | 'mouse';
|
|
19
|
+
export type Browser = 'Chrome' | 'Safari' | 'Firefox' | 'Edge' | 'Opera';
|
|
20
|
+
type Dimensions = {
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
};
|
|
24
|
+
export type ScreenDimensions = {
|
|
25
|
+
/** Provides measurements for use in the visual viewport.
|
|
26
|
+
*
|
|
27
|
+
* The visual viewport is the currently visible viewport and these dimensions
|
|
28
|
+
* can be smaller than the layout viewport if, for example, the user has pinch zoomed or summoned their
|
|
29
|
+
* on-screen keyboards.
|
|
30
|
+
*/
|
|
31
|
+
visual: Dimensions;
|
|
32
|
+
/**
|
|
33
|
+
* Provides measurements for the layout viewport. These values are always fetched from
|
|
34
|
+
* innerHeight and innerWidth, so scrollbars are included.
|
|
35
|
+
*/
|
|
36
|
+
layout?: Dimensions;
|
|
37
|
+
/** Provides measurements for use in fullscreen contexts. */
|
|
38
|
+
fullscreen?: FullscreenDimensions;
|
|
39
|
+
};
|
|
40
|
+
export type FullscreenDimensions = {
|
|
41
|
+
/** The total screen dimensions, essentially equal to the screen resolution configured in OS settings.*/
|
|
42
|
+
total: Dimensions;
|
|
43
|
+
/** The available screen dimensions, taking into account overlays such as browser address bar or virtual keyboard. */
|
|
44
|
+
available: Dimensions;
|
|
45
|
+
};
|
|
46
|
+
export interface IDeviceSummary {
|
|
47
|
+
orientation: ScreenOrientation;
|
|
48
|
+
deviceType: DeviceType;
|
|
49
|
+
userInput: UserInput;
|
|
50
|
+
screenDimensions: ScreenDimensions;
|
|
51
|
+
deepInfo: IDeepDeviceInformation;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/echo-framework",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.27",
|
|
4
4
|
"description": "Modules and components for EchoWeb, utilizing EchoCore",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -105,7 +105,8 @@
|
|
|
105
105
|
"styled-components": "^5.3.6",
|
|
106
106
|
"ts-jest": "^29.0.5",
|
|
107
107
|
"tslib": "^2.4.1",
|
|
108
|
-
"typescript": "=4.9.4"
|
|
108
|
+
"typescript": "=4.9.4",
|
|
109
|
+
"user-agent-data-types": "^0.3.0"
|
|
109
110
|
},
|
|
110
111
|
"compilerOptions": {
|
|
111
112
|
"declaration": true
|