@promr-acorda/core 0.1.0 → 0.1.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/export/index.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +224 -200
- package/dist/index.js.map +1 -1
- package/dist/operations/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import { PDFDocument as
|
|
2
|
-
const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type === "signature",
|
|
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
|
-
},
|
|
5
|
+
}, $ = /* @__PURE__ */ new Set([
|
|
6
6
|
"image/png",
|
|
7
7
|
"image/jpeg",
|
|
8
8
|
"image/jpg"
|
|
9
|
-
]),
|
|
9
|
+
]), C = (e) => {
|
|
10
10
|
const t = e == null ? void 0 : e.trim().toLowerCase();
|
|
11
|
-
if (t &&
|
|
11
|
+
if (t && $.has(t))
|
|
12
12
|
return t === "image/jpg" ? "image/jpeg" : t;
|
|
13
|
-
},
|
|
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
|
-
},
|
|
19
|
-
const t =
|
|
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,
|
|
23
|
-
const r =
|
|
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:
|
|
28
|
-
width:
|
|
29
|
-
height:
|
|
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
|
-
}),
|
|
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"),
|
|
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
|
|
45
|
-
if (
|
|
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
|
|
50
|
-
return
|
|
51
|
-
},
|
|
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
|
-
(
|
|
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
|
-
},
|
|
59
|
+
}, ue = (e, t, r) => {
|
|
60
60
|
const n = Object.fromEntries(
|
|
61
|
-
Object.entries(t).map(([
|
|
62
|
-
|
|
63
|
-
u(
|
|
61
|
+
Object.entries(t).map(([i, s]) => [
|
|
62
|
+
i,
|
|
63
|
+
u(s)
|
|
64
64
|
])
|
|
65
65
|
);
|
|
66
|
-
for (const
|
|
67
|
-
const
|
|
68
|
-
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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 (!
|
|
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
|
-
),
|
|
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
|
-
},
|
|
153
|
-
const
|
|
154
|
-
if (!
|
|
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
|
|
167
|
-
return
|
|
168
|
-
},
|
|
169
|
-
const { fields: t, fieldValues: r, sharedValues: n } = e,
|
|
170
|
-
for (const
|
|
171
|
-
if (
|
|
172
|
-
if (
|
|
173
|
-
if (
|
|
174
|
-
|
|
175
|
-
const a =
|
|
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
|
-
|
|
179
|
+
o.sharedKey
|
|
180
180
|
);
|
|
181
|
-
|
|
181
|
+
s.push(...a.errors);
|
|
182
182
|
} else {
|
|
183
|
-
const a = f(
|
|
184
|
-
|
|
183
|
+
const a = f(o, r, n), d = E(o, a);
|
|
184
|
+
s.push(...d.errors);
|
|
185
185
|
}
|
|
186
|
-
return { valid:
|
|
187
|
-
},
|
|
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 (
|
|
193
|
-
let
|
|
194
|
-
for (; e[r +
|
|
195
|
-
|
|
196
|
-
t += `\\d{${
|
|
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 +=
|
|
199
|
+
t += q(n), r += 1;
|
|
200
200
|
}
|
|
201
201
|
return t;
|
|
202
|
-
},
|
|
202
|
+
}, ge = (e, t) => {
|
|
203
203
|
const r = e.trim();
|
|
204
|
-
return r ? new RegExp(`^(?:${
|
|
205
|
-
}, O = /^(\d{4})-(\d{2})-(\d{2})$/,
|
|
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 [,
|
|
208
|
+
const [, i = "", s = "", o = ""] = r;
|
|
209
209
|
let a = "";
|
|
210
210
|
for (let d = 0; d < n.length; ) {
|
|
211
|
-
const
|
|
212
|
-
if (
|
|
213
|
-
let
|
|
214
|
-
for (; n[d +
|
|
215
|
-
|
|
216
|
-
if (
|
|
217
|
-
a +=
|
|
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 (
|
|
221
|
-
a +=
|
|
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 (
|
|
225
|
-
a +=
|
|
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 +=
|
|
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
|
-
},
|
|
242
|
+
}, B = (e, t) => {
|
|
243
243
|
if (e.some((r) => r.id === t))
|
|
244
244
|
throw new Error(`Field ID "${t}" already exists.`);
|
|
245
|
-
},
|
|
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) &&
|
|
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
|
-
},
|
|
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
|
-
}),
|
|
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
|
-
})),
|
|
274
|
-
const t = await
|
|
275
|
-
return
|
|
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
|
-
},
|
|
281
|
-
|
|
282
|
-
const r =
|
|
283
|
-
return _(
|
|
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:
|
|
305
|
+
fields: i,
|
|
286
306
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
287
307
|
};
|
|
288
308
|
}, P = (e, t, r) => {
|
|
289
|
-
const n = e.fields.map((
|
|
290
|
-
if (
|
|
291
|
-
const
|
|
292
|
-
return { ...
|
|
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
|
-
},
|
|
300
|
-
const r = e.fields.find((
|
|
301
|
-
Object.entries(e.fieldValues).filter(([
|
|
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:
|
|
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
|
-
) || (
|
|
307
|
-
Object.entries(
|
|
326
|
+
) || (s = Object.fromEntries(
|
|
327
|
+
Object.entries(s).filter(([a]) => a !== r.sharedKey)
|
|
308
328
|
))), {
|
|
309
329
|
...e,
|
|
310
330
|
fields: n,
|
|
311
|
-
fieldValues:
|
|
312
|
-
sharedValues:
|
|
331
|
+
fieldValues: i,
|
|
332
|
+
sharedValues: s,
|
|
313
333
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
314
334
|
};
|
|
315
|
-
},
|
|
316
|
-
const { page: n, x:
|
|
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:
|
|
340
|
+
n !== void 0 ? { page: n, x: i, y: s } : { x: i, y: s }
|
|
321
341
|
);
|
|
322
|
-
},
|
|
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((
|
|
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 (!
|
|
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
|
|
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:
|
|
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
|
-
},
|
|
361
|
-
const r = e.fields.find((
|
|
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]:
|
|
391
|
+
const { [r.sharedKey]: s, ...o } = e.sharedValues;
|
|
372
392
|
return {
|
|
373
393
|
...e,
|
|
374
|
-
sharedValues:
|
|
394
|
+
sharedValues: o,
|
|
375
395
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
376
396
|
};
|
|
377
397
|
}
|
|
378
|
-
const { [t]: n, ...
|
|
398
|
+
const { [t]: n, ...i } = e.fieldValues;
|
|
379
399
|
return {
|
|
380
400
|
...e,
|
|
381
|
-
fieldValues:
|
|
401
|
+
fieldValues: i,
|
|
382
402
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
383
403
|
};
|
|
384
|
-
},
|
|
404
|
+
}, Fe = (e, t) => {
|
|
385
405
|
const r = e.fields.find((n) => n.id === t);
|
|
386
406
|
return r ? { ...r } : void 0;
|
|
387
|
-
},
|
|
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
|
|
415
|
+
const i = f(
|
|
396
416
|
n,
|
|
397
417
|
e.fieldValues,
|
|
398
418
|
e.sharedValues
|
|
399
419
|
);
|
|
400
|
-
(
|
|
420
|
+
(i !== void 0 || t.includeEmpty) && (r[n.id] = i);
|
|
401
421
|
}
|
|
402
422
|
return r;
|
|
403
423
|
}
|
|
404
|
-
const
|
|
405
|
-
const a = Math.max(0,
|
|
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
|
|
428
|
+
return i + (s - d) / 2;
|
|
409
429
|
case "right":
|
|
410
|
-
return
|
|
430
|
+
return i + s - 2 - d;
|
|
411
431
|
case "left":
|
|
412
432
|
default:
|
|
413
|
-
return
|
|
433
|
+
return i + 2;
|
|
414
434
|
}
|
|
415
|
-
},
|
|
435
|
+
}, re = (e) => ({
|
|
416
436
|
width: e.getWidth(),
|
|
417
437
|
height: e.getHeight()
|
|
418
|
-
}),
|
|
419
|
-
const
|
|
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:
|
|
443
|
+
size: o,
|
|
424
444
|
font: n,
|
|
425
|
-
color:
|
|
426
|
-
maxWidth:
|
|
445
|
+
color: w(0, 0, 0),
|
|
446
|
+
maxWidth: s.width - 4
|
|
427
447
|
});
|
|
428
|
-
},
|
|
448
|
+
}, ne = (e, t, r, n) => {
|
|
429
449
|
if (!r) return;
|
|
430
|
-
const
|
|
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:
|
|
433
|
-
end: { x: o, y:
|
|
434
|
-
thickness:
|
|
435
|
-
color:
|
|
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:
|
|
438
|
-
end: { x:
|
|
439
|
-
thickness:
|
|
440
|
-
color:
|
|
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
|
-
},
|
|
443
|
-
const
|
|
444
|
-
|
|
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:
|
|
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
|
|
456
|
-
e.drawImage(
|
|
457
|
-
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:
|
|
460
|
-
height:
|
|
483
|
+
width: o.width,
|
|
484
|
+
height: o.height
|
|
461
485
|
});
|
|
462
|
-
},
|
|
486
|
+
}, ie = async (e, t, r, n, i, s) => {
|
|
463
487
|
if (!(n === void 0 || r.hidden)) {
|
|
464
488
|
if (g(n)) {
|
|
465
|
-
await
|
|
489
|
+
await se(
|
|
466
490
|
e,
|
|
467
491
|
t,
|
|
468
492
|
r,
|
|
469
493
|
n.image,
|
|
470
494
|
n.mimeType,
|
|
471
|
-
|
|
495
|
+
s
|
|
472
496
|
);
|
|
473
497
|
return;
|
|
474
498
|
}
|
|
475
499
|
if (typeof n == "boolean") {
|
|
476
|
-
r.type === "checkbox" &&
|
|
500
|
+
r.type === "checkbox" && ne(e, r, n, s);
|
|
477
501
|
return;
|
|
478
502
|
}
|
|
479
503
|
if (typeof n == "string" && n.trim() !== "") {
|
|
480
|
-
|
|
504
|
+
I(
|
|
481
505
|
e,
|
|
482
506
|
r,
|
|
483
507
|
r.type === "date" ? X(n, r.dateFormat) : n,
|
|
484
|
-
|
|
485
|
-
|
|
508
|
+
i,
|
|
509
|
+
s
|
|
486
510
|
);
|
|
487
511
|
return;
|
|
488
512
|
}
|
|
489
|
-
typeof n == "number" &&
|
|
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
|
-
},
|
|
497
|
-
var
|
|
520
|
+
}, Ie = async (e, t = {}) => {
|
|
521
|
+
var o;
|
|
498
522
|
oe(e.pdfData);
|
|
499
|
-
const r = await
|
|
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 =
|
|
502
|
-
|
|
525
|
+
const d = s.get(a.page) ?? [];
|
|
526
|
+
s.set(a.page, [...d, a]);
|
|
503
527
|
}
|
|
504
|
-
for (const [a, d] of
|
|
505
|
-
const
|
|
506
|
-
if (!
|
|
507
|
-
const
|
|
508
|
-
for (const
|
|
509
|
-
const
|
|
510
|
-
|
|
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
|
-
),
|
|
514
|
-
if (!
|
|
537
|
+
), b = E(p, F);
|
|
538
|
+
if (!b.valid)
|
|
515
539
|
throw new Error(
|
|
516
|
-
`Field "${
|
|
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
|
|
542
|
+
await ie(c, r, p, F, n, h);
|
|
519
543
|
}
|
|
520
544
|
}
|
|
521
545
|
return r.save();
|
|
522
546
|
};
|
|
523
547
|
export {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
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
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
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
|
-
|
|
542
|
-
|
|
565
|
+
pe as isIsoDateString,
|
|
566
|
+
de as isPrimitiveValue,
|
|
543
567
|
g as isSignatureValue,
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
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
|
-
|
|
576
|
+
j as setSharedFieldValue,
|
|
553
577
|
S as toAbsoluteRect,
|
|
554
|
-
|
|
578
|
+
he as toNormalizedRect,
|
|
555
579
|
P as updateField,
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
580
|
+
fe as validateDocument,
|
|
581
|
+
E as validateField,
|
|
582
|
+
G as validateSharedFieldGroup
|
|
559
583
|
};
|
|
560
584
|
//# sourceMappingURL=index.js.map
|