|
1 | 1 | import type { Writable } from 'svelte/store'; |
2 | 2 | import type { Models } from '../types/models'; |
3 | 3 | import type { Camera } from './camera'; |
| 4 | + |
| 5 | +/** @ts-ignore */ |
4 | 6 | import type Svelte from '../svelte/Main.svelte'; |
5 | 7 |
|
6 | 8 | import { once, deepCopy, fetchJson, jsonCache, fetchInfo, fetchAlbumInfo, idIsV5 } from './utils'; |
@@ -189,7 +191,7 @@ export class HTMLMicrioElement extends HTMLElement { |
189 | 191 | * Called when an observed attribute changes. Handles changes to `id`, `muted`, `data-grid`, `data-limited`, and `lang`. |
190 | 192 | * @internal |
191 | 193 | */ |
192 | | - attributeChangedCallback(attr:string, oldVal:string, newVal:string) { |
| 194 | + attributeChangedCallback(attr:keyof Models.Attributes.MicrioCustomAttributes, oldVal:string, newVal:string) { |
193 | 195 | switch(attr) { |
194 | 196 | case 'id': { // Handle ID change (initial load or subsequent open) |
195 | 197 | if(!this.isConnected || !newVal) return; |
@@ -255,6 +257,18 @@ export class HTMLMicrioElement extends HTMLElement { |
255 | 257 | } |
256 | 258 | } |
257 | 259 |
|
| 260 | + // Custom overloads for addEventListener to support fully typed custom Micrio events |
| 261 | + addEventListener<K extends keyof Models.MicrioEventMap>(type: K, listener: (this: HTMLMicrioElement, ev: Models.MicrioEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; |
| 262 | + addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLMicrioElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; |
| 263 | + addEventListener(type: string, listener: (this: HTMLMicrioElement, ev: Event) => any, options?: boolean | AddEventListenerOptions): void; |
| 264 | + addEventListener(type: string, listener: EventListener | EventListenerObject, useCapture?: boolean): void { super.addEventListener(type, listener, useCapture); } |
| 265 | + |
| 266 | + // Custom overloads for removeEventListener to support fully typed custom Micrio events |
| 267 | + removeEventListener<K extends keyof Models.MicrioEventMap>(type: K, listener: (this: HTMLMicrioElement, ev: Models.MicrioEventMap[K]) => any, options?: boolean | EventListenerOptions): void; |
| 268 | + removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLMicrioElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void; |
| 269 | + removeEventListener(type: string, listener: (this: HTMLMicrioElement, ev: Event) => any, options?: boolean | EventListenerOptions): void; |
| 270 | + removeEventListener(type: string, listener: EventListener | EventListenerObject, useCapture?: boolean): void { super.removeEventListener(type, listener, useCapture); } |
| 271 | + |
258 | 272 | /** Destroys the Micrio instance, cleans up resources, and removes event listeners. */ |
259 | 273 | destroy() : void { |
260 | 274 | this.current.set(undefined); // Clear current image |
@@ -348,7 +362,7 @@ export class HTMLMicrioElement extends HTMLElement { |
348 | 362 | // --- Final Setup & Open --- |
349 | 363 | this.keepRendering = !!opts.settings.keepRendering; // Set continuous rendering flag |
350 | 364 | const doOpen = opts.id || opts.gallery || opts.grid; // Check if there's something to open |
351 | | - this.events.dispatch('print', opts); // Dispatch 'print' event |
| 365 | + this.events.dispatch('print', opts as Models.ImageInfo.ImageInfo); // Dispatch 'print' event |
352 | 366 |
|
353 | 367 | // Handle lazy loading |
354 | 368 | if(opts.settings.lazyload !== undefined && 'IntersectionObserver' in window) { |
|
0 commit comments