feat(annotations): add fixBase64 and map FRAME annotations to nearest signature

- Added `fixBase64` utility to unescape Base64 strings.
- Updated `mapSignature` to link FRAME annotations to their nearest signature element and include `elementId`.
- Ensures proper mapping of annotation frames and consistent data structure for form fields.
This commit is contained in:
tekh 2025-10-20 14:05:11 +02:00
parent abaa315b24
commit 188cb67306

View File

@ -309,6 +309,13 @@ function isCityField(formField) {
return cityFieldNames.includes(formField.name)
}
function fixBase64(escapedBase64) {
return escapedBase64
.replace(/\\u002B/g, "+")
.replace(/\\u002F/g, "/")
.replace(/\\u003D/g, "=");
}
function mapSignature(iJSON) {
return {
formFields: iJSON.formFieldValues.filter(field => !field.name.includes("label")).map((field) => {
@ -318,6 +325,9 @@ function mapSignature(iJSON) {
return field;
}),
frames: iJSON.annotations.filter(annot => annot.description === 'FRAME').map((annot) => {
const preElement = findNearest(annot, e => e.bbox[0], e => e.bbox[1], ...iJSON.annotations.filter(field => field.id.includes("signature")));
const idPartsOfPre = preElement.id.split('#');
annot.elementId = Number(idPartsOfPre[2]);
annot.name = annot.description.toLowerCase();
annot.value = iJSON.attachments[annot.imageAttachmentId]?.binary || null;
return annot;