UNPKG

4 kBTypeScriptView Raw
1export type ZoomSelector = string | HTMLElement | HTMLElement[] | NodeList
2
3export interface ZoomOptions {
4 /**
5 * The space outside the zoomed image.
6 *
7 * @default 0
8 */
9 margin?: number
10
11 /**
12 * The background of the overlay.
13 *
14 * @default '#fff'
15 */
16 background?: string
17
18 /**
19 * The number of pixels to scroll to close the zoom.
20 *
21 * @default 40
22 */
23 scrollOffset?: number
24
25 /**
26 * The viewport to render the zoom in.
27 *
28 * @default null
29 */
30 container?: string | HTMLElement | ZoomContainer
31
32 /**
33 * The template element to display on zoom.
34 *
35 * @default null
36 */
37 template?: string | HTMLTemplateElement
38}
39
40export interface ZoomContainer {
41 width?: number
42 height?: number
43 top?: number
44 bottom?: number
45 right?: number
46 left?: number
47}
48
49export interface ZoomOpenOptions {
50 /**
51 * The target of the zoom.
52 *
53 * If not specified, the target is the first image of the zoom.
54 *
55 * @default null
56 */
57 target?: HTMLElement
58}
59
60export interface Zoom {
61 /**
62 * Opens the zoom.
63 *
64 * @param options
65 * @returns A promise resolving with the zoom.
66 */
67 open(options?: ZoomOpenOptions): Promise<Zoom>
68
69 /**
70 * Closes the zoom.
71 *
72 * @returns A promise resolving with the zoom.
73 */
74 close(): Promise<Zoom>
75
76 /**
77 * Toggles the zoom.
78 *
79 * @param options
80 * @returns A promise resolving with the zoom.
81 */
82 toggle(options?: ZoomOpenOptions): Promise<Zoom>
83
84 /**
85 * Attaches the images to the zoom.
86 *
87 * @param selectors - The selectors describing the images.
88 * @returns The zoom.
89 */
90 attach(...selectors: ZoomSelector[]): Zoom
91
92 /**
93 * Releases the images from the zoom.
94 *
95 * @param selectors - The selectors describing the images.
96 * @returns The zoom.
97 */
98 detach(...selectors: ZoomSelector[]): Zoom
99
100 /**
101 * Updates the options.
102 *
103 * @param options
104 * @returns The zoom.
105 */
106 update(options: ZoomOptions): Zoom
107
108 /**
109 * Extends the zoom with the provided options merged with the current ones.
110 *
111 * @param options
112 * @returns The zoom.
113 */
114 clone(options?: ZoomOptions): Zoom
115
116 /**
117 * Registers an event handler on each target of the zoom.
118 *
119 * @param type - The event type to listen for.
120 * @param listener - The function to execute when the event is triggered.
121 * @param options - The event listener options (same as [`addEventListener`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Parameters))
122 * @returns The zoom.
123 */
124 on(
125 type: string,
126 listener: EventListenerOrEventListenerObject,
127 options?: boolean | AddEventListenerOptions
128 ): Zoom
129
130 /**
131 * Unregisters an event handler.
132 *
133 * @param type - The event type to unregister.
134 * @param listener - The function to remove from the event target.
135 * @param options - The event listener options (same as [`removeEventListener`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener#Parameters))
136 * @returns The zoom.
137 */
138 off(
139 type: string,
140 listener: EventListenerOrEventListenerObject,
141 options?: boolean | AddEventListenerOptions
142 ): Zoom
143
144 /**
145 * Returns the zoom options.
146 *
147 * @returns The zoom options.
148 */
149 getOptions(): ZoomOptions
150
151 /**
152 * Returns the zoom images.
153 *
154 * @returns The zoom images.
155 */
156 getImages(): HTMLElement[]
157
158 /**
159 * Returns the current zoomed image.
160 *
161 * @returns The current zoomed image.
162 */
163 getZoomedImage(): HTMLElement
164}
165
166/**
167 * Attaches a zoom effect on a selection of images.
168 *
169 * @param selector The selector to target the images.
170 * @param options The options of the zoom.
171 * @returns The zoom.
172 */
173declare function mediumZoom(
174 selector?: ZoomSelector,
175 options?: ZoomOptions
176): Zoom
177
178/**
179 * Attaches a zoom effect on a selection of images.
180 *
181 * @param options The options of the zoom.
182 * @returns The zoom.
183 */
184declare function mediumZoom(options?: ZoomOptions): Zoom
185
186export default mediumZoom
187
\No newline at end of file