🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

hpv-image-previewer

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hpv-image-previewer

Hyper Parametrizable Vanilla image previewer, the best independent image preview tool.

latest
Source
npmnpm
Version
1.0.2-b
Version published
Weekly downloads
5
-37.5%
Maintainers
1
Weekly downloads
 
Created
Source

HpvImagePreviewer

A standalone, extensible JavaScript class for displaying images or galleries in a modal overlay with advanced zoom, pan, navigation, and custom action capabilities. Fully responsive, event-driven, and easily integrated into any web project.

Preview

Modal Gallery Overview Modal overlay with gallery navigation

Zoomed Image Zoom and pan controls in action

Carousel Navigation Gallery carousel with thumbnails

Responsive Layout Fully responsive on desktop and mobile

Features

  • Modal Image & Gallery Display: Show single images or full galleries in a full-screen overlay.
  • Zoom & Pan: Mouse wheel zoom, pinch-to-zoom, and pan when zoomed.
  • Zoom Controls: Zoom in/out/reset buttons with press-and-hold for continuous zoom.
  • Gallery Navigation: Cycle through images with navigation buttons, keyboard arrows, or swipe gestures.
  • Custom Buttons: Flexible button system with custom handlers, keyboard shortcuts, and styling.
  • Touch Support: Pinch-to-zoom, swipe navigation, and touch pan.
  • Readonly Mode: Show/hide buttons based on readonly state.
  • Event Driven: Emits custom events for integration and analytics.
  • Intelligent Sizing: Overlay adapts to image aspect ratio and viewport.
  • Reusable: Single instance can display different images or galleries.
  • Customizable: Configurable button texts, callbacks, and CSS classes.
  • Accessible: Keyboard navigation and ARIA-friendly markup.

Quick Start

  • Include CSS and JS
<link rel="stylesheet" href="src/css/main.css">
<script src="src/js/main.js"></script>
  • Instantiate and Use
const previewer = new HpvImagePreviewer({
  closeButtonText: 'Close',
  isReadOnly: false,
  buttons: [
    {
      id: 'view',
      label: 'View',
      title: 'View full size image',
      customClasses: ['btn-primary'],
      visibleReadOnly: true,
      clickHandler: (image) => window.open(image.url, '_blank')
    },
    {
      id: 'star',
      label: 'Star',
      title: 'Mark as favorite',
      customClasses: ['btn-star'],
      keyPress: { key: 's', shift: true }, // Triggers with Shift+S
      clickHandler: (image) => alert('Starred: ' + image.alt)
    }
  ]
});

const imageModel = { url: 'path/to/image.jpg', alt: 'Description' };
previewer.show(imageModel);
  • Gallery Mode
const images = [
  { url: 'img1.jpg', alt: 'First' },
  { url: 'img2.jpg', alt: 'Second' }
];
previewer.showGallery(images, 0); // Start at first image

API

Constructor Options

OptionTypeDefaultDescription
buttonsArray[]Array of custom button configs
closeButtonTextstring'Close'Text for the close button
isReadOnlybooleanfalseIf true, only shows buttons with visibleReadOnly: true
minScalenumber1Minimum zoom scale
maxScalenumber5Maximum zoom scale
onClosefunctionnullCallback for close button click
onImageSwitchfunctionnullCallback for gallery navigation
isDebugbooleanfalseEnable debug logging

Button Configuration

PropertyTypeRequiredDescription
idstringâś…Unique identifier
labelstringâś…Button text
titlestring❌Tooltip text
iconstring❌CSS class for icon
visibleReadOnlyboolean❌Show in readonly mode (default: true)
customClassesArray❌Extra CSS classes for styling
clickHandlerfunctionâś…Called on click: (image, previewerInstance) => {}
keyPressObject❌Keyboard shortcut: { key: 'd', ctrl: true }

Image Model

{
  url: 'string',     // Required: Image URL
  alt: 'string',     // Optional: Alt text
  file: File,        // Optional: Original file object
  // ...any custom properties
}

Methods

  • show(imageModel)
  • showGallery(galleryImages, activeIndex = 0)
  • navigateGallery(direction)
  • hide()
  • updateOptions(newOptions)
  • toggleReadOnly()
  • setReadOnly(isReadOnly)
  • destroy()

Events

Event NameDetail PayloadDescription
hpvImagePreviewer:customButtonClick{ buttonId, image, button }Custom button clicked
hpvImagePreviewer:close{ image }Overlay closed
hpvImagePreviewer:navigate{ currentImage, currentIndex, previousImage, galleryLength, direction, cycled }Gallery navigation occurred

File Structure

src/js/
  main.js                # HpvImagePreviewer class
src/css/
  main.css               # Overlay/modal/gallery styles
src/index.html           # Sample usage
examples/
  image-previewer-standalone.html  # Advanced example
docs/
  HpvImagePreviewer-README.md      # Full documentation

Browser Support

  • Modern browsers (Chrome, Firefox, Safari, Edge)
  • Touch devices (iOS Safari, Android Chrome)
  • Requires ES6, CustomEvent, and modern CSS

Dependencies

  • None. Pure vanilla JavaScript and CSS.

License

MIT

Contributing

Pull requests and issues are welcome! Please see docs/HpvImagePreviewer-README.md for full documentation and advanced usage.

Keywords

image

FAQs

Package last updated on 31 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts