import { IAdvantageWrapper, AdvantageAd, AdvantageMessage } from '../../types'; /** * AdvantageAdSlotResponder can be used by website owners/publishers if they already have their own custom implementations of high impact ad formats * or if they do not want to use the AdvantageWrapper component for some reason. It takes care of listening for messages from Advantage ads and handling them. * It will handle the creation of a new session, format requests, and format confirmations. * @public * @remarks * This class is internally used by the AdvantageWrapper component to handle messages from Advantage ads. It can also be used by website owners/publishers to handle messages from ads if they have their own custom implementations of high-impact ad formats. * * @example * To handle messages from Advantage ads in a custom implementation, you can create an instance of the AdvantageAdSlotResponder class and pass in the configuration object. * ```typescript * new AdvantageAdSlotResponder({ * adSlotElement: document.querySelector("#the-ad-slot-element")!, * formatRequestHandler: (format, parentElement) => { * return new Promise((resolve, reject) => { * // handle the format request here, e.g. by transforming the parent element into the requested format * // resolve the promise if the format transformation was succesful or reject it if it failed * }); * }); * ``` */ export declare class AdvantageAdSlotResponder { #private; ad: AdvantageAd | null; /** * Constructs a new instance of the AdvantageAdSlotResponder, initializing it with the provided configuration. * * @param config - The configuration object for the class instance. * @param config.adSlotElement - The HTML element that is/contains the ad slot where Advantage ads will loaded/displayed. * @param config.formatRequestHandler - An optional function that handles format requests. It takes a format string and a parent element as arguments. This function can be used to customize the handling of different ad formats. * @param config.messageValidator - An optional function that validates incoming messages. It takes a parent element (which can be an `HTMLElement` or an `IAdvantageWrapper`) and the message event as arguments. It should return a boolean indicating whether the message is valid. */ constructor(config: { adSlotElement: HTMLElement; formatRequestHandler?: (format: string, parentElement: HTMLElement) => Promise; messageValidator?: (parentElement: HTMLElement | IAdvantageWrapper, message: MessageEvent) => boolean; }); /** * Sends a message to the creative through the established MessagePort channel. * This method ensures messages are delivered even when the creative is nested in multiple iframes. * * @param message - The message to send to the creative * @returns true if the message was sent successfully, false if no message channel is established * * @public * @example * ```typescript * // Send a scroll progress update to the creative * responder.sendMessage({ * type: 'advantage', * action: 'SCROLL_PROGRESS', * progress: 0.5 * }); * ``` */ sendMessage(message: Partial): boolean; }