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:
@@ -317,8 +317,9 @@ function fixBase64(escapedBase64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mapSignature(iJSON) {
|
function mapSignature(iJSON) {
|
||||||
return {
|
return [
|
||||||
formFields: iJSON.formFieldValues.filter(field => !field.name.includes("label")).map((field) => {
|
// formFields
|
||||||
|
...iJSON.formFieldValues.filter(field => !field.name.includes("label")).map((field) => {
|
||||||
const nameParts = field.name.split('#');
|
const nameParts = field.name.split('#');
|
||||||
return {
|
return {
|
||||||
elementId: Number(nameParts[2]),
|
elementId: Number(nameParts[2]),
|
||||||
@@ -327,7 +328,9 @@ function mapSignature(iJSON) {
|
|||||||
type: field.type
|
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 preElement = findNearest(annot, e => e.bbox[0], e => e.bbox[1], ...iJSON.annotations.filter(field => field.id.includes("signature")));
|
||||||
const idPartsOfPre = preElement.id.split('#');
|
const idPartsOfPre = preElement.id.split('#');
|
||||||
return {
|
return {
|
||||||
@@ -337,7 +340,9 @@ function mapSignature(iJSON) {
|
|||||||
type: annot.type
|
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 preElement = findNearest(annot, e => e.bbox[0], e => e.bbox[1], ...iJSON.annotations.filter(field => field.id.includes("signature")));
|
||||||
const idPartsOfPre = preElement.id.split('#');
|
const idPartsOfPre = preElement.id.split('#');
|
||||||
|
|
||||||
@@ -359,5 +364,5 @@ function mapSignature(iJSON) {
|
|||||||
type: annot.type
|
type: annot.type
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
};
|
];
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user