@aurigma/design-atoms-model
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
55 lines • 2.59 kB
JavaScript
export const Environment = {
//#region browser & hardware
IsIos: () => {
return (/iPad|iPhone|iPod/.test(navigator.platform) ||
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) &&
!window.MSStream;
},
GetIosVersion: () => {
if (navigator.appVersion == null || !Environment.IsIos())
return [];
const match = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
if (match == null)
return [];
return match.slice(1)
.map((v) => parseInt(v, 10))
.map((n) => isNaN(n) ? null : n);
},
IosMajorVersion: () => {
const ua = navigator.userAgent;
const uaIndex = ua.indexOf("OS ");
if (uaIndex > -1)
return Number(ua.substr(uaIndex + 3, 3).replace("_", ".").charAt(0));
},
IsAndroid: () => !!navigator.userAgent.toLowerCase().match(/(android)/),
IsTouchDevice: () => Environment.IsIos() || Environment.IsAndroid() || Environment.IsTouchIE(),
IsNativeAndroidBrowser: () => {
const nua = navigator.userAgent;
return ((nua.indexOf("Mozilla/5.0") > -1 && nua.indexOf("Android ") > -1 && nua.indexOf("AppleWebKit") > -1) && !(nua.indexOf("Chrome") > -1));
},
IsGoogleChrome: () => typeof window["chrome"] == "object",
IsSafari: () => navigator.userAgent.indexOf("Safari") !== -1 && navigator.userAgent.indexOf("Chrome") === -1,
IsSafariOrSafariWebView: () => Environment.IsSafari() || Environment.IsIos(),
IsFirefox: () => navigator.userAgent.indexOf("Firefox") !== -1 && navigator.userAgent.indexOf("Seamonkey") === -1,
IsTouchIE: () => navigator.userAgent.indexOf("Trident") !== -1 && navigator.userAgent.indexOf("Touch") !== -1,
IsIE: () => navigator.userAgent.indexOf("MSIE") !== -1 || navigator.appVersion.indexOf("Trident/") > 0,
IsEdge: () => navigator.userAgent.indexOf("Edge") != -1,
GetEdgeHtmlVersion: () => {
if (!Environment.IsEdge())
return [];
return navigator.userAgent.match(/Edge\/(\d+).(\d+)/)
.slice(1)
.map((v) => parseInt(v, 10))
.map((n) => isNaN(n) ? null : n);
},
//#endregion
get devicePixelRatio() {
return window.devicePixelRatio != null ? window.devicePixelRatio : 1;
},
get screenDpi() {
return 96 * Environment.devicePixelRatio;
},
IsSmallScreen: () => window.innerWidth <= 500,
};
export default Environment;
//# sourceMappingURL=Environment.js.map