@kamilio/wire 0.1.36 → 0.1.37

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 (34) hide show
  1. package/README.md +6 -0
  2. package/dist/adapters/drive-pdf.d.ts +2 -0
  3. package/dist/adapters/drive-pdf.d.ts.map +1 -0
  4. package/dist/adapters/drive-pdf.js +109 -0
  5. package/dist/adapters/drive-pdf.js.map +1 -0
  6. package/dist/adapters/gdrive.d.ts +6 -0
  7. package/dist/adapters/gdrive.d.ts.map +1 -0
  8. package/dist/adapters/gdrive.js +211 -0
  9. package/dist/adapters/gdrive.js.map +1 -0
  10. package/dist/adapters/pdf-notices/THIRD_PARTY_NOTICES.md +631 -0
  11. package/dist/adapters/pdf-notices/licenses/AGG-2.3.txt +7 -0
  12. package/dist/adapters/pdf-notices/licenses/MIT.txt +21 -0
  13. package/dist/adapters/pdf-notices/licenses/PDFIUM-BSD.txt +27 -0
  14. package/dist/adapters/pdf-notices/licenses/PDFJS-APACHE-2.0.txt +177 -0
  15. package/dist/adapters/pdf-notices/licenses/PYPDF-BSD.txt +29 -0
  16. package/dist/adapters/pdf-notices/licenses/PYTHON-PSF.txt +254 -0
  17. package/dist/adapters/pdf-notices/licenses/V8-BSD.txt +61 -0
  18. package/dist/adapters/root.d.ts +2 -0
  19. package/dist/adapters/root.d.ts.map +1 -1
  20. package/dist/adapters/root.js +10 -0
  21. package/dist/adapters/root.js.map +1 -1
  22. package/dist/cli.d.ts.map +1 -1
  23. package/dist/cli.js +3 -1
  24. package/dist/cli.js.map +1 -1
  25. package/dist/executable.d.ts.map +1 -1
  26. package/dist/executable.js +2 -1
  27. package/dist/executable.js.map +1 -1
  28. package/dist/pdf-reader.mjs +171 -0
  29. package/package.json +9 -3
  30. package/src/adapters/drive-pdf.ts +106 -0
  31. package/src/adapters/gdrive.ts +213 -0
  32. package/src/adapters/root.ts +11 -1
  33. package/src/cli.ts +2 -1
  34. package/src/executable.ts +2 -1
@@ -0,0 +1,631 @@
1
+ # pdf-ast licensing
2
+
3
+ Original code is MIT-licensed; see `licenses/MIT.txt`. The bundled and adapted
4
+ components below retain their respective terms and notices.
5
+
6
+ # Mozilla PDF.js
7
+
8
+ The numeric recovery and malformed-command handling in `src/cos/lexer.ts`, and
9
+ the regression cases in `src/cos/pdfjs-lexer.test.ts`, are adapted from Mozilla
10
+ PDF.js (`src/core/parser.js` and `test/unit/parser_spec.js`), revision
11
+ `91041fb94d6744bc2a5bccd9aad28d617faa8195`.
12
+
13
+ Copyright 2017 Mozilla Foundation. Licensed under the Apache License, Version 2.0;
14
+ the full license is in `licenses/PDFJS-APACHE-2.0.txt`.
15
+
16
+ Adaptations use the local byte-offset/token API, preserve explicit token budgets
17
+ and existing exponent support, and translate Jasmine assertions to Vitest. These
18
+ files have been modified from the upstream originals.
19
+
20
+ The content operator vocabulary, known-command token boundaries, and operand
21
+ recovery in `src/content/operators.ts`, `src/content/parser.ts`, and
22
+ `src/cos/lexer.ts` follow PDF.js `EvaluatorPreprocessor` and `Lexer`. The cases
23
+ in `src/content/pdfjs-operators.test.ts` are adapted from
24
+ `test/unit/evaluator_spec.js` at the same revision. Nested text assertions use
25
+ `BT`/`ET` to expose local text AST nodes; unmatched `Q` is omitted from the local
26
+ balanced group representation. Copyright 2017 Mozilla Foundation, Apache-2.0.
27
+
28
+ The binary-string conversions in `src/bytes.ts` and five utility test cases in
29
+ `src/bytes.test.ts` are adapted from `src/shared/util.js` and
30
+ `test/unit/util_spec.js` at the same revision (Copyright Mozilla Foundation,
31
+ Apache-2.0). Adaptations add TypeScript types, use spread with bounded 8192-byte
32
+ chunks, and replace the upstream error helper with Error. Additional tests cover
33
+ all byte values, content serialization, and form appearance resource isolation.
34
+
35
+ The bounded zlib decoder in `src/cos/flate-stream.ts` adapts the bundled PDF.js
36
+ `FlateStream` Huffman decoding and malformed stored-block recovery. Copyright
37
+ Mozilla Foundation, Apache-2.0. It replaces the growing output buffer with a
38
+ 32 KiB circular history, suspends for input/output chunks, and preserves partial
39
+ output recovery. The original bundled source and license remain included.
40
+
41
+ Source: https://github.com/mozilla/pdf.js
42
+
43
+ # qpdf
44
+
45
+ The fixtures documented in `src/fixtures/SOURCES.md` and the shared-page
46
+ selection regression in `src/edit/qpdf-resources.test.ts` come from qpdf revision
47
+ `4eba95899886e851cc41d76886483b347612f2a8`. Resource-use analysis also follows
48
+ qpdf's `ResourceFinder` and `QPDFPageObjectHelper` behavior.
49
+
50
+ Copyright (c) 2005-2021 Jay Berkenbilt, 2022-2026 Jay Berkenbilt and Manfred Holger.
51
+ Licensed under Apache-2.0; see `licenses/PDFJS-APACHE-2.0.txt`. The tests were
52
+ adapted to the local TypeScript API and extended with redaction cases.
53
+
54
+ Source: https://github.com/qpdf/qpdf
55
+
56
+
57
+ # PDF.js standalone image decoders
58
+
59
+ `src/vendor/pdfjs-image-decoders.mjs` vendors the official PDF.js 4.1.392
60
+ `image_decoders/pdf.image_decoders.mjs` distribution (Mozilla Foundation,
61
+ Apache-2.0). This is the last PDF.js release with synchronous JavaScript JPX
62
+ and JBIG2 decoders, matching this library's synchronous, portable API.
63
+ Local JPX bounds checks reject truncated boxes, markers, tile parts, zero tile
64
+ sizes, and zero component subsampling before allocation. A 101-byte JP2 prefix
65
+ otherwise exhausts memory in the upstream build. Other adaptations remove the global export
66
+ assignment and unavailable source-map reference, add per-instance dimension
67
+ callbacks to enforce requested image budgets before pixel/region allocation,
68
+ preserve budget errors through JPX recovery, add per-instance JPX pre-allocation
69
+ charges for decoder buffers and conservative structural metadata, add JBIG2
70
+ packed standalone output and per-instance admission for contexts, symbols,
71
+ regions, segment metadata and custom Huffman state, add JPEG row-window conversion
72
+ and per-instance pre-allocation callbacks for typed buffers and conservative
73
+ metadata accounting, add a generated-code lint
74
+ comment, and provide a local TypeScript declaration for the used API.
75
+
76
+ Source: https://unpkg.com/pdfjs-dist@4.1.392/image_decoders/pdf.image_decoders.mjs
77
+ Upstream SHA-256: `257b89097a3266bcae8cd04d6faaec135a0774f6762b4476c44f0c76f8334f49`.
78
+ Full license: `licenses/PDFJS-APACHE-2.0.txt`.
79
+ Fixture provenance and independent reference pixels are documented in
80
+ `src/fixtures/SOURCES.md`.
81
+
82
+ # PDF.js font parsing, metrics, and path compilation
83
+
84
+ `src/vendor/pdfjs-fonts.mjs` bundles PDF.js CFF parsing/compilation, Type 2 path
85
+ compilation, encodings, Adobe glyph names, and standard-font metrics from revision
86
+ `91041fb94d6744bc2a5bccd9aad28d617faa8195` (Mozilla Foundation, Apache-2.0).
87
+ Source adaptations export the internal `Type2Compiled` class and retain Float32
88
+ path coordinates on every runtime, including those supporting Float16; local
89
+ code converts its path commands to PDF AST segments without evaluating generated
90
+ JavaScript. `src/fonts/pdfjs-cff.test.ts` ports eight cases from
91
+ `test/unit/cff_parser_spec.js` to Vitest, retaining the Adobe CFF specification
92
+ example bytes and the upstream expectations. The JavaScript bundle can be
93
+ regenerated with `scripts/vendor-pdfjs-fonts.mjs <PDF.js checkout>`.
94
+
95
+ # PDFium/Foxit standard fonts
96
+
97
+ `src/fonts/standard-font-data.ts` contains base64-encoded, unmodified CFF font
98
+ programs. Serif, fixed-width, Symbol, and Dingbats faces are the `Foxit*.pfb`
99
+ files from the same PDF.js revision's `external/standard_fonts` directory.
100
+ Despite their extension these are CFF programs, not Type 1 PFB containers.
101
+ Sans faces are the byte arrays in `FoxitSans{,Bold,Italic,BoldItalic}.cpp` from
102
+ PDFium revision `a84323421e94f484faca52dd9d027934eba42ab8`, directory
103
+ `core/fxge/fontdata/chromefontdata`.
104
+
105
+ Copyright 2014 The PDFium Authors. Original code copyright 2014 Foxit Software
106
+ Inc. Licensed under the BSD terms in `licenses/PDFIUM-BSD.txt`.
107
+ Sources: https://github.com/chromium/pdfium/tree/a84323421e94f484faca52dd9d027934eba42ab8/core/fxge/fontdata/chromefontdata
108
+ and https://github.com/mozilla/pdf.js/tree/91041fb94d6744bc2a5bccd9aad28d617faa8195/external/standard_fonts
109
+
110
+ Regenerate the portable font-data module using
111
+ `scripts/generate-standard-font-data.mjs <PDF.js checkout> <directory containing FoxitSans*.cpp>`.
112
+ No Liberation font files are included.
113
+
114
+ # PDF.js JPEG decoding
115
+
116
+ `src/extract/images.ts` uses the `JpegImage` export of the standalone decoder
117
+ bundle above, replacing the local handwritten JPEG codec. PDF `/Decode` and
118
+ `/ColorTransform` handling follows PDF.js v4.1.392 `src/core/jpeg_stream.js`.
119
+ The vendored decoder accepts an optional dimension callback before allocating
120
+ frame components, preserving caller-specified byte budgets. Local changes also
121
+ interpolate 2:1 subsampled four-component JPEG samples across row boundaries.
122
+ The local CMYK converter uses four-dimensional interpolation of the numeric
123
+ DeviceCMYK corner colors used by Poppler, rather than PDF.js's polynomial.
124
+ `src/extract/jpeg-reference.test.ts` ports the CMYK image shape expectation from
125
+ `test/unit/api_spec.js` (issue 4888) and the baseline/extended/progressive SOF
126
+ header cases from `test/unit/jpeg_stream_spec.js` at revision
127
+ `91041fb94d6744bc2a5bccd9aad28d617faa8195`. The SOF cases assert local byte-budget
128
+ behavior instead of browser ImageDecoder availability. Independent pixel
129
+ oracles extend those upstream checks; provenance is in `src/fixtures/SOURCES.md`.
130
+ Mozilla Foundation, Apache-2.0; see `licenses/PDFJS-APACHE-2.0.txt`.
131
+
132
+ # Embedded CFF integration
133
+
134
+ `src/fonts/cff.ts` reuses the same PDF.js CFF parser/compiler and Type 2 path
135
+ compiler for embedded Type1C and CIDFontType0C programs. Input bytes are copied
136
+ before PDF.js's in-place charstring repairs. Charset CIDs select glyphs directly;
137
+ PDF.js encoding tables and PDF Differences select simple-font glyphs. The shared
138
+ path adapter also renders standard fonts and supplies the Unicode mapping needed
139
+ by Type 2 seac compositions. `src/fonts/pdfjs-cff-mapping.test.ts` ports nine
140
+ charset/encoding/FDSelect cases from `test/unit/cff_parser_spec.js` at the pinned
141
+ revision, preserving input bytes and expected mappings. Mozilla Foundation,
142
+ Apache-2.0; see `licenses/PDFJS-APACHE-2.0.txt`.
143
+
144
+ # Embedded Type 1 integration
145
+
146
+ The font bundle also includes PDF.js `Type1Font` and `Type1Parser` at the pinned
147
+ revision. `src/fonts/type1.ts` uses their PFB/PFA handling, eexec/charstring
148
+ decryption, Type 1-to-Type 2 conversion, and original glyph mapping. It restores
149
+ the original charset after CFF conversion, preserves the embedded .notdef shape,
150
+ and follows `src/core/fonts.js` for seac base/accent selection and displacement.
151
+ `src/fonts/pdfjs-type1.test.ts` ports all 19 cases from
152
+ `test/unit/type1_parser_spec.js`, including CID binary/hex data, subroutines,
153
+ encryption, and malformed/truncated inputs. Adaptations add TypeScript types,
154
+ Vitest imports, and portable byte-to-hex conversion. Copyright 2017 Mozilla
155
+ Foundation, Apache-2.0; see `licenses/PDFJS-APACHE-2.0.txt`.
156
+
157
+ # ToUnicode CMap decoding
158
+
159
+ The same bundle includes the standalone `CMap` class and range budget
160
+ from PDF.js `src/core/cmap.js`; the regeneration script extracts that class without
161
+ its browser/network factory and adds optional allocation callbacks before mapping
162
+ entries or codespace ranges. The existing oversized-range recovery runs before
163
+ allocation callbacks; caller memory rejections propagate. `src/fonts/cmap.ts` adapts the upstream bfchar,
164
+ bfrange, cidchar, cidrange, and codespace block grammar to the existing synchronous
165
+ lexer and delegates range expansion and variable-length character decoding to
166
+ `CMap`. UTF-16BE conversion follows `PartialEvaluator.readToUnicode`, including
167
+ numeric entries and omitted leading zero bytes; local compatibility infers a fixed
168
+ source width when a codespace declaration is absent.
169
+ `src/fonts/cmap-codespaces.test.ts` ports eight cases from
170
+ `test/unit/cmap_spec.js` plus the issue 18099 odd-length destination behavior from
171
+ `src/core/evaluator.js`, and adds integration cases. The tests adapt raw CMap
172
+ values to the public Unicode API. Copyright Mozilla Foundation, Apache-2.0, pinned
173
+ revision `91041fb94d6744bc2a5bccd9aad28d617faa8195`.
174
+
175
+
176
+ # TrueType CID-to-glyph selection
177
+
178
+ `src/content/evaluator.ts` follows PDF.js
179
+ `PartialEvaluator.readCidToGidMap` (`src/core/evaluator.js`, pinned revision
180
+ above) when reading big-endian glyph IDs, including zero-padding an odd trailing
181
+ high byte. The local dense map preserves explicit zero entries and selects glyph
182
+ zero for CIDs outside a supplied stream; Identity and omitted maps retain direct
183
+ CID-to-GID selection. Unicode extraction mappings do not choose CID font shapes.
184
+
185
+ Missing `cmap` tables are accepted following PDF.js `readCmapTable`.
186
+ `src/fonts/truetype.ts` adapts `readPostScriptTable` for version 1/2 glyph names,
187
+ using the upstream `MacStandardGlyphOrdering` table from `fonts_utils.js`.
188
+ Simple fonts without `cmap` use PDF.js-style BaseEncoding/Differences lookup
189
+ against those names. Synthetic tests verify CID and simple-font shapes separately
190
+ from their ToUnicode labels. The same pinned revision and Apache-2.0 license apply.
191
+
192
+
193
+ The CMap block parser and code reader are shared by ToUnicode and embedded Type0
194
+ Encoding streams. Following PDF.js font mapping, source character codes select
195
+ Unicode labels, while the Encoding CMap's CIDs select widths and embedded glyphs.
196
+ The synchronous integration adds no browser or external CMap-fetch dependency.
197
+
198
+
199
+ Word-spacing classification follows PDF.js `Font.charsToGlyphs`
200
+ (`src/core/fonts.js`) and canvas text painting: only an original one-byte 0x20
201
+ receives Tw, regardless of its Unicode label. The internal CMap reader preserves
202
+ that classification without changing the public ToUnicode result shape.
203
+
204
+ Simple-font character segmentation also follows `Font.charsToGlyphs`: Type1,
205
+ TrueType, and Type3 strings use single-byte codes even when ToUnicode declares
206
+ a wider codespace. `src/fonts/simple-font-codespace.test.ts` checks that behavior
207
+ and the original upstream issue17069 equality fixture, including TJ fragments,
208
+ word spacing, Unicode labels spanning multiple characters, and save/reopen.
209
+
210
+ Ordinary clipping follows PDF.js `CanvasGraphics.consumePath`: install pending
211
+ `W`/`W*` intersections after painting the current path, retaining nonzero/even-odd
212
+ winding and implicit closure. `src/render/path-clipping.test.ts` ports the normal
213
+ rendering assertions from `test/unit/api_spec.js`'s `should render with
214
+ operationsFilter` case (7200 black and 12800 white pixels) and the unchanged
215
+ `clippath.pdf` fixture. Other local cases cover curves, reversed rectangles,
216
+ transforms, save/restore, text/image intersections, and issue17069's signature.
217
+
218
+ # PDFium / Anti-Grain Geometry curve subdivision
219
+
220
+ `src/render/cubic.ts` adapts `curve4_div` from PDFium revision
221
+ `a84323421e94f484faca52dd9d027934eba42ab8`, file
222
+ `third_party/agg23/agg_curves.cpp` (Anti-Grain Geometry 2.3).
223
+ Copyright (C) 2002–2005 Maxim Shemanarev. Permission terms are retained in the
224
+ source and `licenses/AGG-2.3.txt`.
225
+
226
+ The TypeScript adapter uses double-precision numbers and arrays, merges the
227
+ equivalent one/two-control-point distance cases, and keeps the upstream
228
+ half-pixel flatness, collinearity handling, and recursion limit of 16.
229
+ `src/render/cubic-flattening.test.ts` compares against points generated by
230
+ compiling the unchanged upstream C++ algorithm with a minimal vector-storage
231
+ adapter; other cases use independently rendered PDF.js pixels.
232
+
233
+ Source: https://github.com/chromium/pdfium/blob/a84323421e94f484faca52dd9d027934eba42ab8/third_party/agg23/agg_curves.cpp
234
+
235
+ `src/render/stroke.ts` adapts the cap, join, miter and arc calculations from
236
+ `third_party/agg23/agg_math_stroke.h`, with forward/backward contour assembly
237
+ from `agg_vcgen_stroke.cpp`, at the same PDFium revision and under the same AGG
238
+ permission terms. The adapter uses double-precision arrays, PDFium's
239
+ `miter_join_revert` bevel fallback, and a one-million-vertex expansion limit.
240
+ Local dash splitting preserves joins across vertices and closed seams, resets
241
+ phase per subpath, and handles odd arrays and zero-length round dots.
242
+ Square zero-length dashes follow PDF.js/Canvas user-axis squares. Dash stepping
243
+ ignores a few ULPs of transformed endpoint residue; SVG reuses these contours for
244
+ zero-length patterns so its endpoint behavior and opacity match PDF painting.
245
+ `src/render/stroke-joins.test.ts` checks native cap/join vectors plus independent
246
+ PDF.js pixels; Poppler also confirms the final zero-length dash is omitted.
247
+ The native harness calls unchanged upstream math routines with minimal support
248
+ headers and local contour assembly; it is not the full upstream generator.
249
+
250
+ Source: https://github.com/chromium/pdfium/blob/a84323421e94f484faca52dd9d027934eba42ab8/third_party/agg23/agg_math_stroke.h
251
+
252
+ Stroke preparation in `src/render/raster.ts` adapts PDF.js
253
+ `CanvasGraphics.getScaleForStroking` and `rescaleAndStroke` from
254
+ `src/display/canvas.js` at revision `91041fb94d6744bc2a5bccd9aad28d617faa8195`
255
+ (Mozilla Foundation, Apache-2.0). It preserves paint-time user coordinates for
256
+ width/dashes, applies the per-axis minimum device thickness, and uses PDF.js's
257
+ larger-factor dash correction when the minimum rescales the axes differently.
258
+ The TypeScript adaptation uses arrays rather than Canvas/DOMMatrix objects,
259
+ shares preparation between bitmap and SVG, and suppresses singular strokes.
260
+ Tests compare independent PDF.js pixels, including identical embedded CFF text.
261
+
262
+
263
+ # SVG labels
264
+
265
+ SVG accessible labels use PDF.js `encodeToXmlString` from `core_utils.js`, with
266
+ a local XML 1.0 Char filter before encoding. Invalid controls and lone surrogates
267
+ cannot be made legal by numeric references. `src/render/svg-labels.test.ts` ports
268
+ the upstream valid-string cases from `core_utils_spec.js` and verifies complete
269
+ SVG documents with an independent XML parser. Only labels are sanitized; PDF
270
+ extraction and glyph geometry are preserved.
271
+
272
+ # Page rotation
273
+
274
+ The same font/graphics vendor bundle includes the unmodified PDF.js
275
+ `src/display/page_viewport.js` class. SVG rendering uses its rotation transform;
276
+ bitmap rendering rotates the finished page before applying pixel crops.
277
+ `src/render/page-rotation.test.ts` adapts the rotated viewport-size case from
278
+ PDF.js `test/unit/api_spec.js` to integer raster dimensions and adds public API
279
+ and pixel-geometry regressions. Mozilla Foundation, Apache-2.0, same pinned
280
+ revision as above.
281
+
282
+ # OpenType CFF tables
283
+
284
+ `src/fonts/truetype.ts` follows PDF.js `FontRendererFactory` by using the `CFF `
285
+ table when an sfnt font has no `glyf` table. It reuses the existing CFF parser
286
+ and path adapter, while retaining sfnt glyph mappings and metrics. The synthetic
287
+ OpenType fixture in `src/fonts/opentype-cff.test.ts` wraps the Adobe/PDF.js CFF
288
+ specification example from `cff_parser_spec.js`, with its second charstring
289
+ replaced by an unhinted triangle and compiled once with PDF.js CFFCompiler.
290
+ The test contains no system font assets. Mozilla Foundation, Apache-2.0, same
291
+ pinned revision and license as the other CFF cases.
292
+
293
+ # FlateDecode
294
+
295
+ The existing PDF.js vendor bundle also includes unmodified `FlateStream` and
296
+ `DecodeStream` from the pinned revision. `src/cos/filters.ts` subclasses its
297
+ output-buffer allocator to enforce caller byte budgets before growth and caps
298
+ buffer capacity at that budget. Raw-DEFLATE and gzip compatibility retains pako
299
+ with bounded output chunks. The simple predictor test in
300
+ `src/cos/pdfjs-flate.test.ts` is ported from `test/unit/stream_spec.js` to Vitest;
301
+ additional regressions use the extracted upstream streams listed in
302
+ `src/fixtures/SOURCES.md`. Copyright 2012/2017 Mozilla Foundation and
303
+ 1996–2003 Glyph & Cog, LLC, Apache-2.0. The upstream Flate implementation is a
304
+ JavaScript port of XPDF's implementation.
305
+
306
+ `src/cos/pypdf-flate-recovery.test.ts` adapts the printable-byte example from
307
+ pypdf 6.19.0 `tests/test_filters.py::test_decompress`, with truncation results
308
+ checked against `pypdf.filters.decompress`. The bounded pako fallback in
309
+ `src/cos/filters.ts` retains partial zlib/gzip output on incomplete input,
310
+ following pypdf's recovery behavior without its byte-at-a-time decoding loop.
311
+ The original PDF.js issue11549 fixture additionally checks the recovered
312
+ Unicode map against pypdf's decoded bytes. pypdf attribution/license is below.
313
+
314
+ # PDF standard security handler
315
+
316
+ `src/vendor/pdfjs-fonts.mjs` also includes `src/core/crypto.js`,
317
+ `src/core/sasl_prep.js`, and their dependencies from the pinned PDF.js revision
318
+ `91041fb94d6744bc2a5bccd9aad28d617faa8195` (Mozilla Foundation, Apache-2.0).
319
+ The vendor script replaces `Map.getOrInsertComputed` with ordinary Map operations
320
+ and `Math.sumPrecise` with exact integer addition over sixteen bytes for Node 22
321
+ and ES2022 compatibility; it does not modify globals. The R5/R6 password hash
322
+ adapter in `src/cos/security.ts` uses PDF.js's PDF17/PDF20 implementation.
323
+ Local inspection additions retain the authenticated password identity and recovered
324
+ user-password bytes, and check whether a user password also matches the owner.
325
+ The security adapter uses 128-bit file keys for V4, matching qpdf instead of
326
+ PDF.js's acceptance of nonstandard short V4 keys.
327
+ The AES256 length cases in `src/cos/security-writer.test.ts` are adapted from
328
+ PDF.js `test/unit/crypto_spec.js`, with independent Node AES validation.
329
+
330
+ The R3 and R6 encryption dictionary construction in `src/cos/security.ts`
331
+ follows pypdf 6.19.0 `pypdf/_encryption.py` (`AlgV4`, `AlgV5`, and
332
+ `Encryption.write_entry`). Modifications adapt the algorithms to the COS API,
333
+ use Web Crypto randomness, and use PDF.js for password hashing/preparation.
334
+ Fixed password/key/permission test values were generated independently with
335
+ that pypdf version and deterministic test-only entropy.
336
+
337
+ pypdf is BSD-3-Clause; copyright Mathieu Fenniak (2006–2008), Ashish Kulkarni
338
+ (2007), and Steve Witham (2014). See `licenses/PYPDF-BSD.txt`.
339
+ Source: https://github.com/py-pdf/pypdf/tree/6.19.0
340
+
341
+ The reader in `src/cos/security.ts` delegates authentication and cipher selection
342
+ to PDF.js `CipherTransformFactory`; its COS adapter resolves encryption entries
343
+ and preserves plaintext cross-reference streams, metadata, and signature
344
+ Contents. Explicit Crypt filter ordering follows PDF.js `src/core/parser.js`
345
+ `makeStream`/`filter`; the adapter retains the remaining encoded filter chain
346
+ when serializing decrypted documents. `src/cos/pdfjs-security.test.ts` ports 23
347
+ upstream authentication cases and adds integration regressions. The original
348
+ fixtures and their hashes are listed in `src/fixtures/SOURCES.md`.
349
+
350
+ For R5 passwords, the adapter additionally follows pypdf’s SASLprep policy as
351
+ a fallback after PDF.js rejects the raw UTF-8 candidate. The generated pypdf
352
+ regression fixture is documented in `src/fixtures/SOURCES.md`.
353
+
354
+ The recovery scanner in `src/cos/parser.ts` follows PDF.js `src/core/xref.js`
355
+ `XRef.indexObjects`: discover trailer and XRef dictionaries before object-stream
356
+ decoding, prefer encryption/ID-bearing trailers, and check Root/Pages candidates.
357
+ It retains the latest valid object bodies and checks the newest trailers first.
358
+ `src/cos/repair-encryption.test.ts` covers the original issue15893 fixture and
359
+ local integration cases, including encrypted object streams and direct Encrypt
360
+ dictionaries. Source revision and Apache-2.0 license are the same as above.
361
+
362
+ XRef stream validation in `src/cos/parser.ts` follows PDF.js `readXRefStream`
363
+ field-width, range, truncation, and entry-type checks. The zero-width regression
364
+ fixture in `src/cos/xref-validation.test.ts` is ported unchanged from
365
+ `test/unit/document_spec.js` at the same pinned revision. The adapter additionally
366
+ checks safe integers and caller-specified object budgets before xref map growth.
367
+
368
+ Uncompressed object loading also follows PDF.js `fetchUncompressed` by checking
369
+ object number and generation against the xref entry. Recovery retries the file
370
+ scan when an eager object read fails, preserving the common authentication and
371
+ resource-limit path. The original issue9418 fixture is documented above.
372
+
373
+ The original PDF.js issue2948 fixture covers mesh shading through PatternType 2
374
+ fills. Its provenance is recorded in `src/fixtures/SOURCES.md`; local triangle
375
+ cases exercise direct and chained references to the shading stream.
376
+
377
+ `src/edit/copy-pages.test.ts` ports `test_append_multiple` from pypdf 6.19.0
378
+ `tests/test_writer.py`, replacing its downloaded PDF with an in-memory page
379
+ and checking every copy and save/reopen. Page copying follows `_writer.py`
380
+ `_add_page`: each occurrence gets a distinct page dictionary while resources
381
+ can remain shared. Edits to shared content replace the page's Contents reference so
382
+ other pages retain their original stream. pypdf attribution/license is above.
383
+
384
+ Windows Symbol cmap selection in `src/content/evaluator.ts` follows PDF.js
385
+ `src/core/fonts.js` `checkAndRepair`: use encoded character codes for (3,0)
386
+ tables and clear the high byte only for F000–F0FF. The TrueType reader records
387
+ the selected cmap's encoding. Tests in `src/fonts/cid-to-gid.test.ts` cover
388
+ raw and prefixed symbol codes plus the original issue2948 fixture at the
389
+ same pinned PDF.js revision documented above.
390
+
391
+ Pattern-painted stencils follow PDF.js `CanvasGraphics._createMaskCanvas`:
392
+ the current pattern is painted in page coordinates through transformed mask
393
+ alpha, rather than coloring the source mask pixels. `stencil-pattern.test.ts`
394
+ ports the original `issue13372` equality fixture and adds memory-only coverage
395
+ for inline masks, rotation, inverted Decode, alpha, one-pixel masks, and tiling.
396
+ The source fixture and hashes are recorded in `src/fixtures/SOURCES.md`.
397
+ The one-pixel gradient expectation is independently verified by Poppler and
398
+ MuPDF; PDF.js's `paintSolidColorImageMask` optimization loses that pattern.
399
+
400
+ `src/render/image-sampling.ts` adapts `CanvasGraphics._scaleImage` from the same
401
+ pinned PDF.js revision (Copyright 2012 Mozilla Foundation, Apache-2.0). The
402
+ successive half-size canvas draws use local bilinear sampling with premultiplied
403
+ alpha; only the current reduction level is retained. Source-axis footprints
404
+ come from the inverse image transform to preserve rotated anisotropic reductions.
405
+ Final downscaling uses smoothing, as in `getImageSmoothingEnabled`, with one
406
+ device pixel as the enlargement threshold. `image-downsampling.test.ts` adds
407
+ memory-only stripe, alpha, transform, stencil, and save/reopen regressions;
408
+ the unchanged upstream issue13372 fixture also covers reduced patterned masks.
409
+
410
+ ExtGState soft-mask evaluation and rendering follow PDF.js `handleSMask`,
411
+ `beginGroup`, `_prepareSMaskCanvas`, and `_bakeSMaskCanvas` at the same revision
412
+ (Mozilla Foundation, Apache-2.0). The adapter captures page-coordinate mask
413
+ paints, resets group alpha/blend/soft-mask state, converts the luminosity
414
+ backdrop before filtering, and builds a 256-entry transfer table. Isolated
415
+ Forms retain their own paint groups so outer opacity is applied once.
416
+ Bitmap masks retain only the current prepared surface; SVG masks use the
417
+ export resolution while isolated Form contents remain vector groups.
418
+ `soft-mask.test.ts` ports four unchanged upstream equality fixtures, recorded
419
+ in `src/fixtures/SOURCES.md`, and adds local alpha/transform/group tests plus
420
+ the original issue17069 signature regression. Soft-mask evaluation is bounded
421
+ by the existing eight-level Form limit; mask-only text is excluded from extraction.
422
+
423
+ Non-isolated transparency Forms follow `beginGroup`'s direct-paint eligibility
424
+ and intermediate-surface state reset. Bitmap and SVG exports follow
425
+ `beginDrawing` in keeping the viewer background outside page blend calculations.
426
+ `src/render/transparency-group.test.ts` adds local opacity/blend/mask cases and
427
+ ports the unchanged `transparency_group.pdf` and `bug1873345.pdf` equality
428
+ fixtures, with independently obtained reference pixels. Non-isolated backdrop
429
+ compositing now uses PDFBox's group-alpha and backdrop-removal algorithm,
430
+ described below.
431
+
432
+ Masked non-isolated Forms with inner blending or soft-mask effects follow
433
+ PDF.js `beginGroup`'s `needsBackdropCopy && inSMaskMode` path. The raster adapter
434
+ copies the existing page within the transformed Form BBox before painting the
435
+ group. The PDFBox adaptation below extends this to ordinary outer-opacity
436
+ groups and removes the copied backdrop before final compositing.
437
+ `src/render/masked-group-backdrop.test.ts` covers these cases and the
438
+ unchanged `issue13520.pdf` fixture. SVG uses a raster fallback for pages requiring
439
+ this backdrop copy; other Form groups retain their vector output.
440
+
441
+ CropBox handling follows PDF.js `Page.getBoundingBox` and `Page.view` in
442
+ `src/core/document.js`, and the SVG corner transform follows
443
+ `PageViewport.convertToViewportRectangle`. The adaptation stores bounds on the
444
+ local display list and crops before page rotation, keeping editing coordinates
445
+ unchanged. `src/render/crop-box.test.ts` covers these rules and the unmodified
446
+ `issue13520.pdf` equality fixture, recorded in `src/fixtures/SOURCES.md`.
447
+
448
+ MediaBox-origin rendering follows PDF.js `PageViewport` in
449
+ `src/display/page_viewport.js`: viewport coordinates subtract the normalized
450
+ lower-left page origin before applying rotation. Local rasterization applies
451
+ that translation to paths, strokes, images, clips, and intermediate mask/group
452
+ surfaces; SVG uses the vendored viewport transform. The unchanged PDF.js
453
+ `bug852992_reduced.pdf` soft-mask fixture and memory-only offset-page tests cover
454
+ this behavior in `src/render/media-box-origin.test.ts`.
455
+
456
+ Sampled-function interpolation adapts PDF.js `PDFFunction.constructSampled`
457
+ in `src/core/function.js`. The local evaluator reads the weighted neighboring
458
+ samples directly, supports unsigned packed samples through 32 bits, and handles
459
+ singleton axes without reading outside the table. Its degenerate-Domain test
460
+ is ported from `test/unit/colorspace_spec.js` (AlternateCS), with assertions on
461
+ the tint components before color conversion. The unchanged
462
+ `bug852992_reduced.pdf` fixture also verifies the restored soft-mask fade.
463
+
464
+ Exponential and stitched function evaluation follows PDF.js
465
+ `PDFFunction.constructInterpolated` and `constructStitched` in the same source:
466
+ apply the exponent to the input, and pass the stitched Encode result to the
467
+ child without rescaling it to a unit interval. Local memory-only regressions
468
+ cover non-unit domains, zero/negative exponents, output ranges, segment bounds,
469
+ reversed encoding, and image tint consistency. Domain and Range clipping also
470
+ follow the PDF function contract.
471
+
472
+ Calculator functions use PDF.js `buildPostScriptJsFunction`
473
+ from `src/core/postscript/js_evaluator.js`, together with its AST and lexer.
474
+ The JavaScript evaluator interprets instructions without `eval`, `Function`,
475
+ or WebAssembly compilation. Compiled functions are cached weakly by COS stream;
476
+ code, Domain, or Range edits invalidate the entry. `pdfjs-postscript.test.ts`
477
+ ports 35 complete input/output vectors from `test/unit/postscript_spec.js`,
478
+ alongside comment, image-function integration, and edit-invalidation coverage.
479
+ Local lexer and stack-interpreter changes preserve integer/real types for `mod`,
480
+ including real function inputs and integer-valued real literals. Programs using
481
+ `mod` bypass the optimizer, which erases these types. A type mismatch produces
482
+ zero output components and a caller warning, matching Poppler's malformed
483
+ function-shading recovery; stored instructions retain the same numeric types.
484
+
485
+ The vendor bundle includes unmodified PDF.js `DeviceCmykCS` from
486
+ `src/core/colorspace.js`. Path, shading, and image color conversion use this
487
+ class directly, including CMYK palette entries and alternate tint colors.
488
+ `src/render/cmyk-colors.test.ts` ports the byte and floating-point reference
489
+ vectors from PDF.js `test/unit/colorspace_spec.js`, through local PDF APIs.
490
+
491
+ The same bundle exports unmodified `CalGrayCS`, `CalRGBCS`, and `LabCS`.
492
+ The shared calibrated-color adapter resolves COS parameters before calling
493
+ CalRGBCS and LabCS. CalGray uses a local sRGB transfer function to match
494
+ Poppler’s neutral-axis conversion. Paths, gradients, images, palettes, and calibrated alternate
495
+ tint spaces use the same converters. `calibrated-colors.test.ts` ports the
496
+ corresponding PDF.js `colorspace_spec.js` inputs (with sRGB CalGray expectations) through those
497
+ APIs and the unchanged `calgray.pdf` equality fixture. Missing WhitePoint
498
+ retains the local D65 fallback for malformed input.
499
+
500
+ Malformed dictionary-key recovery follows PDF.js `Parser.getObj`, skipping
501
+ stray non-Name tokens only in local repair mode. Damaged optional ToUnicode
502
+ streams follow `PartialEvaluator.readToUnicode` error recovery while retaining
503
+ local resource-limit errors. `dictionary-recovery.test.ts` ports the original
504
+ `issue11549` equality fixture and covers ordinary/compressed dictionaries,
505
+ trailer metadata, strict mode, and explicit limits.
506
+
507
+ Mesh stream decoding, Coons/tensor patch tessellation, and vertex packing use
508
+ PDF.js `MeshStreamReader`, `MeshShading`, and their helpers from
509
+ `src/core/pattern.js` at the same revision (Mozilla Foundation, Apache-2.0).
510
+ The generator replaces only the constructor's PDF.js resource lookup with a
511
+ local stream/color adapter and uses equivalent ES2022 cache operations.
512
+ The decoding and geometry algorithms are unchanged. The local rasterizer
513
+ paints the resulting RGB triangles. `src/render/mesh-shading.test.ts` ports
514
+ the unchanged upstream equality fixtures `issue4227` and `issue6305-part-1`,
515
+ with independently rendered reference pixels recorded in the tests.
516
+
517
+ Function-shading BBox coordinates follow PDF.js `FunctionBasedShading` in
518
+ `src/core/pattern.js`, keeping the BBox separate from the function-domain
519
+ Matrix. The local evaluator transforms page pixels back into shading space
520
+ for clipping. `src/render/shading-bbox.test.ts` covers translated, rotated,
521
+ and sheared page transforms and the unchanged upstream equality fixture.
522
+
523
+ Declared stream lengths follow PDF.js `Parser.makeStream`/`tryShift` in
524
+ `src/core/parser.js`: the next token must be `endstream`, otherwise scan for
525
+ the actual terminator. `src/cos/stream-length.test.ts` covers direct/indirect
526
+ lengths, malformed tokens at the claimed end, delimiter text inside accurate
527
+ streams, and PDF.js's unchanged `xobject-image.pdf` through load/save/render.
528
+
529
+ Explicit simple-font width tables follow PDF.js `PartialEvaluator.extractWidths`
530
+ in `src/core/evaluator.js`: undeclared codes use `FontDescriptor.MissingWidth`,
531
+ or zero when absent. Standard-font widths apply only without an explicit
532
+ Widths table. `src/fonts/explicit-widths.test.ts` covers Type1, TrueType and
533
+ Type3 widths with and without ToUnicode, plus the unchanged upstream
534
+ `Type3WordSpacing.pdf` fixture.
535
+
536
+ # Apache PDFBox rendering regressions
537
+
538
+ `src/render/pdfbox-patterns.test.ts` adapts `TestQuality.java` at revision
539
+ `c4d556abc9d5f0cbc486d459c84682321dd38ff4`, retaining its original page,
540
+ 100 dpi resolution, pixel coordinates, and assertions. Test fixture provenance
541
+ and checksums are recorded in `src/fixtures/SOURCES.md`. Licensed under
542
+ Apache-2.0; see `licenses/PDFJS-APACHE-2.0.txt`.
543
+
544
+ Source: https://github.com/apache/pdfbox
545
+
546
+ The pattern transform handling in `src/content/evaluator.ts` follows PDFBox
547
+ `TilingPaint` and `PageDrawer`: concatenate the containing stream initial
548
+ matrix with the pattern matrix, then clip the paint to the glyph or path.
549
+
550
+ Relevant upstream NOTICE:
551
+
552
+ Apache PDFBox
553
+ Copyright 2014 The Apache Software Foundation
554
+
555
+ This product includes software developed at
556
+ The Apache Software Foundation (http://www.apache.org/).
557
+
558
+ Based on source code originally developed in the PDFBox and
559
+ FontBox projects.
560
+
561
+ Copyright (c) 2002-2007, www.pdfbox.org
562
+
563
+ Based on source code originally developed in the PaDaF project.
564
+ Copyright (c) 2010 Atos Worldline SAS
565
+
566
+ `src/pdfbox-strings.test.ts` adapts `TestCOSString` and
567
+ `PDFDocEncodingTest` at the same PDFBox revision, retaining the Unicode inputs
568
+ and expected round trips, including all 256 PDFBOX-3864 characters. Local COS
569
+ nodes preserve byte representation, so decoded strings replace Java COSString
570
+ value equality. `src/ast.ts` follows `COSString` in using PDFDocEncoding only
571
+ for representable characters and UTF-16BE otherwise. The reverse encoding map
572
+ is derived from the existing decoder table. Apache-2.0, ASF notice above.
573
+
574
+ `src/cos/pdfbox-lexer.test.ts` adapts `TestCOSParser` and `TestCOSNumber`,
575
+ keeping the upstream literal, name, and numeric expectations through the local
576
+ token API. Java-specific number range and object identity checks are omitted.
577
+ Literal recovery in `src/cos/lexer.ts` follows `BaseParser.checkForEndOfString`;
578
+ the adapter defers the recovery until EOF to preserve balanced multiline
579
+ strings. Additional local cases check following fields and token budgets.
580
+
581
+ `src/edit/pdfbox-forms.test.ts` adapts `TestRadioButtons.testRadioButtonPDModel`
582
+ and the PDFBOX-4366/PDFBOX-6207 checkbox regressions. In-memory COS dictionaries
583
+ replace PDFBox model builders; field values and widget appearance states retain
584
+ the original expectations. Empty dictionaries stand in for unused appearances.
585
+ `src/render/pdfbox-blend-mode.test.ts` ports all four
586
+ `TestPDFRendererBlendMode` cases, preserving page dimensions, sample coordinates,
587
+ and expected blue/white pixels. Vitest replaces JUnit; bitmap RGBA values replace
588
+ Java packed ARGB integers. Both use the same PDFBox revision and ASF license.
589
+
590
+ Non-isolated group compositing in `src/render/raster.ts` adapts PDFBox
591
+ `PageDrawer.TransparencyGroup` and `GroupGraphics.removeBackdrop` at the same
592
+ revision. Each paint accumulates group-only alpha separately from its color
593
+ surface, which starts with the parent backdrop. Backdrop removal retains inner
594
+ blend effects and restores group alpha before applying outer opacity and masks.
595
+ The local implementation uses a Float32 alpha plane and straight RGBA bytes,
596
+ with a raster SVG fallback for affected pages. `transparency-group.test.ts`
597
+ checks opaque and partial backdrops, nested opacity, masks, overlapping paints,
598
+ strokes, images, untouched pixels, and normal/incremental/copied-page saves.
599
+ Opaque RGB expectations were independently checked using Poppler 26.08.0's
600
+ Splash renderer; transparent expectations also check the PDF compositing
601
+ formula. ASF, Apache-2.0, notices and license above.
602
+
603
+ The font renderer regeneration also adds optional allocation callbacks before
604
+ CFF outline parser scratch, subroutine expansion, command storage, transforms,
605
+ and typed path output. Local path conversion charges the containing font owner,
606
+ and its outline cache retains at most 256 KiB of conservatively sized paths.
607
+ The CFF parser also admits indices, dictionaries, decoded strings, charset and
608
+ FDSelect ranges, and charstring scratch. Truncated charset ranges now fail
609
+ instead of entering a non-progressing loop. CID matrix normalization follows
610
+ CFFCompiler directly, without compiling a duplicate output font. Type1Font now
611
+ retains its converted CFF structure and compiles its byte representation lazily.
612
+ Glyph/subroutine copies and mapping state report allocation callbacks; rendering
613
+ uses the converted structure directly. Type1 parsing admits lexer token growth,
614
+ decryption buffers, CID glyph/offset tables, fallback glyph copies, and every
615
+ recursive charstring conversion before allocation. Skipped comments do not
616
+ reserve token-sized buffers.
617
+
618
+ # Python / V8 stable sorting
619
+
620
+ `src/extract/text-sort.ts` adapts the TimSort implementation in V8
621
+ 14.6.202.34 (`third_party/v8/builtins/array-sort.tq`), derived from Python.
622
+ Copyright (c) 2001–2018 Python Software Foundation; all rights reserved.
623
+ V8 contributions are copyright the V8 project authors. See
624
+ `licenses/PYTHON-PSF.txt` and `licenses/V8-BSD.txt` for the respective terms.
625
+
626
+ The adaptation replaces resident work and temporary arrays with resumable
627
+ record-read, record-write and comparison requests. Scalar run state and the
628
+ comparison decisions are retained; allocation, I/O and cancellation belong to
629
+ the driver.
630
+
631
+ Source: https://github.com/v8/v8/blob/14.6.202.34/third_party/v8/builtins/array-sort.tq
@@ -0,0 +1,7 @@
1
+ Anti-Grain Geometry - Version 2.3
2
+ Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
3
+
4
+ Permission to copy, use, modify, sell and distribute this software
5
+ is granted provided this copyright notice appears in all copies.
6
+ This software is provided "as is" without express or implied
7
+ warranty, and with no claim as to its suitability for any purpose.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Poe Platform
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.