import type { CloseReason, Item } from "../types.mjs"; /** * Lifecycle hooks (Phase 2 of the v1.0 refactor). These let * plugins and controlled-mode consumers observe and gate viewer * transitions without having to subclass `PencereViewer` or patch * internal methods. * * `will*` hooks run before the transition and may be async — the * viewer awaits them, so long-running hooks block the user action. * Throwing from a `will*` hook aborts the transition (the error * propagates to the caller of `open()` / `close()`). * * `did*` hooks run after the transition has committed and are * fire-and-forget: thrown errors are swallowed with a console * warning so one misbehaving plugin can't take down the viewer. * * All hooks receive a small context object so plugins can read * state without reaching into the viewer instance. */ export interface PencereHooks { /** Called just before `core.open()` runs. Throw to abort the open. */ willOpen?: (ctx: OpenHookContext) => void | Promise; /** Called after the dialog is shown and the first render has committed. */ didOpen?: (ctx: OpenHookContext) => void | Promise; /** Called just before `core.close()` runs. Throw to abort the close. */ willClose?: (ctx: CloseHookContext) => void | Promise; /** Called after the dialog is hidden. */ didClose?: (ctx: CloseHookContext) => void | Promise; /** Called at the start of `renderSlide()` after prepare but before load. */ willRender?: (ctx: RenderHookContext) => void | Promise; /** Called after the slide is fully mounted into the slot. */ didRender?: (ctx: RenderHookContext) => void | Promise; /** * Called after the active slide index has changed. `willNavigate` * is intentionally omitted for now: navigation flows through * `core.next()` / `prev()` / `goTo()` directly from gestures and * keyboard, so a gating hook would require wrapping every call * site. Revisit in v1.1 alongside controlled mode (#6). */ didNavigate?: (ctx: NavigateHookContext) => void | Promise; } export interface OpenHookContext { /** Target index being opened (may be undefined → core resolves default). */ index: number | undefined; /** Element the user clicked to open, if any. */ trigger?: HTMLElement; /** Current (pre-open) item list. */ items: readonly T[]; } export interface CloseHookContext { reason: CloseReason; } export interface RenderHookContext { index: number; item: T; } export interface NavigateHookContext { from: number; to: number; item: T; } /** * Run a `will*` hook. Awaited so hook errors propagate to the * caller and can abort the action. */ export declare function runWillHook(hook: ((ctx: Ctx) => void | Promise) | undefined, ctx: Ctx): Promise; /** * Run a `did*` hook. Fire-and-forget: a throwing plugin logs a * warning but does not break the viewer. */ export declare function runDidHook(hook: ((ctx: Ctx) => void | Promise) | undefined, ctx: Ctx, label: string): void;