lite-image-preview 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -77,7 +77,7 @@ if (close) {
77
77
  }
78
78
  ```
79
79
 
80
- If the image fails to load, `previewImage()` resolves to `null`.
80
+ If the image fails to load, `previewImage()` throws an error.
81
81
 
82
82
  ---
83
83
 
@@ -92,7 +92,7 @@ Opens a preview dialog for a raster image.
92
92
 
93
93
  Returns:
94
94
 
95
- * `Promise<PreviewCloseHandle | null>`
95
+ * `Promise<PreviewCloseHandle>`
96
96
 
97
97
  ### `previewSvg(svg, dispose?)`
98
98
 
package/dist/main.cjs CHANGED
@@ -539,9 +539,9 @@ async function previewImage(url, dispose) {
539
539
  `;
540
540
  try {
541
541
  await waitForImageLoad(img);
542
- } catch {
542
+ } catch (e) {
543
543
  dispose?.();
544
- return null;
544
+ throw new Error("Failed to load image", { cause: e });
545
545
  }
546
546
  return createPreview(img, (stage) => {
547
547
  return createTransformAdapter(img, stage, img.naturalWidth || 1, img.naturalHeight || 1, {
@@ -676,7 +676,7 @@ function createSvgViewBoxAdapter(svg) {
676
676
  }
677
677
  function zoomWithWheel(e) {
678
678
  e.preventDefault();
679
- zoomAt(e.clientX, e.clientY, Math.exp(-e.deltaY * .0015));
679
+ zoomAt(e.clientX, e.clientY, Math.exp(e.deltaY * .0015));
680
680
  }
681
681
  function destroy() {
682
682
  pinchStart = null;
package/dist/main.d.ts CHANGED
@@ -105,7 +105,7 @@ declare function createPreview(content: HTMLElement, initAdapter: PreviewAdapter
105
105
  * The returned promise resolves to a close handle when the preview is ready.
106
106
  * If the image fails to load, the promise resolves to null.
107
107
  */
108
- declare function previewImage(url: string, dispose?: () => void): Promise<PreviewCloseHandle | null>;
108
+ declare function previewImage(url: string, dispose?: () => void): Promise<PreviewCloseHandle>;
109
109
  /**
110
110
  * Open an SVG preview dialog.
111
111
  *
package/dist/main.js CHANGED
@@ -538,9 +538,9 @@ async function previewImage(url, dispose) {
538
538
  `;
539
539
  try {
540
540
  await waitForImageLoad(img);
541
- } catch {
541
+ } catch (e) {
542
542
  dispose?.();
543
- return null;
543
+ throw new Error("Failed to load image", { cause: e });
544
544
  }
545
545
  return createPreview(img, (stage) => {
546
546
  return createTransformAdapter(img, stage, img.naturalWidth || 1, img.naturalHeight || 1, {
@@ -675,7 +675,7 @@ function createSvgViewBoxAdapter(svg) {
675
675
  }
676
676
  function zoomWithWheel(e) {
677
677
  e.preventDefault();
678
- zoomAt(e.clientX, e.clientY, Math.exp(-e.deltaY * .0015));
678
+ zoomAt(e.clientX, e.clientY, Math.exp(e.deltaY * .0015));
679
679
  }
680
680
  function destroy() {
681
681
  pinchStart = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lite-image-preview",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Lightweight image and SVG preview dialog with smooth pinch zoom, crisp SVG scaling, and mobile-friendly gesture handling.",
5
5
  "keywords": [
6
6
  "front-end",
package/src/preview.ts CHANGED
@@ -574,7 +574,7 @@ function bindGestures(
574
574
  export async function previewImage(
575
575
  url: string,
576
576
  dispose?: () => void
577
- ): Promise<PreviewCloseHandle | null> {
577
+ ): Promise<PreviewCloseHandle> {
578
578
  const img = document.createElement('img')
579
579
 
580
580
  img.src = url
@@ -588,9 +588,9 @@ export async function previewImage(
588
588
 
589
589
  try {
590
590
  await waitForImageLoad(img)
591
- } catch {
591
+ } catch (e) {
592
592
  dispose?.()
593
- return null
593
+ throw new Error('Failed to load image', { cause: e });
594
594
  }
595
595
 
596
596
  return createPreview(
@@ -779,7 +779,8 @@ function createSvgViewBoxAdapter(svg: SVGSVGElement): PreviewAdapter {
779
779
  e.preventDefault()
780
780
 
781
781
  // Wheel up (deltaY < 0) zooms in; wheel down zooms out.
782
- zoomAt(e.clientX, e.clientY, Math.exp(-e.deltaY * 0.0015))
782
+ // The SVG logic has a specified problem that reverses the factor
783
+ zoomAt(e.clientX, e.clientY, Math.exp(e.deltaY * 0.0015))
783
784
  }
784
785
 
785
786
  function destroy() {