@embedpdf/plugin-signature 2.13.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.
Files changed (80) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.cjs +2 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.js +516 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/lib/actions.d.ts +14 -0
  8. package/dist/lib/handlers/signature-ink.handler.d.ts +4 -0
  9. package/dist/lib/handlers/signature-stamp.handler.d.ts +4 -0
  10. package/dist/lib/index.d.ts +12 -0
  11. package/dist/lib/manifest.d.ts +4 -0
  12. package/dist/lib/reducer.d.ts +5 -0
  13. package/dist/lib/serialization.d.ts +30 -0
  14. package/dist/lib/signature-plugin.d.ts +27 -0
  15. package/dist/lib/tools.d.ts +113 -0
  16. package/dist/lib/types.d.ts +114 -0
  17. package/dist/preact/adapter.d.ts +5 -0
  18. package/dist/preact/annotation.d.ts +1 -0
  19. package/dist/preact/core.d.ts +1 -0
  20. package/dist/preact/index.cjs +2 -0
  21. package/dist/preact/index.cjs.map +1 -0
  22. package/dist/preact/index.d.ts +1 -0
  23. package/dist/preact/index.js +464 -0
  24. package/dist/preact/index.js.map +1 -0
  25. package/dist/react/adapter.d.ts +2 -0
  26. package/dist/react/annotation.d.ts +1 -0
  27. package/dist/react/core.d.ts +1 -0
  28. package/dist/react/index.cjs +2 -0
  29. package/dist/react/index.cjs.map +1 -0
  30. package/dist/react/index.d.ts +1 -0
  31. package/dist/react/index.js +463 -0
  32. package/dist/react/index.js.map +1 -0
  33. package/dist/shared/components/crop-canvas.d.ts +14 -0
  34. package/dist/shared/components/index.d.ts +2 -0
  35. package/dist/shared/components/signature-draw-pad.d.ts +12 -0
  36. package/dist/shared/components/signature-type-pad.d.ts +14 -0
  37. package/dist/shared/hooks/index.d.ts +2 -0
  38. package/dist/shared/hooks/use-signature-upload.d.ts +21 -0
  39. package/dist/shared/hooks/use-signature.d.ts +16 -0
  40. package/dist/shared/index.d.ts +4 -0
  41. package/dist/shared-preact/components/crop-canvas.d.ts +14 -0
  42. package/dist/shared-preact/components/index.d.ts +2 -0
  43. package/dist/shared-preact/components/signature-draw-pad.d.ts +12 -0
  44. package/dist/shared-preact/components/signature-type-pad.d.ts +14 -0
  45. package/dist/shared-preact/hooks/index.d.ts +2 -0
  46. package/dist/shared-preact/hooks/use-signature-upload.d.ts +21 -0
  47. package/dist/shared-preact/hooks/use-signature.d.ts +16 -0
  48. package/dist/shared-preact/index.d.ts +4 -0
  49. package/dist/shared-react/components/crop-canvas.d.ts +14 -0
  50. package/dist/shared-react/components/index.d.ts +2 -0
  51. package/dist/shared-react/components/signature-draw-pad.d.ts +12 -0
  52. package/dist/shared-react/components/signature-type-pad.d.ts +14 -0
  53. package/dist/shared-react/hooks/index.d.ts +2 -0
  54. package/dist/shared-react/hooks/use-signature-upload.d.ts +21 -0
  55. package/dist/shared-react/hooks/use-signature.d.ts +16 -0
  56. package/dist/shared-react/index.d.ts +4 -0
  57. package/dist/shared-vue/components/crop-canvas.d.ts +14 -0
  58. package/dist/svelte/components/SignatureDrawPad.svelte.d.ts +12 -0
  59. package/dist/svelte/components/SignatureTypePad.svelte.d.ts +14 -0
  60. package/dist/svelte/components/index.d.ts +2 -0
  61. package/dist/svelte/hooks/index.d.ts +2 -0
  62. package/dist/svelte/hooks/use-signature-upload.svelte.d.ts +21 -0
  63. package/dist/svelte/hooks/use-signature.svelte.d.ts +17 -0
  64. package/dist/svelte/index.cjs +2 -0
  65. package/dist/svelte/index.cjs.map +1 -0
  66. package/dist/svelte/index.d.ts +4 -0
  67. package/dist/svelte/index.js +415 -0
  68. package/dist/svelte/index.js.map +1 -0
  69. package/dist/vue/components/SignatureDrawPad.vue.d.ts +15 -0
  70. package/dist/vue/components/SignatureTypePad.vue.d.ts +19 -0
  71. package/dist/vue/components/index.d.ts +2 -0
  72. package/dist/vue/hooks/index.d.ts +2 -0
  73. package/dist/vue/hooks/use-signature-upload.d.ts +20 -0
  74. package/dist/vue/hooks/use-signature.d.ts +176 -0
  75. package/dist/vue/index.cjs +2 -0
  76. package/dist/vue/index.cjs.map +1 -0
  77. package/dist/vue/index.d.ts +4 -0
  78. package/dist/vue/index.js +453 -0
  79. package/dist/vue/index.js.map +1 -0
  80. package/package.json +82 -0
@@ -0,0 +1,463 @@
1
+ import { createPluginPackage } from "@embedpdf/core";
2
+ import { SignaturePlugin, SignatureCreationType, SignaturePluginPackage as SignaturePluginPackage$1 } from "@embedpdf/plugin-signature";
3
+ export * from "@embedpdf/plugin-signature";
4
+ import { useCapability, usePlugin } from "@embedpdf/core/react";
5
+ import { useState, useEffect, useRef, useCallback } from "react";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ const useSignaturePlugin = () => usePlugin(SignaturePlugin.id);
8
+ const useSignatureCapability = () => useCapability(SignaturePlugin.id);
9
+ const useSignatureEntries = () => {
10
+ const { provides } = useSignatureCapability();
11
+ const [entries, setEntries] = useState((provides == null ? void 0 : provides.getEntries()) ?? []);
12
+ useEffect(() => {
13
+ if (!provides) return;
14
+ setEntries(provides.getEntries());
15
+ return provides.onEntriesChange((updated) => {
16
+ setEntries(updated);
17
+ });
18
+ }, [provides]);
19
+ return { entries, provides };
20
+ };
21
+ const useActivePlacement = (documentId) => {
22
+ const { provides } = useSignatureCapability();
23
+ const [activePlacement, setActivePlacement] = useState(null);
24
+ useEffect(() => {
25
+ if (!provides) return;
26
+ const scope = provides.forDocument(documentId);
27
+ setActivePlacement(scope.getActivePlacement());
28
+ return scope.onActivePlacementChange(setActivePlacement);
29
+ }, [provides, documentId]);
30
+ return activePlacement;
31
+ };
32
+ function useSignatureUpload({
33
+ accept = "image/png,image/jpeg,image/svg+xml",
34
+ onResult
35
+ }) {
36
+ const inputRef = useRef(null);
37
+ const [previewUrl, setPreviewUrl] = useState(null);
38
+ const [isDragging, setIsDragging] = useState(false);
39
+ const processFile = useCallback(
40
+ (file) => {
41
+ const reader = new FileReader();
42
+ reader.onload = () => {
43
+ const arrayBuffer = reader.result;
44
+ const blob = new Blob([arrayBuffer], { type: file.type });
45
+ const dataUrl = URL.createObjectURL(blob);
46
+ setPreviewUrl((prev) => {
47
+ if (prev) URL.revokeObjectURL(prev);
48
+ return dataUrl;
49
+ });
50
+ const img = new Image();
51
+ img.onload = () => {
52
+ const previewCanvas = document.createElement("canvas");
53
+ previewCanvas.width = img.width;
54
+ previewCanvas.height = img.height;
55
+ const ctx = previewCanvas.getContext("2d");
56
+ if (ctx) {
57
+ ctx.drawImage(img, 0, 0);
58
+ }
59
+ const result = {
60
+ creationType: SignatureCreationType.Upload,
61
+ imageMimeType: file.type,
62
+ imageSize: { width: img.width, height: img.height },
63
+ previewDataUrl: previewCanvas.toDataURL("image/png"),
64
+ imageData: arrayBuffer
65
+ };
66
+ onResult(result);
67
+ };
68
+ img.src = dataUrl;
69
+ };
70
+ reader.readAsArrayBuffer(file);
71
+ },
72
+ [onResult]
73
+ );
74
+ const handleFileInputChange = useCallback(
75
+ (e) => {
76
+ const files = e.target.files;
77
+ if (files && files[0]) {
78
+ processFile(files[0]);
79
+ }
80
+ },
81
+ [processFile]
82
+ );
83
+ const handleDrop = useCallback(
84
+ (e) => {
85
+ var _a;
86
+ e.preventDefault();
87
+ setIsDragging(false);
88
+ const files = (_a = e.dataTransfer) == null ? void 0 : _a.files;
89
+ if (files && files[0]) {
90
+ processFile(files[0]);
91
+ }
92
+ },
93
+ [processFile]
94
+ );
95
+ const handleDragOver = useCallback((e) => {
96
+ e.preventDefault();
97
+ setIsDragging(true);
98
+ }, []);
99
+ const handleDragLeave = useCallback(() => {
100
+ setIsDragging(false);
101
+ }, []);
102
+ const openFilePicker = useCallback(() => {
103
+ var _a;
104
+ (_a = inputRef.current) == null ? void 0 : _a.click();
105
+ }, []);
106
+ const clear = useCallback(() => {
107
+ setPreviewUrl((prev) => {
108
+ if (prev) URL.revokeObjectURL(prev);
109
+ return null;
110
+ });
111
+ onResult(null);
112
+ if (inputRef.current) {
113
+ inputRef.current.value = "";
114
+ }
115
+ }, [onResult]);
116
+ return {
117
+ inputRef,
118
+ openFilePicker,
119
+ processFile,
120
+ handleFileInputChange,
121
+ handleDrop,
122
+ handleDragOver,
123
+ handleDragLeave,
124
+ previewUrl,
125
+ isDragging,
126
+ clear,
127
+ accept
128
+ };
129
+ }
130
+ function cropCanvas(source, padding = 4) {
131
+ const ctx = source.getContext("2d");
132
+ if (!ctx) return null;
133
+ const { width, height } = source;
134
+ if (width === 0 || height === 0) return null;
135
+ const imageData = ctx.getImageData(0, 0, width, height);
136
+ const { data } = imageData;
137
+ let minX = width;
138
+ let minY = height;
139
+ let maxX = 0;
140
+ let maxY = 0;
141
+ for (let y = 0; y < height; y++) {
142
+ for (let x = 0; x < width; x++) {
143
+ const alpha = data[(y * width + x) * 4 + 3];
144
+ if (alpha > 0) {
145
+ if (x < minX) minX = x;
146
+ if (x > maxX) maxX = x;
147
+ if (y < minY) minY = y;
148
+ if (y > maxY) maxY = y;
149
+ }
150
+ }
151
+ }
152
+ if (maxX < minX || maxY < minY) return null;
153
+ const cropX = Math.max(0, minX - padding);
154
+ const cropY = Math.max(0, minY - padding);
155
+ const cropW = Math.min(width, maxX + padding + 1) - cropX;
156
+ const cropH = Math.min(height, maxY + padding + 1) - cropY;
157
+ const cropped = document.createElement("canvas");
158
+ cropped.width = cropW;
159
+ cropped.height = cropH;
160
+ const croppedCtx = cropped.getContext("2d");
161
+ if (!croppedCtx) return null;
162
+ croppedCtx.drawImage(source, cropX, cropY, cropW, cropH, 0, 0, cropW, cropH);
163
+ return {
164
+ canvas: cropped,
165
+ bounds: { x: cropX, y: cropY, width: cropW, height: cropH }
166
+ };
167
+ }
168
+ function SignatureDrawPad({
169
+ onResult,
170
+ padRef,
171
+ strokeColor = "#000000",
172
+ strokeWidth = 4,
173
+ className
174
+ }) {
175
+ const canvasRef = useRef(null);
176
+ const [strokes, setStrokes] = useState([]);
177
+ const isDrawingRef = useRef(false);
178
+ const sizeRef = useRef({ width: 0, height: 0 });
179
+ const strokesRef = useRef(strokes);
180
+ strokesRef.current = strokes;
181
+ const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
182
+ const getCanvasPos = useCallback(
183
+ (e) => {
184
+ const canvas = canvasRef.current;
185
+ if (!canvas) return { x: 0, y: 0 };
186
+ const rect = canvas.getBoundingClientRect();
187
+ return {
188
+ x: (e.clientX - rect.left) * (canvas.width / dpr / rect.width),
189
+ y: (e.clientY - rect.top) * (canvas.height / dpr / rect.height)
190
+ };
191
+ },
192
+ [dpr]
193
+ );
194
+ const redraw = useCallback(
195
+ (currentStrokes) => {
196
+ const canvas = canvasRef.current;
197
+ if (!canvas) return;
198
+ const ctx = canvas.getContext("2d");
199
+ if (!ctx) return;
200
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
201
+ ctx.save();
202
+ ctx.scale(dpr, dpr);
203
+ ctx.strokeStyle = strokeColor;
204
+ ctx.lineWidth = strokeWidth;
205
+ ctx.lineCap = "round";
206
+ ctx.lineJoin = "round";
207
+ for (const stroke of currentStrokes) {
208
+ if (stroke.points.length === 0) continue;
209
+ ctx.beginPath();
210
+ ctx.moveTo(stroke.points[0].x, stroke.points[0].y);
211
+ for (let i = 1; i < stroke.points.length; i++) {
212
+ ctx.lineTo(stroke.points[i].x, stroke.points[i].y);
213
+ }
214
+ ctx.stroke();
215
+ }
216
+ ctx.restore();
217
+ },
218
+ [dpr, strokeColor, strokeWidth]
219
+ );
220
+ const redrawRef = useRef(redraw);
221
+ redrawRef.current = redraw;
222
+ const emitResult = useCallback(
223
+ (currentStrokes) => {
224
+ if (currentStrokes.length === 0 || currentStrokes.every((s) => s.points.length < 2)) {
225
+ onResult(null);
226
+ return;
227
+ }
228
+ const canvas = canvasRef.current;
229
+ if (!canvas) return;
230
+ const cropped = cropCanvas(canvas, Math.ceil(strokeWidth * dpr));
231
+ if (!cropped) {
232
+ onResult(null);
233
+ return;
234
+ }
235
+ const offsetX = cropped.bounds.x / dpr;
236
+ const offsetY = cropped.bounds.y / dpr;
237
+ const croppedWidth = Math.round(cropped.bounds.width / dpr);
238
+ const croppedHeight = Math.round(cropped.bounds.height / dpr);
239
+ const result = {
240
+ creationType: SignatureCreationType.Draw,
241
+ inkData: {
242
+ inkList: currentStrokes.filter((s) => s.points.length >= 2).map((s) => ({
243
+ points: s.points.map((p) => ({
244
+ x: p.x - offsetX,
245
+ y: p.y - offsetY
246
+ }))
247
+ })),
248
+ strokeWidth,
249
+ strokeColor,
250
+ size: { width: croppedWidth, height: croppedHeight }
251
+ },
252
+ previewDataUrl: cropped.canvas.toDataURL("image/png")
253
+ };
254
+ onResult(result);
255
+ },
256
+ [onResult, strokeWidth, strokeColor, dpr]
257
+ );
258
+ useEffect(() => {
259
+ const canvas = canvasRef.current;
260
+ if (!canvas) return;
261
+ const observer = new ResizeObserver((entries) => {
262
+ const { width: w, height: h } = entries[0].contentRect;
263
+ if (w > 0 && h > 0) {
264
+ sizeRef.current = { width: Math.round(w), height: Math.round(h) };
265
+ canvas.width = Math.round(w) * dpr;
266
+ canvas.height = Math.round(h) * dpr;
267
+ redrawRef.current(strokesRef.current);
268
+ }
269
+ });
270
+ observer.observe(canvas);
271
+ return () => observer.disconnect();
272
+ }, [dpr]);
273
+ useEffect(() => {
274
+ redraw(strokes);
275
+ if (strokes.length > 0 && strokes.some((s) => s.points.length >= 2)) {
276
+ emitResult(strokes);
277
+ }
278
+ }, [strokeColor, strokeWidth]);
279
+ const handleClear = useCallback(() => {
280
+ setStrokes([]);
281
+ redraw([]);
282
+ onResult(null);
283
+ }, [redraw, onResult]);
284
+ useEffect(() => {
285
+ padRef == null ? void 0 : padRef({ clear: handleClear });
286
+ return () => padRef == null ? void 0 : padRef(null);
287
+ }, [padRef, handleClear]);
288
+ const handlePointerDown = useCallback(
289
+ (e) => {
290
+ var _a, _b;
291
+ isDrawingRef.current = true;
292
+ const pos = getCanvasPos(e);
293
+ const newStrokes = [...strokes, { points: [pos] }];
294
+ setStrokes(newStrokes);
295
+ redraw(newStrokes);
296
+ (_b = (_a = e.target) == null ? void 0 : _a.setPointerCapture) == null ? void 0 : _b.call(_a, e.pointerId);
297
+ },
298
+ [strokes, getCanvasPos, redraw]
299
+ );
300
+ const handlePointerMove = useCallback(
301
+ (e) => {
302
+ if (!isDrawingRef.current) return;
303
+ const pos = getCanvasPos(e);
304
+ const newStrokes = [...strokes];
305
+ const last = newStrokes[newStrokes.length - 1];
306
+ if (last) {
307
+ last.points.push(pos);
308
+ setStrokes(newStrokes);
309
+ redraw(newStrokes);
310
+ }
311
+ },
312
+ [strokes, getCanvasPos, redraw]
313
+ );
314
+ const handlePointerUp = useCallback(
315
+ (e) => {
316
+ var _a, _b;
317
+ isDrawingRef.current = false;
318
+ (_b = (_a = e.target) == null ? void 0 : _a.releasePointerCapture) == null ? void 0 : _b.call(_a, e.pointerId);
319
+ emitResult(strokes);
320
+ },
321
+ [strokes, emitResult]
322
+ );
323
+ return /* @__PURE__ */ jsx(
324
+ "canvas",
325
+ {
326
+ ref: canvasRef,
327
+ className,
328
+ style: { touchAction: "none", width: "100%", height: "100%", display: "block" },
329
+ onPointerDown: handlePointerDown,
330
+ onPointerMove: handlePointerMove,
331
+ onPointerUp: handlePointerUp
332
+ }
333
+ );
334
+ }
335
+ function SignatureTypePad({
336
+ onResult,
337
+ padRef,
338
+ fontFamily = "'Dancing Script', cursive",
339
+ fontSize = 48,
340
+ color = "#000000",
341
+ className,
342
+ placeholder = "Type your signature..."
343
+ }) {
344
+ const canvasRef = useRef(null);
345
+ const wrapperRef = useRef(null);
346
+ const inputId = useRef(`sig-type-${Math.random().toString(36).slice(2, 8)}`).current;
347
+ const sizeRef = useRef({ width: 0, height: 0 });
348
+ const [text, setText] = useState("");
349
+ const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
350
+ const renderText = useCallback(
351
+ (currentText) => {
352
+ const canvas = canvasRef.current;
353
+ if (!canvas) return;
354
+ const { width, height } = sizeRef.current;
355
+ if (width === 0 || height === 0) return;
356
+ canvas.width = width * dpr;
357
+ canvas.height = height * dpr;
358
+ const ctx = canvas.getContext("2d");
359
+ if (!ctx) return;
360
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
361
+ if (!currentText.trim()) {
362
+ onResult(null);
363
+ return;
364
+ }
365
+ ctx.scale(dpr, dpr);
366
+ ctx.fillStyle = color;
367
+ ctx.font = `${fontSize}px ${fontFamily}`;
368
+ ctx.textBaseline = "middle";
369
+ ctx.textAlign = "center";
370
+ ctx.fillText(currentText, width / 2, height / 2, width - 20);
371
+ const cropped = cropCanvas(canvas, Math.ceil(4 * dpr));
372
+ if (!cropped) {
373
+ onResult(null);
374
+ return;
375
+ }
376
+ const croppedWidth = Math.round(cropped.bounds.width / dpr);
377
+ const croppedHeight = Math.round(cropped.bounds.height / dpr);
378
+ cropped.canvas.toBlob((blob) => {
379
+ if (!blob) return;
380
+ blob.arrayBuffer().then((imageData) => {
381
+ const result = {
382
+ creationType: SignatureCreationType.Type,
383
+ label: currentText,
384
+ imageMimeType: "image/png",
385
+ imageSize: { width: croppedWidth, height: croppedHeight },
386
+ previewDataUrl: cropped.canvas.toDataURL("image/png"),
387
+ imageData
388
+ };
389
+ onResult(result);
390
+ });
391
+ }, "image/png");
392
+ },
393
+ [onResult, color, fontSize, fontFamily, dpr]
394
+ );
395
+ const renderTextRef = useRef(renderText);
396
+ renderTextRef.current = renderText;
397
+ const textRef = useRef(text);
398
+ textRef.current = text;
399
+ useEffect(() => {
400
+ const wrapper = wrapperRef.current;
401
+ if (!wrapper) return;
402
+ const observer = new ResizeObserver((entries) => {
403
+ const { width: w, height: h } = entries[0].contentRect;
404
+ if (w > 0 && h > 0) {
405
+ sizeRef.current = { width: Math.round(w), height: Math.round(h) };
406
+ renderTextRef.current(textRef.current);
407
+ }
408
+ });
409
+ observer.observe(wrapper);
410
+ return () => observer.disconnect();
411
+ }, []);
412
+ useEffect(() => {
413
+ renderText(text);
414
+ }, [text, fontFamily, renderText]);
415
+ const handleClear = useCallback(() => {
416
+ setText("");
417
+ onResult(null);
418
+ }, [onResult]);
419
+ useEffect(() => {
420
+ padRef == null ? void 0 : padRef({ clear: handleClear });
421
+ return () => padRef == null ? void 0 : padRef(null);
422
+ }, [padRef, handleClear]);
423
+ const handleTextChange = useCallback((e) => {
424
+ setText(e.target.value);
425
+ }, []);
426
+ return /* @__PURE__ */ jsxs("div", { ref: wrapperRef, className, style: { width: "100%", height: "100%" }, children: [
427
+ /* @__PURE__ */ jsx("style", { children: `#${inputId}::placeholder { color: ${color}; opacity: 0.5; }` }),
428
+ /* @__PURE__ */ jsx(
429
+ "input",
430
+ {
431
+ id: inputId,
432
+ type: "text",
433
+ value: text,
434
+ onInput: handleTextChange,
435
+ placeholder,
436
+ style: {
437
+ fontFamily,
438
+ fontSize: `${Math.min(fontSize, 32)}px`,
439
+ color,
440
+ width: "100%",
441
+ height: "100%",
442
+ border: "none",
443
+ outline: "none",
444
+ background: "transparent",
445
+ textIndent: "8px"
446
+ }
447
+ }
448
+ ),
449
+ /* @__PURE__ */ jsx("canvas", { ref: canvasRef, style: { display: "none" } })
450
+ ] });
451
+ }
452
+ const SignaturePluginPackage = createPluginPackage(SignaturePluginPackage$1).build();
453
+ export {
454
+ SignatureDrawPad,
455
+ SignaturePluginPackage,
456
+ SignatureTypePad,
457
+ useActivePlacement,
458
+ useSignatureCapability,
459
+ useSignatureEntries,
460
+ useSignaturePlugin,
461
+ useSignatureUpload
462
+ };
463
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-signature.ts","../../src/shared/hooks/use-signature-upload.ts","../../src/shared/components/crop-canvas.ts","../../src/shared/components/signature-draw-pad.tsx","../../src/shared/components/signature-type-pad.tsx","../../src/shared/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { SignaturePlugin, SignatureEntry, ActivePlacementInfo } from '@embedpdf/plugin-signature';\nimport { useState, useEffect } from '@framework';\n\nexport const useSignaturePlugin = () => usePlugin<SignaturePlugin>(SignaturePlugin.id);\nexport const useSignatureCapability = () => useCapability<SignaturePlugin>(SignaturePlugin.id);\n\nexport const useSignatureEntries = () => {\n const { provides } = useSignatureCapability();\n const [entries, setEntries] = useState<SignatureEntry[]>(provides?.getEntries() ?? []);\n\n useEffect(() => {\n if (!provides) return;\n setEntries(provides.getEntries());\n return provides.onEntriesChange((updated) => {\n setEntries(updated);\n });\n }, [provides]);\n\n return { entries, provides };\n};\n\nexport const useActivePlacement = (documentId: string) => {\n const { provides } = useSignatureCapability();\n const [activePlacement, setActivePlacement] = useState<ActivePlacementInfo | null>(null);\n\n useEffect(() => {\n if (!provides) return;\n const scope = provides.forDocument(documentId);\n setActivePlacement(scope.getActivePlacement());\n return scope.onActivePlacementChange(setActivePlacement);\n }, [provides, documentId]);\n\n return activePlacement;\n};\n","import { useRef, useState, useCallback } from '@framework';\nimport { SignatureStampFieldDefinition, SignatureCreationType } from '@embedpdf/plugin-signature';\n\nexport interface UseSignatureUploadOptions {\n accept?: string;\n onResult: (result: SignatureStampFieldDefinition | null) => void;\n}\n\nexport interface UseSignatureUploadReturn {\n inputRef: { current: HTMLInputElement | null };\n openFilePicker: () => void;\n processFile: (file: File) => void;\n handleFileInputChange: (e: Event) => void;\n handleDrop: (e: DragEvent) => void;\n handleDragOver: (e: DragEvent) => void;\n handleDragLeave: () => void;\n previewUrl: string | null;\n isDragging: boolean;\n clear: () => void;\n accept: string;\n}\n\nexport function useSignatureUpload({\n accept = 'image/png,image/jpeg,image/svg+xml',\n onResult,\n}: UseSignatureUploadOptions): UseSignatureUploadReturn {\n const inputRef = useRef<HTMLInputElement>(null);\n const [previewUrl, setPreviewUrl] = useState<string | null>(null);\n const [isDragging, setIsDragging] = useState(false);\n\n const processFile = useCallback(\n (file: File) => {\n const reader = new FileReader();\n reader.onload = () => {\n const arrayBuffer = reader.result as ArrayBuffer;\n const blob = new Blob([arrayBuffer], { type: file.type });\n const dataUrl = URL.createObjectURL(blob);\n\n setPreviewUrl((prev) => {\n if (prev) URL.revokeObjectURL(prev);\n return dataUrl;\n });\n\n const img = new Image();\n img.onload = () => {\n const previewCanvas = document.createElement('canvas');\n previewCanvas.width = img.width;\n previewCanvas.height = img.height;\n const ctx = previewCanvas.getContext('2d');\n if (ctx) {\n ctx.drawImage(img, 0, 0);\n }\n\n const result: SignatureStampFieldDefinition = {\n creationType: SignatureCreationType.Upload,\n imageMimeType: file.type,\n imageSize: { width: img.width, height: img.height },\n previewDataUrl: previewCanvas.toDataURL('image/png'),\n imageData: arrayBuffer,\n };\n onResult(result);\n };\n img.src = dataUrl;\n };\n reader.readAsArrayBuffer(file);\n },\n [onResult],\n );\n\n const handleFileInputChange = useCallback(\n (e: Event) => {\n const files = (e.target as HTMLInputElement).files;\n if (files && files[0]) {\n processFile(files[0]);\n }\n },\n [processFile],\n );\n\n const handleDrop = useCallback(\n (e: DragEvent) => {\n e.preventDefault();\n setIsDragging(false);\n const files = e.dataTransfer?.files;\n if (files && files[0]) {\n processFile(files[0]);\n }\n },\n [processFile],\n );\n\n const handleDragOver = useCallback((e: DragEvent) => {\n e.preventDefault();\n setIsDragging(true);\n }, []);\n\n const handleDragLeave = useCallback(() => {\n setIsDragging(false);\n }, []);\n\n const openFilePicker = useCallback(() => {\n inputRef.current?.click();\n }, []);\n\n const clear = useCallback(() => {\n setPreviewUrl((prev) => {\n if (prev) URL.revokeObjectURL(prev);\n return null;\n });\n onResult(null);\n if (inputRef.current) {\n inputRef.current.value = '';\n }\n }, [onResult]);\n\n return {\n inputRef,\n openFilePicker,\n processFile,\n handleFileInputChange,\n handleDrop,\n handleDragOver,\n handleDragLeave,\n previewUrl,\n isDragging,\n clear,\n accept,\n };\n}\n","export interface CropResult {\n canvas: HTMLCanvasElement;\n bounds: { x: number; y: number; width: number; height: number };\n}\n\n/**\n * Scans a canvas for non-transparent pixels and returns a tightly cropped copy.\n * Returns null if the canvas has no visible content.\n */\nexport function cropCanvas(source: HTMLCanvasElement, padding = 4): CropResult | null {\n const ctx = source.getContext('2d');\n if (!ctx) return null;\n\n const { width, height } = source;\n if (width === 0 || height === 0) return null;\n\n const imageData = ctx.getImageData(0, 0, width, height);\n const { data } = imageData;\n\n let minX = width;\n let minY = height;\n let maxX = 0;\n let maxY = 0;\n\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n const alpha = data[(y * width + x) * 4 + 3];\n if (alpha > 0) {\n if (x < minX) minX = x;\n if (x > maxX) maxX = x;\n if (y < minY) minY = y;\n if (y > maxY) maxY = y;\n }\n }\n }\n\n if (maxX < minX || maxY < minY) return null;\n\n const cropX = Math.max(0, minX - padding);\n const cropY = Math.max(0, minY - padding);\n const cropW = Math.min(width, maxX + padding + 1) - cropX;\n const cropH = Math.min(height, maxY + padding + 1) - cropY;\n\n const cropped = document.createElement('canvas');\n cropped.width = cropW;\n cropped.height = cropH;\n\n const croppedCtx = cropped.getContext('2d');\n if (!croppedCtx) return null;\n\n croppedCtx.drawImage(source, cropX, cropY, cropW, cropH, 0, 0, cropW, cropH);\n\n return {\n canvas: cropped,\n bounds: { x: cropX, y: cropY, width: cropW, height: cropH },\n };\n}\n","import { useEffect, useRef, useState, useCallback } from '@framework';\nimport { SignatureInkFieldDefinition, SignatureCreationType } from '@embedpdf/plugin-signature';\nimport { cropCanvas } from './crop-canvas';\n\nexport interface SignatureDrawPadHandle {\n clear(): void;\n}\n\nexport interface SignatureDrawPadProps {\n onResult: (result: SignatureInkFieldDefinition | null) => void;\n padRef?: (handle: SignatureDrawPadHandle | null) => void;\n strokeColor?: string;\n strokeWidth?: number;\n className?: string;\n}\n\nexport function SignatureDrawPad({\n onResult,\n padRef,\n strokeColor = '#000000',\n strokeWidth = 4,\n className,\n}: SignatureDrawPadProps) {\n const canvasRef = useRef<HTMLCanvasElement>(null);\n const [strokes, setStrokes] = useState<Array<{ points: Array<{ x: number; y: number }> }>>([]);\n const isDrawingRef = useRef(false);\n const sizeRef = useRef({ width: 0, height: 0 });\n const strokesRef = useRef(strokes);\n strokesRef.current = strokes;\n const dpr = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;\n\n const getCanvasPos = useCallback(\n (e: PointerEvent): { x: number; y: number } => {\n const canvas = canvasRef.current;\n if (!canvas) return { x: 0, y: 0 };\n const rect = canvas.getBoundingClientRect();\n return {\n x: (e.clientX - rect.left) * (canvas.width / dpr / rect.width),\n y: (e.clientY - rect.top) * (canvas.height / dpr / rect.height),\n };\n },\n [dpr],\n );\n\n const redraw = useCallback(\n (currentStrokes: Array<{ points: Array<{ x: number; y: number }> }>) => {\n const canvas = canvasRef.current;\n if (!canvas) return;\n const ctx = canvas.getContext('2d');\n if (!ctx) return;\n\n ctx.clearRect(0, 0, canvas.width, canvas.height);\n ctx.save();\n ctx.scale(dpr, dpr);\n ctx.strokeStyle = strokeColor;\n ctx.lineWidth = strokeWidth;\n ctx.lineCap = 'round';\n ctx.lineJoin = 'round';\n\n for (const stroke of currentStrokes) {\n if (stroke.points.length === 0) continue;\n ctx.beginPath();\n ctx.moveTo(stroke.points[0].x, stroke.points[0].y);\n for (let i = 1; i < stroke.points.length; i++) {\n ctx.lineTo(stroke.points[i].x, stroke.points[i].y);\n }\n ctx.stroke();\n }\n ctx.restore();\n },\n [dpr, strokeColor, strokeWidth],\n );\n\n const redrawRef = useRef(redraw);\n redrawRef.current = redraw;\n\n const emitResult = useCallback(\n (currentStrokes: Array<{ points: Array<{ x: number; y: number }> }>) => {\n if (currentStrokes.length === 0 || currentStrokes.every((s) => s.points.length < 2)) {\n onResult(null);\n return;\n }\n\n const canvas = canvasRef.current;\n if (!canvas) return;\n\n const cropped = cropCanvas(canvas, Math.ceil(strokeWidth * dpr));\n if (!cropped) {\n onResult(null);\n return;\n }\n\n const offsetX = cropped.bounds.x / dpr;\n const offsetY = cropped.bounds.y / dpr;\n const croppedWidth = Math.round(cropped.bounds.width / dpr);\n const croppedHeight = Math.round(cropped.bounds.height / dpr);\n\n const result: SignatureInkFieldDefinition = {\n creationType: SignatureCreationType.Draw,\n inkData: {\n inkList: currentStrokes\n .filter((s) => s.points.length >= 2)\n .map((s) => ({\n points: s.points.map((p) => ({\n x: p.x - offsetX,\n y: p.y - offsetY,\n })),\n })),\n strokeWidth,\n strokeColor,\n size: { width: croppedWidth, height: croppedHeight },\n },\n previewDataUrl: cropped.canvas.toDataURL('image/png'),\n };\n\n onResult(result);\n },\n [onResult, strokeWidth, strokeColor, dpr],\n );\n\n useEffect(() => {\n const canvas = canvasRef.current;\n if (!canvas) return;\n const observer = new ResizeObserver((entries) => {\n const { width: w, height: h } = entries[0].contentRect;\n if (w > 0 && h > 0) {\n sizeRef.current = { width: Math.round(w), height: Math.round(h) };\n canvas.width = Math.round(w) * dpr;\n canvas.height = Math.round(h) * dpr;\n redrawRef.current(strokesRef.current);\n }\n });\n observer.observe(canvas);\n return () => observer.disconnect();\n }, [dpr]);\n\n useEffect(() => {\n redraw(strokes);\n if (strokes.length > 0 && strokes.some((s) => s.points.length >= 2)) {\n emitResult(strokes);\n }\n }, [strokeColor, strokeWidth]);\n\n const handleClear = useCallback(() => {\n setStrokes([]);\n redraw([]);\n onResult(null);\n }, [redraw, onResult]);\n\n useEffect(() => {\n padRef?.({ clear: handleClear });\n return () => padRef?.(null);\n }, [padRef, handleClear]);\n\n const handlePointerDown = useCallback(\n (e: PointerEvent) => {\n isDrawingRef.current = true;\n const pos = getCanvasPos(e);\n const newStrokes = [...strokes, { points: [pos] }];\n setStrokes(newStrokes);\n redraw(newStrokes);\n (e.target as HTMLElement)?.setPointerCapture?.(e.pointerId);\n },\n [strokes, getCanvasPos, redraw],\n );\n\n const handlePointerMove = useCallback(\n (e: PointerEvent) => {\n if (!isDrawingRef.current) return;\n const pos = getCanvasPos(e);\n const newStrokes = [...strokes];\n const last = newStrokes[newStrokes.length - 1];\n if (last) {\n last.points.push(pos);\n setStrokes(newStrokes);\n redraw(newStrokes);\n }\n },\n [strokes, getCanvasPos, redraw],\n );\n\n const handlePointerUp = useCallback(\n (e: PointerEvent) => {\n isDrawingRef.current = false;\n (e.target as HTMLElement)?.releasePointerCapture?.(e.pointerId);\n emitResult(strokes);\n },\n [strokes, emitResult],\n );\n\n return (\n <canvas\n ref={canvasRef}\n className={className}\n style={{ touchAction: 'none', width: '100%', height: '100%', display: 'block' }}\n onPointerDown={handlePointerDown as any}\n onPointerMove={handlePointerMove as any}\n onPointerUp={handlePointerUp as any}\n />\n );\n}\n","import { useEffect, useRef, useState, useCallback } from '@framework';\nimport { SignatureStampFieldDefinition, SignatureCreationType } from '@embedpdf/plugin-signature';\nimport { cropCanvas } from './crop-canvas';\n\nexport interface SignatureTypePadHandle {\n clear(): void;\n}\n\nexport interface SignatureTypePadProps {\n onResult: (result: SignatureStampFieldDefinition | null) => void;\n padRef?: (handle: SignatureTypePadHandle | null) => void;\n fontFamily?: string;\n fontSize?: number;\n color?: string;\n className?: string;\n placeholder?: string;\n}\n\nexport function SignatureTypePad({\n onResult,\n padRef,\n fontFamily = \"'Dancing Script', cursive\",\n fontSize = 48,\n color = '#000000',\n className,\n placeholder = 'Type your signature...',\n}: SignatureTypePadProps) {\n const canvasRef = useRef<HTMLCanvasElement>(null);\n const wrapperRef = useRef<HTMLDivElement>(null);\n const inputId = useRef(`sig-type-${Math.random().toString(36).slice(2, 8)}`).current;\n const sizeRef = useRef({ width: 0, height: 0 });\n const [text, setText] = useState('');\n const dpr = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;\n\n const renderText = useCallback(\n (currentText: string) => {\n const canvas = canvasRef.current;\n if (!canvas) return;\n\n const { width, height } = sizeRef.current;\n if (width === 0 || height === 0) return;\n\n canvas.width = width * dpr;\n canvas.height = height * dpr;\n\n const ctx = canvas.getContext('2d');\n if (!ctx) return;\n\n ctx.clearRect(0, 0, canvas.width, canvas.height);\n\n if (!currentText.trim()) {\n onResult(null);\n return;\n }\n\n ctx.scale(dpr, dpr);\n ctx.fillStyle = color;\n ctx.font = `${fontSize}px ${fontFamily}`;\n ctx.textBaseline = 'middle';\n ctx.textAlign = 'center';\n ctx.fillText(currentText, width / 2, height / 2, width - 20);\n\n const cropped = cropCanvas(canvas, Math.ceil(4 * dpr));\n if (!cropped) {\n onResult(null);\n return;\n }\n\n const croppedWidth = Math.round(cropped.bounds.width / dpr);\n const croppedHeight = Math.round(cropped.bounds.height / dpr);\n\n cropped.canvas.toBlob((blob) => {\n if (!blob) return;\n blob.arrayBuffer().then((imageData) => {\n const result: SignatureStampFieldDefinition = {\n creationType: SignatureCreationType.Type,\n label: currentText,\n imageMimeType: 'image/png',\n imageSize: { width: croppedWidth, height: croppedHeight },\n previewDataUrl: cropped.canvas.toDataURL('image/png'),\n imageData,\n };\n onResult(result);\n });\n }, 'image/png');\n },\n [onResult, color, fontSize, fontFamily, dpr],\n );\n\n const renderTextRef = useRef(renderText);\n renderTextRef.current = renderText;\n const textRef = useRef(text);\n textRef.current = text;\n\n useEffect(() => {\n const wrapper = wrapperRef.current;\n if (!wrapper) return;\n const observer = new ResizeObserver((entries) => {\n const { width: w, height: h } = entries[0].contentRect;\n if (w > 0 && h > 0) {\n sizeRef.current = { width: Math.round(w), height: Math.round(h) };\n renderTextRef.current(textRef.current);\n }\n });\n observer.observe(wrapper);\n return () => observer.disconnect();\n }, []);\n\n useEffect(() => {\n renderText(text);\n }, [text, fontFamily, renderText]);\n\n const handleClear = useCallback(() => {\n setText('');\n onResult(null);\n }, [onResult]);\n\n useEffect(() => {\n padRef?.({ clear: handleClear });\n return () => padRef?.(null);\n }, [padRef, handleClear]);\n\n const handleTextChange = useCallback((e: Event) => {\n setText((e.target as HTMLInputElement).value);\n }, []);\n\n return (\n <div ref={wrapperRef} className={className} style={{ width: '100%', height: '100%' }}>\n <style>{`#${inputId}::placeholder { color: ${color}; opacity: 0.5; }`}</style>\n <input\n id={inputId}\n type=\"text\"\n value={text}\n onInput={handleTextChange as any}\n placeholder={placeholder}\n style={{\n fontFamily,\n fontSize: `${Math.min(fontSize, 32)}px`,\n color,\n width: '100%',\n height: '100%',\n border: 'none',\n outline: 'none',\n background: 'transparent',\n textIndent: '8px',\n }}\n />\n <canvas ref={canvasRef} style={{ display: 'none' }} />\n </div>\n );\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { SignaturePluginPackage as BaseSignaturePackage } from '@embedpdf/plugin-signature';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-signature';\n\nexport const SignaturePluginPackage = createPluginPackage(BaseSignaturePackage).build();\n"],"names":["BaseSignaturePackage"],"mappings":";;;;;;AAIO,MAAM,qBAAqB,MAAM,UAA2B,gBAAgB,EAAE;AAC9E,MAAM,yBAAyB,MAAM,cAA+B,gBAAgB,EAAE;AAEtF,MAAM,sBAAsB,MAAM;AACvC,QAAM,EAAE,SAAA,IAAa,uBAAA;AACrB,QAAM,CAAC,SAAS,UAAU,IAAI,UAA2B,qCAAU,iBAAgB,EAAE;AAErF,YAAU,MAAM;AACd,QAAI,CAAC,SAAU;AACf,eAAW,SAAS,YAAY;AAChC,WAAO,SAAS,gBAAgB,CAAC,YAAY;AAC3C,iBAAW,OAAO;AAAA,IACpB,CAAC;AAAA,EACH,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO,EAAE,SAAS,SAAA;AACpB;AAEO,MAAM,qBAAqB,CAAC,eAAuB;AACxD,QAAM,EAAE,SAAA,IAAa,uBAAA;AACrB,QAAM,CAAC,iBAAiB,kBAAkB,IAAI,SAAqC,IAAI;AAEvF,YAAU,MAAM;AACd,QAAI,CAAC,SAAU;AACf,UAAM,QAAQ,SAAS,YAAY,UAAU;AAC7C,uBAAmB,MAAM,oBAAoB;AAC7C,WAAO,MAAM,wBAAwB,kBAAkB;AAAA,EACzD,GAAG,CAAC,UAAU,UAAU,CAAC;AAEzB,SAAO;AACT;ACZO,SAAS,mBAAmB;AAAA,EACjC,SAAS;AAAA,EACT;AACF,GAAwD;AACtD,QAAM,WAAW,OAAyB,IAAI;AAC9C,QAAM,CAAC,YAAY,a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AAA,UACP,QAAQ;AAAA,UACR,QAAQ;AAAA,UACR,SAAS;AAAA,UACT,YAAY;AAAA,UACZ,YAAY;AAAA,QAAA;AAAA,MACd;AAAA,IAAA;AAAA,IAEF,oBAAC,YAAO,KAAK,WAAW,OAAO,EAAE,SAAS,SAAO,CAAG;AAAA,EAAA,GACtD;AAEJ;AC/IO,MAAM,yBAAyB,oBAAoBA,wBAAoB,EAAE,MAAA;"}
@@ -0,0 +1,14 @@
1
+ export interface CropResult {
2
+ canvas: HTMLCanvasElement;
3
+ bounds: {
4
+ x: number;
5
+ y: number;
6
+ width: number;
7
+ height: number;
8
+ };
9
+ }
10
+ /**
11
+ * Scans a canvas for non-transparent pixels and returns a tightly cropped copy.
12
+ * Returns null if the canvas has no visible content.
13
+ */
14
+ export declare function cropCanvas(source: HTMLCanvasElement, padding?: number): CropResult | null;
@@ -0,0 +1,2 @@
1
+ export * from './signature-draw-pad';
2
+ export * from './signature-type-pad';
@@ -0,0 +1,12 @@
1
+ import { SignatureInkFieldDefinition } from '../../index.ts';
2
+ export interface SignatureDrawPadHandle {
3
+ clear(): void;
4
+ }
5
+ export interface SignatureDrawPadProps {
6
+ onResult: (result: SignatureInkFieldDefinition | null) => void;
7
+ padRef?: (handle: SignatureDrawPadHandle | null) => void;
8
+ strokeColor?: string;
9
+ strokeWidth?: number;
10
+ className?: string;
11
+ }
12
+ export declare function SignatureDrawPad({ onResult, padRef, strokeColor, strokeWidth, className, }: SignatureDrawPadProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,14 @@
1
+ import { SignatureStampFieldDefinition } from '../../index.ts';
2
+ export interface SignatureTypePadHandle {
3
+ clear(): void;
4
+ }
5
+ export interface SignatureTypePadProps {
6
+ onResult: (result: SignatureStampFieldDefinition | null) => void;
7
+ padRef?: (handle: SignatureTypePadHandle | null) => void;
8
+ fontFamily?: string;
9
+ fontSize?: number;
10
+ color?: string;
11
+ className?: string;
12
+ placeholder?: string;
13
+ }
14
+ export declare function SignatureTypePad({ onResult, padRef, fontFamily, fontSize, color, className, placeholder, }: SignatureTypePadProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ export * from './use-signature';
2
+ export * from './use-signature-upload';
@@ -0,0 +1,21 @@
1
+ import { SignatureStampFieldDefinition } from '../../index.ts';
2
+ export interface UseSignatureUploadOptions {
3
+ accept?: string;
4
+ onResult: (result: SignatureStampFieldDefinition | null) => void;
5
+ }
6
+ export interface UseSignatureUploadReturn {
7
+ inputRef: {
8
+ current: HTMLInputElement | null;
9
+ };
10
+ openFilePicker: () => void;
11
+ processFile: (file: File) => void;
12
+ handleFileInputChange: (e: Event) => void;
13
+ handleDrop: (e: DragEvent) => void;
14
+ handleDragOver: (e: DragEvent) => void;
15
+ handleDragLeave: () => void;
16
+ previewUrl: string | null;
17
+ isDragging: boolean;
18
+ clear: () => void;
19
+ accept: string;
20
+ }
21
+ export declare function useSignatureUpload({ accept, onResult, }: UseSignatureUploadOptions): UseSignatureUploadReturn;
@@ -0,0 +1,16 @@
1
+ import { SignaturePlugin, SignatureEntry, ActivePlacementInfo } from '../../index.ts';
2
+ export declare const useSignaturePlugin: () => {
3
+ plugin: SignaturePlugin | null;
4
+ isLoading: boolean;
5
+ ready: Promise<void>;
6
+ };
7
+ export declare const useSignatureCapability: () => {
8
+ provides: Readonly<import('../../index.ts').SignatureCapability> | null;
9
+ isLoading: boolean;
10
+ ready: Promise<void>;
11
+ };
12
+ export declare const useSignatureEntries: () => {
13
+ entries: SignatureEntry[];
14
+ provides: Readonly<import('../../index.ts').SignatureCapability> | null;
15
+ };
16
+ export declare const useActivePlacement: (documentId: string) => ActivePlacementInfo | null;
@@ -0,0 +1,4 @@
1
+ export * from './hooks';
2
+ export * from './components';
3
+ export * from '../index.ts';
4
+ export declare const SignaturePluginPackage: import('@embedpdf/core').WithAutoMount<import('@embedpdf/core').PluginPackage<import('../index.ts').SignaturePlugin, import('../index.ts').SignaturePluginConfig, import('../index.ts').SignatureState, import('../index.ts').SignatureAction>>;
@@ -0,0 +1,14 @@
1
+ export interface CropResult {
2
+ canvas: HTMLCanvasElement;
3
+ bounds: {
4
+ x: number;
5
+ y: number;
6
+ width: number;
7
+ height: number;
8
+ };
9
+ }
10
+ /**
11
+ * Scans a canvas for non-transparent pixels and returns a tightly cropped copy.
12
+ * Returns null if the canvas has no visible content.
13
+ */
14
+ export declare function cropCanvas(source: HTMLCanvasElement, padding?: number): CropResult | null;
@@ -0,0 +1,2 @@
1
+ export * from './signature-draw-pad';
2
+ export * from './signature-type-pad';
@@ -0,0 +1,12 @@
1
+ import { SignatureInkFieldDefinition } from '../../lib/index.ts';
2
+ export interface SignatureDrawPadHandle {
3
+ clear(): void;
4
+ }
5
+ export interface SignatureDrawPadProps {
6
+ onResult: (result: SignatureInkFieldDefinition | null) => void;
7
+ padRef?: (handle: SignatureDrawPadHandle | null) => void;
8
+ strokeColor?: string;
9
+ strokeWidth?: number;
10
+ className?: string;
11
+ }
12
+ export declare function SignatureDrawPad({ onResult, padRef, strokeColor, strokeWidth, className, }: SignatureDrawPadProps): import("preact").JSX.Element;
@@ -0,0 +1,14 @@
1
+ import { SignatureStampFieldDefinition } from '../../lib/index.ts';
2
+ export interface SignatureTypePadHandle {
3
+ clear(): void;
4
+ }
5
+ export interface SignatureTypePadProps {
6
+ onResult: (result: SignatureStampFieldDefinition | null) => void;
7
+ padRef?: (handle: SignatureTypePadHandle | null) => void;
8
+ fontFamily?: string;
9
+ fontSize?: number;
10
+ color?: string;
11
+ className?: string;
12
+ placeholder?: string;
13
+ }
14
+ export declare function SignatureTypePad({ onResult, padRef, fontFamily, fontSize, color, className, placeholder, }: SignatureTypePadProps): import("preact").JSX.Element;