5074 Commits

Author SHA1 Message Date
Jonas Jenwald
e8f07d7ca3 [api-minor] Move the getXfaPageViewport helper into the XfaLayer class
This small helper function only exists to support printing of XFA documents, in the viewer, hence it seems like a good idea to (ever so slightly) reduce the official API surface a little bit.
2026-05-16 12:31:53 +02:00
Jonas Jenwald
eda97fe8fc Move the PageViewport class into its own file
This is necessary to prevent import cycles with the next patch.

It also shouldn't hurt to reduce the size of `src/display/display_utils.js` a little bit, since utility-files have a tendency to increase in size over time.
2026-05-16 12:31:40 +02:00
Roland Arnold
16d82e094f fix: inline styles for hidden helper elements
Set layout-neutral styles at the creation sites for the hidden TextLayer
canvas and PDFViewer copy element rather than relying on the shared
web/pdf_viewer.css rule.

This keeps the helper elements invisible and out of layout when viewer CSS
selectors are scoped or omitted, and removes the obsolete hiddenCanvasElement
class and shared CSS rule.
2026-05-14 14:28:41 +01:00
Jonas Jenwald
1079535a1e
Merge pull request #21249 from Snuffleupagus/open-filename-unconditional
Support providing a `filename` unconditionally, when passing binary data to `PDFViewerApplication.open`
2026-05-10 15:48:43 +02:00
Jonas Jenwald
0763c69b6a Support providing a filename unconditionally, when passing binary data to PDFViewerApplication.open
Previously this was only supported in Firefox, however when merging PDFs the `PDFViewerApplication.onSaveAndLoad` method will provide a `filename` unconditionally.
2026-05-10 13:51:33 +02:00
Jonas Jenwald
43ce1bb491 [api-major] Remove the PDFDocumentProxy.prototype.destroy method
This is a left-over from very old code, which pre-dates the introduction of the `PDFDocumentLoadingTask` and it's nothing more than an alias for its `destroy` method.
Given that `PDFDocumentProxy` already provides a way to access the underlying `PDFDocumentLoadingTask` instance, it shouldn't be necessary to have an alias for one of its methods.

*Please note:* For any existing code relying on the removed method, updating it should be as simple as replacing `pdfDocument.destroy()` with `pdfDocument.loadingTask.destroy()`.

---

[1] If the `PDFDocumentProxy` class was added today, there's no chance that it'd include a `destroy` method.
2026-05-09 13:20:39 +02:00
Calixte Denizet
a6cb30a9e5
Make sure the focus moves on the first page of the added pdf after a merge (bug 2034827) 2026-05-06 13:42:49 +02:00
Calixte Denizet
82f55e7dd9
Clear the text layer container when cancelling rendering
It fixes #21217.
2026-05-04 14:36:12 +02:00
Tim van der Meij
038ca33f8e
Optimize runtime of the find controller unit tests
The find controller tests consistently show up in the list of slowest
tests reported by Jasmine. Profiling shows that most of the time is
spent waiting for the find results to arrive, even though the find
command itself is quite fast.

It turns out that the slowdown occurs between receiving the `find` event
and actually triggering the search. The find controller has a hardcoded
delay of 250 milliseconds built in, which was introduced for viewer
performance many years ago because otherwise every keystroke would
trigger a search even though the user's query was not complete yet.

For the unit tests we don't need this delay because, contrary to the
viewer use case, we don't have to account for user interaction and
instead dispatch complete `find` events on the event bus ourselves.
However, since the unit tests were introduced well over a year after
the delay was introduced, due to an oversight it was never made
configurable so we could skip it for the unit tests.

This commit fixes the issue, which locally results in the runtime of
`npx gulp unittest --noChrome` dropping from 39.991 seconds before this
patch to 29.116 seconds afterwards, which is a 27% speedup.
2026-05-01 19:31:13 +02:00
calixteman
7ebf3a4d7c
Merge pull request #21196 from calixteman/bug2035530
Fix free highlight on pages without images (bug 2035530)
2026-04-30 19:34:02 +02:00
Jonas Jenwald
aa08b02a5b Avoid setting page-content for a previous document in the PDFFindController.prototype.#extractText method
Given that all of the relevant API methods are asynchronous it's possible, although quite unlikely, that the existing "is the document active" check won't catch all situations where the document was closed in the middle of searching.
2026-04-29 22:39:53 +02:00
Jonas Jenwald
a6e2a42df1 Improve error handling in the PDFFindController.prototype.#extractText method
This handles *all* errors correctly, if e.g. the document is closed in the middle of searching.
Also, replacing the "promise chains" with more `await` helps simplify the code a little bit.
2026-04-29 22:39:51 +02:00
Calixte Denizet
e7ec356be0
Fix free highlight on pages without images (bug 2035530) 2026-04-29 19:24:35 +02:00
Calixte Denizet
ecd154160d
Fix HCM colors for the views-manager massive unselect button (bug 2035551) 2026-04-28 19:52:53 +02:00
Jonas Jenwald
fae980a72d A couple of internal-viewer fixes
- Bundle the `web/text_layer_builder.css` file correctly, to ensure that textLayer debugging works when the code is *built*.
   Note how loading https://mozilla.github.io/pdf.js/internal-viewer/web/debugger.html currently logs the following error: `GET https://mozilla.github.io/pdf.js/internal-viewer/text_layer_builder.css [HTTP/2 404  7ms]`.

 - Import the `MathClamp` helper function from the *built* library, rather than "manually", since that's more correct.
2026-04-26 19:10:05 +02:00
Jonas Jenwald
9b238b9719 Move the hexNumbers Array into Util, to enable using it in the viewer
This reduces some code duplication, and the new `Util.hexNums` property is now computed lazily.
2026-04-26 12:05:12 +02:00
Jonas Jenwald
1591ddfa8d
Merge pull request #21157 from Snuffleupagus/eslint-radix
Enable the `radix` ESLint rule
2026-04-25 22:27:21 +02:00
Jonas Jenwald
e6dba6ee34 Enable the radix ESLint rule
Many `parseInt` call-sites already provide the `radix` argument, and this rule helps improve consistency in the code-base; see https://eslint.org/docs/latest/rules/radix

*Please note:* The rule is disabled in `src/scripting_api/util.js` for now, since it's not obvious at a glance (at least to me) what the correct `radix` argument should be there.
2026-04-25 12:13:12 +02:00
calixteman
30d060c77a
Merge pull request #21151 from calixteman/bug2034568
Fix clicking on a thumbnail image not navigating to the correct page when using a screen reader (bug 2034568)
2026-04-25 08:20:25 +02:00
Tim van der Meij
7dc4812643
Merge pull request #21138 from calixteman/bug2034111
Fix status label mismatch after merging with a pre-existing selection (bug 2034111)
2026-04-24 20:07:50 +02:00
calixteman
2d896faa1e
Merge pull request #21142 from calixteman/input_color_alpha
[Ink] Replace the opacity slider with an alpha-enabled color input
2026-04-24 15:46:46 +02:00
Calixte Denizet
39eb691252
Fix status label mismatch after merging with a pre-existing selection (bug 2034111) 2026-04-24 14:13:53 +02:00
calixteman
a6382ac97d
Merge pull request #21145 from calixteman/bug2034461
Prompt the user for saving a merged pdf (bug 2034461)
2026-04-24 14:11:36 +02:00
Calixte Denizet
b669fdfc70
Fix clicking on a thumbnail image not navigating to the correct page when using a screen reader (bug 2034568)
Screen readers like NVDA fire synthetic click events on the <img> child of the button rather than on the
thumbnailImageContainer element itself, so the strict classList.contains check silently failed.
2026-04-24 10:10:59 +02:00
Calixte Denizet
987edbb646
Switch to a wasm file for the quickjs sandbox 2026-04-23 22:34:48 +02:00
Calixte Denizet
f266c4d8b8
[Ink] Replace the opacity slider with an alpha-enabled color input
The alpha feature is available in Firefox nightly (with the pref `dom.forms.html_color_picker.enabled` set to `true`).
It's available in Safari but not in Chrome.
2026-04-23 21:37:37 +02:00
Calixte Denizet
302bc5f4d9
Prompt the user for saving a merged pdf (bug 2034461) 2026-04-23 18:37:56 +02:00
Calixte Denizet
9bfad05173 [HCM] Set the correct color for the icon in the merge button when focused with the keyboard (bug 2033603) 2026-04-21 19:24:21 +02:00
Calixte Denizet
8ddbeda4a0
Remove user and password from URLs (bug 2025109) 2026-04-20 20:53:24 +02:00
Calixte Denizet
8c9b819b4e
Add the UI for merging PDFs (bug 2028071) 2026-04-13 19:38:56 +02:00
Tim van der Meij
583c9d6b98
Update dependencies to the most recent versions
Note that the `globals` update rendered two ESLint ignore lines obsolete
because the `Sanitizer` global is now registered [1].

[1] 5d84602967
2026-04-12 16:16:21 +02:00
Calixte Denizet
ea15ac31ef Dont revoke blob URLs while printing but do it after
It fixes #19988.

In Firefox, when printing, the document is cloned and use an image cache
which isn't available when there's a service worker.
2026-04-08 14:04:09 +02:00
calixteman
d6afffe8f6
Merge pull request #21059 from calixteman/bug2028193
Make sure the thumbnails positions are recomputed after a structural change but after a reflow has been done (bug 2028193)
2026-04-07 17:02:07 +02:00
Calixte Denizet
1b2e98f3ce
Make sure the thumbnails positions are recomputed after a structural change but after a reflow has been done (bug 2028193) 2026-04-07 15:48:23 +02:00
Jonas Jenwald
8656b4acb3 Fix the l10n-id for the sidebar toggleButton, in the ViewsManager class
Steps to reproduce:
 1. Open http://localhost:8888/web/viewer.html
 2. Open the console, and run: `PDFViewerApplication.close();`
 3. Note the warning: `[fluent] Missing translations in en-us: pdfjs-toggle-views-manager-button`
2026-04-07 11:13:35 +02:00
Jonas Jenwald
5aaf30a071
Merge pull request #21018 from Snuffleupagus/Node-22
[api-minor] Update the minimum supported Node.js version to 22
2026-04-05 12:39:36 +02:00
Jonas Jenwald
f6bac014ea [api-minor] Remove PostScriptCompiler and PostScriptEvaluator, since it's now dead code (PR 21023 follow-up)
These classes, and various related code, became unused after PR 21023 with only unit-tests actually running that code now.

Also removes the `isEvalSupported` API option, since the `PostScriptCompiler` was the only remaining code where `eval` was used.
2026-04-03 22:14:14 +02:00
Calixte Denizet
1e3d688a32
Add an eslint plugin for using MathClamp when it's possible 2026-04-03 21:12:52 +02:00
Tim van der Meij
bb1033053c
Merge pull request #21029 from Snuffleupagus/Object-hasOwn
Replace all `Object.prototype.hasOwnProperty` usage with `Object.hasOwn`
2026-04-03 19:51:09 +02:00
Jonas Jenwald
f09b03c062 Enable the prefer-object-has-own ESLint rule
Please see https://eslint.org/docs/latest/rules/prefer-object-has-own
2026-04-02 13:24:31 +02:00
Jonas Jenwald
579589a38a Use OffscreenCanvas unconditionally in the web/pdf_thumbnail_view.js file
Given that `OffscreenCanvas` is available in all supported browsers and that the code in the `web/` folder is only intended to run in browsers, the fallback should no longer be necessary.

Please note:
 - https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support
 - https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas#browser_compatibility
2026-04-01 16:32:07 +02:00
Jonas Jenwald
e0423ebbe4 [api-minor] Update the minimum supported Node.js version to 22
This patch updates the minimum supported environments as follows:
 - Node.js 22, which was initially released on 2024-04-24 and has now entered the "Maintenance"-phase; see https://github.com/nodejs/release#release-schedule

Furthermore, note also that Node.js 20 will reach end-of-life on 2026-04-30 which coincides (approximately) with the next PDF.js release.
2026-04-01 12:06:32 +02:00
Calixte Denizet
9f3de1edf6
Add an interpreter for optimized ps code
It'll be used as a fallback when wasm is disabled.
And add in the debugger a view for the generated js code and one for the ps code.
2026-03-31 21:00:22 +02:00
Tim van der Meij
9026329d3d
Merge pull request #21003 from Snuffleupagus/applyOpacity-map
Simplify the `applyOpacity` helper function
2026-03-29 16:06:28 +02:00
Jonas Jenwald
498daadf3c Simplify the applyOpacity helper function
This function only has a single call-site (if we ignore the unit-tests), where the colors are split into separate parameters.
Given that all the color components are modified in the exact same way, it seems easier (and shorter) to pass the colors as-is to `applyOpacity` and have it use `Array.prototype.map()` instead.
2026-03-29 14:52:06 +02:00
Jonas Jenwald
0060eeb726 Use more logical assignment in the code-base 2026-03-27 12:18:04 +01:00
calixteman
0128ead18a
Merge pull request #20985 from calixteman/bug2023150_2
Avoid to be blocked when searching after a page move (bug 2023150)
2026-03-26 23:28:33 +01:00
Calixte Denizet
f98ce9ca85
Avoid to have multiple selected pages after copy/cut operations (bug 2026639) 2026-03-26 21:35:10 +01:00
calixteman
466c6263ad
Merge pull request #20974 from calixteman/bug2025674
Don't walk the children of a node having some attached MathML (bug 2025674)
2026-03-26 21:33:13 +01:00
Tim van der Meij
377f6d8b73
Merge pull request #20984 from calixteman/debugger_dont_update_canvas_view
Update the canvas detail view only when drawing is done
2026-03-26 20:41:22 +01:00