pdf-parser.js 5.2.29 → 5.3.0

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.
Files changed (189) hide show
  1. package/dist/{afm-widths-BHD2HZIL.cjs → afm-widths-C6U0SQj9.cjs} +5 -1448
  2. package/dist/{afm-widths-B_IGbGky.js → afm-widths-p3UfaXme.js} +3 -1398
  3. package/dist/afm-widths.cjs +1 -1
  4. package/dist/afm-widths.js +1 -1
  5. package/dist/annotations.d.cts +3 -3
  6. package/dist/annotations.d.ts +3 -3
  7. package/dist/attachments.d.cts +2 -2
  8. package/dist/attachments.d.ts +2 -2
  9. package/dist/builtin-encoding.cjs +4 -3
  10. package/dist/builtin-encoding.js +2 -1
  11. package/dist/cmap.d.cts +1 -1
  12. package/dist/cmap.d.ts +1 -1
  13. package/dist/content-read.d.cts +1 -1
  14. package/dist/content-read.d.ts +1 -1
  15. package/dist/content-write.cjs +1 -1
  16. package/dist/content-write.d.cts +1 -1
  17. package/dist/content-write.d.ts +1 -1
  18. package/dist/content-write.js +1 -1
  19. package/dist/diagnostics-C9FxfZ6H.d.cts +22 -0
  20. package/dist/diagnostics-C9FxfZ6H.d.ts +22 -0
  21. package/dist/diagnostics.d.cts +1 -21
  22. package/dist/diagnostics.d.ts +1 -21
  23. package/dist/document.d.cts +1 -1
  24. package/dist/document.d.ts +1 -1
  25. package/dist/{embedded-font-ByD7ZiQS.d.ts → embedded-font-CQZbTTDM.d.ts} +1 -1
  26. package/dist/{embedded-font-DgVBedw6.d.cts → embedded-font-CqePfvrl.d.cts} +1 -1
  27. package/dist/embedded-font-write.d.cts +1 -1
  28. package/dist/embedded-font-write.d.ts +1 -1
  29. package/dist/embedded-font.cjs +2 -2
  30. package/dist/embedded-font.d.cts +1 -1
  31. package/dist/embedded-font.d.ts +1 -1
  32. package/dist/embedded-font.js +2 -2
  33. package/dist/encoding-glyph-unicode.cjs +353 -0
  34. package/dist/encoding-glyph-unicode.d.cts +4 -0
  35. package/dist/encoding-glyph-unicode.d.ts +4 -0
  36. package/dist/encoding-glyph-unicode.js +352 -0
  37. package/dist/encoding-standard-tables.cjs +531 -0
  38. package/dist/encoding-standard-tables.d.cts +7 -0
  39. package/dist/encoding-standard-tables.d.ts +7 -0
  40. package/dist/encoding-standard-tables.js +527 -0
  41. package/dist/encoding-symbol-tables.cjs +531 -0
  42. package/dist/encoding-symbol-tables.d.cts +7 -0
  43. package/dist/encoding-symbol-tables.d.ts +7 -0
  44. package/dist/encoding-symbol-tables.js +527 -0
  45. package/dist/encoding.cjs +1 -9
  46. package/dist/encoding.d.cts +1 -9
  47. package/dist/encoding.d.ts +1 -9
  48. package/dist/encoding.js +2 -2
  49. package/dist/encrypt.d.cts +1 -1
  50. package/dist/encrypt.d.ts +1 -1
  51. package/dist/filters.d.cts +1 -1
  52. package/dist/filters.d.ts +1 -1
  53. package/dist/font-read.cjs +4 -3
  54. package/dist/font-read.d.cts +2 -2
  55. package/dist/font-read.d.ts +2 -2
  56. package/dist/font-read.js +2 -1
  57. package/dist/font-registry.d.cts +1 -1
  58. package/dist/font-registry.d.ts +1 -1
  59. package/dist/form.d.cts +2 -2
  60. package/dist/form.d.ts +2 -2
  61. package/dist/gdef-table-D0Hzn4KD.d.cts +15 -0
  62. package/dist/gdef-table-DL0V8wEZ.d.ts +15 -0
  63. package/dist/gdef-table.d.cts +1 -14
  64. package/dist/gdef-table.d.ts +1 -14
  65. package/dist/glyf-contours.d.cts +12 -1
  66. package/dist/glyf-contours.d.ts +12 -1
  67. package/dist/gsub-context.cjs +13 -0
  68. package/dist/gsub-context.d.cts +34 -0
  69. package/dist/gsub-context.d.ts +34 -0
  70. package/dist/gsub-context.js +2 -0
  71. package/dist/gsub-table-BDpJWqpf.d.ts +52 -0
  72. package/dist/gsub-table-D6niKeLi.js +556 -0
  73. package/dist/gsub-table-DW7Wmi9V.d.cts +52 -0
  74. package/dist/gsub-table-hFfYmf1W.cjs +741 -0
  75. package/dist/gsub-table.cjs +21 -556
  76. package/dist/gsub-table.d.cts +2 -2
  77. package/dist/gsub-table.d.ts +2 -2
  78. package/dist/gsub-table.js +2 -554
  79. package/dist/images-read.d.cts +2 -2
  80. package/dist/images-read.d.ts +2 -2
  81. package/dist/index.cjs +6 -6
  82. package/dist/index.d.cts +2 -2
  83. package/dist/index.d.ts +2 -2
  84. package/dist/index.js +6 -6
  85. package/dist/interpret-CqXdXgkY.cjs +712 -0
  86. package/dist/interpret-aWWhdIzr.js +677 -0
  87. package/dist/interpret-colors.cjs +6 -0
  88. package/dist/interpret-colors.d.cts +9 -0
  89. package/dist/interpret-colors.d.ts +9 -0
  90. package/dist/interpret-colors.js +2 -0
  91. package/dist/interpret-marked.cjs +25 -0
  92. package/dist/interpret-marked.d.cts +11 -0
  93. package/dist/interpret-marked.d.ts +11 -0
  94. package/dist/interpret-marked.js +23 -0
  95. package/dist/interpret-shapes.cjs +212 -0
  96. package/dist/interpret-shapes.d.cts +32 -0
  97. package/dist/interpret-shapes.d.ts +32 -0
  98. package/dist/interpret-shapes.js +199 -0
  99. package/dist/interpret-types.cjs +0 -0
  100. package/dist/interpret-types.d.cts +123 -0
  101. package/dist/interpret-types.d.ts +123 -0
  102. package/dist/interpret-types.js +0 -0
  103. package/dist/interpret.cjs +3 -887
  104. package/dist/interpret.d.cts +5 -116
  105. package/dist/interpret.d.ts +5 -116
  106. package/dist/interpret.js +2 -887
  107. package/dist/math-font.cjs +1 -1
  108. package/dist/math-font.js +1 -1
  109. package/dist/measure.cjs +1 -1
  110. package/dist/measure.js +1 -1
  111. package/dist/names.d.cts +2 -2
  112. package/dist/names.d.ts +2 -2
  113. package/dist/navigation.d.cts +2 -2
  114. package/dist/navigation.d.ts +2 -2
  115. package/dist/optional-content.d.cts +2 -2
  116. package/dist/optional-content.d.ts +2 -2
  117. package/dist/ot-layout-common-BcsGRFBS.d.cts +10 -0
  118. package/dist/ot-layout-common-BcsGRFBS.d.ts +10 -0
  119. package/dist/ot-layout-common.d.cts +1 -9
  120. package/dist/ot-layout-common.d.ts +1 -9
  121. package/dist/parse.d.cts +1 -1
  122. package/dist/parse.d.ts +1 -1
  123. package/dist/predictors.d.cts +1 -1
  124. package/dist/predictors.d.ts +1 -1
  125. package/dist/raster-Cdm3idP_.js +794 -0
  126. package/dist/raster-EG2KYRZ0.cjs +829 -0
  127. package/dist/raster-text.cjs +5 -0
  128. package/dist/raster-text.d.cts +20 -0
  129. package/dist/raster-text.d.ts +20 -0
  130. package/dist/raster-text.js +2 -0
  131. package/dist/raster.cjs +4 -795
  132. package/dist/raster.d.cts +17 -6
  133. package/dist/raster.d.ts +17 -6
  134. package/dist/raster.js +2 -792
  135. package/dist/read-convert.cjs +310 -0
  136. package/dist/read-convert.d.cts +58 -0
  137. package/dist/read-convert.d.ts +58 -0
  138. package/dist/read-convert.js +295 -0
  139. package/dist/read.cjs +5 -293
  140. package/dist/read.d.cts +1 -1
  141. package/dist/read.d.ts +1 -1
  142. package/dist/read.js +4 -292
  143. package/dist/structure.d.cts +2 -2
  144. package/dist/structure.d.ts +2 -2
  145. package/dist/winansi.cjs +1 -1
  146. package/dist/winansi.js +1 -1
  147. package/dist/write-annotations.cjs +132 -0
  148. package/dist/write-annotations.d.cts +29 -0
  149. package/dist/write-annotations.d.ts +29 -0
  150. package/dist/write-annotations.js +121 -0
  151. package/dist/write-font-objects.cjs +76 -0
  152. package/dist/write-font-objects.d.cts +35 -0
  153. package/dist/write-font-objects.d.ts +35 -0
  154. package/dist/write-font-objects.js +75 -0
  155. package/dist/write-form.cjs +91 -0
  156. package/dist/write-form.d.cts +19 -0
  157. package/dist/write-form.d.ts +19 -0
  158. package/dist/write-form.js +89 -0
  159. package/dist/write-images.cjs +148 -0
  160. package/dist/write-images.d.cts +25 -0
  161. package/dist/write-images.d.ts +25 -0
  162. package/dist/write-images.js +140 -0
  163. package/dist/write-outline.cjs +46 -0
  164. package/dist/write-outline.d.cts +18 -0
  165. package/dist/write-outline.d.ts +18 -0
  166. package/dist/write-outline.js +45 -0
  167. package/dist/write-page-emit.cjs +97 -0
  168. package/dist/write-page-emit.d.cts +63 -0
  169. package/dist/write-page-emit.d.ts +63 -0
  170. package/dist/write-page-emit.js +96 -0
  171. package/dist/write-pages.cjs +37 -0
  172. package/dist/write-pages.d.cts +21 -0
  173. package/dist/write-pages.d.ts +21 -0
  174. package/dist/write-pages.js +36 -0
  175. package/dist/write-strings.cjs +41 -0
  176. package/dist/write-strings.d.cts +9 -0
  177. package/dist/write-strings.d.ts +9 -0
  178. package/dist/write-strings.js +37 -0
  179. package/dist/write.cjs +53 -553
  180. package/dist/write.d.cts +1 -1
  181. package/dist/write.d.ts +1 -1
  182. package/dist/write.js +49 -549
  183. package/dist/xref.d.cts +1 -1
  184. package/dist/xref.d.ts +1 -1
  185. package/package.json +2 -2
  186. package/dist/glyf-contours-B1PsI9oA.d.ts +0 -13
  187. package/dist/glyf-contours-NHBpgks-.d.cts +0 -13
  188. package/dist/gsub-table-Bm9kSMzk.d.cts +0 -16
  189. package/dist/gsub-table-CdfESH2-.d.ts +0 -16
package/dist/read.js CHANGED
@@ -1,13 +1,12 @@
1
- import "./notes-annotation-author.js";
2
- import { asArray, asName, asNumber, dictGet, pdfArray, pdfDict, pdfNull, pdfNum } from "./objects.js";
1
+ import { asArray, asNumber, dictGet, pdfArray, pdfDict, pdfNull, pdfNum } from "./objects.js";
3
2
  import { decodePdfString, parsePdfDate } from "./pdf-text.js";
4
3
  import { concatBytes } from "./bytes/writer.js";
5
4
  import { serializeObjectToText } from "./serialize.js";
6
- import { applyMatrix, matrixRotationDegrees, matrixScaleX, matrixScaleY, multiplyMatrices, rotatePointAboutCenter, translationMatrix } from "./matrix.js";
5
+ import { applyMatrix, multiplyMatrices, rotatePointAboutCenter, translationMatrix } from "./matrix.js";
7
6
  import { readPageAnnotations } from "./annotations.js";
8
7
  import { decodeStream } from "./filters.js";
9
8
  import { readAttachments } from "./attachments.js";
10
- import { crc32 } from "./bytes/crc32.js";
9
+ import { convertExtractedItem, readLinkAnnotations, readPageNotes } from "./read-convert.js";
11
10
  import { readAcroForm } from "./form.js";
12
11
  import { readXmpMetadata } from "./xmp.js";
13
12
  import { readOptionalContent } from "./optional-content.js";
@@ -17,10 +16,8 @@ import { NOOP_DIAGNOSTIC_SINK, PdfParseError } from "./diagnostics.js";
17
16
  import { openPdfDocument } from "./document.js";
18
17
  import { throwIfAborted } from "./util/abort.js";
19
18
  import { createFontResolver } from "./font-read.js";
20
- import { readImageXObject } from "./images-read.js";
21
- import { interpretContentStream } from "./interpret.js";
19
+ import { t as interpretContentStream } from "./interpret-aWWhdIzr.js";
22
20
  import { createDestinationRegistry, readOutline } from "./navigation.js";
23
- import { bytesToBase64 } from "byte-codec";
24
21
  //#region src/read.ts
25
22
  const PDF_HEADER_BYTES = new TextEncoder().encode("%PDF-");
26
23
  const HEADER_SEARCH_WINDOW = 1024;
@@ -344,291 +341,6 @@ function withStructure(item, structure) {
344
341
  structure
345
342
  };
346
343
  }
347
- function convertExtractedItem(item, pageMatrix, fontResolver, images, imageIdCache, resolver, sink) {
348
- if (item.kind === "text") return convertText(item, pageMatrix, fontResolver);
349
- if (item.kind === "rect") return convertRect(item, pageMatrix);
350
- if (item.kind === "ellipse") return convertEllipse(item, pageMatrix);
351
- if (item.kind === "line") return convertLine(item, pageMatrix);
352
- if (item.kind === "path") return convertPath(item, pageMatrix);
353
- if (item.kind === "image") return convertImage(item, pageMatrix, images, imageIdCache, resolver, sink);
354
- return convertInlineImage(item, pageMatrix, images, resolver, sink);
355
- }
356
- function convertText(item, pageMatrix, fontResolver) {
357
- const font = fontResolver.resolve(item.fontResourceName, item.resources);
358
- const text = font?.decodeToUnicode(item.codes) ?? "";
359
- if (text.length === 0) return;
360
- const startTrm = multiplyMatrices(item.startMatrix, pageMatrix);
361
- const endTrm = multiplyMatrices(item.endMatrix, pageMatrix);
362
- const widthPt = Math.hypot(endTrm[4] - startTrm[4], endTrm[5] - startTrm[5]);
363
- const sizePt = matrixScaleX(startTrm);
364
- const rotationDeg = matrixRotationDegrees(startTrm);
365
- const layoutFont = {
366
- family: font?.family ?? "Helvetica",
367
- weight: font?.bold === true ? "bold" : "normal",
368
- style: font?.italic === true ? "italic" : "normal"
369
- };
370
- return {
371
- kind: "text",
372
- text,
373
- xPt: startTrm[4],
374
- yPt: startTrm[5],
375
- font: layoutFont,
376
- sizePt: sizePt > 0 ? sizePt : item.sizePt,
377
- color: item.color,
378
- widthPt,
379
- rotationDeg: rotationDeg !== 0 ? rotationDeg : void 0,
380
- ...item.vertical === true ? { writingMode: "vertical" } : {},
381
- ...item.layerName !== void 0 ? { layer: item.layerName } : {},
382
- ...item.actualText !== void 0 ? { actualText: item.actualText } : {},
383
- ...item.alt !== void 0 ? { alt: item.alt } : {}
384
- };
385
- }
386
- function paintFields(paint) {
387
- return {
388
- ...paint.fill !== void 0 ? { fill: paint.fill } : {},
389
- ...paint.stroke !== void 0 ? { stroke: paint.stroke } : {}
390
- };
391
- }
392
- function transformBox(item, pageMatrix) {
393
- const p1 = applyMatrix(pageMatrix, {
394
- x: item.xPt,
395
- y: item.yPt
396
- });
397
- const p2 = applyMatrix(pageMatrix, {
398
- x: item.xPt + item.widthPt,
399
- y: item.yPt + item.heightPt
400
- });
401
- return {
402
- xPt: Math.min(p1.x, p2.x),
403
- yPt: Math.min(p1.y, p2.y),
404
- widthPt: Math.abs(p2.x - p1.x),
405
- heightPt: Math.abs(p2.y - p1.y)
406
- };
407
- }
408
- function convertRect(item, pageMatrix) {
409
- return {
410
- kind: "rect",
411
- ...transformBox(item, pageMatrix),
412
- ...paintFields(item),
413
- ...item.layerName !== void 0 ? { layer: item.layerName } : {}
414
- };
415
- }
416
- function convertEllipse(item, pageMatrix) {
417
- return {
418
- kind: "ellipse",
419
- ...transformBox(item, pageMatrix),
420
- ...paintFields(item),
421
- ...item.layerName !== void 0 ? { layer: item.layerName } : {}
422
- };
423
- }
424
- function convertLine(item, pageMatrix) {
425
- const p1 = applyMatrix(pageMatrix, {
426
- x: item.x1Pt,
427
- y: item.y1Pt
428
- });
429
- const p2 = applyMatrix(pageMatrix, {
430
- x: item.x2Pt,
431
- y: item.y2Pt
432
- });
433
- return {
434
- kind: "line",
435
- x1Pt: p1.x,
436
- y1Pt: p1.y,
437
- x2Pt: p2.x,
438
- y2Pt: p2.y,
439
- color: item.color,
440
- widthPt: item.widthPt,
441
- ...item.style !== void 0 ? { style: item.style } : {},
442
- ...item.layerName !== void 0 ? { layer: item.layerName } : {}
443
- };
444
- }
445
- function transformSubpath(subpath, pageMatrix) {
446
- const start = applyMatrix(pageMatrix, {
447
- x: subpath.startXPt,
448
- y: subpath.startYPt
449
- });
450
- const segments = subpath.segments.map((segment) => {
451
- if (segment.kind === "line") {
452
- const p = applyMatrix(pageMatrix, {
453
- x: segment.xPt,
454
- y: segment.yPt
455
- });
456
- return {
457
- kind: "line",
458
- xPt: p.x,
459
- yPt: p.y
460
- };
461
- }
462
- const c1 = applyMatrix(pageMatrix, {
463
- x: segment.c1xPt,
464
- y: segment.c1yPt
465
- });
466
- const c2 = applyMatrix(pageMatrix, {
467
- x: segment.c2xPt,
468
- y: segment.c2yPt
469
- });
470
- const p = applyMatrix(pageMatrix, {
471
- x: segment.xPt,
472
- y: segment.yPt
473
- });
474
- return {
475
- kind: "cubic",
476
- c1xPt: c1.x,
477
- c1yPt: c1.y,
478
- c2xPt: c2.x,
479
- c2yPt: c2.y,
480
- xPt: p.x,
481
- yPt: p.y
482
- };
483
- });
484
- return {
485
- startXPt: start.x,
486
- startYPt: start.y,
487
- segments,
488
- closed: subpath.closed
489
- };
490
- }
491
- function convertPath(item, pageMatrix) {
492
- return {
493
- kind: "path",
494
- subpaths: item.subpaths.map((subpath) => transformSubpath(subpath, pageMatrix)),
495
- ...item.fill !== void 0 ? { fill: item.fill } : {},
496
- ...item.fill !== void 0 && item.fillRule === "evenodd" ? { fillRule: "evenodd" } : {},
497
- ...item.stroke !== void 0 ? { stroke: item.stroke } : {},
498
- ...item.style !== void 0 ? { style: item.style } : {},
499
- ...item.layerName !== void 0 ? { layer: item.layerName } : {}
500
- };
501
- }
502
- function imagePlacementFrom(matrix) {
503
- const rotationDeg = matrixRotationDegrees(matrix);
504
- return {
505
- xPt: matrix[4],
506
- yPt: matrix[5],
507
- widthPt: matrixScaleX(matrix),
508
- heightPt: matrixScaleY(matrix),
509
- rotationDeg: rotationDeg !== 0 ? rotationDeg : void 0
510
- };
511
- }
512
- const HEX_RADIX = 16;
513
- function registerExtractedImage(format, bytes, widthPx, heightPx, images, original) {
514
- const imageId = `img${crc32(bytes).toString(HEX_RADIX)}`;
515
- if (!(imageId in images)) images[imageId] = {
516
- format,
517
- base64: bytesToBase64(bytes),
518
- widthPx,
519
- heightPx,
520
- ...original !== void 0 ? { original: {
521
- filter: original.filter,
522
- base64: bytesToBase64(original.bytes),
523
- ...original.globalsBytes !== void 0 ? { jbig2GlobalsBase64: bytesToBase64(original.globalsBytes) } : {}
524
- } } : {}
525
- };
526
- return imageId;
527
- }
528
- function resolveCachedImageId(dict, raw, images, cache, resolver, sink) {
529
- if (cache.has(dict)) return cache.get(dict) ?? void 0;
530
- const decoded = readImageXObject(dict, raw, resolver, sink);
531
- if (decoded === void 0) {
532
- cache.set(dict, null);
533
- return;
534
- }
535
- const imageId = registerExtractedImage(decoded.format, decoded.bytes, decoded.widthPx, decoded.heightPx, images, decoded.original);
536
- cache.set(dict, imageId);
537
- return imageId;
538
- }
539
- function convertImage(item, pageMatrix, images, cache, resolver, sink) {
540
- const xobjects = resolver.resolveDict(dictGet(item.resources, "XObject"));
541
- const xobj = xobjects !== void 0 ? resolver.resolve(dictGet(xobjects, item.resourceName)) : void 0;
542
- if (xobj?.kind !== "stream") return;
543
- const imageId = resolveCachedImageId(xobj.dict, xobj.raw, images, cache, resolver, sink);
544
- if (imageId === void 0) return;
545
- return {
546
- kind: "image",
547
- imageId,
548
- ...imagePlacementFrom(multiplyMatrices(item.matrix, pageMatrix)),
549
- ...item.layerName !== void 0 ? { layer: item.layerName } : {}
550
- };
551
- }
552
- function convertInlineImage(item, pageMatrix, images, resolver, sink) {
553
- const decoded = readImageXObject(item.dict, item.data, resolver, sink);
554
- if (decoded === void 0) return;
555
- return {
556
- kind: "image",
557
- imageId: registerExtractedImage(decoded.format, decoded.bytes, decoded.widthPx, decoded.heightPx, images, decoded.original),
558
- ...imagePlacementFrom(multiplyMatrices(item.matrix, pageMatrix)),
559
- ...item.layerName !== void 0 ? { layer: item.layerName } : {}
560
- };
561
- }
562
- function readLinkAnnotations(page, pageMatrix, resolver, destinationRegistry) {
563
- const annotsArr = asArray(dictGet(page, "Annots"));
564
- if (annotsArr === void 0) return [];
565
- const links = [];
566
- for (const annotRef of annotsArr) {
567
- const annot = resolver.resolveDict(annotRef);
568
- if (annot === void 0 || asName(dictGet(annot, "Subtype")) !== "Link") continue;
569
- const rectArr = asArray(dictGet(annot, "Rect"));
570
- if (rectArr === void 0) continue;
571
- const uri = readLinkUri(annot, resolver);
572
- const destination = uri === void 0 ? readInternalDestination(annot, resolver, destinationRegistry) : void 0;
573
- if (uri === void 0 && destination === void 0) continue;
574
- const x1 = asNumber(rectArr[0]) ?? 0;
575
- const y1 = asNumber(rectArr[1]) ?? 0;
576
- const x2 = asNumber(rectArr[2]) ?? 0;
577
- const y2 = asNumber(rectArr[3]) ?? 0;
578
- const p1 = applyMatrix(pageMatrix, {
579
- x: Math.min(x1, x2),
580
- y: Math.min(y1, y2)
581
- });
582
- const p2 = applyMatrix(pageMatrix, {
583
- x: Math.max(x1, x2),
584
- y: Math.max(y1, y2)
585
- });
586
- const contentsObj = dictGet(annot, "Contents");
587
- const title = contentsObj?.kind === "string" ? decodePdfString(contentsObj.bytes) : void 0;
588
- const box = {
589
- xPt: Math.min(p1.x, p2.x),
590
- yPt: Math.min(p1.y, p2.y),
591
- widthPt: Math.abs(p2.x - p1.x),
592
- heightPt: Math.abs(p2.y - p1.y),
593
- ...title !== void 0 ? { title } : {}
594
- };
595
- if (uri !== void 0) links.push({
596
- kind: "link",
597
- uri,
598
- ...box
599
- });
600
- else if (destination !== void 0) links.push({
601
- kind: "internalLink",
602
- destination,
603
- ...box
604
- });
605
- }
606
- return links;
607
- }
608
- function readLinkUri(annot, resolver) {
609
- const action = resolver.resolveDict(dictGet(annot, "A"));
610
- if (action === void 0 || asName(dictGet(action, "S")) !== "URI") return;
611
- const uriObj = dictGet(action, "URI");
612
- return uriObj?.kind === "string" ? decodePdfString(uriObj.bytes) : void 0;
613
- }
614
- function readInternalDestination(annot, resolver, destinationRegistry) {
615
- const dest = dictGet(annot, "Dest");
616
- if (dest !== void 0) return destinationRegistry.intern(dest);
617
- const action = resolver.resolveDict(dictGet(annot, "A"));
618
- if (action !== void 0 && asName(dictGet(action, "S")) === "GoTo") return destinationRegistry.intern(dictGet(action, "D"));
619
- }
620
- function readPageNotes(page, resolver) {
621
- const annotsArr = asArray(dictGet(page, "Annots"));
622
- if (annotsArr === void 0) return;
623
- for (const annotRef of annotsArr) {
624
- const annot = resolver.resolveDict(annotRef);
625
- if (annot === void 0 || asName(dictGet(annot, "Subtype")) !== "Text") continue;
626
- const titleObj = dictGet(annot, "T");
627
- if ((titleObj?.kind === "string" ? decodePdfString(titleObj.bytes) : void 0) !== "documents.js:notes") continue;
628
- const contentsObj = dictGet(annot, "Contents");
629
- if (contentsObj?.kind === "string") return decodePdfString(contentsObj.bytes);
630
- }
631
- }
632
344
  function readMetadata(trailer, resolver, catalog, sink) {
633
345
  const info = resolver.resolveDict(dictGet(trailer, "Info"));
634
346
  if (info === void 0) return {};
@@ -1,6 +1,6 @@
1
- import { PdfDiagnosticSink } from "./diagnostics.cjs";
1
+ import { i as PdfDiagnosticSink } from "./diagnostics-C9FxfZ6H.cjs";
2
2
  import { n as PdfDict } from "./objects-e2RS3-yT.cjs";
3
- import { PdfObjectResolver } from "./interpret.cjs";
3
+ import { PdfObjectResolver } from "./interpret-types.cjs";
4
4
  import { LayoutStructureElement } from "./layout.cjs";
5
5
  //#region src/structure.d.ts
6
6
  interface StructureContext {
@@ -1,6 +1,6 @@
1
- import { PdfDiagnosticSink } from "./diagnostics.js";
1
+ import { i as PdfDiagnosticSink } from "./diagnostics-C9FxfZ6H.js";
2
2
  import { n as PdfDict } from "./objects-e2RS3-yT.js";
3
- import { PdfObjectResolver } from "./interpret.js";
3
+ import { PdfObjectResolver } from "./interpret-types.js";
4
4
  import { LayoutStructureElement } from "./layout.js";
5
5
  //#region src/structure.d.ts
6
6
  interface StructureContext {
package/dist/winansi.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_afm_widths = require("./afm-widths-BHD2HZIL.cjs");
2
+ const require_afm_widths = require("./afm-widths-C6U0SQj9.cjs");
3
3
  exports.encodeForShow = require_afm_widths.encodeForShow;
4
4
  exports.sanitizeToWinAnsi = require_afm_widths.sanitizeToWinAnsi;
5
5
  exports.winAnsiCodeToUnicode = require_afm_widths.winAnsiCodeToUnicode;
package/dist/winansi.js CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as winAnsiCodeToUnicode, g as sanitizeToWinAnsi, h as encodeForShow } from "./afm-widths-B_IGbGky.js";
1
+ import { c as sanitizeToWinAnsi, l as winAnsiCodeToUnicode, s as encodeForShow } from "./afm-widths-p3UfaXme.js";
2
2
  export { encodeForShow, sanitizeToWinAnsi, winAnsiCodeToUnicode };
@@ -0,0 +1,132 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_notes_annotation_author = require("./notes-annotation-author.cjs");
3
+ const require_objects = require("./objects.cjs");
4
+ const require_bytes_reader = require("./bytes/reader.cjs");
5
+ const require_parse = require("./parse.cjs");
6
+ const require_write_strings = require("./write-strings.cjs");
7
+ //#region src/write-annotations.ts
8
+ function buildLinkAnnotDict(link) {
9
+ return require_objects.pdfDict({
10
+ Type: require_objects.pdfName("Annot"),
11
+ Subtype: require_objects.pdfName("Link"),
12
+ Rect: require_objects.pdfArray([
13
+ link.xPt,
14
+ link.yPt,
15
+ link.xPt + link.widthPt,
16
+ link.yPt + link.heightPt
17
+ ].map((n) => require_objects.pdfNum(n))),
18
+ Border: require_objects.pdfArray([
19
+ 0,
20
+ 0,
21
+ 0
22
+ ].map((n) => require_objects.pdfNum(n))),
23
+ A: require_objects.pdfDict({
24
+ Type: require_objects.pdfName("Action"),
25
+ S: require_objects.pdfName("URI"),
26
+ URI: require_objects.pdfHexString(new TextEncoder().encode(link.uri))
27
+ })
28
+ });
29
+ }
30
+ function destinationViewArray(target) {
31
+ const n = (value) => value === void 0 ? require_objects.pdfNull() : require_objects.pdfNum(value);
32
+ if (target.kind === "xyz") return [
33
+ require_objects.pdfName("XYZ"),
34
+ n(target.leftPt),
35
+ n(target.topPt),
36
+ n(target.zoom)
37
+ ];
38
+ if (target.kind === "fitH") return [require_objects.pdfName("FitH"), n(target.topPt)];
39
+ if (target.kind === "fitV") return [require_objects.pdfName("FitV"), n(target.leftPt)];
40
+ if (target.kind === "fitR") return [
41
+ require_objects.pdfName("FitR"),
42
+ n(target.leftPt),
43
+ n(target.bottomPt),
44
+ n(target.rightPt),
45
+ n(target.topPt)
46
+ ];
47
+ if (target.kind === "fitBH") return [require_objects.pdfName("FitBH"), n(target.topPt)];
48
+ if (target.kind === "fitBV") return [require_objects.pdfName("FitBV"), n(target.leftPt)];
49
+ return [require_objects.pdfName(target.kind === "fitB" ? "FitB" : "Fit")];
50
+ }
51
+ function resolveDestinationArray(doc, pageAllocs, name, what) {
52
+ const destination = doc.destinations?.find((d) => d.name === name);
53
+ if (destination === void 0) throw new Error(`${what} names destination "${name}", which the document's destinations table does not carry — this is a caller-invariant violation`);
54
+ const targetPage = pageAllocs[destination.pageIndex];
55
+ if (targetPage === void 0) throw new Error(`destination "${destination.name}" names page index ${destination.pageIndex}, which is beyond the document's own pages — this is a caller-invariant violation`);
56
+ return [require_objects.pdfRef(targetPage.pageNum, 0), ...destinationViewArray(destination.target)];
57
+ }
58
+ function buildInternalLinkAnnotDict(link, doc, pageAllocs) {
59
+ return require_objects.pdfDict({
60
+ Type: require_objects.pdfName("Annot"),
61
+ Subtype: require_objects.pdfName("Link"),
62
+ Rect: require_objects.pdfArray([
63
+ link.xPt,
64
+ link.yPt,
65
+ link.xPt + link.widthPt,
66
+ link.yPt + link.heightPt
67
+ ].map((v) => require_objects.pdfNum(v))),
68
+ Border: require_objects.pdfArray([
69
+ 0,
70
+ 0,
71
+ 0
72
+ ].map((v) => require_objects.pdfNum(v))),
73
+ Dest: require_objects.pdfArray(resolveDestinationArray(doc, pageAllocs, link.destination, "internal link"))
74
+ });
75
+ }
76
+ function isLinkItem(item) {
77
+ return item.kind === "link";
78
+ }
79
+ function isInternalLinkItem(item) {
80
+ return item.kind === "internalLink";
81
+ }
82
+ const NOTES_ANNOTATION_HIDDEN_FLAG = 2;
83
+ function buildNotesAnnotDict(notes) {
84
+ return require_objects.pdfDict({
85
+ Type: require_objects.pdfName("Annot"),
86
+ Subtype: require_objects.pdfName("Text"),
87
+ Rect: require_objects.pdfArray([
88
+ 0,
89
+ 0,
90
+ 0,
91
+ 0
92
+ ].map((n) => require_objects.pdfNum(n))),
93
+ Contents: require_write_strings.textToPdfString(notes),
94
+ T: require_write_strings.textToPdfString(require_notes_annotation_author.NOTES_ANNOTATION_AUTHOR),
95
+ F: require_objects.pdfNum(NOTES_ANNOTATION_HIDDEN_FLAG)
96
+ });
97
+ }
98
+ const XREF_OFFSET_DIGITS = 10;
99
+ const XREF_GENERATION_DIGITS = 5;
100
+ function xrefEntry(offset, generation, inUse) {
101
+ return `${offset.toString().padStart(XREF_OFFSET_DIGITS, "0")} ${generation.toString().padStart(XREF_GENERATION_DIGITS, "0")} ${inUse ? "n" : "f"} \n`;
102
+ }
103
+ function parseResidueRow(residue) {
104
+ const reader = new require_bytes_reader.ByteReader(new TextEncoder().encode(residue.xml));
105
+ return require_parse.parseValue(reader, () => void 0);
106
+ }
107
+ function objectContainsReference(obj) {
108
+ if (obj.kind === "ref") return true;
109
+ if (obj.kind === "array") return obj.items.some(objectContainsReference);
110
+ if (obj.kind === "dict") return [...obj.entries.values()].some(objectContainsReference);
111
+ if (obj.kind === "stream") return [...obj.dict.entries.values()].some(objectContainsReference);
112
+ return false;
113
+ }
114
+ function restoreResidueRow(source, key) {
115
+ const row = source?.[key];
116
+ if (row === void 0) return;
117
+ const parsed = parseResidueRow(row);
118
+ if (parsed === void 0 || objectContainsReference(parsed)) return;
119
+ return parsed;
120
+ }
121
+ //#endregion
122
+ exports.buildInternalLinkAnnotDict = buildInternalLinkAnnotDict;
123
+ exports.buildLinkAnnotDict = buildLinkAnnotDict;
124
+ exports.buildNotesAnnotDict = buildNotesAnnotDict;
125
+ exports.destinationViewArray = destinationViewArray;
126
+ exports.isInternalLinkItem = isInternalLinkItem;
127
+ exports.isLinkItem = isLinkItem;
128
+ exports.objectContainsReference = objectContainsReference;
129
+ exports.parseResidueRow = parseResidueRow;
130
+ exports.resolveDestinationArray = resolveDestinationArray;
131
+ exports.restoreResidueRow = restoreResidueRow;
132
+ exports.xrefEntry = xrefEntry;
@@ -0,0 +1,29 @@
1
+ import { r as PdfObject } from "./objects-e2RS3-yT.cjs";
2
+ import { LayoutDestinationTarget, LayoutDocument, LayoutInternalLink, LayoutLink } from "./layout.cjs";
3
+ import { SourceResidue } from "document-schema.js";
4
+ //#region src/write-annotations.d.ts
5
+ declare function buildLinkAnnotDict(link: Readonly<LayoutLink>): PdfObject;
6
+ declare function destinationViewArray(target: Readonly<LayoutDestinationTarget>): PdfObject[];
7
+ declare function resolveDestinationArray(doc: LayoutDocument, pageAllocs: readonly {
8
+ pageNum: number;
9
+ }[], name: string, what: string): PdfObject[];
10
+ declare function buildInternalLinkAnnotDict(link: Readonly<LayoutInternalLink>, doc: LayoutDocument, pageAllocs: readonly {
11
+ pageNum: number;
12
+ }[]): PdfObject;
13
+ declare function isLinkItem(item: {
14
+ readonly kind: string;
15
+ }): item is LayoutLink;
16
+ declare function isInternalLinkItem(item: {
17
+ readonly kind: string;
18
+ }): item is LayoutInternalLink;
19
+ declare function buildNotesAnnotDict(notes: string): PdfObject;
20
+ interface AllocatedObject {
21
+ readonly num: number;
22
+ readonly value: PdfObject;
23
+ }
24
+ declare function xrefEntry(offset: number, generation: number, inUse: boolean): string;
25
+ declare function parseResidueRow(residue: Readonly<SourceResidue>): PdfObject | undefined;
26
+ declare function objectContainsReference(obj: PdfObject): boolean;
27
+ declare function restoreResidueRow(source: Record<string, SourceResidue> | undefined, key: string): PdfObject | undefined;
28
+ //#endregion
29
+ export { AllocatedObject, buildInternalLinkAnnotDict, buildLinkAnnotDict, buildNotesAnnotDict, destinationViewArray, isInternalLinkItem, isLinkItem, objectContainsReference, parseResidueRow, resolveDestinationArray, restoreResidueRow, xrefEntry };
@@ -0,0 +1,29 @@
1
+ import { r as PdfObject } from "./objects-e2RS3-yT.js";
2
+ import { LayoutDestinationTarget, LayoutDocument, LayoutInternalLink, LayoutLink } from "./layout.js";
3
+ import { SourceResidue } from "document-schema.js";
4
+ //#region src/write-annotations.d.ts
5
+ declare function buildLinkAnnotDict(link: Readonly<LayoutLink>): PdfObject;
6
+ declare function destinationViewArray(target: Readonly<LayoutDestinationTarget>): PdfObject[];
7
+ declare function resolveDestinationArray(doc: LayoutDocument, pageAllocs: readonly {
8
+ pageNum: number;
9
+ }[], name: string, what: string): PdfObject[];
10
+ declare function buildInternalLinkAnnotDict(link: Readonly<LayoutInternalLink>, doc: LayoutDocument, pageAllocs: readonly {
11
+ pageNum: number;
12
+ }[]): PdfObject;
13
+ declare function isLinkItem(item: {
14
+ readonly kind: string;
15
+ }): item is LayoutLink;
16
+ declare function isInternalLinkItem(item: {
17
+ readonly kind: string;
18
+ }): item is LayoutInternalLink;
19
+ declare function buildNotesAnnotDict(notes: string): PdfObject;
20
+ interface AllocatedObject {
21
+ readonly num: number;
22
+ readonly value: PdfObject;
23
+ }
24
+ declare function xrefEntry(offset: number, generation: number, inUse: boolean): string;
25
+ declare function parseResidueRow(residue: Readonly<SourceResidue>): PdfObject | undefined;
26
+ declare function objectContainsReference(obj: PdfObject): boolean;
27
+ declare function restoreResidueRow(source: Record<string, SourceResidue> | undefined, key: string): PdfObject | undefined;
28
+ //#endregion
29
+ export { AllocatedObject, buildInternalLinkAnnotDict, buildLinkAnnotDict, buildNotesAnnotDict, destinationViewArray, isInternalLinkItem, isLinkItem, objectContainsReference, parseResidueRow, resolveDestinationArray, restoreResidueRow, xrefEntry };
@@ -0,0 +1,121 @@
1
+ import { NOTES_ANNOTATION_AUTHOR } from "./notes-annotation-author.js";
2
+ import { pdfArray, pdfDict, pdfHexString, pdfName, pdfNull, pdfNum, pdfRef } from "./objects.js";
3
+ import { ByteReader } from "./bytes/reader.js";
4
+ import { parseValue } from "./parse.js";
5
+ import { textToPdfString } from "./write-strings.js";
6
+ //#region src/write-annotations.ts
7
+ function buildLinkAnnotDict(link) {
8
+ return pdfDict({
9
+ Type: pdfName("Annot"),
10
+ Subtype: pdfName("Link"),
11
+ Rect: pdfArray([
12
+ link.xPt,
13
+ link.yPt,
14
+ link.xPt + link.widthPt,
15
+ link.yPt + link.heightPt
16
+ ].map((n) => pdfNum(n))),
17
+ Border: pdfArray([
18
+ 0,
19
+ 0,
20
+ 0
21
+ ].map((n) => pdfNum(n))),
22
+ A: pdfDict({
23
+ Type: pdfName("Action"),
24
+ S: pdfName("URI"),
25
+ URI: pdfHexString(new TextEncoder().encode(link.uri))
26
+ })
27
+ });
28
+ }
29
+ function destinationViewArray(target) {
30
+ const n = (value) => value === void 0 ? pdfNull() : pdfNum(value);
31
+ if (target.kind === "xyz") return [
32
+ pdfName("XYZ"),
33
+ n(target.leftPt),
34
+ n(target.topPt),
35
+ n(target.zoom)
36
+ ];
37
+ if (target.kind === "fitH") return [pdfName("FitH"), n(target.topPt)];
38
+ if (target.kind === "fitV") return [pdfName("FitV"), n(target.leftPt)];
39
+ if (target.kind === "fitR") return [
40
+ pdfName("FitR"),
41
+ n(target.leftPt),
42
+ n(target.bottomPt),
43
+ n(target.rightPt),
44
+ n(target.topPt)
45
+ ];
46
+ if (target.kind === "fitBH") return [pdfName("FitBH"), n(target.topPt)];
47
+ if (target.kind === "fitBV") return [pdfName("FitBV"), n(target.leftPt)];
48
+ return [pdfName(target.kind === "fitB" ? "FitB" : "Fit")];
49
+ }
50
+ function resolveDestinationArray(doc, pageAllocs, name, what) {
51
+ const destination = doc.destinations?.find((d) => d.name === name);
52
+ if (destination === void 0) throw new Error(`${what} names destination "${name}", which the document's destinations table does not carry — this is a caller-invariant violation`);
53
+ const targetPage = pageAllocs[destination.pageIndex];
54
+ if (targetPage === void 0) throw new Error(`destination "${destination.name}" names page index ${destination.pageIndex}, which is beyond the document's own pages — this is a caller-invariant violation`);
55
+ return [pdfRef(targetPage.pageNum, 0), ...destinationViewArray(destination.target)];
56
+ }
57
+ function buildInternalLinkAnnotDict(link, doc, pageAllocs) {
58
+ return pdfDict({
59
+ Type: pdfName("Annot"),
60
+ Subtype: pdfName("Link"),
61
+ Rect: pdfArray([
62
+ link.xPt,
63
+ link.yPt,
64
+ link.xPt + link.widthPt,
65
+ link.yPt + link.heightPt
66
+ ].map((v) => pdfNum(v))),
67
+ Border: pdfArray([
68
+ 0,
69
+ 0,
70
+ 0
71
+ ].map((v) => pdfNum(v))),
72
+ Dest: pdfArray(resolveDestinationArray(doc, pageAllocs, link.destination, "internal link"))
73
+ });
74
+ }
75
+ function isLinkItem(item) {
76
+ return item.kind === "link";
77
+ }
78
+ function isInternalLinkItem(item) {
79
+ return item.kind === "internalLink";
80
+ }
81
+ const NOTES_ANNOTATION_HIDDEN_FLAG = 2;
82
+ function buildNotesAnnotDict(notes) {
83
+ return pdfDict({
84
+ Type: pdfName("Annot"),
85
+ Subtype: pdfName("Text"),
86
+ Rect: pdfArray([
87
+ 0,
88
+ 0,
89
+ 0,
90
+ 0
91
+ ].map((n) => pdfNum(n))),
92
+ Contents: textToPdfString(notes),
93
+ T: textToPdfString(NOTES_ANNOTATION_AUTHOR),
94
+ F: pdfNum(NOTES_ANNOTATION_HIDDEN_FLAG)
95
+ });
96
+ }
97
+ const XREF_OFFSET_DIGITS = 10;
98
+ const XREF_GENERATION_DIGITS = 5;
99
+ function xrefEntry(offset, generation, inUse) {
100
+ return `${offset.toString().padStart(XREF_OFFSET_DIGITS, "0")} ${generation.toString().padStart(XREF_GENERATION_DIGITS, "0")} ${inUse ? "n" : "f"} \n`;
101
+ }
102
+ function parseResidueRow(residue) {
103
+ const reader = new ByteReader(new TextEncoder().encode(residue.xml));
104
+ return parseValue(reader, () => void 0);
105
+ }
106
+ function objectContainsReference(obj) {
107
+ if (obj.kind === "ref") return true;
108
+ if (obj.kind === "array") return obj.items.some(objectContainsReference);
109
+ if (obj.kind === "dict") return [...obj.entries.values()].some(objectContainsReference);
110
+ if (obj.kind === "stream") return [...obj.dict.entries.values()].some(objectContainsReference);
111
+ return false;
112
+ }
113
+ function restoreResidueRow(source, key) {
114
+ const row = source?.[key];
115
+ if (row === void 0) return;
116
+ const parsed = parseResidueRow(row);
117
+ if (parsed === void 0 || objectContainsReference(parsed)) return;
118
+ return parsed;
119
+ }
120
+ //#endregion
121
+ export { buildInternalLinkAnnotDict, buildLinkAnnotDict, buildNotesAnnotDict, destinationViewArray, isInternalLinkItem, isLinkItem, objectContainsReference, parseResidueRow, resolveDestinationArray, restoreResidueRow, xrefEntry };