@promr-acorda/core 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { PDFDocument as I, StandardFonts as N, rgb as p } from "pdf-lib";
2
- const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type === "signature", ie = (e) => typeof e != "object", S = (e) => Object.prototype.toString.call(e) === "[object Uint8Array]", u = (e) => !g(e) || !S(e.image) ? e : {
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 : {
3
3
  ...e,
4
4
  image: Uint8Array.from(e.image)
5
5
  }, D = /* @__PURE__ */ new Set([
@@ -15,85 +15,85 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
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
- }, v = (e) => {
18
+ }, T = (e) => {
19
19
  const t = C(e.image), r = $(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)), m = (e) => Math.max(K, e), T = (e, t) => {
23
- const r = L(e.page, t), s = b(e.x), n = b(e.y), o = m(e.width), i = m(e.height), a = Math.min(o, w - s), d = Math.min(i, w - n);
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);
24
24
  return {
25
25
  page: r,
26
- x: s,
27
- y: n,
28
- width: m(a),
29
- height: m(d)
26
+ x: n,
27
+ y: s,
28
+ width: p(a),
29
+ height: p(d)
30
30
  };
31
- }, M = (e, t, r) => ({
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
- }), ae = (e, t, r) => ({
36
+ }), de = (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
- }), de = (e, t) => e.find((r) => r.sharedKey === t && r.sharedMode === "source"), ce = (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"), he = (e, t) => e.filter((r) => r.sharedKey === t && r.sharedMode === "mirror"), f = (e, t, r) => {
43
43
  if (e.sharedKey) {
44
44
  const o = r[e.sharedKey];
45
45
  if (o !== void 0) return u(o);
46
46
  }
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
- }, k = (e, t, r, s) => {
47
+ const n = t[e.id];
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) => {
52
52
  if (!e.some(
53
53
  (o) => o.sharedKey === r && o.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(s) };
59
- }, he = (e, t, r) => {
60
- const s = Object.fromEntries(
61
- Object.entries(t).map(([n, o]) => [
62
- n,
58
+ return { ...t, [r]: u(n) };
59
+ }, le = (e, t, r) => {
60
+ const n = Object.fromEntries(
61
+ Object.entries(t).map(([s, o]) => [
62
+ s,
63
63
  u(o)
64
64
  ])
65
65
  );
66
- for (const n of e) {
67
- const o = f(n, t, r);
68
- o !== void 0 && (s[n.id] = o);
66
+ for (const s of e) {
67
+ const o = f(s, t, r);
68
+ o !== void 0 && (n[s.id] = o);
69
69
  }
70
- return s;
70
+ return n;
71
71
  }, V = 5 * 1024 * 1024, l = (e, t, r) => {
72
- var s;
72
+ var n;
73
73
  return {
74
74
  fieldId: e.id,
75
75
  fieldName: e.name,
76
- message: ((s = e.validation) == null ? void 0 : s.customMessage) ?? t,
76
+ message: ((n = e.validation) == null ? void 0 : n.customMessage) ?? t,
77
77
  code: r
78
78
  };
79
79
  }, j = (e, t) => {
80
- const r = [], { validation: s } = e;
81
- if (!s) return r;
82
- if (s.minLength !== void 0 && t.length < s.minLength && r.push(
80
+ const r = [], { validation: n } = e;
81
+ if (!n) return r;
82
+ if (n.minLength !== void 0 && t.length < n.minLength && r.push(
83
83
  l(
84
84
  e,
85
- `Must be at least ${s.minLength} characters.`,
85
+ `Must be at least ${n.minLength} characters.`,
86
86
  "MIN_LENGTH"
87
87
  )
88
- ), s.maxLength !== void 0 && t.length > s.maxLength && r.push(
88
+ ), n.maxLength !== void 0 && t.length > n.maxLength && r.push(
89
89
  l(
90
90
  e,
91
- `Must be at most ${s.maxLength} characters.`,
91
+ `Must be at most ${n.maxLength} characters.`,
92
92
  "MAX_LENGTH"
93
93
  )
94
- ), s.pattern !== void 0)
94
+ ), n.pattern !== void 0)
95
95
  try {
96
- new RegExp(s.pattern).test(t) || r.push(
96
+ new RegExp(n.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
  }, z = (e, t) => {
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")
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")
119
119
  ), r;
120
- }, x = (e, t) => {
120
+ }, M = (e, t) => {
121
121
  if (e.sharedMode === "mirror")
122
122
  return { valid: !0, errors: [] };
123
- const r = [], s = t === void 0 || t === "" || t === null || typeof t == "boolean" && !t && e.type !== "checkbox";
124
- if (e.required && s)
123
+ const r = [], n = t === void 0 || t === "" || t === null || typeof t == "boolean" && !t && e.type !== "checkbox";
124
+ if (e.required && n)
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: [] };
@@ -132,7 +132,7 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
132
132
  else if (typeof t == "number")
133
133
  r.push(...z(e, t));
134
134
  else if (g(t)) {
135
- if (!S(t.image) || t.image.length === 0)
135
+ if (!x(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
- ), v(t) === void 0 && r.push(
143
+ ), T(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,72 +149,72 @@ 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, s) => {
153
- const o = e.filter((a) => a.sharedKey === s).find((a) => a.sharedMode === "source");
152
+ }, U = (e, t, r, n) => {
153
+ const o = e.filter((a) => a.sharedKey === n).find((a) => a.sharedMode === "source");
154
154
  if (!o)
155
155
  return {
156
156
  valid: !1,
157
157
  errors: [
158
158
  {
159
- fieldId: s,
160
- fieldName: s,
161
- message: `No source field found for shared key "${s}".`,
159
+ fieldId: n,
160
+ fieldName: n,
161
+ message: `No source field found for shared key "${n}".`,
162
162
  code: "SHARED_SOURCE_NOT_FOUND"
163
163
  }
164
164
  ]
165
165
  };
166
166
  const i = f(o, t, r);
167
- return x(o, i);
168
- }, le = (e) => {
169
- const { fields: t, fieldValues: r, sharedValues: s } = e, n = /* @__PURE__ */ new Set(), o = [];
167
+ return M(o, i);
168
+ }, ue = (e) => {
169
+ const { fields: t, fieldValues: r, sharedValues: n } = e, s = /* @__PURE__ */ new Set(), o = [];
170
170
  for (const i of t)
171
171
  if (i.sharedMode !== "mirror")
172
172
  if (i.sharedKey) {
173
- if (n.has(i.sharedKey)) continue;
174
- n.add(i.sharedKey);
173
+ if (s.has(i.sharedKey)) continue;
174
+ s.add(i.sharedKey);
175
175
  const a = U(
176
176
  t,
177
177
  r,
178
- s,
178
+ n,
179
179
  i.sharedKey
180
180
  );
181
181
  o.push(...a.errors);
182
182
  } else {
183
- const a = f(i, r, s), d = x(i, a);
183
+ const a = f(i, r, n), d = M(i, a);
184
184
  o.push(...d.errors);
185
185
  }
186
186
  return { valid: o.length === 0, errors: o };
187
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) => {
188
188
  let t = "";
189
189
  for (let r = 0; r < e.length; ) {
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;
190
+ const n = e[r];
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;
197
197
  continue;
198
198
  }
199
- t += Y(s), r += 1;
199
+ t += Y(n), r += 1;
200
200
  }
201
201
  return t;
202
- }, ue = (e, t) => {
202
+ }, fe = (e, t) => {
203
203
  const r = e.trim();
204
204
  return r ? new RegExp(`^(?:${q(r)})$`).test(t) : !0;
205
- }, O = /^(\d{4})-(\d{2})-(\d{2})$/, fe = (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 = "", o = "", i = ""] = r;
205
+ }, O = /^(\d{4})-(\d{2})-(\d{2})$/, ge = (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 [, s = "", o = "", i = ""] = r;
209
209
  let a = "";
210
- for (let d = 0; d < s.length; ) {
211
- const h = s[d];
210
+ for (let d = 0; d < n.length; ) {
211
+ const h = n[d];
212
212
  if (h === void 0) break;
213
213
  let c = 1;
214
- for (; s[d + c] === h; )
214
+ for (; n[d + c] === h; )
215
215
  c += 1;
216
216
  if (h === "y" || h === "Y") {
217
- a += c === 2 ? n.slice(-2) : n.padStart(c, "0"), d += c;
217
+ a += c === 2 ? s.slice(-2) : s.padStart(c, "0"), d += c;
218
218
  continue;
219
219
  }
220
220
  if (h === "M" || h === "m") {
@@ -232,24 +232,24 @@ 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 s = t.get(r.sharedKey);
236
- if (s !== void 0)
235
+ const n = t.get(r.sharedKey);
236
+ if (n !== void 0)
237
237
  throw new Error(
238
- `Shared key "${r.sharedKey}" allows only one source field. (Conflict: "${s}" vs "${r.id}")`
238
+ `Shared key "${r.sharedKey}" allows only one source field. (Conflict: "${n}" vs "${r.id}")`
239
239
  );
240
240
  t.set(r.sharedKey, r.id);
241
241
  }
242
- }, B = (e, t) => {
242
+ }, W = (e, t) => {
243
243
  if (e.some((r) => r.id === t))
244
244
  throw new Error(`Field ID "${t}" already exists.`);
245
- }, J = (e, t) => {
245
+ }, B = (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) && S(t.image);
252
+ return g(t) && x(t.image);
253
253
  case "text":
254
254
  case "date":
255
255
  case "email":
@@ -259,93 +259,93 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
259
259
  default:
260
260
  return !1;
261
261
  }
262
- }, W = (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
+ }, 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) => ({
263
263
  ...e,
264
264
  fields: [],
265
265
  fieldValues: {},
266
266
  sharedValues: {},
267
267
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
268
268
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
269
- }), Z = async (e) => (await I.load(e)).getPages().map((r, s) => ({
270
- index: s,
269
+ }), Z = async (e) => (await I.load(e)).getPages().map((r, n) => ({
270
+ index: n,
271
271
  width: r.getWidth(),
272
272
  height: r.getHeight()
273
- })), ge = async (e) => {
273
+ })), ye = async (e) => {
274
274
  const t = await Z(e.pdfData);
275
275
  return Q({
276
276
  ...e,
277
277
  pageCount: t.length,
278
278
  pages: t
279
279
  });
280
- }, ye = (e, t) => {
281
- B(e.fields, t.id);
282
- const r = T(t, e.pageCount), s = { ...t, ...r }, n = [...e.fields, s];
283
- return _(n), {
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), {
284
284
  ...e,
285
- fields: n,
285
+ fields: s,
286
286
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
287
287
  };
288
288
  }, P = (e, t, r) => {
289
- const s = e.fields.map((n) => {
290
- if (n.id !== t) return n;
291
- const o = { ...n, ...r }, i = T(o, e.pageCount);
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
292
  return { ...o, ...i };
293
293
  });
294
- return _(s), {
294
+ return _(n), {
295
295
  ...e,
296
- fields: s,
296
+ fields: n,
297
297
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
298
298
  };
299
299
  }, me = (e, t) => {
300
- const r = e.fields.find((i) => i.id === t), s = e.fields.filter((i) => i.id !== t), n = Object.fromEntries(
300
+ const r = e.fields.find((i) => i.id === t), n = e.fields.filter((i) => i.id !== t), s = Object.fromEntries(
301
301
  Object.entries(e.fieldValues).filter(([i]) => i !== t)
302
302
  );
303
303
  let { sharedValues: o } = e;
304
- return r != null && r.sharedKey && r.sharedMode === "source" && (s.some(
304
+ return r != null && r.sharedKey && r.sharedMode === "source" && (n.some(
305
305
  (a) => a.sharedKey === r.sharedKey && a.sharedMode === "source"
306
306
  ) || (o = Object.fromEntries(
307
307
  Object.entries(o).filter(([a]) => a !== r.sharedKey)
308
308
  ))), {
309
309
  ...e,
310
- fields: s,
311
- fieldValues: n,
310
+ fields: n,
311
+ fieldValues: s,
312
312
  sharedValues: o,
313
313
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
314
314
  };
315
- }, pe = (e, t, r) => {
316
- const { page: s, x: n, y: o } = r;
315
+ }, we = (e, t, r) => {
316
+ const { page: n, x: s, y: o } = r;
317
317
  return P(
318
318
  e,
319
319
  t,
320
- s !== void 0 ? { page: s, x: n, y: o } : { x: n, y: o }
320
+ n !== void 0 ? { page: n, x: s, y: o } : { x: s, y: o }
321
321
  );
322
- }, we = (e, t, r) => P(e, t, {
322
+ }, xe = (e, t, r) => P(e, t, {
323
323
  width: r.width,
324
324
  height: r.height
325
325
  }), Se = (e, t, r) => {
326
- const s = e.fields.find((n) => n.id === t);
327
- if (!s)
326
+ const n = e.fields.find((s) => s.id === t);
327
+ if (!n)
328
328
  throw new Error(`Field ID "${t}" was not found.`);
329
- if (s.sharedMode === "mirror")
329
+ if (n.sharedMode === "mirror")
330
330
  throw new Error(
331
331
  `Cannot set value on mirror field "${t}". Set the value on the source field instead.`
332
332
  );
333
- if (s.readonly)
333
+ if (n.readonly)
334
334
  throw new Error(`Cannot set value on read-only field "${t}".`);
335
- if (!J(s, r))
335
+ if (!B(n, r))
336
336
  throw new Error(
337
- `Value for field "${t}" is incompatible with field type "${s.type}".`
337
+ `Value for field "${t}" is incompatible with field type "${n.type}".`
338
338
  );
339
- if (s.sharedKey && s.sharedMode === "source") {
340
- const n = k(
339
+ if (n.sharedKey && n.sharedMode === "source") {
340
+ const s = k(
341
341
  e.fields,
342
342
  e.sharedValues,
343
- s.sharedKey,
343
+ n.sharedKey,
344
344
  r
345
345
  );
346
346
  return {
347
347
  ...e,
348
- sharedValues: n,
348
+ sharedValues: s,
349
349
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
350
350
  };
351
351
  }
@@ -375,136 +375,147 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
375
375
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
376
376
  };
377
377
  }
378
- const { [t]: s, ...n } = e.fieldValues;
378
+ const { [t]: n, ...s } = e.fieldValues;
379
379
  return {
380
380
  ...e,
381
- fieldValues: n,
381
+ fieldValues: s,
382
382
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
383
383
  };
384
- }, xe = (e, t) => {
385
- const r = e.fields.find((s) => s.id === t);
384
+ }, Ee = (e, t) => {
385
+ const r = e.fields.find((n) => n.id === t);
386
386
  return r ? { ...r } : void 0;
387
- }, Ee = (e, t = {}) => e.fields.filter((r) => W(r, t)).map((r) => ({ ...r })), Fe = (e, t) => {
388
- const r = e.fields.find((s) => s.id === t);
387
+ }, Fe = (e, t = {}) => e.fields.filter((r) => J(r, t)).map((r) => ({ ...r })), be = (e, t) => {
388
+ const r = e.fields.find((n) => n.id === t);
389
389
  if (r)
390
390
  return f(r, e.fieldValues, e.sharedValues);
391
391
  };
392
- function be(e, t = {}) {
392
+ function Ve(e, t = {}) {
393
393
  const r = {};
394
- for (const s of e.fields) {
395
- const n = f(
396
- s,
394
+ for (const n of e.fields) {
395
+ const s = f(
396
+ n,
397
397
  e.fieldValues,
398
398
  e.sharedValues
399
399
  );
400
- (n !== void 0 || t.includeEmpty) && (r[s.id] = n);
400
+ (s !== void 0 || t.includeEmpty) && (r[n.id] = s);
401
401
  }
402
402
  return r;
403
403
  }
404
- const ee = (e) => ({
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);
406
+ switch (e.textAlign) {
407
+ case "center":
408
+ return s + (o - d) / 2;
409
+ case "right":
410
+ return s + o - 2 - d;
411
+ case "left":
412
+ default:
413
+ return s + 2;
414
+ }
415
+ }, te = (e) => ({
405
416
  width: e.getWidth(),
406
417
  height: e.getHeight()
407
- }), A = (e, t, r, s, n) => {
408
- const o = M(t, n.width, n.height), i = t.textSize ?? 10, a = n.height - o.y - o.height / 2 - i / 2;
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);
409
420
  e.drawText(r, {
410
- x: o.x + 2,
421
+ x: d,
411
422
  y: Math.max(0, a),
412
423
  size: i,
413
- font: s,
414
- color: p(0, 0, 0),
424
+ font: n,
425
+ color: m(0, 0, 0),
415
426
  maxWidth: o.width - 4
416
427
  });
417
- }, te = (e, t, r, s) => {
428
+ }, re = (e, t, r, n) => {
418
429
  if (!r) return;
419
- const n = M(t, s.width, s.height), o = n.x + n.width / 2, i = s.height - n.y - n.height / 2;
430
+ const s = S(t, n.width, n.height), o = s.x + s.width / 2, i = n.height - s.y - s.height / 2;
420
431
  e.drawLine({
421
- start: { x: n.x + 2, y: i },
422
- end: { x: o, y: s.height - n.y - n.height + 2 },
432
+ start: { x: s.x + 2, y: i },
433
+ end: { x: o, y: n.height - s.y - s.height + 2 },
423
434
  thickness: 1.5,
424
- color: p(0, 0, 0)
435
+ color: m(0, 0, 0)
425
436
  }), e.drawLine({
426
- start: { x: o, y: s.height - n.y - n.height + 2 },
427
- end: { x: n.x + n.width - 2, y: s.height - n.y - 2 },
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 },
428
439
  thickness: 1.5,
429
- color: p(0, 0, 0)
440
+ color: m(0, 0, 0)
430
441
  });
431
- }, re = async (e, t, r, s, n, o) => {
432
- const i = M(r, o.width, o.height), a = o.height - i.y - i.height, d = v(
433
- n !== void 0 ? {
434
- image: s,
435
- mimeType: n
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 ? {
445
+ image: n,
446
+ mimeType: s
436
447
  } : {
437
- image: s
448
+ image: n
438
449
  }
439
450
  );
440
451
  if (d === void 0)
441
452
  throw new Error(
442
453
  `Field "${r.id}" contains an unsupported signature image format for PDF export.`
443
454
  );
444
- const c = d === "image/jpeg" ? await t.embedJpg(s) : await t.embedPng(s);
455
+ const c = d === "image/jpeg" ? await t.embedJpg(n) : await t.embedPng(n);
445
456
  e.drawImage(c, {
446
457
  x: i.x,
447
458
  y: Math.max(0, a),
448
459
  width: i.width,
449
460
  height: i.height
450
461
  });
451
- }, se = async (e, t, r, s, n, o) => {
452
- if (!(s === void 0 || r.hidden)) {
453
- if (g(s)) {
454
- await re(
462
+ }, se = async (e, t, r, n, s, o) => {
463
+ if (!(n === void 0 || r.hidden)) {
464
+ if (g(n)) {
465
+ await ne(
455
466
  e,
456
467
  t,
457
468
  r,
458
- s.image,
459
- s.mimeType,
469
+ n.image,
470
+ n.mimeType,
460
471
  o
461
472
  );
462
473
  return;
463
474
  }
464
- if (typeof s == "boolean") {
465
- r.type === "checkbox" && te(e, r, s, o);
475
+ if (typeof n == "boolean") {
476
+ r.type === "checkbox" && re(e, r, n, o);
466
477
  return;
467
478
  }
468
- if (typeof s == "string" && s.trim() !== "") {
479
+ if (typeof n == "string" && n.trim() !== "") {
469
480
  A(
470
481
  e,
471
482
  r,
472
- r.type === "date" ? X(s, r.dateFormat) : s,
473
- n,
483
+ r.type === "date" ? X(n, r.dateFormat) : n,
484
+ s,
474
485
  o
475
486
  );
476
487
  return;
477
488
  }
478
- typeof s == "number" && A(e, r, String(s), n, o);
489
+ typeof n == "number" && A(e, r, String(n), s, o);
479
490
  }
480
- }, ne = (e) => {
491
+ }, oe = (e) => {
481
492
  if (!(e.byteLength > 0))
482
493
  throw new Error(
483
494
  "exportToPdf requires a non-empty source PDF in document.pdfData."
484
495
  );
485
- }, Ve = async (e, t = {}) => {
496
+ }, Ae = async (e, t = {}) => {
486
497
  var i;
487
- ne(e.pdfData);
488
- const r = await I.load(e.pdfData), s = await r.embedFont(N.Helvetica), n = r.getPages(), o = /* @__PURE__ */ new Map();
498
+ oe(e.pdfData);
499
+ const r = await I.load(e.pdfData), n = await r.embedFont(N.Helvetica), s = r.getPages(), o = /* @__PURE__ */ new Map();
489
500
  for (const a of e.fields) {
490
501
  const d = o.get(a.page) ?? [];
491
502
  o.set(a.page, [...d, a]);
492
503
  }
493
504
  for (const [a, d] of o) {
494
- const h = n[a];
505
+ const h = s[a];
495
506
  if (!h) continue;
496
- const c = ee(h);
507
+ const c = te(h);
497
508
  for (const y of d) {
498
509
  const E = f(
499
510
  y,
500
511
  e.fieldValues,
501
512
  e.sharedValues
502
- ), F = x(y, E);
513
+ ), F = M(y, E);
503
514
  if (!F.valid)
504
515
  throw new Error(
505
516
  `Field "${y.id}" is invalid for PDF export: ${((i = F.errors[0]) == null ? void 0 : i.message) ?? "Unknown validation error."}`
506
517
  );
507
- await se(h, r, y, E, s, c);
518
+ await se(h, r, y, E, n, c);
508
519
  }
509
520
  }
510
521
  return r.save();
@@ -514,36 +525,36 @@ export {
514
525
  L as clampToPage,
515
526
  Me as clearFieldValue,
516
527
  Q as createDocument,
517
- ge as createDocumentFromPdfData,
518
- ye as createField,
528
+ ye as createDocumentFromPdfData,
529
+ pe as createField,
519
530
  q as dateFormatToRegexPattern,
520
- m as ensureMinSize,
521
- Ve as exportToPdf,
531
+ p as ensureMinSize,
532
+ Ae as exportToPdf,
522
533
  X as formatDateValue,
523
- xe as getField,
524
- Ee as getFields,
525
- ce as getMirrorFields,
534
+ Ee as getField,
535
+ Fe as getFields,
536
+ he as getMirrorFields,
526
537
  Z as getPdfPageInfo,
527
- Fe as getResolvedFieldValue,
528
- be as getResolvedValues,
529
- de as getSourceField,
530
- fe as isIsoDateString,
531
- ie as isPrimitiveValue,
538
+ be as getResolvedFieldValue,
539
+ Ve as getResolvedValues,
540
+ ce as getSourceField,
541
+ ge as isIsoDateString,
542
+ ae as isPrimitiveValue,
532
543
  g as isSignatureValue,
533
- ue as matchesDateFormat,
534
- pe as moveField,
535
- T as normalizeRect,
544
+ fe as matchesDateFormat,
545
+ we as moveField,
546
+ v as normalizeRect,
536
547
  me as removeField,
537
- we as resizeField,
538
- he as resolveAllSharedValues,
548
+ xe as resizeField,
549
+ le as resolveAllSharedValues,
539
550
  f as resolveFieldValue,
540
551
  Se as setFieldValue,
541
552
  k as setSharedFieldValue,
542
- M as toAbsoluteRect,
543
- ae as toNormalizedRect,
553
+ S as toAbsoluteRect,
554
+ de as toNormalizedRect,
544
555
  P as updateField,
545
- le as validateDocument,
546
- x as validateField,
556
+ ue as validateDocument,
557
+ M as validateField,
547
558
  U as validateSharedFieldGroup
548
559
  };
549
560
  //# sourceMappingURL=index.js.map