@arbidocs/react 0.4.60 → 0.4.62
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/annotations/freeze/index.cjs +385 -15
- package/dist/annotations/freeze/index.cjs.map +1 -1
- package/dist/annotations/freeze/index.d.cts +86 -2
- package/dist/annotations/freeze/index.d.ts +86 -2
- package/dist/annotations/freeze/index.js +376 -12
- package/dist/annotations/freeze/index.js.map +1 -1
- package/dist/annotations/index.cjs +441 -39
- package/dist/annotations/index.cjs.map +1 -1
- package/dist/annotations/index.d.cts +78 -3
- package/dist/annotations/index.d.ts +78 -3
- package/dist/annotations/index.js +414 -18
- package/dist/annotations/index.js.map +1 -1
- package/dist/{chunk-JWXIRUWN.js → chunk-COWZGCL5.js} +5 -3
- package/dist/chunk-COWZGCL5.js.map +1 -0
- package/dist/{chunk-X3F5ABY2.cjs → chunk-JTNNUIXO.cjs} +3 -3
- package/dist/{chunk-X3F5ABY2.cjs.map → chunk-JTNNUIXO.cjs.map} +1 -1
- package/dist/{chunk-BGDE4DP5.cjs → chunk-SSOPIPEX.cjs} +5 -3
- package/dist/chunk-SSOPIPEX.cjs.map +1 -0
- package/dist/{chunk-CVN7MAGQ.js → chunk-YIBZJDT4.js} +3 -3
- package/dist/{chunk-CVN7MAGQ.js.map → chunk-YIBZJDT4.js.map} +1 -1
- package/dist/index.cjs +198 -198
- package/dist/index.js +4 -4
- package/dist/{model-DzQxhMMz.d.cts → model-DIwXRuGC.d.cts} +3 -0
- package/dist/{model-DzQxhMMz.d.ts → model-DIwXRuGC.d.ts} +3 -0
- package/dist/ui/index.cjs +137 -137
- package/dist/ui/index.js +2 -2
- package/package.json +4 -3
- package/dist/chunk-BGDE4DP5.cjs.map +0 -1
- package/dist/chunk-JWXIRUWN.js.map +0 -1
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkSSOPIPEX_cjs = require('../../chunk-SSOPIPEX.cjs');
|
|
4
4
|
var pdfLib = require('pdf-lib');
|
|
5
5
|
var reactPdf = require('react-pdf');
|
|
6
|
+
var qrcode = require('qrcode-generator');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var qrcode__default = /*#__PURE__*/_interopDefault(qrcode);
|
|
6
11
|
|
|
7
12
|
// src/annotations/freeze/coords.ts
|
|
8
13
|
function normaliseRotation(angle) {
|
|
@@ -265,18 +270,18 @@ function wrap(font, text, size, maxWidth) {
|
|
|
265
270
|
}
|
|
266
271
|
return lines;
|
|
267
272
|
}
|
|
268
|
-
function appendCommentAppendix(ctx, comments,
|
|
273
|
+
function appendCommentAppendix(ctx, comments, pageSize2) {
|
|
269
274
|
if (comments.length === 0) return;
|
|
270
275
|
const { doc, regular, bold, sanitiser } = ctx;
|
|
271
276
|
const margin = 54;
|
|
272
277
|
const lineHeight = 13;
|
|
273
|
-
const maxWidth =
|
|
274
|
-
let page = doc.addPage(
|
|
275
|
-
let y =
|
|
278
|
+
const maxWidth = pageSize2[0] - margin * 2;
|
|
279
|
+
let page = doc.addPage(pageSize2);
|
|
280
|
+
let y = pageSize2[1] - margin;
|
|
276
281
|
const ensure = (needed) => {
|
|
277
282
|
if (y - needed < margin) {
|
|
278
|
-
page = doc.addPage(
|
|
279
|
-
y =
|
|
283
|
+
page = doc.addPage(pageSize2);
|
|
284
|
+
y = pageSize2[1] - margin;
|
|
280
285
|
}
|
|
281
286
|
};
|
|
282
287
|
const line = (text, font, size, indent = 0) => {
|
|
@@ -445,7 +450,7 @@ function burnMarks(page, marks, options) {
|
|
|
445
450
|
}
|
|
446
451
|
}
|
|
447
452
|
for (const a of marks) {
|
|
448
|
-
if (!
|
|
453
|
+
if (!chunkSSOPIPEX_cjs.isEffectiveRedaction(a)) continue;
|
|
449
454
|
const pad = options.paddingPt * pxPerPt;
|
|
450
455
|
a.rects.forEach((r, i) => {
|
|
451
456
|
const x0 = Math.max(0, Math.floor(r.x * w - pad));
|
|
@@ -511,14 +516,14 @@ var FALLBACK_PAGE = [595.28, 841.89];
|
|
|
511
516
|
var PROVENANCE_KEY = "ArbiProvenance";
|
|
512
517
|
var KINDS = ["highlight", "box", "comment", "stamp", "redaction"];
|
|
513
518
|
async function freezePdf(original, rawLayer, options) {
|
|
514
|
-
const layer =
|
|
519
|
+
const layer = chunkSSOPIPEX_cjs.parseLayer(rawLayer);
|
|
515
520
|
const now = options.now ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
516
521
|
const comments = options.comments ?? "omit";
|
|
517
522
|
const dpi = options.dpi ?? DEFAULT_DPI;
|
|
518
523
|
if (!(dpi >= MIN_DPI && dpi <= MAX_DPI)) {
|
|
519
524
|
throw new FreezeError("invalid-option", `dpi must be between ${MIN_DPI} and ${MAX_DPI}`);
|
|
520
525
|
}
|
|
521
|
-
const redactions = layer.annotations.filter(
|
|
526
|
+
const redactions = layer.annotations.filter(chunkSSOPIPEX_cjs.isEffectiveRedaction);
|
|
522
527
|
const pending = redactions.filter((r) => r.status === "pending");
|
|
523
528
|
if (pending.length > 0 && (options.pendingRedactions ?? "error") === "error") {
|
|
524
529
|
throw new FreezeError(
|
|
@@ -526,7 +531,7 @@ async function freezePdf(original, rawLayer, options) {
|
|
|
526
531
|
`${pending.length} redaction mark(s) have not been approved or rejected`
|
|
527
532
|
);
|
|
528
533
|
}
|
|
529
|
-
const marks = layer.annotations.filter((a) => a.kind !== "redaction" ||
|
|
534
|
+
const marks = layer.annotations.filter((a) => a.kind !== "redaction" || chunkSSOPIPEX_cjs.isEffectiveRedaction(a));
|
|
530
535
|
const modeApplied = redactions.length > 0 ? "image" : options.mode;
|
|
531
536
|
const [originalSha256, layerSha256] = await Promise.all([sha256Hex(original), hashLayer(layer)]);
|
|
532
537
|
const warnings = [];
|
|
@@ -587,16 +592,18 @@ function checkPages(marks, pages) {
|
|
|
587
592
|
function checkAborted(signal) {
|
|
588
593
|
if (signal?.aborted) throw new DOMException("Freeze aborted", "AbortError");
|
|
589
594
|
}
|
|
590
|
-
async function
|
|
591
|
-
let doc;
|
|
595
|
+
async function loadPdfDocument(bytes) {
|
|
592
596
|
try {
|
|
593
|
-
|
|
597
|
+
return await pdfLib.PDFDocument.load(bytes);
|
|
594
598
|
} catch (error) {
|
|
595
599
|
if (error instanceof pdfLib.EncryptedPDFError || /is encrypted/i.test(error?.message ?? "")) {
|
|
596
600
|
throw new FreezeError("encrypted", ENCRYPTED_MESSAGE);
|
|
597
601
|
}
|
|
598
602
|
throw new FreezeError("invalid-pdf", `The PDF could not be read: ${error.message}`);
|
|
599
603
|
}
|
|
604
|
+
}
|
|
605
|
+
async function freezeAsVector(original, marks, comments, now, warnings) {
|
|
606
|
+
const doc = await loadPdfDocument(original);
|
|
600
607
|
const pages = doc.getPages();
|
|
601
608
|
checkPages(marks, pages.length);
|
|
602
609
|
const ctx = await createVectorContext(doc, marks, comments);
|
|
@@ -722,7 +729,7 @@ async function readProvenance(bytes) {
|
|
|
722
729
|
return JSON.parse(value.decodeText());
|
|
723
730
|
}
|
|
724
731
|
async function freezePdfInBrowser(bytes, layer, { assets, password, ...options }) {
|
|
725
|
-
const needsRaster = options.mode === "image" || layer.annotations.some(
|
|
732
|
+
const needsRaster = options.mode === "image" || layer.annotations.some(chunkSSOPIPEX_cjs.isEffectiveRedaction);
|
|
726
733
|
const rasterizer = needsRaster ? await createPdfJsRasterizer(reactPdf.pdfjs, bytes, browserCanvasFactory(), {
|
|
727
734
|
password,
|
|
728
735
|
documentOptions: {
|
|
@@ -734,11 +741,374 @@ async function freezePdfInBrowser(bytes, layer, { assets, password, ...options }
|
|
|
734
741
|
}) : void 0;
|
|
735
742
|
return freezePdf(bytes, layer, { ...options, rasterizer });
|
|
736
743
|
}
|
|
744
|
+
var EDGE_MARGIN_PT = 18;
|
|
745
|
+
var BATES_FONT_SIZE_PT = 9;
|
|
746
|
+
var QR_SIZE_PT = 56;
|
|
747
|
+
var QR_QUIET_MODULES = 2;
|
|
748
|
+
var PLATE_PADDING_PT = 2;
|
|
749
|
+
function batesLabel(options, index) {
|
|
750
|
+
const digits = options.digits ?? 6;
|
|
751
|
+
const number = String(Math.floor((options.start ?? 1) + index)).padStart(digits, "0");
|
|
752
|
+
return `${options.prefix ?? ""}${number}`;
|
|
753
|
+
}
|
|
754
|
+
function validateBates(options) {
|
|
755
|
+
const { start = 1, digits = 6 } = options;
|
|
756
|
+
if (!Number.isInteger(start) || start < 0) {
|
|
757
|
+
throw new FreezeError("invalid-option", "Bates start must be a whole number, 0 or more");
|
|
758
|
+
}
|
|
759
|
+
if (!Number.isInteger(digits) || digits < 1 || digits > 12) {
|
|
760
|
+
throw new FreezeError("invalid-option", "Bates digits must be a whole number from 1 to 12");
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
function plateOrigin(g, corner, w, h) {
|
|
764
|
+
const size = displayedSize(g);
|
|
765
|
+
return {
|
|
766
|
+
x: corner.endsWith("left") ? EDGE_MARGIN_PT : size.width - EDGE_MARGIN_PT - w,
|
|
767
|
+
y: corner.startsWith("top") ? EDGE_MARGIN_PT : size.height - EDGE_MARGIN_PT - h
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
function drawPlate(page, g, box) {
|
|
771
|
+
const size = displayedSize(g);
|
|
772
|
+
const u = normToUserRect(g, {
|
|
773
|
+
x: box.x / size.width,
|
|
774
|
+
y: box.y / size.height,
|
|
775
|
+
w: box.w / size.width,
|
|
776
|
+
h: box.h / size.height
|
|
777
|
+
});
|
|
778
|
+
page.drawRectangle({ x: u.x, y: u.y, width: u.width, height: u.height, color: pdfLib.rgb(1, 1, 1) });
|
|
779
|
+
}
|
|
780
|
+
function drawBatesLabel(page, label, font, corner) {
|
|
781
|
+
const g = pageGeometry(page);
|
|
782
|
+
const textWidth = font.widthOfTextAtSize(label, BATES_FONT_SIZE_PT);
|
|
783
|
+
const w = textWidth + PLATE_PADDING_PT * 2;
|
|
784
|
+
const h = BATES_FONT_SIZE_PT + PLATE_PADDING_PT * 2;
|
|
785
|
+
const { x, y } = plateOrigin(g, corner, w, h);
|
|
786
|
+
drawPlate(page, g, { x, y, w, h });
|
|
787
|
+
const origin = displayedToUser(
|
|
788
|
+
g,
|
|
789
|
+
x + PLATE_PADDING_PT,
|
|
790
|
+
y + PLATE_PADDING_PT + BATES_FONT_SIZE_PT * 0.8
|
|
791
|
+
);
|
|
792
|
+
page.drawText(label, {
|
|
793
|
+
x: origin.x,
|
|
794
|
+
y: origin.y,
|
|
795
|
+
size: BATES_FONT_SIZE_PT,
|
|
796
|
+
font,
|
|
797
|
+
color: pdfLib.rgb(0, 0, 0),
|
|
798
|
+
rotate: pdfLib.degrees(g.rotation)
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
function buildQr(text) {
|
|
802
|
+
try {
|
|
803
|
+
const qr = qrcode__default.default(0, "M");
|
|
804
|
+
qr.addData(text, "Byte");
|
|
805
|
+
qr.make();
|
|
806
|
+
return { modules: qr.getModuleCount(), isDark: (r, c) => qr.isDark(r, c) };
|
|
807
|
+
} catch (error) {
|
|
808
|
+
throw new FreezeError(
|
|
809
|
+
"invalid-option",
|
|
810
|
+
`The QR link could not be encoded: ${error.message}`
|
|
811
|
+
);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
function drawQr(page, qr, corner) {
|
|
815
|
+
const g = pageGeometry(page);
|
|
816
|
+
const total = qr.modules + QR_QUIET_MODULES * 2;
|
|
817
|
+
const module = QR_SIZE_PT / total;
|
|
818
|
+
const { x, y } = plateOrigin(g, corner, QR_SIZE_PT, QR_SIZE_PT);
|
|
819
|
+
drawPlate(page, g, { x, y, w: QR_SIZE_PT, h: QR_SIZE_PT });
|
|
820
|
+
const size = displayedSize(g);
|
|
821
|
+
for (let row = 0; row < qr.modules; row++) {
|
|
822
|
+
let col = 0;
|
|
823
|
+
while (col < qr.modules) {
|
|
824
|
+
if (!qr.isDark(row, col)) {
|
|
825
|
+
col++;
|
|
826
|
+
continue;
|
|
827
|
+
}
|
|
828
|
+
const startCol = col;
|
|
829
|
+
while (col < qr.modules && qr.isDark(row, col)) col++;
|
|
830
|
+
const u = normToUserRect(g, {
|
|
831
|
+
x: (x + (QR_QUIET_MODULES + startCol) * module) / size.width,
|
|
832
|
+
y: (y + (QR_QUIET_MODULES + row) * module) / size.height,
|
|
833
|
+
w: (col - startCol) * module / size.width,
|
|
834
|
+
h: module / size.height
|
|
835
|
+
});
|
|
836
|
+
page.drawRectangle({
|
|
837
|
+
x: u.x,
|
|
838
|
+
y: u.y,
|
|
839
|
+
width: u.width,
|
|
840
|
+
height: u.height,
|
|
841
|
+
color: pdfLib.rgb(0, 0, 0)
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
var A4 = [595.28, 841.89];
|
|
847
|
+
var MARGIN = 54;
|
|
848
|
+
var LINE = 13;
|
|
849
|
+
var TEXT = pdfLib.rgb(0.1, 0.1, 0.1);
|
|
850
|
+
var MUTED = pdfLib.rgb(0.4, 0.4, 0.4);
|
|
851
|
+
async function insertIndexPages(doc, entries, options) {
|
|
852
|
+
const regular = await doc.embedFont(pdfLib.StandardFonts.Helvetica);
|
|
853
|
+
const bold = await doc.embedFont(pdfLib.StandardFonts.HelveticaBold);
|
|
854
|
+
const sanitiser = new TextSanitiser(regular);
|
|
855
|
+
const [width, height] = options.size ?? A4;
|
|
856
|
+
const columns = {
|
|
857
|
+
number: MARGIN,
|
|
858
|
+
name: MARGIN + 28,
|
|
859
|
+
range: width - MARGIN - 190,
|
|
860
|
+
pages: width - MARGIN - 30
|
|
861
|
+
};
|
|
862
|
+
const nameWidth = columns.range - columns.name - 12;
|
|
863
|
+
let inserted = 0;
|
|
864
|
+
let page;
|
|
865
|
+
let y = 0;
|
|
866
|
+
const newPage = () => {
|
|
867
|
+
page = doc.insertPage(inserted++, [width, height]);
|
|
868
|
+
y = height - MARGIN;
|
|
869
|
+
};
|
|
870
|
+
const text = (value, x, font, size, color = TEXT) => page.drawText(sanitiser.clean(value), { x, y: y - size, size, font, color });
|
|
871
|
+
const header = () => {
|
|
872
|
+
text("#", columns.number, bold, 9, MUTED);
|
|
873
|
+
text("Document", columns.name, bold, 9, MUTED);
|
|
874
|
+
text("Bates range", columns.range, bold, 9, MUTED);
|
|
875
|
+
text("Pages", columns.pages, bold, 9, MUTED);
|
|
876
|
+
y -= LINE + 4;
|
|
877
|
+
};
|
|
878
|
+
newPage();
|
|
879
|
+
text("Production index", MARGIN, bold, 16);
|
|
880
|
+
y -= 24;
|
|
881
|
+
const first = entries[0]?.firstLabel;
|
|
882
|
+
const last = entries[entries.length - 1]?.lastLabel;
|
|
883
|
+
const total = entries.reduce((n, e) => n + e.pages, 0);
|
|
884
|
+
const summary = [
|
|
885
|
+
`${entries.length} document${entries.length === 1 ? "" : "s"}, ${total} page${total === 1 ? "" : "s"}`,
|
|
886
|
+
first && last ? `${first} to ${last}` : "",
|
|
887
|
+
`produced ${options.producedAt.slice(0, 10)}`,
|
|
888
|
+
options.producedBy ? `by ${options.producedBy}` : ""
|
|
889
|
+
].filter(Boolean).join(", ");
|
|
890
|
+
text(summary, MARGIN, regular, 10, MUTED);
|
|
891
|
+
y -= LINE + 10;
|
|
892
|
+
header();
|
|
893
|
+
const rangeWidth = columns.pages - columns.range - 8;
|
|
894
|
+
entries.forEach((entry, i) => {
|
|
895
|
+
const lines = wrap(regular, sanitiser.clean(entry.name), 10, nameWidth);
|
|
896
|
+
const single = entry.firstLabel === entry.lastLabel ? entry.firstLabel : `${entry.firstLabel} - ${entry.lastLabel}`;
|
|
897
|
+
const range = regular.widthOfTextAtSize(sanitiser.clean(single), 10) <= rangeWidth ? [single] : [`${entry.firstLabel} -`, entry.lastLabel];
|
|
898
|
+
const rows = Math.max(lines.length, range.length);
|
|
899
|
+
if (y - rows * LINE < MARGIN) {
|
|
900
|
+
newPage();
|
|
901
|
+
header();
|
|
902
|
+
}
|
|
903
|
+
const top = y;
|
|
904
|
+
text(String(i + 1), columns.number, regular, 10);
|
|
905
|
+
text(String(entry.pages), columns.pages, regular, 10);
|
|
906
|
+
range.forEach((line, n) => {
|
|
907
|
+
y = top - n * LINE;
|
|
908
|
+
text(line, columns.range, regular, 10);
|
|
909
|
+
});
|
|
910
|
+
lines.forEach((line, n) => {
|
|
911
|
+
y = top - n * LINE;
|
|
912
|
+
text(line, columns.name, regular, 10);
|
|
913
|
+
});
|
|
914
|
+
y = top - rows * LINE - 4;
|
|
915
|
+
});
|
|
916
|
+
return inserted;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
// src/annotations/freeze/bundle.ts
|
|
920
|
+
var BUNDLE_KEY = "ArbiBundle";
|
|
921
|
+
var DEFAULT_QR_CORNER = "bottom-left";
|
|
922
|
+
var DEFAULT_BATES_CORNER = "bottom-right";
|
|
923
|
+
function checkAborted2(signal) {
|
|
924
|
+
if (signal?.aborted) throw new DOMException("Bundle aborted", "AbortError");
|
|
925
|
+
}
|
|
926
|
+
function outputName(name, used) {
|
|
927
|
+
const base = (name.replace(/\.pdf$/i, "").replace(/[\\/:*?"<>|]+/g, "_").trim() || "document") + ".pdf";
|
|
928
|
+
let candidate = base;
|
|
929
|
+
for (let n = 2; used.has(candidate); n++) candidate = base.replace(/\.pdf$/, `-${n}.pdf`);
|
|
930
|
+
used.add(candidate);
|
|
931
|
+
return candidate;
|
|
932
|
+
}
|
|
933
|
+
function validate(items, options) {
|
|
934
|
+
if (items.length === 0)
|
|
935
|
+
throw new FreezeError("invalid-option", "A bundle needs at least one document");
|
|
936
|
+
validateBates(options.bates);
|
|
937
|
+
if (options.qr) {
|
|
938
|
+
const missing = items.find((i) => !i.qrUrl);
|
|
939
|
+
if (missing) {
|
|
940
|
+
throw new FreezeError("invalid-option", `"${missing.name}" has no link for its QR code`);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
const corner = options.bates.corner ?? DEFAULT_BATES_CORNER;
|
|
944
|
+
if (options.qr && (options.qrCorner ?? DEFAULT_QR_CORNER) === corner) {
|
|
945
|
+
throw new FreezeError(
|
|
946
|
+
"invalid-option",
|
|
947
|
+
"The Bates label and the QR code need different corners"
|
|
948
|
+
);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
async function stampPages(doc, items, firstIndex, options) {
|
|
952
|
+
const font = await doc.embedFont(pdfLib.StandardFonts.Helvetica);
|
|
953
|
+
const sanitiser = new TextSanitiser(font);
|
|
954
|
+
const label = batesLabel(options.bates, firstIndex);
|
|
955
|
+
if (!sanitiser.supports(label)) {
|
|
956
|
+
throw new FreezeError(
|
|
957
|
+
"unsupported-text",
|
|
958
|
+
`Bates prefix "${options.bates.prefix}" uses characters the built-in font cannot draw`
|
|
959
|
+
);
|
|
960
|
+
}
|
|
961
|
+
const pages = doc.getPages();
|
|
962
|
+
const corner = options.bates.corner ?? DEFAULT_BATES_CORNER;
|
|
963
|
+
let at = 0;
|
|
964
|
+
for (const item of items) {
|
|
965
|
+
const qr = options.qr && item.qrUrl ? buildQr(item.qrUrl) : void 0;
|
|
966
|
+
for (let p = 0; p < item.pages; p++, at++) {
|
|
967
|
+
const page = pages[at];
|
|
968
|
+
drawBatesLabel(page, batesLabel(options.bates, firstIndex + at), font, corner);
|
|
969
|
+
if (qr) drawQr(page, qr, options.qrCorner ?? DEFAULT_QR_CORNER);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
function setBundleRecord(doc, record) {
|
|
974
|
+
const info = doc.context.lookup(doc.context.trailerInfo.Info);
|
|
975
|
+
if (!info || !("set" in info)) return;
|
|
976
|
+
info.set(
|
|
977
|
+
pdfLib.PDFName.of(BUNDLE_KEY),
|
|
978
|
+
pdfLib.PDFHexString.fromText(JSON.stringify(record))
|
|
979
|
+
);
|
|
980
|
+
}
|
|
981
|
+
async function buildBundle(items, options) {
|
|
982
|
+
validate(items, options);
|
|
983
|
+
const now = options.now ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
984
|
+
const used = /* @__PURE__ */ new Set();
|
|
985
|
+
const files = [];
|
|
986
|
+
const index = [];
|
|
987
|
+
const loaded = [];
|
|
988
|
+
for (const item of items) {
|
|
989
|
+
checkAborted2(options.signal);
|
|
990
|
+
const doc = await loadPdfDocument(item.bytes);
|
|
991
|
+
loaded.push({ item, doc, pages: doc.getPageCount() });
|
|
992
|
+
}
|
|
993
|
+
if (options.layout === "merged") {
|
|
994
|
+
const out = await pdfLib.PDFDocument.create();
|
|
995
|
+
out.setProducer("ARBI");
|
|
996
|
+
out.setCreator("ARBI");
|
|
997
|
+
out.setCreationDate(new Date(now));
|
|
998
|
+
out.setModificationDate(new Date(now));
|
|
999
|
+
const provenance = {};
|
|
1000
|
+
for (const { item, doc } of loaded) {
|
|
1001
|
+
checkAborted2(options.signal);
|
|
1002
|
+
for (const page of await out.copyPages(doc, doc.getPageIndices())) out.addPage(page);
|
|
1003
|
+
provenance[item.documentId] = await readProvenance(item.bytes).catch(() => null);
|
|
1004
|
+
}
|
|
1005
|
+
await stampPages(
|
|
1006
|
+
out,
|
|
1007
|
+
loaded.map(({ item, pages }) => ({ pages, qrUrl: item.qrUrl })),
|
|
1008
|
+
0,
|
|
1009
|
+
options
|
|
1010
|
+
);
|
|
1011
|
+
const file = outputName(options.mergedName ?? "production.pdf", used);
|
|
1012
|
+
let first2 = 0;
|
|
1013
|
+
for (const { item, pages } of loaded) {
|
|
1014
|
+
index.push({
|
|
1015
|
+
documentId: item.documentId,
|
|
1016
|
+
name: item.name,
|
|
1017
|
+
file,
|
|
1018
|
+
pages,
|
|
1019
|
+
firstLabel: batesLabel(options.bates, first2),
|
|
1020
|
+
lastLabel: batesLabel(options.bates, first2 + pages - 1)
|
|
1021
|
+
});
|
|
1022
|
+
first2 += pages;
|
|
1023
|
+
}
|
|
1024
|
+
const indexPages2 = options.indexPage ? await insertIndexPages(out, index, {
|
|
1025
|
+
size: pageSize(loaded[0].doc),
|
|
1026
|
+
producedAt: now,
|
|
1027
|
+
producedBy: options.author
|
|
1028
|
+
}) : 0;
|
|
1029
|
+
setBundleRecord(out, {
|
|
1030
|
+
schema: 1,
|
|
1031
|
+
producedAt: now,
|
|
1032
|
+
...indexPages2 ? { indexPages: indexPages2 } : {},
|
|
1033
|
+
...options.author ? { producedBy: options.author } : {},
|
|
1034
|
+
layout: "merged",
|
|
1035
|
+
items: index.map((e) => ({
|
|
1036
|
+
documentId: e.documentId,
|
|
1037
|
+
name: e.name,
|
|
1038
|
+
pages: e.pages,
|
|
1039
|
+
firstLabel: e.firstLabel,
|
|
1040
|
+
lastLabel: e.lastLabel,
|
|
1041
|
+
frozen: provenance[e.documentId] ?? null
|
|
1042
|
+
}))
|
|
1043
|
+
});
|
|
1044
|
+
const total = first2;
|
|
1045
|
+
files.push({
|
|
1046
|
+
name: file,
|
|
1047
|
+
bytes: await out.save(),
|
|
1048
|
+
pages: total + indexPages2,
|
|
1049
|
+
firstLabel: batesLabel(options.bates, 0),
|
|
1050
|
+
lastLabel: batesLabel(options.bates, total - 1)
|
|
1051
|
+
});
|
|
1052
|
+
options.onProgress?.(loaded.length, loaded.length);
|
|
1053
|
+
return { files, index, indexPages: indexPages2 };
|
|
1054
|
+
}
|
|
1055
|
+
let first = 0;
|
|
1056
|
+
for (const [n, { item, doc, pages }] of loaded.entries()) {
|
|
1057
|
+
checkAborted2(options.signal);
|
|
1058
|
+
await stampPages(doc, [{ pages, qrUrl: item.qrUrl }], first, options);
|
|
1059
|
+
doc.setModificationDate(new Date(now));
|
|
1060
|
+
const file = outputName(item.name, used);
|
|
1061
|
+
const entry = {
|
|
1062
|
+
documentId: item.documentId,
|
|
1063
|
+
name: item.name,
|
|
1064
|
+
file,
|
|
1065
|
+
pages,
|
|
1066
|
+
firstLabel: batesLabel(options.bates, first),
|
|
1067
|
+
lastLabel: batesLabel(options.bates, first + pages - 1)
|
|
1068
|
+
};
|
|
1069
|
+
index.push(entry);
|
|
1070
|
+
files.push({
|
|
1071
|
+
name: file,
|
|
1072
|
+
bytes: await doc.save(),
|
|
1073
|
+
pages,
|
|
1074
|
+
firstLabel: entry.firstLabel,
|
|
1075
|
+
lastLabel: entry.lastLabel
|
|
1076
|
+
});
|
|
1077
|
+
first += pages;
|
|
1078
|
+
options.onProgress?.(n + 1, loaded.length);
|
|
1079
|
+
}
|
|
1080
|
+
if (!options.indexPage) return { files, index, indexPages: 0 };
|
|
1081
|
+
const cover = await pdfLib.PDFDocument.create();
|
|
1082
|
+
cover.setProducer("ARBI");
|
|
1083
|
+
cover.setCreator("ARBI");
|
|
1084
|
+
cover.setCreationDate(new Date(now));
|
|
1085
|
+
const indexPages = await insertIndexPages(cover, index, {
|
|
1086
|
+
size: pageSize(loaded[0].doc),
|
|
1087
|
+
producedAt: now,
|
|
1088
|
+
producedBy: options.author
|
|
1089
|
+
});
|
|
1090
|
+
files.unshift({
|
|
1091
|
+
name: outputName("index.pdf", used),
|
|
1092
|
+
bytes: await cover.save(),
|
|
1093
|
+
pages: indexPages,
|
|
1094
|
+
firstLabel: "",
|
|
1095
|
+
lastLabel: ""
|
|
1096
|
+
});
|
|
1097
|
+
return { files, index, indexPages };
|
|
1098
|
+
}
|
|
1099
|
+
function pageSize(doc) {
|
|
1100
|
+
const page = doc.getPage(0);
|
|
1101
|
+
const { width, height } = page.getSize();
|
|
1102
|
+
const turned = page.getRotation().angle % 180 !== 0;
|
|
1103
|
+
return turned ? [height, width] : [width, height];
|
|
1104
|
+
}
|
|
737
1105
|
|
|
738
1106
|
exports.DEFAULT_DPI = DEFAULT_DPI;
|
|
739
1107
|
exports.FreezeError = FreezeError;
|
|
740
1108
|
exports.MAX_PAGE_PIXELS = MAX_PAGE_PIXELS;
|
|
1109
|
+
exports.batesLabel = batesLabel;
|
|
741
1110
|
exports.browserCanvasFactory = browserCanvasFactory;
|
|
1111
|
+
exports.buildBundle = buildBundle;
|
|
742
1112
|
exports.burnMarks = burnMarks;
|
|
743
1113
|
exports.createPdfJsRasterizer = createPdfJsRasterizer;
|
|
744
1114
|
exports.freezePdf = freezePdf;
|