mirror of
https://github.com/wukko/cobalt.git
synced 2025-01-24 03:36:22 +01:00
web/device: add default values & types
This commit is contained in:
parent
2deb8aa53b
commit
30c4c1ad20
1 changed files with 31 additions and 20 deletions
|
@ -1,14 +1,29 @@
|
||||||
import { browser } from '$app/environment'
|
import { browser } from "$app/environment";
|
||||||
|
|
||||||
const device = {
|
|
||||||
is: {},
|
|
||||||
prefers: {},
|
|
||||||
supports: {},
|
|
||||||
userAgent: 'sveltekit server'
|
|
||||||
};
|
|
||||||
|
|
||||||
const app = {
|
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) {
|
if (browser) {
|
||||||
|
@ -20,28 +35,24 @@ if (browser) {
|
||||||
const iOS = iPhone || iPad;
|
const iOS = iPhone || iPad;
|
||||||
const android = ua.includes("android") || ua.includes("diordna");
|
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 installed = window.matchMedia('(display-mode: standalone)').matches;
|
||||||
|
|
||||||
const reducedMotion = window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;
|
app.is = {
|
||||||
const reducedTransparency = window.matchMedia(`(prefers-reduced-transparency: reduce)`).matches;
|
installed,
|
||||||
|
};
|
||||||
|
|
||||||
app.is = { installed };
|
|
||||||
device.is = {
|
device.is = {
|
||||||
iPhone,
|
iPhone,
|
||||||
iPad,
|
iPad,
|
||||||
iOS,
|
iOS,
|
||||||
android,
|
android,
|
||||||
mobile,
|
mobile: iOS || android,
|
||||||
};
|
};
|
||||||
|
|
||||||
device.prefers = {
|
device.prefers = {
|
||||||
language,
|
language: navigator.language.toLowerCase().slice(0, 2) || "en",
|
||||||
reducedMotion,
|
reducedMotion: window.matchMedia('(prefers-reduced-motion: reduce)').matches,
|
||||||
reducedTransparency,
|
reducedTransparency: window.matchMedia('(prefers-reduced-transparency: reduce)').matches,
|
||||||
};
|
};
|
||||||
|
|
||||||
device.supports = {
|
device.supports = {
|
||||||
|
|
Loading…
Reference in a new issue