webui/src/lib/screen.ts

19 lines
515 B
TypeScript
Raw Normal View History

import { writable } from 'svelte/store';
2024-06-08 22:34:10 +00:00
// Check if window is available
let initialWidth: number = 0;
if (typeof window !== 'undefined') {
initialWidth = window.innerWidth;
}
// Create a writable store to track screen size
2024-06-08 22:34:10 +00:00
export const screenSize = writable<number>(initialWidth);
// Function to update the screen size
2024-06-08 22:34:10 +00:00
export const updateScreenSize = (): void => {
// Check if window is available before setting the screen size
if (typeof window !== 'undefined') {
screenSize.set(window.innerWidth);
}
};