@vue-pdf-viewer/viewer 3.5.2-rc.0 → 3.6.0-beta.0
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-DlHKq5TV.js → index-CecDeME3.js} +9571 -9373
- package/dist/{index-Bmyx_SBq.js → index-DZ3U5WMt.js} +1 -1
- package/dist/index.js +2 -2
- package/dist/index.umd.cjs +39 -39
- package/dist/types/components/LayerCanvas.vue.d.ts +2 -3
- package/dist/types/components/LayerCanvasDetail.vue.d.ts +23 -0
- package/dist/types/components/ToolZoom.vue.d.ts +0 -4
- package/dist/types/components/ToolZoomPercentageMenu.vue.d.ts +0 -3
- package/dist/types/components/VPdfPage.vue.d.ts +7 -6
- package/dist/types/components/VPdfViewer.vue.d.ts +12 -3
- package/dist/types/components/utils/helpers.d.ts +0 -1
- package/dist/types/composables/usePdfActualPages.d.ts +21 -0
- package/dist/types/composables/usePdfCanvas.d.ts +13 -0
- package/dist/types/composables/usePinch.d.ts +4 -1
- package/dist/types/composables/useRenderQueue.d.ts +5 -1
- package/dist/types/composables/useScale.d.ts +17 -5
- package/dist/types/composables/useVirtualPages.d.ts +35 -4
- package/dist/types/const.d.ts +10 -1
- package/dist/types/utils/CanvasRender.d.ts +113 -0
- package/dist/types/utils/scaleUtils.d.ts +154 -0
- package/dist/types/utils/types.d.ts +36 -7
- package/dist/types/utils.d.ts +12 -0
- package/package.json +1 -1
- package/dist/types/composables/usePdfPagesSizes.d.ts +0 -8
- package/dist/types/composables/useVisibilities.d.ts +0 -9
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { PDFPageProxy } from 'pdfjs-dist';
|
|
2
|
-
import type { CanvasLoadedCallback } from '@/utils/types';
|
|
2
|
+
import type { CanvasLoadedCallback, VisibleArea } from '@/utils/types';
|
|
3
3
|
interface OwnProps {
|
|
4
4
|
page: PDFPageProxy;
|
|
5
|
-
width: number;
|
|
6
|
-
height: number;
|
|
7
5
|
pageIndex: number;
|
|
8
6
|
intersecting: boolean;
|
|
9
7
|
afterCanvasLoaded?: CanvasLoadedCallback;
|
|
8
|
+
visibleArea?: VisibleArea;
|
|
10
9
|
}
|
|
11
10
|
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<OwnProps>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
12
11
|
rendered: (canvasWrapperElement: HTMLDivElement) => void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { PDFPageProxy } from 'pdfjs-dist';
|
|
2
|
+
import type { VisibleArea } from '@/utils/types';
|
|
3
|
+
interface OwnProps {
|
|
4
|
+
page: PDFPageProxy;
|
|
5
|
+
pageIndex: number;
|
|
6
|
+
visibleArea: VisibleArea;
|
|
7
|
+
viewport: any;
|
|
8
|
+
maxCanvasPixels: number;
|
|
9
|
+
capAreaFactor: number;
|
|
10
|
+
queueRenderTask: any;
|
|
11
|
+
annotationMode: number;
|
|
12
|
+
}
|
|
13
|
+
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<OwnProps>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<OwnProps>>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
14
|
+
export default _default;
|
|
15
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
16
|
+
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
17
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
18
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
19
|
+
} : {
|
|
20
|
+
type: import('vue').PropType<T[K]>;
|
|
21
|
+
required: true;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { ViewerPdfPage } from '../utils/types';
|
|
2
1
|
import { ZoomLevel } from '@/utils/enumerators';
|
|
3
2
|
declare const _default: {
|
|
4
3
|
new (...args: any[]): import("vue").CreateComponentPublicInstanceWithMixins<Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
|
|
5
4
|
scale: number;
|
|
6
|
-
focusedPage?: Omit<ViewerPdfPage, "page"> | undefined;
|
|
7
5
|
pagesContainer?: HTMLDivElement | undefined;
|
|
8
6
|
}>>> & Readonly<{
|
|
9
7
|
onZoom?: ((nextScale: number | ZoomLevel) => any) | undefined;
|
|
@@ -18,7 +16,6 @@ declare const _default: {
|
|
|
18
16
|
Defaults: {};
|
|
19
17
|
}, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
|
|
20
18
|
scale: number;
|
|
21
|
-
focusedPage?: Omit<ViewerPdfPage, "page"> | undefined;
|
|
22
19
|
pagesContainer?: HTMLDivElement | undefined;
|
|
23
20
|
}>>> & Readonly<{
|
|
24
21
|
onZoom?: ((nextScale: number | ZoomLevel) => any) | undefined;
|
|
@@ -28,7 +25,6 @@ declare const _default: {
|
|
|
28
25
|
__isSuspense?: undefined;
|
|
29
26
|
} & import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
|
|
30
27
|
scale: number;
|
|
31
|
-
focusedPage?: Omit<ViewerPdfPage, "page"> | undefined;
|
|
32
28
|
pagesContainer?: HTMLDivElement | undefined;
|
|
33
29
|
}>>> & Readonly<{
|
|
34
30
|
onZoom?: ((nextScale: number | ZoomLevel) => any) | undefined;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { ViewerPdfPage } from '../utils/types';
|
|
2
1
|
import { ZoomLevel } from '@/utils/enumerators';
|
|
3
2
|
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
|
|
4
3
|
currentPercentage: string;
|
|
5
|
-
currentPage?: Omit<ViewerPdfPage, "page"> | undefined;
|
|
6
4
|
container?: HTMLDivElement | undefined;
|
|
7
5
|
}>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
8
6
|
select: (scale: number | ZoomLevel) => void;
|
|
9
7
|
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
|
|
10
8
|
currentPercentage: string;
|
|
11
|
-
currentPage?: Omit<ViewerPdfPage, "page"> | undefined;
|
|
12
9
|
container?: HTMLDivElement | undefined;
|
|
13
10
|
}>>> & Readonly<{
|
|
14
11
|
onSelect?: ((scale: number | ZoomLevel) => any) | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PageViewport, PDFPageProxy } from 'pdfjs-dist/types/web/interfaces';
|
|
2
2
|
import type { PDFDocumentProxy } from 'pdfjs-dist';
|
|
3
|
-
import type { CanvasLoadedCallback, AnnotationEventPayload, HighlightEventPayload, HighlightOptions, MatchValue, TextLayerLoadedEventPayload,
|
|
3
|
+
import type { CanvasLoadedCallback, AnnotationEventPayload, HighlightEventPayload, HighlightOptions, MatchValue, TextLayerLoadedEventPayload, TextHighlight, CanvasRenderedEventPayload, VisibleArea } from '../utils/types';
|
|
4
4
|
interface BaseProps {
|
|
5
5
|
pageIndex: number;
|
|
6
6
|
page: PDFPageProxy;
|
|
@@ -8,6 +8,7 @@ interface BaseProps {
|
|
|
8
8
|
document: PDFDocumentProxy;
|
|
9
9
|
afterCanvasLoaded?: CanvasLoadedCallback;
|
|
10
10
|
annoImageResourcesPath?: string;
|
|
11
|
+
visibleArea?: VisibleArea;
|
|
11
12
|
}
|
|
12
13
|
type TextProps = {
|
|
13
14
|
initialTextLayer: boolean;
|
|
@@ -23,7 +24,7 @@ declare const _default: {
|
|
|
23
24
|
onHighlight?: ((payload: HighlightEventPayload) => any) | undefined;
|
|
24
25
|
onTextLoaded?: ((payload: TextLayerLoadedEventPayload) => any) | undefined;
|
|
25
26
|
onAnnotated?: ((payload: AnnotationEventPayload) => any) | undefined;
|
|
26
|
-
|
|
27
|
+
onCanvasRendered?: ((payload: CanvasRenderedEventPayload) => any) | undefined;
|
|
27
28
|
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
28
29
|
highlight: (payload: HighlightEventPayload) => void;
|
|
29
30
|
} & {
|
|
@@ -31,7 +32,7 @@ declare const _default: {
|
|
|
31
32
|
} & {
|
|
32
33
|
annotated: (payload: AnnotationEventPayload) => void;
|
|
33
34
|
} & {
|
|
34
|
-
|
|
35
|
+
canvasRendered: (payload: CanvasRenderedEventPayload) => void;
|
|
35
36
|
}, import("vue").PublicProps, {}, true, {}, {}, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, {}, any, import("vue").ComponentProvideOptions, {
|
|
36
37
|
P: {};
|
|
37
38
|
B: {};
|
|
@@ -43,7 +44,7 @@ declare const _default: {
|
|
|
43
44
|
onHighlight?: ((payload: HighlightEventPayload) => any) | undefined;
|
|
44
45
|
onTextLoaded?: ((payload: TextLayerLoadedEventPayload) => any) | undefined;
|
|
45
46
|
onAnnotated?: ((payload: AnnotationEventPayload) => any) | undefined;
|
|
46
|
-
|
|
47
|
+
onCanvasRendered?: ((payload: CanvasRenderedEventPayload) => any) | undefined;
|
|
47
48
|
}>, {}, {}, {}, {}, {}>;
|
|
48
49
|
__isFragment?: undefined;
|
|
49
50
|
__isTeleport?: undefined;
|
|
@@ -52,7 +53,7 @@ declare const _default: {
|
|
|
52
53
|
onHighlight?: ((payload: HighlightEventPayload) => any) | undefined;
|
|
53
54
|
onTextLoaded?: ((payload: TextLayerLoadedEventPayload) => any) | undefined;
|
|
54
55
|
onAnnotated?: ((payload: AnnotationEventPayload) => any) | undefined;
|
|
55
|
-
|
|
56
|
+
onCanvasRendered?: ((payload: CanvasRenderedEventPayload) => any) | undefined;
|
|
56
57
|
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
57
58
|
highlight: (payload: HighlightEventPayload) => void;
|
|
58
59
|
} & {
|
|
@@ -60,7 +61,7 @@ declare const _default: {
|
|
|
60
61
|
} & {
|
|
61
62
|
annotated: (payload: AnnotationEventPayload) => void;
|
|
62
63
|
} & {
|
|
63
|
-
|
|
64
|
+
canvasRendered: (payload: CanvasRenderedEventPayload) => void;
|
|
64
65
|
}, string, {}, {}, string, {}, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, import("vue").ComponentProvideOptions> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
|
|
65
66
|
$slots: {
|
|
66
67
|
pageOverlay: (_: {
|
|
@@ -148,7 +148,10 @@ declare const _default: {
|
|
|
148
148
|
};
|
|
149
149
|
zoomControl: {
|
|
150
150
|
scale: number;
|
|
151
|
-
zoom: (scale: number | ZoomLevel
|
|
151
|
+
zoom: (scale: number | ZoomLevel, options?: {
|
|
152
|
+
immediate?: boolean | undefined;
|
|
153
|
+
origin?: [number, number] | undefined;
|
|
154
|
+
} | undefined) => void;
|
|
152
155
|
};
|
|
153
156
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
154
157
|
annotation: (data: AnnotationEventPayload) => void;
|
|
@@ -344,7 +347,10 @@ declare const _default: {
|
|
|
344
347
|
};
|
|
345
348
|
zoomControl: {
|
|
346
349
|
scale: number;
|
|
347
|
-
zoom: (scale: number | ZoomLevel
|
|
350
|
+
zoom: (scale: number | ZoomLevel, options?: {
|
|
351
|
+
immediate?: boolean | undefined;
|
|
352
|
+
origin?: [number, number] | undefined;
|
|
353
|
+
} | undefined) => void;
|
|
348
354
|
};
|
|
349
355
|
}, {}, {}, {}, {
|
|
350
356
|
readonly initialViewMode: ViewMode;
|
|
@@ -513,7 +519,10 @@ declare const _default: {
|
|
|
513
519
|
};
|
|
514
520
|
zoomControl: {
|
|
515
521
|
scale: number;
|
|
516
|
-
zoom: (scale: number | ZoomLevel
|
|
522
|
+
zoom: (scale: number | ZoomLevel, options?: {
|
|
523
|
+
immediate?: boolean | undefined;
|
|
524
|
+
origin?: [number, number] | undefined;
|
|
525
|
+
} | undefined) => void;
|
|
517
526
|
};
|
|
518
527
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
519
528
|
annotation: (data: AnnotationEventPayload) => void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { UnwrapRef } from 'vue';
|
|
2
|
+
import { ViewerPdfPage, ViewerState } from '@/utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* Composable for managing PDF pages at base scale (100%).
|
|
5
|
+
*
|
|
6
|
+
* Returns pages with viewports at scale=1. Components that need the viewport
|
|
7
|
+
* at current scale should use: `page.getViewport({ scale: currentScale, rotation })`
|
|
8
|
+
*
|
|
9
|
+
* This pattern follows pdf.js approach where base viewport is stored and
|
|
10
|
+
* scale is applied at render time.
|
|
11
|
+
*
|
|
12
|
+
* @param props - The viewer state containing PDF document and rotation settings
|
|
13
|
+
* @returns Object containing pdfPages (all pages) and filteredPages (view-mode filtered)
|
|
14
|
+
*/
|
|
15
|
+
declare function usePdfActualPages(props: UnwrapRef<ViewerState>): {
|
|
16
|
+
/** All pages at base scale (100%) */
|
|
17
|
+
pdfPages: import("vue").ShallowRef<ViewerPdfPage[], ViewerPdfPage[]>;
|
|
18
|
+
/** Pages filtered by view mode (for page scroll mode) */
|
|
19
|
+
filteredPages: import("vue").ComputedRef<ViewerPdfPage[]>;
|
|
20
|
+
};
|
|
21
|
+
export default usePdfActualPages;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
export interface UsePdfCanvasReturn {
|
|
3
|
+
renderedPages: Ref<Set<number>>;
|
|
4
|
+
hasPageBeenRendered: (pageIndex: number) => boolean;
|
|
5
|
+
markPageAsRendered: (pageIndex: number) => void;
|
|
6
|
+
clearRenderedPages: () => void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Composable to track canvas rendering state across page component remounts.
|
|
10
|
+
* This prevents loaders from appearing again during zoom/rotation operations
|
|
11
|
+
* when pages are re-rendered.
|
|
12
|
+
*/
|
|
13
|
+
export declare function usePdfCanvas(): UsePdfCanvasReturn;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { Ref } from 'vue';
|
|
2
|
-
declare const usePinch: (container: Ref<HTMLDivElement | undefined>, currentScale: Ref<number | undefined
|
|
2
|
+
declare const usePinch: (container: Ref<HTMLDivElement | undefined>, currentScale: Ref<number | undefined>, zoom?: ((scale: number, options?: {
|
|
3
|
+
immediate?: boolean;
|
|
4
|
+
origin?: [number, number];
|
|
5
|
+
}) => void) | undefined) => void;
|
|
3
6
|
export default usePinch;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { Queue } from '@/utils/Queue';
|
|
2
2
|
import { RenderQueueItem } from '@/utils/types';
|
|
3
3
|
import { MaybeRef } from 'vue';
|
|
4
|
-
export declare const useRenderQueue: (focusedPage: MaybeRef<number>) =>
|
|
4
|
+
export declare const useRenderQueue: (focusedPage: MaybeRef<number>) => {
|
|
5
|
+
queue: Queue<RenderQueueItem>;
|
|
6
|
+
cancelAllRenders: () => void;
|
|
7
|
+
reprioritizeCurrentPage: () => void;
|
|
8
|
+
};
|
|
@@ -6,20 +6,32 @@ interface UseScaleProps {
|
|
|
6
6
|
pdfDocument: ShallowRef<PDFDocumentProxy | undefined>;
|
|
7
7
|
pagesContainerRef: ShallowRef<HTMLDivElement | undefined>;
|
|
8
8
|
viewMode: Ref<ViewMode>;
|
|
9
|
-
initialScale: MaybeRef<number | ZoomLevel>;
|
|
10
9
|
focusedPage: MaybeRef<ViewerPdfPage | undefined>;
|
|
11
|
-
|
|
10
|
+
currentScale: Ref<number>;
|
|
11
|
+
onScaleRequest?: (newScale: number, options?: {
|
|
12
|
+
immediate?: boolean;
|
|
13
|
+
origin?: [number, number];
|
|
14
|
+
}) => Promise<void>;
|
|
12
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Composable for handling zoom operations.
|
|
18
|
+
* Calculates scale for ZoomLevel presets and delegates actual scaling to useVirtualPages.
|
|
19
|
+
*
|
|
20
|
+
* @param props - Scale-related props including PDF document, container, and callbacks
|
|
21
|
+
* @param scaleCallback - Optional callback for external scale change listeners
|
|
22
|
+
*/
|
|
13
23
|
declare const useScale: (props: UnwrapRef<UseScaleProps>, scaleCallback?: ((event: UseScaleCallback) => void) | undefined) => {
|
|
14
24
|
currentScale: Ref<number, number>;
|
|
15
|
-
targetScale: Ref<number, number>;
|
|
16
|
-
isScaling: Ref<boolean, boolean>;
|
|
17
25
|
zoom: (scale: number | ZoomLevel, options?: {
|
|
18
26
|
immediate?: boolean;
|
|
27
|
+
origin?: [number, number];
|
|
19
28
|
}) => void;
|
|
20
29
|
zoomControl: {
|
|
21
30
|
scale: number;
|
|
22
|
-
zoom: (scale: number | ZoomLevel
|
|
31
|
+
zoom: (scale: number | ZoomLevel, options?: {
|
|
32
|
+
immediate?: boolean | undefined;
|
|
33
|
+
origin?: [number, number] | undefined;
|
|
34
|
+
} | undefined) => void;
|
|
23
35
|
};
|
|
24
36
|
};
|
|
25
37
|
export default useScale;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ComputedRef, CSSProperties, Ref, StyleValue, UnwrapRef } from 'vue';
|
|
2
|
-
import type { ViewerPdfPage,
|
|
3
|
-
import { ScrollMode, ViewMode } from '@/utils/enumerators';
|
|
1
|
+
import { ComputedRef, CSSProperties, MaybeRef, Ref, StyleValue, UnwrapRef } from 'vue';
|
|
2
|
+
import type { ViewerPdfPage, ElementRect, VisibleArea } from '@/utils/types';
|
|
3
|
+
import { ScrollMode, ViewMode, ZoomLevel } from '@/utils/enumerators';
|
|
4
|
+
import type { PDFDocumentProxy } from 'pdfjs-dist';
|
|
4
5
|
interface UseVirtualListItem<T> {
|
|
5
6
|
data: T;
|
|
6
7
|
index: number;
|
|
@@ -17,16 +18,46 @@ export interface UseVirtualListReturn {
|
|
|
17
18
|
wrapperProps: ComputedRef<{
|
|
18
19
|
style: CSSProperties;
|
|
19
20
|
}>;
|
|
20
|
-
range: Ref<VirtualRange>;
|
|
21
21
|
pagesPerRow: Ref<number>;
|
|
22
|
+
targetScale: Ref<number>;
|
|
23
|
+
isScaling: Ref<boolean>;
|
|
24
|
+
onScaleRequest: (newScale: number, options?: {
|
|
25
|
+
immediate?: boolean;
|
|
26
|
+
origin?: [number, number];
|
|
27
|
+
}) => Promise<void>;
|
|
28
|
+
pageVisibleAreas: Ref<Map<number, VisibleArea>>;
|
|
29
|
+
currentPageIndex: Ref<number>;
|
|
22
30
|
}
|
|
23
31
|
interface UseVirtualPagesProps {
|
|
24
32
|
pages: Ref<ViewerPdfPage[]>;
|
|
33
|
+
actualPdfPages: Ref<ViewerPdfPage[]>;
|
|
25
34
|
viewerRef: Ref<HTMLElement | undefined>;
|
|
26
35
|
scrollMode: Ref<ScrollMode>;
|
|
27
36
|
viewMode: Ref<ViewMode>;
|
|
28
37
|
isRtl: boolean;
|
|
29
38
|
smoothScroll: Ref<boolean>;
|
|
39
|
+
currentScale: Ref<number>;
|
|
40
|
+
pdfDocument: Ref<PDFDocumentProxy | undefined>;
|
|
41
|
+
initialScale: MaybeRef<number | ZoomLevel>;
|
|
42
|
+
cancelAllRenders?: () => void;
|
|
43
|
+
reprioritizeCurrentPage?: () => void;
|
|
30
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Composable for virtual scrolling of PDF pages with support for multiple view modes.
|
|
47
|
+
*
|
|
48
|
+
* Implements efficient virtual scrolling by only rendering pages in the viewport plus overscan.
|
|
49
|
+
* Supports smooth CSS-based zooming with atomic canvas swapping to prevent flashing.
|
|
50
|
+
*
|
|
51
|
+
* Features:
|
|
52
|
+
* - Virtual scrolling with configurable overscan
|
|
53
|
+
* - Multiple scroll modes: vertical, horizontal, wrapped, page
|
|
54
|
+
* - Multiple view modes: single, dual page, dual page with cover
|
|
55
|
+
* - Smooth zoom with CSS transform bridge and debounced re-render
|
|
56
|
+
* - Maintains scroll position during zoom operations
|
|
57
|
+
* - Dual page grouping for proper layout
|
|
58
|
+
*
|
|
59
|
+
* @param props - Configuration for virtual pages including pages, scroll mode, view mode
|
|
60
|
+
* @returns Virtual list utilities including list, scrollTo, containerProps, wrapperProps, and zoom controls
|
|
61
|
+
*/
|
|
31
62
|
declare function useVirtualPages(props: UnwrapRef<UseVirtualPagesProps>): UseVirtualListReturn;
|
|
32
63
|
export default useVirtualPages;
|
package/dist/types/const.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export declare const DEFAULT_VIEWER_HEIGHT = 768;
|
|
|
33
33
|
export declare const PERCENTAGE = 100;
|
|
34
34
|
export declare const MIN_ZOOM_SCALE = 0.25;
|
|
35
35
|
export declare const MAX_ZOOM_SCALE = 10;
|
|
36
|
+
export declare const DEFAULT_SCALE_DELTA = 1.1;
|
|
36
37
|
export declare const SCROLL_BAR_WIDTH = 20;
|
|
37
38
|
export declare const PAGE_PADDING = 1;
|
|
38
39
|
export declare const PAGE_OFFSET = 0;
|
|
@@ -75,6 +76,10 @@ export declare const VIEWER_STATE: InjectionKey<{
|
|
|
75
76
|
isEditing: boolean;
|
|
76
77
|
updateViewerState: (state: Partial<ViewerState>) => void;
|
|
77
78
|
}>;
|
|
79
|
+
export declare const SCALE_ROUND_VALUES: InjectionKey<ComputedRef<{
|
|
80
|
+
scaleRoundX: string;
|
|
81
|
+
scaleRoundY: string;
|
|
82
|
+
}>>;
|
|
78
83
|
export declare const VIEWER_PAGES_PER_ROW: InjectionKey<Ref<number, number>>;
|
|
79
84
|
export declare const TOOLBAR_OPTIONS: InjectionKey<Ref<ToolbarOptions | undefined, ToolbarOptions | undefined>>;
|
|
80
85
|
export declare const TOTAL_TOOL_OTHERS_MENU: InjectionKey<Ref<number, number>>;
|
|
@@ -397,7 +402,7 @@ export declare const QUEUE_RENDER_TASK: InjectionKey<{
|
|
|
397
402
|
} | undefined;
|
|
398
403
|
isEditing?: boolean | undefined;
|
|
399
404
|
};
|
|
400
|
-
onLoaded?: (() => void) | undefined;
|
|
405
|
+
onLoaded?: ((renderTask: import("pdfjs-dist/types/src/display/api").RenderTask) => void) | undefined;
|
|
401
406
|
onError?: ((error: Error) => void) | undefined;
|
|
402
407
|
onComplete?: (() => void) | undefined;
|
|
403
408
|
};
|
|
@@ -407,6 +412,10 @@ export declare const QUEUE_RENDER_TASK: InjectionKey<{
|
|
|
407
412
|
size: () => number;
|
|
408
413
|
clear: () => void;
|
|
409
414
|
}>;
|
|
415
|
+
export declare const PDF_CANVAS_TRACKER: InjectionKey<{
|
|
416
|
+
hasPageBeenRendered: (pageIndex: number) => boolean;
|
|
417
|
+
markPageAsRendered: (pageIndex: number) => void;
|
|
418
|
+
}>;
|
|
410
419
|
export declare const DEFAULT_VIEWER_STATE: Reactive<ViewerState>;
|
|
411
420
|
export declare const SUPPORTED_IMAGE_MIME_TYPES: readonly ["image/apng", "image/avif", "image/bmp", "image/gif", "image/jpeg", "image/png", "image/svg+xml", "image/webp", "image/x-icon"];
|
|
412
421
|
export declare const PIXELS_PER_INCH: {
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared canvas rendering utilities for LayerCanvas and LayerCanvasDetail.
|
|
3
|
+
* Consolidates common patterns to reduce code duplication and memory usage.
|
|
4
|
+
*
|
|
5
|
+
* Following pdf.js patterns:
|
|
6
|
+
* - Dynamic canvas creation (no template canvases)
|
|
7
|
+
* - Atomic swap with opacity transitions (iOS Safari compositor-friendly)
|
|
8
|
+
* - Immediate cleanup via width=0, height=0 (releases GPU texture)
|
|
9
|
+
* - Lifecycle guards to prevent DOM manipulation after unmount
|
|
10
|
+
*/
|
|
11
|
+
/// <reference types="node" />
|
|
12
|
+
import { type Ref } from 'vue';
|
|
13
|
+
/**
|
|
14
|
+
* Canvas context options optimized for PDF rendering.
|
|
15
|
+
* Matches pdf.js quality settings.
|
|
16
|
+
*/
|
|
17
|
+
export declare const CANVAS_CONTEXT_OPTIONS: CanvasRenderingContext2DSettings;
|
|
18
|
+
/**
|
|
19
|
+
* Create a new canvas element with standard settings.
|
|
20
|
+
* All canvases are created dynamically (pdf.js pattern) to prevent
|
|
21
|
+
* dual-canvas confusion that causes visual overlap on iPad Safari.
|
|
22
|
+
*
|
|
23
|
+
* @param className - CSS class name for the canvas
|
|
24
|
+
* @param ariaHidden - Whether to hide from accessibility tree (default: false)
|
|
25
|
+
* @returns New canvas element configured for off-screen rendering
|
|
26
|
+
*/
|
|
27
|
+
export declare function createCanvas(className: string, ariaHidden?: boolean): HTMLCanvasElement;
|
|
28
|
+
/**
|
|
29
|
+
* Get 2D rendering context with optimized settings for PDF rendering.
|
|
30
|
+
* Disables image smoothing for pixel-perfect rendering (pdf.js pattern).
|
|
31
|
+
*
|
|
32
|
+
* @param canvas - Canvas element to get context from
|
|
33
|
+
* @returns Canvas 2D context or null if failed
|
|
34
|
+
*/
|
|
35
|
+
export declare function getCanvasContext(canvas: HTMLCanvasElement): CanvasRenderingContext2D | null;
|
|
36
|
+
/**
|
|
37
|
+
* Show a canvas by setting opacity to 1.
|
|
38
|
+
* Uses opacity instead of hidden attribute for iOS Safari compositor compatibility.
|
|
39
|
+
*
|
|
40
|
+
* @param canvas - Canvas element to show
|
|
41
|
+
*/
|
|
42
|
+
export declare function showCanvas(canvas: HTMLCanvasElement): void;
|
|
43
|
+
/**
|
|
44
|
+
* Clean up a canvas by zeroing its dimensions.
|
|
45
|
+
* This immediately releases the GPU texture (pdf.js pattern).
|
|
46
|
+
*
|
|
47
|
+
* @param canvas - Canvas element to clean up
|
|
48
|
+
* @param removeFromDom - Whether to also remove from DOM (default: false)
|
|
49
|
+
*/
|
|
50
|
+
export declare function cleanupCanvas(canvas: HTMLCanvasElement | null, removeFromDom?: boolean): void;
|
|
51
|
+
/**
|
|
52
|
+
* Perform atomic canvas swap with proper cleanup.
|
|
53
|
+
* Following pdf.js pattern: replaceWith for atomic swap, then show via opacity.
|
|
54
|
+
*
|
|
55
|
+
* @param oldCanvas - Existing canvas to replace (can be null for first render)
|
|
56
|
+
* @param newCanvas - New canvas to insert
|
|
57
|
+
* @param containerRef - Fallback container if oldCanvas has no parent
|
|
58
|
+
* @param isMounted - Ref to check if component is still mounted
|
|
59
|
+
* @param canvasRef - Ref to update with new canvas
|
|
60
|
+
* @param prepend - If true, prepend instead of append (for base canvas under detail)
|
|
61
|
+
* @returns true if swap was successful, false otherwise
|
|
62
|
+
*/
|
|
63
|
+
export declare function performAtomicSwap(oldCanvas: HTMLCanvasElement | null | undefined, newCanvas: HTMLCanvasElement, containerRef: Ref<HTMLDivElement | null | undefined>, isMounted: Ref<boolean>, canvasRef: Ref<HTMLCanvasElement | null | undefined>, prepend?: boolean): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Options for creating a render task.
|
|
66
|
+
*/
|
|
67
|
+
export interface RenderTaskOptions {
|
|
68
|
+
page: any;
|
|
69
|
+
canvas: HTMLCanvasElement;
|
|
70
|
+
renderParameters: any;
|
|
71
|
+
queueRenderTask: any;
|
|
72
|
+
queueId: string;
|
|
73
|
+
priority: number;
|
|
74
|
+
isMounted: Ref<boolean>;
|
|
75
|
+
canvasRef: Ref<HTMLCanvasElement | null>;
|
|
76
|
+
containerRef: Ref<HTMLDivElement | null>;
|
|
77
|
+
prepend?: boolean;
|
|
78
|
+
onSuccess?: (canvas: HTMLCanvasElement) => void;
|
|
79
|
+
onError?: (error: any) => void;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Create and enqueue a render task with standard callback handling.
|
|
83
|
+
* Consolidates the common render task pattern used by both LayerCanvas and LayerCanvasDetail.
|
|
84
|
+
*
|
|
85
|
+
* @param options - Render task configuration
|
|
86
|
+
* @returns Timeout ID for the safety timeout (call clearTimeout on cleanup)
|
|
87
|
+
*/
|
|
88
|
+
export declare function createRenderTask(options: RenderTaskOptions): NodeJS.Timeout;
|
|
89
|
+
/**
|
|
90
|
+
* Clear a debounce timeout safely.
|
|
91
|
+
*
|
|
92
|
+
* @param timeout - Timeout to clear (can be null)
|
|
93
|
+
* @returns null (for easy assignment: timeout = clearDebounceTimeout(timeout))
|
|
94
|
+
*/
|
|
95
|
+
export declare function clearDebounceTimeout(timeout: NodeJS.Timeout | null): null;
|
|
96
|
+
/**
|
|
97
|
+
* Standard cleanup for canvas components.
|
|
98
|
+
* Call this in onBeforeUnmount and onUnmounted.
|
|
99
|
+
*
|
|
100
|
+
* @param options - Cleanup configuration
|
|
101
|
+
*/
|
|
102
|
+
export interface CleanupOptions {
|
|
103
|
+
canvasRef: Ref<HTMLCanvasElement | null>;
|
|
104
|
+
containerRef: Ref<HTMLDivElement | null>;
|
|
105
|
+
newCanvasElement: HTMLCanvasElement | null;
|
|
106
|
+
renderDebounceTimeout: NodeJS.Timeout | null;
|
|
107
|
+
renderTimeout?: NodeJS.Timeout | null;
|
|
108
|
+
queueRenderTask?: any;
|
|
109
|
+
queueId?: string;
|
|
110
|
+
removeFromDom?: boolean;
|
|
111
|
+
clearContainer?: boolean;
|
|
112
|
+
}
|
|
113
|
+
export declare function cleanupCanvasComponent(options: CleanupOptions): void;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scale utilities for CSS round() based dimension calculations
|
|
3
|
+
* Based on pdf.js implementation for pixel-perfect layer alignment
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Detect iOS devices (following pdf.js pattern)
|
|
7
|
+
* Used for platform-specific canvas memory limits and optimizations
|
|
8
|
+
*/
|
|
9
|
+
export declare const isIOS: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Detect Safari browser (following pdf.js pattern from app_options.js)
|
|
12
|
+
* Safari has stricter canvas memory limits than other browsers
|
|
13
|
+
*/
|
|
14
|
+
export declare const isSafari: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Maximum canvas pixels for different browsers (following pdf.js pattern)
|
|
17
|
+
* Safari: 16,777,216 pixels (~16 megapixels) - to stay within ~128MB per-canvas limit
|
|
18
|
+
* Others: 33,554,432 pixels (2^25, ~32 megapixels)
|
|
19
|
+
*
|
|
20
|
+
* Note: iOS Safari uses even lower limits (5.2M) via platform-specific checks
|
|
21
|
+
*/
|
|
22
|
+
export declare const maxCanvasPixels: number;
|
|
23
|
+
/**
|
|
24
|
+
* Maximum canvas dimension (width or height) - following pdf.js app_options.js default
|
|
25
|
+
* This is the browser canvas size limit (32767 on most browsers)
|
|
26
|
+
* Corresponds to pdf.js maxCanvasDim option
|
|
27
|
+
*/
|
|
28
|
+
export declare const MAX_CANVAS_DIM = 32767;
|
|
29
|
+
/**
|
|
30
|
+
* Maximum canvas area (4096×4096) - used for initial scale calculation
|
|
31
|
+
* This is a conservative limit to prevent memory issues during setup
|
|
32
|
+
*/
|
|
33
|
+
export declare const MAX_CANVAS_SIZE: number;
|
|
34
|
+
/**
|
|
35
|
+
* Approximate a float scale value as a fraction using Farey sequence.
|
|
36
|
+
* This ensures CSS and canvas dimensions round to the same pixel boundaries.
|
|
37
|
+
*
|
|
38
|
+
* @param x - The scale value to approximate
|
|
39
|
+
* @returns [numerator, denominator] array
|
|
40
|
+
*/
|
|
41
|
+
export declare function approximateFraction(x: number): [number, number];
|
|
42
|
+
/**
|
|
43
|
+
* Canvas area factor for viewport-based capping (following pdf.js default)
|
|
44
|
+
* Limits canvas to viewportArea × factor pixels
|
|
45
|
+
* Default: 200 (allows ~14x zoom on small viewports, since √200 ≈ 14.14)
|
|
46
|
+
*/
|
|
47
|
+
export declare const DEFAULT_CAP_CANVAS_AREA_FACTOR = 200;
|
|
48
|
+
/**
|
|
49
|
+
* Calculate effective max pixels based on viewport size and area factor.
|
|
50
|
+
* Following pdf.js OutputScale.capPixels() pattern.
|
|
51
|
+
*
|
|
52
|
+
* This function prevents over-allocation of canvas memory for small viewports
|
|
53
|
+
* by capping maxCanvasPixels based on the viewport area. For example, a tiny
|
|
54
|
+
* 400×300 viewport would be capped at 24M pixels instead of the default 33.5M.
|
|
55
|
+
*
|
|
56
|
+
* @param viewportWidth - Viewport width in CSS pixels
|
|
57
|
+
* @param viewportHeight - Viewport height in CSS pixels
|
|
58
|
+
* @param maxPixels - Static maximum canvas pixels limit
|
|
59
|
+
* @param capAreaFactor - Multiplier for viewport area (default: 200, ≤0 = disabled)
|
|
60
|
+
* @returns Effective maximum canvas pixels (minimum of static limit and capped limit)
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* // Small viewport: 400×300 = 120,000 px²
|
|
64
|
+
* capPixels(400, 300, 33554432, 200)
|
|
65
|
+
* // Returns: min(33554432, 120000 × 200) = 24,000,000 pixels
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* // Large viewport: 1920×1080 = 2,073,600 px²
|
|
69
|
+
* capPixels(1920, 1080, 33554432, 200)
|
|
70
|
+
* // Returns: min(33554432, 414720000) = 33,554,432 pixels (static limit wins)
|
|
71
|
+
*/
|
|
72
|
+
export declare function capPixels(viewportWidth: number, viewportHeight: number, maxPixels: number, capAreaFactor?: number): number;
|
|
73
|
+
/**
|
|
74
|
+
* Browser-specific precision rounding.
|
|
75
|
+
* Firefox uses f32 precision for CSS calc, so we need to match it.
|
|
76
|
+
*/
|
|
77
|
+
export declare const calcRound: (x: number) => number;
|
|
78
|
+
/**
|
|
79
|
+
* Floor a value to the nearest multiple of divisor.
|
|
80
|
+
* Used for canvas dimension calculations.
|
|
81
|
+
*
|
|
82
|
+
* @param value - The value to floor
|
|
83
|
+
* @param divisor - The divisor to floor to
|
|
84
|
+
* @returns Floored value
|
|
85
|
+
*/
|
|
86
|
+
export declare function floorToDivide(value: number, divisor: number): number;
|
|
87
|
+
/**
|
|
88
|
+
* Check if the browser supports CSS round() function.
|
|
89
|
+
* Falls back to calc() if not supported.
|
|
90
|
+
*/
|
|
91
|
+
export declare function isCSSRoundSupported(): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Generate CSS dimension string using round() or calc() based on browser support.
|
|
94
|
+
*
|
|
95
|
+
* @param baseVar - The base CSS variable name (e.g., '--page-width')
|
|
96
|
+
* @param scaleVar - The scale CSS variable name (e.g., '--scale-factor')
|
|
97
|
+
* @param roundVar - The rounding CSS variable name (e.g., '--scale-round-x')
|
|
98
|
+
* @returns CSS calc/round string
|
|
99
|
+
*/
|
|
100
|
+
export declare function generateDimensionCSS(baseVar: string, scaleVar?: string, roundVar?: string | null): string;
|
|
101
|
+
/**
|
|
102
|
+
* Calculate scale rounding values for CSS variables.
|
|
103
|
+
*
|
|
104
|
+
* @param scale - The current scale value
|
|
105
|
+
* @returns Object with scaleRoundX and scaleRoundY in pixels
|
|
106
|
+
*/
|
|
107
|
+
export declare function calculateScaleRound(scale: number): {
|
|
108
|
+
scaleRoundX: string;
|
|
109
|
+
scaleRoundY: string;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Calculate safe output scale considering all canvas constraints.
|
|
113
|
+
* Following pdf.js OutputScale.limitCanvas() pattern from display_utils.js
|
|
114
|
+
*
|
|
115
|
+
* This function applies four types of constraints:
|
|
116
|
+
* 1. Viewport-based area capping (viewportArea × capAreaFactor, pdf.js pattern)
|
|
117
|
+
* 2. Total pixel area (width × height ≤ effectiveMaxPixels)
|
|
118
|
+
* 3. Maximum width dimension (width ≤ maxDim)
|
|
119
|
+
* 4. Maximum height dimension (height ≤ maxDim)
|
|
120
|
+
*
|
|
121
|
+
* Takes the most restrictive constraint and scales down if needed.
|
|
122
|
+
*
|
|
123
|
+
* @param width - Canvas width at scale 1
|
|
124
|
+
* @param height - Canvas height at scale 1
|
|
125
|
+
* @param requestedScale - Desired output scale (typically devicePixelRatio)
|
|
126
|
+
* @param viewportWidth - Viewport width for area capping (default: width)
|
|
127
|
+
* @param viewportHeight - Viewport height for area capping (default: height)
|
|
128
|
+
* @param maxPixels - Maximum total canvas pixels (platform-specific, default from maxCanvasPixels)
|
|
129
|
+
* @param maxDim - Maximum canvas dimension for width or height (default 32767)
|
|
130
|
+
* @param capAreaFactor - Viewport area multiplier for capping (default: 200, ≤0 = disabled)
|
|
131
|
+
* @returns Object with scale, needsRestriction flag, and reason for restriction
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* // Normal case: 800×600 page at 2x scale
|
|
135
|
+
* limitCanvasScale(800, 600, 2.0)
|
|
136
|
+
* // Returns: { scale: 2.0, needsRestriction: false }
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* // Wide page: 40000×1000 page at 1x scale
|
|
140
|
+
* limitCanvasScale(40000, 1000, 1.0)
|
|
141
|
+
* // Returns: { scale: 0.819, needsRestriction: true, reason: 'width' }
|
|
142
|
+
* // Actual canvas: 32767×819 pixels
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* // Small viewport: 400×300 viewport with area capping
|
|
146
|
+
* limitCanvasScale(800, 600, 2.0, 400, 300)
|
|
147
|
+
* // Viewport area: 120,000 → capped limit: 24M pixels
|
|
148
|
+
* // Returns: { scale: 1.414, needsRestriction: true, reason: 'area-capped' }
|
|
149
|
+
*/
|
|
150
|
+
export declare function limitCanvasScale(width: number, height: number, requestedScale: number, viewportWidth?: number, viewportHeight?: number, maxPixels?: number, maxDim?: number, capAreaFactor?: number): {
|
|
151
|
+
scale: number;
|
|
152
|
+
needsRestriction: boolean;
|
|
153
|
+
reason?: 'area' | 'area-capped' | 'width' | 'height';
|
|
154
|
+
};
|