diff --git a/src/lib/screen.ts b/src/lib/screen.ts index 4eadfa7..293d5e7 100644 --- a/src/lib/screen.ts +++ b/src/lib/screen.ts @@ -1,9 +1,18 @@ import { writable } from 'svelte/store'; +// Check if window is available +let initialWidth: number = 0; +if (typeof window !== 'undefined') { + initialWidth = window.innerWidth; +} + // Create a writable store to track screen size -export const screenSize = writable(window.innerWidth); +export const screenSize = writable(initialWidth); // Function to update the screen size -export const updateScreenSize = () => { - screenSize.set(window.innerWidth); +export const updateScreenSize = (): void => { + // Check if window is available before setting the screen size + if (typeof window !== 'undefined') { + screenSize.set(window.innerWidth); + } };