const defaults = { "server:apiBase": `${window.location.origin || ""}/api/v1`, "server:gatewayBase": `${location.protocol === "https:" ? "wss" : "ws"}://${location.host}/gateway`, "auth:token": "", "ui:doAnimations": true, "ui:theme": "dark", "state:openChannelId": -1, "log:Gateway": false, "log:Store": false, "ui:stateful:presistSelectedChannel": true, "ui:showSidebarToggle": false, "ui:alwaysUseMobileChatBar": false, "ui:online:processRemoteTypingEvents": true, "ui:online:processRemotePresenceEvents": true, "ui:online:loadMessageHistory": true, "ui:online:sendTypingUpdates": true, "ui:useragent:formFactor": () => { return (window.navigator && window.navigator.maxTouchPoints > 0) ? "touch" : "desktop"; }, "ui:useragent:viewportSizeJustificationMethod": () => { if (CSS.supports("(width: 1dvw)")) { return "dynamicViewportUnits"; } else if (getItem("ui:useragent:formFactor") === "touch") { return "javascriptResponsive"; } else { return "normalUnits"; } } }; const store = new Map(Object.entries(defaults)); const persistentProvider = localStorage; let didCacheProvider = false; export function setItem(key, value) { store.set(key, value); if (persistentProvider) { persistentProvider.setItem(key, typeof value === "string" ? value : JSON.stringify(value)); } } export function getItem(key) { if (!didCacheProvider) { init(); } const value = store.get(key); if (typeof value === "function") { return value(); } return value; } export function removeItem(key) { store.delete(key); if (persistentProvider) { persistentProvider.removeItem(key); } } export function init() { if (!persistentProvider) return; store.forEach((defaultValue, key) => { const override = persistentProvider.getItem(key); if (override !== null) { try { store.set(key, typeof defaultValue === "string" ? override : JSON.parse(override)); } catch (o_O) { console.warn("[Storage]", `init(): An exception was thrown while parsing the value of key "${key}" from persistentProvider. The key "${key}" will be removed from persistentProvider.`, o_O); persistentProvider.removeItem(key); } } }); didCacheProvider = true; } export function apiRoute(fragment) { return `${getItem("server:apiBase")}/${fragment}` }