perf(platform): remove from critical path

This commit is contained in:
Manu Mtz.-Almeida
2018-04-18 23:06:56 +02:00
parent 861ce49363
commit 86a6cde4a1
23 changed files with 347 additions and 1001 deletions

View File

@ -0,0 +1,78 @@
export function isIpad(win: Window) {
return testUserAgent(win, /iPad/i);
}
export function isIphone(win: Window) {
return testUserAgent(win, /iPhone/i);
}
export function isIOS(win: Window) {
return testUserAgent(win, /iPad|iPhone|iPod/i);
}
export function isAndroid(win: Window) {
return !isIOS(win);
}
export function isPhablet(win: Window) {
const width = win.innerWidth;
const height = win.innerHeight;
const smallest = Math.min(width, height);
const largest = Math.max(width, height);
return (smallest > 390 && smallest < 520) &&
(largest > 620 && largest < 800);
}
export function isTablet(win: Window) {
const width = win.innerWidth;
const height = win.innerHeight;
const smallest = Math.min(width, height);
const largest = Math.max(width, height);
return (smallest > 460 && smallest < 820) &&
(largest > 780 && largest < 1400);
}
export function isDevice(win: Window) {
return win.matchMedia('(any-pointer:coarse)').matches;
}
export function isHybrid(win: Window) {
return isCordova(win) || isCapacitor(win);
}
export function isCordova(window: Window): boolean {
const win = window as any;
return !!(win['cordova'] || win['phonegap'] || win['PhoneGap']);
}
export function isCapacitor(window: Window): boolean {
const win = window as any;
return !!(win['Capacitor']);
}
export function isElectron(win: Window): boolean {
return testUserAgent(win, /electron/);
}
export function needInputShims(win: Window) {
return isIOS(win) && isDevice(win);
}
export function testUserAgent(win: Window, expr: RegExp) {
return expr.test(win.navigator.userAgent);
}
export function configFromURL(win: Window) {
const config: any = {};
win.location.search.slice(1)
.split('&')
.filter(entryText => entryText.startsWith('ionic:'))
.map(entryText => entryText.split('='))
.forEach(entry => {
config[entry[0].slice(6)] = decodeURIComponent(entry[1]);
});
return config;
}