claritykit-svelte
Version:
A comprehensive Svelte component library focused on accessibility, ADHD-optimized design, developer experience, and full SSR compatibility
121 lines • 4.49 kB
TypeScript
/**
* SSR-safe DOM utilities
* Provides safe wrappers for DOM operations that work in both server and client environments
*/
/**
* SSR-safe DOM utilities interface
*/
export interface SSRSafeDOMUtils {
querySelector(selector: string): Element | null;
getElementById(id: string): Element | null;
addEventListener(element: Element, event: string, handler: EventListener): void;
removeEventListener(element: Element, event: string, handler: EventListener): void;
getComputedStyle(element: Element): CSSStyleDeclaration | null;
getBoundingClientRect(element: Element): DOMRect | null;
createEvent(type: string): Event | null;
}
/**
* Safely queries for an element using querySelector
* @param selector - CSS selector string
* @returns Element or null if not found or not in browser
*/
export declare function querySelector(selector: string): Element | null;
/**
* Safely gets an element by ID
* @param id - Element ID
* @returns Element or null if not found or not in browser
*/
export declare function getElementById(id: string): Element | null;
/**
* Safely adds an event listener to an element
* @param element - Target element
* @param event - Event type
* @param handler - Event handler function
* @param options - Event listener options
*/
export declare function addEventListener(element: Element, event: string, handler: EventListener, options?: AddEventListenerOptions): void;
/**
* Safely removes an event listener from an element
* @param element - Target element
* @param event - Event type
* @param handler - Event handler function
* @param options - Event listener options
*/
export declare function removeEventListener(element: Element, event: string, handler: EventListener, options?: EventListenerOptions): void;
/**
* Safely gets computed styles for an element
* @param element - Target element
* @returns CSSStyleDeclaration or null if not available
*/
export declare function getComputedStyle(element: Element): CSSStyleDeclaration | null;
/**
* Safely gets bounding client rect for an element
* @param element - Target element
* @returns DOMRect or null if not available
*/
export declare function getBoundingClientRect(element: Element): DOMRect | null;
/**
* Safely creates a custom event
* @param type - Event type
* @param eventInitDict - Event initialization options
* @returns Event or null if not available
*/
export declare function createEvent(type: string, eventInitDict?: EventInit): Event | null;
/**
* Safely creates a custom event with detail data
* @param type - Event type
* @param detail - Custom data to include with event
* @param eventInitDict - Event initialization options
* @returns CustomEvent or null if not available
*/
export declare function createCustomEvent<T = any>(type: string, detail?: T, eventInitDict?: CustomEventInit<T>): CustomEvent<T> | null;
/**
* Safely dispatches an event on an element
* @param element - Target element
* @param event - Event to dispatch
* @returns True if event was dispatched, false otherwise
*/
export declare function dispatchEvent(element: Element, event: Event): boolean;
/**
* Safely focuses an element
* @param element - Element to focus
* @param options - Focus options
*/
export declare function focusElement(element: Element, options?: FocusOptions): void;
/**
* Safely blurs an element
* @param element - Element to blur
*/
export declare function blurElement(element: Element): void;
/**
* Safely scrolls an element into view
* @param element - Element to scroll into view
* @param options - Scroll options
*/
export declare function scrollIntoView(element: Element, options?: ScrollIntoViewOptions): void;
/**
* Safely gets the active element
* @returns Active element or null
*/
export declare function getActiveElement(): Element | null;
/**
* Safely checks if an element contains another element
* @param parent - Parent element
* @param child - Child element
* @returns True if parent contains child, false otherwise
*/
export declare function contains(parent: Element, child: Element): boolean;
/**
* Safely gets element dimensions
* @param element - Target element
* @returns Object with width and height, or null if not available
*/
export declare function getElementDimensions(element: Element): {
width: number;
height: number;
} | null;
/**
* Default SSR-safe DOM utilities implementation
*/
export declare const domUtils: SSRSafeDOMUtils;
//# sourceMappingURL=dom-ssr.d.ts.map