Commit Graph

15557 Commits

Author SHA1 Message Date
Jonas Jenwald
cc1bca6268 Slightly simplify the PDFFindController._extractText method
Currently we're resolving the Promises in the `_extractTextPromises` Array with the page-index, despite that not really being necessary since the Promises in the Array are explicitly inserted in the correct order.
Furthermore, we can replace the standard `for`-loop with a `for...of`-loop which results in ever so slightly more compact code.
2022-03-19 12:13:29 +01:00
Jonas Jenwald
c0736647f9 Add general iteration support in the RefSet and RefSetCache classes
This patch removes the existing `forEach` methods, in favor of making the classes properly iterable instead. Given that the classes are using a `Set` respectively a `Map` internally, implementing this is very easy/efficient and allows us to simplify some existing code.
2022-03-18 14:27:34 +01:00
Jonas Jenwald
5180bafb8f [gulpfile.js] Use the regular defines in the preprocessCSS function
Rather than *manually* specifying a "mode", we can simply use the regular `defines` directly instead. To improve consistency, in the `external/builder/builder.js` file, a couple of parameters are also re-named.
2022-03-16 22:39:48 +01:00
Tim van der Meij
489e9ff7d3
Merge pull request #14675 from Snuffleupagus/build-dev-CSS
Build the `web/viewer.css` file used in the development viewer (i.e. `gulp server`)
2022-03-16 20:14:02 +01:00
Tim van der Meij
00eb942c93
Merge pull request #14678 from Snuffleupagus/PDFDocumentProperties-private
Convert the `PDFDocumentProperties` class to use private methods
2022-03-16 20:10:45 +01:00
Tim van der Meij
82770e0655
Merge pull request #14676 from Snuffleupagus/preprocessCSS-cleanup
Remove the custom `grab`/`grabbing` cursor image files
2022-03-16 20:06:55 +01:00
Jonas Jenwald
be2b1d5d2a [src/display/api.js] Simplify the sendTest function, used with Worker initialization (PR 14291 follow-up)
Given that we now only use Workers when `postMessage` transfers are supported, there's really no point in trying to send a "test" message *without* transfers present.
Hence, if `postMessage` transfers are not supported by the browser, we'll now fallback to "fake" Workers immediately instead. The comment about Opera is also removed, since it was originally added back in PR 983 and mentions Opera `11.60` [which was released in 2011](https://en.wikipedia.org/wiki/History_of_the_Opera_web_browser#Version_11).
2022-03-16 13:25:41 +01:00
Jonas Jenwald
d5c9be341d [src/display/api.js] Use private static class fields, rather than shadowed getter work-arounds (PR 13813, 13882 follow-up)
At the time private static class fields were to new, however that's no longer an issue and we can thus (ever so slightly) simplify the code.
2022-03-16 13:02:34 +01:00
Jonas Jenwald
ba8dae696a Convert the PDFDocumentProperties class to use private methods
Given that none of these methods were ever intended to be accessed directly from the outside, we can use modern ECMAScript features to ensure that they are indeed private.

This patch also makes `fieldData` private, to remove the old hack used to prevent it from being modified from the outside.
2022-03-15 18:17:06 +01:00
Jonas Jenwald
c5574864e1 Remove the -webkit-mask-image/-webkit-mask-image CSS rules
Given that we're now *building* the `web/viewer.css` file used in the development viewer, i.e. with `gulp server`, we no longer need to hard-code these `-webkit`-prefixed rules and can instead let Autoprefixer handle that for us.
2022-03-15 13:37:46 +01:00
Jonas Jenwald
e59c2dc308 Build the web/viewer.css file used in the development viewer (i.e. gulp server)
To allow using modern CSS features that currently only Mozilla Firefox supports[1], while still enabling development/testing in recent Google Chrome versions, we'll have to start building the `web/viewer.css` file with `gulp server` as well.

In my testing, building the development CSS (and copying the images) takes *less than* `200 ms` on average which is hopefully an acceptable overhead for this sort of feature.

---
[1] In particular `float`, with `inline-start`/`inline-end` values.
2022-03-15 13:37:44 +01:00
Jonas Jenwald
ee2896dd1e Remove the custom grab/grabbing cursor image files
According to the MDN compatibility data, see https://developer.mozilla.org/en-US/docs/Web/CSS/cursor#browser_compatibility, all browsers that we now support should have these cursors available natively.
2022-03-14 14:36:38 +01:00
Jonas Jenwald
6776efe491 [gulpfile.js] Remove the cleanup parameter in preprocessCSS helper function
Every single call-site has always passed in `true` for this parameter, ever since the function was first added back in PR 8023. Hence the parameter appears to be completely unnecessary, which is why it's removed and the function is updated to *unconditionally* strip out any license headers (in the middle of the file).
2022-03-14 13:55:05 +01:00
Tim van der Meij
90c5e9882b
Merge pull request #14669 from Snuffleupagus/padding-inline
Replace `dir`-dependent `padding-left`/`padding-right`/`text-align` with logical properties
2022-03-13 20:51:07 +01:00
Tim van der Meij
dd4af1c60d
Merge pull request #14665 from Snuffleupagus/Preferences-private
Convert the `BasePreferences` class to use private fields
2022-03-13 20:45:29 +01:00
Tim van der Meij
48f49ff9f4
Merge pull request #14668 from Snuffleupagus/rm-addLinkAttributes-warn
Remove the `addLinkAttributes` warnings in the Annotation/XFA-layers (PR 14092 follow-up)
2022-03-13 20:40:22 +01:00
Tim van der Meij
f410403c4b
Merge pull request #14667 from Snuffleupagus/fieldObjects-test-Node
Enable the "gets fieldObjects" unit-test in Node.js (PR 14409 follow-up)
2022-03-13 20:39:01 +01:00
Jonas Jenwald
331f4e72de Replace dir-dependent padding-left/padding-right/text-align with logical properties
*Please note:* This is small first step in what will, time permitting, become a series of patches to simplify/modernize the viewer CSS.

Rather than having to *manually* specify ltr/rtl-specific padding-values in the CSS, we can use logical padding instead (and similar for text-align).
These logical properties depend on, among other things, the direction of the HTML document which we *always* specify in the viewer.

Note that a number of logical CSS properties are new enough that we'll need to use PostCSS plugins, however the ones in this patch are natively supported in all browsers that we currently support:
 - https://developer.mozilla.org/en-US/docs/Web/CSS/padding-inline-start#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/padding-inline-end#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/text-align#browser_compatibility
2022-03-13 14:36:11 +01:00
Jonas Jenwald
0c349c701f Remove the addLinkAttributes warnings in the Annotation/XFA-layers (PR 14092 follow-up)
These warnings have now been present in three releases, see PR 14092, hence it should (hopefully) be fine to remove them now.
2022-03-13 11:38:56 +01:00
Jonas Jenwald
fb345ee184 Enable the "gets fieldObjects" unit-test in Node.js (PR 14409 follow-up)
Apparently this unit-test works in Node.js now, hence it's *possible* that the reason it didn't work previously is that there were bugs in our old `structuredClone` polyfill.
2022-03-13 10:40:57 +01:00
Jonas Jenwald
3274972768 Revert Preferences to their previous values, when writing to storage failed
This patch fixes an old inconsistency, when using `BasePreferences.{reset, set}`, where the internal Preference values would be kept even if writing them to storage failed.
2022-03-12 17:25:45 +01:00
Jonas Jenwald
25d7420035 Convert the BasePreferences class to use private fields
Given that none of these fields were ever intended to be accessed directly from the *outside*, since that will lead to inconsistent/broken state, we can use modern ECMAScript features to ensure that they are indeed private.
2022-03-12 14:34:57 +01:00
Tim van der Meij
9e4aaf18f7
Merge pull request #14661 from tiziodcaio/gh_actions
Update Checkout to version 3
2022-03-11 21:11:18 +01:00
Tim van der Meij
790735eaf1
Merge pull request #14658 from Snuffleupagus/api-validate-cMapUrl-standardFontDataUrl
Validate the `cMapUrl`/`standardFontDataUrl` parameters in `getDocument`
2022-03-11 21:09:58 +01:00
Tim van der Meij
bcf453cf14
Merge pull request #14656 from Snuffleupagus/mv-isSameOrigin
Move the `isSameOrigin` helper function
2022-03-11 21:08:49 +01:00
Tim van der Meij
0d265a30ed
Merge pull request #14654 from Snuffleupagus/TestReporter-send-fetch
Replace XMLHttpRequest usage with the Fetch API in `send` (in `test/unit/testreporter.js`)
2022-03-11 21:05:36 +01:00
Jonas Jenwald
4318bc8f86
Merge pull request #14554 from Snuffleupagus/issue-14526
Try to improve a11y for the "button groups" in the SecondaryToolbar/Sidebar (issue 14526)
2022-03-11 20:46:47 +01:00
tiziodcaio
1a380b5736
Update Checkout to version 3
Uses node 16 as default
2022-03-11 14:35:06 +01:00
Jonas Jenwald
1b6e1eac92
Merge pull request #14620 from Snuffleupagus/Firefox-getStrings
Bug 1757527 - Slightly reduce (repeated) message passing overhead when localizing the PDF Viewer
2022-03-11 11:36:51 +01:00
Jonas Jenwald
a60b98412f Validate the cMapUrl/standardFontDataUrl parameters in getDocument
These changes make sense for two reasons:
 - Given that the parameters are potentially passed to the worker-thread, depending on the `useWorkerFetch` parameter, we need to prevent errors if the user provides values that aren't clonable.
 - By ensuring that the default values are indeed `null`, we'll trigger main-thread fetching (of CMaps and Standard fonts) as intended in the `PartialEvaluator` and thus potentially provide better Error messages.
2022-03-10 16:33:10 +01:00
Jonas Jenwald
537ed37835 Move the isSameOrigin helper function
This function is currently placed in the `src/shared/util.js` file, which means that the code is duplicated in both of the *built* `pdf.js` and `pdf.worker.js` files. Furthermore, it only has a single call-site which is also specific to the `GENERIC`-build of the PDF.js library.

Hence this helper function is instead moved into the `src/display/api.js` file, in such a way that it's conditionally defined but still can be unit-tested.
2022-03-10 13:51:09 +01:00
Jonas Jenwald
e08e3f4d37 Replace XMLHttpRequest usage with the Fetch API in send (in test/unit/testreporter.js)
Besides converting the `send` function to use the Fetch API, this patch also changes the method to return a `Promise` to get rid of the callback function. (Although, currently there's no call-site passing in a callback function.)
2022-03-10 12:55:08 +01:00
Jonas Jenwald
48c64c6c8d Bug 1757527 - Slightly reduce (repeated) message passing overhead when localizing the PDF Viewer 2022-03-10 10:20:34 +01:00
Tim van der Meij
ee39499a5a
Merge pull request #14651 from Snuffleupagus/Driver-inlineImages-fetch
Replace XMLHttpRequest usage with the Fetch API in `inlineImages` (in `test/driver.js`)
2022-03-09 20:47:38 +01:00
Tim van der Meij
fee1bc68e9
Merge pull request #14642 from Snuffleupagus/Driver-send-fetch
Replace XMLHttpRequest usage with the Fetch API in `Driver._send`
2022-03-09 20:43:12 +01:00
Tim van der Meij
e85bb0b599
Merge pull request #14645 from Snuffleupagus/Node-DOMMatrix-polyfill
[api-minor] Remove the, in `legacy` builds, bundled `DOMMatrix` polyfill
2022-03-09 20:38:26 +01:00
Tim van der Meij
55a931e454
Merge pull request #14648 from Snuffleupagus/PDFDocument-stream
Simplify the `PDFDocument` constructor
2022-03-09 20:36:49 +01:00
Tim van der Meij
23d1abee0b
Merge pull request #14640 from Snuffleupagus/update-TypeScript
Update TypeScript to version `4.6.2` and work-around stricter type checks
2022-03-09 20:35:24 +01:00
Jonas Jenwald
b3f4758183 Replace XMLHttpRequest usage with the Fetch API in inlineImages (in test/driver.js)
This is the final part in a series of patches that try to re-implement PR 14287 in smaller steps.

Besides converting `inlineImages` to use the Fetch API, this patch also combines the `inlineImages` and `resolveImages` functions since they are always used together.
2022-03-09 11:32:51 +01:00
Jonas Jenwald
6a78f20b17 Simplify the PDFDocument constructor
Originally the code in the `src/`-folder was shared between the main/worker-threads, and back then it probably made sense that the `PDFDocument` constructor accepted different arguments.
However, for many years we've not been passing anything *except* Streams to `PDFDocument` and we should thus be able to slightly simplify that code. Note that for e.g. unit-tests of this code, using either a `NullStream` or a `StringStream` works just fine.
2022-03-08 17:13:47 +01:00
Jonas Jenwald
157a71d404 [api-minor] Remove the, in legacy builds, bundled DOMMatrix polyfill
According to the MDN compatibility data, see https://developer.mozilla.org/en-US/docs/Web/API/DOMMatrix/DOMMatrix#browser_compatibility, all browsers that we support have native `DOMMatrix` implementations (since quite some time too).

Hence Node.js is the only environment that lack `DOMMatrix` support, which probably isn't that surprising given that it's browser functionality.
While the `DOMMatrix` polyfill isn't that large, it nonetheless seems completely unnecessary to bundle it in the `legacy` builds when it's not needed in browsers. However, we can avoid that by simply listing `dommatrix` as a dependency for the `pdfjs-dist` library.
2022-03-08 10:29:11 +01:00
Jonas Jenwald
19c2cc8689 Replace XMLHttpRequest usage with the Fetch API in Driver._send
This is another part in a series of patches that try to re-implement PR 14287 in smaller steps.

Besides converting `Driver._send` to use the Fetch API, this also changes the method to return a `Promise` to get rid of the callback function.
Please note that I *purposely* try to maintain the existing behaviour of re-sending the data on failure/unexpected response, including how/where the old callback function was invoked.
2022-03-07 16:00:52 +01:00
Jonas Jenwald
6f600befdd Update TypeScript to version 4.6.2 and work-around stricter type checks
I'm guessing that we're now running into the class-related improvements mentioned in https://devblogs.microsoft.com/typescript/announcing-typescript-4-6/#target-es2022
To unblock this update, and any future ones, this patch simply tweaks the JSDocs to get `gulp typestest` to run without errors.
2022-03-07 11:55:17 +01:00
Tim van der Meij
3e593cfc1d
Merge pull request #14636 from Snuffleupagus/Driver-quit-fetch
Replace XMLHttpRequest usage with the Fetch API in `Driver._quit`
2022-03-06 18:26:55 +01:00
Jonas Jenwald
d65169d754 Try to improve a11y for the "button groups" in the SecondaryToolbar/Sidebar (issue 14526)
*Please note:* I don't really know anything about a11y, hence it's possible that this patch either doesn't work correctly or at least isn't a complete solution.

In both the SecondaryToolbar and the Sidebar we have "button groups" that functionally acts essentially like radio-buttons. Based on skimming through [this MDN article](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/radio_role) it thus appears that we should tag them as such, using `role="radiogroup"` and `role="radio"`, and then utilize the `aria-checked` attribute to indicate to a11y software which button is currently active.
2022-03-06 16:54:27 +01:00
Jonas Jenwald
c1f73b140f
Merge pull request #14637 from timvandermeij/web-private
Use proper private methods in `web/{pdf_cursor_tools,pdf_find_bar,secondary_toolbar}.js`
2022-03-06 16:47:33 +01:00
Tim van der Meij
a00308d5f3
Merge pull request #14638 from Snuffleupagus/reftest-analyzer-fetch
Replace XMLHttpRequest usage with the Fetch API in the reftest-analyzer
2022-03-06 16:37:31 +01:00
Tim van der Meij
6500aafd00
Use proper private methods in web/secondary_toolbar.js 2022-03-06 16:07:25 +01:00
Tim van der Meij
f33769db2d
Use proper private methods in web/pdf_find_bar.js 2022-03-06 16:07:07 +01:00
Tim van der Meij
a1d106dc5d
Use proper private methods in web/pdf_cursor_tools.js 2022-03-06 16:06:53 +01:00