@promr-acorda/core 0.0.1 → 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.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +288 -253
- package/dist/index.js.map +1 -1
- package/dist/operations/index.d.ts.map +1 -1
- package/dist/types/field.d.ts +2 -0
- package/dist/types/field.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
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
18
|
}, v = (e) => {
|
|
19
|
-
const t =
|
|
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
|
-
x:
|
|
27
|
-
y:
|
|
26
|
+
x: n,
|
|
27
|
+
y: i,
|
|
28
28
|
width: m(a),
|
|
29
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
|
-
}),
|
|
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
|
-
const
|
|
48
|
-
if (
|
|
49
|
-
const
|
|
50
|
-
return
|
|
51
|
-
},
|
|
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) => {
|
|
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
|
-
return { ...t, [r]: u(
|
|
59
|
-
},
|
|
60
|
-
const
|
|
61
|
-
Object.entries(t).map(([
|
|
62
|
-
|
|
63
|
-
u(
|
|
58
|
+
return { ...t, [r]: u(n) };
|
|
59
|
+
}, ue = (e, t, r) => {
|
|
60
|
+
const n = Object.fromEntries(
|
|
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
|
-
return
|
|
70
|
+
return n;
|
|
71
71
|
}, V = 5 * 1024 * 1024, l = (e, t, r) => {
|
|
72
|
-
var
|
|
72
|
+
var n;
|
|
73
73
|
return {
|
|
74
74
|
fieldId: e.id,
|
|
75
75
|
fieldName: e.name,
|
|
76
|
-
message: ((
|
|
76
|
+
message: ((n = e.validation) == null ? void 0 : n.customMessage) ?? t,
|
|
77
77
|
code: r
|
|
78
78
|
};
|
|
79
|
-
},
|
|
80
|
-
const r = [], { validation:
|
|
81
|
-
if (!
|
|
82
|
-
if (
|
|
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(
|
|
83
83
|
l(
|
|
84
84
|
e,
|
|
85
|
-
`Must be at least ${
|
|
85
|
+
`Must be at least ${n.minLength} characters.`,
|
|
86
86
|
"MIN_LENGTH"
|
|
87
87
|
)
|
|
88
|
-
),
|
|
88
|
+
), n.maxLength !== void 0 && t.length > n.maxLength && r.push(
|
|
89
89
|
l(
|
|
90
90
|
e,
|
|
91
|
-
`Must be at most ${
|
|
91
|
+
`Must be at most ${n.maxLength} characters.`,
|
|
92
92
|
"MAX_LENGTH"
|
|
93
93
|
)
|
|
94
|
-
),
|
|
94
|
+
), n.pattern !== void 0)
|
|
95
95
|
try {
|
|
96
|
-
new RegExp(
|
|
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.",
|
|
@@ -110,29 +110,29 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
|
|
|
110
110
|
);
|
|
111
111
|
}
|
|
112
112
|
return r;
|
|
113
|
-
},
|
|
114
|
-
const r = [],
|
|
115
|
-
return
|
|
116
|
-
l(e, `Minimum value is ${
|
|
117
|
-
),
|
|
118
|
-
l(e, `Maximum value is ${
|
|
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")
|
|
119
119
|
), r;
|
|
120
|
-
},
|
|
120
|
+
}, E = (e, t) => {
|
|
121
121
|
if (e.sharedMode === "mirror")
|
|
122
122
|
return { valid: !0, errors: [] };
|
|
123
|
-
const r = [],
|
|
124
|
-
if (e.required &&
|
|
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: [] };
|
|
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(
|
|
@@ -149,93 +149,93 @@ 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: [
|
|
158
158
|
{
|
|
159
|
-
fieldId:
|
|
160
|
-
fieldName:
|
|
161
|
-
message: `No source field found for shared key "${
|
|
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
|
-
const
|
|
167
|
-
return
|
|
168
|
-
},
|
|
169
|
-
const { fields: t, fieldValues: r, sharedValues:
|
|
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
|
-
|
|
179
|
-
|
|
178
|
+
n,
|
|
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
|
-
const
|
|
191
|
-
if (
|
|
192
|
-
if (
|
|
193
|
-
let
|
|
194
|
-
for (; e[r +
|
|
195
|
-
|
|
196
|
-
t += `\\d{${
|
|
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;
|
|
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})$/,
|
|
206
|
-
const r = O.exec(e),
|
|
207
|
-
if (!r || !
|
|
208
|
-
const [,
|
|
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
|
+
const r = O.exec(e), n = t == null ? void 0 : t.trim();
|
|
207
|
+
if (!r || !n) return e;
|
|
208
|
+
const [, i = "", s = "", o = ""] = r;
|
|
209
209
|
let a = "";
|
|
210
|
-
for (let d = 0; d <
|
|
211
|
-
const
|
|
212
|
-
if (
|
|
213
|
-
let
|
|
214
|
-
for (;
|
|
215
|
-
|
|
216
|
-
if (
|
|
217
|
-
a +=
|
|
210
|
+
for (let d = 0; d < n.length; ) {
|
|
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) => {
|
|
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
|
|
236
|
-
if (
|
|
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: "${
|
|
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
|
}
|
|
@@ -249,7 +249,7 @@ const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type ===
|
|
|
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,93 +259,113 @@ 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
|
-
}),
|
|
270
|
-
index:
|
|
289
|
+
}), ee = async (e) => (await T.load(e)).getPages().map((r, n) => ({
|
|
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
300
|
}, ye = (e, t) => {
|
|
281
301
|
B(e.fields, t.id);
|
|
282
|
-
const r =
|
|
283
|
-
return _(
|
|
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
|
|
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
|
-
return _(
|
|
314
|
+
return _(n), {
|
|
295
315
|
...e,
|
|
296
|
-
fields:
|
|
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:
|
|
304
|
-
return r != null && r.sharedKey && r.sharedMode === "source" && (
|
|
323
|
+
let { sharedValues: s } = e;
|
|
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
|
-
fields:
|
|
311
|
-
fieldValues:
|
|
312
|
-
sharedValues:
|
|
330
|
+
fields: n,
|
|
331
|
+
fieldValues: i,
|
|
332
|
+
sharedValues: s,
|
|
313
333
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
314
334
|
};
|
|
315
|
-
},
|
|
316
|
-
const { page:
|
|
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
|
-
|
|
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
|
|
327
|
-
if (!
|
|
346
|
+
const n = e.fields.find((i) => i.id === t);
|
|
347
|
+
if (!n)
|
|
328
348
|
throw new Error(`Field ID "${t}" was not found.`);
|
|
329
|
-
if (
|
|
349
|
+
if (n.sharedMode === "mirror")
|
|
330
350
|
throw new Error(
|
|
331
351
|
`Cannot set value on mirror field "${t}". Set the value on the source field instead.`
|
|
332
352
|
);
|
|
333
|
-
if (
|
|
353
|
+
if (n.readonly)
|
|
334
354
|
throw new Error(`Cannot set value on read-only field "${t}".`);
|
|
335
|
-
if (!J(
|
|
355
|
+
if (!J(n, r))
|
|
336
356
|
throw new Error(
|
|
337
|
-
`Value for field "${t}" is incompatible with field type "${
|
|
357
|
+
`Value for field "${t}" is incompatible with field type "${n.type}".`
|
|
338
358
|
);
|
|
339
|
-
if (
|
|
340
|
-
const
|
|
359
|
+
if (n.sharedKey && n.sharedMode === "source") {
|
|
360
|
+
const i = j(
|
|
341
361
|
e.fields,
|
|
342
362
|
e.sharedValues,
|
|
343
|
-
|
|
363
|
+
n.sharedKey,
|
|
344
364
|
r
|
|
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,182 +388,197 @@ 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]:
|
|
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
|
-
},
|
|
385
|
-
const r = e.fields.find((
|
|
404
|
+
}, Fe = (e, t) => {
|
|
405
|
+
const r = e.fields.find((n) => n.id === t);
|
|
386
406
|
return r ? { ...r } : void 0;
|
|
387
|
-
},
|
|
388
|
-
const r = e.fields.find((
|
|
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);
|
|
389
409
|
if (r)
|
|
390
410
|
return f(r, e.fieldValues, e.sharedValues);
|
|
391
411
|
};
|
|
392
|
-
function
|
|
412
|
+
function Ve(e, t = {}) {
|
|
393
413
|
const r = {};
|
|
394
|
-
for (const
|
|
395
|
-
const
|
|
396
|
-
|
|
414
|
+
for (const n of e.fields) {
|
|
415
|
+
const i = f(
|
|
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
|
|
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);
|
|
426
|
+
switch (e.textAlign) {
|
|
427
|
+
case "center":
|
|
428
|
+
return i + (s - d) / 2;
|
|
429
|
+
case "right":
|
|
430
|
+
return i + s - 2 - d;
|
|
431
|
+
case "left":
|
|
432
|
+
default:
|
|
433
|
+
return i + 2;
|
|
434
|
+
}
|
|
435
|
+
}, re = (e) => ({
|
|
405
436
|
width: e.getWidth(),
|
|
406
437
|
height: e.getHeight()
|
|
407
|
-
}),
|
|
408
|
-
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);
|
|
409
440
|
e.drawText(r, {
|
|
410
|
-
x:
|
|
441
|
+
x: d,
|
|
411
442
|
y: Math.max(0, a),
|
|
412
|
-
size:
|
|
413
|
-
font:
|
|
414
|
-
color:
|
|
415
|
-
maxWidth:
|
|
443
|
+
size: o,
|
|
444
|
+
font: n,
|
|
445
|
+
color: w(0, 0, 0),
|
|
446
|
+
maxWidth: s.width - 4
|
|
416
447
|
});
|
|
417
|
-
},
|
|
448
|
+
}, ne = (e, t, r, n) => {
|
|
418
449
|
if (!r) return;
|
|
419
|
-
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);
|
|
420
455
|
e.drawLine({
|
|
421
|
-
start: { x:
|
|
422
|
-
end: { x: o
|
|
423
|
-
thickness:
|
|
424
|
-
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)
|
|
425
460
|
}), e.drawLine({
|
|
426
|
-
start: { x: o
|
|
427
|
-
end: { x:
|
|
428
|
-
thickness:
|
|
429
|
-
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)
|
|
430
465
|
});
|
|
431
|
-
},
|
|
432
|
-
const
|
|
433
|
-
|
|
434
|
-
image:
|
|
435
|
-
mimeType:
|
|
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 ? {
|
|
469
|
+
image: n,
|
|
470
|
+
mimeType: i
|
|
436
471
|
} : {
|
|
437
|
-
image:
|
|
472
|
+
image: n
|
|
438
473
|
}
|
|
439
474
|
);
|
|
440
475
|
if (d === void 0)
|
|
441
476
|
throw new Error(
|
|
442
477
|
`Field "${r.id}" contains an unsupported signature image format for PDF export.`
|
|
443
478
|
);
|
|
444
|
-
const
|
|
445
|
-
e.drawImage(
|
|
446
|
-
x:
|
|
479
|
+
const h = d === "image/jpeg" ? await t.embedJpg(n) : await t.embedPng(n);
|
|
480
|
+
e.drawImage(h, {
|
|
481
|
+
x: o.x,
|
|
447
482
|
y: Math.max(0, a),
|
|
448
|
-
width:
|
|
449
|
-
height:
|
|
483
|
+
width: o.width,
|
|
484
|
+
height: o.height
|
|
450
485
|
});
|
|
451
|
-
},
|
|
452
|
-
if (!(
|
|
453
|
-
if (g(
|
|
454
|
-
await
|
|
486
|
+
}, ie = async (e, t, r, n, i, s) => {
|
|
487
|
+
if (!(n === void 0 || r.hidden)) {
|
|
488
|
+
if (g(n)) {
|
|
489
|
+
await se(
|
|
455
490
|
e,
|
|
456
491
|
t,
|
|
457
492
|
r,
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
493
|
+
n.image,
|
|
494
|
+
n.mimeType,
|
|
495
|
+
s
|
|
461
496
|
);
|
|
462
497
|
return;
|
|
463
498
|
}
|
|
464
|
-
if (typeof
|
|
465
|
-
r.type === "checkbox" &&
|
|
499
|
+
if (typeof n == "boolean") {
|
|
500
|
+
r.type === "checkbox" && ne(e, r, n, s);
|
|
466
501
|
return;
|
|
467
502
|
}
|
|
468
|
-
if (typeof
|
|
469
|
-
|
|
503
|
+
if (typeof n == "string" && n.trim() !== "") {
|
|
504
|
+
I(
|
|
470
505
|
e,
|
|
471
506
|
r,
|
|
472
|
-
r.type === "date" ? X(
|
|
473
|
-
|
|
474
|
-
|
|
507
|
+
r.type === "date" ? X(n, r.dateFormat) : n,
|
|
508
|
+
i,
|
|
509
|
+
s
|
|
475
510
|
);
|
|
476
511
|
return;
|
|
477
512
|
}
|
|
478
|
-
typeof
|
|
513
|
+
typeof n == "number" && I(e, r, String(n), i, s);
|
|
479
514
|
}
|
|
480
|
-
},
|
|
515
|
+
}, oe = (e) => {
|
|
481
516
|
if (!(e.byteLength > 0))
|
|
482
517
|
throw new Error(
|
|
483
518
|
"exportToPdf requires a non-empty source PDF in document.pdfData."
|
|
484
519
|
);
|
|
485
|
-
},
|
|
486
|
-
var
|
|
487
|
-
|
|
488
|
-
const r = await
|
|
520
|
+
}, Ie = async (e, t = {}) => {
|
|
521
|
+
var o;
|
|
522
|
+
oe(e.pdfData);
|
|
523
|
+
const r = await T.load(e.pdfData), n = await r.embedFont(N.Helvetica), i = r.getPages(), s = /* @__PURE__ */ new Map();
|
|
489
524
|
for (const a of e.fields) {
|
|
490
|
-
const d =
|
|
491
|
-
|
|
525
|
+
const d = s.get(a.page) ?? [];
|
|
526
|
+
s.set(a.page, [...d, a]);
|
|
492
527
|
}
|
|
493
|
-
for (const [a, d] of
|
|
494
|
-
const
|
|
495
|
-
if (!
|
|
496
|
-
const
|
|
497
|
-
for (const
|
|
498
|
-
const
|
|
499
|
-
|
|
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,
|
|
500
535
|
e.fieldValues,
|
|
501
536
|
e.sharedValues
|
|
502
|
-
),
|
|
503
|
-
if (!
|
|
537
|
+
), b = E(p, F);
|
|
538
|
+
if (!b.valid)
|
|
504
539
|
throw new Error(
|
|
505
|
-
`Field "${
|
|
540
|
+
`Field "${p.id}" is invalid for PDF export: ${((o = b.errors[0]) == null ? void 0 : o.message) ?? "Unknown validation error."}`
|
|
506
541
|
);
|
|
507
|
-
await
|
|
542
|
+
await ie(c, r, p, F, n, h);
|
|
508
543
|
}
|
|
509
544
|
}
|
|
510
545
|
return r.save();
|
|
511
546
|
};
|
|
512
547
|
export {
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
548
|
+
A as clampCoord,
|
|
549
|
+
k as clampToPage,
|
|
550
|
+
Ee as clearFieldValue,
|
|
551
|
+
Z as createDocument,
|
|
552
|
+
me as createDocumentFromPdfData,
|
|
518
553
|
ye as createField,
|
|
519
|
-
|
|
554
|
+
W as dateFormatToRegexPattern,
|
|
520
555
|
m as ensureMinSize,
|
|
521
|
-
|
|
556
|
+
Ie as exportToPdf,
|
|
522
557
|
X as formatDateValue,
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
558
|
+
Fe as getField,
|
|
559
|
+
be as getFields,
|
|
560
|
+
le as getMirrorFields,
|
|
561
|
+
ee as getPdfPageInfo,
|
|
562
|
+
Ae as getResolvedFieldValue,
|
|
563
|
+
Ve as getResolvedValues,
|
|
564
|
+
ce as getSourceField,
|
|
565
|
+
pe as isIsoDateString,
|
|
566
|
+
de as isPrimitiveValue,
|
|
532
567
|
g as isSignatureValue,
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
568
|
+
ge as matchesDateFormat,
|
|
569
|
+
xe as moveField,
|
|
570
|
+
y as normalizeRect,
|
|
571
|
+
we as removeField,
|
|
572
|
+
Me as resizeField,
|
|
573
|
+
ue as resolveAllSharedValues,
|
|
539
574
|
f as resolveFieldValue,
|
|
540
575
|
Se as setFieldValue,
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
576
|
+
j as setSharedFieldValue,
|
|
577
|
+
S as toAbsoluteRect,
|
|
578
|
+
he as toNormalizedRect,
|
|
544
579
|
P as updateField,
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
580
|
+
fe as validateDocument,
|
|
581
|
+
E as validateField,
|
|
582
|
+
G as validateSharedFieldGroup
|
|
548
583
|
};
|
|
549
584
|
//# sourceMappingURL=index.js.map
|