@arbidocs/react 0.4.61 → 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,5 +1,5 @@
1
- import { isEffectiveRedaction, parseLayer } from '../../chunk-JWXIRUWN.js';
2
- import { PDFDocument, StandardFonts, rgb, PDFName, PDFHexString, EncryptedPDFError, 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
4
  import qrcode from 'qrcode-generator';
5
5
 
@@ -264,18 +264,18 @@ function wrap(font, text, size, maxWidth) {
264
264
  }
265
265
  return lines;
266
266
  }
267
- function appendCommentAppendix(ctx, comments, pageSize) {
267
+ function appendCommentAppendix(ctx, comments, pageSize2) {
268
268
  if (comments.length === 0) return;
269
269
  const { doc, regular, bold, sanitiser } = ctx;
270
270
  const margin = 54;
271
271
  const lineHeight = 13;
272
- const maxWidth = pageSize[0] - margin * 2;
273
- let page = doc.addPage(pageSize);
274
- let y = pageSize[1] - margin;
272
+ const maxWidth = pageSize2[0] - margin * 2;
273
+ let page = doc.addPage(pageSize2);
274
+ let y = pageSize2[1] - margin;
275
275
  const ensure = (needed) => {
276
276
  if (y - needed < margin) {
277
- page = doc.addPage(pageSize);
278
- y = pageSize[1] - margin;
277
+ page = doc.addPage(pageSize2);
278
+ y = pageSize2[1] - margin;
279
279
  }
280
280
  };
281
281
  const line = (text, font, size, indent = 0) => {
@@ -837,6 +837,78 @@ function drawQr(page, qr, corner) {
837
837
  }
838
838
  }
839
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
+ }
840
912
 
841
913
  // src/annotations/freeze/bundle.ts
842
914
  var BUNDLE_KEY = "ArbiBundle";
@@ -943,9 +1015,15 @@ async function buildBundle(items, options) {
943
1015
  });
944
1016
  first2 += pages;
945
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;
946
1023
  setBundleRecord(out, {
947
1024
  schema: 1,
948
1025
  producedAt: now,
1026
+ ...indexPages2 ? { indexPages: indexPages2 } : {},
949
1027
  ...options.author ? { producedBy: options.author } : {},
950
1028
  layout: "merged",
951
1029
  items: index.map((e) => ({
@@ -961,12 +1039,12 @@ async function buildBundle(items, options) {
961
1039
  files.push({
962
1040
  name: file,
963
1041
  bytes: await out.save(),
964
- pages: total,
1042
+ pages: total + indexPages2,
965
1043
  firstLabel: batesLabel(options.bates, 0),
966
1044
  lastLabel: batesLabel(options.bates, total - 1)
967
1045
  });
968
1046
  options.onProgress?.(loaded.length, loaded.length);
969
- return { files, index };
1047
+ return { files, index, indexPages: indexPages2 };
970
1048
  }
971
1049
  let first = 0;
972
1050
  for (const [n, { item, doc, pages }] of loaded.entries()) {
@@ -993,7 +1071,30 @@ async function buildBundle(items, options) {
993
1071
  first += pages;
994
1072
  options.onProgress?.(n + 1, loaded.length);
995
1073
  }
996
- return { files, index };
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];
997
1098
  }
998
1099
 
999
1100
  export { DEFAULT_DPI, FreezeError, MAX_PAGE_PIXELS, batesLabel, browserCanvasFactory, buildBundle, burnMarks, createPdfJsRasterizer, freezePdf, freezePdfInBrowser, readProvenance };