mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 04:14:21 +08:00
perf(platform): remove from critical path
This commit is contained in:
78
core/src/utils/platform.ts
Normal file
78
core/src/utils/platform.ts
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user