@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.
@@ -1,4 +1,4 @@
1
- import { a as AnnotationKind, b as AnnotationLayer, A as Annotation } from '../../model-DzQxhMMz.js';
1
+ import { a as AnnotationKind, b as AnnotationLayer, A as Annotation } from '../../model-DIwXRuGC.js';
2
2
  import { a as PdfViewerAssets } from '../../PdfViewer-bQH9yxFg.js';
3
3
  import 'react';
4
4
 
@@ -133,6 +133,90 @@ type BrowserFreezeOptions = Omit<FreezeOptions, 'rasterizer'> & {
133
133
  };
134
134
  declare function freezePdfInBrowser(bytes: Uint8Array, layer: AnnotationLayer, { assets, password, ...options }: BrowserFreezeOptions): Promise<FreezeResult>;
135
135
 
136
+ /**
137
+ * Page stamps for a production set: a Bates label and an optional QR code. Both are drawn as
138
+ * plain vector content on a white plate, in the DISPLAYED frame, so cropped and rotated pages come
139
+ * out upright. They are added to a document that is already frozen: nothing here can bring back
140
+ * content a redaction removed.
141
+ */
142
+
143
+ type StampCorner = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
144
+ interface BatesOptions {
145
+ /** Text before the number, e.g. `ACME-`. Plain characters a standard font can draw. */
146
+ prefix?: string;
147
+ /** First number. Default 1. */
148
+ start?: number;
149
+ /** Zero-pad the number to this many digits. Default 6. */
150
+ digits?: number;
151
+ corner?: StampCorner;
152
+ }
153
+ declare function batesLabel(options: BatesOptions, index: number): string;
154
+
155
+ /**
156
+ * Production bundle: take documents that are ALREADY frozen (or never needed freezing) and number
157
+ * them consecutively with a Bates label, optionally adding a QR code that links back to the
158
+ * document in ARBI.
159
+ *
160
+ * `merged` joins the documents into one PDF; `per-document` keeps one PDF each. Either way the
161
+ * numbering runs on across the whole set in the order given, so a label is unique within the
162
+ * production. Splitting a document is deliberately not part of this.
163
+ *
164
+ * `indexPage` adds an index first (every document with its Bates range): the first page(s) of a
165
+ * merged file, or an `index.pdf` of its own ahead of the per-document files. It is not numbered.
166
+ */
167
+
168
+ type BundleLayout = 'merged' | 'per-document';
169
+ interface BundleItem {
170
+ /** Shown in the index and used to name the output file. */
171
+ name: string;
172
+ /** External id of the document this PDF represents. */
173
+ documentId: string;
174
+ /** PDF bytes, normally the output of `freezePdf`. */
175
+ bytes: Uint8Array;
176
+ /** What the QR code opens. Required for every item when `qr` is on. */
177
+ qrUrl?: string;
178
+ }
179
+ interface BundleOptions {
180
+ layout: BundleLayout;
181
+ bates: BatesOptions;
182
+ /** Add a QR code (to each item's `qrUrl`) on every page. Default false. */
183
+ qr?: boolean;
184
+ qrCorner?: StampCorner;
185
+ /** Name of the merged file. Default `production.pdf`. */
186
+ mergedName?: string;
187
+ /** Put an index page (documents and Bates ranges) at the start. Default false. */
188
+ indexPage?: boolean;
189
+ /** ISO timestamp; defaults to now. Injectable for deterministic tests. */
190
+ now?: string;
191
+ /** Who produced the set; recorded in a merged file's metadata. */
192
+ author?: string;
193
+ onProgress?: (done: number, total: number) => void;
194
+ signal?: AbortSignal;
195
+ }
196
+ interface BundleIndexEntry {
197
+ documentId: string;
198
+ name: string;
199
+ /** The output file that holds this document. */
200
+ file: string;
201
+ pages: number;
202
+ firstLabel: string;
203
+ lastLabel: string;
204
+ }
205
+ interface BundleFile {
206
+ name: string;
207
+ bytes: Uint8Array;
208
+ pages: number;
209
+ firstLabel: string;
210
+ lastLabel: string;
211
+ }
212
+ interface BundleResult {
213
+ files: BundleFile[];
214
+ index: BundleIndexEntry[];
215
+ /** Index pages added at the start (0 without `indexPage`). */
216
+ indexPages: number;
217
+ }
218
+ declare function buildBundle(items: BundleItem[], options: BundleOptions): Promise<BundleResult>;
219
+
136
220
  /**
137
221
  * Image-only freeze: render each page onto a canvas, burn the marks into the pixels, and encode.
138
222
  * Once a redaction rectangle is painted black the original pixels are gone, and the rebuilt PDF
@@ -196,4 +280,4 @@ interface BurnOptions {
196
280
  /** Paint every mark for one page onto its rendered pixels. Redactions go last, on top. */
197
281
  declare function burnMarks(page: RenderedPage, marks: Annotation[], options: BurnOptions): void;
198
282
 
199
- export { type BrowserFreezeOptions, type BurnOptions, type CanvasFactory, type CanvasHandle, type CommentOutput, DEFAULT_DPI, FreezeError, type FreezeErrorCode, type FreezeMode, type FreezeOptions, type FreezeProvenance, type FreezeResult, MAX_PAGE_PIXELS, type OcrInput, type OcrWord, type PageRasterizer, type PdfJsModule, type PdfJsRasterizerOptions, type RenderedPage, browserCanvasFactory, burnMarks, createPdfJsRasterizer, freezePdf, freezePdfInBrowser, readProvenance };
283
+ export { type BatesOptions, type BrowserFreezeOptions, type BundleFile, type BundleIndexEntry, type BundleItem, type BundleLayout, type BundleOptions, type BundleResult, type BurnOptions, type CanvasFactory, type CanvasHandle, type CommentOutput, DEFAULT_DPI, FreezeError, type FreezeErrorCode, type FreezeMode, type FreezeOptions, type FreezeProvenance, type FreezeResult, MAX_PAGE_PIXELS, type OcrInput, type OcrWord, type PageRasterizer, type PdfJsModule, type PdfJsRasterizerOptions, type RenderedPage, type StampCorner, batesLabel, browserCanvasFactory, buildBundle, burnMarks, createPdfJsRasterizer, freezePdf, freezePdfInBrowser, readProvenance };
@@ -1,6 +1,7 @@
1
- import { isEffectiveRedaction, parseLayer } from '../../chunk-JWXIRUWN.js';
2
- import { PDFDocument, EncryptedPDFError, StandardFonts, rgb, PDFName, PDFHexString, BlendMode, degrees } from 'pdf-lib';
1
+ import { isEffectiveRedaction, parseLayer } from '../../chunk-COWZGCL5.js';
2
+ import { rgb, PDFDocument, StandardFonts, PDFName, PDFHexString, EncryptedPDFError, BlendMode, degrees } from 'pdf-lib';
3
3
  import { pdfjs } from 'react-pdf';
4
+ import qrcode from 'qrcode-generator';
4
5
 
5
6
  // src/annotations/freeze/coords.ts
6
7
  function normaliseRotation(angle) {
@@ -263,18 +264,18 @@ function wrap(font, text, size, maxWidth) {
263
264
  }
264
265
  return lines;
265
266
  }
266
- function appendCommentAppendix(ctx, comments, pageSize) {
267
+ function appendCommentAppendix(ctx, comments, pageSize2) {
267
268
  if (comments.length === 0) return;
268
269
  const { doc, regular, bold, sanitiser } = ctx;
269
270
  const margin = 54;
270
271
  const lineHeight = 13;
271
- const maxWidth = pageSize[0] - margin * 2;
272
- let page = doc.addPage(pageSize);
273
- let y = pageSize[1] - margin;
272
+ const maxWidth = pageSize2[0] - margin * 2;
273
+ let page = doc.addPage(pageSize2);
274
+ let y = pageSize2[1] - margin;
274
275
  const ensure = (needed) => {
275
276
  if (y - needed < margin) {
276
- page = doc.addPage(pageSize);
277
- y = pageSize[1] - margin;
277
+ page = doc.addPage(pageSize2);
278
+ y = pageSize2[1] - margin;
278
279
  }
279
280
  };
280
281
  const line = (text, font, size, indent = 0) => {
@@ -585,16 +586,18 @@ function checkPages(marks, pages) {
585
586
  function checkAborted(signal) {
586
587
  if (signal?.aborted) throw new DOMException("Freeze aborted", "AbortError");
587
588
  }
588
- async function freezeAsVector(original, marks, comments, now, warnings) {
589
- let doc;
589
+ async function loadPdfDocument(bytes) {
590
590
  try {
591
- doc = await PDFDocument.load(original);
591
+ return await PDFDocument.load(bytes);
592
592
  } catch (error) {
593
593
  if (error instanceof EncryptedPDFError || /is encrypted/i.test(error?.message ?? "")) {
594
594
  throw new FreezeError("encrypted", ENCRYPTED_MESSAGE);
595
595
  }
596
596
  throw new FreezeError("invalid-pdf", `The PDF could not be read: ${error.message}`);
597
597
  }
598
+ }
599
+ async function freezeAsVector(original, marks, comments, now, warnings) {
600
+ const doc = await loadPdfDocument(original);
598
601
  const pages = doc.getPages();
599
602
  checkPages(marks, pages.length);
600
603
  const ctx = await createVectorContext(doc, marks, comments);
@@ -732,7 +735,368 @@ async function freezePdfInBrowser(bytes, layer, { assets, password, ...options }
732
735
  }) : void 0;
733
736
  return freezePdf(bytes, layer, { ...options, rasterizer });
734
737
  }
738
+ var EDGE_MARGIN_PT = 18;
739
+ var BATES_FONT_SIZE_PT = 9;
740
+ var QR_SIZE_PT = 56;
741
+ var QR_QUIET_MODULES = 2;
742
+ var PLATE_PADDING_PT = 2;
743
+ function batesLabel(options, index) {
744
+ const digits = options.digits ?? 6;
745
+ const number = String(Math.floor((options.start ?? 1) + index)).padStart(digits, "0");
746
+ return `${options.prefix ?? ""}${number}`;
747
+ }
748
+ function validateBates(options) {
749
+ const { start = 1, digits = 6 } = options;
750
+ if (!Number.isInteger(start) || start < 0) {
751
+ throw new FreezeError("invalid-option", "Bates start must be a whole number, 0 or more");
752
+ }
753
+ if (!Number.isInteger(digits) || digits < 1 || digits > 12) {
754
+ throw new FreezeError("invalid-option", "Bates digits must be a whole number from 1 to 12");
755
+ }
756
+ }
757
+ function plateOrigin(g, corner, w, h) {
758
+ const size = displayedSize(g);
759
+ return {
760
+ x: corner.endsWith("left") ? EDGE_MARGIN_PT : size.width - EDGE_MARGIN_PT - w,
761
+ y: corner.startsWith("top") ? EDGE_MARGIN_PT : size.height - EDGE_MARGIN_PT - h
762
+ };
763
+ }
764
+ function drawPlate(page, g, box) {
765
+ const size = displayedSize(g);
766
+ const u = normToUserRect(g, {
767
+ x: box.x / size.width,
768
+ y: box.y / size.height,
769
+ w: box.w / size.width,
770
+ h: box.h / size.height
771
+ });
772
+ page.drawRectangle({ x: u.x, y: u.y, width: u.width, height: u.height, color: rgb(1, 1, 1) });
773
+ }
774
+ function drawBatesLabel(page, label, font, corner) {
775
+ const g = pageGeometry(page);
776
+ const textWidth = font.widthOfTextAtSize(label, BATES_FONT_SIZE_PT);
777
+ const w = textWidth + PLATE_PADDING_PT * 2;
778
+ const h = BATES_FONT_SIZE_PT + PLATE_PADDING_PT * 2;
779
+ const { x, y } = plateOrigin(g, corner, w, h);
780
+ drawPlate(page, g, { x, y, w, h });
781
+ const origin = displayedToUser(
782
+ g,
783
+ x + PLATE_PADDING_PT,
784
+ y + PLATE_PADDING_PT + BATES_FONT_SIZE_PT * 0.8
785
+ );
786
+ page.drawText(label, {
787
+ x: origin.x,
788
+ y: origin.y,
789
+ size: BATES_FONT_SIZE_PT,
790
+ font,
791
+ color: rgb(0, 0, 0),
792
+ rotate: degrees(g.rotation)
793
+ });
794
+ }
795
+ function buildQr(text) {
796
+ try {
797
+ const qr = qrcode(0, "M");
798
+ qr.addData(text, "Byte");
799
+ qr.make();
800
+ return { modules: qr.getModuleCount(), isDark: (r, c) => qr.isDark(r, c) };
801
+ } catch (error) {
802
+ throw new FreezeError(
803
+ "invalid-option",
804
+ `The QR link could not be encoded: ${error.message}`
805
+ );
806
+ }
807
+ }
808
+ function drawQr(page, qr, corner) {
809
+ const g = pageGeometry(page);
810
+ const total = qr.modules + QR_QUIET_MODULES * 2;
811
+ const module = QR_SIZE_PT / total;
812
+ const { x, y } = plateOrigin(g, corner, QR_SIZE_PT, QR_SIZE_PT);
813
+ drawPlate(page, g, { x, y, w: QR_SIZE_PT, h: QR_SIZE_PT });
814
+ const size = displayedSize(g);
815
+ for (let row = 0; row < qr.modules; row++) {
816
+ let col = 0;
817
+ while (col < qr.modules) {
818
+ if (!qr.isDark(row, col)) {
819
+ col++;
820
+ continue;
821
+ }
822
+ const startCol = col;
823
+ while (col < qr.modules && qr.isDark(row, col)) col++;
824
+ const u = normToUserRect(g, {
825
+ x: (x + (QR_QUIET_MODULES + startCol) * module) / size.width,
826
+ y: (y + (QR_QUIET_MODULES + row) * module) / size.height,
827
+ w: (col - startCol) * module / size.width,
828
+ h: module / size.height
829
+ });
830
+ page.drawRectangle({
831
+ x: u.x,
832
+ y: u.y,
833
+ width: u.width,
834
+ height: u.height,
835
+ color: rgb(0, 0, 0)
836
+ });
837
+ }
838
+ }
839
+ }
840
+ var A4 = [595.28, 841.89];
841
+ var MARGIN = 54;
842
+ var LINE = 13;
843
+ var TEXT = rgb(0.1, 0.1, 0.1);
844
+ var MUTED = rgb(0.4, 0.4, 0.4);
845
+ async function insertIndexPages(doc, entries, options) {
846
+ const regular = await doc.embedFont(StandardFonts.Helvetica);
847
+ const bold = await doc.embedFont(StandardFonts.HelveticaBold);
848
+ const sanitiser = new TextSanitiser(regular);
849
+ const [width, height] = options.size ?? A4;
850
+ const columns = {
851
+ number: MARGIN,
852
+ name: MARGIN + 28,
853
+ range: width - MARGIN - 190,
854
+ pages: width - MARGIN - 30
855
+ };
856
+ const nameWidth = columns.range - columns.name - 12;
857
+ let inserted = 0;
858
+ let page;
859
+ let y = 0;
860
+ const newPage = () => {
861
+ page = doc.insertPage(inserted++, [width, height]);
862
+ y = height - MARGIN;
863
+ };
864
+ const text = (value, x, font, size, color = TEXT) => page.drawText(sanitiser.clean(value), { x, y: y - size, size, font, color });
865
+ const header = () => {
866
+ text("#", columns.number, bold, 9, MUTED);
867
+ text("Document", columns.name, bold, 9, MUTED);
868
+ text("Bates range", columns.range, bold, 9, MUTED);
869
+ text("Pages", columns.pages, bold, 9, MUTED);
870
+ y -= LINE + 4;
871
+ };
872
+ newPage();
873
+ text("Production index", MARGIN, bold, 16);
874
+ y -= 24;
875
+ const first = entries[0]?.firstLabel;
876
+ const last = entries[entries.length - 1]?.lastLabel;
877
+ const total = entries.reduce((n, e) => n + e.pages, 0);
878
+ const summary = [
879
+ `${entries.length} document${entries.length === 1 ? "" : "s"}, ${total} page${total === 1 ? "" : "s"}`,
880
+ first && last ? `${first} to ${last}` : "",
881
+ `produced ${options.producedAt.slice(0, 10)}`,
882
+ options.producedBy ? `by ${options.producedBy}` : ""
883
+ ].filter(Boolean).join(", ");
884
+ text(summary, MARGIN, regular, 10, MUTED);
885
+ y -= LINE + 10;
886
+ header();
887
+ const rangeWidth = columns.pages - columns.range - 8;
888
+ entries.forEach((entry, i) => {
889
+ const lines = wrap(regular, sanitiser.clean(entry.name), 10, nameWidth);
890
+ const single = entry.firstLabel === entry.lastLabel ? entry.firstLabel : `${entry.firstLabel} - ${entry.lastLabel}`;
891
+ const range = regular.widthOfTextAtSize(sanitiser.clean(single), 10) <= rangeWidth ? [single] : [`${entry.firstLabel} -`, entry.lastLabel];
892
+ const rows = Math.max(lines.length, range.length);
893
+ if (y - rows * LINE < MARGIN) {
894
+ newPage();
895
+ header();
896
+ }
897
+ const top = y;
898
+ text(String(i + 1), columns.number, regular, 10);
899
+ text(String(entry.pages), columns.pages, regular, 10);
900
+ range.forEach((line, n) => {
901
+ y = top - n * LINE;
902
+ text(line, columns.range, regular, 10);
903
+ });
904
+ lines.forEach((line, n) => {
905
+ y = top - n * LINE;
906
+ text(line, columns.name, regular, 10);
907
+ });
908
+ y = top - rows * LINE - 4;
909
+ });
910
+ return inserted;
911
+ }
912
+
913
+ // src/annotations/freeze/bundle.ts
914
+ var BUNDLE_KEY = "ArbiBundle";
915
+ var DEFAULT_QR_CORNER = "bottom-left";
916
+ var DEFAULT_BATES_CORNER = "bottom-right";
917
+ function checkAborted2(signal) {
918
+ if (signal?.aborted) throw new DOMException("Bundle aborted", "AbortError");
919
+ }
920
+ function outputName(name, used) {
921
+ const base = (name.replace(/\.pdf$/i, "").replace(/[\\/:*?"<>|]+/g, "_").trim() || "document") + ".pdf";
922
+ let candidate = base;
923
+ for (let n = 2; used.has(candidate); n++) candidate = base.replace(/\.pdf$/, `-${n}.pdf`);
924
+ used.add(candidate);
925
+ return candidate;
926
+ }
927
+ function validate(items, options) {
928
+ if (items.length === 0)
929
+ throw new FreezeError("invalid-option", "A bundle needs at least one document");
930
+ validateBates(options.bates);
931
+ if (options.qr) {
932
+ const missing = items.find((i) => !i.qrUrl);
933
+ if (missing) {
934
+ throw new FreezeError("invalid-option", `"${missing.name}" has no link for its QR code`);
935
+ }
936
+ }
937
+ const corner = options.bates.corner ?? DEFAULT_BATES_CORNER;
938
+ if (options.qr && (options.qrCorner ?? DEFAULT_QR_CORNER) === corner) {
939
+ throw new FreezeError(
940
+ "invalid-option",
941
+ "The Bates label and the QR code need different corners"
942
+ );
943
+ }
944
+ }
945
+ async function stampPages(doc, items, firstIndex, options) {
946
+ const font = await doc.embedFont(StandardFonts.Helvetica);
947
+ const sanitiser = new TextSanitiser(font);
948
+ const label = batesLabel(options.bates, firstIndex);
949
+ if (!sanitiser.supports(label)) {
950
+ throw new FreezeError(
951
+ "unsupported-text",
952
+ `Bates prefix "${options.bates.prefix}" uses characters the built-in font cannot draw`
953
+ );
954
+ }
955
+ const pages = doc.getPages();
956
+ const corner = options.bates.corner ?? DEFAULT_BATES_CORNER;
957
+ let at = 0;
958
+ for (const item of items) {
959
+ const qr = options.qr && item.qrUrl ? buildQr(item.qrUrl) : void 0;
960
+ for (let p = 0; p < item.pages; p++, at++) {
961
+ const page = pages[at];
962
+ drawBatesLabel(page, batesLabel(options.bates, firstIndex + at), font, corner);
963
+ if (qr) drawQr(page, qr, options.qrCorner ?? DEFAULT_QR_CORNER);
964
+ }
965
+ }
966
+ }
967
+ function setBundleRecord(doc, record) {
968
+ const info = doc.context.lookup(doc.context.trailerInfo.Info);
969
+ if (!info || !("set" in info)) return;
970
+ info.set(
971
+ PDFName.of(BUNDLE_KEY),
972
+ PDFHexString.fromText(JSON.stringify(record))
973
+ );
974
+ }
975
+ async function buildBundle(items, options) {
976
+ validate(items, options);
977
+ const now = options.now ?? (/* @__PURE__ */ new Date()).toISOString();
978
+ const used = /* @__PURE__ */ new Set();
979
+ const files = [];
980
+ const index = [];
981
+ const loaded = [];
982
+ for (const item of items) {
983
+ checkAborted2(options.signal);
984
+ const doc = await loadPdfDocument(item.bytes);
985
+ loaded.push({ item, doc, pages: doc.getPageCount() });
986
+ }
987
+ if (options.layout === "merged") {
988
+ const out = await PDFDocument.create();
989
+ out.setProducer("ARBI");
990
+ out.setCreator("ARBI");
991
+ out.setCreationDate(new Date(now));
992
+ out.setModificationDate(new Date(now));
993
+ const provenance = {};
994
+ for (const { item, doc } of loaded) {
995
+ checkAborted2(options.signal);
996
+ for (const page of await out.copyPages(doc, doc.getPageIndices())) out.addPage(page);
997
+ provenance[item.documentId] = await readProvenance(item.bytes).catch(() => null);
998
+ }
999
+ await stampPages(
1000
+ out,
1001
+ loaded.map(({ item, pages }) => ({ pages, qrUrl: item.qrUrl })),
1002
+ 0,
1003
+ options
1004
+ );
1005
+ const file = outputName(options.mergedName ?? "production.pdf", used);
1006
+ let first2 = 0;
1007
+ for (const { item, pages } of loaded) {
1008
+ index.push({
1009
+ documentId: item.documentId,
1010
+ name: item.name,
1011
+ file,
1012
+ pages,
1013
+ firstLabel: batesLabel(options.bates, first2),
1014
+ lastLabel: batesLabel(options.bates, first2 + pages - 1)
1015
+ });
1016
+ first2 += pages;
1017
+ }
1018
+ const indexPages2 = options.indexPage ? await insertIndexPages(out, index, {
1019
+ size: pageSize(loaded[0].doc),
1020
+ producedAt: now,
1021
+ producedBy: options.author
1022
+ }) : 0;
1023
+ setBundleRecord(out, {
1024
+ schema: 1,
1025
+ producedAt: now,
1026
+ ...indexPages2 ? { indexPages: indexPages2 } : {},
1027
+ ...options.author ? { producedBy: options.author } : {},
1028
+ layout: "merged",
1029
+ items: index.map((e) => ({
1030
+ documentId: e.documentId,
1031
+ name: e.name,
1032
+ pages: e.pages,
1033
+ firstLabel: e.firstLabel,
1034
+ lastLabel: e.lastLabel,
1035
+ frozen: provenance[e.documentId] ?? null
1036
+ }))
1037
+ });
1038
+ const total = first2;
1039
+ files.push({
1040
+ name: file,
1041
+ bytes: await out.save(),
1042
+ pages: total + indexPages2,
1043
+ firstLabel: batesLabel(options.bates, 0),
1044
+ lastLabel: batesLabel(options.bates, total - 1)
1045
+ });
1046
+ options.onProgress?.(loaded.length, loaded.length);
1047
+ return { files, index, indexPages: indexPages2 };
1048
+ }
1049
+ let first = 0;
1050
+ for (const [n, { item, doc, pages }] of loaded.entries()) {
1051
+ checkAborted2(options.signal);
1052
+ await stampPages(doc, [{ pages, qrUrl: item.qrUrl }], first, options);
1053
+ doc.setModificationDate(new Date(now));
1054
+ const file = outputName(item.name, used);
1055
+ const entry = {
1056
+ documentId: item.documentId,
1057
+ name: item.name,
1058
+ file,
1059
+ pages,
1060
+ firstLabel: batesLabel(options.bates, first),
1061
+ lastLabel: batesLabel(options.bates, first + pages - 1)
1062
+ };
1063
+ index.push(entry);
1064
+ files.push({
1065
+ name: file,
1066
+ bytes: await doc.save(),
1067
+ pages,
1068
+ firstLabel: entry.firstLabel,
1069
+ lastLabel: entry.lastLabel
1070
+ });
1071
+ first += pages;
1072
+ options.onProgress?.(n + 1, loaded.length);
1073
+ }
1074
+ if (!options.indexPage) return { files, index, indexPages: 0 };
1075
+ const cover = await PDFDocument.create();
1076
+ cover.setProducer("ARBI");
1077
+ cover.setCreator("ARBI");
1078
+ cover.setCreationDate(new Date(now));
1079
+ const indexPages = await insertIndexPages(cover, index, {
1080
+ size: pageSize(loaded[0].doc),
1081
+ producedAt: now,
1082
+ producedBy: options.author
1083
+ });
1084
+ files.unshift({
1085
+ name: outputName("index.pdf", used),
1086
+ bytes: await cover.save(),
1087
+ pages: indexPages,
1088
+ firstLabel: "",
1089
+ lastLabel: ""
1090
+ });
1091
+ return { files, index, indexPages };
1092
+ }
1093
+ function pageSize(doc) {
1094
+ const page = doc.getPage(0);
1095
+ const { width, height } = page.getSize();
1096
+ const turned = page.getRotation().angle % 180 !== 0;
1097
+ return turned ? [height, width] : [width, height];
1098
+ }
735
1099
 
736
- export { DEFAULT_DPI, FreezeError, MAX_PAGE_PIXELS, browserCanvasFactory, burnMarks, createPdfJsRasterizer, freezePdf, freezePdfInBrowser, readProvenance };
1100
+ export { DEFAULT_DPI, FreezeError, MAX_PAGE_PIXELS, batesLabel, browserCanvasFactory, buildBundle, burnMarks, createPdfJsRasterizer, freezePdf, freezePdfInBrowser, readProvenance };
737
1101
  //# sourceMappingURL=index.js.map
738
1102
  //# sourceMappingURL=index.js.map