UNPKG

@zoom-image/react

Version:
48 lines (43 loc) 1.19 kB
'use strict'; var core = require('@zoom-image/core'); var react = require('react'); // src/useZoomImageWheel.ts // src/shared.ts function noop() { } // src/useZoomImageWheel.ts function useZoomImageWheel() { const result = react.useRef(); const [zoomImageState, updateZoomImageState] = react.useState({ currentZoom: 1, enable: false, currentPositionX: -1, currentPositionY: -1, currentRotation: 0 }); const createZoomImage = react.useCallback((...arg) => { result.current?.cleanup(); result.current = core.createZoomImageWheel(...arg); updateZoomImageState(result.current.getState()); result.current.subscribe(({ state }) => { updateZoomImageState(state); }); }, []); const getZoomImageState = react.useCallback(() => { return result.current?.getState(); }, []); react.useEffect(() => { return () => { result.current?.cleanup(); }; }, []); return { createZoomImage, zoomImageState, getZoomImageState, setZoomImageState: result.current?.setState ?? noop }; } exports.useZoomImageWheel = useZoomImageWheel; //# sourceMappingURL=out.js.map //# sourceMappingURL=useZoomImageWheel.js.map