@tawqi3i/pdf-viewer 0.1.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/README.md +162 -0
- package/dist/index.js +1717 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +1 -0
- package/index.d.ts +350 -0
- package/package.json +71 -0
- package/vite-plugin.d.ts +18 -0
- package/vite-plugin.js +50 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Core types
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
export declare const TOOL: {
|
|
8
|
+
readonly TEXT: "text";
|
|
9
|
+
readonly STAMP: "stamp";
|
|
10
|
+
readonly SIGNATURE: "Esig";
|
|
11
|
+
};
|
|
12
|
+
export type AnnotationType = (typeof TOOL)[keyof typeof TOOL];
|
|
13
|
+
|
|
14
|
+
export interface Stamp {
|
|
15
|
+
id: string;
|
|
16
|
+
label: string;
|
|
17
|
+
/** CSS color for label stamps */
|
|
18
|
+
color?: string;
|
|
19
|
+
/** CSS background color for label stamps */
|
|
20
|
+
bg?: string;
|
|
21
|
+
/** Data URL — when set, the stamp renders as an image */
|
|
22
|
+
imageUrl?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export declare const DEFAULT_STAMPS: Stamp[];
|
|
26
|
+
|
|
27
|
+
/** Coordinates are normalized (0–1) relative to the page they sit on. */
|
|
28
|
+
export interface Annotation {
|
|
29
|
+
id: string;
|
|
30
|
+
type: AnnotationType;
|
|
31
|
+
pageIndex: number;
|
|
32
|
+
normX: number;
|
|
33
|
+
normY: number;
|
|
34
|
+
normW: number;
|
|
35
|
+
normH: number;
|
|
36
|
+
/** TOOL.TEXT only */
|
|
37
|
+
content?: string;
|
|
38
|
+
/** TOOL.STAMP only */
|
|
39
|
+
stamp?: Stamp;
|
|
40
|
+
/** TOOL.SIGNATURE only — PNG data URL */
|
|
41
|
+
imageData?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface PendingSignature {
|
|
45
|
+
imageData: string;
|
|
46
|
+
w: number;
|
|
47
|
+
h: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** GemBox toolbar-button visibility flags. */
|
|
51
|
+
export interface ViewerVisibility {
|
|
52
|
+
open?: boolean;
|
|
53
|
+
download?: boolean;
|
|
54
|
+
print?: boolean;
|
|
55
|
+
[key: string]: boolean | undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
// PdfViewer — display-only wrapper around GemBox PDF Viewer
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
|
|
62
|
+
export interface PdfViewerProps {
|
|
63
|
+
/** URL string opened directly by the viewer. Ignored when fileBlob is set. */
|
|
64
|
+
fileUrl?: string | null;
|
|
65
|
+
/** Blob/File source; takes precedence over fileUrl. */
|
|
66
|
+
fileBlob?: Blob | null;
|
|
67
|
+
height?: string;
|
|
68
|
+
width?: string;
|
|
69
|
+
className?: string;
|
|
70
|
+
/** GemBox license key. Defaults to the free limited key. */
|
|
71
|
+
licenseKey?: string;
|
|
72
|
+
theme?: string | null;
|
|
73
|
+
/** Hides open/download/print unless overridden via visibility. */
|
|
74
|
+
readOnly?: boolean;
|
|
75
|
+
visibility?: ViewerVisibility | null;
|
|
76
|
+
onLoad?: () => void;
|
|
77
|
+
onError?: (err: unknown) => void;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export declare const PdfViewer: React.NamedExoticComponent<PdfViewerProps>;
|
|
81
|
+
|
|
82
|
+
// ---------------------------------------------------------------------------
|
|
83
|
+
// PdfAnnotator — turn-key viewer + annotation workspace
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
export interface PdfAnnotatorLabels {
|
|
87
|
+
completeButton?: string;
|
|
88
|
+
completeSending?: string;
|
|
89
|
+
completeSuccess?: string;
|
|
90
|
+
completeErrorPrefix?: string;
|
|
91
|
+
noFileOpen?: string;
|
|
92
|
+
loadingDocument?: string;
|
|
93
|
+
openFile?: string;
|
|
94
|
+
changeFile?: string;
|
|
95
|
+
renderError?: string;
|
|
96
|
+
saveUnavailable?: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface PdfAnnotatorProps {
|
|
100
|
+
/** Controlled document source. Internal uploads sync back via onFileChange. */
|
|
101
|
+
fileBlob?: File | Blob | null;
|
|
102
|
+
/** URL source used when no blob is set (display only — baking needs a blob). */
|
|
103
|
+
fileUrl?: string | null;
|
|
104
|
+
/** Show the built-in open/change/close buttons and drag-drop empty state. */
|
|
105
|
+
allowFileUpload?: boolean;
|
|
106
|
+
/** Branding slot rendered at the left of the header bar. */
|
|
107
|
+
header?: React.ReactNode;
|
|
108
|
+
/** Show a loading spinner while the host app fetches a remote document. */
|
|
109
|
+
loading?: boolean;
|
|
110
|
+
stamps?: Stamp[];
|
|
111
|
+
licenseKey?: string;
|
|
112
|
+
theme?: string | null;
|
|
113
|
+
visibility?: ViewerVisibility | null;
|
|
114
|
+
/** Hide all annotation UI; view only. */
|
|
115
|
+
readOnly?: boolean;
|
|
116
|
+
/** Marks the document as signed (changes the save button tooltip). */
|
|
117
|
+
isSigned?: boolean;
|
|
118
|
+
saveAlwaysEnabled?: boolean;
|
|
119
|
+
/** Tooltip shown on the filename in the header. */
|
|
120
|
+
documentTitle?: string | null;
|
|
121
|
+
/** Host-supplied error (e.g. remote fetch failure) shown in the empty state. */
|
|
122
|
+
errorMessage?: string | null;
|
|
123
|
+
labels?: PdfAnnotatorLabels;
|
|
124
|
+
/** Fired when the user opens or closes a file through the built-in UI. */
|
|
125
|
+
onFileChange?: (file: File | null) => void;
|
|
126
|
+
/** Save/download button behavior — entirely host-defined. */
|
|
127
|
+
onSave?: (file: File | Blob | null, annotations: Annotation[]) => void;
|
|
128
|
+
/**
|
|
129
|
+
* Complete button behavior (e.g. seal/send an envelope). Async errors are
|
|
130
|
+
* shown in the built-in snackbar; on success annotations are cleared.
|
|
131
|
+
* The button renders only when this prop is provided.
|
|
132
|
+
*/
|
|
133
|
+
onComplete?: (
|
|
134
|
+
file: File | Blob,
|
|
135
|
+
annotations: Annotation[],
|
|
136
|
+
) => void | Promise<void>;
|
|
137
|
+
onError?: (err: unknown) => void;
|
|
138
|
+
className?: string;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export declare function PdfAnnotator(props: PdfAnnotatorProps): React.JSX.Element;
|
|
142
|
+
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
// useAnnotations — annotation state machine for custom layouts
|
|
145
|
+
// ---------------------------------------------------------------------------
|
|
146
|
+
|
|
147
|
+
export interface UseAnnotationsOptions {
|
|
148
|
+
stamps?: Stamp[];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface UseAnnotationsResult {
|
|
152
|
+
annotations: Annotation[];
|
|
153
|
+
setAnnotations: React.Dispatch<React.SetStateAction<Annotation[]>>;
|
|
154
|
+
activeTool: AnnotationType | null;
|
|
155
|
+
selectedStamp: Stamp | null;
|
|
156
|
+
setSelectedStamp: (stamp: Stamp) => void;
|
|
157
|
+
showSignatureModal: boolean;
|
|
158
|
+
setShowSignatureModal: (open: boolean) => void;
|
|
159
|
+
pendingSignature: PendingSignature | null;
|
|
160
|
+
handleToolSelect: (tool: AnnotationType | null) => void;
|
|
161
|
+
handleSignatureConfirm: (imageData: string, w: number, h: number) => void;
|
|
162
|
+
handlePlace: (
|
|
163
|
+
pageIndex: number,
|
|
164
|
+
normX: number,
|
|
165
|
+
normY: number,
|
|
166
|
+
pageW: number,
|
|
167
|
+
pageH: number,
|
|
168
|
+
) => void;
|
|
169
|
+
handleDelete: (id: string) => void;
|
|
170
|
+
handleMove: (id: string, pageIndex: number, normX: number, normY: number) => void;
|
|
171
|
+
handleResize: (id: string, normW: number, normH: number) => void;
|
|
172
|
+
handleTextChange: (id: string, content: string) => void;
|
|
173
|
+
handleUndo: () => void;
|
|
174
|
+
handleClearAll: () => void;
|
|
175
|
+
reset: () => void;
|
|
176
|
+
unsignedCount: number;
|
|
177
|
+
hint: string | null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export declare function useAnnotations(
|
|
181
|
+
options?: UseAnnotationsOptions,
|
|
182
|
+
): UseAnnotationsResult;
|
|
183
|
+
|
|
184
|
+
// ---------------------------------------------------------------------------
|
|
185
|
+
// Building blocks
|
|
186
|
+
// ---------------------------------------------------------------------------
|
|
187
|
+
|
|
188
|
+
export interface AnnotationLayerProps {
|
|
189
|
+
annotations: Annotation[];
|
|
190
|
+
activeTool: AnnotationType | null;
|
|
191
|
+
pendingSignature: PendingSignature | null;
|
|
192
|
+
onPlace: UseAnnotationsResult["handlePlace"];
|
|
193
|
+
onDelete: UseAnnotationsResult["handleDelete"];
|
|
194
|
+
onMove: UseAnnotationsResult["handleMove"];
|
|
195
|
+
onResize: UseAnnotationsResult["handleResize"];
|
|
196
|
+
onTextChange: UseAnnotationsResult["handleTextChange"];
|
|
197
|
+
}
|
|
198
|
+
export declare function AnnotationLayer(
|
|
199
|
+
props: AnnotationLayerProps,
|
|
200
|
+
): React.JSX.Element;
|
|
201
|
+
|
|
202
|
+
export declare function AnnotationItem(props: {
|
|
203
|
+
ann: Annotation;
|
|
204
|
+
pos: { x: number; y: number; w: number; h: number } | undefined;
|
|
205
|
+
onDelete: (id: string) => void;
|
|
206
|
+
onDragStart: (e: React.MouseEvent, id: string) => void;
|
|
207
|
+
onResizeStart: (e: React.MouseEvent, id: string) => void;
|
|
208
|
+
onTextChange: (id: string, content: string) => void;
|
|
209
|
+
}): React.JSX.Element | null;
|
|
210
|
+
|
|
211
|
+
export interface AnnotationToolbarProps {
|
|
212
|
+
activeTool: AnnotationType | null;
|
|
213
|
+
onToolSelect: (tool: AnnotationType | null) => void;
|
|
214
|
+
selectedStamp: Stamp | null;
|
|
215
|
+
onStampSelect: (stamp: Stamp) => void;
|
|
216
|
+
onUndo: () => void;
|
|
217
|
+
onClearAll: () => void;
|
|
218
|
+
onSave: () => void;
|
|
219
|
+
count: number;
|
|
220
|
+
saveAlwaysEnabled?: boolean;
|
|
221
|
+
isSigned?: boolean;
|
|
222
|
+
stamps?: Stamp[];
|
|
223
|
+
}
|
|
224
|
+
export declare function AnnotationToolbar(
|
|
225
|
+
props: AnnotationToolbarProps,
|
|
226
|
+
): React.JSX.Element;
|
|
227
|
+
|
|
228
|
+
export declare function ToolBtn(props: {
|
|
229
|
+
active: boolean;
|
|
230
|
+
onClick: () => void;
|
|
231
|
+
title: string;
|
|
232
|
+
disabled?: boolean;
|
|
233
|
+
danger?: boolean;
|
|
234
|
+
primary?: boolean;
|
|
235
|
+
children?: React.ReactNode;
|
|
236
|
+
}): React.JSX.Element;
|
|
237
|
+
|
|
238
|
+
export declare function SignatureModal(props: {
|
|
239
|
+
onConfirm: (imageData: string, w: number, h: number) => void;
|
|
240
|
+
onClose: () => void;
|
|
241
|
+
}): React.JSX.Element;
|
|
242
|
+
|
|
243
|
+
export declare function StampPicker(props: {
|
|
244
|
+
selected: Stamp | null;
|
|
245
|
+
onSelect: (stamp: Stamp) => void;
|
|
246
|
+
customStamps: Stamp[];
|
|
247
|
+
onImageUpload: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
248
|
+
stamps?: Stamp[];
|
|
249
|
+
}): React.JSX.Element;
|
|
250
|
+
|
|
251
|
+
export interface SnackbarMessage {
|
|
252
|
+
message: string;
|
|
253
|
+
severity?: "success" | "warning" | "error" | "info";
|
|
254
|
+
duration?: number;
|
|
255
|
+
title?: string;
|
|
256
|
+
key?: number | string;
|
|
257
|
+
}
|
|
258
|
+
export declare function Snackbar(props: {
|
|
259
|
+
snackbar: SnackbarMessage | null;
|
|
260
|
+
onDismiss: () => void;
|
|
261
|
+
}): React.JSX.Element | null;
|
|
262
|
+
export declare const SNACKBAR_VARIANTS: Record<
|
|
263
|
+
"success" | "warning" | "error" | "info",
|
|
264
|
+
{
|
|
265
|
+
accent: string;
|
|
266
|
+
outline: string;
|
|
267
|
+
icon: React.FC<{ className?: string }>;
|
|
268
|
+
title: string;
|
|
269
|
+
}
|
|
270
|
+
>;
|
|
271
|
+
|
|
272
|
+
export declare function EmptyState(props: {
|
|
273
|
+
isDragging: boolean;
|
|
274
|
+
error?: string | null;
|
|
275
|
+
onDrop: (e: React.DragEvent) => void;
|
|
276
|
+
onDragOver: (e: React.DragEvent) => void;
|
|
277
|
+
onDragLeave: () => void;
|
|
278
|
+
onBrowse: () => void;
|
|
279
|
+
}): React.JSX.Element;
|
|
280
|
+
|
|
281
|
+
// ---------------------------------------------------------------------------
|
|
282
|
+
// DOM helpers (GemBox page contract: [data-page-number], 1-based)
|
|
283
|
+
// ---------------------------------------------------------------------------
|
|
284
|
+
|
|
285
|
+
export declare function findPageElementAt(
|
|
286
|
+
clientX: number,
|
|
287
|
+
clientY: number,
|
|
288
|
+
): HTMLElement | null;
|
|
289
|
+
export declare function findPageElementByIndex(
|
|
290
|
+
pageIndex: number,
|
|
291
|
+
): HTMLElement | null;
|
|
292
|
+
|
|
293
|
+
// ---------------------------------------------------------------------------
|
|
294
|
+
// PDF utilities
|
|
295
|
+
// ---------------------------------------------------------------------------
|
|
296
|
+
|
|
297
|
+
/** Flattens annotations into the PDF (pdf-lib) and returns base64. */
|
|
298
|
+
export declare function bakeAnnotationsToBase64(
|
|
299
|
+
pdfFile: Blob,
|
|
300
|
+
annotations: Annotation[],
|
|
301
|
+
): Promise<string>;
|
|
302
|
+
|
|
303
|
+
export interface AnnotationField {
|
|
304
|
+
top: number;
|
|
305
|
+
left: number;
|
|
306
|
+
width: number;
|
|
307
|
+
height: number;
|
|
308
|
+
pageNumber: number;
|
|
309
|
+
type: AnnotationType;
|
|
310
|
+
value: string | null;
|
|
311
|
+
}
|
|
312
|
+
/** Converts annotations to coordinate field objects (PDF points, top-left origin). */
|
|
313
|
+
export declare function annotationsToFields(
|
|
314
|
+
pdfFile: Blob,
|
|
315
|
+
annotations: Annotation[],
|
|
316
|
+
): Promise<AnnotationField[]>;
|
|
317
|
+
|
|
318
|
+
export declare function blobToBase64(blob: Blob): Promise<string>;
|
|
319
|
+
export declare function base64ToFile(
|
|
320
|
+
base64: string,
|
|
321
|
+
filename: string,
|
|
322
|
+
mimeType?: string,
|
|
323
|
+
): File;
|
|
324
|
+
export declare function dataUrlToBytes(dataUrl: string): Uint8Array;
|
|
325
|
+
export declare function stripDataUrl(s: string | null): string | null;
|
|
326
|
+
export declare function hexToRgb01(hex: string): unknown;
|
|
327
|
+
export declare function makeUuid(): string;
|
|
328
|
+
|
|
329
|
+
// ---------------------------------------------------------------------------
|
|
330
|
+
// Icons
|
|
331
|
+
// ---------------------------------------------------------------------------
|
|
332
|
+
|
|
333
|
+
type IconComponent = React.FC<{ className?: string }>;
|
|
334
|
+
export declare const PdfIcon: IconComponent;
|
|
335
|
+
export declare const UploadIcon: IconComponent;
|
|
336
|
+
export declare const CloseIcon: IconComponent;
|
|
337
|
+
export declare const DropIcon: IconComponent;
|
|
338
|
+
export declare const ErrorIcon: IconComponent;
|
|
339
|
+
export declare const TextIcon: IconComponent;
|
|
340
|
+
export declare const StampIcon: IconComponent;
|
|
341
|
+
export declare const SignatureIcon: IconComponent;
|
|
342
|
+
export declare const TrashIcon: IconComponent;
|
|
343
|
+
export declare const UndoIcon: IconComponent;
|
|
344
|
+
export declare const ImageIcon: IconComponent;
|
|
345
|
+
export declare const SaveIcon: IconComponent;
|
|
346
|
+
export declare const WarningIcon: IconComponent;
|
|
347
|
+
export declare const CheckIcon: IconComponent;
|
|
348
|
+
export declare const InfoIcon: IconComponent;
|
|
349
|
+
export declare const SendIcon: IconComponent;
|
|
350
|
+
export declare const SpinnerIcon: IconComponent;
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tawqi3i/pdf-viewer",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React PDF viewer and annotation SDK built on GemBox PDF Viewer — view, annotate, stamp, and sign PDFs.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"react",
|
|
9
|
+
"pdf",
|
|
10
|
+
"viewer",
|
|
11
|
+
"annotations",
|
|
12
|
+
"signature",
|
|
13
|
+
"esign",
|
|
14
|
+
"gembox"
|
|
15
|
+
],
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"module": "./dist/index.js",
|
|
18
|
+
"types": "./index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./styles.css": "./dist/styles.css",
|
|
25
|
+
"./vite": {
|
|
26
|
+
"types": "./vite-plugin.d.ts",
|
|
27
|
+
"import": "./vite-plugin.js"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"vite-plugin.js",
|
|
34
|
+
"vite-plugin.d.ts",
|
|
35
|
+
"index.d.ts",
|
|
36
|
+
"README.md"
|
|
37
|
+
],
|
|
38
|
+
"sideEffects": [
|
|
39
|
+
"**/*.css"
|
|
40
|
+
],
|
|
41
|
+
"scripts": {
|
|
42
|
+
"dev": "vite",
|
|
43
|
+
"build": "vite build",
|
|
44
|
+
"dev:lib": "vite build --watch",
|
|
45
|
+
"prepublishOnly": "npm run build",
|
|
46
|
+
"lint": "eslint ."
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"react": ">=18",
|
|
50
|
+
"react-dom": ">=18"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@gembox/pdfviewer": "^2026.6.101",
|
|
54
|
+
"pdf-lib": "^1.17.1"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@eslint/js": "^9.30.1",
|
|
58
|
+
"@tailwindcss/vite": "^4.2.4",
|
|
59
|
+
"@types/react": "^19.1.8",
|
|
60
|
+
"@types/react-dom": "^19.1.6",
|
|
61
|
+
"@vitejs/plugin-react": "^4.6.0",
|
|
62
|
+
"eslint": "^9.30.1",
|
|
63
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
64
|
+
"eslint-plugin-react-refresh": "^0.4.20",
|
|
65
|
+
"globals": "^16.3.0",
|
|
66
|
+
"react": "^19.1.0",
|
|
67
|
+
"react-dom": "^19.1.0",
|
|
68
|
+
"tailwindcss": "^4.2.4",
|
|
69
|
+
"vite": "^7.0.4"
|
|
70
|
+
}
|
|
71
|
+
}
|
package/vite-plugin.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface Tawqi3iPdfViewerPlugin {
|
|
2
|
+
name: string;
|
|
3
|
+
config(): {
|
|
4
|
+
define: Record<string, string>;
|
|
5
|
+
optimizeDeps: { exclude: string[] };
|
|
6
|
+
};
|
|
7
|
+
transform(
|
|
8
|
+
code: string,
|
|
9
|
+
id: string,
|
|
10
|
+
): { code: string; map: null } | undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Vite plugin that applies the GemBox PDF Viewer build workarounds
|
|
15
|
+
* (UMD pdfjs fix, Vue 3 compile-time flags, dep-optimizer exclusion)
|
|
16
|
+
* to the consuming app. Add it to the app's vite.config plugins.
|
|
17
|
+
*/
|
|
18
|
+
export default function tawqi3iPdfViewer(): Tawqi3iPdfViewerPlugin;
|
package/vite-plugin.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Vite plugin for apps consuming @tawqi3i/pdf-viewer.
|
|
2
|
+
//
|
|
3
|
+
// GemBox PDF Viewer needs three build workarounds in the consuming app:
|
|
4
|
+
//
|
|
5
|
+
// 1. Its pdfjs + worker bundles are UMD IIFEs. In Rollup's production build,
|
|
6
|
+
// @rollup/plugin-commonjs can introduce an `exports` object into scope
|
|
7
|
+
// (for React's CJS modules). GemBox's 4-branch UMD checks:
|
|
8
|
+
// 1. typeof exports&&"object"==typeof module → module.exports=e() (CJS)
|
|
9
|
+
// 2. typeof define===...&&define.amd → define(...) (AMD)
|
|
10
|
+
// 3. "object"==typeof exports → exports[key]=e() (old CJS)
|
|
11
|
+
// 4. (else) → globalThis[key]=e() (browser)
|
|
12
|
+
// If branch 1 fires, window["pdfjs-dist/build/pdf"] is never set and
|
|
13
|
+
// GemBox throws "Pdf.js needs to be referenced". We neutralise every
|
|
14
|
+
// typeof-exports guard so the browser-global branch always runs.
|
|
15
|
+
//
|
|
16
|
+
// 2. GemBox is built on Vue 3, whose runtime expects compile-time constants
|
|
17
|
+
// that a React project never defines.
|
|
18
|
+
//
|
|
19
|
+
// 3. Vite's dep optimizer can corrupt GemBox's pre-built ESM (internal
|
|
20
|
+
// Vue/FontAwesome module references), so it must be excluded.
|
|
21
|
+
export default function tawqi3iPdfViewer() {
|
|
22
|
+
return {
|
|
23
|
+
name: "tawqi3i-pdf-viewer",
|
|
24
|
+
config() {
|
|
25
|
+
return {
|
|
26
|
+
define: {
|
|
27
|
+
__VUE_OPTIONS_API__: JSON.stringify(true),
|
|
28
|
+
__VUE_PROD_DEVTOOLS__: JSON.stringify(false),
|
|
29
|
+
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: JSON.stringify(false),
|
|
30
|
+
},
|
|
31
|
+
optimizeDeps: {
|
|
32
|
+
exclude: ["@gembox/pdfviewer"],
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
transform(code, id) {
|
|
37
|
+
if (!id.includes("@gembox/pdfviewer")) return;
|
|
38
|
+
const out = code
|
|
39
|
+
// 4-branch UMD first guard: typeof exports&&"object"==typeof module
|
|
40
|
+
.replaceAll("typeof exports&&", "(!1)&&")
|
|
41
|
+
// 4-branch UMD third guard (minified): "object"==typeof exports
|
|
42
|
+
.replaceAll('"object"==typeof exports', "!1")
|
|
43
|
+
// 3-branch UMD truthy guard: typeof exports?exports[key]=…
|
|
44
|
+
.replaceAll("typeof exports?", "(!1)?")
|
|
45
|
+
// pdfjsViewer UMD (spaced): typeof exports == "object"
|
|
46
|
+
.replaceAll('typeof exports == "object"', "!1");
|
|
47
|
+
return { code: out, map: null };
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|