@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/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 +197 -186
- package/dist/index.js.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,5 +1,5 @@
|
|
|
1
|
-
import { PDFDocument as I, StandardFonts as N, rgb as
|
|
2
|
-
const g = (e) => typeof e == "object" && e !== null && "type" in e && e.type === "signature",
|
|
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
|
-
},
|
|
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)),
|
|
23
|
-
const r = L(e.page, t),
|
|
22
|
+
}, K = 5e-3, R = 0, w = 1, L = (e, t) => Math.max(0, Math.min(t - 1, Math.floor(e))), b = (e) => Math.max(R, Math.min(w, e)), p = (e) => Math.max(K, e), v = (e, t) => {
|
|
23
|
+
const r = L(e.page, t), n = b(e.x), s = b(e.y), o = p(e.width), i = p(e.height), a = Math.min(o, w - n), d = Math.min(i, w - s);
|
|
24
24
|
return {
|
|
25
25
|
page: r,
|
|
26
|
-
x:
|
|
27
|
-
y:
|
|
28
|
-
width:
|
|
29
|
-
height:
|
|
26
|
+
x: n,
|
|
27
|
+
y: s,
|
|
28
|
+
width: p(a),
|
|
29
|
+
height: p(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
|
+
}), 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
|
-
}),
|
|
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
|
|
48
|
-
if (
|
|
49
|
-
const
|
|
50
|
-
return
|
|
51
|
-
}, k = (e, t, r,
|
|
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(
|
|
59
|
-
},
|
|
60
|
-
const
|
|
61
|
-
Object.entries(t).map(([
|
|
62
|
-
|
|
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
|
|
67
|
-
const o = f(
|
|
68
|
-
o !== void 0 && (s
|
|
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
|
|
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
79
|
}, j = (e, t) => {
|
|
80
|
-
const r = [], { validation:
|
|
81
|
-
if (!
|
|
82
|
-
if (
|
|
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.",
|
|
@@ -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 = [],
|
|
115
|
-
return
|
|
116
|
-
l(e, `Minimum value is ${
|
|
117
|
-
),
|
|
118
|
-
l(e, `Maximum value is ${
|
|
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
|
+
}, M = (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: [] };
|
|
@@ -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 (!
|
|
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
|
-
),
|
|
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,
|
|
153
|
-
const o = e.filter((a) => a.sharedKey ===
|
|
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:
|
|
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
166
|
const i = f(o, t, r);
|
|
167
|
-
return
|
|
168
|
-
},
|
|
169
|
-
const { fields: t, fieldValues: r, sharedValues:
|
|
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 (
|
|
174
|
-
|
|
173
|
+
if (s.has(i.sharedKey)) continue;
|
|
174
|
+
s.add(i.sharedKey);
|
|
175
175
|
const a = U(
|
|
176
176
|
t,
|
|
177
177
|
r,
|
|
178
|
-
|
|
178
|
+
n,
|
|
179
179
|
i.sharedKey
|
|
180
180
|
);
|
|
181
181
|
o.push(...a.errors);
|
|
182
182
|
} else {
|
|
183
|
-
const a = f(i, r,
|
|
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
|
|
191
|
-
if (
|
|
192
|
-
if (G.has(
|
|
193
|
-
let
|
|
194
|
-
for (; e[r +
|
|
195
|
-
|
|
196
|
-
t += `\\d{${
|
|
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(
|
|
199
|
+
t += Y(n), r += 1;
|
|
200
200
|
}
|
|
201
201
|
return t;
|
|
202
|
-
},
|
|
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})$/,
|
|
206
|
-
const r = O.exec(e),
|
|
207
|
-
if (!r || !
|
|
208
|
-
const [,
|
|
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 <
|
|
211
|
-
const h =
|
|
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 (;
|
|
214
|
+
for (; n[d + c] === h; )
|
|
215
215
|
c += 1;
|
|
216
216
|
if (h === "y" || h === "Y") {
|
|
217
|
-
a += c === 2 ?
|
|
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
|
|
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
|
}
|
|
242
|
-
},
|
|
242
|
+
}, W = (e, t) => {
|
|
243
243
|
if (e.some((r) => r.id === t))
|
|
244
244
|
throw new Error(`Field ID "${t}" already exists.`);
|
|
245
|
-
},
|
|
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) &&
|
|
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
|
-
},
|
|
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,
|
|
270
|
-
index:
|
|
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
|
-
})),
|
|
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
|
-
},
|
|
281
|
-
|
|
282
|
-
const r =
|
|
283
|
-
return _(
|
|
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:
|
|
285
|
+
fields: s,
|
|
286
286
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
287
287
|
};
|
|
288
288
|
}, P = (e, t, r) => {
|
|
289
|
-
const
|
|
290
|
-
if (
|
|
291
|
-
const o = { ...
|
|
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 _(
|
|
294
|
+
return _(n), {
|
|
295
295
|
...e,
|
|
296
|
-
fields:
|
|
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),
|
|
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" && (
|
|
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:
|
|
311
|
-
fieldValues:
|
|
310
|
+
fields: n,
|
|
311
|
+
fieldValues: s,
|
|
312
312
|
sharedValues: o,
|
|
313
313
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
314
314
|
};
|
|
315
|
-
},
|
|
316
|
-
const { page:
|
|
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
|
-
|
|
320
|
+
n !== void 0 ? { page: n, x: s, y: o } : { x: s, y: o }
|
|
321
321
|
);
|
|
322
|
-
},
|
|
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
|
|
327
|
-
if (!
|
|
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 (
|
|
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 (
|
|
333
|
+
if (n.readonly)
|
|
334
334
|
throw new Error(`Cannot set value on read-only field "${t}".`);
|
|
335
|
-
if (!
|
|
335
|
+
if (!B(n, r))
|
|
336
336
|
throw new Error(
|
|
337
|
-
`Value for field "${t}" is incompatible with field type "${
|
|
337
|
+
`Value for field "${t}" is incompatible with field type "${n.type}".`
|
|
338
338
|
);
|
|
339
|
-
if (
|
|
340
|
-
const
|
|
339
|
+
if (n.sharedKey && n.sharedMode === "source") {
|
|
340
|
+
const s = k(
|
|
341
341
|
e.fields,
|
|
342
342
|
e.sharedValues,
|
|
343
|
-
|
|
343
|
+
n.sharedKey,
|
|
344
344
|
r
|
|
345
345
|
);
|
|
346
346
|
return {
|
|
347
347
|
...e,
|
|
348
|
-
sharedValues:
|
|
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]:
|
|
378
|
+
const { [t]: n, ...s } = e.fieldValues;
|
|
379
379
|
return {
|
|
380
380
|
...e,
|
|
381
|
-
fieldValues:
|
|
381
|
+
fieldValues: s,
|
|
382
382
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
383
383
|
};
|
|
384
|
-
},
|
|
385
|
-
const r = e.fields.find((
|
|
384
|
+
}, Ee = (e, t) => {
|
|
385
|
+
const r = e.fields.find((n) => n.id === t);
|
|
386
386
|
return r ? { ...r } : void 0;
|
|
387
|
-
},
|
|
388
|
-
const r = e.fields.find((
|
|
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
|
|
392
|
+
function Ve(e, t = {}) {
|
|
393
393
|
const r = {};
|
|
394
|
-
for (const
|
|
395
|
-
const
|
|
396
|
-
|
|
394
|
+
for (const n of e.fields) {
|
|
395
|
+
const s = f(
|
|
396
|
+
n,
|
|
397
397
|
e.fieldValues,
|
|
398
398
|
e.sharedValues
|
|
399
399
|
);
|
|
400
|
-
(
|
|
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,
|
|
408
|
-
const o =
|
|
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:
|
|
421
|
+
x: d,
|
|
411
422
|
y: Math.max(0, a),
|
|
412
423
|
size: i,
|
|
413
|
-
font:
|
|
414
|
-
color:
|
|
424
|
+
font: n,
|
|
425
|
+
color: m(0, 0, 0),
|
|
415
426
|
maxWidth: o.width - 4
|
|
416
427
|
});
|
|
417
|
-
},
|
|
428
|
+
}, re = (e, t, r, n) => {
|
|
418
429
|
if (!r) return;
|
|
419
|
-
const
|
|
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:
|
|
422
|
-
end: { x: o, y:
|
|
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:
|
|
435
|
+
color: m(0, 0, 0)
|
|
425
436
|
}), e.drawLine({
|
|
426
|
-
start: { x: o, y:
|
|
427
|
-
end: { x:
|
|
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:
|
|
440
|
+
color: m(0, 0, 0)
|
|
430
441
|
});
|
|
431
|
-
},
|
|
432
|
-
const i =
|
|
433
|
-
|
|
434
|
-
image:
|
|
435
|
-
mimeType:
|
|
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:
|
|
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(
|
|
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,
|
|
452
|
-
if (!(
|
|
453
|
-
if (g(
|
|
454
|
-
await
|
|
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
|
-
|
|
459
|
-
|
|
469
|
+
n.image,
|
|
470
|
+
n.mimeType,
|
|
460
471
|
o
|
|
461
472
|
);
|
|
462
473
|
return;
|
|
463
474
|
}
|
|
464
|
-
if (typeof
|
|
465
|
-
r.type === "checkbox" &&
|
|
475
|
+
if (typeof n == "boolean") {
|
|
476
|
+
r.type === "checkbox" && re(e, r, n, o);
|
|
466
477
|
return;
|
|
467
478
|
}
|
|
468
|
-
if (typeof
|
|
479
|
+
if (typeof n == "string" && n.trim() !== "") {
|
|
469
480
|
A(
|
|
470
481
|
e,
|
|
471
482
|
r,
|
|
472
|
-
r.type === "date" ? X(
|
|
473
|
-
|
|
483
|
+
r.type === "date" ? X(n, r.dateFormat) : n,
|
|
484
|
+
s,
|
|
474
485
|
o
|
|
475
486
|
);
|
|
476
487
|
return;
|
|
477
488
|
}
|
|
478
|
-
typeof
|
|
489
|
+
typeof n == "number" && A(e, r, String(n), s, o);
|
|
479
490
|
}
|
|
480
|
-
},
|
|
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
|
-
},
|
|
496
|
+
}, Ae = async (e, t = {}) => {
|
|
486
497
|
var i;
|
|
487
|
-
|
|
488
|
-
const r = await I.load(e.pdfData),
|
|
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 =
|
|
505
|
+
const h = s[a];
|
|
495
506
|
if (!h) continue;
|
|
496
|
-
const c =
|
|
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 =
|
|
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,
|
|
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
|
-
|
|
518
|
-
|
|
528
|
+
ye as createDocumentFromPdfData,
|
|
529
|
+
pe as createField,
|
|
519
530
|
q as dateFormatToRegexPattern,
|
|
520
|
-
|
|
521
|
-
|
|
531
|
+
p as ensureMinSize,
|
|
532
|
+
Ae as exportToPdf,
|
|
522
533
|
X as formatDateValue,
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
534
|
+
Ee as getField,
|
|
535
|
+
Fe as getFields,
|
|
536
|
+
he as getMirrorFields,
|
|
526
537
|
Z as getPdfPageInfo,
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
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
|
-
|
|
534
|
-
|
|
535
|
-
|
|
544
|
+
fe as matchesDateFormat,
|
|
545
|
+
we as moveField,
|
|
546
|
+
v as normalizeRect,
|
|
536
547
|
me as removeField,
|
|
537
|
-
|
|
538
|
-
|
|
548
|
+
xe as resizeField,
|
|
549
|
+
le as resolveAllSharedValues,
|
|
539
550
|
f as resolveFieldValue,
|
|
540
551
|
Se as setFieldValue,
|
|
541
552
|
k as setSharedFieldValue,
|
|
542
|
-
|
|
543
|
-
|
|
553
|
+
S as toAbsoluteRect,
|
|
554
|
+
de as toNormalizedRect,
|
|
544
555
|
P as updateField,
|
|
545
|
-
|
|
546
|
-
|
|
556
|
+
ue as validateDocument,
|
|
557
|
+
M as validateField,
|
|
547
558
|
U as validateSharedFieldGroup
|
|
548
559
|
};
|
|
549
560
|
//# sourceMappingURL=index.js.map
|