@embedpdf/plugin-scroll 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -661
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -204
- package/dist/index.js +33 -67
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +27 -0
- package/dist/lib/index.d.ts +9 -0
- package/dist/lib/manifest.d.ts +4 -0
- package/dist/lib/reducer.d.ts +6 -0
- package/dist/lib/scroll-plugin.d.ts +45 -0
- package/dist/lib/selectors.d.ts +2 -0
- package/dist/lib/strategies/base-strategy.d.ts +35 -0
- package/dist/lib/strategies/horizontal-strategy.d.ts +14 -0
- package/dist/lib/strategies/vertical-strategy.d.ts +14 -0
- package/dist/lib/types/virtual-item.d.ts +21 -0
- package/dist/lib/types.d.ts +112 -0
- package/dist/preact/adapter.d.ts +4 -0
- package/dist/preact/core.d.ts +1 -0
- package/dist/preact/index.cjs +2 -181
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.d.ts +1 -54
- package/dist/preact/index.js +13 -18
- package/dist/preact/index.js.map +1 -1
- package/dist/react/adapter.d.ts +2 -0
- package/dist/react/core.d.ts +1 -0
- package/dist/react/index.cjs +2 -181
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +1 -53
- package/dist/react/index.js +12 -18
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/components/index.d.ts +1 -0
- package/dist/shared-preact/components/scroller.d.ts +14 -0
- package/dist/shared-preact/hooks/index.d.ts +1 -0
- package/dist/shared-preact/hooks/use-scroll.d.ts +32 -0
- package/dist/shared-preact/index.d.ts +2 -0
- package/dist/shared-react/components/index.d.ts +1 -0
- package/dist/shared-react/components/scroller.d.ts +14 -0
- package/dist/shared-react/hooks/index.d.ts +1 -0
- package/dist/shared-react/hooks/use-scroll.d.ts +32 -0
- package/dist/shared-react/index.d.ts +2 -0
- package/dist/vue/components/index.d.ts +1 -0
- package/dist/vue/components/scroller.vue.d.ts +28 -0
- package/dist/vue/hooks/index.d.ts +1 -0
- package/dist/vue/hooks/use-scroll.d.ts +11 -0
- package/dist/vue/index.cjs +2 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.ts +2 -0
- package/dist/vue/index.js +136 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +22 -13
- package/dist/index.d.cts +0 -204
- package/dist/preact/index.d.cts +0 -54
- package/dist/react/index.d.cts +0 -53
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/lib/scroll-plugin.ts","../src/lib/types.ts","../src/lib/strategies/base-strategy.ts","../src/lib/strategies/vertical-strategy.ts","../src/lib/strategies/horizontal-strategy.ts","../src/lib/actions.ts","../src/lib/selectors.ts","../src/lib/manifest.ts","../src/lib/reducer.ts","../src/lib/index.ts"],"sourcesContent":["export * from './lib';\n","import {\n BasePlugin,\n CoreState,\n PluginRegistry,\n SET_DOCUMENT,\n SET_PAGES,\n SET_ROTATION,\n StoreState,\n createBehaviorEmitter,\n createEmitter,\n getPagesWithRotatedSize,\n} from '@embedpdf/core';\nimport {\n PdfPageObject,\n PdfPageObjectWithRotatedSize,\n Position,\n Rect,\n restoreRect,\n rotateRect,\n Rotation,\n transformRect,\n} from '@embedpdf/models';\nimport { ViewportCapability, ViewportMetrics, ViewportPlugin } from '@embedpdf/plugin-viewport';\nimport {\n ScrollCapability,\n ScrollPluginConfig,\n ScrollStrategy,\n ScrollMetrics,\n ScrollState,\n LayoutChangePayload,\n ScrollerLayout,\n ScrollToPageOptions,\n PageChangePayload,\n} from './types';\nimport { BaseScrollStrategy, ScrollStrategyConfig } from './strategies/base-strategy';\nimport { VerticalScrollStrategy } from './strategies/vertical-strategy';\nimport { HorizontalScrollStrategy } from './strategies/horizontal-strategy';\nimport { updateScrollState, ScrollAction, updateTotalPages } from './actions';\nimport { VirtualItem } from './types/virtual-item';\nimport { getScrollerLayout } from './selectors';\n\ntype PartialScroll = Partial<ScrollState>;\ntype Emits = {\n layout?: LayoutChangePayload;\n metrics?: ScrollMetrics;\n};\n\nexport class ScrollPlugin extends BasePlugin<\n ScrollPluginConfig,\n ScrollCapability,\n ScrollState,\n ScrollAction\n> {\n static readonly id = 'scroll' as const;\n private viewport: ViewportCapability;\n private strategy: BaseScrollStrategy;\n private strategyConfig: ScrollStrategyConfig;\n private currentScale: number = 1;\n private currentRotation: Rotation = Rotation.Degree0;\n private initialPage?: number;\n private currentPage: number = 1;\n private layoutReady: boolean = false;\n\n private readonly layout$ = createBehaviorEmitter<LayoutChangePayload>();\n private readonly scroll$ = createBehaviorEmitter<ScrollMetrics>();\n private readonly state$ = createBehaviorEmitter<ScrollState>();\n private readonly scrollerLayout$ = createBehaviorEmitter<ScrollerLayout>();\n private readonly pageChange$ = createBehaviorEmitter<PageChangePayload>();\n private readonly layoutReady$ = createBehaviorEmitter<boolean>();\n\n constructor(\n public readonly id: string,\n registry: PluginRegistry,\n private config?: ScrollPluginConfig,\n ) {\n super(id, registry);\n\n this.viewport = this.registry.getPlugin<ViewportPlugin>('viewport')!.provides();\n\n this.strategyConfig = {\n pageGap: this.config?.pageGap ?? 10,\n viewportGap: this.viewport.getViewportGap(),\n bufferSize: this.config?.bufferSize ?? 2,\n };\n\n this.strategy =\n this.config?.strategy === ScrollStrategy.Horizontal\n ? new HorizontalScrollStrategy(this.strategyConfig)\n : new VerticalScrollStrategy(this.strategyConfig);\n\n this.initialPage = this.config?.initialPage;\n this.currentScale = this.coreState.core.scale;\n this.currentRotation = this.coreState.core.rotation;\n // Subscribe to viewport and page manager events\n this.viewport.onViewportChange((vp) => this.commitMetrics(this.computeMetrics(vp)), {\n mode: 'throttle',\n wait: 250,\n });\n this.coreStore.onAction(SET_DOCUMENT, (_action, state) => {\n const totalPages = state.core.pages.length;\n this.dispatch(updateTotalPages(totalPages));\n this.pageChange$.emit({ pageNumber: this.currentPage, totalPages });\n this.refreshAll(getPagesWithRotatedSize(state.core), this.viewport.getMetrics());\n });\n this.coreStore.onAction(SET_ROTATION, (_action, state) =>\n this.refreshAll(getPagesWithRotatedSize(state.core), this.viewport.getMetrics()),\n );\n this.coreStore.onAction(SET_PAGES, (_action, state) =>\n this.refreshAll(getPagesWithRotatedSize(state.core), this.viewport.getMetrics()),\n );\n }\n\n /* ------------------------------------------------------------------ */\n /* ᴄᴏᴍᴘᴜᴛᴇʀs */\n /* ------------------------------------------------------------------ */\n\n private computeLayout(pages: PdfPageObjectWithRotatedSize[][]) {\n const virtualItems = this.strategy.createVirtualItems(pages);\n const totalContentSize = this.strategy.getTotalContentSize(virtualItems);\n return { virtualItems, totalContentSize };\n }\n\n private computeMetrics(vp: ViewportMetrics, items: VirtualItem[] = this.state.virtualItems) {\n return this.strategy.handleScroll(vp, items, this.currentScale);\n }\n\n /* ------------------------------------------------------------------ */\n /* ᴄᴏᴍᴍɪᴛ (single source of truth) */\n /* ------------------------------------------------------------------ */\n\n private commit(stateDelta: PartialScroll, emit?: Emits) {\n /* update Redux-like store */\n this.dispatch(updateScrollState(stateDelta));\n\n /* fire optional events */\n if (emit?.layout) this.layout$.emit(emit.layout);\n if (emit?.metrics) {\n this.scroll$.emit(emit.metrics);\n\n if (emit.metrics.currentPage !== this.currentPage) {\n this.currentPage = emit.metrics.currentPage;\n this.pageChange$.emit({ pageNumber: this.currentPage, totalPages: this.state.totalPages });\n }\n }\n\n /* keep scroller-layout reactive */\n this.scrollerLayout$.emit(this.getScrollerLayoutFromState());\n }\n\n /* convenience wrappers */\n private commitMetrics(metrics: ScrollMetrics) {\n this.commit(metrics, { metrics });\n }\n\n /* full re-compute after page-spread or initialisation */\n private refreshAll(pages: PdfPageObjectWithRotatedSize[][], vp: ViewportMetrics) {\n const layout = this.computeLayout(pages);\n const metrics = this.computeMetrics(vp, layout.virtualItems);\n\n this.commit({ ...layout, ...metrics }, { layout, metrics });\n }\n\n private getVirtualItemsFromState(): VirtualItem[] {\n return this.state.virtualItems || [];\n }\n\n private getScrollerLayoutFromState(): ScrollerLayout {\n const scale = this.coreState.core.scale;\n return getScrollerLayout(this.state, scale);\n }\n\n private pushScrollLayout() {\n this.scrollerLayout$.emit(this.getScrollerLayoutFromState());\n }\n\n override onStoreUpdated(_prevState: ScrollState, _newState: ScrollState): void {\n this.pushScrollLayout();\n }\n\n override onCoreStoreUpdated(\n prevState: StoreState<CoreState>,\n newState: StoreState<CoreState>,\n ): void {\n if (prevState.core.scale !== newState.core.scale) {\n this.currentScale = newState.core.scale;\n this.commitMetrics(this.computeMetrics(this.viewport.getMetrics()));\n }\n if (prevState.core.rotation !== newState.core.rotation) {\n this.currentRotation = newState.core.rotation;\n }\n }\n\n /**\n * Change the scroll strategy at runtime (e.g., vertical <-> horizontal)\n * @param newStrategy ScrollStrategy.Horizontal or ScrollStrategy.Vertical\n */\n private setScrollStrategy(newStrategy: ScrollStrategy) {\n // Only update if the strategy is actually changing\n if (\n (newStrategy === ScrollStrategy.Horizontal &&\n this.strategy instanceof HorizontalScrollStrategy) ||\n (newStrategy === ScrollStrategy.Vertical && this.strategy instanceof VerticalScrollStrategy)\n ) {\n return;\n }\n\n this.strategy =\n newStrategy === ScrollStrategy.Horizontal\n ? new HorizontalScrollStrategy(this.strategyConfig)\n : new VerticalScrollStrategy(this.strategyConfig);\n\n // Update state with new strategy\n this.dispatch(\n updateScrollState({\n strategy: newStrategy,\n }),\n );\n\n // Recalculate layout and scroll metrics\n const pages = getPagesWithRotatedSize(this.coreState.core);\n this.refreshAll(pages, this.viewport.getMetrics());\n }\n\n public setLayoutReady() {\n if (this.layoutReady) return;\n\n this.layoutReady = true;\n this.layoutReady$.emit(true);\n }\n\n protected buildCapability(): ScrollCapability {\n return {\n onStateChange: this.state$.on,\n onLayoutChange: this.layout$.on,\n onScroll: this.scroll$.on,\n onPageChange: this.pageChange$.on,\n onScrollerData: this.scrollerLayout$.on,\n onLayoutReady: this.layoutReady$.on,\n getCurrentPage: () => this.currentPage,\n getTotalPages: () => this.state.totalPages,\n scrollToPage: (options: ScrollToPageOptions) => {\n const { pageNumber, behavior = 'smooth', pageCoordinates, center = false } = options;\n const virtualItems = this.getVirtualItemsFromState();\n const position = this.strategy.getScrollPositionForPage(\n pageNumber,\n virtualItems,\n this.currentScale,\n this.currentRotation,\n pageCoordinates,\n );\n if (position) {\n this.viewport.scrollTo({ ...position, behavior, center });\n }\n },\n scrollToNextPage: (behavior = 'smooth') => {\n const virtualItems = this.getVirtualItemsFromState();\n const currentItemIndex = virtualItems.findIndex((item) =>\n item.pageNumbers.includes(this.currentPage),\n );\n if (currentItemIndex >= 0 && currentItemIndex < virtualItems.length - 1) {\n const nextItem = virtualItems[currentItemIndex + 1];\n const position = this.strategy.getScrollPositionForPage(\n nextItem.pageNumbers[0],\n virtualItems,\n this.currentScale,\n this.currentRotation,\n );\n if (position) {\n this.viewport.scrollTo({ ...position, behavior });\n }\n }\n },\n scrollToPreviousPage: (behavior = 'smooth') => {\n const virtualItems = this.getVirtualItemsFromState();\n const currentItemIndex = virtualItems.findIndex((item) =>\n item.pageNumbers.includes(this.currentPage),\n );\n if (currentItemIndex > 0) {\n const prevItem = virtualItems[currentItemIndex - 1];\n const position = this.strategy.getScrollPositionForPage(\n prevItem.pageNumbers[0],\n virtualItems,\n this.currentScale,\n this.currentRotation,\n );\n if (position) {\n this.viewport.scrollTo({ ...position, behavior });\n }\n }\n },\n getMetrics: this.getMetrics.bind(this),\n getLayout: this.getLayout.bind(this),\n getRectPositionForPage: this.getRectPositionForPage.bind(this),\n getPageGap: () => this.state.pageGap,\n getScrollerLayout: () => this.getScrollerLayoutFromState(),\n setScrollStrategy: (strategy: ScrollStrategy) => this.setScrollStrategy(strategy),\n };\n }\n\n private getMetrics(viewport?: ViewportMetrics): ScrollMetrics {\n const metrics = viewport || this.viewport.getMetrics();\n const virtualItems = this.getVirtualItemsFromState();\n return this.strategy.handleScroll(metrics, virtualItems, this.currentScale);\n }\n\n private getLayout(): LayoutChangePayload {\n return {\n virtualItems: this.state.virtualItems,\n totalContentSize: this.state.totalContentSize,\n };\n }\n\n private getRectPositionForPage(\n pageIndex: number,\n rect: Rect,\n scale?: number,\n rotation?: Rotation,\n ): Rect | null {\n return this.strategy.getRectPositionForPage(\n pageIndex + 1,\n this.state.virtualItems,\n scale ?? this.currentScale,\n rotation ?? this.currentRotation,\n rect,\n );\n }\n\n async initialize(): Promise<void> {\n // No DOM initialization needed; state drives rendering\n }\n\n async destroy(): Promise<void> {\n this.layout$.clear();\n this.scroll$.clear();\n this.pageChange$.clear();\n this.state$.clear();\n this.scrollerLayout$.clear();\n this.layoutReady$.clear();\n super.destroy();\n }\n}\n","import { BasePluginConfig, Emitter, EventHook } from '@embedpdf/core';\nimport { PdfPageObject, Rect, Rotation } from '@embedpdf/models';\nimport { ViewportMetrics } from '@embedpdf/plugin-viewport';\nimport { VirtualItem } from './types/virtual-item';\n\nexport interface ScrollState extends ScrollMetrics {\n virtualItems: VirtualItem[];\n totalPages: number;\n totalContentSize: { width: number; height: number };\n desiredScrollPosition: { x: number; y: number };\n strategy: ScrollStrategy;\n pageGap: number;\n scale: number;\n}\n\nexport interface ScrollerLayout {\n startSpacing: number;\n endSpacing: number;\n totalWidth: number;\n totalHeight: number;\n pageGap: number;\n strategy: ScrollState['strategy'];\n items: VirtualItem[];\n}\n\nexport enum ScrollStrategy {\n Vertical = 'vertical',\n Horizontal = 'horizontal',\n}\n\nexport interface PageVisibilityMetrics {\n pageNumber: number;\n viewportX: number;\n viewportY: number;\n visiblePercentage: number;\n original: {\n pageX: number;\n pageY: number;\n visibleWidth: number;\n visibleHeight: number;\n scale: number;\n };\n scaled: {\n pageX: number;\n pageY: number;\n visibleWidth: number;\n visibleHeight: number;\n scale: number;\n };\n}\n\nexport interface ScrollMetrics {\n currentPage: number;\n visiblePages: number[];\n pageVisibilityMetrics: PageVisibilityMetrics[];\n renderedPageIndexes: number[];\n scrollOffset: { x: number; y: number };\n startSpacing: number;\n endSpacing: number;\n}\n\nexport interface ScrollStrategyInterface {\n initialize(container: HTMLElement, innerDiv: HTMLElement): void;\n destroy(): void;\n updateLayout(viewport: ViewportMetrics, pdfPageObject: PdfPageObject[][]): void;\n handleScroll(viewport: ViewportMetrics): void;\n getVirtualItems(): VirtualItem[];\n scrollToPage(pageNumber: number, behavior?: ScrollBehavior): void;\n calculateDimensions(pdfPageObject: PdfPageObject[][]): void;\n}\n\nexport interface ScrollPluginConfig extends BasePluginConfig {\n strategy?: ScrollStrategy;\n initialPage?: number;\n bufferSize?: number;\n pageGap?: number;\n}\n\nexport type LayoutChangePayload = Pick<ScrollState, 'virtualItems' | 'totalContentSize'>;\n\nexport interface ScrollToPageOptions {\n pageNumber: number;\n pageCoordinates?: { x: number; y: number };\n behavior?: ScrollBehavior;\n center?: boolean;\n}\n\nexport interface PageChangePayload {\n pageNumber: number;\n totalPages: number;\n}\n\nexport interface ScrollCapability {\n onScrollerData: EventHook<ScrollerLayout>;\n onStateChange: EventHook<ScrollState>;\n onScroll: EventHook<ScrollMetrics>;\n getCurrentPage(): number;\n getTotalPages(): number;\n onPageChange: EventHook<PageChangePayload>;\n onLayoutChange: EventHook<LayoutChangePayload>;\n onLayoutReady: EventHook<boolean>;\n scrollToPage(options: ScrollToPageOptions): void;\n scrollToNextPage(behavior?: ScrollBehavior): void;\n scrollToPreviousPage(behavior?: ScrollBehavior): void;\n getMetrics(viewport?: ViewportMetrics): ScrollMetrics;\n getLayout(): LayoutChangePayload;\n getScrollerLayout(): ScrollerLayout;\n getRectPositionForPage(\n page: number,\n rect: Rect,\n scale?: number,\n rotation?: Rotation,\n ): Rect | null;\n setScrollStrategy(strategy: ScrollStrategy): void;\n getPageGap(): number;\n}\n","import {\n PdfPageObjectWithRotatedSize,\n Position,\n Rect,\n Rotation,\n scalePosition,\n transformPosition,\n transformRect,\n} from '@embedpdf/models';\nimport { ViewportMetrics } from '@embedpdf/plugin-viewport';\nimport { VirtualItem } from '../types/virtual-item';\nimport { ScrollMetrics } from '../types';\n\nexport interface ScrollStrategyConfig {\n pageGap?: number;\n viewportGap?: number;\n bufferSize?: number;\n}\n\nexport abstract class BaseScrollStrategy {\n protected pageGap: number;\n protected viewportGap: number;\n protected bufferSize: number;\n\n constructor(config: ScrollStrategyConfig) {\n this.pageGap = config.pageGap ?? 20;\n this.viewportGap = config.viewportGap ?? 20;\n this.bufferSize = config.bufferSize ?? 2;\n }\n\n abstract createVirtualItems(pdfPageObject: PdfPageObjectWithRotatedSize[][]): VirtualItem[];\n abstract getTotalContentSize(virtualItems: VirtualItem[]): { width: number; height: number };\n protected abstract getScrollOffset(viewport: ViewportMetrics): number;\n protected abstract getClientSize(viewport: ViewportMetrics): number;\n\n protected getVisibleRange(\n viewport: ViewportMetrics,\n virtualItems: VirtualItem[],\n scale: number,\n ): { start: number; end: number } {\n const scrollOffset = this.getScrollOffset(viewport);\n const clientSize = this.getClientSize(viewport);\n const viewportStart = scrollOffset;\n const viewportEnd = scrollOffset + clientSize;\n\n let startIndex = 0;\n while (\n startIndex < virtualItems.length &&\n (virtualItems[startIndex].offset + virtualItems[startIndex].height) * scale <= viewportStart\n ) {\n startIndex++;\n }\n\n let endIndex = startIndex;\n while (endIndex < virtualItems.length && virtualItems[endIndex].offset * scale <= viewportEnd) {\n endIndex++;\n }\n\n return {\n start: Math.max(0, startIndex - this.bufferSize),\n end: Math.min(virtualItems.length - 1, endIndex + this.bufferSize - 1),\n };\n }\n\n handleScroll(\n viewport: ViewportMetrics,\n virtualItems: VirtualItem[],\n scale: number,\n ): ScrollMetrics {\n const range = this.getVisibleRange(viewport, virtualItems, scale);\n const visibleItems = virtualItems.slice(range.start, range.end + 1);\n const pageVisibilityMetrics = this.calculatePageVisibility(visibleItems, viewport, scale);\n const visiblePages = pageVisibilityMetrics.map((m) => m.pageNumber);\n const renderedPageIndexes = virtualItems\n .slice(range.start, range.end + 1)\n .flatMap((item) => item.index);\n const currentPage = this.determineCurrentPage(pageVisibilityMetrics);\n const first = virtualItems[range.start];\n const last = virtualItems[range.end];\n const startSpacing = first ? first.offset * scale : 0;\n const endSpacing = last\n ? (virtualItems[virtualItems.length - 1].offset + // end of content\n virtualItems[virtualItems.length - 1].height) *\n scale - // minus\n (last.offset + last.height) * scale // end of last rendered\n : 0;\n\n return {\n currentPage,\n visiblePages,\n pageVisibilityMetrics,\n renderedPageIndexes,\n scrollOffset: { x: viewport.scrollLeft, y: viewport.scrollTop },\n startSpacing,\n endSpacing,\n };\n }\n\n protected calculatePageVisibility(\n virtualItems: VirtualItem[],\n viewport: ViewportMetrics,\n scale: number,\n ): ScrollMetrics['pageVisibilityMetrics'] {\n const visibilityMetrics: ScrollMetrics['pageVisibilityMetrics'] = [];\n\n virtualItems.forEach((item) => {\n item.pageLayouts.forEach((page) => {\n const itemX = item.x * scale;\n const itemY = item.y * scale;\n const pageX = itemX + page.x * scale;\n const pageY = itemY + page.y * scale;\n const pageWidth = page.rotatedWidth * scale;\n const pageHeight = page.rotatedHeight * scale;\n\n const viewportLeft = viewport.scrollLeft;\n const viewportTop = viewport.scrollTop;\n const viewportRight = viewportLeft + viewport.clientWidth;\n const viewportBottom = viewportTop + viewport.clientHeight;\n\n const intersectionLeft = Math.max(pageX, viewportLeft);\n const intersectionTop = Math.max(pageY, viewportTop);\n const intersectionRight = Math.min(pageX + pageWidth, viewportRight);\n const intersectionBottom = Math.min(pageY + pageHeight, viewportBottom);\n\n if (intersectionLeft < intersectionRight && intersectionTop < intersectionBottom) {\n const visibleWidth = intersectionRight - intersectionLeft;\n const visibleHeight = intersectionBottom - intersectionTop;\n const totalArea = pageWidth * pageHeight;\n const visibleArea = visibleWidth * visibleHeight;\n\n visibilityMetrics.push({\n pageNumber: page.pageNumber,\n viewportX: intersectionLeft - viewportLeft,\n viewportY: intersectionTop - viewportTop,\n visiblePercentage: (visibleArea / totalArea) * 100,\n original: {\n pageX: (intersectionLeft - pageX) / scale,\n pageY: (intersectionTop - pageY) / scale,\n visibleWidth: visibleWidth / scale,\n visibleHeight: visibleHeight / scale,\n scale: 1,\n },\n scaled: {\n pageX: intersectionLeft - pageX,\n pageY: intersectionTop - pageY,\n visibleWidth,\n visibleHeight,\n scale,\n },\n });\n }\n });\n });\n\n return visibilityMetrics;\n }\n\n protected determineCurrentPage(\n visibilityMetrics: ScrollMetrics['pageVisibilityMetrics'],\n ): number {\n if (visibilityMetrics.length === 0) return 1;\n\n const maxVisibility = Math.max(...visibilityMetrics.map((m) => m.visiblePercentage));\n const mostVisiblePages = visibilityMetrics.filter((m) => m.visiblePercentage === maxVisibility);\n\n return mostVisiblePages.length === 1\n ? mostVisiblePages[0].pageNumber\n : mostVisiblePages.sort((a, b) => a.pageNumber - b.pageNumber)[0].pageNumber;\n }\n\n private getRectLocationForPage(pageNumber: number, virtualItems: VirtualItem[]): Rect | null {\n // Find the virtual item containing the page\n const item = virtualItems.find((item) => item.pageNumbers.includes(pageNumber));\n if (!item) return null;\n\n // Find the specific page layout for the requested page number\n const pageLayout = item.pageLayouts.find((layout) => layout.pageNumber === pageNumber);\n if (!pageLayout) return null;\n\n return {\n origin: {\n x: item.x + pageLayout.x,\n y: item.y + pageLayout.y,\n },\n size: {\n width: pageLayout.width,\n height: pageLayout.height,\n },\n };\n }\n\n getScrollPositionForPage(\n pageNumber: number,\n virtualItems: VirtualItem[],\n scale: number,\n rotation: Rotation,\n pageCoordinates?: { x: number; y: number },\n ): Position | null {\n // Find the virtual item containing the page\n const pageRect = this.getRectLocationForPage(pageNumber, virtualItems);\n if (!pageRect) return null;\n\n const scaledBasePosition = scalePosition(pageRect.origin, scale);\n\n // If specific page coordinates are provided, add them to the base position\n if (pageCoordinates) {\n const rotatedSize = transformPosition(\n {\n width: pageRect.size.width,\n height: pageRect.size.height,\n },\n {\n x: pageCoordinates.x,\n y: pageCoordinates.y,\n },\n rotation,\n scale,\n );\n\n return {\n x: scaledBasePosition.x + rotatedSize.x + this.viewportGap,\n y: scaledBasePosition.y + rotatedSize.y + this.viewportGap,\n };\n }\n\n return {\n x: scaledBasePosition.x + this.viewportGap,\n y: scaledBasePosition.y + this.viewportGap,\n };\n }\n\n getRectPositionForPage(\n pageNumber: number,\n virtualItems: VirtualItem[],\n scale: number,\n rotation: Rotation,\n rect: Rect,\n ): Rect | null {\n const pageRect = this.getRectLocationForPage(pageNumber, virtualItems);\n if (!pageRect) return null;\n\n const scaledBasePosition = scalePosition(pageRect.origin, scale);\n\n const rotatedSize = transformRect(\n {\n width: pageRect.size.width,\n height: pageRect.size.height,\n },\n rect,\n rotation,\n scale,\n );\n\n return {\n origin: {\n x: scaledBasePosition.x + rotatedSize.origin.x,\n y: scaledBasePosition.y + rotatedSize.origin.y,\n },\n size: rotatedSize.size,\n };\n }\n}\n","import { PdfPageObjectWithRotatedSize } from '@embedpdf/models';\nimport { ViewportMetrics } from '@embedpdf/plugin-viewport';\nimport { BaseScrollStrategy, ScrollStrategyConfig } from './base-strategy';\nimport { VirtualItem, PageLayout } from '../types/virtual-item';\nimport { ScrollMetrics } from '../types';\n\nexport class VerticalScrollStrategy extends BaseScrollStrategy {\n constructor(config: ScrollStrategyConfig) {\n super(config);\n }\n\n createVirtualItems(pdfPageObject: PdfPageObjectWithRotatedSize[][]): VirtualItem[] {\n let yOffset = 0;\n return pdfPageObject.map((pagesInSpread, index) => {\n let pageX = 0;\n const pageLayouts: PageLayout[] = pagesInSpread.map((page) => {\n const layout: PageLayout = {\n pageNumber: page.index + 1,\n pageIndex: page.index,\n x: pageX,\n y: 0,\n width: page.size.width,\n height: page.size.height,\n rotatedWidth: page.rotatedSize.width,\n rotatedHeight: page.rotatedSize.height,\n };\n pageX += page.rotatedSize.width + this.pageGap;\n return layout;\n });\n const width = pagesInSpread.reduce(\n (sum, page, i) =>\n sum + page.rotatedSize.width + (i < pagesInSpread.length - 1 ? this.pageGap : 0),\n 0,\n );\n const height = Math.max(...pagesInSpread.map((p) => p.rotatedSize.height));\n const item: VirtualItem = {\n id: `item-${index}`,\n x: 0,\n y: yOffset,\n offset: yOffset,\n width,\n height,\n pageLayouts,\n pageNumbers: pagesInSpread.map((p) => p.index + 1),\n index,\n };\n yOffset += height + this.pageGap;\n return item;\n });\n }\n\n getTotalContentSize(virtualItems: VirtualItem[]): { width: number; height: number } {\n if (virtualItems.length === 0) return { width: 0, height: 0 };\n const maxWidth = Math.max(...virtualItems.map((item) => item.width));\n const totalHeight =\n virtualItems[virtualItems.length - 1].y + virtualItems[virtualItems.length - 1].height;\n return {\n width: maxWidth,\n height: totalHeight,\n };\n }\n\n protected getScrollOffset(viewport: ViewportMetrics): number {\n return viewport.scrollTop;\n }\n\n protected getClientSize(viewport: ViewportMetrics): number {\n return viewport.clientHeight;\n }\n}\n","import { PdfPageObjectWithRotatedSize } from '@embedpdf/models';\nimport { ViewportMetrics } from '@embedpdf/plugin-viewport';\nimport { BaseScrollStrategy, ScrollStrategyConfig } from './base-strategy';\nimport { VirtualItem, PageLayout } from '../types/virtual-item';\n\nexport class HorizontalScrollStrategy extends BaseScrollStrategy {\n constructor(config: ScrollStrategyConfig) {\n super(config);\n }\n\n createVirtualItems(pdfPageObject: PdfPageObjectWithRotatedSize[][]): VirtualItem[] {\n let xOffset = 0;\n return pdfPageObject.map((pagesInSpread, index) => {\n let pageX = 0;\n const pageLayouts: PageLayout[] = pagesInSpread.map((page) => {\n const layout: PageLayout = {\n pageNumber: page.index + 1,\n pageIndex: page.index,\n x: pageX,\n y: 0,\n width: page.size.width,\n height: page.size.height,\n rotatedWidth: page.rotatedSize.width,\n rotatedHeight: page.rotatedSize.height,\n };\n pageX += page.rotatedSize.width + this.pageGap;\n return layout;\n });\n const width = pagesInSpread.reduce(\n (sum, page, i) =>\n sum + page.rotatedSize.width + (i < pagesInSpread.length - 1 ? this.pageGap : 0),\n 0,\n );\n const height = Math.max(...pagesInSpread.map((p) => p.rotatedSize.height));\n const item: VirtualItem = {\n id: `item-${index}`,\n x: xOffset,\n y: 0,\n offset: xOffset,\n width,\n height,\n pageLayouts,\n pageNumbers: pagesInSpread.map((p) => p.index + 1),\n index,\n };\n xOffset += width + this.pageGap;\n return item;\n });\n }\n\n getTotalContentSize(virtualItems: VirtualItem[]): { width: number; height: number } {\n if (virtualItems.length === 0) return { width: 0, height: 0 };\n const totalWidth =\n virtualItems[virtualItems.length - 1].x + virtualItems[virtualItems.length - 1].width;\n const maxHeight = Math.max(...virtualItems.map((item) => item.height));\n return {\n width: totalWidth,\n height: maxHeight,\n };\n }\n\n protected getScrollOffset(viewport: ViewportMetrics): number {\n return viewport.scrollLeft;\n }\n\n protected getClientSize(viewport: ViewportMetrics): number {\n return viewport.clientWidth;\n }\n}\n","import { Action } from '@embedpdf/core';\nimport { ScrollState } from './types';\n\nexport const UPDATE_SCROLL_STATE = 'UPDATE_SCROLL_STATE';\nexport const SET_DESIRED_SCROLL_POSITION = 'SET_DESIRED_SCROLL_POSITION';\nexport const UPDATE_TOTAL_PAGES = 'UPDATE_TOTAL_PAGES';\n\nexport interface UpdateScrollStateAction extends Action {\n type: typeof UPDATE_SCROLL_STATE;\n payload: Partial<ScrollState>;\n}\n\nexport interface SetDesiredScrollPositionAction extends Action {\n type: typeof SET_DESIRED_SCROLL_POSITION;\n payload: { x: number; y: number };\n}\n\nexport interface UpdateTotalPagesAction extends Action {\n type: typeof UPDATE_TOTAL_PAGES;\n payload: number;\n}\n\nexport type ScrollAction =\n | UpdateScrollStateAction\n | SetDesiredScrollPositionAction\n | UpdateTotalPagesAction;\n\nexport function updateScrollState(payload: Partial<ScrollState>): UpdateScrollStateAction {\n return { type: UPDATE_SCROLL_STATE, payload };\n}\n\nexport function setDesiredScrollPosition(payload: {\n x: number;\n y: number;\n}): SetDesiredScrollPositionAction {\n return { type: SET_DESIRED_SCROLL_POSITION, payload };\n}\n\nexport function updateTotalPages(payload: number): UpdateTotalPagesAction {\n return { type: UPDATE_TOTAL_PAGES, payload };\n}\n","import { ScrollerLayout, ScrollState } from './types';\n\nexport const getScrollerLayout = (state: ScrollState, scale: number): ScrollerLayout => {\n return {\n startSpacing: state.startSpacing,\n endSpacing: state.endSpacing,\n totalWidth: state.totalContentSize.width * scale,\n totalHeight: state.totalContentSize.height * scale,\n pageGap: state.pageGap * scale,\n strategy: state.strategy,\n items: state.renderedPageIndexes.map((idx) => {\n return {\n ...state.virtualItems[idx],\n pageLayouts: state.virtualItems[idx].pageLayouts.map((layout) => {\n return {\n ...layout,\n rotatedWidth: layout.rotatedWidth * scale,\n rotatedHeight: layout.rotatedHeight * scale,\n width: layout.width * scale,\n height: layout.height * scale,\n };\n }),\n };\n }),\n };\n};\n","import { PluginManifest } from '@embedpdf/core';\nimport { ScrollPluginConfig } from './types';\n\nexport const SCROLL_PLUGIN_ID = 'scroll';\n\nexport const manifest: PluginManifest<ScrollPluginConfig> = {\n id: SCROLL_PLUGIN_ID,\n name: 'Scroll Plugin',\n version: '1.0.0',\n provides: ['scroll'],\n requires: ['viewport'],\n optional: [],\n defaultConfig: {\n enabled: true,\n pageGap: 10,\n },\n};\n","import { Reducer, CoreState, SET_SCALE, SetScaleAction } from '@embedpdf/core';\nimport { ScrollState, ScrollStrategy, ScrollPluginConfig, ScrollMetrics } from './types';\nimport {\n ScrollAction,\n UPDATE_SCROLL_STATE,\n SET_DESIRED_SCROLL_POSITION,\n UPDATE_TOTAL_PAGES,\n} from './actions';\n\nexport const defaultScrollMetrics: ScrollMetrics = {\n currentPage: 1,\n visiblePages: [],\n pageVisibilityMetrics: [],\n renderedPageIndexes: [],\n scrollOffset: { x: 0, y: 0 },\n startSpacing: 0,\n endSpacing: 0,\n};\n\nexport const initialState: (coreState: CoreState, config: ScrollPluginConfig) => ScrollState = (\n coreState,\n config,\n) => ({\n virtualItems: [],\n totalPages: coreState.pages.length,\n totalContentSize: { width: 0, height: 0 },\n desiredScrollPosition: { x: 0, y: 0 },\n strategy: config.strategy ?? ScrollStrategy.Vertical,\n pageGap: config.pageGap ?? 10,\n scale: coreState.scale,\n ...defaultScrollMetrics,\n});\n\nexport const scrollReducer: Reducer<ScrollState, ScrollAction | SetScaleAction> = (\n state,\n action,\n) => {\n switch (action.type) {\n case UPDATE_TOTAL_PAGES:\n return { ...state, totalPages: action.payload };\n case SET_SCALE:\n return { ...state, scale: action.payload };\n case UPDATE_SCROLL_STATE:\n return { ...state, ...action.payload };\n case SET_DESIRED_SCROLL_POSITION:\n return { ...state, desiredScrollPosition: action.payload };\n default:\n return state;\n }\n};\n","import { PluginPackage } from '@embedpdf/core';\nimport { ScrollPlugin } from './scroll-plugin';\nimport { manifest, SCROLL_PLUGIN_ID } from './manifest';\nimport { ScrollPluginConfig, ScrollState } from './types';\nimport { scrollReducer, initialState } from './reducer';\nimport { ScrollAction } from './actions';\n\nexport const ScrollPluginPackage: PluginPackage<\n ScrollPlugin,\n ScrollPluginConfig,\n ScrollState,\n ScrollAction\n> = {\n manifest,\n create: (registry, _engine, config) => new ScrollPlugin(SCROLL_PLUGIN_ID, registry, config),\n reducer: scrollReducer,\n initialState: (coreState, config) => initialState(coreState, config),\n};\n\nexport * from './scroll-plugin';\nexport * from './types';\nexport * from './manifest';\nexport * from './types/virtual-item';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAWO;AACP,IAAAA,iBASO;;;ACIA,IAAK,iBAAL,kBAAKC,oBAAL;AACL,EAAAA,gBAAA,cAAW;AACX,EAAAA,gBAAA,gBAAa;AAFH,SAAAA;AAAA,GAAA;;;ACzBZ,oBAQO;AAWA,IAAe,qBAAf,MAAkC;AAAA,EAKvC,YAAY,QAA8B;AACxC,SAAK,UAAU,OAAO,WAAW;AACjC,SAAK,cAAc,OAAO,eAAe;AACzC,SAAK,aAAa,OAAO,cAAc;AAAA,EACzC;AAAA,EAOU,gBACR,UACA,cACA,OACgC;AAChC,UAAM,eAAe,KAAK,gBAAgB,QAAQ;AAClD,UAAM,aAAa,KAAK,cAAc,QAAQ;AAC9C,UAAM,gBAAgB;AACtB,UAAM,cAAc,eAAe;AAEnC,QAAI,aAAa;AACjB,WACE,aAAa,a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AA,EACX;AACF;;;AChBA,IAAAC,eAA8D;AASvD,IAAM,uBAAsC;AAAA,EACjD,aAAa;AAAA,EACb,cAAc,CAAC;AAAA,EACf,uBAAuB,CAAC;AAAA,EACxB,qBAAqB,CAAC;AAAA,EACtB,cAAc,EAAE,GAAG,GAAG,GAAG,EAAE;AAAA,EAC3B,cAAc;AAAA,EACd,YAAY;AACd;AAEO,IAAM,eAAkF,CAC7F,WACA,YACI;AAAA,EACJ,cAAc,CAAC;AAAA,EACf,YAAY,UAAU,MAAM;AAAA,EAC5B,kBAAkB,EAAE,OAAO,GAAG,QAAQ,EAAE;AAAA,EACxC,uBAAuB,EAAE,GAAG,GAAG,GAAG,EAAE;AAAA,EACpC,UAAU,OAAO;AAAA,EACjB,SAAS,OAAO,WAAW;AAAA,EAC3B,OAAO,UAAU;AAAA,EACjB,GAAG;AACL;AAEO,IAAM,gBAAqE,CAChF,OACA,WACG;AACH,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,YAAY,OAAO,QAAQ;AAAA,IAChD,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,OAAO,OAAO,QAAQ;AAAA,IAC3C,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,GAAG,OAAO,QAAQ;AAAA,IACvC,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,uBAAuB,OAAO,QAAQ;AAAA,IAC3D;AACE,aAAO;AAAA,EACX;AACF;;;AC1CO,IAAM,sBAKT;AAAA,EACF;AAAA,EACA,QAAQ,CAAC,UAAU,SAAS,WAAW,IAAI,aAAa,kBAAkB,UAAU,MAAM;AAAA,EAC1F,SAAS;AAAA,EACT,cAAc,CAAC,WAAW,WAAW,aAAa,WAAW,MAAM;AACrE;","names":["import_models","ScrollStrategy","item","import_core"]}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/lib/types.ts","../src/lib/strategies/base-strategy.ts","../src/lib/strategies/vertical-strategy.ts","../src/lib/strategies/horizontal-strategy.ts","../src/lib/actions.ts","../src/lib/selectors.ts","../src/lib/scroll-plugin.ts","../src/lib/manifest.ts","../src/lib/reducer.ts","../src/lib/index.ts"],"sourcesContent":["import { BasePluginConfig, Emitter, EventHook } from '@embedpdf/core';\nimport { PdfPageObject, Rect, Rotation } from '@embedpdf/models';\nimport { ViewportMetrics } from '@embedpdf/plugin-viewport';\nimport { VirtualItem } from './types/virtual-item';\n\nexport interface ScrollState extends ScrollMetrics {\n virtualItems: VirtualItem[];\n totalPages: number;\n totalContentSize: { width: number; height: number };\n desiredScrollPosition: { x: number; y: number };\n strategy: ScrollStrategy;\n pageGap: number;\n scale: number;\n}\n\nexport interface ScrollerLayout {\n startSpacing: number;\n endSpacing: number;\n totalWidth: number;\n totalHeight: number;\n pageGap: number;\n strategy: ScrollState['strategy'];\n items: VirtualItem[];\n}\n\nexport enum ScrollStrategy {\n Vertical = 'vertical',\n Horizontal = 'horizontal',\n}\n\nexport interface PageVisibilityMetrics {\n pageNumber: number;\n viewportX: number;\n viewportY: number;\n visiblePercentage: number;\n original: {\n pageX: number;\n pageY: number;\n visibleWidth: number;\n visibleHeight: number;\n scale: number;\n };\n scaled: {\n pageX: number;\n pageY: number;\n visibleWidth: number;\n visibleHeight: number;\n scale: number;\n };\n}\n\nexport interface ScrollMetrics {\n currentPage: number;\n visiblePages: number[];\n pageVisibilityMetrics: PageVisibilityMetrics[];\n renderedPageIndexes: number[];\n scrollOffset: { x: number; y: number };\n startSpacing: number;\n endSpacing: number;\n}\n\nexport interface ScrollStrategyInterface {\n initialize(container: HTMLElement, innerDiv: HTMLElement): void;\n destroy(): void;\n updateLayout(viewport: ViewportMetrics, pdfPageObject: PdfPageObject[][]): void;\n handleScroll(viewport: ViewportMetrics): void;\n getVirtualItems(): VirtualItem[];\n scrollToPage(pageNumber: number, behavior?: ScrollBehavior): void;\n calculateDimensions(pdfPageObject: PdfPageObject[][]): void;\n}\n\nexport interface ScrollPluginConfig extends BasePluginConfig {\n strategy?: ScrollStrategy;\n initialPage?: number;\n bufferSize?: number;\n pageGap?: number;\n}\n\nexport type LayoutChangePayload = Pick<ScrollState, 'virtualItems' | 'totalContentSize'>;\n\nexport interface ScrollToPageOptions {\n pageNumber: number;\n pageCoordinates?: { x: number; y: number };\n behavior?: ScrollBehavior;\n center?: boolean;\n}\n\nexport interface PageChangePayload {\n pageNumber: number;\n totalPages: number;\n}\n\nexport interface ScrollCapability {\n onScrollerData: EventHook<ScrollerLayout>;\n onStateChange: EventHook<ScrollState>;\n onScroll: EventHook<ScrollMetrics>;\n getCurrentPage(): number;\n getTotalPages(): number;\n onPageChange: EventHook<PageChangePayload>;\n onLayoutChange: EventHook<LayoutChangePayload>;\n onLayoutReady: EventHook<boolean>;\n scrollToPage(options: ScrollToPageOptions): void;\n scrollToNextPage(behavior?: ScrollBehavior): void;\n scrollToPreviousPage(behavior?: ScrollBehavior): void;\n getMetrics(viewport?: ViewportMetrics): ScrollMetrics;\n getLayout(): LayoutChangePayload;\n getScrollerLayout(): ScrollerLayout;\n getRectPositionForPage(\n page: number,\n rect: Rect,\n scale?: number,\n rotation?: Rotation,\n ): Rect | null;\n setScrollStrategy(strategy: ScrollStrategy): void;\n getPageGap(): number;\n}\n","import {\n PdfPageObjectWithRotatedSize,\n Position,\n Rect,\n Rotation,\n scalePosition,\n transformPosition,\n transformRect,\n} from '@embedpdf/models';\nimport { ViewportMetrics } from '@embedpdf/plugin-viewport';\nimport { VirtualItem } from '../types/virtual-item';\nimport { ScrollMetrics } from '../types';\n\nexport interface ScrollStrategyConfig {\n pageGap?: number;\n viewportGap?: number;\n bufferSize?: number;\n}\n\nexport abstract class BaseScrollStrategy {\n protected pageGap: number;\n protected viewportGap: number;\n protected bufferSize: number;\n\n constructor(config: ScrollStrategyConfig) {\n this.pageGap = config.pageGap ?? 20;\n this.viewportGap = config.viewportGap ?? 20;\n this.bufferSize = config.bufferSize ?? 2;\n }\n\n abstract createVirtualItems(pdfPageObject: PdfPageObjectWithRotatedSize[][]): VirtualItem[];\n abstract getTotalContentSize(virtualItems: VirtualItem[]): { width: number; height: number };\n protected abstract getScrollOffset(viewport: ViewportMetrics): number;\n protected abstract getClientSize(viewport: ViewportMetrics): number;\n\n protected getVisibleRange(\n viewport: ViewportMetrics,\n virtualItems: VirtualItem[],\n scale: number,\n ): { start: number; end: number } {\n const scrollOffset = this.getScrollOffset(viewport);\n const clientSize = this.getClientSize(viewport);\n const viewportStart = scrollOffset;\n const viewportEnd = scrollOffset + clientSize;\n\n let startIndex = 0;\n while (\n startIndex < virtualItems.length &&\n (virtualItems[startIndex].offset + virtualItems[startIndex].height) * scale <= viewportStart\n ) {\n startIndex++;\n }\n\n let endIndex = startIndex;\n while (endIndex < virtualItems.length && virtualItems[endIndex].offset * scale <= viewportEnd) {\n endIndex++;\n }\n\n return {\n start: Math.max(0, startIndex - this.bufferSize),\n end: Math.min(virtualItems.length - 1, endIndex + this.bufferSize - 1),\n };\n }\n\n handleScroll(\n viewport: ViewportMetrics,\n virtualItems: VirtualItem[],\n scale: number,\n ): ScrollMetrics {\n const range = this.getVisibleRange(viewport, virtualItems, scale);\n const visibleItems = virtualItems.slice(range.start, range.end + 1);\n const pageVisibilityMetrics = this.calculatePageVisibility(visibleItems, viewport, scale);\n const visiblePages = pageVisibilityMetrics.map((m) => m.pageNumber);\n const renderedPageIndexes = virtualItems\n .slice(range.start, range.end + 1)\n .flatMap((item) => item.index);\n const currentPage = this.determineCurrentPage(pageVisibilityMetrics);\n const first = virtualItems[range.start];\n const last = virtualItems[range.end];\n const startSpacing = first ? first.offset * scale : 0;\n const endSpacing = last\n ? (virtualItems[virtualItems.length - 1].offset + // end of content\n virtualItems[virtualItems.length - 1].height) *\n scale - // minus\n (last.offset + last.height) * scale // end of last rendered\n : 0;\n\n return {\n currentPage,\n visiblePages,\n pageVisibilityMetrics,\n renderedPageIndexes,\n scrollOffset: { x: viewport.scrollLeft, y: viewport.scrollTop },\n startSpacing,\n endSpacing,\n };\n }\n\n protected calculatePageVisibility(\n virtualItems: VirtualItem[],\n viewport: ViewportMetrics,\n scale: number,\n ): ScrollMetrics['pageVisibilityMetrics'] {\n const visibilityMetrics: ScrollMetrics['pageVisibilityMetrics'] = [];\n\n virtualItems.forEach((item) => {\n item.pageLayouts.forEach((page) => {\n const itemX = item.x * scale;\n const itemY = item.y * scale;\n const pageX = itemX + page.x * scale;\n const pageY = itemY + page.y * scale;\n const pageWidth = page.rotatedWidth * scale;\n const pageHeight = page.rotatedHeight * scale;\n\n const viewportLeft = viewport.scrollLeft;\n const viewportTop = viewport.scrollTop;\n const viewportRight = viewportLeft + viewport.clientWidth;\n const viewportBottom = viewportTop + viewport.clientHeight;\n\n const intersectionLeft = Math.max(pageX, viewportLeft);\n const intersectionTop = Math.max(pageY, viewportTop);\n const intersectionRight = Math.min(pageX + pageWidth, viewportRight);\n const intersectionBottom = Math.min(pageY + pageHeight, viewportBottom);\n\n if (intersectionLeft < intersectionRight && intersectionTop < intersectionBottom) {\n const visibleWidth = intersectionRight - intersectionLeft;\n const visibleHeight = intersectionBottom - intersectionTop;\n const totalArea = pageWidth * pageHeight;\n const visibleArea = visibleWidth * visibleHeight;\n\n visibilityMetrics.push({\n pageNumber: page.pageNumber,\n viewportX: intersectionLeft - viewportLeft,\n viewportY: intersectionTop - viewportTop,\n visiblePercentage: (visibleArea / totalArea) * 100,\n original: {\n pageX: (intersectionLeft - pageX) / scale,\n pageY: (intersectionTop - pageY) / scale,\n visibleWidth: visibleWidth / scale,\n visibleHeight: visibleHeight / scale,\n scale: 1,\n },\n scaled: {\n pageX: intersectionLeft - pageX,\n pageY: intersectionTop - pageY,\n visibleWidth,\n visibleHeight,\n scale,\n },\n });\n }\n });\n });\n\n return visibilityMetrics;\n }\n\n protected determineCurrentPage(\n visibilityMetrics: ScrollMetrics['pageVisibilityMetrics'],\n ): number {\n if (visibilityMetrics.length === 0) return 1;\n\n const maxVisibility = Math.max(...visibilityMetrics.map((m) => m.visiblePercentage));\n const mostVisiblePages = visibilityMetrics.filter((m) => m.visiblePercentage === maxVisibility);\n\n return mostVisiblePages.length === 1\n ? mostVisiblePages[0].pageNumber\n : mostVisiblePages.sort((a, b) => a.pageNumber - b.pageNumber)[0].pageNumber;\n }\n\n private getRectLocationForPage(pageNumber: number, virtualItems: VirtualItem[]): Rect | null {\n // Find the virtual item containing the page\n const item = virtualItems.find((item) => item.pageNumbers.includes(pageNumber));\n if (!item) return null;\n\n // Find the specific page layout for the requested page number\n const pageLayout = item.pageLayouts.find((layout) => layout.pageNumber === pageNumber);\n if (!pageLayout) return null;\n\n return {\n origin: {\n x: item.x + pageLayout.x,\n y: item.y + pageLayout.y,\n },\n size: {\n width: pageLayout.width,\n height: pageLayout.height,\n },\n };\n }\n\n getScrollPositionForPage(\n pageNumber: number,\n virtualItems: VirtualItem[],\n scale: number,\n rotation: Rotation,\n pageCoordinates?: { x: number; y: number },\n ): Position | null {\n // Find the virtual item containing the page\n const pageRect = this.getRectLocationForPage(pageNumber, virtualItems);\n if (!pageRect) return null;\n\n const scaledBasePosition = scalePosition(pageRect.origin, scale);\n\n // If specific page coordinates are provided, add them to the base position\n if (pageCoordinates) {\n const rotatedSize = transformPosition(\n {\n width: pageRect.size.width,\n height: pageRect.size.height,\n },\n {\n x: pageCoordinates.x,\n y: pageCoordinates.y,\n },\n rotation,\n scale,\n );\n\n return {\n x: scaledBasePosition.x + rotatedSize.x + this.viewportGap,\n y: scaledBasePosition.y + rotatedSize.y + this.viewportGap,\n };\n }\n\n return {\n x: scaledBasePosition.x + this.viewportGap,\n y: scaledBasePosition.y + this.viewportGap,\n };\n }\n\n getRectPositionForPage(\n pageNumber: number,\n virtualItems: VirtualItem[],\n scale: number,\n rotation: Rotation,\n rect: Rect,\n ): Rect | null {\n const pageRect = this.getRectLocationForPage(pageNumber, virtualItems);\n if (!pageRect) return null;\n\n const scaledBasePosition = scalePosition(pageRect.origin, scale);\n\n const rotatedSize = transformRect(\n {\n width: pageRect.size.width,\n height: pageRect.size.height,\n },\n rect,\n rotation,\n scale,\n );\n\n return {\n origin: {\n x: scaledBasePosition.x + rotatedSize.origin.x,\n y: scaledBasePosition.y + rotatedSize.origin.y,\n },\n size: rotatedSize.size,\n };\n }\n}\n","import { PdfPageObjectWithRotatedSize } from '@embedpdf/models';\nimport { ViewportMetrics } from '@embedpdf/plugin-viewport';\nimport { BaseScrollStrategy, ScrollStrategyConfig } from './base-strategy';\nimport { VirtualItem, PageLayout } from '../types/virtual-item';\nimport { ScrollMetrics } from '../types';\n\nexport class VerticalScrollStrategy extends BaseScrollStrategy {\n constructor(config: ScrollStrategyConfig) {\n super(config);\n }\n\n createVirtualItems(pdfPageObject: PdfPageObjectWithRotatedSize[][]): VirtualItem[] {\n let yOffset = 0;\n return pdfPageObject.map((pagesInSpread, index) => {\n let pageX = 0;\n const pageLayouts: PageLayout[] = pagesInSpread.map((page) => {\n const layout: PageLayout = {\n pageNumber: page.index + 1,\n pageIndex: page.index,\n x: pageX,\n y: 0,\n width: page.size.width,\n height: page.size.height,\n rotatedWidth: page.rotatedSize.width,\n rotatedHeight: page.rotatedSize.height,\n };\n pageX += page.rotatedSize.width + this.pageGap;\n return layout;\n });\n const width = pagesInSpread.reduce(\n (sum, page, i) =>\n sum + page.rotatedSize.width + (i < pagesInSpread.length - 1 ? this.pageGap : 0),\n 0,\n );\n const height = Math.max(...pagesInSpread.map((p) => p.rotatedSize.height));\n const item: VirtualItem = {\n id: `item-${index}`,\n x: 0,\n y: yOffset,\n offset: yOffset,\n width,\n height,\n pageLayouts,\n pageNumbers: pagesInSpread.map((p) => p.index + 1),\n index,\n };\n yOffset += height + this.pageGap;\n return item;\n });\n }\n\n getTotalContentSize(virtualItems: VirtualItem[]): { width: number; height: number } {\n if (virtualItems.length === 0) return { width: 0, height: 0 };\n const maxWidth = Math.max(...virtualItems.map((item) => item.width));\n const totalHeight =\n virtualItems[virtualItems.length - 1].y + virtualItems[virtualItems.length - 1].height;\n return {\n width: maxWidth,\n height: totalHeight,\n };\n }\n\n protected getScrollOffset(viewport: ViewportMetrics): number {\n return viewport.scrollTop;\n }\n\n protected getClientSize(viewport: ViewportMetrics): number {\n return viewport.clientHeight;\n }\n}\n","import { PdfPageObjectWithRotatedSize } from '@embedpdf/models';\nimport { ViewportMetrics } from '@embedpdf/plugin-viewport';\nimport { BaseScrollStrategy, ScrollStrategyConfig } from './base-strategy';\nimport { VirtualItem, PageLayout } from '../types/virtual-item';\n\nexport class HorizontalScrollStrategy extends BaseScrollStrategy {\n constructor(config: ScrollStrategyConfig) {\n super(config);\n }\n\n createVirtualItems(pdfPageObject: PdfPageObjectWithRotatedSize[][]): VirtualItem[] {\n let xOffset = 0;\n return pdfPageObject.map((pagesInSpread, index) => {\n let pageX = 0;\n const pageLayouts: PageLayout[] = pagesInSpread.map((page) => {\n const layout: PageLayout = {\n pageNumber: page.index + 1,\n pageIndex: page.index,\n x: pageX,\n y: 0,\n width: page.size.width,\n height: page.size.height,\n rotatedWidth: page.rotatedSize.width,\n rotatedHeight: page.rotatedSize.height,\n };\n pageX += page.rotatedSize.width + this.pageGap;\n return layout;\n });\n const width = pagesInSpread.reduce(\n (sum, page, i) =>\n sum + page.rotatedSize.width + (i < pagesInSpread.length - 1 ? this.pageGap : 0),\n 0,\n );\n const height = Math.max(...pagesInSpread.map((p) => p.rotatedSize.height));\n const item: VirtualItem = {\n id: `item-${index}`,\n x: xOffset,\n y: 0,\n offset: xOffset,\n width,\n height,\n pageLayouts,\n pageNumbers: pagesInSpread.map((p) => p.index + 1),\n index,\n };\n xOffset += width + this.pageGap;\n return item;\n });\n }\n\n getTotalContentSize(virtualItems: VirtualItem[]): { width: number; height: number } {\n if (virtualItems.length === 0) return { width: 0, height: 0 };\n const totalWidth =\n virtualItems[virtualItems.length - 1].x + virtualItems[virtualItems.length - 1].width;\n const maxHeight = Math.max(...virtualItems.map((item) => item.height));\n return {\n width: totalWidth,\n height: maxHeight,\n };\n }\n\n protected getScrollOffset(viewport: ViewportMetrics): number {\n return viewport.scrollLeft;\n }\n\n protected getClientSize(viewport: ViewportMetrics): number {\n return viewport.clientWidth;\n }\n}\n","import { Action } from '@embedpdf/core';\nimport { ScrollState } from './types';\n\nexport const UPDATE_SCROLL_STATE = 'UPDATE_SCROLL_STATE';\nexport const SET_DESIRED_SCROLL_POSITION = 'SET_DESIRED_SCROLL_POSITION';\nexport const UPDATE_TOTAL_PAGES = 'UPDATE_TOTAL_PAGES';\n\nexport interface UpdateScrollStateAction extends Action {\n type: typeof UPDATE_SCROLL_STATE;\n payload: Partial<ScrollState>;\n}\n\nexport interface SetDesiredScrollPositionAction extends Action {\n type: typeof SET_DESIRED_SCROLL_POSITION;\n payload: { x: number; y: number };\n}\n\nexport interface UpdateTotalPagesAction extends Action {\n type: typeof UPDATE_TOTAL_PAGES;\n payload: number;\n}\n\nexport type ScrollAction =\n | UpdateScrollStateAction\n | SetDesiredScrollPositionAction\n | UpdateTotalPagesAction;\n\nexport function updateScrollState(payload: Partial<ScrollState>): UpdateScrollStateAction {\n return { type: UPDATE_SCROLL_STATE, payload };\n}\n\nexport function setDesiredScrollPosition(payload: {\n x: number;\n y: number;\n}): SetDesiredScrollPositionAction {\n return { type: SET_DESIRED_SCROLL_POSITION, payload };\n}\n\nexport function updateTotalPages(payload: number): UpdateTotalPagesAction {\n return { type: UPDATE_TOTAL_PAGES, payload };\n}\n","import { ScrollerLayout, ScrollState } from './types';\n\nexport const getScrollerLayout = (state: ScrollState, scale: number): ScrollerLayout => {\n return {\n startSpacing: state.startSpacing,\n endSpacing: state.endSpacing,\n totalWidth: state.totalContentSize.width * scale,\n totalHeight: state.totalContentSize.height * scale,\n pageGap: state.pageGap * scale,\n strategy: state.strategy,\n items: state.renderedPageIndexes.map((idx) => {\n return {\n ...state.virtualItems[idx],\n pageLayouts: state.virtualItems[idx].pageLayouts.map((layout) => {\n return {\n ...layout,\n rotatedWidth: layout.rotatedWidth * scale,\n rotatedHeight: layout.rotatedHeight * scale,\n width: layout.width * scale,\n height: layout.height * scale,\n };\n }),\n };\n }),\n };\n};\n","import {\n BasePlugin,\n CoreState,\n PluginRegistry,\n SET_DOCUMENT,\n SET_PAGES,\n SET_ROTATION,\n StoreState,\n createBehaviorEmitter,\n createEmitter,\n getPagesWithRotatedSize,\n} from '@embedpdf/core';\nimport {\n PdfPageObject,\n PdfPageObjectWithRotatedSize,\n Position,\n Rect,\n restoreRect,\n rotateRect,\n Rotation,\n transformRect,\n} from '@embedpdf/models';\nimport { ViewportCapability, ViewportMetrics, ViewportPlugin } from '@embedpdf/plugin-viewport';\nimport {\n ScrollCapability,\n ScrollPluginConfig,\n ScrollStrategy,\n ScrollMetrics,\n ScrollState,\n LayoutChangePayload,\n ScrollerLayout,\n ScrollToPageOptions,\n PageChangePayload,\n} from './types';\nimport { BaseScrollStrategy, ScrollStrategyConfig } from './strategies/base-strategy';\nimport { VerticalScrollStrategy } from './strategies/vertical-strategy';\nimport { HorizontalScrollStrategy } from './strategies/horizontal-strategy';\nimport { updateScrollState, ScrollAction, updateTotalPages } from './actions';\nimport { VirtualItem } from './types/virtual-item';\nimport { getScrollerLayout } from './selectors';\n\ntype PartialScroll = Partial<ScrollState>;\ntype Emits = {\n layout?: LayoutChangePayload;\n metrics?: ScrollMetrics;\n};\n\nexport class ScrollPlugin extends BasePlugin<\n ScrollPluginConfig,\n ScrollCapability,\n ScrollState,\n ScrollAction\n> {\n static readonly id = 'scroll' as const;\n private viewport: ViewportCapability;\n private strategy: BaseScrollStrategy;\n private strategyConfig: ScrollStrategyConfig;\n private currentScale: number = 1;\n private currentRotation: Rotation = Rotation.Degree0;\n private initialPage?: number;\n private currentPage: number = 1;\n private layoutReady: boolean = false;\n\n private readonly layout$ = createBehaviorEmitter<LayoutChangePayload>();\n private readonly scroll$ = createBehaviorEmitter<ScrollMetrics>();\n private readonly state$ = createBehaviorEmitter<ScrollState>();\n private readonly scrollerLayout$ = createBehaviorEmitter<ScrollerLayout>();\n private readonly pageChange$ = createBehaviorEmitter<PageChangePayload>();\n private readonly layoutReady$ = createBehaviorEmitter<boolean>();\n\n constructor(\n public readonly id: string,\n registry: PluginRegistry,\n private config?: ScrollPluginConfig,\n ) {\n super(id, registry);\n\n this.viewport = this.registry.getPlugin<ViewportPlugin>('viewport')!.provides();\n\n this.strategyConfig = {\n pageGap: this.config?.pageGap ?? 10,\n viewportGap: this.viewport.getViewportGap(),\n bufferSize: this.config?.bufferSize ?? 2,\n };\n\n this.strategy =\n this.config?.strategy === ScrollStrategy.Horizontal\n ? new HorizontalScrollStrategy(this.strategyConfig)\n : new VerticalScrollStrategy(this.strategyConfig);\n\n this.initialPage = this.config?.initialPage;\n this.currentScale = this.coreState.core.scale;\n this.currentRotation = this.coreState.core.rotation;\n // Subscribe to viewport and page manager events\n this.viewport.onViewportChange((vp) => this.commitMetrics(this.computeMetrics(vp)), {\n mode: 'throttle',\n wait: 250,\n });\n this.coreStore.onAction(SET_DOCUMENT, (_action, state) => {\n const totalPages = state.core.pages.length;\n this.dispatch(updateTotalPages(totalPages));\n this.pageChange$.emit({ pageNumber: this.currentPage, totalPages });\n this.refreshAll(getPagesWithRotatedSize(state.core), this.viewport.getMetrics());\n });\n this.coreStore.onAction(SET_ROTATION, (_action, state) =>\n this.refreshAll(getPagesWithRotatedSize(state.core), this.viewport.getMetrics()),\n );\n this.coreStore.onAction(SET_PAGES, (_action, state) =>\n this.refreshAll(getPagesWithRotatedSize(state.core), this.viewport.getMetrics()),\n );\n }\n\n /* ------------------------------------------------------------------ */\n /* ᴄᴏᴍᴘᴜᴛᴇʀs */\n /* ------------------------------------------------------------------ */\n\n private computeLayout(pages: PdfPageObjectWithRotatedSize[][]) {\n const virtualItems = this.strategy.createVirtualItems(pages);\n const totalContentSize = this.strategy.getTotalContentSize(virtualItems);\n return { virtualItems, totalContentSize };\n }\n\n private computeMetrics(vp: ViewportMetrics, items: VirtualItem[] = this.state.virtualItems) {\n return this.strategy.handleScroll(vp, items, this.currentScale);\n }\n\n /* ------------------------------------------------------------------ */\n /* ᴄᴏᴍᴍɪᴛ (single source of truth) */\n /* ------------------------------------------------------------------ */\n\n private commit(stateDelta: PartialScroll, emit?: Emits) {\n /* update Redux-like store */\n this.dispatch(updateScrollState(stateDelta));\n\n /* fire optional events */\n if (emit?.layout) this.layout$.emit(emit.layout);\n if (emit?.metrics) {\n this.scroll$.emit(emit.metrics);\n\n if (emit.metrics.currentPage !== this.currentPage) {\n this.currentPage = emit.metrics.currentPage;\n this.pageChange$.emit({ pageNumber: this.currentPage, totalPages: this.state.totalPages });\n }\n }\n\n /* keep scroller-layout reactive */\n this.scrollerLayout$.emit(this.getScrollerLayoutFromState());\n }\n\n /* convenience wrappers */\n private commitMetrics(metrics: ScrollMetrics) {\n this.commit(metrics, { metrics });\n }\n\n /* full re-compute after page-spread or initialisation */\n private refreshAll(pages: PdfPageObjectWithRotatedSize[][], vp: ViewportMetrics) {\n const layout = this.computeLayout(pages);\n const metrics = this.computeMetrics(vp, layout.virtualItems);\n\n this.commit({ ...layout, ...metrics }, { layout, metrics });\n }\n\n private getVirtualItemsFromState(): VirtualItem[] {\n return this.state.virtualItems || [];\n }\n\n private getScrollerLayoutFromState(): ScrollerLayout {\n const scale = this.coreState.core.scale;\n return getScrollerLayout(this.state, scale);\n }\n\n private pushScrollLayout() {\n this.scrollerLayout$.emit(this.getScrollerLayoutFromState());\n }\n\n override onStoreUpdated(_prevState: ScrollState, _newState: ScrollState): void {\n this.pushScrollLayout();\n }\n\n override onCoreStoreUpdated(\n prevState: StoreState<CoreState>,\n newState: StoreState<CoreState>,\n ): void {\n if (prevState.core.scale !== newState.core.scale) {\n this.currentScale = newState.core.scale;\n this.commitMetrics(this.computeMetrics(this.viewport.getMetrics()));\n }\n if (prevState.core.rotation !== newState.core.rotation) {\n this.currentRotation = newState.core.rotation;\n }\n }\n\n /**\n * Change the scroll strategy at runtime (e.g., vertical <-> horizontal)\n * @param newStrategy ScrollStrategy.Horizontal or ScrollStrategy.Vertical\n */\n private setScrollStrategy(newStrategy: ScrollStrategy) {\n // Only update if the strategy is actually changing\n if (\n (newStrategy === ScrollStrategy.Horizontal &&\n this.strategy instanceof HorizontalScrollStrategy) ||\n (newStrategy === ScrollStrategy.Vertical && this.strategy instanceof VerticalScrollStrategy)\n ) {\n return;\n }\n\n this.strategy =\n newStrategy === ScrollStrategy.Horizontal\n ? new HorizontalScrollStrategy(this.strategyConfig)\n : new VerticalScrollStrategy(this.strategyConfig);\n\n // Update state with new strategy\n this.dispatch(\n updateScrollState({\n strategy: newStrategy,\n }),\n );\n\n // Recalculate layout and scroll metrics\n const pages = getPagesWithRotatedSize(this.coreState.core);\n this.refreshAll(pages, this.viewport.getMetrics());\n }\n\n public setLayoutReady() {\n if (this.layoutReady) return;\n\n this.layoutReady = true;\n this.layoutReady$.emit(true);\n }\n\n protected buildCapability(): ScrollCapability {\n return {\n onStateChange: this.state$.on,\n onLayoutChange: this.layout$.on,\n onScroll: this.scroll$.on,\n onPageChange: this.pageChange$.on,\n onScrollerData: this.scrollerLayout$.on,\n onLayoutReady: this.layoutReady$.on,\n getCurrentPage: () => this.currentPage,\n getTotalPages: () => this.state.totalPages,\n scrollToPage: (options: ScrollToPageOptions) => {\n const { pageNumber, behavior = 'smooth', pageCoordinates, center = false } = options;\n const virtualItems = this.getVirtualItemsFromState();\n const position = this.strategy.getScrollPositionForPage(\n pageNumber,\n virtualItems,\n this.currentScale,\n this.currentRotation,\n pageCoordinates,\n );\n if (position) {\n this.viewport.scrollTo({ ...position, behavior, center });\n }\n },\n scrollToNextPage: (behavior = 'smooth') => {\n const virtualItems = this.getVirtualItemsFromState();\n const currentItemIndex = virtualItems.findIndex((item) =>\n item.pageNumbers.includes(this.currentPage),\n );\n if (currentItemIndex >= 0 && currentItemIndex < virtualItems.length - 1) {\n const nextItem = virtualItems[currentItemIndex + 1];\n const position = this.strategy.getScrollPositionForPage(\n nextItem.pageNumbers[0],\n virtualItems,\n this.currentScale,\n this.currentRotation,\n );\n if (position) {\n this.viewport.scrollTo({ ...position, behavior });\n }\n }\n },\n scrollToPreviousPage: (behavior = 'smooth') => {\n const virtualItems = this.getVirtualItemsFromState();\n const currentItemIndex = virtualItems.findIndex((item) =>\n item.pageNumbers.includes(this.currentPage),\n );\n if (currentItemIndex > 0) {\n const prevItem = virtualItems[currentItemIndex - 1];\n const position = this.strategy.getScrollPositionForPage(\n prevItem.pageNumbers[0],\n virtualItems,\n this.currentScale,\n this.currentRotation,\n );\n if (position) {\n this.viewport.scrollTo({ ...position, behavior });\n }\n }\n },\n getMetrics: this.getMetrics.bind(this),\n getLayout: this.getLayout.bind(this),\n getRectPositionForPage: this.getRectPositionForPage.bind(this),\n getPageGap: () => this.state.pageGap,\n getScrollerLayout: () => this.getScrollerLayoutFromState(),\n setScrollStrategy: (strategy: ScrollStrategy) => this.setScrollStrategy(strategy),\n };\n }\n\n private getMetrics(viewport?: ViewportMetrics): ScrollMetrics {\n const metrics = viewport || this.viewport.getMetrics();\n const virtualItems = this.getVirtualItemsFromState();\n return this.strategy.handleScroll(metrics, virtualItems, this.currentScale);\n }\n\n private getLayout(): LayoutChangePayload {\n return {\n virtualItems: this.state.virtualItems,\n totalContentSize: this.state.totalContentSize,\n };\n }\n\n private getRectPositionForPage(\n pageIndex: number,\n rect: Rect,\n scale?: number,\n rotation?: Rotation,\n ): Rect | null {\n return this.strategy.getRectPositionForPage(\n pageIndex + 1,\n this.state.virtualItems,\n scale ?? this.currentScale,\n rotation ?? this.currentRotation,\n rect,\n );\n }\n\n async initialize(): Promise<void> {\n // No DOM initialization needed; state drives rendering\n }\n\n async destroy(): Promise<void> {\n this.layout$.clear();\n this.scroll$.clear();\n this.pageChange$.clear();\n this.state$.clear();\n this.scrollerLayout$.clear();\n this.layoutReady$.clear();\n super.destroy();\n }\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { ScrollPluginConfig } from './types';\n\nexport const SCROLL_PLUGIN_ID = 'scroll';\n\nexport const manifest: PluginManifest<ScrollPluginConfig> = {\n id: SCROLL_PLUGIN_ID,\n name: 'Scroll Plugin',\n version: '1.0.0',\n provides: ['scroll'],\n requires: ['viewport'],\n optional: [],\n defaultConfig: {\n enabled: true,\n pageGap: 10,\n },\n};\n","import { Reducer, CoreState, SET_SCALE, SetScaleAction } from '@embedpdf/core';\nimport { ScrollState, ScrollStrategy, ScrollPluginConfig, ScrollMetrics } from './types';\nimport {\n ScrollAction,\n UPDATE_SCROLL_STATE,\n SET_DESIRED_SCROLL_POSITION,\n UPDATE_TOTAL_PAGES,\n} from './actions';\n\nexport const defaultScrollMetrics: ScrollMetrics = {\n currentPage: 1,\n visiblePages: [],\n pageVisibilityMetrics: [],\n renderedPageIndexes: [],\n scrollOffset: { x: 0, y: 0 },\n startSpacing: 0,\n endSpacing: 0,\n};\n\nexport const initialState: (coreState: CoreState, config: ScrollPluginConfig) => ScrollState = (\n coreState,\n config,\n) => ({\n virtualItems: [],\n totalPages: coreState.pages.length,\n totalContentSize: { width: 0, height: 0 },\n desiredScrollPosition: { x: 0, y: 0 },\n strategy: config.strategy ?? ScrollStrategy.Vertical,\n pageGap: config.pageGap ?? 10,\n scale: coreState.scale,\n ...defaultScrollMetrics,\n});\n\nexport const scrollReducer: Reducer<ScrollState, ScrollAction | SetScaleAction> = (\n state,\n action,\n) => {\n switch (action.type) {\n case UPDATE_TOTAL_PAGES:\n return { ...state, totalPages: action.payload };\n case SET_SCALE:\n return { ...state, scale: action.payload };\n case UPDATE_SCROLL_STATE:\n return { ...state, ...action.payload };\n case SET_DESIRED_SCROLL_POSITION:\n return { ...state, desiredScrollPosition: action.payload };\n default:\n return state;\n }\n};\n","import { PluginPackage } from '@embedpdf/core';\nimport { ScrollPlugin } from './scroll-plugin';\nimport { manifest, SCROLL_PLUGIN_ID } from './manifest';\nimport { ScrollPluginConfig, ScrollState } from './types';\nimport { scrollReducer, initialState } from './reducer';\nimport { ScrollAction } from './actions';\n\nexport const ScrollPluginPackage: PluginPackage<\n ScrollPlugin,\n ScrollPluginConfig,\n ScrollState,\n ScrollAction\n> = {\n manifest,\n create: (registry, _engine, config) => new ScrollPlugin(SCROLL_PLUGIN_ID, registry, config),\n reducer: scrollReducer,\n initialState: (coreState, config) => initialState(coreState, config),\n};\n\nexport * from './scroll-plugin';\nexport * from './types';\nexport * from './manifest';\nexport * from './types/virtual-item';\n"],"names":["ScrollStrategy","BaseScrollStrategy","constructor","config","this","pageGap","viewportGap","bufferSize","getVisibleRange","viewport","virtualItems","scale","scrollOffset","getScrollOffset","viewportStart","viewportEnd","getClientSize","startIndex","length","offset","height","endIndex","start","Math","max","end","min","handleScroll","range","visibleItems","slice","pageVisibilityMetrics","calculatePageVisibility","visiblePages","map","m","pageNumber","renderedPageIndexes","flatMap","item","index","currentPage","determineCurrentPage","first","last","startSpacing","endSpacing","x","scrollLeft","y","scrollTop","visibilityMetrics","forEach","pageLayouts","page","itemX","itemY","pageX","pageY","pageWidth","rotatedWidth","pageHeight","rotatedHeight","viewportLeft","viewportTop","viewportRight","clientWidth","viewportBottom","clientHeight","intersectionLeft","intersectionTop","intersectionRight","intersectionBottom","visibleWidth","visibleHeight","totalArea","visibleArea","push","viewportX","viewportY","visiblePercentage","original","scaled","maxVisibility","mostVisiblePages","filter","sort","a","b","getRectLocationForPage","find","pageNumbers","includes","pageLayout","layout","origin","size","width","getScrollPositionForPage","rotation","pageCoordinates","pageRect","scaledBasePosition","scalePosition","rotatedSize","transformPosition","getRectPositionForPage","rect","transformRect","VerticalScrollStrategy","super","createVirtualItems","pdfPageObject","yOffset","pagesInSpread","pageIndex","reduce","sum","i","p","id","getTotalContentSize","HorizontalScrollStrategy","xOffset","UPDATE_SCROLL_STATE","UPDATE_TOTAL_PAGES","updateScrollState","payload","type","_ScrollPlugin","BasePlugin","registry","currentScale","currentRotation","Rotation","Degree0","layoutReady","layout$","createBehaviorEmitter","scroll$","state$","scrollerLayout$","pageChange$","layoutReady$","getPlugin","provides","strategyConfig","_a","getViewportGap","_b","strategy","_c","Horizontal","initialPage","_d","coreState","core","onViewportChange","vp","commitMetrics","computeMetrics","mode","wait","coreStore","onAction","SET_DOCUMENT","_action","state","totalPages","pages","dispatch","emit","refreshAll","getPagesWithRotatedSize","getMetrics","SET_ROTATION","SET_PAGES","computeLayout","totalContentSize","items","commit","stateDelta","metrics","getScrollerLayoutFromState","getVirtualItemsFromState","totalWidth","totalHeight","idx","getScrollerLayout","pushScrollLayout","onStoreUpdated","_prevState","_newState","onCoreStoreUpdated","prevState","newState","setScrollStrategy","newStrategy","Vertical","setLayoutReady","buildCapability","onStateChange","on","onLayoutChange","onScroll","onPageChange","onScrollerData","onLayoutReady","getCurrentPage","getTotalPages","scrollToPage","options","behavior","center","position","scrollTo","scrollToNextPage","currentItemIndex","findIndex","nextItem","scrollToPreviousPage","prevItem","bind","getLayout","getPageGap","initialize","destroy","clear","ScrollPlugin","SCROLL_PLUGIN_ID","manifest","name","version","requires","optional","defaultConfig","enabled","defaultScrollMetrics","ScrollPluginPackage","create","_engine","reducer","action","SET_SCALE","desiredScrollPosition","initialState"],"mappings":"gJAyBY,IAAAA,GAAAA,IACVA,EAAW,SAAA,WACXA,EAAa,WAAA,aAFHA,IAAAA,GAAA,CAAA,GCNL,MAAeC,EAKpB,WAAAC,CAAYC,GACLC,KAAAC,QAAUF,EAAOE,SAAW,GAC5BD,KAAAE,YAAcH,EAAOG,aAAe,GACpCF,KAAAG,WAAaJ,EAAOI,YAAc,CAAA,CAQ/B,eAAAC,CACRC,EACAC,EACAC,GAEM,MAAAC,EAAeR,KAAKS,gBAAgBJ,GAEpCK,EAAgBF,EAChBG,EAAcH,EAFDR,KAAKY,cAAcP,GAItC,IAAIQ,EAAa,EACjB,KACEA,EAAaP,EAAaQ,SACzBR,EAAaO,GAAYE,OAAST,EAAaO,GAAYG,QAAUT,GAASG,GAE/EG,IAGF,IAAII,EAAWJ,EACR,KAAAI,EAAWX,EAAaQ,QAAUR,EAAaW,GAAUF,OAASR,GAASI,GAChFM,IAGK,MAAA,CACLC,MAAOC,KAAKC,IAAI,EAAGP,EAAab,KAAKG,YACrCkB,IAAKF,KAAKG,IAAIhB,EA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AO6E,sBAAuBF,EAAOnH,SACnD,QACS,OAAAwC,EAAA,EC/BX8E,aAAc,CAAC1F,EAAWxJ,IDGmE,EAC7FwJ,EACAxJ,KACI,CACJO,aAAc,GACd8J,WAAYb,EAAUc,MAAMvJ,OAC5BgK,iBAAkB,CAAEjF,MAAO,EAAG7E,OAAQ,GACtCgO,sBAAuB,CAAErM,EAAG,EAAGE,EAAG,GAClCqG,SAAUnJ,EAAOmJ,UAAYtJ,EAAesM,SAC5CjM,QAASF,EAAOE,SAAW,GAC3BM,MAAOgJ,EAAUhJ,SACdkO,ICdkCQ,CAAa1F,EAAWxJ"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,204 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { Rect, Rotation, PdfPageObject } from '@embedpdf/models';
|
|
3
|
-
import { ViewportMetrics } from '@embedpdf/plugin-viewport';
|
|
4
|
-
|
|
5
|
-
interface PageLayout {
|
|
6
|
-
pageNumber: number;
|
|
7
|
-
pageIndex: number;
|
|
8
|
-
x: number;
|
|
9
|
-
y: number;
|
|
10
|
-
width: number;
|
|
11
|
-
height: number;
|
|
12
|
-
rotatedWidth: number;
|
|
13
|
-
rotatedHeight: number;
|
|
14
|
-
}
|
|
15
|
-
interface VirtualItem {
|
|
16
|
-
id: string;
|
|
17
|
-
x: number;
|
|
18
|
-
y: number;
|
|
19
|
-
offset: number;
|
|
20
|
-
width: number;
|
|
21
|
-
height: number;
|
|
22
|
-
pageLayouts: PageLayout[];
|
|
23
|
-
pageNumbers: number[];
|
|
24
|
-
index: number;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface ScrollState extends ScrollMetrics {
|
|
28
|
-
virtualItems: VirtualItem[];
|
|
29
|
-
totalPages: number;
|
|
30
|
-
totalContentSize: {
|
|
31
|
-
width: number;
|
|
32
|
-
height: number;
|
|
33
|
-
};
|
|
34
|
-
desiredScrollPosition: {
|
|
35
|
-
x: number;
|
|
36
|
-
y: number;
|
|
37
|
-
};
|
|
38
|
-
strategy: ScrollStrategy;
|
|
39
|
-
pageGap: number;
|
|
40
|
-
scale: number;
|
|
41
|
-
}
|
|
42
|
-
interface ScrollerLayout {
|
|
43
|
-
startSpacing: number;
|
|
44
|
-
endSpacing: number;
|
|
45
|
-
totalWidth: number;
|
|
46
|
-
totalHeight: number;
|
|
47
|
-
pageGap: number;
|
|
48
|
-
strategy: ScrollState['strategy'];
|
|
49
|
-
items: VirtualItem[];
|
|
50
|
-
}
|
|
51
|
-
declare enum ScrollStrategy {
|
|
52
|
-
Vertical = "vertical",
|
|
53
|
-
Horizontal = "horizontal"
|
|
54
|
-
}
|
|
55
|
-
interface PageVisibilityMetrics {
|
|
56
|
-
pageNumber: number;
|
|
57
|
-
viewportX: number;
|
|
58
|
-
viewportY: number;
|
|
59
|
-
visiblePercentage: number;
|
|
60
|
-
original: {
|
|
61
|
-
pageX: number;
|
|
62
|
-
pageY: number;
|
|
63
|
-
visibleWidth: number;
|
|
64
|
-
visibleHeight: number;
|
|
65
|
-
scale: number;
|
|
66
|
-
};
|
|
67
|
-
scaled: {
|
|
68
|
-
pageX: number;
|
|
69
|
-
pageY: number;
|
|
70
|
-
visibleWidth: number;
|
|
71
|
-
visibleHeight: number;
|
|
72
|
-
scale: number;
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
interface ScrollMetrics {
|
|
76
|
-
currentPage: number;
|
|
77
|
-
visiblePages: number[];
|
|
78
|
-
pageVisibilityMetrics: PageVisibilityMetrics[];
|
|
79
|
-
renderedPageIndexes: number[];
|
|
80
|
-
scrollOffset: {
|
|
81
|
-
x: number;
|
|
82
|
-
y: number;
|
|
83
|
-
};
|
|
84
|
-
startSpacing: number;
|
|
85
|
-
endSpacing: number;
|
|
86
|
-
}
|
|
87
|
-
interface ScrollStrategyInterface {
|
|
88
|
-
initialize(container: HTMLElement, innerDiv: HTMLElement): void;
|
|
89
|
-
destroy(): void;
|
|
90
|
-
updateLayout(viewport: ViewportMetrics, pdfPageObject: PdfPageObject[][]): void;
|
|
91
|
-
handleScroll(viewport: ViewportMetrics): void;
|
|
92
|
-
getVirtualItems(): VirtualItem[];
|
|
93
|
-
scrollToPage(pageNumber: number, behavior?: ScrollBehavior): void;
|
|
94
|
-
calculateDimensions(pdfPageObject: PdfPageObject[][]): void;
|
|
95
|
-
}
|
|
96
|
-
interface ScrollPluginConfig extends BasePluginConfig {
|
|
97
|
-
strategy?: ScrollStrategy;
|
|
98
|
-
initialPage?: number;
|
|
99
|
-
bufferSize?: number;
|
|
100
|
-
pageGap?: number;
|
|
101
|
-
}
|
|
102
|
-
type LayoutChangePayload = Pick<ScrollState, 'virtualItems' | 'totalContentSize'>;
|
|
103
|
-
interface ScrollToPageOptions {
|
|
104
|
-
pageNumber: number;
|
|
105
|
-
pageCoordinates?: {
|
|
106
|
-
x: number;
|
|
107
|
-
y: number;
|
|
108
|
-
};
|
|
109
|
-
behavior?: ScrollBehavior;
|
|
110
|
-
center?: boolean;
|
|
111
|
-
}
|
|
112
|
-
interface PageChangePayload {
|
|
113
|
-
pageNumber: number;
|
|
114
|
-
totalPages: number;
|
|
115
|
-
}
|
|
116
|
-
interface ScrollCapability {
|
|
117
|
-
onScrollerData: EventHook<ScrollerLayout>;
|
|
118
|
-
onStateChange: EventHook<ScrollState>;
|
|
119
|
-
onScroll: EventHook<ScrollMetrics>;
|
|
120
|
-
getCurrentPage(): number;
|
|
121
|
-
getTotalPages(): number;
|
|
122
|
-
onPageChange: EventHook<PageChangePayload>;
|
|
123
|
-
onLayoutChange: EventHook<LayoutChangePayload>;
|
|
124
|
-
onLayoutReady: EventHook<boolean>;
|
|
125
|
-
scrollToPage(options: ScrollToPageOptions): void;
|
|
126
|
-
scrollToNextPage(behavior?: ScrollBehavior): void;
|
|
127
|
-
scrollToPreviousPage(behavior?: ScrollBehavior): void;
|
|
128
|
-
getMetrics(viewport?: ViewportMetrics): ScrollMetrics;
|
|
129
|
-
getLayout(): LayoutChangePayload;
|
|
130
|
-
getScrollerLayout(): ScrollerLayout;
|
|
131
|
-
getRectPositionForPage(page: number, rect: Rect, scale?: number, rotation?: Rotation): Rect | null;
|
|
132
|
-
setScrollStrategy(strategy: ScrollStrategy): void;
|
|
133
|
-
getPageGap(): number;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
declare const UPDATE_SCROLL_STATE = "UPDATE_SCROLL_STATE";
|
|
137
|
-
declare const SET_DESIRED_SCROLL_POSITION = "SET_DESIRED_SCROLL_POSITION";
|
|
138
|
-
declare const UPDATE_TOTAL_PAGES = "UPDATE_TOTAL_PAGES";
|
|
139
|
-
interface UpdateScrollStateAction extends Action {
|
|
140
|
-
type: typeof UPDATE_SCROLL_STATE;
|
|
141
|
-
payload: Partial<ScrollState>;
|
|
142
|
-
}
|
|
143
|
-
interface SetDesiredScrollPositionAction extends Action {
|
|
144
|
-
type: typeof SET_DESIRED_SCROLL_POSITION;
|
|
145
|
-
payload: {
|
|
146
|
-
x: number;
|
|
147
|
-
y: number;
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
interface UpdateTotalPagesAction extends Action {
|
|
151
|
-
type: typeof UPDATE_TOTAL_PAGES;
|
|
152
|
-
payload: number;
|
|
153
|
-
}
|
|
154
|
-
type ScrollAction = UpdateScrollStateAction | SetDesiredScrollPositionAction | UpdateTotalPagesAction;
|
|
155
|
-
|
|
156
|
-
declare class ScrollPlugin extends BasePlugin<ScrollPluginConfig, ScrollCapability, ScrollState, ScrollAction> {
|
|
157
|
-
readonly id: string;
|
|
158
|
-
private config?;
|
|
159
|
-
static readonly id: "scroll";
|
|
160
|
-
private viewport;
|
|
161
|
-
private strategy;
|
|
162
|
-
private strategyConfig;
|
|
163
|
-
private currentScale;
|
|
164
|
-
private currentRotation;
|
|
165
|
-
private initialPage?;
|
|
166
|
-
private currentPage;
|
|
167
|
-
private layoutReady;
|
|
168
|
-
private readonly layout$;
|
|
169
|
-
private readonly scroll$;
|
|
170
|
-
private readonly state$;
|
|
171
|
-
private readonly scrollerLayout$;
|
|
172
|
-
private readonly pageChange$;
|
|
173
|
-
private readonly layoutReady$;
|
|
174
|
-
constructor(id: string, registry: PluginRegistry, config?: ScrollPluginConfig | undefined);
|
|
175
|
-
private computeLayout;
|
|
176
|
-
private computeMetrics;
|
|
177
|
-
private commit;
|
|
178
|
-
private commitMetrics;
|
|
179
|
-
private refreshAll;
|
|
180
|
-
private getVirtualItemsFromState;
|
|
181
|
-
private getScrollerLayoutFromState;
|
|
182
|
-
private pushScrollLayout;
|
|
183
|
-
onStoreUpdated(_prevState: ScrollState, _newState: ScrollState): void;
|
|
184
|
-
onCoreStoreUpdated(prevState: StoreState<CoreState>, newState: StoreState<CoreState>): void;
|
|
185
|
-
/**
|
|
186
|
-
* Change the scroll strategy at runtime (e.g., vertical <-> horizontal)
|
|
187
|
-
* @param newStrategy ScrollStrategy.Horizontal or ScrollStrategy.Vertical
|
|
188
|
-
*/
|
|
189
|
-
private setScrollStrategy;
|
|
190
|
-
setLayoutReady(): void;
|
|
191
|
-
protected buildCapability(): ScrollCapability;
|
|
192
|
-
private getMetrics;
|
|
193
|
-
private getLayout;
|
|
194
|
-
private getRectPositionForPage;
|
|
195
|
-
initialize(): Promise<void>;
|
|
196
|
-
destroy(): Promise<void>;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
declare const SCROLL_PLUGIN_ID = "scroll";
|
|
200
|
-
declare const manifest: PluginManifest<ScrollPluginConfig>;
|
|
201
|
-
|
|
202
|
-
declare const ScrollPluginPackage: PluginPackage<ScrollPlugin, ScrollPluginConfig, ScrollState, ScrollAction>;
|
|
203
|
-
|
|
204
|
-
export { type LayoutChangePayload, type PageChangePayload, type PageLayout, type PageVisibilityMetrics, SCROLL_PLUGIN_ID, type ScrollCapability, type ScrollMetrics, ScrollPlugin, type ScrollPluginConfig, ScrollPluginPackage, type ScrollState, ScrollStrategy, type ScrollStrategyInterface, type ScrollToPageOptions, type ScrollerLayout, type VirtualItem, manifest };
|
|
1
|
+
export * from './lib';
|
package/dist/index.js
CHANGED
|
@@ -1,30 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
BasePlugin,
|
|
4
|
-
SET_DOCUMENT,
|
|
5
|
-
SET_PAGES,
|
|
6
|
-
SET_ROTATION,
|
|
7
|
-
createBehaviorEmitter,
|
|
8
|
-
getPagesWithRotatedSize
|
|
9
|
-
} from "@embedpdf/core";
|
|
10
|
-
import {
|
|
11
|
-
Rotation as Rotation2
|
|
12
|
-
} from "@embedpdf/models";
|
|
13
|
-
|
|
14
|
-
// src/lib/types.ts
|
|
1
|
+
import { BasePlugin, createBehaviorEmitter, SET_DOCUMENT, getPagesWithRotatedSize, SET_ROTATION, SET_PAGES, SET_SCALE } from "@embedpdf/core";
|
|
2
|
+
import { scalePosition, transformPosition, transformRect, Rotation } from "@embedpdf/models";
|
|
15
3
|
var ScrollStrategy = /* @__PURE__ */ ((ScrollStrategy2) => {
|
|
16
4
|
ScrollStrategy2["Vertical"] = "vertical";
|
|
17
5
|
ScrollStrategy2["Horizontal"] = "horizontal";
|
|
18
6
|
return ScrollStrategy2;
|
|
19
7
|
})(ScrollStrategy || {});
|
|
20
|
-
|
|
21
|
-
// src/lib/strategies/base-strategy.ts
|
|
22
|
-
import {
|
|
23
|
-
scalePosition,
|
|
24
|
-
transformPosition,
|
|
25
|
-
transformRect
|
|
26
|
-
} from "@embedpdf/models";
|
|
27
|
-
var BaseScrollStrategy = class {
|
|
8
|
+
class BaseScrollStrategy {
|
|
28
9
|
constructor(config) {
|
|
29
10
|
this.pageGap = config.pageGap ?? 20;
|
|
30
11
|
this.viewportGap = config.viewportGap ?? 20;
|
|
@@ -189,10 +170,8 @@ var BaseScrollStrategy = class {
|
|
|
189
170
|
size: rotatedSize.size
|
|
190
171
|
};
|
|
191
172
|
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// src/lib/strategies/vertical-strategy.ts
|
|
195
|
-
var VerticalScrollStrategy = class extends BaseScrollStrategy {
|
|
173
|
+
}
|
|
174
|
+
class VerticalScrollStrategy extends BaseScrollStrategy {
|
|
196
175
|
constructor(config) {
|
|
197
176
|
super(config);
|
|
198
177
|
}
|
|
@@ -249,10 +228,8 @@ var VerticalScrollStrategy = class extends BaseScrollStrategy {
|
|
|
249
228
|
getClientSize(viewport) {
|
|
250
229
|
return viewport.clientHeight;
|
|
251
230
|
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// src/lib/strategies/horizontal-strategy.ts
|
|
255
|
-
var HorizontalScrollStrategy = class extends BaseScrollStrategy {
|
|
231
|
+
}
|
|
232
|
+
class HorizontalScrollStrategy extends BaseScrollStrategy {
|
|
256
233
|
constructor(config) {
|
|
257
234
|
super(config);
|
|
258
235
|
}
|
|
@@ -309,21 +286,17 @@ var HorizontalScrollStrategy = class extends BaseScrollStrategy {
|
|
|
309
286
|
getClientSize(viewport) {
|
|
310
287
|
return viewport.clientWidth;
|
|
311
288
|
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
var SET_DESIRED_SCROLL_POSITION = "SET_DESIRED_SCROLL_POSITION";
|
|
317
|
-
var UPDATE_TOTAL_PAGES = "UPDATE_TOTAL_PAGES";
|
|
289
|
+
}
|
|
290
|
+
const UPDATE_SCROLL_STATE = "UPDATE_SCROLL_STATE";
|
|
291
|
+
const SET_DESIRED_SCROLL_POSITION = "SET_DESIRED_SCROLL_POSITION";
|
|
292
|
+
const UPDATE_TOTAL_PAGES = "UPDATE_TOTAL_PAGES";
|
|
318
293
|
function updateScrollState(payload) {
|
|
319
294
|
return { type: UPDATE_SCROLL_STATE, payload };
|
|
320
295
|
}
|
|
321
296
|
function updateTotalPages(payload) {
|
|
322
297
|
return { type: UPDATE_TOTAL_PAGES, payload };
|
|
323
298
|
}
|
|
324
|
-
|
|
325
|
-
// src/lib/selectors.ts
|
|
326
|
-
var getScrollerLayout = (state, scale) => {
|
|
299
|
+
const getScrollerLayout = (state, scale) => {
|
|
327
300
|
return {
|
|
328
301
|
startSpacing: state.startSpacing,
|
|
329
302
|
endSpacing: state.endSpacing,
|
|
@@ -347,15 +320,14 @@ var getScrollerLayout = (state, scale) => {
|
|
|
347
320
|
})
|
|
348
321
|
};
|
|
349
322
|
};
|
|
350
|
-
|
|
351
|
-
// src/lib/scroll-plugin.ts
|
|
352
|
-
var ScrollPlugin = class extends BasePlugin {
|
|
323
|
+
const _ScrollPlugin = class _ScrollPlugin extends BasePlugin {
|
|
353
324
|
constructor(id, registry, config) {
|
|
325
|
+
var _a, _b, _c, _d;
|
|
354
326
|
super(id, registry);
|
|
355
327
|
this.id = id;
|
|
356
328
|
this.config = config;
|
|
357
329
|
this.currentScale = 1;
|
|
358
|
-
this.currentRotation =
|
|
330
|
+
this.currentRotation = Rotation.Degree0;
|
|
359
331
|
this.currentPage = 1;
|
|
360
332
|
this.layoutReady = false;
|
|
361
333
|
this.layout$ = createBehaviorEmitter();
|
|
@@ -366,12 +338,12 @@ var ScrollPlugin = class extends BasePlugin {
|
|
|
366
338
|
this.layoutReady$ = createBehaviorEmitter();
|
|
367
339
|
this.viewport = this.registry.getPlugin("viewport").provides();
|
|
368
340
|
this.strategyConfig = {
|
|
369
|
-
pageGap: this.config
|
|
341
|
+
pageGap: ((_a = this.config) == null ? void 0 : _a.pageGap) ?? 10,
|
|
370
342
|
viewportGap: this.viewport.getViewportGap(),
|
|
371
|
-
bufferSize: this.config
|
|
343
|
+
bufferSize: ((_b = this.config) == null ? void 0 : _b.bufferSize) ?? 2
|
|
372
344
|
};
|
|
373
|
-
this.strategy = this.config
|
|
374
|
-
this.initialPage = this.config
|
|
345
|
+
this.strategy = ((_c = this.config) == null ? void 0 : _c.strategy) === ScrollStrategy.Horizontal ? new HorizontalScrollStrategy(this.strategyConfig) : new VerticalScrollStrategy(this.strategyConfig);
|
|
346
|
+
this.initialPage = (_d = this.config) == null ? void 0 : _d.initialPage;
|
|
375
347
|
this.currentScale = this.coreState.core.scale;
|
|
376
348
|
this.currentRotation = this.coreState.core.rotation;
|
|
377
349
|
this.viewport.onViewportChange((vp) => this.commitMetrics(this.computeMetrics(vp)), {
|
|
@@ -409,8 +381,8 @@ var ScrollPlugin = class extends BasePlugin {
|
|
|
409
381
|
/* ------------------------------------------------------------------ */
|
|
410
382
|
commit(stateDelta, emit) {
|
|
411
383
|
this.dispatch(updateScrollState(stateDelta));
|
|
412
|
-
if (emit
|
|
413
|
-
if (emit
|
|
384
|
+
if (emit == null ? void 0 : emit.layout) this.layout$.emit(emit.layout);
|
|
385
|
+
if (emit == null ? void 0 : emit.metrics) {
|
|
414
386
|
this.scroll$.emit(emit.metrics);
|
|
415
387
|
if (emit.metrics.currentPage !== this.currentPage) {
|
|
416
388
|
this.currentPage = emit.metrics.currentPage;
|
|
@@ -456,10 +428,10 @@ var ScrollPlugin = class extends BasePlugin {
|
|
|
456
428
|
* @param newStrategy ScrollStrategy.Horizontal or ScrollStrategy.Vertical
|
|
457
429
|
*/
|
|
458
430
|
setScrollStrategy(newStrategy) {
|
|
459
|
-
if (newStrategy ===
|
|
431
|
+
if (newStrategy === ScrollStrategy.Horizontal && this.strategy instanceof HorizontalScrollStrategy || newStrategy === ScrollStrategy.Vertical && this.strategy instanceof VerticalScrollStrategy) {
|
|
460
432
|
return;
|
|
461
433
|
}
|
|
462
|
-
this.strategy = newStrategy ===
|
|
434
|
+
this.strategy = newStrategy === ScrollStrategy.Horizontal ? new HorizontalScrollStrategy(this.strategyConfig) : new VerticalScrollStrategy(this.strategyConfig);
|
|
463
435
|
this.dispatch(
|
|
464
436
|
updateScrollState({
|
|
465
437
|
strategy: newStrategy
|
|
@@ -573,11 +545,10 @@ var ScrollPlugin = class extends BasePlugin {
|
|
|
573
545
|
super.destroy();
|
|
574
546
|
}
|
|
575
547
|
};
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
var manifest = {
|
|
548
|
+
_ScrollPlugin.id = "scroll";
|
|
549
|
+
let ScrollPlugin = _ScrollPlugin;
|
|
550
|
+
const SCROLL_PLUGIN_ID = "scroll";
|
|
551
|
+
const manifest = {
|
|
581
552
|
id: SCROLL_PLUGIN_ID,
|
|
582
553
|
name: "Scroll Plugin",
|
|
583
554
|
version: "1.0.0",
|
|
@@ -589,10 +560,7 @@ var manifest = {
|
|
|
589
560
|
pageGap: 10
|
|
590
561
|
}
|
|
591
562
|
};
|
|
592
|
-
|
|
593
|
-
// src/lib/reducer.ts
|
|
594
|
-
import { SET_SCALE } from "@embedpdf/core";
|
|
595
|
-
var defaultScrollMetrics = {
|
|
563
|
+
const defaultScrollMetrics = {
|
|
596
564
|
currentPage: 1,
|
|
597
565
|
visiblePages: [],
|
|
598
566
|
pageVisibilityMetrics: [],
|
|
@@ -601,17 +569,17 @@ var defaultScrollMetrics = {
|
|
|
601
569
|
startSpacing: 0,
|
|
602
570
|
endSpacing: 0
|
|
603
571
|
};
|
|
604
|
-
|
|
572
|
+
const initialState = (coreState, config) => ({
|
|
605
573
|
virtualItems: [],
|
|
606
574
|
totalPages: coreState.pages.length,
|
|
607
575
|
totalContentSize: { width: 0, height: 0 },
|
|
608
576
|
desiredScrollPosition: { x: 0, y: 0 },
|
|
609
|
-
strategy: config.strategy ??
|
|
577
|
+
strategy: config.strategy ?? ScrollStrategy.Vertical,
|
|
610
578
|
pageGap: config.pageGap ?? 10,
|
|
611
579
|
scale: coreState.scale,
|
|
612
580
|
...defaultScrollMetrics
|
|
613
581
|
});
|
|
614
|
-
|
|
582
|
+
const scrollReducer = (state, action) => {
|
|
615
583
|
switch (action.type) {
|
|
616
584
|
case UPDATE_TOTAL_PAGES:
|
|
617
585
|
return { ...state, totalPages: action.payload };
|
|
@@ -625,9 +593,7 @@ var scrollReducer = (state, action) => {
|
|
|
625
593
|
return state;
|
|
626
594
|
}
|
|
627
595
|
};
|
|
628
|
-
|
|
629
|
-
// src/lib/index.ts
|
|
630
|
-
var ScrollPluginPackage = {
|
|
596
|
+
const ScrollPluginPackage = {
|
|
631
597
|
manifest,
|
|
632
598
|
create: (registry, _engine, config) => new ScrollPlugin(SCROLL_PLUGIN_ID, registry, config),
|
|
633
599
|
reducer: scrollReducer,
|
|
@@ -640,4 +606,4 @@ export {
|
|
|
640
606
|
ScrollStrategy,
|
|
641
607
|
manifest
|
|
642
608
|
};
|
|
643
|
-
//# sourceMappingURL=index.js.map
|
|
609
|
+
//# sourceMappingURL=index.js.map
|