lite-image-preview 1.0.3 → 1.1.0

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
@@ -83,12 +83,13 @@ If the image fails to load, `previewImage()` throws an error.
83
83
 
84
84
  ## API overview
85
85
 
86
- ### `previewImage(url, dispose?)`
86
+ ### `previewImage(url, dispose?, options?)`
87
87
 
88
88
  Opens a preview dialog for a raster image.
89
89
 
90
90
  * `url` — Image URL.
91
91
  * `dispose?` — Optional callback invoked after the dialog fully closes.
92
+ * `options?` — Optional preview configuration (see `ImagePreviewOptions`).
92
93
 
93
94
  Returns:
94
95
 
@@ -234,6 +235,13 @@ The package exports the main types so advanced consumers can build custom adapte
234
235
  * `TransformState`
235
236
  * `ViewBox`
236
237
  * `PreviewCloseHandle`
238
+ * `ImagePreviewOptions`
239
+
240
+ `ImagePreviewOptions` includes:
241
+ - `minScale?: number` — minimum zoom scale (default: 0.1)
242
+ - `maxScale?: number` — maximum zoom scale (default: 8)
243
+ - `fitPadding?: number` — padding around the image when fitting to stage (default: 0)
244
+ - `fitMaxScale?: number` — maximum scale when fitting to stage (default: 1)
237
245
 
238
246
  ---
239
247
 
package/dist/main.cjs CHANGED
@@ -237,7 +237,7 @@ function createPreview(content, initAdapter, dispose) {
237
237
  function createTransformAdapter(content, stage, baseWidth, baseHeight, options) {
238
238
  const minScale = options?.minScale ?? .1;
239
239
  const maxScale = options?.maxScale ?? 8;
240
- const fitPadding = options?.fitPadding ?? 32;
240
+ const fitPadding = options?.fitPadding ?? 0;
241
241
  const fitMaxScale = options?.fitMaxScale ?? 1;
242
242
  const prev = {
243
243
  transform: content.style.transform,
@@ -527,7 +527,7 @@ function bindGestures(content, adapter) {
527
527
  * The returned promise resolves to a close handle when the preview is ready.
528
528
  * If the image fails to load, the promise resolves to null.
529
529
  */
530
- async function previewImage(url, dispose) {
530
+ async function previewImage(url, dispose, options) {
531
531
  const img = document.createElement("img");
532
532
  img.src = url;
533
533
  img.alt = "";
@@ -545,10 +545,11 @@ async function previewImage(url, dispose) {
545
545
  }
546
546
  return createPreview(img, (stage) => {
547
547
  return createTransformAdapter(img, stage, img.naturalWidth || 1, img.naturalHeight || 1, {
548
- minScale: .1,
549
- maxScale: 8,
550
- fitPadding: 32,
551
- fitMaxScale: 1
548
+ minScale: 0,
549
+ maxScale: 20,
550
+ fitPadding: 0,
551
+ fitMaxScale: 1,
552
+ ...options
552
553
  });
553
554
  }, dispose);
554
555
  }
package/dist/main.d.ts CHANGED
@@ -85,6 +85,27 @@ interface PreviewAdapter extends PreviewController {
85
85
  * Factory function used by createPreview to initialize a rendering adapter.
86
86
  */
87
87
  type PreviewAdapterFactory = (stage: HTMLElement) => PreviewAdapter;
88
+ /**
89
+ * Options for image previews.
90
+ */
91
+ interface ImagePreviewOptions {
92
+ /**
93
+ * Minimum zoom scale (default: 0.1).
94
+ */
95
+ minScale?: number;
96
+ /**
97
+ * Maximum zoom scale (default: 8).
98
+ */
99
+ maxScale?: number;
100
+ /**
101
+ * Padding around the image when fitting to stage (default: 0).
102
+ */
103
+ fitPadding?: number;
104
+ /**
105
+ * Maximum scale when fitting to stage (default: 1).
106
+ */
107
+ fitMaxScale?: number;
108
+ }
88
109
  //#endregion
89
110
  //#region src/preview.d.ts
90
111
  /**
@@ -105,7 +126,7 @@ declare function createPreview(content: HTMLElement, initAdapter: PreviewAdapter
105
126
  * The returned promise resolves to a close handle when the preview is ready.
106
127
  * If the image fails to load, the promise resolves to null.
107
128
  */
108
- declare function previewImage(url: string, dispose?: () => void): Promise<PreviewCloseHandle>;
129
+ declare function previewImage(url: string, dispose?: () => void, options?: ImagePreviewOptions): Promise<PreviewCloseHandle>;
109
130
  /**
110
131
  * Open an SVG preview dialog.
111
132
  *
@@ -113,4 +134,4 @@ declare function previewImage(url: string, dispose?: () => void): Promise<Previe
113
134
  */
114
135
  declare function previewSvg(svg: SVGSVGElement, dispose?: () => void): Promise<PreviewCloseHandle>;
115
136
  //#endregion
116
- export { type Point, type PreviewAdapter, type PreviewAdapterFactory, type PreviewCloseHandle, type PreviewController, type TransformState, type ViewBox, createPreview, previewImage, previewSvg };
137
+ export { type ImagePreviewOptions, type Point, type PreviewAdapter, type PreviewAdapterFactory, type PreviewCloseHandle, type PreviewController, type TransformState, type ViewBox, createPreview, previewImage, previewSvg };
package/dist/main.js CHANGED
@@ -236,7 +236,7 @@ function createPreview(content, initAdapter, dispose) {
236
236
  function createTransformAdapter(content, stage, baseWidth, baseHeight, options) {
237
237
  const minScale = options?.minScale ?? .1;
238
238
  const maxScale = options?.maxScale ?? 8;
239
- const fitPadding = options?.fitPadding ?? 32;
239
+ const fitPadding = options?.fitPadding ?? 0;
240
240
  const fitMaxScale = options?.fitMaxScale ?? 1;
241
241
  const prev = {
242
242
  transform: content.style.transform,
@@ -526,7 +526,7 @@ function bindGestures(content, adapter) {
526
526
  * The returned promise resolves to a close handle when the preview is ready.
527
527
  * If the image fails to load, the promise resolves to null.
528
528
  */
529
- async function previewImage(url, dispose) {
529
+ async function previewImage(url, dispose, options) {
530
530
  const img = document.createElement("img");
531
531
  img.src = url;
532
532
  img.alt = "";
@@ -544,10 +544,11 @@ async function previewImage(url, dispose) {
544
544
  }
545
545
  return createPreview(img, (stage) => {
546
546
  return createTransformAdapter(img, stage, img.naturalWidth || 1, img.naturalHeight || 1, {
547
- minScale: .1,
548
- maxScale: 8,
549
- fitPadding: 32,
550
- fitMaxScale: 1
547
+ minScale: 0,
548
+ maxScale: 20,
549
+ fitPadding: 0,
550
+ fitMaxScale: 1,
551
+ ...options
551
552
  });
552
553
  }, dispose);
553
554
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lite-image-preview",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
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/main.ts CHANGED
@@ -6,6 +6,7 @@ export type {
6
6
  PreviewController,
7
7
  PreviewAdapter,
8
8
  PreviewAdapterFactory,
9
+ ImagePreviewOptions,
9
10
  } from './types'
10
11
 
11
12
  export { createPreview, previewImage, previewSvg } from './preview'
package/src/preview.ts CHANGED
@@ -5,6 +5,7 @@ import type {
5
5
  PreviewCloseHandle,
6
6
  TransformState,
7
7
  ViewBox,
8
+ ImagePreviewOptions,
8
9
  } from './types'
9
10
  import {
10
11
  clamp,
@@ -184,16 +185,11 @@ function createTransformAdapter(
184
185
  stage: HTMLElement,
185
186
  baseWidth: number,
186
187
  baseHeight: number,
187
- options?: {
188
- minScale?: number
189
- maxScale?: number
190
- fitPadding?: number
191
- fitMaxScale?: number
192
- }
188
+ options?: ImagePreviewOptions
193
189
  ): PreviewAdapter {
194
190
  const minScale = options?.minScale ?? 0.1
195
191
  const maxScale = options?.maxScale ?? 8
196
- const fitPadding = options?.fitPadding ?? 32
192
+ const fitPadding = options?.fitPadding ?? 0
197
193
  const fitMaxScale = options?.fitMaxScale ?? 1
198
194
 
199
195
  const prev = {
@@ -573,7 +569,8 @@ function bindGestures(
573
569
  */
574
570
  export async function previewImage(
575
571
  url: string,
576
- dispose?: () => void
572
+ dispose?: () => void,
573
+ options?: ImagePreviewOptions
577
574
  ): Promise<PreviewCloseHandle> {
578
575
  const img = document.createElement('img')
579
576
 
@@ -602,8 +599,9 @@ export async function previewImage(
602
599
  return createTransformAdapter(img, stage, w, h, {
603
600
  minScale: 0,
604
601
  maxScale: 20,
605
- fitPadding: 10,
602
+ fitPadding: 0,
606
603
  fitMaxScale: 1,
604
+ ...options,
607
605
  })
608
606
  },
609
607
  dispose
package/src/types.ts CHANGED
@@ -96,3 +96,25 @@ export interface PreviewAdapter extends PreviewController {
96
96
  * Factory function used by createPreview to initialize a rendering adapter.
97
97
  */
98
98
  export type PreviewAdapterFactory = (stage: HTMLElement) => PreviewAdapter
99
+
100
+ /**
101
+ * Options for image previews.
102
+ */
103
+ export interface ImagePreviewOptions {
104
+ /**
105
+ * Minimum zoom scale (default: 0.1).
106
+ */
107
+ minScale?: number
108
+ /**
109
+ * Maximum zoom scale (default: 8).
110
+ */
111
+ maxScale?: number
112
+ /**
113
+ * Padding around the image when fitting to stage (default: 0).
114
+ */
115
+ fitPadding?: number
116
+ /**
117
+ * Maximum scale when fitting to stage (default: 1).
118
+ */
119
+ fitMaxScale?: number
120
+ }