hana-img-viewer
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
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 | |
| 4.0.0 | ^3.5.0 | MIT | |
| 3.1.0 | MIT | ||
| 3.0.0 | MIT | ||
| 2.0.2 | MIT | ||
| 2.0.1 | MIT | ||
| 2.0.0 | MIT | ||
| 1.2.9 | MIT | ||
| 1.2.8 | MIT | ||
| 1.2.7 | MIT | ||
| 1.2.6 | MIT | ||
| 1.2.5 | MIT | ||
| 1.2.4 | MIT | ||
| 1.2.3 | MIT | ||
| 1.2.2 | MIT | ||
| 1.2.1 | MIT | ||
| 1.1.1 | MIT | ||
| 1.1.0 | MIT | ||
| 1.0.5 | MIT | ||
| 1.0.4 | MIT | ||
| 0.0.0 | ISC |