Commit Graph

13657 Commits

Author SHA1 Message Date
Jonas Jenwald
5b5061afa8 Enable the ESLint no-var rule globally
A significant portion of the code-base has now been converted to use `let`/`const`, rather than `var`, hence it should be possible to simply enable the ESLint `no-var` rule globally.
This way we can ensure that new code won't accidentally use `var`, and it also removes the need to manually enable the rule in various folders.

Obviously it makes sense to continue the efforts to replace `var`, but that should probably happen on a file and/or folder basis.

Please note that this patch excludes the following code:
 - The `extensions/` folder, since that seemed easiest for now (and I don't know exactly what the support situation is for the Chromium-extension).

 - The entire `external/` folder is ignored, since most of it's currently excluded from linting.
   For the code that isn't imported from elsewhere (and should be ignored), we should probably (at some point) bring the code up to the same linting/formatting standard as the rest of the code-base.

 - Various files in the `test/` folder are ignored, as necessary, since the way that a lot of this code is loaded will require some care (or perhaps larger re-factoring) when removing `var` usage.
2021-03-13 16:12:53 +01:00
Tim van der Meij
17c0bf0473
Merge pull request #13084 from Snuffleupagus/type1-class
Enable the ESLint `no-var` rule in a few font-parsing files, and convert `src/core/type1_parser.js` to use "standard" classes
2021-03-13 13:15:53 +01:00
Tim van der Meij
1abdcbaab5
Merge pull request #13087 from Snuffleupagus/eslint-examples-no-var
Enable the ESLint `no-var` rule in the `examples/` folder
2021-03-13 13:04:00 +01:00
Tim van der Meij
ba567321da
Merge pull request #13079 from Snuffleupagus/issue-13075
Ensure that `getDocument` handles Node.js `Buffer`s more gracefully (issue 13075)
2021-03-13 12:58:29 +01:00
Tim van der Meij
6ae81255bc
Merge pull request #13090 from Snuffleupagus/eslint-no-var-gulpfile
Enable the ESLint `no-var` rule in `gulpfile.js`
2021-03-13 12:55:34 +01:00
Jonas Jenwald
22e0ed51c6 Remove unnecessary /* eslint no-var: error */ lines in the test/unit/ folder (PR 12528 follow-up)
These lines are no longer needed, since the ESLint `no-var` rule has been enabled in the entire folder.
2021-03-13 11:50:11 +01:00
Jonas Jenwald
f58fee0956 Enable the ESLint no-var rule in gulpfile.js
Given that `let`/`const` is already used here and there in this file, converting the rest of the `var` occurrences shouldn't be a problem.

Note that the majority of these changes were done automatically, by using the `gulp lint --fix` command, and the manual changes were limited to the following diff:

```diff
diff --git a/gulpfile.js b/gulpfile.js
index e2360c8ec..905420c33 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -676,8 +676,8 @@ gulp.task("default_preferences-pre", function () {
       ],
     }).code;
   }
-  var babel = require("@babel/core");
-  var ctx = {
+  const babel = require("@babel/core");
+  const ctx = {
     rootPath: __dirname,
     saveComments: false,
     defines: builder.merge(DEFINES, {
@@ -690,7 +690,7 @@ gulp.task("default_preferences-pre", function () {
       "pdfjs-lib": "../pdf",
     },
   };
-  var preprocessor2 = require("./external/builder/preprocessor2.js");
+  const preprocessor2 = require("./external/builder/preprocessor2.js");
   return merge([
     gulp.src(["web/{app_options,viewer_compatibility}.js"], {
       base: ".",
@@ -1418,14 +1418,14 @@ function buildLib(defines, dir) {
     });
     return licenseHeaderLibre + content;
   }
-  var babel = require("@babel/core");
+  const babel = require("@babel/core");
   const versionInfo = getVersionJSON();
-  var bundleDefines = builder.merge(defines, {
+  const bundleDefines = builder.merge(defines, {
     BUNDLE_VERSION: versionInfo.version,
     BUNDLE_BUILD: versionInfo.commit,
     TESTING: process.env.TESTING === "true",
   });
-  var ctx = {
+  const ctx = {
     rootPath: __dirname,
     saveComments: false,
     defines: bundleDefines,
@@ -1433,10 +1433,10 @@ function buildLib(defines, dir) {
       "pdfjs-lib": "../pdf",
     },
   };
-  var licenseHeaderLibre = fs
+  const licenseHeaderLibre = fs
     .readFileSync("./src/license_header_libre.js")
     .toString();
-  var preprocessor2 = require("./external/builder/preprocessor2.js");
+  const preprocessor2 = require("./external/builder/preprocessor2.js");
   return merge([
     gulp.src(
       [
```
2021-03-13 11:47:06 +01:00
Jonas Jenwald
50681d71c8 Ensure that getDocument handles Node.js Buffers more gracefully (issue 13075)
While the JSDocs have never advertised `getDocument` as supporting Node.js `Buffer`s, that apparently doesn't stop users from passing such data structures to `getDocument`.
In theory the existing `instanceof Uint8Array` check ought to have caught Node.js `Buffer`s, however for reasons that I don't even pretend to understand that check actually passes. Hence this patch which, *only* in Node.js environments, will special-case `Buffer`s to hopefully provide a slightly better out-of-the-box behaviour in Node.js environments[1].

---
[1] Although I'm not sure that we necessarily want to advertise this in the JSDocs, given the specialized use-case.
2021-03-13 10:52:38 +01:00
Tim van der Meij
61318c42aa
Merge pull request #13085 from Snuffleupagus/driver-rasterize-errors
Ensure that *all* errors are handled in `rasterizeTextLayer`/`rasterizeAnnotationLayer`
2021-03-12 21:16:16 +01:00
Tim van der Meij
be4a41960a
Merge pull request #13081 from Snuffleupagus/objectFromMap
Replace the `objectFromEntries` helper function with an `objectFromMap` one instead, and simplify the data lookup in the AnnotationStorage.getValue method
2021-03-12 21:12:03 +01:00
Tim van der Meij
6af9b6449e
Merge pull request #13074 from Snuffleupagus/scripting-refactor-destroy
Re-factor the `PDFScriptingManager._destroyScripting` method (PR 13042 follow-up)
2021-03-12 21:08:05 +01:00
Jonas Jenwald
d144d01afe Simplify the animationStarted handling in the mobile-viewer/ example
(This is something that I happened to notice while working on the previous patch.)

The code in the `examples/mobile-viewer/viewer.js` file is essentially copied from an older version of the default viewer, hence we can slightly simplify the `animationStarted` handling here.
2021-03-12 17:52:58 +01:00
Jonas Jenwald
5c712f2131 Enable the ESLint no-var rule in the examples/ folder
Updating the examples to use `let`/`const` should be fine, given that they are available in all browsers/platforms that the PDF.js library now supports; please note the following compatibility information:

 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const#browser_compatibility
2021-03-12 17:52:52 +01:00
Jonas Jenwald
276fa4ad8f Replace *most* cases of var with let/const in the examples/ folder
These changes were done automatically, by using the `gulp lint --fix` command, in preparation for the next patch.
2021-03-12 17:16:59 +01:00
Jonas Jenwald
39cd844243 Ensure that *all* errors are handled in rasterizeTextLayer/rasterizeAnnotationLayer
Currently errors occurring within the `src/display/{text_layer, annotation_layer}.js` files are not being handled properly by the test-suite, and the tests simply time out rather than failing as intended.
This makes it *very* easy to accidentally overlook a certain type of errors, see e.g. https://github.com/mozilla/pdf.js/pull/13055#discussion_r589005041, which this patch will thus prevent.
2021-03-12 14:05:53 +01:00
Jonas Jenwald
ab91f42a5e Convert code in src/core/type1_parser.js to use "standard" classes
All of this code predates the existence of native JS classes, however we can now clean this up a little bit.
2021-03-12 12:16:50 +01:00
Jonas Jenwald
8fc8dc020e Enable the ESLint no-var rule in the src/core/type1_parser.js file
Note that the majority of these changes were done automatically, by using `gulp lint --fix`, and the manual changes were limited to the following diff:

```diff
diff --git a/src/core/type1_parser.js b/src/core/type1_parser.js
index 192781de1..05c5fe2e5 100644
--- a/src/core/type1_parser.js
+++ b/src/core/type1_parser.js
@@ -251,7 +251,7 @@ const Type1CharString = (function Type1CharStringClosure() {
               // vhea tables reconstruction -- ignoring it.
               this.stack.pop(); // wy
               wx = this.stack.pop();
-              var sby = this.stack.pop();
+              const sby = this.stack.pop();
               sbx = this.stack.pop();
               this.lsb = sbx;
               this.width = wx;
@@ -263,8 +263,8 @@ const Type1CharString = (function Type1CharStringClosure() {
                 error = true;
                 break;
               }
-              var num2 = this.stack.pop();
-              var num1 = this.stack.pop();
+              const num2 = this.stack.pop();
+              const num1 = this.stack.pop();
               this.stack.push(num1 / num2);
               break;
             case (12 << 8) + 16: // callothersubr
@@ -273,7 +273,7 @@ const Type1CharString = (function Type1CharStringClosure() {
                 break;
               }
               subrNumber = this.stack.pop();
-              var numArgs = this.stack.pop();
+              const numArgs = this.stack.pop();
               if (subrNumber === 0 && numArgs === 3) {
                 const flexArgs = this.stack.splice(this.stack.length - 17, 17);
                 this.stack.push(
@@ -397,9 +397,9 @@ const Type1Parser = (function Type1ParserClosure() {
     if (discardNumber >= data.length) {
       return new Uint8Array(0);
     }
+    const c1 = 52845,
+      c2 = 22719;
     let r = key | 0,
-      c1 = 52845,
-      c2 = 22719,
       i,
       j;
     for (i = 0; i < discardNumber; i++) {
@@ -416,9 +416,9 @@ const Type1Parser = (function Type1ParserClosure() {
   }

   function decryptAscii(data, key, discardNumber) {
-    let r = key | 0,
-      c1 = 52845,
+    const c1 = 52845,
       c2 = 22719;
+    let r = key | 0;
     const count = data.length,
       maybeLength = count >>> 1;
     const decrypted = new Uint8Array(maybeLength);
@@ -429,7 +429,7 @@ const Type1Parser = (function Type1ParserClosure() {
         continue;
       }
       i++;
-      var digit2;
+      let digit2;
       while (i < count && !isHexDigit((digit2 = data[i]))) {
         i++;
       }
@@ -599,7 +599,7 @@ const Type1Parser = (function Type1ParserClosure() {
               if (token !== "/") {
                 continue;
               }
-              var glyph = this.getToken();
+              const glyph = this.getToken();
               length = this.readInt();
               this.getToken(); // read in 'RD' or '-|'
               data = length > 0 ? stream.getBytes(length) : new Uint8Array(0);
@@ -638,7 +638,7 @@ const Type1Parser = (function Type1ParserClosure() {
           case "OtherBlues":
           case "FamilyBlues":
           case "FamilyOtherBlues":
-            var blueArray = this.readNumberArray();
+            const blueArray = this.readNumberArray();
             // *Blue* values may contain invalid data: disables reading of
             // those values when hinting is disabled.
             if (
@@ -672,7 +672,7 @@ const Type1Parser = (function Type1ParserClosure() {
       }

       for (let i = 0; i < charstrings.length; i++) {
-        glyph = charstrings[i].glyph;
+        const glyph = charstrings[i].glyph;
         encoded = charstrings[i].encoded;
         const charString = new Type1CharString();
         const error = charString.convert(
@@ -728,12 +728,12 @@ const Type1Parser = (function Type1ParserClosure() {
         token = this.getToken();
         switch (token) {
           case "FontMatrix":
-            var matrix = this.readNumberArray();
+            const matrix = this.readNumberArray();
             properties.fontMatrix = matrix;
             break;
           case "Encoding":
-            var encodingArg = this.getToken();
-            var encoding;
+            const encodingArg = this.getToken();
+            let encoding;
             if (!/^\d+$/.test(encodingArg)) {
               // encoding name is specified
               encoding = getEncoding(encodingArg);
@@ -764,7 +764,7 @@ const Type1Parser = (function Type1ParserClosure() {
             properties.builtInEncoding = encoding;
             break;
           case "FontBBox":
-            var fontBBox = this.readNumberArray();
+            const fontBBox = this.readNumberArray();
             // adjusting ascent/descent
             properties.ascent = Math.max(fontBBox[3], fontBBox[1]);
             properties.descent = Math.min(fontBBox[1], fontBBox[3]);
```
2021-03-12 12:05:48 +01:00
Jonas Jenwald
82062f7e0d Enable the ESLint no-var rule in the src/core/cff_parser.js file
Note that the majority of these changes were done automatically, by using `gulp lint --fix`, and the manual changes were limited to the following diff:

```diff
diff --git a/src/core/cff_parser.js b/src/core/cff_parser.js
index d684c200e..2e2b811e4 100644
--- a/src/core/cff_parser.js
+++ b/src/core/cff_parser.js
@@ -555,7 +555,7 @@ const CFFParser = (function CFFParserClosure() {
           stackSize %= 2;
           validationCommand = CharstringValidationData[value];
         } else if (value === 10 || value === 29) {
-          var subrsIndex;
+          let subrsIndex;
           if (value === 10) {
             subrsIndex = localSubrIndex;
           } else {
@@ -886,15 +886,15 @@ const CFFParser = (function CFFParserClosure() {
         format = bytes[pos++];
         switch (format & 0x7f) {
           case 0:
-            var glyphsCount = bytes[pos++];
+            const glyphsCount = bytes[pos++];
             for (i = 1; i <= glyphsCount; i++) {
               encoding[bytes[pos++]] = i;
             }
             break;

           case 1:
-            var rangesCount = bytes[pos++];
-            var gid = 1;
+            const rangesCount = bytes[pos++];
+            let gid = 1;
             for (i = 0; i < rangesCount; i++) {
               const start = bytes[pos++];
               const left = bytes[pos++];
@@ -938,7 +938,7 @@ const CFFParser = (function CFFParserClosure() {
           }
           break;
         case 3:
-          var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
+          const rangesCount = (bytes[pos++] << 8) | bytes[pos++];
           for (i = 0; i < rangesCount; ++i) {
             let first = (bytes[pos++] << 8) | bytes[pos++];
             if (i === 0 && first !== 0) {
@@ -1173,7 +1173,7 @@ class CFFDict {
   }
 }

-var CFFTopDict = (function CFFTopDictClosure() {
+const CFFTopDict = (function CFFTopDictClosure() {
   const layout = [
     [[12, 30], "ROS", ["sid", "sid", "num"], null],
     [[12, 20], "SyntheticBase", "num", null],
@@ -1229,7 +1229,7 @@ var CFFTopDict = (function CFFTopDictClosure() {
   return CFFTopDict;
 })();

-var CFFPrivateDict = (function CFFPrivateDictClosure() {
+const CFFPrivateDict = (function CFFPrivateDictClosure() {
   const layout = [
     [6, "BlueValues", "delta", null],
     [7, "OtherBlues", "delta", null],
@@ -1265,11 +1265,12 @@ var CFFPrivateDict = (function CFFPrivateDictClosure() {
   return CFFPrivateDict;
 })();

-var CFFCharsetPredefinedTypes = {
+const CFFCharsetPredefinedTypes = {
   ISO_ADOBE: 0,
   EXPERT: 1,
   EXPERT_SUBSET: 2,
 };
+
 class CFFCharset {
   constructor(predefined, format, charset, raw) {
     this.predefined = predefined;
@@ -1695,7 +1696,7 @@ class CFFCompiler {
             // For offsets we just insert a 32bit integer so we don't have to
             // deal with figuring out the length of the offset when it gets
             // replaced later on by the compiler.
-            var name = dict.keyToNameMap[key];
+            const name = dict.keyToNameMap[key];
             // Some offsets have the offset and the length, so just record the
             // position of the first one.
             if (!offsetTracker.isTracking(name)) {
```
2021-03-12 12:00:38 +01:00
Jonas Jenwald
f3948aeb90 Enable the ESLint no-var rule in the src/core/font_renderer.js file
Note that the majority of these changes were done automatically, by using `gulp lint --fix`, and the manual changes were limited to the following diff:

```diff
diff --git a/src/core/font_renderer.js b/src/core/font_renderer.js
index e1538c481..00f5424cd 100644
--- a/src/core/font_renderer.js
+++ b/src/core/font_renderer.js
@@ -152,9 +152,9 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
   }

   function lookupCmap(ranges, unicode) {
-    let code = unicode.codePointAt(0),
-      gid = 0;
-    let l = 0,
+    const code = unicode.codePointAt(0);
+    let gid = 0,
+      l = 0,
       r = ranges.length - 1;
     while (l < r) {
       const c = (l + r + 1) >> 1;
@@ -199,7 +199,7 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
         flags = (code[i] << 8) | code[i + 1];
         const glyphIndex = (code[i + 2] << 8) | code[i + 3];
         i += 4;
-        var arg1, arg2;
+        let arg1, arg2;
         if (flags & 0x01) {
           arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
           arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
@@ -366,7 +366,7 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
       while (i < code.length) {
         let stackClean = false;
         let v = code[i++];
-        var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
+        let xa, xb, ya, yb, y1, y2, y3, n, subrCode;
         switch (v) {
           case 1: // hstem
             stems += stack.length >> 1;
@@ -494,7 +494,7 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
                 bezierCurveTo(xa, y2, xb, y3, x, y);
                 break;
               case 37: // flex1
-                var x0 = x,
+                const x0 = x,
                   y0 = y;
                 xa = x + stack.shift();
                 ya = y + stack.shift();
```
2021-03-12 11:57:27 +01:00
Brendan Dahl
56fd01bf8d
Merge pull request #13078 from brendandahl/disable-missing
Disable intermittent unit test "creates pdf doc from non-existent URL"
2021-03-11 21:17:54 -08:00
Brendan Dahl
47a5550f10 Disable intermittent unit test "creates pdf doc from non-existent URL"
Disable this test so we don't have to manually review unit test
failure log all the time.
2021-03-11 11:40:40 -08:00
Brendan Dahl
1b42fe2917
Merge pull request #13015 from calixteman/avoid_dl
JS - Avoid a popup to ask for updating Acrobat.
2021-03-11 08:43:49 -08:00
Jonas Jenwald
b326432895 Simplify the data lookup in the AnnotationStorage.getValue method
Rather than first checking if data exists before fetching it from storage, we can simply do the lookup directly and then check its value.
Note that this follows the same pattern as utilized in the `AnnotationStorage.setValue` method.
2021-03-11 16:37:38 +01:00
Jonas Jenwald
a0e584eeb2 Replace the objectFromEntries helper function with an objectFromMap one instead
Given that it's only used with `Map`s, and that it's currently implemented in such a way that we (indirectly) must iterate through the data *twice*, some simplification cannot hurt here.
Note that the only reason that we're not using `Object.fromEntries(...)` directly, at each call-site, is that that one won't guarantee that a `null` prototype is being used.
2021-03-11 16:37:34 +01:00
Brendan Dahl
3d4bb5e5c5
Merge pull request #13018 from calixteman/xfa_bind
XFA - Create Form DOM in merging template and data trees
2021-03-10 10:27:06 -08:00
Jonas Jenwald
52a598915f Re-factor the PDFScriptingManager._destroyScripting method (PR 13042 follow-up)
*Please note:* Given the pre-existing issues raised in PR 13056, which seem to block immediate progress there, this patch extracts some *overall* improvements of the scripting/sandbox destruction in `PDFScriptingManager`.

As can be seen in `BaseViewer.setDocument`, it's currently necessary to *manually* delay the `PDFScriptingManager`-destruction in order for things to work correctly. This is, in hindsight, obviously an *extremely poor* design choice on my part; sorry about the churn here!

In order to improve things overall, the `PDFScriptingManager._destroyScripting`-method is re-factored to wait for the relevant events to be dispatched *before* sandbox-destruction occurs.
To avoid the scripting/sandbox-destruction hanging indefinitely, we utilize a timeout to force-destroy the sandbox after a short time (currently set to 1 second).
2021-03-10 13:08:19 +01:00
Calixte Denizet
3243672727 XFA - Create Form DOM in merging template and data trees
- Spec: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.364.2157&rep=rep1&type=pdf#page=171;
  - support for the 2 ways of merging: consumeData and matchTemplate;
  - create additional nodes in template DOM when occur node allows it;
  - support for global values in data DOM.
2021-03-08 14:10:30 +01:00
Tim van der Meij
5e3af62d58
Merge pull request #13063 from Snuffleupagus/more-web-optional-chaining
Use more optional chaining in the web/-folder (PR 12961 follow-up)
2021-03-07 19:00:57 +01:00
Jonas Jenwald
bc13932ac1 Use more optional chaining in the web/-folder (PR 12961 follow-up)
I overlooked these cases previously, but there's no reason why optional chaining (and nullish coalescing) cannot be used here as well.
2021-03-07 16:20:52 +01:00
Jonas Jenwald
bdde621366 Avoid unnecessary size_kb calculation, for large files, in PDFDocumentProperties._parseFileSize (PR 13050 follow-up) 2021-03-07 16:10:11 +01:00
Tim van der Meij
34c9e889ac
Merge pull request #13062 from Snuffleupagus/rm-features
Remove the `test/features` folder, since it's very out of date (issue 11954)
2021-03-07 13:51:49 +01:00
Jonas Jenwald
36bb4fa823 Remove the test/features folder, since it's very out of date (issue 11954)
These tests, and their [accompanying Wiki page](https://github.com/mozilla/pdf.js/wiki/Required-Browser-Features), haven't received any real updates for *many years* and are sufficiently out of date to be effectively useless now.
Providing *irrelevant* compatibility information seems overall worse than not providing any information, and as suggested in the issue it'd probably be better to use https://github.com/mozilla/pdf.js#online-demo for checking if a particular platform/browser is supported.

Thanks to version control, it's easy to restore these files should the need ever arise. However, re-introducing these tests would essentially require updating every single test-case *and* a commitment to keeping them up to date with future code changes.
2021-03-07 13:41:30 +01:00
Tim van der Meij
ba1b4097dc
Merge pull request #13055 from calixteman/reset_radio
JS - reset correctly radio buttons
2021-03-07 13:23:18 +01:00
Tim van der Meij
11d86df4a7
Merge pull request #13060 from Snuffleupagus/update-packages
Update packages and translations
2021-03-07 12:54:13 +01:00
Jonas Jenwald
d4cf751f91 Update l10n files 2021-03-07 12:05:10 +01:00
Jonas Jenwald
75eb2aedaa Update npm packages 2021-03-07 12:00:57 +01:00
Calixte Denizet
c01ef24541 JS - reset correctly radio buttons 2021-03-07 11:04:40 +01:00
Tim van der Meij
709c57a66b
Merge pull request #13054 from Snuffleupagus/scripting-pageOpenClose
Move handling of the PageOpen/PageClose events into the `PDFScriptingManager` (PR 13042 follow-up)
2021-03-06 20:33:07 +01:00
Jonas Jenwald
87dd93b7fc Move handling of the PageOpen/PageClose events into the PDFScriptingManager (PR 13042 follow-up)
By moving this code from the `BaseViewer` and into `PDFScriptingManager`, all of the scripting initialization/handling code is now limited to just one file/class which help overall readability (in my opinion). Also, this patch is a *net reduction* in number of lines of code which can never hurt.

As part of these changes, the intermediary "pageopen"/"pageclose" events are now removed in favor of using the "regular" viewer events directly in `PDFScriptingManager`. Hence this removes some (strictly unnecessary) indirection in the current code, when handling PageOpen/PageClose events, which leads to overall fewer function calls in this part of the code.
2021-03-06 10:12:32 +01:00
Tim van der Meij
fb87704b38
Merge pull request #13042 from Snuffleupagus/PDFScriptingManager
[api-minor] Move the viewer scripting initialization/handling into a new `PDFScriptingManager` class
2021-03-05 21:43:42 +01:00
Jonas Jenwald
a6d1cba38c [api-minor] Move the viewer scripting initialization/handling into a new PDFScriptingManager class
The *main* purpose of this patch is to allow scripting to be used together with the viewer components, note the updated "simpleviewer"/"singlepageviewer" examples, in addition to the full default viewer.
Given how the scripting functionality is currently implemented in the default viewer, trying to re-use this with the standalone viewer components would be *very* hard and ideally you'd want it to work out-of-the-box.

For an initial implementation, in the default viewer, of the scripting functionality it probably made sense to simply dump all of the code in the `app.js` file, however that cannot be used with the viewer components.
To address this, the functionality is moved into a new `PDFScriptingManager` class which can thus be handled in the same way as all other viewer components (and e.g. be passed to the `BaseViewer`-implementations).

Obviously the scripting functionality needs quite a lot of data, during its initialization, and for the default viewer we want to maintain the current way of doing the lookups since that helps avoid a number of redundant API-calls.
To that end, the `PDFScriptingManager` implementation accepts (optional) factories/functions such that we can maintain the current behaviour for the default viewer. For the viewer components specifically, fallback code-paths are provided to ensure that scripting will "just work"[1].

Besides moving the viewer handling of the scripting code to its own file/class, this patch also takes the opportunity to re-factor the functionality into a number of helper methods to improve overall readability[2].
Note that it's definitely possible that the `PDFScriptingManager` class could be improved even further (e.g. for general re-use), since it's still heavily tailored to the default viewer use-case, however I believe that this patch is still a good step forward overall.

---

[1] Obviously *all* the relevant document properties might not be available in the viewer components use-case (e.g. the various URLs), but most things should work just fine.

[2] The old `PDFViewerApplication._initializeJavaScript` method, where everything was simply inlined, have over time (in my opinion) become quite large and somewhat difficult to *easily* reason about.
2021-03-05 20:31:48 +01:00
Jonas Jenwald
5b9638329c Move apiPageLayoutToSpreadMode and apiPageModeToSidebarView from web/app.js and into web/ui_utils.js
These changes will be necessary for the next patch, since we don't want to accidentally pull in the entire default viewer in the standalone viewer components.
2021-03-05 20:31:48 +01:00
Tim van der Meij
583d77a53f
Merge pull request #13053 from Snuffleupagus/dev-enableScripting
Enable scripting by default in the development viewer; remove the standalone `acroforms` example
2021-03-05 20:27:25 +01:00
Jonas Jenwald
bd7868f54c Remove the standalone acroforms example
At this point in time the standalone `acroforms` example is no longer needed, since both the `simpleviewer` and `singlepageviewer` examples already support AcroForms by default.
Moreover, the `acroforms` example no longer illustrate best practices, given the direct usage of `PDFPageView` for a multipage document.
2021-03-04 23:56:51 +01:00
Jonas Jenwald
7dc1bbf05e Enable scripting by default in the development viewer
Given that scripting is now enabled in Firefox Nightly (but only there), it seems weird to not have scripting enabled by default in `gulp server` mode.
2021-03-04 23:56:51 +01:00
Tim van der Meij
4b49db7c95
Merge pull request #13050 from Snuffleupagus/l10n-fallback
Collect all l10n fallback strings, used in the viewer, in one helper function (PR 12981 follow-up)
2021-03-04 23:46:48 +01:00
Jonas Jenwald
038668bf8c Collect all l10n fallback strings, used in the viewer, in one helper function (PR 12981 follow-up)
Rather than having to spell out the English fallback strings at *every* single `IL10n.get` call-site throughout the viewer, we can simplify things by collecting them in *one* central spot.
This provides a much better overview of the fallback l10n strings used, which makes future changes easier and ensures that fallback strings occuring in multiple places cannot accidentally get out of sync.
Furthermore, by making the `fallback` parameter of the `IL10n.get` method *optional*[1] many of the call-sites (and their surrounding code) become a lot less verbose.

---
[1] It's obviously still possible to pass in a fallback string, it's just not required.
2021-03-04 11:34:51 +01:00
Tim van der Meij
8d203b3039
Merge pull request #13045 from mozilla/dependabot/npm_and_yarn/pug-code-gen-2.0.3
Bump pug-code-gen from 2.0.1 to 2.0.3
2021-03-03 19:51:22 +01:00
dependabot[bot]
6312a321df
Bump pug-code-gen from 2.0.1 to 2.0.3
Bumps [pug-code-gen](https://github.com/pugjs/pug) from 2.0.1 to 2.0.3.
- [Release notes](https://github.com/pugjs/pug/releases)
- [Commits](https://github.com/pugjs/pug/compare/pug-code-gen@2.0.1...pug@2.0.3)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-03 02:28:49 +00:00
Tim van der Meij
9d91237d14
Merge pull request #13039 from Snuffleupagus/issue-13036
Change the background to ensure that the sidebar is visible/readable when the viewer is narrow (issue 13036)
2021-03-01 23:25:44 +01:00