teamsync-pdf-viewer 1.0.3 → 1.2.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/LICENSE +96 -1
  3. package/README.md +186 -165
  4. package/dist/src/annotations/AnnotationManager.d.ts +90 -0
  5. package/dist/src/annotations/geometry.d.ts +51 -0
  6. package/dist/src/annotations/ids.d.ts +6 -0
  7. package/dist/src/annotations/types.d.ts +72 -0
  8. package/dist/src/annotations/xfdf.d.ts +18 -0
  9. package/dist/src/components/AboutModal.d.ts +6 -0
  10. package/dist/src/components/AnnotationContextMenu.d.ts +17 -0
  11. package/dist/src/components/DocumentViewer.d.ts +50 -0
  12. package/dist/src/components/Header.d.ts +36 -0
  13. package/dist/src/components/InsertLinkModal.d.ts +10 -0
  14. package/dist/src/components/LeftSidebar.d.ts +10 -0
  15. package/dist/src/components/PageContextMenu.d.ts +20 -0
  16. package/dist/src/components/PageRenderer.d.ts +40 -0
  17. package/dist/src/components/SettingsModal.d.ts +8 -0
  18. package/dist/src/components/Sidebar.d.ts +18 -0
  19. package/dist/src/components/TeamSyncViewer.d.ts +35 -0
  20. package/dist/src/components/TextSelectionMenu.d.ts +18 -0
  21. package/dist/src/core/ViewerInstance.d.ts +94 -0
  22. package/dist/src/core/busContext.d.ts +3 -0
  23. package/dist/src/core/createWebViewer.d.ts +5 -0
  24. package/dist/src/core/eventBus.d.ts +25 -0
  25. package/dist/src/core/export.d.ts +23 -0
  26. package/dist/src/core/pdfAssets.d.ts +27 -0
  27. package/dist/src/core/print.d.ts +12 -0
  28. package/dist/src/core/types.d.ts +108 -0
  29. package/dist/src/hooks/usePdfSearch.d.ts +23 -0
  30. package/dist/src/hooks/useShortcuts.d.ts +13 -0
  31. package/dist/src/hooks/useViewerBus.d.ts +7 -0
  32. package/dist/src/index.d.ts +29 -0
  33. package/dist/src/plugins/index.d.ts +1 -0
  34. package/dist/src/plugins/types.d.ts +26 -0
  35. package/dist/src/utils/findRegexRedactions.d.ts +6 -0
  36. package/dist/src/utils/rotationUtils.d.ts +32 -0
  37. package/dist/style.css +2 -0
  38. package/dist/teamsync-pdf-viewer.js +6177 -0
  39. package/dist/teamsync-pdf-viewer.js.map +1 -0
  40. package/package.json +48 -15
  41. package/dist/TeamSync.pdf +0 -0
  42. package/dist/ThirdPartyNotices.txt +0 -639
  43. package/dist/favicon.svg +0 -16
  44. package/dist/icons.svg +0 -24
  45. package/dist/index.d.ts +0 -1
  46. package/dist/teamsync-pdf-viewer.css +0 -2
  47. package/dist/teamsync-pdf-viewer.es.js +0 -51524
  48. package/dist/teamsync-pdf-viewer.umd.cjs +0 -327
  49. package/dist/webviewer.js +0 -92
@@ -0,0 +1,23 @@
1
+ import { Annotation } from '../annotations/types';
2
+ import { Redaction, WatermarkOptions } from './types';
3
+ import { GeometryResolver } from '../annotations/geometry';
4
+ /** Refuse to build documents larger than this in the browser (memory safety). */
5
+ export declare const MAX_EXPORT_BYTES: number;
6
+ export interface ExportInput {
7
+ /** Returns the original document bytes (prefer `pdfDocument.getData()`). */
8
+ getSourceBytes: () => Promise<Uint8Array | ArrayBuffer>;
9
+ /** Page geometry resolver (from the loaded pdf.js document). Derived from the bytes when absent. */
10
+ getPageGeometry?: GeometryResolver;
11
+ annotations: Annotation[];
12
+ redactions: Redaction[];
13
+ watermark?: WatermarkOptions;
14
+ /** Name printed on digital-signature placeholder blocks when the annotation has no signer. */
15
+ signerName?: string;
16
+ }
17
+ export interface ExportOptions {
18
+ /** Bake exactly these annotations instead of the live list. */
19
+ explicitAnnotations?: Annotation[];
20
+ /** Accepted for API compatibility; annotations are always taken from the live list / explicitAnnotations. */
21
+ xfdfString?: string;
22
+ }
23
+ export declare function buildPdfBytes(input: ExportInput, options?: ExportOptions): Promise<Uint8Array>;
@@ -0,0 +1,27 @@
1
+ import { DocumentInitParameters } from 'pdfjs-dist/types/src/display/api';
2
+ export interface PdfAssetPaths {
3
+ /** URL of `pdf.worker.min.mjs` matching the installed pdfjs-dist version. REQUIRED. */
4
+ workerSrc?: string;
5
+ /** Directory URL (trailing slash) of the packed CMaps — needed for CJK/Indic text. */
6
+ cMapUrl?: string;
7
+ /** Directory URL (trailing slash) of the standard 14 font substitutes. */
8
+ standardFontDataUrl?: string;
9
+ /** Directory URL (trailing slash) of the wasm decoders (JPX/OpenJPEG, qcms). */
10
+ wasmUrl?: string;
11
+ /** Directory URL (trailing slash) of ICC profiles. */
12
+ iccUrl?: string;
13
+ }
14
+ export declare function configurePdfAssets(paths: PdfAssetPaths): void;
15
+ export declare function getPdfAssetPaths(): Readonly<PdfAssetPaths>;
16
+ /** True once a worker URL has been configured (either via configurePdfAssets or directly on pdf.js). */
17
+ export declare function isWorkerConfigured(): boolean;
18
+ /**
19
+ * Throws a descriptive error when the worker has not been configured. Called lazily right before
20
+ * the first `getDocument()` — never at module scope, so importing the package is side-effect free
21
+ * and safe under SSR.
22
+ */
23
+ export declare function assertWorkerConfigured(): void;
24
+ /** Extra `getDocument()` parameters derived from the configured asset paths. */
25
+ export declare function getDocumentParams(): Partial<DocumentInitParameters>;
26
+ /** pdfjs-dist version this build was compiled against (useful for worker-version mismatch checks). */
27
+ export declare const pdfjsVersion: string;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * © 2026 AngelBot Ai Pvt Ltd. All rights reserved.
3
+ * Printing: the exported document (annotations / redactions / watermark baked in) is loaded into a
4
+ * hidden iframe and printed through the browser's PDF viewer. Falls back to opening the PDF in a
5
+ * new tab when the frame cannot print (e.g. the browser has no inline PDF viewer).
6
+ */
7
+ export interface PrintOptions {
8
+ title?: string;
9
+ /** How long the hidden frame is kept alive for the print dialog (default 60s). */
10
+ timeoutMs?: number;
11
+ }
12
+ export declare function printPdfBytes(bytes: Uint8Array, opts?: PrintOptions): Promise<void>;
@@ -0,0 +1,108 @@
1
+ import { ViewerPlugin } from '../plugins/types';
2
+ import { Annotation } from '../annotations/types';
3
+ import { AnnotationChangedEvent } from '../annotations/AnnotationManager';
4
+ import { PdfAssetPaths } from './pdfAssets';
5
+ export type { PdfAssetPaths };
6
+ export interface Redaction {
7
+ id?: string;
8
+ /** 1-based page number */
9
+ pageIndex: number;
10
+ x: number;
11
+ y: number;
12
+ width: number;
13
+ height: number;
14
+ status?: 'pending' | 'applied';
15
+ }
16
+ export interface WatermarkOptions {
17
+ text: string;
18
+ opacity?: number;
19
+ size?: number;
20
+ mode?: 'single' | 'tiled';
21
+ color?: string;
22
+ }
23
+ export interface SDKPermissions {
24
+ canAddAnnotations?: boolean;
25
+ canEditAnnotations?: boolean;
26
+ canDeleteAnnotations?: boolean;
27
+ canRedact?: boolean;
28
+ /** Allow editing/deleting annotations authored by other users (default false). */
29
+ canEditOthers?: boolean;
30
+ }
31
+ export interface ViewerUser {
32
+ id: string;
33
+ name: string;
34
+ }
35
+ export type InitialScale = number | 'fit-width' | 'fit-page';
36
+ /**
37
+ * Options accepted by `createWebViewer()` (and the deprecated `WebViewer()` alias).
38
+ * Every option is also available as a prop on `<TeamSyncViewer>`.
39
+ */
40
+ export interface WebViewerOptions {
41
+ /** @deprecated Only meaningful for the iframe package (`public/webviewer.js`). */
42
+ path?: string;
43
+ /** URL of the PDF to load. Presigned/CORS-enabled URLs work; bytes are fetched by pdf.js. */
44
+ initialDoc?: string;
45
+ /** Display name used for downloads. */
46
+ fileName?: string;
47
+ initialScale?: InitialScale;
48
+ /** 1-based page to scroll to after load. */
49
+ initialPage?: number;
50
+ plugins?: ViewerPlugin[];
51
+ redactions?: Redaction[];
52
+ regexRedactions?: RegExp[];
53
+ enableAnnotations?: boolean;
54
+ enableSign?: boolean;
55
+ signOptions?: ('digital' | 'ades' | 'simple')[];
56
+ watermark?: WatermarkOptions;
57
+ permissions?: SDKPermissions;
58
+ enableRedactions?: boolean;
59
+ canAddAnnotations?: boolean;
60
+ canEditAnnotations?: boolean;
61
+ canDeleteAnnotations?: boolean;
62
+ /** Shorthand for "no annotation/redaction editing at all". */
63
+ readOnly?: boolean;
64
+ /** Author attached to annotations created in this viewer. */
65
+ currentUser?: ViewerUser;
66
+ /** pdf.js worker / CMap / font / wasm locations (see `configurePdfAssets`). */
67
+ assets?: PdfAssetPaths;
68
+ /** Send cookies with the document request (same-origin session-bound URLs). Default false. */
69
+ withCredentials?: boolean;
70
+ /** Render the top toolbar. Default true. */
71
+ toolbar?: boolean;
72
+ /** Render the left (thumbnails) and right (comments/search) panels. Default true. */
73
+ sidebars?: boolean;
74
+ /** Start with the thumbnails panel open. Default true. */
75
+ leftPanelOpen?: boolean;
76
+ /** Focus the viewer on mount so keyboard shortcuts work immediately. Default false. */
77
+ autoFocus?: boolean;
78
+ }
79
+ /** Events available through `instance.on(type, listener)`. */
80
+ export interface ViewerEventMap {
81
+ documentLoaded: {
82
+ url: string;
83
+ numPages: number;
84
+ };
85
+ documentLoadError: {
86
+ url: string;
87
+ error: Error;
88
+ passwordRequired: boolean;
89
+ };
90
+ firstPageRendered: {
91
+ url: string;
92
+ pageNumber: number;
93
+ };
94
+ pageChanged: {
95
+ pageNumber: number;
96
+ numPages: number;
97
+ };
98
+ annotationsChanged: {
99
+ annotations: Annotation[];
100
+ };
101
+ /** Granular add / modify / delete (with the `imported` flag) from the AnnotationManager. */
102
+ annotationChanged: AnnotationChangedEvent;
103
+ toolChanged: {
104
+ tool: string | null;
105
+ };
106
+ destroy: Record<string, never>;
107
+ }
108
+ export type ViewerEventType = keyof ViewerEventMap;
@@ -0,0 +1,23 @@
1
+ import { Redaction } from '../core/types';
2
+ import * as pdfjsLib from 'pdfjs-dist';
3
+ export interface SearchBounds {
4
+ x: number;
5
+ y: number;
6
+ width: number;
7
+ height: number;
8
+ }
9
+ export interface SearchResult {
10
+ id: string;
11
+ pageIndex: number;
12
+ snippet: string;
13
+ matchStartIndex: number;
14
+ matchLength: number;
15
+ bounds: SearchBounds[];
16
+ }
17
+ export declare function usePdfSearch(pdfDoc: pdfjsLib.PDFDocumentProxy | null, redactions?: Redaction[]): {
18
+ search: (query: string) => Promise<void>;
19
+ searchResults: SearchResult[];
20
+ isSearching: boolean;
21
+ searchProgress: number;
22
+ clearSearch: () => void;
23
+ };
@@ -0,0 +1,13 @@
1
+ export type ActionType = 'ROTATE_CW' | 'ROTATE_CCW' | 'UNDO' | 'REDO' | 'DELETE' | 'COPY' | 'PASTE' | 'FILE_PICKER' | 'SEARCH';
2
+ export interface Shortcut {
3
+ action: ActionType;
4
+ description: string;
5
+ defaultCommand: string;
6
+ command: string;
7
+ }
8
+ export declare function useShortcuts(): {
9
+ shortcuts: Shortcut[];
10
+ updateShortcut: (action: ActionType, newCommand: string) => void;
11
+ getCommand: (action: ActionType) => string;
12
+ };
13
+ export declare function matchShortcut(e: KeyboardEvent, commandString: string): boolean;
@@ -0,0 +1,7 @@
1
+ import { ViewerBus, BusListener } from '../core/eventBus';
2
+ export declare function useViewerBus(): ViewerBus;
3
+ /**
4
+ * Subscribe to a bus event for the lifetime of the component.
5
+ * The latest `listener` is always invoked (no stale closures) without re-subscribing on every render.
6
+ */
7
+ export declare function useBusEvent<T = unknown>(type: string, listener: BusListener<T>): void;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * © 2026 AngelBot Ai Pvt Ltd. All rights reserved.
3
+ * TeamSync PDF Viewer SDK — public entry point.
4
+ *
5
+ * This module is side-effect free: importing it never touches `window`/`document`, so it is safe
6
+ * to import under SSR. Mount with `createWebViewer()` or render `<TeamSyncViewer>` on the client.
7
+ */
8
+ export { createWebViewer, WebViewer } from './core/createWebViewer';
9
+ export { WebViewerInstance } from './core/ViewerInstance';
10
+ export { TeamSyncViewer } from './components/TeamSyncViewer';
11
+ export type { TeamSyncViewerProps } from './components/TeamSyncViewer';
12
+ export { configurePdfAssets, getPdfAssetPaths, isWorkerConfigured, pdfjsVersion } from './core/pdfAssets';
13
+ export type { PdfAssetPaths } from './core/pdfAssets';
14
+ export { ViewerBus } from './core/eventBus';
15
+ export type { BusListener } from './core/eventBus';
16
+ export { buildPdfBytes, MAX_EXPORT_BYTES } from './core/export';
17
+ export type { ExportInput, ExportOptions } from './core/export';
18
+ export type { WebViewerOptions, Redaction, WatermarkOptions, SDKPermissions, ViewerUser, InitialScale, ViewerEventMap, ViewerEventType, } from './core/types';
19
+ export type { Annotation, AnnotationType, AnnotationPoint, AnnotationInput } from './annotations/types';
20
+ export { AnnotationManager } from './annotations/AnnotationManager';
21
+ export type { AnnotationAction, AnnotationChangedEvent, CommitOptions, ViewerUserInfo } from './annotations/AnnotationManager';
22
+ export { newAnnotationId } from './annotations/ids';
23
+ export { createPageGeometry, geometryFromPage, createGeometryResolver, toPdfPoint, fromPdfPoint, rectToPdf, rectFromPdf, rectToQuadPoints, quadPointsToRects, } from './annotations/geometry';
24
+ export type { PageGeometry, GeometryResolver, PdfRect, Rect, Point } from './annotations/geometry';
25
+ export { annotationsToXfdf, annotationToXfdfFragment, parseXfdf, toPdfDate, fromPdfDate, XFDF_NS } from './annotations/xfdf';
26
+ export type { XfdfExportOptions } from './annotations/xfdf';
27
+ export { printPdfBytes } from './core/print';
28
+ export type { PrintOptions } from './core/print';
29
+ export * from './plugins/types';
@@ -0,0 +1 @@
1
+ export * from './types';
@@ -0,0 +1,26 @@
1
+ import { default as React } from 'react';
2
+ export interface PluginContext {
3
+ activeTool: string | null;
4
+ setActiveTool: (tool: string | null) => void;
5
+ annotations: any[];
6
+ setAnnotations: React.Dispatch<React.SetStateAction<any[]>>;
7
+ commitAnnotations: (anns: any[]) => void;
8
+ scale: number;
9
+ pdfDoc: any;
10
+ permissions?: any;
11
+ initialDoc?: string;
12
+ watermark?: any;
13
+ }
14
+ export interface ViewerPlugin {
15
+ id: string;
16
+ name: string;
17
+ renderHeaderActions?: (context: PluginContext) => React.ReactNode;
18
+ renderModals?: (context: PluginContext) => React.ReactNode;
19
+ onInit?: (context: PluginContext) => void;
20
+ onBeforeSave?: (pdfBytes: Uint8Array, context: PluginContext) => Promise<Uint8Array>;
21
+ }
22
+ export interface DigitalSignerOptions {
23
+ allowedTypes?: Array<'digital' | 'ades' | 'simple'>;
24
+ usbBridgeUrl?: string;
25
+ defaultSignerName?: string;
26
+ }
@@ -0,0 +1,6 @@
1
+ import { Redaction } from '../core/types';
2
+ /**
3
+ * © 2026 AngelBot Ai Pvt Ltd. All rights reserved.
4
+ */
5
+ import * as pdfjsLib from 'pdfjs-dist';
6
+ export declare function findRegexRedactions(pdfDoc: pdfjsLib.PDFDocumentProxy, regexes: RegExp[]): Promise<Redaction[]>;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * © 2026 AngelBot Ai Pvt Ltd. All rights reserved.
3
+ */
4
+ /**
5
+ * Converts screen/canvas coordinates in rotated page space to canonical unrotated page space.
6
+ */
7
+ export declare function convertToUnrotated(rawX: number, rawY: number, rotation: number, unW: number, unH: number): {
8
+ x: number;
9
+ y: number;
10
+ };
11
+ /**
12
+ * Converts canonical unrotated page coordinates to rotated page space.
13
+ */
14
+ export declare function convertToRotated(unX: number, unY: number, rotation: number, unW: number, unH: number): {
15
+ x: number;
16
+ y: number;
17
+ };
18
+ /**
19
+ * Converts a rectangle from unrotated page space to rotated page space.
20
+ */
21
+ export declare function convertToRotatedRect(x: number, y: number, width: number, height: number, rotation: number, unW: number, unH: number): {
22
+ x: number;
23
+ y: number;
24
+ width: number;
25
+ height: number;
26
+ };
27
+ /**
28
+ * Returns SVG transform string for SVG groups to match page rotation.
29
+ */
30
+ export declare function getRotationTransform(rotation: number, unW: number, unH: number): string | undefined;
31
+ /** Normalizes any degree value into [0, 360). */
32
+ export declare function normalizeRotation(rotation: number): number;