@promr-acorda/core 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6,27 +6,27 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
6
6
  "image/png",
7
7
  "image/jpeg",
8
8
  "image/jpg"
9
- ]), C = (e) => {
9
+ ]), K = (e) => {
10
10
  const t = e == null ? void 0 : e.trim().toLowerCase();
11
11
  if (t && $.has(t))
12
12
  return t === "image/jpg" ? "image/jpeg" : t;
13
- }, R = (e) => {
13
+ }, C = (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
18
  }, T = (e) => {
19
- const t = R(e.image), r = C(e.mimeType);
19
+ const t = C(e.image), r = K(e.mimeType);
20
20
  if (!(r && t && r !== t))
21
21
  return r ?? t;
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)), p = (e) => Math.max(K, e), y = (e, t) => {
23
- const r = k(e.page, t), n = A(e.x), i = A(e.y), s = p(e.width), o = p(e.height), a = Math.min(s, x - n), d = Math.min(o, x - i);
22
+ }, R = 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(R, e), y = (e, t) => {
23
+ const r = k(e.page, t), s = A(e.x), n = A(e.y), i = m(e.width), o = m(e.height), a = Math.min(i, x - s), d = Math.min(o, x - n);
24
24
  return {
25
25
  page: r,
26
- x: n,
27
- y: i,
28
- width: p(a),
29
- height: p(d)
26
+ x: s,
27
+ y: n,
28
+ width: m(a),
29
+ height: m(d)
30
30
  };
31
31
  }, S = (e, t, r) => ({
32
32
  x: e.x * t,
@@ -41,59 +41,59 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
41
41
  height: e.height / r
42
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 s = r[e.sharedKey];
45
- if (s !== void 0) return u(s);
44
+ const i = r[e.sharedKey];
45
+ if (i !== void 0) return u(i);
46
46
  }
47
- const n = t[e.id];
48
- if (n !== void 0) return u(n);
49
- const i = e.defaultValue;
50
- return i !== void 0 ? u(i) : void 0;
51
- }, j = (e, t, r, n) => {
47
+ const s = t[e.id];
48
+ if (s !== void 0) return u(s);
49
+ const n = e.defaultValue;
50
+ return n !== void 0 ? u(n) : void 0;
51
+ }, j = (e, t, r, s) => {
52
52
  if (!e.some(
53
- (s) => s.sharedKey === r && s.sharedMode === "source"
53
+ (i) => i.sharedKey === r && i.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
- return { ...t, [r]: u(n) };
58
+ return { ...t, [r]: u(s) };
59
59
  }, ue = (e, t, r) => {
60
- const n = Object.fromEntries(
61
- Object.entries(t).map(([i, s]) => [
62
- i,
63
- u(s)
60
+ const s = Object.fromEntries(
61
+ Object.entries(t).map(([n, i]) => [
62
+ n,
63
+ u(i)
64
64
  ])
65
65
  );
66
- for (const i of e) {
67
- const s = f(i, t, r);
68
- s !== void 0 && (n[i.id] = s);
66
+ for (const n of e) {
67
+ const i = f(n, t, r);
68
+ i !== void 0 && (s[n.id] = i);
69
69
  }
70
- return n;
70
+ return s;
71
71
  }, V = 5 * 1024 * 1024, l = (e, t, r) => {
72
- var n;
72
+ var s;
73
73
  return {
74
74
  fieldId: e.id,
75
75
  fieldName: e.name,
76
- message: ((n = e.validation) == null ? void 0 : n.customMessage) ?? t,
76
+ message: ((s = e.validation) == null ? void 0 : s.customMessage) ?? t,
77
77
  code: r
78
78
  };
79
79
  }, z = (e, t) => {
80
- const r = [], { validation: n } = e;
81
- if (!n) return r;
82
- if (n.minLength !== void 0 && t.length < n.minLength && r.push(
80
+ const r = [], { validation: s } = e;
81
+ if (!s) return r;
82
+ if (s.minLength !== void 0 && t.length < s.minLength && r.push(
83
83
  l(
84
84
  e,
85
- `Must be at least ${n.minLength} characters.`,
85
+ `Must be at least ${s.minLength} characters.`,
86
86
  "MIN_LENGTH"
87
87
  )
88
- ), n.maxLength !== void 0 && t.length > n.maxLength && r.push(
88
+ ), s.maxLength !== void 0 && t.length > s.maxLength && r.push(
89
89
  l(
90
90
  e,
91
- `Must be at most ${n.maxLength} characters.`,
91
+ `Must be at most ${s.maxLength} characters.`,
92
92
  "MAX_LENGTH"
93
93
  )
94
- ), n.pattern !== void 0)
94
+ ), s.pattern !== void 0)
95
95
  try {
96
- new RegExp(n.pattern).test(t) || r.push(
96
+ new RegExp(s.pattern).test(t) || r.push(
97
97
  l(
98
98
  e,
99
99
  "The value does not match the required format.",
@@ -111,17 +111,17 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
111
111
  }
112
112
  return r;
113
113
  }, U = (e, t) => {
114
- const r = [], n = e;
115
- return n.min !== void 0 && t < n.min && r.push(
116
- l(e, `Minimum value is ${n.min}.`, "MIN_VALUE")
117
- ), n.max !== void 0 && t > n.max && r.push(
118
- l(e, `Maximum value is ${n.max}.`, "MAX_VALUE")
114
+ const r = [], s = e;
115
+ return s.min !== void 0 && t < s.min && r.push(
116
+ l(e, `Minimum value is ${s.min}.`, "MIN_VALUE")
117
+ ), s.max !== void 0 && t > s.max && r.push(
118
+ l(e, `Maximum value is ${s.max}.`, "MAX_VALUE")
119
119
  ), r;
120
120
  }, E = (e, t) => {
121
121
  if (e.sharedMode === "mirror")
122
122
  return { valid: !0, errors: [] };
123
- const r = [], n = t === void 0 || t === "" || t === null || typeof t == "boolean" && !t && e.type !== "checkbox";
124
- if (e.required && n)
123
+ const r = [], s = t === void 0 || t === "" || t === null || typeof t == "boolean" && !t && e.type !== "checkbox";
124
+ if (e.required && s)
125
125
  return r.push(l(e, "This field is required.", "REQUIRED")), { valid: !1, errors: r };
126
126
  if (t === void 0 || t === "")
127
127
  return { valid: !0, errors: [] };
@@ -149,76 +149,76 @@ 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
- }, G = (e, t, r, n) => {
153
- const s = e.filter((a) => a.sharedKey === n).find((a) => a.sharedMode === "source");
154
- if (!s)
152
+ }, q = (e, t, r, s) => {
153
+ const i = e.filter((a) => a.sharedKey === s).find((a) => a.sharedMode === "source");
154
+ if (!i)
155
155
  return {
156
156
  valid: !1,
157
157
  errors: [
158
158
  {
159
- fieldId: n,
160
- fieldName: n,
161
- message: `No source field found for shared key "${n}".`,
159
+ fieldId: s,
160
+ fieldName: s,
161
+ message: `No source field found for shared key "${s}".`,
162
162
  code: "SHARED_SOURCE_NOT_FOUND"
163
163
  }
164
164
  ]
165
165
  };
166
- const o = f(s, t, r);
167
- return E(s, o);
166
+ const o = f(i, t, r);
167
+ return E(i, o);
168
168
  }, fe = (e) => {
169
- const { fields: t, fieldValues: r, sharedValues: n } = e, i = /* @__PURE__ */ new Set(), s = [];
169
+ const { fields: t, fieldValues: r, sharedValues: s } = e, n = /* @__PURE__ */ new Set(), i = [];
170
170
  for (const o of t)
171
171
  if (o.sharedMode !== "mirror")
172
172
  if (o.sharedKey) {
173
- if (i.has(o.sharedKey)) continue;
174
- i.add(o.sharedKey);
175
- const a = G(
173
+ if (n.has(o.sharedKey)) continue;
174
+ n.add(o.sharedKey);
175
+ const a = q(
176
176
  t,
177
177
  r,
178
- n,
178
+ s,
179
179
  o.sharedKey
180
180
  );
181
- s.push(...a.errors);
181
+ i.push(...a.errors);
182
182
  } else {
183
- const a = f(o, r, n), d = E(o, a);
184
- s.push(...d.errors);
183
+ const a = f(o, r, s), d = E(o, a);
184
+ i.push(...d.errors);
185
185
  }
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) => {
186
+ return { valid: i.length === 0, errors: i };
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, W = (e) => {
188
188
  let t = "";
189
189
  for (let r = 0; r < e.length; ) {
190
- const n = e[r];
191
- if (n === void 0) break;
192
- if (H.has(n)) {
193
- let i = 1;
194
- for (; e[r + i] === n; )
195
- i += 1;
196
- t += `\\d{${i}}`, r += i;
190
+ const s = e[r];
191
+ if (s === void 0) break;
192
+ if (G.has(s)) {
193
+ let n = 1;
194
+ for (; e[r + n] === s; )
195
+ n += 1;
196
+ t += `\\d{${n}}`, r += n;
197
197
  continue;
198
198
  }
199
- t += q(n), r += 1;
199
+ t += Y(s), r += 1;
200
200
  }
201
201
  return t;
202
202
  }, ge = (e, t) => {
203
203
  const r = e.trim();
204
204
  return r ? new RegExp(`^(?:${W(r)})$`).test(t) : !0;
205
- }, O = /^(\d{4})-(\d{2})-(\d{2})$/, me = (e) => O.test(e), X = (e, t) => {
206
- const r = O.exec(e), n = t == null ? void 0 : t.trim();
207
- if (!r || !n) return e;
208
- const [, i = "", s = "", o = ""] = r;
205
+ }, O = /^(\d{4})-(\d{2})-(\d{2})$/, pe = (e) => O.test(e), X = (e, t) => {
206
+ const r = O.exec(e), s = t == null ? void 0 : t.trim();
207
+ if (!r || !s) return e;
208
+ const [, n = "", i = "", o = ""] = r;
209
209
  let a = "";
210
- for (let d = 0; d < n.length; ) {
211
- const c = n[d];
210
+ for (let d = 0; d < s.length; ) {
211
+ const c = s[d];
212
212
  if (c === void 0) break;
213
213
  let h = 1;
214
- for (; n[d + h] === c; )
214
+ for (; s[d + h] === c; )
215
215
  h += 1;
216
216
  if (c === "y" || c === "Y") {
217
- a += h === 2 ? i.slice(-2) : i.padStart(h, "0"), d += h;
217
+ a += h === 2 ? n.slice(-2) : n.padStart(h, "0"), d += h;
218
218
  continue;
219
219
  }
220
220
  if (c === "M" || c === "m") {
221
- a += h === 1 ? String(Number(s)) : s.padStart(h, "0"), d += h;
221
+ a += h === 1 ? String(Number(i)) : i.padStart(h, "0"), d += h;
222
222
  continue;
223
223
  }
224
224
  if (c === "d" || c === "D") {
@@ -232,10 +232,10 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
232
232
  const t = /* @__PURE__ */ new Map();
233
233
  for (const r of e) {
234
234
  if (!r.sharedKey || r.sharedMode !== "source") continue;
235
- const n = t.get(r.sharedKey);
236
- if (n !== void 0)
235
+ const s = t.get(r.sharedKey);
236
+ if (s !== void 0)
237
237
  throw new Error(
238
- `Shared key "${r.sharedKey}" allows only one source field. (Conflict: "${n}" vs "${r.id}")`
238
+ `Shared key "${r.sharedKey}" allows only one source field. (Conflict: "${s}" vs "${r.id}")`
239
239
  );
240
240
  t.set(r.sharedKey, r.id);
241
241
  }
@@ -261,11 +261,11 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
261
261
  }
262
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.disabled !== void 0 && (e.disabled ?? !1) !== t.disabled || t.sharedKey !== void 0 && e.sharedKey !== t.sharedKey || t.sharedMode !== void 0 && e.sharedMode !== t.sharedMode), D = (e, t) => {
263
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);
264
+ if (!(e.type === "checkbox" || e.type === "signature" && e.signatureMode === "stamp-only")) return r;
265
+ const n = t.pages.find((o) => o.index === r.page);
266
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);
267
+ const o = Math.min(r.width, r.height);
268
+ return y({ ...r, width: o, height: o }, t.pageCount);
269
269
  }
270
270
  const i = Math.min(
271
271
  r.width * n.width,
@@ -286,11 +286,11 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
286
286
  sharedValues: {},
287
287
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
288
288
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
289
- }), ee = async (e) => (await v.load(e)).getPages().map((r, n) => ({
290
- index: n,
289
+ }), ee = async (e) => (await v.load(e)).getPages().map((r, s) => ({
290
+ index: s,
291
291
  width: r.getWidth(),
292
292
  height: r.getHeight()
293
- })), pe = async (e) => {
293
+ })), me = async (e) => {
294
294
  const t = await ee(e.pdfData);
295
295
  return Z({
296
296
  ...e,
@@ -299,73 +299,73 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
299
299
  });
300
300
  }, ye = (e, t) => {
301
301
  B(e.fields, t.id);
302
- const r = D(t, e), n = { ...t, ...r }, i = [...e.fields, n];
303
- return _(i), {
302
+ const r = D(t, e), s = { ...t, ...r }, n = [...e.fields, s];
303
+ return _(n), {
304
304
  ...e,
305
- fields: i,
305
+ fields: n,
306
306
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
307
307
  };
308
308
  }, P = (e, t, r) => {
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 };
309
+ const s = e.fields.map((n) => {
310
+ if (n.id !== t) return n;
311
+ const i = { ...n, ...r }, o = D(i, e);
312
+ return { ...i, ...o };
313
313
  });
314
- return _(n), {
314
+ return _(s), {
315
315
  ...e,
316
- fields: n,
316
+ fields: s,
317
317
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
318
318
  };
319
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(
320
+ const r = e.fields.find((o) => o.id === t), s = e.fields.filter((o) => o.id !== t), n = Object.fromEntries(
321
321
  Object.entries(e.fieldValues).filter(([o]) => o !== t)
322
322
  );
323
- let { sharedValues: s } = e;
324
- return r != null && r.sharedKey && r.sharedMode === "source" && (n.some(
323
+ let { sharedValues: i } = e;
324
+ return r != null && r.sharedKey && r.sharedMode === "source" && (s.some(
325
325
  (a) => a.sharedKey === r.sharedKey && a.sharedMode === "source"
326
- ) || (s = Object.fromEntries(
327
- Object.entries(s).filter(([a]) => a !== r.sharedKey)
326
+ ) || (i = Object.fromEntries(
327
+ Object.entries(i).filter(([a]) => a !== r.sharedKey)
328
328
  ))), {
329
329
  ...e,
330
- fields: n,
331
- fieldValues: i,
332
- sharedValues: s,
330
+ fields: s,
331
+ fieldValues: n,
332
+ sharedValues: i,
333
333
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
334
334
  };
335
335
  }, xe = (e, t, r) => {
336
- const { page: n, x: i, y: s } = r;
336
+ const { page: s, x: n, y: i } = r;
337
337
  return P(
338
338
  e,
339
339
  t,
340
- n !== void 0 ? { page: n, x: i, y: s } : { x: i, y: s }
340
+ s !== void 0 ? { page: s, x: n, y: i } : { x: n, y: i }
341
341
  );
342
342
  }, Me = (e, t, r) => P(e, t, {
343
343
  width: r.width,
344
344
  height: r.height
345
345
  }), Se = (e, t, r) => {
346
- const n = e.fields.find((i) => i.id === t);
347
- if (!n)
346
+ const s = e.fields.find((n) => n.id === t);
347
+ if (!s)
348
348
  throw new Error(`Field ID "${t}" was not found.`);
349
- if (n.sharedMode === "mirror")
349
+ if (s.sharedMode === "mirror")
350
350
  throw new Error(
351
351
  `Cannot set value on mirror field "${t}". Set the value on the source field instead.`
352
352
  );
353
- if (n.readonly)
353
+ if (s.readonly)
354
354
  throw new Error(`Cannot set value on read-only field "${t}".`);
355
- if (!J(n, r))
355
+ if (!J(s, r))
356
356
  throw new Error(
357
- `Value for field "${t}" is incompatible with field type "${n.type}".`
357
+ `Value for field "${t}" is incompatible with field type "${s.type}".`
358
358
  );
359
- if (n.sharedKey && n.sharedMode === "source") {
360
- const i = j(
359
+ if (s.sharedKey && s.sharedMode === "source") {
360
+ const n = j(
361
361
  e.fields,
362
362
  e.sharedValues,
363
- n.sharedKey,
363
+ s.sharedKey,
364
364
  r
365
365
  );
366
366
  return {
367
367
  ...e,
368
- sharedValues: i,
368
+ sharedValues: n,
369
369
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
370
370
  };
371
371
  }
@@ -378,7 +378,7 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
378
378
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
379
379
  };
380
380
  }, Ee = (e, t) => {
381
- const r = e.fields.find((s) => s.id === t);
381
+ const r = e.fields.find((i) => i.id === t);
382
382
  if (!r)
383
383
  throw new Error(`Field ID "${t}" was not found.`);
384
384
  if (r.sharedMode === "mirror")
@@ -388,129 +388,129 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
388
388
  if (r.readonly)
389
389
  throw new Error(`Cannot clear value on read-only field "${t}".`);
390
390
  if (r.sharedKey && r.sharedMode === "source") {
391
- const { [r.sharedKey]: s, ...o } = e.sharedValues;
391
+ const { [r.sharedKey]: i, ...o } = e.sharedValues;
392
392
  return {
393
393
  ...e,
394
394
  sharedValues: o,
395
395
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
396
396
  };
397
397
  }
398
- const { [t]: n, ...i } = e.fieldValues;
398
+ const { [t]: s, ...n } = e.fieldValues;
399
399
  return {
400
400
  ...e,
401
- fieldValues: i,
401
+ fieldValues: n,
402
402
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
403
403
  };
404
404
  }, Fe = (e, t) => {
405
- const r = e.fields.find((n) => n.id === t);
405
+ const r = e.fields.find((s) => s.id === t);
406
406
  return r ? { ...r } : void 0;
407
407
  }, be = (e, t = {}) => e.fields.filter((r) => Q(r, t)).map((r) => ({ ...r })), Ae = (e, t) => {
408
- const r = e.fields.find((n) => n.id === t);
408
+ const r = e.fields.find((s) => s.id === t);
409
409
  if (r)
410
410
  return f(r, e.fieldValues, e.sharedValues);
411
411
  };
412
412
  function Ve(e, t = {}) {
413
413
  const r = {};
414
- for (const n of e.fields) {
415
- const i = f(
416
- n,
414
+ for (const s of e.fields) {
415
+ const n = f(
416
+ s,
417
417
  e.fieldValues,
418
418
  e.sharedValues
419
419
  );
420
- (i !== void 0 || t.includeEmpty) && (r[n.id] = i);
420
+ (n !== void 0 || t.includeEmpty) && (r[s.id] = n);
421
421
  }
422
422
  return r;
423
423
  }
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);
424
+ const te = (e, t, r, s, n, i) => {
425
+ const a = Math.max(0, i - 4), d = Math.min(r.widthOfTextAtSize(t, s), a);
426
426
  switch (e.textAlign) {
427
427
  case "center":
428
- return i + (s - d) / 2;
428
+ return n + (i - d) / 2;
429
429
  case "right":
430
- return i + s - 2 - d;
430
+ return n + i - 2 - d;
431
431
  case "left":
432
432
  default:
433
- return i + 2;
433
+ return n + 2;
434
434
  }
435
435
  }, re = (e) => ({
436
436
  width: e.getWidth(),
437
437
  height: e.getHeight()
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);
438
+ }), I = (e, t, r, s, n) => {
439
+ const i = S(t, n.width, n.height), o = t.textSize ?? 10, a = n.height - i.y - i.height / 2 - o / 2, d = te(t, r, s, o, i.x, i.width);
440
440
  e.drawText(r, {
441
441
  x: d,
442
442
  y: Math.max(0, a),
443
443
  size: o,
444
- font: n,
444
+ font: s,
445
445
  color: w(0, 0, 0),
446
- maxWidth: s.width - 4
446
+ maxWidth: i.width - 4
447
447
  });
448
- }, ne = (e, t, r, n) => {
448
+ }, se = (e, t, r, s) => {
449
449
  if (!r) return;
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);
450
+ const n = S(t, s.width, s.height), i = Math.min(n.width, n.height), o = {
451
+ ...n,
452
+ x: n.x + (n.width - i) / 2,
453
+ y: n.y + (n.height - i) / 2
454
+ }, a = s.height - o.y - i, d = Math.max(1.2, i * 0.11);
455
455
  e.drawLine({
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 },
456
+ start: { x: o.x + i * 0.22, y: a + i * 0.49 },
457
+ end: { x: o.x + i * 0.42, y: a + i * 0.31 },
458
458
  thickness: d,
459
459
  color: w(0, 0, 0)
460
460
  }), e.drawLine({
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 },
461
+ start: { x: o.x + i * 0.42, y: a + i * 0.31 },
462
+ end: { x: o.x + i * 0.78, y: a + i * 0.68 },
463
463
  thickness: d,
464
464
  color: w(0, 0, 0)
465
465
  });
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 = T(
468
- i !== void 0 ? {
469
- image: n,
470
- mimeType: i
466
+ }, ne = async (e, t, r, s, n, i) => {
467
+ const o = S(r, i.width, i.height), a = i.height - o.y - o.height, d = T(
468
+ n !== void 0 ? {
469
+ image: s,
470
+ mimeType: n
471
471
  } : {
472
- image: n
472
+ image: s
473
473
  }
474
474
  );
475
475
  if (d === void 0)
476
476
  throw new Error(
477
477
  `Field "${r.id}" contains an unsupported signature image format for PDF export.`
478
478
  );
479
- const h = d === "image/jpeg" ? await t.embedJpg(n) : await t.embedPng(n);
479
+ const h = d === "image/jpeg" ? await t.embedJpg(s) : await t.embedPng(s);
480
480
  e.drawImage(h, {
481
481
  x: o.x,
482
482
  y: Math.max(0, a),
483
483
  width: o.width,
484
484
  height: o.height
485
485
  });
486
- }, ie = async (e, t, r, n, i, s) => {
487
- if (!(n === void 0 || r.hidden)) {
488
- if (g(n)) {
489
- await se(
486
+ }, ie = async (e, t, r, s, n, i) => {
487
+ if (!(s === void 0 || r.hidden)) {
488
+ if (g(s)) {
489
+ await ne(
490
490
  e,
491
491
  t,
492
492
  r,
493
- n.image,
494
- n.mimeType,
495
- s
493
+ s.image,
494
+ s.mimeType,
495
+ i
496
496
  );
497
497
  return;
498
498
  }
499
- if (typeof n == "boolean") {
500
- r.type === "checkbox" && ne(e, r, n, s);
499
+ if (typeof s == "boolean") {
500
+ r.type === "checkbox" && se(e, r, s, i);
501
501
  return;
502
502
  }
503
- if (typeof n == "string" && n.trim() !== "") {
503
+ if (typeof s == "string" && s.trim() !== "") {
504
504
  I(
505
505
  e,
506
506
  r,
507
- r.type === "date" ? X(n, r.dateFormat) : n,
508
- i,
509
- s
507
+ r.type === "date" ? X(s, r.dateFormat) : s,
508
+ n,
509
+ i
510
510
  );
511
511
  return;
512
512
  }
513
- typeof n == "number" && I(e, r, String(n), i, s);
513
+ typeof s == "number" && I(e, r, String(s), n, i);
514
514
  }
515
515
  }, oe = (e) => {
516
516
  if (!(e.byteLength > 0))
@@ -520,26 +520,26 @@ const te = (e, t, r, n, i, s) => {
520
520
  }, Ie = async (e, t = {}) => {
521
521
  var o;
522
522
  oe(e.pdfData);
523
- const r = await v.load(e.pdfData), n = await r.embedFont(N.Helvetica), i = r.getPages(), s = /* @__PURE__ */ new Map();
523
+ const r = await v.load(e.pdfData), s = await r.embedFont(N.Helvetica), n = r.getPages(), i = /* @__PURE__ */ new Map();
524
524
  for (const a of e.fields) {
525
- const d = s.get(a.page) ?? [];
526
- s.set(a.page, [...d, a]);
525
+ const d = i.get(a.page) ?? [];
526
+ i.set(a.page, [...d, a]);
527
527
  }
528
- for (const [a, d] of s) {
529
- const c = i[a];
528
+ for (const [a, d] of i) {
529
+ const c = n[a];
530
530
  if (!c) continue;
531
531
  const h = re(c);
532
- for (const m of d) {
532
+ for (const p of d) {
533
533
  const F = f(
534
- m,
534
+ p,
535
535
  e.fieldValues,
536
536
  e.sharedValues
537
- ), b = E(m, F);
537
+ ), b = E(p, F);
538
538
  if (!b.valid)
539
539
  throw new Error(
540
- `Field "${m.id}" is invalid for PDF export: ${((o = b.errors[0]) == null ? void 0 : o.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."}`
541
541
  );
542
- await ie(c, r, m, F, n, h);
542
+ await ie(c, r, p, F, s, h);
543
543
  }
544
544
  }
545
545
  return r.save();
@@ -549,10 +549,10 @@ export {
549
549
  k as clampToPage,
550
550
  Ee as clearFieldValue,
551
551
  Z as createDocument,
552
- pe as createDocumentFromPdfData,
552
+ me as createDocumentFromPdfData,
553
553
  ye as createField,
554
554
  W as dateFormatToRegexPattern,
555
- p as ensureMinSize,
555
+ m as ensureMinSize,
556
556
  Ie as exportToPdf,
557
557
  X as formatDateValue,
558
558
  Fe as getField,
@@ -562,7 +562,7 @@ export {
562
562
  Ae as getResolvedFieldValue,
563
563
  Ve as getResolvedValues,
564
564
  ce as getSourceField,
565
- me as isIsoDateString,
565
+ pe as isIsoDateString,
566
566
  de as isPrimitiveValue,
567
567
  g as isSignatureValue,
568
568
  ge as matchesDateFormat,
@@ -579,6 +579,6 @@ export {
579
579
  P as updateField,
580
580
  fe as validateDocument,
581
581
  E as validateField,
582
- G as validateSharedFieldGroup
582
+ q as validateSharedFieldGroup
583
583
  };
584
584
  //# sourceMappingURL=index.js.map