@signiphi/page-assembly 0.2.0-beta.14 → 0.2.0-beta.15
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.d.mts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +33 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -329,6 +329,14 @@ interface SigniphiFieldMetadata {
|
|
|
329
329
|
* when a source that had baked its labels is merged with one that deferred.
|
|
330
330
|
*/
|
|
331
331
|
textLabelBaked?: boolean;
|
|
332
|
+
/**
|
|
333
|
+
* CHECKBOX only: this field's caption is already in the page stream, written
|
|
334
|
+
* by document-prepare's bake. Declared so the merge carries it through — it
|
|
335
|
+
* is what pdf-signer's `checkboxLabelSource` actually decides on, the
|
|
336
|
+
* document-level `checkboxLabelsBaked` below being only the bake's mode.
|
|
337
|
+
* Nothing here sets or reads it.
|
|
338
|
+
*/
|
|
339
|
+
checkboxCaptionBaked?: boolean;
|
|
332
340
|
/**
|
|
333
341
|
* Persisted geometry, written by `document-prepare` for RADIO and TEXT_LABEL
|
|
334
342
|
* fields only. Declared here for ONE reason: its `page` is the SOURCE
|
|
@@ -381,6 +389,13 @@ interface SigniphiMetadata {
|
|
|
381
389
|
* means it is already in the page stream.
|
|
382
390
|
*/
|
|
383
391
|
textLabelsBaked?: boolean;
|
|
392
|
+
/**
|
|
393
|
+
* Document-level: `false` means CHECKBOX captions were deliberately NOT baked
|
|
394
|
+
* beside their boxes (multi-signer), so the sign-time pass draws them per
|
|
395
|
+
* signer. `true` means they are already in the page stream. Absent means the
|
|
396
|
+
* source predates baked captions, which pdf-signer also reads as "draw".
|
|
397
|
+
*/
|
|
398
|
+
checkboxLabelsBaked?: boolean;
|
|
384
399
|
}
|
|
385
400
|
/**
|
|
386
401
|
* Extract SigniphiMetadata from a PDF document
|
package/dist/index.d.ts
CHANGED
|
@@ -329,6 +329,14 @@ interface SigniphiFieldMetadata {
|
|
|
329
329
|
* when a source that had baked its labels is merged with one that deferred.
|
|
330
330
|
*/
|
|
331
331
|
textLabelBaked?: boolean;
|
|
332
|
+
/**
|
|
333
|
+
* CHECKBOX only: this field's caption is already in the page stream, written
|
|
334
|
+
* by document-prepare's bake. Declared so the merge carries it through — it
|
|
335
|
+
* is what pdf-signer's `checkboxLabelSource` actually decides on, the
|
|
336
|
+
* document-level `checkboxLabelsBaked` below being only the bake's mode.
|
|
337
|
+
* Nothing here sets or reads it.
|
|
338
|
+
*/
|
|
339
|
+
checkboxCaptionBaked?: boolean;
|
|
332
340
|
/**
|
|
333
341
|
* Persisted geometry, written by `document-prepare` for RADIO and TEXT_LABEL
|
|
334
342
|
* fields only. Declared here for ONE reason: its `page` is the SOURCE
|
|
@@ -381,6 +389,13 @@ interface SigniphiMetadata {
|
|
|
381
389
|
* means it is already in the page stream.
|
|
382
390
|
*/
|
|
383
391
|
textLabelsBaked?: boolean;
|
|
392
|
+
/**
|
|
393
|
+
* Document-level: `false` means CHECKBOX captions were deliberately NOT baked
|
|
394
|
+
* beside their boxes (multi-signer), so the sign-time pass draws them per
|
|
395
|
+
* signer. `true` means they are already in the page stream. Absent means the
|
|
396
|
+
* source predates baked captions, which pdf-signer also reads as "draw".
|
|
397
|
+
*/
|
|
398
|
+
checkboxLabelsBaked?: boolean;
|
|
384
399
|
}
|
|
385
400
|
/**
|
|
386
401
|
* Extract SigniphiMetadata from a PDF document
|
package/dist/index.js
CHANGED
|
@@ -1413,6 +1413,7 @@ function mergeSourceMetadata(sources) {
|
|
|
1413
1413
|
const merged = { version: "1.0", fields: {}, fieldIdIndex: {} };
|
|
1414
1414
|
let radioLabelsBaked;
|
|
1415
1415
|
let textLabelsBaked;
|
|
1416
|
+
let checkboxLabelsBaked;
|
|
1416
1417
|
for (const source of sources) {
|
|
1417
1418
|
const meta = source.metadata;
|
|
1418
1419
|
if (!meta || source.fields.length === 0) continue;
|
|
@@ -1420,6 +1421,8 @@ function mergeSourceMetadata(sources) {
|
|
|
1420
1421
|
else if (meta.radioLabelsBaked === true && radioLabelsBaked === void 0) radioLabelsBaked = true;
|
|
1421
1422
|
if (meta.textLabelsBaked === false) textLabelsBaked = false;
|
|
1422
1423
|
else if (meta.textLabelsBaked === true && textLabelsBaked === void 0) textLabelsBaked = true;
|
|
1424
|
+
if (meta.checkboxLabelsBaked === false) checkboxLabelsBaked = false;
|
|
1425
|
+
else if (meta.checkboxLabelsBaked === true && checkboxLabelsBaked === void 0) checkboxLabelsBaked = true;
|
|
1423
1426
|
}
|
|
1424
1427
|
for (const source of sources) {
|
|
1425
1428
|
const meta = source.metadata;
|
|
@@ -1438,8 +1441,9 @@ function mergeSourceMetadata(sources) {
|
|
|
1438
1441
|
}
|
|
1439
1442
|
if (radioLabelsBaked !== void 0) merged.radioLabelsBaked = radioLabelsBaked;
|
|
1440
1443
|
if (textLabelsBaked !== void 0) merged.textLabelsBaked = textLabelsBaked;
|
|
1444
|
+
if (checkboxLabelsBaked !== void 0) merged.checkboxLabelsBaked = checkboxLabelsBaked;
|
|
1441
1445
|
const hasEntries = Object.keys(merged.fields).length > 0;
|
|
1442
|
-
const hasMarkers = radioLabelsBaked !== void 0 || textLabelsBaked !== void 0;
|
|
1446
|
+
const hasMarkers = radioLabelsBaked !== void 0 || textLabelsBaked !== void 0 || checkboxLabelsBaked !== void 0;
|
|
1443
1447
|
if (!hasEntries && !hasMarkers) return null;
|
|
1444
1448
|
if (Object.keys(merged.fieldIdIndex).length === 0) delete merged.fieldIdIndex;
|
|
1445
1449
|
return merged;
|
|
@@ -1668,6 +1672,7 @@ function setSigniphiMetadata(pdfDoc, metadata) {
|
|
|
1668
1672
|
throw error;
|
|
1669
1673
|
}
|
|
1670
1674
|
}
|
|
1675
|
+
var SIGNIPHI_CHECKBOX_LABEL_MARKER = "SiPL_Check";
|
|
1671
1676
|
var FormFieldType = /* @__PURE__ */ ((FormFieldType2) => {
|
|
1672
1677
|
FormFieldType2["TEXT"] = "text";
|
|
1673
1678
|
FormFieldType2["SIGNATURE"] = "signature";
|
|
@@ -1753,6 +1758,7 @@ async function addFormFieldsToPdf(pdfBytes, formFields, options = {}) {
|
|
|
1753
1758
|
}
|
|
1754
1759
|
}
|
|
1755
1760
|
const font = await pdfDoc.embedFont(pdfLib.StandardFonts.Helvetica);
|
|
1761
|
+
const bakedCheckboxCaptions = /* @__PURE__ */ new Map();
|
|
1756
1762
|
const fieldNamePages = /* @__PURE__ */ new Map();
|
|
1757
1763
|
for (const field of formFields) {
|
|
1758
1764
|
const baseName = field.name;
|
|
@@ -1849,10 +1855,15 @@ async function addFormFieldsToPdf(pdfBytes, formFields, options = {}) {
|
|
|
1849
1855
|
} catch {
|
|
1850
1856
|
}
|
|
1851
1857
|
if (drawLabels) {
|
|
1852
|
-
const fontSize = Math.min(
|
|
1858
|
+
const fontSize = Math.max(1, Math.min(10, field.position.height * 0.4));
|
|
1853
1859
|
const labelX = pdfX + field.position.width + 5;
|
|
1854
1860
|
const labelY = pdfY + (field.position.height - fontSize) / 2;
|
|
1861
|
+
page.pushOperators(
|
|
1862
|
+
pdfLib.PDFOperator.of(pdfLib.PDFOperatorNames.BeginMarkedContent, [pdfLib.PDFName.of(SIGNIPHI_CHECKBOX_LABEL_MARKER)])
|
|
1863
|
+
);
|
|
1855
1864
|
page.drawText(field.label, { x: labelX, y: labelY, size: fontSize, font, color: pdfLib.rgb(0, 0, 0) });
|
|
1865
|
+
page.pushOperators(pdfLib.PDFOperator.of(pdfLib.PDFOperatorNames.EndMarkedContent));
|
|
1866
|
+
bakedCheckboxCaptions.set(encodedName, field);
|
|
1856
1867
|
}
|
|
1857
1868
|
}
|
|
1858
1869
|
break;
|
|
@@ -2004,8 +2015,28 @@ async function addFormFieldsToPdf(pdfBytes, formFields, options = {}) {
|
|
|
2004
2015
|
console.error(`Error adding field ${field.name}:`, error);
|
|
2005
2016
|
}
|
|
2006
2017
|
}
|
|
2018
|
+
recordBakedCheckboxCaptions(pdfDoc, bakedCheckboxCaptions);
|
|
2007
2019
|
return await pdfDoc.save();
|
|
2008
2020
|
}
|
|
2021
|
+
function recordBakedCheckboxCaptions(pdfDoc, captions) {
|
|
2022
|
+
if (captions.size === 0) return;
|
|
2023
|
+
try {
|
|
2024
|
+
const metadata = getSigniphiMetadata(pdfDoc);
|
|
2025
|
+
if (!metadata) return;
|
|
2026
|
+
metadata.fields ?? (metadata.fields = {});
|
|
2027
|
+
for (const [name, field] of captions) {
|
|
2028
|
+
metadata.fields[name] = {
|
|
2029
|
+
signer: field.assignedSignerEmail,
|
|
2030
|
+
label: field.label,
|
|
2031
|
+
...metadata.fields[name],
|
|
2032
|
+
checkboxCaptionBaked: true
|
|
2033
|
+
};
|
|
2034
|
+
}
|
|
2035
|
+
setSigniphiMetadata(pdfDoc, metadata);
|
|
2036
|
+
} catch (error) {
|
|
2037
|
+
console.warn("Failed to record baked checkbox captions:", error);
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2009
2040
|
function mapFieldPositionsAfterAssembly(fields, pageMapping) {
|
|
2010
2041
|
return fields.map((field) => {
|
|
2011
2042
|
const mappingKey = String(field.position.page - 1);
|