// Types for the Areaform snippet's `element.areaform` and its `areaform:` events. // https://areaform.app/docs/camera/ // // Served beside the snippet, as https://cdn.areaform.app/v1/areaform.d.ts, so it always matches // the snippet that runs. Save it in your project, e.g. as `src/areaform.d.ts`, and // `element.areaform` and the `areaform:…` events are typed on every HTMLElement; the interfaces // can be imported from it too. /** A point on the plan, in metres: x east, y south. */ export type Vec2 = [number, number]; /** A point in the 3D view, in metres: x east, y up, z south. */ export type Vec3 = [number, number, number]; /** A camera, as `getCamera` gives it. With `levelId`, `flyTo` shows that Level first. */ export interface PlanCamera { position: Vec3; /** The point it looks at. */ target: Vec3; levelId?: string; } /** What a flight's Promise resolves with: `interrupted` when something took the camera on the way. */ export interface FlightResult { interrupted: boolean; } /** How long a flight takes. */ export interface FlyToOptions { /** Seconds; 0 jumps there. A Viewpoint's own flight time, or 3, when absent (1.5 to turn). */ seconds?: number; } /** How `lookAt` turns the camera, and how near it ends. */ export interface LookAtOptions extends FlyToOptions { /** Metres from the camera to what it looks at, once there. */ distance?: number; } /** What each event tells, as `on`'s handler gets it and as the `areaform:…` DOM event's `detail`. */ export interface AreaformEvents { /** Another Level is shown, for any reason: the page, the Level switcher or a route. */ levelchange: { levelId: string }; /** A flight started with `flyTo` arrived: at a Viewpoint (its id) or at a camera (`id` null). */ viewpoint: { id: string | null; levelId: string }; /** A visitor clicked a Zone: its id, its Level and its `data`. */ zoneclick: { id: string; levelId: string; data: Record | undefined }; /** The tour reached a Viewpoint and stays there a while. */ tourstep: { id: string; levelId: string; index: number }; /** * Nobody used the page for `data-idle-reset` seconds. The plan is then put back as it opened, * unless the DOM event's `preventDefault()` keeps it. */ idle: { seconds: number }; /** The plan was put back as it opened, by `reset()` or after `idle`. */ reset: undefined; } /** `element.areaform`, on the snippet's element once the plan is drawn (`areaform:ready`). */ export interface AreaformPlan { /** Flies to a Viewpoint by its id, or to a camera. */ flyTo(to: string | PlanCamera, options?: FlyToOptions): Promise; /** Turns to a Zone by its id, or to a plan point. */ lookAt(to: string | Vec2, options?: LookAtOptions): Promise; /** Puts the camera along the shown Level's Viewpoints, 0 to 1. */ setProgress(t: number): void; /** Shows another Level, by its id. */ setLevel(levelId: string): void; /** The id of the Level shown. */ getLevel(): string; /** The camera now, in the 3D view's coordinates; null before the plan is drawn. */ getCamera(): Required | null; /** Puts the plan back as it opened, for the next visitor at a kiosk. */ reset(): void; /** * Opens a Zone as `data-to` does: with Here, the way to it at once; without, its Level with * its card open; without Directions, highlighted on its Level. Resolves false when the plan has * no such Zone. */ showPlace(zoneId: string): Promise; /** Draws these Zones, by id, in the highlight colour; `[]` clears it. */ highlight(zoneIds: string[]): void; /** * Brings these Zones forward on every Level, keeping their colours with a thick outline, and * fades every other Zone, e.g. the shops of one category; `[]` ends it. */ focus(zoneIds: string[]): void; /** Calls `handler` on each `event`; returns a function that stops it. */ on( event: E, handler: (detail: AreaformEvents[E]) => void, ): () => void; } /** * The DOM events on the snippet's element, which bubble: `areaform:ready` once the plan is drawn, * then one for each of `AreaformEvents`, with its `detail`. */ export type AreaformDomEvents = { 'areaform:ready': CustomEvent } & { [E in keyof AreaformEvents as `areaform:${E}`]: CustomEvent; }; declare global { interface HTMLElement { /** The plan's handle, once `areaform:ready` has been sent; absent on other elements. */ areaform?: AreaformPlan; } // Adds the events to the DOM's own map, so `addEventListener` knows each one's `detail`. // eslint-disable-next-line @typescript-eslint/no-empty-object-type interface HTMLElementEventMap extends AreaformDomEvents {} }