@signiphi/page-assembly 0.2.0-beta.10 → 0.2.0-beta.12
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 +31 -8
- package/dist/index.d.ts +31 -8
- package/dist/index.js +70 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -23
- package/dist/index.mjs.map +1 -1
- package/dist/styles/index.css +6 -73
- package/package.json +5 -2
package/dist/index.mjs
CHANGED
|
@@ -16,9 +16,7 @@ import * as TooltipPrimitive from '@radix-ui/react-tooltip';
|
|
|
16
16
|
import * as pdfjsLib from 'pdfjs-dist';
|
|
17
17
|
import { PDFDocument, PDFTextField, PDFCheckBox, PDFDropdown, PDFRadioGroup, StandardFonts, rgb, PDFName, PDFString, PDFDict, PDFArray, PDFHexString, PDFInvalidObject, PDFObjectParser, PDFRawStream, PDFObjectStreamParser, PDFRef, PDFBool, PDFNumber } from 'pdf-lib';
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
21
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
19
|
+
// src/components/PageAssembler.tsx
|
|
22
20
|
function cn(...inputs) {
|
|
23
21
|
return twMerge(clsx(inputs));
|
|
24
22
|
}
|
|
@@ -553,9 +551,8 @@ var PdfPasswordRequiredError = class extends Error {
|
|
|
553
551
|
constructor() {
|
|
554
552
|
const message = "This PDF is password-protected. Please remove the password and upload it again.";
|
|
555
553
|
super(message);
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
__publicField(this, "userMessage");
|
|
554
|
+
this.code = "PDF_PASSWORD_REQUIRED";
|
|
555
|
+
this.recoverable = true;
|
|
559
556
|
this.name = "PdfPasswordRequiredError";
|
|
560
557
|
this.userMessage = message;
|
|
561
558
|
}
|
|
@@ -564,6 +561,7 @@ var UnsupportedPdfEncryptionError = class extends Error {
|
|
|
564
561
|
constructor(detail) {
|
|
565
562
|
super(`This PDF uses an unsupported encryption scheme (${detail}).`);
|
|
566
563
|
this.name = "UnsupportedPdfEncryptionError";
|
|
564
|
+
this.detail = detail;
|
|
567
565
|
}
|
|
568
566
|
};
|
|
569
567
|
function concatBytes(...parts) {
|
|
@@ -1101,30 +1099,70 @@ async function decryptPdf(pdfBytes) {
|
|
|
1101
1099
|
if (!doc.isEncrypted) return pdfBytes;
|
|
1102
1100
|
return decryptLoadedDocument(doc);
|
|
1103
1101
|
}
|
|
1104
|
-
var
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1102
|
+
var SLASH = 47;
|
|
1103
|
+
var HASH = 35;
|
|
1104
|
+
var ENCRYPT_NAME = "Encrypt";
|
|
1105
|
+
function hexDigit(byte) {
|
|
1106
|
+
if (byte === void 0) return -1;
|
|
1107
|
+
if (byte >= 48 && byte <= 57) return byte - 48;
|
|
1108
|
+
if (byte >= 65 && byte <= 70) return byte - 65 + 10;
|
|
1109
|
+
if (byte >= 97 && byte <= 102) return byte - 97 + 10;
|
|
1110
|
+
return -1;
|
|
1111
|
+
}
|
|
1112
|
+
function matchesEncryptNameAt(bytes, start) {
|
|
1113
|
+
let at = start;
|
|
1114
|
+
for (let k = 0; k < ENCRYPT_NAME.length; k++) {
|
|
1115
|
+
const want = ENCRYPT_NAME.charCodeAt(k);
|
|
1116
|
+
const byte = bytes[at];
|
|
1117
|
+
if (byte === want) {
|
|
1118
|
+
at += 1;
|
|
1119
|
+
continue;
|
|
1110
1120
|
}
|
|
1111
|
-
|
|
1121
|
+
if (byte === HASH) {
|
|
1122
|
+
const high = hexDigit(bytes[at + 1]);
|
|
1123
|
+
const low = hexDigit(bytes[at + 2]);
|
|
1124
|
+
if (high >= 0 && low >= 0 && (high << 4 | low) === want) {
|
|
1125
|
+
at += 3;
|
|
1126
|
+
continue;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
return false;
|
|
1130
|
+
}
|
|
1131
|
+
return true;
|
|
1132
|
+
}
|
|
1133
|
+
function containsEncryptMarker(bytes) {
|
|
1134
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
1135
|
+
if (bytes[i] !== SLASH) continue;
|
|
1136
|
+
if (matchesEncryptNameAt(bytes, i + 1)) return true;
|
|
1112
1137
|
}
|
|
1113
1138
|
return false;
|
|
1114
1139
|
}
|
|
1115
|
-
async function normalizePdfEncryption(pdfBytes) {
|
|
1140
|
+
async function normalizePdfEncryption(pdfBytes, options) {
|
|
1116
1141
|
if (!containsEncryptMarker(pdfBytes)) return pdfBytes;
|
|
1117
1142
|
const doc = await PDFDocument.load(pdfBytes.slice(), {
|
|
1118
1143
|
ignoreEncryption: true,
|
|
1119
1144
|
updateMetadata: false
|
|
1120
1145
|
});
|
|
1121
1146
|
if (!doc.isEncrypted) return pdfBytes;
|
|
1122
|
-
|
|
1123
|
-
console.info("[PageAssembler] Encrypted PDF detected during ingestion; decrypting");
|
|
1124
|
-
}
|
|
1147
|
+
options?.logger?.info("[PDF_DECRYPT] Encrypted PDF detected during ingestion; decrypting");
|
|
1125
1148
|
return decryptLoadedDocument(doc);
|
|
1126
1149
|
}
|
|
1127
1150
|
|
|
1151
|
+
// src/utils/pdf-decrypt.ts
|
|
1152
|
+
var PdfPasswordRequiredError2 = PdfPasswordRequiredError;
|
|
1153
|
+
var UnsupportedPdfEncryptionError2 = UnsupportedPdfEncryptionError;
|
|
1154
|
+
var decryptPdf2 = decryptPdf;
|
|
1155
|
+
var consoleLogger = {
|
|
1156
|
+
info(message, ...args) {
|
|
1157
|
+
if (typeof process === "undefined" || process.env?.NODE_ENV !== "production") {
|
|
1158
|
+
console.info(`[PageAssembler] ${message}`, ...args);
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
function normalizePdfEncryption2(pdfBytes) {
|
|
1163
|
+
return normalizePdfEncryption(pdfBytes, { logger: consoleLogger });
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1128
1166
|
// src/utils/pdf-helpers.ts
|
|
1129
1167
|
if (typeof window !== "undefined") {
|
|
1130
1168
|
pdfjsLib.GlobalWorkerOptions.workerSrc = "/pdfjs/build/pdf.worker.mjs";
|
|
@@ -1216,7 +1254,7 @@ async function rasterizePdfToPdf(pdfBytes) {
|
|
|
1216
1254
|
sourceDoc = await pdfjsLib.getDocument({ data: pdfBytes.slice(0), verbosity: 0 }).promise;
|
|
1217
1255
|
} catch (error) {
|
|
1218
1256
|
if (error?.name === "PasswordException") {
|
|
1219
|
-
throw new
|
|
1257
|
+
throw new PdfPasswordRequiredError2();
|
|
1220
1258
|
}
|
|
1221
1259
|
throw error;
|
|
1222
1260
|
}
|
|
@@ -1248,10 +1286,10 @@ async function rasterizePdfToPdf(pdfBytes) {
|
|
|
1248
1286
|
}
|
|
1249
1287
|
async function normalizeUploadedPdfBytes(pdfBytes) {
|
|
1250
1288
|
try {
|
|
1251
|
-
const normalized = await
|
|
1289
|
+
const normalized = await normalizePdfEncryption2(pdfBytes);
|
|
1252
1290
|
return normalized === pdfBytes ? pdfBytes : new Uint8Array(normalized);
|
|
1253
1291
|
} catch (error) {
|
|
1254
|
-
if (error instanceof
|
|
1292
|
+
if (error instanceof PdfPasswordRequiredError2) throw error;
|
|
1255
1293
|
console.warn(
|
|
1256
1294
|
"[PageAssembler] Structural decryption failed; rebuilding document from rendered pages:",
|
|
1257
1295
|
error
|
|
@@ -1376,11 +1414,17 @@ function getBaseFieldName(encodedName) {
|
|
|
1376
1414
|
}
|
|
1377
1415
|
return baseName;
|
|
1378
1416
|
}
|
|
1417
|
+
function stripFieldTypeSuffix(value) {
|
|
1418
|
+
const stripped = value.replace(/_(signature|initials|date)$/i, "");
|
|
1419
|
+
return stripped || value;
|
|
1420
|
+
}
|
|
1379
1421
|
function getSignerFromFieldName(encodedName) {
|
|
1380
1422
|
if (encodedName.includes("__SIGNER__")) {
|
|
1381
1423
|
const parts = encodedName.split("__SIGNER__");
|
|
1382
1424
|
if (parts[1]) {
|
|
1383
|
-
|
|
1425
|
+
const segment = parts[1].split("__")[0] || parts[1];
|
|
1426
|
+
const isTerminal = segment === parts[1];
|
|
1427
|
+
return isTerminal ? stripFieldTypeSuffix(segment) : segment;
|
|
1384
1428
|
}
|
|
1385
1429
|
}
|
|
1386
1430
|
return void 0;
|
|
@@ -2724,7 +2768,7 @@ var PageAssembler = forwardRef(
|
|
|
2724
2768
|
dispatch({ type: "ADD_FILE", payload: fileInfo });
|
|
2725
2769
|
} catch (error) {
|
|
2726
2770
|
console.error(`Error processing file ${file.name}:`, error);
|
|
2727
|
-
if (error instanceof
|
|
2771
|
+
if (error instanceof PdfPasswordRequiredError2) {
|
|
2728
2772
|
setUploadError(`${file.name}: ${error.userMessage}`);
|
|
2729
2773
|
} else {
|
|
2730
2774
|
setUploadError(`Failed to process "${file.name}". The file may be corrupted or unsupported.`);
|
|
@@ -3306,6 +3350,6 @@ function debounce(func, wait) {
|
|
|
3306
3350
|
});
|
|
3307
3351
|
}
|
|
3308
3352
|
|
|
3309
|
-
export { Button, FormFieldType, PageAssembler, PdfPasswordRequiredError, UnsupportedPdfEncryptionError, addFormFieldsToPdf, createPdfBlobUrl, decryptPdf, downloadPdf, extractFieldsFromPdf, getSigniphiMetadata, imageToPdf, mapFieldPositionsAfterAssembly, normalizePdfEncryption, normalizeUploadedPdfBytes, pdfToImages, rasterizePdfToPdf, setSigniphiMetadata };
|
|
3353
|
+
export { Button, FormFieldType, PageAssembler, PdfPasswordRequiredError2 as PdfPasswordRequiredError, UnsupportedPdfEncryptionError2 as UnsupportedPdfEncryptionError, addFormFieldsToPdf, createPdfBlobUrl, decryptPdf2 as decryptPdf, downloadPdf, extractFieldsFromPdf, getSigniphiMetadata, imageToPdf, mapFieldPositionsAfterAssembly, normalizePdfEncryption2 as normalizePdfEncryption, normalizeUploadedPdfBytes, pdfToImages, rasterizePdfToPdf, setSigniphiMetadata };
|
|
3310
3354
|
//# sourceMappingURL=index.mjs.map
|
|
3311
3355
|
//# sourceMappingURL=index.mjs.map
|