2024-08-31 19:46:10 +02:00
|
|
|
import { browser } from '$app/environment'
|
2024-06-29 16:24:14 +02:00
|
|
|
|
2024-08-31 19:46:10 +02:00
|
|
|
const device = {
|
|
|
|
is: {},
|
|
|
|
prefers: {},
|
|
|
|
supports: {},
|
|
|
|
userAgent: 'sveltekit server'
|
|
|
|
};
|
2024-07-03 15:05:14 +02:00
|
|
|
|
2024-08-31 19:46:10 +02:00
|
|
|
const app = {
|
|
|
|
is: {}
|
|
|
|
}
|
2024-07-03 15:05:14 +02:00
|
|
|
|
2024-08-31 19:46:10 +02:00
|
|
|
if (browser) {
|
|
|
|
const ua = navigator.userAgent.toLowerCase();
|
2024-06-29 16:24:14 +02:00
|
|
|
|
2024-08-31 19:46:10 +02:00
|
|
|
const iPhone = ua.includes("iphone os");
|
|
|
|
const iPad = !iPhone && ua.includes("mac os") && navigator.maxTouchPoints > 0;
|
2024-07-02 20:16:03 +02:00
|
|
|
|
2024-08-31 19:46:10 +02:00
|
|
|
const iOS = iPhone || iPad;
|
|
|
|
const android = ua.includes("android") || ua.includes("diordna");
|
2024-07-02 20:16:03 +02:00
|
|
|
|
2024-08-31 19:46:10 +02:00
|
|
|
const mobile = iOS || android;
|
2024-07-12 14:49:29 +02:00
|
|
|
|
2024-08-31 19:46:10 +02:00
|
|
|
const language = navigator.language.toLowerCase().slice(0, 2);
|
2024-07-28 14:59:58 +02:00
|
|
|
|
2024-08-31 19:46:10 +02:00
|
|
|
const installed = window.matchMedia('(display-mode: standalone)').matches;
|
|
|
|
|
|
|
|
const reducedMotion = window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;
|
|
|
|
const reducedTransparency = window.matchMedia(`(prefers-reduced-transparency: reduce)`).matches;
|
|
|
|
|
|
|
|
app.is = { installed };
|
|
|
|
device.is = {
|
2024-07-03 15:05:14 +02:00
|
|
|
iPhone,
|
2024-07-10 19:28:23 +02:00
|
|
|
iPad,
|
2024-07-03 15:05:14 +02:00
|
|
|
iOS,
|
|
|
|
android,
|
|
|
|
mobile,
|
2024-08-31 19:46:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
device.prefers = {
|
2024-07-12 14:49:29 +02:00
|
|
|
language,
|
|
|
|
reducedMotion,
|
|
|
|
reducedTransparency,
|
2024-08-31 19:46:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
device.supports = {
|
2024-07-28 14:59:58 +02:00
|
|
|
share: navigator.share !== undefined,
|
|
|
|
directDownload: !(installed && iOS),
|
2024-08-31 19:46:10 +02:00
|
|
|
};
|
2024-06-29 16:24:14 +02:00
|
|
|
|
2024-08-31 19:46:10 +02:00
|
|
|
device.userAgent = navigator.userAgent;
|
|
|
|
}
|
2024-07-03 15:05:14 +02:00
|
|
|
|
|
|
|
export { device, app };
|