claritykit-svelte
Version:
A comprehensive Svelte component library focused on accessibility, ADHD-optimized design, developer experience, and full SSR compatibility
64 lines • 2.43 kB
TypeScript
/**
* Environment detection utilities for SSR compatibility
* Provides reliable browser/server environment detection and safe API access
*/
/**
* Detects if code is running in a browser environment
* Checks for both window and document to ensure full browser context
*/
export declare const isBrowser: boolean;
/**
* Detects if code is running in a server environment
* Inverse of isBrowser for clearer semantic meaning
*/
export declare const isServer: boolean;
/**
* Safely executes a callback that requires DOM access
* @param callback - Function that accesses DOM APIs
* @param fallback - Value to return if DOM is not available
* @returns Result of callback or fallback value
*/
export declare function safelyAccessDOM<T>(callback: () => T, fallback?: T): T | undefined;
/**
* Safely executes a callback that requires window object
* @param callback - Function that accesses window APIs
* @param fallback - Value to return if window is not available
* @returns Result of callback or fallback value
*/
export declare function safelyAccessWindow<T>(callback: () => T, fallback?: T): T | undefined;
/**
* Safely executes a callback that requires localStorage
* @param callback - Function that accesses localStorage
* @param fallback - Value to return if localStorage is not available
* @returns Result of callback or fallback value
*/
export declare function safelyAccessStorage<T>(callback: () => T, fallback?: T): T | undefined;
/**
* Returns a promise that resolves when DOM is ready
* Useful for components that need to wait for client-side hydration
*/
export declare function waitForDOM(): Promise<void>;
/**
* Checks if the current environment supports a specific API
* @param apiName - Name of the API to check (e.g., 'IntersectionObserver', 'ResizeObserver')
* @returns True if API is available, false otherwise
*/
export declare function supportsAPI(apiName: string): boolean;
/**
* Environment information object
*/
export interface EnvironmentInfo {
isBrowser: boolean;
isServer: boolean;
userAgent?: string;
supportsIntersectionObserver: boolean;
supportsResizeObserver: boolean;
supportsMatchMedia: boolean;
supportsLocalStorage: boolean;
}
/**
* Gets comprehensive environment information
* @returns Object containing environment details
*/
export declare function getEnvironmentInfo(): EnvironmentInfo;
//# sourceMappingURL=environment.d.ts.map