@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,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkBGDE4DP5_cjs = require('../../chunk-BGDE4DP5.cjs');
3
+ var chunkSSOPIPEX_cjs = require('../../chunk-SSOPIPEX.cjs');
4
4
  var pdfLib = require('pdf-lib');
5
5
  var reactPdf = require('react-pdf');
6
6
  var qrcode = require('qrcode-generator');
@@ -270,18 +270,18 @@ function wrap(font, text, size, maxWidth) {
270
270
  }
271
271
  return lines;
272
272
  }
273
- function appendCommentAppendix(ctx, comments, pageSize) {
273
+ function appendCommentAppendix(ctx, comments, pageSize2) {
274
274
  if (comments.length === 0) return;
275
275
  const { doc, regular, bold, sanitiser } = ctx;
276
276
  const margin = 54;
277
277
  const lineHeight = 13;
278
- const maxWidth = pageSize[0] - margin * 2;
279
- let page = doc.addPage(pageSize);
280
- let y = pageSize[1] - margin;
278
+ const maxWidth = pageSize2[0] - margin * 2;
279
+ let page = doc.addPage(pageSize2);
280
+ let y = pageSize2[1] - margin;
281
281
  const ensure = (needed) => {
282
282
  if (y - needed < margin) {
283
- page = doc.addPage(pageSize);
284
- y = pageSize[1] - margin;
283
+ page = doc.addPage(pageSize2);
284
+ y = pageSize2[1] - margin;
285
285
  }
286
286
  };
287
287
  const line = (text, font, size, indent = 0) => {
@@ -450,7 +450,7 @@ function burnMarks(page, marks, options) {
450
450
  }
451
451
  }
452
452
  for (const a of marks) {
453
- if (!chunkBGDE4DP5_cjs.isEffectiveRedaction(a)) continue;
453
+ if (!chunkSSOPIPEX_cjs.isEffectiveRedaction(a)) continue;
454
454
  const pad = options.paddingPt * pxPerPt;
455
455
  a.rects.forEach((r, i) => {
456
456
  const x0 = Math.max(0, Math.floor(r.x * w - pad));
@@ -516,14 +516,14 @@ var FALLBACK_PAGE = [595.28, 841.89];
516
516
  var PROVENANCE_KEY = "ArbiProvenance";
517
517
  var KINDS = ["highlight", "box", "comment", "stamp", "redaction"];
518
518
  async function freezePdf(original, rawLayer, options) {
519
- const layer = chunkBGDE4DP5_cjs.parseLayer(rawLayer);
519
+ const layer = chunkSSOPIPEX_cjs.parseLayer(rawLayer);
520
520
  const now = options.now ?? (/* @__PURE__ */ new Date()).toISOString();
521
521
  const comments = options.comments ?? "omit";
522
522
  const dpi = options.dpi ?? DEFAULT_DPI;
523
523
  if (!(dpi >= MIN_DPI && dpi <= MAX_DPI)) {
524
524
  throw new FreezeError("invalid-option", `dpi must be between ${MIN_DPI} and ${MAX_DPI}`);
525
525
  }
526
- const redactions = layer.annotations.filter(chunkBGDE4DP5_cjs.isEffectiveRedaction);
526
+ const redactions = layer.annotations.filter(chunkSSOPIPEX_cjs.isEffectiveRedaction);
527
527
  const pending = redactions.filter((r) => r.status === "pending");
528
528
  if (pending.length > 0 && (options.pendingRedactions ?? "error") === "error") {
529
529
  throw new FreezeError(
@@ -531,7 +531,7 @@ async function freezePdf(original, rawLayer, options) {
531
531
  `${pending.length} redaction mark(s) have not been approved or rejected`
532
532
  );
533
533
  }
534
- const marks = layer.annotations.filter((a) => a.kind !== "redaction" || chunkBGDE4DP5_cjs.isEffectiveRedaction(a));
534
+ const marks = layer.annotations.filter((a) => a.kind !== "redaction" || chunkSSOPIPEX_cjs.isEffectiveRedaction(a));
535
535
  const modeApplied = redactions.length > 0 ? "image" : options.mode;
536
536
  const [originalSha256, layerSha256] = await Promise.all([sha256Hex(original), hashLayer(layer)]);
537
537
  const warnings = [];
@@ -729,7 +729,7 @@ async function readProvenance(bytes) {
729
729
  return JSON.parse(value.decodeText());
730
730
  }
731
731
  async function freezePdfInBrowser(bytes, layer, { assets, password, ...options }) {
732
- const needsRaster = options.mode === "image" || layer.annotations.some(chunkBGDE4DP5_cjs.isEffectiveRedaction);
732
+ const needsRaster = options.mode === "image" || layer.annotations.some(chunkSSOPIPEX_cjs.isEffectiveRedaction);
733
733
  const rasterizer = needsRaster ? await createPdfJsRasterizer(reactPdf.pdfjs, bytes, browserCanvasFactory(), {
734
734
  password,
735
735
  documentOptions: {
@@ -843,6 +843,78 @@ function drawQr(page, qr, corner) {
843
843
  }
844
844
  }
845
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
+ }
846
918
 
847
919
  // src/annotations/freeze/bundle.ts
848
920
  var BUNDLE_KEY = "ArbiBundle";
@@ -949,9 +1021,15 @@ async function buildBundle(items, options) {
949
1021
  });
950
1022
  first2 += pages;
951
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;
952
1029
  setBundleRecord(out, {
953
1030
  schema: 1,
954
1031
  producedAt: now,
1032
+ ...indexPages2 ? { indexPages: indexPages2 } : {},
955
1033
  ...options.author ? { producedBy: options.author } : {},
956
1034
  layout: "merged",
957
1035
  items: index.map((e) => ({
@@ -967,12 +1045,12 @@ async function buildBundle(items, options) {
967
1045
  files.push({
968
1046
  name: file,
969
1047
  bytes: await out.save(),
970
- pages: total,
1048
+ pages: total + indexPages2,
971
1049
  firstLabel: batesLabel(options.bates, 0),
972
1050
  lastLabel: batesLabel(options.bates, total - 1)
973
1051
  });
974
1052
  options.onProgress?.(loaded.length, loaded.length);
975
- return { files, index };
1053
+ return { files, index, indexPages: indexPages2 };
976
1054
  }
977
1055
  let first = 0;
978
1056
  for (const [n, { item, doc, pages }] of loaded.entries()) {
@@ -999,7 +1077,30 @@ async function buildBundle(items, options) {
999
1077
  first += pages;
1000
1078
  options.onProgress?.(n + 1, loaded.length);
1001
1079
  }
1002
- return { files, index };
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];
1003
1104
  }
1004
1105
 
1005
1106
  exports.DEFAULT_DPI = DEFAULT_DPI;