declare global { interface Window { parentIFrame: ReturnType; } } export declare namespace IFrameUtils { type ResizeMethod = (e: HTMLElement, width: boolean) => number; type Data = boolean | number | string | { [key: string]: any; }; export const resizeMethods: { elementOffset: (e: HTMLElement, width: boolean) => number; elementScroll: (e: HTMLElement, width: boolean) => number; max: (e: HTMLElement, width: boolean) => number; min: (e: HTMLElement, width: boolean) => number; lowestElement: (e: HTMLElement, width: boolean) => any; }; interface IChildFrameProps { targetOrigins: string[]; method: ResizeMethod; autoResize?: boolean; canLog?: boolean; } export interface IPageInfo { iframeHeight: number; iframeWidth: number; iframeTop: number; iframeLeft: number; clientHeight: number; clientWidth: number; offsetTop: number; offsetLeft: number; scrollTop: number; scrollLeft: number; documentHeight: number; documentWidth: number; windowHeight: number; windowWidth: number; } /** * Sets up IFrame child and returns IFrame functions * * initChild({ * targetOrigins: ["http://127.0.0.1:5500"], * autoresize: true, * method: IFrameUtils.resizeMethods.elementOffset, * canLog: false * }) */ export function initChild({ targetOrigins, autoResize, method }: IChildFrameProps): { iFrameElement: HTMLElement; sendIframeTransform: (target: HTMLElement) => void; postMessage: (messageName: string, messageToPost: {}, targets?: string[]) => void; fetch: (messageName: string, onReceive: (data: any) => void, eventListener?: string, targets?: string[]) => void; getPageInfo: (callBack: (data: IPageInfo) => void, resendOnResizeScroll?: boolean) => void; receiveMessage: typeof receiveMessage; getLocalStorageItem: (keyName: string) => { [name: string]: any; }; setLocalStorageItem: (keyName: string, data: { [name: string]: any; }) => void; removeCallOnResize: { (messageName: string): void; (callBack: (data: any) => void): void; }; localStorageLoaded: boolean; }; interface IParentFrameProps { targetDiv: HTMLElement; iframeSrc: string; targetOrigin: string; iframe?: HTMLIFrameElement; canLog?: boolean; } /** * Sets up IFrame parent and returns IFrame * * initParent({ * targetDiv: document.querySelector('body'), * iframeSrc: "http://localhost:8055/video-embed/NocXEwsJGOQ", * targetOrigin: "http://localhost:8055", * iframe: document.querySelector('iframe') * }) */ export function initParent({ targetDiv, iframeSrc, targetOrigin, iframe, }: IParentFrameProps): { iframe: HTMLIFrameElement; receiveMessage: typeof receiveMessage; receiveFetchRequest: (messageName: string, data: Data | (() => any) | (() => Promise)) => void; postMessage: (messageName: string, messageToPost: {}, target?: string) => void; }; function receiveMessage(messageName: string, onReceive: (data: any) => void): void; export function getPopupBounces(pageInfo: IPageInfo): { top: number; height: number; }; export {}; }