epochs-pdf 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.
@@ -0,0 +1,3449 @@
1
+ var yi = Object.defineProperty;
2
+ var bi = (e, t, n) => t in e ? yi(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var Ht = (e, t, n) => bi(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { useRef as _e, useState as U, useEffect as xe, useMemo as Mt, useCallback as q, Fragment as _i } from "react";
5
+ import { jsxs as T, jsx as a, Fragment as bt } from "react/jsx-runtime";
6
+ import * as ct from "pdfjs-dist";
7
+ import { TextLayer as vi } from "pdfjs-dist";
8
+ const mt = "#ffffff", un = [
9
+ { id: "yellow", label: "Yellow", hex: "#facc15" },
10
+ { id: "green", label: "Green", hex: "#4ade80" },
11
+ { id: "pink", label: "Pink", hex: "#f472b6" },
12
+ { id: "blue", label: "Blue", hex: "#60a5fa" },
13
+ { id: "orange", label: "Orange", hex: "#fb923c" },
14
+ { id: "purple", label: "Purple", hex: "#c084fc" }
15
+ ], fn = [
16
+ { id: "blue", label: "Blue", hex: "#2563eb" },
17
+ { id: "red", label: "Red", hex: "#dc2626" },
18
+ { id: "green", label: "Green", hex: "#16a34a" },
19
+ { id: "orange", label: "Orange", hex: "#ea580c" },
20
+ { id: "purple", label: "Purple", hex: "#7c3aed" },
21
+ { id: "black", label: "Black", hex: "#111827" }
22
+ ], gn = un[0].hex, xi = fn[0].hex;
23
+ mn(gn, "highlight");
24
+ function zt() {
25
+ return `m_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
26
+ }
27
+ function Qe(e) {
28
+ const t = e.trim();
29
+ if (/^#[0-9a-fA-F]{6}$/.test(t)) return t.toLowerCase();
30
+ if (/^#[0-9a-fA-F]{3}$/.test(t)) {
31
+ const n = t[1], i = t[2], r = t[3];
32
+ return `#${n}${n}${i}${i}${r}${r}`.toLowerCase();
33
+ }
34
+ return t;
35
+ }
36
+ function mn(e, t, n = 0.45) {
37
+ const i = Qe(e);
38
+ if (t === "underline" || t === "redact") return i;
39
+ const r = /^#([0-9a-f]{6})$/i.exec(i);
40
+ if (!r) return `rgba(250, 204, 21, ${n})`;
41
+ const s = Number.parseInt(r[1], 16), c = s >> 16 & 255, l = s >> 8 & 255, y = s & 255;
42
+ return `rgba(${c}, ${l}, ${y}, ${n})`;
43
+ }
44
+ function jt(e, t) {
45
+ const n = window.getSelection();
46
+ if (!n || n.isCollapsed || n.rangeCount === 0)
47
+ return null;
48
+ const i = n.getRangeAt(0);
49
+ if (!e.contains(i.commonAncestorContainer))
50
+ return null;
51
+ const r = e.getBoundingClientRect(), s = Array.from(i.getClientRects()).filter(
52
+ (x) => x.width > 0 && x.height > 0
53
+ );
54
+ if (!s.length) return null;
55
+ const c = t || 1, l = e.clientWidth || r.width, y = e.clientHeight || r.height;
56
+ return { rects: s.map((x) => ({
57
+ x: r.width > 0 ? (x.left - r.left) / r.width * (l / c) : 0,
58
+ y: r.height > 0 ? (x.top - r.top) / r.height * (y / c) : 0,
59
+ w: r.width > 0 ? x.width / r.width * (l / c) : 0,
60
+ h: r.height > 0 ? x.height / r.height * (y / c) : 0
61
+ })), text: n.toString() };
62
+ }
63
+ function on(e) {
64
+ const n = [...e].sort((i, r) => i.y - r.y || i.x - r.x)[0] ?? { x: 0, y: 0, h: 14 };
65
+ return {
66
+ x: n.x,
67
+ y: n.y,
68
+ fontSize: Math.max(8, Math.round(n.h * 0.9) || 14)
69
+ };
70
+ }
71
+ function Ot(e, t = 2) {
72
+ return e.map((n) => ({
73
+ x: Math.max(0, n.x - t),
74
+ y: Math.max(0, n.y - t),
75
+ w: n.w + t * 2,
76
+ h: n.h + t * 2
77
+ }));
78
+ }
79
+ function wn(e, t, n) {
80
+ for (const i of t)
81
+ for (const r of i.rects) {
82
+ const s = r.x * n, c = r.y * n, l = r.w * n, y = r.h * n;
83
+ if (i.kind === "highlight")
84
+ e.save(), e.globalCompositeOperation = "multiply", e.fillStyle = i.color, e.fillRect(s, c, l, y), e.restore();
85
+ else if (i.kind === "redact")
86
+ e.fillStyle = i.color || mt, e.fillRect(s, c, l, y);
87
+ else {
88
+ const f = Math.max(2, n * 1.5);
89
+ e.fillStyle = i.color, e.fillRect(s, c + y - f, l, f);
90
+ }
91
+ }
92
+ }
93
+ function Tt() {
94
+ return `s_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
95
+ }
96
+ async function yn(e, t, n) {
97
+ for (const i of t) {
98
+ const r = await Mi(i.imageDataUrl);
99
+ e.drawImage(
100
+ r,
101
+ i.x * n,
102
+ i.y * n,
103
+ i.width * n,
104
+ i.height * n
105
+ );
106
+ }
107
+ }
108
+ function ki(e, t, n, i) {
109
+ e.save();
110
+ for (const r of t) {
111
+ const s = n.has(r.id), c = r.x * i, l = r.y * i, y = r.width * i, f = r.height * i;
112
+ e.fillStyle = s ? "rgba(29, 78, 216, 0.08)" : "rgba(29, 78, 216, 0.18)", e.strokeStyle = s ? "rgba(29, 78, 216, 0.45)" : "#1d4ed8", e.lineWidth = 1.5, e.setLineDash(s ? [] : [4, 3]), e.fillRect(c, l, y, f), e.strokeRect(c, l, y, f);
113
+ }
114
+ e.restore();
115
+ }
116
+ function Mi(e) {
117
+ return new Promise((t, n) => {
118
+ const i = new Image();
119
+ i.onload = () => t(i), i.onerror = () => n(new Error("Failed to load signature image")), i.src = e;
120
+ });
121
+ }
122
+ function Pi(e, t, n = 180, i = 64) {
123
+ if (e <= 0 || t <= 0)
124
+ return { width: n, height: i };
125
+ const r = Math.min(n / e, i / t);
126
+ return {
127
+ width: Math.max(40, e * r),
128
+ height: Math.max(20, t * r)
129
+ };
130
+ }
131
+ function Pt(e, t, n, i) {
132
+ const r = n.getBoundingClientRect(), s = n.clientWidth || r.width, c = n.clientHeight || r.height;
133
+ return r.width <= 0 || r.height <= 0 || i <= 0 ? { x: 0, y: 0 } : {
134
+ x: (e - r.left) / r.width * (s / i),
135
+ y: (t - r.top) / r.height * (c / i)
136
+ };
137
+ }
138
+ function yt(e, t) {
139
+ return {
140
+ width: e.clientWidth / t,
141
+ height: e.clientHeight / t
142
+ };
143
+ }
144
+ function Ni(e, t, n, i) {
145
+ const r = n.getBoundingClientRect(), s = n.clientWidth || r.width, c = n.clientHeight || r.height;
146
+ return r.width <= 0 || r.height <= 0 || i <= 0 ? { dx: 0, dy: 0 } : {
147
+ dx: e / r.width * (s / i),
148
+ dy: t / r.height * (c / i)
149
+ };
150
+ }
151
+ function $i(e, t, n) {
152
+ const i = t.getBoundingClientRect(), { width: r, height: s } = yt(t, n);
153
+ return i.width <= 0 || i.height <= 0 ? { left: 0, top: 0, right: r, bottom: s } : {
154
+ left: (e.left - i.left) / i.width * r,
155
+ top: (e.top - i.top) / i.height * s,
156
+ right: (e.right - i.left) / i.width * r,
157
+ bottom: (e.bottom - i.top) / i.height * s
158
+ };
159
+ }
160
+ const _t = 14, wt = "#111827", Ut = 24, Wt = 20;
161
+ function Gt() {
162
+ return `t_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
163
+ }
164
+ function ut(e, t) {
165
+ if (typeof document > "u")
166
+ return {
167
+ width: Math.max(Ut, e.length * t * 0.55),
168
+ height: Math.max(Wt, t * 1.25)
169
+ };
170
+ const i = document.createElement("canvas").getContext("2d");
171
+ if (!i)
172
+ return {
173
+ width: Math.max(Ut, e.length * t * 0.55),
174
+ height: Math.max(Wt, t * 1.25)
175
+ };
176
+ i.font = `${t}px sans-serif`;
177
+ const r = e.split(`
178
+ `), s = t * 1.25;
179
+ let c = Ut;
180
+ for (const l of r)
181
+ c = Math.max(c, i.measureText(l || " ").width + 4);
182
+ return {
183
+ width: c,
184
+ height: Math.max(Wt, r.length * s)
185
+ };
186
+ }
187
+ function Ti(e, t, n, i, r) {
188
+ var E;
189
+ const s = n.getBoundingClientRect(), c = n.clientWidth || s.width, l = n.clientHeight || s.height, y = (I) => s.width > 0 ? (I - s.left) / s.width * (c / r) : 0, f = (I) => s.height > 0 ? (I - s.top) / s.height * (l / r) : 0, x = (I, V) => {
190
+ const te = V === "x" ? s.width : s.height, X = V === "x" ? c : l;
191
+ return te > 0 ? I / te * (X / r) : 0;
192
+ };
193
+ let v = y(e), m = f(t), M = _t;
194
+ const $ = Ii(e, t, i);
195
+ if ($)
196
+ return {
197
+ x: y($.x),
198
+ y: f($.y),
199
+ fontSize: Math.max(8, Math.round(x($.fontSize, "y") * 10) / 10)
200
+ };
201
+ const G = document, S = (E = G.caretRangeFromPoint) == null ? void 0 : E.call(G, e, t);
202
+ if (S && i.contains(S.startContainer)) {
203
+ const I = S.getClientRects(), V = I.length > 0 ? I[0] : S.getBoundingClientRect();
204
+ if (V.height > 0) {
205
+ m = f(V.top), M = Li(S.startContainer, r, n);
206
+ const te = y(V.left);
207
+ return Math.abs(te - v) < x(8, "x") && (v = te), { x: v, y: m, fontSize: M };
208
+ }
209
+ }
210
+ const z = Ci(e, t, i);
211
+ return z && (m = f(z.top), M = Math.max(8, Math.round(x(z.height, "y") * 10) / 10)), { x: v, y: m, fontSize: M };
212
+ }
213
+ function Ii(e, t, n) {
214
+ var s;
215
+ const i = Array.from(
216
+ n.querySelectorAll("span")
217
+ );
218
+ if (i.length < 2) return null;
219
+ const r = [];
220
+ for (const c of i) {
221
+ if (!((s = c.textContent) != null && s.trim())) continue;
222
+ const l = c.getBoundingClientRect();
223
+ l.width <= 0 || l.height <= 0 || t < l.top - 4 || t > l.bottom + 4 || r.push({
224
+ left: l.left,
225
+ right: l.right,
226
+ top: l.top,
227
+ bottom: l.bottom,
228
+ height: l.height
229
+ });
230
+ }
231
+ r.sort((c, l) => c.left - l.left);
232
+ for (let c = 0; c < r.length - 1; c += 1) {
233
+ const l = r[c], y = r[c + 1], f = l.right, x = y.left;
234
+ if (!(x - f < 1) && e >= f - 2 && e <= x + 2)
235
+ return {
236
+ x: e,
237
+ y: Math.min(l.top, y.top),
238
+ fontSize: Math.min(l.height, y.height)
239
+ };
240
+ }
241
+ return null;
242
+ }
243
+ function Ci(e, t, n) {
244
+ var s;
245
+ const i = Array.from(
246
+ n.querySelectorAll("span")
247
+ );
248
+ let r = null;
249
+ for (const c of i) {
250
+ if (!((s = c.textContent) != null && s.trim())) continue;
251
+ const l = c.getBoundingClientRect();
252
+ if (l.width <= 0 || l.height <= 0 || t < l.top - 6 || t > l.bottom + 6) continue;
253
+ const y = (l.left + l.right) / 2, f = Math.abs(e - y);
254
+ (!r || f < r.dist) && (r = { top: l.top, height: l.height, dist: f });
255
+ }
256
+ return r ? { top: r.top, height: r.height } : null;
257
+ }
258
+ function Li(e, t, n) {
259
+ const i = e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement;
260
+ return i ? Ri(i, t, n) : _t;
261
+ }
262
+ function Ri(e, t, n) {
263
+ const i = e.getBoundingClientRect().height;
264
+ if (i > 0) {
265
+ if (n) {
266
+ const c = n.getBoundingClientRect(), l = n.clientHeight || c.height;
267
+ if (c.height > 0)
268
+ return Math.max(
269
+ 8,
270
+ Math.round(i / c.height * (l / t) * 10) / 10
271
+ );
272
+ }
273
+ return Math.max(8, Math.round(i / t * 10) / 10);
274
+ }
275
+ const r = window.getComputedStyle(e).fontSize, s = Number.parseFloat(r);
276
+ return Number.isFinite(s) && s > 0 ? Math.max(8, Math.round(s / t * 10) / 10) : _t;
277
+ }
278
+ function Di(e, t, n, i) {
279
+ for (const r of n)
280
+ if (r.pageNumber === i && e >= r.x && e <= r.x + r.width && t >= r.y && t <= r.y + r.height)
281
+ return r;
282
+ return null;
283
+ }
284
+ function Fi(e, t, n) {
285
+ var M;
286
+ if (!n) return null;
287
+ const i = document, r = (M = i.caretRangeFromPoint) == null ? void 0 : M.call(i, e, t);
288
+ if (!r || !n.contains(r.startContainer)) return null;
289
+ const s = r.startContainer;
290
+ if (s.nodeType !== Node.TEXT_NODE || !s.textContent) return null;
291
+ const c = s.textContent;
292
+ let l = r.startOffset;
293
+ l = Math.min(Math.max(0, l), c.length);
294
+ const y = ($) => /[\p{L}\p{N}_'-]/u.test($);
295
+ let f = l, x = l;
296
+ for (; f > 0 && y(c[f - 1]); ) f -= 1;
297
+ for (; x < c.length && y(c[x]); ) x += 1;
298
+ if (f === x) return null;
299
+ const v = document.createRange();
300
+ v.setStart(s, f), v.setEnd(s, x);
301
+ const m = window.getSelection();
302
+ return m == null || m.removeAllRanges(), m == null || m.addRange(v), c.slice(f, x);
303
+ }
304
+ function bn(e, t, n) {
305
+ e.save();
306
+ for (const i of t) {
307
+ if (!i.value.trim()) continue;
308
+ const r = i.x * n, s = i.y * n, c = Math.max(8, i.fontSize * n);
309
+ e.fillStyle = i.color, e.font = `${c}px sans-serif`, e.textBaseline = "top";
310
+ const l = c * 1.25, y = i.value.split(`
311
+ `);
312
+ let f = s;
313
+ for (const x of y)
314
+ e.fillText(x, r, f), f += l;
315
+ }
316
+ e.restore();
317
+ }
318
+ function Ai(e, t, n, i) {
319
+ e.save();
320
+ for (const r of t) {
321
+ const s = n.has(r.id), c = r.x * i, l = r.y * i, y = r.width * i, f = r.height * i;
322
+ e.fillStyle = s ? "rgba(5, 150, 105, 0.08)" : "rgba(5, 150, 105, 0.16)", e.strokeStyle = s ? "rgba(5, 150, 105, 0.45)" : "#059669", e.lineWidth = 1.5, e.setLineDash(s ? [] : [4, 3]), e.fillRect(c, l, y, f), e.strokeRect(c, l, y, f);
323
+ }
324
+ e.restore();
325
+ }
326
+ function Te({
327
+ size: e = 14,
328
+ className: t,
329
+ children: n
330
+ }) {
331
+ return /* @__PURE__ */ a(
332
+ "svg",
333
+ {
334
+ xmlns: "http://www.w3.org/2000/svg",
335
+ width: e,
336
+ height: e,
337
+ viewBox: "0 0 24 24",
338
+ fill: "none",
339
+ stroke: "currentColor",
340
+ strokeWidth: "2",
341
+ strokeLinecap: "round",
342
+ strokeLinejoin: "round",
343
+ className: t,
344
+ "aria-hidden": "true",
345
+ children: n
346
+ }
347
+ );
348
+ }
349
+ function Si(e) {
350
+ return /* @__PURE__ */ a(Te, { ...e, children: /* @__PURE__ */ a("polyline", { points: "15 18 9 12 15 6" }) });
351
+ }
352
+ function Ei(e) {
353
+ return /* @__PURE__ */ a(Te, { ...e, children: /* @__PURE__ */ a("polyline", { points: "9 18 15 12 9 6" }) });
354
+ }
355
+ function Bi(e) {
356
+ return /* @__PURE__ */ T(Te, { ...e, children: [
357
+ /* @__PURE__ */ a("path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" }),
358
+ /* @__PURE__ */ a("polyline", { points: "7 10 12 15 17 10" }),
359
+ /* @__PURE__ */ a("line", { x1: "12", y1: "15", x2: "12", y2: "3" })
360
+ ] });
361
+ }
362
+ function Hi(e) {
363
+ return /* @__PURE__ */ T(Te, { ...e, children: [
364
+ /* @__PURE__ */ a("path", { d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" }),
365
+ /* @__PURE__ */ a("polyline", { points: "15 3 21 3 21 9" }),
366
+ /* @__PURE__ */ a("line", { x1: "10", y1: "14", x2: "21", y2: "3" })
367
+ ] });
368
+ }
369
+ function zi(e) {
370
+ return /* @__PURE__ */ T(Te, { ...e, children: [
371
+ /* @__PURE__ */ a("rect", { x: "3", y: "3", width: "7", height: "7" }),
372
+ /* @__PURE__ */ a("rect", { x: "14", y: "3", width: "7", height: "7" }),
373
+ /* @__PURE__ */ a("rect", { x: "14", y: "14", width: "7", height: "7" }),
374
+ /* @__PURE__ */ a("rect", { x: "3", y: "14", width: "7", height: "7" })
375
+ ] });
376
+ }
377
+ function ji(e) {
378
+ return /* @__PURE__ */ a(Te, { ...e, children: /* @__PURE__ */ a("line", { x1: "5", y1: "12", x2: "19", y2: "12" }) });
379
+ }
380
+ function Oi(e) {
381
+ return /* @__PURE__ */ T(Te, { ...e, children: [
382
+ /* @__PURE__ */ a("line", { x1: "12", y1: "5", x2: "12", y2: "19" }),
383
+ /* @__PURE__ */ a("line", { x1: "5", y1: "12", x2: "19", y2: "12" })
384
+ ] });
385
+ }
386
+ function Ui(e) {
387
+ return /* @__PURE__ */ T(Te, { ...e, children: [
388
+ /* @__PURE__ */ a("polyline", { points: "6 9 6 2 18 2 18 9" }),
389
+ /* @__PURE__ */ a("path", { d: "M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2" }),
390
+ /* @__PURE__ */ a("rect", { x: "6", y: "14", width: "12", height: "8" })
391
+ ] });
392
+ }
393
+ function Wi(e) {
394
+ return /* @__PURE__ */ T(Te, { ...e, children: [
395
+ /* @__PURE__ */ a("polyline", { points: "23 4 23 10 17 10" }),
396
+ /* @__PURE__ */ a("polyline", { points: "1 20 1 14 7 14" }),
397
+ /* @__PURE__ */ a("path", { d: "M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15" })
398
+ ] });
399
+ }
400
+ function Gi(e) {
401
+ return /* @__PURE__ */ T(Te, { ...e, children: [
402
+ /* @__PURE__ */ a("polyline", { points: "23 4 23 10 17 10" }),
403
+ /* @__PURE__ */ a("path", { d: "M20.49 15a9 9 0 1 1-2.12-9.36L23 10" })
404
+ ] });
405
+ }
406
+ function Xi(e) {
407
+ return /* @__PURE__ */ T(Te, { ...e, children: [
408
+ /* @__PURE__ */ a("path", { d: "M12 20h9" }),
409
+ /* @__PURE__ */ a("path", { d: "M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z" })
410
+ ] });
411
+ }
412
+ function qi(e) {
413
+ return /* @__PURE__ */ T(Te, { ...e, children: [
414
+ /* @__PURE__ */ a("path", { d: "M6 3v7a6 6 0 0 0 12 0V3" }),
415
+ /* @__PURE__ */ a("line", { x1: "4", y1: "21", x2: "20", y2: "21" })
416
+ ] });
417
+ }
418
+ function Yi(e) {
419
+ return /* @__PURE__ */ T(Te, { ...e, children: [
420
+ /* @__PURE__ */ a("path", { d: "m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21" }),
421
+ /* @__PURE__ */ a("path", { d: "M22 21H7" }),
422
+ /* @__PURE__ */ a("path", { d: "m5 11 9 9" })
423
+ ] });
424
+ }
425
+ function Ki({ size: e = 16, className: t }) {
426
+ return /* @__PURE__ */ a(
427
+ "svg",
428
+ {
429
+ xmlns: "http://www.w3.org/2000/svg",
430
+ width: e,
431
+ height: e,
432
+ viewBox: "0 0 256 256",
433
+ fill: "currentColor",
434
+ stroke: "currentColor",
435
+ strokeWidth: "12",
436
+ strokeLinejoin: "round",
437
+ className: t,
438
+ "aria-hidden": "true",
439
+ children: /* @__PURE__ */ a("path", { d: "M232,172H57.32c4-7.83,8.18-16.11,12.21-24.56,15.14,3.55,34.13-8.06,56.54-34.59,3.67,12.5,12.53,34.83,29.08,35.15h.35c8.71,0,17.64-6.25,27.16-19.06C187.17,137.14,199.31,148,232,148a4,4,0,0,0,0-8c-42.88,0-44-19.24-44-20a4,4,0,0,0-7.35-2.18C168.74,136.1,160.42,140,155.48,140h-.18c-13-.25-21.29-26.52-23.38-36.61a4,4,0,0,0-7-1.69c-20.94,26.27-39.06,39.55-51.8,38.2C97.31,87.5,105.19,53.16,96.49,37.77,94,33.31,88.7,28,77.91,28,64.09,28,52.54,42.41,47,66.54A122.7,122.7,0,0,0,45.46,113c2.64,15.29,8.39,26.05,16.69,31.35-4.58,9.6-9.3,19-13.84,27.68H24a4,4,0,0,0,0,8H44.1c-12.87,24.17-23.37,41.68-23.53,41.94a4,4,0,0,0,1.37,5.49A3.93,3.93,0,0,0,24,228a4,4,0,0,0,3.43-1.94c.16-.27,11.85-19.75,25.72-46.06H232a4,4,0,0,0,0-8ZM53.34,111.61a114.81,114.81,0,0,1,1.49-43.29C58.4,52.7,66.34,36,77.91,36c7.52,0,10.23,3.26,11.61,5.7C99,58.4,79.92,106,65.6,137,59.76,132.69,55.46,123.83,53.34,111.61Z" })
440
+ }
441
+ );
442
+ }
443
+ function Zi(e) {
444
+ return /* @__PURE__ */ T(Te, { ...e, children: [
445
+ /* @__PURE__ */ a("path", { d: "M12 20h9" }),
446
+ /* @__PURE__ */ a("path", { d: "M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z" })
447
+ ] });
448
+ }
449
+ function Vi(e) {
450
+ return /* @__PURE__ */ T(Te, { ...e, children: [
451
+ /* @__PURE__ */ a("polyline", { points: "4 7 4 4 20 4 20 7" }),
452
+ /* @__PURE__ */ a("line", { x1: "9", y1: "20", x2: "15", y2: "20" }),
453
+ /* @__PURE__ */ a("line", { x1: "12", y1: "4", x2: "12", y2: "20" })
454
+ ] });
455
+ }
456
+ function Qi({
457
+ pdfDoc: e,
458
+ pageNumber: t,
459
+ scale: n,
460
+ rotation: i,
461
+ pageRef: r,
462
+ onRendered: s,
463
+ markupTool: c = "none",
464
+ markupColor: l,
465
+ annotations: y = [],
466
+ onAddAnnotation: f,
467
+ onRemoveAnnotation: x,
468
+ signatures: v = [],
469
+ pendingSignature: m = null,
470
+ onAddSignature: M,
471
+ onUpdateSignature: $,
472
+ onRemoveSignature: G,
473
+ onEditSignature: S,
474
+ onDuplicateSignature: z,
475
+ selectedSignatureId: E = null,
476
+ onSelectSignature: I,
477
+ signatureFields: V = [],
478
+ selectedSignatureFieldId: te = null,
479
+ onSelectSignatureField: X,
480
+ hasFixedSignatureFields: oe = !1,
481
+ onOpenSignaturePad: ke,
482
+ fieldValues: ye = {},
483
+ onFieldValueChange: D,
484
+ onFieldValueCommit: ae,
485
+ pendingFieldValue: C = null,
486
+ onPlaceFieldValue: F,
487
+ texts: Q = [],
488
+ onAddText: Me,
489
+ onUpdateText: Ie,
490
+ onRemoveText: ue,
491
+ selectedTextId: be = null,
492
+ onSelectText: J,
493
+ textFields: Ee = [],
494
+ selectedTextFieldId: Ye = null,
495
+ onSelectTextField: Pe,
496
+ hasFixedTextFields: Oe = !1,
497
+ editingTextId: ve = null,
498
+ onEditingTextIdChange: B
499
+ }) {
500
+ const fe = _e(null), je = _e(null), ie = _e(null), ge = _e(null), he = _e(null), u = _e(null), [g, j] = U(null), Y = _e(null), se = _e(!1);
501
+ xe(() => {
502
+ if (!e || !je.current || !ie.current || !ge.current)
503
+ return;
504
+ let o = !1;
505
+ const w = je.current, _ = ie.current, k = ge.current, P = w.getContext("2d");
506
+ return P ? ((async () => {
507
+ try {
508
+ if (he.current) {
509
+ try {
510
+ he.current.cancel();
511
+ } catch {
512
+ }
513
+ he.current = null;
514
+ }
515
+ if (u.current) {
516
+ try {
517
+ u.current.cancel();
518
+ } catch {
519
+ }
520
+ u.current = null;
521
+ }
522
+ const L = await e.getPage(t);
523
+ if (o) return;
524
+ const O = L.getViewport({ scale: n, rotation: i }), Z = Math.floor(O.width), W = Math.floor(O.height);
525
+ w.width = Z, w.height = W, k.style.width = `${Z}px`, k.style.height = `${W}px`;
526
+ const H = L.render({ canvasContext: P, viewport: O });
527
+ if (he.current = H, await H.promise, o) return;
528
+ _.replaceChildren(), _.style.setProperty("--scale-factor", String(O.scale));
529
+ const le = await L.getTextContent();
530
+ if (o) return;
531
+ const de = new vi({
532
+ textContentSource: le,
533
+ container: _,
534
+ viewport: O
535
+ });
536
+ if (u.current = de, await de.render(), o) return;
537
+ s == null || s(t);
538
+ } catch {
539
+ }
540
+ })(), () => {
541
+ if (o = !0, he.current) {
542
+ try {
543
+ he.current.cancel();
544
+ } catch {
545
+ }
546
+ he.current = null;
547
+ }
548
+ if (u.current) {
549
+ try {
550
+ u.current.cancel();
551
+ } catch {
552
+ }
553
+ u.current = null;
554
+ }
555
+ }) : void 0;
556
+ }, [e, t, n, i, s]), xe(() => {
557
+ const o = ge.current;
558
+ if (!o) return;
559
+ const w = (N) => {
560
+ var W;
561
+ if (!f) return !1;
562
+ const L = N === "redact" ? mt : l;
563
+ if (!L) return !1;
564
+ const O = jt(o, n);
565
+ if (!O) return !1;
566
+ const Z = N === "redact" ? Ot(O.rects) : O.rects;
567
+ return f({
568
+ id: zt(),
569
+ pageNumber: t,
570
+ kind: N,
571
+ color: L,
572
+ rects: Z,
573
+ text: O.text
574
+ }), (W = window.getSelection()) == null || W.removeAllRanges(), !0;
575
+ }, _ = (N) => {
576
+ var le;
577
+ if (!f || !Me) return !1;
578
+ const L = jt(o, n);
579
+ if (!L) return !1;
580
+ const O = Ot(L.rects);
581
+ f({
582
+ id: zt(),
583
+ pageNumber: t,
584
+ kind: "redact",
585
+ color: mt,
586
+ rects: O,
587
+ text: L.text
588
+ });
589
+ const Z = on(L.rects), W = ut(N || " ", Z.fontSize), H = {
590
+ id: Gt(),
591
+ pageNumber: t,
592
+ x: Z.x,
593
+ y: Z.y,
594
+ width: W.width,
595
+ height: W.height,
596
+ value: N,
597
+ fontSize: Z.fontSize,
598
+ color: wt
599
+ };
600
+ return Me(H), J == null || J(H.id), B == null || B(H.id), (le = window.getSelection()) == null || le.removeAllRanges(), se.current = !0, window.setTimeout(() => {
601
+ se.current = !1;
602
+ }, 0), !0;
603
+ }, k = () => {
604
+ if (c === "highlight" || c === "underline") {
605
+ w(c);
606
+ return;
607
+ }
608
+ if (c === "erase") {
609
+ w("redact");
610
+ return;
611
+ }
612
+ if (c === "text") {
613
+ const N = window.getSelection();
614
+ N && !N.isCollapsed && N.toString().trim() && N.anchorNode && o.contains(N.anchorNode) && _(N.toString());
615
+ }
616
+ }, P = (N) => {
617
+ const L = N.target;
618
+ if (L != null && L.closest("[contenteditable='true']") || L != null && L.closest("[contenteditable='']") || L != null && L.isContentEditable)
619
+ return;
620
+ const O = window.getSelection(), Z = O != null && !O.isCollapsed && O.toString().trim().length > 0 && O.anchorNode != null && o.contains(O.anchorNode);
621
+ if (c === "text" && Z) {
622
+ if (N.key === "Enter" && !N.shiftKey) {
623
+ N.preventDefault(), _(O.toString());
624
+ return;
625
+ }
626
+ if (N.key.length === 1 && !N.ctrlKey && !N.metaKey && !N.altKey) {
627
+ N.preventDefault(), _(N.key);
628
+ return;
629
+ }
630
+ }
631
+ c !== "text" && c !== "erase" || N.key !== "Backspace" && N.key !== "Delete" || Z && (N.preventDefault(), w("redact"));
632
+ };
633
+ return o.addEventListener("mouseup", k), window.addEventListener("keydown", P), () => {
634
+ o.removeEventListener("mouseup", k), window.removeEventListener("keydown", P);
635
+ };
636
+ }, [
637
+ c,
638
+ l,
639
+ f,
640
+ Me,
641
+ B,
642
+ J,
643
+ t,
644
+ n
645
+ ]), xe(() => {
646
+ if (!g) return;
647
+ let o = 0, w = 0, _ = 0, k = 0;
648
+ const P = () => {
649
+ var H;
650
+ return (H = fe.current) == null ? void 0 : H.closest(".epochs-pdf-viewer__body");
651
+ }, N = (H, le) => {
652
+ if (g.kind !== "resize" || !$ || oe) return;
653
+ const de = v.find((Xe) => Xe.id === g.id);
654
+ if (!de) return;
655
+ const ne = ge.current, Ne = ne ? yt(ne, n) : { width: 1 / 0, height: 1 / 0 }, { dx: pe, dy: me } = ne ? Ni(
656
+ H - g.startX,
657
+ le - g.startY,
658
+ ne,
659
+ n
660
+ ) : { dx: 0, dy: 0 }, $e = Ne.width - de.x, Ge = Ne.height - de.y, Se = Math.min($e, Math.max(40, g.startW + pe)), lt = Math.min(Ge, Math.max(20, g.startH + me));
661
+ $(g.id, { width: Se, height: lt });
662
+ }, L = (H, le) => {
663
+ var xt;
664
+ if (g.kind !== "signature" || !$ || oe) return;
665
+ const de = v.find((Ze) => Ze.id === g.id);
666
+ if (!de) return;
667
+ let ne = (xt = document.elementFromPoint(H, le)) == null ? void 0 : xt.closest("[data-page-number]");
668
+ if (ne || (ne = Array.from(
669
+ document.querySelectorAll(".epochs-pdf-viewer__page[data-page-number]")
670
+ ).find((Lt) => {
671
+ const Je = Lt.getBoundingClientRect();
672
+ return le >= Je.top && le <= Je.bottom;
673
+ }) ?? null), ne || (ne = fe.current), !ne) return;
674
+ const Ne = ne.querySelector(
675
+ ".epochs-pdf-viewer__surface"
676
+ );
677
+ if (!Ne) return;
678
+ const pe = Number.parseInt(
679
+ ne.getAttribute("data-page-number") || String(de.pageNumber),
680
+ 10
681
+ ), me = Pt(H, le, Ne, n), $e = yt(Ne, n);
682
+ let Ge = me.x - g.offsetX, Se = me.y - g.offsetY;
683
+ const lt = Math.max(0, $e.width - de.width), Xe = Math.max(0, $e.height - de.height);
684
+ Ge = Math.min(Math.max(0, Ge), lt), Se = Math.min(Math.max(0, Se), Xe), $(g.id, {
685
+ pageNumber: pe,
686
+ x: Ge,
687
+ y: Se
688
+ });
689
+ }, O = () => {
690
+ if (o = 0, !k) return;
691
+ const H = P();
692
+ if (!H) return;
693
+ const le = H.scrollHeight - H.clientHeight;
694
+ if (le <= 0) return;
695
+ const de = 56, ne = H.getBoundingClientRect(), Ne = _ - ne.top, pe = ne.bottom - _;
696
+ let me = 0;
697
+ if (k < 0 && Ne < de)
698
+ me = -Math.max(6, (de - Ne) / de * 28);
699
+ else if (k > 0 && pe < de)
700
+ me = Math.max(6, (de - pe) / de * 28);
701
+ else {
702
+ k = 0;
703
+ return;
704
+ }
705
+ const $e = H.scrollTop;
706
+ H.scrollTop = Math.min(le, Math.max(0, $e + me)), H.scrollTop !== $e && L(w, _), me < 0 && H.scrollTop > 0 || me > 0 && H.scrollTop < le ? o = window.requestAnimationFrame(O) : k = 0;
707
+ }, Z = (H) => {
708
+ w = H.clientX, _ = H.clientY;
709
+ const le = P();
710
+ if (le) {
711
+ const ne = le.getBoundingClientRect(), Ne = H.clientY - ne.top, pe = ne.bottom - H.clientY;
712
+ Ne < 56 ? (k = -1, o || (o = window.requestAnimationFrame(O))) : pe < 56 ? (k = 1, o || (o = window.requestAnimationFrame(O))) : k = 0;
713
+ }
714
+ g.kind === "resize" ? N(H.clientX, H.clientY) : L(H.clientX, H.clientY);
715
+ }, W = () => {
716
+ k = 0, o && (window.cancelAnimationFrame(o), o = 0), j(null);
717
+ };
718
+ return window.addEventListener("pointermove", Z), window.addEventListener("pointerup", W), window.addEventListener("pointercancel", W), () => {
719
+ k = 0, o && window.cancelAnimationFrame(o), window.removeEventListener("pointermove", Z), window.removeEventListener("pointerup", W), window.removeEventListener("pointercancel", W);
720
+ };
721
+ }, [
722
+ g,
723
+ oe,
724
+ $,
725
+ n,
726
+ v
727
+ ]), xe(() => {
728
+ if (!ve || !Y.current) return;
729
+ const o = Y.current, w = Q.find((P) => P.id === ve);
730
+ o.textContent = (w == null ? void 0 : w.value) ?? "", o.focus();
731
+ const _ = document.createRange();
732
+ _.selectNodeContents(o), _.collapse(!1);
733
+ const k = window.getSelection();
734
+ k == null || k.removeAllRanges(), k == null || k.addRange(_);
735
+ }, [ve]);
736
+ const re = (o) => {
737
+ fe.current = o, r == null || r(o);
738
+ }, Ce = y.filter((o) => o.pageNumber === t), ce = v.filter((o) => o.pageNumber === t), Be = V.filter((o) => o.pageNumber === t), Ae = Q.filter((o) => o.pageNumber === t), Ue = (o, w) => {
739
+ const _ = w.trim();
740
+ if (!_) {
741
+ ue == null || ue(o.id), B == null || B(null);
742
+ return;
743
+ }
744
+ const k = ut(_, o.fontSize);
745
+ Ie == null || Ie(o.id, {
746
+ value: _,
747
+ width: k.width,
748
+ height: k.height
749
+ }), B == null || B(null);
750
+ }, Ke = (o, w) => {
751
+ if (!Me) return;
752
+ const _ = ge.current, k = ie.current;
753
+ if (!_ || !k) return;
754
+ let P = Ti(
755
+ o,
756
+ w,
757
+ _,
758
+ k,
759
+ n
760
+ ), N, L = wt;
761
+ if (Oe) {
762
+ const W = Di(
763
+ P.x,
764
+ P.y,
765
+ Ee,
766
+ t
767
+ );
768
+ if (!W) return;
769
+ const H = Q.find((le) => le.fieldId === W.id);
770
+ if (H) {
771
+ J == null || J(H.id), Pe == null || Pe(W.id), B == null || B(H.id);
772
+ return;
773
+ }
774
+ N = W.id, P = {
775
+ x: W.x,
776
+ y: W.y,
777
+ fontSize: W.fontSize ?? _t
778
+ }, L = W.color ?? wt, Pe == null || Pe(W.id);
779
+ }
780
+ const O = ut("", P.fontSize), Z = {
781
+ id: Gt(),
782
+ fieldId: N,
783
+ pageNumber: t,
784
+ x: P.x,
785
+ y: P.y,
786
+ width: O.width,
787
+ height: O.height,
788
+ value: "",
789
+ fontSize: P.fontSize,
790
+ color: L
791
+ };
792
+ Me(Z), J == null || J(Z.id), B == null || B(Z.id);
793
+ }, Le = (o) => {
794
+ var _;
795
+ if (c !== "text" || o.target.closest(".epochs-pdf-viewer__inline-text"))
796
+ return;
797
+ if (se.current) {
798
+ se.current = !1;
799
+ return;
800
+ }
801
+ const w = window.getSelection();
802
+ if (!(w && !w.isCollapsed && w.toString().trim())) {
803
+ if (o.detail >= 2 && Fi(o.clientX, o.clientY, ie.current)) {
804
+ const P = ge.current;
805
+ if (P && f && Me) {
806
+ const N = jt(P, n);
807
+ if (N) {
808
+ f({
809
+ id: zt(),
810
+ pageNumber: t,
811
+ kind: "redact",
812
+ color: mt,
813
+ rects: Ot(N.rects),
814
+ text: N.text
815
+ });
816
+ const L = on(N.rects), O = ut(N.text || " ", L.fontSize), Z = {
817
+ id: Gt(),
818
+ pageNumber: t,
819
+ x: L.x,
820
+ y: L.y,
821
+ width: O.width,
822
+ height: O.height,
823
+ value: N.text,
824
+ fontSize: L.fontSize,
825
+ color: wt
826
+ };
827
+ Me(Z), J == null || J(Z.id), B == null || B(Z.id), (_ = window.getSelection()) == null || _.removeAllRanges(), se.current = !0;
828
+ }
829
+ }
830
+ return;
831
+ }
832
+ o.stopPropagation(), Ke(o.clientX, o.clientY);
833
+ }
834
+ }, We = (o) => {
835
+ const w = o.target;
836
+ if (!(w.closest(".epochs-pdf-viewer__signature") || w.closest(".epochs-pdf-viewer__signature-field") || w.closest(".epochs-pdf-viewer__inline-text"))) {
837
+ if (c === "text") {
838
+ Ke(o.clientX, o.clientY);
839
+ return;
840
+ }
841
+ if (!oe && c === "sign" && C && F) {
842
+ const _ = ge.current;
843
+ if (!_) return;
844
+ const k = Pt(o.clientX, o.clientY, _, n);
845
+ F(t, Math.max(0, k.x - 75), Math.max(0, k.y - 12));
846
+ return;
847
+ }
848
+ if (!oe && c === "sign" && m && M) {
849
+ const _ = ge.current;
850
+ if (!_) return;
851
+ const k = yt(_, n), P = Pt(o.clientX, o.clientY, _, n);
852
+ let N = P.x - m.width / 2, L = P.y - m.height / 2;
853
+ const O = Math.max(0, k.width - m.width), Z = Math.max(0, k.height - m.height);
854
+ N = Math.min(Math.max(0, N), O), L = Math.min(Math.max(0, L), Z), M({
855
+ id: Tt(),
856
+ pageNumber: t,
857
+ x: N,
858
+ y: L,
859
+ width: m.width,
860
+ height: m.height,
861
+ imageDataUrl: m.imageDataUrl
862
+ });
863
+ return;
864
+ }
865
+ }
866
+ }, vt = (o) => ve === o.id ? /* @__PURE__ */ a(
867
+ "span",
868
+ {
869
+ ref: Y,
870
+ contentEditable: !0,
871
+ suppressContentEditableWarning: !0,
872
+ role: "textbox",
873
+ "aria-label": "Edit text",
874
+ className: "epochs-pdf-viewer__inline-text epochs-pdf-viewer__inline-text--editing",
875
+ style: {
876
+ left: o.x * n,
877
+ top: o.y * n,
878
+ fontSize: o.fontSize * n,
879
+ color: o.color,
880
+ minWidth: Math.max(12, o.fontSize * n * 0.5),
881
+ width: Math.max(o.width * n, o.fontSize * n * 0.5)
882
+ },
883
+ onClick: (_) => _.stopPropagation(),
884
+ onPointerDown: (_) => _.stopPropagation(),
885
+ onInput: (_) => {
886
+ const k = _.currentTarget.textContent ?? "", P = ut(k || " ", o.fontSize);
887
+ Ie == null || Ie(o.id, {
888
+ value: k,
889
+ width: P.width,
890
+ height: P.height
891
+ });
892
+ },
893
+ onBlur: (_) => {
894
+ Ue(o, _.currentTarget.textContent ?? "");
895
+ },
896
+ onKeyDown: (_) => {
897
+ _.stopPropagation(), _.key === "Escape" && (_.preventDefault(), _.currentTarget.blur()), _.key === "Enter" && !_.shiftKey && (_.preventDefault(), _.currentTarget.blur());
898
+ }
899
+ },
900
+ o.id
901
+ ) : o.value.trim() ? /* @__PURE__ */ a(
902
+ "span",
903
+ {
904
+ className: be === o.id ? "epochs-pdf-viewer__inline-text epochs-pdf-viewer__inline-text--selected" : "epochs-pdf-viewer__inline-text",
905
+ style: {
906
+ left: o.x * n,
907
+ top: o.y * n,
908
+ fontSize: o.fontSize * n,
909
+ color: o.color
910
+ },
911
+ onClick: (_) => {
912
+ if (_.stopPropagation(), c === "erase") {
913
+ ue == null || ue(o.id);
914
+ return;
915
+ }
916
+ c === "text" && (J == null || J(o.id), B == null || B(o.id));
917
+ },
918
+ children: o.value
919
+ },
920
+ o.id
921
+ ) : null;
922
+ return /* @__PURE__ */ a(
923
+ "div",
924
+ {
925
+ ref: re,
926
+ "data-page-number": t,
927
+ className: "epochs-pdf-viewer__page",
928
+ children: /* @__PURE__ */ T(
929
+ "div",
930
+ {
931
+ ref: ge,
932
+ className: `epochs-pdf-viewer__surface epochs-pdf-viewer__surface--tool-${c}`,
933
+ onClick: We,
934
+ children: [
935
+ /* @__PURE__ */ a("canvas", { ref: je, className: "epochs-pdf-viewer__canvas" }),
936
+ /* @__PURE__ */ a("div", { className: "epochs-pdf-viewer__markup-layer", "aria-hidden": "true", children: Ce.map(
937
+ (o) => o.kind === "redact" ? null : o.rects.map((w, _) => o.kind === "highlight" ? /* @__PURE__ */ a(
938
+ "div",
939
+ {
940
+ className: "epochs-pdf-viewer__markup epochs-pdf-viewer__markup--highlight",
941
+ style: {
942
+ left: w.x * n,
943
+ top: w.y * n,
944
+ width: w.w * n,
945
+ height: w.h * n,
946
+ background: o.color
947
+ },
948
+ onClick: (k) => {
949
+ c === "erase" && (k.stopPropagation(), x == null || x(o.id));
950
+ }
951
+ },
952
+ `${o.id}_${_}`
953
+ ) : /* @__PURE__ */ a(
954
+ "div",
955
+ {
956
+ className: "epochs-pdf-viewer__markup epochs-pdf-viewer__markup--underline",
957
+ style: {
958
+ left: w.x * n,
959
+ top: (w.y + w.h) * n - Math.max(2, n * 1.5),
960
+ width: w.w * n,
961
+ height: Math.max(2, n * 1.5),
962
+ background: o.color
963
+ },
964
+ onClick: (k) => {
965
+ c === "erase" && (k.stopPropagation(), x == null || x(o.id));
966
+ }
967
+ },
968
+ `${o.id}_${_}`
969
+ ))
970
+ ) }),
971
+ /* @__PURE__ */ T("div", { className: "epochs-pdf-viewer__signature-layer", children: [
972
+ Be.map((o) => {
973
+ const w = ce.some((_) => _.fieldId === o.id);
974
+ return /* @__PURE__ */ a(
975
+ "button",
976
+ {
977
+ type: "button",
978
+ "data-signature-field-id": o.id,
979
+ className: te === o.id ? "epochs-pdf-viewer__signature-field epochs-pdf-viewer__signature-field--selected" : w ? "epochs-pdf-viewer__signature-field epochs-pdf-viewer__signature-field--filled" : "epochs-pdf-viewer__signature-field",
980
+ style: {
981
+ left: o.x * n,
982
+ top: o.y * n,
983
+ width: o.width * n,
984
+ height: o.height * n
985
+ },
986
+ onClick: (_) => {
987
+ _.stopPropagation();
988
+ const k = o.type;
989
+ if (k === "date" || k === "text") return;
990
+ X == null || X(o.id);
991
+ const P = ce.find((N) => N.fieldId === o.id);
992
+ I == null || I((P == null ? void 0 : P.id) ?? null), P ? S == null || S(P.id) : ke == null || ke(o.type);
993
+ },
994
+ title: w ? "Signed field" : "Signature field",
995
+ children: (() => {
996
+ const _ = o.type;
997
+ return _ === "date" ? /* @__PURE__ */ a(
998
+ "input",
999
+ {
1000
+ type: "date",
1001
+ className: "epochs-pdf-viewer__signature-field-input",
1002
+ value: ye[o.id] ?? "",
1003
+ onClick: (k) => k.stopPropagation(),
1004
+ onChange: (k) => {
1005
+ k.stopPropagation(), D == null || D(o.id, k.target.value), ae == null || ae(o.id);
1006
+ },
1007
+ style: { width: "100%", height: "100%" }
1008
+ }
1009
+ ) : _ === "text" ? /* @__PURE__ */ a(
1010
+ "input",
1011
+ {
1012
+ type: "text",
1013
+ className: "epochs-pdf-viewer__signature-field-input",
1014
+ value: ye[o.id] ?? "",
1015
+ placeholder: o.placeholder ?? "Enter text",
1016
+ onClick: (k) => k.stopPropagation(),
1017
+ onChange: (k) => {
1018
+ k.stopPropagation(), D == null || D(o.id, k.target.value);
1019
+ },
1020
+ onBlur: () => ae == null ? void 0 : ae(o.id),
1021
+ style: { width: "100%", height: "100%" }
1022
+ }
1023
+ ) : w ? null : /* @__PURE__ */ a("span", { children: "Sign here" });
1024
+ })()
1025
+ },
1026
+ o.id
1027
+ );
1028
+ }),
1029
+ ce.map((o) => /* @__PURE__ */ T(
1030
+ "div",
1031
+ {
1032
+ className: E === o.id ? "epochs-pdf-viewer__signature epochs-pdf-viewer__signature--selected" : "epochs-pdf-viewer__signature",
1033
+ style: {
1034
+ left: o.x * n,
1035
+ top: o.y * n,
1036
+ width: o.width * n,
1037
+ height: o.height * n
1038
+ },
1039
+ onPointerDown: (w) => {
1040
+ if (w.stopPropagation(), w.preventDefault(), I == null || I(o.id), c === "erase" && !oe) {
1041
+ G == null || G(o.id);
1042
+ return;
1043
+ }
1044
+ if (oe) {
1045
+ X == null || X(o.fieldId ?? null), S == null || S(o.id);
1046
+ return;
1047
+ }
1048
+ const _ = ge.current;
1049
+ if (!_) return;
1050
+ const k = Pt(w.clientX, w.clientY, _, n);
1051
+ j({
1052
+ kind: "signature",
1053
+ id: o.id,
1054
+ offsetX: k.x - o.x,
1055
+ offsetY: k.y - o.y
1056
+ });
1057
+ },
1058
+ children: [
1059
+ /* @__PURE__ */ a(
1060
+ "button",
1061
+ {
1062
+ type: "button",
1063
+ className: "epochs-pdf-viewer__signature-edit",
1064
+ title: "Edit signature",
1065
+ "aria-label": "Edit signature",
1066
+ onPointerDown: (w) => {
1067
+ w.stopPropagation();
1068
+ },
1069
+ onClick: (w) => {
1070
+ w.stopPropagation(), I == null || I(o.id), S == null || S(o.id);
1071
+ },
1072
+ children: /* @__PURE__ */ a(Zi, { size: 12 })
1073
+ }
1074
+ ),
1075
+ oe ? null : /* @__PURE__ */ T(bt, { children: [
1076
+ /* @__PURE__ */ a(
1077
+ "button",
1078
+ {
1079
+ type: "button",
1080
+ className: "epochs-pdf-viewer__signature-duplicate",
1081
+ title: "Duplicate signature",
1082
+ "aria-label": "Duplicate signature",
1083
+ onPointerDown: (w) => {
1084
+ w.stopPropagation();
1085
+ },
1086
+ onClick: (w) => {
1087
+ w.stopPropagation(), I == null || I(o.id), z == null || z(o.id);
1088
+ },
1089
+ children: "⧉"
1090
+ }
1091
+ ),
1092
+ /* @__PURE__ */ a(
1093
+ "button",
1094
+ {
1095
+ type: "button",
1096
+ className: "epochs-pdf-viewer__signature-remove",
1097
+ title: "Remove signature",
1098
+ "aria-label": "Remove signature",
1099
+ onPointerDown: (w) => {
1100
+ w.stopPropagation();
1101
+ },
1102
+ onClick: (w) => {
1103
+ w.stopPropagation(), G == null || G(o.id);
1104
+ },
1105
+ children: "×"
1106
+ }
1107
+ )
1108
+ ] }),
1109
+ /* @__PURE__ */ a("img", { src: o.imageDataUrl, alt: "Signature", draggable: !1 }),
1110
+ oe ? null : /* @__PURE__ */ a(
1111
+ "div",
1112
+ {
1113
+ className: "epochs-pdf-viewer__signature-resize",
1114
+ title: "Resize",
1115
+ onPointerDown: (w) => {
1116
+ w.stopPropagation(), w.preventDefault(), I == null || I(o.id), j({
1117
+ kind: "resize",
1118
+ id: o.id,
1119
+ startX: w.clientX,
1120
+ startY: w.clientY,
1121
+ startW: o.width,
1122
+ startH: o.height
1123
+ });
1124
+ },
1125
+ children: /* @__PURE__ */ a("svg", { width: "8", height: "8", viewBox: "0 0 8 8", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ a("path", { d: "M7 1L1 7M7 4L4 7", stroke: "white", strokeWidth: "1.2", strokeLinecap: "round" }) })
1126
+ }
1127
+ )
1128
+ ]
1129
+ },
1130
+ o.id
1131
+ ))
1132
+ ] }),
1133
+ /* @__PURE__ */ a("div", { className: "epochs-pdf-viewer__text-layer-overlay", children: Ae.map((o) => vt(o)) }),
1134
+ /* @__PURE__ */ a(
1135
+ "div",
1136
+ {
1137
+ ref: ie,
1138
+ className: "textLayer epochs-pdf-viewer__text-layer",
1139
+ onClick: Le
1140
+ }
1141
+ ),
1142
+ /* @__PURE__ */ a("div", { className: "epochs-pdf-viewer__redact-layer", "aria-hidden": "true", children: Ce.map(
1143
+ (o) => o.kind === "redact" ? o.rects.map((w, _) => /* @__PURE__ */ a(
1144
+ "div",
1145
+ {
1146
+ className: "epochs-pdf-viewer__markup epochs-pdf-viewer__markup--redact",
1147
+ style: {
1148
+ left: w.x * n,
1149
+ top: w.y * n,
1150
+ width: w.w * n,
1151
+ height: w.h * n,
1152
+ background: o.color || mt
1153
+ },
1154
+ onClick: (k) => {
1155
+ c === "erase" && (k.stopPropagation(), x == null || x(o.id));
1156
+ }
1157
+ },
1158
+ `${o.id}_${_}`
1159
+ )) : null
1160
+ ) })
1161
+ ]
1162
+ }
1163
+ )
1164
+ }
1165
+ );
1166
+ }
1167
+ function Ji({
1168
+ pdfDoc: e,
1169
+ pageNumber: t,
1170
+ isActive: n,
1171
+ rotation: i,
1172
+ onSelect: r,
1173
+ width: s = 140,
1174
+ annotations: c = [],
1175
+ signatures: l = [],
1176
+ signatureFields: y = [],
1177
+ texts: f = [],
1178
+ textFields: x = []
1179
+ }) {
1180
+ const v = _e(null);
1181
+ return xe(() => {
1182
+ if (!e || !v.current) return;
1183
+ let m = !1;
1184
+ const M = v.current, $ = M.getContext("2d");
1185
+ if (!$) return;
1186
+ let G = null;
1187
+ return (async () => {
1188
+ try {
1189
+ const z = await e.getPage(t);
1190
+ if (m) return;
1191
+ const E = z.getViewport({ scale: 1, rotation: i }), I = s / E.width, V = z.getViewport({ scale: I, rotation: i });
1192
+ M.width = Math.floor(V.width), M.height = Math.floor(V.height), G = z.render({ canvasContext: $, viewport: V }), await G.promise;
1193
+ const te = c.filter((D) => D.pageNumber === t);
1194
+ te.length > 0 && wn($, te, I);
1195
+ const X = l.filter((D) => D.pageNumber === t), oe = y.filter(
1196
+ (D) => D.pageNumber === t
1197
+ );
1198
+ oe.length > 0 && ki(
1199
+ $,
1200
+ oe,
1201
+ new Set(X.map((D) => D.fieldId).filter(Boolean)),
1202
+ I
1203
+ ), X.length > 0 && await yn($, X, I);
1204
+ const ke = f.filter((D) => D.pageNumber === t), ye = x.filter(
1205
+ (D) => D.pageNumber === t
1206
+ );
1207
+ ye.length > 0 && Ai(
1208
+ $,
1209
+ ye,
1210
+ new Set(
1211
+ ke.filter((D) => D.fieldId && D.value.trim()).map((D) => D.fieldId)
1212
+ ),
1213
+ I
1214
+ ), ke.length > 0 && bn($, ke, I);
1215
+ } catch {
1216
+ }
1217
+ })(), () => {
1218
+ if (m = !0, G)
1219
+ try {
1220
+ G.cancel();
1221
+ } catch {
1222
+ }
1223
+ };
1224
+ }, [
1225
+ c,
1226
+ e,
1227
+ t,
1228
+ i,
1229
+ y,
1230
+ l,
1231
+ x,
1232
+ f,
1233
+ s
1234
+ ]), /* @__PURE__ */ T(
1235
+ "button",
1236
+ {
1237
+ type: "button",
1238
+ onClick: () => r(t),
1239
+ className: n ? "epochs-pdf-viewer__thumb epochs-pdf-viewer__thumb--active" : "epochs-pdf-viewer__thumb",
1240
+ title: `Page ${t}`,
1241
+ children: [
1242
+ /* @__PURE__ */ a("div", { className: "epochs-pdf-viewer__thumb-frame", children: /* @__PURE__ */ a("canvas", { ref: v }) }),
1243
+ /* @__PURE__ */ a("span", { className: "epochs-pdf-viewer__thumb-label", children: t })
1244
+ ]
1245
+ }
1246
+ );
1247
+ }
1248
+ const er = /^(blob:|https?:|data:)/i;
1249
+ let _n = !1;
1250
+ function sn(e) {
1251
+ ct.GlobalWorkerOptions.workerSrc = e, _n = !0;
1252
+ }
1253
+ function tr(e) {
1254
+ if (e) {
1255
+ sn(e);
1256
+ return;
1257
+ }
1258
+ _n || ct.GlobalWorkerOptions.workerSrc || sn(
1259
+ `https://unpkg.com/pdfjs-dist@${ct.version}/build/pdf.worker.min.mjs`
1260
+ );
1261
+ }
1262
+ function nr(e, t, n = "") {
1263
+ const i = t || e;
1264
+ if (!i) return "";
1265
+ if (er.test(i)) return i;
1266
+ const r = i.startsWith("/") ? i : `/${i}`;
1267
+ return n ? `${n.replace(/\/$/, "")}${r}` : r;
1268
+ }
1269
+ async function ir(e, t) {
1270
+ const n = await fetch(e, t);
1271
+ if (!n.ok)
1272
+ throw new Error(`Failed to fetch PDF (${n.status})`);
1273
+ return n.arrayBuffer();
1274
+ }
1275
+ async function an(e, t) {
1276
+ if (typeof e == "string")
1277
+ return ir(e, t);
1278
+ if (e instanceof ArrayBuffer) return e.slice(0);
1279
+ if (e instanceof Uint8Array) {
1280
+ const n = new Uint8Array(e.byteLength);
1281
+ return n.set(e), n.buffer;
1282
+ }
1283
+ return e.arrayBuffer();
1284
+ }
1285
+ async function rr(e, t, n) {
1286
+ const {
1287
+ scale: i,
1288
+ rotation: r,
1289
+ annotations: s,
1290
+ signatures: c = [],
1291
+ texts: l = [],
1292
+ mimeType: y = "image/jpeg",
1293
+ quality: f = 0.92
1294
+ } = n, x = await e.getPage(t), v = x.getViewport({ scale: i, rotation: r }), m = x.getViewport({ scale: 1, rotation: r }), M = document.createElement("canvas"), $ = M.getContext("2d", { alpha: !1 });
1295
+ if (!$)
1296
+ throw new Error("Could not create canvas context");
1297
+ const G = Math.floor(v.width), S = Math.floor(v.height);
1298
+ M.width = G, M.height = S, $.fillStyle = "#ffffff", $.fillRect(0, 0, G, S), await x.render({ canvasContext: $, viewport: v }).promise;
1299
+ const z = s.filter((X) => X.pageNumber === t);
1300
+ z.length > 0 && wn($, z, i);
1301
+ const E = c.filter((X) => X.pageNumber === t);
1302
+ E.length > 0 && await yn($, E, i);
1303
+ const I = l.filter((X) => X.pageNumber === t);
1304
+ I.length > 0 && bn($, I, i);
1305
+ const V = M.toDataURL(y, f), te = or(V);
1306
+ return M.width = 0, M.height = 0, {
1307
+ pageNumber: t,
1308
+ width: G,
1309
+ height: S,
1310
+ pageWidth: m.width,
1311
+ pageHeight: m.height,
1312
+ dataUrl: V,
1313
+ jpegBytes: te
1314
+ };
1315
+ }
1316
+ async function cn(e, t) {
1317
+ const n = [];
1318
+ for (let i = 1; i <= e.numPages; i += 1)
1319
+ n.push(await rr(e, i, t));
1320
+ return n;
1321
+ }
1322
+ function or(e) {
1323
+ const t = e.split(",")[1] ?? "", n = atob(t), i = new Uint8Array(n.length);
1324
+ for (let r = 0; r < n.length; r += 1)
1325
+ i[r] = n.charCodeAt(r);
1326
+ return i;
1327
+ }
1328
+ function ze(e) {
1329
+ return new TextEncoder().encode(e);
1330
+ }
1331
+ function ln(...e) {
1332
+ const t = e.reduce((r, s) => r + s.byteLength, 0), n = new Uint8Array(t);
1333
+ let i = 0;
1334
+ for (const r of e)
1335
+ n.set(r, i), i += r.byteLength;
1336
+ return n;
1337
+ }
1338
+ function sr(e) {
1339
+ const t = [], n = (m) => (t.push(m), t.length), i = [];
1340
+ for (const m of e) {
1341
+ const M = ln(
1342
+ ze(
1343
+ `<< /Type /XObject /Subtype /Image /Width ${m.width} /Height ${m.height} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${m.jpegBytes.byteLength} >>
1344
+ stream
1345
+ `
1346
+ ),
1347
+ m.jpegBytes,
1348
+ ze(`
1349
+ endstream`)
1350
+ ), $ = n(M), G = `q
1351
+ ${m.pageWidth.toFixed(2)} 0 0 ${m.pageHeight.toFixed(2)} 0 0 cm
1352
+ /Im0 Do
1353
+ Q`, S = n(
1354
+ ze(`<< /Length ${G.length} >>
1355
+ stream
1356
+ ${G}
1357
+ endstream`)
1358
+ ), z = n(
1359
+ ze(
1360
+ `<< /Type /Page /Parent __PAGES__ 0 R /MediaBox [0 0 ${m.pageWidth.toFixed(2)} ${m.pageHeight.toFixed(2)}] /Contents ${S} 0 R /Resources << /XObject << /Im0 ${$} 0 R >> >> >>`
1361
+ )
1362
+ );
1363
+ i.push(z);
1364
+ }
1365
+ const r = i.map((m) => `${m} 0 R`).join(" "), s = n(
1366
+ ze(`<< /Type /Pages /Kids [${r}] /Count ${i.length} >>`)
1367
+ );
1368
+ for (const m of i) {
1369
+ const M = new TextDecoder().decode(t[m - 1]);
1370
+ t[m - 1] = ze(
1371
+ M.replace("/Parent __PAGES__ 0 R", `/Parent ${s} 0 R`)
1372
+ );
1373
+ }
1374
+ const c = n(ze(`<< /Type /Catalog /Pages ${s} 0 R >>`)), l = [ze(`%PDF-1.4
1375
+ `)], y = [0];
1376
+ let f = l[0].byteLength;
1377
+ for (let m = 0; m < t.length; m += 1) {
1378
+ y.push(f);
1379
+ const M = ze(`${m + 1} 0 obj
1380
+ `), $ = ze(`
1381
+ endobj
1382
+ `);
1383
+ l.push(M, t[m], $), f += M.byteLength + t[m].byteLength + $.byteLength;
1384
+ }
1385
+ const x = f;
1386
+ let v = `xref
1387
+ 0 ${t.length + 1}
1388
+ `;
1389
+ v += `0000000000 65535 f
1390
+ `;
1391
+ for (let m = 1; m <= t.length; m += 1)
1392
+ v += `${String(y[m]).padStart(10, "0")} 00000 n
1393
+ `;
1394
+ return v += `trailer
1395
+ << /Size ${t.length + 1} /Root ${c} 0 R >>
1396
+ `, v += `startxref
1397
+ ${x}
1398
+ %%EOF`, l.push(ze(v)), ln(...l);
1399
+ }
1400
+ function Xt(e, t) {
1401
+ const n = URL.createObjectURL(e), i = document.createElement("a");
1402
+ i.href = n, i.download = t, i.click(), URL.revokeObjectURL(n);
1403
+ }
1404
+ const It = [
1405
+ { id: "dancing-script", label: "Dancing Script", family: "Dancing Script" },
1406
+ { id: "great-vibes", label: "Great Vibes", family: "Great Vibes" },
1407
+ { id: "pacifico", label: "Pacifico", family: "Pacifico" },
1408
+ { id: "satisfy", label: "Satisfy", family: "Satisfy" },
1409
+ { id: "allura", label: "Allura", family: "Allura" }
1410
+ ], ar = "https://fonts.googleapis.com/css2?family=Allura&family=Dancing+Script:wght@500;600&family=Great+Vibes&family=Pacifico&family=Satisfy&display=swap";
1411
+ let Nt = null;
1412
+ function cr() {
1413
+ return typeof document > "u" ? Promise.resolve() : Nt || (Nt = new Promise((e) => {
1414
+ var i;
1415
+ if (!document.querySelector(
1416
+ 'link[data-epochs-signature-fonts="true"]'
1417
+ )) {
1418
+ const r = document.createElement("link");
1419
+ r.rel = "stylesheet", r.href = ar, r.dataset.epochsSignatureFonts = "true", document.head.appendChild(r);
1420
+ }
1421
+ const n = () => Promise.all(
1422
+ It.map(
1423
+ (r) => document.fonts.load(`48px "${r.family}"`)
1424
+ )
1425
+ ).then(() => {
1426
+ });
1427
+ (i = document.fonts) != null && i.ready ? document.fonts.ready.then(n).then(e).catch(() => e()) : window.setTimeout(() => {
1428
+ n().then(e).catch(() => e());
1429
+ }, 300);
1430
+ }), Nt);
1431
+ }
1432
+ function lr({
1433
+ open: e,
1434
+ onClose: t,
1435
+ onSave: n,
1436
+ fieldType: i,
1437
+ showFieldTypeTabs: r = !1,
1438
+ textPlaceholder: s
1439
+ }) {
1440
+ const c = _e(null), l = _e(!1), y = _e(null), f = _e([]), x = _e([]), v = i ?? "sign", [m, M] = U(v), [$, G] = U(""), [S, z] = U(""), [E, I] = U("draw"), [V, te] = U(""), [X, oe] = U(""), [ke, ye] = U(!1), [D, ae] = U("signature"), [C, F] = U("#111827"), [Q, Me] = U("dancing-script"), [Ie, ue] = U(!1), be = It.find((u) => u.id === Q) ?? It[0], J = D === "initials" ? X.trim() : V.trim(), Ee = J || (D === "initials" ? "AB" : "Signature");
1441
+ if (xe(() => {
1442
+ e && (M(v), G((/* @__PURE__ */ new Date()).toISOString().slice(0, 10)), z(""));
1443
+ }, [e, v]), xe(() => {
1444
+ if (!e || m !== "sign") return;
1445
+ const u = c.current;
1446
+ if (!u) return;
1447
+ const g = u.getContext("2d");
1448
+ g && (u.width = 560, u.height = 200, g.fillStyle = "#ffffff", g.fillRect(0, 0, u.width, u.height), g.lineCap = "round", g.lineJoin = "round", g.strokeStyle = C, g.lineWidth = 2.5, y.current = null, l.current = !1);
1449
+ }, [e, m]), xe(() => {
1450
+ if (!e) return;
1451
+ let u = !1;
1452
+ return ue(!1), cr().then(() => {
1453
+ u || ue(!0);
1454
+ }), () => {
1455
+ u = !0;
1456
+ };
1457
+ }, [e]), xe(() => {
1458
+ const u = c.current, g = u == null ? void 0 : u.getContext("2d");
1459
+ g && (g.strokeStyle = C, g.fillStyle = C);
1460
+ }, [C]), xe(() => {
1461
+ if (!e || E !== "type") return;
1462
+ const u = c.current, g = u == null ? void 0 : u.getContext("2d");
1463
+ if (!u || !g || (g.fillStyle = "#ffffff", g.fillRect(0, 0, u.width, u.height), !J)) return;
1464
+ const j = D === "initials" ? 72 : be.family === "Great Vibes" || be.family === "Allura" ? 56 : be.family === "Pacifico" ? 44 : 48;
1465
+ g.fillStyle = C, g.textAlign = "center", g.textBaseline = "middle", g.font = `${j}px "${be.family}", cursive`, g.fillText(J, u.width / 2, u.height / 2);
1466
+ }, [
1467
+ J,
1468
+ D,
1469
+ E,
1470
+ C,
1471
+ e,
1472
+ be,
1473
+ Ie
1474
+ ]), !e) return null;
1475
+ const Ye = (u) => {
1476
+ const g = c.current, j = g.getBoundingClientRect();
1477
+ return {
1478
+ x: (u.clientX - j.left) / j.width * g.width,
1479
+ y: (u.clientY - j.top) / j.height * g.height
1480
+ };
1481
+ }, Pe = (u) => {
1482
+ if (E !== "draw") return;
1483
+ u.currentTarget.setPointerCapture(u.pointerId), l.current = !0;
1484
+ const g = Ye(u);
1485
+ y.current = g, x.current = [g];
1486
+ }, Oe = (u) => {
1487
+ if (!l.current || E !== "draw") return;
1488
+ const g = c.current, j = g == null ? void 0 : g.getContext("2d"), Y = y.current;
1489
+ if (!j || !Y) return;
1490
+ const se = Ye(u);
1491
+ j.beginPath(), j.moveTo(Y.x, Y.y), j.lineTo(se.x, se.y), j.stroke(), y.current = se, x.current.push(se);
1492
+ }, ve = () => {
1493
+ x.current.length > 1 && f.current.push([...x.current]), x.current = [], l.current = !1, y.current = null;
1494
+ }, B = () => {
1495
+ const u = c.current, g = u == null ? void 0 : u.getContext("2d");
1496
+ !u || !g || (g.fillStyle = "#ffffff", g.fillRect(0, 0, u.width, u.height), f.current = [], x.current = [], te(""), oe(""), ye(!1));
1497
+ }, fe = (u) => {
1498
+ te(u), ke || oe(dr(u));
1499
+ }, je = () => {
1500
+ if (E === "draw") {
1501
+ const u = f.current;
1502
+ if (u.length === 0) return;
1503
+ let g = 1 / 0, j = 1 / 0, Y = -1 / 0, se = -1 / 0;
1504
+ for (const Ke of u)
1505
+ for (const Le of Ke)
1506
+ Le.x < g && (g = Le.x), Le.y < j && (j = Le.y), Le.x > Y && (Y = Le.x), Le.y > se && (se = Le.y);
1507
+ const re = 8;
1508
+ g = Math.max(0, g - re), j = Math.max(0, j - re), Y += re, se += re;
1509
+ const Ce = Y - g, ce = se - j, Be = u.map((Ke) => "M" + Ke.map((We) => ({ x: We.x - g, y: We.y - j })).map((We) => `${We.x.toFixed(1)},${We.y.toFixed(1)}`).join("L")).join(" "), Ae = `<svg xmlns="http://www.w3.org/2000/svg" width="${Ce.toFixed(0)}" height="${ce.toFixed(0)}" viewBox="0 0 ${Ce.toFixed(0)} ${ce.toFixed(0)}"><path d="${Be}" fill="none" stroke="${C}" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`, Ue = `data:image/svg+xml;base64,${btoa(Ae)}`;
1510
+ n(Ue, Ce, ce);
1511
+ } else {
1512
+ if (!J) return;
1513
+ const u = 3, g = D === "initials" ? 72 : be.family === "Great Vibes" || be.family === "Allura" ? 56 : be.family === "Pacifico" ? 44 : 48, Y = document.createElement("canvas").getContext("2d");
1514
+ Y.font = `${g * u}px "${be.family}", cursive`;
1515
+ const se = Y.measureText(J), re = 12 * u, Ce = Math.ceil(se.width) + re * 2, ce = g * u + re * 2, Be = document.createElement("canvas");
1516
+ Be.width = Ce, Be.height = ce;
1517
+ const Ae = Be.getContext("2d");
1518
+ Ae.clearRect(0, 0, Ce, ce), Ae.font = `${g * u}px "${be.family}", cursive`, Ae.fillStyle = C, Ae.textBaseline = "middle", Ae.fillText(J, re, ce / 2);
1519
+ const Ue = Be.toDataURL("image/png");
1520
+ n(Ue, Ce / u, ce / u);
1521
+ }
1522
+ }, ie = () => {
1523
+ const u = m === "date" ? $ : S.trim();
1524
+ if (!u) return;
1525
+ const g = document.createElement("canvas"), j = g.getContext("2d"), Y = 16;
1526
+ j.font = `${Y}px sans-serif`;
1527
+ const se = j.measureText(u), re = 8;
1528
+ g.width = Math.ceil(se.width) + re * 2, g.height = Y + re * 2, j.clearRect(0, 0, g.width, g.height), j.font = `${Y}px sans-serif`, j.fillStyle = "#111827", j.textBaseline = "middle", j.fillText(u, re, g.height / 2);
1529
+ const Ce = g.toDataURL("image/png");
1530
+ n(Ce, g.width, g.height);
1531
+ }, ge = m === "sign";
1532
+ return /* @__PURE__ */ T("div", { className: "epochs-pdf-viewer__modal", role: "dialog", "aria-modal": "true", children: [
1533
+ /* @__PURE__ */ a("div", { className: "epochs-pdf-viewer__modal-backdrop", onClick: t }),
1534
+ /* @__PURE__ */ T("div", { className: "epochs-pdf-viewer__modal-card", children: [
1535
+ /* @__PURE__ */ T("div", { className: "epochs-pdf-viewer__modal-header", children: [
1536
+ /* @__PURE__ */ a("h3", { children: m === "date" ? "Pick a date" : m === "text" ? "Enter text" : "Create e-signature" }),
1537
+ /* @__PURE__ */ a(
1538
+ "button",
1539
+ {
1540
+ type: "button",
1541
+ className: "epochs-pdf-viewer__btn",
1542
+ onClick: t,
1543
+ title: "Close",
1544
+ children: "×"
1545
+ }
1546
+ )
1547
+ ] }),
1548
+ r && !i ? /* @__PURE__ */ a("div", { className: "epochs-pdf-viewer__field-type-tabs", role: "tablist", children: ["sign", "date", "text"].map((u) => /* @__PURE__ */ a(
1549
+ "button",
1550
+ {
1551
+ type: "button",
1552
+ role: "tab",
1553
+ "aria-selected": m === u,
1554
+ className: m === u ? "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--active" : "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",
1555
+ onClick: () => M(u),
1556
+ children: u === "sign" ? "Sign" : u === "date" ? "Date" : "Text"
1557
+ },
1558
+ u
1559
+ )) }) : null,
1560
+ ge ? /* @__PURE__ */ T(bt, { children: [
1561
+ /* @__PURE__ */ T("div", { className: "epochs-pdf-viewer__sign-modes", children: [
1562
+ /* @__PURE__ */ a(
1563
+ "button",
1564
+ {
1565
+ type: "button",
1566
+ className: E === "draw" ? "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--active" : "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",
1567
+ onClick: () => {
1568
+ I("draw"), B();
1569
+ },
1570
+ children: "Draw"
1571
+ }
1572
+ ),
1573
+ /* @__PURE__ */ a(
1574
+ "button",
1575
+ {
1576
+ type: "button",
1577
+ className: E === "type" ? "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--active" : "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",
1578
+ onClick: () => I("type"),
1579
+ children: "Type"
1580
+ }
1581
+ ),
1582
+ /* @__PURE__ */ T("label", { className: "epochs-pdf-viewer__sign-ink", children: [
1583
+ "Ink",
1584
+ /* @__PURE__ */ a(
1585
+ "input",
1586
+ {
1587
+ type: "color",
1588
+ value: C,
1589
+ onChange: (u) => F(u.target.value)
1590
+ }
1591
+ )
1592
+ ] })
1593
+ ] }),
1594
+ E === "type" ? /* @__PURE__ */ T(bt, { children: [
1595
+ /* @__PURE__ */ a(
1596
+ "div",
1597
+ {
1598
+ className: "epochs-pdf-viewer__sign-fonts",
1599
+ role: "group",
1600
+ "aria-label": "Handwriting style",
1601
+ children: It.map((u) => /* @__PURE__ */ a(
1602
+ "button",
1603
+ {
1604
+ type: "button",
1605
+ className: Q === u.id ? "epochs-pdf-viewer__sign-font epochs-pdf-viewer__sign-font--active" : "epochs-pdf-viewer__sign-font",
1606
+ style: { fontFamily: `"${u.family}", cursive` },
1607
+ onClick: () => Me(u.id),
1608
+ title: u.label,
1609
+ children: Ee
1610
+ },
1611
+ u.id
1612
+ ))
1613
+ }
1614
+ ),
1615
+ /* @__PURE__ */ T("div", { className: "epochs-pdf-viewer__sign-type-fields", children: [
1616
+ /* @__PURE__ */ T("label", { className: "epochs-pdf-viewer__sign-type-field", children: [
1617
+ /* @__PURE__ */ a("span", { children: "Full name" }),
1618
+ /* @__PURE__ */ a(
1619
+ "input",
1620
+ {
1621
+ className: "epochs-pdf-viewer__sign-type-input",
1622
+ type: "text",
1623
+ value: V,
1624
+ onChange: (u) => fe(u.target.value),
1625
+ onFocus: () => ae("signature"),
1626
+ placeholder: "Type your full name",
1627
+ style: { fontFamily: `"${be.family}", cursive` },
1628
+ autoFocus: !0
1629
+ }
1630
+ )
1631
+ ] }),
1632
+ /* @__PURE__ */ T("label", { className: "epochs-pdf-viewer__sign-type-field", children: [
1633
+ /* @__PURE__ */ a("span", { children: "Initials" }),
1634
+ /* @__PURE__ */ a(
1635
+ "input",
1636
+ {
1637
+ className: "epochs-pdf-viewer__sign-type-input",
1638
+ type: "text",
1639
+ value: X,
1640
+ onChange: (u) => {
1641
+ ye(!0), oe(u.target.value.toUpperCase());
1642
+ },
1643
+ onFocus: () => ae("initials"),
1644
+ placeholder: "e.g. JD",
1645
+ maxLength: 4,
1646
+ style: { fontFamily: `"${be.family}", cursive` }
1647
+ }
1648
+ )
1649
+ ] })
1650
+ ] }),
1651
+ /* @__PURE__ */ T(
1652
+ "div",
1653
+ {
1654
+ className: "epochs-pdf-viewer__sign-type-kind",
1655
+ role: "group",
1656
+ "aria-label": "Preview type",
1657
+ children: [
1658
+ /* @__PURE__ */ a(
1659
+ "button",
1660
+ {
1661
+ type: "button",
1662
+ className: D === "signature" ? "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--active" : "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",
1663
+ onClick: () => ae("signature"),
1664
+ children: "Use full name"
1665
+ }
1666
+ ),
1667
+ /* @__PURE__ */ a(
1668
+ "button",
1669
+ {
1670
+ type: "button",
1671
+ className: D === "initials" ? "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--active" : "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",
1672
+ onClick: () => ae("initials"),
1673
+ children: "Use initials"
1674
+ }
1675
+ )
1676
+ ]
1677
+ }
1678
+ )
1679
+ ] }) : /* @__PURE__ */ a("p", { className: "epochs-pdf-viewer__sign-hint", children: "Draw your signature below" }),
1680
+ /* @__PURE__ */ a(
1681
+ "canvas",
1682
+ {
1683
+ ref: c,
1684
+ className: E === "draw" ? "epochs-pdf-viewer__sign-canvas" : "epochs-pdf-viewer__sign-canvas epochs-pdf-viewer__sign-canvas--preview",
1685
+ onPointerDown: Pe,
1686
+ onPointerMove: Oe,
1687
+ onPointerUp: ve,
1688
+ onPointerLeave: ve
1689
+ }
1690
+ )
1691
+ ] }) : m === "date" ? /* @__PURE__ */ T("label", { className: "epochs-pdf-viewer__sign-type-field", style: { padding: "1rem" }, children: [
1692
+ /* @__PURE__ */ a("span", { children: "Date" }),
1693
+ /* @__PURE__ */ a(
1694
+ "input",
1695
+ {
1696
+ className: "epochs-pdf-viewer__sign-type-input",
1697
+ type: "date",
1698
+ value: $,
1699
+ onChange: (u) => G(u.target.value),
1700
+ autoFocus: !0
1701
+ }
1702
+ )
1703
+ ] }) : /* @__PURE__ */ T("label", { className: "epochs-pdf-viewer__sign-type-field", style: { padding: "1rem" }, children: [
1704
+ /* @__PURE__ */ a("span", { children: "Text" }),
1705
+ /* @__PURE__ */ a(
1706
+ "input",
1707
+ {
1708
+ className: "epochs-pdf-viewer__sign-type-input",
1709
+ type: "text",
1710
+ value: S,
1711
+ onChange: (u) => z(u.target.value),
1712
+ placeholder: s ?? "Enter text",
1713
+ autoFocus: !0
1714
+ }
1715
+ )
1716
+ ] }),
1717
+ /* @__PURE__ */ T("div", { className: "epochs-pdf-viewer__modal-actions", children: [
1718
+ ge ? /* @__PURE__ */ a(
1719
+ "button",
1720
+ {
1721
+ type: "button",
1722
+ className: "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",
1723
+ onClick: B,
1724
+ children: "Clear"
1725
+ }
1726
+ ) : null,
1727
+ /* @__PURE__ */ a(
1728
+ "button",
1729
+ {
1730
+ type: "button",
1731
+ className: "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",
1732
+ onClick: t,
1733
+ children: "Cancel"
1734
+ }
1735
+ ),
1736
+ /* @__PURE__ */ a(
1737
+ "button",
1738
+ {
1739
+ type: "button",
1740
+ className: "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--primary",
1741
+ onClick: ge ? je : ie,
1742
+ disabled: m === "date" ? !$ : m === "text" ? !S.trim() : !1,
1743
+ children: ge ? "Use signature" : "Place on page"
1744
+ }
1745
+ )
1746
+ ] })
1747
+ ] })
1748
+ ] });
1749
+ }
1750
+ function dr(e) {
1751
+ const t = e.trim().split(/\s+/).filter(Boolean);
1752
+ return t.length === 0 ? "" : t.length === 1 ? t[0].slice(0, 2).toUpperCase() : t.slice(0, 3).map((n) => {
1753
+ var i;
1754
+ return ((i = n[0]) == null ? void 0 : i.toUpperCase()) ?? "";
1755
+ }).join("");
1756
+ }
1757
+ const Ct = "__epochsToolbarToolId";
1758
+ function Fe(e, t) {
1759
+ const n = (() => null);
1760
+ return n.displayName = t, Object.defineProperty(n, Ct, {
1761
+ value: e,
1762
+ enumerable: !0
1763
+ }), n;
1764
+ }
1765
+ function dn(e) {
1766
+ return e[Ct];
1767
+ }
1768
+ function hr(e) {
1769
+ return typeof e == "function" && Ct in e && typeof e[Ct] == "string";
1770
+ }
1771
+ const vn = Fe("thumbnail", "Thumbnail"), xn = Fe("navigation", "Navigation"), kn = Fe("zoom", "Zoom"), Mn = Fe("rotate", "Rotate"), Pn = Fe("reload", "Reload"), Nn = Fe("print", "Print"), $n = Fe("open", "Open"), Tn = Fe("download", "Download"), In = Fe("highlight", "Highlight"), Cn = Fe("underline", "Underline"), Ln = Fe("signature", "Signature"), Rn = Fe("text", "AddText"), Dn = Fe("erase", "Erase"), Fn = Fe("clear", "Clear"), Br = [
1772
+ vn,
1773
+ xn,
1774
+ kn,
1775
+ Mn,
1776
+ In,
1777
+ Cn,
1778
+ Ln,
1779
+ Rn,
1780
+ Dn,
1781
+ Fn,
1782
+ Pn,
1783
+ Nn,
1784
+ $n,
1785
+ Tn
1786
+ ], hn = [
1787
+ [vn, xn],
1788
+ [
1789
+ kn,
1790
+ Mn,
1791
+ In,
1792
+ Cn,
1793
+ Ln,
1794
+ Rn,
1795
+ Dn,
1796
+ Fn,
1797
+ Pn,
1798
+ Nn,
1799
+ $n,
1800
+ Tn
1801
+ ]
1802
+ ], pr = [
1803
+ "highlight",
1804
+ "underline",
1805
+ "signature",
1806
+ "text",
1807
+ "erase",
1808
+ "clear"
1809
+ ];
1810
+ function pn(e) {
1811
+ return pr.includes(e);
1812
+ }
1813
+ function ur(e, t, n) {
1814
+ const i = [];
1815
+ switch (n != null && n.showMarkupSep && i.push(
1816
+ /* @__PURE__ */ a(
1817
+ "span",
1818
+ {
1819
+ className: "epochs-pdf-viewer__toolbar-sep",
1820
+ "aria-hidden": "true"
1821
+ },
1822
+ `${e}-sep`
1823
+ )
1824
+ ), e) {
1825
+ case "thumbnail":
1826
+ i.push(
1827
+ /* @__PURE__ */ a(
1828
+ "button",
1829
+ {
1830
+ type: "button",
1831
+ className: "epochs-pdf-viewer__btn",
1832
+ onClick: () => t.setShowThumbnails((r) => !r),
1833
+ title: t.showThumbnails ? "Hide thumbnails" : "Show thumbnails",
1834
+ children: /* @__PURE__ */ a(zi, {})
1835
+ },
1836
+ "thumbnail"
1837
+ )
1838
+ );
1839
+ break;
1840
+ case "navigation":
1841
+ i.push(
1842
+ /* @__PURE__ */ a(
1843
+ "button",
1844
+ {
1845
+ type: "button",
1846
+ className: "epochs-pdf-viewer__btn",
1847
+ onClick: t.handlePrev,
1848
+ disabled: !t.canGoPrev || t.status !== "ready",
1849
+ title: "Previous page",
1850
+ children: /* @__PURE__ */ a(Si, {})
1851
+ },
1852
+ "nav-prev"
1853
+ ),
1854
+ /* @__PURE__ */ T("div", { className: "epochs-pdf-viewer__page-input", children: [
1855
+ /* @__PURE__ */ a(
1856
+ "input",
1857
+ {
1858
+ type: "number",
1859
+ value: t.pageNumber,
1860
+ min: 1,
1861
+ max: t.numPages || 1,
1862
+ onChange: (r) => {
1863
+ const s = Number.parseInt(r.target.value, 10);
1864
+ Number.isFinite(s) && t.scrollToPage(
1865
+ Math.max(1, Math.min(t.numPages || 1, s))
1866
+ );
1867
+ },
1868
+ disabled: t.status !== "ready",
1869
+ "aria-label": "Page number"
1870
+ }
1871
+ ),
1872
+ /* @__PURE__ */ T("span", { children: [
1873
+ "/ ",
1874
+ t.numPages || "-"
1875
+ ] })
1876
+ ] }, "nav-page"),
1877
+ /* @__PURE__ */ a(
1878
+ "button",
1879
+ {
1880
+ type: "button",
1881
+ className: "epochs-pdf-viewer__btn",
1882
+ onClick: t.handleNext,
1883
+ disabled: !t.canGoNext || t.status !== "ready",
1884
+ title: "Next page",
1885
+ children: /* @__PURE__ */ a(Ei, {})
1886
+ },
1887
+ "nav-next"
1888
+ )
1889
+ );
1890
+ break;
1891
+ case "zoom":
1892
+ i.push(
1893
+ /* @__PURE__ */ a(
1894
+ "button",
1895
+ {
1896
+ type: "button",
1897
+ className: "epochs-pdf-viewer__btn",
1898
+ onClick: t.handleZoomOut,
1899
+ disabled: t.status !== "ready",
1900
+ title: "Zoom out",
1901
+ children: /* @__PURE__ */ a(ji, {})
1902
+ },
1903
+ "zoom-out"
1904
+ ),
1905
+ /* @__PURE__ */ T("span", { className: "epochs-pdf-viewer__zoom-label", children: [
1906
+ Math.round(t.scale * 100),
1907
+ "%"
1908
+ ] }, "zoom-label"),
1909
+ /* @__PURE__ */ a(
1910
+ "button",
1911
+ {
1912
+ type: "button",
1913
+ className: "epochs-pdf-viewer__btn",
1914
+ onClick: t.handleZoomIn,
1915
+ disabled: t.status !== "ready",
1916
+ title: "Zoom in",
1917
+ children: /* @__PURE__ */ a(Oi, {})
1918
+ },
1919
+ "zoom-in"
1920
+ ),
1921
+ /* @__PURE__ */ a(
1922
+ "button",
1923
+ {
1924
+ type: "button",
1925
+ className: "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",
1926
+ onClick: () => void t.handleFitWidth(),
1927
+ disabled: t.status !== "ready",
1928
+ title: "Fit to width",
1929
+ children: "Fit"
1930
+ },
1931
+ "zoom-fit"
1932
+ )
1933
+ );
1934
+ break;
1935
+ case "rotate":
1936
+ i.push(
1937
+ /* @__PURE__ */ a(
1938
+ "button",
1939
+ {
1940
+ type: "button",
1941
+ className: "epochs-pdf-viewer__btn",
1942
+ onClick: t.handleRotate,
1943
+ disabled: t.status !== "ready",
1944
+ title: "Rotate",
1945
+ children: /* @__PURE__ */ a(Gi, {})
1946
+ },
1947
+ "rotate"
1948
+ )
1949
+ );
1950
+ break;
1951
+ case "highlight":
1952
+ i.push(
1953
+ /* @__PURE__ */ a(
1954
+ "button",
1955
+ {
1956
+ type: "button",
1957
+ className: t.markupTool === "highlight" ? "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--active" : "epochs-pdf-viewer__btn",
1958
+ onClick: () => t.toggleMarkupTool("highlight"),
1959
+ disabled: t.status !== "ready",
1960
+ title: "Highlight text — select text to highlight",
1961
+ children: /* @__PURE__ */ a(Xi, {})
1962
+ },
1963
+ "highlight"
1964
+ )
1965
+ );
1966
+ break;
1967
+ case "underline":
1968
+ i.push(
1969
+ /* @__PURE__ */ a(
1970
+ "button",
1971
+ {
1972
+ type: "button",
1973
+ className: t.markupTool === "underline" ? "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--active" : "epochs-pdf-viewer__btn",
1974
+ onClick: () => t.toggleMarkupTool("underline"),
1975
+ disabled: t.status !== "ready",
1976
+ title: "Underline text — select text to underline",
1977
+ children: /* @__PURE__ */ a(qi, {})
1978
+ },
1979
+ "underline"
1980
+ )
1981
+ );
1982
+ break;
1983
+ case "signature":
1984
+ i.push(
1985
+ /* @__PURE__ */ a(
1986
+ "button",
1987
+ {
1988
+ type: "button",
1989
+ className: t.markupTool === "sign" ? "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--active" : "epochs-pdf-viewer__btn",
1990
+ onClick: () => {
1991
+ if (!t.hasFixedSignatureFields && t.pendingSignature && t.markupTool !== "sign") {
1992
+ t.setMarkupTool("sign");
1993
+ return;
1994
+ }
1995
+ t.setSignaturePadOpen(!0);
1996
+ },
1997
+ disabled: t.status !== "ready",
1998
+ title: t.hasFixedSignatureFields ? "Create e-signature for a fixed field" : t.pendingSignature ? "Place signature — click on the page, then drag to move" : "Create e-signature",
1999
+ children: /* @__PURE__ */ a(Ki, {})
2000
+ },
2001
+ "signature"
2002
+ )
2003
+ );
2004
+ break;
2005
+ case "text":
2006
+ i.push(
2007
+ /* @__PURE__ */ a(
2008
+ "button",
2009
+ {
2010
+ type: "button",
2011
+ className: t.markupTool === "text" ? "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--active" : "epochs-pdf-viewer__btn",
2012
+ onClick: () => t.toggleMarkupTool("text"),
2013
+ disabled: t.status !== "ready",
2014
+ title: t.hasFixedTextFields ? "Edit text in predefined areas — click to type" : "Edit PDF text — select words, then change them",
2015
+ children: /* @__PURE__ */ a(Vi, {})
2016
+ },
2017
+ "text"
2018
+ )
2019
+ );
2020
+ break;
2021
+ case "erase":
2022
+ i.push(
2023
+ /* @__PURE__ */ a(
2024
+ "button",
2025
+ {
2026
+ type: "button",
2027
+ className: t.markupTool === "erase" ? "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--active" : "epochs-pdf-viewer__btn",
2028
+ onClick: () => t.toggleMarkupTool("erase"),
2029
+ disabled: t.status !== "ready",
2030
+ title: "Remove text — select PDF words to cover them, or click added markup",
2031
+ children: /* @__PURE__ */ a(Yi, {})
2032
+ },
2033
+ "erase"
2034
+ )
2035
+ );
2036
+ break;
2037
+ case "clear":
2038
+ i.push(
2039
+ /* @__PURE__ */ a(
2040
+ "button",
2041
+ {
2042
+ type: "button",
2043
+ className: "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",
2044
+ onClick: t.handleClearAnnotations,
2045
+ disabled: t.status !== "ready" || t.annotationsLength === 0 && t.signaturesLength === 0 && t.textsLength === 0,
2046
+ title: "Clear all markup",
2047
+ children: "Clear"
2048
+ },
2049
+ "clear"
2050
+ )
2051
+ );
2052
+ break;
2053
+ case "reload":
2054
+ i.push(
2055
+ /* @__PURE__ */ a(
2056
+ "button",
2057
+ {
2058
+ type: "button",
2059
+ className: "epochs-pdf-viewer__btn",
2060
+ onClick: () => void t.loadDocument(),
2061
+ title: "Reload",
2062
+ children: /* @__PURE__ */ a(Wi, {})
2063
+ },
2064
+ "reload"
2065
+ )
2066
+ );
2067
+ break;
2068
+ case "print":
2069
+ i.push(
2070
+ /* @__PURE__ */ a(
2071
+ "button",
2072
+ {
2073
+ type: "button",
2074
+ className: "epochs-pdf-viewer__btn",
2075
+ onClick: () => void t.handlePrint(),
2076
+ disabled: t.status !== "ready" || !t.pdfDoc || t.isPrinting,
2077
+ title: t.isPrinting ? "Preparing print…" : "Print (includes highlights & underlines)",
2078
+ children: /* @__PURE__ */ a(Ui, {})
2079
+ },
2080
+ "print"
2081
+ )
2082
+ );
2083
+ break;
2084
+ case "open":
2085
+ i.push(
2086
+ /* @__PURE__ */ a(
2087
+ "a",
2088
+ {
2089
+ className: "epochs-pdf-viewer__btn",
2090
+ href: t.displayUrl || t.resolvedUrl || void 0,
2091
+ target: "_blank",
2092
+ rel: "noopener noreferrer",
2093
+ title: "Open in new tab",
2094
+ children: /* @__PURE__ */ a(Hi, {})
2095
+ },
2096
+ "open"
2097
+ )
2098
+ );
2099
+ break;
2100
+ case "download":
2101
+ i.push(
2102
+ /* @__PURE__ */ a(
2103
+ "button",
2104
+ {
2105
+ type: "button",
2106
+ className: "epochs-pdf-viewer__btn",
2107
+ onClick: () => void t.handleDownload(),
2108
+ disabled: t.status !== "ready" || !t.pdfDoc || t.isDownloading,
2109
+ title: t.isDownloading ? "Preparing download…" : t.annotationsLength > 0 || t.signaturesLength > 0 || t.textsLength > 0 ? "Download PDF with markup" : "Download PDF",
2110
+ children: /* @__PURE__ */ a(Bi, {})
2111
+ },
2112
+ "download"
2113
+ )
2114
+ );
2115
+ break;
2116
+ }
2117
+ return i.length > 0 ? i : null;
2118
+ }
2119
+ function fr(e, t) {
2120
+ const n = [];
2121
+ if (e.markupTool === "sign" && e.pendingSignature && !e.hasFixedSignatureFields && t.has("signature") && n.push(
2122
+ /* @__PURE__ */ a("span", { className: "epochs-pdf-viewer__markup-hint", children: "Click page to place duplicate/new signature" }, "sign-hint")
2123
+ ), e.markupTool === "text" && t.has("text") && n.push(
2124
+ /* @__PURE__ */ a("span", { className: "epochs-pdf-viewer__markup-hint", children: e.hasFixedTextFields ? "Click in a predefined text area to type" : "Select text to edit it — e.g. change this PDF to this is PDF" }, "text-hint")
2125
+ ), e.markupTool === "erase" && t.has("erase") && n.push(
2126
+ /* @__PURE__ */ a("span", { className: "epochs-pdf-viewer__markup-hint", children: "Select PDF words to remove · click added text/markup to erase" }, "erase-hint")
2127
+ ), e.markupTool === "highlight" && t.has("highlight") || e.markupTool === "underline" && t.has("underline")) {
2128
+ const i = e.markupTool === "highlight" ? e.highlightHex : e.underlineHex, r = e.markupTool === "highlight" ? e.setHighlightHex : e.setUnderlineHex, s = e.markupTool === "highlight" ? un : fn;
2129
+ n.push(
2130
+ /* @__PURE__ */ T(
2131
+ "div",
2132
+ {
2133
+ className: "epochs-pdf-viewer__color-picker",
2134
+ role: "group",
2135
+ "aria-label": `${e.markupTool} color`,
2136
+ children: [
2137
+ s.map((c) => /* @__PURE__ */ a(
2138
+ "button",
2139
+ {
2140
+ type: "button",
2141
+ className: Qe(i) === Qe(c.hex) ? "epochs-pdf-viewer__swatch epochs-pdf-viewer__swatch--active" : "epochs-pdf-viewer__swatch",
2142
+ style: { background: c.hex },
2143
+ title: c.label,
2144
+ "aria-label": c.label,
2145
+ "aria-pressed": Qe(i) === Qe(c.hex),
2146
+ onClick: () => r(Qe(c.hex))
2147
+ },
2148
+ c.id
2149
+ )),
2150
+ /* @__PURE__ */ T(
2151
+ "label",
2152
+ {
2153
+ className: "epochs-pdf-viewer__custom-color",
2154
+ title: "Custom color",
2155
+ children: [
2156
+ /* @__PURE__ */ a(
2157
+ "span",
2158
+ {
2159
+ className: "epochs-pdf-viewer__custom-color-chip",
2160
+ style: { background: i }
2161
+ }
2162
+ ),
2163
+ /* @__PURE__ */ a(
2164
+ "input",
2165
+ {
2166
+ type: "color",
2167
+ value: Qe(i),
2168
+ onChange: (c) => r(Qe(c.target.value)),
2169
+ "aria-label": "Custom color"
2170
+ }
2171
+ )
2172
+ ]
2173
+ }
2174
+ )
2175
+ ]
2176
+ },
2177
+ "color-picker"
2178
+ )
2179
+ );
2180
+ }
2181
+ return n.length > 0 ? n : null;
2182
+ }
2183
+ function gr(e, t) {
2184
+ if (!e) return null;
2185
+ if (Array.isArray(e)) {
2186
+ const s = (c) => (c ?? []).filter(hr).map(dn);
2187
+ return {
2188
+ left: s(e[0]),
2189
+ right: s(e[1])
2190
+ };
2191
+ }
2192
+ const n = t.enableThumbnails, i = (s, c) => s.map(dn).filter((l) => c[l] !== !1), r = {
2193
+ thumbnail: n,
2194
+ navigation: t.enableNavigation,
2195
+ zoom: t.enableZoom,
2196
+ rotate: t.enableRotate,
2197
+ reload: t.enableReload,
2198
+ print: t.enablePrint,
2199
+ open: t.enableOpen,
2200
+ download: t.enableDownload,
2201
+ highlight: t.enableHighlight,
2202
+ underline: t.enableUnderline,
2203
+ signature: t.enableSignature,
2204
+ text: t.enableText,
2205
+ erase: t.enableErase,
2206
+ clear: t.enableClear
2207
+ };
2208
+ return {
2209
+ left: i(hn[0], r),
2210
+ right: i(hn[1], r)
2211
+ };
2212
+ }
2213
+ function Hr({
2214
+ file: e,
2215
+ fileUrl: t,
2216
+ baseUrl: n = "",
2217
+ fetchOptions: i,
2218
+ height: r = "80vh",
2219
+ title: s = "PDF document",
2220
+ initialScale: c = 1,
2221
+ withThumbnails: l = !1,
2222
+ thumbnailWidth: y = 140,
2223
+ maxThumbnails: f = 60,
2224
+ className: x,
2225
+ workerSrc: v,
2226
+ enableToolbar: m = !1,
2227
+ enableThumbnails: M,
2228
+ enableNavigation: $ = !0,
2229
+ enableZoom: G = !0,
2230
+ enableRotate: S = !0,
2231
+ enableReload: z = !0,
2232
+ enablePrint: E = !0,
2233
+ enableOpen: I = !0,
2234
+ enableDownload: V = !0,
2235
+ enableMarkup: te = !0,
2236
+ enableHighlight: X = !0,
2237
+ enableUnderline: oe = !0,
2238
+ enableSignature: ke = !0,
2239
+ enableText: ye = !0,
2240
+ enableErase: D = !0,
2241
+ enableClear: ae = !0,
2242
+ signatureFields: C = [],
2243
+ textFields: F = [],
2244
+ onSignatureComplete: Q,
2245
+ onFieldValueComplete: Me,
2246
+ openSignaturePad: Ie = !1,
2247
+ onSignaturePadClose: ue,
2248
+ onSubmit: be,
2249
+ submitLabel: J = "Submit"
2250
+ }) {
2251
+ const Ee = _e(null), Ye = _e(null), Pe = _e(/* @__PURE__ */ new Map()), Oe = _e(!1), ve = Mt(() => e && typeof e != "string" ? e : null, [e]), B = Mt(() => ve ? "" : nr(typeof e == "string" ? e : void 0, t, n), [ve, e, t, n]), [fe, je] = U("idle"), [ie, ge] = U(null), [he, u] = U(0), [g, j] = U(1), [Y, se] = U(c), [re, Ce] = U(0), [ce, Be] = U(null), [Ae, Ue] = U(!1), [Ke, Le] = U(!1), [We, vt] = U(!1), [o, w] = U("none"), [_, k] = U([]), [P, N] = U([]), [L, O] = U([]), [Z, W] = U(!1), [H, le] = U(void 0), [de, ne] = U(null), [Ne, pe] = U(
2252
+ null
2253
+ ), [me, $e] = U(
2254
+ null
2255
+ ), [Ge, Se] = U(null), [lt, Xe] = U(null), [xt, Ze] = U(null), [Lt, Je] = U(null), [Kt, On] = U(gn), [Zt, Un] = U(xi), He = C.length > 0, dt = F.length > 0, [it, Wn] = U({});
2256
+ xe(() => {
2257
+ Ie && W(!0);
2258
+ }, [Ie]);
2259
+ const et = Mt(
2260
+ () => gr(m, {
2261
+ enableThumbnails: M,
2262
+ enableNavigation: $,
2263
+ enableZoom: G,
2264
+ enableRotate: S,
2265
+ enableReload: z,
2266
+ enablePrint: E,
2267
+ enableOpen: I,
2268
+ enableDownload: V,
2269
+ enableHighlight: X,
2270
+ enableUnderline: oe,
2271
+ enableSignature: ke,
2272
+ enableText: ye,
2273
+ enableErase: D,
2274
+ enableClear: ae
2275
+ }),
2276
+ [
2277
+ m,
2278
+ M,
2279
+ $,
2280
+ G,
2281
+ S,
2282
+ z,
2283
+ E,
2284
+ I,
2285
+ V,
2286
+ X,
2287
+ oe,
2288
+ ke,
2289
+ ye,
2290
+ D,
2291
+ ae
2292
+ ]
2293
+ ), tt = Mt(() => et ? /* @__PURE__ */ new Set([...et.left, ...et.right]) : /* @__PURE__ */ new Set(), [et]);
2294
+ xe(() => {
2295
+ if (!tt.has("thumbnail")) {
2296
+ Ue(!1);
2297
+ return;
2298
+ }
2299
+ const p = window.matchMedia("(max-width: 720px)"), d = () => {
2300
+ Ue(p.matches ? !1 : l);
2301
+ };
2302
+ return d(), p.addEventListener("change", d), () => p.removeEventListener("change", d);
2303
+ }, [tt, l]);
2304
+ const Vt = !He && tt.has("highlight"), Qt = !He && tt.has("underline"), Rt = tt.has("signature"), Jt = tt.has("text") || dt, en = !He && tt.has("erase"), ht = q(() => {
2305
+ Ye.current && (URL.revokeObjectURL(Ye.current), Ye.current = null);
2306
+ }, []), Dt = q(async () => {
2307
+ if (!(!ve && !B)) {
2308
+ tr(v), je("loading"), ge(null), u(0), j(1), k([]), N([]), O([]), ne(null), pe(null), $e(null), Se(null), Xe(null), Ze(null), Je(null), w("none");
2309
+ try {
2310
+ const h = ve ? await an(ve, i) : await an(B, i), p = new Blob([h], { type: "application/pdf" }), d = URL.createObjectURL(p);
2311
+ ht(), Ye.current = d, Be(d);
2312
+ const A = await ct.getDocument({
2313
+ data: h,
2314
+ cMapUrl: `https://unpkg.com/pdfjs-dist@${ct.version}/cmaps/`,
2315
+ cMapPacked: !0,
2316
+ standardFontDataUrl: `https://unpkg.com/pdfjs-dist@${ct.version}/standard_fonts/`
2317
+ }).promise;
2318
+ ge(A), u(A.numPages), je("ready");
2319
+ } catch {
2320
+ je("error");
2321
+ }
2322
+ }
2323
+ }, [
2324
+ ve,
2325
+ B,
2326
+ i,
2327
+ ht,
2328
+ v
2329
+ ]);
2330
+ xe(() => {
2331
+ if (!ve && !B) {
2332
+ je("idle"), ge(null), u(0), Be(null), ht();
2333
+ return;
2334
+ }
2335
+ return Dt(), () => {
2336
+ ht();
2337
+ };
2338
+ }, [ve, B, Dt, ht]), xe(() => {
2339
+ (o === "highlight" && !Vt || o === "underline" && !Qt || o === "sign" && !Rt || o === "text" && !Jt || o === "erase" && !en) && w("none");
2340
+ }, [Vt, Qt, Rt, Jt, en, o]);
2341
+ const rt = q(
2342
+ (h) => {
2343
+ const p = Math.max(1, Math.min(he || 1, h)), d = Pe.current.get(p);
2344
+ if (!d) {
2345
+ j(p);
2346
+ return;
2347
+ }
2348
+ Oe.current = !0, d.scrollIntoView({ behavior: "smooth", block: "start" }), j(p), window.setTimeout(() => {
2349
+ Oe.current = !1;
2350
+ }, 500);
2351
+ },
2352
+ [he]
2353
+ ), ot = q(
2354
+ (h) => {
2355
+ const p = Pe.current.get(h.pageNumber);
2356
+ p && (Oe.current = !0, j(h.pageNumber));
2357
+ const d = () => {
2358
+ var A;
2359
+ const b = (A = Ee.current) == null ? void 0 : A.querySelector(
2360
+ `[data-signature-field-id="${CSS.escape(h.id)}"]`
2361
+ );
2362
+ b ? b.scrollIntoView({ behavior: "smooth", block: "center" }) : p && p.scrollIntoView({ behavior: "smooth", block: "start" }), window.setTimeout(() => {
2363
+ Oe.current = !1;
2364
+ }, 500);
2365
+ };
2366
+ window.requestAnimationFrame(() => {
2367
+ window.setTimeout(d, 40);
2368
+ });
2369
+ },
2370
+ []
2371
+ );
2372
+ xe(() => {
2373
+ if (fe !== "ready" || !Ee.current || !he) return;
2374
+ const h = Ee.current, p = new IntersectionObserver(
2375
+ (d) => {
2376
+ if (Oe.current) return;
2377
+ let b = null;
2378
+ for (const A of d) {
2379
+ if (!A.isIntersecting) continue;
2380
+ const R = Number.parseInt(
2381
+ A.target.dataset.pageNumber || "0",
2382
+ 10
2383
+ );
2384
+ R && (!b || A.intersectionRatio > b.ratio) && (b = { page: R, ratio: A.intersectionRatio });
2385
+ }
2386
+ b && j(b.page);
2387
+ },
2388
+ {
2389
+ root: h,
2390
+ threshold: [0.25, 0.5, 0.75]
2391
+ }
2392
+ );
2393
+ for (let d = 1; d <= he; d += 1) {
2394
+ const b = Pe.current.get(d);
2395
+ b && p.observe(b);
2396
+ }
2397
+ return () => p.disconnect();
2398
+ }, [fe, he]);
2399
+ const Ft = g > 1, At = he ? g < he : !1, Gn = q(() => {
2400
+ Ft && rt(g - 1);
2401
+ }, [Ft, g, rt]), Xn = q(() => {
2402
+ At && rt(g + 1);
2403
+ }, [At, g, rt]), qn = q(() => {
2404
+ Ce((h) => (h + 90) % 360);
2405
+ }, []), Yn = q(() => {
2406
+ se((h) => Math.max(0.25, Math.round((h - 0.1) * 100) / 100));
2407
+ }, []), Kn = q(() => {
2408
+ se((h) => Math.min(5, Math.round((h + 0.1) * 100) / 100));
2409
+ }, []), St = q(async () => {
2410
+ if (!(!ie || !Ee.current))
2411
+ try {
2412
+ const p = (await ie.getPage(g)).getViewport({ scale: 1, rotation: re }), b = window.matchMedia("(max-width: 720px)").matches ? 16 : 24, R = Math.max(
2413
+ 0,
2414
+ Ee.current.clientWidth - b
2415
+ ) / p.width;
2416
+ se(Math.max(0.25, Math.min(5, Math.round(R * 100) / 100)));
2417
+ } catch {
2418
+ }
2419
+ }, [ie, g, re]);
2420
+ xe(() => {
2421
+ if (fe !== "ready" || !ie || !window.matchMedia("(max-width: 720px)").matches) return;
2422
+ let h = !1;
2423
+ const p = () => {
2424
+ h || St();
2425
+ };
2426
+ p();
2427
+ const d = Ee.current, b = typeof ResizeObserver < "u" && d ? new ResizeObserver(() => p()) : null;
2428
+ b == null || b.observe(d);
2429
+ const A = window.matchMedia("(max-width: 720px)"), R = () => {
2430
+ A.matches && p();
2431
+ };
2432
+ return A.addEventListener("change", R), () => {
2433
+ h = !0, b == null || b.disconnect(), A.removeEventListener("change", R);
2434
+ };
2435
+ }, [fe, ie, Ae, re, St]);
2436
+ const Zn = q(async () => {
2437
+ var h;
2438
+ if (!(!ie || fe !== "ready")) {
2439
+ Le(!0);
2440
+ try {
2441
+ const p = await cn(ie, {
2442
+ scale: 1.5,
2443
+ rotation: re,
2444
+ annotations: _,
2445
+ signatures: P,
2446
+ texts: L,
2447
+ mimeType: "image/png"
2448
+ }), d = document.createElement("iframe");
2449
+ d.style.position = "fixed", d.style.right = "0", d.style.bottom = "0", d.style.width = "0", d.style.height = "0", d.style.border = "0", d.setAttribute("aria-hidden", "true"), document.body.appendChild(d);
2450
+ const b = (h = d.contentWindow) == null ? void 0 : h.document;
2451
+ if (!b) throw new Error("print iframe not available");
2452
+ b.open(), b.write(`<!doctype html>
2453
+ <html>
2454
+ <head>
2455
+ <meta charset="utf-8" />
2456
+ <title>${s.replace(/</g, "&lt;")}</title>
2457
+ <style>
2458
+ html, body { margin: 0; padding: 0; }
2459
+ img { width: 100%; display: block; }
2460
+ .page { page-break-after: always; }
2461
+ .page:last-child { page-break-after: auto; }
2462
+ @page { margin: 10mm; }
2463
+ </style>
2464
+ </head>
2465
+ <body></body>
2466
+ </html>`), b.close();
2467
+ const A = b.body;
2468
+ for (const R of p) {
2469
+ const K = b.createElement("img");
2470
+ K.src = R.dataUrl;
2471
+ const Re = b.createElement("div");
2472
+ Re.className = "page", Re.appendChild(K), A.appendChild(Re);
2473
+ }
2474
+ await Promise.all(
2475
+ Array.from(A.querySelectorAll("img")).map(
2476
+ (R) => {
2477
+ var K;
2478
+ return ((K = R.decode) == null ? void 0 : K.call(R).catch(() => {
2479
+ })) ?? Promise.resolve();
2480
+ }
2481
+ )
2482
+ ), setTimeout(() => {
2483
+ var R, K;
2484
+ try {
2485
+ (R = d.contentWindow) == null || R.focus(), (K = d.contentWindow) == null || K.print();
2486
+ } finally {
2487
+ setTimeout(() => {
2488
+ try {
2489
+ document.body.removeChild(d);
2490
+ } catch {
2491
+ }
2492
+ }, 1e3);
2493
+ }
2494
+ }, 50);
2495
+ } catch {
2496
+ try {
2497
+ ce ? window.open(ce, "_blank", "noopener,noreferrer") : B && window.open(B, "_blank", "noopener,noreferrer");
2498
+ } catch {
2499
+ }
2500
+ } finally {
2501
+ Le(!1);
2502
+ }
2503
+ }
2504
+ }, [ie, fe, re, s, ce, B, _, P, L]), Vn = q(async () => {
2505
+ if (!ie || fe !== "ready") return;
2506
+ const h = `${s.replace(/[^\w.-]+/g, "_") || "document"}.pdf`;
2507
+ if (!(_.length > 0 || P.length > 0 || L.length > 0) && ce) {
2508
+ Xt(
2509
+ await fetch(ce).then((d) => d.blob()),
2510
+ h
2511
+ );
2512
+ return;
2513
+ }
2514
+ vt(!0);
2515
+ try {
2516
+ const d = await cn(ie, {
2517
+ scale: 2,
2518
+ rotation: re,
2519
+ annotations: _,
2520
+ signatures: P,
2521
+ texts: L,
2522
+ mimeType: "image/jpeg",
2523
+ quality: 0.92
2524
+ }), b = sr(d), A = new Uint8Array(b.byteLength);
2525
+ A.set(b), Xt(
2526
+ new Blob([A], { type: "application/pdf" }),
2527
+ h
2528
+ );
2529
+ } catch {
2530
+ ce && Xt(
2531
+ await fetch(ce).then((d) => d.blob()),
2532
+ h
2533
+ );
2534
+ } finally {
2535
+ vt(!1);
2536
+ }
2537
+ }, [ie, fe, re, s, ce, _, P, L]), Qn = q((h) => {
2538
+ w((p) => p === h ? "none" : h);
2539
+ }, []), Jn = o === "highlight" || o === "underline" ? mn(o === "highlight" ? Kt : o === "underline" ? Zt : null, o) : void 0, st = Ne != null ? P.find((h) => h.id === Ne) ?? null : null, ei = q((h) => {
2540
+ k((p) => [...p, h]);
2541
+ }, []), ti = q((h) => {
2542
+ k((p) => p.filter((d) => d.id !== h));
2543
+ }, []), ni = q(() => {
2544
+ k([]), N([]), O([]), pe(null), Xe(null), Ze(null), Je(null);
2545
+ }, []), ii = q(
2546
+ (h) => {
2547
+ le(h), W(!0);
2548
+ },
2549
+ []
2550
+ ), ri = q((h, p) => {
2551
+ Wn((d) => ({ ...d, [h]: p }));
2552
+ }, []), oi = q(
2553
+ (h) => {
2554
+ const p = it[h];
2555
+ p && (Me == null || Me(h, p));
2556
+ const d = C.findIndex((R) => R.id === h), b = new Set(
2557
+ Object.keys(it).filter((R) => {
2558
+ var K;
2559
+ return (K = it[R]) == null ? void 0 : K.trim();
2560
+ })
2561
+ );
2562
+ b.add(h);
2563
+ const A = C.slice(d + 1).find(
2564
+ (R) => !b.has(R.id) && !P.some((K) => K.fieldId === R.id)
2565
+ ) ?? C.slice(0, Math.max(0, d)).find(
2566
+ (R) => !b.has(R.id) && !P.some((K) => K.fieldId === R.id)
2567
+ );
2568
+ if (A) {
2569
+ $e(A.id), ot(A);
2570
+ const R = A.type;
2571
+ (R === "sign" || !R) && window.setTimeout(() => W(!0), 350);
2572
+ }
2573
+ },
2574
+ [C, it, P, ot]
2575
+ ), si = q(
2576
+ (h, p, d) => {
2577
+ const b = Pi(p, d);
2578
+ if (Ge) {
2579
+ N(
2580
+ (ee) => ee.map(
2581
+ (De) => De.id === Ge ? {
2582
+ ...De,
2583
+ imageDataUrl: h,
2584
+ width: De.fieldId ? De.width : b.width,
2585
+ height: De.fieldId ? De.height : b.height
2586
+ } : De
2587
+ )
2588
+ ), ne(null), w("none"), W(!1), Se(null);
2589
+ return;
2590
+ }
2591
+ if (He) {
2592
+ const ee = C.find(
2593
+ (we) => we.id === me && !P.some((nt) => nt.fieldId === we.id)
2594
+ ) ?? C.find(
2595
+ (we) => !P.some((nt) => nt.fieldId === we.id)
2596
+ );
2597
+ if (!ee) {
2598
+ W(!1);
2599
+ return;
2600
+ }
2601
+ const De = {
2602
+ id: Tt(),
2603
+ fieldId: ee.id,
2604
+ pageNumber: ee.pageNumber,
2605
+ x: ee.x,
2606
+ y: ee.y,
2607
+ width: ee.width,
2608
+ height: ee.height,
2609
+ imageDataUrl: h
2610
+ };
2611
+ N((we) => [
2612
+ ...we.filter((nt) => nt.fieldId !== ee.id),
2613
+ De
2614
+ ]), Q == null || Q(ee.id, De), ne(null), w("none"), W(!1), Se(null);
2615
+ const Ve = new Set(
2616
+ P.filter((we) => we.fieldId && we.fieldId !== ee.id).map((we) => we.fieldId)
2617
+ );
2618
+ Ve.add(ee.id);
2619
+ const kt = C.findIndex(
2620
+ (we) => we.id === ee.id
2621
+ ), pt = C.slice(kt + 1).find((we) => !Ve.has(we.id)) ?? C.slice(0, Math.max(0, kt)).find((we) => !Ve.has(we.id));
2622
+ pt ? ($e(pt.id), pe(null), ot(pt), window.setTimeout(() => {
2623
+ W(!0);
2624
+ }, 350)) : (pe(De.id), $e(ee.id));
2625
+ return;
2626
+ }
2627
+ const A = Pe.current.get(g), R = A == null ? void 0 : A.querySelector(
2628
+ ".epochs-pdf-viewer__surface"
2629
+ );
2630
+ let K = 24, Re = 24;
2631
+ if (R) {
2632
+ const ee = yt(R, Y), De = R.closest(".epochs-pdf-viewer__body");
2633
+ if (De) {
2634
+ const Ve = $i(
2635
+ De.getBoundingClientRect(),
2636
+ R,
2637
+ Y
2638
+ ), kt = Math.max(0, Ve.top), pt = Math.min(ee.height, Ve.bottom), we = Math.max(0, Ve.left), nt = Math.min(ee.width, Ve.right);
2639
+ K = Math.max(0, (we + nt) / 2 - b.width / 2), Re = Math.max(0, (kt + pt) / 2 - b.height / 2), K = Math.min(K, Math.max(0, ee.width - b.width)), Re = Math.min(Re, Math.max(0, ee.height - b.height));
2640
+ } else
2641
+ K = Math.max(0, (ee.width - b.width) / 2), Re = Math.max(0, (ee.height - b.height) / 2);
2642
+ }
2643
+ const qe = {
2644
+ id: Tt(),
2645
+ pageNumber: g,
2646
+ x: K,
2647
+ y: Re,
2648
+ width: b.width,
2649
+ height: b.height,
2650
+ imageDataUrl: h
2651
+ };
2652
+ N((ee) => [...ee, qe]), Q == null || Q(void 0, qe), pe(qe.id), ne(null), w("none"), W(!1), Se(null);
2653
+ },
2654
+ [
2655
+ Ge,
2656
+ He,
2657
+ g,
2658
+ Y,
2659
+ ot,
2660
+ me,
2661
+ C,
2662
+ P,
2663
+ Q
2664
+ ]
2665
+ ), ai = q((h) => {
2666
+ N((p) => [...p, h]), pe(h.id), ne(null), w("none");
2667
+ }, []), ci = q(
2668
+ (h, p) => {
2669
+ N(
2670
+ (d) => d.map((b) => b.id === h ? { ...b, ...p } : b)
2671
+ );
2672
+ },
2673
+ []
2674
+ ), li = q((h) => {
2675
+ const p = P.find((d) => d.id === h);
2676
+ N((d) => d.filter((b) => b.id !== h)), pe((d) => d === h ? null : d), p != null && p.fieldId && $e(p.fieldId);
2677
+ }, [P]), di = q((h) => {
2678
+ const p = h ? P.find((qe) => qe.id === h) ?? null : st;
2679
+ if (!p) return;
2680
+ const d = Pe.current.get(p.pageNumber), b = d == null ? void 0 : d.querySelector(
2681
+ ".epochs-pdf-viewer__surface"
2682
+ ), A = 18;
2683
+ let R = p.x + A, K = p.y + A;
2684
+ if (b) {
2685
+ const qe = b.clientWidth / Y, ee = b.clientHeight / Y;
2686
+ R = Math.min(
2687
+ Math.max(0, R),
2688
+ Math.max(0, qe - p.width)
2689
+ ), K = Math.min(
2690
+ Math.max(0, K),
2691
+ Math.max(0, ee - p.height)
2692
+ );
2693
+ }
2694
+ const Re = {
2695
+ ...p,
2696
+ id: Tt(),
2697
+ x: R,
2698
+ y: K
2699
+ };
2700
+ N((qe) => [...qe, Re]), pe(Re.id), ne(null), w("none");
2701
+ }, [Y, st, P]), hi = q((h) => {
2702
+ const p = h ?? (st == null ? void 0 : st.id);
2703
+ p && (pe(p), Se(p), W(!0));
2704
+ }, [st]), pi = q((h) => {
2705
+ O((p) => h.fieldId ? [...p.filter((d) => d.fieldId !== h.fieldId), h] : [...p, h]), Xe(h.id), h.fieldId && Ze(h.fieldId);
2706
+ }, []), ui = q(
2707
+ (h, p) => {
2708
+ O(
2709
+ (d) => d.map((b) => b.id === h ? { ...b, ...p } : b)
2710
+ );
2711
+ },
2712
+ []
2713
+ ), fi = q((h) => {
2714
+ const p = L.find((d) => d.id === h);
2715
+ O((d) => d.filter((b) => b.id !== h)), Xe((d) => d === h ? null : d), Je((d) => d === h ? null : d), p != null && p.fieldId && Ze(p.fieldId);
2716
+ }, [L]);
2717
+ xe(() => {
2718
+ dt && O(
2719
+ (h) => h.map((p) => {
2720
+ if (!p.fieldId) return p;
2721
+ const d = F.find((b) => b.id === p.fieldId);
2722
+ return d ? {
2723
+ ...p,
2724
+ pageNumber: d.pageNumber,
2725
+ x: d.x,
2726
+ y: d.y,
2727
+ width: d.width,
2728
+ height: d.height,
2729
+ fontSize: d.fontSize ?? p.fontSize ?? _t,
2730
+ color: d.color ?? p.color ?? wt
2731
+ } : p;
2732
+ })
2733
+ );
2734
+ }, [dt, F]);
2735
+ const tn = q(
2736
+ (h) => {
2737
+ var A;
2738
+ if (!C.length) return;
2739
+ const p = me != null ? C.findIndex((R) => R.id === me) : -1, d = Math.min(
2740
+ C.length - 1,
2741
+ Math.max(0, (p < 0 ? 0 : p) + h)
2742
+ ), b = C[d];
2743
+ b && ($e(b.id), pe(
2744
+ ((A = P.find((R) => R.fieldId === b.id)) == null ? void 0 : A.id) ?? null
2745
+ ), ot(b));
2746
+ },
2747
+ [
2748
+ ot,
2749
+ me,
2750
+ C,
2751
+ P
2752
+ ]
2753
+ );
2754
+ if (!ve && !B)
2755
+ return /* @__PURE__ */ a(
2756
+ "div",
2757
+ {
2758
+ "data-testid": "pdf-viewer",
2759
+ className: `epochs-pdf-viewer epochs-pdf-viewer--empty ${x ?? ""}`.trim(),
2760
+ children: "No PDF file provided."
2761
+ }
2762
+ );
2763
+ const gi = {
2764
+ height: r
2765
+ }, nn = {
2766
+ status: fe,
2767
+ showThumbnails: Ae,
2768
+ setShowThumbnails: Ue,
2769
+ canGoPrev: Ft,
2770
+ canGoNext: At,
2771
+ handlePrev: Gn,
2772
+ handleNext: Xn,
2773
+ pageNumber: g,
2774
+ numPages: he,
2775
+ scrollToPage: rt,
2776
+ scale: Y,
2777
+ handleZoomOut: Yn,
2778
+ handleZoomIn: Kn,
2779
+ handleFitWidth: St,
2780
+ handleRotate: qn,
2781
+ markupTool: o,
2782
+ toggleMarkupTool: (h) => Qn(h),
2783
+ hasFixedSignatureFields: He,
2784
+ hasFixedTextFields: dt,
2785
+ pendingSignature: de,
2786
+ setMarkupTool: w,
2787
+ setSignaturePadOpen: W,
2788
+ annotationsLength: _.length,
2789
+ signaturesLength: P.length,
2790
+ textsLength: L.length,
2791
+ handleClearAnnotations: ni,
2792
+ highlightHex: Kt,
2793
+ underlineHex: Zt,
2794
+ setHighlightHex: On,
2795
+ setUnderlineHex: Un,
2796
+ loadDocument: Dt,
2797
+ handlePrint: Zn,
2798
+ isPrinting: Ke,
2799
+ pdfDoc: ie,
2800
+ displayUrl: ce,
2801
+ resolvedUrl: B,
2802
+ handleDownload: Vn,
2803
+ isDownloading: We
2804
+ }, mi = (h) => h.filter((p) => !(He && (p === "highlight" || p === "underline" || p === "erase"))), Et = me ? C.findIndex((h) => h.id === me) : 0, wi = C.filter((h) => {
2805
+ var d;
2806
+ const p = h.type ?? "sign";
2807
+ return p === "date" || p === "text" ? !!((d = it[h.id]) != null && d.trim()) : P.some((b) => b.fieldId === h.id);
2808
+ }).length, Bt = C.length > 0 ? Math.round(wi / C.length * 100) : 0, rn = (h, p = !1) => {
2809
+ const d = mi(h);
2810
+ if (d.length === 0 && !p)
2811
+ return /* @__PURE__ */ a("div", { className: "epochs-pdf-viewer__toolbar-group" });
2812
+ if (d.length === 0)
2813
+ return /* @__PURE__ */ a("div", { className: "epochs-pdf-viewer__toolbar-group epochs-pdf-viewer__toolbar-group--end" });
2814
+ const b = d.map((A, R) => {
2815
+ const K = d[R - 1], Re = pn(A) && (!K || !pn(K));
2816
+ return /* @__PURE__ */ a(_i, { children: ur(A, nn, { showMarkupSep: Re }) }, A);
2817
+ });
2818
+ return /* @__PURE__ */ T(
2819
+ "div",
2820
+ {
2821
+ className: p ? "epochs-pdf-viewer__toolbar-group epochs-pdf-viewer__toolbar-group--end" : "epochs-pdf-viewer__toolbar-group",
2822
+ children: [
2823
+ b,
2824
+ fr(nn, new Set(d))
2825
+ ]
2826
+ }
2827
+ );
2828
+ };
2829
+ return /* @__PURE__ */ T(
2830
+ "div",
2831
+ {
2832
+ "data-testid": "pdf-viewer",
2833
+ "data-file-url": B || void 0,
2834
+ className: `epochs-pdf-viewer ${x ?? ""}`.trim(),
2835
+ style: gi,
2836
+ children: [
2837
+ et ? /* @__PURE__ */ T("div", { className: "epochs-pdf-viewer__toolbar", children: [
2838
+ rn(et.left),
2839
+ rn(et.right, !0)
2840
+ ] }) : null,
2841
+ Rt || Ie ? /* @__PURE__ */ a(
2842
+ lr,
2843
+ {
2844
+ open: Z,
2845
+ onClose: () => {
2846
+ W(!1), Se(null), ue == null || ue();
2847
+ },
2848
+ onSave: si,
2849
+ fieldType: H,
2850
+ showFieldTypeTabs: !He
2851
+ }
2852
+ ) : null,
2853
+ /* @__PURE__ */ T("div", { className: "epochs-pdf-viewer__content", children: [
2854
+ Ae ? /* @__PURE__ */ a(
2855
+ "div",
2856
+ {
2857
+ className: "epochs-pdf-viewer__thumbnails",
2858
+ style: { width: y + 24 },
2859
+ children: fe === "ready" && ie ? /* @__PURE__ */ T(bt, { children: [
2860
+ Array.from({
2861
+ length: Math.min(he || 0, f)
2862
+ }).map((h, p) => {
2863
+ const d = p + 1;
2864
+ return /* @__PURE__ */ a("div", { className: "epochs-pdf-viewer__thumb-wrap", children: /* @__PURE__ */ a(
2865
+ Ji,
2866
+ {
2867
+ pdfDoc: ie,
2868
+ pageNumber: d,
2869
+ isActive: d === g,
2870
+ rotation: re,
2871
+ onSelect: rt,
2872
+ width: y,
2873
+ annotations: _,
2874
+ signatures: P,
2875
+ signatureFields: C,
2876
+ texts: L,
2877
+ textFields: F
2878
+ }
2879
+ ) }, d);
2880
+ }),
2881
+ he > f ? /* @__PURE__ */ T("div", { className: "epochs-pdf-viewer__thumb-more", children: [
2882
+ "Showing first ",
2883
+ f,
2884
+ " pages"
2885
+ ] }) : null
2886
+ ] }) : /* @__PURE__ */ a("div", { className: "epochs-pdf-viewer__muted", children: "Thumbnails" })
2887
+ }
2888
+ ) : null,
2889
+ /* @__PURE__ */ T("div", { ref: Ee, className: "epochs-pdf-viewer__body", children: [
2890
+ fe === "loading" ? /* @__PURE__ */ T("div", { className: "epochs-pdf-viewer__overlay epochs-pdf-viewer__muted", children: [
2891
+ "Loading PDF…",
2892
+ /* @__PURE__ */ a("span", { className: "epochs-pdf-viewer__spinner" })
2893
+ ] }) : null,
2894
+ fe === "error" ? /* @__PURE__ */ T("div", { className: "epochs-pdf-viewer__overlay epochs-pdf-viewer__error", children: [
2895
+ "Unable to load PDF.",
2896
+ B ? /* @__PURE__ */ a(
2897
+ "a",
2898
+ {
2899
+ className: "epochs-pdf-viewer__open-link",
2900
+ href: B,
2901
+ target: "_blank",
2902
+ rel: "noopener noreferrer",
2903
+ children: "Open file"
2904
+ }
2905
+ ) : null
2906
+ ] }) : null,
2907
+ fe === "ready" && ie ? /* @__PURE__ */ a("div", { children: Array.from({ length: he }).map((h, p) => {
2908
+ const d = p + 1;
2909
+ return /* @__PURE__ */ a(
2910
+ Qi,
2911
+ {
2912
+ pdfDoc: ie,
2913
+ pageNumber: d,
2914
+ scale: Y,
2915
+ rotation: re,
2916
+ markupTool: te ? o : "none",
2917
+ markupColor: Jn,
2918
+ annotations: _,
2919
+ onAddAnnotation: ei,
2920
+ onRemoveAnnotation: ti,
2921
+ signatures: P,
2922
+ pendingSignature: de,
2923
+ onAddSignature: ai,
2924
+ onUpdateSignature: ci,
2925
+ onRemoveSignature: li,
2926
+ onEditSignature: hi,
2927
+ onDuplicateSignature: di,
2928
+ selectedSignatureId: Ne,
2929
+ onSelectSignature: pe,
2930
+ signatureFields: C,
2931
+ selectedSignatureFieldId: me,
2932
+ onSelectSignatureField: $e,
2933
+ hasFixedSignatureFields: He,
2934
+ onOpenSignaturePad: ii,
2935
+ fieldValues: it,
2936
+ onFieldValueChange: ri,
2937
+ onFieldValueCommit: oi,
2938
+ texts: L,
2939
+ onAddText: pi,
2940
+ onUpdateText: ui,
2941
+ onRemoveText: fi,
2942
+ selectedTextId: lt,
2943
+ onSelectText: Xe,
2944
+ textFields: F,
2945
+ selectedTextFieldId: xt,
2946
+ onSelectTextField: Ze,
2947
+ hasFixedTextFields: dt,
2948
+ editingTextId: Lt,
2949
+ onEditingTextIdChange: Je,
2950
+ pageRef: (b) => {
2951
+ b && Pe.current.set(d, b);
2952
+ }
2953
+ },
2954
+ d
2955
+ );
2956
+ }) }) : null
2957
+ ] })
2958
+ ] }),
2959
+ He || be ? /* @__PURE__ */ T("div", { className: "epochs-pdf-viewer__footer", role: "navigation", "aria-label": "Viewer actions", children: [
2960
+ He ? /* @__PURE__ */ T(bt, { children: [
2961
+ /* @__PURE__ */ T("div", { className: "epochs-pdf-viewer__footer-nav", children: [
2962
+ /* @__PURE__ */ a(
2963
+ "button",
2964
+ {
2965
+ type: "button",
2966
+ className: "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",
2967
+ disabled: C.length <= 1 || Et <= 0,
2968
+ onClick: () => tn(-1),
2969
+ children: "Prev"
2970
+ }
2971
+ ),
2972
+ /* @__PURE__ */ a(
2973
+ "button",
2974
+ {
2975
+ type: "button",
2976
+ className: "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text",
2977
+ disabled: C.length <= 1 || Et >= C.length - 1,
2978
+ onClick: () => tn(1),
2979
+ children: "Next"
2980
+ }
2981
+ )
2982
+ ] }),
2983
+ /* @__PURE__ */ T("div", { className: "epochs-pdf-viewer__footer-center", children: [
2984
+ /* @__PURE__ */ T("span", { className: "epochs-pdf-viewer__footer-label", children: [
2985
+ "Field ",
2986
+ Math.max(1, Et + 1),
2987
+ " of ",
2988
+ C.length
2989
+ ] }),
2990
+ /* @__PURE__ */ a(
2991
+ "div",
2992
+ {
2993
+ className: "epochs-pdf-viewer__footer-progress",
2994
+ role: "progressbar",
2995
+ "aria-valuemin": 0,
2996
+ "aria-valuemax": 100,
2997
+ "aria-valuenow": Bt,
2998
+ "aria-label": "Signature progress",
2999
+ children: /* @__PURE__ */ a(
3000
+ "div",
3001
+ {
3002
+ className: "epochs-pdf-viewer__footer-progress-bar",
3003
+ style: { width: `${Bt}%` }
3004
+ }
3005
+ )
3006
+ }
3007
+ ),
3008
+ /* @__PURE__ */ T("span", { className: "epochs-pdf-viewer__footer-percent", children: [
3009
+ Bt,
3010
+ "%"
3011
+ ] })
3012
+ ] })
3013
+ ] }) : /* @__PURE__ */ a("div", { className: "epochs-pdf-viewer__footer-center" }),
3014
+ be ? /* @__PURE__ */ a(
3015
+ "button",
3016
+ {
3017
+ type: "button",
3018
+ className: "epochs-pdf-viewer__btn epochs-pdf-viewer__btn--text epochs-pdf-viewer__btn--primary",
3019
+ onClick: be,
3020
+ children: J
3021
+ }
3022
+ ) : null
3023
+ ] }) : null
3024
+ ]
3025
+ }
3026
+ );
3027
+ }
3028
+ function mr(e) {
3029
+ return null;
3030
+ }
3031
+ mr.displayName = "Document";
3032
+ function wr(e) {
3033
+ return null;
3034
+ }
3035
+ wr.displayName = "Page";
3036
+ function yr(e) {
3037
+ return null;
3038
+ }
3039
+ yr.displayName = "View";
3040
+ function br(e) {
3041
+ return null;
3042
+ }
3043
+ br.displayName = "Text";
3044
+ function _r(e) {
3045
+ return null;
3046
+ }
3047
+ _r.displayName = "Image";
3048
+ function vr(e) {
3049
+ return null;
3050
+ }
3051
+ vr.displayName = "Link";
3052
+ const xr = {
3053
+ Document: "DOCUMENT",
3054
+ Page: "PAGE",
3055
+ View: "VIEW",
3056
+ Text: "TEXT",
3057
+ Image: "IMAGE",
3058
+ Link: "LINK"
3059
+ };
3060
+ function kr(e) {
3061
+ if (typeof e == "string") return e;
3062
+ if (typeof e == "function") {
3063
+ const t = e;
3064
+ return t.displayName || t.name || null;
3065
+ }
3066
+ return null;
3067
+ }
3068
+ function An(e) {
3069
+ const t = [], n = (i) => {
3070
+ if (!(i == null || typeof i == "boolean")) {
3071
+ if (Array.isArray(i)) {
3072
+ i.forEach(n);
3073
+ return;
3074
+ }
3075
+ t.push(i);
3076
+ }
3077
+ };
3078
+ return n(e), t;
3079
+ }
3080
+ function Sn(e) {
3081
+ return An(e).map((t) => typeof t == "string" || typeof t == "number" ? String(t) : t && typeof t == "object" && "props" in t ? Sn(t.props.children) : "").join("");
3082
+ }
3083
+ function En(e) {
3084
+ const t = kr(e.type), n = t ? xr[t] : void 0;
3085
+ if (!n)
3086
+ throw new Error(
3087
+ `[epochs-pdf] Unsupported element "${t ?? "unknown"}". Use Document, Page, View, Text, Image, or Link.`
3088
+ );
3089
+ const i = { ...e.props }, r = i.children;
3090
+ if (delete i.children, n === "TEXT" || n === "LINK")
3091
+ return {
3092
+ type: n,
3093
+ props: i,
3094
+ children: [],
3095
+ text: Sn(r)
3096
+ };
3097
+ const s = An(r).filter(
3098
+ (c) => !!c && typeof c == "object" && "type" in c
3099
+ ).map(En);
3100
+ return {
3101
+ type: n,
3102
+ props: i,
3103
+ children: s
3104
+ };
3105
+ }
3106
+ const Mr = {
3107
+ A4: [595.28, 841.89],
3108
+ LETTER: [612, 792],
3109
+ LEGAL: [612, 1008]
3110
+ };
3111
+ function Pr(e = "A4", t = "portrait") {
3112
+ const [n, i] = Array.isArray(e) ? e : Mr[e];
3113
+ return t === "landscape" ? [i, n] : [n, i];
3114
+ }
3115
+ function Bn(e = {}) {
3116
+ const t = e.padding ?? 0;
3117
+ return {
3118
+ top: e.paddingTop ?? t,
3119
+ right: e.paddingRight ?? t,
3120
+ bottom: e.paddingBottom ?? t,
3121
+ left: e.paddingLeft ?? t
3122
+ };
3123
+ }
3124
+ function ft(e = {}) {
3125
+ const t = e.margin ?? 0;
3126
+ return {
3127
+ top: e.marginTop ?? t,
3128
+ right: e.marginRight ?? t,
3129
+ bottom: e.marginBottom ?? t,
3130
+ left: e.marginLeft ?? t
3131
+ };
3132
+ }
3133
+ function $t(e) {
3134
+ if (!e) return null;
3135
+ const t = e.trim();
3136
+ if (t.startsWith("#")) {
3137
+ const i = t.slice(1);
3138
+ if (i.length === 3) {
3139
+ const r = parseInt(i[0] + i[0], 16) / 255, s = parseInt(i[1] + i[1], 16) / 255, c = parseInt(i[2] + i[2], 16) / 255;
3140
+ return [r, s, c];
3141
+ }
3142
+ if (i.length === 6) {
3143
+ const r = parseInt(i.slice(0, 2), 16) / 255, s = parseInt(i.slice(2, 4), 16) / 255, c = parseInt(i.slice(4, 6), 16) / 255;
3144
+ return [r, s, c];
3145
+ }
3146
+ }
3147
+ const n = e.match(
3148
+ /rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/i
3149
+ );
3150
+ return n ? [
3151
+ Math.min(1, Number(n[1]) / 255),
3152
+ Math.min(1, Number(n[2]) / 255),
3153
+ Math.min(1, Number(n[3]) / 255)
3154
+ ] : null;
3155
+ }
3156
+ function at(e, t, n = 0) {
3157
+ if (e == null) return n;
3158
+ if (typeof e == "number") return e;
3159
+ if (e.endsWith("%")) {
3160
+ const r = Number.parseFloat(e);
3161
+ return Number.isFinite(r) ? r / 100 * t : n;
3162
+ }
3163
+ const i = Number.parseFloat(e);
3164
+ return Number.isFinite(i) ? i : n;
3165
+ }
3166
+ function qt(e) {
3167
+ return e === "bold" ? !0 : typeof e == "number" ? e >= 600 : !1;
3168
+ }
3169
+ const Nr = 12, $r = 1.4, Tr = 0.5;
3170
+ function Hn(e, t, n) {
3171
+ const i = t.fontSize ?? Nr, r = (t.lineHeight ?? $r) * i, s = i * (qt(t.fontWeight) ? 0.55 : Tr);
3172
+ if (!e)
3173
+ return { width: 0, height: r, lines: [""] };
3174
+ const c = e.split(/\s+/), l = [];
3175
+ let y = "";
3176
+ for (const x of c) {
3177
+ const v = y ? `${y} ${x}` : x;
3178
+ v.length * s <= n || !y ? y = v : (l.push(y), y = x);
3179
+ }
3180
+ y && l.push(y);
3181
+ const f = Math.max(...l.map((x) => x.length * s), 0);
3182
+ return {
3183
+ width: Math.min(f, n),
3184
+ height: l.length * r,
3185
+ lines: l
3186
+ };
3187
+ }
3188
+ function zn(e, t, n, i, r) {
3189
+ const s = e.props.style ?? {}, c = ft(s), l = Bn(s), y = t + c.left, f = n + c.top, x = Math.max(
3190
+ 0,
3191
+ at(s.width, i, i) - c.left - c.right
3192
+ ), v = Math.max(0, x - l.left - l.right);
3193
+ if (e.type === "TEXT" || e.type === "LINK") {
3194
+ const F = Hn(e.text ?? "", s, v), Q = at(s.height, r, F.height + l.top + l.bottom);
3195
+ return {
3196
+ x: y,
3197
+ y: f,
3198
+ width: x,
3199
+ height: Q,
3200
+ node: e,
3201
+ children: [],
3202
+ style: s,
3203
+ text: e.text
3204
+ };
3205
+ }
3206
+ if (e.type === "IMAGE") {
3207
+ const F = at(s.width, i, Math.min(200, i)), Q = at(s.height, r, 120);
3208
+ return {
3209
+ x: y,
3210
+ y: f,
3211
+ width: F - c.left - c.right,
3212
+ height: Q,
3213
+ node: e,
3214
+ children: [],
3215
+ style: s
3216
+ };
3217
+ }
3218
+ const m = s.flexDirection ?? "column", M = s.gap ?? 0, $ = [];
3219
+ let G = y + l.left, S = f + l.top, z = 0, E = 0;
3220
+ for (let F = 0; F < e.children.length; F++) {
3221
+ const Q = e.children[F], Me = m === "row" ? Math.max(0, v - z - (F > 0 ? M : 0)) : v, Ie = m === "column" ? Math.max(0, r - (S - n) - c.bottom) : r, ue = zn(Q, G, S, Me, Ie);
3222
+ $.push(ue), m === "row" ? (z += ue.width + ft(Q.props.style ?? {}).left + ft(Q.props.style ?? {}).right, F < e.children.length - 1 && (z += M), G = y + l.left + z, E = Math.max(E, ue.height)) : (z += ue.height + ft(Q.props.style ?? {}).top + ft(Q.props.style ?? {}).bottom, F < e.children.length - 1 && (z += M), S = f + l.top + z, E = Math.max(E, ue.width));
3223
+ }
3224
+ const I = at(
3225
+ s.height,
3226
+ r,
3227
+ m === "column" ? z + l.top + l.bottom : E + l.top + l.bottom
3228
+ ), V = m === "row" ? at(s.width, i, z + l.left + l.right) : x, te = s.justifyContent ?? "flex-start", X = s.alignItems ?? "stretch", oe = m === "column" ? I - l.top - l.bottom : V - l.left - l.right, ye = Math.max(0, oe - z);
3229
+ let D = 0, ae = M;
3230
+ te === "center" && (D = ye / 2), te === "flex-end" && (D = ye), te === "space-between" && $.length > 1 && (ae = M + ye / ($.length - 1)), te === "space-around" && $.length > 0 && (ae = M + ye / $.length, D = ae / 2);
3231
+ let C = 0;
3232
+ for (const F of $)
3233
+ m === "column" ? (F.y = f + l.top + D + C, X === "center" ? F.x = y + l.left + Math.max(0, (v - F.width) / 2) : X === "flex-end" ? F.x = y + l.left + Math.max(0, v - F.width) : X === "stretch" && F.style.width == null && (F.width = v), C += F.height + ae) : (F.x = y + l.left + D + C, X === "center" ? F.y = f + l.top + Math.max(0, (I - l.top - l.bottom - F.height) / 2) : X === "flex-end" ? F.y = f + l.top + Math.max(0, I - l.top - l.bottom - F.height) : X === "stretch" && F.style.height == null && (F.height = I - l.top - l.bottom), C += F.width + ae);
3234
+ return {
3235
+ x: y,
3236
+ y: f,
3237
+ width: V,
3238
+ height: I,
3239
+ node: e,
3240
+ children: $,
3241
+ style: s
3242
+ };
3243
+ }
3244
+ function Ir(e) {
3245
+ if (e.type !== "DOCUMENT")
3246
+ throw new Error("[epochs-pdf] Root element must be <Document>.");
3247
+ const t = [];
3248
+ for (const n of e.children) {
3249
+ if (n.type !== "PAGE")
3250
+ throw new Error("[epochs-pdf] Direct children of <Document> must be <Page>.");
3251
+ const i = n.props.size, r = n.props.orientation ?? "portrait", [s, c] = Pr(i, r), l = n.props.style ?? {}, y = Bn(l), f = {
3252
+ type: "VIEW",
3253
+ props: {
3254
+ style: {
3255
+ ...l,
3256
+ width: s,
3257
+ height: c,
3258
+ paddingTop: y.top,
3259
+ paddingRight: y.right,
3260
+ paddingBottom: y.bottom,
3261
+ paddingLeft: y.left
3262
+ }
3263
+ },
3264
+ children: n.children
3265
+ }, x = zn(f, 0, 0, s, c);
3266
+ t.push({
3267
+ width: s,
3268
+ height: c,
3269
+ boxes: x.children,
3270
+ style: l
3271
+ });
3272
+ }
3273
+ return {
3274
+ meta: {
3275
+ title: String(e.props.title ?? "Untitled"),
3276
+ author: String(e.props.author ?? ""),
3277
+ subject: String(e.props.subject ?? ""),
3278
+ creator: String(e.props.creator ?? "epochs-pdf")
3279
+ },
3280
+ pages: t
3281
+ };
3282
+ }
3283
+ function gt(e) {
3284
+ return e.replace(/\\/g, "\\\\").replace(/\(/g, "\\(").replace(/\)/g, "\\)").replace(/\r/g, "\\r").replace(/\n/g, "\\n");
3285
+ }
3286
+ class Cr {
3287
+ constructor() {
3288
+ Ht(this, "objects", [null]);
3289
+ Ht(this, "offsets", [0]);
3290
+ }
3291
+ addObject(t) {
3292
+ return this.objects.push(t), this.objects.length - 1;
3293
+ }
3294
+ build(t) {
3295
+ const n = this.addObject(
3296
+ `<< /Title (${gt(t.meta.title)}) /Author (${gt(t.meta.author)}) /Subject (${gt(t.meta.subject)}) /Creator (${gt(t.meta.creator)}) /Producer (epochs-pdf) >>`
3297
+ ), i = this.addObject(
3298
+ "<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>"
3299
+ ), r = this.addObject(
3300
+ "<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica-Bold >>"
3301
+ ), s = [];
3302
+ for (const v of t.pages) {
3303
+ const m = this.renderPageContent(
3304
+ v.boxes,
3305
+ v.width,
3306
+ v.height,
3307
+ v.style
3308
+ ), M = this.addObject(
3309
+ `<< /Length ${m.length} >>
3310
+ stream
3311
+ ${m}
3312
+ endstream`
3313
+ ), $ = this.addObject("");
3314
+ s.push($), this.objects[$] = `<< /Type /Page /Parent 0 0 R /MediaBox [0 0 ${v.width.toFixed(2)} ${v.height.toFixed(2)}] /Contents ${M} 0 R /Resources << /Font << /F1 ${i} 0 R /F2 ${r} 0 R >> >> >>`;
3315
+ }
3316
+ const c = s.map((v) => `${v} 0 R`).join(" "), l = this.addObject(
3317
+ `<< /Type /Pages /Kids [${c}] /Count ${s.length} >>`
3318
+ );
3319
+ for (const v of s)
3320
+ this.objects[v] = this.objects[v].replace(
3321
+ "/Parent 0 0 R",
3322
+ `/Parent ${l} 0 R`
3323
+ );
3324
+ const y = this.addObject(
3325
+ `<< /Type /Catalog /Pages ${l} 0 R >>`
3326
+ );
3327
+ let f = `%PDF-1.4
3328
+ `;
3329
+ this.offsets = [0];
3330
+ for (let v = 1; v < this.objects.length; v++)
3331
+ this.offsets[v] = f.length, f += `${v} 0 obj
3332
+ ${this.objects[v]}
3333
+ endobj
3334
+ `;
3335
+ const x = f.length;
3336
+ f += `xref
3337
+ 0 ${this.objects.length}
3338
+ `, f += `0000000000 65535 f
3339
+ `;
3340
+ for (let v = 1; v < this.objects.length; v++)
3341
+ f += `${String(this.offsets[v]).padStart(10, "0")} 00000 n
3342
+ `;
3343
+ return f += `trailer
3344
+ << /Size ${this.objects.length} /Root ${y} 0 R /Info ${n} 0 R >>
3345
+ `, f += `startxref
3346
+ ${x}
3347
+ %%EOF`, new TextEncoder().encode(f);
3348
+ }
3349
+ renderPageContent(t, n, i, r) {
3350
+ const s = [], c = $t(r.backgroundColor);
3351
+ c && (s.push("q"), s.push(
3352
+ `${c[0].toFixed(3)} ${c[1].toFixed(3)} ${c[2].toFixed(3)} rg`
3353
+ ), s.push(
3354
+ `0 0 ${n.toFixed(2)} ${i.toFixed(2)} re f`
3355
+ ), s.push("Q"));
3356
+ const l = (y) => {
3357
+ const { x: f, y: x, width: v, height: m, style: M, node: $, text: G } = y, S = i - x - m, z = $t(M.backgroundColor);
3358
+ if (z && (s.push("q"), s.push(`${z[0].toFixed(3)} ${z[1].toFixed(3)} ${z[2].toFixed(3)} rg`), s.push(`${f.toFixed(2)} ${S.toFixed(2)} ${v.toFixed(2)} ${m.toFixed(2)} re f`), s.push("Q")), M.borderWidth && M.borderWidth > 0) {
3359
+ const E = $t(M.borderColor) ?? [0, 0, 0];
3360
+ s.push("q"), s.push(`${M.borderWidth} w`), s.push(`${E[0].toFixed(3)} ${E[1].toFixed(3)} ${E[2].toFixed(3)} RG`), s.push(`${f.toFixed(2)} ${S.toFixed(2)} ${v.toFixed(2)} ${m.toFixed(2)} re S`), s.push("Q");
3361
+ }
3362
+ if (($.type === "TEXT" || $.type === "LINK") && G != null) {
3363
+ const E = M.fontSize ?? 12, I = $t(M.color) ?? [0, 0, 0], V = qt(M.fontWeight) ? "F2" : "F1", te = M.paddingLeft ?? M.padding ?? 0, X = M.paddingTop ?? M.padding ?? 0, oe = Math.max(0, v - te - (M.paddingRight ?? M.padding ?? 0)), ke = Hn(G, M, oe || v), ye = (M.lineHeight ?? 1.4) * E;
3364
+ s.push("q"), s.push("BT"), s.push(`/${V} ${E} Tf`), s.push(`${I[0].toFixed(3)} ${I[1].toFixed(3)} ${I[2].toFixed(3)} rg`), ke.lines.forEach((D, ae) => {
3365
+ let C = f + te;
3366
+ const F = D.length * E * (qt(M.fontWeight) ? 0.55 : 0.5);
3367
+ M.textAlign === "center" ? C = f + (v - F) / 2 : M.textAlign === "right" && (C = f + v - F - (M.paddingRight ?? M.padding ?? 0));
3368
+ const Q = i - x - X - E - ae * ye;
3369
+ s.push(`1 0 0 1 ${C.toFixed(2)} ${Q.toFixed(2)} Tm`), s.push(`(${gt(D)}) Tj`);
3370
+ }), s.push("ET"), s.push("Q");
3371
+ }
3372
+ $.type === "IMAGE" && (s.push("q"), s.push("0.85 0.85 0.85 rg"), s.push(`${f.toFixed(2)} ${S.toFixed(2)} ${v.toFixed(2)} ${m.toFixed(2)} re f`), s.push("0.6 0.6 0.6 RG 1 w"), s.push(`${f.toFixed(2)} ${S.toFixed(2)} ${v.toFixed(2)} ${m.toFixed(2)} re S`), s.push(
3373
+ `BT /F1 10 Tf 0.4 0.4 0.4 rg 1 0 0 1 ${(f + 8).toFixed(2)} ${(S + m / 2 - 4).toFixed(2)} Tm (Image) Tj ET`
3374
+ ), s.push("Q"));
3375
+ for (const E of y.children)
3376
+ l(E);
3377
+ };
3378
+ for (const y of t)
3379
+ l(y);
3380
+ return s.join(`
3381
+ `);
3382
+ }
3383
+ }
3384
+ function Lr(e) {
3385
+ return new Cr().build(e);
3386
+ }
3387
+ function Yt(e) {
3388
+ const t = En(e), n = Ir(t);
3389
+ return Lr(n);
3390
+ }
3391
+ function zr(e) {
3392
+ return Yt(e);
3393
+ }
3394
+ function jn(e) {
3395
+ const t = Yt(e), n = new Uint8Array(t.byteLength);
3396
+ return n.set(t), new Blob([n], { type: "application/pdf" });
3397
+ }
3398
+ function Rr(e) {
3399
+ return URL.createObjectURL(jn(e));
3400
+ }
3401
+ function jr(e, t = "document.pdf") {
3402
+ const n = Rr(e), i = document.createElement("a");
3403
+ i.href = n, i.download = t, i.click(), URL.revokeObjectURL(n);
3404
+ }
3405
+ async function Or(e) {
3406
+ return Yt(e);
3407
+ }
3408
+ async function Ur(e) {
3409
+ return jn(e);
3410
+ }
3411
+ export {
3412
+ Br as ALL_TOOLBAR_TOOLS,
3413
+ Rn as AddText,
3414
+ Fn as Clear,
3415
+ hn as DEFAULT_TOOLBAR_LAYOUT,
3416
+ mr as Document,
3417
+ Tn as Download,
3418
+ Dn as Erase,
3419
+ un as HIGHLIGHT_PRESETS,
3420
+ In as Highlight,
3421
+ _r as Image,
3422
+ vr as Link,
3423
+ xn as Navigation,
3424
+ $n as Open,
3425
+ Mr as PAGE_SIZES,
3426
+ wr as Page,
3427
+ Hr as PdfViewer,
3428
+ Nn as Print,
3429
+ Pn as Reload,
3430
+ Mn as Rotate,
3431
+ Ln as Signature,
3432
+ br as Text,
3433
+ vn as Thumbnail,
3434
+ fn as UNDERLINE_PRESETS,
3435
+ Cn as Underline,
3436
+ yr as View,
3437
+ kn as Zoom,
3438
+ Hr as default,
3439
+ jr as download,
3440
+ mn as hexToMarkupColor,
3441
+ zr as pdf,
3442
+ Ur as renderToBlob,
3443
+ Or as renderToBuffer,
3444
+ Pr as resolvePageSize,
3445
+ sn as setPdfWorkerSrc,
3446
+ jn as toBlob,
3447
+ Rr as toUrl
3448
+ };
3449
+ //# sourceMappingURL=epochs-pdf.js.map