/** * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/IntersectionObserver} */ type ObserverOptions = { root?: HTMLElement; rootMargin: string; threshold: number[]; }; type PostTrackerConfig = { options?: ObserverOptions; query: string; returnVisibleElement: boolean; minMillisecondsToReport?: number; observerUpdateEventString?: string; liveBlogWrapperQuery?: string; liveBlogWrapper?: HTMLElement; onEntersViewport: (args: { timestamp: string; element?: HTMLElement; }) => void; onRead: (args: { post: object; viewport: ViewPort; summary: object[]; }) => void; onError: (event: Error) => void; }; type ViewPort = { height: number; width: number; }; /** * A class representing an intersection observer tracker. * * Used to track how a user reads through articles on FT pages. * * If no elements are found IntersectionObserverTracker the onError callback is called. */ export declare class PostTracker { config: PostTrackerConfig; currentlyObservedElements: Set; visibleElements: Set; wrapperElement: HTMLElement | null; defaultOptions: { root: null; rootMargin: string; threshold: number[]; }; onEntersViewport: PostTrackerConfig['onEntersViewport']; onRead: PostTrackerConfig['onRead']; onError: PostTrackerConfig['onError']; observer: IntersectionObserver; constructor(config: PostTrackerConfig); setUp(): void; /** * checks if the PostTrackerConfig passed in is valid * * @returns {Boolean} */ isValidConfig(): boolean; /** * Handles reporting when a DOM element gets into the view * Also reports when a post has been on the viewport for more than 5s */ manageIntersection(entries: IntersectionObserverEntry[]): void; /** * Adds window visibility data to dataset.visibilityData for all DOM elements if this.visibleElements */ handleVisibilityChange(event: Event): void; /** * Starts observing a list of elements that match query. * Calls the on error callback if no element is found. */ observeElements(query: string): void; /** * Observes new post rendered in the wrapper */ observeNewElements(): void; /** * Disconnects the intersection observer and stops watching for visibility changes * @returns */ stopObservation(): void; /** * Stops observing element visibility and cleans up resources */ destroy(): void; /** * Calls the onEntersViewport callback only once when the target element of an IntersectionObserverEntry enters the user's viewPort. */ reportOnEntersViewport(entry: IntersectionObserverEntry): void; summariseAndReport(entry: IntersectionObserverEntry): void; /** * Gets the summary data from the IntersectionObserverEntry and stores it * in the IntersectionObserverEntry.target.dataset.visibilityData as a * JSON.stringified object (refers to an Array). */ summariseAndStoreViewData(entry: IntersectionObserverEntry): void; /** * Emits the View data to the consumer */ reportRead(element: HTMLElement): void; /** * Adds or removes a DOM element from the this.visibleElements depending on if * the element is intersecting */ updateVisibleElements(entry: IntersectionObserverEntry): void; /** * Processes the times for when the DOM element was in view * * @param {(VisibilityData|TabVisibilityData)[]} summary - NB not working when try this in typescript */ processTime(summary: any): { summary: any[]; duration: number; start: any; end: any; }; /** * Emits the read event for all visible elements when the user closes the browser window * this function doesn't exist, unclear whether anything should happen or not */ handleWindowClose(): void; /** * runs read report for all visible elements */ runFinalReadReport(): void; /** * Calls the onError callback if a function is passed to the */ triggerError(error: Error): void; /** * checks if an element is currently being observed * @returns {boolean} */ isElementBeingObserved(element: Element): boolean; } export {};