Skip to content

Image Preview API

v0.3.21 · Latest stable

The default immersive preset shows only a centered image, without a header, toolbar, or scrollbars. The panel follows the scaled image dimensions but never exceeds the viewport area left after padding.

Minimal example

ts
import { bindImagePreview } from 'sodialog'

const binding = bindImagePreview({ root: document.querySelector('.help-content')! })
binding.destroy()
ts
import { openImagePreview } from 'sodialog'

const preview = openImagePreview('/images/manual.png', {
  alt: 'Product instructions',
  showToolbar: true,
})
preview.setScale(1.5)

Methods

MethodReturnsDescription
openImagePreview(source, options?)SoImagePreviewHandleOpen a URL or HTMLImageElement immediately.
bindImagePreview(options?)SoImagePreviewBindingHandleDelegate image clicks from a root node.

Options

OptionTypeDefaultDescription
titlestringimage alt or Image previewAccessible name and optional visible title.
altstringsource image altOverrides preview alternative text.
initialScale'fit' | 'original' | number'fit'Initial scale; fit only shrinks oversized images.
minScalenumber0.25Minimum zoom.
maxScalenumber4Maximum zoom.
wheelStepnumber0.1Mouse-wheel zoom increment.
viewportPaddingnumber32Total space reserved around the viewport.
resizeWithScalebooleantrueResize the panel with the scaled image.
showHeaderbooleanfalseShow the title and close button.
showToolbarbooleanfalseShow zoom-out, scale, zoom-in, and 1:1 controls.
showScalebooleantrueShow the current zoom percentage when the toolbar is enabled.
overflow'hidden' | 'auto''hidden'Enable scrollbars when requested.

Binding options also accept root?: ParentNode (default document) and selector?: string (default img). The preview handle exposes image, scale(), and clamped setScale(scale) in addition to SoDialogHandle. Call the binding handle's destroy() when its host is removed.

Released under the MIT License.