pdfjs-annotation-extension-for-react 0.1.2

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,439 @@
1
+ import { default as default_2 } from 'react';
2
+ import { EventBus } from 'pdfjs-dist/types/web/pdf_viewer';
3
+ import { IRect } from 'konva/lib/types';
4
+ import { PDFViewer } from 'pdfjs-dist/types/web/pdf_viewer';
5
+
6
+ declare enum AnnotationType {
7
+ NONE = -1,// 没有批注类型
8
+ SELECT = 0,// 选择批注
9
+ HIGHLIGHT = 1,// 高亮批注
10
+ STRIKEOUT = 2,// 删除线批注
11
+ UNDERLINE = 3,// 下划线批注
12
+ FREETEXT = 4,// 自由文本批注
13
+ RECTANGLE = 5,// 矩形批注
14
+ CIRCLE = 6,// 圆形批注
15
+ FREEHAND = 7,// 自由绘制批注
16
+ FREE_HIGHLIGHT = 8,// 自由高亮批注
17
+ SIGNATURE = 9,// 签名批注
18
+ STAMP = 10,// 盖章批注
19
+ NOTE = 11,// 注释
20
+ ARROW = 12,// 箭头批注
21
+ CLOUD = 13
22
+ }
23
+
24
+ declare enum CommentStatus {
25
+ Accepted = "Accepted",
26
+ Rejected = "Rejected",
27
+ Cancelled = "Cancelled",
28
+ Completed = "Completed",
29
+ None = "None",
30
+ Closed = "Closed"
31
+ }
32
+
33
+ declare type DeepPartial<T> = {
34
+ [K in keyof T]?: T[K] extends object ? (T[K] extends Function ? T[K] : DeepPartial<T[K]>) : T[K];
35
+ };
36
+
37
+ declare interface IAnnotationComment {
38
+ id: string;
39
+ title: string;
40
+ date: string | null;
41
+ content: string;
42
+ status?: CommentStatus;
43
+ }
44
+
45
+ declare interface IAnnotationContentsObj {
46
+ text: string;
47
+ image?: string;
48
+ }
49
+
50
+ export declare interface IAnnotationStore {
51
+ id: string;
52
+ pageNumber: number;
53
+ konvaString: string;
54
+ konvaClientRect: IRect;
55
+ title: string;
56
+ type: AnnotationType;
57
+ color?: string | null;
58
+ subtype: PdfjsAnnotationSubtype;
59
+ pdfjsType: PdfjsAnnotationType;
60
+ date: string | null;
61
+ contentsObj?: IAnnotationContentsObj | null;
62
+ comments: IAnnotationComment[];
63
+ user: User;
64
+ native: boolean;
65
+ }
66
+
67
+ export declare const PdfAnnotator: default_2.FC<PdfAnnotatorProps>;
68
+
69
+ /**
70
+ * PDF 注解器配置选项 / PDF Annotator Configuration Options
71
+ * 定义PDF注解器的所有可配置参数 / Defines all configurable parameters for the PDF annotator
72
+ */
73
+ export declare type PdfAnnotatorOptions = {
74
+ /**
75
+ * 颜色选项 / Color options
76
+ * 用户在注解工具中可以选择的颜色列表 / List of colors users can select in annotation tools
77
+ * @default: ['#ff0000', '#ffbe00', '#ffff00', '#83d33c', '#00b445', '#00b2f4', '#1677ff', '#001f63', '#7828a4', '#ff00ff']
78
+ */
79
+ colors?: string[];
80
+ /**
81
+ * 签名配置 / Signature configuration
82
+ * 控制签名功能的相关设置 / Settings that control signature functionality
83
+ */
84
+ signature?: {
85
+ /**
86
+ * 签名颜色选项 / Signature color options
87
+ * 签名工具可用的颜色 / Colors available for the signature tool
88
+ * @default: ['#000000', '#ff0000', '#1677ff']
89
+ */
90
+ colors?: string[];
91
+ /**
92
+ * 默认签名类型 / Default signature type
93
+ * Draw: 手绘签名 / Draw: Hand-drawn signature
94
+ * Enter: 键入签名 / Enter: Typed signature
95
+ * Upload: 上传签名 / Upload: Uploaded signature
96
+ * @default: 'Draw'
97
+ */
98
+ type?: 'Draw' | 'Enter' | 'Upload';
99
+ /**
100
+ * 最大文件大小 / Maximum file size
101
+ * 允许上传的签名文件最大字节数 / Maximum bytes allowed for uploaded signature files
102
+ * @default: 1024 * 1024 * 5 (5MB)
103
+ */
104
+ maxSize?: number;
105
+ /**
106
+ * 接受的文件类型 / Accepted file types
107
+ * 签名上传功能接受的文件扩展名 / File extensions accepted by the signature upload feature
108
+ * @default: '.png,.jpg,.jpeg,.bmp'
109
+ */
110
+ accept?: string;
111
+ /**
112
+ * 默认的签名图片 base64 string / Default signature
113
+ * @default: []
114
+ */
115
+ defaultSignature?: string[];
116
+ /**
117
+ * 手写字体列表 / Handwriting font list
118
+ * 特殊的手写字体选项 / Special handwriting font options
119
+ * @example [
120
+ {
121
+ label: '楷体',
122
+ value: 'STKaiti',
123
+ external: false,
124
+ },{
125
+ label: 'font name',
126
+ value: 'font value',
127
+ external: true,
128
+ url: 'font url'
129
+ },
130
+ {
131
+ label: '平方长安体',
132
+ value: 'PingFangChangAnTi-2',
133
+ external: true,
134
+ url: PingFangChangAnTiFont import url
135
+ }
136
+ ]
137
+ * @default: []
138
+ */
139
+ defaultFont?: {
140
+ /**
141
+ * 字体显示名称 / Font display name
142
+ */
143
+ label: string;
144
+ /**
145
+ * 实际CSS字体值 / Actual CSS font value
146
+ */
147
+ value: string;
148
+ /**
149
+ * 是否为外部字体 / Whether it's an external font
150
+ * 如果为true,则从url加载字体 / If true, font is loaded from the url
151
+ */
152
+ external: boolean;
153
+ /**
154
+ * 字体文件URL / Font file URL
155
+ * 外部字体文件的位置 / Location of the external font file
156
+ */
157
+ url?: string;
158
+ }[];
159
+ };
160
+ /**
161
+ * 盖章配置 / Stamp configuration
162
+ * 控制盖章功能的相关设置 / Settings that control stamp functionality
163
+ */
164
+ stamp?: {
165
+ /**
166
+ * 最大文件大小 / Maximum file size
167
+ * 允许上传的印章文件最大字节数 / Maximum bytes allowed for uploaded stamp files
168
+ * @default: 1024 * 1024 * 5 (5MB)
169
+ */
170
+ maxSize?: number;
171
+ /**
172
+ * 接受的文件类型 / Accepted file types
173
+ * 盖章上传功能接受的文件扩展名 / File extensions accepted by the stamp upload feature
174
+ * @default: '.png,.jpg,.jpeg,.bmp'
175
+ */
176
+ accept?: string;
177
+ /**
178
+ * 默认印章 base64 string / Default stamp
179
+ * @default: []
180
+ */
181
+ defaultStamp?: string[];
182
+ /**
183
+ * 印章编辑器配置 / Stamp editor configuration
184
+ * 控制印章编辑器外观的设置 / Settings controlling the appearance of the stamp editor
185
+ */
186
+ editor?: {
187
+ /**
188
+ * 默认背景颜色 / Default background color
189
+ * 印章的默认背景颜色 / Default background color for stamps
190
+ * @default: #00b445
191
+ */
192
+ defaultBackgroundColor?: string;
193
+ /**
194
+ * 默认边框颜色 / Default border color
195
+ * 印章的默认边框颜色 / Default border color for stamps
196
+ * @default: ''
197
+ */
198
+ defaultBorderColor?: string;
199
+ defaultBorderStyle?: 'none' | 'solid' | 'dashed';
200
+ /**
201
+ * 默认文字颜色 / Default text color
202
+ * 印章文字的默认颜色 / Default color for stamp text
203
+ * @default: '#fff'
204
+ */
205
+ defaultTextColor?: string;
206
+ /**
207
+ * 默认字体列表 / Default font
208
+ * 提供的默认字体选项,包含标签和实际CSS字体值 / Provided default font options with labels and actual CSS font values
209
+ * @default [
210
+ { label: 'Arial', value: 'Arial' },
211
+ { label: 'Times New Roman', value: 'Times New Roman' },
212
+ { label: 'Georgia', value: 'Georgia' },
213
+ { label: 'Verdana', value: 'Verdana' },
214
+ { label: 'Tahoma', value: 'Tahoma, Geneva, sans-serif' },
215
+ { label: 'Trebuchet MS', value: '"Trebuchet MS", sans-serif' },
216
+ { label: 'Courier New', value: '"Courier New", Courier, monospace' },
217
+ { label: 'Lucida Console', value: '"Lucida Console", Monaco, monospace' },
218
+ { label: '宋体', value: 'SimSun, Songti SC, STSong, 宋体, "Noto Serif SC", serif' },
219
+ { label: '黑体', value: 'Microsoft YaHei, PingFang SC, Heiti SC, SimHei, 黑体, sans-serif' },
220
+ { label: '楷体', value: 'KaiTi, KaiTi_GB2312, STFangsong, 楷体, "AR PL UKai CN", serif' }
221
+ ]
222
+ */
223
+ defaultFont?: {
224
+ /**
225
+ * 字体显示名称 / Font display name
226
+ */
227
+ label: string;
228
+ /**
229
+ * 实际CSS字体值 / Actual CSS font value
230
+ */
231
+ value: string;
232
+ }[];
233
+ };
234
+ };
235
+ };
236
+
237
+ /**
238
+ * PDF 批注组件的配置参数
239
+ */
240
+ export declare interface PdfAnnotatorProps extends PdfBaseProps {
241
+ /**
242
+ * 当前用户信息,用于标注作者标识
243
+ * @default: { id: 'null', name: 'unknown' }
244
+ */
245
+ user?: User;
246
+ /**
247
+ * 是否加载PDF自带的批注
248
+ * @default false
249
+ */
250
+ enableNativeAnnotations?: boolean;
251
+ /**
252
+ * 默认选项配置
253
+ * 如果不提供,则使用系统默认配置
254
+ */
255
+ defaultOptions?: DeepPartial<PdfAnnotatorUserOptions>;
256
+ /**
257
+ * 已有的批注列表,用于在初始化时显示已存在的批注
258
+ */
259
+ initialAnnotations?: IAnnotationStore[];
260
+ /**
261
+ * 自定义额外按钮区域组件
262
+ * 可以是一个 React 组件或者 React 元素
263
+ * 组件会接收到以下属性:
264
+ * - onSave: () => void 保存当前批注
265
+ * - getData: () => IAnnotationStore[] 获取当前批注数据
266
+ * - exportToExcel: () => void 导出到 Excel
267
+ * - exportToPdf: () => void 导出到 PDF
268
+ */
269
+ actions?: React.ReactNode | React.ComponentType<{
270
+ save: () => void;
271
+ getAnnotations: () => IAnnotationStore[];
272
+ exportToExcel: (fileName?: string) => void;
273
+ exportToPdf: (fileName?: string) => void;
274
+ }>;
275
+ /**
276
+ * 保存回调
277
+ * @param annotations IAnnotationStore
278
+ */
279
+ onSave?: (annotations: IAnnotationStore[]) => void;
280
+ /**
281
+ * 加载完成回调
282
+ */
283
+ onLoad?: () => void;
284
+ /**
285
+ * 添加批注回调
286
+ * @param annotation
287
+ * @returns
288
+ */
289
+ onAnnotationAdded?: (annotation: IAnnotationStore) => void;
290
+ /**
291
+ * 删除批注回调
292
+ * @param annotation
293
+ * @returns
294
+ */
295
+ onAnnotationDeleted?: (id: string) => void;
296
+ /**
297
+ * 选中批注回调
298
+ * @param annotation
299
+ * @param isClick
300
+ * @returns
301
+ */
302
+ onAnnotationSelected?: (annotation: IAnnotationStore | null, isClick: boolean) => void;
303
+ /**
304
+ * 修改批注回调
305
+ * @param annotation
306
+ * @returns
307
+ */
308
+ onAnnotationUpdated?: (annotation: IAnnotationStore) => void;
309
+ }
310
+
311
+ declare type PdfAnnotatorUserOptions = DeepPartial<PdfAnnotatorOptions>;
312
+
313
+ export declare interface PdfBaseProps {
314
+ /**
315
+ * 主题色
316
+ * @default: 'indigo'
317
+ */
318
+ theme?: 'ruby' | 'indigo' | 'gray' | 'gold' | 'bronze' | 'brown' | 'yellow' | 'amber' | 'orange' | 'tomato' | 'red' | 'crimson' | 'pink' | 'plum' | 'purple' | 'violet' | 'iris' | 'blue' | 'cyan' | 'teal' | 'jade' | 'green' | 'grass' | 'lime' | 'mint' | 'sky' | undefined;
319
+ /**
320
+ * 页面标题
321
+ */
322
+ title?: React.ReactNode;
323
+ /**
324
+ * PDF 文件地址,支持字符串 URL 或 URL 对象
325
+ * @example "https://example.com/doc.pdf"
326
+ */
327
+ url: string | URL;
328
+ /**
329
+ * 语言区域,用于国际化
330
+ * @default 'zh-CN'
331
+ */
332
+ locale?: 'zh-CN' | 'en-US';
333
+ /**
334
+ * 默认选项,用于初始化 PDF 阅读器 缩放
335
+ * @default 'auto'
336
+ */
337
+ initialScale?: PdfScale;
338
+ /**
339
+ * pdf viewer 容器的样式
340
+ * @default { width: '100vw', height: '100vh' }
341
+ */
342
+ layoutStyle?: React.CSSProperties;
343
+ /**
344
+ * 控制侧边栏是否折叠
345
+ */
346
+ isSidebarCollapsed?: boolean;
347
+ }
348
+
349
+ declare type PdfjsAnnotationSubtype = 'None' | 'Link' | 'Text' | 'Widget' | 'Popup' | 'FreeText' | 'Line' | 'Square' | 'Circle' | 'PolyLine' | 'Polygon' | 'Caret' | 'Ink' | 'Highlight' | 'Underline' | 'Squiggly' | 'StrikeOut' | 'Stamp' | 'FileAttachment' | 'Note' | 'Arrow';
350
+
351
+ declare enum PdfjsAnnotationType {
352
+ NONE = 0,
353
+ TEXT = 1,
354
+ LINK = 2,
355
+ FREETEXT = 3,
356
+ LINE = 4,
357
+ SQUARE = 5,
358
+ CIRCLE = 6,
359
+ POLYGON = 7,
360
+ POLYLINE = 8,
361
+ HIGHLIGHT = 9,
362
+ UNDERLINE = 10,
363
+ SQUIGGLY = 11,
364
+ STRIKEOUT = 12,
365
+ STAMP = 13,
366
+ CARET = 14,
367
+ INK = 15,
368
+ POPUP = 16,
369
+ FILEATTACHMENT = 17,
370
+ SOUND = 18,
371
+ MOVIE = 19,
372
+ WIDGET = 20,
373
+ SCREEN = 21,
374
+ PRINTERMARK = 22,
375
+ TRAPNET = 23,
376
+ WATERMARK = 24,
377
+ THREED = 25,
378
+ REDACT = 26,
379
+ NOTE = 27
380
+ }
381
+
382
+ declare type PdfScale = 'auto' | 'page-actual' | 'page-fit' | 'page-width' | string;
383
+
384
+ export declare const PdfViewer: default_2.FC<PdfViewerProps>;
385
+
386
+ declare interface PdfViewerContextValue {
387
+ pdfViewer: PDFViewer | null;
388
+ setSidebarCollapsed: (collapsed: boolean) => void;
389
+ toggleSidebar: () => void;
390
+ }
391
+
392
+ export declare interface PdfViewerProps extends PdfBaseProps {
393
+ /**
394
+ * 自定义额外按钮区域组件
395
+ * 可以是一个 React 组件或者 React 元素
396
+ */
397
+ actions?: default_2.ReactNode | ((context: PdfViewerContextValue) => default_2.ReactNode);
398
+ /**
399
+ * 自定义侧边栏组件
400
+ * 可以是一个 React 组件或者 React 元素
401
+ */
402
+ sidebar?: default_2.ReactNode | ((context: PdfViewerContextValue) => default_2.ReactNode);
403
+ /**
404
+ * 自定义工具栏组件
405
+ * 可以是一个 React 组件或者 React 元素
406
+ * 默认显示 ZoomTool 组件
407
+ */
408
+ toolbar?: default_2.ReactNode | ((context: PdfViewerContextValue) => default_2.ReactNode);
409
+ /**
410
+ * 是否显示侧边栏触发按钮
411
+ * @default false
412
+ */
413
+ showSidebarTrigger?: boolean;
414
+ /**
415
+ * 是否显示文本层(用于选择和搜索文本)
416
+ * @default true
417
+ */
418
+ showTextLayer?: boolean;
419
+ /**
420
+ * 文档加载完成回调
421
+ * @param pdfViewer
422
+ * @returns
423
+ */
424
+ onDocumentLoaded?: (pdfViewer: PDFViewer | null) => void;
425
+ /**
426
+ * PDFjs EventBus 完成回调
427
+ * @param eventBus
428
+ * @returns
429
+ */
430
+ onEventBusReady?: (eventBus: EventBus | null) => void;
431
+ }
432
+
433
+ export declare interface User {
434
+ id: string;
435
+ name: string;
436
+ avatarUrl?: string;
437
+ }
438
+
439
+ export { }