import { ModuleName } from "@readium/navigator-html-injectables"; import { Locator, Publication, ReadingProgression, Page, Link } from "@readium/shared"; import { FrameCommsListener } from "../frame/index.ts"; import FrameBlobBuider from "../frame/FrameBlobBuilder.ts"; import { FXLFrameManager } from "./FXLFrameManager.ts"; import { FXLPeripherals } from "./FXLPeripherals.ts"; import { FXLSpreader, Orientation, Spread } from "./FXLSpreader.ts"; import { VisualNavigatorViewport, IContentProtectionConfig, IKeyboardPeripheralsConfig } from "../../Navigator.ts"; import { Injector } from "../../injection/Injector.ts"; const UPPER_BOUNDARY = 8; const LOWER_BOUNDARY = 5; const OFFSCREEN_LOAD_DELAY = 300; const OFFSCREEN_LOAD_TIMEOUT = 15000; const RESIZE_UPDATE_TIMEOUT = 250; const SLIDE_FAST = 150; const SLIDE_SLOW = 500; export class FXLFramePoolManager { private readonly container: HTMLElement; private readonly positions: Locator[]; private readonly pool: Map = new Map(); private readonly blobs: Map = new Map(); private readonly inprogress: Map> = new Map(); private readonly delayedShow: Map> = new Map(); private readonly delayedTimeout: Map = new Map(); private currentBaseURL: string | undefined; private previousFrames: FXLFrameManager[] = []; private readonly injector: Injector | null = null; private readonly contentProtectionConfig: IContentProtectionConfig; private readonly keyboardPeripheralsConfig: IKeyboardPeripheralsConfig; // NEW private readonly bookElement: HTMLDivElement; public readonly spineElement: HTMLDivElement; private readonly pub: Publication; public width: number = 0; public height: number = 0; private transform: string = ""; public currentSlide: number = 0; private spreader: FXLSpreader; private spread = true; // TODO private readonly spreadPresentation: Spread; private orientationInternal = -1; // Portrait = 1, Landscape = 0, Unknown = -1 private containerHeightCached: number; private resizeTimeout: number | undefined; // private readonly pages: FXLFrameManager[] = []; public readonly peripherals: FXLPeripherals; constructor( container: HTMLElement, positions: Locator[], pub: Publication, injector?: Injector | null, contentProtectionConfig?: IContentProtectionConfig, keyboardPeripheralsConfig?: IKeyboardPeripheralsConfig, ) { this.container = container; this.positions = positions; this.pub = pub; this.injector = injector ?? null; this.contentProtectionConfig = contentProtectionConfig || {}; this.keyboardPeripheralsConfig = keyboardPeripheralsConfig || []; this.spreadPresentation = pub.metadata.otherMetadata?.spread || Spread.auto; if(this.pub.metadata.effectiveReadingProgression !== ReadingProgression.rtl && this.pub.metadata.effectiveReadingProgression !== ReadingProgression.ltr) // TODO support TTB and BTT throw Error("Unsupported reading progression for EPUB"); // NEW this.spreader = new FXLSpreader(this.pub); this.containerHeightCached = container.clientHeight; this.bookElement = document.createElement("div"); this.bookElement.ariaLabel = "Book"; this.bookElement.tabIndex = -1; this.updateBookStyle(true); this.spineElement = document.createElement("div"); this.spineElement.ariaLabel = "Spine"; this.bookElement.appendChild(this.spineElement); this.container.appendChild(this.bookElement); this.updateSpineStyle(true); this.peripherals = new FXLPeripherals(this); this.pub.readingOrder.items.forEach((link) => { // Create