teamsync-pdf-viewer 1.2.0 → 1.3.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/CHANGELOG.md +25 -0
- package/README.md +184 -184
- package/dist/src/components/CompareCurtainSlider.d.ts +8 -0
- package/dist/src/components/CompareToolbar.d.ts +13 -0
- package/dist/src/components/DiffHighlightOverlay.d.ts +11 -0
- package/dist/src/components/DiffSummarySidebar.d.ts +13 -0
- package/dist/src/components/DocumentViewer.d.ts +4 -2
- package/dist/src/components/PageRenderer.d.ts +3 -2
- package/dist/src/components/SideBySideViewer.d.ts +29 -0
- package/dist/src/components/TeamSyncViewer.d.ts +3 -1
- package/dist/src/core/ViewerInstance.d.ts +49 -1
- package/dist/src/core/types.d.ts +28 -0
- package/dist/src/hooks/usePdfSearch.d.ts +8 -8
- package/dist/src/index.d.ts +5 -0
- package/dist/src/types/compare.d.ts +56 -0
- package/dist/src/utils/pdfDiffEngine.d.ts +37 -0
- package/dist/style.css +1 -1
- package/dist/teamsync-pdf-viewer.js +3355 -1854
- package/dist/teamsync-pdf-viewer.js.map +1 -1
- package/package.json +5 -5
|
@@ -2,7 +2,8 @@ import { ViewerBus } from './eventBus';
|
|
|
2
2
|
import { ExportOptions } from './export';
|
|
3
3
|
import { Annotation } from '../annotations/types';
|
|
4
4
|
import { AnnotationManager } from '../annotations/AnnotationManager';
|
|
5
|
-
import { Redaction, WatermarkOptions, ViewerEventMap, ViewerEventType } from './types';
|
|
5
|
+
import { Redaction, WatermarkOptions, ViewerEventMap, ViewerEventType, TransientHighlight } from './types';
|
|
6
|
+
import { SearchResult } from '../hooks/usePdfSearch';
|
|
6
7
|
/**
|
|
7
8
|
* © 2026 AngelBot Ai Pvt Ltd. All rights reserved.
|
|
8
9
|
* WebViewerInstance — the imperative handle returned by `createWebViewer()` and exposed through
|
|
@@ -21,6 +22,11 @@ export interface ViewerBinding {
|
|
|
21
22
|
getCurrentPage(): number;
|
|
22
23
|
getPageCount(): number;
|
|
23
24
|
loadDocument(url: string): void;
|
|
25
|
+
goToPage(pageNumber: number, options?: {
|
|
26
|
+
smooth?: boolean;
|
|
27
|
+
}): void;
|
|
28
|
+
getTransientHighlights(): TransientHighlight[];
|
|
29
|
+
setTransientHighlights(highlights: TransientHighlight[]): void;
|
|
24
30
|
}
|
|
25
31
|
export declare class WebViewerInstance {
|
|
26
32
|
readonly bus: ViewerBus;
|
|
@@ -56,6 +62,39 @@ export declare class WebViewerInstance {
|
|
|
56
62
|
getPdfDocument(): pdfjsLib.PDFDocumentProxy | null;
|
|
57
63
|
getCurrentPage(): number;
|
|
58
64
|
getPageCount(): number;
|
|
65
|
+
/** Navigate to a specific page number (1-based). */
|
|
66
|
+
goToPage(pageNumber: number, options?: {
|
|
67
|
+
smooth?: boolean;
|
|
68
|
+
}): void;
|
|
69
|
+
/** Set the current page number (1-based). Alias of goToPage. */
|
|
70
|
+
setCurrentPage(pageNumber: number): void;
|
|
71
|
+
/**
|
|
72
|
+
* Search the document for text matches, returning snippets and page bounding boxes.
|
|
73
|
+
*/
|
|
74
|
+
searchText(query: string): Promise<SearchResult[]>;
|
|
75
|
+
/** Get the current list of transient highlights. */
|
|
76
|
+
getTransientHighlights(): TransientHighlight[];
|
|
77
|
+
/**
|
|
78
|
+
* Set transient visual highlights across one or more pages.
|
|
79
|
+
* These render directly on the PDF canvas but are NEVER saved into AnnotationManager
|
|
80
|
+
* or exported to XFDF.
|
|
81
|
+
*/
|
|
82
|
+
setTransientHighlights(highlights: TransientHighlight[]): void;
|
|
83
|
+
/** Add a single transient highlight to the current list. */
|
|
84
|
+
addTransientHighlight(highlight: TransientHighlight): void;
|
|
85
|
+
/** Clear all active transient highlights. */
|
|
86
|
+
clearTransientHighlights(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Search for a snippet or citation query, scroll to its page, and highlight it temporarily.
|
|
89
|
+
* Returns the matched SearchResult or null if not found.
|
|
90
|
+
*/
|
|
91
|
+
highlightSnippet(query: string, options?: {
|
|
92
|
+
pageIndex?: number;
|
|
93
|
+
pulse?: boolean;
|
|
94
|
+
scrollTo?: boolean;
|
|
95
|
+
color?: string;
|
|
96
|
+
tooltip?: string;
|
|
97
|
+
}): Promise<SearchResult | null>;
|
|
59
98
|
getAnnotations(): Annotation[];
|
|
60
99
|
/** Print the exported document (annotations, redactions and watermark baked in). */
|
|
61
100
|
print(): void;
|
|
@@ -67,6 +106,8 @@ export declare class WebViewerInstance {
|
|
|
67
106
|
readonly UI: {
|
|
68
107
|
/** Theming is not implemented; kept for API compatibility. */
|
|
69
108
|
setTheme: (_theme: string) => void;
|
|
109
|
+
goToPage: (pageNumber: number) => void;
|
|
110
|
+
setCurrentPageNumber: (pageNumber: number) => void;
|
|
70
111
|
openElements: (elements: string[]) => void;
|
|
71
112
|
closeElements: (elements: string[]) => void;
|
|
72
113
|
enableElements: (elements: string[]) => void;
|
|
@@ -77,6 +118,10 @@ export declare class WebViewerInstance {
|
|
|
77
118
|
fitPage: () => void;
|
|
78
119
|
fitToWidth: () => void;
|
|
79
120
|
fitToPage: () => void;
|
|
121
|
+
startCompare: (docA: any, docB: any, options?: any) => void;
|
|
122
|
+
stopCompare: () => void;
|
|
123
|
+
setCompareMode: (mode: "overlay" | "side-by-side" | "semantic") => void;
|
|
124
|
+
setCompareColors: (colorA: string, colorB: string) => void;
|
|
80
125
|
};
|
|
81
126
|
readonly Core: {
|
|
82
127
|
/** The real AnnotationManager (XFDF import/export, granular events, permissions). */
|
|
@@ -86,6 +131,9 @@ export declare class WebViewerInstance {
|
|
|
86
131
|
removeEventListener: (event: string, callback: (detail: unknown) => void) => void;
|
|
87
132
|
getCurrentPage: () => number;
|
|
88
133
|
getPageCount: () => number;
|
|
134
|
+
goToPage: (pageNumber: number) => void;
|
|
135
|
+
setCurrentPage: (pageNumber: number) => void;
|
|
136
|
+
setCurrentPageNumber: (pageNumber: number) => void;
|
|
89
137
|
getDocument: () => {
|
|
90
138
|
getFileData: (options?: ExportOptions) => Promise<Uint8Array<ArrayBufferLike>>;
|
|
91
139
|
};
|
package/dist/src/core/types.d.ts
CHANGED
|
@@ -3,6 +3,27 @@ import { Annotation } from '../annotations/types';
|
|
|
3
3
|
import { AnnotationChangedEvent } from '../annotations/AnnotationManager';
|
|
4
4
|
import { PdfAssetPaths } from './pdfAssets';
|
|
5
5
|
export type { PdfAssetPaths };
|
|
6
|
+
export interface SearchBounds {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}
|
|
12
|
+
export interface TransientHighlight {
|
|
13
|
+
id?: string;
|
|
14
|
+
/** 1-based page number */
|
|
15
|
+
pageIndex: number;
|
|
16
|
+
/** Bounding boxes on the page in PDF coordinate points */
|
|
17
|
+
bounds: SearchBounds[];
|
|
18
|
+
/** Background fill color (default 'rgba(250, 204, 21, 0.4)') */
|
|
19
|
+
color?: string;
|
|
20
|
+
/** Border color (default 'rgba(234, 179, 8, 0.8)') */
|
|
21
|
+
borderColor?: string;
|
|
22
|
+
/** Whether to animate with a pulsing focus ring */
|
|
23
|
+
pulse?: boolean;
|
|
24
|
+
/** Optional tooltip text displayed above the highlight */
|
|
25
|
+
tooltip?: string;
|
|
26
|
+
}
|
|
6
27
|
export interface Redaction {
|
|
7
28
|
id?: string;
|
|
8
29
|
/** 1-based page number */
|
|
@@ -47,6 +68,10 @@ export interface WebViewerOptions {
|
|
|
47
68
|
initialScale?: InitialScale;
|
|
48
69
|
/** 1-based page to scroll to after load. */
|
|
49
70
|
initialPage?: number;
|
|
71
|
+
/** Current 1-based page to display. Changes navigate to the given page. */
|
|
72
|
+
page?: number;
|
|
73
|
+
/** Transient visual highlights that render on pages without polluting AnnotationManager. */
|
|
74
|
+
transientHighlights?: TransientHighlight[];
|
|
50
75
|
plugins?: ViewerPlugin[];
|
|
51
76
|
redactions?: Redaction[];
|
|
52
77
|
regexRedactions?: RegExp[];
|
|
@@ -100,6 +125,9 @@ export interface ViewerEventMap {
|
|
|
100
125
|
};
|
|
101
126
|
/** Granular add / modify / delete (with the `imported` flag) from the AnnotationManager. */
|
|
102
127
|
annotationChanged: AnnotationChangedEvent;
|
|
128
|
+
transientHighlightsChanged: {
|
|
129
|
+
highlights: TransientHighlight[];
|
|
130
|
+
};
|
|
103
131
|
toolChanged: {
|
|
104
132
|
tool: string | null;
|
|
105
133
|
};
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import { Redaction } from '../core/types';
|
|
2
|
-
import * as pdfjsLib from 'pdfjs-dist';
|
|
3
|
-
export
|
|
4
|
-
x: number;
|
|
5
|
-
y: number;
|
|
6
|
-
width: number;
|
|
7
|
-
height: number;
|
|
8
|
-
}
|
|
1
|
+
import { Redaction, SearchBounds } from '../core/types';
|
|
2
|
+
import type * as pdfjsLib from 'pdfjs-dist';
|
|
3
|
+
export type { SearchBounds };
|
|
9
4
|
export interface SearchResult {
|
|
10
5
|
id: string;
|
|
11
6
|
pageIndex: number;
|
|
@@ -14,6 +9,11 @@ export interface SearchResult {
|
|
|
14
9
|
matchLength: number;
|
|
15
10
|
bounds: SearchBounds[];
|
|
16
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Standalone asynchronous text search across all pages of a PDFDocumentProxy.
|
|
14
|
+
* Sanitizes redacted regions and returns matching snippets and bounding boxes.
|
|
15
|
+
*/
|
|
16
|
+
export declare function searchPdfText(pdfDoc: pdfjsLib.PDFDocumentProxy, query: string, redactions?: Redaction[], onProgress?: (progress: number) => void): Promise<SearchResult[]>;
|
|
17
17
|
export declare function usePdfSearch(pdfDoc: pdfjsLib.PDFDocumentProxy | null, redactions?: Redaction[]): {
|
|
18
18
|
search: (query: string) => Promise<void>;
|
|
19
19
|
searchResults: SearchResult[];
|
package/dist/src/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export { createWebViewer, WebViewer } from './core/createWebViewer';
|
|
|
9
9
|
export { WebViewerInstance } from './core/ViewerInstance';
|
|
10
10
|
export { TeamSyncViewer } from './components/TeamSyncViewer';
|
|
11
11
|
export type { TeamSyncViewerProps } from './components/TeamSyncViewer';
|
|
12
|
+
export * from './types/compare';
|
|
13
|
+
export * from './utils/pdfDiffEngine';
|
|
12
14
|
export { configurePdfAssets, getPdfAssetPaths, isWorkerConfigured, pdfjsVersion } from './core/pdfAssets';
|
|
13
15
|
export type { PdfAssetPaths } from './core/pdfAssets';
|
|
14
16
|
export { ViewerBus } from './core/eventBus';
|
|
@@ -26,4 +28,7 @@ export { annotationsToXfdf, annotationToXfdfFragment, parseXfdf, toPdfDate, from
|
|
|
26
28
|
export type { XfdfExportOptions } from './annotations/xfdf';
|
|
27
29
|
export { printPdfBytes } from './core/print';
|
|
28
30
|
export type { PrintOptions } from './core/print';
|
|
31
|
+
export { usePdfSearch, searchPdfText } from './hooks/usePdfSearch';
|
|
32
|
+
export type { SearchResult, SearchBounds } from './hooks/usePdfSearch';
|
|
33
|
+
export type { TransientHighlight } from './core/types';
|
|
29
34
|
export * from './plugins/types';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* © 2026 AngelBot Ai Pvt Ltd. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
export type CompareMode = 'overlay' | 'side-by-side' | 'semantic';
|
|
5
|
+
export interface CompareOptions {
|
|
6
|
+
docA?: string | ArrayBuffer | Uint8Array;
|
|
7
|
+
docB?: string | ArrayBuffer | Uint8Array;
|
|
8
|
+
mode?: CompareMode;
|
|
9
|
+
colorA?: string;
|
|
10
|
+
colorB?: string;
|
|
11
|
+
opacityA?: number;
|
|
12
|
+
opacityB?: number;
|
|
13
|
+
blendMode?: 'multiply' | 'difference' | 'screen' | 'normal';
|
|
14
|
+
}
|
|
15
|
+
export interface TextDiffSegment {
|
|
16
|
+
type: 'equal' | 'add' | 'delete';
|
|
17
|
+
text: string;
|
|
18
|
+
pageIndex: number;
|
|
19
|
+
}
|
|
20
|
+
export interface DiffBoundingBox {
|
|
21
|
+
id: string;
|
|
22
|
+
pageIndex: number;
|
|
23
|
+
type: 'addition' | 'deletion' | 'modification';
|
|
24
|
+
text: string;
|
|
25
|
+
x: number;
|
|
26
|
+
y: number;
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
}
|
|
30
|
+
export interface DiffItem {
|
|
31
|
+
id: string;
|
|
32
|
+
pageIndex: number;
|
|
33
|
+
type: 'addition' | 'deletion' | 'modification';
|
|
34
|
+
description: string;
|
|
35
|
+
x?: number;
|
|
36
|
+
y?: number;
|
|
37
|
+
width?: number;
|
|
38
|
+
height?: number;
|
|
39
|
+
}
|
|
40
|
+
export interface CompareState {
|
|
41
|
+
isActive: boolean;
|
|
42
|
+
docA?: string | ArrayBuffer | Uint8Array;
|
|
43
|
+
docB?: string | ArrayBuffer | Uint8Array;
|
|
44
|
+
mode: CompareMode;
|
|
45
|
+
colorA: string;
|
|
46
|
+
colorB: string;
|
|
47
|
+
opacityA: number;
|
|
48
|
+
opacityB: number;
|
|
49
|
+
blendMode: 'multiply' | 'difference' | 'screen' | 'normal';
|
|
50
|
+
curtainPosition: number;
|
|
51
|
+
showCurtain: boolean;
|
|
52
|
+
diffItems: DiffItem[];
|
|
53
|
+
currentDiffIndex: number;
|
|
54
|
+
pageDiffsA?: Record<number, DiffBoundingBox[]>;
|
|
55
|
+
pageDiffsB?: Record<number, DiffBoundingBox[]>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { TextDiffSegment, DiffItem, DiffBoundingBox } from '../types/compare';
|
|
2
|
+
/**
|
|
3
|
+
* © 2026 AngelBot Ai Pvt Ltd. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
import type * as pdfjsLib from 'pdfjs-dist';
|
|
6
|
+
export interface PageDiffResult {
|
|
7
|
+
diffsA: DiffBoundingBox[];
|
|
8
|
+
diffsB: DiffBoundingBox[];
|
|
9
|
+
summary: DiffItem[];
|
|
10
|
+
}
|
|
11
|
+
export interface WordToken {
|
|
12
|
+
text: string;
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Extracts individual words with precise unscaled viewport bounding boxes from a PDF.js page.
|
|
20
|
+
*/
|
|
21
|
+
export declare function extractWordsFromPage(page: pdfjsLib.PDFPageProxy): Promise<WordToken[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Computes exact text difference bounding boxes on a page for both Document A and Document B.
|
|
24
|
+
*/
|
|
25
|
+
export declare function computePageDiffBoxes(pdfDocA: pdfjsLib.PDFDocumentProxy, pdfDocB: pdfjsLib.PDFDocumentProxy, pageIndex: number): Promise<PageDiffResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Lightweight client-side Myers Diff algorithm for raw text comparison.
|
|
28
|
+
*/
|
|
29
|
+
export declare function computeTextDiff(textA: string, textB: string, pageIndex: number): TextDiffSegment[];
|
|
30
|
+
/**
|
|
31
|
+
* Colorizes a rendered page canvas with a custom hex tint.
|
|
32
|
+
*/
|
|
33
|
+
export declare function tintCanvas(ctx: CanvasRenderingContext2D, width: number, height: number, colorHex: string, opacity?: number): void;
|
|
34
|
+
/**
|
|
35
|
+
* Computes pixel-level difference bounding boxes between two rendered page canvases.
|
|
36
|
+
*/
|
|
37
|
+
export declare function computeCanvasPixelDiff(canvasA: HTMLCanvasElement, canvasB: HTMLCanvasElement, pageIndex: number, scale: number): DiffItem[];
|