@jacktea/pdf-viewer-react 0.1.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.
@@ -0,0 +1,85 @@
1
+ import React from 'react';
2
+ import { PdfViewerConfig, Annotation, AnnotationComment, CommentThread, PdfViewerElement, ServerWritebackPayload } from '@jacktea/pdf-viewer-component';
3
+
4
+ declare global {
5
+ namespace JSX {
6
+ interface IntrinsicElements {
7
+ "pdf-viewer": React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & {
8
+ class?: string;
9
+ src?: string | Blob | ArrayBuffer | Uint8Array;
10
+ page?: number;
11
+ scale?: number | string;
12
+ rotation?: number;
13
+ theme?: "light" | "dark" | "sepia" | "nord" | "high-contrast" | string;
14
+ compact?: boolean;
15
+ "scale-mode"?: "page-width" | "page-fit" | "auto";
16
+ locale?: string;
17
+ }, HTMLElement>;
18
+ }
19
+ }
20
+ }
21
+ interface PdfViewerProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange'> {
22
+ src?: string | Blob | ArrayBuffer | Uint8Array;
23
+ page?: number;
24
+ scale?: number | string;
25
+ rotation?: number;
26
+ theme?: "light" | "dark" | "sepia" | "nord" | "high-contrast" | string;
27
+ compact?: boolean;
28
+ scaleMode?: "page-width" | "page-fit" | "auto";
29
+ locale?: string;
30
+ config?: PdfViewerConfig;
31
+ onPageChange?: (page: number, pageCount: number) => void;
32
+ onZoomChange?: (scale: number) => void;
33
+ onDocumentChange?: (pageCount: number, pageOrder: number[], source?: string) => void;
34
+ onAnnotationSelect?: (annotationId: string | null) => void;
35
+ onAnnotationAdd?: (annotation: Annotation) => void;
36
+ onAnnotationUpdate?: (annotation: Annotation) => void;
37
+ onAnnotationRemove?: (annotation: Annotation) => void;
38
+ onCommentAdd?: (comment: AnnotationComment, thread: CommentThread) => void;
39
+ onCommentUpdate?: (comment: AnnotationComment, thread: CommentThread) => void;
40
+ onCommentRemove?: (comment: AnnotationComment, thread: CommentThread) => void;
41
+ onPanelToggle?: (state: "open" | "close") => void;
42
+ onOutlineSelect?: (pageIndex: number) => void;
43
+ onThumbnailSelect?: (pageIndex: number) => void;
44
+ onExportError?: (message: string) => void;
45
+ onWatermarkApplied?: (watermark: any) => void;
46
+ onThemeChange?: (theme: "light" | "dark" | "sepia" | "nord" | "high-contrast" | string) => void;
47
+ onViewerModeChange?: (mode: string) => void;
48
+ onScaleModeChange?: (mode: string) => void;
49
+ onPreviewModeChange?: (mode: string) => void;
50
+ onAnnotationToolChange?: (tool: string) => void;
51
+ onHistoryChange?: (action: "undo" | "redo") => void;
52
+ }
53
+ interface PdfViewerRef {
54
+ element: PdfViewerElement | null;
55
+ setPage: (page: number) => void;
56
+ zoomIn: () => void;
57
+ zoomOut: () => void;
58
+ rotate: () => void;
59
+ setLocale: (locale: string) => void;
60
+ setDocumentMode: (mode: "normal" | "preview") => void;
61
+ getAnnotations: () => Annotation[];
62
+ setAnnotations: (annotations: Annotation[]) => void;
63
+ addAnnotation: (annotation: Annotation) => void;
64
+ updateAnnotation: (annotation: Annotation) => void;
65
+ removeAnnotation: (id: string) => void;
66
+ selectAnnotation: (id: string | null) => void;
67
+ getCommentThreads: () => CommentThread[];
68
+ setCommentThreads: (threads: CommentThread[]) => void;
69
+ addComment: (comment: AnnotationComment) => void;
70
+ updateComment: (comment: AnnotationComment) => void;
71
+ removeComment: (annotationId: string, commentId: string) => void;
72
+ resolveCommentThread: (annotationId: string) => void;
73
+ reopenCommentThread: (annotationId: string) => void;
74
+ writeBackFromServer: (payload: ServerWritebackPayload) => void;
75
+ deletePage: (pageIndex: number) => void;
76
+ movePage: (fromIndex: number, toIndex: number) => void;
77
+ undo: () => void;
78
+ redo: () => void;
79
+ exportPdf: (embedWatermark?: boolean) => Promise<Uint8Array>;
80
+ exportData: () => Promise<any>;
81
+ importData: (data: any) => Promise<void>;
82
+ }
83
+ declare const PdfViewer: React.ForwardRefExoticComponent<PdfViewerProps & React.RefAttributes<PdfViewerRef>>;
84
+
85
+ export { PdfViewer, type PdfViewerProps, type PdfViewerRef };
@@ -0,0 +1,85 @@
1
+ import React from 'react';
2
+ import { PdfViewerConfig, Annotation, AnnotationComment, CommentThread, PdfViewerElement, ServerWritebackPayload } from '@jacktea/pdf-viewer-component';
3
+
4
+ declare global {
5
+ namespace JSX {
6
+ interface IntrinsicElements {
7
+ "pdf-viewer": React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & {
8
+ class?: string;
9
+ src?: string | Blob | ArrayBuffer | Uint8Array;
10
+ page?: number;
11
+ scale?: number | string;
12
+ rotation?: number;
13
+ theme?: "light" | "dark" | "sepia" | "nord" | "high-contrast" | string;
14
+ compact?: boolean;
15
+ "scale-mode"?: "page-width" | "page-fit" | "auto";
16
+ locale?: string;
17
+ }, HTMLElement>;
18
+ }
19
+ }
20
+ }
21
+ interface PdfViewerProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange'> {
22
+ src?: string | Blob | ArrayBuffer | Uint8Array;
23
+ page?: number;
24
+ scale?: number | string;
25
+ rotation?: number;
26
+ theme?: "light" | "dark" | "sepia" | "nord" | "high-contrast" | string;
27
+ compact?: boolean;
28
+ scaleMode?: "page-width" | "page-fit" | "auto";
29
+ locale?: string;
30
+ config?: PdfViewerConfig;
31
+ onPageChange?: (page: number, pageCount: number) => void;
32
+ onZoomChange?: (scale: number) => void;
33
+ onDocumentChange?: (pageCount: number, pageOrder: number[], source?: string) => void;
34
+ onAnnotationSelect?: (annotationId: string | null) => void;
35
+ onAnnotationAdd?: (annotation: Annotation) => void;
36
+ onAnnotationUpdate?: (annotation: Annotation) => void;
37
+ onAnnotationRemove?: (annotation: Annotation) => void;
38
+ onCommentAdd?: (comment: AnnotationComment, thread: CommentThread) => void;
39
+ onCommentUpdate?: (comment: AnnotationComment, thread: CommentThread) => void;
40
+ onCommentRemove?: (comment: AnnotationComment, thread: CommentThread) => void;
41
+ onPanelToggle?: (state: "open" | "close") => void;
42
+ onOutlineSelect?: (pageIndex: number) => void;
43
+ onThumbnailSelect?: (pageIndex: number) => void;
44
+ onExportError?: (message: string) => void;
45
+ onWatermarkApplied?: (watermark: any) => void;
46
+ onThemeChange?: (theme: "light" | "dark" | "sepia" | "nord" | "high-contrast" | string) => void;
47
+ onViewerModeChange?: (mode: string) => void;
48
+ onScaleModeChange?: (mode: string) => void;
49
+ onPreviewModeChange?: (mode: string) => void;
50
+ onAnnotationToolChange?: (tool: string) => void;
51
+ onHistoryChange?: (action: "undo" | "redo") => void;
52
+ }
53
+ interface PdfViewerRef {
54
+ element: PdfViewerElement | null;
55
+ setPage: (page: number) => void;
56
+ zoomIn: () => void;
57
+ zoomOut: () => void;
58
+ rotate: () => void;
59
+ setLocale: (locale: string) => void;
60
+ setDocumentMode: (mode: "normal" | "preview") => void;
61
+ getAnnotations: () => Annotation[];
62
+ setAnnotations: (annotations: Annotation[]) => void;
63
+ addAnnotation: (annotation: Annotation) => void;
64
+ updateAnnotation: (annotation: Annotation) => void;
65
+ removeAnnotation: (id: string) => void;
66
+ selectAnnotation: (id: string | null) => void;
67
+ getCommentThreads: () => CommentThread[];
68
+ setCommentThreads: (threads: CommentThread[]) => void;
69
+ addComment: (comment: AnnotationComment) => void;
70
+ updateComment: (comment: AnnotationComment) => void;
71
+ removeComment: (annotationId: string, commentId: string) => void;
72
+ resolveCommentThread: (annotationId: string) => void;
73
+ reopenCommentThread: (annotationId: string) => void;
74
+ writeBackFromServer: (payload: ServerWritebackPayload) => void;
75
+ deletePage: (pageIndex: number) => void;
76
+ movePage: (fromIndex: number, toIndex: number) => void;
77
+ undo: () => void;
78
+ redo: () => void;
79
+ exportPdf: (embedWatermark?: boolean) => Promise<Uint8Array>;
80
+ exportData: () => Promise<any>;
81
+ importData: (data: any) => Promise<void>;
82
+ }
83
+ declare const PdfViewer: React.ForwardRefExoticComponent<PdfViewerProps & React.RefAttributes<PdfViewerRef>>;
84
+
85
+ export { PdfViewer, type PdfViewerProps, type PdfViewerRef };
package/dist/index.js ADDED
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ PdfViewer: () => PdfViewer
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/PdfViewer.tsx
28
+ var import_react = require("react");
29
+ var import_pdf_viewer_component = require("@jacktea/pdf-viewer-component");
30
+ var import_jsx_runtime = require("react/jsx-runtime");
31
+ var PdfViewer = (0, import_react.forwardRef)(
32
+ ({
33
+ src,
34
+ page,
35
+ scale,
36
+ rotation,
37
+ theme,
38
+ compact,
39
+ scaleMode,
40
+ config,
41
+ onPageChange,
42
+ onZoomChange,
43
+ onDocumentChange,
44
+ onAnnotationSelect,
45
+ onAnnotationAdd,
46
+ onAnnotationUpdate,
47
+ onAnnotationRemove,
48
+ onCommentAdd,
49
+ onCommentUpdate,
50
+ onCommentRemove,
51
+ onPanelToggle,
52
+ onOutlineSelect,
53
+ onThumbnailSelect,
54
+ onExportError,
55
+ onWatermarkApplied,
56
+ onThemeChange,
57
+ onViewerModeChange,
58
+ onScaleModeChange,
59
+ onPreviewModeChange,
60
+ onAnnotationToolChange,
61
+ onHistoryChange,
62
+ className,
63
+ style,
64
+ ...props
65
+ }, ref) => {
66
+ const elementRef = (0, import_react.useRef)(null);
67
+ (0, import_react.useImperativeHandle)(ref, () => ({
68
+ element: elementRef.current,
69
+ setPage: (p) => elementRef.current?.setPage(p),
70
+ zoomIn: () => elementRef.current?.zoomIn(),
71
+ zoomOut: () => elementRef.current?.zoomOut(),
72
+ rotate: () => elementRef.current?.rotate(),
73
+ setLocale: (locale) => elementRef.current?.setLocale(locale),
74
+ setDocumentMode: (mode) => elementRef.current?.setDocumentMode(mode),
75
+ getAnnotations: () => elementRef.current?.getAnnotations() ?? [],
76
+ setAnnotations: (annotations) => elementRef.current?.setAnnotations(annotations),
77
+ addAnnotation: (annotation) => elementRef.current?.addAnnotation(annotation),
78
+ updateAnnotation: (annotation) => elementRef.current?.updateAnnotation(annotation),
79
+ removeAnnotation: (id) => elementRef.current?.removeAnnotation(id),
80
+ selectAnnotation: (id) => elementRef.current?.selectAnnotation(id),
81
+ getCommentThreads: () => elementRef.current?.getCommentThreads() ?? [],
82
+ setCommentThreads: (threads) => elementRef.current?.setCommentThreads(threads),
83
+ addComment: (comment) => elementRef.current?.addComment(comment),
84
+ updateComment: (comment) => elementRef.current?.updateComment(comment),
85
+ removeComment: (annotationId, commentId) => elementRef.current?.removeComment(annotationId, commentId),
86
+ resolveCommentThread: (annotationId) => elementRef.current?.resolveCommentThread(annotationId),
87
+ reopenCommentThread: (annotationId) => elementRef.current?.reopenCommentThread(annotationId),
88
+ writeBackFromServer: (payload) => elementRef.current?.writeBackFromServer(payload),
89
+ deletePage: (pageIndex) => elementRef.current?.deletePage(pageIndex),
90
+ movePage: (from, to) => elementRef.current?.movePage(from, to),
91
+ undo: () => elementRef.current?.undo(),
92
+ redo: () => elementRef.current?.redo(),
93
+ exportPdf: (embedWatermark) => elementRef.current.exportPdf(embedWatermark),
94
+ exportData: () => elementRef.current.exportData(),
95
+ importData: (data) => elementRef.current.importData(data)
96
+ }));
97
+ (0, import_react.useEffect)(() => {
98
+ if (config && elementRef.current) {
99
+ elementRef.current.setConfig(config);
100
+ }
101
+ }, [config]);
102
+ (0, import_react.useEffect)(() => {
103
+ const el = elementRef.current;
104
+ if (!el) return;
105
+ const handlers = [
106
+ ["pagechange", (e) => onPageChange?.(e.detail.page, e.detail.pageCount)],
107
+ ["zoomchange", (e) => onZoomChange?.(e.detail.scale)],
108
+ ["documentchange", (e) => onDocumentChange?.(e.detail.pageCount, e.detail.pageOrder, e.detail.source)],
109
+ ["annotation:select", (e) => onAnnotationSelect?.(e.detail.annotationId)],
110
+ ["annotation:add", (e) => onAnnotationAdd?.(e.detail.annotation)],
111
+ ["annotation:update", (e) => onAnnotationUpdate?.(e.detail.annotation)],
112
+ ["annotation:remove", (e) => onAnnotationRemove?.(e.detail.annotation)],
113
+ ["comment:add", (e) => onCommentAdd?.(e.detail.comment, e.detail.thread)],
114
+ ["comment:update", (e) => onCommentUpdate?.(e.detail.comment, e.detail.thread)],
115
+ ["comment:remove", (e) => onCommentRemove?.(e.detail.comment, e.detail.thread)],
116
+ ["panel:toggle", (e) => onPanelToggle?.(e.detail.state)],
117
+ ["outline:select", (e) => onOutlineSelect?.(e.detail.pageIndex)],
118
+ ["thumbnail:select", (e) => onThumbnailSelect?.(e.detail.pageIndex)],
119
+ ["export:error", (e) => onExportError?.(e.detail.message)],
120
+ ["watermark:applied", (e) => onWatermarkApplied?.(e.detail.watermark)],
121
+ ["theme:change", (e) => onThemeChange?.(e.detail.theme)],
122
+ ["viewer:mode:change", (e) => onViewerModeChange?.(e.detail.mode)],
123
+ ["scale:mode:change", (e) => onScaleModeChange?.(e.detail.mode)],
124
+ ["preview:mode:change", (e) => onPreviewModeChange?.(e.detail.mode)],
125
+ ["annotation:tool:change", (e) => onAnnotationToolChange?.(e.detail.tool)],
126
+ ["history:change", (e) => onHistoryChange?.(e.detail.action)]
127
+ ];
128
+ handlers.forEach(([event, handler]) => {
129
+ if (handler) el.addEventListener(event, handler);
130
+ });
131
+ return () => {
132
+ handlers.forEach(([event, handler]) => {
133
+ if (handler) el.removeEventListener(event, handler);
134
+ });
135
+ };
136
+ }, [
137
+ onPageChange,
138
+ onZoomChange,
139
+ onDocumentChange,
140
+ onAnnotationSelect,
141
+ onAnnotationAdd,
142
+ onAnnotationUpdate,
143
+ onAnnotationRemove,
144
+ onCommentAdd,
145
+ onCommentUpdate,
146
+ onCommentRemove,
147
+ onPanelToggle,
148
+ onOutlineSelect,
149
+ onThumbnailSelect,
150
+ onExportError,
151
+ onWatermarkApplied,
152
+ onThemeChange,
153
+ onViewerModeChange,
154
+ onScaleModeChange,
155
+ onPreviewModeChange,
156
+ onAnnotationToolChange,
157
+ onHistoryChange
158
+ ]);
159
+ (0, import_react.useEffect)(() => {
160
+ if (!elementRef.current) return;
161
+ if (src && typeof src !== "string") {
162
+ elementRef.current.loadDocument(src);
163
+ }
164
+ if (src) {
165
+ elementRef.current.loadDocument(src);
166
+ }
167
+ }, [src]);
168
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
169
+ "pdf-viewer",
170
+ {
171
+ ref: elementRef,
172
+ class: className,
173
+ page,
174
+ scale,
175
+ rotation,
176
+ theme,
177
+ compact,
178
+ "scale-mode": scaleMode,
179
+ locale: props.locale,
180
+ ...props
181
+ }
182
+ );
183
+ }
184
+ );
185
+ // Annotate the CommonJS export names for ESM import in node:
186
+ 0 && (module.exports = {
187
+ PdfViewer
188
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,166 @@
1
+ // src/PdfViewer.tsx
2
+ import {
3
+ useEffect,
4
+ useRef,
5
+ useImperativeHandle,
6
+ forwardRef
7
+ } from "react";
8
+ import "@jacktea/pdf-viewer-component";
9
+ import { jsx } from "react/jsx-runtime";
10
+ var PdfViewer = forwardRef(
11
+ ({
12
+ src,
13
+ page,
14
+ scale,
15
+ rotation,
16
+ theme,
17
+ compact,
18
+ scaleMode,
19
+ config,
20
+ onPageChange,
21
+ onZoomChange,
22
+ onDocumentChange,
23
+ onAnnotationSelect,
24
+ onAnnotationAdd,
25
+ onAnnotationUpdate,
26
+ onAnnotationRemove,
27
+ onCommentAdd,
28
+ onCommentUpdate,
29
+ onCommentRemove,
30
+ onPanelToggle,
31
+ onOutlineSelect,
32
+ onThumbnailSelect,
33
+ onExportError,
34
+ onWatermarkApplied,
35
+ onThemeChange,
36
+ onViewerModeChange,
37
+ onScaleModeChange,
38
+ onPreviewModeChange,
39
+ onAnnotationToolChange,
40
+ onHistoryChange,
41
+ className,
42
+ style,
43
+ ...props
44
+ }, ref) => {
45
+ const elementRef = useRef(null);
46
+ useImperativeHandle(ref, () => ({
47
+ element: elementRef.current,
48
+ setPage: (p) => elementRef.current?.setPage(p),
49
+ zoomIn: () => elementRef.current?.zoomIn(),
50
+ zoomOut: () => elementRef.current?.zoomOut(),
51
+ rotate: () => elementRef.current?.rotate(),
52
+ setLocale: (locale) => elementRef.current?.setLocale(locale),
53
+ setDocumentMode: (mode) => elementRef.current?.setDocumentMode(mode),
54
+ getAnnotations: () => elementRef.current?.getAnnotations() ?? [],
55
+ setAnnotations: (annotations) => elementRef.current?.setAnnotations(annotations),
56
+ addAnnotation: (annotation) => elementRef.current?.addAnnotation(annotation),
57
+ updateAnnotation: (annotation) => elementRef.current?.updateAnnotation(annotation),
58
+ removeAnnotation: (id) => elementRef.current?.removeAnnotation(id),
59
+ selectAnnotation: (id) => elementRef.current?.selectAnnotation(id),
60
+ getCommentThreads: () => elementRef.current?.getCommentThreads() ?? [],
61
+ setCommentThreads: (threads) => elementRef.current?.setCommentThreads(threads),
62
+ addComment: (comment) => elementRef.current?.addComment(comment),
63
+ updateComment: (comment) => elementRef.current?.updateComment(comment),
64
+ removeComment: (annotationId, commentId) => elementRef.current?.removeComment(annotationId, commentId),
65
+ resolveCommentThread: (annotationId) => elementRef.current?.resolveCommentThread(annotationId),
66
+ reopenCommentThread: (annotationId) => elementRef.current?.reopenCommentThread(annotationId),
67
+ writeBackFromServer: (payload) => elementRef.current?.writeBackFromServer(payload),
68
+ deletePage: (pageIndex) => elementRef.current?.deletePage(pageIndex),
69
+ movePage: (from, to) => elementRef.current?.movePage(from, to),
70
+ undo: () => elementRef.current?.undo(),
71
+ redo: () => elementRef.current?.redo(),
72
+ exportPdf: (embedWatermark) => elementRef.current.exportPdf(embedWatermark),
73
+ exportData: () => elementRef.current.exportData(),
74
+ importData: (data) => elementRef.current.importData(data)
75
+ }));
76
+ useEffect(() => {
77
+ if (config && elementRef.current) {
78
+ elementRef.current.setConfig(config);
79
+ }
80
+ }, [config]);
81
+ useEffect(() => {
82
+ const el = elementRef.current;
83
+ if (!el) return;
84
+ const handlers = [
85
+ ["pagechange", (e) => onPageChange?.(e.detail.page, e.detail.pageCount)],
86
+ ["zoomchange", (e) => onZoomChange?.(e.detail.scale)],
87
+ ["documentchange", (e) => onDocumentChange?.(e.detail.pageCount, e.detail.pageOrder, e.detail.source)],
88
+ ["annotation:select", (e) => onAnnotationSelect?.(e.detail.annotationId)],
89
+ ["annotation:add", (e) => onAnnotationAdd?.(e.detail.annotation)],
90
+ ["annotation:update", (e) => onAnnotationUpdate?.(e.detail.annotation)],
91
+ ["annotation:remove", (e) => onAnnotationRemove?.(e.detail.annotation)],
92
+ ["comment:add", (e) => onCommentAdd?.(e.detail.comment, e.detail.thread)],
93
+ ["comment:update", (e) => onCommentUpdate?.(e.detail.comment, e.detail.thread)],
94
+ ["comment:remove", (e) => onCommentRemove?.(e.detail.comment, e.detail.thread)],
95
+ ["panel:toggle", (e) => onPanelToggle?.(e.detail.state)],
96
+ ["outline:select", (e) => onOutlineSelect?.(e.detail.pageIndex)],
97
+ ["thumbnail:select", (e) => onThumbnailSelect?.(e.detail.pageIndex)],
98
+ ["export:error", (e) => onExportError?.(e.detail.message)],
99
+ ["watermark:applied", (e) => onWatermarkApplied?.(e.detail.watermark)],
100
+ ["theme:change", (e) => onThemeChange?.(e.detail.theme)],
101
+ ["viewer:mode:change", (e) => onViewerModeChange?.(e.detail.mode)],
102
+ ["scale:mode:change", (e) => onScaleModeChange?.(e.detail.mode)],
103
+ ["preview:mode:change", (e) => onPreviewModeChange?.(e.detail.mode)],
104
+ ["annotation:tool:change", (e) => onAnnotationToolChange?.(e.detail.tool)],
105
+ ["history:change", (e) => onHistoryChange?.(e.detail.action)]
106
+ ];
107
+ handlers.forEach(([event, handler]) => {
108
+ if (handler) el.addEventListener(event, handler);
109
+ });
110
+ return () => {
111
+ handlers.forEach(([event, handler]) => {
112
+ if (handler) el.removeEventListener(event, handler);
113
+ });
114
+ };
115
+ }, [
116
+ onPageChange,
117
+ onZoomChange,
118
+ onDocumentChange,
119
+ onAnnotationSelect,
120
+ onAnnotationAdd,
121
+ onAnnotationUpdate,
122
+ onAnnotationRemove,
123
+ onCommentAdd,
124
+ onCommentUpdate,
125
+ onCommentRemove,
126
+ onPanelToggle,
127
+ onOutlineSelect,
128
+ onThumbnailSelect,
129
+ onExportError,
130
+ onWatermarkApplied,
131
+ onThemeChange,
132
+ onViewerModeChange,
133
+ onScaleModeChange,
134
+ onPreviewModeChange,
135
+ onAnnotationToolChange,
136
+ onHistoryChange
137
+ ]);
138
+ useEffect(() => {
139
+ if (!elementRef.current) return;
140
+ if (src && typeof src !== "string") {
141
+ elementRef.current.loadDocument(src);
142
+ }
143
+ if (src) {
144
+ elementRef.current.loadDocument(src);
145
+ }
146
+ }, [src]);
147
+ return /* @__PURE__ */ jsx(
148
+ "pdf-viewer",
149
+ {
150
+ ref: elementRef,
151
+ class: className,
152
+ page,
153
+ scale,
154
+ rotation,
155
+ theme,
156
+ compact,
157
+ "scale-mode": scaleMode,
158
+ locale: props.locale,
159
+ ...props
160
+ }
161
+ );
162
+ }
163
+ );
164
+ export {
165
+ PdfViewer
166
+ };
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@jacktea/pdf-viewer-react",
3
+ "version": "0.1.3",
4
+ "private": false,
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.mjs",
15
+ "require": "./dist/index.js"
16
+ }
17
+ },
18
+ "peerDependencies": {
19
+ "react": ">=16.8.0",
20
+ "react-dom": ">=16.8.0"
21
+ },
22
+ "dependencies": {
23
+ "@jacktea/pdf-viewer-component": "0.1.3"
24
+ },
25
+ "devDependencies": {
26
+ "@types/react": "^18.2.0",
27
+ "@types/react-dom": "^18.2.0",
28
+ "react": "^18.2.0",
29
+ "react-dom": "^18.2.0",
30
+ "tsup": "^8.0.1",
31
+ "typescript": "^5.3.3"
32
+ },
33
+ "scripts": {
34
+ "build": "tsup src/index.ts --format cjs,esm --dts",
35
+ "typecheck": "tsc -p tsconfig.json --noEmit --noUnusedLocals false --noUnusedParameters false",
36
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
37
+ "lint": "eslint src --ext ts,tsx",
38
+ "clean": "rm -rf dist"
39
+ }
40
+ }