kviewer 0.0.1
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 +134 -0
- package/dist/module.d.mts +15 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +26 -0
- package/dist/runtime/annotation/engine/config.d.ts +52 -0
- package/dist/runtime/annotation/engine/config.js +283 -0
- package/dist/runtime/annotation/engine/const.d.ts +6 -0
- package/dist/runtime/annotation/engine/const.js +7 -0
- package/dist/runtime/annotation/engine/cursor-preview.d.ts +2 -0
- package/dist/runtime/annotation/engine/cursor-preview.js +88 -0
- package/dist/runtime/annotation/engine/editor/editor.d.ts +69 -0
- package/dist/runtime/annotation/engine/editor/editor.js +233 -0
- package/dist/runtime/annotation/engine/editor/selector.d.ts +74 -0
- package/dist/runtime/annotation/engine/editor/selector.js +594 -0
- package/dist/runtime/annotation/engine/import-normalize.d.ts +5 -0
- package/dist/runtime/annotation/engine/import-normalize.js +99 -0
- package/dist/runtime/annotation/engine/input-device.d.ts +53 -0
- package/dist/runtime/annotation/engine/input-device.js +64 -0
- package/dist/runtime/annotation/engine/painter.d.ts +97 -0
- package/dist/runtime/annotation/engine/painter.js +591 -0
- package/dist/runtime/annotation/engine/store.d.ts +11 -0
- package/dist/runtime/annotation/engine/store.js +47 -0
- package/dist/runtime/annotation/engine/tools/arrow.d.ts +22 -0
- package/dist/runtime/annotation/engine/tools/arrow.js +126 -0
- package/dist/runtime/annotation/engine/tools/circle.d.ts +45 -0
- package/dist/runtime/annotation/engine/tools/circle.js +148 -0
- package/dist/runtime/annotation/engine/tools/cloud.d.ts +50 -0
- package/dist/runtime/annotation/engine/tools/cloud.js +244 -0
- package/dist/runtime/annotation/engine/tools/free-highlight.d.ts +43 -0
- package/dist/runtime/annotation/engine/tools/free-highlight.js +165 -0
- package/dist/runtime/annotation/engine/tools/free-text.d.ts +27 -0
- package/dist/runtime/annotation/engine/tools/free-text.js +114 -0
- package/dist/runtime/annotation/engine/tools/freehand.d.ts +44 -0
- package/dist/runtime/annotation/engine/tools/freehand.js +151 -0
- package/dist/runtime/annotation/engine/tools/highlight.d.ts +87 -0
- package/dist/runtime/annotation/engine/tools/highlight.js +215 -0
- package/dist/runtime/annotation/engine/tools/note.d.ts +9 -0
- package/dist/runtime/annotation/engine/tools/note.js +34 -0
- package/dist/runtime/annotation/engine/tools/rectangle.d.ts +45 -0
- package/dist/runtime/annotation/engine/tools/rectangle.js +142 -0
- package/dist/runtime/annotation/engine/tools/signature.d.ts +16 -0
- package/dist/runtime/annotation/engine/tools/signature.js +74 -0
- package/dist/runtime/annotation/engine/tools/stamp.d.ts +18 -0
- package/dist/runtime/annotation/engine/tools/stamp.js +94 -0
- package/dist/runtime/annotation/engine/types.d.ts +170 -0
- package/dist/runtime/annotation/engine/types.js +67 -0
- package/dist/runtime/annotation/engine/utils.d.ts +40 -0
- package/dist/runtime/annotation/engine/utils.js +257 -0
- package/dist/runtime/annotation/parsers/parseFormFields.d.ts +9 -0
- package/dist/runtime/annotation/parsers/parseFormFields.js +101 -0
- package/dist/runtime/annotation/pdf-export/download.d.ts +1 -0
- package/dist/runtime/annotation/pdf-export/download.js +10 -0
- package/dist/runtime/annotation/pdf-export/export-form-fields.d.ts +9 -0
- package/dist/runtime/annotation/pdf-export/export-form-fields.js +90 -0
- package/dist/runtime/annotation/pdf-export/export.d.ts +15 -0
- package/dist/runtime/annotation/pdf-export/export.js +145 -0
- package/dist/runtime/annotation/pdf-export/parse.d.ts +10 -0
- package/dist/runtime/annotation/pdf-export/parse.js +19 -0
- package/dist/runtime/annotation/pdf-export/parse_circle.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_circle.js +41 -0
- package/dist/runtime/annotation/pdf-export/parse_freetext.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_freetext.js +54 -0
- package/dist/runtime/annotation/pdf-export/parse_highlight.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_highlight.js +134 -0
- package/dist/runtime/annotation/pdf-export/parse_ink.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_ink.js +124 -0
- package/dist/runtime/annotation/pdf-export/parse_line.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_line.js +71 -0
- package/dist/runtime/annotation/pdf-export/parse_polyline.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_polyline.js +93 -0
- package/dist/runtime/annotation/pdf-export/parse_square.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_square.js +41 -0
- package/dist/runtime/annotation/pdf-export/parse_stamp.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_stamp.js +195 -0
- package/dist/runtime/annotation/pdf-export/parse_strikeout.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_strikeout.js +59 -0
- package/dist/runtime/annotation/pdf-export/parse_text.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_text.js +42 -0
- package/dist/runtime/annotation/pdf-export/parse_underline.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_underline.js +59 -0
- package/dist/runtime/assets/kviewer.css +1 -0
- package/dist/runtime/components/AnnotationToolbar.d.vue.ts +3 -0
- package/dist/runtime/components/AnnotationToolbar.vue +125 -0
- package/dist/runtime/components/AnnotationToolbar.vue.d.ts +3 -0
- package/dist/runtime/components/FloatingPageIndicator.d.vue.ts +6 -0
- package/dist/runtime/components/FloatingPageIndicator.vue +93 -0
- package/dist/runtime/components/FloatingPageIndicator.vue.d.ts +6 -0
- package/dist/runtime/components/FormFieldLayer.d.vue.ts +11 -0
- package/dist/runtime/components/FormFieldLayer.vue +40 -0
- package/dist/runtime/components/FormFieldLayer.vue.d.ts +11 -0
- package/dist/runtime/components/PdfPage.d.vue.ts +9 -0
- package/dist/runtime/components/PdfPage.vue +199 -0
- package/dist/runtime/components/PdfPage.vue.d.ts +9 -0
- package/dist/runtime/components/ToolButton.d.vue.ts +13 -0
- package/dist/runtime/components/ToolButton.vue +26 -0
- package/dist/runtime/components/ToolButton.vue.d.ts +13 -0
- package/dist/runtime/components/Toolbar.d.vue.ts +3 -0
- package/dist/runtime/components/Toolbar.vue +11 -0
- package/dist/runtime/components/Toolbar.vue.d.ts +3 -0
- package/dist/runtime/components/Viewer.d.vue.ts +45 -0
- package/dist/runtime/components/Viewer.vue +617 -0
- package/dist/runtime/components/Viewer.vue.d.ts +45 -0
- package/dist/runtime/components/ViewerBar.d.vue.ts +3 -0
- package/dist/runtime/components/ViewerBar.vue +91 -0
- package/dist/runtime/components/ViewerBar.vue.d.ts +3 -0
- package/dist/runtime/components/ViewerTabs.d.vue.ts +381 -0
- package/dist/runtime/components/ViewerTabs.vue +171 -0
- package/dist/runtime/components/ViewerTabs.vue.d.ts +381 -0
- package/dist/runtime/components/form-fields/FormButton.d.vue.ts +7 -0
- package/dist/runtime/components/form-fields/FormButton.vue +39 -0
- package/dist/runtime/components/form-fields/FormButton.vue.d.ts +7 -0
- package/dist/runtime/components/form-fields/FormCheckbox.d.vue.ts +7 -0
- package/dist/runtime/components/form-fields/FormCheckbox.vue +28 -0
- package/dist/runtime/components/form-fields/FormCheckbox.vue.d.ts +7 -0
- package/dist/runtime/components/form-fields/FormDropdown.d.vue.ts +7 -0
- package/dist/runtime/components/form-fields/FormDropdown.vue +112 -0
- package/dist/runtime/components/form-fields/FormDropdown.vue.d.ts +7 -0
- package/dist/runtime/components/form-fields/FormFieldWrapper.d.vue.ts +8 -0
- package/dist/runtime/components/form-fields/FormFieldWrapper.vue +41 -0
- package/dist/runtime/components/form-fields/FormFieldWrapper.vue.d.ts +8 -0
- package/dist/runtime/components/form-fields/FormRadioButton.d.vue.ts +7 -0
- package/dist/runtime/components/form-fields/FormRadioButton.vue +30 -0
- package/dist/runtime/components/form-fields/FormRadioButton.vue.d.ts +7 -0
- package/dist/runtime/components/form-fields/FormSignatureField.d.vue.ts +7 -0
- package/dist/runtime/components/form-fields/FormSignatureField.vue +54 -0
- package/dist/runtime/components/form-fields/FormSignatureField.vue.d.ts +7 -0
- package/dist/runtime/components/form-fields/FormTextField.d.vue.ts +7 -0
- package/dist/runtime/components/form-fields/FormTextField.vue +66 -0
- package/dist/runtime/components/form-fields/FormTextField.vue.d.ts +7 -0
- package/dist/runtime/components/modals/FreeTextModal.d.vue.ts +25 -0
- package/dist/runtime/components/modals/FreeTextModal.vue +89 -0
- package/dist/runtime/components/modals/FreeTextModal.vue.d.ts +25 -0
- package/dist/runtime/components/modals/SignatureDrawModal.d.vue.ts +14 -0
- package/dist/runtime/components/modals/SignatureDrawModal.vue +120 -0
- package/dist/runtime/components/modals/SignatureDrawModal.vue.d.ts +14 -0
- package/dist/runtime/components/panels/SignaturePicker.d.vue.ts +3 -0
- package/dist/runtime/components/panels/SignaturePicker.vue +85 -0
- package/dist/runtime/components/panels/SignaturePicker.vue.d.ts +3 -0
- package/dist/runtime/components/panels/StampPicker.d.vue.ts +3 -0
- package/dist/runtime/components/panels/StampPicker.vue +46 -0
- package/dist/runtime/components/panels/StampPicker.vue.d.ts +3 -0
- package/dist/runtime/components/tools/ActionTools.d.vue.ts +3 -0
- package/dist/runtime/components/tools/ActionTools.vue +32 -0
- package/dist/runtime/components/tools/ActionTools.vue.d.ts +3 -0
- package/dist/runtime/components/tools/DrawingTools.d.vue.ts +6 -0
- package/dist/runtime/components/tools/DrawingTools.vue +57 -0
- package/dist/runtime/components/tools/DrawingTools.vue.d.ts +6 -0
- package/dist/runtime/components/tools/HandTool.d.vue.ts +3 -0
- package/dist/runtime/components/tools/HandTool.vue +14 -0
- package/dist/runtime/components/tools/HandTool.vue.d.ts +3 -0
- package/dist/runtime/components/tools/MarqueeTool.d.vue.ts +3 -0
- package/dist/runtime/components/tools/MarqueeTool.vue +15 -0
- package/dist/runtime/components/tools/MarqueeTool.vue.d.ts +3 -0
- package/dist/runtime/components/tools/PageInfo.d.vue.ts +3 -0
- package/dist/runtime/components/tools/PageInfo.vue +10 -0
- package/dist/runtime/components/tools/PageInfo.vue.d.ts +3 -0
- package/dist/runtime/components/tools/PageSettings.d.vue.ts +3 -0
- package/dist/runtime/components/tools/PageSettings.vue +92 -0
- package/dist/runtime/components/tools/PageSettings.vue.d.ts +3 -0
- package/dist/runtime/components/tools/SearchTool.d.vue.ts +3 -0
- package/dist/runtime/components/tools/SearchTool.vue +149 -0
- package/dist/runtime/components/tools/SearchTool.vue.d.ts +3 -0
- package/dist/runtime/components/tools/ToolProperties.d.vue.ts +7 -0
- package/dist/runtime/components/tools/ToolProperties.vue +174 -0
- package/dist/runtime/components/tools/ToolProperties.vue.d.ts +7 -0
- package/dist/runtime/components/tools/ZoomControls.d.vue.ts +3 -0
- package/dist/runtime/components/tools/ZoomControls.vue +59 -0
- package/dist/runtime/components/tools/ZoomControls.vue.d.ts +3 -0
- package/dist/runtime/composables/search-utils.d.ts +20 -0
- package/dist/runtime/composables/search-utils.js +55 -0
- package/dist/runtime/composables/useAnnotationEngine.d.ts +7 -0
- package/dist/runtime/composables/useAnnotationEngine.js +70 -0
- package/dist/runtime/composables/useAnnotationHistory.d.ts +12 -0
- package/dist/runtime/composables/useAnnotationHistory.js +69 -0
- package/dist/runtime/composables/useFormFields.d.ts +26 -0
- package/dist/runtime/composables/useFormFields.js +112 -0
- package/dist/runtime/composables/usePageProxyCache.d.ts +8 -0
- package/dist/runtime/composables/usePageProxyCache.js +73 -0
- package/dist/runtime/composables/usePageSettings.d.ts +16 -0
- package/dist/runtime/composables/usePageSettings.js +66 -0
- package/dist/runtime/composables/usePageVirtualization.d.ts +19 -0
- package/dist/runtime/composables/usePageVirtualization.js +203 -0
- package/dist/runtime/composables/useSearchIndex.d.ts +11 -0
- package/dist/runtime/composables/useSearchIndex.js +71 -0
- package/dist/runtime/composables/useViewerSearch.d.ts +32 -0
- package/dist/runtime/composables/useViewerSearch.js +418 -0
- package/dist/runtime/composables/useViewerState.d.ts +62 -0
- package/dist/runtime/composables/useViewerState.js +189 -0
- package/dist/runtime/composables/viewMode.d.ts +11 -0
- package/dist/runtime/composables/viewMode.js +19 -0
- package/dist/runtime/plugin.d.ts +2 -0
- package/dist/runtime/plugin.js +3 -0
- package/dist/runtime/public-types.d.ts +2 -0
- package/dist/runtime/public-types.js +0 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/types.d.mts +5 -0
- package/package.json +64 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import type { IRect } from 'konva/lib/types';
|
|
2
|
+
export type PdfjsAnnotationSubtype = 'Link' | 'Text' | 'Widget' | 'Popup' | 'FreeText' | 'Line' | 'Square' | 'Circle' | 'PolyLine' | 'Polygon' | 'Caret' | 'Ink' | 'Highlight' | 'Underline' | 'Squiggly' | 'StrikeOut' | 'Stamp' | 'FileAttachment' | 'Note' | 'Arrow';
|
|
3
|
+
export declare enum PdfjsAnnotationType {
|
|
4
|
+
NONE = 0,
|
|
5
|
+
TEXT = 1,
|
|
6
|
+
LINK = 2,
|
|
7
|
+
FREETEXT = 3,
|
|
8
|
+
LINE = 4,
|
|
9
|
+
SQUARE = 5,
|
|
10
|
+
CIRCLE = 6,
|
|
11
|
+
POLYGON = 7,
|
|
12
|
+
POLYLINE = 8,
|
|
13
|
+
HIGHLIGHT = 9,
|
|
14
|
+
UNDERLINE = 10,
|
|
15
|
+
SQUIGGLY = 11,
|
|
16
|
+
STRIKEOUT = 12,
|
|
17
|
+
STAMP = 13,
|
|
18
|
+
CARET = 14,
|
|
19
|
+
INK = 15,
|
|
20
|
+
POPUP = 16,
|
|
21
|
+
FILEATTACHMENT = 17,
|
|
22
|
+
SOUND = 18,
|
|
23
|
+
MOVIE = 19,
|
|
24
|
+
WIDGET = 20,
|
|
25
|
+
SCREEN = 21,
|
|
26
|
+
PRINTERMARK = 22,
|
|
27
|
+
TRAPNET = 23,
|
|
28
|
+
WATERMARK = 24,
|
|
29
|
+
THREED = 25,
|
|
30
|
+
REDACT = 26,
|
|
31
|
+
NOTE = 27
|
|
32
|
+
}
|
|
33
|
+
export declare enum PdfjsAnnotationEditorType {
|
|
34
|
+
DISABLE = -1,
|
|
35
|
+
NONE = 0,
|
|
36
|
+
FREETEXT = 3,
|
|
37
|
+
HIGHLIGHT = 9,
|
|
38
|
+
STAMP = 13,
|
|
39
|
+
INK = 15
|
|
40
|
+
}
|
|
41
|
+
export declare enum AnnotationType {
|
|
42
|
+
NONE = -1,
|
|
43
|
+
SELECT = 0,
|
|
44
|
+
HIGHLIGHT = 1,
|
|
45
|
+
STRIKEOUT = 2,
|
|
46
|
+
UNDERLINE = 3,
|
|
47
|
+
FREETEXT = 4,
|
|
48
|
+
RECTANGLE = 5,
|
|
49
|
+
CIRCLE = 6,
|
|
50
|
+
FREEHAND = 7,
|
|
51
|
+
FREE_HIGHLIGHT = 8,
|
|
52
|
+
SIGNATURE = 9,
|
|
53
|
+
STAMP = 10,
|
|
54
|
+
NOTE = 11,
|
|
55
|
+
ARROW = 12,
|
|
56
|
+
CLOUD = 13
|
|
57
|
+
}
|
|
58
|
+
export interface IAnnotationType {
|
|
59
|
+
name: string;
|
|
60
|
+
type: AnnotationType;
|
|
61
|
+
pdfjsEditorType: PdfjsAnnotationEditorType;
|
|
62
|
+
pdfjsAnnotationType: PdfjsAnnotationType;
|
|
63
|
+
subtype?: PdfjsAnnotationSubtype;
|
|
64
|
+
isOnce: boolean;
|
|
65
|
+
resizable: boolean;
|
|
66
|
+
draggable: boolean;
|
|
67
|
+
icon?: string;
|
|
68
|
+
style?: IAnnotationStyle;
|
|
69
|
+
styleEditable?: {
|
|
70
|
+
color: boolean;
|
|
71
|
+
strokeWidth: boolean;
|
|
72
|
+
opacity: boolean;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export interface IAnnotationStyle {
|
|
76
|
+
color?: string;
|
|
77
|
+
fontSize?: number;
|
|
78
|
+
opacity?: number;
|
|
79
|
+
strokeWidth?: number;
|
|
80
|
+
}
|
|
81
|
+
export interface IAnnotationComment {
|
|
82
|
+
id: string;
|
|
83
|
+
title: string;
|
|
84
|
+
date: string;
|
|
85
|
+
content: string;
|
|
86
|
+
status?: CommentStatus;
|
|
87
|
+
}
|
|
88
|
+
export declare enum CommentStatus {
|
|
89
|
+
Accepted = "Accepted",
|
|
90
|
+
Rejected = "Rejected",
|
|
91
|
+
Cancelled = "Cancelled",
|
|
92
|
+
Completed = "Completed",
|
|
93
|
+
None = "None",
|
|
94
|
+
Closed = "Closed"
|
|
95
|
+
}
|
|
96
|
+
export interface IAnnotationContentsObj {
|
|
97
|
+
text: string;
|
|
98
|
+
image?: string;
|
|
99
|
+
}
|
|
100
|
+
export interface StampDefinition {
|
|
101
|
+
id: string;
|
|
102
|
+
name: string;
|
|
103
|
+
imageUrl: string;
|
|
104
|
+
previewUrl?: string;
|
|
105
|
+
width?: number;
|
|
106
|
+
height?: number;
|
|
107
|
+
}
|
|
108
|
+
export interface SignatureData {
|
|
109
|
+
id: string;
|
|
110
|
+
imageUrl: string;
|
|
111
|
+
name?: string;
|
|
112
|
+
}
|
|
113
|
+
export interface SignatureHandlers {
|
|
114
|
+
onLoad: () => Promise<SignatureData[]>;
|
|
115
|
+
onSave: (imageUrl: string) => Promise<SignatureData>;
|
|
116
|
+
onDelete: (id: string) => Promise<void>;
|
|
117
|
+
}
|
|
118
|
+
export interface IAnnotationStore {
|
|
119
|
+
id: string;
|
|
120
|
+
pageNumber: number;
|
|
121
|
+
konvaString: string;
|
|
122
|
+
konvaClientRect: IRect;
|
|
123
|
+
title: string;
|
|
124
|
+
type: AnnotationType;
|
|
125
|
+
color?: string | null;
|
|
126
|
+
subtype: PdfjsAnnotationSubtype;
|
|
127
|
+
fontSize?: number | null;
|
|
128
|
+
pdfjsType: PdfjsAnnotationType;
|
|
129
|
+
pdfjsEditorType: PdfjsAnnotationEditorType;
|
|
130
|
+
date: string;
|
|
131
|
+
contentsObj?: IAnnotationContentsObj | null;
|
|
132
|
+
comments: IAnnotationComment[];
|
|
133
|
+
resizable: boolean;
|
|
134
|
+
draggable: boolean;
|
|
135
|
+
}
|
|
136
|
+
export type FormFieldType = 'text' | 'checkbox' | 'radio' | 'dropdown' | 'signature' | 'button';
|
|
137
|
+
export interface FormFieldDefinition {
|
|
138
|
+
id: string;
|
|
139
|
+
pageNumber: number;
|
|
140
|
+
fieldType: FormFieldType;
|
|
141
|
+
fieldName: string;
|
|
142
|
+
rect: [number, number, number, number];
|
|
143
|
+
readOnly: boolean;
|
|
144
|
+
required: boolean;
|
|
145
|
+
defaultValue?: string;
|
|
146
|
+
maxLen?: number;
|
|
147
|
+
multiLine?: boolean;
|
|
148
|
+
password?: boolean;
|
|
149
|
+
comb?: boolean;
|
|
150
|
+
exportValue?: string;
|
|
151
|
+
buttonValue?: string;
|
|
152
|
+
options?: {
|
|
153
|
+
displayValue: string;
|
|
154
|
+
exportValue: string;
|
|
155
|
+
}[];
|
|
156
|
+
combo?: boolean;
|
|
157
|
+
multiSelect?: boolean;
|
|
158
|
+
editable?: boolean;
|
|
159
|
+
buttonLabel?: string;
|
|
160
|
+
fontSize?: number;
|
|
161
|
+
color?: number[];
|
|
162
|
+
backgroundColor?: number[];
|
|
163
|
+
textAlignment?: number;
|
|
164
|
+
}
|
|
165
|
+
export interface FormFieldValue {
|
|
166
|
+
fieldId: string;
|
|
167
|
+
fieldName: string;
|
|
168
|
+
fieldType: FormFieldType;
|
|
169
|
+
value: string | boolean | string[];
|
|
170
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export var PdfjsAnnotationType = /* @__PURE__ */ ((PdfjsAnnotationType2) => {
|
|
2
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["NONE"] = 0] = "NONE";
|
|
3
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["TEXT"] = 1] = "TEXT";
|
|
4
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["LINK"] = 2] = "LINK";
|
|
5
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["FREETEXT"] = 3] = "FREETEXT";
|
|
6
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["LINE"] = 4] = "LINE";
|
|
7
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["SQUARE"] = 5] = "SQUARE";
|
|
8
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["CIRCLE"] = 6] = "CIRCLE";
|
|
9
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["POLYGON"] = 7] = "POLYGON";
|
|
10
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["POLYLINE"] = 8] = "POLYLINE";
|
|
11
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["HIGHLIGHT"] = 9] = "HIGHLIGHT";
|
|
12
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["UNDERLINE"] = 10] = "UNDERLINE";
|
|
13
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["SQUIGGLY"] = 11] = "SQUIGGLY";
|
|
14
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["STRIKEOUT"] = 12] = "STRIKEOUT";
|
|
15
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["STAMP"] = 13] = "STAMP";
|
|
16
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["CARET"] = 14] = "CARET";
|
|
17
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["INK"] = 15] = "INK";
|
|
18
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["POPUP"] = 16] = "POPUP";
|
|
19
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["FILEATTACHMENT"] = 17] = "FILEATTACHMENT";
|
|
20
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["SOUND"] = 18] = "SOUND";
|
|
21
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["MOVIE"] = 19] = "MOVIE";
|
|
22
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["WIDGET"] = 20] = "WIDGET";
|
|
23
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["SCREEN"] = 21] = "SCREEN";
|
|
24
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["PRINTERMARK"] = 22] = "PRINTERMARK";
|
|
25
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["TRAPNET"] = 23] = "TRAPNET";
|
|
26
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["WATERMARK"] = 24] = "WATERMARK";
|
|
27
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["THREED"] = 25] = "THREED";
|
|
28
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["REDACT"] = 26] = "REDACT";
|
|
29
|
+
PdfjsAnnotationType2[PdfjsAnnotationType2["NOTE"] = 27] = "NOTE";
|
|
30
|
+
return PdfjsAnnotationType2;
|
|
31
|
+
})(PdfjsAnnotationType || {});
|
|
32
|
+
export var PdfjsAnnotationEditorType = /* @__PURE__ */ ((PdfjsAnnotationEditorType2) => {
|
|
33
|
+
PdfjsAnnotationEditorType2[PdfjsAnnotationEditorType2["DISABLE"] = -1] = "DISABLE";
|
|
34
|
+
PdfjsAnnotationEditorType2[PdfjsAnnotationEditorType2["NONE"] = 0] = "NONE";
|
|
35
|
+
PdfjsAnnotationEditorType2[PdfjsAnnotationEditorType2["FREETEXT"] = 3] = "FREETEXT";
|
|
36
|
+
PdfjsAnnotationEditorType2[PdfjsAnnotationEditorType2["HIGHLIGHT"] = 9] = "HIGHLIGHT";
|
|
37
|
+
PdfjsAnnotationEditorType2[PdfjsAnnotationEditorType2["STAMP"] = 13] = "STAMP";
|
|
38
|
+
PdfjsAnnotationEditorType2[PdfjsAnnotationEditorType2["INK"] = 15] = "INK";
|
|
39
|
+
return PdfjsAnnotationEditorType2;
|
|
40
|
+
})(PdfjsAnnotationEditorType || {});
|
|
41
|
+
export var AnnotationType = /* @__PURE__ */ ((AnnotationType2) => {
|
|
42
|
+
AnnotationType2[AnnotationType2["NONE"] = -1] = "NONE";
|
|
43
|
+
AnnotationType2[AnnotationType2["SELECT"] = 0] = "SELECT";
|
|
44
|
+
AnnotationType2[AnnotationType2["HIGHLIGHT"] = 1] = "HIGHLIGHT";
|
|
45
|
+
AnnotationType2[AnnotationType2["STRIKEOUT"] = 2] = "STRIKEOUT";
|
|
46
|
+
AnnotationType2[AnnotationType2["UNDERLINE"] = 3] = "UNDERLINE";
|
|
47
|
+
AnnotationType2[AnnotationType2["FREETEXT"] = 4] = "FREETEXT";
|
|
48
|
+
AnnotationType2[AnnotationType2["RECTANGLE"] = 5] = "RECTANGLE";
|
|
49
|
+
AnnotationType2[AnnotationType2["CIRCLE"] = 6] = "CIRCLE";
|
|
50
|
+
AnnotationType2[AnnotationType2["FREEHAND"] = 7] = "FREEHAND";
|
|
51
|
+
AnnotationType2[AnnotationType2["FREE_HIGHLIGHT"] = 8] = "FREE_HIGHLIGHT";
|
|
52
|
+
AnnotationType2[AnnotationType2["SIGNATURE"] = 9] = "SIGNATURE";
|
|
53
|
+
AnnotationType2[AnnotationType2["STAMP"] = 10] = "STAMP";
|
|
54
|
+
AnnotationType2[AnnotationType2["NOTE"] = 11] = "NOTE";
|
|
55
|
+
AnnotationType2[AnnotationType2["ARROW"] = 12] = "ARROW";
|
|
56
|
+
AnnotationType2[AnnotationType2["CLOUD"] = 13] = "CLOUD";
|
|
57
|
+
return AnnotationType2;
|
|
58
|
+
})(AnnotationType || {});
|
|
59
|
+
export var CommentStatus = /* @__PURE__ */ ((CommentStatus2) => {
|
|
60
|
+
CommentStatus2["Accepted"] = "Accepted";
|
|
61
|
+
CommentStatus2["Rejected"] = "Rejected";
|
|
62
|
+
CommentStatus2["Cancelled"] = "Cancelled";
|
|
63
|
+
CommentStatus2["Completed"] = "Completed";
|
|
64
|
+
CommentStatus2["None"] = "None";
|
|
65
|
+
CommentStatus2["Closed"] = "Closed";
|
|
66
|
+
return CommentStatus2;
|
|
67
|
+
})(CommentStatus || {});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { PDFHexString } from 'pdf-lib';
|
|
2
|
+
export declare function getRGB(color: string): number[];
|
|
3
|
+
export declare function rgbToPdfColor(input: string | undefined): [number, number, number];
|
|
4
|
+
export declare function isElementInDOM(element: HTMLElement): boolean;
|
|
5
|
+
export declare function generateUUID(): string;
|
|
6
|
+
export declare function setCssCustomProperty(propertyName: string, value: string): void;
|
|
7
|
+
export declare function removeCssCustomProperty(propertyName: string): void;
|
|
8
|
+
export declare function base64ToImageBitmap(base64: string): Promise<ImageBitmap>;
|
|
9
|
+
export declare function resizeImage(width: number, height: number, max: number): {
|
|
10
|
+
newWidth: number;
|
|
11
|
+
newHeight: number;
|
|
12
|
+
};
|
|
13
|
+
export declare function convertToRGB(array: number[], index?: number): string;
|
|
14
|
+
export declare function formatTimestamp(timestamp: number): string;
|
|
15
|
+
export declare function formatPDFDate(dateString: string | null, full?: boolean): string;
|
|
16
|
+
export declare function getPDFDateTimestamp(dateString: string): number;
|
|
17
|
+
export declare function convertKonvaRectToPdfRect(konvaRect: {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
}, pageHeight: number): [number, number, number, number];
|
|
23
|
+
export declare function stringToPDFHexString(input: string): PDFHexString;
|
|
24
|
+
export declare function getTimestampString(date?: Date): string;
|
|
25
|
+
export declare function normalizeColor(input: string): string;
|
|
26
|
+
export declare function isSameColor(color1: string, color2: string): boolean;
|
|
27
|
+
export declare function debounce(fn: (...args: unknown[]) => void, delay: number): (...args: unknown[]) => void;
|
|
28
|
+
export declare function createDocumentIcon({ x, y, fill, stroke, strokeWidth, cornerSize, }: {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
fill?: string;
|
|
32
|
+
stroke?: string;
|
|
33
|
+
strokeWidth?: number;
|
|
34
|
+
cornerSize?: number;
|
|
35
|
+
}): (import("konva/lib/shapes/Rect").Rect | import("konva/lib/shapes/Line").Line<{
|
|
36
|
+
points: number[];
|
|
37
|
+
stroke: string;
|
|
38
|
+
strokeWidth: number;
|
|
39
|
+
lineCap: "round";
|
|
40
|
+
}>)[];
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import Konva from "konva";
|
|
2
|
+
import { PDFHexString } from "pdf-lib";
|
|
3
|
+
export function getRGB(color) {
|
|
4
|
+
if (color.startsWith("#")) {
|
|
5
|
+
const colorRGB = Number.parseInt(color.slice(1), 16);
|
|
6
|
+
return [
|
|
7
|
+
(colorRGB & 16711680) >> 16,
|
|
8
|
+
(colorRGB & 65280) >> 8,
|
|
9
|
+
colorRGB & 255
|
|
10
|
+
];
|
|
11
|
+
}
|
|
12
|
+
if (color.startsWith("rgb(")) {
|
|
13
|
+
return color.slice(4, -1).split(",").map((x) => Number.parseInt(x.trim()));
|
|
14
|
+
}
|
|
15
|
+
if (color.startsWith("rgba(")) {
|
|
16
|
+
return color.slice(5, -1).split(",").map((x, index) => index < 3 ? Number.parseInt(x.trim()) : 1);
|
|
17
|
+
}
|
|
18
|
+
console.error(`Not a valid color format: "${color}"`);
|
|
19
|
+
return [0, 0, 0];
|
|
20
|
+
}
|
|
21
|
+
export function rgbToPdfColor(input) {
|
|
22
|
+
if (!input) return [1, 1, 0];
|
|
23
|
+
if (input.startsWith("rgb")) {
|
|
24
|
+
const match = input.match(/\d+/g);
|
|
25
|
+
if (!match || match.length < 3) return [1, 1, 0];
|
|
26
|
+
return match.slice(0, 3).map((x) => Number.parseInt(x) / 255);
|
|
27
|
+
}
|
|
28
|
+
if (input.startsWith("#")) {
|
|
29
|
+
const hex = input.replace("#", "");
|
|
30
|
+
if (hex.length !== 6) return [1, 1, 0];
|
|
31
|
+
const r = Number.parseInt(hex.slice(0, 2), 16) / 255;
|
|
32
|
+
const g = Number.parseInt(hex.slice(2, 4), 16) / 255;
|
|
33
|
+
const b = Number.parseInt(hex.slice(4, 6), 16) / 255;
|
|
34
|
+
return [r, g, b];
|
|
35
|
+
}
|
|
36
|
+
return [1, 1, 0];
|
|
37
|
+
}
|
|
38
|
+
export function isElementInDOM(element) {
|
|
39
|
+
return document.body.contains(element);
|
|
40
|
+
}
|
|
41
|
+
export function generateUUID() {
|
|
42
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
43
|
+
return crypto.randomUUID();
|
|
44
|
+
}
|
|
45
|
+
const bytes = new Uint8Array(16);
|
|
46
|
+
crypto.getRandomValues(bytes);
|
|
47
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
48
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
49
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
50
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
51
|
+
}
|
|
52
|
+
export function setCssCustomProperty(propertyName, value) {
|
|
53
|
+
document.documentElement.style.setProperty(propertyName, value);
|
|
54
|
+
}
|
|
55
|
+
export function removeCssCustomProperty(propertyName) {
|
|
56
|
+
document.documentElement.style.removeProperty(propertyName);
|
|
57
|
+
}
|
|
58
|
+
export async function base64ToImageBitmap(base64) {
|
|
59
|
+
const base64Data = base64.split(",")[1];
|
|
60
|
+
const binaryString = atob(base64Data);
|
|
61
|
+
const length = binaryString.length;
|
|
62
|
+
const bytes = new Uint8Array(length);
|
|
63
|
+
for (let i = 0; i < length; i++) {
|
|
64
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
65
|
+
}
|
|
66
|
+
const blob = new Blob([bytes], { type: "image/png" });
|
|
67
|
+
return await createImageBitmap(blob);
|
|
68
|
+
}
|
|
69
|
+
export function resizeImage(width, height, max) {
|
|
70
|
+
if (width <= max && height <= max) {
|
|
71
|
+
return { newWidth: width, newHeight: height };
|
|
72
|
+
}
|
|
73
|
+
const scaleFactor = Math.min(max / width, max / height);
|
|
74
|
+
return {
|
|
75
|
+
newWidth: width * scaleFactor,
|
|
76
|
+
newHeight: height * scaleFactor
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export function convertToRGB(array, index = 0) {
|
|
80
|
+
if (index < 0 || index * 3 + 2 >= array.length) {
|
|
81
|
+
throw new Error("Index out of bounds");
|
|
82
|
+
}
|
|
83
|
+
const r = array[index * 3];
|
|
84
|
+
const g = array[index * 3 + 1];
|
|
85
|
+
const b = array[index * 3 + 2];
|
|
86
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
87
|
+
}
|
|
88
|
+
export function formatTimestamp(timestamp) {
|
|
89
|
+
const date = new Date(timestamp);
|
|
90
|
+
const year = date.getFullYear();
|
|
91
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
92
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
93
|
+
const hours = String(date.getHours()).padStart(2, "0");
|
|
94
|
+
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
95
|
+
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
96
|
+
const timezoneOffset = -date.getTimezoneOffset();
|
|
97
|
+
const timezoneHours = String(
|
|
98
|
+
Math.floor(Math.abs(timezoneOffset) / 60)
|
|
99
|
+
).padStart(2, "0");
|
|
100
|
+
const timezoneMinutes = String(Math.abs(timezoneOffset) % 60).padStart(
|
|
101
|
+
2,
|
|
102
|
+
"0"
|
|
103
|
+
);
|
|
104
|
+
const timezoneSign = timezoneOffset >= 0 ? "+" : "-";
|
|
105
|
+
return `D:${year}${month}${day}${hours}${minutes}${seconds}${timezoneSign}${timezoneHours}'${timezoneMinutes}'`;
|
|
106
|
+
}
|
|
107
|
+
export function formatPDFDate(dateString, full = false) {
|
|
108
|
+
if (!dateString || typeof dateString !== "string" || !dateString.startsWith("D:")) {
|
|
109
|
+
return "";
|
|
110
|
+
}
|
|
111
|
+
const datePart = dateString.slice(2, 16);
|
|
112
|
+
if (datePart.length !== 14) return "";
|
|
113
|
+
const year = datePart.slice(0, 4);
|
|
114
|
+
const month = datePart.slice(4, 6);
|
|
115
|
+
const day = datePart.slice(6, 8);
|
|
116
|
+
const hour = datePart.slice(8, 10);
|
|
117
|
+
const minute = datePart.slice(10, 12);
|
|
118
|
+
if (full) {
|
|
119
|
+
return `${year}-${month}-${day} ${hour}:${minute}`;
|
|
120
|
+
}
|
|
121
|
+
const currentDate = /* @__PURE__ */ new Date();
|
|
122
|
+
const currentYear = currentDate.getFullYear().toString();
|
|
123
|
+
const currentMonth = (currentDate.getMonth() + 1).toString().padStart(2, "0");
|
|
124
|
+
const currentDay = currentDate.getDate().toString().padStart(2, "0");
|
|
125
|
+
if (year === currentYear && month === currentMonth && day === currentDay) {
|
|
126
|
+
return `${hour}:${minute}`;
|
|
127
|
+
}
|
|
128
|
+
if (year === currentYear) {
|
|
129
|
+
return `${month}-${day}`;
|
|
130
|
+
}
|
|
131
|
+
return `${year}-${month}-${day}`;
|
|
132
|
+
}
|
|
133
|
+
export function getPDFDateTimestamp(dateString) {
|
|
134
|
+
const datePart = dateString.slice(2, 16);
|
|
135
|
+
const year = Number.parseInt(datePart.slice(0, 4), 10);
|
|
136
|
+
const month = Number.parseInt(datePart.slice(4, 6), 10) - 1;
|
|
137
|
+
const day = Number.parseInt(datePart.slice(6, 8), 10);
|
|
138
|
+
const hour = Number.parseInt(datePart.slice(8, 10), 10);
|
|
139
|
+
const minute = Number.parseInt(datePart.slice(10, 12), 10);
|
|
140
|
+
const second = Number.parseInt(datePart.slice(12, 14), 10) || 0;
|
|
141
|
+
const tzMatch = dateString.slice(16).match(/([+-])(\d{2})'?(\d{2})?'/);
|
|
142
|
+
let tzOffset = 0;
|
|
143
|
+
if (tzMatch) {
|
|
144
|
+
const sign = tzMatch[1] === "+" ? 1 : -1;
|
|
145
|
+
const hours = Number.parseInt(tzMatch[2], 10) || 0;
|
|
146
|
+
const minutes = Number.parseInt(tzMatch[3] || "0", 10) || 0;
|
|
147
|
+
tzOffset = sign * (hours * 60 + minutes);
|
|
148
|
+
}
|
|
149
|
+
const date = new Date(Date.UTC(year, month, day, hour, minute, second));
|
|
150
|
+
return date.getTime() - tzOffset * 60 * 1e3;
|
|
151
|
+
}
|
|
152
|
+
export function convertKonvaRectToPdfRect(konvaRect, pageHeight) {
|
|
153
|
+
const { x, y, width, height } = konvaRect;
|
|
154
|
+
const pdfX1 = x;
|
|
155
|
+
const pdfY1 = pageHeight - y - height;
|
|
156
|
+
const pdfX2 = pdfX1 + width;
|
|
157
|
+
const pdfY2 = pdfY1 + height;
|
|
158
|
+
return [pdfX1, pdfY1, pdfX2, pdfY2];
|
|
159
|
+
}
|
|
160
|
+
export function stringToPDFHexString(input) {
|
|
161
|
+
const bom = [254, 255];
|
|
162
|
+
const utf16be = [...bom];
|
|
163
|
+
for (let i = 0; i < input.length; i++) {
|
|
164
|
+
const code = input.charCodeAt(i);
|
|
165
|
+
utf16be.push(code >> 8 & 255, code & 255);
|
|
166
|
+
}
|
|
167
|
+
const hexString = utf16be.map((b) => b.toString(16).padStart(2, "0")).join("").toUpperCase();
|
|
168
|
+
return PDFHexString.of(hexString);
|
|
169
|
+
}
|
|
170
|
+
export function getTimestampString(date = /* @__PURE__ */ new Date()) {
|
|
171
|
+
const pad = (n) => n.toString().padStart(2, "0");
|
|
172
|
+
const year = date.getFullYear();
|
|
173
|
+
const month = pad(date.getMonth() + 1);
|
|
174
|
+
const day = pad(date.getDate());
|
|
175
|
+
const hour = pad(date.getHours());
|
|
176
|
+
const minute = pad(date.getMinutes());
|
|
177
|
+
const second = pad(date.getSeconds());
|
|
178
|
+
return `${year}${month}${day}_${hour}${minute}${second}`;
|
|
179
|
+
}
|
|
180
|
+
export function normalizeColor(input) {
|
|
181
|
+
const hexRegex = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
182
|
+
const rgbRegex = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/;
|
|
183
|
+
input = input.trim().toLowerCase();
|
|
184
|
+
if (hexRegex.test(input)) {
|
|
185
|
+
if (input.length === 4) {
|
|
186
|
+
return "#" + input.slice(1).split("").map((c) => c + c).join("");
|
|
187
|
+
}
|
|
188
|
+
return input;
|
|
189
|
+
}
|
|
190
|
+
const match = input.match(rgbRegex);
|
|
191
|
+
if (match) {
|
|
192
|
+
const r = Number(match[1]);
|
|
193
|
+
const g = Number(match[2]);
|
|
194
|
+
const b = Number(match[3]);
|
|
195
|
+
const clamp = (n) => Math.max(0, Math.min(255, n));
|
|
196
|
+
return "#" + [r, g, b].map((n) => clamp(n).toString(16).padStart(2, "0")).join("");
|
|
197
|
+
}
|
|
198
|
+
throw new Error(`Unsupported color format: ${input}`);
|
|
199
|
+
}
|
|
200
|
+
export function isSameColor(color1, color2) {
|
|
201
|
+
try {
|
|
202
|
+
return normalizeColor(color1) === normalizeColor(color2);
|
|
203
|
+
} catch {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
export function debounce(fn, delay) {
|
|
208
|
+
let timeout;
|
|
209
|
+
return (...args) => {
|
|
210
|
+
if (timeout) clearTimeout(timeout);
|
|
211
|
+
timeout = setTimeout(() => fn(...args), delay);
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
export function createDocumentIcon({
|
|
215
|
+
x,
|
|
216
|
+
y,
|
|
217
|
+
fill = "rgb(255, 222, 33)",
|
|
218
|
+
stroke = "#000",
|
|
219
|
+
strokeWidth = 1,
|
|
220
|
+
cornerSize = 3
|
|
221
|
+
}) {
|
|
222
|
+
const width = 16;
|
|
223
|
+
const height = 16;
|
|
224
|
+
const paddingTop = 4;
|
|
225
|
+
const paddingBottom = 4;
|
|
226
|
+
const textLineCount = 4;
|
|
227
|
+
const spacing = (height - paddingTop - paddingBottom) / (textLineCount + 1);
|
|
228
|
+
const rect = new Konva.Rect({
|
|
229
|
+
x,
|
|
230
|
+
y,
|
|
231
|
+
width,
|
|
232
|
+
height,
|
|
233
|
+
fillLinearGradientStartPoint: { x: 0, y: 0 },
|
|
234
|
+
fillLinearGradientEndPoint: { x: 0, y: height },
|
|
235
|
+
fillLinearGradientColorStops: [0, fill, 1, "#fff"],
|
|
236
|
+
stroke,
|
|
237
|
+
cornerRadius: [0, cornerSize, 0, 0],
|
|
238
|
+
strokeWidth,
|
|
239
|
+
shadowColor: "rgba(0,0,0,0.2)",
|
|
240
|
+
shadowBlur: 2,
|
|
241
|
+
shadowOffset: { x: 1, y: 1 },
|
|
242
|
+
shadowOpacity: 0.3
|
|
243
|
+
});
|
|
244
|
+
const lines = [];
|
|
245
|
+
for (let i = 1; i <= textLineCount; i++) {
|
|
246
|
+
const yPos = y + paddingTop + i * spacing;
|
|
247
|
+
const xEnd = i === 1 ? x + width - 6 : x + width - 3;
|
|
248
|
+
const line = new Konva.Line({
|
|
249
|
+
points: [x + 3, yPos, xEnd, yPos],
|
|
250
|
+
stroke: "#555",
|
|
251
|
+
strokeWidth: 0.6,
|
|
252
|
+
lineCap: "round"
|
|
253
|
+
});
|
|
254
|
+
lines.push(line);
|
|
255
|
+
}
|
|
256
|
+
return [rect, ...lines];
|
|
257
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type FormFieldDefinition } from '../engine/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parse raw pdf.js annotation objects and extract Widget (form field) annotations
|
|
4
|
+
* into structured FormFieldDefinition objects.
|
|
5
|
+
*
|
|
6
|
+
* pdf.js `page.getAnnotations()` returns annotation objects with an `annotationType`
|
|
7
|
+
* property. Widget annotations (annotationType === 20) represent interactive form fields.
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseFormFields(annotations: any[], pageNumber: number): FormFieldDefinition[];
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { PdfjsAnnotationType } from "../engine/types.js";
|
|
2
|
+
export function parseFormFields(annotations, pageNumber) {
|
|
3
|
+
const fields = [];
|
|
4
|
+
for (const ann of annotations) {
|
|
5
|
+
if (ann.annotationType !== PdfjsAnnotationType.WIDGET) continue;
|
|
6
|
+
const fieldType = resolveFieldType(ann);
|
|
7
|
+
if (!fieldType) continue;
|
|
8
|
+
const rect = ann.rect;
|
|
9
|
+
if (!rect || rect.length < 4) continue;
|
|
10
|
+
const normalizedRect = [
|
|
11
|
+
Math.min(rect[0], rect[2]),
|
|
12
|
+
Math.min(rect[1], rect[3]),
|
|
13
|
+
Math.max(rect[0], rect[2]),
|
|
14
|
+
Math.max(rect[1], rect[3])
|
|
15
|
+
];
|
|
16
|
+
const def = {
|
|
17
|
+
id: String(ann.id),
|
|
18
|
+
pageNumber,
|
|
19
|
+
fieldType,
|
|
20
|
+
fieldName: ann.fieldName ?? "",
|
|
21
|
+
rect: normalizedRect,
|
|
22
|
+
readOnly: Boolean(ann.readOnly),
|
|
23
|
+
required: Boolean(ann.required)
|
|
24
|
+
};
|
|
25
|
+
if (fieldType === "text") {
|
|
26
|
+
if (ann.fieldValue != null) def.defaultValue = String(ann.fieldValue);
|
|
27
|
+
if (typeof ann.maxLen === "number" && ann.maxLen > 0) def.maxLen = ann.maxLen;
|
|
28
|
+
def.multiLine = Boolean(ann.multiLine);
|
|
29
|
+
def.password = Boolean(ann.password);
|
|
30
|
+
def.comb = Boolean(ann.comb);
|
|
31
|
+
}
|
|
32
|
+
if (fieldType === "checkbox") {
|
|
33
|
+
def.exportValue = ann.exportValue ?? "Yes";
|
|
34
|
+
if (ann.fieldValue != null) {
|
|
35
|
+
def.defaultValue = String(ann.fieldValue);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (fieldType === "radio") {
|
|
39
|
+
def.buttonValue = ann.buttonValue ?? ann.exportValue ?? "";
|
|
40
|
+
if (ann.fieldValue != null) {
|
|
41
|
+
def.defaultValue = String(ann.fieldValue);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (fieldType === "dropdown") {
|
|
45
|
+
def.combo = ann.combo !== false;
|
|
46
|
+
def.multiSelect = Boolean(ann.multiSelect);
|
|
47
|
+
def.editable = Boolean(ann.editable);
|
|
48
|
+
if (ann.fieldValue != null) def.defaultValue = String(ann.fieldValue);
|
|
49
|
+
if (Array.isArray(ann.options)) {
|
|
50
|
+
def.options = ann.options.map((opt) => {
|
|
51
|
+
if (Array.isArray(opt)) {
|
|
52
|
+
return {
|
|
53
|
+
exportValue: String(opt[0] ?? ""),
|
|
54
|
+
displayValue: String(opt[1] ?? opt[0] ?? "")
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (typeof opt === "object" && opt !== null) {
|
|
58
|
+
const o = opt;
|
|
59
|
+
return {
|
|
60
|
+
exportValue: String(o.exportValue ?? o.value ?? ""),
|
|
61
|
+
displayValue: String(o.displayValue ?? o.label ?? o.exportValue ?? o.value ?? "")
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return { exportValue: String(opt), displayValue: String(opt) };
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (fieldType === "button") {
|
|
69
|
+
def.buttonLabel = ann.alternativeText ?? ann.fieldValue ?? ann.fieldName ?? "Button";
|
|
70
|
+
}
|
|
71
|
+
if (typeof ann.fontSize === "number") def.fontSize = ann.fontSize;
|
|
72
|
+
if (Array.isArray(ann.color)) {
|
|
73
|
+
def.color = ann.color.map(
|
|
74
|
+
(c) => (
|
|
75
|
+
// pdf.js colors may be 0-1 floats or 0-255 integers
|
|
76
|
+
c <= 1 ? Math.round(c * 255) : Math.round(c)
|
|
77
|
+
)
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
if (Array.isArray(ann.backgroundColor)) {
|
|
81
|
+
def.backgroundColor = ann.backgroundColor.map(
|
|
82
|
+
(c) => c <= 1 ? Math.round(c * 255) : Math.round(c)
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
if (typeof ann.textAlignment === "number") def.textAlignment = ann.textAlignment;
|
|
86
|
+
fields.push(def);
|
|
87
|
+
}
|
|
88
|
+
return fields;
|
|
89
|
+
}
|
|
90
|
+
function resolveFieldType(ann) {
|
|
91
|
+
const ft = ann.fieldType;
|
|
92
|
+
if (ft === "Tx") return "text";
|
|
93
|
+
if (ft === "Btn") {
|
|
94
|
+
if (ann.checkBox) return "checkbox";
|
|
95
|
+
if (ann.radioButton) return "radio";
|
|
96
|
+
return "button";
|
|
97
|
+
}
|
|
98
|
+
if (ft === "Ch") return "dropdown";
|
|
99
|
+
if (ft === "Sig") return "signature";
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function downloadPdfBytes(data: Uint8Array, fileName: string): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function downloadPdfBytes(data, fileName) {
|
|
2
|
+
const arrayBuffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
3
|
+
const blob = new Blob([arrayBuffer], { type: "application/pdf" });
|
|
4
|
+
const link = document.createElement("a");
|
|
5
|
+
const url = URL.createObjectURL(blob);
|
|
6
|
+
link.href = url;
|
|
7
|
+
link.download = fileName;
|
|
8
|
+
link.click();
|
|
9
|
+
URL.revokeObjectURL(url);
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PDFDocument } from 'pdf-lib';
|
|
2
|
+
import type { FormFieldValue } from '../engine/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Write form field values back to the PDF using pdf-lib's AcroForm API.
|
|
5
|
+
*
|
|
6
|
+
* This updates existing form fields in the PDF with the values the user
|
|
7
|
+
* entered in the viewer. It does NOT create new fields.
|
|
8
|
+
*/
|
|
9
|
+
export declare function writeFormFieldsToPdf(pdfDoc: PDFDocument, fieldValues: FormFieldValue[]): Promise<void>;
|