formatferry 1.0.25 → 1.0.27
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.js +62 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -22549,6 +22549,58 @@ function dedupAgainstWidgets(textItems, widgets) {
|
|
|
22549
22549
|
}
|
|
22550
22550
|
return kept;
|
|
22551
22551
|
}
|
|
22552
|
+
function associateLabelsToWidgets(widgets, textItems) {
|
|
22553
|
+
if (widgets.length === 0 || textItems.length === 0) return [widgets, textItems];
|
|
22554
|
+
const consumedIndices = /* @__PURE__ */ new Set();
|
|
22555
|
+
const updatedWidgets = widgets.map((w) => {
|
|
22556
|
+
if (/^\[([ X]|Signed|Signature)\]$/.test(w.str)) return w;
|
|
22557
|
+
const refSize = Math.max(w.height, 10);
|
|
22558
|
+
const leftTolerance = refSize * 3;
|
|
22559
|
+
const aboveTolerance = refSize * 1;
|
|
22560
|
+
let bestCandidate = null;
|
|
22561
|
+
for (let i = 0; i < textItems.length; i++) {
|
|
22562
|
+
if (consumedIndices.has(i)) continue;
|
|
22563
|
+
const txt = textItems[i];
|
|
22564
|
+
const isToLeft = txt.right <= w.x + 2;
|
|
22565
|
+
if (isToLeft) {
|
|
22566
|
+
const hGap = w.x - txt.right;
|
|
22567
|
+
if (hGap <= leftTolerance) {
|
|
22568
|
+
const yOverlap = Math.min(txt.y + txt.height, w.y + w.height) - Math.max(txt.y, w.y);
|
|
22569
|
+
const minH = Math.min(txt.height, w.height);
|
|
22570
|
+
if (yOverlap / minH >= 0.5) {
|
|
22571
|
+
const score = hGap;
|
|
22572
|
+
if (!bestCandidate || score < bestCandidate.score) {
|
|
22573
|
+
bestCandidate = { idx: i, str: txt.str, score };
|
|
22574
|
+
}
|
|
22575
|
+
}
|
|
22576
|
+
}
|
|
22577
|
+
}
|
|
22578
|
+
if (!isToLeft) {
|
|
22579
|
+
const widgetTop = w.y + w.height;
|
|
22580
|
+
const labelBottom = txt.y;
|
|
22581
|
+
const vGap = labelBottom - widgetTop;
|
|
22582
|
+
if (vGap >= 0 && vGap <= aboveTolerance) {
|
|
22583
|
+
const xOverlap = Math.min(txt.right, w.right) - Math.max(txt.x, w.x);
|
|
22584
|
+
if (xOverlap > 0) {
|
|
22585
|
+
const score = vGap;
|
|
22586
|
+
if (!bestCandidate || score < bestCandidate.score) {
|
|
22587
|
+
bestCandidate = { idx: i, str: txt.str, score };
|
|
22588
|
+
}
|
|
22589
|
+
}
|
|
22590
|
+
}
|
|
22591
|
+
}
|
|
22592
|
+
}
|
|
22593
|
+
if (bestCandidate) {
|
|
22594
|
+
consumedIndices.add(bestCandidate.idx);
|
|
22595
|
+
const labelStr = bestCandidate.str.trimEnd();
|
|
22596
|
+
const separator = /[::]\s*$/.test(labelStr) ? " " : ": ";
|
|
22597
|
+
return { ...w, str: `${labelStr}${separator}${w.str}` };
|
|
22598
|
+
}
|
|
22599
|
+
return w;
|
|
22600
|
+
});
|
|
22601
|
+
const remainingText = textItems.filter((_, i) => !consumedIndices.has(i));
|
|
22602
|
+
return [updatedWidgets, remainingText];
|
|
22603
|
+
}
|
|
22552
22604
|
function itemsToLinearText(items) {
|
|
22553
22605
|
if (items.length === 0) return "";
|
|
22554
22606
|
const sorted = [...items].sort((a, b) => b.y + b.height - (a.y + a.height) || a.x - b.x);
|
|
@@ -23203,7 +23255,14 @@ var PdfAdapter = class {
|
|
|
23203
23255
|
...annotations.flatMap(widgetToPositionedItems),
|
|
23204
23256
|
...groupRadioButtons(annotations)
|
|
23205
23257
|
];
|
|
23206
|
-
|
|
23258
|
+
let items;
|
|
23259
|
+
if (widgetItems.length > 0) {
|
|
23260
|
+
const dedupedText = dedupAgainstWidgets(positionedText, widgetItems);
|
|
23261
|
+
const [labelledWidgets, remainingText] = associateLabelsToWidgets(widgetItems, dedupedText);
|
|
23262
|
+
items = [...remainingText, ...labelledWidgets];
|
|
23263
|
+
} else {
|
|
23264
|
+
items = positionedText;
|
|
23265
|
+
}
|
|
23207
23266
|
if (getFeatureFlags().enablePdfEnhanced) {
|
|
23208
23267
|
applyLinkAnnotations(items, annotations);
|
|
23209
23268
|
}
|
|
@@ -25761,8 +25820,8 @@ import { readFileSync as readFileSync4 } from "fs";
|
|
|
25761
25820
|
import { resolve, dirname as dirname3 } from "path";
|
|
25762
25821
|
import { fileURLToPath } from "url";
|
|
25763
25822
|
var getVersion = () => {
|
|
25764
|
-
if ("1.0.
|
|
25765
|
-
return "1.0.
|
|
25823
|
+
if ("1.0.27") {
|
|
25824
|
+
return "1.0.27";
|
|
25766
25825
|
}
|
|
25767
25826
|
try {
|
|
25768
25827
|
const __dirname = dirname3(fileURLToPath(import.meta.url));
|