import { Thread, type ThreadOptions, type ThreadMessageTarget } from '../../Thread.ts'; import { ThreadNestedWindow } from './ThreadNestedWindow.ts'; export interface ThreadWindowOptions, Exports = Record> extends ThreadOptions { targetOrigin?: string; } /** * Creates a thread from a `Window` created by this environment. * * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe * * @example * import {ThreadWindow} from '@quilted/threads'; * * const popup = window.open('https://my-app.com/popup', 'MyAppPopup', 'popup'); * const thread = new ThreadWindow(popup); * await thread.imports.sendMessage('Hello world!'); */ export declare class ThreadWindow, Exports = Record> extends Thread { readonly window: Window; /** * Creates a thread from a `Window` created by this environment. * * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe * * @example * import {ThreadWindow} from '@quilted/threads'; * * const popup = window.open('https://my-app.com/popup', 'MyAppPopup', 'popup'); * const thread = ThreadWindow.from(popup); * await thread.imports.sendMessage('Hello world!'); */ static from, Exports = Record>(window: Window, options?: ThreadWindowOptions): ThreadWindow; /** * Starts a thread wrapped around a `window` object, and returns the imports * of the thread. * * @example * ```ts * import {ThreadWindow} from '@quilted/threads'; * * const {getMessage} = ThreadWindow.import(window); * const message = await getMessage(); // 'Hello, world!' * * // In the nested window: * * import {ThreadNestedWindow} from '@quilted/threads'; * * ThreadNestedWindow.export(window.opener, { * async getMessage() { * return 'Hello, world!'; * }, * }); * ``` */ static import>(window: Window, options?: Omit>, 'imports'>): import("../../Thread.ts").ThreadImports>; /** * Starts a thread wrapped around a `window` object, providing the second * argument as the exports of the thread. * * @example * ```ts * import {ThreadWindow} from '@quilted/threads'; * * ThreadWindow.export(window, { * async getMessage() { * return 'Hello, world!'; * }, * }); * * // In the nested window: * * import {ThreadNestedWindow} from '@quilted/threads'; * * const {getMessage} = ThreadNestedWindow.import(window.opener); * const message = await getMessage(); // 'Hello, world!' * ``` */ static export>(window: Window, exports: Exports, options?: Omit, Exports>, 'exports'>): void; /** * Creates a thread from within a window created by a parent document (for example, * an `iframe` or popup window). * * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/opener * * @example * import {ThreadWindow} from '@quilted/threads'; * * // Inside a document opened as a popup window * const thread = ThreadWindow.opener(); * await thread.imports.sendMessage('Hello world!'); */ static opener: (>(options?: Omit>, "imports">) => ThreadNestedWindow, Record>) & { /** * Starts a thread wrapped around a nested `window` object, and returns the imports * of the thread. * * @example * ```ts * import {ThreadWindow} from '@quilted/threads'; * * const {getMessage} = ThreadWindow.opener.import(); * const message = await getMessage(); // 'Hello, world!' * * // In the parent window: * * import {ThreadWindow} from '@quilted/threads'; * * ThreadWindow.export(window, { * async getMessage() { * return 'Hello, world!'; * }, * }); * ``` */ import: >(options?: Omit>, "imports">) => import("../../Thread.ts").ThreadImports; /** * Starts a thread wrapped around a nested `window` object, providing the second * argument as the exports of the thread. * * @example * ```ts * import {ThreadWindow} from '@quilted/threads'; * * ThreadWindow.opener.export({ * async getMessage() { * return 'Hello, world!'; * }, * }); * * // In the parent window: * * import {ThreadWindow} from '@quilted/threads'; * * const {getMessage} = ThreadWindow.import(window); * const message = await getMessage(); // 'Hello, world!' * ``` */ export: >(exports: Exports_1, options?: Omit, Exports_1>, "exports">) => void; }; constructor(window: Window, { targetOrigin, ...options }?: ThreadWindowOptions); } export declare function windowToThreadTarget(window: Window, { targetOrigin }?: { targetOrigin?: string; }): ThreadMessageTarget; //# sourceMappingURL=ThreadWindow.d.ts.map