@promr-acorda/core 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,71 +1,71 @@
1
- import { PDFDocument as I, StandardFonts as N, rgb as m } from "pdf-lib";
2
- const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type === "signature", ae = (e) => typeof e != "object", x = (e) => Object.prototype.toString.call(e) === "[object Uint8Array]", u = (e) => !g(e) || !x(e.image) ? e : {
1
+ import { PDFDocument as T, StandardFonts as N, rgb as w } from "pdf-lib";
2
+ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type === "signature", de = (e) => typeof e != "object", M = (e) => Object.prototype.toString.call(e) === "[object Uint8Array]", u = (e) => !g(e) || !M(e.image) ? e : {
3
3
  ...e,
4
4
  image: Uint8Array.from(e.image)
5
- }, D = /* @__PURE__ */ new Set([
5
+ }, $ = /* @__PURE__ */ new Set([
6
6
  "image/png",
7
7
  "image/jpeg",
8
8
  "image/jpg"
9
- ]), $ = (e) => {
9
+ ]), C = (e) => {
10
10
  const t = e == null ? void 0 : e.trim().toLowerCase();
11
- if (t && D.has(t))
11
+ if (t && $.has(t))
12
12
  return t === "image/jpg" ? "image/jpeg" : t;
13
- }, C = (e) => {
13
+ }, R = (e) => {
14
14
  if (e.length >= 8 && e[0] === 137 && e[1] === 80 && e[2] === 78 && e[3] === 71 && e[4] === 13 && e[5] === 10 && e[6] === 26 && e[7] === 10)
15
15
  return "image/png";
16
16
  if (e.length >= 3 && e[0] === 255 && e[1] === 216 && e[2] === 255)
17
17
  return "image/jpeg";
18
- }, T = (e) => {
19
- const t = C(e.image), r = $(e.mimeType);
18
+ }, v = (e) => {
19
+ const t = R(e.image), r = C(e.mimeType);
20
20
  if (!(r && t && r !== t))
21
21
  return r ?? t;
22
- }, K = 5e-3, R = 0, w = 1, L = (e, t) => Math.max(0, Math.min(t - 1, Math.floor(e))), b = (e) => Math.max(R, Math.min(w, e)), p = (e) => Math.max(K, e), v = (e, t) => {
23
- const r = L(e.page, t), n = b(e.x), s = b(e.y), o = p(e.width), i = p(e.height), a = Math.min(o, w - n), d = Math.min(i, w - s);
22
+ }, K = 5e-3, L = 0, x = 1, k = (e, t) => Math.max(0, Math.min(t - 1, Math.floor(e))), A = (e) => Math.max(L, Math.min(x, e)), m = (e) => Math.max(K, e), y = (e, t) => {
23
+ const r = k(e.page, t), n = A(e.x), i = A(e.y), s = m(e.width), o = m(e.height), a = Math.min(s, x - n), d = Math.min(o, x - i);
24
24
  return {
25
25
  page: r,
26
26
  x: n,
27
- y: s,
28
- width: p(a),
29
- height: p(d)
27
+ y: i,
28
+ width: m(a),
29
+ height: m(d)
30
30
  };
31
31
  }, S = (e, t, r) => ({
32
32
  x: e.x * t,
33
33
  y: e.y * r,
34
34
  width: e.width * t,
35
35
  height: e.height * r
36
- }), de = (e, t, r) => ({
36
+ }), he = (e, t, r) => ({
37
37
  page: e.page,
38
38
  x: e.x / t,
39
39
  y: e.y / r,
40
40
  width: e.width / t,
41
41
  height: e.height / r
42
- }), ce = (e, t) => e.find((r) => r.sharedKey === t && r.sharedMode === "source"), he = (e, t) => e.filter((r) => r.sharedKey === t && r.sharedMode === "mirror"), f = (e, t, r) => {
42
+ }), ce = (e, t) => e.find((r) => r.sharedKey === t && r.sharedMode === "source"), le = (e, t) => e.filter((r) => r.sharedKey === t && r.sharedMode === "mirror"), f = (e, t, r) => {
43
43
  if (e.sharedKey) {
44
- const o = r[e.sharedKey];
45
- if (o !== void 0) return u(o);
44
+ const s = r[e.sharedKey];
45
+ if (s !== void 0) return u(s);
46
46
  }
47
47
  const n = t[e.id];
48
48
  if (n !== void 0) return u(n);
49
- const s = e.defaultValue;
50
- return s !== void 0 ? u(s) : void 0;
51
- }, k = (e, t, r, n) => {
49
+ const i = e.defaultValue;
50
+ return i !== void 0 ? u(i) : void 0;
51
+ }, j = (e, t, r, n) => {
52
52
  if (!e.some(
53
- (o) => o.sharedKey === r && o.sharedMode === "source"
53
+ (s) => s.sharedKey === r && s.sharedMode === "source"
54
54
  ))
55
55
  throw new Error(
56
56
  `Cannot set shared value: no source field exists for key "${r}".`
57
57
  );
58
58
  return { ...t, [r]: u(n) };
59
- }, le = (e, t, r) => {
59
+ }, ue = (e, t, r) => {
60
60
  const n = Object.fromEntries(
61
- Object.entries(t).map(([s, o]) => [
62
- s,
63
- u(o)
61
+ Object.entries(t).map(([i, s]) => [
62
+ i,
63
+ u(s)
64
64
  ])
65
65
  );
66
- for (const s of e) {
67
- const o = f(s, t, r);
68
- o !== void 0 && (n[s.id] = o);
66
+ for (const i of e) {
67
+ const s = f(i, t, r);
68
+ s !== void 0 && (n[i.id] = s);
69
69
  }
70
70
  return n;
71
71
  }, V = 5 * 1024 * 1024, l = (e, t, r) => {
@@ -76,7 +76,7 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
76
76
  message: ((n = e.validation) == null ? void 0 : n.customMessage) ?? t,
77
77
  code: r
78
78
  };
79
- }, j = (e, t) => {
79
+ }, z = (e, t) => {
80
80
  const r = [], { validation: n } = e;
81
81
  if (!n) return r;
82
82
  if (n.minLength !== void 0 && t.length < n.minLength && r.push(
@@ -110,14 +110,14 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
110
110
  );
111
111
  }
112
112
  return r;
113
- }, z = (e, t) => {
113
+ }, U = (e, t) => {
114
114
  const r = [], n = e;
115
115
  return n.min !== void 0 && t < n.min && r.push(
116
116
  l(e, `Minimum value is ${n.min}.`, "MIN_VALUE")
117
117
  ), n.max !== void 0 && t > n.max && r.push(
118
118
  l(e, `Maximum value is ${n.max}.`, "MAX_VALUE")
119
119
  ), r;
120
- }, M = (e, t) => {
120
+ }, E = (e, t) => {
121
121
  if (e.sharedMode === "mirror")
122
122
  return { valid: !0, errors: [] };
123
123
  const r = [], n = t === void 0 || t === "" || t === null || typeof t == "boolean" && !t && e.type !== "checkbox";
@@ -128,11 +128,11 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
128
128
  if (e.type === "checkbox" && typeof t != "boolean" || e.type === "number" && (typeof t != "number" || !Number.isFinite(t)) || e.type === "signature" && !g(t) || e.type !== "checkbox" && e.type !== "number" && e.type !== "signature" && typeof t != "string")
129
129
  return r.push(l(e, "The value type is invalid for this field.", "INVALID_TYPE")), { valid: !1, errors: r };
130
130
  if (typeof t == "string")
131
- r.push(...j(e, t));
132
- else if (typeof t == "number")
133
131
  r.push(...z(e, t));
132
+ else if (typeof t == "number")
133
+ r.push(...U(e, t));
134
134
  else if (g(t)) {
135
- if (!x(t.image) || t.image.length === 0)
135
+ if (!M(t.image) || t.image.length === 0)
136
136
  return r.push(l(e, "Image data is invalid.", "INVALID_TYPE")), { valid: !1, errors: r };
137
137
  t.image.length > V && r.push(
138
138
  l(
@@ -140,7 +140,7 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
140
140
  `Image data must be ${Math.floor(V / (1024 * 1024))} MB or smaller.`,
141
141
  "INVALID_TYPE"
142
142
  )
143
- ), T(t) === void 0 && r.push(
143
+ ), v(t) === void 0 && r.push(
144
144
  l(
145
145
  e,
146
146
  "Only PNG and JPEG signature images are allowed, and MIME type must match the image data.",
@@ -149,9 +149,9 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
149
149
  );
150
150
  }
151
151
  return { valid: r.length === 0, errors: r };
152
- }, U = (e, t, r, n) => {
153
- const o = e.filter((a) => a.sharedKey === n).find((a) => a.sharedMode === "source");
154
- if (!o)
152
+ }, G = (e, t, r, n) => {
153
+ const s = e.filter((a) => a.sharedKey === n).find((a) => a.sharedMode === "source");
154
+ if (!s)
155
155
  return {
156
156
  valid: !1,
157
157
  errors: [
@@ -163,69 +163,69 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
163
163
  }
164
164
  ]
165
165
  };
166
- const i = f(o, t, r);
167
- return M(o, i);
168
- }, ue = (e) => {
169
- const { fields: t, fieldValues: r, sharedValues: n } = e, s = /* @__PURE__ */ new Set(), o = [];
170
- for (const i of t)
171
- if (i.sharedMode !== "mirror")
172
- if (i.sharedKey) {
173
- if (s.has(i.sharedKey)) continue;
174
- s.add(i.sharedKey);
175
- const a = U(
166
+ const o = f(s, t, r);
167
+ return E(s, o);
168
+ }, fe = (e) => {
169
+ const { fields: t, fieldValues: r, sharedValues: n } = e, i = /* @__PURE__ */ new Set(), s = [];
170
+ for (const o of t)
171
+ if (o.sharedMode !== "mirror")
172
+ if (o.sharedKey) {
173
+ if (i.has(o.sharedKey)) continue;
174
+ i.add(o.sharedKey);
175
+ const a = G(
176
176
  t,
177
177
  r,
178
178
  n,
179
- i.sharedKey
179
+ o.sharedKey
180
180
  );
181
- o.push(...a.errors);
181
+ s.push(...a.errors);
182
182
  } else {
183
- const a = f(i, r, n), d = M(i, a);
184
- o.push(...d.errors);
183
+ const a = f(o, r, n), d = E(o, a);
184
+ s.push(...d.errors);
185
185
  }
186
- return { valid: o.length === 0, errors: o };
187
- }, G = /* @__PURE__ */ new Set(["y", "Y", "M", "m", "d", "D", "h", "H", "s", "S"]), H = /* @__PURE__ */ new Set(["\\", "^", "$", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", "|"]), Y = (e) => H.has(e) ? `\\${e}` : e, q = (e) => {
186
+ return { valid: s.length === 0, errors: s };
187
+ }, H = /* @__PURE__ */ new Set(["y", "Y", "M", "m", "d", "D", "h", "H", "s", "S"]), Y = /* @__PURE__ */ new Set(["\\", "^", "$", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", "|"]), q = (e) => Y.has(e) ? `\\${e}` : e, W = (e) => {
188
188
  let t = "";
189
189
  for (let r = 0; r < e.length; ) {
190
190
  const n = e[r];
191
191
  if (n === void 0) break;
192
- if (G.has(n)) {
193
- let s = 1;
194
- for (; e[r + s] === n; )
195
- s += 1;
196
- t += `\\d{${s}}`, r += s;
192
+ if (H.has(n)) {
193
+ let i = 1;
194
+ for (; e[r + i] === n; )
195
+ i += 1;
196
+ t += `\\d{${i}}`, r += i;
197
197
  continue;
198
198
  }
199
- t += Y(n), r += 1;
199
+ t += q(n), r += 1;
200
200
  }
201
201
  return t;
202
- }, fe = (e, t) => {
202
+ }, ge = (e, t) => {
203
203
  const r = e.trim();
204
- return r ? new RegExp(`^(?:${q(r)})$`).test(t) : !0;
205
- }, O = /^(\d{4})-(\d{2})-(\d{2})$/, ge = (e) => O.test(e), X = (e, t) => {
204
+ return r ? new RegExp(`^(?:${W(r)})$`).test(t) : !0;
205
+ }, O = /^(\d{4})-(\d{2})-(\d{2})$/, pe = (e) => O.test(e), X = (e, t) => {
206
206
  const r = O.exec(e), n = t == null ? void 0 : t.trim();
207
207
  if (!r || !n) return e;
208
- const [, s = "", o = "", i = ""] = r;
208
+ const [, i = "", s = "", o = ""] = r;
209
209
  let a = "";
210
210
  for (let d = 0; d < n.length; ) {
211
- const h = n[d];
212
- if (h === void 0) break;
213
- let c = 1;
214
- for (; n[d + c] === h; )
215
- c += 1;
216
- if (h === "y" || h === "Y") {
217
- a += c === 2 ? s.slice(-2) : s.padStart(c, "0"), d += c;
211
+ const c = n[d];
212
+ if (c === void 0) break;
213
+ let h = 1;
214
+ for (; n[d + h] === c; )
215
+ h += 1;
216
+ if (c === "y" || c === "Y") {
217
+ a += h === 2 ? i.slice(-2) : i.padStart(h, "0"), d += h;
218
218
  continue;
219
219
  }
220
- if (h === "M" || h === "m") {
221
- a += c === 1 ? String(Number(o)) : o.padStart(c, "0"), d += c;
220
+ if (c === "M" || c === "m") {
221
+ a += h === 1 ? String(Number(s)) : s.padStart(h, "0"), d += h;
222
222
  continue;
223
223
  }
224
- if (h === "d" || h === "D") {
225
- a += c === 1 ? String(Number(i)) : i.padStart(c, "0"), d += c;
224
+ if (c === "d" || c === "D") {
225
+ a += h === 1 ? String(Number(o)) : o.padStart(h, "0"), d += h;
226
226
  continue;
227
227
  }
228
- a += h, d += 1;
228
+ a += c, d += 1;
229
229
  }
230
230
  return a;
231
231
  }, _ = (e) => {
@@ -239,17 +239,17 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
239
239
  );
240
240
  t.set(r.sharedKey, r.id);
241
241
  }
242
- }, W = (e, t) => {
242
+ }, B = (e, t) => {
243
243
  if (e.some((r) => r.id === t))
244
244
  throw new Error(`Field ID "${t}" already exists.`);
245
- }, B = (e, t) => {
245
+ }, J = (e, t) => {
246
246
  switch (e.type) {
247
247
  case "checkbox":
248
248
  return typeof t == "boolean";
249
249
  case "number":
250
250
  return typeof t == "number" && Number.isFinite(t);
251
251
  case "signature":
252
- return g(t) && x(t.image);
252
+ return g(t) && M(t.image);
253
253
  case "text":
254
254
  case "date":
255
255
  case "email":
@@ -259,71 +259,91 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
259
259
  default:
260
260
  return !1;
261
261
  }
262
- }, J = (e, t) => !(t.page !== void 0 && e.page !== t.page || t.type !== void 0 && e.type !== t.type || t.required !== void 0 && (e.required ?? !1) !== t.required || t.hidden !== void 0 && (e.hidden ?? !1) !== t.hidden || t.readonly !== void 0 && (e.readonly ?? !1) !== t.readonly || t.sharedKey !== void 0 && e.sharedKey !== t.sharedKey || t.sharedMode !== void 0 && e.sharedMode !== t.sharedMode), Q = (e) => ({
262
+ }, Q = (e, t) => !(t.page !== void 0 && e.page !== t.page || t.type !== void 0 && e.type !== t.type || t.required !== void 0 && (e.required ?? !1) !== t.required || t.hidden !== void 0 && (e.hidden ?? !1) !== t.hidden || t.readonly !== void 0 && (e.readonly ?? !1) !== t.readonly || t.sharedKey !== void 0 && e.sharedKey !== t.sharedKey || t.sharedMode !== void 0 && e.sharedMode !== t.sharedMode), D = (e, t) => {
263
+ const r = y(e, t.pageCount);
264
+ if (e.type !== "checkbox") return r;
265
+ const n = t.pages.find((s) => s.index === r.page);
266
+ if (!n || n.width <= 0 || n.height <= 0) {
267
+ const s = Math.min(r.width, r.height);
268
+ return y({ ...r, width: s, height: s }, t.pageCount);
269
+ }
270
+ const i = Math.min(
271
+ r.width * n.width,
272
+ r.height * n.height
273
+ );
274
+ return y(
275
+ {
276
+ ...r,
277
+ width: i / n.width,
278
+ height: i / n.height
279
+ },
280
+ t.pageCount
281
+ );
282
+ }, Z = (e) => ({
263
283
  ...e,
264
284
  fields: [],
265
285
  fieldValues: {},
266
286
  sharedValues: {},
267
287
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
268
288
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
269
- }), Z = async (e) => (await I.load(e)).getPages().map((r, n) => ({
289
+ }), ee = async (e) => (await T.load(e)).getPages().map((r, n) => ({
270
290
  index: n,
271
291
  width: r.getWidth(),
272
292
  height: r.getHeight()
273
- })), ye = async (e) => {
274
- const t = await Z(e.pdfData);
275
- return Q({
293
+ })), me = async (e) => {
294
+ const t = await ee(e.pdfData);
295
+ return Z({
276
296
  ...e,
277
297
  pageCount: t.length,
278
298
  pages: t
279
299
  });
280
- }, pe = (e, t) => {
281
- W(e.fields, t.id);
282
- const r = v(t, e.pageCount), n = { ...t, ...r }, s = [...e.fields, n];
283
- return _(s), {
300
+ }, ye = (e, t) => {
301
+ B(e.fields, t.id);
302
+ const r = D(t, e), n = { ...t, ...r }, i = [...e.fields, n];
303
+ return _(i), {
284
304
  ...e,
285
- fields: s,
305
+ fields: i,
286
306
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
287
307
  };
288
308
  }, P = (e, t, r) => {
289
- const n = e.fields.map((s) => {
290
- if (s.id !== t) return s;
291
- const o = { ...s, ...r }, i = v(o, e.pageCount);
292
- return { ...o, ...i };
309
+ const n = e.fields.map((i) => {
310
+ if (i.id !== t) return i;
311
+ const s = { ...i, ...r }, o = D(s, e);
312
+ return { ...s, ...o };
293
313
  });
294
314
  return _(n), {
295
315
  ...e,
296
316
  fields: n,
297
317
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
298
318
  };
299
- }, me = (e, t) => {
300
- const r = e.fields.find((i) => i.id === t), n = e.fields.filter((i) => i.id !== t), s = Object.fromEntries(
301
- Object.entries(e.fieldValues).filter(([i]) => i !== t)
319
+ }, we = (e, t) => {
320
+ const r = e.fields.find((o) => o.id === t), n = e.fields.filter((o) => o.id !== t), i = Object.fromEntries(
321
+ Object.entries(e.fieldValues).filter(([o]) => o !== t)
302
322
  );
303
- let { sharedValues: o } = e;
323
+ let { sharedValues: s } = e;
304
324
  return r != null && r.sharedKey && r.sharedMode === "source" && (n.some(
305
325
  (a) => a.sharedKey === r.sharedKey && a.sharedMode === "source"
306
- ) || (o = Object.fromEntries(
307
- Object.entries(o).filter(([a]) => a !== r.sharedKey)
326
+ ) || (s = Object.fromEntries(
327
+ Object.entries(s).filter(([a]) => a !== r.sharedKey)
308
328
  ))), {
309
329
  ...e,
310
330
  fields: n,
311
- fieldValues: s,
312
- sharedValues: o,
331
+ fieldValues: i,
332
+ sharedValues: s,
313
333
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
314
334
  };
315
- }, we = (e, t, r) => {
316
- const { page: n, x: s, y: o } = r;
335
+ }, xe = (e, t, r) => {
336
+ const { page: n, x: i, y: s } = r;
317
337
  return P(
318
338
  e,
319
339
  t,
320
- n !== void 0 ? { page: n, x: s, y: o } : { x: s, y: o }
340
+ n !== void 0 ? { page: n, x: i, y: s } : { x: i, y: s }
321
341
  );
322
- }, xe = (e, t, r) => P(e, t, {
342
+ }, Me = (e, t, r) => P(e, t, {
323
343
  width: r.width,
324
344
  height: r.height
325
345
  }), Se = (e, t, r) => {
326
- const n = e.fields.find((s) => s.id === t);
346
+ const n = e.fields.find((i) => i.id === t);
327
347
  if (!n)
328
348
  throw new Error(`Field ID "${t}" was not found.`);
329
349
  if (n.sharedMode === "mirror")
@@ -332,12 +352,12 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
332
352
  );
333
353
  if (n.readonly)
334
354
  throw new Error(`Cannot set value on read-only field "${t}".`);
335
- if (!B(n, r))
355
+ if (!J(n, r))
336
356
  throw new Error(
337
357
  `Value for field "${t}" is incompatible with field type "${n.type}".`
338
358
  );
339
359
  if (n.sharedKey && n.sharedMode === "source") {
340
- const s = k(
360
+ const i = j(
341
361
  e.fields,
342
362
  e.sharedValues,
343
363
  n.sharedKey,
@@ -345,7 +365,7 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
345
365
  );
346
366
  return {
347
367
  ...e,
348
- sharedValues: s,
368
+ sharedValues: i,
349
369
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
350
370
  };
351
371
  }
@@ -357,8 +377,8 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
357
377
  },
358
378
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
359
379
  };
360
- }, Me = (e, t) => {
361
- const r = e.fields.find((o) => o.id === t);
380
+ }, Ee = (e, t) => {
381
+ const r = e.fields.find((s) => s.id === t);
362
382
  if (!r)
363
383
  throw new Error(`Field ID "${t}" was not found.`);
364
384
  if (r.sharedMode === "mirror")
@@ -368,23 +388,23 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
368
388
  if (r.readonly)
369
389
  throw new Error(`Cannot clear value on read-only field "${t}".`);
370
390
  if (r.sharedKey && r.sharedMode === "source") {
371
- const { [r.sharedKey]: o, ...i } = e.sharedValues;
391
+ const { [r.sharedKey]: s, ...o } = e.sharedValues;
372
392
  return {
373
393
  ...e,
374
- sharedValues: i,
394
+ sharedValues: o,
375
395
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
376
396
  };
377
397
  }
378
- const { [t]: n, ...s } = e.fieldValues;
398
+ const { [t]: n, ...i } = e.fieldValues;
379
399
  return {
380
400
  ...e,
381
- fieldValues: s,
401
+ fieldValues: i,
382
402
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
383
403
  };
384
- }, Ee = (e, t) => {
404
+ }, Fe = (e, t) => {
385
405
  const r = e.fields.find((n) => n.id === t);
386
406
  return r ? { ...r } : void 0;
387
- }, Fe = (e, t = {}) => e.fields.filter((r) => J(r, t)).map((r) => ({ ...r })), be = (e, t) => {
407
+ }, be = (e, t = {}) => e.fields.filter((r) => Q(r, t)).map((r) => ({ ...r })), Ae = (e, t) => {
388
408
  const r = e.fields.find((n) => n.id === t);
389
409
  if (r)
390
410
  return f(r, e.fieldValues, e.sharedValues);
@@ -392,58 +412,62 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
392
412
  function Ve(e, t = {}) {
393
413
  const r = {};
394
414
  for (const n of e.fields) {
395
- const s = f(
415
+ const i = f(
396
416
  n,
397
417
  e.fieldValues,
398
418
  e.sharedValues
399
419
  );
400
- (s !== void 0 || t.includeEmpty) && (r[n.id] = s);
420
+ (i !== void 0 || t.includeEmpty) && (r[n.id] = i);
401
421
  }
402
422
  return r;
403
423
  }
404
- const ee = (e, t, r, n, s, o) => {
405
- const a = Math.max(0, o - 4), d = Math.min(r.widthOfTextAtSize(t, n), a);
424
+ const te = (e, t, r, n, i, s) => {
425
+ const a = Math.max(0, s - 4), d = Math.min(r.widthOfTextAtSize(t, n), a);
406
426
  switch (e.textAlign) {
407
427
  case "center":
408
- return s + (o - d) / 2;
428
+ return i + (s - d) / 2;
409
429
  case "right":
410
- return s + o - 2 - d;
430
+ return i + s - 2 - d;
411
431
  case "left":
412
432
  default:
413
- return s + 2;
433
+ return i + 2;
414
434
  }
415
- }, te = (e) => ({
435
+ }, re = (e) => ({
416
436
  width: e.getWidth(),
417
437
  height: e.getHeight()
418
- }), A = (e, t, r, n, s) => {
419
- const o = S(t, s.width, s.height), i = t.textSize ?? 10, a = s.height - o.y - o.height / 2 - i / 2, d = ee(t, r, n, i, o.x, o.width);
438
+ }), I = (e, t, r, n, i) => {
439
+ const s = S(t, i.width, i.height), o = t.textSize ?? 10, a = i.height - s.y - s.height / 2 - o / 2, d = te(t, r, n, o, s.x, s.width);
420
440
  e.drawText(r, {
421
441
  x: d,
422
442
  y: Math.max(0, a),
423
- size: i,
443
+ size: o,
424
444
  font: n,
425
- color: m(0, 0, 0),
426
- maxWidth: o.width - 4
445
+ color: w(0, 0, 0),
446
+ maxWidth: s.width - 4
427
447
  });
428
- }, re = (e, t, r, n) => {
448
+ }, ne = (e, t, r, n) => {
429
449
  if (!r) return;
430
- const s = S(t, n.width, n.height), o = s.x + s.width / 2, i = n.height - s.y - s.height / 2;
450
+ const i = S(t, n.width, n.height), s = Math.min(i.width, i.height), o = {
451
+ ...i,
452
+ x: i.x + (i.width - s) / 2,
453
+ y: i.y + (i.height - s) / 2
454
+ }, a = n.height - o.y - s, d = Math.max(1.2, s * 0.11);
431
455
  e.drawLine({
432
- start: { x: s.x + 2, y: i },
433
- end: { x: o, y: n.height - s.y - s.height + 2 },
434
- thickness: 1.5,
435
- color: m(0, 0, 0)
456
+ start: { x: o.x + s * 0.22, y: a + s * 0.49 },
457
+ end: { x: o.x + s * 0.42, y: a + s * 0.31 },
458
+ thickness: d,
459
+ color: w(0, 0, 0)
436
460
  }), e.drawLine({
437
- start: { x: o, y: n.height - s.y - s.height + 2 },
438
- end: { x: s.x + s.width - 2, y: n.height - s.y - 2 },
439
- thickness: 1.5,
440
- color: m(0, 0, 0)
461
+ start: { x: o.x + s * 0.42, y: a + s * 0.31 },
462
+ end: { x: o.x + s * 0.78, y: a + s * 0.68 },
463
+ thickness: d,
464
+ color: w(0, 0, 0)
441
465
  });
442
- }, ne = async (e, t, r, n, s, o) => {
443
- const i = S(r, o.width, o.height), a = o.height - i.y - i.height, d = T(
444
- s !== void 0 ? {
466
+ }, se = async (e, t, r, n, i, s) => {
467
+ const o = S(r, s.width, s.height), a = s.height - o.y - o.height, d = v(
468
+ i !== void 0 ? {
445
469
  image: n,
446
- mimeType: s
470
+ mimeType: i
447
471
  } : {
448
472
  image: n
449
473
  }
@@ -452,109 +476,109 @@ const ee = (e, t, r, n, s, o) => {
452
476
  throw new Error(
453
477
  `Field "${r.id}" contains an unsupported signature image format for PDF export.`
454
478
  );
455
- const c = d === "image/jpeg" ? await t.embedJpg(n) : await t.embedPng(n);
456
- e.drawImage(c, {
457
- x: i.x,
479
+ const h = d === "image/jpeg" ? await t.embedJpg(n) : await t.embedPng(n);
480
+ e.drawImage(h, {
481
+ x: o.x,
458
482
  y: Math.max(0, a),
459
- width: i.width,
460
- height: i.height
483
+ width: o.width,
484
+ height: o.height
461
485
  });
462
- }, se = async (e, t, r, n, s, o) => {
486
+ }, ie = async (e, t, r, n, i, s) => {
463
487
  if (!(n === void 0 || r.hidden)) {
464
488
  if (g(n)) {
465
- await ne(
489
+ await se(
466
490
  e,
467
491
  t,
468
492
  r,
469
493
  n.image,
470
494
  n.mimeType,
471
- o
495
+ s
472
496
  );
473
497
  return;
474
498
  }
475
499
  if (typeof n == "boolean") {
476
- r.type === "checkbox" && re(e, r, n, o);
500
+ r.type === "checkbox" && ne(e, r, n, s);
477
501
  return;
478
502
  }
479
503
  if (typeof n == "string" && n.trim() !== "") {
480
- A(
504
+ I(
481
505
  e,
482
506
  r,
483
507
  r.type === "date" ? X(n, r.dateFormat) : n,
484
- s,
485
- o
508
+ i,
509
+ s
486
510
  );
487
511
  return;
488
512
  }
489
- typeof n == "number" && A(e, r, String(n), s, o);
513
+ typeof n == "number" && I(e, r, String(n), i, s);
490
514
  }
491
515
  }, oe = (e) => {
492
516
  if (!(e.byteLength > 0))
493
517
  throw new Error(
494
518
  "exportToPdf requires a non-empty source PDF in document.pdfData."
495
519
  );
496
- }, Ae = async (e, t = {}) => {
497
- var i;
520
+ }, Ie = async (e, t = {}) => {
521
+ var o;
498
522
  oe(e.pdfData);
499
- const r = await I.load(e.pdfData), n = await r.embedFont(N.Helvetica), s = r.getPages(), o = /* @__PURE__ */ new Map();
523
+ const r = await T.load(e.pdfData), n = await r.embedFont(N.Helvetica), i = r.getPages(), s = /* @__PURE__ */ new Map();
500
524
  for (const a of e.fields) {
501
- const d = o.get(a.page) ?? [];
502
- o.set(a.page, [...d, a]);
525
+ const d = s.get(a.page) ?? [];
526
+ s.set(a.page, [...d, a]);
503
527
  }
504
- for (const [a, d] of o) {
505
- const h = s[a];
506
- if (!h) continue;
507
- const c = te(h);
508
- for (const y of d) {
509
- const E = f(
510
- y,
528
+ for (const [a, d] of s) {
529
+ const c = i[a];
530
+ if (!c) continue;
531
+ const h = re(c);
532
+ for (const p of d) {
533
+ const F = f(
534
+ p,
511
535
  e.fieldValues,
512
536
  e.sharedValues
513
- ), F = M(y, E);
514
- if (!F.valid)
537
+ ), b = E(p, F);
538
+ if (!b.valid)
515
539
  throw new Error(
516
- `Field "${y.id}" is invalid for PDF export: ${((i = F.errors[0]) == null ? void 0 : i.message) ?? "Unknown validation error."}`
540
+ `Field "${p.id}" is invalid for PDF export: ${((o = b.errors[0]) == null ? void 0 : o.message) ?? "Unknown validation error."}`
517
541
  );
518
- await se(h, r, y, E, n, c);
542
+ await ie(c, r, p, F, n, h);
519
543
  }
520
544
  }
521
545
  return r.save();
522
546
  };
523
547
  export {
524
- b as clampCoord,
525
- L as clampToPage,
526
- Me as clearFieldValue,
527
- Q as createDocument,
528
- ye as createDocumentFromPdfData,
529
- pe as createField,
530
- q as dateFormatToRegexPattern,
531
- p as ensureMinSize,
532
- Ae as exportToPdf,
548
+ A as clampCoord,
549
+ k as clampToPage,
550
+ Ee as clearFieldValue,
551
+ Z as createDocument,
552
+ me as createDocumentFromPdfData,
553
+ ye as createField,
554
+ W as dateFormatToRegexPattern,
555
+ m as ensureMinSize,
556
+ Ie as exportToPdf,
533
557
  X as formatDateValue,
534
- Ee as getField,
535
- Fe as getFields,
536
- he as getMirrorFields,
537
- Z as getPdfPageInfo,
538
- be as getResolvedFieldValue,
558
+ Fe as getField,
559
+ be as getFields,
560
+ le as getMirrorFields,
561
+ ee as getPdfPageInfo,
562
+ Ae as getResolvedFieldValue,
539
563
  Ve as getResolvedValues,
540
564
  ce as getSourceField,
541
- ge as isIsoDateString,
542
- ae as isPrimitiveValue,
565
+ pe as isIsoDateString,
566
+ de as isPrimitiveValue,
543
567
  g as isSignatureValue,
544
- fe as matchesDateFormat,
545
- we as moveField,
546
- v as normalizeRect,
547
- me as removeField,
548
- xe as resizeField,
549
- le as resolveAllSharedValues,
568
+ ge as matchesDateFormat,
569
+ xe as moveField,
570
+ y as normalizeRect,
571
+ we as removeField,
572
+ Me as resizeField,
573
+ ue as resolveAllSharedValues,
550
574
  f as resolveFieldValue,
551
575
  Se as setFieldValue,
552
- k as setSharedFieldValue,
576
+ j as setSharedFieldValue,
553
577
  S as toAbsoluteRect,
554
- de as toNormalizedRect,
578
+ he as toNormalizedRect,
555
579
  P as updateField,
556
- ue as validateDocument,
557
- M as validateField,
558
- U as validateSharedFieldGroup
580
+ fe as validateDocument,
581
+ E as validateField,
582
+ G as validateSharedFieldGroup
559
583
  };
560
584
  //# sourceMappingURL=index.js.map