pdf-skryba 0.10.1 → 1.0.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 (110) hide show
  1. package/CHANGELOG.md +58 -3
  2. package/README.md +22 -20
  3. package/dist/first-party/reader.js +5849 -5088
  4. package/dist/first-party/reader.js.map +4 -4
  5. package/dist/first-party.js +118 -92
  6. package/dist/first-party.js.map +3 -3
  7. package/dist/index.js +5928 -5164
  8. package/dist/index.js.map +4 -4
  9. package/dist/index.min.js +4 -4
  10. package/dist/light.js +152 -113
  11. package/dist/light.js.map +3 -3
  12. package/dist/light.min.js +1 -1
  13. package/dist/types/extractor/codecs/ccitt-fax.d.ts +3 -3
  14. package/dist/types/extractor/document-cache.d.ts +1 -1
  15. package/dist/types/extractor/extraction-cost.d.ts +2 -2
  16. package/dist/types/extractor/font-weight.d.ts +2 -2
  17. package/dist/types/extractor/glyph-positions.d.ts +14 -14
  18. package/dist/types/extractor/glyph-runs.d.ts +4 -4
  19. package/dist/types/extractor/glyph-window.d.ts +2 -2
  20. package/dist/types/extractor/pdf-aside-figures.d.ts +1 -1
  21. package/dist/types/extractor/pdf-bands.d.ts +2 -2
  22. package/dist/types/extractor/pdf-ccitt-images.d.ts +1 -1
  23. package/dist/types/extractor/pdf-colour-ours.d.ts +4 -4
  24. package/dist/types/extractor/pdf-decrypt.d.ts +1 -1
  25. package/dist/types/extractor/pdf-document-info.d.ts +4 -4
  26. package/dist/types/extractor/pdf-document-scale.d.ts +1 -1
  27. package/dist/types/extractor/pdf-embedded-images.d.ts +1 -1
  28. package/dist/types/extractor/pdf-facts.d.ts +3 -3
  29. package/dist/types/extractor/pdf-flate-images.d.ts +1 -1
  30. package/dist/types/extractor/pdf-font-bridge.d.ts +3 -3
  31. package/dist/types/extractor/pdf-font-objects.d.ts +5 -5
  32. package/dist/types/extractor/pdf-fonts/font-text.d.ts +6 -6
  33. package/dist/types/extractor/pdf-fonts/predefined-cmaps.d.ts +6 -6
  34. package/dist/types/extractor/pdf-fonts/type1-encoding.d.ts +1 -1
  35. package/dist/types/extractor/pdf-fonts/widths.d.ts +2 -2
  36. package/dist/types/extractor/pdf-glyph-source.d.ts +13 -14
  37. package/dist/types/extractor/pdf-hidden-text.d.ts +3 -3
  38. package/dist/types/extractor/pdf-image-anchors.d.ts +1 -1
  39. package/dist/types/extractor/pdf-image-pixels.d.ts +13 -13
  40. package/dist/types/extractor/pdf-image-refusal.d.ts +2 -2
  41. package/dist/types/extractor/pdf-images.d.ts +4 -4
  42. package/dist/types/extractor/pdf-jpeg-images.d.ts +1 -1
  43. package/dist/types/extractor/pdf-layers.d.ts +1 -1
  44. package/dist/types/extractor/pdf-letter-spacing.d.ts +1 -1
  45. package/dist/types/extractor/pdf-line-breaks.d.ts +2 -2
  46. package/dist/types/extractor/pdf-links-ours.d.ts +2 -2
  47. package/dist/types/extractor/pdf-links.d.ts +2 -2
  48. package/dist/types/extractor/pdf-model.d.ts +8 -8
  49. package/dist/types/extractor/pdf-objects/bounds.d.ts +4 -4
  50. package/dist/types/extractor/pdf-objects/content.d.ts +4 -4
  51. package/dist/types/extractor/pdf-objects/document.d.ts +14 -14
  52. package/dist/types/extractor/pdf-objects/objects.d.ts +10 -10
  53. package/dist/types/extractor/pdf-objects/parse.d.ts +4 -4
  54. package/dist/types/extractor/pdf-objects/refusal.d.ts +2 -2
  55. package/dist/types/extractor/pdf-objects/streams.d.ts +4 -4
  56. package/dist/types/extractor/pdf-objects/xref.d.ts +3 -3
  57. package/dist/types/extractor/pdf-objstm-guard.d.ts +1 -1
  58. package/dist/types/extractor/pdf-objstm-source.d.ts +1 -1
  59. package/dist/types/extractor/pdf-open.d.ts +1 -1
  60. package/dist/types/extractor/pdf-ops-ours.d.ts +3 -3
  61. package/dist/types/extractor/pdf-ops.d.ts +9 -9
  62. package/dist/types/extractor/pdf-outline.d.ts +3 -3
  63. package/dist/types/extractor/pdf-page-content.d.ts +2 -2
  64. package/dist/types/extractor/pdf-page-figures.d.ts +1 -1
  65. package/dist/types/extractor/pdf-page-plan.d.ts +3 -3
  66. package/dist/types/extractor/pdf-page-stages.d.ts +2 -2
  67. package/dist/types/extractor/pdf-paragraphs.d.ts +1 -1
  68. package/dist/types/extractor/pdf-paths-ours.d.ts +4 -8
  69. package/dist/types/extractor/pdf-reference-ours.d.ts +2 -2
  70. package/dist/types/extractor/pdf-region-order.d.ts +2 -2
  71. package/dist/types/extractor/pdf-scanned.d.ts +2 -2
  72. package/dist/types/extractor/pdf-smask.d.ts +3 -3
  73. package/dist/types/extractor/pdf-source.d.ts +31 -32
  74. package/dist/types/extractor/pdf-stencil-images.d.ts +1 -1
  75. package/dist/types/extractor/pdf-structure.d.ts +1 -1
  76. package/dist/types/extractor/pdf-symbol-page.d.ts +2 -2
  77. package/dist/types/extractor/pdf-symbol-verdict.d.ts +3 -3
  78. package/dist/types/extractor/pdf-table-detector.d.ts +6 -6
  79. package/dist/types/extractor/pdf-table-render.d.ts +1 -1
  80. package/dist/types/extractor/text-writing-direction.d.ts +1 -1
  81. package/dist/types/layout/cell-text.d.ts +1 -1
  82. package/dist/types/layout/column-discriminant.d.ts +2 -2
  83. package/dist/types/layout/column-grid.d.ts +4 -4
  84. package/dist/types/layout/cut-word.d.ts +3 -3
  85. package/dist/types/layout/geometry.d.ts +3 -3
  86. package/dist/types/layout/grid-band.d.ts +3 -3
  87. package/dist/types/layout/gutter.d.ts +6 -6
  88. package/dist/types/layout/heading-sizes.d.ts +2 -2
  89. package/dist/types/layout/hidden-repaints.d.ts +1 -1
  90. package/dist/types/layout/hyphenation.d.ts +1 -1
  91. package/dist/types/layout/image-frontier.d.ts +1 -1
  92. package/dist/types/layout/induced-markers.d.ts +2 -2
  93. package/dist/types/layout/intervals.d.ts +3 -3
  94. package/dist/types/layout/list.d.ts +9 -9
  95. package/dist/types/layout/merged-cells.d.ts +1 -1
  96. package/dist/types/layout/mode.d.ts +2 -2
  97. package/dist/types/layout/superscript.d.ts +1 -1
  98. package/dist/types/layout/text-size.d.ts +1 -1
  99. package/dist/types/layout/vector-grid.d.ts +5 -5
  100. package/dist/types/lib/chunk.d.ts +1 -1
  101. package/dist/types/lib/extent.d.ts +2 -2
  102. package/dist/types/lib/link-schemes.d.ts +1 -1
  103. package/dist/types/lib/pdf-first-party.d.ts +4 -4
  104. package/dist/types/lib/pdf-light.d.ts +2 -2
  105. package/dist/types/lib/reader-options.d.ts +3 -3
  106. package/dist/types/lib/table-leading-bands.d.ts +2 -2
  107. package/dist/types/pipeline/cut-paragraph-repair.d.ts +1 -1
  108. package/dist/types/pipeline/glued-word-repair.d.ts +1 -1
  109. package/dist/types/pipeline/pdf-conservation-source.d.ts +8 -8
  110. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -2,14 +2,63 @@
2
2
 
3
3
  All notable changes to `pdf-skryba` are written here. The format follows
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the package follows
5
- [Semantic Versioning](https://semver.org/spec/v2.0.0.html): while the version is `0.x`, a minor
6
- version may break the published surface, and a patch never does. Dates are the publication dates on
7
- the npm registry (UTC).
5
+ [Semantic Versioning](https://semver.org/spec/v2.0.0.html): since 1.0.0, only a major version may break the
6
+ published surface (`pdf-skryba`, `pdf-skryba/light` and their minified twins); before 1.0, a minor version could.
7
+ The `pdf-skryba/first-party` entries are not covered (see the README). Dates are the publication dates on the npm
8
+ registry (UTC).
8
9
 
9
10
  The package was named `skryba` from 0.1.0 to 0.6.2; `skryba` stays frozen at 0.6.2 and is deprecated
10
11
  with the message « Renamed to pdf-skryba ». Before 0.1.0 the same reader was published as
11
12
  `@miksumia/reader`, which the registry no longer serves; those versions are not reconstructed here.
12
13
 
14
+ ## [1.0.0] - 2026-11-29
15
+
16
+ The first stable version. Every published name now follows one vocabulary: functions are verbs, booleans start
17
+ with `is`, `has`, `can` or `should`, and no name is abbreviated. Nothing changes in what the reader publishes: the
18
+ pages of 197 reference PDFs are byte-identical to 0.10.2.
19
+
20
+ ### Changed (breaking)
21
+
22
+ - `pdf-skryba/light`: `noWorse` → `isGluedRepairNoWorse`, `joinNoWorse` → `isParagraphJoinNoWorse`.
23
+ - `ExtractOptions`: `ocr` → `canUseOcr`, `scanAsImages` → `shouldReturnScansAsImages`, `readAll` →
24
+ `shouldReadAllPages`.
25
+ - The result of `extractPdf`: `doc` → `document`, `docFacts` → `documentFacts`; in `PdfDocumentFacts`, `tagged` →
26
+ `isTagged`, `linearized` → `isLinearized`, `form` → `hasForm`.
27
+ - `pdf-skryba/first-party` (not covered by Semantic Versioning, listed for the record): `chunk` → `splitIntoChunks`,
28
+ `PUBLISHED_SCHEME` → `PUBLISHED_LINK_SCHEME_PATTERN`, `ReferenceCycle` → `ReferenceTextRun` (its fields `artifact`,
29
+ `rotated`, `hidden`, `note`, `middle` → `isArtifact`, `isRotated`, `isHidden`, `isInNote`, `verticalCentre`),
30
+ `PdfConservationSource.letters` → `letterReading`, and the property names of the objects the reader entry returns
31
+ (`PdfReference.objectNumber`/`generationNumber`, `dictionary`, `visibleBox`, `operator`/`operands`…).
32
+ - About 200 names inside the reader, reachable from no entry, take the same vocabulary.
33
+
34
+ ### Removed
35
+
36
+ - `PdfTextRun.dir`, always `"ltr"` and read by nothing.
37
+ - `MAX_STATE_DEPTH`: it was the same bound as `GRAPHICS_STATE_MAX_DEPTH` (256), which stays.
38
+
39
+ ### Other
40
+
41
+ - The column evidence value `"chars"` (`extractPdfPages` option `columns`) is now `"characters"`.
42
+ - `PathBuilder`'s members are truly private (`#private` in the published declaration).
43
+ - The type check covers the development scripts under `tools/`.
44
+
45
+ ## [0.10.2] - 2026-11-28
46
+
47
+ ### Fixed
48
+
49
+ - A Type 1 font program that names an encoding inherited from `Object.prototype` (`/Encoding toString def`) now
50
+ abstains instead of throwing, which lost the glyphs of that font.
51
+ - A content-stream operator named `toString`, `__proto__`, `constructor` or `valueOf` is no longer mapped to an
52
+ operator whose name is not a string.
53
+
54
+ ### Changed
55
+
56
+ - The whole reader was cleaned for readability, with no change of behaviour: the published type declarations are
57
+ byte-identical to 0.10.1, and what 197 reference PDFs publish is byte-identical too.
58
+ - Two property tests found failing by the weekly ×100 fuzz were wrong, not the reader: the test writer no longer
59
+ writes a cross-reference stream with no subsection (ISO 32000-1 §7.5.4), and the decryption property accepts the
60
+ security refusal a damaged image may raise, as designed.
61
+
13
62
  ## [0.10.1] - 2026-11-28
14
63
 
15
64
  ### Changed
@@ -225,7 +274,13 @@ The registry also lists `0.0.0-stage` for each name, a placeholder npm creates f
225
274
  publishing. It is not a release.
226
275
 
227
276
  [Unreleased]: https://github.com/numiastowski-design/pdf-skryba
277
+
278
+ [1.0.0]: https://www.npmjs.com/package/pdf-skryba/v/1.0.0
279
+ [0.10.2]: https://www.npmjs.com/package/pdf-skryba/v/0.10.2
228
280
  [0.10.1]: https://www.npmjs.com/package/pdf-skryba/v/0.10.1
281
+ [0.10.0]: https://www.npmjs.com/package/pdf-skryba/v/0.10.0
282
+ [0.9.1]: https://www.npmjs.com/package/pdf-skryba/v/0.9.1
283
+ [0.9.0]: https://www.npmjs.com/package/pdf-skryba/v/0.9.0
229
284
  [0.8.0]: https://www.npmjs.com/package/pdf-skryba/v/0.8.0
230
285
  [0.7.0]: https://www.npmjs.com/package/pdf-skryba/v/0.7.0
231
286
  [0.6.2]: https://www.npmjs.com/package/skryba/v/0.6.2
package/README.md CHANGED
@@ -29,13 +29,15 @@ if (path === undefined) throw new Error("usage: node read.js <file.pdf>");
29
29
  // A refusal is told by its name: that holds whichever entry, and whichever copy of the package, threw it.
30
30
  const isRefusal = (error: unknown): error is ReaderError => error instanceof Error && error.name === "ReaderError";
31
31
 
32
- // No AI reading here: with `ocr: false`, a page without a text layer is counted, never sent.
32
+ // No AI reading here: with `canUseOcr: false`, a page without a text layer is counted, never sent.
33
33
  const vision = { analyzeDocument: () => Promise.reject(new Error("no AI reading configured")) };
34
34
 
35
35
  try {
36
- const { doc, pageCount, notices } = await extractPdf(new Uint8Array(readFileSync(path)), vision, { ocr: false });
36
+ const { document, pageCount, notices } = await extractPdf(new Uint8Array(readFileSync(path)), vision, {
37
+ canUseOcr: false,
38
+ });
37
39
  console.log(`pages: ${pageCount}`);
38
- const [pages] = doc.blocks;
40
+ const [pages] = document.blocks;
39
41
  if (pages?.kind === "tabs") console.log(`blocks on page 1: ${pages.tabs[0]?.blocks.length ?? 0}`);
40
42
  console.log(`notices: ${notices?.length ?? 0}`);
41
43
  } catch (error) {
@@ -52,18 +54,18 @@ import { readFileSync } from "node:fs";
52
54
  import { extractPdf } from "pdf-skryba";
53
55
 
54
56
  const bytes = new Uint8Array(readFileSync("report.pdf"));
55
- const { doc, pageCount, notices } = await extractPdf(bytes, vision, { ocr: false });
57
+ const { document, pageCount, notices } = await extractPdf(bytes, vision, { canUseOcr: false });
56
58
 
57
- pageCount; // 12
58
- doc.blocks[0].kind; // "tabs" — one tab per page
59
- doc.blocks[0].tabs[0]; // its blocks: headings, paragraphs, lists, tables, images
60
- notices; // every part it could not read, each with a named reason
59
+ pageCount; // 12
60
+ document.blocks[0].kind; // "tabs" — one tab per page
61
+ document.blocks[0].tabs[0]; // its blocks: headings, paragraphs, lists, tables, images
62
+ notices; // every part it could not read, each with a named reason
61
63
  ```
62
64
 
63
65
  ## Scanned pages: the AI reading is yours
64
66
 
65
67
  `vision` is a port you implement. It receives a small PDF holding the pages to read and returns one
66
- result per page, in order. With `ocr: false` a page with no text layer is counted and never read; a
68
+ result per page, in order. With `canUseOcr: false` a page with no text layer is counted and never read; a
67
69
  file that is a scan from end to end is refused (`SCANNED_PDF_NEEDS_AI_OCR`).
68
70
 
69
71
  ```js
@@ -72,10 +74,10 @@ const vision = {
72
74
  };
73
75
 
74
76
  // Hand back the page pictures instead of refusing a full scan:
75
- await extractPdf(bytes, vision, { ocr: false, scanAsImages: true });
77
+ await extractPdf(bytes, vision, { canUseOcr: false, shouldReturnScansAsImages: true });
76
78
 
77
79
  // Or let the AI read every page, text layer included:
78
- await extractPdf(bytes, vision, { readAll: true, languages: ["en", "fr"] });
80
+ await extractPdf(bytes, vision, { shouldReadAllPages: true, languages: ["en", "fr"] });
79
81
  ```
80
82
 
81
83
  ## Your own ceilings
@@ -96,11 +98,11 @@ whichever copy of the package, threw the error. `pdf-skryba/light` exports the t
96
98
 
97
99
  ```js
98
100
  try {
99
- await extractPdf(bytes, vision, { ocr: false });
101
+ await extractPdf(bytes, vision, { canUseOcr: false });
100
102
  } catch (error) {
101
103
  if (error instanceof Error && error.name === "ReaderError") {
102
- error.code; // "SCANNED_PDF_NEEDS_AI_OCR", "FILE_UNSAFE", "EXTRACT_FAILED"…
103
- error.pageCount; // what it knew before refusing
104
+ error.code; // "SCANNED_PDF_NEEDS_AI_OCR", "FILE_UNSAFE", "EXTRACT_FAILED"…
105
+ error.pageCount; // what it knew before refusing
104
106
  }
105
107
  }
106
108
  ```
@@ -116,10 +118,10 @@ import { textConservation } from "pdf-skryba/light";
116
118
  const { conservationSource } = await extractPdf(bytes, vision);
117
119
  const verdict = textConservation(conservationSource.runs, { blocks: myPublishedTexts });
118
120
 
119
- verdict.decision; // "ok" | "lost" | "glued" | "abstain"
120
- verdict.lostLetters; // how many, and
121
- verdict.lostPassages; // where: each passage, with the page it came from
122
- verdict.pages; // the pages concerned
121
+ verdict.decision; // "ok" | "lost" | "glued" | "abstain"
122
+ verdict.lostLetters; // how many, and
123
+ verdict.lostPassages; // where: each passage, with the page it came from
124
+ verdict.pages; // the pages concerned
123
125
  ```
124
126
 
125
127
  ## Principles
@@ -154,8 +156,8 @@ Four entries, two of them the minified twins of the others.
154
156
  - `pdf-skryba` — the reader, `extractPdf`, called as `extractPdf(bytes, vision, options?)`; and
155
157
  `detectLanguage`; with the types of its options and results (`ExtractOptions`, `PdfDocumentFacts`…).
156
158
  - `pdf-skryba/light` — loads no reader. The conservation check: `textConservation`, `lostWords`,
157
- `placeLostPassages`, `gluedWordEdits`, `cutParagraphEdits`, `noWorse`, `joinNoWorse`, `wordKeysOf`,
158
- `conservationKey`. Refusals and ceilings: `ReaderError`, `MAX_PAYLOAD_BYTES`. And the types of the
159
+ `placeLostPassages`, `gluedWordEdits`, `cutParagraphEdits`, `isGluedRepairNoWorse`,
160
+ `isParagraphJoinNoWorse`, `wordKeysOf`, `conservationKey`. Refusals and ceilings: `ReaderError`, `MAX_PAYLOAD_BYTES`. And the types of the
159
161
  representation (`IRDoc`, `IRBlock`, `TableData`…).
160
162
  - `pdf-skryba/min` and `pdf-skryba/light/min` — the same code, minified.
161
163