@vue-pdf-viewer/viewer
Version:
A vue-pdf-viewer component for Vue and Nuxt. Suitable for vue-pdf document.
45 lines (44 loc) • 1.51 kB
TypeScript
/**
* Composable for accessing the shared viewer state.
*
* This composable provides access to the reactive ViewerState that is
* provided by the VPdfViewer component. It centralizes the inject logic
* and ensures type safety.
*
* @example
* ```ts
* // In any component inside VPdfViewer
* const viewerState = useViewerState()
*
* // Access reactive properties directly (no .value needed)
* console.log(viewerState.scale)
*
* // Watch for changes
* watch(() => viewerState.scale, (newScale) => {
* console.log('Scale changed:', newScale)
* })
*
* // Update values (watchers in other components will trigger)
* viewerState.scale = 1.5
*
* // Use toRefs for destructuring with reactivity
* const { scale, rotation } = toRefs(viewerState)
* console.log(scale.value) // refs need .value
* ```
*/
import { type Reactive } from 'vue';
import type { ViewerState } from '@/utils/types';
/**
* Access the shared ViewerState from the parent VPdfViewer component.
*
* @returns The reactive ViewerState object with plain value properties
* @throws Error if used outside of VPdfViewer component tree
*/
export declare function useViewerState(): Reactive<ViewerState>;
/**
* Access the shared ViewerState, returning undefined if not available.
* Use this when the component may be used outside VPdfViewer context.
*
* @returns The reactive ViewerState object or undefined if not in VPdfViewer context
*/
export declare function useViewerStateOptional(): Reactive<ViewerState> | undefined;