hana-img-viewer

A lightweight and easy-to-use image previewer for Vue 3
6,565 13
Install
npm install hana-img-viewer
Latest Version:6.0.0
Vue:3
License:MIT
Last Updated:Sep 11, 2026
Links: GitHub  ·  npm
Maintainer: non_hana

hana-img-viewer

A lightweight Vue 3 image previewer. Only src and an optional alt are required to get started; the styles are shipped separately in style.css.

Features

  • Thumbnail-origin FLIP open and close
  • src-first preview path with optional silent previewSrc enhancement
  • Wheel, double-click, drag, and pinch interactions
  • SSR-safe thumbnail-only server render

Usage

Install:

pnpm add hana-img-viewer

Import in a .vue component:

<script setup lang="ts">
import { HanaImgViewer } from 'hana-img-viewer'
</script>

<template>
  <HanaImgViewer src="/images/post-thumb.jpg" alt="Article cover" />
</template>

Import style.css in main.ts:

import 'hana-img-viewer/style.css'

API

Props

Prop Type Default Description
src string required Thumbnail and initial preview source.
as keyof HTMLElementTagNameMap 'div' HTML element used for the visible thumbnail root.
previewSrc string undefined Higher-quality source that silently replaces src after loading.
alt string '' Alternative text for both images.
open boolean false Viewer visibility, usually used with v-model:open.
container HTMLElement | null undefined Overlay mount container. undefined uses document.body; null waits for a container.
minZoom number 0.5 Minimum zoom. Must be greater than 0 and no greater than maxZoom.
maxZoom number 10 Maximum zoom.
transitionDuration number 300 Open and close FLIP transition duration in milliseconds.
closeOnBackdropClick boolean true Request close when the backdrop is clicked.
closeOnEscape boolean true Request close when the focused viewer receives Escape.
showCloseButton boolean true Show an explicit close button in the top-right corner of the overlay.

The component emits only update:open. Use v-model:open to keep the state in sync:

<script setup lang="ts">
import { ref } from 'vue'

const open = ref(false)
</script>

<template>
  <HanaImgViewer v-model:open="open" src="/images/post-thumb.jpg" />
</template>

The thumbnail root is a div by default. Choose a non-void element compatible with its parent when the viewer is rendered in a constrained HTML context, such as Markdown prose:

<p>
  <HanaImgViewer as="span" src="/images/post-thumb.jpg" />
</p>

Plain class, style, and other attrs fall through to the visible thumbnail root.

A custom mount target only accepts an HTMLElement:

<script setup lang="ts">
import { ref } from 'vue'

const container = ref<HTMLElement | null>(null)
</script>

<template>
  <div ref="container" />
  <HanaImgViewer :container="container" src="/images/post-thumb.jpg" />
</template>

The component supports both local registration and app.use(HanaImgViewer); the default and named exports are the same component reference.

Related Packages

@scayle/nuxt-image-provider

An image provider to handle SCAYLE-specific modifiers

99,945
@rhapsodic/nuxt-vuewer

Nuxt module for viewing images

4,632 0
nuxt-ssr-api-logger

Nuxt module for logging SSR API requests.

22,791 11
@thunderid/nuxt

Nuxt SDK for ThunderID

6,771 7
nuxt-lazy-hydration

Lazy hydration of server-side rendered Vue.js components

2,795

Version History

Version Released Vue License
6.0.0 ^3.5.0 MIT
5.2.0 ^3.5.0 MIT
5.1.1 ^3.5.0 MIT
5.1.0 ^3.5.0 MIT
5.0.0 ^3.5.0 MIT