API
Types
Every public type, importable from the package.
import type {
ImageViewerApi,
ImageViewerButton,
ImageViewerButtonIcon,
ImageViewerControls,
ImageViewerItem,
ImageViewerOpenOptions,
ImageViewerSlide,
ImageViewerUi,
ImageViewerLabels,
ModuleOptions,
} from 'nuxt-image-viewer'
All of them carry JSDoc, so your editor — and your coding agent — shows the docs inline.
ImageViewerItem
One image passed to open(). Only src is required.
interface ImageViewerItem {
/** Full-size image shown in the viewer. */
src: string
/** Smaller copy already loaded on the page — shown at once while `src` loads. */
thumb?: string
/** Natural size of `src`. Without it the image is measured before opening. */
width?: number
height?: number
alt?: string
/** Text shown under the image. */
caption?: string
/** Element on the page the image opens from and closes back into. */
element?: HTMLElement
}
ImageViewerOpenOptions
Overrides of the global options for one open() call.
type ImageViewerOpenOptions = Partial<{
zIndex: number
bgOpacity: number
loop: boolean
spacing: number
maxZoom: number
closeOnVerticalDrag: boolean
closeOnBackdropClick: boolean
idleDelay: number
idleHidesCaption: boolean
}> & {
ui?: Partial<ImageViewerUi>
labels?: Partial<ImageViewerLabels>
/** Your own components in place of the arrows. */
controls?: Partial<ImageViewerControls>
/** Replace the buttons set with configure(). */
buttons?: ImageViewerButton[]
}
ImageViewerButton
A custom button in the toolbar: an icon component, a text, or both. An icon-only button needs a label.
type ImageViewerButton = {
/** Unique name. Also the class modifier: .image-viewer__button--{name} */
name: string
onClick: (context: { item: ImageViewerSlide, index: number, close: () => void }) => void
} & (
| { icon: ImageViewerButtonIcon, text?: string, label: string }
| { icon?: ImageViewerButtonIcon, text: string, label?: string }
)
/** A Nuxt Icon name, as in <UIcon name>, or any component. */
type ImageViewerButtonIcon = string | Component
ImageViewerControls
Your own arrows in place of the built-in ones — any components, they need no props: the viewer places them, scrolls on their click and names an icon-only button from the labels.
interface ImageViewerControls {
prev: Component
next: Component
}
ImageViewerUi
interface ImageViewerUi {
counter: boolean
zoom: boolean
fullscreen: boolean
close: boolean
arrows: boolean
caption: boolean
}
ImageViewerLabels
interface ImageViewerLabels {
dialog: string
close: string
zoomIn: string
zoomOut: string
fullscreen: string
exitFullscreen: string
prev: string
next: string
}
ImageViewerSlide
An item with everything resolved — what useImageViewer().items holds.
interface ImageViewerSlide {
src: string
thumb: string
width: number
height: number
alt: string
caption?: string
element?: HTMLElement
}
ImageViewerApi
What useImageViewer() returns — see useImageViewer().
ModuleOptions
The imageViewer key of nuxt.config — see Options.