web/device: add default values & types

This commit is contained in:
wukko 2024-09-03 13:52:41 +06:00
parent 2deb8aa53b
commit 30c4c1ad20
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2

View file

@ -1,14 +1,29 @@
import { browser } from '$app/environment'
const device = {
is: {},
prefers: {},
supports: {},
userAgent: 'sveltekit server'
};
import { browser } from "$app/environment";
const app = {
is: {}
is: {
installed: false,
}
}
const device = {
is: {
iPhone: false,
iPad: false,
iOS: false,
android: false,
mobile: false,
},
prefers: {
language: "en",
reducedMotion: false,
reducedTransparency: false,
},
supports: {
share: false,
directDownload: false,
},
userAgent: "sveltekit server",
}
if (browser) {
@ -20,28 +35,24 @@ if (browser) {
const iOS = iPhone || iPad;
const android = ua.includes("android") || ua.includes("diordna");
const mobile = iOS || android;
const language = navigator.language.toLowerCase().slice(0, 2);
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,
};
app.is = { installed };
device.is = {
iPhone,
iPad,
iOS,
android,
mobile,
mobile: iOS || android,
};
device.prefers = {
language,
reducedMotion,
reducedTransparency,
language: navigator.language.toLowerCase().slice(0, 2) || "en",
reducedMotion: window.matchMedia('(prefers-reduced-motion: reduce)').matches,
reducedTransparency: window.matchMedia('(prefers-reduced-transparency: reduce)').matches,
};
device.supports = {