export type handler = (payload?: any, event?: MessageEvent) => any; export type TinyNewWinEventsMap = Record<`win:${string}`, (payload: any, event: MessageEvent) => void> & { WINDOW_REF_CLOSED: () => void; }; /** * @callback handler * A function to handle incoming event payloads. * @param {any} [payload] - The data sent by the emitter. * @param {MessageEvent} [event] - Metadata about the message. */ /** * Event map for {@link TinyNewWinEvents}. * Routed events are prefixed with `win:` followed by the route name. * @typedef {Record<`win:${string}`, (payload: any, event: MessageEvent) => void> & { * WINDOW_REF_CLOSED: () => void, * }} TinyNewWinEventsMap */ /** @type {new (settings?: { targetOrigin?: string, url?: string, name?: string, features?: string }) => import('../../../jsdoc/EventEmitter.mjs').ICustomEventEmitter} */ declare const TypedEventEmitter: new (settings?: { targetOrigin?: string; url?: string; name?: string; features?: string; }) => import('../../../jsdoc/EventEmitter.mjs').ICustomEventEmitter; /** * TinyNewWinEvents provides structured communication between a main window * and a child window (created using window.open) using postMessage. * * It supports routing, queuing messages until handshake is ready, * connection status checks, and close detection. * * @class */ declare class TinyNewWinEvents extends TypedEventEmitter { #private; _handleMessage: (event: MessageEvent) => void; /** * Gets the current destruction status of the instance. * * @returns {boolean} True if the instance is destroyed, false otherwise. */ get destroyed(): boolean; /** * Gets the internal handshake event name. * @returns {string} */ get readyEventName(): string; /** * Sets the internal handshake event name. * @param {string} name * @throws {TypeError} If the value is not a string. */ set readyEventName(name: string); /** * Gets the internal route event name. * @returns {string} */ get routeEventName(): string; /** * Sets the internal route event name. * @param {string} name * @throws {TypeError} If the value is not a string. */ set routeEventName(name: string); /** * Initializes a TinyNewWinEvents instance for communication. * * @param {Object} [settings={}] Configuration object. * @param {string} [settings.targetOrigin] Origin to enforce in postMessage. * @param {string} [settings.url] URL string to open. * @param {string} [settings.name] Window name (required if opening a new window). * @param {string} [settings.features] Features string for `window.open`. * * @throws {Error} If `name` is "_blank", which is not allowed. * @throws {TypeError} If `targetOrigin`, `url`, or `features` are not strings (when provided). * @throws {Error} If the window reference is invalid or already being tracked. */ constructor({ targetOrigin, url, name, features }?: { targetOrigin?: string; url?: string; name?: string; features?: string; }); /** * Returns the internal window reference. * * @returns {Window|null} */ getWin(): Window | null; /** * Closes the child window (only allowed from the host). * * @returns {void} */ close(): void; /** * Emits a message to the other window on a specific route. * If the handshake is not yet complete, the message is queued. * Throws an error if the instance has already been destroyed. * * @param {string} route - Route name used to identify the message handler. * @param {any} payload - Data to send along with the message. * @throws {Error} If the instance is already destroyed. * @returns {void} */ winEmit(route: string, payload: any): void; /** * Checks if the connection is active and the window is still open. * * @returns {boolean} */ isConnected(): boolean; /** * Registers a callback for when the window is closed. * * @param {handler} callback Callback to run on close * @returns {void} */ onClose(callback: handler): void; /** * Unregisters a previously registered close callback. * * @param {handler} callback Callback to remove * @returns {void} */ offClose(callback: handler): void; /** * Checks if the communication instance has been destroyed. * * @returns {boolean} */ isDestroyed(): boolean; /** * Destroys the communication instance, cleaning up all resources and listeners. * * @returns {void} */ destroy(): void; } export default TinyNewWinEvents; //# sourceMappingURL=TinyNewWinEvents.d.mts.map