| 56 | } |
| 57 | |
| 58 | export class PptxViewer extends EventTarget { |
| 59 | protected container: HTMLElement |
| 60 | private viewerOptions: ViewerOptions |
| 61 | private presentation: PresentationData | null = null |
| 62 | private mediaUrlCache = new Map<string, string>() |
| 63 | private chartInstances = new Set<ECharts>() |
| 64 | private currentSlide = 0 |
| 65 | private _fitMode: FitMode |
| 66 | private _isRendering = false |
| 67 | private zoomFactor = 1 |
| 68 | private renderChain: Promise<void> = Promise.resolve() |
| 69 | private cleanupListMount?: () => void |
| 70 | private cleanupScrollObserver?: () => void |
| 71 | private suppressScrollChange = false |
| 72 | private ensureListSlideMountedFn?: (index: number) => void |
| 73 | private resizeObserver?: ResizeObserver |
| 74 | private windowResizeHandler?: () => void |
| 75 | private resizeRafId: number | null = null |
| 76 | private lastMeasuredContainerWidth = 0 |
| 77 | private mountedSlides = new Set<number>() |
| 78 | private slideHandles = new Map<number, SlideHandle>() |
| 79 | private activeRenderMode: 'list' | 'slide' | null = null |
| 80 | private listOptions: Required<ListRenderOptions> = { |
| 81 | windowed: false, |
| 82 | batchSize: 12, |
| 83 | initialSlides: 4, |
| 84 | overscanViewport: 1.5, |
| 85 | showSlideLabels: false, |
| 86 | } |
| 87 | |
| 88 | constructor(container: HTMLElement, options?: ViewerOptions) { |
| 89 | super() |
| 90 | this.container = container |
| 91 | this.viewerOptions = options ?? {} |
| 92 | const zoomPercent = this.normalizeZoomPercent(options?.zoomPercent ?? 100) |
| 93 | this._fitMode = options?.fitMode ?? 'contain' |
| 94 | this.zoomFactor = zoomPercent / 100 |
| 95 | |
| 96 | // Register shorthand callbacks as event listeners |
| 97 | if (options?.onSlideChange) { |
| 98 | const cb = options.onSlideChange |
| 99 | this.addEventListener('slidechange', ((e: CustomEvent) => |
| 100 | cb(e.detail.index)) as EventListener) |
| 101 | } |
| 102 | if (options?.onSlideRendered) { |
| 103 | const cb = options.onSlideRendered |
| 104 | this.addEventListener('sliderendered', ((e: CustomEvent) => |
| 105 | cb(e.detail.index, e.detail.element)) as EventListener) |
| 106 | } |
| 107 | if (options?.onSlideError) { |
| 108 | const cb = options.onSlideError |
| 109 | this.addEventListener('slideerror', ((e: CustomEvent) => |
| 110 | cb(e.detail.index, e.detail.error)) as EventListener) |
| 111 | } |
| 112 | if (options?.onSlideUnmounted) { |
| 113 | const cb = options.onSlideUnmounted |
| 114 | this.addEventListener('slideunmounted', ((e: CustomEvent) => |
| 115 | cb(e.detail.index)) as EventListener) |