/** * Popover component: the native element, placed and reported. * * @augments IvComponent */ export class Popover extends IvComponent { /** @type {Readonly} */ static defaults: Readonly; /** * Returns the instance attached to `el`, if any. * * @param {Element} el Host element. * @returns {Popover|undefined} The instance or `undefined`. */ static get(el: Element): Popover | undefined; /** * Returns the existing instance or creates one. * * @param {Element} el Host element. * @param {Partial} [options] Options passed in JavaScript. * @returns {Popover} The instance. */ static getOrCreate(el: Element, options?: Partial): Popover; /** * Instantiates every `[data-iv-component="popover"]` inside `root`. * * @param {ParentNode} [root] Subtree to scan. * @returns {Popover[]} Newly created instances. */ static initAll(root?: ParentNode): Popover[]; /** * @param {Element} el The `[popover]` panel itself. * @param {Partial} [options] Options passed in JavaScript. */ constructor(el: Element, options?: Partial); /** @type {boolean} Whether the panel is showing. */ _open: boolean; /** @type {HTMLElement|null} Control the panel is anchored to. */ _invoker: HTMLElement | null; /** @type {PopoverReason} Reason carried from `beforetoggle` to `toggle`. */ _reason: PopoverReason; /** @type {PopoverReason|null} Reason forced by a call to the API. */ _called: PopoverReason | null; /** @type {boolean} Whether focus was inside the panel when it closed. */ _returning: boolean; /** @type {boolean} Whether the temporary `tabindex` is ours. */ _tabindex: boolean; /** @type {EventListener|null} Resize listener while the panel is open. */ _resize: EventListener | null; /** @type {EventListener|null} Scroll listener of the measured branch. */ _scroll: EventListener | null; /** @type {number} Pending animation frame of a scroll. */ _scrollFrame: number; /** @type {string} Anchor name given to the invoker, empty when unused. */ _anchorName: string; /** * Resolved options. * * @returns {Readonly} The options. */ get options(): Readonly; /** * Whether the panel is showing. * * @returns {boolean} `true` while it is open. */ get isOpen(): boolean; /** * Control the panel is anchored to. * * @returns {HTMLElement|null} The invoker, or `null` while closed. */ get invoker(): HTMLElement | null; /** * Opens the panel through the native API. Reported with reason `api`. * * @returns {void} */ open(): void; /** * Closes the panel through the native API. Reported with reason `api`. * * @returns {void} */ close(): void; /** * Opens the panel when it is closed, closes it when it is open. * * @returns {void} */ toggle(): void; /** * The native `beforetoggle`: the cancelable half of the contract. Cancelling * `iv:open` or `iv:close` cancels the native toggle as well. * * @param {Event} event The native event. * @returns {void} */ _onBefore(event: Event): void; /** * The native `toggle`: the panel is in its new state. * * @param {Event} event The native event. * @returns {void} */ _onToggle(event: Event): void; /** * The control the panel belongs to: the invoker the browser reports, or the * nearest `[popovertarget]` pointing at this panel. * * @param {unknown} source `source` of the native event, when the browser has one. * @returns {HTMLElement|null} The invoker, or `null` when there is none. */ _resolveInvoker(source: unknown): HTMLElement | null; /** * Places the panel next to its invoker, by anchor positioning when the * browser has it and by measurement when it does not. * * @returns {void} */ _place(): void; /** * Area the panel occupies around its anchor, in the grammar of * `position-area`. * * @param {"top"|"bottom"} placement Preferred side. * @returns {string} The value written on the panel. */ _area(placement: "top" | "bottom"): string; /** * Moves the focus into the panel: the first focusable element, or the panel * itself with a `tabindex` that leaves with it. * * @returns {void} */ _focus(): void; /** * Removes every style and attribute this instance wrote. * * @returns {void} */ _clear(): void; /** * Follows the viewport while the panel is open: a resize changes the room on * each side, and a measured placement would otherwise fall off the screen. * Without anchor positioning a scroll (of the page or of any container, so * the listener captures) also moves the invoker away from the panel; it is * followed once per animation frame, passively. * * @returns {void} */ _startResize(): void; /** * Drops the resize and scroll listeners. * * @returns {void} */ _stopResize(): void; } export type PopoverOptions = { /** * Preferred side of the invoker. */ placement: "bottom" | "top"; /** * Alignment along the invoker. */ align: "start" | "center" | "end"; /** * Gap between invoker and panel, in pixels. */ offset: number; /** * Whether opening moves the focus into the panel. */ focus: boolean; }; export type PopoverReason = "trigger" | "light-dismiss" | "api"; import { IvComponent } from "../core/component.js";