teamsync-pdf-viewer 1.3.1 → 1.3.3

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/CHANGELOG.md CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  All notable changes to `teamsync-pdf-viewer` are documented here.
4
4
 
5
+ ## [1.3.3] — 2026-09-04
6
+
7
+ ### Fixed
8
+ - **Initial Programmatic Fit Scroll Compensation**: Fixed view jump on initial fit where scaling from seed 1.0 to ~2.27 at `scrollTop = 0` triggered viewport center compensation and hid page 1's top. Added `calculateScrollCompensation` with programmatic fit bypass and top-of-document boundary guard.
9
+ - **Capped Canvas Output Scale**: Capped `outputScale = Math.min(window.devicePixelRatio || 1, 2)` in `PageRenderer` and `LeftSidebar`, reducing GPU canvas raster memory and repaint strain on 3x+ Retina and mobile displays by over 55% while preserving 2x sharpness.
10
+ - **Scroll Shaking & Up-Front Dimension Reservation**: Replaced asynchronous sequential dimension streaming with up-front dimension measurement and space pre-allocation (`estimatePageDimensions`). Full scroll container height and row tops are reserved on the first frame, eliminating layout recalculations and page shifting/shaking during scrolling.
11
+ - **Exported Layout & Zoom Utilities**: Exported `calculateScrollCompensation`, `estimatePageDimensions`, `computeRowLayout`, `DEFAULT_FALLBACK_DIMS`, and related types from the package root.
12
+
13
+ ## [1.3.2] — 2026-09-04
14
+
15
+ ### Fixed
16
+ - **Hardware-Bounded Canvas Texture Clamping**: Fixed crash and invisible content when zooming past 800% (up to 1000%) by clamping internal raster buffers to safe hardware limits (`MAX_CANVAS_DIM` = 4096 / 8192 px, `MAX_CANVAS_PIXELS` = 16.7 MP / ~64MB buffer) while keeping CSS layout full-sized for smooth, distortion-free GPU scaling.
17
+ - **In-Flight Render Task Cancellation**: Resolved UI freezing and crashes during rapid clicking of `+` / `-` zoom buttons by cancelling running PDF.js render tasks directly by reference and releasing completed/cancelled page resources (`page.cleanup()`).
18
+ - **Immediate GPU Texture Deallocation**: Zeroed offscreen `tempCanvas` dimensions immediately after raster blitting to return GPU backing texture memory to the system without waiting for garbage collection.
19
+ - **Zoom Gesture Debouncing**: Added 150ms debounce on zoom changes to allow existing textures to scale at 60fps via CSS transforms before triggering expensive PDF.js vector rasterization upon motion settling.
20
+ - **Eliminated False Cache Invalidation in `React.memo`**: Removed stale `scrollTop` / `scrollLeft` checks in `PageRenderer`, preventing re-rendering of all mounted pages on every scroll and zoom frame.
21
+ - **Scale-Aware Virtualization Window**: Virtualized document rows dynamically based on zoom scale, keeping mounted pages to a maximum of 3 at high zoom levels.
22
+ - **Intuitive Zoom Stepping Curves & Controls**: Implemented responsive stepping curves (+0.25 under 2x, +0.5 under 5x, +1.0 above 5x), capped max zoom at 1000% (`MAX_SCALE = 10.0`), and disabled `+` / `-` toolbar buttons at boundary limits. Exported `MIN_SCALE`, `MAX_SCALE`, `clampScale`, `calculateNextZoomIn`, and `calculateNextZoomOut`.
23
+
5
24
  ## [1.3.1] — 2026-09-04
6
25
 
7
26
  ### Fixed
@@ -31,4 +31,8 @@ export type { PrintOptions } from './core/print';
31
31
  export { usePdfSearch, searchPdfText } from './hooks/usePdfSearch';
32
32
  export type { SearchResult, SearchBounds } from './hooks/usePdfSearch';
33
33
  export type { TransientHighlight } from './core/types';
34
+ export { MIN_SCALE, MAX_SCALE, clampScale, calculateNextZoomIn, calculateNextZoomOut, calculateScrollCompensation } from './utils/zoomUtils';
35
+ export type { ScrollCompensationParams, ScrollPosition } from './utils/zoomUtils';
36
+ export { estimatePageDimensions, computeRowLayout, DEFAULT_FALLBACK_DIMS, hasDimensionMismatch } from './utils/layoutUtils';
37
+ export type { PageDimension, RowLayout } from './utils/layoutUtils';
34
38
  export * from './plugins/types';
@@ -0,0 +1,28 @@
1
+ /**
2
+ * © 2026 AngelBot Ai Pvt Ltd. All rights reserved.
3
+ */
4
+ export interface PageDimension {
5
+ width: number;
6
+ height: number;
7
+ }
8
+ export interface RowLayout {
9
+ heights: number[];
10
+ tops: number[];
11
+ total: number;
12
+ }
13
+ /** Standard US Letter dimensions in PDF points (72 points/inch: 8.5 x 11 inches). */
14
+ export declare const DEFAULT_FALLBACK_DIMS: PageDimension;
15
+ /**
16
+ * Pre-allocates an array of page dimensions for the entire document up front,
17
+ * reserving estimated space based on a sample page (e.g. Page 1).
18
+ */
19
+ export declare function estimatePageDimensions(numPages: number, sampleDim?: PageDimension): PageDimension[];
20
+ /**
21
+ * Computes row heights, vertical tops, and total container scroll height
22
+ * for given rows of pages and scale.
23
+ */
24
+ export declare function computeRowLayout(rows: number[][], dimsFor: (page: number) => PageDimension, scale: number, gap?: number): RowLayout;
25
+ /**
26
+ * Checks if any page dimension in array A differs from array B beyond a tolerance.
27
+ */
28
+ export declare function hasDimensionMismatch(dimsA: PageDimension[], dimsB: PageDimension[], tolerance?: number): boolean;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * © 2026 AngelBot Ai Pvt Ltd. All rights reserved.
3
+ */
4
+ export declare const MIN_SCALE = 0.1;
5
+ export declare const MAX_SCALE = 10;
6
+ export declare const isSafariOrMobile: () => boolean;
7
+ export declare const MAX_CANVAS_DIM = 8192;
8
+ export declare const MAX_CANVAS_DIM_MOBILE = 4096;
9
+ export declare const MAX_CANVAS_PIXELS = 16777216;
10
+ /**
11
+ * Calculates the next step when zooming in.
12
+ * - Below 200%: steps by +25%
13
+ * - 200% to 500%: steps by +50%
14
+ * - 500% to 1000%: steps by +100%
15
+ */
16
+ export declare function calculateNextZoomIn(currentScale: number, maxScale?: number): number;
17
+ /**
18
+ * Calculates the next step when zooming out.
19
+ * - At or below 200%: steps by -25%
20
+ * - 200% to 500%: steps by -50%
21
+ * - Above 500%: steps by -100%
22
+ */
23
+ export declare function calculateNextZoomOut(currentScale: number, minScale?: number): number;
24
+ /**
25
+ * Clamps and rounds a requested zoom level within [minScale, maxScale].
26
+ */
27
+ export declare function clampScale(scale: number, minScale?: number, maxScale?: number): number;
28
+ /**
29
+ * Calculates the safe rasterization scale for PDF.js viewport rendering so that
30
+ * canvas dimensions and texture memory stay strictly within hardware limits.
31
+ */
32
+ export declare function calculateSafeRenderScale(scale: number, outputScale: number, unscaledWidth: number, unscaledHeight: number, maxDim?: number, maxPixels?: number): number;
33
+ export interface ScrollCompensationParams {
34
+ prevScale: number;
35
+ newScale: number;
36
+ containerWidth: number;
37
+ containerHeight: number;
38
+ currentScrollLeft: number;
39
+ currentScrollTop: number;
40
+ basePageWidth: number;
41
+ focusPoint?: {
42
+ vx: number | null;
43
+ vy: number | null;
44
+ } | null;
45
+ isProgrammatic?: boolean;
46
+ }
47
+ export interface ScrollPosition {
48
+ scrollLeft: number;
49
+ scrollTop: number;
50
+ }
51
+ /**
52
+ * Calculates compensating scroll offsets during scale changes.
53
+ * Prevents view jumping or pushing page 1 down on initial fit or programmatic fit.
54
+ */
55
+ export declare function calculateScrollCompensation(params: ScrollCompensationParams): ScrollPosition;