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