Commit Graph

16118 Commits

Author SHA1 Message Date
Jonas Jenwald
723584dd4f Enable the unicorn/prefer-array-find ESLint plugin rule
Please find additional information here:
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find#browser_compatibility
 - https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-array-find.md
2022-08-24 16:46:26 +02:00
Tim van der Meij
14e8167df9
Merge pull request #15335 from Snuffleupagus/PasswordPrompt-activeCapability
Ensure that we don't try to re-open, or update the password-callback, when the password dialog is already open
2022-08-21 12:52:34 +02:00
Tim van der Meij
81a700079f
Merge pull request #15332 from Snuffleupagus/Babel-targets
[api-minor] Add the Babel `targets`-option to avoid transpiling code for unsupported browsers
2022-08-21 12:06:43 +02:00
Tim van der Meij
255cc8b9eb
Merge pull request #15338 from Snuffleupagus/update-packages
Update packages and translations
2022-08-21 11:45:46 +02:00
Jonas Jenwald
635db46b0d Update l10n files 2022-08-21 10:04:47 +02:00
Jonas Jenwald
1001ae5474 Update npm packages 2022-08-21 10:04:47 +02:00
Jonas Jenwald
6e31799948 [api-minor] Add the Babel targets-option to avoid transpiling code for unsupported browsers
Currently we simply use the Babel `preset-env` in the `legacy`-builds of the PDF.js library. This has the side-effect of transpiling the code for *very old* browsers/environments, including ones that we (since many years) no longer support which unnecessarily bloats the size of the `legacy`-builds.

For the CSS files we're only targeting *the supported browsers*, and it's thus possible to extend that to also apply to Babel.
One of the most significant changes, with this patch, is that we'll no longer polyfill `async`/`await` in the `legacy`-builds. However, this shouldn't be an issue given the browsers that we currently support in PDF.js; please refer to:
 - https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function#browser_compatibility
2022-08-19 22:19:43 +02:00
Jonas Jenwald
89840649d9 Ensure that we don't try to re-open, or update the password-callback, when the password dialog is already open
Currently in `disableWorker=true` mode it's possible that opening of password-protected PDF documents outright fails, if an *incorrect* password is entered. Apparently the event ordering is subtly different in the non-Worker case, which causes the password-callback to be updated *before* the dialog has been fully closed.
To avoid that we'll utilize a `PromiseCapability` to keep track of the state of the password dialog, such that we can delay both re-opening and (importantly) updating of the password-callback until doing so is safe.

This patch *may* also fix issue 15330, but it's impossible for me to tell.
2022-08-19 20:10:37 +02:00
calixteman
1a007164f7
Merge pull request #15329 from calixteman/1782564
[api-minor][Annotations] charLimit === 0 means unlimited (bug 1782564)
2022-08-19 12:54:47 +02:00
Calixte Denizet
c06c5f7cbd [Annotations] charLimit === 0 means unlimited (bug 1782564)
Changing the charLimit in JS had no impact, so this patch aims to fix
that and add an integration test for it.
2022-08-19 11:28:28 +02:00
Jonas Jenwald
8f74fe6e1b
Merge pull request #15327 from Snuffleupagus/bug-1785218
Correctly mimic the proper event-format in `AnnotationElement._setDefaultPropertiesFromJS` (bug 1785218)
2022-08-17 16:15:13 +02:00
Jonas Jenwald
5e126032ff Correctly mimic the proper event-format in AnnotationElement._setDefaultPropertiesFromJS (bug 1785218)
*This is a follow-up to PR 14869.*

In the old code we're accidentally "swallowing" part of the event-details, which explains why the annotationLayer didn't render.
One thing that made debugging a lot harder was the lack of error messages, from the viewer, and a few `PDFPageView`-methods were updated to improve this situation.
2022-08-17 15:44:27 +02:00
Jonas Jenwald
b05010c3eb
Merge pull request #15325 from Snuffleupagus/issue-15324
Ignoring "resize" events during printing (issue 15324)
2022-08-16 14:41:36 +02:00
Jonas Jenwald
f669e5dd34 Ignoring "resize" events during printing (issue 15324)
This is a quick work-around, to prevent the viewer from breaking as a result of https://bugzilla.mozilla.org/show_bug.cgi?id=774398
2022-08-16 13:51:35 +02:00
Jonas Jenwald
518115fddc
Merge pull request #15315 from Snuffleupagus/type1-parser-rm-closure
Remove the remaining closures in the `src/core/type1_parser.js` file
2022-08-15 18:56:31 +02:00
Jonas Jenwald
bf6593372b
Merge pull request #15318 from Snuffleupagus/worker-small-fixes
A couple of small `PDFWorker` changes
2022-08-15 18:55:29 +02:00
Jonas Jenwald
44f6b76365
Merge pull request #15319 from Snuffleupagus/bug-1784850
Refresh the viewer if the window resolution changes (bug 1784850)
2022-08-15 18:54:08 +02:00
Jonas Jenwald
4919dae294 Refresh the viewer if the window resolution changes (bug 1784850)
*Please note:* This probably fixes bug 1784850, however I don't have the necessary hardware to reproduce the situation described in https://bugzilla.mozilla.org/show_bug.cgi?id=1784850#c0

Unfortunately it doesn't, as far as I can tell, appear possible to detect *all* resolution changes with a single media query. Instead we have to update it, and its listener, on every resolution change as outlined in [this MDN example](https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio#monitoring_screen_resolution_or_zoom_level_changes).
2022-08-15 16:56:57 +02:00
Jonas Jenwald
c02d0aa2cb A couple of small PDFWorker changes
- Remove the `typeof Worker` check, since all browsers have had `Worker` support for many years now; see https://developer.mozilla.org/en-US/docs/Web/API/Worker#browser_compatibility
   Furthermore the `new Worker(...)` call is wrapped in try-catch, which means that we'll still fallback to "fake workers" if necessary.

 - Limit the `fallbackWorkerSrc` handling, in the `PDFWorker.workerSrc` getter, to only GENERIC builds since that's the only place where it's defined anyway.
2022-08-15 12:17:48 +02:00
Jonas Jenwald
6a2c2a646f Remove the remaining closures in the src/core/type1_parser.js file
Given that the code is written with JavaScript module-syntax, none of this functionality will "leak" outside of this file with these change.
By removing this closure the file-size is decreased, even for the *built* `pdf.worker.js` file, since there's now less overall indentation in the code.
2022-08-14 12:50:26 +02:00
Tim van der Meij
e6fe127433
Merge pull request #15313 from Snuffleupagus/move-binarySearchFirstItem
Move `binarySearchFirstItem` back to the `web/`-folder (PR 15237 follow-up)
2022-08-14 12:14:32 +02:00
Tim van der Meij
92edfb59f7
Merge pull request #15310 from Snuffleupagus/cff-parser-rm-closure
Remove the remaining closures in the `src/core/cff_parser.js` file
2022-08-14 11:53:00 +02:00
Jonas Jenwald
0024165f1f Move binarySearchFirstItem back to the web/-folder (PR 15237 follow-up)
This was moved into the `src/display/`-folder in PR 15110, for the initial editor-a11y patch. However, with the changes in PR 15237 we're again only using `binarySearchFirstItem` in the `web/`-folder and it thus seem reasonable to move it back there.
The primary reason for moving it back is that `binarySearchFirstItem` is currently exposed in the public API, and we always want to avoid that unless it's either PDF-related functionality or code that simply must be shared between the `src/`- and `web/`-folders. In this case, `binarySearchFirstItem` is a general helper function that doesn't really satisfy either of those alternatives.
2022-08-14 11:38:17 +02:00
Jonas Jenwald
2b66ed5fef
Merge pull request #15311 from Snuffleupagus/text-a11y-removed-element
Don't add `aria-owns` attributes for non-existent elements (PR 15237 follow-up)
2022-08-14 09:31:29 +02:00
Jonas Jenwald
6c4561f3d8 Don't add aria-owns attributes for non-existent elements (PR 15237 follow-up)
Currently when the `TextAccessibilityManager.enabled` method is called, we'll update `aria-owns` for any pre-existing elements. This obviously makes sense when e.g. zooming/rotating in the viewer, since the annotationLayer/annotationEditorLayer is kept in those cases.
However when the page is *fully* reset, e.g. as result of going out-of-view and thus being evicted from the cache, we still keep the `#textNodes`-Map around. This causes us to set the `aria-owns` attribute (in the textLayer) for an element that doesn't actually exist any more, which as far as I'm concerned seems incorrect. In this case the element will simply, as already implemented, be re-inserted when the annotationLayer/annotationEditorLayer renders again.
2022-08-13 21:52:38 +02:00
Jonas Jenwald
e5e756c0b4 Remove the remaining closures in the src/core/cff_parser.js file
Given that the code is written with JavaScript module-syntax, none of this functionality will "leak" outside of this file with these changes.
For e.g. the `gulp mozcentral` command the *built* `pdf.worker.js` file-size decreases `~2 kB` with this patch, and most of the improvement comes from having less overall indentation in the code.
2022-08-13 19:48:17 +02:00
Tim van der Meij
b040d64a3c
Merge pull request #15300 from Snuffleupagus/viewer-export-constants
[GENERIC viewer] Export some viewer constants in the default viewer (issue 15294)
2022-08-13 15:25:29 +02:00
Tim van der Meij
f212341d01
Merge pull request #15306 from Snuffleupagus/Type3-only-Path2D
Only compile Type3 glyphs when `Path2D` is supported
2022-08-13 15:23:11 +02:00
Tim van der Meij
c81903d72d
Merge pull request #15309 from Snuffleupagus/function-rm-closure
Remove the remaining closure in the `src/core/function.js` file
2022-08-13 15:05:17 +02:00
Jonas Jenwald
9dcfdb9578 Remove the remaining closure in the src/core/function.js file
Given that the code is written with JavaScript module-syntax, none of this functionality will "leak" outside of this file with these changes.
By removing this closure the file-size is decreased, even for the *built* `pdf.worker.js` file, since there's now less overall indentation in the code.
2022-08-13 12:52:36 +02:00
calixteman
3cf31a8b17
Merge pull request #15307 from calixteman/role_comment
[Annotation] Add an aria role comment for FreeText annotations
2022-08-12 16:22:37 +02:00
Calixte Denizet
2916910ea1 [Annotation] Add an aria role comment for FreeText annotations 2022-08-12 15:59:21 +02:00
calixteman
6b4c2464ad
Merge pull request #15237 from calixteman/annotation_a11y
[Annotations] Add some aria-owns in the text layer to link to annotations (bug 1780375)
2022-08-12 15:04:56 +02:00
Calixte Denizet
f316300113 [Annotations] Add some aria-owns in the text layer to link to annotations (bug 1780375)
This patch doesn't structurally change the text layer: it just adds some aria-owns
attributes to some spans.
The aria-owns attribute expect to have an element id, hence it's why it adds back an
id on the element rendering an annotation, but this id is built in using crypto.randomUUID
to avoid any potential issues with the hash in the url.
The elements in the annotation layer are moved into the DOM in order to have them in the
same "order" as they visually are.
The overall goal is to help screen readers to present to the user the annotations as
they visually are and as they come in the text flow.
It is clearly not perfect, but it should improve readability for some people with visual
disabilities.
2022-08-12 14:35:26 +02:00
Jonas Jenwald
e9e9fee833 Only compile Type3 glyphs when Path2D is supported
According to MDN `Path2D` is available in all browsers that we currently support, see https://developer.mozilla.org/en-US/docs/Web/API/Path2D#browser_compatibility
Hence only Node.js is currently lagging behind here, and requires that we keep the old code as a fallback in the `compileType3Glyph` function. However, there's an open PR in the `node-canvas` repository for adding `Path2D` support.

As far as I'm concerned, there's two possible solutions here:
 - We land this patch now, since it removes unnecessary code in e.g. the Firefox PDF Viewer, which means that compilation of Type3 glyphs will be disabled in Node.js until that PR is landed.[1]
   If users report bugs about Type3 glyphs looking "inconsistent" in Node.js and/or being slow to render, we could perhaps encourage them to upvote and otherwise help out getting that PR landed?

 - We wait for the mentioned PR to land *first*, before moving forward with this patch. Given that there's been no updates on that PR for almost two months, this alternative may possibly take a while.

---
[1] Note that Type3 fonts are first of all not very common in PDF documents, and secondly that compilation only applies specifically to Type3 glyphs that contain /ImageMask-data (i.e. not all Type3 fonts are affected).
2022-08-12 13:06:42 +02:00
Jonas Jenwald
b8bb1d67d4 [GENERIC viewer] Export some viewer constants in the default viewer (issue 15294)
This exports the same constants as the viewer components, but in the default viewer. To avoid bloating the global-scope the constants are added to a new `PDFViewerApplicationConstants` object[1], which also allows us to skip this in builds where it's not actually needed (e.g. the Firefox *built-in* PDF Viewer).

*Please note:* I'm not completely sold on this idea, and thus wouldn't mind the patch being rejected, since we probably don't want to export every single viewer constant this way. (And it may seem a bit arbitrary, to users, why some constants are exported and others are not.)

---
[1] Somewhat similar to the existing `PDFViewerApplicationOptions` structure.
2022-08-11 16:22:12 +02:00
Jonas Jenwald
69462e5e14 Export additional constants in the viewer components
In addition to the existing `LinkTarget` constant, used by the `PDFLinkService`-constructor, this patch exports the following constants in the viewer components:
 - `ScrollMode` and `SpreadMode`, since the `BaseViewer` has getters/setters which work with those constants.
 - `RenderingStates`, since that one may be helpful when using `PDFPageView` directly.
2022-08-11 16:22:07 +02:00
Jonas Jenwald
ab1297f053
Merge pull request #15299 from Snuffleupagus/getDocument-ArrayBuffer
Add *official* support for passing `ArrayBuffer`-data to `getDocument` (issue 15269)
2022-08-11 14:12:55 +02:00
Jonas Jenwald
dd95e4f851 Add *official* support for passing ArrayBuffer-data to getDocument (issue 15269)
While this has always worked, as a consequence of the implementation, it's never been officially supported.
In addition to adding basic unit-tests, this patch also introduces a couple of new JSDoc `@typedef`s in the API to avoid overly long lines.
2022-08-10 14:13:01 +02:00
Jonas Jenwald
e1e97c6edd
Merge pull request #15279 from Snuffleupagus/firefox-rm-README
Remove the `extensions/firefox/README.mozilla` file (bug 1778567 follow-up)
2022-08-10 11:13:00 +02:00
calixteman
cef2ac99e5
Merge pull request #15298 from calixteman/ink_min_size
[Editor] Ensure an ink editor has the minimal required size after having been pasted
2022-08-10 10:27:37 +02:00
calixteman
3eb11fafca
Merge pull request #15297 from calixteman/check_pointer_down
[Editor] Avoid creation of an editor on "wrong" clicks
2022-08-10 10:27:12 +02:00
Calixte Denizet
63361dcfc7 [Editor] Ensure an ink editor has the minimal required size after having been pasted 2022-08-10 10:15:23 +02:00
Jonas Jenwald
fa48e90e3c
Merge pull request #15296 from Snuffleupagus/toolbars-reset
Move the `reset`-calls to occur last in the toolbar-constructors
2022-08-10 10:14:23 +02:00
Calixte Denizet
71ca249d2b [Editor] Avoid creation of an editor on "wrong" clicks 2022-08-10 10:05:04 +02:00
Jonas Jenwald
047522a34a Move the reset-calls to occur last in the toolbar-constructors
By invoking the `reset` methods *last* in the `Toolbar`/`SecondaryToolbar`-constructors, we ensure that the "toolbarreset"/"secondarytoolbarreset"-events are actually handle when the viewer loads. Note that previously those events were dispatched *before* the relevant event-listeners had been attached.
With this small change we can avoid inconsistent initial toolbar-state, specifically in the case when the viewer is *reloaded* (since Firefox keeps the HTML-state on "soft" reloads).
2022-08-09 22:39:38 +02:00
Jonas Jenwald
2b0b8cd665 Add more private properties/methods in web/toolbar.js 2022-08-09 22:39:07 +02:00
calixteman
0079ce4ad0
Merge pull request #15295 from calixteman/disable_editing
[Editing] Disable buttons until the first page is rendered
2022-08-09 21:47:21 +02:00
Calixte Denizet
fbce8786d0 [Editing] Disable buttons until the first page is rendered 2022-08-09 20:35:35 +02:00
Jonas Jenwald
63708a1a5b Remove the extensions/firefox/README.mozilla file (bug 1778567 follow-up)
With the changes made in [bug 1778567](https://bugzilla.mozilla.org/show_bug.cgi?id=1778567), it no longer seems correct to overwrite the mozilla-central file.
2022-08-09 13:13:39 +02:00