refactor(annotation): simplify mapSignature function to return a flat array

Reworked mapSignature to return a single flattened array combining formFields,
frames, and signatures instead of a nested object. This simplifies downstream
processing and improves readability.
This commit is contained in:
2025-10-21 09:48:06 +02:00
parent 6cc631111c
commit a1d6b5347f

View File

@@ -317,8 +317,9 @@ function fixBase64(escapedBase64) {
}
function mapSignature(iJSON) {
return {
formFields: iJSON.formFieldValues.filter(field => !field.name.includes("label")).map((field) => {
return [
// formFields
...iJSON.formFieldValues.filter(field => !field.name.includes("label")).map((field) => {
const nameParts = field.name.split('#');
return {
elementId: Number(nameParts[2]),
@@ -327,7 +328,9 @@ function mapSignature(iJSON) {
type: field.type
};
}),
frames: iJSON.annotations.filter(annot => annot.description === 'FRAME').map((annot) => {
// 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('#');
return {
@@ -337,7 +340,9 @@ function mapSignature(iJSON) {
type: annot.type
};
}),
signatures: iJSON.annotations.filter(annot => annot.isSignature).map(annot => {
// signatures
...iJSON.annotations.filter(annot => annot.isSignature).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('#');
@@ -359,5 +364,5 @@ function mapSignature(iJSON) {
type: annot.type
};
})
};
];
}