@rajeev02/document 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/lib/editor/index.d.ts +134 -0
- package/lib/editor/index.d.ts.map +1 -0
- package/lib/editor/index.js +250 -0
- package/lib/editor/index.js.map +1 -0
- package/lib/index.d.ts +15 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +27 -0
- package/lib/index.js.map +1 -0
- package/lib/picker/index.d.ts +62 -0
- package/lib/picker/index.d.ts.map +1 -0
- package/lib/picker/index.js +182 -0
- package/lib/picker/index.js.map +1 -0
- package/lib/signature/index.d.ts +103 -0
- package/lib/signature/index.d.ts.map +1 -0
- package/lib/signature/index.js +147 -0
- package/lib/signature/index.js.map +1 -0
- package/package.json +52 -0
- package/src/editor/index.ts +352 -0
- package/src/index.ts +44 -0
- package/src/picker/index.ts +246 -0
- package/src/signature/index.ts +227 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @rajeev02/document — Signature
|
|
3
|
+
* Digital signature: draw, type, upload, place on documents, stamp, legal timestamp
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type SignatureType = "drawn" | "typed" | "uploaded" | "aadhaar_esign";
|
|
7
|
+
|
|
8
|
+
export interface SignatureData {
|
|
9
|
+
id: string;
|
|
10
|
+
type: SignatureType;
|
|
11
|
+
/** Base64 image of signature */
|
|
12
|
+
imageBase64: string;
|
|
13
|
+
/** For typed signatures */
|
|
14
|
+
text?: string;
|
|
15
|
+
fontFamily?: string;
|
|
16
|
+
/** Color of signature */
|
|
17
|
+
color: string;
|
|
18
|
+
/** When created */
|
|
19
|
+
createdAt: number;
|
|
20
|
+
/** Whether this is the default signature */
|
|
21
|
+
isDefault: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface SignaturePlacement {
|
|
25
|
+
signatureId: string;
|
|
26
|
+
pageNumber: number;
|
|
27
|
+
position: { x: number; y: number };
|
|
28
|
+
size: { width: number; height: number };
|
|
29
|
+
rotation: number;
|
|
30
|
+
/** Legal timestamp */
|
|
31
|
+
timestamp: number;
|
|
32
|
+
/** Signer name */
|
|
33
|
+
signerName?: string;
|
|
34
|
+
/** Signer email */
|
|
35
|
+
signerEmail?: string;
|
|
36
|
+
/** IP address at time of signing */
|
|
37
|
+
ipAddress?: string;
|
|
38
|
+
/** Reason for signing */
|
|
39
|
+
reason?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface SignatureConfig {
|
|
43
|
+
/** Canvas width for drawn signatures */
|
|
44
|
+
canvasWidth: number;
|
|
45
|
+
/** Canvas height */
|
|
46
|
+
canvasHeight: number;
|
|
47
|
+
/** Default pen color */
|
|
48
|
+
penColor: string;
|
|
49
|
+
/** Pen thickness */
|
|
50
|
+
penThickness: number;
|
|
51
|
+
/** Available pen colors */
|
|
52
|
+
availableColors: string[];
|
|
53
|
+
/** Available fonts for typed signatures */
|
|
54
|
+
availableFonts: string[];
|
|
55
|
+
/** Whether to include timestamp overlay */
|
|
56
|
+
includeTimestamp: boolean;
|
|
57
|
+
/** Whether to require reason for signing */
|
|
58
|
+
requireReason: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Signature Manager — manages saved signatures and placement
|
|
63
|
+
*/
|
|
64
|
+
export class SignatureManager {
|
|
65
|
+
private signatures: Map<string, SignatureData> = new Map();
|
|
66
|
+
private placements: SignaturePlacement[] = [];
|
|
67
|
+
private config: SignatureConfig;
|
|
68
|
+
|
|
69
|
+
constructor(config?: Partial<SignatureConfig>) {
|
|
70
|
+
this.config = {
|
|
71
|
+
canvasWidth: 600,
|
|
72
|
+
canvasHeight: 200,
|
|
73
|
+
penColor: "#000000",
|
|
74
|
+
penThickness: 3,
|
|
75
|
+
availableColors: ["#000000", "#1E3A5F", "#8B0000", "#006400"],
|
|
76
|
+
availableFonts: [
|
|
77
|
+
"Dancing Script",
|
|
78
|
+
"Great Vibes",
|
|
79
|
+
"Allura",
|
|
80
|
+
"Sacramento",
|
|
81
|
+
"Alex Brush",
|
|
82
|
+
"Pacifico",
|
|
83
|
+
],
|
|
84
|
+
includeTimestamp: true,
|
|
85
|
+
requireReason: false,
|
|
86
|
+
...config,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Save a drawn signature */
|
|
91
|
+
saveDrawnSignature(imageBase64: string, color: string = "#000000"): string {
|
|
92
|
+
const id = `sig_${Date.now()}`;
|
|
93
|
+
const sig: SignatureData = {
|
|
94
|
+
id,
|
|
95
|
+
type: "drawn",
|
|
96
|
+
imageBase64,
|
|
97
|
+
color,
|
|
98
|
+
createdAt: Date.now(),
|
|
99
|
+
isDefault: this.signatures.size === 0,
|
|
100
|
+
};
|
|
101
|
+
this.signatures.set(id, sig);
|
|
102
|
+
return id;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Save a typed signature */
|
|
106
|
+
saveTypedSignature(
|
|
107
|
+
text: string,
|
|
108
|
+
fontFamily: string,
|
|
109
|
+
color: string = "#000000",
|
|
110
|
+
): string {
|
|
111
|
+
const id = `sig_${Date.now()}`;
|
|
112
|
+
const sig: SignatureData = {
|
|
113
|
+
id,
|
|
114
|
+
type: "typed",
|
|
115
|
+
imageBase64: "",
|
|
116
|
+
text,
|
|
117
|
+
fontFamily,
|
|
118
|
+
color,
|
|
119
|
+
createdAt: Date.now(),
|
|
120
|
+
isDefault: this.signatures.size === 0,
|
|
121
|
+
};
|
|
122
|
+
this.signatures.set(id, sig);
|
|
123
|
+
return id;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Save an uploaded signature image */
|
|
127
|
+
saveUploadedSignature(imageBase64: string): string {
|
|
128
|
+
const id = `sig_${Date.now()}`;
|
|
129
|
+
const sig: SignatureData = {
|
|
130
|
+
id,
|
|
131
|
+
type: "uploaded",
|
|
132
|
+
imageBase64,
|
|
133
|
+
color: "#000000",
|
|
134
|
+
createdAt: Date.now(),
|
|
135
|
+
isDefault: this.signatures.size === 0,
|
|
136
|
+
};
|
|
137
|
+
this.signatures.set(id, sig);
|
|
138
|
+
return id;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Delete a saved signature */
|
|
142
|
+
deleteSignature(id: string): boolean {
|
|
143
|
+
return this.signatures.delete(id);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Set default signature */
|
|
147
|
+
setDefault(id: string): void {
|
|
148
|
+
for (const sig of this.signatures.values()) sig.isDefault = false;
|
|
149
|
+
const sig = this.signatures.get(id);
|
|
150
|
+
if (sig) sig.isDefault = true;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Get default signature */
|
|
154
|
+
getDefault(): SignatureData | null {
|
|
155
|
+
return (
|
|
156
|
+
Array.from(this.signatures.values()).find((s) => s.isDefault) ?? null
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Get all saved signatures */
|
|
161
|
+
getAllSignatures(): SignatureData[] {
|
|
162
|
+
return Array.from(this.signatures.values());
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Place signature on a document */
|
|
166
|
+
placeSignature(placement: Omit<SignaturePlacement, "timestamp">): void {
|
|
167
|
+
this.placements.push({ ...placement, timestamp: Date.now() });
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Get all placements */
|
|
171
|
+
getPlacements(): SignaturePlacement[] {
|
|
172
|
+
return [...this.placements];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Get placements for a specific page */
|
|
176
|
+
getPagePlacements(pageNumber: number): SignaturePlacement[] {
|
|
177
|
+
return this.placements.filter((p) => p.pageNumber === pageNumber);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Remove a placement */
|
|
181
|
+
removePlacement(index: number): void {
|
|
182
|
+
this.placements.splice(index, 1);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Generate signing certificate data (for legal compliance) */
|
|
186
|
+
generateSigningRecord(
|
|
187
|
+
signerName: string,
|
|
188
|
+
signerEmail: string,
|
|
189
|
+
reason: string,
|
|
190
|
+
documentHash: string,
|
|
191
|
+
): Record<string, unknown> {
|
|
192
|
+
return {
|
|
193
|
+
signerName,
|
|
194
|
+
signerEmail,
|
|
195
|
+
reason,
|
|
196
|
+
documentHash,
|
|
197
|
+
signedAt: new Date().toISOString(),
|
|
198
|
+
signatureCount: this.placements.length,
|
|
199
|
+
placements: this.placements.map((p) => ({
|
|
200
|
+
page: p.pageNumber,
|
|
201
|
+
x: p.position.x,
|
|
202
|
+
y: p.position.y,
|
|
203
|
+
timestamp: p.timestamp,
|
|
204
|
+
})),
|
|
205
|
+
certificateVersion: "1.0",
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
getConfig(): SignatureConfig {
|
|
210
|
+
return { ...this.config };
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Default signature placement sizes */
|
|
215
|
+
export function getSignatureSizePresets(): {
|
|
216
|
+
id: string;
|
|
217
|
+
label: string;
|
|
218
|
+
width: number;
|
|
219
|
+
height: number;
|
|
220
|
+
}[] {
|
|
221
|
+
return [
|
|
222
|
+
{ id: "small", label: "Small", width: 0.15, height: 0.04 },
|
|
223
|
+
{ id: "medium", label: "Medium", width: 0.25, height: 0.06 },
|
|
224
|
+
{ id: "large", label: "Large", width: 0.35, height: 0.08 },
|
|
225
|
+
{ id: "full_width", label: "Full Width", width: 0.5, height: 0.1 },
|
|
226
|
+
];
|
|
227
|
+
}
|