lite-image-preview 1.0.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/LICENSE +24 -0
- package/README.md +286 -0
- package/dist/main.cjs +722 -0
- package/dist/main.d.ts +116 -0
- package/dist/main.js +719 -0
- package/package.json +63 -0
- package/rolldown.config.js +18 -0
- package/src/main.ts +11 -0
- package/src/preview.ts +834 -0
- package/src/types.ts +98 -0
- package/src/util.ts +102 -0
- package/tsconfig.app.json +47 -0
- package/tsconfig.json +11 -0
- package/tsconfig.node.json +24 -0
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A 2D point in viewport/client coordinates.
|
|
4
|
+
*/
|
|
5
|
+
type Point = {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A simple transform state used by the default transform-based adapter.
|
|
11
|
+
*/
|
|
12
|
+
type TransformState = {
|
|
13
|
+
scale: number;
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* An SVG viewBox rectangle.
|
|
19
|
+
*/
|
|
20
|
+
type ViewBox = {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
w: number;
|
|
24
|
+
h: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* A function that closes an opened preview dialog.
|
|
28
|
+
*/
|
|
29
|
+
type PreviewCloseHandle = () => void;
|
|
30
|
+
/**
|
|
31
|
+
* The minimum controller interface used by the preview container.
|
|
32
|
+
* Custom adapters may extend this behavior, but these methods are required.
|
|
33
|
+
*/
|
|
34
|
+
interface PreviewController {
|
|
35
|
+
/**
|
|
36
|
+
* Zoom in or out using a wheel event.
|
|
37
|
+
* Implementations should call preventDefault() when appropriate.
|
|
38
|
+
*/
|
|
39
|
+
zoomWithWheel: (e: WheelEvent) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Release listeners and internal state created by the adapter.
|
|
42
|
+
*/
|
|
43
|
+
destroy: () => void;
|
|
44
|
+
/**
|
|
45
|
+
* Restore the element's inline styles or attributes back to the pre-preview state.
|
|
46
|
+
*/
|
|
47
|
+
resetStyle: () => void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The public adapter interface used by createPreview.
|
|
51
|
+
*
|
|
52
|
+
* The preview container handles dialog lifecycle and gesture routing,
|
|
53
|
+
* while the adapter owns the actual rendering backend.
|
|
54
|
+
* For example:
|
|
55
|
+
* - image previews can use CSS transform
|
|
56
|
+
* - SVG previews can use viewBox
|
|
57
|
+
*/
|
|
58
|
+
interface PreviewAdapter extends PreviewController {
|
|
59
|
+
/**
|
|
60
|
+
* Reset the visual state to the initial "fit to stage" layout.
|
|
61
|
+
*/
|
|
62
|
+
fitToStage: (stage: HTMLElement) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Move the content by a delta measured in client pixels.
|
|
65
|
+
*/
|
|
66
|
+
panBy: (dx: number, dy: number) => void;
|
|
67
|
+
/**
|
|
68
|
+
* Zoom around a specific client coordinate.
|
|
69
|
+
*
|
|
70
|
+
* @param clientX - Client X coordinate.
|
|
71
|
+
* @param clientY - Client Y coordinate.
|
|
72
|
+
* @param factor - Multiplicative zoom factor.
|
|
73
|
+
*/
|
|
74
|
+
zoomAt: (clientX: number, clientY: number, factor: number) => void;
|
|
75
|
+
/**
|
|
76
|
+
* Start a pinch gesture using two points in client coordinates.
|
|
77
|
+
*/
|
|
78
|
+
beginPinch: (points: [Point, Point]) => void;
|
|
79
|
+
/**
|
|
80
|
+
* Update an active pinch gesture using two points in client coordinates.
|
|
81
|
+
*/
|
|
82
|
+
updatePinch: (points: [Point, Point]) => void;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Factory function used by createPreview to initialize a rendering adapter.
|
|
86
|
+
*/
|
|
87
|
+
type PreviewAdapterFactory = (stage: HTMLElement) => PreviewAdapter;
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/preview.d.ts
|
|
90
|
+
/**
|
|
91
|
+
* Open a modal preview dialog for arbitrary content.
|
|
92
|
+
*
|
|
93
|
+
* The dialog container handles lifecycle and gestures, while the adapter
|
|
94
|
+
* implements the actual rendering backend.
|
|
95
|
+
*
|
|
96
|
+
* @param content - The DOM element to preview.
|
|
97
|
+
* @param initAdapter - Factory that creates a preview adapter after the stage is mounted.
|
|
98
|
+
* @param dispose - Optional cleanup callback called after the dialog closes.
|
|
99
|
+
* @returns A function that closes the preview dialog.
|
|
100
|
+
*/
|
|
101
|
+
declare function createPreview(content: HTMLElement, initAdapter: PreviewAdapterFactory, dispose?: () => void): PreviewCloseHandle;
|
|
102
|
+
/**
|
|
103
|
+
* Open an image preview dialog.
|
|
104
|
+
*
|
|
105
|
+
* The returned promise resolves to a close handle when the preview is ready.
|
|
106
|
+
* If the image fails to load, the promise resolves to null.
|
|
107
|
+
*/
|
|
108
|
+
declare function previewImage(url: string, dispose?: () => void): Promise<PreviewCloseHandle | null>;
|
|
109
|
+
/**
|
|
110
|
+
* Open an SVG preview dialog.
|
|
111
|
+
*
|
|
112
|
+
* The returned promise resolves to a close handle when the preview is ready.
|
|
113
|
+
*/
|
|
114
|
+
declare function previewSvg(svg: SVGSVGElement, dispose?: () => void): Promise<PreviewCloseHandle>;
|
|
115
|
+
//#endregion
|
|
116
|
+
export { type Point, type PreviewAdapter, type PreviewAdapterFactory, type PreviewCloseHandle, type PreviewController, type TransformState, type ViewBox, createPreview, previewImage, previewSvg };
|