Commit Graph

313 Commits

Author SHA1 Message Date
Jonas Jenwald
62a9435190 [api-minor] Stop including the "lib"-build in the pdfjs-dist repository
The `pdfjs-dist/lib/` directory contains a README file that explicitly advises against using those files, however based on a fairly large number of issues filed over the years users seem to be (mostly) overlooking that warning.
In particular it unfortunately seems to be somewhat common for users to attempt to "combine" proper builds from `pdfjs-dist/build/` together with individual components from the `pdfjs-dist/lib/web/` directory, which more often than not leads to subtle bugs and general problems.

When we receive bug reports about this it's often not immediately obvious what the problem is, given that many issues lack enough details (such as runnable test-cases), but after some back-and-forth it usually turns out that usage of `pdfjs-dist/lib/` is the culprit.
Considering that keeping the general PDF.js library working is challenging and time-consuming enough nowadays, this patch thus proposes that we stop including the "lib"-build in the `pdfjs-dist` repository to both reduce user confusion and the support burden.
2023-04-26 12:11:13 +02:00
Tim van der Meij
f6f33065ef
Update mkdirp to version 3.0.0
The only change in this major version is the removal of the default
export, so we must simply use the named export instead.
2023-04-23 14:37:40 +02:00
Tim van der Meij
c9359957e6
Merge pull request #16305 from Snuffleupagus/PDFJSDev-skip-PRODUCTION
Remove the `PRODUCTION` build-target
2023-04-22 14:53:30 +02:00
Jonas Jenwald
19526d2322 Update eslint-plugin-mozilla to avoid having to force-install packages (issue 15429)
The latest version of `eslint-plugin-mozilla` removed the Prettier dependency, see https://bugzilla.mozilla.org/show_bug.cgi?id=1677562, which means that we no longer need to use `npm install --force` in the PDF.js library.
2023-04-20 16:14:31 +02:00
Jonas Jenwald
89b0fd9628 Remove the remaining PRODUCTION build-target usage
After the previous patch we now have only *a single* `PRODUCTION` occurrence in the entire code-base, more specifically in the `web/viewer.html` file.
This special build-target can be replaced with any condition that always evaluate to `false`, such as e.g. a comment.

*Please note:* This patch might be considered too hacky, hence I completely understand if it's rejected.
2023-04-17 12:07:20 +02:00
Jonas Jenwald
877c867a92 Update npm packages 2023-04-15 22:10:02 +02:00
Jonas Jenwald
d3d16b15ac [Firefox] Use float: inline-start/inline-end directly in MOZCENTRAL builds (PR 15968 follow-up)
Currently `float: inline-start/inline-end` is only supported in Firefox, see https://developer.mozilla.org/en-US/docs/Web/CSS/float#browser_compatibility, and in order to support other browsers we're thus forced to jump through some hoops.
This leads to slightly less nice code in the *built-in* Firefox PDF Viewer, and this patch attempts to improve the current situation:
 - Use Stylelint to forbid direct use of `float: inline-start/inline-end` in the CSS files, to prevent future bugs in the general PDF.js viewer.
 - Do a build-time replacement, only in MOZCENTRAL builds, to replace the CSS-variables with raw `float: inline-start/inline-end` instances.
2023-04-10 16:26:19 +02:00
Tim van der Meij
8398cabd17
Merge pull request #16249 from Snuffleupagus/Chrome-88
[api-minor] Update the minimum supported Google Chrome version
2023-04-10 15:41:42 +02:00
Tim van der Meij
20f79f870e
Merge pull request #16246 from Snuffleupagus/dist-install-force
Force-install when using `gulp dist-install` (issue 15435)
2023-04-10 15:40:09 +02:00
Calixte Denizet
3b147205ba [GeckoView] Add a basic toolbar with a download button for GV (bug 1823164) 2023-04-07 11:54:16 +02:00
Jonas Jenwald
ce3ea58778 [api-minor] Update the minimum supported Google Chrome version
The patch changes the minimum supported version of Google Chrome as follows:
 - Chrome 88, which was released on 2021-01-19; see https://en.wikipedia.org/wiki/Google_Chrome_version_history

This is done to allow use of modern CSS features, such as e.g. `:is()` and `:where()` in the code-base.
2023-04-03 13:23:26 +02:00
Jonas Jenwald
bf57a8f660 Force-install when using gulp dist-install (issue 15435)
When installing the PDF.js project itself it's currently necessary to use `--force` in order for all packages to install correctly, see issue 15429, hence the same is also necessary when using the `gulp dist-install` command for local development/testing.
2023-04-02 16:06:36 +02:00
Mark Banner
bb5467789b Remove now unnecessary eslint-disable statement generated for PdfJsDefaultPreferences.sys.mjs. (bug 1825522). 2023-03-30 14:47:31 +01:00
Calixte Denizet
5f5256b4c4 ESMify some modules for m-c (bug 1824610) 2023-03-27 12:01:31 +02:00
Jonas Jenwald
1fc09f0235 Enable the unicorn/prefer-string-replace-all ESLint plugin rule
Note that the `replaceAll` method still requires that a *global* regular expression is used, however by using this method it's immediately obvious when looking at the code that all occurrences will be replaced; please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll#parameters

Please find additional details at https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-string-replace-all.md
2023-03-23 12:57:10 +01:00
Jonas Jenwald
6d3506548d [api-minor] Update the minimum supported Node.js version to 16
This patch updates the minimum supported environments as follows:
 - Node.js 16, which was released on 2021-04-20; see https://en.wikipedia.org/wiki/Node.js#Releases

Note also that Node.js 14 will very soon reach EOL, and thus no longer receive any security updates.
2023-03-07 16:33:56 +01:00
Jonas Jenwald
2f2f1e5088 Revert "Update rimraf to version 4"
This reverts commit 32357e3d17.
2023-03-06 19:57:00 +01:00
Jonas Jenwald
90ffbc1d39 Remove most build-time require statements from the viewer (PR 16009 follow-up)
This further extends the web-specific import maps introduced in PR 16009, to allow removing *most* of the build-time `require` statements from the viewer. The few remaining ones are fallbacks used for the COMPONENTS respectively the `legacy` GENERIC builds.
2023-02-07 22:45:19 +01:00
Jonas Jenwald
8f37301d1f Remove the "div-css" gulp task (PR 15968 follow-up)
After the compatibility updates in PR 15968 it's no longer strictly necessary to build the `viewer.css` file in order for the *development viewer* to work in Chromium-based browsers.

*Please note:* Given that Chromium-based browsers still don't support the *unprefixed* `mask-image` property the icons won't look right, however the development viewer itself works.
Given that Firefox is the *primary* development target, and that running `gulp generic` locally will generate polyfilled CSS, it seems reasonable to make this simplification here.
2023-02-07 21:37:41 +01:00
Jonas Jenwald
a98e80c4ff [GeckoView] Reduce the size of the *built* viewer
Given that the GV-viewer isn't using most of the UI-related components of the default-viewer, we can avoid including them in the *built* viewer to save space.[1]
The least "invasive" way of implementing this, at least that I could come up with, is to leverage import maps with suitable stubs for the GV-viewer.

The one slightly annoying thing is that we now have larger import maps across multiple html-files, and you'll need to remember to update all of them when making future changes.

---
[1] With this patch, the built `viewer.js` size is 391 kB and `viewer-geckoview.js` is 285 kB.
2023-02-05 14:12:32 +01:00
Jonas Jenwald
ca996d2546 [api-minor] Update the minimum supported browsers, and remove the PostCSS logical plugin
The patch updates the minimum supported browsers/environments as follows:
 - Chrome 87, which was released on 2020-11-17; see https://en.wikipedia.org/wiki/Google_Chrome_version_history
 - Firefox ESR (no change); see https://wiki.mozilla.org/Release_Management/Calendar
 - Safari 14.1, which was released on 2021-04-26; see https://en.wikipedia.org/wiki/Safari_version_history#Safari_14
 - Node.js 14 (no change); see https://en.wikipedia.org/wiki/Node.js#Releases

The recent *major* release of the PostCSS `logical` plugin effectively removed support for all of the things that we used it for, which includes (but may not be limited to): preserving the original CSS code (for up-to-date browsers), re-writing the `:dir` pseudo-class, and support for re-writing `float: inline-start;`/`float: inline-end;` properties.
Please find additional details at https://github.com/csstools/postcss-plugins/blob/main/plugins/postcss-logical/CHANGELOG.md#600-january-24-2023
Hence the primary reason for these changes are related to native support for *logical* CSS properties/values. Currently, in the default viewer, we're using the following ones:
 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset-inline-start#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset-inline-end#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline-start#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline-end#browser_compatibility
 - 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
 - https://developer.mozilla.org/en-US/docs/Web/CSS/float#browser_compatibility

By updating the minimum supported browsers, we thus only have to worry about the *last* case here. Thankfully there's not that many `float: inline-start;`/`float: inline-end;` occurrences, and we can utilize CSS variables together with the pre-processor to support those in a way that won't affect the Firefox PDF Viewer.
2023-01-29 20:25:05 +01:00
Jonas Jenwald
cf0369d622 Polyfill Path2D in Node.js environments
Until just recently the only existing `Path2D` polyfill didn't have support for Node.js and/or the `node-canvas` package. Given that this was just fixed, in the latest version, we can now finally remove our inline-checks at the relevant call-sites; please also see https://github.com/nilzona/path2d-polyfill#usage-with-node-canvas
2023-01-28 18:28:22 +01:00
Jonas Jenwald
07ba352903 Update npm packages 2023-01-28 08:13:13 +01:00
Jonas Jenwald
32357e3d17 Update rimraf to version 4
The primary change is that the `rimraf` function now returns a Promise instead of taking a callback; please see https://github.com/isaacs/rimraf#major-changes-from-v3-to-v4
2023-01-15 15:38:30 +01:00
Calixte Denizet
685b5866e4 Remove shadow around each pages (fix issue #15836) 2023-01-02 14:58:53 +01:00
Jonas Jenwald
492ce090bd Update npm packages 2022-12-25 12:59:34 +01:00
Calixte Denizet
f19572c4cc [GV] Add a viewer for GeckoView 2022-12-15 13:39:48 +01:00
Jonas Jenwald
fbcc20adb7 Update npm packages 2022-11-13 21:28:21 +01:00
Takashi Tamura
0bb478cb23 Move canvas to optionalDependencies, which enables npm to continue installing pdfjs-dist
even if the installation of canvas fails. Close #15652
2022-11-02 08:33:31 +09:00
Jonas Jenwald
c894be92fb Replace the DOMMatrix polyfill, used with Node.js, with the one from node-canvas
Fewer dependencies shouldn't be a bad idea in general, and given that the `node-canvas` package already include a `DOMMatrix` polyfill we can simply use that one instead.
2022-09-27 12:12:50 +02:00
Tim van der Meij
d78619cd66
Merge pull request #15452 from Snuffleupagus/chrome-extension
Temporarily stop listing the official Chrome extension in the main README
2022-09-18 14:29:46 +02:00
Jonas Jenwald
b7f987a185 [api-major] Update the minimum supported browsers/environments
In the `legacy`-builds we (obviously) support the currently maintained Firefox ESR version, and looking at the [release history](https://wiki.mozilla.org/Release_Management/Calendar) those are officially supported (by Mozilla) for about 1-1.5 years.
However, for non-Firefox browsers the `legacy`-builds currently attempt to "support" browsers that are approximately *three* years old.[1] Historically, in the PDF.js project, trying to support old browsers have caused some maintenance problems and even delayed adoption of new web-platform features/functionality.

To lessen the support burden, given that the primary purpose of the PDF.js library is still to develop the *built-in* Firefox PDF Viewer, this patch proposes that the upcoming *major* release changes the minimum supported browsers/environments as follows:
 - Chrome 85, which was released on 2020-08-25; see https://en.wikipedia.org/wiki/Google_Chrome_version_history
 - Firefox ESR (as before); see https://wiki.mozilla.org/Release_Management/Calendar
 - Safari 14, which was released on 2020-09-16; see https://en.wikipedia.org/wiki/Safari_version_history#Safari_14
 - Node.js 14 (as before), which is now explicitly listed to prevent it from accidentally breaking; see https://en.wikipedia.org/wiki/Node.js#Releases

---
[1] In older browsers some functionality may not be available and generally we'll ask users to update to a modern browser when bugs, specific to old browsers, are being reported.
2022-09-18 01:12:15 +02:00
Jonas Jenwald
afabbc28c5 Temporarily stop listing the official Chrome extension in the main README
The [official Chrome extension](https://chrome.google.com/webstore/detail/pdf-viewer/oemmndcbldboiebfnladdacbdfmadadm) has unfortunately not been updated for *three years*, which means that it's currently missing out on years worth of bug fixes, performance improvements, and new features.
In particular, the Chrome extension suffers from a known bug with non-embedded standard fonts; see issue 13669 for details.

For the time being, this patch proposes that we *temporary* make the following changes:
 - Remove the mention of the official Chrome extension from the main README, since it seems unfortunate to somewhat prominently recommend users an old and partially non-working extension.
 - Don't run the `gulp lint-chromium` task as part of the CI, since in addition to the official extension not having been updated its code is also not being actively maintained.[1]

Once the official Chrome extension has been updated, and it's being actively maintained again, this patch should be simple enough to revert.

---
[1] The last commits, which aren't e.g. linting or general code-maintenance related, happened a year ago now.
2022-09-17 16:29:19 +02:00
Sam Magura
1c2d200918 [api-minor] Use new Worker() syntax in webpack entrypoint
This requires Webpack 5 and will break for anyone using Webpack 4.
worker-loader no longer needs to be installed.
2022-09-13 11:12:00 -04:00
Jonas Jenwald
5b903a6e2d Remove Bower support in pdfjs-dist
Given that the official Bower website, since almost five years, has been advising users to utilize other tools it doesn't seem entirely necessary to keep including the `bower.json` file in the `pdfjs-dist` repository; see e.g. https://bower.io/blog/2017/how-to-migrate-away-from-bower/
2022-09-03 13:05:59 +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
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
Jonas Jenwald
ad11cea33c [api-minor] Update the minimum supported Safari version
The Ink-editor uses `ResizeObserver`, which is supported in all reasonably modern browsers; see https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver#browser_compatibility

With the exception of Safari, `ResizeObserver` is thus available in all of the browsers that the PDF.js library currently support. Rather than trying to e.g. add a polyfill, let's just bump the compatibility (slightly) to Safari 13.1 instead; see https://en.wikipedia.org/wiki/Safari_version_history#Safari_13
2022-07-31 17:40:26 +02:00
Jonas Jenwald
37ebc28756 Use more for...of loops in the code-base
Note that these cases, which are all in older code, were found using the [`unicorn/no-for-loop`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-for-loop.md) ESLint plugin rule.
However, note that I've opted not to enable this rule by default since there's still *some* cases where I do think that it makes sense to allow "regular" for-loops.
2022-07-17 16:18:54 +02:00
Jonas Jenwald
345bb18575 [editor] Use the fit-curve package (issue 15004)
Rather than including all of this external code in the PDF.js repository, we should be using the npm package instead.
Unfortunately this is slightly more complicated than you'd hope, since the `fit-curve` package (which is older) isn't directly compatible with modern JavaScript modules.
In particular, the following cases needed to be considered:
 - For the development viewer (i.e. `gulp server`) and the unit-tests, we thus need to build a fitCurve-bundle that can be directly `import`ed.
 - For the actual PDF.js build-targets, we can slightly reduce the sizes by depending on the "raw" `fit-curve` source-code.
 - For the Node.js unit-tests, the `fit-curve` package can be used as-is.
2022-07-07 10:43:43 +02:00
Jonas Jenwald
2f0ed3a9ca [api-minor] Update the minimum supported browsers/environments
*Please note:* The dates below are still a little ways off, however that obviously won't affect the existing PDF.js releases. Hence I think that we can make these changes now, since by the time of the *next* official PDF.js release they'll likely match up pretty well.[1]

While we "support" some (by now) fairly old browsers, that essentially means that the library (and viewer) will load and that the basic functionality will work as intended.[2]
However, in older browsers, some functionality may not be available and generally we'll ask users to update to a modern browser when bugs (specific to old browsers) are reported.[3]

Since we've previously settled on only supporting browsers/environments that are approximately *three years old*, this patch updates the minimum supported browsers/environments as follows:
 - Chrome 76, which was released on 2019-07-30; see https://en.wikipedia.org/wiki/Google_Chrome_version_history
 - Firefox ESR (as before); see https://wiki.mozilla.org/Release_Management/Calendar
 - Safari 13, which was released on 2019-09-19; see https://en.wikipedia.org/wiki/Safari_version_history#Safari_13
 - Node.js 14, which was release on 2020-04-21 (all older versions have reached EOL); see https://en.wikipedia.org/wiki/Node.js#Releases

---
[1] Given that the releases usually happen every two to three months.

[2] Assuming that a `legacy/`-build is being used, of course.

[3] In general it's never a good idea to use old/outdated browsers, since those may contain *known* security vulnerabilities.
2022-06-11 16:50:01 +02:00
calixteman
c8f6cb9fcf
Revert "Change the name of the generated pdf.sandbox.external for mozilla-central" 2022-06-10 11:34:28 +02:00
Calixte Denizet
7b37af7eb4 Change the name of the generated pdf.sandbox.external for mozilla-central
This patch is blocking https://phabricator.services.mozilla.com/D148600.
2022-06-08 10:36:38 +02:00
Jonas Jenwald
bb8f5ec20b Bundle the <dialog> polyfill-CSS in the GENERIC legacy/-viewer (PR 14710 follow-up)
In PR 14710 we only included the JavaScript-part of the polyfill, however we probably need to include the CSS as well to reduce the risk of problems in older browsers.

With the recent CSS-related improvements in the `preprocess`-function we could probably have included this conditionally in the `viewer.css` file. However, considering that the `<dialog>` polyfill-code is only invoked when actually needed it seemed most appropriate/correct to lazy-load the polyfill-CSS as well.
2022-06-04 18:11:35 +02:00
Takashi Tamura
10932e3f9d Use globalThis for webpack's output.globalObject instead of this. Close #14915.
That allows us to import pdfjs-dist/build/pdf.js dynamically from modules.

- https://webpack.js.org/configuration/output/#outputglobalobject
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
2022-05-29 11:28:17 +09:00
Jonas Jenwald
5320316f73 Update npm packages 2022-05-15 09:07:35 +02:00
Jonas Jenwald
80910f44e5 Stop bundling the openFile-buttons in the CHROME build
This is, for all intents and purposes, equivalent to PR 14833 and slightly reduces the size of the `gulp chromium` output.
2022-05-07 22:45:56 +02:00
Jonas Jenwald
d1f13a6af3 Use the regular preprocess-function for the CSS files as well
An old shortcoming of the `preprocessCSS`-function is its complete lack of support for our "normal" defines, which makes it very difficult to have build-specific CSS rules. Recently we've started using specially crafted comments to remove CSS rules from the MOZCENTRAL build, but (ab)using the `preprocessCSS`-function in this way really doesn't feel great.
However, it turns out to be surprisingly simple to instead use the "regular" `preprocess`-function for the CSS files as well. The only special-handling that's still necessary is the helper-function for dealing with CSS-imports, but apart from that everything seems to just work.

One reason, as far as I can tell, for having a separate `preprocessCSS`-function was likely that we originally used *lots* of vendor-prefixed CSS rules in our CSS files. With improvements over the years, especially thanks to Autoprefixer and PostCSS, we've been able to remove *almost* all non-standard CSS rules and the need for special-casing the CSS parsing has mostly vanished.

*Please note:* As part of testing this patch I've diffed the output of `gulp generic`, `gulp mozcentral`, and `gulp chromium` against the `master`-branch to check that there was no obvious breakage.
2022-05-07 22:45:52 +02:00
Tim van der Meij
dacd61fede
Update dependencies to the most recent versions
There are two notable changes here:

- `dommatrix` is a major version upgrade, but looking through the commit
  history of their `package.json` file at https://github.com/thednp/dommatrix/commits/master/package.json
  (due to the lack of a changelog) I couldn't find any breaking changes.
- `es-module-shims` is a regular update, but it was previously pinned
  for causing intermittent breakage when running the unit tests in a
  browser manually. Fortunately this cannot be reproduced anymore with
  the most recent version, so we can also put the caret back now.
2022-05-01 13:08:00 +02:00
Jonas Jenwald
b04c373362 Stop bundling the openFile-buttons in the MOZCENTRAL build
Note how both of the openFile-buttons are always hidden during viewer initialization in the MOZCENTRAL build, i.e. the *built-in* Firefox PDF Viewer. Despite that we still include HTML, CSS, and JavaScript code for these buttons in the build.

This patch *reduces* the size of the `gulp mozcentral` output by `1679` bytes, which isn't a lot but still cannot hurt.
2022-04-25 11:35:17 +02:00