import { createWindowManager, createDesktopBinder } from './chunk-YCHJXSTC.js'; import { useState, useEffect, useSyncExternalStore, useCallback, useRef, useMemo } from 'react'; function useWindowManager(options) { const [wm] = useState(() => createWindowManager(options)); useEffect(() => () => wm.destroy(), [wm]); return wm; } function useWmState(wm) { return useSyncExternalStore(wm.subscribe, wm.getState, wm.getState); } function useWmWindow(wm, id) { const getSnapshot = useCallback(() => wm.get(id), [wm, id]); return useSyncExternalStore(wm.subscribe, getSnapshot, getSnapshot); } function useDesktop(wm, options) { const optionsRef = useRef(options); const binder = useMemo(() => createDesktopBinder(wm, optionsRef.current), [wm]); const cleanupRef = useRef(null); const ref = useCallback( (node) => { if (node) { cleanupRef.current = binder.bindDesktop(node); } else { cleanupRef.current?.(); cleanupRef.current = null; } }, [binder] ); return { ref, binder, controller: binder.controller }; } function useWmWindowRef(binder, id, options) { const optionsRef = useRef(options); const cleanupRef = useRef(null); return useCallback( (node) => { if (node) { cleanupRef.current = binder.bindWindow(id, node, optionsRef.current); } else { cleanupRef.current?.(); cleanupRef.current = null; } }, [binder, id] ); } export { useDesktop, useWindowManager, useWmState, useWmWindow, useWmWindowRef }; //# sourceMappingURL=react.js.map //# sourceMappingURL=react.js.map